@sommpicks/sommpicks-shopify 24.12.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/Logger.ts +18 -0
- package/README.md +258 -0
- package/addTypings.sh +2 -0
- package/bitbucket-pipelines.yml +38 -0
- package/index.ts +132 -0
- package/package.json +57 -0
- package/publish.sh +20 -0
- package/services/CacheWrapper.ts +30 -0
- package/services/CountryCodeService.ts +507 -0
- package/shopify/ShopifyAppService.ts +109 -0
- package/shopify/ShopifyAssetService.ts +20 -0
- package/shopify/ShopifyBillingService.ts +73 -0
- package/shopify/ShopifyCartTrasnformationService.ts +207 -0
- package/shopify/ShopifyCollectionService.ts +523 -0
- package/shopify/ShopifyCustomerService.ts +472 -0
- package/shopify/ShopifyDeliveryCustomisationService.ts +220 -0
- package/shopify/ShopifyDiscountService.ts +131 -0
- package/shopify/ShopifyDraftOrderService.ts +125 -0
- package/shopify/ShopifyFulfillmentService.ts +41 -0
- package/shopify/ShopifyFunctionsProductDiscountsService.ts +166 -0
- package/shopify/ShopifyInventoryService.ts +415 -0
- package/shopify/ShopifyLocationService.ts +29 -0
- package/shopify/ShopifyOrderRefundsService.ts +138 -0
- package/shopify/ShopifyOrderRiskService.ts +19 -0
- package/shopify/ShopifyOrderService.ts +1143 -0
- package/shopify/ShopifyPageService.ts +62 -0
- package/shopify/ShopifyProductService.ts +772 -0
- package/shopify/ShopifyShippingZonesService.ts +37 -0
- package/shopify/ShopifyShopService.ts +101 -0
- package/shopify/ShopifyTemplateService.ts +30 -0
- package/shopify/ShopifyThemeService.ts +33 -0
- package/shopify/ShopifyUtils.ts +56 -0
- package/shopify/ShopifyWebhookService.ts +110 -0
- package/shopify/base/APIVersion.ts +4 -0
- package/shopify/base/AbstractService.ts +152 -0
- package/shopify/base/ErrorHelper.ts +24 -0
- package/shopify/errors/InspiraShopifyCustomError.ts +7 -0
- package/shopify/errors/InspiraShopifyError.ts +15 -0
- package/shopify/errors/InspiraShopifyUnableToReserveInventoryError.ts +7 -0
- package/shopify/helpers/ShopifyProductServiceHelper.ts +450 -0
- package/shopify/product/ShopifyProductCountService.ts +110 -0
- package/shopify/product/ShopifyProductListService.ts +333 -0
- package/shopify/product/ShopifyProductMetafieldsService.ts +405 -0
- package/shopify/product/ShopifyProductPublicationsService.ts +112 -0
- package/shopify/product/ShopifyVariantService.ts +584 -0
- package/shopify/router/ShopifyMandatoryRouter.ts +37 -0
- package/shopify/router/ShopifyRouter.ts +85 -0
- package/shopify/router/ShopifyRouterBis.ts +85 -0
- package/shopify/router/ShopifyRouterBisBis.ts +85 -0
- package/shopify/router/ShopifyRouterBisBisBis.ts +85 -0
- package/shopify/router/ShopifyRouterBisBisBisBis.ts +85 -0
- package/shopify/router/WebhookSkipMiddleware.ts +73 -0
- package/shopify/router/services/CryptoService.ts +26 -0
- package/shopify/router/services/HmacValidator.ts +36 -0
- package/shopify/router/services/OauthService.ts +17 -0
- package/shopify/router/services/RestUtils.ts +13 -0
- package/shopify/router/services/rateLimiter/MemoryStores.ts +46 -0
- package/shopify/router/services/rateLimiter/StoreRateLimiter.ts +46 -0
- package/test/README.md +223 -0
- package/test/router/ShopifyRouter.test.ts +71 -0
- package/test/router/WebhookSkipMiddleware.test.ts +86 -0
- package/test/router/services/HmacValidator.test.ts +24 -0
- package/test/router/services/RestUtils.test.ts +13 -0
- package/test/router/services/rateLimiter/StoreRateLimiter.test.ts +62 -0
- package/test/services/CacheWrapper.test.ts +30 -0
- package/test/shopify/ShopifyOrderService.test.ts +29 -0
- package/test/shopify/ShopifyProductService.test.ts +118 -0
- package/test/shopify/ShopifyWebhookService.test.ts +105 -0
- package/tsconfig.json +10 -0
- package/typings/axios.d.ts +8 -0
- package/typings/index.d.ts +1682 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
export default class CountryCodeService {
|
|
2
|
+
public static countryCodeMap: Map<string, string> = new Map<string, string>([
|
|
3
|
+
['Afghanistan','AF'],
|
|
4
|
+
['Albania','AL'],
|
|
5
|
+
['Algeria','DZ'],
|
|
6
|
+
['American Samoa','AS'],
|
|
7
|
+
['Andorra','AD'],
|
|
8
|
+
['Angola','AO'],
|
|
9
|
+
['Anguilla','AI'],
|
|
10
|
+
['Antarctica','AQ'],
|
|
11
|
+
['Antigua and Barbuda','AG'],
|
|
12
|
+
['Argentina','AR'],
|
|
13
|
+
['Armenia','AM'],
|
|
14
|
+
['Aruba','AW'],
|
|
15
|
+
['Australia','AU'],
|
|
16
|
+
['Austria','AT'],
|
|
17
|
+
['Azerbaijan','AZ'],
|
|
18
|
+
['Bahamas','BS'],
|
|
19
|
+
['Bahrain','BH'],
|
|
20
|
+
['Bangladesh','BD'],
|
|
21
|
+
['Barbados','BB'],
|
|
22
|
+
['Belarus','BY'],
|
|
23
|
+
['Belgium','BE'],
|
|
24
|
+
['Belize','BZ'],
|
|
25
|
+
['Benin','BJ'],
|
|
26
|
+
['Bermuda','BM'],
|
|
27
|
+
['Bhutan','BT'],
|
|
28
|
+
['Bolivia','BO'],
|
|
29
|
+
['Bonaire','BQ'],
|
|
30
|
+
['Bosnia and Herzegovina','BA'],
|
|
31
|
+
['Botswana','BW'],
|
|
32
|
+
['Bouvet Island','BV'],
|
|
33
|
+
['Brazil','BR'],
|
|
34
|
+
['British Indian Ocean Territory','IO'],
|
|
35
|
+
['Brunei Darussalam','BN'],
|
|
36
|
+
['Bulgaria','BG'],
|
|
37
|
+
['Burkina Faso','BF'],
|
|
38
|
+
['Burundi','BI'],
|
|
39
|
+
['Cabo Verde','CV'],
|
|
40
|
+
['Cambodia','KH'],
|
|
41
|
+
['Cameroon','CM'],
|
|
42
|
+
['Canada','CA'],
|
|
43
|
+
['Cayman Islands','KY'],
|
|
44
|
+
['Central African Republic','CF'],
|
|
45
|
+
['Chad','TD'],
|
|
46
|
+
['Chile','CL'],
|
|
47
|
+
['China','CN'],
|
|
48
|
+
['Christmas Island','CX'],
|
|
49
|
+
['Cocos','CC'],
|
|
50
|
+
['Colombia','CO'],
|
|
51
|
+
['Comoros','KM'],
|
|
52
|
+
['Congo','CG'],
|
|
53
|
+
['Cook Islands','CK'],
|
|
54
|
+
['Costa Rica','CR'],
|
|
55
|
+
['Croatia','HR'],
|
|
56
|
+
['Cuba','CU'],
|
|
57
|
+
['Curaçao','CW'],
|
|
58
|
+
['Cyprus','CY'],
|
|
59
|
+
['Czechia','CZ'],
|
|
60
|
+
['Côte d\'Ivoire','CI'],
|
|
61
|
+
['Denmark','DK'],
|
|
62
|
+
['Djibouti','DJ'],
|
|
63
|
+
['Dominica','DM'],
|
|
64
|
+
['Dominican Republic','DO'],
|
|
65
|
+
['Ecuador','EC'],
|
|
66
|
+
['Egypt','EG'],
|
|
67
|
+
['El Salvador','SV'],
|
|
68
|
+
['Equatorial Guinea','GQ'],
|
|
69
|
+
['Eritrea','ER'],
|
|
70
|
+
['Estonia','EE'],
|
|
71
|
+
['Eswatini','SZ'],
|
|
72
|
+
['Ethiopia','ET'],
|
|
73
|
+
['Falkland Islands','FK'],
|
|
74
|
+
['Faroe Islands','FO'],
|
|
75
|
+
['Fiji','FJ'],
|
|
76
|
+
['Finland','FI'],
|
|
77
|
+
['France','FR'],
|
|
78
|
+
['French Guiana','GF'],
|
|
79
|
+
['French Polynesia','PF'],
|
|
80
|
+
['French Southern Territories','TF'],
|
|
81
|
+
['Gabon','GA'],
|
|
82
|
+
['Gambia','GM'],
|
|
83
|
+
['Georgia','GE'],
|
|
84
|
+
['Germany','DE'],
|
|
85
|
+
['Ghana','GH'],
|
|
86
|
+
['Gibraltar','GI'],
|
|
87
|
+
['Greece','GR'],
|
|
88
|
+
['Greenland','GL'],
|
|
89
|
+
['Grenada','GD'],
|
|
90
|
+
['Guadeloupe','GP'],
|
|
91
|
+
['Guam','GU'],
|
|
92
|
+
['Guatemala','GT'],
|
|
93
|
+
['Guernsey','GG'],
|
|
94
|
+
['Guinea','GN'],
|
|
95
|
+
['Guinea-Bissau','GW'],
|
|
96
|
+
['Guyana','GY'],
|
|
97
|
+
['Haiti','HT'],
|
|
98
|
+
['Heard Island and McDonald Islands','HM'],
|
|
99
|
+
['Holy See','VA'],
|
|
100
|
+
['Honduras','HN'],
|
|
101
|
+
['Hong Kong','HK'],
|
|
102
|
+
['Hungary','HU'],
|
|
103
|
+
['Iceland','IS'],
|
|
104
|
+
['India','IN'],
|
|
105
|
+
['Indonesia','ID'],
|
|
106
|
+
['Iran','IR'],
|
|
107
|
+
['Iraq','IQ'],
|
|
108
|
+
['Ireland','IE'],
|
|
109
|
+
['Isle of Man','IM'],
|
|
110
|
+
['Israel','IL'],
|
|
111
|
+
['Italy','IT'],
|
|
112
|
+
['Jamaica','JM'],
|
|
113
|
+
['Japan','JP'],
|
|
114
|
+
['Jersey','JE'],
|
|
115
|
+
['Jordan','JO'],
|
|
116
|
+
['Kazakhstan','KZ'],
|
|
117
|
+
['Kenya','KE'],
|
|
118
|
+
['Kiribati','KI'],
|
|
119
|
+
['Korea','KR'],
|
|
120
|
+
['Kuwait','KW'],
|
|
121
|
+
['Kyrgyzstan','KG'],
|
|
122
|
+
['Lao','LA'],
|
|
123
|
+
['Latvia','LV'],
|
|
124
|
+
['Lebanon','LB'],
|
|
125
|
+
['Lesotho','LS'],
|
|
126
|
+
['Liberia','LR'],
|
|
127
|
+
['Libya','LY'],
|
|
128
|
+
['Liechtenstein','LI'],
|
|
129
|
+
['Lithuania','LT'],
|
|
130
|
+
['Luxembourg','LU'],
|
|
131
|
+
['Macao','MO'],
|
|
132
|
+
['Madagascar','MG'],
|
|
133
|
+
['Malawi','MW'],
|
|
134
|
+
['Malaysia','MY'],
|
|
135
|
+
['Maldives','MV'],
|
|
136
|
+
['Mali','ML'],
|
|
137
|
+
['Malta','MT'],
|
|
138
|
+
['Marshall Islands','MH'],
|
|
139
|
+
['Martinique','MQ'],
|
|
140
|
+
['Mauritania','MR'],
|
|
141
|
+
['Mauritius','MU'],
|
|
142
|
+
['Mayotte','YT'],
|
|
143
|
+
['Mexico','MX'],
|
|
144
|
+
['Micronesia','FM'],
|
|
145
|
+
['Moldova','MD'],
|
|
146
|
+
['Monaco','MC'],
|
|
147
|
+
['Mongolia','MN'],
|
|
148
|
+
['Montenegro','ME'],
|
|
149
|
+
['Montserrat','MS'],
|
|
150
|
+
['Morocco','MA'],
|
|
151
|
+
['Mozambique','MZ'],
|
|
152
|
+
['Myanmar','MM'],
|
|
153
|
+
['Namibia','NA'],
|
|
154
|
+
['Nauru','NR'],
|
|
155
|
+
['Nepal','NP'],
|
|
156
|
+
['Netherlands','NL'],
|
|
157
|
+
['New Caledonia','NC'],
|
|
158
|
+
['New Zealand','NZ'],
|
|
159
|
+
['Nicaragua','NI'],
|
|
160
|
+
['Niger','NE'],
|
|
161
|
+
['Nigeria','NG'],
|
|
162
|
+
['Niue','NU'],
|
|
163
|
+
['Norfolk Island','NF'],
|
|
164
|
+
['Northern Mariana Islands','MP'],
|
|
165
|
+
['Norway','NO'],
|
|
166
|
+
['Oman','OM'],
|
|
167
|
+
['Pakistan','PK'],
|
|
168
|
+
['Palau','PW'],
|
|
169
|
+
['Palestine, State of','PS'],
|
|
170
|
+
['Panama','PA'],
|
|
171
|
+
['Papua New Guinea','PG'],
|
|
172
|
+
['Paraguay','PY'],
|
|
173
|
+
['Peru','PE'],
|
|
174
|
+
['Philippines','PH'],
|
|
175
|
+
['Pitcairn','PN'],
|
|
176
|
+
['Poland','PL'],
|
|
177
|
+
['Portugal','PT'],
|
|
178
|
+
['Puerto Rico','PR'],
|
|
179
|
+
['Qatar','QA'],
|
|
180
|
+
['Republic of North Macedonia','MK'],
|
|
181
|
+
['Romania','RO'],
|
|
182
|
+
['Russian Federation','RU'],
|
|
183
|
+
['Rwanda','RW'],
|
|
184
|
+
['Réunion','RE'],
|
|
185
|
+
['Saint Barthélemy','BL'],
|
|
186
|
+
['Saint Helena, Ascension and Tristan da Cunha','SH'],
|
|
187
|
+
['Saint Kitts and Nevis','KN'],
|
|
188
|
+
['Saint Lucia','LC'],
|
|
189
|
+
['Saint Martin','MF'],
|
|
190
|
+
['Saint Pierre and Miquelon','PM'],
|
|
191
|
+
['Saint Vincent and the Grenadines','VC'],
|
|
192
|
+
['Samoa','WS'],
|
|
193
|
+
['San Marino','SM'],
|
|
194
|
+
['Sao Tome and Principe','ST'],
|
|
195
|
+
['Saudi Arabia','SA'],
|
|
196
|
+
['Senegal','SN'],
|
|
197
|
+
['Serbia','RS'],
|
|
198
|
+
['Seychelles','SC'],
|
|
199
|
+
['Sierra Leone','SL'],
|
|
200
|
+
['Singapore','SG'],
|
|
201
|
+
['Sint Maarten','SX'],
|
|
202
|
+
['Slovakia','SK'],
|
|
203
|
+
['Slovenia','SI'],
|
|
204
|
+
['Solomon Islands','SB'],
|
|
205
|
+
['Somalia','SO'],
|
|
206
|
+
['South Africa','ZA'],
|
|
207
|
+
['South Georgia and the South Sandwich Islands','GS'],
|
|
208
|
+
['South Sudan','SS'],
|
|
209
|
+
['Spain','ES'],
|
|
210
|
+
['Sri Lanka','LK'],
|
|
211
|
+
['Sudan','SD'],
|
|
212
|
+
['Suriname','SR'],
|
|
213
|
+
['Svalbard and Jan Mayen','SJ'],
|
|
214
|
+
['Sweden','SE'],
|
|
215
|
+
['Switzerland','CH'],
|
|
216
|
+
['Syrian Arab Republic','SY'],
|
|
217
|
+
['Taiwan','TW'],
|
|
218
|
+
['Tajikistan','TJ'],
|
|
219
|
+
['Tanzania','TZ'],
|
|
220
|
+
['Thailand','TH'],
|
|
221
|
+
['Timor-Leste','TL'],
|
|
222
|
+
['Togo','TG'],
|
|
223
|
+
['Tokelau','TK'],
|
|
224
|
+
['Tonga','TO'],
|
|
225
|
+
['Trinidad and Tobago','TT'],
|
|
226
|
+
['Tunisia','TN'],
|
|
227
|
+
['Turkey','TR'],
|
|
228
|
+
['Turkmenistan','TM'],
|
|
229
|
+
['Turks and Caicos Islands','TC'],
|
|
230
|
+
['Tuvalu','TV'],
|
|
231
|
+
['Uganda','UG'],
|
|
232
|
+
['Ukraine','UA'],
|
|
233
|
+
['United Arab Emirates','AE'],
|
|
234
|
+
['United Kingdom','GB'],
|
|
235
|
+
['United States','US'],
|
|
236
|
+
['Uruguay','UY'],
|
|
237
|
+
['Uzbekistan','UZ'],
|
|
238
|
+
['Vanuatu','VU'],
|
|
239
|
+
['Venezuela','VE'],
|
|
240
|
+
['Viet Nam','VN'],
|
|
241
|
+
['Virgin Islands','VG'],
|
|
242
|
+
['Wallis and Futuna','WF'],
|
|
243
|
+
['Western Sahara','EH'],
|
|
244
|
+
['Yemen','YE'],
|
|
245
|
+
['Zambia','ZM'],
|
|
246
|
+
['Zimbabwe','ZW'],
|
|
247
|
+
['Åland Islands','AX']
|
|
248
|
+
]);
|
|
249
|
+
|
|
250
|
+
public static countryCodeReverseMap: Map<string, string> = new Map<string, string>([
|
|
251
|
+
['AF','Afghanistan'],
|
|
252
|
+
['AL', 'Albania'],
|
|
253
|
+
['DZ', 'Algeria'],
|
|
254
|
+
['AS', 'American Samoa'],
|
|
255
|
+
['AD', 'Andorra'],
|
|
256
|
+
['AO', 'Angola'],
|
|
257
|
+
['AI', 'Anguilla'],
|
|
258
|
+
['AQ', 'Antarctica'],
|
|
259
|
+
['AG', 'Antigua and Barbuda'],
|
|
260
|
+
['AR', 'Argentina'],
|
|
261
|
+
['AM', 'Armenia'],
|
|
262
|
+
['AW', 'Aruba'],
|
|
263
|
+
['AU', 'Australia'],
|
|
264
|
+
['AT', 'Austria'],
|
|
265
|
+
['AZ', 'Azerbaijan'],
|
|
266
|
+
['BS', 'Bahamas'],
|
|
267
|
+
['BH', 'Bahrain'],
|
|
268
|
+
['BD', 'Bangladesh'],
|
|
269
|
+
['BB', 'Barbados'],
|
|
270
|
+
['BY', 'Belarus'],
|
|
271
|
+
['BE', 'Belgium'],
|
|
272
|
+
['BZ', 'Belize'],
|
|
273
|
+
['BJ', 'Benin'],
|
|
274
|
+
['BM', 'Bermuda'],
|
|
275
|
+
['BT', 'Bhutan'],
|
|
276
|
+
['BO', 'Bolivia'],
|
|
277
|
+
['BQ', 'Bonaire'],
|
|
278
|
+
['BA', 'Bosnia and Herzegovina'],
|
|
279
|
+
['BW', 'Botswana'],
|
|
280
|
+
['BV', 'Bouvet Island'],
|
|
281
|
+
['BR', 'Brazil'],
|
|
282
|
+
['IO', 'British Indian Ocean Territory'],
|
|
283
|
+
['BN', 'Brunei Darussalam'],
|
|
284
|
+
['BG', 'Bulgaria'],
|
|
285
|
+
['BF', 'Burkina Faso'],
|
|
286
|
+
['BI', 'Burundi'],
|
|
287
|
+
['CV', 'Cabo Verde'],
|
|
288
|
+
['KH', 'Cambodia'],
|
|
289
|
+
['CM', 'Cameroon'],
|
|
290
|
+
['CA', 'Canada'],
|
|
291
|
+
['KY', 'Cayman Islands'],
|
|
292
|
+
['CF', 'Central African Republic'],
|
|
293
|
+
['TD', 'Chad'],
|
|
294
|
+
['CL', 'Chile'],
|
|
295
|
+
['CN', 'China'],
|
|
296
|
+
['CX', 'Christmas Island'],
|
|
297
|
+
['CC', 'Cocos'],
|
|
298
|
+
['CO', 'Colombia'],
|
|
299
|
+
['KM', 'Comoros'],
|
|
300
|
+
['CG', 'Congo'],
|
|
301
|
+
['CK', 'Cook Islands'],
|
|
302
|
+
['CR', 'Costa Rica'],
|
|
303
|
+
['HR', 'Croatia'],
|
|
304
|
+
['CU', 'Cuba'],
|
|
305
|
+
['CW', 'Curaçao'],
|
|
306
|
+
['CY', 'Cyprus'],
|
|
307
|
+
['CZ', 'Czechia'],
|
|
308
|
+
['CI', 'Côte d\'Ivoire'],
|
|
309
|
+
['DK','Denmark'],
|
|
310
|
+
['DJ','Djibouti'],
|
|
311
|
+
['DM','Dominica'],
|
|
312
|
+
['DO', 'Dominican Republic'],
|
|
313
|
+
['EC', 'Ecuador'],
|
|
314
|
+
['EG', 'Egypt'],
|
|
315
|
+
['SV', 'El Salvador'],
|
|
316
|
+
['GQ', 'Equatorial Guinea'],
|
|
317
|
+
['ER', 'Eritrea'],
|
|
318
|
+
['EE', 'Estonia'],
|
|
319
|
+
['SZ', 'Eswatini'],
|
|
320
|
+
['ET', 'Ethiopia'],
|
|
321
|
+
['FK', 'Falkland Islands'],
|
|
322
|
+
['FO', 'Faroe Islands'],
|
|
323
|
+
['FJ', 'Fiji'],
|
|
324
|
+
['FI', 'Finland'],
|
|
325
|
+
['FR', 'France'],
|
|
326
|
+
['GF', 'French Guiana'],
|
|
327
|
+
['PF', 'French Polynesia'],
|
|
328
|
+
['TF', 'French Southern Territories'],
|
|
329
|
+
['GA', 'Gabon'],
|
|
330
|
+
['GM', 'Gambia'],
|
|
331
|
+
['GE', 'Georgia'],
|
|
332
|
+
['DE', 'Germany'],
|
|
333
|
+
['GH', 'Ghana'],
|
|
334
|
+
['GI', 'Gibraltar'],
|
|
335
|
+
['GR', 'Greece'],
|
|
336
|
+
['GL', 'Greenland'],
|
|
337
|
+
['GD', 'Grenada'],
|
|
338
|
+
['GP', 'Guadeloupe'],
|
|
339
|
+
['GU', 'Guam'],
|
|
340
|
+
['GT', 'Guatemala'],
|
|
341
|
+
['GG', 'Guernsey'],
|
|
342
|
+
['GN', 'Guinea'],
|
|
343
|
+
['GW', 'Guinea-Bissau'],
|
|
344
|
+
['GY', 'Guyana'],
|
|
345
|
+
['HT', 'Haiti'],
|
|
346
|
+
['HM', 'Heard Island and McDonald Islands'],
|
|
347
|
+
['VA', 'Holy See'],
|
|
348
|
+
['HN', 'Honduras'],
|
|
349
|
+
['HK', 'Hong Kong'],
|
|
350
|
+
['HU', 'Hungary'],
|
|
351
|
+
['IS', 'Iceland'],
|
|
352
|
+
['IN', 'India'],
|
|
353
|
+
['ID', 'Indonesia'],
|
|
354
|
+
['IR', 'Iran'],
|
|
355
|
+
['IQ', 'Iraq'],
|
|
356
|
+
['IE', 'Ireland'],
|
|
357
|
+
['IM', 'Isle of Man'],
|
|
358
|
+
['IL', 'Israel'],
|
|
359
|
+
['IT', 'Italy'],
|
|
360
|
+
['JM', 'Jamaica'],
|
|
361
|
+
['JP', 'Japan'],
|
|
362
|
+
['JE', 'Jersey'],
|
|
363
|
+
['JO', 'Jordan'],
|
|
364
|
+
['KZ', 'Kazakhstan'],
|
|
365
|
+
['KE', 'Kenya'],
|
|
366
|
+
['KI', 'Kiribati'],
|
|
367
|
+
['KR', 'Korea'],
|
|
368
|
+
['KW', 'Kuwait'],
|
|
369
|
+
['KG', 'Kyrgyzstan'],
|
|
370
|
+
['LA', 'Lao'],
|
|
371
|
+
['LV', 'Latvia'],
|
|
372
|
+
['LB', 'Lebanon'],
|
|
373
|
+
['LS', 'Lesotho'],
|
|
374
|
+
['LR', 'Liberia'],
|
|
375
|
+
['LY', 'Libya'],
|
|
376
|
+
['LI', 'Liechtenstein'],
|
|
377
|
+
['LT', 'Lithuania'],
|
|
378
|
+
['LU', 'Luxembourg'],
|
|
379
|
+
['MO', 'Macao'],
|
|
380
|
+
['MG', 'Madagascar'],
|
|
381
|
+
['MW', 'Malawi'],
|
|
382
|
+
['MY', 'Malaysia'],
|
|
383
|
+
['MV', 'Maldives'],
|
|
384
|
+
['ML', 'Mali'],
|
|
385
|
+
['MT', 'Malta'],
|
|
386
|
+
['MH', 'Marshall Islands'],
|
|
387
|
+
['MQ', 'Martinique'],
|
|
388
|
+
['MR', 'Mauritania'],
|
|
389
|
+
['MU', 'Mauritius'],
|
|
390
|
+
['YT', 'Mayotte'],
|
|
391
|
+
['MX', 'Mexico'],
|
|
392
|
+
['FM', 'Micronesia'],
|
|
393
|
+
['MD', 'Moldova'],
|
|
394
|
+
['MC', 'Monaco'],
|
|
395
|
+
['MN', 'Mongolia'],
|
|
396
|
+
['ME', 'Montenegro'],
|
|
397
|
+
['MS', 'Montserrat'],
|
|
398
|
+
['MA', 'Morocco'],
|
|
399
|
+
['MZ', 'Mozambique'],
|
|
400
|
+
['MM', 'Myanmar'],
|
|
401
|
+
['NA', 'Namibia'],
|
|
402
|
+
['NR', 'Nauru'],
|
|
403
|
+
['NP', 'Nepal'],
|
|
404
|
+
['NL', 'Netherlands'],
|
|
405
|
+
['NC', 'New Caledonia'],
|
|
406
|
+
['NZ', 'New Zealand'],
|
|
407
|
+
['NI', 'Nicaragua'],
|
|
408
|
+
['NE', 'Niger'],
|
|
409
|
+
['NG', 'Nigeria'],
|
|
410
|
+
['NU', 'Niue'],
|
|
411
|
+
['NF', 'Norfolk Island'],
|
|
412
|
+
['MP', 'Northern Mariana Islands'],
|
|
413
|
+
['NO', 'Norway'],
|
|
414
|
+
['OM', 'Oman'],
|
|
415
|
+
['PK', 'Pakistan'],
|
|
416
|
+
['PW', 'Palau'],
|
|
417
|
+
['PS', 'Palestine, State of'],
|
|
418
|
+
['PA', 'Panama'],
|
|
419
|
+
['PG', 'Papua New Guinea'],
|
|
420
|
+
['PY', 'Paraguay'],
|
|
421
|
+
['PE', 'Peru'],
|
|
422
|
+
['PH', 'Philippines'],
|
|
423
|
+
['PN', 'Pitcairn'],
|
|
424
|
+
['PL', 'Poland'],
|
|
425
|
+
['PT', 'Portugal'],
|
|
426
|
+
['PR', 'Puerto Rico'],
|
|
427
|
+
['QA', 'Qatar'],
|
|
428
|
+
['MK', 'Republic of North Macedonia'],
|
|
429
|
+
['RO', 'Romania'],
|
|
430
|
+
['RU', 'Russian Federation'],
|
|
431
|
+
['RW', 'Rwanda'],
|
|
432
|
+
['RE', 'Réunion'],
|
|
433
|
+
['BL', 'Saint Barthélemy'],
|
|
434
|
+
['SH', 'Saint Helena, Ascension and Tan da Cunha'],
|
|
435
|
+
['KN', 'Saint Kitts and Nevis'],
|
|
436
|
+
['LC', 'Saint Lucia'],
|
|
437
|
+
['MF', 'Saint Martin'],
|
|
438
|
+
['PM', 'Saint Pierre and Miquelon'],
|
|
439
|
+
['VC', 'Saint Vincent and the Grenadi'],
|
|
440
|
+
['WS', 'Samoa'],
|
|
441
|
+
['SM', 'San Marino'],
|
|
442
|
+
['ST', 'Sao Tome and Principe'],
|
|
443
|
+
['SA', 'Saudi Arabia'],
|
|
444
|
+
['SN', 'Senegal'],
|
|
445
|
+
['RS', 'Serbia'],
|
|
446
|
+
['SC', 'Seychelles'],
|
|
447
|
+
['SL', 'Sierra Leone'],
|
|
448
|
+
['SG', 'Singapore'],
|
|
449
|
+
['SX', 'Sint Maarten'],
|
|
450
|
+
['SK', 'Slovakia'],
|
|
451
|
+
['SI', 'Slovenia'],
|
|
452
|
+
['SB', 'Solomon Islands'],
|
|
453
|
+
['SO', 'Somalia'],
|
|
454
|
+
['ZA', 'South Africa'],
|
|
455
|
+
['GS', 'South Georgia and the South SanSich Islands'],
|
|
456
|
+
['SS', 'South Sudan'],
|
|
457
|
+
['ES', 'Spain'],
|
|
458
|
+
['LK', 'Sri Lanka'],
|
|
459
|
+
['SD', 'Sudan'],
|
|
460
|
+
['SR', 'Suriname'],
|
|
461
|
+
['SJ', 'Svalbard and Jan Mayen'],
|
|
462
|
+
['SE', 'Sweden'],
|
|
463
|
+
['CH', 'Switzerland'],
|
|
464
|
+
['SY', 'Syrian Arab Republic'],
|
|
465
|
+
['TW', 'Taiwan'],
|
|
466
|
+
['TJ', 'Tajikistan'],
|
|
467
|
+
['TZ', 'Tanzania'],
|
|
468
|
+
['TH', 'Thailand'],
|
|
469
|
+
['TL', 'Timor-Leste'],
|
|
470
|
+
['TG', 'Togo'],
|
|
471
|
+
['TK', 'Tokelau'],
|
|
472
|
+
['TO', 'Tonga'],
|
|
473
|
+
['TT', 'Trinidad and Tobago'],
|
|
474
|
+
['TN', 'Tunisia'],
|
|
475
|
+
['TR', 'Turkey'],
|
|
476
|
+
['TM', 'Turkmenistan'],
|
|
477
|
+
['TC', 'Turks and Caicos Islands'],
|
|
478
|
+
['TV', 'Tuvalu'],
|
|
479
|
+
['UG', 'Uganda'],
|
|
480
|
+
['UA', 'Ukraine'],
|
|
481
|
+
['AE', 'United Arab Emirates'],
|
|
482
|
+
['GB', 'United Kingdom'],
|
|
483
|
+
['US', 'United States'],
|
|
484
|
+
['UY', 'Uruguay'],
|
|
485
|
+
['UZ', 'Uzbekistan'],
|
|
486
|
+
['VU', 'Vanuatu'],
|
|
487
|
+
['VE', 'Venezuela'],
|
|
488
|
+
['VN', 'Viet Nam'],
|
|
489
|
+
['VG', 'Virgin Islands'],
|
|
490
|
+
['WF', 'Wallis and Futuna'],
|
|
491
|
+
['EH', 'Western Sahara'],
|
|
492
|
+
['YE', 'Yemen'],
|
|
493
|
+
['ZM', 'Zambia'],
|
|
494
|
+
['ZW', 'Zimbabwe'],
|
|
495
|
+
['AX', 'Åland Islands']
|
|
496
|
+
]);
|
|
497
|
+
|
|
498
|
+
public static getCountryCode = (countryName: string): string =>{
|
|
499
|
+
if(CountryCodeService.countryCodeMap.has(countryName)) {
|
|
500
|
+
return CountryCodeService.countryCodeMap.get(countryName);
|
|
501
|
+
} else if(CountryCodeService.countryCodeReverseMap.has(countryName)){
|
|
502
|
+
return countryName;
|
|
503
|
+
} else {
|
|
504
|
+
return 'GB';
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { print } from 'graphql';
|
|
3
|
+
import gql from 'graphql-tag';
|
|
4
|
+
import { Logger } from '../Logger';
|
|
5
|
+
import { AbstractService } from './base/AbstractService';
|
|
6
|
+
import InspiraShopifyError from './errors/InspiraShopifyError';
|
|
7
|
+
import ErrorHelper from './base/ErrorHelper';
|
|
8
|
+
|
|
9
|
+
export class ShopifyAppService extends AbstractService {
|
|
10
|
+
|
|
11
|
+
constructor(private axiosInstance: AxiosInstance) {
|
|
12
|
+
super();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get APP installation
|
|
17
|
+
*
|
|
18
|
+
* @returns Promise
|
|
19
|
+
*/
|
|
20
|
+
public getInstallationId = async (): Promise<{id: string;}> => {
|
|
21
|
+
try {
|
|
22
|
+
Logger.info('Getting app installation');
|
|
23
|
+
const query = gql `query { currentAppInstallation {
|
|
24
|
+
id
|
|
25
|
+
}
|
|
26
|
+
}`;
|
|
27
|
+
const response = await this.axiosInstance.post('/graphql.json', { query: print(query),
|
|
28
|
+
variables: {} }, { query_cost: 10 });
|
|
29
|
+
|
|
30
|
+
if(response && response.data && response.data.data && response.data.data.currentAppInstallation && response.data.data.currentAppInstallation.id ){
|
|
31
|
+
return { id: response.data.data.currentAppInstallation.id };
|
|
32
|
+
} else {
|
|
33
|
+
Logger.error(`Get APP installation ID. Error is ${JSON.stringify(response.data.errors)}. All data is ${JSON.stringify(response.data)}` );
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
} catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); throw new InspiraShopifyError(error); }
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get APP installation and a metafield
|
|
41
|
+
*
|
|
42
|
+
* @returns Promise
|
|
43
|
+
*/
|
|
44
|
+
public getInstallationIdAndMetafield = async (namespace: string, key: string): Promise<{id: string; metafield: { value: string; key: string; type: string; namespace: string; }}> => {
|
|
45
|
+
try {
|
|
46
|
+
Logger.info('Getting app installation');
|
|
47
|
+
const query = gql `query { currentAppInstallation {
|
|
48
|
+
id
|
|
49
|
+
metafield(namespace: "${namespace}", key: "${key}") {
|
|
50
|
+
value
|
|
51
|
+
key
|
|
52
|
+
type
|
|
53
|
+
namespace
|
|
54
|
+
id
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}`;
|
|
58
|
+
const response = await this.axiosInstance.post('/graphql.json', { query: print(query),
|
|
59
|
+
variables: {} }, { query_cost: 10 });
|
|
60
|
+
|
|
61
|
+
if(response && response.data && response.data.data && response.data.data.currentAppInstallation && response.data.data.currentAppInstallation.id ){
|
|
62
|
+
return { id: response.data.data.currentAppInstallation.id, metafield: response.data.data.currentAppInstallation.metafield };
|
|
63
|
+
} else {
|
|
64
|
+
Logger.error(`Get APP installation ID. Error is ${JSON.stringify(response.data.errors)}. All data is ${JSON.stringify(response.data)}` );
|
|
65
|
+
}
|
|
66
|
+
} catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); throw new InspiraShopifyError(error); }
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Sets App-data metafield
|
|
71
|
+
*
|
|
72
|
+
* @param {number} appInstallationId
|
|
73
|
+
* @param {string} namespace
|
|
74
|
+
* @param {string} key
|
|
75
|
+
* @param {string} value
|
|
76
|
+
*
|
|
77
|
+
* @returns Promise
|
|
78
|
+
*/
|
|
79
|
+
public setMetafield = async (appInstallationId: string, namespace: string, key: string, value: string): Promise<{id: string;}> => {
|
|
80
|
+
try {
|
|
81
|
+
Logger.info(`Set add-data metafield for ${appInstallationId}, namespace: ${namespace} and key: ${key} with val ${value}`);
|
|
82
|
+
const metafieldQuery = gql `mutation CreateAppDataMetafield($customizationId: ID!, $configurationValue: String!) {
|
|
83
|
+
metafieldsSet(metafields: [
|
|
84
|
+
{
|
|
85
|
+
ownerId: $customizationId
|
|
86
|
+
namespace: "${namespace}"
|
|
87
|
+
key: "${key}"
|
|
88
|
+
value: $configurationValue
|
|
89
|
+
type: "json"
|
|
90
|
+
}
|
|
91
|
+
]) {
|
|
92
|
+
metafields {
|
|
93
|
+
id
|
|
94
|
+
}
|
|
95
|
+
userErrors {
|
|
96
|
+
message
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}`;
|
|
100
|
+
|
|
101
|
+
const metafieldResponse = await this.axiosInstance.post('/graphql.json', { query: print(metafieldQuery),
|
|
102
|
+
variables: { customizationId: appInstallationId, configurationValue: value }}, { query_cost: 803 });
|
|
103
|
+
|
|
104
|
+
Logger.info(`Meta response ${JSON.stringify(metafieldResponse.data)}`);
|
|
105
|
+
return { id: appInstallationId };
|
|
106
|
+
} catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); throw new InspiraShopifyError(error); }
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Logger } from '../Logger';
|
|
2
|
+
import { AxiosInstance } from 'axios';
|
|
3
|
+
import ErrorHelper from './base/ErrorHelper';
|
|
4
|
+
import InspiraShopifyError from './errors/InspiraShopifyError';
|
|
5
|
+
|
|
6
|
+
export class ShopifyAssetService {
|
|
7
|
+
|
|
8
|
+
constructor(private axiosInstance: AxiosInstance) { }
|
|
9
|
+
|
|
10
|
+
public put = async (themeId: number, src: string, key: string): Promise<ITemplate> => {
|
|
11
|
+
return new Promise<ITemplate>(async (resolve, reject) => {
|
|
12
|
+
try {
|
|
13
|
+
Logger.info(`Changing / Adding asset in theme ${themeId} from ${src}`);
|
|
14
|
+
const assetRequest = { key: key, src: src };
|
|
15
|
+
const response = await this.axiosInstance.put(`/themes/${themeId}/assets.json`, { asset: assetRequest });
|
|
16
|
+
resolve(response.data.asset);
|
|
17
|
+
} catch (error) { Logger.error(error, ErrorHelper.getErrorFromResponse(error)); reject(new InspiraShopifyError(error)); }
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
}
|