@nuskin/contentstack-lib 2.1.0-pa-1117.8 → 2.1.0-pa-1117.10
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 +0 -77
- package/__tests__/api.spec.js +0 -360
- package/docs/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/src/api.js +3 -73
package/README.md
CHANGED
|
@@ -7,7 +7,6 @@ This project extends the Contentstack delivery sdk, to be shared between the bac
|
|
|
7
7
|
getSingletonEntries TAKES AN OPTION CALLED mergeWithFallback. IF THAT IS SET TO TRUE THEN IT WILL MERGE THE RESULTS
|
|
8
8
|
FOR COMMON SPANISH AND MX-es FOR EXAMPLE.
|
|
9
9
|
4. getSingletonEntries also allows you to convert the keys from snake case to camel case.
|
|
10
|
-
5. It extends the stack with getAddressForms and getShippingAddressForms for address form content types.
|
|
11
10
|
|
|
12
11
|
## Installing
|
|
13
12
|
|
|
@@ -55,82 +54,6 @@ const [
|
|
|
55
54
|
mergeWithFallback: true
|
|
56
55
|
});
|
|
57
56
|
|
|
58
|
-
// Get address forms for a list of countries.
|
|
59
|
-
// By default the returned keys are snake_case.
|
|
60
|
-
const addressForms = await Stack.getAddressForms(['United States']);
|
|
61
|
-
|
|
62
|
-
// Example result:
|
|
63
|
-
// [
|
|
64
|
-
// {
|
|
65
|
-
// address_elements: [
|
|
66
|
-
// {
|
|
67
|
-
// field: 'address1',
|
|
68
|
-
// width: 'full',
|
|
69
|
-
// editable: true,
|
|
70
|
-
// max_length: 40,
|
|
71
|
-
// required: true
|
|
72
|
-
// }
|
|
73
|
-
// ],
|
|
74
|
-
// postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
75
|
-
// verify_after_autocomplete: true,
|
|
76
|
-
// wrap_address1_to_address2: false
|
|
77
|
-
// }
|
|
78
|
-
// ]
|
|
79
|
-
|
|
80
|
-
// Pass true as the second parameter to camelCase the returned keys.
|
|
81
|
-
const camelizedAddressForms = await Stack.getAddressForms(['United States'], true);
|
|
82
|
-
|
|
83
|
-
// Get shipping address forms with referenced address form fields expanded.
|
|
84
|
-
// countries is normalized to a list of { code, name } objects.
|
|
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.
|
|
132
|
-
const camelizedShippingAddressForms = await Stack.getShippingAddressForms(['United States'], true);
|
|
133
|
-
|
|
134
57
|
// We could possibly add functionality to return the list of regions markets and languages in a single object structure
|
|
135
58
|
```
|
|
136
59
|
|
package/__tests__/api.spec.js
CHANGED
|
@@ -80,25 +80,6 @@ const mockResults = () => {
|
|
|
80
80
|
mockSinglePromiseResult.mockResolvedValueOnce(singleCheckoutCartStrings);
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
const addressFormFieldEntries = [
|
|
84
|
-
{
|
|
85
|
-
field: 'address1',
|
|
86
|
-
width: 'full',
|
|
87
|
-
editable: true,
|
|
88
|
-
max_length: '40',
|
|
89
|
-
required: true,
|
|
90
|
-
api_mappings: ['address1']
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
field: 'postalCode',
|
|
94
|
-
width: 'half',
|
|
95
|
-
editable: false,
|
|
96
|
-
max_length: '10',
|
|
97
|
-
required: false,
|
|
98
|
-
api_mappings: ['postalCode']
|
|
99
|
-
}
|
|
100
|
-
];
|
|
101
|
-
|
|
102
83
|
describe("ContentstackApi", () => {
|
|
103
84
|
test("getSingletonEntries", async () => {
|
|
104
85
|
mockResults();
|
|
@@ -164,142 +145,6 @@ describe("ContentstackApi", () => {
|
|
|
164
145
|
});
|
|
165
146
|
});
|
|
166
147
|
|
|
167
|
-
test('extractAddressFormFields maps address form field entries', () => {
|
|
168
|
-
const {getStack} = require('../src/api');
|
|
169
|
-
const Stack = getStack('dev');
|
|
170
|
-
expect(Stack.extractAddressFormFields(addressFormFieldEntries)).toStrictEqual([
|
|
171
|
-
{
|
|
172
|
-
field: 'address1',
|
|
173
|
-
width: 'full',
|
|
174
|
-
editable: true,
|
|
175
|
-
max_length: 40,
|
|
176
|
-
required: true,
|
|
177
|
-
api_mappings: ['address1']
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
field: 'postalCode',
|
|
181
|
-
width: 'half',
|
|
182
|
-
editable: false,
|
|
183
|
-
max_length: 10,
|
|
184
|
-
required: false,
|
|
185
|
-
api_mappings: ['postalCode']
|
|
186
|
-
}
|
|
187
|
-
]);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test('extractAddressFormFields camelcases address form field entries', () => {
|
|
191
|
-
const {getStack} = require('../src/api');
|
|
192
|
-
const Stack = getStack('dev');
|
|
193
|
-
expect(Stack.extractAddressFormFields(addressFormFieldEntries, true)).toStrictEqual([
|
|
194
|
-
{
|
|
195
|
-
field: 'address1',
|
|
196
|
-
width: 'full',
|
|
197
|
-
editable: true,
|
|
198
|
-
maxLength: 40,
|
|
199
|
-
required: true,
|
|
200
|
-
apiMappings: ['address1']
|
|
201
|
-
},
|
|
202
|
-
{
|
|
203
|
-
field: 'postalCode',
|
|
204
|
-
width: 'half',
|
|
205
|
-
editable: false,
|
|
206
|
-
maxLength: 10,
|
|
207
|
-
required: false,
|
|
208
|
-
apiMappings: ['postalCode']
|
|
209
|
-
}
|
|
210
|
-
]);
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
test('extractAddressFormFields returns an empty list when no entries are provided', () => {
|
|
214
|
-
const {getStack} = require('../src/api');
|
|
215
|
-
const Stack = getStack('dev');
|
|
216
|
-
expect(Stack.extractAddressFormFields()).toStrictEqual([]);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
test('getAddressForms maps address_elements', async () => {
|
|
220
|
-
mockPromiseResult.mockResolvedValueOnce([[
|
|
221
|
-
{
|
|
222
|
-
title: 'United States',
|
|
223
|
-
address_elements: addressFormFieldEntries,
|
|
224
|
-
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
225
|
-
verify_after_autocomplete: true,
|
|
226
|
-
wrap_address1_to_address2: false
|
|
227
|
-
}
|
|
228
|
-
]]);
|
|
229
|
-
const {getStack} = require('../src/api');
|
|
230
|
-
const Stack = getStack('dev');
|
|
231
|
-
await expect(Stack.getAddressForms(['United States'])).resolves.toStrictEqual([
|
|
232
|
-
{
|
|
233
|
-
address_elements: [
|
|
234
|
-
{
|
|
235
|
-
field: 'address1',
|
|
236
|
-
width: 'full',
|
|
237
|
-
editable: true,
|
|
238
|
-
max_length: 40,
|
|
239
|
-
required: true,
|
|
240
|
-
api_mappings: ['address1']
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
field: 'postalCode',
|
|
244
|
-
width: 'half',
|
|
245
|
-
editable: false,
|
|
246
|
-
max_length: 10,
|
|
247
|
-
required: false,
|
|
248
|
-
api_mappings: ['postalCode']
|
|
249
|
-
}
|
|
250
|
-
],
|
|
251
|
-
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
252
|
-
verify_after_autocomplete: true,
|
|
253
|
-
wrap_address1_to_address2: false
|
|
254
|
-
}
|
|
255
|
-
]);
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test('getAddressForms camelcases returned field names', async () => {
|
|
259
|
-
mockPromiseResult.mockResolvedValueOnce([[
|
|
260
|
-
{
|
|
261
|
-
address_elements: addressFormFieldEntries,
|
|
262
|
-
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
263
|
-
verify_after_autocomplete: true,
|
|
264
|
-
wrap_address1_to_address2: false
|
|
265
|
-
}
|
|
266
|
-
]]);
|
|
267
|
-
const {getStack} = require('../src/api');
|
|
268
|
-
const Stack = getStack('dev');
|
|
269
|
-
await expect(Stack.getAddressForms(['United States'], true)).resolves.toStrictEqual([
|
|
270
|
-
{
|
|
271
|
-
addressElements: [
|
|
272
|
-
{
|
|
273
|
-
field: 'address1',
|
|
274
|
-
width: 'full',
|
|
275
|
-
editable: true,
|
|
276
|
-
maxLength: 40,
|
|
277
|
-
required: true,
|
|
278
|
-
apiMappings: ['address1']
|
|
279
|
-
},
|
|
280
|
-
{
|
|
281
|
-
field: 'postalCode',
|
|
282
|
-
width: 'half',
|
|
283
|
-
editable: false,
|
|
284
|
-
maxLength: 10,
|
|
285
|
-
required: false,
|
|
286
|
-
apiMappings: ['postalCode']
|
|
287
|
-
}
|
|
288
|
-
],
|
|
289
|
-
postalCodeRegex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
290
|
-
verifyAfterAutocomplete: true,
|
|
291
|
-
wrapAddress1ToAddress2: false
|
|
292
|
-
}
|
|
293
|
-
]);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
test('getAddressForms returns an empty list when no forms are found', async () => {
|
|
297
|
-
mockPromiseResult.mockResolvedValueOnce([undefined]);
|
|
298
|
-
const {getStack} = require('../src/api');
|
|
299
|
-
const Stack = getStack('dev');
|
|
300
|
-
await expect(Stack.getAddressForms(['Unknown'])).resolves.toStrictEqual([]);
|
|
301
|
-
});
|
|
302
|
-
|
|
303
148
|
test('getSingletonEntries maps language code in to id', async () => {
|
|
304
149
|
mockSinglePromiseResult.mockResolvedValueOnce(singleCheckoutAdrStrings);
|
|
305
150
|
const {getStack} = require('../src/api');
|
|
@@ -307,209 +152,4 @@ describe("ContentstackApi", () => {
|
|
|
307
152
|
await Stack.getSingletonEntries({contentTypeUIDs: ['checkout_adr_strings'], language: 'in'});
|
|
308
153
|
expect(mockSinglePromiseResult).toHaveBeenCalled();
|
|
309
154
|
});
|
|
310
|
-
|
|
311
|
-
test('getShippingAddressForms maps nested address form fields', async () => {
|
|
312
|
-
mockPromiseResult.mockResolvedValueOnce([[
|
|
313
|
-
{
|
|
314
|
-
title: 'United States',
|
|
315
|
-
countries: [
|
|
316
|
-
{
|
|
317
|
-
countries: [
|
|
318
|
-
{
|
|
319
|
-
country_code: 'US',
|
|
320
|
-
country_name: 'United States'
|
|
321
|
-
},
|
|
322
|
-
{
|
|
323
|
-
country_code: 'CA',
|
|
324
|
-
country_name: 'Canada'
|
|
325
|
-
}
|
|
326
|
-
]
|
|
327
|
-
}
|
|
328
|
-
],
|
|
329
|
-
pre_address_fields: [addressFormFieldEntries[0]],
|
|
330
|
-
address_form: [
|
|
331
|
-
{
|
|
332
|
-
title: 'default',
|
|
333
|
-
address_elements: addressFormFieldEntries,
|
|
334
|
-
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
335
|
-
verify_after_autocomplete: true,
|
|
336
|
-
wrap_address1_to_address2: false
|
|
337
|
-
}
|
|
338
|
-
],
|
|
339
|
-
post_address_fields: [addressFormFieldEntries[1]]
|
|
340
|
-
}
|
|
341
|
-
]]);
|
|
342
|
-
const {getStack} = require('../src/api');
|
|
343
|
-
const Stack = getStack('dev');
|
|
344
|
-
await expect(Stack.getShippingAddressForms(['United States'])).resolves.toStrictEqual([
|
|
345
|
-
{
|
|
346
|
-
countries: [
|
|
347
|
-
{
|
|
348
|
-
code: 'US',
|
|
349
|
-
name: 'United States'
|
|
350
|
-
},
|
|
351
|
-
{
|
|
352
|
-
code: 'CA',
|
|
353
|
-
name: 'Canada'
|
|
354
|
-
}
|
|
355
|
-
],
|
|
356
|
-
pre_address_fields: [
|
|
357
|
-
{
|
|
358
|
-
field: 'address1',
|
|
359
|
-
width: 'full',
|
|
360
|
-
editable: true,
|
|
361
|
-
max_length: 40,
|
|
362
|
-
required: true,
|
|
363
|
-
api_mappings: ['address1']
|
|
364
|
-
}
|
|
365
|
-
],
|
|
366
|
-
address_form: {
|
|
367
|
-
address_elements: [
|
|
368
|
-
{
|
|
369
|
-
field: 'address1',
|
|
370
|
-
width: 'full',
|
|
371
|
-
editable: true,
|
|
372
|
-
max_length: 40,
|
|
373
|
-
required: true,
|
|
374
|
-
api_mappings: ['address1']
|
|
375
|
-
},
|
|
376
|
-
{
|
|
377
|
-
field: 'postalCode',
|
|
378
|
-
width: 'half',
|
|
379
|
-
editable: false,
|
|
380
|
-
max_length: 10,
|
|
381
|
-
required: false,
|
|
382
|
-
api_mappings: ['postalCode']
|
|
383
|
-
}
|
|
384
|
-
],
|
|
385
|
-
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
386
|
-
verify_after_autocomplete: true,
|
|
387
|
-
wrap_address1_to_address2: false
|
|
388
|
-
},
|
|
389
|
-
post_address_fields: [
|
|
390
|
-
{
|
|
391
|
-
field: 'postalCode',
|
|
392
|
-
width: 'half',
|
|
393
|
-
editable: false,
|
|
394
|
-
max_length: 10,
|
|
395
|
-
required: false,
|
|
396
|
-
api_mappings: ['postalCode']
|
|
397
|
-
}
|
|
398
|
-
]
|
|
399
|
-
}
|
|
400
|
-
]);
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
test('getShippingAddressForms camelcases returned field names', async () => {
|
|
404
|
-
mockPromiseResult.mockResolvedValueOnce([[
|
|
405
|
-
{
|
|
406
|
-
title: 'United States',
|
|
407
|
-
countries: [
|
|
408
|
-
{
|
|
409
|
-
countries: [
|
|
410
|
-
{
|
|
411
|
-
country_code: 'US',
|
|
412
|
-
country_name: 'United States'
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
country_code: 'CA',
|
|
416
|
-
country_name: 'Canada'
|
|
417
|
-
}
|
|
418
|
-
]
|
|
419
|
-
}
|
|
420
|
-
],
|
|
421
|
-
pre_address_fields: [addressFormFieldEntries[0]],
|
|
422
|
-
address_form: [
|
|
423
|
-
{
|
|
424
|
-
title: 'default',
|
|
425
|
-
address_elements: addressFormFieldEntries,
|
|
426
|
-
postal_code_regex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
427
|
-
verify_after_autocomplete: true,
|
|
428
|
-
wrap_address1_to_address2: false
|
|
429
|
-
}
|
|
430
|
-
],
|
|
431
|
-
post_address_fields: [addressFormFieldEntries[1]]
|
|
432
|
-
}
|
|
433
|
-
]]);
|
|
434
|
-
const {getStack} = require('../src/api');
|
|
435
|
-
const Stack = getStack('dev');
|
|
436
|
-
await expect(Stack.getShippingAddressForms(['United States'], true)).resolves.toStrictEqual([
|
|
437
|
-
{
|
|
438
|
-
countries: [
|
|
439
|
-
{
|
|
440
|
-
code: 'US',
|
|
441
|
-
name: 'United States'
|
|
442
|
-
},
|
|
443
|
-
{
|
|
444
|
-
code: 'CA',
|
|
445
|
-
name: 'Canada'
|
|
446
|
-
}
|
|
447
|
-
],
|
|
448
|
-
preAddressFields: [
|
|
449
|
-
{
|
|
450
|
-
field: 'address1',
|
|
451
|
-
width: 'full',
|
|
452
|
-
editable: true,
|
|
453
|
-
maxLength: 40,
|
|
454
|
-
required: true,
|
|
455
|
-
apiMappings: ['address1']
|
|
456
|
-
}
|
|
457
|
-
],
|
|
458
|
-
addressForm: {
|
|
459
|
-
addressElements: [
|
|
460
|
-
{
|
|
461
|
-
field: 'address1',
|
|
462
|
-
width: 'full',
|
|
463
|
-
editable: true,
|
|
464
|
-
maxLength: 40,
|
|
465
|
-
required: true,
|
|
466
|
-
apiMappings: ['address1']
|
|
467
|
-
},
|
|
468
|
-
{
|
|
469
|
-
field: 'postalCode',
|
|
470
|
-
width: 'half',
|
|
471
|
-
editable: false,
|
|
472
|
-
maxLength: 10,
|
|
473
|
-
required: false,
|
|
474
|
-
apiMappings: ['postalCode']
|
|
475
|
-
}
|
|
476
|
-
],
|
|
477
|
-
postalCodeRegex: '^[0-9]{5}(?:-[0-9]{4})?$',
|
|
478
|
-
verifyAfterAutocomplete: true,
|
|
479
|
-
wrapAddress1ToAddress2: false
|
|
480
|
-
},
|
|
481
|
-
postAddressFields: [
|
|
482
|
-
{
|
|
483
|
-
field: 'postalCode',
|
|
484
|
-
width: 'half',
|
|
485
|
-
editable: false,
|
|
486
|
-
maxLength: 10,
|
|
487
|
-
required: false,
|
|
488
|
-
apiMappings: ['postalCode']
|
|
489
|
-
}
|
|
490
|
-
]
|
|
491
|
-
}
|
|
492
|
-
]);
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
test('getShippingAddressForms returns empty nested data when optional references are missing', async () => {
|
|
496
|
-
mockPromiseResult.mockResolvedValueOnce([[
|
|
497
|
-
{
|
|
498
|
-
countries: [],
|
|
499
|
-
pre_address_fields: undefined,
|
|
500
|
-
address_form: [],
|
|
501
|
-
post_address_fields: undefined
|
|
502
|
-
}
|
|
503
|
-
]]);
|
|
504
|
-
const {getStack} = require('../src/api');
|
|
505
|
-
const Stack = getStack('dev');
|
|
506
|
-
await expect(Stack.getShippingAddressForms(['Unknown'])).resolves.toStrictEqual([
|
|
507
|
-
{
|
|
508
|
-
countries: [],
|
|
509
|
-
pre_address_fields: [],
|
|
510
|
-
address_form: undefined,
|
|
511
|
-
post_address_fields: []
|
|
512
|
-
}
|
|
513
|
-
]);
|
|
514
|
-
});
|
|
515
155
|
});
|
package/docs/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
# [2.1.0-pa-1117.
|
|
1
|
+
# [2.1.0-pa-1117.10](https://code.tls.nuskin.io/ns-am/utility/npm/contentstack-lib/compare/v2.1.0-pa-1117.9...v2.1.0-pa-1117.10) (2026-05-20)
|
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.10",
|
|
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
|
@@ -179,7 +179,7 @@ async function getSingletonEntries(options) {
|
|
|
179
179
|
* @param {string[]} values
|
|
180
180
|
* @return {Promise<{Object}>} config
|
|
181
181
|
*/
|
|
182
|
-
const
|
|
182
|
+
const getMultiEntries = async (contentType, includeRefs, values) => {
|
|
183
183
|
try {
|
|
184
184
|
const [results] = await Stack
|
|
185
185
|
.ContentType(contentType)
|
|
@@ -195,76 +195,10 @@ const _getMultiEntries = async (contentType, includeRefs, values) => {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
-
/**
|
|
199
|
-
* Maps address form field entries into a small normalized dataset.
|
|
200
|
-
* @param {Object[]} addressFormFields
|
|
201
|
-
* @return {Object[]}
|
|
202
|
-
* @private
|
|
203
|
-
*/
|
|
204
|
-
const _extractAddressFormFields = (addressFormFields = [], camelcase = false) => {
|
|
205
|
-
const mappedFields = addressFormFields.map(({field, width, editable, max_length, required, api_mappings}) => ({
|
|
206
|
-
field,
|
|
207
|
-
width,
|
|
208
|
-
editable,
|
|
209
|
-
max_length: Number(max_length),
|
|
210
|
-
required,
|
|
211
|
-
api_mappings
|
|
212
|
-
}));
|
|
213
|
-
|
|
214
|
-
return camelcase ? _snakeObjectToCamel(mappedFields) : mappedFields;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const _extractAddressForm = (addressForm, camelcase = false) => {
|
|
218
|
-
if (!addressForm) {
|
|
219
|
-
return addressForm;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const mappedForm = {
|
|
223
|
-
address_elements: _extractAddressFormFields(addressForm.address_elements, camelcase),
|
|
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
|
-
};
|
|
228
|
-
|
|
229
|
-
return camelcase ? _snakeObjectToCamel(mappedForm) : mappedForm;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const _extractShippingCountries = (countries = []) => {
|
|
233
|
-
const shippingCountries = countries[0]?.countries ?? [];
|
|
234
|
-
|
|
235
|
-
return shippingCountries.map(({country_code, country_name}) => ({
|
|
236
|
-
code: country_code,
|
|
237
|
-
name: country_name
|
|
238
|
-
}));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const getShippingAddressForms = async (forms, camelcase = false) => {
|
|
242
|
-
const results = await _getMultiEntries(
|
|
243
|
-
'shipping_address_form',
|
|
244
|
-
['countries', 'pre_address_fields', 'address_form', 'address_form.address_elements', 'post_address_fields'],
|
|
245
|
-
forms
|
|
246
|
-
);
|
|
247
|
-
const mappedResults = (results || []).map((result) => ({
|
|
248
|
-
countries: _extractShippingCountries(result.countries),
|
|
249
|
-
pre_address_fields: _extractAddressFormFields(result.pre_address_fields, camelcase),
|
|
250
|
-
address_form: _extractAddressForm(result.address_form[0], camelcase),
|
|
251
|
-
post_address_fields: _extractAddressFormFields(result.post_address_fields, camelcase)
|
|
252
|
-
}));
|
|
253
|
-
|
|
254
|
-
return camelcase ? _snakeObjectToCamel(mappedResults) : mappedResults;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const getAddressForms = async (forms, camelcase = false) => {
|
|
258
|
-
const results = await _getMultiEntries('address_form', 'address_elements', forms);
|
|
259
|
-
const mappedResults = (results || []).map((result) => _extractAddressForm(result, camelcase));
|
|
260
|
-
|
|
261
|
-
return camelcase ? _snakeObjectToCamel(mappedResults) : mappedResults;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
198
|
/**
|
|
265
199
|
* Returns contentstack Stack object initialized with the api key, deliveryToken, and extended with custom functionality
|
|
266
200
|
* @param {'dev' | 'test' | 'stage' | 'prod'} envrnmnt
|
|
267
|
-
* @return {Object} Stack - contentstack Stack sdk object with additional
|
|
201
|
+
* @return {Object} Stack - contentstack Stack sdk object with additional helper functions
|
|
268
202
|
*/
|
|
269
203
|
function getStack(envrnmnt) {
|
|
270
204
|
if (!envrnmnt) {
|
|
@@ -285,11 +219,7 @@ function getStack(envrnmnt) {
|
|
|
285
219
|
|
|
286
220
|
// extend the Stack with a custom function to get translations
|
|
287
221
|
Stack.getSingletonEntries = getSingletonEntries;
|
|
288
|
-
|
|
289
|
-
Stack.getAddressForms = getAddressForms;
|
|
290
|
-
// extend the Stack with a custom function to get ShippingAddressForms
|
|
291
|
-
Stack.getShippingAddressForms = getShippingAddressForms;
|
|
292
|
-
Stack.extractAddressFormFields = _extractAddressFormFields;
|
|
222
|
+
Stack.getMultiEntries = getMultiEntries;
|
|
293
223
|
|
|
294
224
|
return Stack;
|
|
295
225
|
}
|