@agility/content-sync 1.0.0 → 1.0.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/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
 
@@ -9277,14 +9277,18 @@ __webpack_require__(29).config({
9277
9277
  path: ".env.".concat("production") });
9278
9278
 
9279
9279
 
9280
-
9281
- var getFilePath = function getFilePath(_ref) {var options = _ref.options,itemType = _ref.itemType,languageCode = _ref.languageCode,itemID = _ref.itemID;
9282
- var fileName = "".concat(itemID, ".json");
9283
-
9284
- return path.join(options.rootPath, languageCode, itemType, fileName);
9285
- };
9286
-
9287
- var saveItem = /*#__PURE__*/function () {var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref2) {var options, item, itemType, languageCode, itemID, filePath, dirPath, json;return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:options = _ref2.options, item = _ref2.item, itemType = _ref2.itemType, languageCode = _ref2.languageCode, itemID = _ref2.itemID;
9280
+ /**
9281
+ * 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.
9282
+ * @param {Object} params - The parameters object
9283
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
9284
+ * @param {String} params.options.rootPath - The path to store/access the content as JSON
9285
+ * @param {Object} params.item - The object representing the Content Item, Page, Url Redirections, Sync State (state), or Sitemap that needs to be saved/updated
9286
+ * @param {String} params.itemType - The type of item being saved/updated, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
9287
+ * @param {String} params.languageCode - The locale code associated to the item being saved/updated
9288
+ * @param {(String|Number)} params.itemID - The ID of the item being saved/updated - this could be a string or number depending on the itemType
9289
+ * @returns {Void}
9290
+ */
9291
+ var saveItem = /*#__PURE__*/function () {var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {var options, item, itemType, languageCode, itemID, filePath, dirPath, json;return regeneratorRuntime.wrap(function _callee$(_context) {while (1) {switch (_context.prev = _context.next) {case 0:options = _ref.options, item = _ref.item, itemType = _ref.itemType, languageCode = _ref.languageCode, itemID = _ref.itemID;
9288
9292
 
9289
9293
  filePath = getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });
9290
9294
 
@@ -9296,20 +9300,40 @@ var saveItem = /*#__PURE__*/function () {var _ref3 = _asyncToGenerator( /*#__PUR
9296
9300
  }
9297
9301
 
9298
9302
  json = JSON.stringify(item);
9299
- fs.writeFileSync(filePath, json);case 6:case "end":return _context.stop();}}}, _callee);}));return function saveItem(_x) {return _ref3.apply(this, arguments);};}();
9303
+ fs.writeFileSync(filePath, json);case 6:case "end":return _context.stop();}}}, _callee);}));return function saveItem(_x) {return _ref2.apply(this, arguments);};}();
9300
9304
 
9301
-
9302
- var deleteItem = /*#__PURE__*/function () {var _ref5 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref4) {var options, itemType, languageCode, itemID, filePath;return regeneratorRuntime.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0:options = _ref4.options, itemType = _ref4.itemType, languageCode = _ref4.languageCode, itemID = _ref4.itemID;
9305
+ /**
9306
+ * The function to handle deleting an item to your storage. This could be a Content Item, Page, Url Redirections, Sync State (state), or Sitemap.
9307
+ * @param {Object} params - The parameters object
9308
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
9309
+ * @param {String} params.options.rootPath - The path to store/access the content as JSON
9310
+ * @param {String} params.itemType - The type of item being deleted, expected values are `item`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
9311
+ * @param {String} params.languageCode - The locale code associated to the item being saved/updated
9312
+ * @param {(String|Number)} params.itemID - The ID of the item being deleted - this could be a string or number depending on the itemType
9313
+ * @returns {Void}
9314
+ */
9315
+ var deleteItem = /*#__PURE__*/function () {var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref3) {var options, itemType, languageCode, itemID, filePath;return regeneratorRuntime.wrap(function _callee2$(_context2) {while (1) {switch (_context2.prev = _context2.next) {case 0:options = _ref3.options, itemType = _ref3.itemType, languageCode = _ref3.languageCode, itemID = _ref3.itemID;
9303
9316
 
9304
9317
  filePath = getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });
9305
9318
 
9306
9319
  if (fs.existsSync(filePath)) {
9307
9320
  fs.unlinkSync(filePath);
9308
- }case 3:case "end":return _context2.stop();}}}, _callee2);}));return function deleteItem(_x2) {return _ref5.apply(this, arguments);};}();
9309
-
9321
+ }case 3:case "end":return _context2.stop();}}}, _callee2);}));return function deleteItem(_x2) {return _ref4.apply(this, arguments);};}();
9310
9322
 
9311
9323
 
9312
- var mergeItemToList = /*#__PURE__*/function () {var _ref7 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(_ref6) {var options, item, languageCode, itemID, referenceName, definitionName, contentList, cIndex;return regeneratorRuntime.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0:options = _ref6.options, item = _ref6.item, languageCode = _ref6.languageCode, itemID = _ref6.itemID, referenceName = _ref6.referenceName, definitionName = _ref6.definitionName;_context3.next = 3;return (
9324
+ /**
9325
+ * The function to handle updating and placing a Content Item into a "list" so that you can handle querying a collection of items.
9326
+ * @param {Object} params - The parameters object
9327
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
9328
+ * @param {String} params.options.rootPath - The path to store/access the content as JSON
9329
+ * @param {Object} params.item - The object representing the Content Item
9330
+ * @param {String} params.languageCode - The locale code associated to the item being saved/updated
9331
+ * @param {(String|Number)} params.itemID - The ID of the item being updated - this could be a string or number depending on the itemType
9332
+ * @param {String} params.referenceName - The reference name of the Content List that this Content Item should be added to
9333
+ * @param {String} params.definitionName - The Model name that the Content Item is based on
9334
+ * @returns {Void}
9335
+ */
9336
+ var mergeItemToList = /*#__PURE__*/function () {var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(_ref5) {var options, item, languageCode, itemID, referenceName, definitionName, contentList, cIndex;return regeneratorRuntime.wrap(function _callee3$(_context3) {while (1) {switch (_context3.prev = _context3.next) {case 0:options = _ref5.options, item = _ref5.item, languageCode = _ref5.languageCode, itemID = _ref5.itemID, referenceName = _ref5.referenceName, definitionName = _ref5.definitionName;_context3.next = 3;return (
9313
9337
 
9314
9338
  getItem({ options: options, itemType: "list", languageCode: languageCode, itemID: referenceName }));case 3:contentList = _context3.sent;
9315
9339
 
@@ -9341,31 +9365,45 @@ var mergeItemToList = /*#__PURE__*/function () {var _ref7 = _asyncToGenerator( /
9341
9365
  }
9342
9366
  }_context3.next = 7;return (
9343
9367
 
9344
- saveItem({ options: options, item: contentList, itemType: "list", languageCode: languageCode, itemID: referenceName }));case 7:case "end":return _context3.stop();}}}, _callee3);}));return function mergeItemToList(_x3) {return _ref7.apply(this, arguments);};}();
9345
-
9368
+ saveItem({ options: options, item: contentList, itemType: "list", languageCode: languageCode, itemID: referenceName }));case 7:case "end":return _context3.stop();}}}, _callee3);}));return function mergeItemToList(_x3) {return _ref6.apply(this, arguments);};}();
9346
9369
 
9347
- var getItem = /*#__PURE__*/function () {var _ref9 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(_ref8) {var options, itemType, languageCode, itemID, filePath, json;return regeneratorRuntime.wrap(function _callee4$(_context4) {while (1) {switch (_context4.prev = _context4.next) {case 0:options = _ref8.options, itemType = _ref8.itemType, languageCode = _ref8.languageCode, itemID = _ref8.itemID;
9370
+ /**
9371
+ * The function to handle retrieving a Content Item, Page, Url Redirections, Sync State (state), or Sitemap
9372
+ * @param {Object} params - The parameters object
9373
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
9374
+ * @param {String} params.options.rootPath - The path to store/access the content as JSON
9375
+ * @param {String} params.itemType - The type of item being accessed, expected values are `item`, `list`, `page`, `sitemap`, `nestedsitemap`, `state`, `urlredirections`
9376
+ * @param {String} params.languageCode - The locale code associated to the item being accessed
9377
+ * @param {(String|Number)} params.itemID - The ID of the item being accessed - this could be a string or number depending on the itemType
9378
+ * @returns {Object}
9379
+ */
9380
+ var getItem = /*#__PURE__*/function () {var _ref8 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(_ref7) {var options, itemType, languageCode, itemID, filePath, json;return regeneratorRuntime.wrap(function _callee4$(_context4) {while (1) {switch (_context4.prev = _context4.next) {case 0:options = _ref7.options, itemType = _ref7.itemType, languageCode = _ref7.languageCode, itemID = _ref7.itemID;
9348
9381
  filePath = getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });if (
9349
9382
 
9350
9383
  fs.existsSync(filePath)) {_context4.next = 4;break;}return _context4.abrupt("return", null);case 4:
9351
9384
 
9352
9385
  json = fs.readFileSync(filePath, 'utf8');return _context4.abrupt("return",
9353
- JSON.parse(json));case 6:case "end":return _context4.stop();}}}, _callee4);}));return function getItem(_x4) {return _ref9.apply(this, arguments);};}();
9354
-
9355
-
9356
- var clearItems = /*#__PURE__*/function () {var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(_ref10) {var options;return regeneratorRuntime.wrap(function _callee5$(_context5) {while (1) {switch (_context5.prev = _context5.next) {case 0:options = _ref10.options;
9357
- fs.rmdirSync(options.rootPath, { recursive: true });case 2:case "end":return _context5.stop();}}}, _callee5);}));return function clearItems(_x5) {return _ref11.apply(this, arguments);};}();
9386
+ JSON.parse(json));case 6:case "end":return _context4.stop();}}}, _callee4);}));return function getItem(_x4) {return _ref8.apply(this, arguments);};}();
9358
9387
 
9359
9388
 
9360
- var waitOnLock = /*#__PURE__*/function () {var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6(lockFile) {return regeneratorRuntime.wrap(function _callee6$(_context6) {while (1) {switch (_context6.prev = _context6.next) {case 0:_context6.next = 2;return (
9361
-
9362
- check(lockFile));case 2:if (!_context6.sent) {_context6.next = 7;break;}_context6.next = 5;return (
9363
- sleep(100));case 5:_context6.next = 0;break;case 7:case "end":return _context6.stop();}}}, _callee6);}));return function waitOnLock(_x6) {return _ref12.apply(this, arguments);};}();
9389
+ /**
9390
+ * The function to handle clearing the cache of synchronized data from the CMS
9391
+ * @param {Object} params - The parameters object
9392
+ * @param {Object} params.options - A flexible object that can contain any properties specifically related to this interface
9393
+ * @param {String} params.options.rootPath - The path to store/access the content as JSON
9394
+ * @returns {Void}
9395
+ */
9396
+ var clearItems = /*#__PURE__*/function () {var _ref10 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(_ref9) {var options;return regeneratorRuntime.wrap(function _callee5$(_context5) {while (1) {switch (_context5.prev = _context5.next) {case 0:options = _ref9.options;
9397
+ fs.rmdirSync(options.rootPath, { recursive: true });case 2:case "end":return _context5.stop();}}}, _callee5);}));return function clearItems(_x5) {return _ref10.apply(this, arguments);};}();
9364
9398
 
9365
9399
 
9366
9400
 
9367
9401
 
9368
- var mutexLock = /*#__PURE__*/function () {var _ref13 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7() {var dir, lockFile;return regeneratorRuntime.wrap(function _callee7$(_context7) {while (1) {switch (_context7.prev = _context7.next) {case 0:
9402
+ /**
9403
+ * The function to handle multi-threaded Syncs that may be happening at the same time. If you need to prevent a sync from happening and let it wait until another sync has finished use this.
9404
+ * @returns {Promise}
9405
+ */
9406
+ var mutexLock = /*#__PURE__*/function () {var _ref11 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee6() {var dir, lockFile;return regeneratorRuntime.wrap(function _callee6$(_context6) {while (1) {switch (_context6.prev = _context6.next) {case 0:
9369
9407
 
9370
9408
 
9371
9409
  dir = os.tmpdir();
@@ -9375,39 +9413,50 @@ var mutexLock = /*#__PURE__*/function () {var _ref13 = _asyncToGenerator( /*#__P
9375
9413
  }
9376
9414
 
9377
9415
  //THE LOCK IS ALREADY HELD - WAIT UP!
9378
- _context7.next = 5;return waitOnLock(lockFile);case 5:_context7.prev = 5;return _context7.abrupt("return",
9416
+ _context6.next = 5;return waitOnLock(lockFile);case 5:_context6.prev = 5;return _context6.abrupt("return",
9379
9417
 
9380
9418
 
9381
- lockSync(lockFile));case 9:_context7.prev = 9;_context7.t0 = _context7["catch"](5);if (!(
9419
+ lockSync(lockFile));case 9:_context6.prev = 9;_context6.t0 = _context6["catch"](5);if (!(
9382
9420
 
9383
- "".concat(_context7.t0).indexOf("Lock file is already being held") !== -1)) {_context7.next = 28;break;}_context7.next = 14;return (
9421
+ "".concat(_context6.t0).indexOf("Lock file is already being held") !== -1)) {_context6.next = 28;break;}_context6.next = 14;return (
9384
9422
 
9385
9423
 
9386
- sleep(100));case 14:_context7.next = 16;return (
9387
- waitOnLock(lockFile));case 16:_context7.prev = 16;return _context7.abrupt("return",
9424
+ sleep(100));case 14:_context6.next = 16;return (
9425
+ waitOnLock(lockFile));case 16:_context6.prev = 16;return _context6.abrupt("return",
9388
9426
 
9389
9427
 
9390
- lockSync(lockFile));case 20:_context7.prev = 20;_context7.t1 = _context7["catch"](16);if (!(
9428
+ lockSync(lockFile));case 20:_context6.prev = 20;_context6.t1 = _context6["catch"](16);if (!(
9391
9429
 
9392
- "".concat(_context7.t0).indexOf("Lock file is already being held") !== -1)) {_context7.next = 28;break;}_context7.next = 25;return (
9430
+ "".concat(_context6.t0).indexOf("Lock file is already being held") !== -1)) {_context6.next = 28;break;}_context6.next = 25;return (
9393
9431
 
9394
9432
 
9395
- sleep(100));case 25:_context7.next = 27;return (
9396
- waitOnLock(lockFile));case 27:return _context7.abrupt("return",
9433
+ sleep(100));case 25:_context6.next = 27;return (
9434
+ waitOnLock(lockFile));case 27:return _context6.abrupt("return",
9397
9435
  lockSync(lockFile));case 28:throw (
9398
9436
 
9399
9437
 
9400
9438
 
9401
9439
 
9402
- Error("The mutex lock could not be obtained."));case 29:case "end":return _context7.stop();}}}, _callee7, null, [[5, 9], [16, 20]]);}));return function mutexLock() {return _ref13.apply(this, arguments);};}();
9440
+ Error("The mutex lock could not be obtained."));case 29:case "end":return _context6.stop();}}}, _callee6, null, [[5, 9], [16, 20]]);}));return function mutexLock() {return _ref11.apply(this, arguments);};}();
9403
9441
 
9404
9442
 
9405
9443
 
9406
9444
 
9407
9445
 
9446
+ //private function to get a wait on a lock file
9447
+ var waitOnLock = /*#__PURE__*/function () {var _ref12 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee7(lockFile) {return regeneratorRuntime.wrap(function _callee7$(_context7) {while (1) {switch (_context7.prev = _context7.next) {case 0:_context7.next = 2;return (
9448
+ check(lockFile));case 2:if (!_context7.sent) {_context7.next = 7;break;}_context7.next = 5;return (
9449
+ sleep(100));case 5:_context7.next = 0;break;case 7:case "end":return _context7.stop();}}}, _callee7);}));return function waitOnLock(_x6) {return _ref12.apply(this, arguments);};}();
9408
9450
 
9409
9451
 
9410
9452
 
9453
+ //private function to get path of an item
9454
+ var getFilePath = function getFilePath(_ref13) {var options = _ref13.options,itemType = _ref13.itemType,languageCode = _ref13.languageCode,itemID = _ref13.itemID;
9455
+ var fileName = "".concat(itemID, ".json");
9456
+ return path.join(options.rootPath, languageCode, itemType, fileName);
9457
+ };
9458
+
9459
+
9411
9460
  module.exports = {
9412
9461
  saveItem: saveItem,
9413
9462
  deleteItem: deleteItem,
@@ -11177,7 +11226,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11177
11226
  //if the api is being updated, wait a few ms and try again...
11178
11227
  waitMS += waitIntervalMS;if (!(
11179
11228
  waitMS > waitMaxMS)) {_context.next = 15;break;}
11180
- Object(util["logWarning"])("Sync API has been busy for too long, canceling.");return _context.abrupt("break", 33);case 15:
11229
+ Object(util["logWarning"])("Sync API has been busy for too long, canceling.");return _context.abrupt("break", 36);case 15:
11181
11230
 
11182
11231
 
11183
11232
 
@@ -11187,7 +11236,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11187
11236
  Object(util["logInfo"])("Sync API is busy. Waiting...");
11188
11237
  }_context.next = 18;return (
11189
11238
 
11190
- Object(util["sleep"])(waitIntervalMS));case 18:return _context.abrupt("continue", 32);case 19:
11239
+ Object(util["sleep"])(waitIntervalMS));case 18:return _context.abrupt("continue", 35);case 19:
11191
11240
 
11192
11241
 
11193
11242
 
@@ -11200,18 +11249,22 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11200
11249
  syncItems = syncRet.items;
11201
11250
 
11202
11251
  //if we don't get anything back, kick out
11203
- if (!(syncItems.length === 0)) {_context.next = 23;break;}return _context.abrupt("break", 33);case 23:
11252
+ if (!(syncItems.length > 0)) {_context.next = 29;break;}
11253
+
11254
+ index = 0;case 23:if (!(index < syncItems.length)) {_context.next = 29;break;}_context.next = 26;return (
11255
+ storeInterface.saveContentItem({ contentItem: syncItems[index], languageCode: languageCode }));case 26:index++;_context.next = 23;break;case 29:if (!(
11256
+
11204
11257
 
11205
11258
 
11259
+ syncRet.syncToken > token)) {_context.next = 33;break;}
11260
+ token = syncRet.syncToken;_context.next = 34;break;case 33:return _context.abrupt("break", 36);case 34:
11206
11261
 
11207
- index = 0;case 24:if (!(index < syncItems.length)) {_context.next = 30;break;}_context.next = 27;return (
11208
- storeInterface.saveContentItem({ contentItem: syncItems[index], languageCode: languageCode }));case 27:index++;_context.next = 24;break;case 30:
11209
11262
 
11210
11263
 
11211
- token = syncRet.syncToken;
11212
- itemCount += syncItems.length;case 32:if (
11213
11264
 
11214
- token > 0 || busy === true) {_context.next = 7;break;}case 33:
11265
+ itemCount += syncItems.length;case 35:if (
11266
+
11267
+ token > 0 || busy === true) {_context.next = 7;break;}case 36:
11215
11268
 
11216
11269
  if (itemCount > 0) {
11217
11270
  Object(util["logInfo"])("Content Sync returned ".concat(itemCount, " item(s)."));
@@ -11219,7 +11272,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11219
11272
  Object(util["logInfo"])("Content Sync returned no item(s).");
11220
11273
  }return _context.abrupt("return",
11221
11274
 
11222
- token);case 35:case "end":return _context.stop();}}}, _callee, this);}));return syncContent_ref.apply(this, arguments);}
11275
+ token);case 38:case "end":return _context.stop();}}}, _callee, this);}));return syncContent_ref.apply(this, arguments);}
11223
11276
  // CONCATENATED MODULE: ./src/methods/clearSync.js
11224
11277
  function clearSync_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {Promise.resolve(value).then(_next, _throw);}}function clearSync_asyncToGenerator(fn) {return function () {var self = this,args = arguments;return new Promise(function (resolve, reject) {var gen = fn.apply(self, args);function _next(value) {clearSync_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);}function _throw(err) {clearSync_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);}_next(undefined);});};}
11225
11278
 
@@ -11255,7 +11308,7 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11255
11308
  //if the api is being updated, wait a few ms and try again...
11256
11309
  waitMS += waitIntervalMS;if (!(
11257
11310
  waitMS > waitMaxMS)) {_context.next = 15;break;}
11258
- Object(util["logWarning"])("Sync API has been busy for too long, canceling.");return _context.abrupt("break", 33);case 15:
11311
+ Object(util["logWarning"])("Sync API has been busy for too long, canceling.");return _context.abrupt("break", 36);case 15:
11259
11312
 
11260
11313
 
11261
11314
 
@@ -11264,7 +11317,7 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11264
11317
  Object(util["logInfo"])("Sync API is busy. Waiting...");
11265
11318
  }_context.next = 18;return (
11266
11319
 
11267
- Object(util["sleep"])(waitIntervalMS));case 18:return _context.abrupt("continue", 32);case 19:
11320
+ Object(util["sleep"])(waitIntervalMS));case 18:return _context.abrupt("continue", 35);case 19:
11268
11321
 
11269
11322
 
11270
11323
 
@@ -11276,20 +11329,25 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11276
11329
 
11277
11330
  syncItems = syncRet.items;
11278
11331
 
11279
- //if we don't get anything back, kick out
11280
- if (!(syncItems.length === 0)) {_context.next = 23;break;}return _context.abrupt("break", 33);case 23:
11332
+ //if we have something...
11333
+ if (!(syncItems.length > 0)) {_context.next = 29;break;}
11334
+
11335
+
11336
+ index = 0;case 23:if (!(index < syncItems.length)) {_context.next = 29;break;}_context.next = 26;return (
11337
+ storeInterface.savePageItem({ pageItem: syncItems[index], languageCode: languageCode }));case 26:index++;_context.next = 23;break;case 29:if (!(
11338
+
11339
+
11281
11340
 
11341
+ syncRet.syncToken > token)) {_context.next = 33;break;}
11342
+ token = syncRet.syncToken;_context.next = 34;break;case 33:return _context.abrupt("break", 36);case 34:
11282
11343
 
11283
11344
 
11284
- index = 0;case 24:if (!(index < syncItems.length)) {_context.next = 30;break;}_context.next = 27;return (
11285
- storeInterface.savePageItem({ pageItem: syncItems[index], languageCode: languageCode }));case 27:index++;_context.next = 24;break;case 30:
11286
11345
 
11287
11346
 
11288
- token = syncRet.syncToken;
11289
- itemCount += syncItems.length;case 32:if (
11347
+ itemCount += syncItems.length;case 35:if (
11290
11348
 
11291
11349
 
11292
- token > 0 || busy === true) {_context.next = 7;break;}case 33:
11350
+ token > 0 || busy === true) {_context.next = 7;break;}case 36:
11293
11351
 
11294
11352
  if (itemCount > 0) {
11295
11353
  Object(util["logInfo"])("Page Sync returned ".concat(itemCount, " item(s)."));
@@ -11298,7 +11356,7 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11298
11356
  }return _context.abrupt("return",
11299
11357
 
11300
11358
 
11301
- token);case 35:case "end":return _context.stop();}}}, _callee, this);}));return syncPages_ref.apply(this, arguments);}
11359
+ token);case 38:case "end":return _context.stop();}}}, _callee, this);}));return syncPages_ref.apply(this, arguments);}
11302
11360
  // CONCATENATED MODULE: ./src/methods/runSync.js
11303
11361
  function _createForOfIteratorHelper(o, allowArrayLike) {var it;if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {if (it) o = it;var i = 0;var F = function F() {};return { s: F, n: function n() {if (i >= o.length) return { done: true };return { done: false, value: o[i++] };}, e: function e(_e) {throw _e;}, f: F };}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var normalCompletion = true,didErr = false,err;return { s: function s() {it = o[Symbol.iterator]();}, n: function n() {var step = it.next();normalCompletion = step.done;return step;}, e: function e(_e2) {didErr = true;err = _e2;}, f: function f() {try {if (!normalCompletion && it["return"] != null) it["return"]();} finally {if (didErr) throw err;}} };}function _unsupportedIterableToArray(o, minLen) {if (!o) return;if (typeof o === "string") return _arrayLikeToArray(o, minLen);var n = Object.prototype.toString.call(o).slice(8, -1);if (n === "Object" && o.constructor) n = o.constructor.name;if (n === "Map" || n === "Set") return Array.from(o);if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);}function _arrayLikeToArray(arr, len) {if (len == null || len > arr.length) len = arr.length;for (var i = 0, arr2 = new Array(len); i < len; i++) {arr2[i] = arr[i];}return arr2;}function runSync_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try {var info = gen[key](arg);var value = info.value;} catch (error) {reject(error);return;}if (info.done) {resolve(value);} else {Promise.resolve(value).then(_next, _throw);}}function runSync_asyncToGenerator(fn) {return function () {var self = this,args = arguments;return new Promise(function (resolve, reject) {var gen = fn.apply(self, args);function _next(value) {runSync_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);}function _throw(err) {runSync_asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);}_next(undefined);});};}
11304
11362