arky-sdk 0.9.12 → 0.9.16

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.
Files changed (40) hide show
  1. package/README.md +16 -12
  2. package/dist/admin-C-ZTxvz3.d.ts +1544 -0
  3. package/dist/admin-Dm2WRN6q.d.cts +1544 -0
  4. package/dist/admin.cjs +980 -433
  5. package/dist/admin.cjs.map +1 -1
  6. package/dist/admin.d.cts +3 -3
  7. package/dist/admin.d.ts +3 -3
  8. package/dist/admin.js +980 -433
  9. package/dist/admin.js.map +1 -1
  10. package/dist/{api-D4lMmvF0.d.cts → api-D37IpMSq.d.cts} +1415 -671
  11. package/dist/{api-D4lMmvF0.d.ts → api-D37IpMSq.d.ts} +1415 -671
  12. package/dist/index.cjs +1315 -547
  13. package/dist/index.cjs.map +1 -1
  14. package/dist/index.d.cts +3 -3
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.js +1315 -547
  17. package/dist/index.js.map +1 -1
  18. package/dist/{index-Be8suRwP.d.ts → inventory-DdN96PX3.d.cts} +6 -4
  19. package/dist/{index-BS2x278C.d.cts → inventory-Dh1RevEb.d.ts} +6 -4
  20. package/dist/storefront.cjs +1210 -658
  21. package/dist/storefront.cjs.map +1 -1
  22. package/dist/storefront.d.cts +88 -285
  23. package/dist/storefront.d.ts +88 -285
  24. package/dist/storefront.js +1207 -659
  25. package/dist/storefront.js.map +1 -1
  26. package/dist/types.cjs.map +1 -1
  27. package/dist/types.d.cts +1 -1
  28. package/dist/types.d.ts +1 -1
  29. package/dist/types.js.map +1 -1
  30. package/dist/utils.cjs +198 -16
  31. package/dist/utils.cjs.map +1 -1
  32. package/dist/utils.d.cts +18 -2
  33. package/dist/utils.d.ts +18 -2
  34. package/dist/utils.js +191 -17
  35. package/dist/utils.js.map +1 -1
  36. package/package.json +4 -5
  37. package/dist/admin-D8HiRDCl.d.cts +0 -1536
  38. package/dist/admin-Dnnv18wN.d.ts +0 -1536
  39. package/scripts/contract-admin.mjs +0 -137
  40. package/scripts/contract-storefront.mjs +0 -296
package/dist/index.js CHANGED
@@ -6,32 +6,25 @@ var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
6
6
  })(PaymentMethodType || {});
7
7
 
8
8
  // src/utils/orderItems.ts
9
- function normalizeOrderQuoteItems(items) {
9
+ function sanitizePublicCheckoutItems(items) {
10
10
  return items.map((item) => {
11
- if ("type" in item) {
12
- return item;
13
- }
14
- if ("product_id" in item) {
15
- return { type: "product", ...item };
16
- }
17
- return { type: "service", ...item };
18
- });
19
- }
20
- function normalizeOrderCheckoutItems(items) {
21
- return items.map((item) => {
22
- if ("type" in item) {
23
- return item;
24
- }
25
- if ("product_id" in item) {
26
- return { type: "product", ...item };
11
+ if (item.type === "product") {
12
+ return {
13
+ type: "product",
14
+ ...item.id ? { id: item.id } : {},
15
+ product_id: item.product_id,
16
+ variant_id: item.variant_id,
17
+ quantity: item.quantity
18
+ };
27
19
  }
28
- return { type: "service", ...item };
29
- });
30
- }
31
- function normalizePublicCheckoutItems(items) {
32
- return normalizeOrderCheckoutItems(items).map((item) => {
33
- const { price: _price, ...publicItem } = item;
34
- return publicItem;
20
+ return {
21
+ type: "service",
22
+ ...item.id ? { id: item.id } : {},
23
+ service_id: item.service_id,
24
+ provider_id: item.provider_id,
25
+ slots: item.slots,
26
+ ...item.forms ? { forms: item.forms } : {}
27
+ };
35
28
  });
36
29
  }
37
30
 
@@ -56,10 +49,9 @@ var createActionApi = (apiConfig) => ({
56
49
  COMMON_ACTION_KEYS,
57
50
  async track(params) {
58
51
  try {
59
- const key = "key" in params && params.key ? params.key : params.type;
60
52
  await apiConfig.httpClient.post(
61
53
  `/v1/storefront/${apiConfig.storeId}/actions/track`,
62
- { key, payload: params.payload }
54
+ { key: params.key, payload: params.payload }
63
55
  );
64
56
  } catch {
65
57
  }
@@ -67,6 +59,47 @@ var createActionApi = (apiConfig) => ({
67
59
  });
68
60
  var createStorefrontApi = (apiConfig, updateContactSession) => {
69
61
  const base = (storeId = apiConfig.storeId) => `/v1/storefront/${storeId}`;
62
+ const pendingVerifications = /* @__PURE__ */ new Map();
63
+ function persistIdentification(result) {
64
+ const issued = result.token;
65
+ if (issued?.token) {
66
+ updateContactSession(() => ({
67
+ access_token: issued.token,
68
+ contact: result.contact,
69
+ store: result.store,
70
+ market: result.market
71
+ }));
72
+ } else {
73
+ if (result.verification_challenge) {
74
+ pendingVerifications.set(result.verification_challenge.challenge_id, {
75
+ store: result.store,
76
+ market: result.market
77
+ });
78
+ }
79
+ updateContactSession(
80
+ (current) => current ? {
81
+ ...current,
82
+ contact: result.contact,
83
+ store: result.store,
84
+ market: result.market
85
+ } : null
86
+ );
87
+ }
88
+ return result;
89
+ }
90
+ async function submitIdentification(path, params, options) {
91
+ const store_id = apiConfig.storeId;
92
+ const result = await apiConfig.httpClient.post(
93
+ `${base(store_id)}/account/${path}`,
94
+ {
95
+ store_id,
96
+ market: params?.market || apiConfig.market || null,
97
+ email: params?.email
98
+ },
99
+ options
100
+ );
101
+ return persistIdentification(result);
102
+ }
70
103
  return {
71
104
  store: {
72
105
  getStore(options) {
@@ -74,7 +107,10 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
74
107
  },
75
108
  location: {
76
109
  getCountries(options) {
77
- return apiConfig.httpClient.get(`/v1/platform/countries`, options);
110
+ return apiConfig.httpClient.get(
111
+ `/v1/platform/countries`,
112
+ options
113
+ );
78
114
  },
79
115
  getCountry(countryCode, options) {
80
116
  return apiConfig.httpClient.get(
@@ -83,18 +119,30 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
83
119
  );
84
120
  },
85
121
  list(options) {
86
- return apiConfig.httpClient.get(`${base()}/locations`, options);
122
+ return apiConfig.httpClient.get(
123
+ `${base()}/locations`,
124
+ options
125
+ );
87
126
  },
88
127
  get(id, options) {
89
- return apiConfig.httpClient.get(`${base()}/locations/${id}`, options);
128
+ return apiConfig.httpClient.get(
129
+ `${base()}/locations/${id}`,
130
+ options
131
+ );
90
132
  }
91
133
  },
92
134
  market: {
93
135
  list(options) {
94
- return apiConfig.httpClient.get(`${base()}/markets`, options);
136
+ return apiConfig.httpClient.get(
137
+ `${base()}/markets`,
138
+ options
139
+ );
95
140
  },
96
141
  get(id, options) {
97
- return apiConfig.httpClient.get(`${base()}/markets/${id}`, options);
142
+ return apiConfig.httpClient.get(
143
+ `${base()}/markets/${id}`,
144
+ options
145
+ );
98
146
  }
99
147
  }
100
148
  },
@@ -102,11 +150,9 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
102
150
  collection: {
103
151
  get(params, options) {
104
152
  const store_id = params.store_id || apiConfig.storeId;
105
- if (!params.id) {
106
- throw new Error("GetCollectionParams requires id");
107
- }
153
+ const identifier = params.id !== void 0 ? params.id : `${store_id}:${params.key}`;
108
154
  return apiConfig.httpClient.get(
109
- `${base(store_id)}/collections/${params.id}`,
155
+ `${base(store_id)}/collections/${identifier}`,
110
156
  options
111
157
  );
112
158
  }
@@ -124,10 +170,13 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
124
170
  },
125
171
  find(params, options) {
126
172
  const { store_id, ...queryParams } = params;
127
- return apiConfig.httpClient.get(`${base(store_id)}/entries`, {
128
- ...options,
129
- params: queryParams
130
- });
173
+ return apiConfig.httpClient.get(
174
+ `${base(store_id)}/entries`,
175
+ {
176
+ ...options,
177
+ params: queryParams
178
+ }
179
+ );
131
180
  }
132
181
  },
133
182
  form: {
@@ -203,10 +252,13 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
203
252
  },
204
253
  find(params, options) {
205
254
  const { store_id, ...queryParams } = params;
206
- return apiConfig.httpClient.get(`${base(store_id)}/products`, {
207
- ...options,
208
- params: queryParams
209
- });
255
+ return apiConfig.httpClient.get(
256
+ `${base(store_id)}/products`,
257
+ {
258
+ ...options,
259
+ params: queryParams
260
+ }
261
+ );
210
262
  }
211
263
  },
212
264
  cart: {
@@ -215,16 +267,23 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
215
267
  const { store_id: _store_id, ...payload } = params;
216
268
  return apiConfig.httpClient.post(
217
269
  `${base(store_id)}/carts/current`,
218
- { ...payload, store_id, market: payload.market || apiConfig.market },
270
+ {
271
+ ...payload,
272
+ store_id,
273
+ market: payload.market || apiConfig.market
274
+ },
219
275
  options
220
276
  );
221
277
  },
222
278
  get(params, options) {
223
279
  const store_id = params.store_id || apiConfig.storeId;
224
- return apiConfig.httpClient.get(`${base(store_id)}/carts/${params.id}`, {
225
- ...options,
226
- params: params.token ? { token: params.token } : options?.params
227
- });
280
+ return apiConfig.httpClient.get(
281
+ `${base(store_id)}/carts/${params.id}`,
282
+ {
283
+ ...options,
284
+ params: params.token ? { token: params.token } : options?.params
285
+ }
286
+ );
228
287
  },
229
288
  update(params, options) {
230
289
  const { store_id, items, ...payload } = params;
@@ -234,7 +293,7 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
234
293
  {
235
294
  ...payload,
236
295
  store_id: target,
237
- ...items ? { items: normalizePublicCheckoutItems(items) } : {}
296
+ ...items ? { items: sanitizePublicCheckoutItems(items) } : {}
238
297
  },
239
298
  options
240
299
  );
@@ -247,7 +306,7 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
247
306
  {
248
307
  ...payload,
249
308
  store_id: target,
250
- item: normalizePublicCheckoutItems([item])[0]
309
+ item: sanitizePublicCheckoutItems([item])[0]
251
310
  },
252
311
  options
253
312
  );
@@ -302,18 +361,35 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
302
361
  },
303
362
  find(params, options) {
304
363
  const { store_id, ...queryParams } = params;
305
- return apiConfig.httpClient.get(`${base(store_id)}/orders`, {
306
- ...options,
307
- params: queryParams
308
- });
364
+ return apiConfig.httpClient.get(
365
+ `${base(store_id)}/orders`,
366
+ {
367
+ ...options,
368
+ params: queryParams
369
+ }
370
+ );
309
371
  },
310
372
  downloadDigitalAccess(params, options) {
311
373
  const store_id = params.store_id || apiConfig.storeId;
312
374
  return apiConfig.httpClient.post(
313
- `${base(store_id)}/orders/${params.id}/digital-access/${params.grant_id}/download`,
375
+ `${base(store_id)}/orders/${params.order_id}/digital-access/${params.grant_id}/download`,
314
376
  {},
315
377
  options
316
378
  );
379
+ },
380
+ findDigitalAccess(params, options) {
381
+ const { order_id, store_id, ...queryParams } = params;
382
+ return apiConfig.httpClient.get(
383
+ `${base(store_id)}/orders/${order_id}/digital-access`,
384
+ { ...options, params: queryParams }
385
+ );
386
+ },
387
+ getDigitalAccess(params, options) {
388
+ const store_id = params.store_id || apiConfig.storeId;
389
+ return apiConfig.httpClient.get(
390
+ `${base(store_id)}/orders/${params.order_id}/digital-access/${params.grant_id}`,
391
+ options
392
+ );
317
393
  }
318
394
  },
319
395
  service: {
@@ -334,17 +410,23 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
334
410
  },
335
411
  find(params, options) {
336
412
  const { store_id, ...queryParams } = params;
337
- return apiConfig.httpClient.get(`${base(store_id)}/services`, {
338
- ...options,
339
- params: queryParams
340
- });
413
+ return apiConfig.httpClient.get(
414
+ `${base(store_id)}/services`,
415
+ {
416
+ ...options,
417
+ params: queryParams
418
+ }
419
+ );
341
420
  },
342
421
  findProviders(params, options) {
343
422
  const { store_id, ...queryParams } = params;
344
- return apiConfig.httpClient.get(`${base(store_id)}/service-providers`, {
345
- ...options,
346
- params: queryParams
347
- });
423
+ return apiConfig.httpClient.get(
424
+ `${base(store_id)}/service-providers`,
425
+ {
426
+ ...options,
427
+ params: queryParams
428
+ }
429
+ );
348
430
  },
349
431
  getAvailability(params, options) {
350
432
  const { store_id, ...queryParams } = params;
@@ -373,48 +455,47 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
373
455
  },
374
456
  find(params, options) {
375
457
  const { store_id, ...queryParams } = params;
376
- return apiConfig.httpClient.get(`${base(store_id)}/providers`, {
377
- ...options,
378
- params: queryParams
379
- });
458
+ return apiConfig.httpClient.get(
459
+ `${base(store_id)}/providers`,
460
+ {
461
+ ...options,
462
+ params: queryParams
463
+ }
464
+ );
380
465
  }
381
466
  }
382
467
  },
383
468
  crm: {
384
469
  contact: {
385
- async identify(params, options) {
386
- const store_id = apiConfig.storeId;
387
- const result = await apiConfig.httpClient.post(
388
- `${base(store_id)}/account/identify`,
389
- {
390
- store_id,
391
- market: params?.market || apiConfig.market || null,
392
- email: params?.email,
393
- verify: params?.verify ?? false
394
- },
395
- options
396
- );
397
- if (result?.token?.token) {
398
- updateContactSession(() => ({
399
- access_token: result.token.token,
400
- contact: result.contact,
401
- store: result.store,
402
- market: result.market
403
- }));
404
- }
405
- return result;
470
+ identify(params, options) {
471
+ return submitIdentification("identify", params, options);
472
+ },
473
+ requestCode(params, options) {
474
+ return submitIdentification("code", params, options);
406
475
  },
407
476
  async verify(params, options) {
408
477
  const store_id = apiConfig.storeId;
409
478
  const result = await apiConfig.httpClient.post(
410
479
  `${base(store_id)}/account/verify`,
411
- { store_id, code: params.code },
480
+ { store_id, challenge_id: params.challenge_id, code: params.code },
412
481
  options
413
482
  );
414
- if (result?.token) {
483
+ if (result?.token?.token) {
484
+ const pending = pendingVerifications.get(params.challenge_id);
485
+ const identifiedStore = pending?.store || await apiConfig.httpClient.get(base(store_id), options);
415
486
  updateContactSession(
416
- (prev) => prev ? { ...prev, access_token: result.token } : null
487
+ (prev) => prev ? {
488
+ ...prev,
489
+ access_token: result.token.token,
490
+ contact: result.contact
491
+ } : {
492
+ access_token: result.token.token,
493
+ contact: result.contact,
494
+ store: identifiedStore,
495
+ market: pending?.market || null
496
+ }
417
497
  );
498
+ pendingVerifications.delete(params.challenge_id);
418
499
  }
419
500
  return result;
420
501
  },
@@ -431,7 +512,10 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
431
512
  }
432
513
  },
433
514
  getMe(options) {
434
- return apiConfig.httpClient.get(`${base()}/account/me`, options);
515
+ return apiConfig.httpClient.get(
516
+ `${base()}/account/me`,
517
+ options
518
+ );
435
519
  }
436
520
  },
437
521
  contactList: {
@@ -444,10 +528,31 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
444
528
  },
445
529
  find(params, options) {
446
530
  const { store_id, ...queryParams } = params || {};
447
- return apiConfig.httpClient.get(`${base(store_id)}/contact-lists`, {
448
- ...options,
449
- params: queryParams
450
- });
531
+ return apiConfig.httpClient.get(
532
+ `${base(store_id)}/contact-lists`,
533
+ {
534
+ ...options,
535
+ params: queryParams
536
+ }
537
+ );
538
+ },
539
+ plans: {
540
+ find(params, options) {
541
+ const { store_id, contact_list_id, ...queryParams } = params;
542
+ return apiConfig.httpClient.get(
543
+ `${base(store_id)}/contact-lists/${contact_list_id}/plans`,
544
+ { ...options, params: queryParams }
545
+ );
546
+ }
547
+ },
548
+ memberships: {
549
+ find(params, options) {
550
+ const { store_id, ...queryParams } = params || {};
551
+ return apiConfig.httpClient.get(`${base(store_id)}/contact-lists/memberships`, {
552
+ ...options,
553
+ params: queryParams
554
+ });
555
+ }
451
556
  },
452
557
  subscribe(params, options) {
453
558
  const { store_id, id, ...payload } = params;
@@ -472,13 +577,31 @@ var createStorefrontApi = (apiConfig, updateContactSession) => {
472
577
  options
473
578
  );
474
579
  },
475
- unsubscribe(token, options) {
580
+ manage(token, options) {
476
581
  return apiConfig.httpClient.post(
477
- `${base()}/contact-lists/unsubscribe`,
582
+ `${base()}/contact-lists/manage`,
478
583
  { token },
479
584
  options
480
585
  );
481
586
  },
587
+ unsubscribe(token, options) {
588
+ const headers = { ...options?.headers };
589
+ for (const name of Object.keys(headers)) {
590
+ if (name.toLowerCase() === "content-type") delete headers[name];
591
+ }
592
+ return apiConfig.httpClient.post(
593
+ `${base()}/contact-lists/unsubscribe`,
594
+ new URLSearchParams({ "List-Unsubscribe": "One-Click" }),
595
+ {
596
+ ...options,
597
+ params: { ...options?.params || {}, token },
598
+ headers: {
599
+ ...headers,
600
+ "Content-Type": "application/x-www-form-urlencoded"
601
+ }
602
+ }
603
+ );
604
+ },
482
605
  confirm(token, options) {
483
606
  return apiConfig.httpClient.post(
484
607
  `${base()}/contact-lists/confirm`,
@@ -643,27 +766,47 @@ var convertServerErrorToRequestError = (serverError, renameRules) => {
643
766
 
644
767
  // src/utils/queryParams.ts
645
768
  function buildQueryString(params) {
646
- const queryParts = [];
647
- Object.entries(params).forEach(([key, value]) => {
648
- if (value === null || value === void 0) {
649
- return;
650
- }
651
- if (Array.isArray(value)) {
652
- const jsonString = JSON.stringify(value);
653
- queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
654
- } else if (typeof value === "string") {
655
- queryParts.push(`${key}=${encodeURIComponent(value)}`);
656
- } else if (typeof value === "number" || typeof value === "boolean") {
657
- queryParts.push(`${key}=${value}`);
658
- } else if (typeof value === "object") {
659
- const jsonString = JSON.stringify(value);
660
- queryParts.push(`${key}=${encodeURIComponent(jsonString)}`);
769
+ const queryParts = Object.entries(params).flatMap(
770
+ ([key, value]) => {
771
+ if (value === null || value === void 0) return [];
772
+ if (typeof value === "string") {
773
+ return [`${key}=${encodeURIComponent(value)}`];
774
+ }
775
+ if (typeof value === "number" || typeof value === "boolean") {
776
+ return [`${key}=${value}`];
777
+ }
778
+ if (Array.isArray(value) || typeof value === "object") {
779
+ return [`${key}=${encodeURIComponent(JSON.stringify(value))}`];
780
+ }
781
+ return [];
661
782
  }
662
- });
783
+ );
663
784
  return queryParts.length > 0 ? `?${queryParts.join("&")}` : "";
664
785
  }
665
786
 
666
787
  // src/services/createHttpClient.ts
788
+ function requestError(name, message, details = {}) {
789
+ return Object.assign(new Error(message), { name }, details);
790
+ }
791
+ function isRecord(value) {
792
+ return typeof value === "object" && value !== null;
793
+ }
794
+ function isTokenSet(value) {
795
+ return isRecord(value) && typeof value.access_token === "string" && (value.refresh_token === void 0 || typeof value.refresh_token === "string") && (value.access_expires_at === void 0 || typeof value.access_expires_at === "number");
796
+ }
797
+ function isValidationError(value) {
798
+ return isRecord(value) && typeof value.field === "string" && typeof value.error === "string";
799
+ }
800
+ function toServerError(value, statusCode) {
801
+ const payload = isRecord(value) ? value : {};
802
+ const validationErrors = Array.isArray(payload.validationErrors) ? payload.validationErrors.filter(isValidationError) : [];
803
+ return {
804
+ message: typeof payload.message === "string" ? payload.message : "Request failed",
805
+ error: typeof payload.error === "string" ? payload.error : "REQUEST_FAILED",
806
+ statusCode: typeof payload.statusCode === "number" ? payload.statusCode : statusCode,
807
+ validationErrors
808
+ };
809
+ }
667
810
  function createHttpClient(cfg) {
668
811
  const { authStorage } = cfg;
669
812
  let refreshPromise = null;
@@ -680,32 +823,41 @@ function createHttpClient(cfg) {
680
823
  const refresh_token = tokens?.refresh_token;
681
824
  if (!refresh_token) {
682
825
  authStorage.onForcedLogout();
683
- const err = new Error("No refresh token available");
684
- err.name = "ApiError";
685
- err.statusCode = 401;
686
- throw err;
826
+ throw requestError("ApiError", "No refresh token available", {
827
+ statusCode: 401
828
+ });
687
829
  }
688
830
  const refRes = await fetch(getRefreshEndpoint(), {
689
831
  method: "POST",
690
- headers: { Accept: "application/json", "Content-Type": "application/json" },
832
+ headers: {
833
+ Accept: "application/json",
834
+ "Content-Type": "application/json"
835
+ },
691
836
  body: JSON.stringify({ refresh_token })
692
837
  });
693
838
  if (!refRes.ok) {
694
839
  authStorage.onForcedLogout();
695
- const err = new Error("Token refresh failed");
696
- err.name = "ApiError";
697
- err.statusCode = 401;
698
- throw err;
840
+ throw requestError("ApiError", "Token refresh failed", {
841
+ statusCode: 401
842
+ });
699
843
  }
700
844
  const data = await refRes.json();
845
+ if (!isTokenSet(data)) {
846
+ authStorage.onForcedLogout();
847
+ throw requestError(
848
+ "ParseError",
849
+ "Token refresh returned an invalid response",
850
+ { statusCode: refRes.status }
851
+ );
852
+ }
701
853
  authStorage.onTokensRefreshed(data);
702
854
  })().finally(() => {
703
855
  refreshPromise = null;
704
856
  });
705
857
  return refreshPromise;
706
858
  }
707
- async function request(method, path, body, options) {
708
- if (options?.transformRequest) {
859
+ async function request(method, path, body, options, retried = false) {
860
+ if (!retried && options?.transformRequest) {
709
861
  body = options.transformRequest(body);
710
862
  }
711
863
  const headers = {
@@ -723,23 +875,27 @@ function createHttpClient(cfg) {
723
875
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
724
876
  }
725
877
  const finalPath = options?.params ? path + buildQueryString(options.params) : path;
726
- const fetchOpts = { method, headers, signal: options?.signal };
878
+ const fetchOptions = {
879
+ method,
880
+ headers,
881
+ signal: options?.signal
882
+ };
727
883
  if (!["GET", "DELETE"].includes(method) && body !== void 0) {
728
- fetchOpts.body = JSON.stringify(body);
884
+ fetchOptions.body = body instanceof URLSearchParams ? body.toString() : JSON.stringify(body);
729
885
  }
730
886
  const fullUrl = `${cfg.baseUrl}${finalPath}`;
731
887
  let res;
732
888
  let data;
733
889
  const startedAt = Date.now();
734
890
  try {
735
- res = await fetch(fullUrl, fetchOpts);
891
+ res = await fetch(fullUrl, fetchOptions);
736
892
  } catch (error) {
737
893
  const aborted = options?.signal?.aborted || error instanceof Error && error.name === "AbortError";
738
- const err = new Error(error instanceof Error ? error.message : "Network request failed");
739
- err.name = aborted ? "AbortError" : "NetworkError";
740
- err.method = method;
741
- err.url = fullUrl;
742
- err.aborted = aborted;
894
+ const err = requestError(
895
+ aborted ? "AbortError" : "NetworkError",
896
+ error instanceof Error ? error.message : "Network request failed",
897
+ { method, url: fullUrl, aborted }
898
+ );
743
899
  if (options?.onError && method !== "GET") {
744
900
  Promise.resolve(
745
901
  options.onError({ error: err, method, url: fullUrl, aborted })
@@ -748,18 +904,9 @@ function createHttpClient(cfg) {
748
904
  }
749
905
  throw err;
750
906
  }
751
- if (res.status === 401 && !options?.["_retried"]) {
752
- try {
753
- await ensureFreshToken();
754
- const refreshed = authStorage.getTokens();
755
- if (refreshed?.access_token) {
756
- headers["Authorization"] = `Bearer ${refreshed.access_token}`;
757
- fetchOpts.headers = headers;
758
- }
759
- return request(method, path, body, { ...options, _retried: true });
760
- } catch (refreshError) {
761
- throw refreshError;
762
- }
907
+ if (res.status === 401 && !retried) {
908
+ await ensureFreshToken();
909
+ return request(method, path, body, options, true);
763
910
  }
764
911
  try {
765
912
  const contentLength = res.headers.get("content-length");
@@ -770,30 +917,35 @@ function createHttpClient(cfg) {
770
917
  data = await res.json();
771
918
  }
772
919
  } catch (error) {
773
- const err = new Error("Failed to parse response");
774
- err.name = "ParseError";
775
- err.method = method;
776
- err.url = fullUrl;
777
- err.status = res.status;
920
+ const err = requestError("ParseError", "Failed to parse response", {
921
+ method,
922
+ url: fullUrl,
923
+ statusCode: res.status
924
+ });
778
925
  if (options?.onError && method !== "GET") {
779
926
  Promise.resolve(
780
- options.onError({ error: err, method, url: fullUrl, status: res.status })
927
+ options.onError({
928
+ error: err,
929
+ method,
930
+ url: fullUrl,
931
+ status: res.status
932
+ })
781
933
  ).catch(() => {
782
934
  });
783
935
  }
784
936
  throw err;
785
937
  }
786
938
  if (!res.ok) {
787
- const serverErr = data;
939
+ const serverErr = toServerError(data, res.status);
788
940
  const reqErr = convertServerErrorToRequestError(serverErr);
789
- const err = new Error(serverErr.message || "Request failed");
790
- err.name = "ApiError";
791
- err.statusCode = serverErr.statusCode || res.status;
792
- err.validationErrors = reqErr.validationErrors;
793
- err.method = method;
794
- err.url = fullUrl;
795
941
  const requestId = res.headers.get("x-request-id") || res.headers.get("request-id");
796
- if (requestId) err.requestId = requestId;
942
+ const err = requestError("ApiError", serverErr.message, {
943
+ statusCode: serverErr.statusCode,
944
+ validationErrors: reqErr.validationErrors,
945
+ method,
946
+ url: fullUrl,
947
+ requestId: requestId || void 0
948
+ });
797
949
  if (options?.onError && method !== "GET") {
798
950
  Promise.resolve(
799
951
  options.onError({
@@ -836,35 +988,73 @@ function createHttpClient(cfg) {
836
988
  }
837
989
 
838
990
  // src/api/account.ts
839
- var createAccountApi = (apiConfig) => {
840
- return {
841
- async updateAccount(params, options) {
842
- const payload = {};
843
- if (params.phone_numbers !== void 0) payload.phone_numbers = params.phone_numbers;
844
- if (params.addresses !== void 0) payload.addresses = params.addresses;
845
- if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
846
- return apiConfig.httpClient.put("/v1/accounts", payload, options);
847
- },
848
- async deleteAccount(_params, options) {
849
- return apiConfig.httpClient.delete("/v1/accounts", options);
850
- },
851
- async getMe(_params, options) {
852
- return apiConfig.httpClient.get("/v1/accounts/me", options);
853
- },
854
- async searchAccounts(params, options) {
855
- return apiConfig.httpClient.get("/v1/accounts/search", {
856
- ...options,
857
- params: {
858
- ...params,
859
- store_id: apiConfig.storeId
860
- }
861
- });
862
- }
863
- };
864
- };
991
+ var createAccountApi = (apiConfig) => ({
992
+ async updateAccount(_params, options) {
993
+ return apiConfig.httpClient.put(
994
+ "/v1/accounts",
995
+ {},
996
+ options
997
+ );
998
+ },
999
+ async deleteAccount(_params, options) {
1000
+ return apiConfig.httpClient.delete(
1001
+ "/v1/accounts",
1002
+ options
1003
+ );
1004
+ },
1005
+ async getMe(_params, options) {
1006
+ return apiConfig.httpClient.get("/v1/accounts/me", options);
1007
+ },
1008
+ async searchAccounts(params, options) {
1009
+ return apiConfig.httpClient.get(
1010
+ "/v1/accounts/search",
1011
+ { ...options, params }
1012
+ );
1013
+ },
1014
+ async listApiTokens(options) {
1015
+ return apiConfig.httpClient.get(
1016
+ "/v1/accounts/me/api-tokens",
1017
+ options
1018
+ );
1019
+ },
1020
+ async createApiToken(params, options) {
1021
+ return apiConfig.httpClient.post(
1022
+ "/v1/accounts/me/api-tokens",
1023
+ params,
1024
+ options
1025
+ );
1026
+ },
1027
+ async updateApiToken(params, options) {
1028
+ const { id, ...payload } = params;
1029
+ return apiConfig.httpClient.put(
1030
+ `/v1/accounts/me/api-tokens/${id}`,
1031
+ payload,
1032
+ options
1033
+ );
1034
+ },
1035
+ async revokeApiToken(id, options) {
1036
+ return apiConfig.httpClient.delete(
1037
+ `/v1/accounts/me/api-tokens/${id}`,
1038
+ options
1039
+ );
1040
+ },
1041
+ async listSessions(options) {
1042
+ return apiConfig.httpClient.get(
1043
+ "/v1/accounts/me/sessions",
1044
+ options
1045
+ );
1046
+ },
1047
+ async revokeSession(id, options) {
1048
+ return apiConfig.httpClient.delete(
1049
+ `/v1/accounts/me/sessions/${id}`,
1050
+ options
1051
+ );
1052
+ }
1053
+ });
865
1054
 
866
1055
  // src/api/auth.ts
867
1056
  var createAuthApi = (apiConfig, updateSession) => {
1057
+ const pendingEmails = /* @__PURE__ */ new Map();
868
1058
  function applyAuthToken(result, email) {
869
1059
  const next = {
870
1060
  access_token: result.access_token,
@@ -876,7 +1066,9 @@ var createAuthApi = (apiConfig, updateSession) => {
876
1066
  }
877
1067
  return {
878
1068
  async code(params, options) {
879
- return apiConfig.httpClient.post("/v1/auth/code", params, options);
1069
+ const result = await apiConfig.httpClient.post("/v1/auth/code", params, options);
1070
+ pendingEmails.set(result.challenge_id, params.email);
1071
+ return result;
880
1072
  },
881
1073
  async verify(params, options) {
882
1074
  const result = await apiConfig.httpClient.post(
@@ -885,7 +1077,8 @@ var createAuthApi = (apiConfig, updateSession) => {
885
1077
  options
886
1078
  );
887
1079
  if (result?.access_token) {
888
- applyAuthToken(result, params.email);
1080
+ applyAuthToken(result, pendingEmails.get(params.challenge_id));
1081
+ pendingEmails.delete(params.challenge_id);
889
1082
  }
890
1083
  return result;
891
1084
  },
@@ -893,7 +1086,9 @@ var createAuthApi = (apiConfig, updateSession) => {
893
1086
  return apiConfig.httpClient.post("/v1/auth/refresh", params, options);
894
1087
  },
895
1088
  async storeCode(storeId, params, options) {
896
- return apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/code`, params, options);
1089
+ const result = await apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/code`, params, options);
1090
+ pendingEmails.set(result.challenge_id, params.email);
1091
+ return result;
897
1092
  },
898
1093
  async storeVerify(storeId, params, options) {
899
1094
  const result = await apiConfig.httpClient.post(
@@ -902,7 +1097,8 @@ var createAuthApi = (apiConfig, updateSession) => {
902
1097
  options
903
1098
  );
904
1099
  if (result?.access_token) {
905
- applyAuthToken(result, params.email);
1100
+ applyAuthToken(result, pendingEmails.get(params.challenge_id));
1101
+ pendingEmails.delete(params.challenge_id);
906
1102
  }
907
1103
  return result;
908
1104
  }
@@ -916,23 +1112,10 @@ var createStoreApi = (apiConfig, _updateSession) => {
916
1112
  return apiConfig.httpClient.post(`/v1/stores`, params, options);
917
1113
  },
918
1114
  async updateStore(params, options) {
919
- return apiConfig.httpClient.put(
920
- `/v1/stores/${params.id}`,
921
- params,
922
- options
923
- );
924
- },
925
- async deleteStore(params, options) {
926
- return apiConfig.httpClient.delete(
927
- `/v1/stores/${params.id}`,
928
- options
929
- );
1115
+ return apiConfig.httpClient.put(`/v1/stores/${params.id}`, params, options);
930
1116
  },
931
1117
  async getStore(_params, options) {
932
- return apiConfig.httpClient.get(
933
- `/v1/stores/${apiConfig.storeId}`,
934
- options
935
- );
1118
+ return apiConfig.httpClient.get(`/v1/stores/${apiConfig.storeId}`, options);
936
1119
  },
937
1120
  async getStores(params, options) {
938
1121
  return apiConfig.httpClient.get(`/v1/stores`, {
@@ -941,20 +1124,58 @@ var createStoreApi = (apiConfig, _updateSession) => {
941
1124
  });
942
1125
  },
943
1126
  async getSubscriptionPlans(_params, options) {
944
- return apiConfig.httpClient.get(
945
- "/v1/stores/plans",
1127
+ return apiConfig.httpClient.get("/v1/stores/plans", options);
1128
+ },
1129
+ async createSubscriptionAction(params, options) {
1130
+ const { store_id, ...payload } = params;
1131
+ const target_store_id = store_id || apiConfig.storeId;
1132
+ const response = await apiConfig.httpClient.post(
1133
+ `/v1/stores/${target_store_id}/subscription/actions`,
1134
+ payload,
946
1135
  options
947
1136
  );
1137
+ if (response.id !== params.action_id) {
1138
+ throw new Error("Subscription response did not match the requested action_id");
1139
+ }
1140
+ return response;
948
1141
  },
949
- async subscribe(params, options) {
950
- const { store_id, plan_id, action, success_url, cancel_url } = params;
951
- const target_store_id = store_id || apiConfig.storeId;
952
- return apiConfig.httpClient.put(
953
- `/v1/stores/${target_store_id}/subscribe`,
954
- { plan_id, action, success_url, cancel_url },
1142
+ async getSubscription(params = {}, options) {
1143
+ const store_id = params.store_id || apiConfig.storeId;
1144
+ return apiConfig.httpClient.get(`/v1/stores/${store_id}/subscription`, options);
1145
+ },
1146
+ async retrySubscriptionAction(params, options) {
1147
+ const store_id = params.store_id || apiConfig.storeId;
1148
+ return apiConfig.httpClient.post(
1149
+ `/v1/stores/${store_id}/subscription/actions/${params.action_id}/retry`,
1150
+ {},
955
1151
  options
956
1152
  );
957
1153
  },
1154
+ async getSubscriptionAction(params, options) {
1155
+ const store_id = params.store_id || apiConfig.storeId;
1156
+ return apiConfig.httpClient.get(`/v1/stores/${store_id}/subscription/actions/${params.action_id}`, options);
1157
+ },
1158
+ async findSubscriptionActionEffects(params, options) {
1159
+ const { store_id, action_id, ...query } = params;
1160
+ return apiConfig.httpClient.get(
1161
+ `/v1/stores/${store_id || apiConfig.storeId}/subscription/actions/${action_id}/effects`,
1162
+ { ...options, params: query }
1163
+ );
1164
+ },
1165
+ async getSubscriptionActionEffect(params, options) {
1166
+ const store_id = params.store_id || apiConfig.storeId;
1167
+ return apiConfig.httpClient.get(
1168
+ `/v1/stores/${store_id}/subscription/actions/${params.action_id}/effects/${params.effect_id}`,
1169
+ options
1170
+ );
1171
+ },
1172
+ async findSubscriptionActions(params = {}, options) {
1173
+ const { store_id, ...query } = params;
1174
+ return apiConfig.httpClient.get(
1175
+ `/v1/stores/${store_id || apiConfig.storeId}/subscription/actions`,
1176
+ { ...options, params: query }
1177
+ );
1178
+ },
958
1179
  async createPortalSession(params, options) {
959
1180
  const store_id = params.store_id || apiConfig.storeId;
960
1181
  return apiConfig.httpClient.post(
@@ -965,114 +1186,61 @@ var createStoreApi = (apiConfig, _updateSession) => {
965
1186
  },
966
1187
  async addMember(params, options) {
967
1188
  const { store_id, ...payload } = params;
968
- return apiConfig.httpClient.post(
969
- `/v1/stores/${store_id || apiConfig.storeId}/members`,
970
- payload,
971
- options
972
- );
1189
+ return apiConfig.httpClient.post(`/v1/stores/${store_id || apiConfig.storeId}/members`, payload, options);
973
1190
  },
974
1191
  async inviteUser(params, options) {
975
1192
  const { store_id, ...payload } = params;
976
- return apiConfig.httpClient.post(
977
- `/v1/stores/${store_id || apiConfig.storeId}/members`,
978
- payload,
979
- options
980
- );
1193
+ return apiConfig.httpClient.post(`/v1/stores/${store_id || apiConfig.storeId}/invitation`, payload, options);
1194
+ },
1195
+ async findMembers(params = {}, options) {
1196
+ const { store_id, ...query } = params;
1197
+ return apiConfig.httpClient.get(`/v1/stores/${store_id || apiConfig.storeId}/members`, {
1198
+ ...options,
1199
+ params: query
1200
+ });
1201
+ },
1202
+ async findOwnMemberships(options) {
1203
+ return apiConfig.httpClient.get("/v1/stores/memberships", options);
981
1204
  },
982
1205
  async removeMember(params, options) {
983
1206
  return apiConfig.httpClient.delete(
984
- `/v1/stores/${apiConfig.storeId}/members/${params.account_id}`,
1207
+ `/v1/stores/${params.store_id || apiConfig.storeId}/members/${params.account_id}`,
985
1208
  options
986
1209
  );
987
1210
  },
988
1211
  async testWebhook(params, options) {
989
- return apiConfig.httpClient.post(
990
- `/v1/stores/${apiConfig.storeId}/webhooks/test`,
991
- params,
992
- options
993
- );
994
- },
995
- async getStoreMedia(params, options) {
996
- const queryParams = {
997
- limit: params.limit
998
- };
999
- if (params.cursor) queryParams.cursor = params.cursor;
1000
- if (params.ids && params.ids.length > 0)
1001
- queryParams.ids = JSON.stringify(params.ids);
1002
- if (params.query) queryParams.query = params.query;
1003
- if (params.mime_type) queryParams.mime_type = params.mime_type;
1004
- if (params.sort_field) queryParams.sort_field = params.sort_field;
1005
- if (params.sort_direction)
1006
- queryParams.sort_direction = params.sort_direction;
1007
- return apiConfig.httpClient.get(
1008
- `/v1/stores/${params.id}/media`,
1009
- {
1010
- ...options,
1011
- params: queryParams
1012
- }
1013
- );
1212
+ return apiConfig.httpClient.post(`/v1/stores/${apiConfig.storeId}/webhooks/test`, params, options);
1014
1213
  },
1015
1214
  async listBuildHooks(params, options) {
1016
- return apiConfig.httpClient.get(
1017
- `/v1/stores/${params.store_id}/build-hooks`,
1018
- options
1019
- );
1215
+ return apiConfig.httpClient.get(`/v1/stores/${params.store_id}/build-hooks`, options);
1020
1216
  },
1021
1217
  async createBuildHook(params, options) {
1022
1218
  const { store_id, ...payload } = params;
1023
- return apiConfig.httpClient.post(
1024
- `/v1/stores/${store_id}/build-hooks`,
1025
- payload,
1026
- options
1027
- );
1219
+ return apiConfig.httpClient.post(`/v1/stores/${store_id}/build-hooks`, payload, options);
1028
1220
  },
1029
1221
  async updateBuildHook(params, options) {
1030
1222
  const { store_id, id, ...payload } = params;
1031
- return apiConfig.httpClient.put(
1032
- `/v1/stores/${store_id}/build-hooks/${id}`,
1033
- payload,
1034
- options
1035
- );
1223
+ return apiConfig.httpClient.put(`/v1/stores/${store_id}/build-hooks/${id}`, payload, options);
1036
1224
  },
1037
1225
  async deleteBuildHook(params, options) {
1038
- return apiConfig.httpClient.delete(
1039
- `/v1/stores/${params.store_id}/build-hooks/${params.id}`,
1040
- options
1041
- );
1226
+ return apiConfig.httpClient.delete(`/v1/stores/${params.store_id}/build-hooks/${params.id}`, options);
1042
1227
  },
1043
- async getStoreConfig(params, options) {
1044
- return apiConfig.httpClient.get(
1045
- `/v1/stores/${params.store_id}/config/${params.type}`,
1046
- options
1047
- );
1228
+ async getPaymentConfig(params, options) {
1229
+ return apiConfig.httpClient.get(`/v1/stores/${params.store_id}/config/payment`, options);
1048
1230
  },
1049
1231
  async listWebhooks(params, options) {
1050
- return apiConfig.httpClient.get(
1051
- `/v1/stores/${params.store_id}/webhooks`,
1052
- options
1053
- );
1232
+ return apiConfig.httpClient.get(`/v1/stores/${params.store_id}/webhooks`, options);
1054
1233
  },
1055
1234
  async createWebhook(params, options) {
1056
1235
  const { store_id, ...payload } = params;
1057
- return apiConfig.httpClient.post(
1058
- `/v1/stores/${store_id}/webhooks`,
1059
- payload,
1060
- options
1061
- );
1236
+ return apiConfig.httpClient.post(`/v1/stores/${store_id}/webhooks`, payload, options);
1062
1237
  },
1063
1238
  async updateWebhook(params, options) {
1064
1239
  const { store_id, id, ...payload } = params;
1065
- return apiConfig.httpClient.put(
1066
- `/v1/stores/${store_id}/webhooks/${id}`,
1067
- payload,
1068
- options
1069
- );
1240
+ return apiConfig.httpClient.put(`/v1/stores/${store_id}/webhooks/${id}`, payload, options);
1070
1241
  },
1071
1242
  async deleteWebhook(params, options) {
1072
- return apiConfig.httpClient.delete(
1073
- `/v1/stores/${params.store_id}/webhooks/${params.id}`,
1074
- options
1075
- );
1243
+ return apiConfig.httpClient.delete(`/v1/stores/${params.store_id}/webhooks/${params.id}`, options);
1076
1244
  }
1077
1245
  };
1078
1246
  };
@@ -1109,9 +1277,10 @@ var createMediaApi = (apiConfig) => {
1109
1277
  return await response.json();
1110
1278
  },
1111
1279
  async deleteStoreMedia(params, options) {
1112
- const { id, media_id } = params;
1280
+ const { store_id, media_id } = params;
1281
+ const target_store_id = store_id || apiConfig.storeId;
1113
1282
  return apiConfig.httpClient.delete(
1114
- `/v1/stores/${id}/media/${media_id}`,
1283
+ `/v1/stores/${target_store_id}/media/${media_id}`,
1115
1284
  options
1116
1285
  );
1117
1286
  },
@@ -1155,16 +1324,23 @@ var createMediaApi = (apiConfig) => {
1155
1324
  // src/api/notification.ts
1156
1325
  var createNotificationApi = (apiConfig) => {
1157
1326
  return {
1158
- async trackEmailOpen(params, options) {
1327
+ async sendEmail(request, options) {
1328
+ return apiConfig.httpClient.post(
1329
+ "/v1/notifications/email",
1330
+ request,
1331
+ options
1332
+ );
1333
+ },
1334
+ async getEmailDelivery(params, options) {
1159
1335
  return apiConfig.httpClient.get(
1160
- `/v1/notifications/track/pixel/${params.tracking_pixel_id}`,
1336
+ `/v1/notifications/email-deliveries/${params.delivery_id}`,
1161
1337
  options
1162
1338
  );
1163
1339
  },
1164
- async trigger(params, options) {
1340
+ async retryEmailDelivery(params, options) {
1165
1341
  return apiConfig.httpClient.post(
1166
- "/v1/notifications/trigger",
1167
- params,
1342
+ `/v1/notifications/email-deliveries/${params.delivery_id}/retry`,
1343
+ { revision: params.revision },
1168
1344
  options
1169
1345
  );
1170
1346
  }
@@ -1247,14 +1423,7 @@ var createCmsApi = (apiConfig) => {
1247
1423
  },
1248
1424
  async getCollection(params, options) {
1249
1425
  const target_store_id = params.store_id || apiConfig.storeId;
1250
- let identifier;
1251
- if (params.id) {
1252
- identifier = params.id;
1253
- } else if (params.key) {
1254
- identifier = `${target_store_id}:${params.key}`;
1255
- } else {
1256
- throw new Error("GetCollectionParams requires id or key");
1257
- }
1426
+ const identifier = params.id !== void 0 ? params.id : `${target_store_id}:${params.key}`;
1258
1427
  return apiConfig.httpClient.get(
1259
1428
  `/v1/stores/${target_store_id}/collections/${identifier}`,
1260
1429
  options
@@ -1522,7 +1691,7 @@ var createEshopApi = (apiConfig) => {
1522
1691
  const target_store_id = store_id || apiConfig.storeId;
1523
1692
  const payload = {
1524
1693
  ...rest,
1525
- ...items ? { items: normalizeOrderCheckoutItems(items) } : {}
1694
+ ...items ? { items } : {}
1526
1695
  };
1527
1696
  return apiConfig.httpClient.put(
1528
1697
  `/v1/stores/${target_store_id}/orders/${params.id}`,
@@ -1573,7 +1742,7 @@ var createEshopApi = (apiConfig) => {
1573
1742
  `/v1/stores/${target_store_id}/carts`,
1574
1743
  {
1575
1744
  ...payload,
1576
- items: normalizeOrderCheckoutItems(payload.items || [])
1745
+ items: payload.items || []
1577
1746
  },
1578
1747
  options
1579
1748
  );
@@ -1585,7 +1754,7 @@ var createEshopApi = (apiConfig) => {
1585
1754
  `/v1/stores/${target_store_id}/carts/${id}`,
1586
1755
  {
1587
1756
  ...payload,
1588
- ...items ? { items: normalizeOrderCheckoutItems(items) } : {}
1757
+ ...items ? { items } : {}
1589
1758
  },
1590
1759
  options
1591
1760
  );
@@ -1595,7 +1764,7 @@ var createEshopApi = (apiConfig) => {
1595
1764
  const target_store_id = store_id || apiConfig.storeId;
1596
1765
  return apiConfig.httpClient.post(
1597
1766
  `/v1/stores/${target_store_id}/carts/${id}/items`,
1598
- { item: normalizeOrderCheckoutItems([item])[0] },
1767
+ { item },
1599
1768
  options
1600
1769
  );
1601
1770
  },
@@ -1649,27 +1818,134 @@ var createEshopApi = (apiConfig) => {
1649
1818
  `/v1/stores/${target_store_id}/orders/quote`,
1650
1819
  {
1651
1820
  ...rest,
1652
- items: normalizeOrderQuoteItems(items),
1821
+ items,
1653
1822
  shipping_address,
1654
1823
  market: rest.market || apiConfig.market
1655
1824
  },
1656
1825
  options
1657
1826
  );
1658
1827
  },
1659
- async processRefund(params, options) {
1828
+ async createRefund(params, options) {
1829
+ const target_store_id = params.store_id || apiConfig.storeId;
1830
+ const response = await apiConfig.httpClient.post(
1831
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/refunds`,
1832
+ {
1833
+ amount: params.amount,
1834
+ refund_id: params.refund_id
1835
+ },
1836
+ options
1837
+ );
1838
+ if (response.refund_id !== params.refund_id) {
1839
+ throw new Error(
1840
+ "Refund response did not match the requested refund_id"
1841
+ );
1842
+ }
1843
+ if (!Number.isSafeInteger(response.amount) || response.amount !== params.amount) {
1844
+ throw new Error("Refund response did not match the requested amount");
1845
+ }
1846
+ if (![
1847
+ "requested",
1848
+ "processing",
1849
+ "succeeded",
1850
+ "rejected",
1851
+ "failed",
1852
+ "unknown"
1853
+ ].includes(response.status)) {
1854
+ throw new Error("Refund response contained an invalid status");
1855
+ }
1856
+ return response;
1857
+ },
1858
+ async retryRefund(params, options) {
1859
+ const target_store_id = params.store_id || apiConfig.storeId;
1660
1860
  return apiConfig.httpClient.post(
1661
- `/v1/stores/${apiConfig.storeId}/orders/${params.id}/refund`,
1662
- { amount: params.amount },
1861
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/refunds/${params.refund_id}/retry`,
1862
+ {},
1863
+ options
1864
+ );
1865
+ },
1866
+ async getPayment(params, options) {
1867
+ const target_store_id = params.store_id || apiConfig.storeId;
1868
+ return apiConfig.httpClient.get(
1869
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/payment`,
1870
+ options
1871
+ );
1872
+ },
1873
+ async retryPaymentTransaction(params, options) {
1874
+ const target_store_id = params.store_id || apiConfig.storeId;
1875
+ return apiConfig.httpClient.post(
1876
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/payment/transactions/${params.transaction_id}/retry`,
1877
+ {},
1878
+ options
1879
+ );
1880
+ },
1881
+ async getPaymentTransactions(params, options) {
1882
+ const { order_id, store_id, ...queryParams } = params;
1883
+ const target_store_id = store_id || apiConfig.storeId;
1884
+ return apiConfig.httpClient.get(
1885
+ `/v1/stores/${target_store_id}/orders/${order_id}/payment/transactions`,
1886
+ { ...options, params: queryParams }
1887
+ );
1888
+ },
1889
+ async getPaymentTransaction(params, options) {
1890
+ const target_store_id = params.store_id || apiConfig.storeId;
1891
+ return apiConfig.httpClient.get(
1892
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/payment/transactions/${params.transaction_id}`,
1663
1893
  options
1664
1894
  );
1665
1895
  },
1896
+ async getRefund(params, options) {
1897
+ const target_store_id = params.store_id || apiConfig.storeId;
1898
+ return apiConfig.httpClient.get(
1899
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/refunds/${params.refund_id}`,
1900
+ options
1901
+ );
1902
+ },
1903
+ async getRefunds(params, options) {
1904
+ const { order_id, store_id, ...queryParams } = params;
1905
+ const target_store_id = store_id || apiConfig.storeId;
1906
+ return apiConfig.httpClient.get(
1907
+ `/v1/stores/${target_store_id}/orders/${order_id}/refunds`,
1908
+ { ...options, params: queryParams }
1909
+ );
1910
+ },
1666
1911
  async downloadDigitalAccess(params, options) {
1667
1912
  const target_store_id = params.store_id || apiConfig.storeId;
1668
1913
  return apiConfig.httpClient.post(
1669
- `/v1/stores/${target_store_id}/orders/${params.id}/digital-access/${params.grant_id}/download`,
1914
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/digital-access/${params.grant_id}/download`,
1915
+ {},
1916
+ options
1917
+ );
1918
+ },
1919
+ async activateDigitalAccess(params, options) {
1920
+ const target_store_id = params.store_id || apiConfig.storeId;
1921
+ return apiConfig.httpClient.post(
1922
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/digital-access/${params.grant_id}/activate`,
1670
1923
  {},
1671
1924
  options
1672
1925
  );
1926
+ },
1927
+ async revokeDigitalAccess(params, options) {
1928
+ const target_store_id = params.store_id || apiConfig.storeId;
1929
+ return apiConfig.httpClient.post(
1930
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/digital-access/${params.grant_id}/revoke`,
1931
+ {},
1932
+ options
1933
+ );
1934
+ },
1935
+ async findDigitalAccess(params, options) {
1936
+ const { order_id, store_id, ...queryParams } = params;
1937
+ const target_store_id = store_id || apiConfig.storeId;
1938
+ return apiConfig.httpClient.get(
1939
+ `/v1/stores/${target_store_id}/orders/${order_id}/digital-access`,
1940
+ { ...options, params: queryParams }
1941
+ );
1942
+ },
1943
+ async getDigitalAccess(params, options) {
1944
+ const target_store_id = params.store_id || apiConfig.storeId;
1945
+ return apiConfig.httpClient.get(
1946
+ `/v1/stores/${target_store_id}/orders/${params.order_id}/digital-access/${params.grant_id}`,
1947
+ options
1948
+ );
1673
1949
  }
1674
1950
  };
1675
1951
  };
@@ -1868,17 +2144,27 @@ var createContactApi = (apiConfig) => {
1868
2144
  options
1869
2145
  );
1870
2146
  },
1871
- async revokeToken(params, options) {
2147
+ async findSessions(params, options) {
2148
+ const store_id = params.store_id || apiConfig.storeId;
2149
+ const queryParams = {};
2150
+ if (params.limit !== void 0) queryParams.limit = params.limit;
2151
+ if (params.cursor) queryParams.cursor = params.cursor;
2152
+ return apiConfig.httpClient.get(
2153
+ `/v1/stores/${store_id}/contacts/${params.contact_id}/sessions`,
2154
+ { ...options, params: queryParams }
2155
+ );
2156
+ },
2157
+ async revokeSession(params, options) {
1872
2158
  const store_id = params.store_id || apiConfig.storeId;
1873
2159
  return apiConfig.httpClient.delete(
1874
- `/v1/stores/${store_id}/contacts/${params.id}/sessions/${params.token_id}`,
2160
+ `/v1/stores/${store_id}/contacts/${params.contact_id}/sessions/${params.session_id}`,
1875
2161
  options
1876
2162
  );
1877
2163
  },
1878
- async revokeAllTokens(params, options) {
2164
+ async revokeAllSessions(params, options) {
1879
2165
  const store_id = params.store_id || apiConfig.storeId;
1880
2166
  return apiConfig.httpClient.delete(
1881
- `/v1/stores/${store_id}/contacts/${params.id}/sessions`,
2167
+ `/v1/stores/${store_id}/contacts/${params.contact_id}/sessions`,
1882
2168
  options
1883
2169
  );
1884
2170
  },
@@ -1916,6 +2202,49 @@ var createContactApi = (apiConfig) => {
1916
2202
  { ...options, params: queryParams }
1917
2203
  );
1918
2204
  },
2205
+ plans: {
2206
+ async create(params, options) {
2207
+ const { store_id, contact_list_id, ...payload } = params;
2208
+ const target_store_id = store_id || apiConfig.storeId;
2209
+ return apiConfig.httpClient.post(
2210
+ `/v1/stores/${target_store_id}/contact-lists/${contact_list_id}/plans`,
2211
+ payload,
2212
+ options
2213
+ );
2214
+ },
2215
+ async update(params, options) {
2216
+ const { id, store_id, contact_list_id, ...payload } = params;
2217
+ const target_store_id = store_id || apiConfig.storeId;
2218
+ return apiConfig.httpClient.put(
2219
+ `/v1/stores/${target_store_id}/contact-lists/${contact_list_id}/plans/${id}`,
2220
+ payload,
2221
+ options
2222
+ );
2223
+ },
2224
+ async get(params, options) {
2225
+ const target_store_id = params.store_id || apiConfig.storeId;
2226
+ return apiConfig.httpClient.get(
2227
+ `/v1/stores/${target_store_id}/contact-lists/${params.contact_list_id}/plans/${params.id}`,
2228
+ options
2229
+ );
2230
+ },
2231
+ async find(params, options) {
2232
+ const { store_id, contact_list_id, ...queryParams } = params;
2233
+ const target_store_id = store_id || apiConfig.storeId;
2234
+ return apiConfig.httpClient.get(
2235
+ `/v1/stores/${target_store_id}/contact-lists/${contact_list_id}/plans`,
2236
+ { ...options, params: queryParams }
2237
+ );
2238
+ },
2239
+ async retryCatalog(params, options) {
2240
+ const target_store_id = params.store_id || apiConfig.storeId;
2241
+ return apiConfig.httpClient.post(
2242
+ `/v1/stores/${target_store_id}/contact-lists/${params.contact_list_id}/plans/${params.plan_id}/catalog/retry`,
2243
+ {},
2244
+ options
2245
+ );
2246
+ }
2247
+ },
1919
2248
  async importContacts(params, options) {
1920
2249
  const { store_id, contact_list_id, ...payload } = params;
1921
2250
  const target_store_id = store_id || apiConfig.storeId;
@@ -1972,9 +2301,102 @@ var createContactApi = (apiConfig) => {
1972
2301
  { ...options, params: queryParams }
1973
2302
  );
1974
2303
  }
2304
+ },
2305
+ memberships: {
2306
+ async refund(params, options) {
2307
+ const { store_id, contact_list_id, membership_id, ...payload } = params;
2308
+ const target_store_id = store_id || apiConfig.storeId;
2309
+ const response = await apiConfig.httpClient.post(
2310
+ `/v1/stores/${target_store_id}/contact-lists/${contact_list_id}/memberships/${membership_id}/refund`,
2311
+ payload,
2312
+ options
2313
+ );
2314
+ if (response.refund_id !== params.refund_id) {
2315
+ throw new Error(
2316
+ "Membership refund response did not match the requested refund_id"
2317
+ );
2318
+ }
2319
+ return response;
2320
+ },
2321
+ paymentAttempts: {
2322
+ async find(params, options) {
2323
+ const { store_id, contact_list_id, membership_id, ...queryParams } = params;
2324
+ const target_store_id = store_id || apiConfig.storeId;
2325
+ return apiConfig.httpClient.get(
2326
+ `/v1/stores/${target_store_id}/contact-lists/${contact_list_id}/memberships/${membership_id}/payment-attempts`,
2327
+ { ...options, params: queryParams }
2328
+ );
2329
+ },
2330
+ async get(params, options) {
2331
+ const target_store_id = params.store_id || apiConfig.storeId;
2332
+ return apiConfig.httpClient.get(
2333
+ `/v1/stores/${target_store_id}/contact-lists/${params.contact_list_id}/memberships/${params.membership_id}/payment-attempts/${params.id}`,
2334
+ options
2335
+ );
2336
+ }
2337
+ },
2338
+ refunds: {
2339
+ async find(params, options) {
2340
+ const { store_id, contact_list_id, membership_id, ...queryParams } = params;
2341
+ const target_store_id = store_id || apiConfig.storeId;
2342
+ return apiConfig.httpClient.get(
2343
+ `/v1/stores/${target_store_id}/contact-lists/${contact_list_id}/memberships/${membership_id}/refunds`,
2344
+ { ...options, params: queryParams }
2345
+ );
2346
+ },
2347
+ async get(params, options) {
2348
+ const target_store_id = params.store_id || apiConfig.storeId;
2349
+ return apiConfig.httpClient.get(
2350
+ `/v1/stores/${target_store_id}/contact-lists/${params.contact_list_id}/memberships/${params.membership_id}/refunds/${params.id}`,
2351
+ options
2352
+ );
2353
+ },
2354
+ async retry(params, options) {
2355
+ const target_store_id = params.store_id || apiConfig.storeId;
2356
+ return apiConfig.httpClient.post(
2357
+ `/v1/stores/${target_store_id}/contact-lists/${params.contact_list_id}/memberships/${params.membership_id}/refunds/${params.id}/retry`,
2358
+ {},
2359
+ options
2360
+ );
2361
+ }
2362
+ },
2363
+ cancellations: {
2364
+ async find(params, options) {
2365
+ const { store_id, contact_list_id, membership_id, ...queryParams } = params;
2366
+ const target_store_id = store_id || apiConfig.storeId;
2367
+ return apiConfig.httpClient.get(
2368
+ `/v1/stores/${target_store_id}/contact-lists/${contact_list_id}/memberships/${membership_id}/cancellations`,
2369
+ { ...options, params: queryParams }
2370
+ );
2371
+ },
2372
+ async get(params, options) {
2373
+ const target_store_id = params.store_id || apiConfig.storeId;
2374
+ return apiConfig.httpClient.get(
2375
+ `/v1/stores/${target_store_id}/contact-lists/${params.contact_list_id}/memberships/${params.membership_id}/cancellations/${params.id}`,
2376
+ options
2377
+ );
2378
+ },
2379
+ async retry(params, options) {
2380
+ const target_store_id = params.store_id || apiConfig.storeId;
2381
+ return apiConfig.httpClient.post(
2382
+ `/v1/stores/${target_store_id}/contact-lists/${params.contact_list_id}/memberships/${params.membership_id}/cancellations/${params.id}/retry`,
2383
+ {},
2384
+ options
2385
+ );
2386
+ }
2387
+ }
1975
2388
  }
1976
2389
  },
1977
2390
  mailbox: {
2391
+ async connectGoogle(params, options) {
2392
+ const { store_id, ...payload } = params;
2393
+ const target_store_id = store_id || apiConfig.storeId;
2394
+ return apiConfig.httpClient.post(
2395
+ `/v1/stores/${target_store_id}/mailboxes/google/connect-url`,
2396
+ payload,
2397
+ options
2398
+ );
2399
+ },
1978
2400
  async create(params, options) {
1979
2401
  const { store_id, ...payload } = params;
1980
2402
  const target_store_id = store_id || apiConfig.storeId;
@@ -2231,28 +2653,49 @@ function supportConversationQuery(params) {
2231
2653
  if (params.after_id) qs.set("after_id", params.after_id);
2232
2654
  return qs.toString();
2233
2655
  }
2656
+ function storefrontSupportOptions(supportToken, options) {
2657
+ if (!/^[0-9a-f]{64}$/.test(supportToken)) {
2658
+ throw new Error("support_token must be a 64-character lowercase hexadecimal token");
2659
+ }
2660
+ const headers = { ...options?.headers };
2661
+ for (const name of Object.keys(headers)) {
2662
+ if (name.toLowerCase() === "x-arky-support-token") delete headers[name];
2663
+ }
2664
+ return {
2665
+ ...options,
2666
+ headers: {
2667
+ ...headers,
2668
+ "X-Arky-Support-Token": supportToken
2669
+ }
2670
+ };
2671
+ }
2234
2672
  function createStorefrontSupportApi(config) {
2235
- const { httpClient, storeId } = config;
2673
+ const { httpClient } = config;
2236
2674
  return {
2237
2675
  async startConversation(params = {}, opts) {
2676
+ const storeId = config.storeId;
2238
2677
  return httpClient.post(
2239
2678
  `/v1/storefront/${storeId}/support/conversations`,
2240
- { store_id: storeId, ...params },
2679
+ { ...params, store_id: storeId },
2241
2680
  opts
2242
2681
  );
2243
2682
  },
2244
2683
  async sendMessage(params, opts) {
2684
+ const { support_token, ...request } = params;
2685
+ const storeId = config.storeId;
2245
2686
  return httpClient.post(
2246
- `/v1/storefront/${storeId}/support/conversations/${params.conversation_id}/messages`,
2247
- { store_id: storeId, ...params },
2248
- opts
2687
+ `/v1/storefront/${storeId}/support/conversations/${request.conversation_id}/messages`,
2688
+ { ...request, store_id: storeId },
2689
+ storefrontSupportOptions(support_token, opts)
2249
2690
  );
2250
2691
  },
2251
2692
  async getConversation(params, opts) {
2252
- const qs = supportConversationQuery({ store_id: storeId, ...params });
2693
+ const { support_token, ...request } = params;
2694
+ const storeId = config.storeId;
2695
+ const qs = supportConversationQuery({ ...request, store_id: storeId });
2253
2696
  return httpClient.get(
2254
- `/v1/storefront/${storeId}/support/conversations/${params.conversation_id}?${qs}`,
2255
- opts
2697
+ `/v1/storefront/${storeId}/support/conversations/${request.conversation_id}?${qs}`,
2698
+ storefrontSupportOptions(support_token, opts)
2256
2699
  );
2257
2700
  }
2258
2701
  };
@@ -2574,11 +3017,50 @@ var createSocialApi = (apiConfig) => {
2574
3017
  options
2575
3018
  );
2576
3019
  },
2577
- async replyToPublicationComment(params, options) {
2578
- const { store_id, publication_id, comment_id, text } = params;
3020
+ async createCommentReply(params, options) {
3021
+ const { store_id, publication_id, comment_id, ...payload } = params;
3022
+ return apiConfig.httpClient.post(
3023
+ `/v1/stores/${storeId(store_id)}/social-publications/${publication_id}/comments/${comment_id}/replies`,
3024
+ payload,
3025
+ options
3026
+ );
3027
+ },
3028
+ async listCommentReplies(params, options) {
3029
+ const { store_id, publication_id, comment_id, ...queryParams } = params;
3030
+ return apiConfig.httpClient.get(
3031
+ `/v1/stores/${storeId(store_id)}/social-publications/${publication_id}/comments/${comment_id}/replies`,
3032
+ {
3033
+ ...options,
3034
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
3035
+ }
3036
+ );
3037
+ },
3038
+ async getCommentReply(params, options) {
3039
+ return apiConfig.httpClient.get(
3040
+ `/v1/stores/${storeId(params.store_id)}/social-publications/${params.publication_id}/comments/${params.comment_id}/replies/${params.reply_id}`,
3041
+ options
3042
+ );
3043
+ },
3044
+ async retryCommentReply(params, options) {
2579
3045
  return apiConfig.httpClient.post(
2580
- `/v1/stores/${storeId(store_id)}/social-publications/${publication_id}/comments/${comment_id}/reply`,
2581
- { text },
3046
+ `/v1/stores/${storeId(params.store_id)}/social-publications/${params.publication_id}/comments/${params.comment_id}/replies/${params.reply_id}/retry`,
3047
+ {},
3048
+ options
3049
+ );
3050
+ },
3051
+ async listPublicationEffects(params, options) {
3052
+ const { store_id, publication_id, ...queryParams } = params;
3053
+ return apiConfig.httpClient.get(
3054
+ `/v1/stores/${storeId(store_id)}/social-publications/${publication_id}/effects`,
3055
+ {
3056
+ ...options,
3057
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
3058
+ }
3059
+ );
3060
+ },
3061
+ async getPublicationEffect(params, options) {
3062
+ return apiConfig.httpClient.get(
3063
+ `/v1/stores/${storeId(params.store_id)}/social-publications/${params.publication_id}/effects/${params.effect_id}`,
2582
3064
  options
2583
3065
  );
2584
3066
  },
@@ -2605,41 +3087,41 @@ var createSocialApi = (apiConfig) => {
2605
3087
  },
2606
3088
  async getCapabilities(params, options) {
2607
3089
  return apiConfig.httpClient.get(
2608
- `/v1/stores/${storeId(params?.store_id)}/social-accounts/capabilities`,
3090
+ `/v1/stores/${storeId(params?.store_id)}/social-connections/capabilities`,
2609
3091
  options
2610
3092
  );
2611
3093
  },
2612
- async listAccounts(params, options) {
3094
+ async listConnections(params, options) {
2613
3095
  return apiConfig.httpClient.get(
2614
- `/v1/stores/${storeId(params?.store_id)}/social-accounts`,
3096
+ `/v1/stores/${storeId(params?.store_id)}/social-connections`,
2615
3097
  options
2616
3098
  );
2617
3099
  },
2618
3100
  async connect(params, options) {
2619
3101
  const { store_id, ...payload } = params;
2620
3102
  return apiConfig.httpClient.post(
2621
- `/v1/stores/${storeId(store_id)}/social-accounts/oauth/connect`,
3103
+ `/v1/stores/${storeId(store_id)}/social-connections/oauth/connect`,
2622
3104
  payload,
2623
3105
  options
2624
3106
  );
2625
3107
  },
2626
3108
  async getOAuthAttempt(params, options) {
2627
3109
  return apiConfig.httpClient.get(
2628
- `/v1/stores/${storeId(params.store_id)}/social-accounts/oauth/attempts/${params.attempt_id}`,
3110
+ `/v1/stores/${storeId(params.store_id)}/social-connections/oauth/attempts/${params.attempt_id}`,
2629
3111
  options
2630
3112
  );
2631
3113
  },
2632
3114
  async selectDestination(params, options) {
2633
3115
  const { store_id, ...payload } = params;
2634
3116
  return apiConfig.httpClient.post(
2635
- `/v1/stores/${storeId(store_id)}/social-accounts/oauth/select-destination`,
3117
+ `/v1/stores/${storeId(store_id)}/social-connections/oauth/select-destination`,
2636
3118
  payload,
2637
3119
  options
2638
3120
  );
2639
3121
  },
2640
- async deleteAccount(params, options) {
3122
+ async deleteConnection(params, options) {
2641
3123
  return apiConfig.httpClient.delete(
2642
- `/v1/stores/${storeId(params.store_id)}/social-accounts/${params.id}`,
3124
+ `/v1/stores/${storeId(params.store_id)}/social-connections/${params.id}`,
2643
3125
  options
2644
3126
  );
2645
3127
  },
@@ -2725,35 +3207,44 @@ var createWorkflowApi = (apiConfig) => {
2725
3207
  options
2726
3208
  );
2727
3209
  },
2728
- async getWorkflowAccounts(params, options) {
2729
- const store_id = params?.store_id || apiConfig.storeId;
3210
+ async getWorkflowEffects(params, options) {
3211
+ const store_id = params.store_id || apiConfig.storeId;
3212
+ const { store_id: _, workflow_id, execution_id, ...queryParams } = params;
3213
+ return apiConfig.httpClient.get(
3214
+ `/v1/stores/${store_id}/workflows/${workflow_id}/executions/${execution_id}/effects`,
3215
+ {
3216
+ ...options,
3217
+ params: Object.keys(queryParams).length > 0 ? queryParams : void 0
3218
+ }
3219
+ );
3220
+ },
3221
+ async getWorkflowEffect(params, options) {
3222
+ const store_id = params.store_id || apiConfig.storeId;
2730
3223
  return apiConfig.httpClient.get(
2731
- `/v1/stores/${store_id}/workflow-accounts`,
3224
+ `/v1/stores/${store_id}/workflows/${params.workflow_id}/executions/${params.execution_id}/effects/${params.effect_id}`,
2732
3225
  options
2733
3226
  );
2734
3227
  },
2735
- async getWorkflowAccountConnectUrl(params, options) {
2736
- const { store_id, type, ...payload } = params;
2737
- const target_store_id = store_id || apiConfig.storeId;
2738
- return apiConfig.httpClient.post(
2739
- `/v1/stores/${target_store_id}/workflow-accounts/connect-url`,
2740
- { ...payload, type, store_id: target_store_id },
3228
+ async getWorkflowConnections(params, options) {
3229
+ const store_id = params?.store_id || apiConfig.storeId;
3230
+ return apiConfig.httpClient.get(
3231
+ `/v1/stores/${store_id}/workflow-connections`,
2741
3232
  options
2742
3233
  );
2743
3234
  },
2744
- async connectWorkflowAccount(params, options) {
3235
+ async getWorkflowConnectionConnectUrl(params, options) {
2745
3236
  const { store_id, type, ...payload } = params;
2746
3237
  const target_store_id = store_id || apiConfig.storeId;
2747
3238
  return apiConfig.httpClient.post(
2748
- `/v1/stores/${target_store_id}/workflow-accounts/connect`,
3239
+ `/v1/stores/${target_store_id}/workflow-connections/connect-url`,
2749
3240
  { ...payload, type, store_id: target_store_id },
2750
3241
  options
2751
3242
  );
2752
3243
  },
2753
- async deleteWorkflowAccount(params, options) {
3244
+ async deleteWorkflowConnection(params, options) {
2754
3245
  const store_id = params.store_id || apiConfig.storeId;
2755
3246
  return apiConfig.httpClient.delete(
2756
- `/v1/stores/${store_id}/workflow-accounts/${params.id}`,
3247
+ `/v1/stores/${store_id}/workflow-connections/${params.id}`,
2757
3248
  options
2758
3249
  );
2759
3250
  }
@@ -2797,27 +3288,105 @@ var createPlatformApi = (apiConfig) => {
2797
3288
 
2798
3289
  // src/api/shipping.ts
2799
3290
  var createShippingApi = (apiConfig) => {
3291
+ const storeId = (value) => value || apiConfig.storeId;
2800
3292
  return {
3293
+ async findFulfillmentOrders(params, options) {
3294
+ const { store_id, order_id, ...queryParams } = params;
3295
+ return apiConfig.httpClient.get(
3296
+ `/v1/stores/${storeId(store_id)}/orders/${order_id}/fulfillment-orders`,
3297
+ { ...options, params: queryParams }
3298
+ );
3299
+ },
3300
+ async getFulfillmentOrder(params, options) {
3301
+ return apiConfig.httpClient.get(
3302
+ `/v1/stores/${storeId(params.store_id)}/orders/${params.order_id}/fulfillment-orders/${params.fulfillment_order_id}`,
3303
+ options
3304
+ );
3305
+ },
2801
3306
  async getRates(params, options) {
2802
- const { order_id, ...payload } = params;
3307
+ const { store_id, order_id, ...payload } = params;
2803
3308
  return apiConfig.httpClient.post(
2804
- `/v1/stores/${apiConfig.storeId}/orders/${order_id}/shipping/rates`,
3309
+ `/v1/stores/${storeId(store_id)}/orders/${order_id}/shipping/rates`,
2805
3310
  payload,
2806
3311
  options
2807
3312
  );
2808
3313
  },
2809
- async ship(params, options) {
2810
- const { order_id, ...payload } = params;
2811
- return apiConfig.httpClient.post(
2812
- `/v1/stores/${apiConfig.storeId}/orders/${order_id}/ship`,
3314
+ async findShipments(params, options) {
3315
+ const { store_id, order_id, ...queryParams } = params;
3316
+ return apiConfig.httpClient.get(
3317
+ `/v1/stores/${storeId(store_id)}/orders/${order_id}/shipments`,
3318
+ { ...options, params: queryParams }
3319
+ );
3320
+ },
3321
+ async getShipment(params, options) {
3322
+ return apiConfig.httpClient.get(
3323
+ `/v1/stores/${storeId(params.store_id)}/orders/${params.order_id}/shipments/${params.shipment_id}`,
3324
+ options
3325
+ );
3326
+ },
3327
+ async createShipment(params, options) {
3328
+ const { store_id, order_id, ...payload } = params;
3329
+ const response = await apiConfig.httpClient.post(
3330
+ `/v1/stores/${storeId(store_id)}/orders/${order_id}/shipments`,
2813
3331
  payload,
2814
3332
  options
2815
3333
  );
3334
+ if (response.shipment_id !== params.shipment_id || response.shipment.id !== params.shipment_id) {
3335
+ throw new Error("Shipping response did not match the requested shipment_id");
3336
+ }
3337
+ return response;
3338
+ },
3339
+ async retryShipment(params, options) {
3340
+ return apiConfig.httpClient.post(
3341
+ `/v1/stores/${storeId(params.store_id)}/orders/${params.order_id}/shipments/${params.shipment_id}/retry`,
3342
+ {},
3343
+ options
3344
+ );
3345
+ },
3346
+ async requestRefund(params, options) {
3347
+ return apiConfig.httpClient.post(
3348
+ `/v1/stores/${storeId(params.store_id)}/orders/${params.order_id}/shipments/${params.shipment_id}/refunds`,
3349
+ {},
3350
+ options
3351
+ );
3352
+ },
3353
+ async findRefunds(params, options) {
3354
+ const { store_id, order_id, shipment_id, ...queryParams } = params;
3355
+ return apiConfig.httpClient.get(
3356
+ `/v1/stores/${storeId(store_id)}/orders/${order_id}/shipments/${shipment_id}/refunds`,
3357
+ { ...options, params: queryParams }
3358
+ );
3359
+ },
3360
+ async getRefund(params, options) {
3361
+ return apiConfig.httpClient.get(
3362
+ `/v1/stores/${storeId(params.store_id)}/orders/${params.order_id}/shipments/${params.shipment_id}/refunds/${params.refund_id}`,
3363
+ options
3364
+ );
3365
+ },
3366
+ async retryRefund(params, options) {
3367
+ return apiConfig.httpClient.post(
3368
+ `/v1/stores/${storeId(params.store_id)}/orders/${params.order_id}/shipments/${params.shipment_id}/refunds/${params.refund_id}/retry`,
3369
+ {},
3370
+ options
3371
+ );
3372
+ },
3373
+ async findAdjustments(params, options) {
3374
+ const { store_id, order_id, shipment_id, ...queryParams } = params;
3375
+ return apiConfig.httpClient.get(
3376
+ `/v1/stores/${storeId(store_id)}/orders/${order_id}/shipments/${shipment_id}/adjustments`,
3377
+ { ...options, params: queryParams }
3378
+ );
3379
+ },
3380
+ async findSettlements(params, options) {
3381
+ const { store_id, order_id, shipment_id, ...queryParams } = params;
3382
+ return apiConfig.httpClient.get(
3383
+ `/v1/stores/${storeId(store_id)}/orders/${order_id}/shipments/${shipment_id}/settlements`,
3384
+ { ...options, params: queryParams }
3385
+ );
2816
3386
  },
2817
- async refundLabel(params, options) {
2818
- const { order_id, shipment_id } = params;
3387
+ async retrySettlement(params, options) {
2819
3388
  return apiConfig.httpClient.post(
2820
- `/v1/stores/${apiConfig.storeId}/orders/${order_id}/shipments/${shipment_id}/label/refund`,
3389
+ `/v1/stores/${storeId(params.store_id)}/orders/${params.order_id}/shipments/${params.shipment_id}/settlements/${params.settlement_id}/retry`,
2821
3390
  {},
2822
3391
  options
2823
3392
  );
@@ -3126,155 +3695,230 @@ var createExperimentsApi = (apiConfig) => {
3126
3695
  };
3127
3696
 
3128
3697
  // src/utils/blocks.ts
3129
- function getBlockLabel(block) {
3130
- if (!block) return "";
3131
- return block.key?.replace(/_/g, " ").replace(/\b\w/g, (l) => l.toUpperCase()) ?? "";
3698
+ function isRecord2(value) {
3699
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3132
3700
  }
3133
- function formatBlockValue(block) {
3134
- if (!block || block.value === null || block.value === void 0) return "";
3135
- const value = block.value;
3136
- switch (block.type) {
3137
- case "boolean":
3138
- return value ? "Yes" : "No";
3139
- case "number":
3140
- if (block.properties?.variant === "DATE" || block.properties?.variant === "DATE_TIME") {
3141
- return new Date(value).toLocaleDateString();
3142
- }
3143
- return String(value);
3144
- case "media":
3145
- if (value && typeof value === "object") {
3146
- return value.mime_type ? value.name || value.id : value.title || value.name || value.id;
3147
- }
3148
- return String(value);
3149
- default:
3150
- return String(value);
3151
- }
3701
+ function isBlock(value) {
3702
+ return isRecord2(value) && typeof value.key === "string" && typeof value.type === "string";
3152
3703
  }
3153
- function prepareBlocksForSubmission(formData, blockTypes) {
3154
- return Object.keys(formData).filter((key) => formData[key] !== null && formData[key] !== void 0).map((key) => ({
3155
- key,
3156
- value: (blockTypes?.[key] || "text") === "array" && !Array.isArray(formData[key]) ? [formData[key]] : formData[key]
3157
- }));
3704
+ function recordFromBlocks(values, locale) {
3705
+ const result = {};
3706
+ for (const value of values) {
3707
+ if (!isBlock(value)) continue;
3708
+ result[value.key] = unwrapBlock(value, locale);
3709
+ }
3710
+ return result;
3158
3711
  }
3159
- function extractBlockValues(blocks) {
3160
- const values = {};
3161
- blocks.forEach((block) => {
3162
- values[block.key] = block.value ?? null;
3163
- });
3164
- return values;
3712
+ function localizedValue(value, locale) {
3713
+ if (typeof value === "string") return value;
3714
+ if (!isRecord2(value)) return "";
3715
+ const selected = value[locale] ?? value.en;
3716
+ return typeof selected === "string" ? selected : "";
3165
3717
  }
3166
- var getBlockValue = (entry, blockKey) => {
3167
- const block = entry?.blocks?.find((f) => f.key === blockKey);
3168
- return block?.value ?? null;
3169
- };
3170
- var getBlockTextValue = (block, locale = "en") => {
3171
- if (!block || block.value === null || block.value === void 0) return "";
3172
- const blockType = block.type;
3173
- if (blockType === "localized_text" || blockType === "markdown") {
3174
- if (typeof block.value === "object" && block.value !== null) {
3175
- return block.value[locale] ?? block.value["en"] ?? "";
3176
- }
3177
- }
3178
- if (typeof block.value === "string") return block.value;
3179
- return String(block.value ?? "");
3180
- };
3181
- var getBlockValues = (entry, blockKey) => {
3182
- const block = entry?.blocks?.find((f) => f.key === blockKey);
3183
- if (!block) return [];
3184
- if (block.type === "array" && Array.isArray(block.value)) {
3185
- return block.value;
3718
+ function unwrapBlock(value, locale) {
3719
+ if (!isBlock(value)) return value;
3720
+ if (value.type === "localized_text" || value.type === "markdown") {
3721
+ return localizedValue(value.value, locale);
3186
3722
  }
3187
- return [];
3188
- };
3189
- function unwrapBlock(block, locale) {
3190
- if (!block?.type || block.value === void 0) return block;
3191
- const blockType = block.type;
3192
- if (blockType === "array") {
3193
- return block.value.map((obj) => {
3194
- const parsed = {};
3195
- for (const [k, v] of Object.entries(obj)) {
3196
- parsed[k] = unwrapBlock(v, locale);
3723
+ if (value.type === "array") {
3724
+ if (!Array.isArray(value.value)) return [];
3725
+ return value.value.map((item) => {
3726
+ if (isBlock(item)) return unwrapBlock(item, locale);
3727
+ if (isRecord2(item) && Array.isArray(item.value)) {
3728
+ return recordFromBlocks(item.value, locale);
3197
3729
  }
3198
- return parsed;
3730
+ if (!isRecord2(item)) return item;
3731
+ return Object.fromEntries(
3732
+ Object.entries(item).map(([key, nested]) => [key, unwrapBlock(nested, locale)])
3733
+ );
3199
3734
  });
3200
3735
  }
3201
- if (blockType === "object") {
3202
- const parsed = {};
3203
- for (const [k, v] of Object.entries(block.value || {})) {
3204
- parsed[k] = unwrapBlock(v, locale);
3205
- }
3206
- return parsed;
3736
+ if (value.type === "object") {
3737
+ if (Array.isArray(value.value)) return recordFromBlocks(value.value, locale);
3738
+ if (!isRecord2(value.value)) return {};
3739
+ return Object.fromEntries(
3740
+ Object.entries(value.value).map(([key, nested]) => [key, unwrapBlock(nested, locale)])
3741
+ );
3207
3742
  }
3208
- if (blockType === "localized_text" || blockType === "markdown") {
3209
- return block.value?.[locale];
3743
+ return value.value;
3744
+ }
3745
+ function blockContentArray(values, locale) {
3746
+ const blocks = values.filter(isBlock);
3747
+ if (blocks.length === 0) return [];
3748
+ if (blocks.every((block) => block.key === blocks[0].key)) {
3749
+ return blocks.map((block) => blockContentValue(block, locale));
3210
3750
  }
3211
- return block.value;
3751
+ return Object.fromEntries(
3752
+ blocks.map((block) => [block.key, blockContentValue(block, locale)])
3753
+ );
3212
3754
  }
3213
- var getBlockObjectValues = (entry, blockKey, locale = "en") => {
3214
- const block = entry?.blocks?.find((f) => f.key === blockKey);
3215
- if (!block || block.type !== "array" || !Array.isArray(block.value)) return [];
3216
- return block.value.map((obj) => {
3217
- if (!obj?.value || !Array.isArray(obj.value)) return {};
3218
- return obj.value.reduce((acc, current) => {
3219
- acc[current.key] = unwrapBlock(current, locale);
3220
- return acc;
3221
- }, {});
3222
- });
3223
- };
3224
- var getBlockFromArray = (entry, blockKey, locale = "en") => {
3225
- const block = entry?.blocks?.find((f) => f.key === blockKey);
3226
- if (!block) return {};
3227
- if (block.type === "array" && Array.isArray(block.value)) {
3228
- return block.value.reduce((acc, current) => {
3229
- acc[current.key] = unwrapBlock(current, locale);
3230
- return acc;
3231
- }, {});
3755
+ function blockContentValue(block, locale) {
3756
+ if (block.type === "localized_text" || block.type === "markdown") {
3757
+ return localizedValue(block.value, locale);
3758
+ }
3759
+ if (block.type === "media") return block.value ?? null;
3760
+ if (block.type === "array") {
3761
+ return Array.isArray(block.value) ? blockContentArray(block.value, locale) : [];
3232
3762
  }
3233
- if (block.type === "object" && block.value && typeof block.value === "object") {
3234
- const result = {};
3235
- for (const [k, v] of Object.entries(block.value)) {
3236
- result[k] = unwrapBlock(v, locale);
3763
+ if (block.type === "object") {
3764
+ if (Array.isArray(block.value)) return blockContentArray(block.value, locale);
3765
+ if (!isRecord2(block.value)) return {};
3766
+ return Object.fromEntries(
3767
+ Object.entries(block.value).map(([key, value]) => [
3768
+ key,
3769
+ isBlock(value) ? blockContentValue(value, locale) : value
3770
+ ])
3771
+ );
3772
+ }
3773
+ return block.value;
3774
+ }
3775
+ function findBlock(entry, key) {
3776
+ return entry?.blocks?.find((block) => block.key === key);
3777
+ }
3778
+ function getBlockLabel(block) {
3779
+ return block?.key.replace(/_/g, " ").replace(/\b\w/g, (letter) => letter.toUpperCase()) ?? "";
3780
+ }
3781
+ function formatBlockValue(block) {
3782
+ if (block?.value === null || block?.value === void 0) return "";
3783
+ if (block.type === "boolean") return block.value ? "Yes" : "No";
3784
+ if (block.type === "number") {
3785
+ const properties = isRecord2(block.properties) ? block.properties : {};
3786
+ if (properties.variant === "DATE" || properties.variant === "DATE_TIME") {
3787
+ return new Date(Number(block.value)).toLocaleDateString();
3237
3788
  }
3238
- return result;
3239
3789
  }
3240
- return { [block.key]: unwrapBlock(block, locale) };
3241
- };
3242
- var getImageUrl = (imageBlock, isBlock = true) => {
3243
- if (!imageBlock) return null;
3244
- if (imageBlock.type === "media") {
3245
- const mediaValue = imageBlock.value;
3246
- return mediaValue?.resolutions?.original?.url || mediaValue?.url || null;
3790
+ if (block.type === "media" && isRecord2(block.value)) {
3791
+ const label = block.value.name ?? block.value.title ?? block.value.id;
3792
+ return typeof label === "string" ? label : "";
3247
3793
  }
3248
- if (isBlock) {
3249
- if (typeof imageBlock === "string") return imageBlock;
3250
- if (imageBlock.url) return imageBlock.url;
3794
+ return String(block.value);
3795
+ }
3796
+ function prepareBlocksForSubmission(formData, blockTypes = {}) {
3797
+ return Object.entries(formData).filter(([, value]) => value !== null && value !== void 0).map(([key, value]) => ({
3798
+ key,
3799
+ value: blockTypes[key] === "array" && !Array.isArray(value) ? [value] : value
3800
+ }));
3801
+ }
3802
+ function extractBlockValues(blocks) {
3803
+ return Object.fromEntries(blocks.map((block) => [block.key, block.value ?? null]));
3804
+ }
3805
+ function getBlockValue(entry, key) {
3806
+ return findBlock(entry, key)?.value ?? null;
3807
+ }
3808
+ function getBlockTextValue(block, locale = "en") {
3809
+ if (!block || block.value === null || block.value === void 0) return "";
3810
+ if (block.type === "localized_text" || block.type === "markdown") {
3811
+ return localizedValue(block.value, locale);
3251
3812
  }
3252
- return imageBlock.resolutions?.original?.url || null;
3253
- };
3813
+ return typeof block.value === "string" ? block.value : String(block.value);
3814
+ }
3815
+ function getBlockContentValue(entry, key, locale = "en") {
3816
+ const block = findBlock(entry, key);
3817
+ return block ? blockContentValue(block, locale) : null;
3818
+ }
3819
+ function getBlockValues(entry, key) {
3820
+ const block = findBlock(entry, key);
3821
+ return block?.type === "array" && Array.isArray(block.value) ? block.value : [];
3822
+ }
3823
+ function getBlockObjectValues(entry, key, locale = "en") {
3824
+ return getBlockValues(entry, key).map((value) => {
3825
+ if (isRecord2(value) && Array.isArray(value.value)) {
3826
+ return recordFromBlocks(value.value, locale);
3827
+ }
3828
+ return isRecord2(value) ? Object.fromEntries(
3829
+ Object.entries(value).map(([field, nested]) => [field, unwrapBlock(nested, locale)])
3830
+ ) : {};
3831
+ });
3832
+ }
3833
+ function getBlockFromArray(entry, key, locale = "en") {
3834
+ const block = findBlock(entry, key);
3835
+ if (!block) return {};
3836
+ const value = unwrapBlock(block, locale);
3837
+ if (isRecord2(value)) return value;
3838
+ if (Array.isArray(block.value)) return recordFromBlocks(block.value, locale);
3839
+ return { [block.key]: value };
3840
+ }
3841
+ function nestedUrl(value) {
3842
+ const resolutions = isRecord2(value.resolutions) ? value.resolutions : null;
3843
+ const original = resolutions && isRecord2(resolutions.original) ? resolutions.original : null;
3844
+ if (typeof original?.url === "string") return original.url;
3845
+ return typeof value.url === "string" ? value.url : null;
3846
+ }
3847
+ function getImageUrl(value, isBlock2 = true) {
3848
+ if (typeof value === "string") return value;
3849
+ if (!isRecord2(value)) return null;
3850
+ if (value.type === "media" && isRecord2(value.value)) return nestedUrl(value.value);
3851
+ if (isBlock2 && typeof value.url === "string") return value.url;
3852
+ return nestedUrl(value);
3853
+ }
3254
3854
 
3255
3855
  // src/utils/price.ts
3856
+ var SUPPORTED_STORE_CURRENCIES = Object.freeze([
3857
+ "USD",
3858
+ "EUR",
3859
+ "GBP",
3860
+ "JPY",
3861
+ "CNY",
3862
+ "CHF",
3863
+ "AUD",
3864
+ "CAD",
3865
+ "HKD",
3866
+ "SGD",
3867
+ "NZD",
3868
+ "KRW",
3869
+ "SEK",
3870
+ "NOK",
3871
+ "DKK",
3872
+ "INR",
3873
+ "MXN",
3874
+ "BRL",
3875
+ "ZAR",
3876
+ "RUB",
3877
+ "TRY",
3878
+ "PLN",
3879
+ "THB",
3880
+ "IDR",
3881
+ "MYR",
3882
+ "PHP",
3883
+ "CZK",
3884
+ "ILS",
3885
+ "AED",
3886
+ "SAR",
3887
+ "HUF",
3888
+ "RON",
3889
+ "BGN",
3890
+ "HRK",
3891
+ "BAM",
3892
+ "RSD",
3893
+ "MKD",
3894
+ "ALL"
3895
+ ]);
3896
+ var SUPPORTED_STORE_CURRENCY_SET = Object.freeze(
3897
+ new Set(SUPPORTED_STORE_CURRENCIES)
3898
+ );
3899
+ var ZERO_MINOR_UNIT_STORE_CURRENCIES = Object.freeze(
3900
+ /* @__PURE__ */ new Set(["JPY", "KRW"])
3901
+ );
3256
3902
  function formatCurrency(amount, currencyCode, locale = "en") {
3257
- if (!currencyCode) return "";
3903
+ const normalized = currencyCode.trim().toUpperCase();
3904
+ if (!normalized) return "";
3905
+ const minorUnits = getCurrencyMinorUnits(normalized);
3258
3906
  return new Intl.NumberFormat(locale, {
3259
3907
  style: "currency",
3260
- currency: currencyCode.toUpperCase()
3908
+ currency: normalized,
3909
+ minimumFractionDigits: minorUnits,
3910
+ maximumFractionDigits: minorUnits
3261
3911
  }).format(amount);
3262
3912
  }
3263
- function getMinorUnits(currency) {
3264
- try {
3265
- const formatter = new Intl.NumberFormat("en", {
3266
- style: "currency",
3267
- currency: currency.toUpperCase()
3268
- });
3269
- const parts = formatter.formatToParts(1.11);
3270
- const fractionPart = parts.find((p) => p.type === "fraction");
3271
- return fractionPart?.value.length ?? 2;
3272
- } catch {
3273
- return 2;
3913
+ function getCurrencyMinorUnits(currency) {
3914
+ const normalized = currency.trim().toUpperCase();
3915
+ if (!SUPPORTED_STORE_CURRENCY_SET.has(normalized)) {
3916
+ throw new RangeError(`Unsupported currency '${currency}'`);
3274
3917
  }
3918
+ return ZERO_MINOR_UNIT_STORE_CURRENCIES.has(normalized) ? 0 : 2;
3275
3919
  }
3276
3920
  function convertToMajor(minorAmount, currency) {
3277
- const units = getMinorUnits(currency);
3921
+ const units = getCurrencyMinorUnits(currency);
3278
3922
  return minorAmount / Math.pow(10, units);
3279
3923
  }
3280
3924
  function getCurrencySymbol(currency) {
@@ -3296,22 +3940,24 @@ function getCurrencyName(currency) {
3296
3940
  }
3297
3941
  }
3298
3942
  function formatMinor(amountMinor, currency) {
3299
- if (!currency) return "";
3943
+ if (!Number.isSafeInteger(amountMinor)) {
3944
+ throw new RangeError("Minor-unit amount must be a safe integer");
3945
+ }
3300
3946
  return formatCurrency(convertToMajor(amountMinor, currency), currency);
3301
3947
  }
3302
3948
  function formatPayment(payment) {
3303
3949
  return formatMinor(payment.total, payment.currency);
3304
3950
  }
3305
3951
  function formatPrice(prices, marketId) {
3306
- if (!prices || prices.length === 0) return "";
3307
- const price = marketId ? prices.find((p) => p.market === marketId) || prices[0] : prices[0];
3308
- if (!price) return "";
3952
+ if (!prices || prices.length === 0 || !marketId) return "";
3953
+ const price = prices.find((p) => p.market === marketId);
3954
+ if (!price || !Number.isSafeInteger(price.amount) || price.amount < 0 || !price.currency) return "";
3309
3955
  return formatMinor(price.amount, price.currency);
3310
3956
  }
3311
3957
  function getPriceAmount(prices, marketId) {
3312
- if (!prices || prices.length === 0) return 0;
3313
- const price = prices.find((p) => p.market === marketId) || prices[0];
3314
- return price?.amount || 0;
3958
+ if (!prices || prices.length === 0 || !marketId) return null;
3959
+ const price = prices.find((p) => p.market === marketId);
3960
+ return price && Number.isSafeInteger(price.amount) && price.amount >= 0 ? price.amount : null;
3315
3961
  }
3316
3962
 
3317
3963
  // src/utils/validation.ts
@@ -3412,6 +4058,7 @@ function formatDate(date, locale) {
3412
4058
  async function fetchSvgContent(mediaObject) {
3413
4059
  if (!mediaObject) return null;
3414
4060
  const svgUrl = getImageUrl(mediaObject, false);
4061
+ if (!svgUrl) return null;
3415
4062
  try {
3416
4063
  const response = await fetch(svgUrl);
3417
4064
  if (!response.ok) {
@@ -3502,7 +4149,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
3502
4149
  }
3503
4150
 
3504
4151
  // src/index.ts
3505
- var SDK_VERSION = "0.9.11";
4152
+ var SDK_VERSION = "0.9.16";
3506
4153
  var SUPPORTED_FRAMEWORKS = [
3507
4154
  "astro",
3508
4155
  "react",
@@ -3512,9 +4159,10 @@ var SUPPORTED_FRAMEWORKS = [
3512
4159
  ];
3513
4160
  function createUtilitySurface(apiConfig) {
3514
4161
  return {
3515
- getImageUrl: (imageBlock, isBlock = true) => getImageUrl(imageBlock, isBlock),
4162
+ getImageUrl: (imageBlock, isBlock2 = true) => getImageUrl(imageBlock, isBlock2),
3516
4163
  getBlockValue,
3517
4164
  getBlockTextValue,
4165
+ getBlockContentValue,
3518
4166
  getBlockValues,
3519
4167
  getBlockLabel,
3520
4168
  getBlockObjectValues,
@@ -3665,10 +4313,11 @@ function createAdmin(config) {
3665
4313
  trigger: workflowApi.triggerWorkflow,
3666
4314
  getExecutions: workflowApi.getWorkflowExecutions,
3667
4315
  getExecution: workflowApi.getWorkflowExecution,
3668
- listAccounts: workflowApi.getWorkflowAccounts,
3669
- getAccountConnectUrl: workflowApi.getWorkflowAccountConnectUrl,
3670
- connectAccount: workflowApi.connectWorkflowAccount,
3671
- deleteAccount: workflowApi.deleteWorkflowAccount
4316
+ listEffects: workflowApi.getWorkflowEffects,
4317
+ getEffect: workflowApi.getWorkflowEffect,
4318
+ listConnections: workflowApi.getWorkflowConnections,
4319
+ getConnectionConnectUrl: workflowApi.getWorkflowConnectionConnectUrl,
4320
+ deleteConnection: workflowApi.deleteWorkflowConnection
3672
4321
  };
3673
4322
  const formApi = createFormApi(apiConfig);
3674
4323
  const taxonomyApi = createTaxonomyApi(apiConfig);
@@ -3681,22 +4330,43 @@ function createAdmin(config) {
3681
4330
  delete: accountApi.deleteAccount,
3682
4331
  getMe: accountApi.getMe,
3683
4332
  search: accountApi.searchAccounts,
4333
+ apiToken: {
4334
+ list: accountApi.listApiTokens,
4335
+ create: accountApi.createApiToken,
4336
+ update: accountApi.updateApiToken,
4337
+ revoke: accountApi.revokeApiToken
4338
+ },
4339
+ session: {
4340
+ list: accountApi.listSessions,
4341
+ revoke: accountApi.revokeSession
4342
+ },
3684
4343
  auth: authApi
3685
4344
  },
3686
4345
  store: {
3687
4346
  create: storeApi.createStore,
3688
4347
  update: storeApi.updateStore,
3689
- delete: storeApi.deleteStore,
3690
4348
  get: storeApi.getStore,
3691
4349
  find: storeApi.getStores,
3692
4350
  subscription: {
4351
+ get: storeApi.getSubscription,
3693
4352
  getPlans: storeApi.getSubscriptionPlans,
3694
- subscribe: storeApi.subscribe,
4353
+ action: {
4354
+ create: storeApi.createSubscriptionAction,
4355
+ find: storeApi.findSubscriptionActions,
4356
+ get: storeApi.getSubscriptionAction,
4357
+ retry: storeApi.retrySubscriptionAction,
4358
+ effect: {
4359
+ find: storeApi.findSubscriptionActionEffects,
4360
+ get: storeApi.getSubscriptionActionEffect
4361
+ }
4362
+ },
3695
4363
  createPortalSession: storeApi.createPortalSession
3696
4364
  },
3697
4365
  member: {
3698
4366
  add: storeApi.addMember,
3699
4367
  invite: storeApi.inviteUser,
4368
+ find: storeApi.findMembers,
4369
+ findOwn: storeApi.findOwnMemberships,
3700
4370
  remove: storeApi.removeMember
3701
4371
  },
3702
4372
  buildHook: {
@@ -3713,10 +4383,7 @@ function createAdmin(config) {
3713
4383
  delete: storeApi.deleteWebhook
3714
4384
  },
3715
4385
  config: {
3716
- get: storeApi.getStoreConfig
3717
- },
3718
- media: {
3719
- find: storeApi.getStoreMedia
4386
+ getPayment: storeApi.getPaymentConfig
3720
4387
  },
3721
4388
  location: locationApi,
3722
4389
  market: marketApi,
@@ -3725,22 +4392,21 @@ function createAdmin(config) {
3725
4392
  media: createMediaApi(apiConfig),
3726
4393
  notification: {
3727
4394
  email: {
3728
- trackOpen: notificationApi.trackEmailOpen
3729
- },
3730
- trigger: {
3731
- send: notificationApi.trigger
4395
+ send: notificationApi.sendEmail,
4396
+ getDelivery: notificationApi.getEmailDelivery,
4397
+ retryDelivery: notificationApi.retryEmailDelivery
3732
4398
  },
3733
4399
  mailbox: crmApi.mailbox
3734
4400
  },
3735
4401
  platform: platformApi,
3736
4402
  social: {
3737
- account: {
4403
+ connection: {
3738
4404
  getCapabilities: socialApi.getCapabilities,
3739
- list: socialApi.listAccounts,
4405
+ list: socialApi.listConnections,
3740
4406
  connect: socialApi.connect,
3741
4407
  getOAuthAttempt: socialApi.getOAuthAttempt,
3742
4408
  selectDestination: socialApi.selectDestination,
3743
- delete: socialApi.deleteAccount
4409
+ delete: socialApi.deleteConnection
3744
4410
  },
3745
4411
  publication: {
3746
4412
  create: socialApi.createPublication,
@@ -3756,7 +4422,16 @@ function createAdmin(config) {
3756
4422
  syncCommentThread: socialApi.syncPublicationCommentThread,
3757
4423
  findComments: socialApi.findPublicationComments,
3758
4424
  classifyComments: socialApi.classifyPublicationComments,
3759
- replyToComment: socialApi.replyToPublicationComment,
4425
+ commentReply: {
4426
+ create: socialApi.createCommentReply,
4427
+ list: socialApi.listCommentReplies,
4428
+ get: socialApi.getCommentReply,
4429
+ retry: socialApi.retryCommentReply
4430
+ },
4431
+ effect: {
4432
+ list: socialApi.listPublicationEffects,
4433
+ get: socialApi.getPublicationEffect
4434
+ },
3760
4435
  getMetrics: socialApi.getPublicationMetrics,
3761
4436
  syncMetrics: socialApi.syncPublicationMetrics,
3762
4437
  syncEngagement: socialApi.syncEngagement
@@ -3818,11 +4493,43 @@ function createAdmin(config) {
3818
4493
  get: eshopApi.getOrder,
3819
4494
  find: eshopApi.getOrders,
3820
4495
  getQuote: eshopApi.getQuote,
3821
- processRefund: eshopApi.processRefund,
4496
+ createRefund: eshopApi.createRefund,
4497
+ getRefund: eshopApi.getRefund,
4498
+ getRefunds: eshopApi.getRefunds,
4499
+ retryRefund: eshopApi.retryRefund,
4500
+ getPayment: eshopApi.getPayment,
4501
+ retryPaymentTransaction: eshopApi.retryPaymentTransaction,
4502
+ getPaymentTransactions: eshopApi.getPaymentTransactions,
4503
+ getPaymentTransaction: eshopApi.getPaymentTransaction,
4504
+ findDigitalAccess: eshopApi.findDigitalAccess,
4505
+ getDigitalAccess: eshopApi.getDigitalAccess,
3822
4506
  downloadDigitalAccess: eshopApi.downloadDigitalAccess,
3823
- getShippingRates: shippingApi.getRates,
3824
- ship: shippingApi.ship,
3825
- refundShippingLabel: shippingApi.refundLabel
4507
+ activateDigitalAccess: eshopApi.activateDigitalAccess,
4508
+ revokeDigitalAccess: eshopApi.revokeDigitalAccess
4509
+ },
4510
+ shipment: {
4511
+ getRates: shippingApi.getRates,
4512
+ create: shippingApi.createShipment,
4513
+ get: shippingApi.getShipment,
4514
+ find: shippingApi.findShipments,
4515
+ retry: shippingApi.retryShipment,
4516
+ fulfillment: {
4517
+ find: shippingApi.findFulfillmentOrders,
4518
+ get: shippingApi.getFulfillmentOrder
4519
+ },
4520
+ refund: {
4521
+ request: shippingApi.requestRefund,
4522
+ get: shippingApi.getRefund,
4523
+ find: shippingApi.findRefunds,
4524
+ retry: shippingApi.retryRefund
4525
+ },
4526
+ adjustment: {
4527
+ find: shippingApi.findAdjustments
4528
+ },
4529
+ settlement: {
4530
+ find: shippingApi.findSettlements,
4531
+ retry: shippingApi.retrySettlement
4532
+ }
3826
4533
  },
3827
4534
  cart: {
3828
4535
  create: eshopApi.createCart,
@@ -3864,8 +4571,9 @@ function createAdmin(config) {
3864
4571
  update: crmApi.update,
3865
4572
  merge: crmApi.merge,
3866
4573
  import: crmApi.import,
3867
- revokeToken: crmApi.revokeToken,
3868
- revokeAllTokens: crmApi.revokeAllTokens
4574
+ findSessions: crmApi.findSessions,
4575
+ revokeSession: crmApi.revokeSession,
4576
+ revokeAllSessions: crmApi.revokeAllSessions
3869
4577
  },
3870
4578
  contactList: {
3871
4579
  create: crmApi.contactList.create,
@@ -3877,7 +4585,14 @@ function createAdmin(config) {
3877
4585
  addMember: crmApi.contactList.members.add,
3878
4586
  updateMember: crmApi.contactList.members.update,
3879
4587
  removeMember: crmApi.contactList.members.remove,
3880
- findMembers: crmApi.contactList.members.find
4588
+ findMembers: crmApi.contactList.members.find,
4589
+ plans: crmApi.contactList.plans,
4590
+ memberships: {
4591
+ refund: crmApi.contactList.memberships.refund,
4592
+ paymentAttempts: crmApi.contactList.memberships.paymentAttempts,
4593
+ refunds: crmApi.contactList.memberships.refunds,
4594
+ cancellations: crmApi.contactList.memberships.cancellations
4595
+ }
3881
4596
  },
3882
4597
  action: crmApi.action
3883
4598
  },
@@ -3951,29 +4666,50 @@ function createAdmin(config) {
3951
4666
  };
3952
4667
  return sdk;
3953
4668
  }
3954
- var CONTACT_STORAGE_KEY = "arky_contact_session";
3955
- function readContactSession() {
4669
+ function defaultStorefrontSessionStorage() {
3956
4670
  if (typeof window === "undefined") return null;
3957
4671
  try {
3958
- const raw = localStorage.getItem(CONTACT_STORAGE_KEY);
3959
- return raw ? JSON.parse(raw) : null;
4672
+ return window.localStorage;
3960
4673
  } catch {
3961
4674
  return null;
3962
4675
  }
3963
4676
  }
3964
- function writeContactSession(s) {
3965
- if (typeof window === "undefined") return;
3966
- if (s) {
3967
- localStorage.setItem(CONTACT_STORAGE_KEY, JSON.stringify(s));
3968
- } else {
3969
- localStorage.removeItem(CONTACT_STORAGE_KEY);
3970
- }
4677
+ function storefrontSessionStorageKey(baseUrl, storeId) {
4678
+ const normalizedBaseUrl = baseUrl.trim().replace(/\/+$/, "").toLowerCase();
4679
+ return `arky_contact_session:${encodeURIComponent(normalizedBaseUrl)}:${encodeURIComponent(storeId)}`;
3971
4680
  }
3972
- function createStorefront(config) {
4681
+ function createStorefrontClient(config) {
3973
4682
  const locale = config.locale || "en";
3974
4683
  const initialMarket = config.market || "";
3975
4684
  const listeners = /* @__PURE__ */ new Set();
3976
4685
  let bareIdentifyPromise = null;
4686
+ let identityTail = Promise.resolve();
4687
+ const sessionStorage = config.sessionStorage || defaultStorefrontSessionStorage();
4688
+ let memorySession = null;
4689
+ function readContactSession() {
4690
+ if (!sessionStorage) return memorySession;
4691
+ try {
4692
+ const raw = sessionStorage.getItem(
4693
+ storefrontSessionStorageKey(config.baseUrl, config.storeId)
4694
+ );
4695
+ return raw ? JSON.parse(raw) : null;
4696
+ } catch {
4697
+ return memorySession;
4698
+ }
4699
+ }
4700
+ function writeContactSession(session) {
4701
+ memorySession = session;
4702
+ if (!sessionStorage) return;
4703
+ const key = storefrontSessionStorageKey(config.baseUrl, config.storeId);
4704
+ try {
4705
+ if (session) {
4706
+ sessionStorage.setItem(key, JSON.stringify(session));
4707
+ } else {
4708
+ sessionStorage.removeItem(key);
4709
+ }
4710
+ } catch {
4711
+ }
4712
+ }
3977
4713
  function toPublic(s) {
3978
4714
  return s ? { contact: s.contact, store: s.store, market: s.market } : null;
3979
4715
  }
@@ -4029,19 +4765,23 @@ function createStorefront(config) {
4029
4765
  const contactApi = storefrontApi.crm.contact;
4030
4766
  function identify(params) {
4031
4767
  if (params?.market !== void 0) apiConfig.market = params.market;
4768
+ const market = apiConfig.market;
4032
4769
  const isBareCall = !params?.email && !params?.verify;
4033
4770
  if (isBareCall && bareIdentifyPromise) return bareIdentifyPromise;
4034
- const promise = (async () => {
4771
+ const run = async () => {
4035
4772
  try {
4036
- const result = await contactApi.identify({
4037
- market: apiConfig.market,
4038
- email: params?.email,
4039
- verify: params?.verify
4040
- });
4773
+ const result = await (params?.verify ? contactApi.requestCode({
4774
+ market,
4775
+ email: params.email
4776
+ }) : contactApi.identify({
4777
+ market,
4778
+ email: params?.email
4779
+ }));
4041
4780
  return {
4042
4781
  contact: result.contact,
4043
4782
  store: result.store,
4044
- market: result.market
4783
+ market: result.market,
4784
+ verification_challenge: result.verification_challenge
4045
4785
  };
4046
4786
  } catch (err) {
4047
4787
  const e = err;
@@ -4049,21 +4789,34 @@ function createStorefront(config) {
4049
4789
  if (isBareCall && status === 401) {
4050
4790
  updateSession(() => null);
4051
4791
  const result = await contactApi.identify({
4052
- market: apiConfig.market
4792
+ market
4053
4793
  });
4054
4794
  return {
4055
4795
  contact: result.contact,
4056
4796
  store: result.store,
4057
- market: result.market
4797
+ market: result.market,
4798
+ verification_challenge: result.verification_challenge
4058
4799
  };
4059
4800
  }
4060
4801
  throw err;
4061
4802
  }
4062
- })().catch((err) => {
4063
- if (isBareCall) bareIdentifyPromise = null;
4064
- throw err;
4065
- });
4066
- if (isBareCall) bareIdentifyPromise = promise;
4803
+ };
4804
+ const promise = identityTail.then(run);
4805
+ identityTail = promise.then(
4806
+ () => void 0,
4807
+ () => void 0
4808
+ );
4809
+ if (isBareCall) {
4810
+ bareIdentifyPromise = promise;
4811
+ void promise.then(
4812
+ () => {
4813
+ if (bareIdentifyPromise === promise) bareIdentifyPromise = null;
4814
+ },
4815
+ () => {
4816
+ if (bareIdentifyPromise === promise) bareIdentifyPromise = null;
4817
+ }
4818
+ );
4819
+ }
4067
4820
  return promise;
4068
4821
  }
4069
4822
  async function verify(params) {
@@ -4106,17 +4859,12 @@ function createStorefront(config) {
4106
4859
  };
4107
4860
  },
4108
4861
  store: storefrontApi.store,
4109
- cart: createCartController(storefrontApi.eshop.cart),
4110
4862
  cms: storefrontApi.cms,
4111
4863
  eshop: storefrontApi.eshop,
4112
4864
  crm: storefrontApi.crm,
4113
4865
  action: storefrontApi.action,
4114
4866
  experiments: storefrontApi.experiments,
4115
4867
  support: createStorefrontSupportApi(apiConfig),
4116
- setStoreId: (storeId) => {
4117
- apiConfig.storeId = storeId;
4118
- bareIdentifyPromise = null;
4119
- },
4120
4868
  getStoreId: () => apiConfig.storeId,
4121
4869
  setMarket: (key) => {
4122
4870
  apiConfig.market = key;
@@ -4130,6 +4878,26 @@ function createStorefront(config) {
4130
4878
  utils: createUtilitySurface(apiConfig)
4131
4879
  };
4132
4880
  }
4881
+ function createStorefront(config) {
4882
+ const sessionStorage = config.sessionStorage || defaultStorefrontSessionStorage() || void 0;
4883
+ const scopedConfig = {
4884
+ ...config,
4885
+ sessionStorage
4886
+ };
4887
+ const client = createStorefrontClient(scopedConfig);
4888
+ Object.defineProperty(client, "forStore", {
4889
+ enumerable: true,
4890
+ configurable: false,
4891
+ writable: false,
4892
+ value: (storeId) => createStorefront({
4893
+ ...scopedConfig,
4894
+ storeId,
4895
+ market: client.getMarket(),
4896
+ locale: client.getLocale()
4897
+ })
4898
+ });
4899
+ return client;
4900
+ }
4133
4901
 
4134
4902
  export { COMMON_ACTION_KEYS, PaymentMethodType, SDK_VERSION, SUPPORTED_FRAMEWORKS, createAdmin, createCartController, createStorefront };
4135
4903
  //# sourceMappingURL=index.js.map