@agility/content-sync 1.0.3 → 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,78 +9300,110 @@ 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);};}();
9300
-
9303
+ fs.writeFileSync(filePath, json);case 6:case "end":return _context.stop();}}}, _callee);}));return function saveItem(_x) {return _ref2.apply(this, arguments);};}();
9301
9304
 
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
 
9316
9340
  if (contentList == null) {
9317
9341
  //initialize the list
9318
- contentList = [];
9319
- }
9320
-
9321
-
9322
- //replace the item...
9323
- cIndex = contentList.findIndex(function (ci) {
9324
- return ci.contentID === itemID;
9325
- });
9326
-
9327
- if (item.properties.state === 3) {
9328
- //*** deleted item (remove from the list) ***
9329
- if (cIndex >= 0) {
9330
- //remove the item
9331
- contentList.splice(cIndex, 1);
9332
- }
9333
-
9342
+ contentList = [item];
9334
9343
  } else {
9335
- //*** regular item (merge) ***
9336
- if (cIndex >= 0) {
9337
- //replace the existing item
9338
- contentList[cIndex] = item;
9344
+ //replace the item...
9345
+ cIndex = contentList.findIndex(function (ci) {
9346
+ return ci.contentID === itemID;
9347
+ });
9348
+
9349
+ if (item.properties.state === 3) {
9350
+ //*** deleted item (remove from the list) ***
9351
+ if (cIndex >= 0) {
9352
+ //remove the item
9353
+ contentList.splice(cIndex, 1);
9354
+ }
9355
+
9339
9356
  } else {
9340
- //and it to the end of the
9341
- contentList.push(item);
9357
+ //*** regular item (merge) ***
9358
+ if (cIndex >= 0) {
9359
+ //replace the existing item
9360
+ contentList[cIndex] = item;
9361
+ } else {
9362
+ //and it to the end of the
9363
+ contentList.push(item);
9364
+ }
9342
9365
  }
9366
+ }_context3.next = 7;return (
9343
9367
 
9344
- }_context3.next = 9;return (
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);};}();
9345
9369
 
9346
- saveItem({ options: options, item: contentList, itemType: "list", languageCode: languageCode, itemID: referenceName }));case 9:case "end":return _context3.stop();}}}, _callee3);}));return function mergeItemToList(_x3) {return _ref7.apply(this, arguments);};}();
9347
-
9348
-
9349
- 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;
9350
9381
  filePath = getFilePath({ options: options, itemType: itemType, languageCode: languageCode, itemID: itemID });if (
9351
9382
 
9352
9383
  fs.existsSync(filePath)) {_context4.next = 4;break;}return _context4.abrupt("return", null);case 4:
9353
9384
 
9354
9385
  json = fs.readFileSync(filePath, 'utf8');return _context4.abrupt("return",
9355
- JSON.parse(json));case 6:case "end":return _context4.stop();}}}, _callee4);}));return function getItem(_x4) {return _ref9.apply(this, arguments);};}();
9356
-
9357
-
9358
- 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;
9359
- 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);};}();
9360
9387
 
9361
9388
 
9362
- 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 (
9363
-
9364
- check(lockFile));case 2:if (!_context6.sent) {_context6.next = 7;break;}_context6.next = 5;return (
9365
- 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);};}();
9366
9398
 
9367
9399
 
9368
9400
 
9369
9401
 
9370
- 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:
9371
9407
 
9372
9408
 
9373
9409
  dir = os.tmpdir();
@@ -9377,38 +9413,49 @@ var mutexLock = /*#__PURE__*/function () {var _ref13 = _asyncToGenerator( /*#__P
9377
9413
  }
9378
9414
 
9379
9415
  //THE LOCK IS ALREADY HELD - WAIT UP!
9380
- _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",
9381
9417
 
9382
9418
 
9383
- 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 (!(
9384
9420
 
9385
- "".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 (
9386
9422
 
9387
9423
 
9388
- sleep(100));case 14:_context7.next = 16;return (
9389
- 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",
9390
9426
 
9391
9427
 
9392
- 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 (!(
9393
9429
 
9394
- "".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 (
9395
9431
 
9396
9432
 
9397
- sleep(100));case 25:_context7.next = 27;return (
9398
- 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",
9399
9435
  lockSync(lockFile));case 28:throw (
9400
9436
 
9401
9437
 
9402
9438
 
9403
9439
 
9404
- 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);};}();
9441
+
9405
9442
 
9406
9443
 
9407
9444
 
9408
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);};}();
9409
9450
 
9410
9451
 
9411
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
+
9412
9459
 
9413
9460
  module.exports = {
9414
9461
  saveItem: saveItem,
@@ -11179,7 +11226,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11179
11226
  //if the api is being updated, wait a few ms and try again...
11180
11227
  waitMS += waitIntervalMS;if (!(
11181
11228
  waitMS > waitMaxMS)) {_context.next = 15;break;}
11182
- 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:
11183
11230
 
11184
11231
 
11185
11232
 
@@ -11189,7 +11236,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11189
11236
  Object(util["logInfo"])("Sync API is busy. Waiting...");
11190
11237
  }_context.next = 18;return (
11191
11238
 
11192
- 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:
11193
11240
 
11194
11241
 
11195
11242
 
@@ -11202,18 +11249,22 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11202
11249
  syncItems = syncRet.items;
11203
11250
 
11204
11251
  //if we don't get anything back, kick out
11205
- 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
+
11206
11257
 
11207
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:
11208
11261
 
11209
- index = 0;case 24:if (!(index < syncItems.length)) {_context.next = 30;break;}_context.next = 27;return (
11210
- storeInterface.saveContentItem({ contentItem: syncItems[index], languageCode: languageCode }));case 27:index++;_context.next = 24;break;case 30:
11211
11262
 
11212
11263
 
11213
- token = syncRet.syncToken;
11214
- itemCount += syncItems.length;case 32:if (
11215
11264
 
11216
- 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:
11217
11268
 
11218
11269
  if (itemCount > 0) {
11219
11270
  Object(util["logInfo"])("Content Sync returned ".concat(itemCount, " item(s)."));
@@ -11221,7 +11272,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
11221
11272
  Object(util["logInfo"])("Content Sync returned no item(s).");
11222
11273
  }return _context.abrupt("return",
11223
11274
 
11224
- 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);}
11225
11276
  // CONCATENATED MODULE: ./src/methods/clearSync.js
11226
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);});};}
11227
11278
 
@@ -11257,7 +11308,7 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11257
11308
  //if the api is being updated, wait a few ms and try again...
11258
11309
  waitMS += waitIntervalMS;if (!(
11259
11310
  waitMS > waitMaxMS)) {_context.next = 15;break;}
11260
- 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:
11261
11312
 
11262
11313
 
11263
11314
 
@@ -11266,7 +11317,7 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11266
11317
  Object(util["logInfo"])("Sync API is busy. Waiting...");
11267
11318
  }_context.next = 18;return (
11268
11319
 
11269
- 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:
11270
11321
 
11271
11322
 
11272
11323
 
@@ -11278,20 +11329,25 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11278
11329
 
11279
11330
  syncItems = syncRet.items;
11280
11331
 
11281
- //if we don't get anything back, kick out
11282
- 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
+
11283
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:
11284
11343
 
11285
11344
 
11286
- index = 0;case 24:if (!(index < syncItems.length)) {_context.next = 30;break;}_context.next = 27;return (
11287
- storeInterface.savePageItem({ pageItem: syncItems[index], languageCode: languageCode }));case 27:index++;_context.next = 24;break;case 30:
11288
11345
 
11289
11346
 
11290
- token = syncRet.syncToken;
11291
- itemCount += syncItems.length;case 32:if (
11347
+ itemCount += syncItems.length;case 35:if (
11292
11348
 
11293
11349
 
11294
- token > 0 || busy === true) {_context.next = 7;break;}case 33:
11350
+ token > 0 || busy === true) {_context.next = 7;break;}case 36:
11295
11351
 
11296
11352
  if (itemCount > 0) {
11297
11353
  Object(util["logInfo"])("Page Sync returned ".concat(itemCount, " item(s)."));
@@ -11300,7 +11356,7 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
11300
11356
  }return _context.abrupt("return",
11301
11357
 
11302
11358
 
11303
- 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);}
11304
11360
  // CONCATENATED MODULE: ./src/methods/runSync.js
11305
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);});};}
11306
11362
 
@@ -11465,7 +11521,7 @@ var saveContentItem = /*#__PURE__*/function () {var _ref2 = store_interface_asyn
11465
11521
  definitionName = sanitizeName(contentItem.properties.definitionName);
11466
11522
  referenceName = contentItem.properties.referenceName;if (!(
11467
11523
 
11468
- contentItem.properties.state === 3)) {_context.next = 15;break;}_context.next = 9;return (
11524
+ contentItem.properties.state === 3)) {_context.next = 17;break;}_context.next = 9;return (
11469
11525
 
11470
11526
 
11471
11527
 
@@ -11473,27 +11529,26 @@ var saveContentItem = /*#__PURE__*/function () {var _ref2 = store_interface_asyn
11473
11529
  options: options,
11474
11530
  itemType: "item",
11475
11531
  languageCode: languageCode,
11476
- itemID: contentItem.contentID }));case 9:currentItem = _context.sent;
11532
+ itemID: contentItem.contentID }));case 9:currentItem = _context.sent;if (!
11477
11533
 
11534
+ currentItem) {_context.next = 15;break;}
11478
11535
 
11479
- if (currentItem) {
11480
- //if the item is deleted, we need to grab the def and ref name from the current
11481
- definitionName = sanitizeName(currentItem.properties.definitionName);
11482
- referenceName = currentItem.properties.referenceName;
11483
- }_context.next = 13;return (
11536
+ //if the item is deleted, we need to grab the def and ref name from the current
11537
+ definitionName = sanitizeName(currentItem.properties.definitionName);
11538
+ referenceName = currentItem.properties.referenceName;_context.next = 15;return (
11484
11539
 
11485
11540
  store_interface_store.deleteItem({
11486
11541
  options: options,
11487
11542
  itemType: "item",
11488
11543
  languageCode: languageCode,
11489
- itemID: contentItem.contentID }));case 13:_context.next = 20;break;case 15:if (!(
11544
+ itemID: contentItem.contentID }));case 15:_context.next = 22;break;case 17:if (!(
11490
11545
 
11491
11546
 
11492
11547
 
11493
11548
 
11494
11549
  !contentItem.properties.definitionName ||
11495
- !contentItem.properties.referenceName)) {_context.next = 18;break;}
11496
- Object(util["logWarning"])("Content with id ".concat(contentItem.contentID, " does not have the neccessary properties to be saved."));return _context.abrupt("return");case 18:_context.next = 20;return (
11550
+ !contentItem.properties.referenceName)) {_context.next = 20;break;}
11551
+ Object(util["logWarning"])("Content with id ".concat(contentItem.contentID, " does not have the neccessary properties to be saved."));return _context.abrupt("return");case 20:_context.next = 22;return (
11497
11552
 
11498
11553
 
11499
11554
 
@@ -11504,11 +11559,11 @@ var saveContentItem = /*#__PURE__*/function () {var _ref2 = store_interface_asyn
11504
11559
  item: contentItem,
11505
11560
  itemType: "item",
11506
11561
  languageCode: languageCode,
11507
- itemID: contentItem.contentID }));case 20:if (!
11562
+ itemID: contentItem.contentID }));case 22:if (!
11508
11563
 
11509
11564
 
11510
11565
 
11511
- referenceName) {_context.next = 23;break;}_context.next = 23;return (
11566
+ referenceName) {_context.next = 25;break;}_context.next = 25;return (
11512
11567
 
11513
11568
  store_interface_store.mergeItemToList({
11514
11569
  options: options,
@@ -11516,7 +11571,7 @@ var saveContentItem = /*#__PURE__*/function () {var _ref2 = store_interface_asyn
11516
11571
  languageCode: languageCode,
11517
11572
  itemID: contentItem.contentID,
11518
11573
  referenceName: referenceName,
11519
- definitionName: definitionName }));case 23:case "end":return _context.stop();}}}, _callee);}));return function saveContentItem(_x) {return _ref2.apply(this, arguments);};}();
11574
+ definitionName: definitionName }));case 25:case "end":return _context.stop();}}}, _callee);}));return function saveContentItem(_x) {return _ref2.apply(this, arguments);};}();
11520
11575
 
11521
11576
 
11522
11577