@agility/content-sync 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -12,10 +12,11 @@ By keeping a local cache of your content, your web app can access content faster
12
12
 
13
13
  ## Use Cases
14
14
  1. You want to reduce the amount of REST API calls made to your Agility CMS instance.
15
- 2. You want so synchronize content from the CMS to another system such Redis Cache
16
- 3. You are running a **Server-Side Rendered (SSR)** web app and you want to cache your content locally, reducing latency for retrieving content.
17
- 4. You are using a **Static Site Generator (SSG)** and you don't want to have to re-source all of your content on each build.
18
- 5. You have a client-side **Single Page Application**, and want to cache content in local storage in the browser.
15
+ 2. You have a client-side Single Page Application, and want to cache content in local storage in the browser.
16
+ 3. You want so synchronize content from the CMS to another system such Redis Cache
17
+ 4. You are running a **Server-Side Rendered (SSR)** web app and you want to cache your content locally, reducing latency for retrieving content.
18
+ 5. You are using a **Static Site Generator (SSG)** and you don't want to have to re-source all of your content on each build.
19
+ 6. You have a client-side **Single Page Application**, and want to cache content in local storage in the browser.
19
20
 
20
21
  ## How it Works
21
22
  This Sync SDK uses the Sync API `getSyncPages` and `getSyncContent` found in our [Agility CMS Content Fetch JS SDK](https://agilitydocs.netlify.com/agility-content-fetch-js-sdk/) and aims to abstract some of the complexities involved in managing synced content.
@@ -58,32 +59,6 @@ npm install @agility/content-sync
58
59
  ```
59
60
  `runSync()` will pull down all your *Sitemap*, *Pages*, and *Content* and store them in your local filesystem under the default path `.agility-files`.
60
61
 
61
- ## Sync using a Custom Store
62
- While this SDK provides a filesystem sync interface by default, you can change this and use another one or create your own.
63
- ```javascript
64
- import agilitySync from '@agility/constent-sync'
65
- import aSampleSyncConsoleInterface from './store-interface-console'
66
- const syncClient = agilitySync.getSyncClient({
67
- //your 'guid' from Agility CMS
68
- guid: 'some-guid',
69
- //your 'apiKey' from Agility CMS
70
- apiKey: 'some-api-key',
71
- //the language(s) of content you want to source
72
- languages: ['en-us'],
73
- //your channel(s) for the pages you want to source
74
- channels: ['website'],
75
- //your custom storage/access interface
76
- store: {
77
- //must be the interface used to store and access content
78
- interface: aSampleSyncConsoleInterface,
79
- //any options/config that you want to pass along to your interface as an argument 'options'
80
- options: {}
81
- }
82
- });
83
- //start the sync process
84
- syncClient.runSync();
85
- ```
86
-
87
62
  ## Accessing Content
88
63
  Once content is in your sync store, you can easily access it as you need it:
89
64
  ```javascript
@@ -121,32 +96,106 @@ await syncClient.clearSync();
121
96
  ```
122
97
 
123
98
  ## How to Create your Own Sync Store
124
- Create a new `.js` file which exports the following methods:
99
+ While this SDK provides a filesystem sync interface by default, you can change this and use another one or create your own.
100
+ 1. Create a new `.js` file which exports the following methods:
125
101
  ```javascript
126
- exports.saveItem = async ({ options, item, itemType, languageCode, itemID }) => {
102
+ /**
103
+ * The function to handle saving/updating an item to your storage. This could be a Content Item, Page, Url Redirections, Sync State (state), or Sitemap.
104
+ * @param {Object} params - The parameters object
105
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
106
+ * @param {Object} params.item - The object representing the Content Item, Page, Url Redirections, Sync State (state), or Sitemap that needs to be saved/updated
107
+ * @param {String} params.itemType - The type of item being saved/updated, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
108
+ * @param {String} params.languageCode - The locale code associated to the item being saved/updated
109
+ * @param {(String|Number)} params.itemID - The ID of the item being saved/updated - this could be a string or number depending on the itemType
110
+ * @returns {Void}
111
+ */
112
+ const saveItem = async ({ options, item, itemType, languageCode, itemID }) => {
127
113
  console.log(`Console Interface: saveItem has been called`);
128
114
  return null;
129
115
  }
130
-
131
- exports.deleteItem = async ({ options, itemType, languageCode, itemID }) => {
116
+ /**
117
+ * The function to handle deleting an item to your storage. This could be a Content Item, Page, Url Redirections, Sync State (state), or Sitemap.
118
+ * @param {Object} params - The parameters object
119
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
120
+ * @param {String} params.itemType - The type of item being deleted, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
121
+ * @param {String} params.languageCode - The locale code associated to the item being saved/updated
122
+ * @param {(String|Number)} params.itemID - The ID of the item being deleted - this could be a string or number depending on the itemType
123
+ * @returns {Void}
124
+ */
125
+ const deleteItem = async ({ options, itemType, languageCode, itemID }) => {
132
126
  console.log(`Console Interface: deleteItem has been called`);
133
127
  return null;
134
128
  }
135
-
136
- exports.mergeItemToList = async ({ options, item, languageCode, itemID, referenceName, definitionName }) => {
129
+ /**
130
+ * The function to handle updating and placing a Content Item into a "list" so that you can handle querying a collection of items.
131
+ * @param {Object} params - The parameters object
132
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
133
+ * @param {Object} params.item - The object representing the Content Item
134
+ * @param {String} params.languageCode - The locale code associated to the item being saved/updated
135
+ * @param {(String|Number)} params.itemID - The ID of the item being updated - this could be a string or number depending on the itemType
136
+ * @param {String} params.referenceName - The reference name of the Content List that this Content Item should be added to
137
+ * @param {String} params.definitionName - The Model name that the Content Item is based on
138
+ * @returns {Void}
139
+ */
140
+ const mergeItemToList = async ({ options, item, languageCode, itemID, referenceName, definitionName }) => {
137
141
  console.log(`Console Interface: mergeItemToList has been called`);
138
142
  return null;
139
143
  }
140
-
141
- exports.getItem = async ({ options, itemType, languageCode, itemID }) => {
144
+ /**
145
+ * The function to handle retrieving a Content Item, Page, Url Redirections, Sync State (state), or Sitemap
146
+ * @param {Object} params - The parameters object
147
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
148
+ * @param {String} params.itemType - The type of item being accessed, expected values are `item`, `list`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
149
+ * @param {String} params.languageCode - The locale code associated to the item being accessed
150
+ * @param {(String|Number)} params.itemID - The ID of the item being accessed - this could be a string or number depending on the itemType
151
+ * @returns {Object}
152
+ */
153
+ const getItem = async ({ options, itemType, languageCode, itemID }) => {
142
154
  console.log(`Console Interface: getItem has been called`)
143
155
  return null;
144
156
  }
145
-
146
- exports.clearItems = async ({ options }) => {
157
+ /**
158
+ * The function to handle clearing the cache of synchronized data from the CMS
159
+ * @param {Object} params - The parameters object
160
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
161
+ * @returns {Void}
162
+ */
163
+ const clearItems = async ({ options }) => {
147
164
  console.log(`Console Interface: clearItem has been called`)
148
165
  return null;
149
166
  }
167
+
168
+ module.exports = {
169
+ saveItem,
170
+ deleteItem,
171
+ mergeItemToList,
172
+ getItem,
173
+ clearItems
174
+ }
175
+ ```
176
+ 2. Register the `syncClient` to use your **Sync Store**
177
+ ```javascript
178
+ import agilitySync from '@agility/constent-sync'
179
+ import sampleSyncConsoleInterface from './store-interface-console'
180
+ const syncClient = agilitySync.getSyncClient({
181
+ //your 'guid' from Agility CMS
182
+ guid: 'some-guid',
183
+ //your 'apiKey' from Agility CMS
184
+ apiKey: 'some-api-key',
185
+ //the language(s) of content you want to source
186
+ languages: ['en-us'],
187
+ //your channel(s) for the pages you want to source
188
+ channels: ['website'],
189
+ //your custom storage/access interface
190
+ store: {
191
+ //must be the interface used to store and access content
192
+ interface: sampleSyncConsoleInterface,
193
+ //any options/config that you want to pass along to your interface as an argument 'options'
194
+ options: {}
195
+ }
196
+ });
197
+ //start the sync process
198
+ syncClient.runSync();
150
199
  ```
151
200
 
152
201