@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,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
/* eslint-disable unicorn/explicit-length-check */
|
|
5
|
+
/* eslint-disable no-unused-expressions */
|
|
6
|
+
const base_1 = tslib_1.__importDefault(require("../modules/base"));
|
|
7
|
+
// Utils
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
// Map methods
|
|
10
|
+
const { get, getMapInstance, getDataWithAction } = utils_1.map;
|
|
11
|
+
const mapInstance = getMapInstance();
|
|
12
|
+
const { ContentType, MANAGEMENT_SDK, actions: _actions } = utils_1.constants;
|
|
13
|
+
class ContentTypeService {
|
|
14
|
+
constructor() {
|
|
15
|
+
// Stores actions required for moveField function
|
|
16
|
+
this.moveFieldActions = [];
|
|
17
|
+
this.base = new base_1.default();
|
|
18
|
+
this.stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);
|
|
19
|
+
}
|
|
20
|
+
async fetchContentType(callsite, id) {
|
|
21
|
+
const method = 'GET';
|
|
22
|
+
const [err, result] = await (0, utils_1.safePromise)(this.stackSDKInstance.contentType(id).fetch());
|
|
23
|
+
if (err) {
|
|
24
|
+
(0, utils_1.errorHelper)(err);
|
|
25
|
+
this.base.dispatch(callsite, id, err, 'apiError');
|
|
26
|
+
throw err;
|
|
27
|
+
}
|
|
28
|
+
(0, utils_1.successHandler)(id, ContentType, method);
|
|
29
|
+
return result || {};
|
|
30
|
+
}
|
|
31
|
+
async postContentTypes(callsite, id, action) {
|
|
32
|
+
const data = getDataWithAction(id, mapInstance, action);
|
|
33
|
+
const [err, result] = await (0, utils_1.safePromise)(this.stackSDKInstance.contentType().create(data));
|
|
34
|
+
if (err) {
|
|
35
|
+
(0, utils_1.errorHelper)(err);
|
|
36
|
+
this.base.dispatch(callsite, id, err, 'apiError');
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
(0, utils_1.successHandler)(id, ContentType, 'POST');
|
|
40
|
+
return result.content_type || {};
|
|
41
|
+
}
|
|
42
|
+
async editContentType(callsite, data) {
|
|
43
|
+
const d = getDataWithAction(data.uid, mapInstance, _actions.EDIT_CT);
|
|
44
|
+
data = Object.assign(Object.assign({}, data), d.content_type);
|
|
45
|
+
const method = 'PUT';
|
|
46
|
+
const [err, result] = await (0, utils_1.safePromise)(data.update());
|
|
47
|
+
if (err) {
|
|
48
|
+
(0, utils_1.errorHelper)(err);
|
|
49
|
+
this.base.dispatch(callsite, data.uid, err, 'apiError');
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
(0, utils_1.successHandler)(data.uid, ContentType, method);
|
|
53
|
+
return result.content_type || {};
|
|
54
|
+
}
|
|
55
|
+
async deleteContentType(callsite) {
|
|
56
|
+
const { id } = this;
|
|
57
|
+
const method = 'DELETE';
|
|
58
|
+
const [err, result] = await (0, utils_1.safePromise)(this.stackSDKInstance.contentType(id).delete());
|
|
59
|
+
if (err) {
|
|
60
|
+
(0, utils_1.errorHelper)(err);
|
|
61
|
+
this.base.dispatch(callsite, id, err, 'apiError');
|
|
62
|
+
throw err;
|
|
63
|
+
}
|
|
64
|
+
(0, utils_1.successHandler)(id, ContentType, method);
|
|
65
|
+
return result.content_type || {};
|
|
66
|
+
}
|
|
67
|
+
applyActionsOnFields(callsite, data, cb) {
|
|
68
|
+
const { schema } = data;
|
|
69
|
+
const { moveFieldActions, mergeEditSchema } = this;
|
|
70
|
+
let i = 0;
|
|
71
|
+
let finalSchema;
|
|
72
|
+
try {
|
|
73
|
+
finalSchema = mergeEditSchema.call(this, schema);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
this.base.dispatch(callsite, null, error, 'field');
|
|
77
|
+
// Call the callback with error
|
|
78
|
+
if (typeof cb === 'function')
|
|
79
|
+
return cb(error);
|
|
80
|
+
}
|
|
81
|
+
data.schema = finalSchema;
|
|
82
|
+
// Handle for no move field action required
|
|
83
|
+
if (!moveFieldActions.length)
|
|
84
|
+
return cb ? cb(null, data) : data;
|
|
85
|
+
// eslint-disable-next-line
|
|
86
|
+
while (true) {
|
|
87
|
+
/** VALIDATIONS */
|
|
88
|
+
const validResult = this.getValidated(finalSchema, moveFieldActions[i]);
|
|
89
|
+
if (!validResult.isValid) {
|
|
90
|
+
const error = { message: `${validResult.missingField} does not exist in schema.` };
|
|
91
|
+
this.base.dispatch(callsite, null, error, 'field');
|
|
92
|
+
// Call the callback with error
|
|
93
|
+
if (typeof cb === 'function')
|
|
94
|
+
return cb(error);
|
|
95
|
+
}
|
|
96
|
+
finalSchema = this[moveFieldActions[i].action](finalSchema, moveFieldActions[i]);
|
|
97
|
+
i++;
|
|
98
|
+
if (!moveFieldActions[i])
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
data.schema = finalSchema;
|
|
102
|
+
if (cb)
|
|
103
|
+
return cb(null, data);
|
|
104
|
+
return data;
|
|
105
|
+
}
|
|
106
|
+
getActions(action) {
|
|
107
|
+
this.moveFieldActions.push(action);
|
|
108
|
+
}
|
|
109
|
+
// Sets id and action for this instance
|
|
110
|
+
setIdAndAction(id, action) {
|
|
111
|
+
this.id = id;
|
|
112
|
+
this.action = action;
|
|
113
|
+
}
|
|
114
|
+
// Merges the user specified with new fields with existing schema
|
|
115
|
+
mergeEditSchema(schema = []) {
|
|
116
|
+
const _mapInstance = getMapInstance();
|
|
117
|
+
const { id, action } = this;
|
|
118
|
+
const contentType = get(id, _mapInstance);
|
|
119
|
+
if (!contentType || !contentType[action]) {
|
|
120
|
+
throw { message: 'Content type not found in map' };
|
|
121
|
+
}
|
|
122
|
+
let contentTypeSchema = contentType[action].content_type.schema;
|
|
123
|
+
contentTypeSchema = contentTypeSchema || [];
|
|
124
|
+
const indicesToRemoveFromNewSchema = [];
|
|
125
|
+
const indicesToRemoveFromOldSchema = [];
|
|
126
|
+
let isEditFieldValid = false;
|
|
127
|
+
let isEditFieldPresent = false;
|
|
128
|
+
let isDeleteFieldValid = false;
|
|
129
|
+
let isDeleteFieldPresent = false;
|
|
130
|
+
let fieldToRaiseExceptionAgainst;
|
|
131
|
+
if (contentTypeSchema.length > 0 && schema.length > 0) {
|
|
132
|
+
// If found a updated field replace the new field with the existing field
|
|
133
|
+
contentTypeSchema.forEach((newSchema, i) => {
|
|
134
|
+
schema.every((oldSchema, j) => {
|
|
135
|
+
/** VALIDATIONS */
|
|
136
|
+
if (newSchema.isEdit) {
|
|
137
|
+
isEditFieldPresent = true;
|
|
138
|
+
fieldToRaiseExceptionAgainst = newSchema.uid;
|
|
139
|
+
newSchema.uid === oldSchema.uid && (isEditFieldValid = true);
|
|
140
|
+
}
|
|
141
|
+
if (newSchema.isDelete) {
|
|
142
|
+
isDeleteFieldPresent = true;
|
|
143
|
+
fieldToRaiseExceptionAgainst = newSchema.uid;
|
|
144
|
+
newSchema.uid === oldSchema.uid && (isDeleteFieldValid = true);
|
|
145
|
+
}
|
|
146
|
+
/** VALIDATIONS ENDS */
|
|
147
|
+
if (newSchema.uid === oldSchema.uid) {
|
|
148
|
+
let tempObj = newSchema;
|
|
149
|
+
indicesToRemoveFromNewSchema.push(i);
|
|
150
|
+
// Handle delete action here
|
|
151
|
+
if (newSchema.isDelete) {
|
|
152
|
+
indicesToRemoveFromOldSchema.push(j);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
schema.splice(j, 1, tempObj); // Replace the new schema with old schema
|
|
156
|
+
}
|
|
157
|
+
// break
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
// continue
|
|
161
|
+
return true;
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
// Raise exception if any of the following conditions are true
|
|
166
|
+
if ((isEditFieldPresent && !isEditFieldValid) || (isDeleteFieldPresent && !isDeleteFieldValid)) {
|
|
167
|
+
throw { message: `${fieldToRaiseExceptionAgainst} does not exist in the schema. Please check again` };
|
|
168
|
+
}
|
|
169
|
+
contentTypeSchema = contentTypeSchema.filter((_, i) => !indicesToRemoveFromNewSchema.includes(i));
|
|
170
|
+
schema = schema.filter((_, i) => !indicesToRemoveFromOldSchema.includes(i));
|
|
171
|
+
schema = schema.concat(contentTypeSchema);
|
|
172
|
+
contentType[action].content_type.schema = schema;
|
|
173
|
+
return schema;
|
|
174
|
+
}
|
|
175
|
+
toTheTop(schema, actionObj) {
|
|
176
|
+
const { fieldToMove } = actionObj;
|
|
177
|
+
let i = 0;
|
|
178
|
+
// eslint-disable-next-line
|
|
179
|
+
while (true) {
|
|
180
|
+
if (!schema[i])
|
|
181
|
+
break;
|
|
182
|
+
if (schema[i].uid === fieldToMove) {
|
|
183
|
+
let tempObj = schema[i];
|
|
184
|
+
schema.splice(i, 1);
|
|
185
|
+
schema.unshift(tempObj);
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
i++;
|
|
189
|
+
}
|
|
190
|
+
return schema;
|
|
191
|
+
}
|
|
192
|
+
toTheBottom(schema, actionObj) {
|
|
193
|
+
const { fieldToMove } = actionObj;
|
|
194
|
+
let i = 0;
|
|
195
|
+
// eslint-disable-next-line
|
|
196
|
+
while (true) {
|
|
197
|
+
if (!schema[i])
|
|
198
|
+
break;
|
|
199
|
+
if (schema[i].uid === fieldToMove) {
|
|
200
|
+
let tempObj = schema[i];
|
|
201
|
+
schema.splice(i, 1);
|
|
202
|
+
schema.push(tempObj);
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
i++;
|
|
206
|
+
}
|
|
207
|
+
return schema;
|
|
208
|
+
}
|
|
209
|
+
afterField(schema, actionObj) {
|
|
210
|
+
const { fieldToMove, against } = actionObj;
|
|
211
|
+
let i = 0;
|
|
212
|
+
let indexToMove = 0;
|
|
213
|
+
let tempObj;
|
|
214
|
+
let found = 0;
|
|
215
|
+
// eslint-disable-next-line
|
|
216
|
+
while (true) {
|
|
217
|
+
if (!schema[i])
|
|
218
|
+
break;
|
|
219
|
+
if (schema[i].uid === against) {
|
|
220
|
+
indexToMove = i;
|
|
221
|
+
found++;
|
|
222
|
+
}
|
|
223
|
+
if (schema[i].uid === fieldToMove) {
|
|
224
|
+
tempObj = schema[i];
|
|
225
|
+
schema.splice(i, 1);
|
|
226
|
+
found++;
|
|
227
|
+
}
|
|
228
|
+
i++;
|
|
229
|
+
if (found === 2)
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
// TODO: Handle error
|
|
233
|
+
found === 2 && schema.splice(indexToMove + 1, null, tempObj);
|
|
234
|
+
return schema;
|
|
235
|
+
}
|
|
236
|
+
beforeField(schema, actionObj) {
|
|
237
|
+
const { fieldToMove, against } = actionObj;
|
|
238
|
+
let i = 0;
|
|
239
|
+
let indexToMove = 0;
|
|
240
|
+
let tempObj = 0;
|
|
241
|
+
let found = 0;
|
|
242
|
+
// eslint-disable-next-line
|
|
243
|
+
while (true) {
|
|
244
|
+
if (!schema[i])
|
|
245
|
+
break;
|
|
246
|
+
if (schema[i].uid === against) {
|
|
247
|
+
indexToMove = i;
|
|
248
|
+
found++;
|
|
249
|
+
}
|
|
250
|
+
if (schema[i].uid === fieldToMove) {
|
|
251
|
+
tempObj = schema[i];
|
|
252
|
+
schema.splice(i, 1);
|
|
253
|
+
found++;
|
|
254
|
+
}
|
|
255
|
+
i++;
|
|
256
|
+
if (found === 2)
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
found === 2 && schema.splice(indexToMove, null, tempObj);
|
|
260
|
+
return schema;
|
|
261
|
+
}
|
|
262
|
+
getValidated(schema, actionObj) {
|
|
263
|
+
let isValid = true;
|
|
264
|
+
let found = 0;
|
|
265
|
+
let missingField = '';
|
|
266
|
+
let i = 0;
|
|
267
|
+
const { fieldToMove, against } = actionObj;
|
|
268
|
+
const uids = [];
|
|
269
|
+
// Handle empty schema case
|
|
270
|
+
if (!schema || schema.length === 0) {
|
|
271
|
+
return {
|
|
272
|
+
isValid: false,
|
|
273
|
+
missingField: fieldToMove,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
// eslint-disable-next-line
|
|
277
|
+
while (true) {
|
|
278
|
+
if (!schema[i])
|
|
279
|
+
break;
|
|
280
|
+
uids.push(schema[i].uid);
|
|
281
|
+
if (schema[i].uid === fieldToMove) {
|
|
282
|
+
found++;
|
|
283
|
+
}
|
|
284
|
+
if (against === schema[i].uid) {
|
|
285
|
+
found++;
|
|
286
|
+
}
|
|
287
|
+
i++;
|
|
288
|
+
}
|
|
289
|
+
// TODO: Need a better way to handle this
|
|
290
|
+
missingField = uids.includes(fieldToMove) ? null : fieldToMove;
|
|
291
|
+
if (!missingField && against) {
|
|
292
|
+
missingField = uids.includes(against) ? null : against;
|
|
293
|
+
}
|
|
294
|
+
// Handling both the scenarios
|
|
295
|
+
if (found === 0 || (against && found === 1)) {
|
|
296
|
+
isValid = false;
|
|
297
|
+
}
|
|
298
|
+
return { isValid, missingField };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
exports.default = ContentTypeService;
|
|
302
|
+
//# sourceMappingURL=content-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-types.js","sourceRoot":"","sources":["../../src/services/content-types.ts"],"names":[],"mappings":";;;AAAA,kDAAkD;AAClD,0CAA0C;AAC1C,mEAAmC;AACnC,QAAQ;AACR,oCAA4F;AAC5F,cAAc;AACd,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,iBAAiB,EAAE,GAAG,WAAI,CAAC;AACxD,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;AACrC,MAAM,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,iBAAS,CAAC;AAErE,MAAqB,kBAAkB;IAOrC;QACE,iDAAiD;QACjD,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,cAAI,EAAE,CAAC;QACvB,IAAI,CAAC,gBAAgB,GAAG,GAAG,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;IAC3D,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,QAAa,EAAE,EAAU;QAC9C,MAAM,MAAM,GAAG,KAAK,CAAC;QAErB,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,MAAM,IAAA,mBAAW,EAAC,IAAI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IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE;YAClC,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,YAAY,EAAE,WAAW;aAC1B,CAAC;SACH;QAED,2BAA2B;QAC3B,OAAO,IAAI,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;gBAAE,MAAM;YACtB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAEzB,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,WAAW,EAAE;gBACjC,KAAK,EAAE,CAAC;aACT;YACD,IAAI,OAAO,KAAK,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE;gBAC7B,KAAK,EAAE,CAAC;aACT;YACD,CAAC,EAAE,CAAC;SACL;QACD,yCAAyC;QACzC,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;QAE/D,IAAI,CAAC,YAAY,IAAI,OAAO,EAAE;YAC5B,YAAY,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;SACxD;QAED,8BAA8B;QAC9B,IAAI,KAAK,KAAK,CAAC,IAAI,CAAC,OAAO,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE;YAC3C,OAAO,GAAG,KAAK,CAAC;SACjB;QAED,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;IACnC,CAAC;CACF;AAjUD,qCAiUC","sourcesContent":["/* eslint-disable unicorn/explicit-length-check */\n/* eslint-disable no-unused-expressions */\nimport Base from '../modules/base';\n// Utils\nimport { map as _map, safePromise, successHandler, constants, errorHelper } from '../utils';\n// Map methods\nconst { get, getMapInstance, getDataWithAction } = _map;\nconst mapInstance = getMapInstance();\nconst { ContentType, MANAGEMENT_SDK, actions: _actions } = constants;\n\nexport default class ContentTypeService {\n moveFieldActions: any[];\n base: Base;\n stackSDKInstance: any;\n id: string | undefined;\n action: string | undefined;\n\n constructor() {\n // Stores actions required for moveField function\n this.moveFieldActions = [];\n this.base = new Base();\n this.stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);\n }\n\n async fetchContentType(callsite: any, id: string): Promise<any> {\n const method = 'GET';\n\n const [err, result] = await safePromise(this.stackSDKInstance.contentType(id).fetch());\n if (err) {\n errorHelper(err);\n this.base.dispatch(callsite, id, err, 'apiError');\n throw err;\n }\n successHandler(id, ContentType, method);\n\n return result || {};\n }\n\n async postContentTypes(callsite: any, id: string, action: string): Promise<any> {\n const data = getDataWithAction(id, mapInstance, action);\n const [err, result] = await safePromise(this.stackSDKInstance.contentType().create(data));\n if (err) {\n errorHelper(err);\n this.base.dispatch(callsite, id, err, 'apiError');\n throw err;\n }\n\n successHandler(id, ContentType, 'POST');\n return result.content_type || {};\n }\n\n async editContentType(callsite: any, data: any): Promise<any> {\n const d = getDataWithAction(data.uid, mapInstance, _actions.EDIT_CT);\n data = { ...data, ...d.content_type };\n const method = 'PUT';\n const [err, result] = await safePromise(data.update());\n if (err) {\n errorHelper(err);\n this.base.dispatch(callsite, data.uid, err, 'apiError');\n throw err;\n }\n\n successHandler(data.uid, ContentType, method);\n return result.content_type || {};\n }\n\n async deleteContentType(callsite: any): Promise<any> {\n const { id } = this;\n const method = 'DELETE';\n const [err, result] = await safePromise(this.stackSDKInstance.contentType(id as string).delete());\n\n if (err) {\n errorHelper(err);\n this.base.dispatch(callsite, id as string, err, 'apiError');\n throw err;\n }\n successHandler(id as string, ContentType, method);\n return result.content_type || {};\n }\n\n applyActionsOnFields(callsite: any, data: any, cb?: (err: any, data?: any) => void): any {\n const { schema } = data;\n const { moveFieldActions, mergeEditSchema } = this;\n let i = 0;\n let finalSchema: any;\n try {\n finalSchema = mergeEditSchema.call(this, schema);\n } catch (error) {\n this.base.dispatch(callsite, null, error, 'field');\n // Call the callback with error\n if (typeof cb === 'function') return cb(error);\n }\n data.schema = finalSchema;\n // Handle for no move field action required\n if (!moveFieldActions.length) return cb ? cb(null, data) : data;\n // eslint-disable-next-line\n while (true) {\n /** VALIDATIONS */\n const validResult = this.getValidated(finalSchema, moveFieldActions[i]);\n if (!validResult.isValid) {\n const error = { message: `${validResult.missingField} does not exist in schema.` };\n this.base.dispatch(callsite, null, error, 'field');\n // Call the callback with error\n if (typeof cb === 'function') return cb(error);\n }\n\n finalSchema = (this as any)[moveFieldActions[i].action](finalSchema, moveFieldActions[i]);\n i++;\n if (!moveFieldActions[i]) break;\n }\n data.schema = finalSchema;\n if (cb) return cb(null, data);\n return data;\n }\n\n getActions(action: any): void {\n this.moveFieldActions.push(action);\n }\n\n // Sets id and action for this instance\n setIdAndAction(id: string, action: string): void {\n this.id = id;\n this.action = action;\n }\n\n // Merges the user specified with new fields with existing schema\n mergeEditSchema(schema: any[] = []): any[] {\n const _mapInstance = getMapInstance();\n\n const { id, action } = this;\n\n const contentType = get(id as string, _mapInstance);\n \n if (!contentType || !contentType[action as string]) {\n throw { message: 'Content type not found in map' };\n }\n\n let contentTypeSchema = contentType[action as string].content_type.schema;\n contentTypeSchema = contentTypeSchema || [];\n\n const indicesToRemoveFromNewSchema: number[] = [];\n const indicesToRemoveFromOldSchema: number[] = [];\n\n let isEditFieldValid = false;\n let isEditFieldPresent = false;\n let isDeleteFieldValid = false;\n let isDeleteFieldPresent = false;\n let fieldToRaiseExceptionAgainst: string | undefined;\n\n if (contentTypeSchema.length > 0 && schema.length > 0) {\n // If found a updated field replace the new field with the existing field\n contentTypeSchema.forEach((newSchema: any, i: number) => {\n schema.every((oldSchema: any, j: number) => {\n /** VALIDATIONS */\n if (newSchema.isEdit) {\n isEditFieldPresent = true;\n fieldToRaiseExceptionAgainst = newSchema.uid;\n newSchema.uid === oldSchema.uid && (isEditFieldValid = true);\n }\n\n if (newSchema.isDelete) {\n isDeleteFieldPresent = true;\n fieldToRaiseExceptionAgainst = newSchema.uid;\n\n newSchema.uid === oldSchema.uid && (isDeleteFieldValid = true);\n }\n /** VALIDATIONS ENDS */\n\n if (newSchema.uid === oldSchema.uid) {\n let tempObj = newSchema;\n indicesToRemoveFromNewSchema.push(i);\n // Handle delete action here\n if (newSchema.isDelete) {\n indicesToRemoveFromOldSchema.push(j);\n } else {\n schema.splice(j, 1, tempObj); // Replace the new schema with old schema\n }\n // break\n return false;\n }\n // continue\n return true;\n });\n });\n }\n\n // Raise exception if any of the following conditions are true\n if ((isEditFieldPresent && !isEditFieldValid) || (isDeleteFieldPresent && !isDeleteFieldValid)) {\n throw { message: `${fieldToRaiseExceptionAgainst} does not exist in the schema. Please check again` };\n }\n\n contentTypeSchema = contentTypeSchema.filter((_: any, i: number) => !indicesToRemoveFromNewSchema.includes(i));\n\n schema = schema.filter((_: any, i: number) => !indicesToRemoveFromOldSchema.includes(i));\n\n schema = schema.concat(contentTypeSchema);\n contentType[action as string].content_type.schema = schema;\n return schema;\n }\n\n toTheTop(schema: any[], actionObj: any): any[] {\n const { fieldToMove } = actionObj;\n let i = 0;\n // eslint-disable-next-line\n while (true) {\n if (!schema[i]) break;\n if (schema[i].uid === fieldToMove) {\n let tempObj = schema[i];\n schema.splice(i, 1);\n schema.unshift(tempObj);\n break;\n }\n i++;\n }\n return schema;\n }\n\n toTheBottom(schema: any[], actionObj: any): any[] {\n const { fieldToMove } = actionObj;\n\n let i = 0;\n // eslint-disable-next-line\n while (true) {\n if (!schema[i]) break;\n if (schema[i].uid === fieldToMove) {\n let tempObj = schema[i];\n schema.splice(i, 1);\n schema.push(tempObj);\n break;\n }\n i++;\n }\n return schema;\n }\n\n afterField(schema: any[], actionObj: any): any[] {\n const { fieldToMove, against } = actionObj;\n let i = 0;\n let indexToMove = 0;\n let tempObj: any;\n let found = 0;\n // eslint-disable-next-line\n while (true) {\n if (!schema[i]) break;\n if (schema[i].uid === against) {\n indexToMove = i;\n found++;\n }\n if (schema[i].uid === fieldToMove) {\n tempObj = schema[i];\n schema.splice(i, 1);\n found++;\n }\n i++;\n if (found === 2) break;\n }\n // TODO: Handle error\n found === 2 && schema.splice(indexToMove + 1, null, tempObj);\n return schema;\n }\n\n beforeField(schema: any[], actionObj: any): any[] {\n const { fieldToMove, against } = actionObj;\n\n let i = 0;\n let indexToMove = 0;\n let tempObj: any = 0;\n let found = 0;\n // eslint-disable-next-line\n while (true) {\n if (!schema[i]) break;\n if (schema[i].uid === against) {\n indexToMove = i;\n found++;\n }\n if (schema[i].uid === fieldToMove) {\n tempObj = schema[i];\n schema.splice(i, 1);\n found++;\n }\n i++;\n if (found === 2) break;\n }\n found === 2 && schema.splice(indexToMove, null, tempObj);\n return schema;\n }\n\n getValidated(schema: any[], actionObj: any): { isValid: boolean; missingField: string | null } {\n let isValid = true;\n let found = 0;\n let missingField: string | null = '';\n let i = 0;\n\n const { fieldToMove, against } = actionObj;\n const uids: string[] = [];\n \n // Handle empty schema case\n if (!schema || schema.length === 0) {\n return {\n isValid: false,\n missingField: fieldToMove,\n };\n }\n \n // eslint-disable-next-line\n while (true) {\n if (!schema[i]) break;\n uids.push(schema[i].uid);\n\n if (schema[i].uid === fieldToMove) {\n found++;\n }\n if (against === schema[i].uid) {\n found++;\n }\n i++;\n }\n // TODO: Need a better way to handle this\n missingField = uids.includes(fieldToMove) ? null : fieldToMove;\n\n if (!missingField && against) {\n missingField = uids.includes(against) ? null : against;\n }\n\n // Handling both the scenarios\n if (found === 0 || (against && found === 1)) {\n isValid = false;\n }\n\n return { isValid, missingField };\n }\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocaleService = exports.ContentTypeService = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const content_types_1 = tslib_1.__importDefault(require("./content-types"));
|
|
6
|
+
exports.ContentTypeService = content_types_1.default;
|
|
7
|
+
const locales_1 = tslib_1.__importDefault(require("./locales"));
|
|
8
|
+
exports.LocaleService = locales_1.default;
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;AAAA,4EAAiD;AAGxC,6BAHF,uBAAkB,CAGE;AAF3B,gEAAsC;AAET,wBAFtB,iBAAa,CAEsB","sourcesContent":["import ContentTypeService from './content-types';\nimport LocaleService from './locales';\n\nexport { ContentTypeService, LocaleService };\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// Utils
|
|
4
|
+
const utils_1 = require("../utils");
|
|
5
|
+
const { MANAGEMENT_SDK } = utils_1.constants;
|
|
6
|
+
const { get, getMapInstance } = utils_1.map;
|
|
7
|
+
const mapInstance = getMapInstance();
|
|
8
|
+
class LocaleService {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);
|
|
11
|
+
}
|
|
12
|
+
async getLocale() {
|
|
13
|
+
const [err, result] = await (0, utils_1.safePromise)(this.stackSDKInstance.locale().query().find());
|
|
14
|
+
if (err)
|
|
15
|
+
throw err;
|
|
16
|
+
let orderedResult = this.getOrderedResult(result);
|
|
17
|
+
return orderedResult;
|
|
18
|
+
}
|
|
19
|
+
getOrderedResult(result) {
|
|
20
|
+
if (result && result.items) {
|
|
21
|
+
const locales = result.items;
|
|
22
|
+
let i = 0;
|
|
23
|
+
let noEventTookPlace = 0; // counter which tracks if the list is sorted by fallback language
|
|
24
|
+
let len = locales.length;
|
|
25
|
+
const maxIterations = len * len * 2; // Prevent infinite loops
|
|
26
|
+
let iterations = 0;
|
|
27
|
+
// Circular loop (Time complexity => Order of n^2, complexity of splice op is ignored)
|
|
28
|
+
do {
|
|
29
|
+
iterations++;
|
|
30
|
+
if (iterations > maxIterations) {
|
|
31
|
+
// Break out to prevent infinite loop in case of circular references
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
i = (i % len) + 1;
|
|
35
|
+
noEventTookPlace++;
|
|
36
|
+
let correctedI = i - 1;
|
|
37
|
+
let a = locales[correctedI];
|
|
38
|
+
if (a.fallback_locale) {
|
|
39
|
+
let fallbackLangIndex = 0;
|
|
40
|
+
let currentLangIndex = 0;
|
|
41
|
+
for (let x = 0; x < len; x++) {
|
|
42
|
+
if (locales[x].code === a.code) {
|
|
43
|
+
currentLangIndex = x;
|
|
44
|
+
}
|
|
45
|
+
if (locales[x].code === a.fallback_locale) {
|
|
46
|
+
fallbackLangIndex = x;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
// if index of fallback langauge is smaller no operation is required, it might be sorted
|
|
50
|
+
if (currentLangIndex > fallbackLangIndex) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
let temp = a;
|
|
54
|
+
// remove the object
|
|
55
|
+
locales.splice(correctedI, 1);
|
|
56
|
+
// add the object at fallbackLangIndex cus size of locales is decremented
|
|
57
|
+
locales.splice(fallbackLangIndex, 0, temp);
|
|
58
|
+
i--;
|
|
59
|
+
noEventTookPlace--;
|
|
60
|
+
}
|
|
61
|
+
} while (noEventTookPlace < len);
|
|
62
|
+
return locales;
|
|
63
|
+
}
|
|
64
|
+
throw { message: 'Something went wrong.' };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = LocaleService;
|
|
68
|
+
//# sourceMappingURL=locales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.js","sourceRoot":"","sources":["../../src/services/locales.ts"],"names":[],"mappings":";;AAAA,QAAQ;AACR,oCAA+D;AAC/D,MAAM,EAAE,cAAc,EAAE,GAAG,iBAAS,CAAC;AACrC,MAAM,EAAE,GAAG,EAAE,cAAc,EAAE,GAAG,WAAI,CAAC;AACrC,MAAM,WAAW,GAAG,cAAc,EAAE,CAAC;AAErC,MAAqB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AG,CAAC,CAAC;oBAEzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;wBAC5B,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EAAE;4BAC9B,gBAAgB,GAAG,CAAC,CAAC;yBACtB;wBACD,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,eAAe,EAAE;4BACzC,iBAAiB,GAAG,CAAC,CAAC;yBACvB;qBACF;oBAED,wFAAwF;oBACxF,IAAI,gBAAgB,GAAG,iBAAiB,EAAE;wBACxC,SAAS;qBACV;oBACD,IAAI,IAAI,GAAG,CAAC,CAAC;oBACb,oBAAoB;oBACpB,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;oBAC9B,yEAAyE;oBACzE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;oBAC3C,CAAC,EAAE,CAAC;oBACJ,gBAAgB,EAAE,CAAC;iBACpB;aACF,QAAQ,gBAAgB,GAAG,GAAG,EAAE;YAEjC,OAAO,OAAO,CAAC;SAChB;QACD,MAAM,EAAE,OAAO,EAAE,uBAAuB,EAAE,CAAC;IAC7C,CAAC;CACF;AArED,gCAqEC","sourcesContent":["// Utils\nimport { safePromise, constants, map as _map } from '../utils';\nconst { MANAGEMENT_SDK } = constants;\nconst { get, getMapInstance } = _map;\nconst mapInstance = getMapInstance();\n\nexport default class LocaleService {\n stackSDKInstance: any;\n\n constructor() {\n this.stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);\n }\n\n async getLocale(): Promise<any[]> {\n const [err, result] = await safePromise(this.stackSDKInstance.locale().query().find());\n if (err) throw err;\n let orderedResult = this.getOrderedResult(result);\n return orderedResult;\n }\n\n getOrderedResult(result: any): any[] {\n if (result && result.items) {\n const locales = result.items;\n\n let i = 0;\n let noEventTookPlace = 0; // counter which tracks if the list is sorted by fallback language\n let len = locales.length;\n const maxIterations = len * len * 2; // Prevent infinite loops\n let iterations = 0;\n\n // Circular loop (Time complexity => Order of n^2, complexity of splice op is ignored)\n do {\n iterations++;\n if (iterations > maxIterations) {\n // Break out to prevent infinite loop in case of circular references\n break;\n }\n i = (i % len) + 1;\n noEventTookPlace++;\n\n let correctedI = i - 1;\n\n let a = locales[correctedI];\n\n if (a.fallback_locale) {\n let fallbackLangIndex = 0;\n let currentLangIndex = 0;\n\n for (let x = 0; x < len; x++) {\n if (locales[x].code === a.code) {\n currentLangIndex = x;\n }\n if (locales[x].code === a.fallback_locale) {\n fallbackLangIndex = x;\n }\n }\n\n // if index of fallback langauge is smaller no operation is required, it might be sorted\n if (currentLangIndex > fallbackLangIndex) {\n continue;\n }\n let temp = a;\n // remove the object\n locales.splice(correctedI, 1);\n // add the object at fallbackLangIndex cus size of locales is decremented\n locales.splice(fallbackLangIndex, 0, temp);\n i--;\n noEventTookPlace--;\n }\n } while (noEventTookPlace < len);\n\n return locales;\n }\n throw { message: 'Something went wrong.' };\n }\n}\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("./constants");
|
|
4
|
+
const __safePromise = (promise, data) => {
|
|
5
|
+
return promise(data)
|
|
6
|
+
.then((res) => [null, res])
|
|
7
|
+
.catch((err) => [err]);
|
|
8
|
+
};
|
|
9
|
+
async function autoRetry(promise, retryCount = 0, data) {
|
|
10
|
+
/**
|
|
11
|
+
* Entries functions needs to pass params directly to http object,
|
|
12
|
+
* whereas for content types it fetches request params from global map object,
|
|
13
|
+
* thus the handling
|
|
14
|
+
*/
|
|
15
|
+
let requestData;
|
|
16
|
+
if (data !== undefined) {
|
|
17
|
+
requestData = data;
|
|
18
|
+
}
|
|
19
|
+
const [error, result] = await __safePromise(promise, requestData);
|
|
20
|
+
if (error) {
|
|
21
|
+
retryCount++;
|
|
22
|
+
if (retryCount === constants_1.MAX_RETRY) {
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
return await autoRetry(promise, retryCount, data);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
exports.default = autoRetry;
|
|
30
|
+
//# sourceMappingURL=auto-retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-retry.js","sourceRoot":"","sources":["../../src/utils/auto-retry.ts"],"names":[],"mappings":";;AAAA,2CAAwC;AAExC,MAAM,aAAa,GAAG,CAAC,OAAY,EAAE,IAAS,EAAgC,EAAE;IAC9E,OAAO,OAAO,CAAC,IAAI,CAAC;SACjB,IAAI,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;SAC/B,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAChC,CAAC,CAAC;AAEF,KAAK,UAAU,SAAS,CAAC,OAAY,EAAE,aAAqB,CAAC,EAAE,IAAU;IACvE;;;;OAIG;IACH,IAAI,WAAgB,CAAC;IACrB,IAAI,IAAI,KAAK,SAAS,EAAE;QACtB,WAAW,GAAG,IAAI,CAAC;KACpB;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,MAAM,aAAa,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;IAElE,IAAI,KAAK,EAAE;QACT,UAAU,EAAE,CAAC;QACb,IAAI,UAAU,KAAK,qBAAS,EAAE;YAC5B,MAAM,KAAK,CAAC;SACb;QACD,OAAO,MAAM,SAAS,CAAC,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;KACnD;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,kBAAe,SAAS,CAAC","sourcesContent":["import { MAX_RETRY } from './constants';\n\nconst __safePromise = (promise: any, data: any): Promise<[Error | null, any]> => {\n return promise(data)\n .then((res: any) => [null, res])\n .catch((err: any) => [err]);\n};\n\nasync function autoRetry(promise: any, retryCount: number = 0, data?: any): Promise<any> {\n /**\n * Entries functions needs to pass params directly to http object,\n * whereas for content types it fetches request params from global map object,\n * thus the handling\n */\n let requestData: any;\n if (data !== undefined) {\n requestData = data;\n }\n\n const [error, result] = await __safePromise(promise, requestData);\n\n if (error) {\n retryCount++;\n if (retryCount === MAX_RETRY) {\n throw error;\n }\n return await autoRetry(promise, retryCount, data);\n }\n return result;\n}\n\nexport default autoRetry;\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const callsites_1 = tslib_1.__importDefault(require("callsites"));
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
|
+
function getFileDirectory(path) {
|
|
8
|
+
const parentPath = (0, cli_utilities_1.pathValidator)((0, path_1.resolve)((0, cli_utilities_1.sanitizePath)(path), '../')); // Assuming that will be 2 folders up
|
|
9
|
+
return (0, path_1.parse)(parentPath).dir;
|
|
10
|
+
}
|
|
11
|
+
exports.default = () => {
|
|
12
|
+
const thisDir = getFileDirectory(__filename);
|
|
13
|
+
const callsites = (0, callsites_1.default)();
|
|
14
|
+
const externalFile = callsites.find((callsite) => {
|
|
15
|
+
const currentDir = getFileDirectory(callsite.getFileName());
|
|
16
|
+
const isNotThisDir = thisDir !== currentDir;
|
|
17
|
+
return isNotThisDir;
|
|
18
|
+
});
|
|
19
|
+
return externalFile;
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=callsite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"callsite.js","sourceRoot":"","sources":["../../src/utils/callsite.ts"],"names":[],"mappings":";;;AAAA,kEAAqC;AACrC,+BAAsC;AACtC,+DAA0E;AAE1E,SAAS,gBAAgB,CAAC,IAAY;IACpC,MAAM,UAAU,GAAG,IAAA,6BAAa,EAAC,IAAA,cAAO,EAAC,IAAA,4BAAY,EAAC,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,qCAAqC;IAC3G,OAAO,IAAA,YAAK,EAAC,UAAU,CAAC,CAAC,GAAG,CAAC;AAC/B,CAAC;AAED,kBAAe,GAAQ,EAAE;IACvB,MAAM,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAAC;IAC7C,MAAM,SAAS,GAAG,IAAA,mBAAY,GAAE,CAAC;IAEjC,MAAM,YAAY,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,QAAa,EAAE,EAAE;QACpD,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;QAC5D,MAAM,YAAY,GAAG,OAAO,KAAK,UAAU,CAAC;QAC5C,OAAO,YAAY,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,OAAO,YAAY,CAAC;AACtB,CAAC,CAAC","sourcesContent":["import getCallsites from 'callsites';\nimport { parse, resolve } from 'path';\nimport { pathValidator, sanitizePath } from '@contentstack/cli-utilities';\n\nfunction getFileDirectory(path: string): string {\n const parentPath = pathValidator(resolve(sanitizePath(path), '../')); // Assuming that will be 2 folders up\n return parse(parentPath).dir;\n}\n\nexport default (): any => {\n const thisDir = getFileDirectory(__filename);\n const callsites = getCallsites();\n\n const externalFile = callsites.find((callsite: any) => {\n const currentDir = getFileDirectory(callsite.getFileName());\n const isNotThisDir = thisDir !== currentDir;\n return isNotThisDir;\n });\n\n return externalFile;\n};\n"]}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
export declare const mapObject: Map<string, any>;
|
|
2
|
+
export declare const version = 3;
|
|
3
|
+
export declare const defaultDataType = "text";
|
|
4
|
+
export declare const MANAGEMENT_SDK = "MANAGEMENT_SDK";
|
|
5
|
+
export declare const MANAGEMENT_CLIENT = "MANAGEMENT_CLIENT";
|
|
6
|
+
export declare const MANAGEMENT_TOKEN = "MANAGEMENT_TOKEN";
|
|
7
|
+
export declare const AUTH_TOKEN = "AUTH_TOKEN";
|
|
8
|
+
export declare const API_KEY = "API_KEY";
|
|
9
|
+
export declare const BRANCH = "BRANCH";
|
|
10
|
+
export declare const SOURCE_BRANCH = "SOURCE_BRANCH";
|
|
11
|
+
export declare const data_type = "data_type";
|
|
12
|
+
export declare const mandatory = "mandatory";
|
|
13
|
+
export declare const _default = "default";
|
|
14
|
+
export declare const unique = "unique";
|
|
15
|
+
export declare const display_name = "display_name";
|
|
16
|
+
export declare const reference_to = "reference_to";
|
|
17
|
+
export declare const field_metadata = "field_metadata";
|
|
18
|
+
export declare const taxonomies = "taxonomies";
|
|
19
|
+
export declare const multiple = "multiple";
|
|
20
|
+
export declare const actions: {
|
|
21
|
+
CUSTOM_TASK: string;
|
|
22
|
+
CREATE_CT: string;
|
|
23
|
+
DELETE_CT: string;
|
|
24
|
+
EDIT_CT: string;
|
|
25
|
+
LOCALES: string;
|
|
26
|
+
EDIT_FIELD: string;
|
|
27
|
+
DELETE_FIELD: string;
|
|
28
|
+
MOVE_FIELD: string;
|
|
29
|
+
};
|
|
30
|
+
export declare const MAX_RETRY = 3;
|
|
31
|
+
export declare const requests = "REQUESTS";
|
|
32
|
+
export declare const limit = 1;
|
|
33
|
+
export declare const nonWritableMethods: string[];
|
|
34
|
+
export declare const ContentType = "Content type";
|
|
35
|
+
export declare const Entry = "Entry";
|
|
36
|
+
export declare const errorMessageHandler: {
|
|
37
|
+
POST: string;
|
|
38
|
+
GET: string;
|
|
39
|
+
PUT: string;
|
|
40
|
+
DELETE: string;
|
|
41
|
+
};
|
|
42
|
+
export declare const successMessageHandler: {
|
|
43
|
+
POST: string;
|
|
44
|
+
GET: string;
|
|
45
|
+
PUT: string;
|
|
46
|
+
DELETE: string;
|
|
47
|
+
};
|
|
48
|
+
export declare const actionMapper = "actions";
|
|
49
|
+
export declare const batchLimit = 20;
|
|
50
|
+
export declare const contentTypeProperties: string[];
|
|
51
|
+
export declare const validationAction: {
|
|
52
|
+
create: string;
|
|
53
|
+
edit: string;
|
|
54
|
+
customTask: string;
|
|
55
|
+
transformEntries: string;
|
|
56
|
+
deriveLinkedEntries: string;
|
|
57
|
+
transformEntriesToType: string;
|
|
58
|
+
typeError: string;
|
|
59
|
+
apiError: string;
|
|
60
|
+
schema: string;
|
|
61
|
+
__migrationError: string;
|
|
62
|
+
field: string;
|
|
63
|
+
};
|
|
64
|
+
export declare const transformEntriesProperties: ({
|
|
65
|
+
name: string;
|
|
66
|
+
type: string;
|
|
67
|
+
mandatory: boolean;
|
|
68
|
+
dependsOn?: undefined;
|
|
69
|
+
} | {
|
|
70
|
+
name: string;
|
|
71
|
+
type: string;
|
|
72
|
+
mandatory: boolean;
|
|
73
|
+
dependsOn: string;
|
|
74
|
+
})[];
|
|
75
|
+
export declare const deriveLinkedEntriesProperties: ({
|
|
76
|
+
name: string;
|
|
77
|
+
type: string;
|
|
78
|
+
mandatory: boolean;
|
|
79
|
+
dependsOn?: undefined;
|
|
80
|
+
} | {
|
|
81
|
+
name: string;
|
|
82
|
+
type: string;
|
|
83
|
+
mandatory: boolean;
|
|
84
|
+
dependsOn: string;
|
|
85
|
+
})[];
|
|
86
|
+
export declare const transformEntriesToTypeProperties: ({
|
|
87
|
+
name: string;
|
|
88
|
+
type: string;
|
|
89
|
+
mandatory: boolean;
|
|
90
|
+
dependsOn?: undefined;
|
|
91
|
+
} | {
|
|
92
|
+
name: string;
|
|
93
|
+
type: string;
|
|
94
|
+
mandatory: boolean;
|
|
95
|
+
dependsOn: string;
|
|
96
|
+
})[];
|
|
97
|
+
export declare const SDK_ACTIONS: {
|
|
98
|
+
CONTENTTYPE_GET: string;
|
|
99
|
+
CONTENTTYPE_POST: string;
|
|
100
|
+
CONTENTTYPE_DELETE: string;
|
|
101
|
+
CONTENTTYPE_PUT: string;
|
|
102
|
+
LOCALES_GET: string;
|
|
103
|
+
ENTRY_GET: string;
|
|
104
|
+
ENTRY_POST: string;
|
|
105
|
+
ENTRY_PUT: string;
|
|
106
|
+
ENTRY_DELETE: string;
|
|
107
|
+
ENTRY_PUBLISH: string;
|
|
108
|
+
};
|