@contentstack/cli-migration 1.10.2 → 1.11.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/README.md +2 -2
- package/lib/actions/action-list.d.ts +8 -0
- package/lib/actions/action-list.js +31 -0
- package/lib/actions/action-list.js.map +1 -0
- package/lib/actions/index.d.ts +180 -0
- package/lib/actions/index.js +207 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/commands/cm/stacks/migration.d.ts +14 -0
- package/lib/commands/cm/stacks/migration.js +274 -0
- package/lib/commands/cm/stacks/migration.js.map +1 -0
- package/lib/config/api-config.d.ts +13 -0
- package/lib/config/api-config.js +19 -0
- package/lib/config/api-config.js.map +1 -0
- package/lib/config/default-options.d.ts +5 -0
- package/lib/config/default-options.js +8 -0
- package/lib/config/default-options.js.map +1 -0
- package/lib/config/index.d.ts +4 -0
- package/lib/config/index.js +11 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/master-locale.d.ts +7 -0
- package/lib/config/master-locale.js +11 -0
- package/lib/config/master-locale.js.map +1 -0
- package/lib/modules/base.d.ts +39 -0
- package/lib/modules/base.js +84 -0
- package/lib/modules/base.js.map +1 -0
- package/lib/modules/content-types.d.ts +61 -0
- package/lib/modules/content-types.js +173 -0
- package/lib/modules/content-types.js.map +1 -0
- package/lib/modules/fields.d.ts +179 -0
- package/lib/modules/fields.js +292 -0
- package/lib/modules/fields.js.map +1 -0
- package/lib/modules/index.d.ts +5 -0
- package/lib/modules/index.js +13 -0
- package/lib/modules/index.js.map +1 -0
- package/lib/modules/locale.d.ts +6 -0
- package/lib/modules/locale.js +27 -0
- package/lib/modules/locale.js.map +1 -0
- package/lib/modules/migration.d.ts +50 -0
- package/lib/modules/migration.js +109 -0
- package/lib/modules/migration.js.map +1 -0
- package/lib/modules/parser.d.ts +3 -0
- package/lib/modules/parser.js +93 -0
- package/lib/modules/parser.js.map +1 -0
- package/lib/services/content-types.d.ts +25 -0
- package/lib/services/content-types.js +302 -0
- package/lib/services/content-types.js.map +1 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +9 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/locales.d.ts +6 -0
- package/lib/services/locales.js +68 -0
- package/lib/services/locales.js.map +1 -0
- package/lib/utils/auto-retry.d.ts +2 -0
- package/lib/utils/auto-retry.js +30 -0
- package/lib/utils/auto-retry.js.map +1 -0
- package/lib/utils/callsite.d.ts +2 -0
- package/lib/utils/callsite.js +21 -0
- package/lib/utils/callsite.js.map +1 -0
- package/lib/utils/constants.d.ts +108 -0
- package/lib/utils/constants.js +206 -0
- package/lib/utils/constants.js.map +1 -0
- package/lib/utils/contentstack-sdk.d.ts +7 -0
- package/lib/utils/contentstack-sdk.js +53 -0
- package/lib/utils/contentstack-sdk.js.map +1 -0
- package/lib/utils/error-helper.d.ts +2 -0
- package/lib/utils/error-helper.js +102 -0
- package/lib/utils/error-helper.js.map +1 -0
- package/lib/utils/fs-helper.d.ts +4 -0
- package/lib/utils/fs-helper.js +37 -0
- package/lib/utils/fs-helper.js.map +1 -0
- package/lib/utils/get-batches.d.ts +2 -0
- package/lib/utils/get-batches.js +8 -0
- package/lib/utils/get-batches.js.map +1 -0
- package/lib/utils/get-config.d.ts +6 -0
- package/lib/utils/get-config.js +11 -0
- package/lib/utils/get-config.js.map +1 -0
- package/lib/utils/group-by.d.ts +1 -0
- package/lib/utils/group-by.js +41 -0
- package/lib/utils/group-by.js.map +1 -0
- package/lib/utils/index.d.ts +18 -0
- package/lib/utils/index.js +39 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.js +68 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/map.d.ts +7 -0
- package/lib/utils/map.js +40 -0
- package/lib/utils/map.js.map +1 -0
- package/lib/utils/migration-logger.d.ts +7 -0
- package/lib/utils/migration-logger.js +26 -0
- package/lib/utils/migration-logger.js.map +1 -0
- package/lib/utils/modules.d.ts +2 -0
- package/lib/utils/modules.js +118 -0
- package/lib/utils/modules.js.map +1 -0
- package/lib/utils/object-helper.d.ts +1 -0
- package/lib/utils/object-helper.js +12 -0
- package/lib/utils/object-helper.js.map +1 -0
- package/lib/utils/request.d.ts +9 -0
- package/lib/utils/request.js +78 -0
- package/lib/utils/request.js.map +1 -0
- package/lib/utils/safe-promise.d.ts +2 -0
- package/lib/utils/safe-promise.js +6 -0
- package/lib/utils/safe-promise.js.map +1 -0
- package/lib/utils/schema-helper.d.ts +5 -0
- package/lib/utils/schema-helper.js +36 -0
- package/lib/utils/schema-helper.js.map +1 -0
- package/lib/utils/success-handler.d.ts +2 -0
- package/lib/utils/success-handler.js +12 -0
- package/lib/utils/success-handler.js.map +1 -0
- package/lib/validators/api-error.d.ts +4 -0
- package/lib/validators/api-error.js +17 -0
- package/lib/validators/api-error.js.map +1 -0
- package/lib/validators/base-validator.d.ts +4 -0
- package/lib/validators/base-validator.js +34 -0
- package/lib/validators/base-validator.js.map +1 -0
- package/lib/validators/create-content-type-validator.d.ts +7 -0
- package/lib/validators/create-content-type-validator.js +45 -0
- package/lib/validators/create-content-type-validator.js.map +1 -0
- package/lib/validators/edit-content-type-validator.d.ts +7 -0
- package/lib/validators/edit-content-type-validator.js +44 -0
- package/lib/validators/edit-content-type-validator.js.map +1 -0
- package/lib/validators/field-validator.d.ts +4 -0
- package/lib/validators/field-validator.js +17 -0
- package/lib/validators/field-validator.js.map +1 -0
- package/lib/validators/index.d.ts +8 -0
- package/lib/validators/index.js +19 -0
- package/lib/validators/index.js.map +1 -0
- package/lib/validators/migration-error.d.ts +4 -0
- package/lib/validators/migration-error.js +16 -0
- package/lib/validators/migration-error.js.map +1 -0
- package/lib/validators/schema-validator.d.ts +4 -0
- package/lib/validators/schema-validator.js +19 -0
- package/lib/validators/schema-validator.js.map +1 -0
- package/lib/validators/type-error.d.ts +5 -0
- package/lib/validators/type-error.js +18 -0
- package/lib/validators/type-error.js.map +1 -0
- package/oclif.manifest.json +145 -0
- package/package.json +22 -12
- package/src/actions/action-list.js +0 -32
- package/src/actions/index.js +0 -217
- package/src/commands/cm/stacks/migration.js +0 -316
- package/src/config/api-config.js +0 -18
- package/src/config/default-options.js +0 -7
- package/src/config/index.js +0 -7
- package/src/config/master-locale.js +0 -10
- package/src/modules/base.js +0 -95
- package/src/modules/content-types.js +0 -208
- package/src/modules/fields.js +0 -339
- package/src/modules/index.js +0 -8
- package/src/modules/locale.js +0 -33
- package/src/modules/migration.js +0 -112
- package/src/modules/parser.js +0 -105
- package/src/services/content-types.js +0 -317
- package/src/services/index.js +0 -6
- package/src/services/locales.js +0 -71
- package/src/utils/auto-retry.js +0 -32
- package/src/utils/callsite.js +0 -23
- package/src/utils/constants.js +0 -223
- package/src/utils/contentstack-sdk.js +0 -70
- package/src/utils/error-helper.js +0 -105
- package/src/utils/fs-helper.js +0 -29
- package/src/utils/get-batches.js +0 -7
- package/src/utils/get-config.js +0 -13
- package/src/utils/group-by.js +0 -38
- package/src/utils/index.js +0 -21
- package/src/utils/logger.js +0 -75
- package/src/utils/map.js +0 -40
- package/src/utils/migration-logger.js +0 -21
- package/src/utils/modules.js +0 -134
- package/src/utils/object-helper.js +0 -9
- package/src/utils/request.js +0 -95
- package/src/utils/safe-promise.js +0 -3
- package/src/utils/schema-helper.js +0 -35
- package/src/utils/success-handler.js +0 -12
- package/src/validators/api-error.js +0 -20
- package/src/validators/base-validator.js +0 -39
- package/src/validators/create-content-type-validator.js +0 -54
- package/src/validators/edit-content-type-validator.js +0 -53
- package/src/validators/field-validator.js +0 -21
- package/src/validators/index.js +0 -11
- package/src/validators/migration-error.js +0 -20
- package/src/validators/schema-validator.js +0 -23
- package/src/validators/type-error.js +0 -22
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.warn = exports.error = exports.success = exports.init = void 0;
|
|
4
|
+
const winston_1 = require("winston");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
|
+
// FS helper
|
|
8
|
+
const fs_helper_1 = require("./fs-helper");
|
|
9
|
+
const { NODE_ENV } = process.env;
|
|
10
|
+
function getString(args) {
|
|
11
|
+
let str = '';
|
|
12
|
+
if (args && args.length > 0) {
|
|
13
|
+
str = args
|
|
14
|
+
.map((item) => (item && typeof item === 'object' ? JSON.stringify(item) : item))
|
|
15
|
+
.join(' ')
|
|
16
|
+
.trim();
|
|
17
|
+
}
|
|
18
|
+
return str;
|
|
19
|
+
}
|
|
20
|
+
const customFormat = winston_1.format.printf(({ level, message }) => {
|
|
21
|
+
return `${level}: ${message}`;
|
|
22
|
+
});
|
|
23
|
+
function init(logFileName) {
|
|
24
|
+
var _a;
|
|
25
|
+
const logsDir = (0, path_1.resolve)((_a = process.env.CS_CLI_LOG_PATH) !== null && _a !== void 0 ? _a : process.cwd(), 'logs');
|
|
26
|
+
// Create dir if does not exist
|
|
27
|
+
(0, fs_helper_1.makeDir)(logsDir);
|
|
28
|
+
const logPath = (0, cli_utilities_1.pathValidator)((0, path_1.join)((0, cli_utilities_1.sanitizePath)(logsDir), (0, cli_utilities_1.sanitizePath)(logFileName) + '.log'));
|
|
29
|
+
const logger = (0, winston_1.createLogger)({
|
|
30
|
+
format: winston_1.format.combine(winston_1.format.colorize(), winston_1.format.label({ label: 'Migration' }), customFormat),
|
|
31
|
+
transports: [new winston_1.transports.File({ filename: logPath })],
|
|
32
|
+
});
|
|
33
|
+
let args;
|
|
34
|
+
let logString;
|
|
35
|
+
return {
|
|
36
|
+
log: function (...args) {
|
|
37
|
+
logString = getString(args);
|
|
38
|
+
logString && logger.log('info', logString);
|
|
39
|
+
},
|
|
40
|
+
warn: function (...args) {
|
|
41
|
+
logString = getString(args);
|
|
42
|
+
logString && logger.log('warn', logString);
|
|
43
|
+
},
|
|
44
|
+
error: function () {
|
|
45
|
+
// args = slice.call(arguments);
|
|
46
|
+
// logString = getString(args);
|
|
47
|
+
// logString && logger.log('error', logString);
|
|
48
|
+
},
|
|
49
|
+
debug: function (...args) {
|
|
50
|
+
logString = getString(args);
|
|
51
|
+
logString && logger.log('debug', logString);
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
exports.init = init;
|
|
56
|
+
const successFn = init('success');
|
|
57
|
+
exports.success = successFn.log;
|
|
58
|
+
let errorFn;
|
|
59
|
+
if (NODE_ENV === 'test') {
|
|
60
|
+
errorFn = init('warn');
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
errorFn = init('error');
|
|
64
|
+
}
|
|
65
|
+
exports.error = errorFn.error;
|
|
66
|
+
const warnFn = init('warn');
|
|
67
|
+
exports.warn = warnFn.warn;
|
|
68
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":";;;AAAA,qCAA2D;AAC3D,+BAAqC;AACrC,+DAA0E;AAE1E,YAAY;AACZ,2CAAsC;AAEtC,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEjC,SAAS,SAAS,CAAC,IAAW;IAC5B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QAC3B,GAAG,GAAG,IAAI;aACP,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aAC/E,IAAI,CAAC,GAAG,CAAC;aACT,IAAI,EAAE,CAAC;KACX;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,YAAY,GAAG,gBAAM,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK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YACL,gCAAgC;YAChC,+BAA+B;YAC/B,+CAA+C;QACjD,CAAC;QACD,KAAK,EAAE,UAAU,GAAG,IAAW;YAC7B,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;YAC5B,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC9C,CAAC;KACF,CAAC;AACJ,CAAC;AAjCD,oBAiCC;AAED,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;AACrB,QAAA,OAAO,GAAG,SAAS,CAAC,GAAG,CAAC;AAErC,IAAI,OAAY,CAAC;AACjB,IAAI,QAAQ,KAAK,MAAM,EAAE;IACvB,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;CACxB;KAAM;IACL,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;CACzB;AACY,QAAA,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;AAEnC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;AACf,QAAA,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC","sourcesContent":["import { createLogger, format, transports } from 'winston';\nimport { resolve, join } from 'path';\nimport { pathValidator, sanitizePath } from '@contentstack/cli-utilities';\n\n// FS helper\nimport { makeDir } from './fs-helper';\n\nconst { NODE_ENV } = process.env;\n\nfunction getString(args: any[]): string {\n let str = '';\n if (args && args.length > 0) {\n str = args\n .map((item) => (item && typeof item === 'object' ? JSON.stringify(item) : item))\n .join(' ')\n .trim();\n }\n return str;\n}\n\nconst customFormat = format.printf(({ level, message }: any) => {\n return `${level}: ${message}`;\n});\n\nexport function init(logFileName: string): any {\n const logsDir = resolve(process.env.CS_CLI_LOG_PATH ?? process.cwd(), 'logs');\n // Create dir if does not exist\n makeDir(logsDir);\n\n const logPath = pathValidator(join(sanitizePath(logsDir), sanitizePath(logFileName) + '.log'));\n const logger = createLogger({\n format: format.combine(format.colorize(), format.label({ label: 'Migration' }), customFormat),\n transports: [new transports.File({ filename: logPath })],\n });\n\n let args: any;\n let logString: string;\n\n return {\n log: function (...args: any[]) {\n logString = getString(args);\n logString && logger.log('info', logString);\n },\n warn: function (...args: any[]) {\n logString = getString(args);\n logString && logger.log('warn', logString);\n },\n error: function () {\n // args = slice.call(arguments);\n // logString = getString(args);\n // logString && logger.log('error', logString);\n },\n debug: function (...args: any[]) {\n logString = getString(args);\n logString && logger.log('debug', logString);\n },\n };\n}\n\nconst successFn = init('success');\nexport const success = successFn.log;\n\nlet errorFn: any;\nif (NODE_ENV === 'test') {\n errorFn = init('warn');\n} else {\n errorFn = init('error');\n}\nexport const error = errorFn.error;\n\nconst warnFn = init('warn');\nexport const warn = warnFn.warn;\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const getMapInstance: () => Map<string, any>;
|
|
2
|
+
export declare const get: (id: string, mapInstance: Map<string, any>, data?: any) => any;
|
|
3
|
+
export declare const set: (id: string, mapInstance: Map<string, any>, data: any) => Map<string, any>;
|
|
4
|
+
export declare const remove: (id: string, mapInstance: Map<string, any>) => boolean;
|
|
5
|
+
export declare const getDataWithAction: (id: string, mapInstance: Map<string, any>, action: string) => any;
|
|
6
|
+
export declare const resetMapInstance: (mapInstance: Map<string, any>) => void;
|
|
7
|
+
export declare const deleteMap: () => void;
|
package/lib/utils/map.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteMap = exports.resetMapInstance = exports.getDataWithAction = exports.remove = exports.set = exports.get = exports.getMapInstance = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
const getMapInstance = () => {
|
|
6
|
+
return constants_1.mapObject;
|
|
7
|
+
};
|
|
8
|
+
exports.getMapInstance = getMapInstance;
|
|
9
|
+
const get = (id, mapInstance, data = []) => {
|
|
10
|
+
// Create key if does not exist
|
|
11
|
+
let __data = mapInstance.get(id);
|
|
12
|
+
if (!__data) {
|
|
13
|
+
mapInstance.set(id, data);
|
|
14
|
+
__data = mapInstance.get(id);
|
|
15
|
+
}
|
|
16
|
+
return __data;
|
|
17
|
+
};
|
|
18
|
+
exports.get = get;
|
|
19
|
+
const set = (id, mapInstance, data) => {
|
|
20
|
+
return mapInstance.set(id, data);
|
|
21
|
+
};
|
|
22
|
+
exports.set = set;
|
|
23
|
+
const remove = (id, mapInstance) => {
|
|
24
|
+
return mapInstance.delete(id);
|
|
25
|
+
};
|
|
26
|
+
exports.remove = remove;
|
|
27
|
+
const getDataWithAction = (id, mapInstance, action) => {
|
|
28
|
+
let data = (0, exports.get)(id, mapInstance);
|
|
29
|
+
data = data[action];
|
|
30
|
+
return data;
|
|
31
|
+
};
|
|
32
|
+
exports.getDataWithAction = getDataWithAction;
|
|
33
|
+
const resetMapInstance = (mapInstance) => {
|
|
34
|
+
(0, exports.set)(constants_1.actionMapper, mapInstance, []);
|
|
35
|
+
(0, exports.set)(constants_1.requests, mapInstance, []);
|
|
36
|
+
};
|
|
37
|
+
exports.resetMapInstance = resetMapInstance;
|
|
38
|
+
const deleteMap = () => { };
|
|
39
|
+
exports.deleteMap = deleteMap;
|
|
40
|
+
//# sourceMappingURL=map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"map.js","sourceRoot":"","sources":["../../src/utils/map.ts"],"names":[],"mappings":";;;AAAA,2CAAgE;AAEzD,MAAM,cAAc,GAAG,GAAqB,EAAE;IACnD,OAAO,qBAAS,CAAC;AACnB,CAAC,CAAC;AAFW,QAAA,cAAc,kBAEzB;AAEK,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,WAA6B,EAAE,OAAY,EAAE,EAAO,EAAE;IACpF,+BAA+B;IAC/B,IAAI,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAEjC,IAAI,CAAC,MAAM,EAAE;QACX,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;QAC1B,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;KAC9B;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAVW,QAAA,GAAG,OAUd;AAEK,MAAM,GAAG,GAAG,CAAC,EAAU,EAAE,WAA6B,EAAE,IAAS,EAAoB,EAAE;IAC5F,OAAO,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;AACnC,CAAC,CAAC;AAFW,QAAA,GAAG,OAEd;AAEK,MAAM,MAAM,GAAG,CAAC,EAAU,EAAE,WAA6B,EAAW,EAAE;IAC3E,OAAO,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAChC,CAAC,CAAC;AAFW,QAAA,MAAM,UAEjB;AAEK,MAAM,iBAAiB,GAAG,CAAC,EAAU,EAAE,WAA6B,EAAE,MAAc,EAAO,EAAE;IAClG,IAAI,IAAI,GAAG,IAAA,WAAG,EAAC,EAAE,EAAE,WAAW,CAAC,CAAC;IAChC,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AAJW,QAAA,iBAAiB,qBAI5B;AAEK,MAAM,gBAAgB,GAAG,CAAC,WAA6B,EAAQ,EAAE;IACtE,IAAA,WAAG,EAAC,wBAAY,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;IACnC,IAAA,WAAG,EAAC,oBAAQ,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;AACjC,CAAC,CAAC;AAHW,QAAA,gBAAgB,oBAG3B;AAEK,MAAM,SAAS,GAAG,GAAS,EAAE,GAAG,CAAC,CAAC;AAA5B,QAAA,SAAS,aAAmB","sourcesContent":["import { mapObject, actionMapper, requests } from './constants';\n\nexport const getMapInstance = (): Map<string, any> => {\n return mapObject;\n};\n\nexport const get = (id: string, mapInstance: Map<string, any>, data: any = []): any => {\n // Create key if does not exist\n let __data = mapInstance.get(id);\n\n if (!__data) {\n mapInstance.set(id, data);\n __data = mapInstance.get(id);\n }\n\n return __data;\n};\n\nexport const set = (id: string, mapInstance: Map<string, any>, data: any): Map<string, any> => {\n return mapInstance.set(id, data);\n};\n\nexport const remove = (id: string, mapInstance: Map<string, any>): boolean => {\n return mapInstance.delete(id);\n};\n\nexport const getDataWithAction = (id: string, mapInstance: Map<string, any>, action: string): any => {\n let data = get(id, mapInstance);\n data = data[action];\n return data;\n};\n\nexport const resetMapInstance = (mapInstance: Map<string, any>): void => {\n set(actionMapper, mapInstance, []);\n set(requests, mapInstance, []);\n};\n\nexport const deleteMap = (): void => { };\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const winston_1 = tslib_1.__importDefault(require("winston"));
|
|
5
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
6
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
|
+
class MigrationLogger {
|
|
8
|
+
constructor(filePath) {
|
|
9
|
+
this.filePath = path_1.default.join((0, cli_utilities_1.sanitizePath)(filePath), 'migration-logs');
|
|
10
|
+
this.logger = winston_1.default.createLogger({
|
|
11
|
+
levels: { error: 1 },
|
|
12
|
+
transports: [
|
|
13
|
+
new winston_1.default.transports.File({
|
|
14
|
+
level: 'error',
|
|
15
|
+
filename: path_1.default.join((0, cli_utilities_1.sanitizePath)(this.filePath), 'error.logs'),
|
|
16
|
+
format: winston_1.default.format.combine(winston_1.default.format.timestamp(), winston_1.default.format.json()),
|
|
17
|
+
}),
|
|
18
|
+
],
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
log(level, message) {
|
|
22
|
+
this.logger.log('error', message);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.default = MigrationLogger;
|
|
26
|
+
//# sourceMappingURL=migration-logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-logger.js","sourceRoot":"","sources":["../../src/utils/migration-logger.ts"],"names":[],"mappings":";;;AAAA,8DAA8B;AAC9B,wDAAwB;AACxB,+DAA2D;AAE3D,MAAqB,eAAe;IAIlC,YAAY,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,cAAI,CAAC,IAAI,CAAC,IAAA,4BAAY,EAAC,QAAQ,CAAC,EAAE,gBAAgB,CAAC,CAAC;QACpE,IAAI,CAAC,MAAM,GAAG,iBAAO,CAAC,YAAY,CAAC;YACjC,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE;YACpB,UAAU,EAAE;gBACV,IAAI,iBAAO,CAAC,UAAU,CAAC,IAAI,CAAC;oBAC1B,KAAK,EAAE,OAAO;oBACd,QAAQ,EAAE,cAAI,CAAC,IAAI,CAAC,IAAA,4BAAY,EAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAC;oBAC9D,MAAM,EAAE,iBAAO,CAAC,MAAM,CAAC,OAAO,CAAC,iBAAO,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,iBAAO,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;iBAClF,CAAC;aACH;SACF,CAAC,CAAC;IACL,CAAC;IAED,GAAG,CAAC,KAAa,EAAE,OAAY;QAC7B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;CACF;AArBD,kCAqBC","sourcesContent":["import winston from 'winston';\nimport path from 'path';\nimport { sanitizePath } from '@contentstack/cli-utilities';\n\nexport default class MigrationLogger {\n filePath: string;\n logger: winston.Logger;\n\n constructor(filePath: string) {\n this.filePath = path.join(sanitizePath(filePath), 'migration-logs');\n this.logger = winston.createLogger({\n levels: { error: 1 },\n transports: [\n new winston.transports.File({\n level: 'error',\n filename: path.join(sanitizePath(this.filePath), 'error.logs'),\n format: winston.format.combine(winston.format.timestamp(), winston.format.json()),\n }),\n ],\n });\n }\n\n log(level: string, message: any): void {\n this.logger.log('error', message);\n }\n}\n"]}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
7
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
8
|
+
const module_1 = require("module");
|
|
9
|
+
const internalModules = new Set(module_1.builtinModules);
|
|
10
|
+
function checkWritePermissionToDirectory(directory) {
|
|
11
|
+
try {
|
|
12
|
+
fs_1.default.accessSync(directory, fs_1.default.constants.W_OK);
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
catch (err) {
|
|
16
|
+
console.log(`Permission denied. You do not have the necessary write access for this directory.`);
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function doesPackageJsonExist(directory) {
|
|
21
|
+
return fs_1.default.existsSync(path_1.default.join((0, cli_utilities_1.sanitizePath)(directory), 'package.json'));
|
|
22
|
+
}
|
|
23
|
+
function scanDirectory(directory) {
|
|
24
|
+
return fs_1.default.readdirSync(directory);
|
|
25
|
+
}
|
|
26
|
+
function scanFileForDependencies(directory, files) {
|
|
27
|
+
const dependencies = new Set();
|
|
28
|
+
files.forEach((file) => {
|
|
29
|
+
const filePath = path_1.default.join((0, cli_utilities_1.sanitizePath)(directory), (0, cli_utilities_1.sanitizePath)(file));
|
|
30
|
+
if (path_1.default.extname(filePath) === '.js') {
|
|
31
|
+
const fileContent = fs_1.default.readFileSync(filePath, 'utf-8');
|
|
32
|
+
findModulesSync(fileContent).forEach((dep) => dependencies.add(dep));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return [...dependencies];
|
|
36
|
+
}
|
|
37
|
+
function createPackageJson(directory) {
|
|
38
|
+
const templateString = `{
|
|
39
|
+
"name": "MigrationPackage",
|
|
40
|
+
"version": "1.0.0",
|
|
41
|
+
"main": "",
|
|
42
|
+
"scripts": {},
|
|
43
|
+
"keywords": [],
|
|
44
|
+
"author": "",
|
|
45
|
+
"license": "ISC",
|
|
46
|
+
"description": ""
|
|
47
|
+
}`;
|
|
48
|
+
fs_1.default.writeFileSync(path_1.default.join((0, cli_utilities_1.sanitizePath)(directory), 'package.json'), templateString);
|
|
49
|
+
}
|
|
50
|
+
function installDependencies(dependencies, directory) {
|
|
51
|
+
const installedDependencies = new Set();
|
|
52
|
+
dependencies.forEach((dep) => {
|
|
53
|
+
if (!internalModules.has(dep)) {
|
|
54
|
+
const pkg = dep.startsWith('@') ? dep : dep.split('/')[0];
|
|
55
|
+
if (!installedDependencies.has(pkg)) {
|
|
56
|
+
executeShellCommand(pkg, directory);
|
|
57
|
+
installedDependencies.add(pkg);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function executeShellCommand(pkg, directory = '') {
|
|
63
|
+
try {
|
|
64
|
+
const result = (0, child_process_1.spawnSync)(`npm`, ['i', pkg], { stdio: 'inherit', cwd: directory, shell: false });
|
|
65
|
+
if (result === null || result === void 0 ? void 0 : result.error)
|
|
66
|
+
throw result.error;
|
|
67
|
+
console.log(`Command executed successfully`);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
console.error(`Command execution failed. Error: ${error === null || error === void 0 ? void 0 : error.message}`);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function installModules(filePath, multiple) {
|
|
74
|
+
const files = multiple ? [] : [path_1.default.basename(filePath)];
|
|
75
|
+
const dirPath = multiple ? filePath : path_1.default.dirname(filePath);
|
|
76
|
+
if (checkWritePermissionToDirectory(dirPath)) {
|
|
77
|
+
if (multiple) {
|
|
78
|
+
files.push(...scanDirectory(dirPath));
|
|
79
|
+
}
|
|
80
|
+
if (files.length === 0) {
|
|
81
|
+
console.log(`Error: Could not locate files needed to create package.json. Exiting the process.`);
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
const dependencies = scanFileForDependencies(dirPath, files);
|
|
85
|
+
if (!doesPackageJsonExist(dirPath)) {
|
|
86
|
+
console.log(`package.json not found. Creating a new package.json...`);
|
|
87
|
+
createPackageJson(dirPath);
|
|
88
|
+
}
|
|
89
|
+
installDependencies(dependencies, dirPath);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.log(`You don't have write permission to the directory`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
console.log(`All dependencies installed successfully.`);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
function findModulesSync(data) {
|
|
99
|
+
try {
|
|
100
|
+
const requireRegex = /require\(['"`](.*?)['"`]\)/g;
|
|
101
|
+
const importRegex = /import\s+(?:(?:[\w*\s{},]*)\s+from\s+)?['"`](.*?)['"`]/g;
|
|
102
|
+
const modules = new Set();
|
|
103
|
+
let match;
|
|
104
|
+
while ((match = requireRegex.exec(data)) !== null) {
|
|
105
|
+
modules.add(match[1]);
|
|
106
|
+
}
|
|
107
|
+
while ((match = importRegex.exec(data)) !== null) {
|
|
108
|
+
modules.add(match[1]);
|
|
109
|
+
}
|
|
110
|
+
return [...modules];
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
console.error(`Error reading file: ${error.message}`);
|
|
114
|
+
return [];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
exports.default = installModules;
|
|
118
|
+
//# sourceMappingURL=modules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modules.js","sourceRoot":"","sources":["../../src/utils/modules.ts"],"names":[],"mappings":";;;AAAA,oDAAoB;AACpB,iDAA0C;AAC1C,wDAAwB;AACxB,+DAA2D;AAE3D,mCAAwC;AAExC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,uBAAc,CAA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AU,CAAC;QAClC,IAAI,KAA6B,CAAC;QAElC,OAAO,CAAC,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;YACjD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACvB;QAED,OAAO,CAAC,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE;YAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACvB;QAED,OAAO,CAAC,GAAG,OAAO,CAAC,CAAC;KACrB;IAAC,OAAO,KAAU,EAAE;QACnB,OAAO,CAAC,KAAK,CAAC,uBAAuB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACtD,OAAO,EAAE,CAAC;KACX;AACH,CAAC;AAED,kBAAe,cAAc,CAAC","sourcesContent":["import fs from 'fs';\nimport { spawnSync } from 'child_process';\nimport path from 'path';\nimport { sanitizePath } from '@contentstack/cli-utilities';\nimport os from 'os';\nimport { builtinModules } from 'module';\n\nconst internalModules = new Set(builtinModules);\n\nfunction checkWritePermissionToDirectory(directory: string): boolean {\n try {\n fs.accessSync(directory, fs.constants.W_OK);\n return true;\n } catch (err) {\n console.log(`Permission denied. You do not have the necessary write access for this directory.`);\n return false;\n }\n}\n\nfunction doesPackageJsonExist(directory: string): boolean {\n return fs.existsSync(path.join(sanitizePath(directory), 'package.json'));\n}\n\nfunction scanDirectory(directory: string): string[] {\n return fs.readdirSync(directory);\n}\n\nfunction scanFileForDependencies(directory: string, files: string[]): string[] {\n const dependencies = new Set<string>();\n\n files.forEach((file) => {\n const filePath = path.join(sanitizePath(directory), sanitizePath(file));\n if (path.extname(filePath) === '.js') {\n const fileContent = fs.readFileSync(filePath, 'utf-8');\n findModulesSync(fileContent).forEach((dep) => dependencies.add(dep));\n }\n });\n\n return [...dependencies];\n}\n\nfunction createPackageJson(directory: string): void {\n const templateString = `{\n \"name\": \"MigrationPackage\",\n \"version\": \"1.0.0\",\n \"main\": \"\",\n \"scripts\": {},\n \"keywords\": [],\n \"author\": \"\",\n \"license\": \"ISC\",\n \"description\": \"\"\n }`;\n\n fs.writeFileSync(path.join(sanitizePath(directory), 'package.json'), templateString);\n}\n\nfunction installDependencies(dependencies: string[], directory: string): void {\n const installedDependencies = new Set<string>();\n\n dependencies.forEach((dep) => {\n if (!internalModules.has(dep)) {\n const pkg = dep.startsWith('@') ? dep : dep.split('/')[0];\n if (!installedDependencies.has(pkg)) {\n executeShellCommand(pkg, directory);\n installedDependencies.add(pkg);\n }\n }\n });\n}\n\nfunction executeShellCommand(pkg: string, directory: string = ''): void {\n try {\n const result = spawnSync(`npm`, ['i', pkg], { stdio: 'inherit', cwd: directory, shell: false });\n if (result?.error) throw result.error;\n console.log(`Command executed successfully`);\n } catch (error: any) {\n console.error(`Command execution failed. Error: ${error?.message}`);\n }\n}\n\nasync function installModules(filePath: string, multiple: boolean): Promise<boolean> {\n const files = multiple ? [] : [path.basename(filePath)];\n const dirPath = multiple ? filePath : path.dirname(filePath);\n\n if (checkWritePermissionToDirectory(dirPath)) {\n if (multiple) {\n files.push(...scanDirectory(dirPath));\n }\n\n if (files.length === 0) {\n console.log(`Error: Could not locate files needed to create package.json. Exiting the process.`);\n return true;\n }\n\n const dependencies = scanFileForDependencies(dirPath, files);\n\n if (!doesPackageJsonExist(dirPath)) {\n console.log(`package.json not found. Creating a new package.json...`);\n createPackageJson(dirPath);\n }\n\n installDependencies(dependencies, dirPath);\n } else {\n console.log(`You don't have write permission to the directory`);\n return false;\n }\n\n console.log(`All dependencies installed successfully.`);\n return true;\n}\n\nfunction findModulesSync(data: string): string[] {\n try {\n const requireRegex = /require\\(['\"`](.*?)['\"`]\\)/g;\n const importRegex = /import\\s+(?:(?:[\\w*\\s{},]*)\\s+from\\s+)?['\"`](.*?)['\"`]/g;\n\n const modules = new Set<string>();\n let match: RegExpExecArray | null;\n\n while ((match = requireRegex.exec(data)) !== null) {\n modules.add(match[1]);\n }\n\n while ((match = importRegex.exec(data)) !== null) {\n modules.add(match[1]);\n }\n\n return [...modules];\n } catch (error: any) {\n console.error(`Error reading file: ${error.message}`);\n return [];\n }\n}\n\nexport default installModules;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getEntryObj: (fields: string[], obj: any) => any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getEntryObj = void 0;
|
|
4
|
+
const getEntryObj = (fields, obj) => {
|
|
5
|
+
let entryObj = {};
|
|
6
|
+
fields.forEach((field) => {
|
|
7
|
+
entryObj[field] = obj[field];
|
|
8
|
+
});
|
|
9
|
+
return entryObj;
|
|
10
|
+
};
|
|
11
|
+
exports.getEntryObj = getEntryObj;
|
|
12
|
+
//# sourceMappingURL=object-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object-helper.js","sourceRoot":"","sources":["../../src/utils/object-helper.ts"],"names":[],"mappings":";;;AAAO,MAAM,WAAW,GAAG,CAAC,MAAgB,EAAE,GAAQ,EAAO,EAAE;IAC7D,IAAI,QAAQ,GAAQ,EAAE,CAAC;IACvB,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AANW,QAAA,WAAW,eAMtB","sourcesContent":["export const getEntryObj = (fields: string[], obj: any): any => {\n let entryObj: any = {};\n fields.forEach((field) => {\n entryObj[field] = obj[field];\n });\n return entryObj;\n};\n"]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Dependencies
|
|
4
|
+
const https_1 = require("https");
|
|
5
|
+
// Map helper
|
|
6
|
+
const map_1 = require("./map");
|
|
7
|
+
// constants
|
|
8
|
+
const constants_1 = require("./constants");
|
|
9
|
+
// Properties
|
|
10
|
+
const { DELETE_CT } = constants_1.actions;
|
|
11
|
+
exports.default = ({ hostname, path, headers, method, id, action, }) => {
|
|
12
|
+
let options = {
|
|
13
|
+
hostname,
|
|
14
|
+
path,
|
|
15
|
+
headers,
|
|
16
|
+
method,
|
|
17
|
+
id,
|
|
18
|
+
action,
|
|
19
|
+
};
|
|
20
|
+
return (_data) => {
|
|
21
|
+
// get data here using id and action
|
|
22
|
+
let data = getData(_data, id, action, method);
|
|
23
|
+
// Special handling for non writable methods
|
|
24
|
+
options = getNewOptions(options, data, action, method);
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
const req = (0, https_1.request)(options, (res) => {
|
|
27
|
+
let response = '';
|
|
28
|
+
res.on('data', (_res) => {
|
|
29
|
+
response += _res.toString();
|
|
30
|
+
});
|
|
31
|
+
res.on('end', () => {
|
|
32
|
+
try {
|
|
33
|
+
response = JSON.parse(response);
|
|
34
|
+
resolve(response);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
reject('Error while parsing response!');
|
|
38
|
+
// throw new Error('Error while parsing response!');
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
req.on('error', (err) => {
|
|
43
|
+
reject(err);
|
|
44
|
+
});
|
|
45
|
+
!constants_1.nonWritableMethods.includes(method) && req.write(data);
|
|
46
|
+
req.end();
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
function getData(_data, id, action, method) {
|
|
51
|
+
if (method === 'GET')
|
|
52
|
+
return;
|
|
53
|
+
// if (!nonWritableMethods.includes(method)) {
|
|
54
|
+
let mapInstance = (0, map_1.getMapInstance)();
|
|
55
|
+
let data = _data ? _data : (0, map_1.getDataWithAction)(id, mapInstance, action);
|
|
56
|
+
return JSON.stringify(data);
|
|
57
|
+
}
|
|
58
|
+
function getNewOptions(options, data, action, method) {
|
|
59
|
+
// Special handling for delete method
|
|
60
|
+
if (action === DELETE_CT) {
|
|
61
|
+
try {
|
|
62
|
+
data = JSON.parse(data);
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw 'Error while parsing data for delete operation';
|
|
66
|
+
}
|
|
67
|
+
options.path = `${options.path}?force=${data.content_type.force}`;
|
|
68
|
+
}
|
|
69
|
+
if (!constants_1.nonWritableMethods.includes(method) && data) {
|
|
70
|
+
options.headers['Content-Length'] = data.length;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
delete options.headers['Content-Type'];
|
|
74
|
+
delete options.headers['Content-Length'];
|
|
75
|
+
}
|
|
76
|
+
return options;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/utils/request.ts"],"names":[],"mappings":";;AAAA,eAAe;AACf,iCAAgC;AAEhC,aAAa;AACb,+BAA0D;AAE1D,YAAY;AACZ,2CAA0D;AAE1D,aAAa;AACb,MAAM,EAAE,SAAS,EAAE,GAAG,mBAAO,CAAC;AAE9B,kBAAe,CAAC,EACd,QAAQ,EACR,IAAI,EACJ,OAAO,EACP,MAAM,EACN,EAAE,EACF,MAAM,GAQP,EAAE,EAAE;IACH,IAAI,OAAO,GAAQ;QACjB,QAAQ;QACR,IAAI;QACJ,OAAO;QACP,MAAM;QACN,EAAE;QACF,MAAM;KACP,CAAC;IACF,OAAO,CAAC,KAAU,EAAE,EAAE;QACpB,oCAAoC;QACpC,IAAI,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,4CAA4C;QAC5C,OAAO,GAAG,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CA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C,EAAE,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;IACtE,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC;AAED,SAAS,aAAa,CAAC,OAAY,EAAE,IAAwB,EAAE,MAAc,EAAE,MAAc;IAC3F,qCAAqC;IACrC,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,IAAI;YACF,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAc,CAAC,CAAC;SACnC;QAAC,OAAO,GAAG,EAAE;YACZ,MAAM,+CAA+C,CAAC;SACvD;QACD,OAAO,CAAC,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,UAAW,IAAY,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC;KAC5E;IAED,IAAI,CAAC,8BAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,IAAI,EAAE;QAChD,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;KACjD;SAAM;QACL,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACvC,OAAO,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;KAC1C;IAED,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["// Dependencies\nimport { request } from 'https';\n\n// Map helper\nimport { getMapInstance, getDataWithAction } from './map';\n\n// constants\nimport { actions, nonWritableMethods } from './constants';\n\n// Properties\nconst { DELETE_CT } = actions;\n\nexport default ({\n hostname,\n path,\n headers,\n method,\n id,\n action,\n}: {\n hostname: string;\n path: string;\n headers: any;\n method: string;\n id: string;\n action: string;\n}) => {\n let options: any = {\n hostname,\n path,\n headers,\n method,\n id,\n action,\n };\n return (_data: any) => {\n // get data here using id and action\n let data = getData(_data, id, action, method);\n // Special handling for non writable methods\n options = getNewOptions(options, data, action, method);\n\n return new Promise((resolve, reject) => {\n const req = request(options, (res) => {\n let response = '';\n\n res.on('data', (_res) => {\n response += _res.toString();\n });\n\n res.on('end', () => {\n try {\n response = JSON.parse(response);\n resolve(response);\n } catch (err) {\n reject('Error while parsing response!');\n // throw new Error('Error while parsing response!');\n }\n });\n });\n\n req.on('error', (err) => {\n reject(err);\n });\n\n !nonWritableMethods.includes(method) && req.write(data);\n req.end();\n });\n };\n};\n\nfunction getData(_data: any, id: string, action: string, method: string): string | undefined {\n if (method === 'GET') return;\n // if (!nonWritableMethods.includes(method)) {\n let mapInstance = getMapInstance();\n\n let data = _data ? _data : getDataWithAction(id, mapInstance, action);\n return JSON.stringify(data);\n}\n\nfunction getNewOptions(options: any, data: string | undefined, action: string, method: string): any {\n // Special handling for delete method\n if (action === DELETE_CT) {\n try {\n data = JSON.parse(data as string);\n } catch (err) {\n throw 'Error while parsing data for delete operation';\n }\n options.path = `${options.path}?force=${(data as any).content_type.force}`;\n }\n\n if (!nonWritableMethods.includes(method) && data) {\n options.headers['Content-Length'] = data.length;\n } else {\n delete options.headers['Content-Type'];\n delete options.headers['Content-Length'];\n }\n\n return options;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"safe-promise.js","sourceRoot":"","sources":["../../src/utils/safe-promise.ts"],"names":[],"mappings":";;AAAA,kBAAe,CAAC,OAAqB,EAAgC,EAAE;IACrE,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,CAAgB,CAAC,CAAC,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,IAAI,CAAkB,CAAC,CAAC;AAClH,CAAC,CAAC","sourcesContent":["export default (promise: Promise<any>): Promise<[Error | null, any]> => {\n return promise.then((res: any) => [null, res] as [null, any]).catch((err: any) => [err, null] as [Error, null]);\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const getUid: (data: string) => string;
|
|
2
|
+
export declare const getMandatoryVal: (data: string) => boolean;
|
|
3
|
+
export declare const getUniqueVal: (data: string) => boolean;
|
|
4
|
+
export declare const getFieldMetaData: (data: string) => any;
|
|
5
|
+
export declare const getSchema: (field: string, subAction: string) => any;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSchema = exports.getFieldMetaData = exports.getUniqueVal = exports.getMandatoryVal = exports.getUid = void 0;
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const getUid = (data) => data.split(' ').join('_').toLowerCase();
|
|
7
|
+
exports.getUid = getUid;
|
|
8
|
+
const getMandatoryVal = (data) => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';
|
|
9
|
+
exports.getMandatoryVal = getMandatoryVal;
|
|
10
|
+
const getUniqueVal = (data) => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';
|
|
11
|
+
exports.getUniqueVal = getUniqueVal;
|
|
12
|
+
const getFieldMetaData = (data) => {
|
|
13
|
+
return {
|
|
14
|
+
_default: (0, exports.getMandatoryVal)(data),
|
|
15
|
+
version: constants_1.version,
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
exports.getFieldMetaData = getFieldMetaData;
|
|
19
|
+
const getSchema = (field, subAction) => {
|
|
20
|
+
const { EDIT_FIELD, DELETE_FIELD } = constants_1.actions;
|
|
21
|
+
const schema = {
|
|
22
|
+
display_name: field,
|
|
23
|
+
uid: (0, exports.getUid)(field),
|
|
24
|
+
data_type: constants_1.defaultDataType,
|
|
25
|
+
mandatory: (0, exports.getMandatoryVal)(field),
|
|
26
|
+
unique: (0, exports.getUniqueVal)(field),
|
|
27
|
+
field_metadata: (0, exports.getFieldMetaData)(field),
|
|
28
|
+
non_localizable: false,
|
|
29
|
+
// isDelete: !!isDelete,
|
|
30
|
+
isDelete: subAction === DELETE_FIELD,
|
|
31
|
+
isEdit: subAction === EDIT_FIELD,
|
|
32
|
+
};
|
|
33
|
+
return schema;
|
|
34
|
+
};
|
|
35
|
+
exports.getSchema = getSchema;
|
|
36
|
+
//# sourceMappingURL=schema-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-helper.js","sourceRoot":"","sources":["../../src/utils/schema-helper.ts"],"names":[],"mappings":";;;AAAA,8BAA8B;AAC9B,2CAAgE;AAEzD,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AAA3E,QAAA,MAAM,UAAqE;AAEjF,MAAM,eAAe,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;AAA5G,QAAA,eAAe,mBAA6F;AAElH,MAAM,YAAY,GAAG,CAAC,IAAY,EAAW,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,OAAO,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;AAAzG,QAAA,YAAY,gBAA6F;AAE/G,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAAO,EAAE;IACpD,OAAO;QACL,QAAQ,EAAE,IAAA,uBAAe,EAAC,IAAI,CAAC;QAC/B,OAAO,EAAP,mBAAO;KACR,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,gBAAgB,oBAK3B;AAEK,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,SAAiB,EAAO,EAAE;IACjE,MAAM,EAAE,UAAU,EAAE,YAAY,EAAE,GAAG,mBAAO,CAAC;IAE7C,MAAM,MAAM,GAAG;QACb,YAAY,EAAE,KAAK;QACnB,GAAG,EAAE,IAAA,cAAM,EAAC,KAAK,CAAC;QAClB,SAAS,EAAE,2BAAe;QAC1B,SAAS,EAAE,IAAA,uBAAe,EAAC,KAAK,CAAC;QACjC,MAAM,EAAE,IAAA,oBAAY,EAAC,KAAK,CAAC;QAC3B,cAAc,EAAE,IAAA,wBAAgB,EAAC,KAAK,CAAC;QACvC,eAAe,EAAE,KAAK;QACtB,wBAAwB;QACxB,QAAQ,EAAE,SAAS,KAAK,YAAY;QACpC,MAAM,EAAE,SAAS,KAAK,UAAU;KACjC,CAAC;IACF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAhBW,QAAA,SAAS,aAgBpB","sourcesContent":["/* eslint-disable camelcase */\nimport { version, defaultDataType, actions } from './constants';\n\nexport const getUid = (data: string): string => data.split(' ').join('_').toLowerCase();\n\nexport const getMandatoryVal = (data: string): boolean => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';\n\nexport const getUniqueVal = (data: string): boolean => data.toLowerCase() === 'title' || data.toLowerCase() === 'url';\n\nexport const getFieldMetaData = (data: string): any => {\n return {\n _default: getMandatoryVal(data),\n version,\n };\n};\n\nexport const getSchema = (field: string, subAction: string): any => {\n const { EDIT_FIELD, DELETE_FIELD } = actions;\n\n const schema = {\n display_name: field,\n uid: getUid(field),\n data_type: defaultDataType, // This will be overridden if user specifies data type\n mandatory: getMandatoryVal(field),\n unique: getUniqueVal(field),\n field_metadata: getFieldMetaData(field),\n non_localizable: false,\n // isDelete: !!isDelete,\n isDelete: subAction === DELETE_FIELD,\n isEdit: subAction === EDIT_FIELD,\n };\n return schema;\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const logger_1 = require("./logger");
|
|
4
|
+
exports.default = (data, type, method) => {
|
|
5
|
+
if (data && type && method) {
|
|
6
|
+
//success(`Successfully ${successMessageHandler[method]} ${type}: ${data}`);
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
(0, logger_1.success)(`${type} successfully completed`);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=success-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"success-handler.js","sourceRoot":"","sources":["../../src/utils/success-handler.ts"],"names":[],"mappings":";;AAAA,qCAAmC;AAGnC,kBAAe,CAAC,IAAS,EAAE,IAAY,EAAE,MAAc,EAAQ,EAAE;IAC/D,IAAI,IAAI,IAAI,IAAI,IAAI,MAAM,EAAE;QAC1B,4EAA4E;KAC7E;SAAM;QACL,IAAA,gBAAO,EAAC,GAAG,IAAI,yBAAyB,CAAC,CAAC;KAC3C;AACH,CAAC,CAAC","sourcesContent":["import { success } from './logger';\nimport { successMessageHandler } from './constants';\n\nexport default (data: any, type: string, method: string): void => {\n if (data && type && method) {\n //success(`Successfully ${successMessageHandler[method]} ${type}: ${data}`);\n } else {\n success(`${type} successfully completed`);\n }\n};\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class ApiError {
|
|
4
|
+
validate(data) {
|
|
5
|
+
if (data.payload.apiError) {
|
|
6
|
+
return [
|
|
7
|
+
Object.assign(Object.assign({}, data), { message: `${data.payload.apiError.error_message}` }),
|
|
8
|
+
];
|
|
9
|
+
}
|
|
10
|
+
return [];
|
|
11
|
+
}
|
|
12
|
+
isApplicable(action) {
|
|
13
|
+
return action.type === 'apiError';
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.default = ApiError;
|
|
17
|
+
//# sourceMappingURL=api-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-error.js","sourceRoot":"","sources":["../../src/validators/api-error.ts"],"names":[],"mappings":";;AAAA,MAAqB,QAAQ;IAC3B,QAAQ,CAAC,IAAS;QAChB,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE;YACzB,OAAO;gDAEA,IAAI,KACP,OAAO,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,EAAE;aAEpD,CAAC;SACH;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,YAAY,CAAC,MAAW;QACtB,OAAO,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC;IACpC,CAAC;CACF;AAhBD,2BAgBC","sourcesContent":["export default class ApiError {\n validate(data: any): any[] {\n if (data.payload.apiError) {\n return [\n {\n ...data,\n message: `${data.payload.apiError.error_message}`,\n },\n ];\n }\n return [];\n }\n\n isApplicable(action: any): boolean {\n return action.type === 'apiError';\n }\n}\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class BaseValidator {
|
|
4
|
+
commonValidate(properties, data) {
|
|
5
|
+
const errors = [];
|
|
6
|
+
const opts = data.payload.options;
|
|
7
|
+
const dataKeys = Object.keys(opts);
|
|
8
|
+
for (let i = 0; i < properties.length; i++) {
|
|
9
|
+
let prop = properties[i];
|
|
10
|
+
// Check if property is mandatory but not present in user specified params
|
|
11
|
+
if (prop.mandatory && !dataKeys.includes(prop.name)) {
|
|
12
|
+
errors.push(Object.assign(Object.assign({}, data), { message: `${prop.name} is required.` }));
|
|
13
|
+
}
|
|
14
|
+
if (prop.name in opts) {
|
|
15
|
+
const dataType = this.getDataType(opts[prop.name]);
|
|
16
|
+
if (dataType !== prop.type) {
|
|
17
|
+
errors.push(Object.assign(Object.assign({}, data), { message: `${prop.name} is a ${dataType} type` }));
|
|
18
|
+
}
|
|
19
|
+
if (prop.dependsOn && !(prop.dependsOn in opts) && opts[prop.name]) {
|
|
20
|
+
errors.push(Object.assign(Object.assign({}, data), { message: `${prop.dependsOn} is required with ${prop.name}` }));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return errors;
|
|
25
|
+
}
|
|
26
|
+
getDataType(data) {
|
|
27
|
+
if (Array.isArray(data)) {
|
|
28
|
+
return 'array';
|
|
29
|
+
}
|
|
30
|
+
return typeof data;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.default = BaseValidator;
|
|
34
|
+
//# sourceMappingURL=base-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-validator.js","sourceRoot":"","sources":["../../src/validators/base-validator.ts"],"names":[],"mappings":";;AAAA,MAAqB,aAAa;IAChC,cAAc,CAAC,UAAiB,EAAE,IAAS;QACzC,MAAM,MAAM,GAAU,EAAE,CAAC;QACzB,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC;QAClC,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEnC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC1C,IAAI,IAAI,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;YACzB,0EAA0E;YAC1E,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACnD,MAAM,CAAC,IAAI,iCAAM,IAAI,KAAE,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,eAAe,IAAG,CAAC;aAChE;YAED,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,EAAE;gBACrB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBACnD,IAAI,QAAQ,KAAK,IAAI,CAAC,IAAI,EAAE;oBAC1B,MAAM,CAAC,IAAI,iCAAM,IAAI,KAAE,OAAO,EAAE,GAAG,IAAI,CAAC,IAAI,SAAS,QAAQ,OAAO,IAAG,CAAC;iBACzE;gBAED,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;oBAClE,MAAM,CAAC,IAAI,iCAAM,IAAI,KAAE,OAAO,EAAE,GAAG,IAAI,CAAC,SAAS,qBAAqB,IAAI,CAAC,IAAI,EAAE,IAAG,CAAC;iBACtF;aACF;SACF;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,WAAW,CAAC,IAAS;QACnB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,OAAO,OAAO,CAAC;SAChB;QACD,OAAO,OAAO,IAAI,CAAC;IACrB,CAAC;CACF;AAlCD,gCAkCC","sourcesContent":["export default class BaseValidator {\n commonValidate(properties: any[], data: any): any[] {\n const errors: any[] = [];\n const opts = data.payload.options;\n const dataKeys = Object.keys(opts);\n\n for (let i = 0; i < properties.length; i++) {\n let prop = properties[i];\n // Check if property is mandatory but not present in user specified params\n if (prop.mandatory && !dataKeys.includes(prop.name)) {\n errors.push({ ...data, message: `${prop.name} is required.` });\n }\n\n if (prop.name in opts) {\n const dataType = this.getDataType(opts[prop.name]);\n if (dataType !== prop.type) {\n errors.push({ ...data, message: `${prop.name} is a ${dataType} type` });\n }\n\n if (prop.dependsOn && !(prop.dependsOn in opts) && opts[prop.name]) {\n errors.push({ ...data, message: `${prop.dependsOn} is required with ${prop.name}` });\n }\n }\n }\n\n return errors;\n }\n\n getDataType(data: any): string {\n if (Array.isArray(data)) {\n return 'array';\n }\n return typeof data;\n }\n}\n"]}
|