{"id":15022901,"url":"https://github.com/lexascms/ember-data-lexascms","last_synced_at":"2025-04-04T07:43:12.703Z","repository":{"id":38280596,"uuid":"279543550","full_name":"LexasCMS/ember-data-lexascms","owner":"LexasCMS","description":"The officially supported addon for using LexasCMS with Ember Data.","archived":false,"fork":false,"pushed_at":"2024-01-09T17:41:57.000Z","size":3834,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-01T08:03:16.142Z","etag":null,"topics":["ember-addon","ember-data","emberjs","lexascms"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LexasCMS.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-07-14T09:38:02.000Z","updated_at":"2022-02-17T08:44:28.000Z","dependencies_parsed_at":"2024-09-22T13:01:17.943Z","dependency_job_id":"cc5049ca-9cfb-45b2-a6fb-b29cf2873360","html_url":"https://github.com/LexasCMS/ember-data-lexascms","commit_stats":{"total_commits":49,"total_committers":4,"mean_commits":12.25,"dds":0.4897959183673469,"last_synced_commit":"b1325212bc3f0fea7934f258c6d5fb9b6a12ca98"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexasCMS%2Fember-data-lexascms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexasCMS%2Fember-data-lexascms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexasCMS%2Fember-data-lexascms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LexasCMS%2Fember-data-lexascms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LexasCMS","download_url":"https://codeload.github.com/LexasCMS/ember-data-lexascms/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142042,"owners_count":20890652,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ember-addon","ember-data","emberjs","lexascms"],"created_at":"2024-09-24T19:58:30.415Z","updated_at":"2025-04-04T07:43:12.684Z","avatar_url":"https://github.com/LexasCMS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca href=\"https://github.com/LexasCMS/ember-data-lexascms/actions\"\u003e\n  \u003cimg src=\"https://github.com/LexasCMS/ember-data-lexascms/workflows/CI/badge.svg\" alt=\"CI Build Status\" /\u003e\n\u003c/a\u003e\n\n\u003ca href=\"https://badge.fury.io/js/ember-data-lexascms\"\u003e\n  \u003cimg src=\"https://badge.fury.io/js/ember-data-lexascms.svg\" alt=\"NPM Package Version\" /\u003e\n\u003c/a\u003e\n\n\nember-data-lexascms\n===============================================================\n\nThis is the officially supported addon for using the [LexasCMS](https://www.lexascms.com/) JSON:API content delivery API with [Ember Data](https://github.com/emberjs/data/).\n\n\nTable of Contents\n---------------------------------------------------------------\n\n- [Why do I need this addon?](#why-do-i-need-this-addon)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Configure Adapters and Serializers](#configure-adapters-and-serializers)\n  - [Retrieving Image Fields](#retrieving-image-fields)\n  - [Retrieving and Querying Content](#retrieving-and-querying-content)\n  - [Setting the Request Context](#setting-the-request-context)\n  - [Supporting Content Previews](#supporting-content-previews)\n- [Contributing](#contributing)\n- [License](#license)\n\n\nWhy do I need this addon?\n---------------------------------------------------------------\n\nWhile LexasCMS does natively support JSON:API and can be used with Ember Data without this addon, the addon defines some helpful defaults and provides predefined models in order to improve developer experience.\n\nThe addon currently provides the following:\n\n- Preconfigured adapater/serializer\n- Predefined model for retrieving `image` fields\n- `lexascms` service for managing the LexasCMS request context\n\n\nInstallation\n---------------------------------------------------------------\n\n```\nember install ember-data-lexascms\n```\n\n\nUsage\n---------------------------------------------------------------\n\n\u003e You'll need a LexasCMS account before you can use this addon. If you don't have one already, you can [click here to create one](https://app.lexascms.com/signup).\n\nAfter you've installed the addon, add the following config to your applications `config/environment.js` file.\n\n```js\nlet ENV = {\n  // ...\n\n  lexascms: {\n    spaceId: 'YOUR_LEXASCMS_SPACE_ID',\n    apiKey: 'YOUR_LEXASCMS_API_KEY' // Optional, unless using content previews\n  }\n\n  // ...\n};\n```\n\n**Warning:** Placing API keys in your `config/environment.js` file will cause them to be publicly exposed. When using content previews, we recommend using private environments which cannot be accessed publicly.\n\n### Configure Adapters and Serializers\n\nIn order to have Ember Data pull content from LexasCMS, you'll also need to define some customer adapters and serializers.\n\nIf there are only specific models which are to be retrieved from LexasCMS, you'll need to define a custom adapter and serializer for each model.\n\nThe below examples defines an adapter and serializer for the `blog-post` model.\n\n```js\n// File: app/adapters/blog-post.js\n\nimport LexasCMSAdapter from 'ember-data-lexascms/adapters/lexascms';\n\nexport default class BlogPostAdapter extends LexasCMSAdapter {\n}\n```\n\n```js\n// File: app/serializers/blog-post.js\n\nimport LexasCMSSerializer from 'ember-data-lexascms/serializers/lexascms';\n\nexport default class BlogPostSerializer extends LexasCMSSerializer {\n}\n```\n\nAlternatively, if all of your models are to be retrieved from LexasCMS, you can just define a custom application adapter and serializer. These will then be used for all of the models within your application.\n\n```js\n// File: app/adapters/application.js\n\nimport LexasCMSAdapter from 'ember-data-lexascms/adapters/lexascms';\n\nexport default class ApplicationAdapter extends LexasCMSAdapter {\n}\n```\n\n```js\n// File: app/serializers/application.js\n\nimport LexasCMSSerializer from 'ember-data-lexascms/serializers/lexascms';\n\nexport default class ApplicationSerializer extends LexasCMSSerializer {\n}\n```\n\n### Retrieving Image Fields\n\nIn LexasCMS, image fields are treated as relationships. When defining a model which contains an image field, you should create a `belongsTo` relationship to the predefined `core-image` model.\n\nThe below example shows how you could define a `blog-post` model which contains an image field called `coverImage`:\n\n```js\nimport Model, { attr, belongsTo } from '@ember-data/model';\n\nexport default class BlogPostModel extends Model {\n\n  @attr slug;\n  @attr title;\n  @attr publishedAt;\n  @attr excerpt;\n  @attr mainContent;\n  \n  @belongsTo('author') author;\n  @belongsTo('core-image') coverImage;\n\n}\n```\n\n### Retrieving and Querying Content\n\nOnce you have completed the above steps and defined all of your models, you can retrieve content from LexasCMS using the regular Ember Data methods (`findAll`, `findRecord`, `query` etc.).\n\nIf you would like to apply filters or sorting options to your query, you can provide those options by using Ember Data's `query` method like so:\n\n```js\nthis.store.query('blog-post', {\n\n  // Fitering\n  filter: {\n    publishedAt: { _gte: '2020-01-01' }\n  },\n\n  // Sorting\n  sort: '-publishedAt'\n  \n});\n```\n\nFor further information on the available query options, please see the [full documentation](https://www.lexascms.com/docs/api-reference/content-delivery/jsonapi/) for the JSON:API content delivery API.\n\n### Setting the Request Context\n\nIn the event that you would like to set a request context on your requests to LexasCMS (i.e. for content personalisation), you can call the `setRequestContext` method on the `lexascms` service.\n\nThis method can be called from anywhere within your application, and will automatically attach the provided context to all requests made to LexasCMS via Ember Data.\n\n**Note:** You can also retrieve the current request context using the `getRequestContext` method on the `lexascms` service.\n\nThe following example shows how you could attach a request context from the `beforeModel` hook of your application route.\n\n```js\nimport Route from '@ember/routing/route';\nimport { inject as service } from '@ember/service';\n\nexport default class ApplicationRoute extends Route {\n\n  @service lexascms;\n\n  beforeModel() {\n    this.lexascms.setRequestContext({\n      audienceAttributes: {\n        age: 25,\n        location: 'GB'\n      }\n    });\n  }\n\n}\n```\n\n### Supporting Content Previews\n\nWhen making use of LexasCMS's [visual content previews](https://www.lexascms.com/features/content-previews/) feature, LexasCMS will load your application with the `lexascmsRequestContent` query parameter.\n\nThis value of this parameter will be a pre-encoded request context, which should be provided directly to all request to the Content Delivery API.\n\nThe code snippet below shows an example of how you could achieve this using your Application route.\n\n```js\nimport Route from '@ember/routing/route';\nimport { inject as service } from '@ember/service';\n\nexport default class ApplicationRoute extends Route {\n\n  @service lexascms;\n\n  queryParams = {\n    lexascmsRequestContext: {\n      refreshModel: true\n    }\n  };\n\n  model({ lexascmsRequestContext }) {\n    // Set request context if 'lexascmsRequestContext' is defined\n    if (lexascmsRequestContext !== undefined) {\n      this.lexascms.setRequestContext(lexascmsRequestContext);\n    }\n  }\n\n}\n```\n\n\nContributing\n---------------------------------------------------------------\n\nSee the [Contributing](CONTRIBUTING.md) guide for details.\n\n\nLicense\n---------------------------------------------------------------\n\nThis project is licensed under the [MIT License](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexascms%2Fember-data-lexascms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flexascms%2Fember-data-lexascms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flexascms%2Fember-data-lexascms/lists"}