@agility/content-sync 1.1.0 → 1.1.3

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.
@@ -10856,27 +10856,26 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
10856
10856
  itemCount = 0;
10857
10857
  busy = false;
10858
10858
  waitMS = 0;
10859
- waitMaxMS = 60000;
10860
- waitIntervalMS = 1000;case 7:
10859
+ waitMaxMS = 10 * 60 * 1000;
10860
+ waitIntervalMS = 1000;case 7:_context.next = 9;return (
10861
10861
 
10862
10862
 
10863
- syncRet = null;
10864
10863
 
10865
10864
 
10866
- //sync content items...
10867
- _context.next = 10;return this.agilityClient.getSyncContent({
10868
- syncToken: token,
10869
- pageSize: 100,
10870
- languageCode: languageCode });case 10:syncRet = _context.sent;if (!(
10871
10865
 
10866
+ this.agilityClient.getSyncContent({
10867
+ syncToken: token,
10868
+ pageSize: 100,
10869
+ languageCode: languageCode }));case 9:syncRet = _context.sent;if (!(
10872
10870
 
10873
10871
 
10874
10872
 
10875
- syncRet === undefined || syncRet.busy !== undefined && syncRet.busy === true)) {_context.next = 20;break;}
10873
+
10874
+ syncRet === undefined || syncRet === null || syncRet.busy !== undefined && syncRet.busy === true)) {_context.next = 19;break;}
10876
10875
  //if the api is being updated, wait a few ms and try again...
10877
10876
  waitMS += waitIntervalMS;if (!(
10878
- waitMS > waitMaxMS)) {_context.next = 16;break;}
10879
- Object(util["logWarning"])("Sync API has been busy for too long, canceling.");return _context.abrupt("break", 37);case 16:
10877
+ waitMS > waitMaxMS)) {_context.next = 15;break;}
10878
+ Object(util["logWarning"])("Sync API has been busy for too long, canceling.");return _context.abrupt("break", 36);case 15:
10880
10879
 
10881
10880
 
10882
10881
 
@@ -10884,9 +10883,9 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
10884
10883
  //first time we're busy...
10885
10884
  busy = true;
10886
10885
  Object(util["logInfo"])("Sync API is busy. Waiting...");
10887
- }_context.next = 19;return (
10886
+ }_context.next = 18;return (
10888
10887
 
10889
- Object(util["sleep"])(waitIntervalMS));case 19:return _context.abrupt("continue", 36);case 20:
10888
+ Object(util["sleep"])(waitIntervalMS));case 18:return _context.abrupt("continue", 35);case 19:
10890
10889
 
10891
10890
 
10892
10891
 
@@ -10899,22 +10898,22 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
10899
10898
  syncItems = syncRet.items;
10900
10899
 
10901
10900
  //if we don't get anything back, kick out
10902
- if (!(syncItems.length > 0)) {_context.next = 30;break;}
10901
+ if (!(syncItems.length > 0)) {_context.next = 29;break;}
10903
10902
 
10904
- index = 0;case 24:if (!(index < syncItems.length)) {_context.next = 30;break;}_context.next = 27;return (
10905
- storeInterface.saveContentItem({ contentItem: syncItems[index], languageCode: languageCode }));case 27:index++;_context.next = 24;break;case 30:if (!(
10903
+ index = 0;case 23:if (!(index < syncItems.length)) {_context.next = 29;break;}_context.next = 26;return (
10904
+ storeInterface.saveContentItem({ contentItem: syncItems[index], languageCode: languageCode }));case 26:index++;_context.next = 23;break;case 29:if (!(
10906
10905
 
10907
10906
 
10908
10907
 
10909
- syncRet.syncToken > token)) {_context.next = 34;break;}
10910
- token = syncRet.syncToken;_context.next = 35;break;case 34:return _context.abrupt("break", 37);case 35:
10908
+ syncRet.syncToken > token)) {_context.next = 33;break;}
10909
+ token = syncRet.syncToken;_context.next = 34;break;case 33:return _context.abrupt("break", 36);case 34:
10911
10910
 
10912
10911
 
10913
10912
 
10914
10913
 
10915
- itemCount += syncItems.length;case 36:if (
10914
+ itemCount += syncItems.length;case 35:if (
10916
10915
 
10917
- token > 0 || busy === true) {_context.next = 7;break;}case 37:
10916
+ token > 0 || busy === true) {_context.next = 7;break;}case 36:
10918
10917
 
10919
10918
  if (itemCount > 0) {
10920
10919
  Object(util["logInfo"])("Content Sync returned ".concat(itemCount, " item(s)."));
@@ -10922,7 +10921,7 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {try
10922
10921
  Object(util["logInfo"])("Content Sync returned no item(s).");
10923
10922
  }return _context.abrupt("return",
10924
10923
 
10925
- token);case 39:case "end":return _context.stop();}}}, _callee, this);}));return syncContent_ref.apply(this, arguments);}
10924
+ token);case 38:case "end":return _context.stop();}}}, _callee, this);}));return syncContent_ref.apply(this, arguments);}
10926
10925
  // CONCATENATED MODULE: ./src/methods/clearSync.js
10927
10926
  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);});};}
10928
10927
 
@@ -10941,8 +10940,8 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
10941
10940
 
10942
10941
  busy = false;
10943
10942
  waitMS = 0;
10944
- waitMaxMS = 30000;
10945
- waitIntervalMS = 500;case 7:_context.next = 9;return (
10943
+ waitMaxMS = 10 * 60 * 1000;
10944
+ waitIntervalMS = 1000;case 7:_context.next = 9;return (
10946
10945
 
10947
10946
 
10948
10947
 
@@ -10953,8 +10952,7 @@ function syncPages_asyncGeneratorStep(gen, resolve, reject, _next, _throw, key,
10953
10952
  languageCode: languageCode }));case 9:syncRet = _context.sent;if (!(
10954
10953
 
10955
10954
 
10956
- syncRet.busy !== undefined &&
10957
- syncRet.busy === true)) {_context.next = 19;break;}
10955
+ syncRet === undefined || syncRet === null || syncRet.busy !== undefined && syncRet.busy === true)) {_context.next = 19;break;}
10958
10956
  //if the api is being updated, wait a few ms and try again...
10959
10957
  waitMS += waitIntervalMS;if (!(
10960
10958
  waitMS > waitMaxMS)) {_context.next = 15;break;}
@@ -11399,7 +11397,7 @@ var expandContentItem = /*#__PURE__*/function () {var _ref19 = store_interface_a
11399
11397
  }case 42:_context10.next = 35;break;case 44:_context10.next = 49;break;case 46:_context10.prev = 46;_context10.t2 = _context10["catch"](33);_iterator.e(_context10.t2);case 49:_context10.prev = 49;_iterator.f();return _context10.finish(49);case 52:_iterator2 = store_interface_createForOfIteratorHelper(
11400
11398
 
11401
11399
 
11402
- list);_context10.prev = 53;_iterator2.s();case 55:if ((_step2 = _iterator2.n()).done) {_context10.next = 69;break;}listItem = _step2.value;
11400
+ list.items);_context10.prev = 53;_iterator2.s();case 55:if ((_step2 = _iterator2.n()).done) {_context10.next = 69;break;}listItem = _step2.value;
11403
11401
  itemCount++;if (!(
11404
11402
  itemCount > 50)) {_context10.next = 60;break;}return _context10.abrupt("break", 69);case 60:
11405
11403
 
@@ -11463,21 +11461,27 @@ var expandContentItem = /*#__PURE__*/function () {var _ref19 = store_interface_a
11463
11461
  * @param {number} [requestParams.skip] - The number of items to skip from the list. Used for implementing pagination.
11464
11462
  * @returns {Promise<[] | Object>} - Returns a list of content items, or, if skip or take has been specified, an object with an items array and totalCount property.
11465
11463
  */
11466
- var getContentList = /*#__PURE__*/function () {var _ref21 = store_interface_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(_ref20) {var referenceName, languageCode, _ref20$depth, depth, _ref20$expandAllConte, expandAllContentLinks, _ref20$skip, skip, _ref20$take, take, lst, totalCount, i;return regeneratorRuntime.wrap(function _callee11$(_context11) {while (1) {switch (_context11.prev = _context11.next) {case 0:referenceName = _ref20.referenceName, languageCode = _ref20.languageCode, _ref20$depth = _ref20.depth, depth = _ref20$depth === void 0 ? 0 : _ref20$depth, _ref20$expandAllConte = _ref20.expandAllContentLinks, expandAllContentLinks = _ref20$expandAllConte === void 0 ? false : _ref20$expandAllConte, _ref20$skip = _ref20.skip, skip = _ref20$skip === void 0 ? -1 : _ref20$skip, _ref20$take = _ref20.take, take = _ref20$take === void 0 ? -1 : _ref20$take;_context11.next = 3;return (
11464
+ var getContentList = /*#__PURE__*/function () {var _ref21 = store_interface_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee11(_ref20) {var referenceName, languageCode, depth, contentLinkDepth, _ref20$expandAllConte, expandAllContentLinks, _ref20$skip, skip, _ref20$take, take, lst, totalCount, i;return regeneratorRuntime.wrap(function _callee11$(_context11) {while (1) {switch (_context11.prev = _context11.next) {case 0:referenceName = _ref20.referenceName, languageCode = _ref20.languageCode, depth = _ref20.depth, contentLinkDepth = _ref20.contentLinkDepth, _ref20$expandAllConte = _ref20.expandAllContentLinks, expandAllContentLinks = _ref20$expandAllConte === void 0 ? false : _ref20$expandAllConte, _ref20$skip = _ref20.skip, skip = _ref20$skip === void 0 ? -1 : _ref20$skip, _ref20$take = _ref20.take, take = _ref20$take === void 0 ? -1 : _ref20$take;
11465
+
11466
+ if (depth === undefined && contentLinkDepth !== undefined) {
11467
+ depth = contentLinkDepth;
11468
+ } else if (depth === undefined && contentLinkDepth === undefined) {
11469
+ depth = 2;
11470
+ }_context11.next = 4;return (
11467
11471
 
11468
11472
  store_interface_store.getItem({
11469
11473
  options: options,
11470
11474
  itemType: "list",
11471
11475
  languageCode: languageCode,
11472
- itemID: referenceName }));case 3:_context11.t0 = _context11.sent;if (_context11.t0) {_context11.next = 6;break;}_context11.t0 =
11473
- [];case 6:lst = _context11.t0;if (!(
11476
+ itemID: referenceName }));case 4:_context11.t0 = _context11.sent;if (_context11.t0) {_context11.next = 7;break;}_context11.t0 =
11477
+ [];case 7:lst = _context11.t0;if (!(
11474
11478
 
11475
- depth > 0 && take === -1)) {_context11.next = 9;break;}throw (
11476
- new Error("If you specify depth > 0, you must also specify the take parameter."));case 9:if (!(
11479
+ depth > 0 && take === -1)) {_context11.next = 10;break;}throw (
11480
+ new Error("If you specify depth > 0, you must also specify the take parameter."));case 10:if (!(
11477
11481
 
11478
11482
 
11479
- expandAllContentLinks && take === -1)) {_context11.next = 11;break;}throw (
11480
- new Error("If you specify expandAllContentLinks=true, you must also specify the take parameter."));case 11:
11483
+ expandAllContentLinks && take === -1)) {_context11.next = 12;break;}throw (
11484
+ new Error("If you specify expandAllContentLinks=true, you must also specify the take parameter."));case 12:
11481
11485
 
11482
11486
 
11483
11487
  totalCount = lst.length;
@@ -11490,26 +11494,26 @@ var getContentList = /*#__PURE__*/function () {var _ref21 = store_interface_asyn
11490
11494
  lst = lst.slice(0, take);
11491
11495
  }if (!(
11492
11496
 
11493
- depth > 0)) {_context11.next = 23;break;}
11494
- i = 0;case 16:if (!(i < lst.length)) {_context11.next = 23;break;}_context11.next = 19;return (
11497
+ depth > 0)) {_context11.next = 24;break;}
11498
+ i = 0;case 17:if (!(i < lst.length)) {_context11.next = 24;break;}_context11.next = 20;return (
11495
11499
  expandContentItem({
11496
11500
  contentItem: lst[i],
11497
11501
  depth: depth - 1,
11498
11502
  languageCode: languageCode,
11499
- expandAllContentLinks: expandAllContentLinks }));case 19:lst[i] = _context11.sent;case 20:i++;_context11.next = 16;break;case 23:if (!(
11503
+ expandAllContentLinks: expandAllContentLinks }));case 20:lst[i] = _context11.sent;case 21:i++;_context11.next = 17;break;case 24:if (!(
11500
11504
 
11501
11505
 
11502
11506
 
11503
11507
 
11504
- skip > 0 || take > 0)) {_context11.next = 27;break;}return _context11.abrupt("return",
11508
+ skip > 0 || take > 0)) {_context11.next = 28;break;}return _context11.abrupt("return",
11505
11509
 
11506
11510
  {
11507
11511
  items: lst,
11508
- totalCount: totalCount });case 27:return _context11.abrupt("return",
11512
+ totalCount: totalCount });case 28:return _context11.abrupt("return",
11509
11513
 
11510
11514
 
11511
11515
 
11512
- lst);case 28:case "end":return _context11.stop();}}}, _callee11);}));return function getContentList(_x11) {return _ref21.apply(this, arguments);};}();
11516
+ lst);case 29:case "end":return _context11.stop();}}}, _callee11);}));return function getContentList(_x11) {return _ref21.apply(this, arguments);};}();
11513
11517
 
11514
11518
 
11515
11519
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agility/content-sync",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "description": "JavaScript SDK for synchronizing content from Agility CMS",
5
5
  "main": "dist/agility-sync-sdk.node.js",
6
6
  "scripts": {
@@ -12,15 +12,14 @@ export default async function (languageCode, token) {
12
12
  let itemCount = 0
13
13
  let busy = false
14
14
  let waitMS = 0
15
- const waitMaxMS = 60000
15
+ const waitMaxMS = 10 * 60 * 1000
16
16
  const waitIntervalMS = 1000
17
17
 
18
18
  do {
19
- let syncRet = null
20
19
 
21
20
 
22
21
  //sync content items...
23
- syncRet = await this.agilityClient.getSyncContent({
22
+ const syncRet = await this.agilityClient.getSyncContent({
24
23
  syncToken: token,
25
24
  pageSize: 100,
26
25
  languageCode: languageCode,
@@ -28,7 +27,7 @@ export default async function (languageCode, token) {
28
27
  });
29
28
 
30
29
 
31
- if (syncRet === undefined || (syncRet.busy !== undefined && syncRet.busy === true)) {
30
+ if (syncRet === undefined || syncRet === null || (syncRet.busy !== undefined && syncRet.busy === true)) {
32
31
  //if the api is being updated, wait a few ms and try again...
33
32
  waitMS += waitIntervalMS
34
33
  if (waitMS > waitMaxMS) {
@@ -8,8 +8,8 @@ export default async function (languageCode, token) {
8
8
 
9
9
  let busy = false
10
10
  let waitMS = 0
11
- const waitMaxMS = 30000
12
- const waitIntervalMS = 500
11
+ const waitMaxMS = 10 * 60 * 1000
12
+ const waitIntervalMS = 1000
13
13
 
14
14
 
15
15
  do {
@@ -20,8 +20,7 @@ export default async function (languageCode, token) {
20
20
  languageCode: languageCode
21
21
  });
22
22
 
23
- if (syncRet.busy !== undefined
24
- && syncRet.busy === true) {
23
+ if (syncRet === undefined || syncRet === null || (syncRet.busy !== undefined && syncRet.busy === true)) {
25
24
  //if the api is being updated, wait a few ms and try again...
26
25
  waitMS += waitIntervalMS
27
26
  if (waitMS > waitMaxMS) {
@@ -300,7 +300,7 @@ const expandContentItem = async ({ contentItem, languageCode, depth, expandAllCo
300
300
  }
301
301
  }
302
302
 
303
- for (const listItem of list) {
303
+ for (const listItem of list.items) {
304
304
  itemCount++
305
305
  if (itemCount > 50) break;
306
306
 
@@ -364,7 +364,13 @@ const expandContentItem = async ({ contentItem, languageCode, depth, expandAllCo
364
364
  * @param {number} [requestParams.skip] - The number of items to skip from the list. Used for implementing pagination.
365
365
  * @returns {Promise<[] | Object>} - Returns a list of content items, or, if skip or take has been specified, an object with an items array and totalCount property.
366
366
  */
367
- const getContentList = async ({ referenceName, languageCode, depth = 0, expandAllContentLinks = false, skip = -1, take = -1 }) => {
367
+ const getContentList = async ({ referenceName, languageCode, depth, contentLinkDepth, expandAllContentLinks = false, skip = -1, take = -1 }) => {
368
+
369
+ if (depth === undefined && contentLinkDepth !== undefined) {
370
+ depth = contentLinkDepth
371
+ } else if (depth === undefined && contentLinkDepth === undefined) {
372
+ depth = 0
373
+ }
368
374
 
369
375
  let lst = await store.getItem({
370
376
  options,
@@ -42,5 +42,26 @@ describe('store.getContentList:', async function() {
42
42
  assert.strictEqual(contentList.items.length, 1, 'retrieved only the item of the content list we asked for')
43
43
 
44
44
  })
45
+
46
+
47
+ it('should be able to expand a nested list with expandAllContentLinks', async function () {
48
+ var syncClient = createSyncClient();
49
+
50
+ const contentList = await syncClient.store.getContentList({
51
+ referenceName: 'listwithnestedcontentlink',
52
+ languageCode: languageCode,
53
+ depth: 10,
54
+ take: 50,
55
+ skip: 0,
56
+ expandAllContentLinks: true
57
+ })
58
+
59
+ assert.isAtLeast(contentList.totalCount, 1, 'retrieved the totalCount of the content list we asked for')
60
+ assert.exists(contentList.items, 'retrieved the items of the content list we asked for')
61
+ assert.exists(contentList.items[0].fields, 'retrieved the item of the content list we asked for')
62
+ assert.isAtLeast(contentList.items[0].fields.posts.length, 1, 'expanded the linked cotnent of the posts field')
63
+
64
+
65
+ })
45
66
  });
46
67
 
@@ -15,7 +15,8 @@ function createSyncClient() {
15
15
  apiKey: apiKeyFetch,
16
16
  isPreview: false,
17
17
  channels: [ 'website'],
18
- languages: ['en-us']
18
+ languages: ['en-us'],
19
+ baseUrl: "https://api-dev.aglty.io"
19
20
  });
20
21
 
21
22
  return syncClient;
@@ -31,7 +32,8 @@ function createSyncClientUsingConsoleStore() {
31
32
  store: {
32
33
  interface: storeInterfaceConsole,
33
34
  options: {}
34
- }
35
+ },
36
+ baseUrl: "https://api-dev.aglty.io"
35
37
  });
36
38
  return syncClient;
37
39
  }
@@ -43,7 +45,8 @@ function createPreviewSyncClient() {
43
45
  apiKey: apiKeyPreview,
44
46
  isPreview: true,
45
47
  channels: [ 'website'],
46
- languages: ['en-us']
48
+ languages: ['en-us'],
49
+ baseUrl: "https://api-dev.aglty.io"
47
50
  });
48
51
  return syncClient;
49
52
  }