@nuskin/contentstack-lib 2.1.0-pa-1117.7 → 2.1.0-pa-1117.8
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 +57 -17
- package/__tests__/api.spec.js +36 -18
- package/docs/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/src/api.js +7 -6
package/README.md
CHANGED
|
@@ -11,13 +11,13 @@ FOR COMMON SPANISH AND MX-es FOR EXAMPLE.
|
|
|
11
11
|
|
|
12
12
|
## Installing
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Using npm:
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
npm install @nuskin/contentstack-lib
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
Using yarn:
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
23
|
yarn add @nuskin/contentstack-lib
|
|
@@ -28,8 +28,9 @@ yarn add @nuskin/contentstack-lib
|
|
|
28
28
|
```js
|
|
29
29
|
const { getStack } = require('@nuskin/contentstack-lib')
|
|
30
30
|
|
|
31
|
-
//
|
|
32
|
-
|
|
31
|
+
// Pass an environment explicitly outside the browser.
|
|
32
|
+
// In the browser, getStack() can infer the env from the hostname.
|
|
33
|
+
const Stack = getStack('prod')
|
|
33
34
|
|
|
34
35
|
// get all languages
|
|
35
36
|
const languages = await Stack.ContentType('supported_language').Query().toJSON().find();
|
|
@@ -37,16 +38,6 @@ const languages = await Stack.ContentType('supported_language').Query().toJSON()
|
|
|
37
38
|
// get all markets
|
|
38
39
|
const markets = await Stack.ContentType('market').Query().toJSON().find();
|
|
39
40
|
|
|
40
|
-
// Use the extended getStrings function to get translations
|
|
41
|
-
// ==================== Deprecated - Dont use this function ==========================
|
|
42
|
-
const translations = Stack.getStrings({
|
|
43
|
-
contentTypes: ['checkout_adr_strings', 'checkout_cart_strings'], // List of content types you want to get translations for
|
|
44
|
-
language: 'en',
|
|
45
|
-
country: 'US',
|
|
46
|
-
merge: true // Will combine checkout_adr_strings and checkout_cart_strings object with single list of strings
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Use this function instead to get your translations
|
|
50
41
|
// The entries are returned in the order they were requested so you can destructure the array accordingly
|
|
51
42
|
// To get the result in camelcase instead of snake case you can pass in the option.camelcase: true
|
|
52
43
|
// Contentstack does not merge common english strings with en_US strings. This function allows you to merge the two with mergeWithFallback: true
|
|
@@ -76,10 +67,13 @@ const addressForms = await Stack.getAddressForms(['United States']);
|
|
|
76
67
|
// field: 'address1',
|
|
77
68
|
// width: 'full',
|
|
78
69
|
// editable: true,
|
|
79
|
-
// max_length: 40
|
|
70
|
+
// max_length: 40,
|
|
71
|
+
// required: true
|
|
80
72
|
// }
|
|
81
73
|
// ],
|
|
82
|
-
// postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$'
|
|
74
|
+
// postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
75
|
+
// verify_after_autocomplete: true,
|
|
76
|
+
// wrap_address1_to_address2: false
|
|
83
77
|
// }
|
|
84
78
|
// ]
|
|
85
79
|
|
|
@@ -87,8 +81,54 @@ const addressForms = await Stack.getAddressForms(['United States']);
|
|
|
87
81
|
const camelizedAddressForms = await Stack.getAddressForms(['United States'], true);
|
|
88
82
|
|
|
89
83
|
// Get shipping address forms with referenced address form fields expanded.
|
|
90
|
-
//
|
|
84
|
+
// countries is normalized to a list of { code, name } objects.
|
|
91
85
|
const shippingAddressForms = await Stack.getShippingAddressForms(['United States']);
|
|
86
|
+
|
|
87
|
+
// Example result:
|
|
88
|
+
// [
|
|
89
|
+
// {
|
|
90
|
+
// countries: [
|
|
91
|
+
// {
|
|
92
|
+
// code: 'US',
|
|
93
|
+
// name: 'United States'
|
|
94
|
+
// }
|
|
95
|
+
// ],
|
|
96
|
+
// pre_address_fields: [
|
|
97
|
+
// {
|
|
98
|
+
// field: 'givenName',
|
|
99
|
+
// width: 'half',
|
|
100
|
+
// editable: true,
|
|
101
|
+
// max_length: 30,
|
|
102
|
+
// required: true
|
|
103
|
+
// }
|
|
104
|
+
// ],
|
|
105
|
+
// address_form: {
|
|
106
|
+
// address_elements: [
|
|
107
|
+
// {
|
|
108
|
+
// field: 'address1',
|
|
109
|
+
// width: 'full',
|
|
110
|
+
// editable: true,
|
|
111
|
+
// max_length: 40,
|
|
112
|
+
// required: true
|
|
113
|
+
// }
|
|
114
|
+
// ],
|
|
115
|
+
// postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
116
|
+
// verify_after_autocomplete: true,
|
|
117
|
+
// wrap_address1_to_address2: false
|
|
118
|
+
// },
|
|
119
|
+
// post_address_fields: [
|
|
120
|
+
// {
|
|
121
|
+
// field: 'mobilePhone',
|
|
122
|
+
// width: 'full',
|
|
123
|
+
// editable: true,
|
|
124
|
+
// max_length: 20,
|
|
125
|
+
// required: true
|
|
126
|
+
// }
|
|
127
|
+
// ]
|
|
128
|
+
// }
|
|
129
|
+
// ]
|
|
130
|
+
|
|
131
|
+
// Pass true as the second parameter to camelCase the returned keys.
|
|
92
132
|
const camelizedShippingAddressForms = await Stack.getShippingAddressForms(['United States'], true);
|
|
93
133
|
|
|
94
134
|
// We could possibly add functionality to return the list of regions markets and languages in a single object structure
|
package/__tests__/api.spec.js
CHANGED
|
@@ -86,14 +86,16 @@ const addressFormFieldEntries = [
|
|
|
86
86
|
width: 'full',
|
|
87
87
|
editable: true,
|
|
88
88
|
max_length: '40',
|
|
89
|
-
required: true
|
|
89
|
+
required: true,
|
|
90
|
+
api_mappings: ['address1']
|
|
90
91
|
},
|
|
91
92
|
{
|
|
92
93
|
field: 'postalCode',
|
|
93
94
|
width: 'half',
|
|
94
95
|
editable: false,
|
|
95
96
|
max_length: '10',
|
|
96
|
-
required: false
|
|
97
|
+
required: false,
|
|
98
|
+
api_mappings: ['postalCode']
|
|
97
99
|
}
|
|
98
100
|
];
|
|
99
101
|
|
|
@@ -171,14 +173,16 @@ describe("ContentstackApi", () => {
|
|
|
171
173
|
width: 'full',
|
|
172
174
|
editable: true,
|
|
173
175
|
max_length: 40,
|
|
174
|
-
required: true
|
|
176
|
+
required: true,
|
|
177
|
+
api_mappings: ['address1']
|
|
175
178
|
},
|
|
176
179
|
{
|
|
177
180
|
field: 'postalCode',
|
|
178
181
|
width: 'half',
|
|
179
182
|
editable: false,
|
|
180
183
|
max_length: 10,
|
|
181
|
-
required: false
|
|
184
|
+
required: false,
|
|
185
|
+
api_mappings: ['postalCode']
|
|
182
186
|
}
|
|
183
187
|
]);
|
|
184
188
|
});
|
|
@@ -192,14 +196,16 @@ describe("ContentstackApi", () => {
|
|
|
192
196
|
width: 'full',
|
|
193
197
|
editable: true,
|
|
194
198
|
maxLength: 40,
|
|
195
|
-
required: true
|
|
199
|
+
required: true,
|
|
200
|
+
apiMappings: ['address1']
|
|
196
201
|
},
|
|
197
202
|
{
|
|
198
203
|
field: 'postalCode',
|
|
199
204
|
width: 'half',
|
|
200
205
|
editable: false,
|
|
201
206
|
maxLength: 10,
|
|
202
|
-
required: false
|
|
207
|
+
required: false,
|
|
208
|
+
apiMappings: ['postalCode']
|
|
203
209
|
}
|
|
204
210
|
]);
|
|
205
211
|
});
|
|
@@ -230,14 +236,16 @@ describe("ContentstackApi", () => {
|
|
|
230
236
|
width: 'full',
|
|
231
237
|
editable: true,
|
|
232
238
|
max_length: 40,
|
|
233
|
-
required: true
|
|
239
|
+
required: true,
|
|
240
|
+
api_mappings: ['address1']
|
|
234
241
|
},
|
|
235
242
|
{
|
|
236
243
|
field: 'postalCode',
|
|
237
244
|
width: 'half',
|
|
238
245
|
editable: false,
|
|
239
246
|
max_length: 10,
|
|
240
|
-
required: false
|
|
247
|
+
required: false,
|
|
248
|
+
api_mappings: ['postalCode']
|
|
241
249
|
}
|
|
242
250
|
],
|
|
243
251
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
@@ -266,14 +274,16 @@ describe("ContentstackApi", () => {
|
|
|
266
274
|
width: 'full',
|
|
267
275
|
editable: true,
|
|
268
276
|
maxLength: 40,
|
|
269
|
-
required: true
|
|
277
|
+
required: true,
|
|
278
|
+
apiMappings: ['address1']
|
|
270
279
|
},
|
|
271
280
|
{
|
|
272
281
|
field: 'postalCode',
|
|
273
282
|
width: 'half',
|
|
274
283
|
editable: false,
|
|
275
284
|
maxLength: 10,
|
|
276
|
-
required: false
|
|
285
|
+
required: false,
|
|
286
|
+
apiMappings: ['postalCode']
|
|
277
287
|
}
|
|
278
288
|
],
|
|
279
289
|
postalCodeRegex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
@@ -349,7 +359,8 @@ describe("ContentstackApi", () => {
|
|
|
349
359
|
width: 'full',
|
|
350
360
|
editable: true,
|
|
351
361
|
max_length: 40,
|
|
352
|
-
required: true
|
|
362
|
+
required: true,
|
|
363
|
+
api_mappings: ['address1']
|
|
353
364
|
}
|
|
354
365
|
],
|
|
355
366
|
address_form: {
|
|
@@ -359,14 +370,16 @@ describe("ContentstackApi", () => {
|
|
|
359
370
|
width: 'full',
|
|
360
371
|
editable: true,
|
|
361
372
|
max_length: 40,
|
|
362
|
-
required: true
|
|
373
|
+
required: true,
|
|
374
|
+
api_mappings: ['address1']
|
|
363
375
|
},
|
|
364
376
|
{
|
|
365
377
|
field: 'postalCode',
|
|
366
378
|
width: 'half',
|
|
367
379
|
editable: false,
|
|
368
380
|
max_length: 10,
|
|
369
|
-
required: false
|
|
381
|
+
required: false,
|
|
382
|
+
api_mappings: ['postalCode']
|
|
370
383
|
}
|
|
371
384
|
],
|
|
372
385
|
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
@@ -379,7 +392,8 @@ describe("ContentstackApi", () => {
|
|
|
379
392
|
width: 'half',
|
|
380
393
|
editable: false,
|
|
381
394
|
max_length: 10,
|
|
382
|
-
required: false
|
|
395
|
+
required: false,
|
|
396
|
+
api_mappings: ['postalCode']
|
|
383
397
|
}
|
|
384
398
|
]
|
|
385
399
|
}
|
|
@@ -437,7 +451,8 @@ describe("ContentstackApi", () => {
|
|
|
437
451
|
width: 'full',
|
|
438
452
|
editable: true,
|
|
439
453
|
maxLength: 40,
|
|
440
|
-
required: true
|
|
454
|
+
required: true,
|
|
455
|
+
apiMappings: ['address1']
|
|
441
456
|
}
|
|
442
457
|
],
|
|
443
458
|
addressForm: {
|
|
@@ -447,14 +462,16 @@ describe("ContentstackApi", () => {
|
|
|
447
462
|
width: 'full',
|
|
448
463
|
editable: true,
|
|
449
464
|
maxLength: 40,
|
|
450
|
-
required: true
|
|
465
|
+
required: true,
|
|
466
|
+
apiMappings: ['address1']
|
|
451
467
|
},
|
|
452
468
|
{
|
|
453
469
|
field: 'postalCode',
|
|
454
470
|
width: 'half',
|
|
455
471
|
editable: false,
|
|
456
472
|
maxLength: 10,
|
|
457
|
-
required: false
|
|
473
|
+
required: false,
|
|
474
|
+
apiMappings: ['postalCode']
|
|
458
475
|
}
|
|
459
476
|
],
|
|
460
477
|
postalCodeRegex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
@@ -467,7 +484,8 @@ describe("ContentstackApi", () => {
|
|
|
467
484
|
width: 'half',
|
|
468
485
|
editable: false,
|
|
469
486
|
maxLength: 10,
|
|
470
|
-
required: false
|
|
487
|
+
required: false,
|
|
488
|
+
apiMappings: ['postalCode']
|
|
471
489
|
}
|
|
472
490
|
]
|
|
473
491
|
}
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# [2.1.0-pa-1117.
|
|
1
|
+
# [2.1.0-pa-1117.8](https://code.tls.nuskin.io/ns-am/utility/npm/contentstack-lib/compare/v2.1.0-pa-1117.7...v2.1.0-pa-1117.8) (2026-05-08)
|
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.8",
|
|
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
|
@@ -202,12 +202,13 @@ const _getMultiEntries = async (contentType, includeRefs, values) => {
|
|
|
202
202
|
* @private
|
|
203
203
|
*/
|
|
204
204
|
const _extractAddressFormFields = (addressFormFields = [], camelcase = false) => {
|
|
205
|
-
const mappedFields = addressFormFields.map(({field, width, editable, max_length, required}) => ({
|
|
205
|
+
const mappedFields = addressFormFields.map(({field, width, editable, max_length, required, api_mappings}) => ({
|
|
206
206
|
field,
|
|
207
207
|
width,
|
|
208
208
|
editable,
|
|
209
209
|
max_length: Number(max_length),
|
|
210
|
-
required
|
|
210
|
+
required,
|
|
211
|
+
api_mappings
|
|
211
212
|
}));
|
|
212
213
|
|
|
213
214
|
return camelcase ? _snakeObjectToCamel(mappedFields) : mappedFields;
|
|
@@ -237,11 +238,11 @@ const _extractShippingCountries = (countries = []) => {
|
|
|
237
238
|
}));
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
const getShippingAddressForms = async (
|
|
241
|
+
const getShippingAddressForms = async (forms, camelcase = false) => {
|
|
241
242
|
const results = await _getMultiEntries(
|
|
242
243
|
'shipping_address_form',
|
|
243
244
|
['countries', 'pre_address_fields', 'address_form', 'address_form.address_elements', 'post_address_fields'],
|
|
244
|
-
|
|
245
|
+
forms
|
|
245
246
|
);
|
|
246
247
|
const mappedResults = (results || []).map((result) => ({
|
|
247
248
|
countries: _extractShippingCountries(result.countries),
|
|
@@ -253,8 +254,8 @@ const getShippingAddressForms = async (countries, camelcase = false) => {
|
|
|
253
254
|
return camelcase ? _snakeObjectToCamel(mappedResults) : mappedResults;
|
|
254
255
|
}
|
|
255
256
|
|
|
256
|
-
const getAddressForms = async (
|
|
257
|
-
const results = await _getMultiEntries('address_form', 'address_elements',
|
|
257
|
+
const getAddressForms = async (forms, camelcase = false) => {
|
|
258
|
+
const results = await _getMultiEntries('address_form', 'address_elements', forms);
|
|
258
259
|
const mappedResults = (results || []).map((result) => _extractAddressForm(result, camelcase));
|
|
259
260
|
|
|
260
261
|
return camelcase ? _snakeObjectToCamel(mappedResults) : mappedResults;
|