@contentstack/datasync-manager 2.0.9 → 2.1.0
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/config.js +5 -0
- package/dist/core/index.js +64 -5
- package/dist/core/plugins.js +43 -37
- package/dist/util/fs.js +5 -15
- package/dist/util/index.js +6 -4
- package/package.json +2 -2
package/dist/config.js
CHANGED
|
@@ -129,4 +129,9 @@ exports.config = {
|
|
|
129
129
|
saveFailedItems: true,
|
|
130
130
|
saveFilteredItems: true,
|
|
131
131
|
},
|
|
132
|
+
checkpoint: {
|
|
133
|
+
enabled: false,
|
|
134
|
+
filePath: ".checkpoint",
|
|
135
|
+
preserve: false // Set to true if you want to preserve the checkpoint file during clean operation
|
|
136
|
+
},
|
|
132
137
|
};
|
package/dist/core/index.js
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
7
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
8
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
9
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -18,6 +36,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
36
|
};
|
|
19
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
38
|
exports.unlock = exports.lock = exports.poke = exports.pop = exports.unshift = exports.push = exports.init = void 0;
|
|
39
|
+
/*!
|
|
40
|
+
* Contentstack DataSync Manager
|
|
41
|
+
* Copyright (c) 2019 Contentstack LLC
|
|
42
|
+
* MIT Licensed
|
|
43
|
+
*/
|
|
44
|
+
const fs = __importStar(require("fs"));
|
|
45
|
+
const path = __importStar(require("path"));
|
|
21
46
|
const debug_1 = __importDefault(require("debug"));
|
|
22
47
|
const events_1 = require("events");
|
|
23
48
|
const lodash_1 = require("lodash");
|
|
@@ -30,6 +55,7 @@ const promise_map_1 = require("../util/promise.map");
|
|
|
30
55
|
const inet_1 = require("./inet");
|
|
31
56
|
const q_1 = require("./q");
|
|
32
57
|
const token_management_1 = require("./token-management");
|
|
58
|
+
const helper_1 = require("../plugins/helper");
|
|
33
59
|
const debug = (0, debug_1.default)('sync-core');
|
|
34
60
|
const emitter = new events_1.EventEmitter();
|
|
35
61
|
const formattedAssetType = '_assets';
|
|
@@ -55,6 +81,7 @@ const init = (contentStore, assetStore) => {
|
|
|
55
81
|
return new Promise((resolve, reject) => {
|
|
56
82
|
try {
|
|
57
83
|
Contentstack = config.contentstack;
|
|
84
|
+
const checkPointConfig = config.checkpoint;
|
|
58
85
|
const paths = config.paths;
|
|
59
86
|
const environment = Contentstack.environment || process.env.NODE_ENV || 'development';
|
|
60
87
|
debug(`Environment: ${environment}`);
|
|
@@ -64,6 +91,7 @@ const init = (contentStore, assetStore) => {
|
|
|
64
91
|
limit: config.syncManager.limit,
|
|
65
92
|
},
|
|
66
93
|
};
|
|
94
|
+
loadCheckpoint(checkPointConfig, paths);
|
|
67
95
|
if (typeof Contentstack.sync_token === 'string' && Contentstack.sync_token.length !== 0) {
|
|
68
96
|
request.qs.sync_token = Contentstack.sync_token;
|
|
69
97
|
}
|
|
@@ -94,6 +122,37 @@ const init = (contentStore, assetStore) => {
|
|
|
94
122
|
});
|
|
95
123
|
};
|
|
96
124
|
exports.init = init;
|
|
125
|
+
const loadCheckpoint = (checkPointConfig, paths) => {
|
|
126
|
+
if (!(checkPointConfig === null || checkPointConfig === void 0 ? void 0 : checkPointConfig.enabled))
|
|
127
|
+
return;
|
|
128
|
+
// Try reading checkpoint from primary path
|
|
129
|
+
let checkpoint = readHiddenFile(paths.checkpoint);
|
|
130
|
+
// Fallback to filePath in config if not found
|
|
131
|
+
if (!checkpoint) {
|
|
132
|
+
const fallbackPath = path.join((0, helper_1.sanitizePath)(__dirname), (0, helper_1.sanitizePath)(checkPointConfig.filePath || ".checkpoint"));
|
|
133
|
+
checkpoint = readHiddenFile(fallbackPath);
|
|
134
|
+
}
|
|
135
|
+
// Set sync token if checkpoint is found
|
|
136
|
+
if (checkpoint) {
|
|
137
|
+
debug("Found sync token in checkpoint file:", checkpoint);
|
|
138
|
+
Contentstack.sync_token = checkpoint.token;
|
|
139
|
+
debug("Using sync token:", Contentstack.sync_token);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
function readHiddenFile(filePath) {
|
|
143
|
+
try {
|
|
144
|
+
if (!fs.existsSync(filePath)) {
|
|
145
|
+
logger_1.logger.error("File does not exist:", filePath);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const data = fs.readFileSync(filePath, "utf8");
|
|
149
|
+
return JSON.parse(data);
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
logger_1.logger.error("Error reading file:", err);
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
97
156
|
const push = (data) => {
|
|
98
157
|
Q.emit('push', data);
|
|
99
158
|
};
|
package/dist/core/plugins.js
CHANGED
|
@@ -22,47 +22,53 @@ const pluginMethods = ['beforeSync', 'afterSync'];
|
|
|
22
22
|
*/
|
|
23
23
|
const load = (config) => {
|
|
24
24
|
debug('Plugins load called');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
pluginInstances.external[pluginMethod] = pluginInstances[pluginMethod] || [];
|
|
32
|
-
pluginInstances.internal[pluginMethod] = pluginInstances[pluginMethod] || [];
|
|
33
|
-
});
|
|
34
|
-
plugins.forEach((plugin) => {
|
|
35
|
-
(0, validations_1.validatePlugin)(plugin);
|
|
36
|
-
const pluginName = plugin.name;
|
|
37
|
-
const slicedName = pluginName.slice(0, 13);
|
|
38
|
-
let isInternal = false;
|
|
39
|
-
if (slicedName === '_cs_internal_') {
|
|
40
|
-
isInternal = true;
|
|
41
|
-
}
|
|
42
|
-
const pluginPath = (0, index_1.normalizePluginPath)(config, plugin, isInternal);
|
|
43
|
-
const Plugin = require(pluginPath);
|
|
44
|
-
Plugin.options = plugin.options || {};
|
|
45
|
-
// execute/initiate plugin
|
|
46
|
-
Plugin();
|
|
25
|
+
try {
|
|
26
|
+
const pluginInstances = {
|
|
27
|
+
external: {},
|
|
28
|
+
internal: {},
|
|
29
|
+
};
|
|
30
|
+
const plugins = config.plugins || [];
|
|
47
31
|
pluginMethods.forEach((pluginMethod) => {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
32
|
+
pluginInstances.external[pluginMethod] = pluginInstances[pluginMethod] || [];
|
|
33
|
+
pluginInstances.internal[pluginMethod] = pluginInstances[pluginMethod] || [];
|
|
34
|
+
});
|
|
35
|
+
plugins.forEach((plugin) => {
|
|
36
|
+
(0, validations_1.validatePlugin)(plugin);
|
|
37
|
+
const pluginName = plugin.name;
|
|
38
|
+
const slicedName = pluginName.slice(0, 13);
|
|
39
|
+
let isInternal = false;
|
|
40
|
+
if (slicedName === '_cs_internal_') {
|
|
41
|
+
isInternal = true;
|
|
42
|
+
}
|
|
43
|
+
const pluginPath = (0, index_1.normalizePluginPath)(config, plugin, isInternal);
|
|
44
|
+
const Plugin = require(pluginPath);
|
|
45
|
+
Plugin.options = plugin.options || {};
|
|
46
|
+
// execute/initiate plugin
|
|
47
|
+
Plugin();
|
|
48
|
+
pluginMethods.forEach((pluginMethod) => {
|
|
49
|
+
if ((0, lodash_1.hasIn)(Plugin, pluginMethod)) {
|
|
50
|
+
if (plugin.disabled) {
|
|
51
|
+
// do nothing
|
|
52
|
+
}
|
|
53
|
+
else if (isInternal) {
|
|
54
|
+
pluginInstances.internal[pluginMethod].push(Plugin[pluginMethod]);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
pluginInstances.external[pluginMethod].push(Plugin[pluginMethod]);
|
|
58
|
+
}
|
|
59
|
+
debug(`${pluginMethod} loaded from ${pluginName} successfully!`);
|
|
54
60
|
}
|
|
55
61
|
else {
|
|
56
|
-
|
|
62
|
+
debug(`${pluginMethod} not found in ${pluginName}`);
|
|
57
63
|
}
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
debug(`${pluginMethod} not found in ${pluginName}`);
|
|
62
|
-
}
|
|
64
|
+
});
|
|
63
65
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
debug('Plugins loaded successfully!');
|
|
67
|
+
return pluginInstances;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
debug('Error while loading plugins:', error);
|
|
71
|
+
throw new Error(`Failed to load plugins: ${error === null || error === void 0 ? void 0 : error.message}`);
|
|
72
|
+
}
|
|
67
73
|
};
|
|
68
74
|
exports.load = load;
|
package/dist/util/fs.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.mkdirpSync = exports.stat = exports.mkdir = exports.readFileSync = expor
|
|
|
13
13
|
const Debug = require("debug");
|
|
14
14
|
const fs_1 = require("fs");
|
|
15
15
|
Object.defineProperty(exports, "existsSync", { enumerable: true, get: function () { return fs_1.existsSync; } });
|
|
16
|
-
const mkdirp_1 =
|
|
16
|
+
const mkdirp_1 = require("mkdirp");
|
|
17
17
|
const path_1 = require("path");
|
|
18
18
|
const write_file_atomic_1 = __importDefault(require("write-file-atomic"));
|
|
19
19
|
const debug = Debug('sm:util-fs');
|
|
@@ -29,7 +29,7 @@ const writeFile = (filePath, data) => {
|
|
|
29
29
|
try {
|
|
30
30
|
const fileDirectory = (0, path_1.dirname)(filePath);
|
|
31
31
|
if (!(0, fs_1.existsSync)(fileDirectory)) {
|
|
32
|
-
mkdirp_1.
|
|
32
|
+
(0, mkdirp_1.mkdirpSync)(fileDirectory);
|
|
33
33
|
}
|
|
34
34
|
return (0, write_file_atomic_1.default)(filePath, (typeof data === 'object') ? JSON.stringify(data) : data, (wfError) => {
|
|
35
35
|
if (wfError) {
|
|
@@ -98,19 +98,9 @@ exports.readFileSync = readFileSync;
|
|
|
98
98
|
*/
|
|
99
99
|
const mkdir = (path) => {
|
|
100
100
|
debug(`mkdir called on ${path}`);
|
|
101
|
-
return
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (error) {
|
|
105
|
-
return reject(error);
|
|
106
|
-
}
|
|
107
|
-
return resolve('');
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
catch (error) {
|
|
111
|
-
return reject(error);
|
|
112
|
-
}
|
|
113
|
-
});
|
|
101
|
+
return (0, mkdirp_1.mkdirp)(path)
|
|
102
|
+
.then(() => '')
|
|
103
|
+
.catch(error => Promise.reject(error));
|
|
114
104
|
};
|
|
115
105
|
exports.mkdir = mkdir;
|
|
116
106
|
/**
|
package/dist/util/index.js
CHANGED
|
@@ -131,8 +131,9 @@ const formatItems = (items, config) => {
|
|
|
131
131
|
items[i]._type = config.contentstack.actions.publish;
|
|
132
132
|
// extra keys
|
|
133
133
|
items[i]._synced_at = time;
|
|
134
|
-
|
|
135
|
-
items[i] = (0, lodash_1.merge)(items[i], items[i].data);
|
|
134
|
+
const assetLocale = items[i].data.publish_details.locale;
|
|
135
|
+
items[i] = (0, lodash_1.merge)((0, lodash_1.cloneDeep)(items[i]), items[i].data);
|
|
136
|
+
items[i].locale = assetLocale;
|
|
136
137
|
break;
|
|
137
138
|
case 'asset_unpublished':
|
|
138
139
|
delete items[i].type;
|
|
@@ -152,8 +153,9 @@ const formatItems = (items, config) => {
|
|
|
152
153
|
items[i]._content_type_uid = items[i].content_type_uid;
|
|
153
154
|
// extra keys
|
|
154
155
|
items[i]._synced_at = time;
|
|
155
|
-
|
|
156
|
-
items[i] = (0, lodash_1.merge)(items[i], items[i].data);
|
|
156
|
+
const entryLocale = items[i].data.publish_details.locale;
|
|
157
|
+
items[i] = (0, lodash_1.merge)((0, lodash_1.cloneDeep)(items[i]), items[i].data);
|
|
158
|
+
items[i].locale = entryLocale;
|
|
157
159
|
break;
|
|
158
160
|
case 'entry_unpublished':
|
|
159
161
|
delete items[i].type;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/datasync-manager",
|
|
3
3
|
"author": "Contentstack LLC <support@contentstack.com>",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "The primary module of Contentstack DataSync. Syncs Contentstack data with your server using Contentstack Sync API",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"dependencies": {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"husky": "^9.1.7",
|
|
31
31
|
"jest": "^29.7.0",
|
|
32
32
|
"jest-html-reporter": "^3.10.2",
|
|
33
|
-
"mkdirp": "^
|
|
33
|
+
"mkdirp": "^3.0.1",
|
|
34
34
|
"nock": "^10.0.6",
|
|
35
35
|
"node-notifier": "^10.0.1",
|
|
36
36
|
"rimraf": "^2.7.1",
|