@agility/content-sync 1.1.5 → 1.1.7

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/package.json CHANGED
@@ -1,46 +1,46 @@
1
- {
2
- "name": "@agility/content-sync",
3
- "version": "1.1.5",
4
- "description": "JavaScript SDK for synchronizing content from Agility CMS",
5
- "main": "dist/agility-sync-sdk.node.js",
6
- "scripts": {
7
- "test": "nyc --reporter=html --reporter=text mocha --require @babel/register --recursive ./test/",
8
- "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
9
- "build": "webpack --config webpack.config -p"
10
- },
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/agility/agility-sync-sdk.git"
14
- },
15
- "author": "Agility CMS",
16
- "license": "MIT",
17
- "contributors": [
18
- "Joel Varty",
19
- "James Vidler",
20
- "Joshua Isaac"
21
- ],
22
- "bugs": {
23
- "url": "https://github.com/agility/agility-sync-sdk/issues"
24
- },
25
- "homepage": "https://github.com/agility/agility-sync-sdk#readme",
26
- "dependencies": {
27
- "@agility/content-fetch": "^1.0.0",
28
- "dotenv": "^8.2.0",
29
- "proper-lockfile": "^4.1.2"
30
- },
31
- "devDependencies": {
32
- "@babel/cli": "^7.2.3",
33
- "@babel/core": "^7.3.4",
34
- "@babel/node": "^7.2.2",
35
- "@babel/preset-env": "^7.3.4",
36
- "@babel/register": "^7.0.0",
37
- "agility-jsdoc-template": "1.0.3",
38
- "babel-loader": "^8.0.5",
39
- "chai": "^4.2.0",
40
- "jsdoc": "^3.5.5",
41
- "mocha": "^8.2.1",
42
- "nyc": "^15.0.0",
43
- "webpack": "^4.29.6",
44
- "webpack-cli": "^3.2.3"
45
- }
46
- }
1
+ {
2
+ "name": "@agility/content-sync",
3
+ "version": "1.1.7",
4
+ "description": "JavaScript SDK for synchronizing content from Agility CMS",
5
+ "main": "dist/agility-sync-sdk.node.js",
6
+ "scripts": {
7
+ "test": "nyc --reporter=html --reporter=text mocha --require @babel/register --recursive ./test/",
8
+ "generate-docs": "node_modules/.bin/jsdoc --configure .jsdoc.json --verbose",
9
+ "build": "webpack --config webpack.config -p"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/agility/agility-sync-sdk.git"
14
+ },
15
+ "author": "Agility CMS",
16
+ "license": "MIT",
17
+ "contributors": [
18
+ "Joel Varty",
19
+ "James Vidler",
20
+ "Joshua Isaac"
21
+ ],
22
+ "bugs": {
23
+ "url": "https://github.com/agility/agility-sync-sdk/issues"
24
+ },
25
+ "homepage": "https://github.com/agility/agility-sync-sdk#readme",
26
+ "dependencies": {
27
+ "@agility/content-fetch": "^1.0.0",
28
+ "dotenv": "^8.2.0",
29
+ "proper-lockfile": "^4.1.2"
30
+ },
31
+ "devDependencies": {
32
+ "@babel/cli": "^7.2.3",
33
+ "@babel/core": "^7.3.4",
34
+ "@babel/node": "^7.2.2",
35
+ "@babel/preset-env": "^7.3.4",
36
+ "@babel/register": "^7.0.0",
37
+ "agility-jsdoc-template": "1.0.3",
38
+ "babel-loader": "^8.0.5",
39
+ "chai": "^4.2.0",
40
+ "jsdoc": "^3.5.5",
41
+ "mocha": "^8.2.1",
42
+ "nyc": "^15.0.0",
43
+ "webpack": "^4.29.6",
44
+ "webpack-cli": "^3.2.3"
45
+ }
46
+ }
@@ -1,7 +1,7 @@
1
- import { logSuccess } from '../util'
2
-
3
- export default async function () {
4
- const storeInterface = this.store;
5
- await storeInterface.clear();
6
- logSuccess(`Cleared Sync Items`);
7
- }
1
+ import { logSuccess } from '../util'
2
+
3
+ export default async function () {
4
+ const storeInterface = this.store;
5
+ await storeInterface.clear();
6
+ logSuccess(`Cleared Sync Items`);
7
+ }
@@ -1,95 +1,95 @@
1
- import { logInfo, logSuccess } from '../util'
2
-
3
-
4
- const syncRunner = async function () {
5
-
6
- const storeInterface = this.store.getStore();
7
-
8
- //if a mutex has been defined, call the wait lock
9
- let lockRelease = null
10
- if (storeInterface.mutexLock !== undefined) {
11
- lockRelease = await storeInterface.mutexLock()
12
- }
13
-
14
- try {
15
-
16
- //check to see
17
-
18
-
19
- //actually do the sync
20
- await sync(this)
21
-
22
- } finally {
23
- if (lockRelease) {
24
- lockRelease()
25
- }
26
- }
27
-
28
- }
29
-
30
-
31
- const sync = async (clientObj) => {
32
-
33
- const languageCodes = clientObj.config.languages;
34
- const channels = clientObj.config.channels;
35
- const storeInterface = clientObj.store;
36
-
37
- const modeStr = clientObj.config.isPreview ? "preview" : "live"
38
-
39
- for (const languageCode of languageCodes) {
40
-
41
-
42
- let syncState = await storeInterface.getSyncState(languageCode);
43
-
44
- if (!syncState) syncState = { itemToken: 0, pageToken: 0 };
45
-
46
- const lastSyncDate = syncState.lastSyncDate || null
47
- //run at MOST once a second
48
- if (lastSyncDate && (new Date()) - new Date(lastSyncDate) < 1000) {
49
- //skip sync...
50
- continue;
51
- }
52
-
53
- logSuccess(`Starting Sync for ${languageCode} - ${modeStr} mode.`);
54
- const newItemToken = await clientObj.syncContent(languageCode, syncState.itemToken);
55
- const newPageToken = await clientObj.syncPages(languageCode, syncState.pageToken);
56
-
57
- if (newItemToken != syncState.itemToken
58
- || newPageToken != syncState.pageToken) {
59
- //if we sync ANYTHING - pull the new sitemap down
60
-
61
- for (const channelName of channels) {
62
- logInfo(`Updating Sitemap channel ${channelName} in ${languageCode}`);
63
-
64
- const sitemap = await clientObj.agilityClient.getSitemapFlat({ channelName, languageCode });
65
- storeInterface.saveSitemap({ sitemap, languageCode, channelName });
66
-
67
- const sitemapNested = await clientObj.agilityClient.getSitemapNested({ channelName, languageCode });
68
- storeInterface.saveSitemapNested({ sitemapNested, languageCode, channelName });
69
-
70
- }
71
- }
72
-
73
- //save the redirects if they have changed...
74
- let urlRedirections = await storeInterface.getUrlRedirections({ languageCode });
75
- let lastAccessDate = null;
76
- if (urlRedirections) lastAccessDate = urlRedirections.lastAccessDate;
77
-
78
- urlRedirections = await clientObj.agilityClient.getUrlRedirections({ lastAccessDate });
79
- if (urlRedirections && urlRedirections.isUpToDate === false) {
80
- logInfo(`URL Redirections Updated and Saved`);
81
- await storeInterface.saveUrlRedirections({ urlRedirections, languageCode });
82
- }
83
-
84
- syncState.itemToken = newItemToken;
85
- syncState.pageToken = newPageToken;
86
- syncState.lastSyncDate = new Date();
87
-
88
- await storeInterface.saveSyncState({ syncState, languageCode });
89
-
90
- logSuccess(`Completed Sync for ${languageCode} - ${modeStr} mode.`);
91
- }
92
- }
93
-
94
-
1
+ import { logInfo, logSuccess } from '../util'
2
+
3
+
4
+ const syncRunner = async function () {
5
+
6
+ const storeInterface = this.store.getStore();
7
+
8
+ //if a mutex has been defined, call the wait lock
9
+ let lockRelease = null
10
+ if (storeInterface.mutexLock !== undefined) {
11
+ lockRelease = await storeInterface.mutexLock()
12
+ }
13
+
14
+ try {
15
+
16
+ //check to see
17
+
18
+
19
+ //actually do the sync
20
+ await sync(this)
21
+
22
+ } finally {
23
+ if (lockRelease) {
24
+ lockRelease()
25
+ }
26
+ }
27
+
28
+ }
29
+
30
+
31
+ const sync = async (clientObj) => {
32
+
33
+ const languageCodes = clientObj.config.languages;
34
+ const channels = clientObj.config.channels;
35
+ const storeInterface = clientObj.store;
36
+
37
+ const modeStr = clientObj.config.isPreview ? "preview" : "live"
38
+
39
+ for (const languageCode of languageCodes) {
40
+
41
+
42
+ let syncState = await storeInterface.getSyncState(languageCode);
43
+
44
+ if (!syncState) syncState = { itemToken: 0, pageToken: 0 };
45
+
46
+ const lastSyncDate = syncState.lastSyncDate || null
47
+ //run at MOST once a second
48
+ if (lastSyncDate && (new Date()) - new Date(lastSyncDate) < 1000) {
49
+ //skip sync...
50
+ continue;
51
+ }
52
+
53
+ logSuccess(`Starting Sync for ${languageCode} - ${modeStr} mode.`);
54
+ const newItemToken = await clientObj.syncContent(languageCode, syncState.itemToken);
55
+ const newPageToken = await clientObj.syncPages(languageCode, syncState.pageToken);
56
+
57
+ if (newItemToken != syncState.itemToken
58
+ || newPageToken != syncState.pageToken) {
59
+ //if we sync ANYTHING - pull the new sitemap down
60
+
61
+ for (const channelName of channels) {
62
+ logInfo(`Updating Sitemap channel ${channelName} in ${languageCode}`);
63
+
64
+ const sitemap = await clientObj.agilityClient.getSitemapFlat({ channelName, languageCode });
65
+ storeInterface.saveSitemap({ sitemap, languageCode, channelName });
66
+
67
+ const sitemapNested = await clientObj.agilityClient.getSitemapNested({ channelName, languageCode });
68
+ storeInterface.saveSitemapNested({ sitemapNested, languageCode, channelName });
69
+
70
+ }
71
+ }
72
+
73
+ //save the redirects if they have changed...
74
+ let urlRedirections = await storeInterface.getUrlRedirections({ languageCode });
75
+ let lastAccessDate = null;
76
+ if (urlRedirections) lastAccessDate = urlRedirections.lastAccessDate;
77
+
78
+ urlRedirections = await clientObj.agilityClient.getUrlRedirections({ lastAccessDate });
79
+ if (urlRedirections && urlRedirections.isUpToDate === false) {
80
+ logInfo(`URL Redirections Updated and Saved`);
81
+ await storeInterface.saveUrlRedirections({ urlRedirections, languageCode });
82
+ }
83
+
84
+ syncState.itemToken = newItemToken;
85
+ syncState.pageToken = newPageToken;
86
+ syncState.lastSyncDate = new Date();
87
+
88
+ await storeInterface.saveSyncState({ syncState, languageCode });
89
+
90
+ logSuccess(`Completed Sync for ${languageCode} - ${modeStr} mode.`);
91
+ }
92
+ }
93
+
94
+
95
95
  export default syncRunner
@@ -1,81 +1,81 @@
1
- import { logInfo, logWarning, sleep } from '../util'
2
-
3
-
4
- /**
5
- * Sync the content items in the specified Agility Instance.
6
- */
7
- export default async function (languageCode, token) {
8
- const storeInterface = this.store;
9
-
10
- if (!token) token = 0;
11
-
12
- let itemCount = 0
13
- let busy = false
14
- let waitMS = 0
15
- const waitMaxMS = 10 * 60 * 1000
16
- const waitIntervalMS = 1000
17
-
18
- do {
19
-
20
-
21
- //sync content items...
22
- const syncRet = await this.agilityClient.getSyncContent({
23
- syncToken: token,
24
- pageSize: 100,
25
- languageCode: languageCode,
26
-
27
- });
28
-
29
-
30
- if (syncRet === undefined || syncRet === null || (syncRet.busy !== undefined && syncRet.busy === true)) {
31
- //if the api is being updated, wait a few ms and try again...
32
- waitMS += waitIntervalMS
33
- if (waitMS > waitMaxMS) {
34
- logWarning("Sync API has been busy for too long, canceling.")
35
- break
36
- }
37
-
38
- if (! busy) {
39
- //first time we're busy...
40
- busy = true
41
- logInfo("Sync API is busy. Waiting...")
42
- }
43
-
44
- await sleep(waitIntervalMS)
45
- continue
46
- }
47
-
48
- if (busy === true) {
49
- logInfo("Continuing sync...")
50
- busy = false
51
- waitMS = 0
52
- }
53
-
54
- const syncItems = syncRet.items;
55
-
56
- //if we don't get anything back, kick out
57
- if (syncItems.length > 0 ) {
58
-
59
- for (let index = 0; index < syncItems.length; index++) {
60
- await storeInterface.saveContentItem({ contentItem: syncItems[index], languageCode });
61
- }
62
- }
63
-
64
- if (syncRet.syncToken > token) {
65
- token = syncRet.syncToken;
66
- } else {
67
- break;
68
- }
69
-
70
- itemCount += syncItems.length;
71
-
72
- } while (token > 0 || busy === true)
73
-
74
- if (itemCount > 0) {
75
- logInfo(`Content Sync returned ${itemCount} item(s).`);
76
- } else {
77
- logInfo(`Content Sync returned no item(s).`);
78
- }
79
-
80
- return token;
1
+ import { logInfo, logWarning, sleep } from '../util'
2
+
3
+
4
+ /**
5
+ * Sync the content items in the specified Agility Instance.
6
+ */
7
+ export default async function (languageCode, token) {
8
+ const storeInterface = this.store;
9
+
10
+ if (!token) token = 0;
11
+
12
+ let itemCount = 0
13
+ let busy = false
14
+ let waitMS = 0
15
+ const waitMaxMS = 10 * 60 * 1000
16
+ const waitIntervalMS = 1000
17
+
18
+ do {
19
+
20
+
21
+ //sync content items...
22
+ const syncRet = await this.agilityClient.getSyncContent({
23
+ syncToken: token,
24
+ pageSize: 100,
25
+ languageCode: languageCode,
26
+
27
+ });
28
+
29
+
30
+ if (syncRet === undefined || syncRet === null || (syncRet.busy !== undefined && syncRet.busy === true)) {
31
+ //if the api is being updated, wait a few ms and try again...
32
+ waitMS += waitIntervalMS
33
+ if (waitMS > waitMaxMS) {
34
+ logWarning("Sync API has been busy for too long, canceling.")
35
+ break
36
+ }
37
+
38
+ if (! busy) {
39
+ //first time we're busy...
40
+ busy = true
41
+ logInfo("Sync API is busy. Waiting...")
42
+ }
43
+
44
+ await sleep(waitIntervalMS)
45
+ continue
46
+ }
47
+
48
+ if (busy === true) {
49
+ logInfo("Continuing sync...")
50
+ busy = false
51
+ waitMS = 0
52
+ }
53
+
54
+ const syncItems = syncRet.items;
55
+
56
+ //if we don't get anything back, kick out
57
+ if (syncItems.length > 0 ) {
58
+
59
+ for (let index = 0; index < syncItems.length; index++) {
60
+ await storeInterface.saveContentItem({ contentItem: syncItems[index], languageCode });
61
+ }
62
+ }
63
+
64
+ if (syncRet.syncToken > token) {
65
+ token = syncRet.syncToken;
66
+ } else {
67
+ break;
68
+ }
69
+
70
+ itemCount += syncItems.length;
71
+
72
+ } while (token > 0 || busy === true)
73
+
74
+ if (itemCount > 0) {
75
+ logInfo(`Content Sync returned ${itemCount} item(s).`);
76
+ } else {
77
+ logInfo(`Content Sync returned no item(s).`);
78
+ }
79
+
80
+ return token;
81
81
  }
@@ -1,76 +1,76 @@
1
- import { logInfo, logWarning, sleep } from '../util'
2
-
3
- export default async function (languageCode, token) {
4
- const storeInterface = this.store;
5
- if (!token) token = 0;
6
-
7
- let itemCount = 0;
8
-
9
- let busy = false
10
- let waitMS = 0
11
- const waitMaxMS = 10 * 60 * 1000
12
- const waitIntervalMS = 1000
13
-
14
-
15
- do {
16
- //sync pages...
17
- const syncRet = await this.agilityClient.getSyncPages({
18
- syncToken: token,
19
- pageSize: 100,
20
- languageCode: languageCode
21
- });
22
-
23
- if (syncRet === undefined || syncRet === null || (syncRet.busy !== undefined && syncRet.busy === true)) {
24
- //if the api is being updated, wait a few ms and try again...
25
- waitMS += waitIntervalMS
26
- if (waitMS > waitMaxMS) {
27
- logWarning("Sync API has been busy for too long, canceling.")
28
- break
29
- }
30
-
31
- if (!busy) {
32
- busy = true
33
- logInfo("Sync API is busy. Waiting...")
34
- }
35
-
36
- await sleep(waitIntervalMS)
37
- continue
38
- }
39
-
40
- if (busy === true) {
41
- logInfo("Continuing sync...")
42
- waitMS = 0
43
- busy = false
44
- }
45
-
46
- const syncItems = syncRet.items;
47
-
48
- //if we have something...
49
- if (syncItems.length > 0) {
50
-
51
-
52
- for (let index = 0; index < syncItems.length; index++) {
53
- await storeInterface.savePageItem({ pageItem: syncItems[index], languageCode });
54
- }
55
- }
56
-
57
- if (syncRet.syncToken > token) {
58
- token = syncRet.syncToken;
59
- } else {
60
- break;
61
- }
62
-
63
- itemCount += syncItems.length;
64
-
65
-
66
- } while (token > 0 || busy === true)
67
-
68
- if (itemCount > 0) {
69
- logInfo(`Page Sync returned ${itemCount} item(s).`);
70
- } else {
71
- logInfo(`Page Sync returned no item(s).`);
72
- }
73
-
74
-
75
- return token;
1
+ import { logInfo, logWarning, sleep } from '../util'
2
+
3
+ export default async function (languageCode, token) {
4
+ const storeInterface = this.store;
5
+ if (!token) token = 0;
6
+
7
+ let itemCount = 0;
8
+
9
+ let busy = false
10
+ let waitMS = 0
11
+ const waitMaxMS = 10 * 60 * 1000
12
+ const waitIntervalMS = 1000
13
+
14
+
15
+ do {
16
+ //sync pages...
17
+ const syncRet = await this.agilityClient.getSyncPages({
18
+ syncToken: token,
19
+ pageSize: 100,
20
+ languageCode: languageCode
21
+ });
22
+
23
+ if (syncRet === undefined || syncRet === null || (syncRet.busy !== undefined && syncRet.busy === true)) {
24
+ //if the api is being updated, wait a few ms and try again...
25
+ waitMS += waitIntervalMS
26
+ if (waitMS > waitMaxMS) {
27
+ logWarning("Sync API has been busy for too long, canceling.")
28
+ break
29
+ }
30
+
31
+ if (!busy) {
32
+ busy = true
33
+ logInfo("Sync API is busy. Waiting...")
34
+ }
35
+
36
+ await sleep(waitIntervalMS)
37
+ continue
38
+ }
39
+
40
+ if (busy === true) {
41
+ logInfo("Continuing sync...")
42
+ waitMS = 0
43
+ busy = false
44
+ }
45
+
46
+ const syncItems = syncRet.items;
47
+
48
+ //if we have something...
49
+ if (syncItems.length > 0) {
50
+
51
+
52
+ for (let index = 0; index < syncItems.length; index++) {
53
+ await storeInterface.savePageItem({ pageItem: syncItems[index], languageCode });
54
+ }
55
+ }
56
+
57
+ if (syncRet.syncToken > token) {
58
+ token = syncRet.syncToken;
59
+ } else {
60
+ break;
61
+ }
62
+
63
+ itemCount += syncItems.length;
64
+
65
+
66
+ } while (token > 0 || busy === true)
67
+
68
+ if (itemCount > 0) {
69
+ logInfo(`Page Sync returned ${itemCount} item(s).`);
70
+ } else {
71
+ logInfo(`Page Sync returned no item(s).`);
72
+ }
73
+
74
+
75
+ return token;
76
76
  }