@agility/content-sync 1.1.2 → 1.1.4

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/.babelrc CHANGED
@@ -1,7 +1,7 @@
1
- {
2
- "presets": [
3
- "@babel/preset-env"
4
- ],
5
- "sourceMaps": true,
6
- "retainLines": true
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env"
4
+ ],
5
+ "sourceMaps": true,
6
+ "retainLines": true
7
7
  }
@@ -1,35 +1,35 @@
1
- {
2
- "version": "0.2.0",
3
- "configurations": [
4
- {
5
- "type": "node",
6
- "request": "launch",
7
- "name": "Mocha All",
8
- "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
9
- "args": [
10
- "--timeout",
11
- "999999",
12
- "--colors",
13
- "${workspaceFolder}/test"
14
- ],
15
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
16
- "console": "integratedTerminal",
17
- "internalConsoleOptions": "neverOpen"
18
- },
19
- {
20
- "type": "node",
21
- "request": "launch",
22
- "name": "Mocha Current File",
23
- "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
24
- "args": [
25
- "--timeout",
26
- "999999",
27
- "--colors",
28
- "${file}"
29
- ],
30
- "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
31
- "console": "integratedTerminal",
32
- "internalConsoleOptions": "neverOpen"
33
- }
34
- ]
1
+ {
2
+ "version": "0.2.0",
3
+ "configurations": [
4
+ {
5
+ "type": "node",
6
+ "request": "launch",
7
+ "name": "Mocha All",
8
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
9
+ "args": [
10
+ "--timeout",
11
+ "999999",
12
+ "--colors",
13
+ "${workspaceFolder}/test"
14
+ ],
15
+ "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
16
+ "console": "integratedTerminal",
17
+ "internalConsoleOptions": "neverOpen"
18
+ },
19
+ {
20
+ "type": "node",
21
+ "request": "launch",
22
+ "name": "Mocha Current File",
23
+ "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
24
+ "args": [
25
+ "--timeout",
26
+ "999999",
27
+ "--colors",
28
+ "${file}"
29
+ ],
30
+ "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
31
+ "console": "integratedTerminal",
32
+ "internalConsoleOptions": "neverOpen"
33
+ }
34
+ ]
35
35
  }
package/README.md CHANGED
@@ -1,206 +1,206 @@
1
- # Agility CMS Sync SDK
2
- The Agility CMS Sync SDK provides an interface to sync, store and access content locally.
3
-
4
- By keeping a local cache of your content, your web app can access content faster.
5
-
6
- ## Benefits
7
- - Access your content quickly, and locally in your web or mobile app
8
- - Use your own persistent storage, such as **Gatsby GraphQL**, a **Database**, or **Local Storage**
9
- - Simplify syncing content
10
-
11
-
12
-
13
- ## Use Cases
14
- 1. You want to reduce the amount of REST API calls made to your Agility CMS instance.
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.
20
-
21
- ## How it Works
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.
23
-
24
- It Calls the Sync API and returns content that has not yet been synced. The first call will pull everything and save it to your local store. Subsequent calls will only refresh content that has changed since the last time the Sync API was called.
25
-
26
- This SDK:
27
- - Calls the API
28
- - Manages your `syncToken` for you
29
- - Stores content in the filesystem (by default)
30
- - Provides ability to extend and store/access content in other places
31
-
32
- ## Setup
33
- Install `@agility/content-sync`:
34
- ```
35
- npm install @agility/content-sync
36
- ```
37
-
38
- ## Sync to Filesystem (using Defaults)
39
- 1. Create a sync client:
40
- ```javascript
41
- import agilitySync from '@agility/content-sync'
42
- const syncClient = agilitySync.getSyncClient({
43
- //your 'guid' from Agility CMS
44
- guid: 'some-guid',
45
- //your 'apiKey' from Agility CMS
46
- apiKey: 'some-api-key',
47
- //the language(s) of content you want to source
48
- languages: ['en-us'],
49
- //your channel(s) for the pages you want to source
50
- channels: ['website'],
51
- //whether you are using the preview key or not
52
- isPreview: false
53
- });
54
- ```
55
-
56
- 2. Run the `runSync` command to synchronize your Agility CMS content (*Content* and *Pages*) to your local filesystem
57
- ```javascript
58
- await syncClient.runSync();
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`.
61
-
62
- ## Accessing Content
63
- Once content is in your sync store, you can easily access it as you need it:
64
- ```javascript
65
- import agilitySync from '@agility/constent-sync'
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
- });
76
-
77
- //start the sync process
78
- await syncClient.runSync();
79
-
80
- //query and retrieve your content
81
- const contentItem = await syncClient.store.getContentItem({
82
- contentID: 21,
83
- languageCode: languageCode
84
- })
85
-
86
- const contentList = await syncClient.store.getContentList({
87
- referenceName: 'posts',
88
- languageCode: languageCode
89
- })
90
- ```
91
-
92
- ## Clearing out the Sync Content
93
- To clear out the locally synced content, run the clearSync command.
94
- ```javascript
95
- await syncClient.clearSync();
96
- ```
97
-
98
- ## How to Create your Own Sync Store
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:
101
- ```javascript
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 }) => {
113
- console.log(`Console Interface: saveItem has been called`);
114
- return null;
115
- }
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 }) => {
126
- console.log(`Console Interface: deleteItem has been called`);
127
- return null;
128
- }
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 }) => {
141
- console.log(`Console Interface: mergeItemToList has been called`);
142
- return null;
143
- }
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 }) => {
154
- console.log(`Console Interface: getItem has been called`)
155
- return null;
156
- }
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 }) => {
164
- console.log(`Console Interface: clearItem has been called`)
165
- return null;
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();
199
- ```
200
-
201
-
202
-
203
-
204
-
205
-
206
-
1
+ # Agility CMS Sync SDK
2
+ The Agility CMS Sync SDK provides an interface to sync, store and access content locally.
3
+
4
+ By keeping a local cache of your content, your web app can access content faster.
5
+
6
+ ## Benefits
7
+ - Access your content quickly, and locally in your web or mobile app
8
+ - Use your own persistent storage, such as **Gatsby GraphQL**, a **Database**, or **Local Storage**
9
+ - Simplify syncing content
10
+
11
+
12
+
13
+ ## Use Cases
14
+ 1. You want to reduce the amount of REST API calls made to your Agility CMS instance.
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.
20
+
21
+ ## How it Works
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.
23
+
24
+ It Calls the Sync API and returns content that has not yet been synced. The first call will pull everything and save it to your local store. Subsequent calls will only refresh content that has changed since the last time the Sync API was called.
25
+
26
+ This SDK:
27
+ - Calls the API
28
+ - Manages your `syncToken` for you
29
+ - Stores content in the filesystem (by default)
30
+ - Provides ability to extend and store/access content in other places
31
+
32
+ ## Setup
33
+ Install `@agility/content-sync`:
34
+ ```
35
+ npm install @agility/content-sync
36
+ ```
37
+
38
+ ## Sync to Filesystem (using Defaults)
39
+ 1. Create a sync client:
40
+ ```javascript
41
+ import agilitySync from '@agility/content-sync'
42
+ const syncClient = agilitySync.getSyncClient({
43
+ //your 'guid' from Agility CMS
44
+ guid: 'some-guid',
45
+ //your 'apiKey' from Agility CMS
46
+ apiKey: 'some-api-key',
47
+ //the language(s) of content you want to source
48
+ languages: ['en-us'],
49
+ //your channel(s) for the pages you want to source
50
+ channels: ['website'],
51
+ //whether you are using the preview key or not
52
+ isPreview: false
53
+ });
54
+ ```
55
+
56
+ 2. Run the `runSync` command to synchronize your Agility CMS content (*Content* and *Pages*) to your local filesystem
57
+ ```javascript
58
+ await syncClient.runSync();
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`.
61
+
62
+ ## Accessing Content
63
+ Once content is in your sync store, you can easily access it as you need it:
64
+ ```javascript
65
+ import agilitySync from '@agility/constent-sync'
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
+ });
76
+
77
+ //start the sync process
78
+ await syncClient.runSync();
79
+
80
+ //query and retrieve your content
81
+ const contentItem = await syncClient.store.getContentItem({
82
+ contentID: 21,
83
+ languageCode: languageCode
84
+ })
85
+
86
+ const contentList = await syncClient.store.getContentList({
87
+ referenceName: 'posts',
88
+ languageCode: languageCode
89
+ })
90
+ ```
91
+
92
+ ## Clearing out the Sync Content
93
+ To clear out the locally synced content, run the clearSync command.
94
+ ```javascript
95
+ await syncClient.clearSync();
96
+ ```
97
+
98
+ ## How to Create your Own Sync Store
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:
101
+ ```javascript
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 }) => {
113
+ console.log(`Console Interface: saveItem has been called`);
114
+ return null;
115
+ }
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 }) => {
126
+ console.log(`Console Interface: deleteItem has been called`);
127
+ return null;
128
+ }
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 }) => {
141
+ console.log(`Console Interface: mergeItemToList has been called`);
142
+ return null;
143
+ }
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 }) => {
154
+ console.log(`Console Interface: getItem has been called`)
155
+ return null;
156
+ }
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 }) => {
164
+ console.log(`Console Interface: clearItem has been called`)
165
+ return null;
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();
199
+ ```
200
+
201
+
202
+
203
+
204
+
205
+
206
+