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