ti2-bokun 1.0.6 → 1.0.13
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/index.js +644 -286
- package/package.json +2 -2
- package/resolvers/product.js +75 -4
- package/utils/bokunRequest.js +80 -0
- package/utils/bookingFields.js +211 -0
- package/utils/country.js +1177 -0
- package/utils/customFields.js +249 -0
- package/utils/customerFieldConstants.js +35 -0
- package/utils/customerInfoFields.js +321 -0
- package/utils/phone.js +303 -0
package/utils/country.js
ADDED
|
@@ -0,0 +1,1177 @@
|
|
|
1
|
+
const { buildRequestUrlAndPath, getHeaders } = require('./bokunRequest');
|
|
2
|
+
|
|
3
|
+
const COUNTRIES_CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This is a list of countries that are supported by Bokun.
|
|
7
|
+
* It is used to validate the country of the contact. This list is returned
|
|
8
|
+
* from the Bokun https://api.bokuntest.com/country.json/findAll endpoint.
|
|
9
|
+
*
|
|
10
|
+
* This is the default list of countries that are supported by Bokun.
|
|
11
|
+
* We are fetching the latest list from the Bokun API at runtime and
|
|
12
|
+
* caching it for 7 days.
|
|
13
|
+
*/
|
|
14
|
+
const COUNTRIES = [
|
|
15
|
+
{
|
|
16
|
+
isoCode: 'AF',
|
|
17
|
+
title: 'Afghanistan',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
isoCode: 'AL',
|
|
21
|
+
title: 'Albania',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
isoCode: 'DZ',
|
|
25
|
+
title: 'Algeria',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
isoCode: 'AS',
|
|
29
|
+
title: 'American Samoa',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
isoCode: 'AD',
|
|
33
|
+
title: 'Andorra',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
isoCode: 'AO',
|
|
37
|
+
title: 'Angola',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
isoCode: 'AI',
|
|
41
|
+
title: 'Anguilla',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
isoCode: 'AQ',
|
|
45
|
+
title: 'Antarctica',
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
isoCode: 'AG',
|
|
49
|
+
title: 'Antigua & Barbuda',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
isoCode: 'AR',
|
|
53
|
+
title: 'Argentina',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
isoCode: 'AM',
|
|
57
|
+
title: 'Armenia',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
isoCode: 'AW',
|
|
61
|
+
title: 'Aruba',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
isoCode: 'AU',
|
|
65
|
+
title: 'Australia',
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
isoCode: 'AT',
|
|
69
|
+
title: 'Austria',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
isoCode: 'AZ',
|
|
73
|
+
title: 'Azerbaijan',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
isoCode: 'BS',
|
|
77
|
+
title: 'Bahamas',
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
isoCode: 'BH',
|
|
81
|
+
title: 'Bahrain',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
isoCode: 'BD',
|
|
85
|
+
title: 'Bangladesh',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
isoCode: 'BB',
|
|
89
|
+
title: 'Barbados',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
isoCode: 'BY',
|
|
93
|
+
title: 'Belarus',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
isoCode: 'BE',
|
|
97
|
+
title: 'Belgium',
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
isoCode: 'BZ',
|
|
101
|
+
title: 'Belize',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
isoCode: 'BJ',
|
|
105
|
+
title: 'Benin',
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
isoCode: 'BM',
|
|
109
|
+
title: 'Bermuda',
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
isoCode: 'BT',
|
|
113
|
+
title: 'Bhutan',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
isoCode: 'BO',
|
|
117
|
+
title: 'Bolivia',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
isoCode: 'BA',
|
|
121
|
+
title: 'Bosnia & Herzegovina',
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
isoCode: 'BW',
|
|
125
|
+
title: 'Botswana',
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
isoCode: 'BV',
|
|
129
|
+
title: 'Bouvet Island',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
isoCode: 'BR',
|
|
133
|
+
title: 'Brazil',
|
|
134
|
+
},
|
|
135
|
+
{
|
|
136
|
+
isoCode: 'IO',
|
|
137
|
+
title: 'British Indian Ocean Territory',
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
isoCode: 'VG',
|
|
141
|
+
title: 'British Virgin Islands',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
isoCode: 'BN',
|
|
145
|
+
title: 'Brunei',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
isoCode: 'BG',
|
|
149
|
+
title: 'Bulgaria',
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
isoCode: 'BF',
|
|
153
|
+
title: 'Burkina Faso',
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
isoCode: 'BI',
|
|
157
|
+
title: 'Burundi',
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
isoCode: 'KH',
|
|
161
|
+
title: 'Cambodia',
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
isoCode: 'CM',
|
|
165
|
+
title: 'Cameroon',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
isoCode: 'CA',
|
|
169
|
+
title: 'Canada',
|
|
170
|
+
},
|
|
171
|
+
{
|
|
172
|
+
isoCode: 'CV',
|
|
173
|
+
title: 'Cape Verde',
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
isoCode: 'BQ',
|
|
177
|
+
title: 'Caribbean Netherlands',
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
isoCode: 'KY',
|
|
181
|
+
title: 'Cayman Islands',
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
isoCode: 'CF',
|
|
185
|
+
title: 'Central African Republic',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
isoCode: 'TD',
|
|
189
|
+
title: 'Chad',
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
isoCode: 'CL',
|
|
193
|
+
title: 'Chile',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
isoCode: 'CN',
|
|
197
|
+
title: 'China',
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
isoCode: 'CX',
|
|
201
|
+
title: 'Christmas Island',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
isoCode: 'CC',
|
|
205
|
+
title: 'Cocos (Keeling) Islands',
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
isoCode: 'CO',
|
|
209
|
+
title: 'Colombia',
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
isoCode: 'KM',
|
|
213
|
+
title: 'Comoros',
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
isoCode: 'CG',
|
|
217
|
+
title: 'Congo - Brazzaville',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
isoCode: 'CD',
|
|
221
|
+
title: 'Congo - Kinshasa',
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
isoCode: 'CK',
|
|
225
|
+
title: 'Cook Islands',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
isoCode: 'CR',
|
|
229
|
+
title: 'Costa Rica',
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
isoCode: 'HR',
|
|
233
|
+
title: 'Croatia',
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
isoCode: 'CU',
|
|
237
|
+
title: 'Cuba',
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
isoCode: 'CW',
|
|
241
|
+
title: 'Curaçao',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
isoCode: 'CY',
|
|
245
|
+
title: 'Cyprus',
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
isoCode: 'CZ',
|
|
249
|
+
title: 'Czechia',
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
isoCode: 'CI',
|
|
253
|
+
title: 'Côte d’Ivoire',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
isoCode: 'DK',
|
|
257
|
+
title: 'Denmark',
|
|
258
|
+
},
|
|
259
|
+
{
|
|
260
|
+
isoCode: 'DJ',
|
|
261
|
+
title: 'Djibouti',
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
isoCode: 'DM',
|
|
265
|
+
title: 'Dominica',
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
isoCode: 'DO',
|
|
269
|
+
title: 'Dominican Republic',
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
isoCode: 'EC',
|
|
273
|
+
title: 'Ecuador',
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
isoCode: 'EG',
|
|
277
|
+
title: 'Egypt',
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
isoCode: 'SV',
|
|
281
|
+
title: 'El Salvador',
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
isoCode: 'GQ',
|
|
285
|
+
title: 'Equatorial Guinea',
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
isoCode: 'ER',
|
|
289
|
+
title: 'Eritrea',
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
isoCode: 'EE',
|
|
293
|
+
title: 'Estonia',
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
isoCode: 'SZ',
|
|
297
|
+
title: 'Eswatini',
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
isoCode: 'ET',
|
|
301
|
+
title: 'Ethiopia',
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
isoCode: 'FK',
|
|
305
|
+
title: 'Falkland Islands',
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
isoCode: 'FO',
|
|
309
|
+
title: 'Faroe Islands',
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
isoCode: 'FJ',
|
|
313
|
+
title: 'Fiji',
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
isoCode: 'FI',
|
|
317
|
+
title: 'Finland',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
isoCode: 'FR',
|
|
321
|
+
title: 'France',
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
isoCode: 'GF',
|
|
325
|
+
title: 'French Guiana',
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
isoCode: 'PF',
|
|
329
|
+
title: 'French Polynesia',
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
isoCode: 'TF',
|
|
333
|
+
title: 'French Southern Territories',
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
isoCode: 'GA',
|
|
337
|
+
title: 'Gabon',
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
isoCode: 'GM',
|
|
341
|
+
title: 'Gambia',
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
isoCode: 'GE',
|
|
345
|
+
title: 'Georgia',
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
isoCode: 'DE',
|
|
349
|
+
title: 'Germany',
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
isoCode: 'GH',
|
|
353
|
+
title: 'Ghana',
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
isoCode: 'GI',
|
|
357
|
+
title: 'Gibraltar',
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
isoCode: 'GR',
|
|
361
|
+
title: 'Greece',
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
isoCode: 'GL',
|
|
365
|
+
title: 'Greenland',
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
isoCode: 'GD',
|
|
369
|
+
title: 'Grenada',
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
isoCode: 'GP',
|
|
373
|
+
title: 'Guadeloupe',
|
|
374
|
+
},
|
|
375
|
+
{
|
|
376
|
+
isoCode: 'GU',
|
|
377
|
+
title: 'Guam',
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
isoCode: 'GT',
|
|
381
|
+
title: 'Guatemala',
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
isoCode: 'GG',
|
|
385
|
+
title: 'Guernsey',
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
isoCode: 'GN',
|
|
389
|
+
title: 'Guinea',
|
|
390
|
+
},
|
|
391
|
+
{
|
|
392
|
+
isoCode: 'GW',
|
|
393
|
+
title: 'Guinea-Bissau',
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
isoCode: 'GY',
|
|
397
|
+
title: 'Guyana',
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
isoCode: 'HT',
|
|
401
|
+
title: 'Haiti',
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
isoCode: 'HM',
|
|
405
|
+
title: 'Heard & McDonald Islands',
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
isoCode: 'HN',
|
|
409
|
+
title: 'Honduras',
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
isoCode: 'HK',
|
|
413
|
+
title: 'Hong Kong SAR China',
|
|
414
|
+
},
|
|
415
|
+
{
|
|
416
|
+
isoCode: 'HU',
|
|
417
|
+
title: 'Hungary',
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
isoCode: 'IS',
|
|
421
|
+
title: 'Iceland',
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
isoCode: 'IN',
|
|
425
|
+
title: 'India',
|
|
426
|
+
},
|
|
427
|
+
{
|
|
428
|
+
isoCode: 'ID',
|
|
429
|
+
title: 'Indonesia',
|
|
430
|
+
},
|
|
431
|
+
{
|
|
432
|
+
isoCode: 'IR',
|
|
433
|
+
title: 'Iran',
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
isoCode: 'IQ',
|
|
437
|
+
title: 'Iraq',
|
|
438
|
+
},
|
|
439
|
+
{
|
|
440
|
+
isoCode: 'IE',
|
|
441
|
+
title: 'Ireland',
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
isoCode: 'IM',
|
|
445
|
+
title: 'Isle of Man',
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
isoCode: 'IL',
|
|
449
|
+
title: 'Israel',
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
isoCode: 'IT',
|
|
453
|
+
title: 'Italy',
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
isoCode: 'JM',
|
|
457
|
+
title: 'Jamaica',
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
isoCode: 'JP',
|
|
461
|
+
title: 'Japan',
|
|
462
|
+
},
|
|
463
|
+
{
|
|
464
|
+
isoCode: 'JE',
|
|
465
|
+
title: 'Jersey',
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
isoCode: 'JO',
|
|
469
|
+
title: 'Jordan',
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
isoCode: 'KZ',
|
|
473
|
+
title: 'Kazakhstan',
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
isoCode: 'KE',
|
|
477
|
+
title: 'Kenya',
|
|
478
|
+
},
|
|
479
|
+
{
|
|
480
|
+
isoCode: 'KI',
|
|
481
|
+
title: 'Kiribati',
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
isoCode: 'KW',
|
|
485
|
+
title: 'Kuwait',
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
isoCode: 'KG',
|
|
489
|
+
title: 'Kyrgyzstan',
|
|
490
|
+
},
|
|
491
|
+
{
|
|
492
|
+
isoCode: 'LA',
|
|
493
|
+
title: 'Laos',
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
isoCode: 'LV',
|
|
497
|
+
title: 'Latvia',
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
isoCode: 'LB',
|
|
501
|
+
title: 'Lebanon',
|
|
502
|
+
},
|
|
503
|
+
{
|
|
504
|
+
isoCode: 'LS',
|
|
505
|
+
title: 'Lesotho',
|
|
506
|
+
},
|
|
507
|
+
{
|
|
508
|
+
isoCode: 'LR',
|
|
509
|
+
title: 'Liberia',
|
|
510
|
+
},
|
|
511
|
+
{
|
|
512
|
+
isoCode: 'LY',
|
|
513
|
+
title: 'Libya',
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
isoCode: 'LI',
|
|
517
|
+
title: 'Liechtenstein',
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
isoCode: 'LT',
|
|
521
|
+
title: 'Lithuania',
|
|
522
|
+
},
|
|
523
|
+
{
|
|
524
|
+
isoCode: 'LU',
|
|
525
|
+
title: 'Luxembourg',
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
isoCode: 'MO',
|
|
529
|
+
title: 'Macao SAR China',
|
|
530
|
+
},
|
|
531
|
+
{
|
|
532
|
+
isoCode: 'MG',
|
|
533
|
+
title: 'Madagascar',
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
isoCode: 'MW',
|
|
537
|
+
title: 'Malawi',
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
isoCode: 'MY',
|
|
541
|
+
title: 'Malaysia',
|
|
542
|
+
},
|
|
543
|
+
{
|
|
544
|
+
isoCode: 'MV',
|
|
545
|
+
title: 'Maldives',
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
isoCode: 'ML',
|
|
549
|
+
title: 'Mali',
|
|
550
|
+
},
|
|
551
|
+
{
|
|
552
|
+
isoCode: 'MT',
|
|
553
|
+
title: 'Malta',
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
isoCode: 'MH',
|
|
557
|
+
title: 'Marshall Islands',
|
|
558
|
+
},
|
|
559
|
+
{
|
|
560
|
+
isoCode: 'MQ',
|
|
561
|
+
title: 'Martinique',
|
|
562
|
+
},
|
|
563
|
+
{
|
|
564
|
+
isoCode: 'MR',
|
|
565
|
+
title: 'Mauritania',
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
isoCode: 'MU',
|
|
569
|
+
title: 'Mauritius',
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
isoCode: 'YT',
|
|
573
|
+
title: 'Mayotte',
|
|
574
|
+
},
|
|
575
|
+
{
|
|
576
|
+
isoCode: 'MX',
|
|
577
|
+
title: 'Mexico',
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
isoCode: 'FM',
|
|
581
|
+
title: 'Micronesia',
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
isoCode: 'MD',
|
|
585
|
+
title: 'Moldova',
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
isoCode: 'MC',
|
|
589
|
+
title: 'Monaco',
|
|
590
|
+
},
|
|
591
|
+
{
|
|
592
|
+
isoCode: 'MN',
|
|
593
|
+
title: 'Mongolia',
|
|
594
|
+
},
|
|
595
|
+
{
|
|
596
|
+
isoCode: 'ME',
|
|
597
|
+
title: 'Montenegro',
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
isoCode: 'MS',
|
|
601
|
+
title: 'Montserrat',
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
isoCode: 'MA',
|
|
605
|
+
title: 'Morocco',
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
isoCode: 'MZ',
|
|
609
|
+
title: 'Mozambique',
|
|
610
|
+
},
|
|
611
|
+
{
|
|
612
|
+
isoCode: 'MM',
|
|
613
|
+
title: 'Myanmar (Burma)',
|
|
614
|
+
},
|
|
615
|
+
{
|
|
616
|
+
isoCode: 'NA',
|
|
617
|
+
title: 'Namibia',
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
isoCode: 'NR',
|
|
621
|
+
title: 'Nauru',
|
|
622
|
+
},
|
|
623
|
+
{
|
|
624
|
+
isoCode: 'NP',
|
|
625
|
+
title: 'Nepal',
|
|
626
|
+
},
|
|
627
|
+
{
|
|
628
|
+
isoCode: 'NL',
|
|
629
|
+
title: 'Netherlands',
|
|
630
|
+
},
|
|
631
|
+
{
|
|
632
|
+
isoCode: 'NC',
|
|
633
|
+
title: 'New Caledonia',
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
isoCode: 'NZ',
|
|
637
|
+
title: 'New Zealand',
|
|
638
|
+
},
|
|
639
|
+
{
|
|
640
|
+
isoCode: 'NI',
|
|
641
|
+
title: 'Nicaragua',
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
isoCode: 'NE',
|
|
645
|
+
title: 'Niger',
|
|
646
|
+
},
|
|
647
|
+
{
|
|
648
|
+
isoCode: 'NG',
|
|
649
|
+
title: 'Nigeria',
|
|
650
|
+
},
|
|
651
|
+
{
|
|
652
|
+
isoCode: 'NU',
|
|
653
|
+
title: 'Niue',
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
isoCode: 'NF',
|
|
657
|
+
title: 'Norfolk Island',
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
isoCode: 'KP',
|
|
661
|
+
title: 'North Korea',
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
isoCode: 'MK',
|
|
665
|
+
title: 'North Macedonia',
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
isoCode: 'MP',
|
|
669
|
+
title: 'Northern Mariana Islands',
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
isoCode: 'NO',
|
|
673
|
+
title: 'Norway',
|
|
674
|
+
},
|
|
675
|
+
{
|
|
676
|
+
isoCode: 'OM',
|
|
677
|
+
title: 'Oman',
|
|
678
|
+
},
|
|
679
|
+
{
|
|
680
|
+
isoCode: 'PK',
|
|
681
|
+
title: 'Pakistan',
|
|
682
|
+
},
|
|
683
|
+
{
|
|
684
|
+
isoCode: 'PW',
|
|
685
|
+
title: 'Palau',
|
|
686
|
+
},
|
|
687
|
+
{
|
|
688
|
+
isoCode: 'PS',
|
|
689
|
+
title: 'Palestinian Territories',
|
|
690
|
+
},
|
|
691
|
+
{
|
|
692
|
+
isoCode: 'PA',
|
|
693
|
+
title: 'Panama',
|
|
694
|
+
},
|
|
695
|
+
{
|
|
696
|
+
isoCode: 'PG',
|
|
697
|
+
title: 'Papua New Guinea',
|
|
698
|
+
},
|
|
699
|
+
{
|
|
700
|
+
isoCode: 'PY',
|
|
701
|
+
title: 'Paraguay',
|
|
702
|
+
},
|
|
703
|
+
{
|
|
704
|
+
isoCode: 'PE',
|
|
705
|
+
title: 'Peru',
|
|
706
|
+
},
|
|
707
|
+
{
|
|
708
|
+
isoCode: 'PH',
|
|
709
|
+
title: 'Philippines',
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
isoCode: 'PN',
|
|
713
|
+
title: 'Pitcairn Islands',
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
isoCode: 'PL',
|
|
717
|
+
title: 'Poland',
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
isoCode: 'PT',
|
|
721
|
+
title: 'Portugal',
|
|
722
|
+
},
|
|
723
|
+
{
|
|
724
|
+
isoCode: 'PR',
|
|
725
|
+
title: 'Puerto Rico',
|
|
726
|
+
},
|
|
727
|
+
{
|
|
728
|
+
isoCode: 'QA',
|
|
729
|
+
title: 'Qatar',
|
|
730
|
+
},
|
|
731
|
+
{
|
|
732
|
+
isoCode: 'RO',
|
|
733
|
+
title: 'Romania',
|
|
734
|
+
},
|
|
735
|
+
{
|
|
736
|
+
isoCode: 'RU',
|
|
737
|
+
title: 'Russia',
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
isoCode: 'RW',
|
|
741
|
+
title: 'Rwanda',
|
|
742
|
+
},
|
|
743
|
+
{
|
|
744
|
+
isoCode: 'RE',
|
|
745
|
+
title: 'Réunion',
|
|
746
|
+
},
|
|
747
|
+
{
|
|
748
|
+
isoCode: 'WS',
|
|
749
|
+
title: 'Samoa',
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
isoCode: 'SM',
|
|
753
|
+
title: 'San Marino',
|
|
754
|
+
},
|
|
755
|
+
{
|
|
756
|
+
isoCode: 'SA',
|
|
757
|
+
title: 'Saudi Arabia',
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
isoCode: 'SN',
|
|
761
|
+
title: 'Senegal',
|
|
762
|
+
},
|
|
763
|
+
{
|
|
764
|
+
isoCode: 'RS',
|
|
765
|
+
title: 'Serbia',
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
isoCode: 'SC',
|
|
769
|
+
title: 'Seychelles',
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
isoCode: 'SL',
|
|
773
|
+
title: 'Sierra Leone',
|
|
774
|
+
},
|
|
775
|
+
{
|
|
776
|
+
isoCode: 'SG',
|
|
777
|
+
title: 'Singapore',
|
|
778
|
+
},
|
|
779
|
+
{
|
|
780
|
+
isoCode: 'SX',
|
|
781
|
+
title: 'Sint Maarten',
|
|
782
|
+
},
|
|
783
|
+
{
|
|
784
|
+
isoCode: 'SK',
|
|
785
|
+
title: 'Slovakia',
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
isoCode: 'SI',
|
|
789
|
+
title: 'Slovenia',
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
isoCode: 'SB',
|
|
793
|
+
title: 'Solomon Islands',
|
|
794
|
+
},
|
|
795
|
+
{
|
|
796
|
+
isoCode: 'SO',
|
|
797
|
+
title: 'Somalia',
|
|
798
|
+
},
|
|
799
|
+
{
|
|
800
|
+
isoCode: 'ZA',
|
|
801
|
+
title: 'South Africa',
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
isoCode: 'GS',
|
|
805
|
+
title: 'South Georgia & South Sandwich Islands',
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
isoCode: 'KR',
|
|
809
|
+
title: 'South Korea',
|
|
810
|
+
},
|
|
811
|
+
{
|
|
812
|
+
isoCode: 'SS',
|
|
813
|
+
title: 'South Sudan',
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
isoCode: 'ES',
|
|
817
|
+
title: 'Spain',
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
isoCode: 'LK',
|
|
821
|
+
title: 'Sri Lanka',
|
|
822
|
+
},
|
|
823
|
+
{
|
|
824
|
+
isoCode: 'BL',
|
|
825
|
+
title: 'St. Barthélemy',
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
isoCode: 'SH',
|
|
829
|
+
title: 'St. Helena',
|
|
830
|
+
},
|
|
831
|
+
{
|
|
832
|
+
isoCode: 'KN',
|
|
833
|
+
title: 'St. Kitts & Nevis',
|
|
834
|
+
},
|
|
835
|
+
{
|
|
836
|
+
isoCode: 'LC',
|
|
837
|
+
title: 'St. Lucia',
|
|
838
|
+
},
|
|
839
|
+
{
|
|
840
|
+
isoCode: 'MF',
|
|
841
|
+
title: 'St. Martin',
|
|
842
|
+
},
|
|
843
|
+
{
|
|
844
|
+
isoCode: 'PM',
|
|
845
|
+
title: 'St. Pierre & Miquelon',
|
|
846
|
+
},
|
|
847
|
+
{
|
|
848
|
+
isoCode: 'VC',
|
|
849
|
+
title: 'St. Vincent & Grenadines',
|
|
850
|
+
},
|
|
851
|
+
{
|
|
852
|
+
isoCode: 'SD',
|
|
853
|
+
title: 'Sudan',
|
|
854
|
+
},
|
|
855
|
+
{
|
|
856
|
+
isoCode: 'SR',
|
|
857
|
+
title: 'Suriname',
|
|
858
|
+
},
|
|
859
|
+
{
|
|
860
|
+
isoCode: 'SJ',
|
|
861
|
+
title: 'Svalbard & Jan Mayen',
|
|
862
|
+
},
|
|
863
|
+
{
|
|
864
|
+
isoCode: 'SE',
|
|
865
|
+
title: 'Sweden',
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
isoCode: 'CH',
|
|
869
|
+
title: 'Switzerland',
|
|
870
|
+
},
|
|
871
|
+
{
|
|
872
|
+
isoCode: 'SY',
|
|
873
|
+
title: 'Syria',
|
|
874
|
+
},
|
|
875
|
+
{
|
|
876
|
+
isoCode: 'ST',
|
|
877
|
+
title: 'São Tomé & Príncipe',
|
|
878
|
+
},
|
|
879
|
+
{
|
|
880
|
+
isoCode: 'TW',
|
|
881
|
+
title: 'Taiwan',
|
|
882
|
+
},
|
|
883
|
+
{
|
|
884
|
+
isoCode: 'TJ',
|
|
885
|
+
title: 'Tajikistan',
|
|
886
|
+
},
|
|
887
|
+
{
|
|
888
|
+
isoCode: 'TZ',
|
|
889
|
+
title: 'Tanzania',
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
isoCode: 'TH',
|
|
893
|
+
title: 'Thailand',
|
|
894
|
+
},
|
|
895
|
+
{
|
|
896
|
+
isoCode: 'TL',
|
|
897
|
+
title: 'Timor-Leste',
|
|
898
|
+
},
|
|
899
|
+
{
|
|
900
|
+
isoCode: 'TG',
|
|
901
|
+
title: 'Togo',
|
|
902
|
+
},
|
|
903
|
+
{
|
|
904
|
+
isoCode: 'TK',
|
|
905
|
+
title: 'Tokelau',
|
|
906
|
+
},
|
|
907
|
+
{
|
|
908
|
+
isoCode: 'TO',
|
|
909
|
+
title: 'Tonga',
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
isoCode: 'TT',
|
|
913
|
+
title: 'Trinidad & Tobago',
|
|
914
|
+
},
|
|
915
|
+
{
|
|
916
|
+
isoCode: 'TN',
|
|
917
|
+
title: 'Tunisia',
|
|
918
|
+
},
|
|
919
|
+
{
|
|
920
|
+
isoCode: 'TR',
|
|
921
|
+
title: 'Turkey',
|
|
922
|
+
},
|
|
923
|
+
{
|
|
924
|
+
isoCode: 'TM',
|
|
925
|
+
title: 'Turkmenistan',
|
|
926
|
+
},
|
|
927
|
+
{
|
|
928
|
+
isoCode: 'TC',
|
|
929
|
+
title: 'Turks & Caicos Islands',
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
isoCode: 'TV',
|
|
933
|
+
title: 'Tuvalu',
|
|
934
|
+
},
|
|
935
|
+
{
|
|
936
|
+
isoCode: 'UM',
|
|
937
|
+
title: 'U.S. Outlying Islands',
|
|
938
|
+
},
|
|
939
|
+
{
|
|
940
|
+
isoCode: 'VI',
|
|
941
|
+
title: 'U.S. Virgin Islands',
|
|
942
|
+
},
|
|
943
|
+
{
|
|
944
|
+
isoCode: 'UG',
|
|
945
|
+
title: 'Uganda',
|
|
946
|
+
},
|
|
947
|
+
{
|
|
948
|
+
isoCode: 'UA',
|
|
949
|
+
title: 'Ukraine',
|
|
950
|
+
},
|
|
951
|
+
{
|
|
952
|
+
isoCode: 'AE',
|
|
953
|
+
title: 'United Arab Emirates',
|
|
954
|
+
},
|
|
955
|
+
{
|
|
956
|
+
isoCode: 'GB',
|
|
957
|
+
title: 'United Kingdom',
|
|
958
|
+
},
|
|
959
|
+
{
|
|
960
|
+
isoCode: 'US',
|
|
961
|
+
title: 'United States',
|
|
962
|
+
},
|
|
963
|
+
{
|
|
964
|
+
isoCode: 'UY',
|
|
965
|
+
title: 'Uruguay',
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
isoCode: 'UZ',
|
|
969
|
+
title: 'Uzbekistan',
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
isoCode: 'VU',
|
|
973
|
+
title: 'Vanuatu',
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
isoCode: 'VA',
|
|
977
|
+
title: 'Vatican City',
|
|
978
|
+
},
|
|
979
|
+
{
|
|
980
|
+
isoCode: 'VE',
|
|
981
|
+
title: 'Venezuela',
|
|
982
|
+
},
|
|
983
|
+
{
|
|
984
|
+
isoCode: 'VN',
|
|
985
|
+
title: 'Vietnam',
|
|
986
|
+
},
|
|
987
|
+
{
|
|
988
|
+
isoCode: 'WF',
|
|
989
|
+
title: 'Wallis & Futuna',
|
|
990
|
+
},
|
|
991
|
+
{
|
|
992
|
+
isoCode: 'EH',
|
|
993
|
+
title: 'Western Sahara',
|
|
994
|
+
},
|
|
995
|
+
{
|
|
996
|
+
isoCode: 'YE',
|
|
997
|
+
title: 'Yemen',
|
|
998
|
+
},
|
|
999
|
+
{
|
|
1000
|
+
isoCode: 'ZM',
|
|
1001
|
+
title: 'Zambia',
|
|
1002
|
+
},
|
|
1003
|
+
{
|
|
1004
|
+
isoCode: 'ZW',
|
|
1005
|
+
title: 'Zimbabwe',
|
|
1006
|
+
},
|
|
1007
|
+
{
|
|
1008
|
+
isoCode: 'AX',
|
|
1009
|
+
title: 'Åland Islands',
|
|
1010
|
+
},
|
|
1011
|
+
];
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Map a Bokun-style country list (`{ isoCode, title }`) to the
|
|
1015
|
+
* `{ label, value }` option shape used by Bokun's UI fields.
|
|
1016
|
+
* Tolerates a few alternate keys so we can also accept lightly
|
|
1017
|
+
* pre-processed lists (e.g. `code`, `name`).
|
|
1018
|
+
*/
|
|
1019
|
+
const buildCountryOptions = list => (
|
|
1020
|
+
(Array.isArray(list) ? list : [])
|
|
1021
|
+
.map(country => {
|
|
1022
|
+
if (!country || typeof country !== 'object') return null;
|
|
1023
|
+
const value = country.isoCode || country.code || country.id;
|
|
1024
|
+
const label = country.title || country.name || country.label || value;
|
|
1025
|
+
if (!value || !label) return null;
|
|
1026
|
+
return { label: String(label), value: String(value) };
|
|
1027
|
+
})
|
|
1028
|
+
.filter(Boolean)
|
|
1029
|
+
);
|
|
1030
|
+
|
|
1031
|
+
// Normalize a country entry from any of the shapes we accept (raw Bokun
|
|
1032
|
+
// `{isoCode, title}`, UI option `{value, label}`, lightly preprocessed `{code,
|
|
1033
|
+
// name}`) to a single internal shape `{isoCode, title}`.
|
|
1034
|
+
const normalizeCountryEntry = entry => {
|
|
1035
|
+
if (!entry || typeof entry !== 'object') return null;
|
|
1036
|
+
const isoCode = entry.isoCode || entry.value || entry.code || entry.id;
|
|
1037
|
+
const title = entry.title || entry.label || entry.name || isoCode;
|
|
1038
|
+
if (!isoCode) return null;
|
|
1039
|
+
return { isoCode: String(isoCode), title: String(title) };
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
const buildCountryIndex = entries => {
|
|
1043
|
+
const byIso = Object.create(null);
|
|
1044
|
+
const byName = Object.create(null);
|
|
1045
|
+
entries.forEach(c => {
|
|
1046
|
+
if (!c) return;
|
|
1047
|
+
byIso[c.isoCode.toUpperCase()] = c;
|
|
1048
|
+
byName[c.title.trim().toLowerCase()] = c;
|
|
1049
|
+
});
|
|
1050
|
+
return { byIso, byName };
|
|
1051
|
+
};
|
|
1052
|
+
|
|
1053
|
+
/**
|
|
1054
|
+
* Build a country-lookup helper.
|
|
1055
|
+
*
|
|
1056
|
+
* Precedence:
|
|
1057
|
+
* - When `overrideEntries` is a non-empty list (typically the cached
|
|
1058
|
+
* response from Bokun's `/country.json/findAll`) it is treated as the
|
|
1059
|
+
* authoritative source and the bundled static list is NOT consulted.
|
|
1060
|
+
* Bokun's live list is the source of truth; falling back to the
|
|
1061
|
+
* bundled snapshot would let us silently accept countries that Bokun
|
|
1062
|
+
* has since dropped.
|
|
1063
|
+
* - When `overrideEntries` is missing or empty (no list available — e.g.
|
|
1064
|
+
* offline, network failed, or fetch hasn't happened yet) we fall back
|
|
1065
|
+
* to the bundled static list as a bootstrap so the lookup still works.
|
|
1066
|
+
*
|
|
1067
|
+
* The returned `getByIso` / `getByName` always yield `{ isoCode, title }`
|
|
1068
|
+
* so callers can be agnostic to the input shape.
|
|
1069
|
+
*/
|
|
1070
|
+
// Bundled snapshot mapped to the UI option shape. Hoisted to module scope so
|
|
1071
|
+
// it's built once at require-time rather than on every cache-miss / no-network
|
|
1072
|
+
// call into `fetchCountriesList`.
|
|
1073
|
+
const STATIC_COUNTRY_OPTIONS = buildCountryOptions(COUNTRIES);
|
|
1074
|
+
|
|
1075
|
+
const buildCountryLookup = overrideEntries => {
|
|
1076
|
+
const useOverride = Array.isArray(overrideEntries) && overrideEntries.length > 0;
|
|
1077
|
+
const index = useOverride
|
|
1078
|
+
? buildCountryIndex(overrideEntries.map(normalizeCountryEntry).filter(Boolean))
|
|
1079
|
+
: buildCountryIndex(COUNTRIES.map(normalizeCountryEntry).filter(Boolean));
|
|
1080
|
+
return {
|
|
1081
|
+
getByIso: isoCode => {
|
|
1082
|
+
if (isoCode == null) return undefined;
|
|
1083
|
+
return index.byIso[String(isoCode).trim().toUpperCase()];
|
|
1084
|
+
},
|
|
1085
|
+
getByName: name => {
|
|
1086
|
+
if (name == null) return undefined;
|
|
1087
|
+
return index.byName[String(name).trim().toLowerCase()];
|
|
1088
|
+
},
|
|
1089
|
+
};
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
/**
|
|
1093
|
+
* Fetch the Bokun country reference list for use as `options` on the
|
|
1094
|
+
* `country` and `nationality` UI fields.
|
|
1095
|
+
*
|
|
1096
|
+
* The list is small, slow-moving, and identical across products, so we
|
|
1097
|
+
* cache it on the plugin instance keyed by baseUrl for COUNTRIES_CACHE_TTL_MS
|
|
1098
|
+
* (7 days). Concurrent callers share the in-flight promise.
|
|
1099
|
+
*
|
|
1100
|
+
* If `useNetwork` is false, or axios/token/credentials are missing, we
|
|
1101
|
+
* skip the network call and return the static fallback list bundled in
|
|
1102
|
+
* this module so the response shape stays stable.
|
|
1103
|
+
*
|
|
1104
|
+
* `plugin` is expected to expose:
|
|
1105
|
+
* - `endpoint` (string, optional default base URL)
|
|
1106
|
+
* - `countriesCacheByBaseUrl` (Map-like cache shared across calls)
|
|
1107
|
+
* - `getCredentials(token)` returning `{ accessKey, secretKey }`
|
|
1108
|
+
*/
|
|
1109
|
+
const fetchCountriesList = async (plugin, { axios, token, useNetwork = true } = {}) => {
|
|
1110
|
+
const { endpoint, testMode } = token || {};
|
|
1111
|
+
const baseUrl = testMode
|
|
1112
|
+
? 'https://api.bokuntest.com'
|
|
1113
|
+
: (endpoint || plugin.endpoint || 'https://api.bokun.io');
|
|
1114
|
+
|
|
1115
|
+
const cache = plugin.countriesCacheByBaseUrl;
|
|
1116
|
+
const cached = cache?.get?.(baseUrl);
|
|
1117
|
+
const now = Date.now();
|
|
1118
|
+
if (cached?.options && cached.expiresAt > now) {
|
|
1119
|
+
return cached.options;
|
|
1120
|
+
}
|
|
1121
|
+
if (cached?.promise) return cached.promise;
|
|
1122
|
+
|
|
1123
|
+
if (!useNetwork || !axios || !token) {
|
|
1124
|
+
return STATIC_COUNTRY_OPTIONS;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
let accessKey;
|
|
1128
|
+
let secretKey;
|
|
1129
|
+
try {
|
|
1130
|
+
({ accessKey, secretKey } = plugin.getCredentials(token));
|
|
1131
|
+
} catch (_) {
|
|
1132
|
+
return STATIC_COUNTRY_OPTIONS;
|
|
1133
|
+
}
|
|
1134
|
+
if (!accessKey || !secretKey) return STATIC_COUNTRY_OPTIONS;
|
|
1135
|
+
|
|
1136
|
+
const path = '/country.json/findAll';
|
|
1137
|
+
const { url, pathForSigning } = buildRequestUrlAndPath(baseUrl, path);
|
|
1138
|
+
const headers = getHeaders({
|
|
1139
|
+
accessKey,
|
|
1140
|
+
secretKey,
|
|
1141
|
+
method: 'GET',
|
|
1142
|
+
path: pathForSigning,
|
|
1143
|
+
});
|
|
1144
|
+
|
|
1145
|
+
const promise = (async () => {
|
|
1146
|
+
try {
|
|
1147
|
+
const response = await axios({ method: 'get', url, headers });
|
|
1148
|
+
const data = (response && response.data) || [];
|
|
1149
|
+
let list = [];
|
|
1150
|
+
if (Array.isArray(data)) list = data;
|
|
1151
|
+
else if (Array.isArray(data?.items)) list = data.items;
|
|
1152
|
+
const options = buildCountryOptions(list);
|
|
1153
|
+
const finalOptions = options.length > 0 ? options : STATIC_COUNTRY_OPTIONS;
|
|
1154
|
+
cache?.set?.(baseUrl, {
|
|
1155
|
+
options: finalOptions,
|
|
1156
|
+
expiresAt: Date.now() + COUNTRIES_CACHE_TTL_MS,
|
|
1157
|
+
});
|
|
1158
|
+
return finalOptions;
|
|
1159
|
+
} catch (err) {
|
|
1160
|
+
const status = err.response?.status;
|
|
1161
|
+
console.error(
|
|
1162
|
+
`Could not fetch country list from ${baseUrl} (status ${status || 'n/a'}):`,
|
|
1163
|
+
err.response?.data || err.message,
|
|
1164
|
+
);
|
|
1165
|
+
cache?.delete?.(baseUrl);
|
|
1166
|
+
return STATIC_COUNTRY_OPTIONS;
|
|
1167
|
+
}
|
|
1168
|
+
})();
|
|
1169
|
+
|
|
1170
|
+
cache?.set?.(baseUrl, { promise, expiresAt: 0 });
|
|
1171
|
+
return promise;
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
module.exports = {
|
|
1175
|
+
buildCountryLookup,
|
|
1176
|
+
fetchCountriesList,
|
|
1177
|
+
};
|