@nuskin/contentstack-lib 2.1.0-pa-1117.8 → 2.1.0-pa-1117.9
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/__tests__/api.spec.js +60 -30
- package/docs/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/src/api.js +47 -20
package/__tests__/api.spec.js
CHANGED
|
@@ -87,7 +87,8 @@ const addressFormFieldEntries = [
|
|
|
87
87
|
editable: true,
|
|
88
88
|
max_length: '40',
|
|
89
89
|
required: true,
|
|
90
|
-
api_mappings: ['address1']
|
|
90
|
+
api_mappings: ['address1'],
|
|
91
|
+
autocomplete_token: 'address-line1'
|
|
91
92
|
},
|
|
92
93
|
{
|
|
93
94
|
field: 'postalCode',
|
|
@@ -95,7 +96,8 @@ const addressFormFieldEntries = [
|
|
|
95
96
|
editable: false,
|
|
96
97
|
max_length: '10',
|
|
97
98
|
required: false,
|
|
98
|
-
api_mappings: ['postalCode']
|
|
99
|
+
api_mappings: ['postalCode'],
|
|
100
|
+
validation_message: 'Invalid postal code'
|
|
99
101
|
}
|
|
100
102
|
];
|
|
101
103
|
|
|
@@ -174,7 +176,8 @@ describe("ContentstackApi", () => {
|
|
|
174
176
|
editable: true,
|
|
175
177
|
max_length: 40,
|
|
176
178
|
required: true,
|
|
177
|
-
api_mappings: ['address1']
|
|
179
|
+
api_mappings: ['address1'],
|
|
180
|
+
autocomplete_token: 'address-line1'
|
|
178
181
|
},
|
|
179
182
|
{
|
|
180
183
|
field: 'postalCode',
|
|
@@ -182,7 +185,8 @@ describe("ContentstackApi", () => {
|
|
|
182
185
|
editable: false,
|
|
183
186
|
max_length: 10,
|
|
184
187
|
required: false,
|
|
185
|
-
api_mappings: ['postalCode']
|
|
188
|
+
api_mappings: ['postalCode'],
|
|
189
|
+
validation_message: 'Invalid postal code'
|
|
186
190
|
}
|
|
187
191
|
]);
|
|
188
192
|
});
|
|
@@ -197,7 +201,8 @@ describe("ContentstackApi", () => {
|
|
|
197
201
|
editable: true,
|
|
198
202
|
maxLength: 40,
|
|
199
203
|
required: true,
|
|
200
|
-
apiMappings: ['address1']
|
|
204
|
+
apiMappings: ['address1'],
|
|
205
|
+
autocompleteToken: 'address-line1'
|
|
201
206
|
},
|
|
202
207
|
{
|
|
203
208
|
field: 'postalCode',
|
|
@@ -205,7 +210,8 @@ describe("ContentstackApi", () => {
|
|
|
205
210
|
editable: false,
|
|
206
211
|
maxLength: 10,
|
|
207
212
|
required: false,
|
|
208
|
-
apiMappings: ['postalCode']
|
|
213
|
+
apiMappings: ['postalCode'],
|
|
214
|
+
validationMessage: 'Invalid postal code'
|
|
209
215
|
}
|
|
210
216
|
]);
|
|
211
217
|
});
|
|
@@ -223,7 +229,8 @@ describe("ContentstackApi", () => {
|
|
|
223
229
|
address_elements: addressFormFieldEntries,
|
|
224
230
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
225
231
|
verify_after_autocomplete: true,
|
|
226
|
-
wrap_address1_to_address2: false
|
|
232
|
+
wrap_address1_to_address2: false,
|
|
233
|
+
allowed_countries: ['US', 'CA']
|
|
227
234
|
}
|
|
228
235
|
]]);
|
|
229
236
|
const {getStack} = require('../src/api');
|
|
@@ -237,7 +244,8 @@ describe("ContentstackApi", () => {
|
|
|
237
244
|
editable: true,
|
|
238
245
|
max_length: 40,
|
|
239
246
|
required: true,
|
|
240
|
-
api_mappings: ['address1']
|
|
247
|
+
api_mappings: ['address1'],
|
|
248
|
+
autocomplete_token: 'address-line1'
|
|
241
249
|
},
|
|
242
250
|
{
|
|
243
251
|
field: 'postalCode',
|
|
@@ -245,12 +253,14 @@ describe("ContentstackApi", () => {
|
|
|
245
253
|
editable: false,
|
|
246
254
|
max_length: 10,
|
|
247
255
|
required: false,
|
|
248
|
-
api_mappings: ['postalCode']
|
|
256
|
+
api_mappings: ['postalCode'],
|
|
257
|
+
validation_message: 'Invalid postal code'
|
|
249
258
|
}
|
|
250
259
|
],
|
|
251
260
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
252
261
|
verify_after_autocomplete: true,
|
|
253
|
-
wrap_address1_to_address2: false
|
|
262
|
+
wrap_address1_to_address2: false,
|
|
263
|
+
allowed_countries: ['US', 'CA']
|
|
254
264
|
}
|
|
255
265
|
]);
|
|
256
266
|
});
|
|
@@ -261,7 +271,8 @@ describe("ContentstackApi", () => {
|
|
|
261
271
|
address_elements: addressFormFieldEntries,
|
|
262
272
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
263
273
|
verify_after_autocomplete: true,
|
|
264
|
-
wrap_address1_to_address2: false
|
|
274
|
+
wrap_address1_to_address2: false,
|
|
275
|
+
allowed_countries: ['US', 'CA']
|
|
265
276
|
}
|
|
266
277
|
]]);
|
|
267
278
|
const {getStack} = require('../src/api');
|
|
@@ -275,7 +286,8 @@ describe("ContentstackApi", () => {
|
|
|
275
286
|
editable: true,
|
|
276
287
|
maxLength: 40,
|
|
277
288
|
required: true,
|
|
278
|
-
apiMappings: ['address1']
|
|
289
|
+
apiMappings: ['address1'],
|
|
290
|
+
autocompleteToken: 'address-line1'
|
|
279
291
|
},
|
|
280
292
|
{
|
|
281
293
|
field: 'postalCode',
|
|
@@ -283,12 +295,14 @@ describe("ContentstackApi", () => {
|
|
|
283
295
|
editable: false,
|
|
284
296
|
maxLength: 10,
|
|
285
297
|
required: false,
|
|
286
|
-
apiMappings: ['postalCode']
|
|
298
|
+
apiMappings: ['postalCode'],
|
|
299
|
+
validationMessage: 'Invalid postal code'
|
|
287
300
|
}
|
|
288
301
|
],
|
|
289
302
|
postalCodeRegex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
290
303
|
verifyAfterAutocomplete: true,
|
|
291
|
-
wrapAddress1ToAddress2: false
|
|
304
|
+
wrapAddress1ToAddress2: false,
|
|
305
|
+
allowedCountries: ['US', 'CA']
|
|
292
306
|
}
|
|
293
307
|
]);
|
|
294
308
|
});
|
|
@@ -333,10 +347,12 @@ describe("ContentstackApi", () => {
|
|
|
333
347
|
address_elements: addressFormFieldEntries,
|
|
334
348
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
335
349
|
verify_after_autocomplete: true,
|
|
336
|
-
wrap_address1_to_address2: false
|
|
350
|
+
wrap_address1_to_address2: false,
|
|
351
|
+
allowed_countries: ['US', 'CA']
|
|
337
352
|
}
|
|
338
353
|
],
|
|
339
|
-
post_address_fields: [addressFormFieldEntries[1]]
|
|
354
|
+
post_address_fields: [addressFormFieldEntries[1]],
|
|
355
|
+
display_name: 'North America'
|
|
340
356
|
}
|
|
341
357
|
]]);
|
|
342
358
|
const {getStack} = require('../src/api');
|
|
@@ -360,7 +376,8 @@ describe("ContentstackApi", () => {
|
|
|
360
376
|
editable: true,
|
|
361
377
|
max_length: 40,
|
|
362
378
|
required: true,
|
|
363
|
-
api_mappings: ['address1']
|
|
379
|
+
api_mappings: ['address1'],
|
|
380
|
+
autocomplete_token: 'address-line1'
|
|
364
381
|
}
|
|
365
382
|
],
|
|
366
383
|
address_form: {
|
|
@@ -371,7 +388,8 @@ describe("ContentstackApi", () => {
|
|
|
371
388
|
editable: true,
|
|
372
389
|
max_length: 40,
|
|
373
390
|
required: true,
|
|
374
|
-
api_mappings: ['address1']
|
|
391
|
+
api_mappings: ['address1'],
|
|
392
|
+
autocomplete_token: 'address-line1'
|
|
375
393
|
},
|
|
376
394
|
{
|
|
377
395
|
field: 'postalCode',
|
|
@@ -379,12 +397,14 @@ describe("ContentstackApi", () => {
|
|
|
379
397
|
editable: false,
|
|
380
398
|
max_length: 10,
|
|
381
399
|
required: false,
|
|
382
|
-
api_mappings: ['postalCode']
|
|
400
|
+
api_mappings: ['postalCode'],
|
|
401
|
+
validation_message: 'Invalid postal code'
|
|
383
402
|
}
|
|
384
403
|
],
|
|
385
404
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
386
405
|
verify_after_autocomplete: true,
|
|
387
|
-
wrap_address1_to_address2: false
|
|
406
|
+
wrap_address1_to_address2: false,
|
|
407
|
+
allowed_countries: ['US', 'CA']
|
|
388
408
|
},
|
|
389
409
|
post_address_fields: [
|
|
390
410
|
{
|
|
@@ -393,9 +413,11 @@ describe("ContentstackApi", () => {
|
|
|
393
413
|
editable: false,
|
|
394
414
|
max_length: 10,
|
|
395
415
|
required: false,
|
|
396
|
-
api_mappings: ['postalCode']
|
|
416
|
+
api_mappings: ['postalCode'],
|
|
417
|
+
validation_message: 'Invalid postal code'
|
|
397
418
|
}
|
|
398
|
-
]
|
|
419
|
+
],
|
|
420
|
+
display_name: 'North America'
|
|
399
421
|
}
|
|
400
422
|
]);
|
|
401
423
|
});
|
|
@@ -425,10 +447,12 @@ describe("ContentstackApi", () => {
|
|
|
425
447
|
address_elements: addressFormFieldEntries,
|
|
426
448
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
427
449
|
verify_after_autocomplete: true,
|
|
428
|
-
wrap_address1_to_address2: false
|
|
450
|
+
wrap_address1_to_address2: false,
|
|
451
|
+
allowed_countries: ['US', 'CA']
|
|
429
452
|
}
|
|
430
453
|
],
|
|
431
|
-
post_address_fields: [addressFormFieldEntries[1]]
|
|
454
|
+
post_address_fields: [addressFormFieldEntries[1]],
|
|
455
|
+
display_name: 'North America'
|
|
432
456
|
}
|
|
433
457
|
]]);
|
|
434
458
|
const {getStack} = require('../src/api');
|
|
@@ -452,7 +476,8 @@ describe("ContentstackApi", () => {
|
|
|
452
476
|
editable: true,
|
|
453
477
|
maxLength: 40,
|
|
454
478
|
required: true,
|
|
455
|
-
apiMappings: ['address1']
|
|
479
|
+
apiMappings: ['address1'],
|
|
480
|
+
autocompleteToken: 'address-line1'
|
|
456
481
|
}
|
|
457
482
|
],
|
|
458
483
|
addressForm: {
|
|
@@ -463,7 +488,8 @@ describe("ContentstackApi", () => {
|
|
|
463
488
|
editable: true,
|
|
464
489
|
maxLength: 40,
|
|
465
490
|
required: true,
|
|
466
|
-
apiMappings: ['address1']
|
|
491
|
+
apiMappings: ['address1'],
|
|
492
|
+
autocompleteToken: 'address-line1'
|
|
467
493
|
},
|
|
468
494
|
{
|
|
469
495
|
field: 'postalCode',
|
|
@@ -471,12 +497,14 @@ describe("ContentstackApi", () => {
|
|
|
471
497
|
editable: false,
|
|
472
498
|
maxLength: 10,
|
|
473
499
|
required: false,
|
|
474
|
-
apiMappings: ['postalCode']
|
|
500
|
+
apiMappings: ['postalCode'],
|
|
501
|
+
validationMessage: 'Invalid postal code'
|
|
475
502
|
}
|
|
476
503
|
],
|
|
477
504
|
postalCodeRegex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
478
505
|
verifyAfterAutocomplete: true,
|
|
479
|
-
wrapAddress1ToAddress2: false
|
|
506
|
+
wrapAddress1ToAddress2: false,
|
|
507
|
+
allowedCountries: ['US', 'CA']
|
|
480
508
|
},
|
|
481
509
|
postAddressFields: [
|
|
482
510
|
{
|
|
@@ -485,9 +513,11 @@ describe("ContentstackApi", () => {
|
|
|
485
513
|
editable: false,
|
|
486
514
|
maxLength: 10,
|
|
487
515
|
required: false,
|
|
488
|
-
apiMappings: ['postalCode']
|
|
516
|
+
apiMappings: ['postalCode'],
|
|
517
|
+
validationMessage: 'Invalid postal code'
|
|
489
518
|
}
|
|
490
|
-
]
|
|
519
|
+
],
|
|
520
|
+
displayName: 'North America'
|
|
491
521
|
}
|
|
492
522
|
]);
|
|
493
523
|
});
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# [2.1.0-pa-1117.
|
|
1
|
+
# [2.1.0-pa-1117.9](https://code.tls.nuskin.io/ns-am/utility/npm/contentstack-lib/compare/v2.1.0-pa-1117.8...v2.1.0-pa-1117.9) (2026-05-18)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuskin/contentstack-lib",
|
|
3
|
-
"version": "2.1.0-pa-1117.
|
|
3
|
+
"version": "2.1.0-pa-1117.9",
|
|
4
4
|
"description": "This project contains configuration and api code to access Contentstack, to be shared between the backend (AWS Lambda) and frontend (Vue, etc).",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
package/src/api.js
CHANGED
|
@@ -22,6 +22,22 @@ const COMMON_LANGUAGES = {
|
|
|
22
22
|
'tr': 'tr-tr'
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
const CONTENTSTACK_SYSTEM_FIELDS = new Set([
|
|
26
|
+
'_content_type_uid',
|
|
27
|
+
'uid',
|
|
28
|
+
'title',
|
|
29
|
+
'tags',
|
|
30
|
+
'locale',
|
|
31
|
+
'created_by',
|
|
32
|
+
'updated_by',
|
|
33
|
+
'created_at',
|
|
34
|
+
'updated_at',
|
|
35
|
+
'ACL',
|
|
36
|
+
'_version',
|
|
37
|
+
'_in_progress',
|
|
38
|
+
'publish_details'
|
|
39
|
+
]);
|
|
40
|
+
|
|
25
41
|
/**
|
|
26
42
|
* Gets the correct contentstack config settings
|
|
27
43
|
* @param {string} env
|
|
@@ -195,6 +211,18 @@ const _getMultiEntries = async (contentType, includeRefs, values) => {
|
|
|
195
211
|
}
|
|
196
212
|
}
|
|
197
213
|
|
|
214
|
+
/**
|
|
215
|
+
* Removes Contentstack-managed metadata fields while preserving custom content fields.
|
|
216
|
+
* @param {Object} entry
|
|
217
|
+
* @return {Object}
|
|
218
|
+
* @private
|
|
219
|
+
*/
|
|
220
|
+
const _omitContentstackSystemFields = (entry = {}) => {
|
|
221
|
+
return Object.fromEntries(
|
|
222
|
+
Object.entries(entry).filter(([key]) => !CONTENTSTACK_SYSTEM_FIELDS.has(key))
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
198
226
|
/**
|
|
199
227
|
* Maps address form field entries into a small normalized dataset.
|
|
200
228
|
* @param {Object[]} addressFormFields
|
|
@@ -202,14 +230,15 @@ const _getMultiEntries = async (contentType, includeRefs, values) => {
|
|
|
202
230
|
* @private
|
|
203
231
|
*/
|
|
204
232
|
const _extractAddressFormFields = (addressFormFields = [], camelcase = false) => {
|
|
205
|
-
const mappedFields = addressFormFields.map((
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
233
|
+
const mappedFields = addressFormFields.map((addressFormField) => {
|
|
234
|
+
const mappedField = _omitContentstackSystemFields(addressFormField);
|
|
235
|
+
|
|
236
|
+
if (mappedField.max_length !== undefined && mappedField.max_length !== null) {
|
|
237
|
+
mappedField.max_length = Number(mappedField.max_length);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return mappedField;
|
|
241
|
+
});
|
|
213
242
|
|
|
214
243
|
return camelcase ? _snakeObjectToCamel(mappedFields) : mappedFields;
|
|
215
244
|
}
|
|
@@ -219,12 +248,8 @@ const _extractAddressForm = (addressForm, camelcase = false) => {
|
|
|
219
248
|
return addressForm;
|
|
220
249
|
}
|
|
221
250
|
|
|
222
|
-
const mappedForm =
|
|
223
|
-
|
|
224
|
-
postal_code_regex: addressForm.postal_code_regex,
|
|
225
|
-
verify_after_autocomplete: addressForm.verify_after_autocomplete,
|
|
226
|
-
wrap_address1_to_address2: addressForm.wrap_address1_to_address2
|
|
227
|
-
};
|
|
251
|
+
const mappedForm = _omitContentstackSystemFields(addressForm);
|
|
252
|
+
mappedForm.address_elements = _extractAddressFormFields(addressForm.address_elements, camelcase);
|
|
228
253
|
|
|
229
254
|
return camelcase ? _snakeObjectToCamel(mappedForm) : mappedForm;
|
|
230
255
|
}
|
|
@@ -244,12 +269,14 @@ const getShippingAddressForms = async (forms, camelcase = false) => {
|
|
|
244
269
|
['countries', 'pre_address_fields', 'address_form', 'address_form.address_elements', 'post_address_fields'],
|
|
245
270
|
forms
|
|
246
271
|
);
|
|
247
|
-
const mappedResults = (results || []).map((result) =>
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
272
|
+
const mappedResults = (results || []).map((result) => {
|
|
273
|
+
const mappedResult = _omitContentstackSystemFields(result);
|
|
274
|
+
mappedResult.countries = _extractShippingCountries(result.countries);
|
|
275
|
+
mappedResult.pre_address_fields = _extractAddressFormFields(result.pre_address_fields, camelcase);
|
|
276
|
+
mappedResult.address_form = _extractAddressForm(result.address_form[0], camelcase);
|
|
277
|
+
mappedResult.post_address_fields = _extractAddressFormFields(result.post_address_fields, camelcase);
|
|
278
|
+
return mappedResult;
|
|
279
|
+
});
|
|
253
280
|
|
|
254
281
|
return camelcase ? _snakeObjectToCamel(mappedResults) : mappedResults;
|
|
255
282
|
}
|