arky-sdk 0.7.78 → 0.7.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +227 -233
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +120 -102
- package/dist/index.d.ts +120 -102
- package/dist/index.js +227 -233
- package/dist/index.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +518 -521
- package/dist/types.d.ts +518 -521
- package/dist/types.js.map +1 -1
- package/dist/utils.cjs +2 -2
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +2 -2
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var nanostores = require('nanostores');
|
|
4
|
+
|
|
3
5
|
// src/types/index.ts
|
|
4
6
|
var PaymentMethodType = /* @__PURE__ */ ((PaymentMethodType2) => {
|
|
5
7
|
PaymentMethodType2["Cash"] = "cash";
|
|
@@ -26,7 +28,7 @@ function formatBlockValue(block) {
|
|
|
26
28
|
case "relationship_entry":
|
|
27
29
|
case "relationship_media":
|
|
28
30
|
if (value && typeof value === "object") {
|
|
29
|
-
return value.
|
|
31
|
+
return value.mime_type ? value.name || value.id : value.title || value.name || value.id;
|
|
30
32
|
}
|
|
31
33
|
return String(value);
|
|
32
34
|
default:
|
|
@@ -151,42 +153,26 @@ var COMMON_ACTIVITY_TYPES = [
|
|
|
151
153
|
"share",
|
|
152
154
|
"wishlist_added"
|
|
153
155
|
];
|
|
154
|
-
async function ensureCustomer(apiConfig) {
|
|
155
|
-
if (apiConfig.getToken) {
|
|
156
|
-
const tokens = await apiConfig.getToken();
|
|
157
|
-
if (tokens?.accessToken) return;
|
|
158
|
-
}
|
|
159
|
-
const response = await apiConfig.httpClient.post(
|
|
160
|
-
`/v1/storefront/${apiConfig.businessId}/customers/initialize`,
|
|
161
|
-
{
|
|
162
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0
|
|
163
|
-
}
|
|
164
|
-
);
|
|
165
|
-
const accessToken = response?.accessToken;
|
|
166
|
-
const refreshToken = response?.refreshToken;
|
|
167
|
-
const accessExpiresAt = response?.accessExpiresAt;
|
|
168
|
-
if (accessToken) {
|
|
169
|
-
apiConfig.setToken?.({ accessToken, refreshToken, accessExpiresAt });
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
156
|
var createActivityApi = (apiConfig) => ({
|
|
173
157
|
COMMON_ACTIVITY_TYPES,
|
|
174
158
|
async track(params) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
159
|
+
try {
|
|
160
|
+
await apiConfig.httpClient.post(
|
|
161
|
+
`/v1/storefront/${apiConfig.businessId}/activities/track`,
|
|
162
|
+
{ type: params.type, payload: params.payload }
|
|
163
|
+
);
|
|
164
|
+
} catch {
|
|
165
|
+
}
|
|
180
166
|
}
|
|
181
167
|
});
|
|
182
168
|
function groupCartToItems(cart) {
|
|
183
169
|
const groups = /* @__PURE__ */ new Map();
|
|
184
170
|
for (const slot of cart) {
|
|
185
|
-
const key = `${slot.
|
|
171
|
+
const key = `${slot.service_id}:${slot.provider_id}`;
|
|
186
172
|
if (!groups.has(key)) {
|
|
187
173
|
groups.set(key, {
|
|
188
|
-
|
|
189
|
-
|
|
174
|
+
service_id: slot.service_id,
|
|
175
|
+
provider_id: slot.provider_id,
|
|
190
176
|
slots: []
|
|
191
177
|
});
|
|
192
178
|
}
|
|
@@ -202,12 +188,6 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
202
188
|
getBusiness(options) {
|
|
203
189
|
return apiConfig.httpClient.get(base(), options);
|
|
204
190
|
},
|
|
205
|
-
getIntegrationConfig(params, options) {
|
|
206
|
-
return apiConfig.httpClient.get(
|
|
207
|
-
`${base(params.businessId)}/integrations/config/${params.type}`,
|
|
208
|
-
options
|
|
209
|
-
);
|
|
210
|
-
},
|
|
211
191
|
location: {
|
|
212
192
|
getCountries(options) {
|
|
213
193
|
return apiConfig.httpClient.get(`/v1/platform/countries`, options);
|
|
@@ -361,18 +341,18 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
361
341
|
getQuote(params, options) {
|
|
362
342
|
const businessId = params.businessId || apiConfig.businessId;
|
|
363
343
|
const { location, businessId: _businessId, ...rest } = params;
|
|
364
|
-
const
|
|
344
|
+
const shipping_address = location ? {
|
|
365
345
|
country: location.country || "",
|
|
366
346
|
state: location.state || "",
|
|
367
347
|
city: location.city || "",
|
|
368
|
-
|
|
348
|
+
postal_code: location.postal_code || "",
|
|
369
349
|
name: "",
|
|
370
350
|
street1: "",
|
|
371
351
|
street2: null
|
|
372
352
|
} : void 0;
|
|
373
353
|
return apiConfig.httpClient.post(
|
|
374
354
|
`${base(businessId)}/orders/quote`,
|
|
375
|
-
{ ...rest,
|
|
355
|
+
{ ...rest, shipping_address, market: apiConfig.market },
|
|
376
356
|
options
|
|
377
357
|
);
|
|
378
358
|
},
|
|
@@ -522,15 +502,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
522
502
|
const businessId = params?.businessId || apiConfig.businessId;
|
|
523
503
|
return apiConfig.httpClient.post(
|
|
524
504
|
`${base(businessId)}/customers/initialize`,
|
|
525
|
-
{ businessId },
|
|
526
|
-
options
|
|
527
|
-
);
|
|
528
|
-
},
|
|
529
|
-
signInAnonymously(params, options) {
|
|
530
|
-
const businessId = params?.businessId || apiConfig.businessId;
|
|
531
|
-
return apiConfig.httpClient.post(
|
|
532
|
-
`${base(businessId)}/customers/initialize`,
|
|
533
|
-
{ businessId },
|
|
505
|
+
{ business_id: businessId, market: params?.market || apiConfig.market },
|
|
534
506
|
options
|
|
535
507
|
);
|
|
536
508
|
},
|
|
@@ -562,7 +534,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
562
534
|
const businessId = params.businessId || apiConfig.businessId;
|
|
563
535
|
return apiConfig.httpClient.post(
|
|
564
536
|
`${base(businessId)}/customers/auth/refresh`,
|
|
565
|
-
{
|
|
537
|
+
{ refresh_token: params.refresh_token },
|
|
566
538
|
options
|
|
567
539
|
);
|
|
568
540
|
},
|
|
@@ -595,11 +567,11 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
595
567
|
return apiConfig.httpClient.post(
|
|
596
568
|
`${base()}/audiences/${params.id}/subscribe`,
|
|
597
569
|
{
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
570
|
+
customer_id: params.customer_id,
|
|
571
|
+
price_id: params.price_id,
|
|
572
|
+
success_url: params.success_url,
|
|
573
|
+
cancel_url: params.cancel_url,
|
|
574
|
+
confirm_url: params.confirm_url
|
|
603
575
|
},
|
|
604
576
|
options
|
|
605
577
|
);
|
|
@@ -646,7 +618,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
646
618
|
sendMessage(params, options) {
|
|
647
619
|
const businessId = params.businessId || apiConfig.businessId;
|
|
648
620
|
const body = { message: params.message };
|
|
649
|
-
if (params.
|
|
621
|
+
if (params.chat_id) body.chat_id = params.chat_id;
|
|
650
622
|
return apiConfig.httpClient.post(
|
|
651
623
|
`${base(businessId)}/agents/${params.id}/chats/messages`,
|
|
652
624
|
body,
|
|
@@ -656,7 +628,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
656
628
|
getChat(params, options) {
|
|
657
629
|
const businessId = params.businessId || apiConfig.businessId;
|
|
658
630
|
return apiConfig.httpClient.get(
|
|
659
|
-
`${base(businessId)}/agents/${params.id}/chats/${params.
|
|
631
|
+
`${base(businessId)}/agents/${params.id}/chats/${params.chat_id}`,
|
|
660
632
|
options
|
|
661
633
|
);
|
|
662
634
|
},
|
|
@@ -665,7 +637,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
665
637
|
const queryParams = {};
|
|
666
638
|
if (params.limit) queryParams.limit = String(params.limit);
|
|
667
639
|
return apiConfig.httpClient.get(
|
|
668
|
-
`${base(businessId)}/agents/${params.id}/chats/${params.
|
|
640
|
+
`${base(businessId)}/agents/${params.id}/chats/${params.chat_id}/messages`,
|
|
669
641
|
{
|
|
670
642
|
...options,
|
|
671
643
|
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
@@ -677,7 +649,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
677
649
|
const body = { rating: params.rating };
|
|
678
650
|
if (params.comment) body.comment = params.comment;
|
|
679
651
|
return apiConfig.httpClient.post(
|
|
680
|
-
`${base(businessId)}/agents/${params.id}/chats/${params.
|
|
652
|
+
`${base(businessId)}/agents/${params.id}/chats/${params.chat_id}/rate`,
|
|
681
653
|
body,
|
|
682
654
|
options
|
|
683
655
|
);
|
|
@@ -731,19 +703,19 @@ var STORAGE_KEYS = {
|
|
|
731
703
|
accessExpiresAt: "arky_expires_at"
|
|
732
704
|
};
|
|
733
705
|
function defaultGetToken() {
|
|
734
|
-
if (typeof window === "undefined") return {
|
|
706
|
+
if (typeof window === "undefined") return { access_token: "" };
|
|
735
707
|
return {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
708
|
+
access_token: localStorage.getItem(STORAGE_KEYS.accessToken) || "",
|
|
709
|
+
refresh_token: localStorage.getItem(STORAGE_KEYS.refreshToken) || "",
|
|
710
|
+
access_expires_at: parseInt(localStorage.getItem(STORAGE_KEYS.accessExpiresAt) || "0", 10)
|
|
739
711
|
};
|
|
740
712
|
}
|
|
741
713
|
function defaultSetToken(tokens) {
|
|
742
714
|
if (typeof window === "undefined") return;
|
|
743
|
-
if (tokens.
|
|
744
|
-
localStorage.setItem(STORAGE_KEYS.accessToken, tokens.
|
|
745
|
-
localStorage.setItem(STORAGE_KEYS.refreshToken, tokens.
|
|
746
|
-
localStorage.setItem(STORAGE_KEYS.accessExpiresAt, (tokens.
|
|
715
|
+
if (tokens.access_token) {
|
|
716
|
+
localStorage.setItem(STORAGE_KEYS.accessToken, tokens.access_token);
|
|
717
|
+
localStorage.setItem(STORAGE_KEYS.refreshToken, tokens.refresh_token || "");
|
|
718
|
+
localStorage.setItem(STORAGE_KEYS.accessExpiresAt, (tokens.access_expires_at || 0).toString());
|
|
747
719
|
} else {
|
|
748
720
|
Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
|
|
749
721
|
}
|
|
@@ -768,8 +740,8 @@ function createHttpClient(cfg) {
|
|
|
768
740
|
return refreshPromise;
|
|
769
741
|
}
|
|
770
742
|
refreshPromise = (async () => {
|
|
771
|
-
const {
|
|
772
|
-
if (!
|
|
743
|
+
const { refresh_token } = await getToken();
|
|
744
|
+
if (!refresh_token) {
|
|
773
745
|
logout();
|
|
774
746
|
const err = new Error("No refresh token available");
|
|
775
747
|
err.name = "ApiError";
|
|
@@ -779,7 +751,7 @@ function createHttpClient(cfg) {
|
|
|
779
751
|
const refRes = await fetch(refreshEndpoint, {
|
|
780
752
|
method: "POST",
|
|
781
753
|
headers: { Accept: "application/json", "Content-Type": "application/json" },
|
|
782
|
-
body: JSON.stringify({
|
|
754
|
+
body: JSON.stringify({ refresh_token })
|
|
783
755
|
});
|
|
784
756
|
if (!refRes.ok) {
|
|
785
757
|
logout();
|
|
@@ -804,15 +776,15 @@ function createHttpClient(cfg) {
|
|
|
804
776
|
"Content-Type": "application/json",
|
|
805
777
|
...options?.headers || {}
|
|
806
778
|
};
|
|
807
|
-
let {
|
|
779
|
+
let { access_token, access_expires_at } = await getToken();
|
|
808
780
|
const nowSec = Date.now() / 1e3;
|
|
809
|
-
if (
|
|
781
|
+
if (access_expires_at && nowSec > access_expires_at) {
|
|
810
782
|
await ensureFreshToken();
|
|
811
783
|
const tokens = await getToken();
|
|
812
|
-
|
|
784
|
+
access_token = tokens.access_token;
|
|
813
785
|
}
|
|
814
|
-
if (
|
|
815
|
-
headers["Authorization"] = `Bearer ${
|
|
786
|
+
if (access_token) {
|
|
787
|
+
headers["Authorization"] = `Bearer ${access_token}`;
|
|
816
788
|
}
|
|
817
789
|
const finalPath = options?.params ? path + buildQueryString(options.params) : path;
|
|
818
790
|
const fetchOpts = { method, headers };
|
|
@@ -842,7 +814,7 @@ function createHttpClient(cfg) {
|
|
|
842
814
|
try {
|
|
843
815
|
await ensureFreshToken();
|
|
844
816
|
const tokens = await getToken();
|
|
845
|
-
headers["Authorization"] = `Bearer ${tokens.
|
|
817
|
+
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
846
818
|
fetchOpts.headers = headers;
|
|
847
819
|
return request(method, path, body, { ...options, _retried: true });
|
|
848
820
|
} catch (refreshError) {
|
|
@@ -927,9 +899,9 @@ var createAccountApi = (apiConfig) => {
|
|
|
927
899
|
return {
|
|
928
900
|
async updateAccount(params, options) {
|
|
929
901
|
const payload = {};
|
|
930
|
-
if (params.
|
|
902
|
+
if (params.phone_numbers !== void 0) payload.phone_numbers = params.phone_numbers;
|
|
931
903
|
if (params.addresses !== void 0) payload.addresses = params.addresses;
|
|
932
|
-
if (params.
|
|
904
|
+
if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
|
|
933
905
|
return apiConfig.httpClient.put("/v1/accounts", payload, options);
|
|
934
906
|
},
|
|
935
907
|
async deleteAccount(params, options) {
|
|
@@ -958,8 +930,8 @@ var createAuthApi = (apiConfig) => {
|
|
|
958
930
|
},
|
|
959
931
|
async verify(params, options) {
|
|
960
932
|
const result = await apiConfig.httpClient.post("/v1/auth/verify", params, options);
|
|
961
|
-
if (result?.
|
|
962
|
-
apiConfig.setToken({ ...result, email: params.email,
|
|
933
|
+
if (result?.access_token) {
|
|
934
|
+
apiConfig.setToken({ ...result, email: params.email, is_verified: true });
|
|
963
935
|
}
|
|
964
936
|
return result;
|
|
965
937
|
},
|
|
@@ -971,8 +943,8 @@ var createAuthApi = (apiConfig) => {
|
|
|
971
943
|
},
|
|
972
944
|
async businessVerify(businessId, params, options) {
|
|
973
945
|
const result = await apiConfig.httpClient.post(`/v1/businesses/${businessId}/auth/verify`, params, options);
|
|
974
|
-
if (result?.
|
|
975
|
-
apiConfig.setToken({ ...result, email: params.email,
|
|
946
|
+
if (result?.access_token) {
|
|
947
|
+
apiConfig.setToken({ ...result, email: params.email, is_verified: true });
|
|
976
948
|
}
|
|
977
949
|
return result;
|
|
978
950
|
},
|
|
@@ -1039,7 +1011,7 @@ var createBusinessApi = (apiConfig) => {
|
|
|
1039
1011
|
},
|
|
1040
1012
|
async removeMember(params, options) {
|
|
1041
1013
|
return apiConfig.httpClient.delete(
|
|
1042
|
-
`/v1/businesses/${apiConfig.businessId}/members/${params.
|
|
1014
|
+
`/v1/businesses/${apiConfig.businessId}/members/${params.account_id}`,
|
|
1043
1015
|
options
|
|
1044
1016
|
);
|
|
1045
1017
|
},
|
|
@@ -1064,9 +1036,9 @@ var createBusinessApi = (apiConfig) => {
|
|
|
1064
1036
|
if (params.cursor) queryParams.cursor = params.cursor;
|
|
1065
1037
|
if (params.ids && params.ids.length > 0) queryParams.ids = params.ids.join(",");
|
|
1066
1038
|
if (params.query) queryParams.query = params.query;
|
|
1067
|
-
if (params.
|
|
1068
|
-
if (params.
|
|
1069
|
-
if (params.
|
|
1039
|
+
if (params.mime_type) queryParams.mime_type = params.mime_type;
|
|
1040
|
+
if (params.sort_field) queryParams.sort_field = params.sort_field;
|
|
1041
|
+
if (params.sort_direction) queryParams.sort_direction = params.sort_direction;
|
|
1070
1042
|
return apiConfig.httpClient.get(`/v1/businesses/${params.id}/media`, {
|
|
1071
1043
|
...options,
|
|
1072
1044
|
params: queryParams
|
|
@@ -1075,7 +1047,7 @@ var createBusinessApi = (apiConfig) => {
|
|
|
1075
1047
|
async oauthConnect(params, options) {
|
|
1076
1048
|
return apiConfig.httpClient.post(
|
|
1077
1049
|
`/v1/businesses/${params.businessId}/oauth/connect`,
|
|
1078
|
-
{ provider: params.provider, code: params.code,
|
|
1050
|
+
{ provider: params.provider, code: params.code, redirect_uri: params.redirect_uri },
|
|
1079
1051
|
options
|
|
1080
1052
|
);
|
|
1081
1053
|
},
|
|
@@ -1173,7 +1145,7 @@ var createMediaApi = (apiConfig) => {
|
|
|
1173
1145
|
method: "POST",
|
|
1174
1146
|
body: formData,
|
|
1175
1147
|
headers: {
|
|
1176
|
-
Authorization: `Bearer ${tokens.
|
|
1148
|
+
Authorization: `Bearer ${tokens.access_token}`
|
|
1177
1149
|
}
|
|
1178
1150
|
});
|
|
1179
1151
|
if (!response.ok) {
|
|
@@ -1189,21 +1161,21 @@ var createMediaApi = (apiConfig) => {
|
|
|
1189
1161
|
);
|
|
1190
1162
|
},
|
|
1191
1163
|
async getBusinessMedia(params, options) {
|
|
1192
|
-
const { businessId, cursor, limit, ids, query,
|
|
1164
|
+
const { businessId, cursor, limit, ids, query, mime_type, sort_field, sort_direction } = params;
|
|
1193
1165
|
const targetBusinessId = businessId || apiConfig.businessId;
|
|
1194
1166
|
const url = `${apiConfig.baseUrl}/v1/businesses/${targetBusinessId}/media`;
|
|
1195
1167
|
const queryParams = { limit: String(limit) };
|
|
1196
1168
|
if (cursor) queryParams.cursor = cursor;
|
|
1197
1169
|
if (ids && ids.length > 0) queryParams.ids = ids.join(",");
|
|
1198
1170
|
if (query) queryParams.query = query;
|
|
1199
|
-
if (
|
|
1200
|
-
if (
|
|
1201
|
-
if (
|
|
1171
|
+
if (mime_type) queryParams.mime_type = mime_type;
|
|
1172
|
+
if (sort_field) queryParams.sort_field = sort_field;
|
|
1173
|
+
if (sort_direction) queryParams.sort_direction = sort_direction;
|
|
1202
1174
|
const queryString = new URLSearchParams(queryParams).toString();
|
|
1203
1175
|
const tokens = await apiConfig.getToken();
|
|
1204
1176
|
const response = await fetch(`${url}?${queryString}`, {
|
|
1205
1177
|
headers: {
|
|
1206
|
-
Authorization: `Bearer ${tokens.
|
|
1178
|
+
Authorization: `Bearer ${tokens.access_token}`
|
|
1207
1179
|
}
|
|
1208
1180
|
});
|
|
1209
1181
|
if (!response.ok) {
|
|
@@ -1229,7 +1201,7 @@ var createNotificationApi = (apiConfig) => {
|
|
|
1229
1201
|
return {
|
|
1230
1202
|
async trackEmailOpen(params, options) {
|
|
1231
1203
|
return apiConfig.httpClient.get(
|
|
1232
|
-
`/v1/notifications/track/pixel/${params.
|
|
1204
|
+
`/v1/notifications/track/pixel/${params.tracking_pixel_id}`,
|
|
1233
1205
|
options
|
|
1234
1206
|
);
|
|
1235
1207
|
},
|
|
@@ -1441,18 +1413,18 @@ var createEshopApi = (apiConfig) => {
|
|
|
1441
1413
|
},
|
|
1442
1414
|
async getQuote(params, options) {
|
|
1443
1415
|
const { location, ...rest } = params;
|
|
1444
|
-
const
|
|
1416
|
+
const shipping_address = location ? {
|
|
1445
1417
|
country: location.country || "",
|
|
1446
1418
|
state: location.state || "",
|
|
1447
1419
|
city: location.city || "",
|
|
1448
|
-
|
|
1420
|
+
postal_code: location.postal_code || "",
|
|
1449
1421
|
name: "",
|
|
1450
1422
|
street1: "",
|
|
1451
1423
|
street2: null
|
|
1452
1424
|
} : void 0;
|
|
1453
1425
|
return apiConfig.httpClient.post(
|
|
1454
1426
|
`/v1/businesses/${apiConfig.businessId}/orders/quote`,
|
|
1455
|
-
{ ...rest,
|
|
1427
|
+
{ ...rest, shipping_address, market: apiConfig.market },
|
|
1456
1428
|
options
|
|
1457
1429
|
);
|
|
1458
1430
|
},
|
|
@@ -1644,10 +1616,10 @@ var createBookingApi = (apiConfig) => {
|
|
|
1644
1616
|
);
|
|
1645
1617
|
},
|
|
1646
1618
|
async cancelBookingItem(params, options) {
|
|
1647
|
-
const { businessId,
|
|
1619
|
+
const { businessId, booking_id, item_id, ...payload } = params;
|
|
1648
1620
|
const targetBusinessId = businessId || apiConfig.businessId;
|
|
1649
1621
|
return apiConfig.httpClient.post(
|
|
1650
|
-
`/v1/businesses/${targetBusinessId}/bookings/${
|
|
1622
|
+
`/v1/businesses/${targetBusinessId}/bookings/${booking_id}/items/${item_id}/cancel`,
|
|
1651
1623
|
payload,
|
|
1652
1624
|
options
|
|
1653
1625
|
);
|
|
@@ -1777,41 +1749,13 @@ var createMarketApi = (apiConfig) => {
|
|
|
1777
1749
|
var createActivityAdminApi = (apiConfig) => ({
|
|
1778
1750
|
async timeline(params, options) {
|
|
1779
1751
|
const businessId = params.businessId || apiConfig.businessId;
|
|
1780
|
-
const queryParams = {
|
|
1752
|
+
const queryParams = { customer_id: params.customer_id };
|
|
1781
1753
|
if (params.limit !== void 0) queryParams.limit = params.limit;
|
|
1782
1754
|
if (params.cursor) queryParams.cursor = params.cursor;
|
|
1783
1755
|
return apiConfig.httpClient.get(
|
|
1784
1756
|
`/v1/businesses/${businessId}/activities/timeline`,
|
|
1785
1757
|
{ ...options, params: queryParams }
|
|
1786
1758
|
);
|
|
1787
|
-
},
|
|
1788
|
-
async count(params, options) {
|
|
1789
|
-
const businessId = params.businessId || apiConfig.businessId;
|
|
1790
|
-
const queryParams = {};
|
|
1791
|
-
if (params.type) queryParams.type = params.type;
|
|
1792
|
-
if (params.payloadKey) queryParams.payloadKey = params.payloadKey;
|
|
1793
|
-
if (params.payloadValue) queryParams.payloadValue = params.payloadValue;
|
|
1794
|
-
if (params.windowSeconds !== void 0) queryParams.windowSeconds = params.windowSeconds;
|
|
1795
|
-
return apiConfig.httpClient.get(
|
|
1796
|
-
`/v1/businesses/${businessId}/activities/count`,
|
|
1797
|
-
{ ...options, params: queryParams }
|
|
1798
|
-
);
|
|
1799
|
-
},
|
|
1800
|
-
async types(params, options) {
|
|
1801
|
-
const businessId = params?.businessId || apiConfig.businessId;
|
|
1802
|
-
return apiConfig.httpClient.get(
|
|
1803
|
-
`/v1/businesses/${businessId}/activities/types`,
|
|
1804
|
-
options
|
|
1805
|
-
);
|
|
1806
|
-
},
|
|
1807
|
-
async countryBreakdown(params, options) {
|
|
1808
|
-
const businessId = params?.businessId || apiConfig.businessId;
|
|
1809
|
-
const queryParams = {};
|
|
1810
|
-
if (params?.windowSeconds !== void 0) queryParams.windowSeconds = params.windowSeconds;
|
|
1811
|
-
return apiConfig.httpClient.get(
|
|
1812
|
-
`/v1/businesses/${businessId}/activities/country-breakdown`,
|
|
1813
|
-
{ ...options, params: queryParams }
|
|
1814
|
-
);
|
|
1815
1759
|
}
|
|
1816
1760
|
});
|
|
1817
1761
|
var createCustomerApi = (apiConfig) => {
|
|
@@ -1835,8 +1779,8 @@ var createCustomerApi = (apiConfig) => {
|
|
|
1835
1779
|
if (params?.limit !== void 0) queryParams.limit = params.limit;
|
|
1836
1780
|
if (params?.cursor) queryParams.cursor = params.cursor;
|
|
1837
1781
|
if (params?.query) queryParams.query = params.query;
|
|
1838
|
-
if (params?.
|
|
1839
|
-
if (params?.
|
|
1782
|
+
if (params?.sort_field) queryParams.sort_field = params.sort_field;
|
|
1783
|
+
if (params?.sort_direction) queryParams.sort_direction = params.sort_direction;
|
|
1840
1784
|
return apiConfig.httpClient.get(
|
|
1841
1785
|
`/v1/businesses/${businessId}/customers`,
|
|
1842
1786
|
{
|
|
@@ -1856,8 +1800,8 @@ var createCustomerApi = (apiConfig) => {
|
|
|
1856
1800
|
async merge(params, options) {
|
|
1857
1801
|
const businessId = params.businessId || apiConfig.businessId;
|
|
1858
1802
|
return apiConfig.httpClient.post(
|
|
1859
|
-
`/v1/businesses/${businessId}/customers/${params.
|
|
1860
|
-
{
|
|
1803
|
+
`/v1/businesses/${businessId}/customers/${params.target_id}/merge`,
|
|
1804
|
+
{ source_id: params.source_id, businessId },
|
|
1861
1805
|
options
|
|
1862
1806
|
);
|
|
1863
1807
|
},
|
|
@@ -1922,13 +1866,13 @@ var createCustomerApi = (apiConfig) => {
|
|
|
1922
1866
|
async addSubscriber(params, options) {
|
|
1923
1867
|
return apiConfig.httpClient.post(
|
|
1924
1868
|
`/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers`,
|
|
1925
|
-
{
|
|
1869
|
+
{ customer_id: params.customer_id },
|
|
1926
1870
|
options
|
|
1927
1871
|
);
|
|
1928
1872
|
},
|
|
1929
1873
|
async removeSubscriber(params, options) {
|
|
1930
1874
|
return apiConfig.httpClient.delete(
|
|
1931
|
-
`/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers/${params.
|
|
1875
|
+
`/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers/${params.customer_id}`,
|
|
1932
1876
|
options
|
|
1933
1877
|
);
|
|
1934
1878
|
}
|
|
@@ -1981,9 +1925,9 @@ var createWorkflowApi = (apiConfig) => {
|
|
|
1981
1925
|
},
|
|
1982
1926
|
async getWorkflowExecutions(params, options) {
|
|
1983
1927
|
const businessId = params.businessId || apiConfig.businessId;
|
|
1984
|
-
const { businessId: _,
|
|
1928
|
+
const { businessId: _, workflow_id, ...queryParams } = params;
|
|
1985
1929
|
return apiConfig.httpClient.get(
|
|
1986
|
-
`/v1/businesses/${businessId}/workflows/${
|
|
1930
|
+
`/v1/businesses/${businessId}/workflows/${workflow_id}/executions`,
|
|
1987
1931
|
{
|
|
1988
1932
|
...options,
|
|
1989
1933
|
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
@@ -1993,7 +1937,7 @@ var createWorkflowApi = (apiConfig) => {
|
|
|
1993
1937
|
async getWorkflowExecution(params, options) {
|
|
1994
1938
|
const businessId = params.businessId || apiConfig.businessId;
|
|
1995
1939
|
return apiConfig.httpClient.get(
|
|
1996
|
-
`/v1/businesses/${businessId}/workflows/${params.
|
|
1940
|
+
`/v1/businesses/${businessId}/workflows/${params.workflow_id}/executions/${params.execution_id}`,
|
|
1997
1941
|
options
|
|
1998
1942
|
);
|
|
1999
1943
|
}
|
|
@@ -2019,17 +1963,17 @@ var createPlatformApi = (apiConfig) => {
|
|
|
2019
1963
|
var createShippingApi = (apiConfig) => {
|
|
2020
1964
|
return {
|
|
2021
1965
|
async getRates(params, options) {
|
|
2022
|
-
const {
|
|
1966
|
+
const { order_id, ...payload } = params;
|
|
2023
1967
|
return apiConfig.httpClient.post(
|
|
2024
|
-
`/v1/businesses/${apiConfig.businessId}/orders/${
|
|
1968
|
+
`/v1/businesses/${apiConfig.businessId}/orders/${order_id}/shipping/rates`,
|
|
2025
1969
|
payload,
|
|
2026
1970
|
options
|
|
2027
1971
|
);
|
|
2028
1972
|
},
|
|
2029
1973
|
async ship(params, options) {
|
|
2030
|
-
const {
|
|
1974
|
+
const { order_id, ...payload } = params;
|
|
2031
1975
|
return apiConfig.httpClient.post(
|
|
2032
|
-
`/v1/businesses/${apiConfig.businessId}/orders/${
|
|
1976
|
+
`/v1/businesses/${apiConfig.businessId}/orders/${order_id}/ship`,
|
|
2033
1977
|
payload,
|
|
2034
1978
|
options
|
|
2035
1979
|
);
|
|
@@ -2077,7 +2021,7 @@ var createAgentApi = (apiConfig) => {
|
|
|
2077
2021
|
},
|
|
2078
2022
|
async sendMessage(params, options) {
|
|
2079
2023
|
const body = { message: params.message };
|
|
2080
|
-
if (params.
|
|
2024
|
+
if (params.chat_id) body.chat_id = params.chat_id;
|
|
2081
2025
|
if (params.direct) body.direct = params.direct;
|
|
2082
2026
|
return apiConfig.httpClient.post(
|
|
2083
2027
|
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/messages`,
|
|
@@ -2099,13 +2043,13 @@ var createAgentApi = (apiConfig) => {
|
|
|
2099
2043
|
},
|
|
2100
2044
|
async getChat(params, options) {
|
|
2101
2045
|
return apiConfig.httpClient.get(
|
|
2102
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2046
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}`,
|
|
2103
2047
|
options
|
|
2104
2048
|
);
|
|
2105
2049
|
},
|
|
2106
2050
|
async updateChat(params, options) {
|
|
2107
2051
|
return apiConfig.httpClient.put(
|
|
2108
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2052
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}`,
|
|
2109
2053
|
{ status: params.status },
|
|
2110
2054
|
options
|
|
2111
2055
|
);
|
|
@@ -2114,7 +2058,7 @@ var createAgentApi = (apiConfig) => {
|
|
|
2114
2058
|
const body = { rating: params.rating };
|
|
2115
2059
|
if (params.comment) body.comment = params.comment;
|
|
2116
2060
|
return apiConfig.httpClient.post(
|
|
2117
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2061
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}/rate`,
|
|
2118
2062
|
body,
|
|
2119
2063
|
options
|
|
2120
2064
|
);
|
|
@@ -2131,7 +2075,7 @@ var createAgentApi = (apiConfig) => {
|
|
|
2131
2075
|
const queryParams = {};
|
|
2132
2076
|
if (params.limit) queryParams.limit = String(params.limit);
|
|
2133
2077
|
return apiConfig.httpClient.get(
|
|
2134
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2078
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}/messages`,
|
|
2135
2079
|
{
|
|
2136
2080
|
...options,
|
|
2137
2081
|
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
@@ -2359,22 +2303,12 @@ var createTaxonomyApi = (apiConfig) => {
|
|
|
2359
2303
|
// src/api/analytics.ts
|
|
2360
2304
|
var createAnalyticsApi = (apiConfig) => {
|
|
2361
2305
|
return {
|
|
2362
|
-
async
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
{
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
}
|
|
2369
|
-
);
|
|
2370
|
-
},
|
|
2371
|
-
async getStatusBreakdown(params, options) {
|
|
2372
|
-
return apiConfig.httpClient.get(
|
|
2373
|
-
`/v1/businesses/${apiConfig.businessId}/analytics/status`,
|
|
2374
|
-
{
|
|
2375
|
-
...options,
|
|
2376
|
-
params
|
|
2377
|
-
}
|
|
2306
|
+
async query(spec, options) {
|
|
2307
|
+
const businessId = options?.businessId || apiConfig.businessId;
|
|
2308
|
+
return apiConfig.httpClient.post(
|
|
2309
|
+
`/v1/businesses/${businessId}/analytics/query`,
|
|
2310
|
+
spec,
|
|
2311
|
+
options
|
|
2378
2312
|
);
|
|
2379
2313
|
}
|
|
2380
2314
|
};
|
|
@@ -2454,6 +2388,57 @@ function validatePhoneNumber(phone) {
|
|
|
2454
2388
|
}
|
|
2455
2389
|
return { isValid: true };
|
|
2456
2390
|
}
|
|
2391
|
+
function createStores() {
|
|
2392
|
+
const $business = nanostores.atom(null);
|
|
2393
|
+
const $market = nanostores.atom(null);
|
|
2394
|
+
const $loading = nanostores.atom(false);
|
|
2395
|
+
const $error = nanostores.atom(null);
|
|
2396
|
+
const $initialized = nanostores.atom(false);
|
|
2397
|
+
const $currency = nanostores.computed($market, (m) => m?.currency);
|
|
2398
|
+
const $currencySymbol = nanostores.computed($market, (m) => {
|
|
2399
|
+
if (!m?.currency) return void 0;
|
|
2400
|
+
return new Intl.NumberFormat("en", {
|
|
2401
|
+
style: "currency",
|
|
2402
|
+
currency: m.currency.toUpperCase(),
|
|
2403
|
+
currencyDisplay: "narrowSymbol"
|
|
2404
|
+
}).formatToParts(0).find((p) => p.type === "currency")?.value || m.currency.toUpperCase();
|
|
2405
|
+
});
|
|
2406
|
+
const $paymentMethods = nanostores.computed(
|
|
2407
|
+
$market,
|
|
2408
|
+
(m) => (m?.payment_methods || []).map((pm) => pm.id)
|
|
2409
|
+
);
|
|
2410
|
+
const $paymentMethodObjects = nanostores.computed(
|
|
2411
|
+
$market,
|
|
2412
|
+
(m) => m?.payment_methods || []
|
|
2413
|
+
);
|
|
2414
|
+
const $paymentConfig = nanostores.computed([$business, $paymentMethods], (biz, methods) => {
|
|
2415
|
+
const payment = biz?.payment || null;
|
|
2416
|
+
const hasCreditCard = methods.includes("credit_card");
|
|
2417
|
+
return {
|
|
2418
|
+
provider: payment,
|
|
2419
|
+
enabled: hasCreditCard && !!payment
|
|
2420
|
+
};
|
|
2421
|
+
});
|
|
2422
|
+
const $zones = nanostores.computed($market, (m) => m?.zones || []);
|
|
2423
|
+
return {
|
|
2424
|
+
business: $business,
|
|
2425
|
+
market: $market,
|
|
2426
|
+
loading: $loading,
|
|
2427
|
+
error: $error,
|
|
2428
|
+
initialized: $initialized,
|
|
2429
|
+
currency: $currency,
|
|
2430
|
+
currencySymbol: $currencySymbol,
|
|
2431
|
+
paymentMethods: $paymentMethods,
|
|
2432
|
+
paymentMethodObjects: $paymentMethodObjects,
|
|
2433
|
+
paymentConfig: $paymentConfig,
|
|
2434
|
+
zones: $zones
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
function populateStores(stores, data) {
|
|
2438
|
+
stores.business.set(data.business);
|
|
2439
|
+
stores.market.set(data.market);
|
|
2440
|
+
stores.initialized.set(true);
|
|
2441
|
+
}
|
|
2457
2442
|
|
|
2458
2443
|
// src/utils/timezone.ts
|
|
2459
2444
|
var tzGroups = [
|
|
@@ -2607,28 +2592,6 @@ function nameToKey(name) {
|
|
|
2607
2592
|
return toKey(name);
|
|
2608
2593
|
}
|
|
2609
2594
|
|
|
2610
|
-
// src/utils/analytics.ts
|
|
2611
|
-
function injectGA4Script(measurementId) {
|
|
2612
|
-
if (typeof window === "undefined") return;
|
|
2613
|
-
if (document.querySelector(`script[src*="${measurementId}"]`)) return;
|
|
2614
|
-
window.dataLayer = window.dataLayer || [];
|
|
2615
|
-
window.gtag = function gtag(...args) {
|
|
2616
|
-
window.dataLayer.push(args);
|
|
2617
|
-
};
|
|
2618
|
-
window.gtag("js", /* @__PURE__ */ new Date());
|
|
2619
|
-
window.gtag("config", measurementId);
|
|
2620
|
-
const script = document.createElement("script");
|
|
2621
|
-
script.async = true;
|
|
2622
|
-
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
|
|
2623
|
-
document.head.appendChild(script);
|
|
2624
|
-
}
|
|
2625
|
-
function track(eventName, params) {
|
|
2626
|
-
if (typeof window === "undefined") return;
|
|
2627
|
-
if (window.gtag) {
|
|
2628
|
-
window.gtag("event", eventName, params);
|
|
2629
|
-
}
|
|
2630
|
-
}
|
|
2631
|
-
|
|
2632
2595
|
// src/utils/inventory.ts
|
|
2633
2596
|
function getAvailableStock(variant) {
|
|
2634
2597
|
if (!variant?.inventory) return 0;
|
|
@@ -2642,15 +2605,15 @@ function hasStock(variant, quantity = 1) {
|
|
|
2642
2605
|
return getAvailableStock(variant) >= quantity;
|
|
2643
2606
|
}
|
|
2644
2607
|
function getInventoryAt(variant, locationId) {
|
|
2645
|
-
return variant?.inventory?.find((inv) => inv.
|
|
2608
|
+
return variant?.inventory?.find((inv) => inv.location_id === locationId);
|
|
2646
2609
|
}
|
|
2647
2610
|
function getFirstAvailableFCId(variant, quantity = 1) {
|
|
2648
2611
|
const inv = variant?.inventory?.find((i) => i.available >= quantity);
|
|
2649
|
-
return inv?.
|
|
2612
|
+
return inv?.location_id;
|
|
2650
2613
|
}
|
|
2651
2614
|
|
|
2652
2615
|
// src/index.ts
|
|
2653
|
-
var SDK_VERSION = "0.7.
|
|
2616
|
+
var SDK_VERSION = "0.7.84";
|
|
2654
2617
|
var SUPPORTED_FRAMEWORKS = [
|
|
2655
2618
|
"astro",
|
|
2656
2619
|
"react",
|
|
@@ -2690,7 +2653,6 @@ function createUtilitySurface(apiConfig) {
|
|
|
2690
2653
|
validateKey,
|
|
2691
2654
|
toKey,
|
|
2692
2655
|
nameToKey,
|
|
2693
|
-
track,
|
|
2694
2656
|
getAvailableStock,
|
|
2695
2657
|
getReservedStock,
|
|
2696
2658
|
hasStock,
|
|
@@ -2718,17 +2680,6 @@ async function createAdmin(config) {
|
|
|
2718
2680
|
const authApi = createAuthApi(apiConfig);
|
|
2719
2681
|
const businessApi = createBusinessApi(apiConfig);
|
|
2720
2682
|
const platformApi = createPlatformApi(apiConfig);
|
|
2721
|
-
if (typeof window !== "undefined" && apiConfig.businessId) {
|
|
2722
|
-
businessApi.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
|
|
2723
|
-
if (!configs) return;
|
|
2724
|
-
for (const c of Array.isArray(configs) ? configs : [configs]) {
|
|
2725
|
-
if (c.measurementId) {
|
|
2726
|
-
injectGA4Script(c.measurementId);
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
}).catch(() => {
|
|
2730
|
-
});
|
|
2731
|
-
}
|
|
2732
2683
|
const cmsApi = createCmsApi(apiConfig);
|
|
2733
2684
|
const eshopApi = createEshopApi(apiConfig);
|
|
2734
2685
|
const bookingApi = createBookingApi(apiConfig);
|
|
@@ -2887,9 +2838,7 @@ async function createAdmin(config) {
|
|
|
2887
2838
|
}
|
|
2888
2839
|
},
|
|
2889
2840
|
analytics: {
|
|
2890
|
-
|
|
2891
|
-
getSummary: analyticsApi.getSummary,
|
|
2892
|
-
getStatusBreakdown: analyticsApi.getStatusBreakdown
|
|
2841
|
+
query: analyticsApi.query
|
|
2893
2842
|
},
|
|
2894
2843
|
setBusinessId: (businessId) => {
|
|
2895
2844
|
apiConfig.businessId = businessId;
|
|
@@ -2911,8 +2860,35 @@ async function createAdmin(config) {
|
|
|
2911
2860
|
};
|
|
2912
2861
|
return sdk;
|
|
2913
2862
|
}
|
|
2914
|
-
|
|
2863
|
+
var SESSION_CACHE_TTL = 36e5;
|
|
2864
|
+
function getCachedSession(businessId) {
|
|
2865
|
+
if (typeof window === "undefined") return null;
|
|
2866
|
+
try {
|
|
2867
|
+
const raw = localStorage.getItem(`arky_session_${businessId}`);
|
|
2868
|
+
if (!raw) return null;
|
|
2869
|
+
const parsed = JSON.parse(raw);
|
|
2870
|
+
if (Date.now() - (parsed.timestamp || 0) > SESSION_CACHE_TTL) {
|
|
2871
|
+
localStorage.removeItem(`arky_session_${businessId}`);
|
|
2872
|
+
return null;
|
|
2873
|
+
}
|
|
2874
|
+
return { business: parsed.business, market: parsed.market };
|
|
2875
|
+
} catch {
|
|
2876
|
+
return null;
|
|
2877
|
+
}
|
|
2878
|
+
}
|
|
2879
|
+
function setCachedSession(businessId, data) {
|
|
2880
|
+
if (typeof window === "undefined") return;
|
|
2881
|
+
try {
|
|
2882
|
+
localStorage.setItem(
|
|
2883
|
+
`arky_session_${businessId}`,
|
|
2884
|
+
JSON.stringify({ ...data, timestamp: Date.now() })
|
|
2885
|
+
);
|
|
2886
|
+
} catch {
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
function createStorefront(config) {
|
|
2915
2890
|
const locale = config.locale || "en";
|
|
2891
|
+
const market = config.market || "";
|
|
2916
2892
|
const getToken = config.getToken || defaultGetToken;
|
|
2917
2893
|
const setToken = config.setToken || defaultSetToken;
|
|
2918
2894
|
const logout = config.logout || defaultLogout;
|
|
@@ -2928,44 +2904,67 @@ async function createStorefront(config) {
|
|
|
2928
2904
|
httpClient,
|
|
2929
2905
|
businessId: config.businessId,
|
|
2930
2906
|
baseUrl: config.baseUrl,
|
|
2931
|
-
market
|
|
2907
|
+
market,
|
|
2932
2908
|
locale,
|
|
2933
2909
|
setToken,
|
|
2934
2910
|
getToken
|
|
2935
2911
|
};
|
|
2936
2912
|
const storefrontApi = createStorefrontApi(apiConfig);
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
if (
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
const
|
|
2945
|
-
|
|
2946
|
-
|
|
2913
|
+
const stores = createStores();
|
|
2914
|
+
let initPromise = null;
|
|
2915
|
+
function init() {
|
|
2916
|
+
if (initPromise) return initPromise;
|
|
2917
|
+
initPromise = (async () => {
|
|
2918
|
+
stores.loading.set(true);
|
|
2919
|
+
stores.error.set(null);
|
|
2920
|
+
const cached = getCachedSession(config.businessId);
|
|
2921
|
+
const tokens = await getToken();
|
|
2922
|
+
const hasToken = !!tokens.access_token;
|
|
2923
|
+
if (hasToken && cached) {
|
|
2924
|
+
populateStores(stores, cached);
|
|
2925
|
+
stores.loading.set(false);
|
|
2926
|
+
return cached;
|
|
2947
2927
|
}
|
|
2948
|
-
|
|
2949
|
-
|
|
2928
|
+
if (hasToken) {
|
|
2929
|
+
const [business, allMarkets] = await Promise.all([
|
|
2930
|
+
storefrontApi.business.getBusiness(),
|
|
2931
|
+
storefrontApi.business.market.list().catch(() => [])
|
|
2932
|
+
]);
|
|
2933
|
+
const marketData = market ? allMarkets.find((m) => m.key === market) || null : null;
|
|
2934
|
+
const session2 = { business, market: marketData };
|
|
2935
|
+
populateStores(stores, session2);
|
|
2936
|
+
setCachedSession(config.businessId, session2);
|
|
2937
|
+
stores.loading.set(false);
|
|
2938
|
+
return session2;
|
|
2939
|
+
}
|
|
2940
|
+
const result = await storefrontApi.crm.customer.initialize({
|
|
2941
|
+
market
|
|
2942
|
+
});
|
|
2943
|
+
if (result?.token?.access_token) {
|
|
2944
|
+
setToken(result.token);
|
|
2945
|
+
}
|
|
2946
|
+
const session = {
|
|
2947
|
+
business: result.business,
|
|
2948
|
+
market: result.market
|
|
2949
|
+
};
|
|
2950
|
+
populateStores(stores, session);
|
|
2951
|
+
setCachedSession(config.businessId, session);
|
|
2952
|
+
stores.loading.set(false);
|
|
2953
|
+
return session;
|
|
2954
|
+
})().catch((err) => {
|
|
2955
|
+
stores.error.set(err.message || "Initialization failed");
|
|
2956
|
+
stores.loading.set(false);
|
|
2957
|
+
initPromise = null;
|
|
2958
|
+
throw err;
|
|
2950
2959
|
});
|
|
2951
|
-
return
|
|
2960
|
+
return initPromise;
|
|
2952
2961
|
}
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
});
|
|
2956
|
-
if (apiConfig.businessId) {
|
|
2957
|
-
storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
|
|
2958
|
-
if (!configs) return;
|
|
2959
|
-
for (const c of Array.isArray(configs) ? configs : [configs]) {
|
|
2960
|
-
if (c.measurementId) {
|
|
2961
|
-
injectGA4Script(c.measurementId);
|
|
2962
|
-
}
|
|
2963
|
-
}
|
|
2964
|
-
}).catch(() => {
|
|
2965
|
-
});
|
|
2966
|
-
}
|
|
2962
|
+
function setMarket(key) {
|
|
2963
|
+
apiConfig.market = key;
|
|
2967
2964
|
}
|
|
2968
2965
|
return {
|
|
2966
|
+
init,
|
|
2967
|
+
stores,
|
|
2969
2968
|
business: storefrontApi.business,
|
|
2970
2969
|
cms: storefrontApi.cms,
|
|
2971
2970
|
eshop: storefrontApi.eshop,
|
|
@@ -2973,16 +2972,11 @@ async function createStorefront(config) {
|
|
|
2973
2972
|
crm: storefrontApi.crm,
|
|
2974
2973
|
activity: storefrontApi.activity,
|
|
2975
2974
|
automation: storefrontApi.automation,
|
|
2976
|
-
analytics: {
|
|
2977
|
-
track
|
|
2978
|
-
},
|
|
2979
2975
|
setBusinessId: (businessId) => {
|
|
2980
2976
|
apiConfig.businessId = businessId;
|
|
2981
2977
|
},
|
|
2982
2978
|
getBusinessId: () => apiConfig.businessId,
|
|
2983
|
-
setMarket
|
|
2984
|
-
apiConfig.market = market;
|
|
2985
|
-
},
|
|
2979
|
+
setMarket,
|
|
2986
2980
|
getMarket: () => apiConfig.market,
|
|
2987
2981
|
setLocale: (locale2) => {
|
|
2988
2982
|
apiConfig.locale = locale2;
|