@agility/content-sync 1.0.4 → 1.1.2
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/dist/agility-sync-sdk.node.js +1729 -2007
- package/package.json +1 -1
- package/src/methods/syncContent.js +5 -4
- package/src/methods/syncPages.js +3 -4
- package/src/store-interface.js +88 -14
- package/src/sync-client.js +4 -4
- package/test/04-store.getContentList.tests.js +21 -0
- package/test/_syncClients.config.js +6 -3
- package/package-lock.json +0 -6856
package/package.json
CHANGED
|
@@ -12,11 +12,12 @@ export default async function (languageCode, token) {
|
|
|
12
12
|
let itemCount = 0
|
|
13
13
|
let busy = false
|
|
14
14
|
let waitMS = 0
|
|
15
|
-
const waitMaxMS =
|
|
16
|
-
const waitIntervalMS =
|
|
15
|
+
const waitMaxMS = 60000
|
|
16
|
+
const waitIntervalMS = 1000
|
|
17
17
|
|
|
18
18
|
do {
|
|
19
19
|
|
|
20
|
+
|
|
20
21
|
//sync content items...
|
|
21
22
|
const syncRet = await this.agilityClient.getSyncContent({
|
|
22
23
|
syncToken: token,
|
|
@@ -25,8 +26,8 @@ export default async function (languageCode, token) {
|
|
|
25
26
|
|
|
26
27
|
});
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
|
|
30
|
+
if (syncRet === undefined || syncRet === null || (syncRet.busy !== undefined && syncRet.busy === true)) {
|
|
30
31
|
//if the api is being updated, wait a few ms and try again...
|
|
31
32
|
waitMS += waitIntervalMS
|
|
32
33
|
if (waitMS > waitMaxMS) {
|
package/src/methods/syncPages.js
CHANGED
|
@@ -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 =
|
|
12
|
-
const waitIntervalMS =
|
|
11
|
+
const waitMaxMS = 60000
|
|
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) {
|
package/src/store-interface.js
CHANGED
|
@@ -220,7 +220,14 @@ const getSyncState = async (languageCode) => {
|
|
|
220
220
|
* @param {boolean} [requestParams.expandAllContentLinks] - Whether or not to expand entire linked content references, includings lists and items that are rendered in the CMS as Grid or Link. Default is **false**
|
|
221
221
|
* @returns {Promise<Object>} - Returns a content item object.
|
|
222
222
|
*/
|
|
223
|
-
const getContentItem = async ({ contentID, languageCode, depth
|
|
223
|
+
const getContentItem = async ({ contentID, languageCode, depth, contentLinkDepth, expandAllContentLinks = false }) => {
|
|
224
|
+
|
|
225
|
+
if (depth === undefined && contentLinkDepth !== undefined) {
|
|
226
|
+
depth = contentLinkDepth
|
|
227
|
+
} else if (depth === undefined && contentLinkDepth === undefined) {
|
|
228
|
+
depth = 2
|
|
229
|
+
}
|
|
230
|
+
|
|
224
231
|
const contentItem = await store.getItem({
|
|
225
232
|
options,
|
|
226
233
|
itemType: "item",
|
|
@@ -250,33 +257,92 @@ const expandContentItem = async ({ contentItem, languageCode, depth, expandAllCo
|
|
|
250
257
|
depth: depth - 1,
|
|
251
258
|
});
|
|
252
259
|
if (childItem != null) fields[fieldName] = childItem;
|
|
253
|
-
} else if (fieldValue.
|
|
254
|
-
|
|
255
|
-
|
|
260
|
+
} else if (fieldValue.fulllist === true
|
|
261
|
+
&& fieldValue.referencename
|
|
262
|
+
&& expandAllContentLinks === true) {
|
|
263
|
+
|
|
264
|
+
//LINK TO THE FULL LIST
|
|
265
|
+
const referenceName = fieldValue.referencename
|
|
266
|
+
|
|
267
|
+
const skip = 0
|
|
268
|
+
const take = 50
|
|
269
|
+
|
|
270
|
+
const list = await getContentList({
|
|
271
|
+
referenceName,
|
|
272
|
+
languageCode,
|
|
273
|
+
depth: depth - 1,
|
|
274
|
+
expandAllContentLinks,
|
|
275
|
+
skip,
|
|
276
|
+
take
|
|
277
|
+
})
|
|
278
|
+
|
|
279
|
+
let sortIDAry = []
|
|
280
|
+
|
|
281
|
+
if (fieldValue.sortids && fieldValue.sortids.split) {
|
|
282
|
+
sortIDAry = fieldValue.sortids.split(",");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
let itemCount = 0
|
|
256
286
|
const childItems = [];
|
|
257
287
|
for (const childItemID of sortIDAry) {
|
|
288
|
+
itemCount++
|
|
258
289
|
const childItem = await getContentItem({
|
|
259
290
|
contentID: childItemID,
|
|
260
291
|
languageCode,
|
|
261
292
|
depth: depth - 1,
|
|
293
|
+
expandAllContentLinks,
|
|
294
|
+
skip,
|
|
295
|
+
take
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
if (childItem != null) {
|
|
299
|
+
childItems.push(childItem);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
for (const listItem of list.items) {
|
|
304
|
+
itemCount++
|
|
305
|
+
if (itemCount > 50) break;
|
|
306
|
+
|
|
307
|
+
const listItemContentID = listItem.contentID
|
|
308
|
+
if (sortIDAry.includes(`${listItemContentID}`)) {
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const childItem = await getContentItem({
|
|
313
|
+
contentID: listItemContentID,
|
|
314
|
+
languageCode,
|
|
315
|
+
depth: depth - 1,
|
|
262
316
|
expandAllContentLinks
|
|
263
317
|
});
|
|
264
318
|
if (childItem != null) childItems.push(childItem);
|
|
265
319
|
}
|
|
320
|
+
|
|
266
321
|
fields[fieldName] = childItems;
|
|
267
|
-
} else if (fieldValue.referencename
|
|
268
|
-
&& expandAllContentLinks === true) {
|
|
269
|
-
//if we are expanding ALL content links...
|
|
270
322
|
|
|
271
|
-
|
|
272
|
-
|
|
323
|
+
} else if (fieldValue.sortids && fieldValue.sortids.split && fieldValue.fulllist !== true) {
|
|
324
|
+
//MULTI LINKED ITEM
|
|
325
|
+
let sortIDAry = []
|
|
326
|
+
if (fieldValue.sortids && fieldValue.sortids.split) {
|
|
327
|
+
sortIDAry = fieldValue.sortids.split(",");
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const skip = expandAllContentLinks ? 0 : undefined
|
|
331
|
+
const take = expandAllContentLinks ? 50 : undefined
|
|
332
|
+
|
|
333
|
+
const childItems = [];
|
|
334
|
+
for (const childItemID of sortIDAry) {
|
|
335
|
+
const childItem = await getContentItem({
|
|
336
|
+
contentID: childItemID,
|
|
273
337
|
languageCode,
|
|
274
338
|
depth: depth - 1,
|
|
275
339
|
expandAllContentLinks,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
340
|
+
skip,
|
|
341
|
+
take
|
|
342
|
+
});
|
|
343
|
+
if (childItem != null) childItems.push(childItem);
|
|
344
|
+
}
|
|
345
|
+
fields[fieldName] = childItems;
|
|
280
346
|
|
|
281
347
|
}
|
|
282
348
|
}
|
|
@@ -357,7 +423,14 @@ const getContentList = async ({ referenceName, languageCode, depth = 0, expandAl
|
|
|
357
423
|
* @param {*} { pageID, languageCode, depth = 3 }
|
|
358
424
|
* @returns
|
|
359
425
|
*/
|
|
360
|
-
const getPage = async ({ pageID, languageCode, depth =
|
|
426
|
+
const getPage = async ({ pageID, languageCode, depth, contentLinkDepth, expandAllContentLinks = false }) => {
|
|
427
|
+
|
|
428
|
+
if (depth === undefined && contentLinkDepth !== undefined) {
|
|
429
|
+
depth = contentLinkDepth
|
|
430
|
+
} else if (depth === undefined && contentLinkDepth === undefined) {
|
|
431
|
+
depth = 2
|
|
432
|
+
}
|
|
433
|
+
|
|
361
434
|
let pageItem = await store.getItem({
|
|
362
435
|
options,
|
|
363
436
|
itemType: "page",
|
|
@@ -376,6 +449,7 @@ const getPage = async ({ pageID, languageCode, depth = 3 }) => {
|
|
|
376
449
|
contentID: mod.item.contentid,
|
|
377
450
|
languageCode,
|
|
378
451
|
depth: depth - 1,
|
|
452
|
+
expandAllContentLinks
|
|
379
453
|
});
|
|
380
454
|
mod.item = moduleItem;
|
|
381
455
|
}
|
package/src/sync-client.js
CHANGED
|
@@ -9,7 +9,7 @@ import storeInterfaceFileSystem from './store-interface-filesystem'
|
|
|
9
9
|
|
|
10
10
|
function getSyncClient (userConfig) {
|
|
11
11
|
validateConfigParams(userConfig);
|
|
12
|
-
return
|
|
12
|
+
return createSyncClient(userConfig);
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
function validateConfigParams(configParams) {
|
|
@@ -39,11 +39,11 @@ const defaultConfig = {
|
|
|
39
39
|
}
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
function
|
|
42
|
+
function createSyncClient(userConfig) {
|
|
43
43
|
let config = {
|
|
44
44
|
...defaultConfig,
|
|
45
45
|
...userConfig
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const agilityClient = agility.getApi({
|
|
@@ -60,7 +60,7 @@ function createSyncCient(userConfig) {
|
|
|
60
60
|
|
|
61
61
|
//set the sync storage interface provider, it will also validate it
|
|
62
62
|
storeInterface.setStore(store, config.store.options);
|
|
63
|
-
|
|
63
|
+
|
|
64
64
|
return {
|
|
65
65
|
config,
|
|
66
66
|
agilityClient,
|
|
@@ -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
|
-
|
|
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
|
}
|