arky-sdk 0.7.80 → 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 +220 -187
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +76 -59
- package/dist/index.d.ts +76 -59
- package/dist/index.js +220 -187
- 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,7 +1749,7 @@ 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(
|
|
@@ -1807,8 +1779,8 @@ var createCustomerApi = (apiConfig) => {
|
|
|
1807
1779
|
if (params?.limit !== void 0) queryParams.limit = params.limit;
|
|
1808
1780
|
if (params?.cursor) queryParams.cursor = params.cursor;
|
|
1809
1781
|
if (params?.query) queryParams.query = params.query;
|
|
1810
|
-
if (params?.
|
|
1811
|
-
if (params?.
|
|
1782
|
+
if (params?.sort_field) queryParams.sort_field = params.sort_field;
|
|
1783
|
+
if (params?.sort_direction) queryParams.sort_direction = params.sort_direction;
|
|
1812
1784
|
return apiConfig.httpClient.get(
|
|
1813
1785
|
`/v1/businesses/${businessId}/customers`,
|
|
1814
1786
|
{
|
|
@@ -1828,8 +1800,8 @@ var createCustomerApi = (apiConfig) => {
|
|
|
1828
1800
|
async merge(params, options) {
|
|
1829
1801
|
const businessId = params.businessId || apiConfig.businessId;
|
|
1830
1802
|
return apiConfig.httpClient.post(
|
|
1831
|
-
`/v1/businesses/${businessId}/customers/${params.
|
|
1832
|
-
{
|
|
1803
|
+
`/v1/businesses/${businessId}/customers/${params.target_id}/merge`,
|
|
1804
|
+
{ source_id: params.source_id, businessId },
|
|
1833
1805
|
options
|
|
1834
1806
|
);
|
|
1835
1807
|
},
|
|
@@ -1894,13 +1866,13 @@ var createCustomerApi = (apiConfig) => {
|
|
|
1894
1866
|
async addSubscriber(params, options) {
|
|
1895
1867
|
return apiConfig.httpClient.post(
|
|
1896
1868
|
`/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers`,
|
|
1897
|
-
{
|
|
1869
|
+
{ customer_id: params.customer_id },
|
|
1898
1870
|
options
|
|
1899
1871
|
);
|
|
1900
1872
|
},
|
|
1901
1873
|
async removeSubscriber(params, options) {
|
|
1902
1874
|
return apiConfig.httpClient.delete(
|
|
1903
|
-
`/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers/${params.
|
|
1875
|
+
`/v1/businesses/${apiConfig.businessId}/audiences/${params.id}/subscribers/${params.customer_id}`,
|
|
1904
1876
|
options
|
|
1905
1877
|
);
|
|
1906
1878
|
}
|
|
@@ -1953,9 +1925,9 @@ var createWorkflowApi = (apiConfig) => {
|
|
|
1953
1925
|
},
|
|
1954
1926
|
async getWorkflowExecutions(params, options) {
|
|
1955
1927
|
const businessId = params.businessId || apiConfig.businessId;
|
|
1956
|
-
const { businessId: _,
|
|
1928
|
+
const { businessId: _, workflow_id, ...queryParams } = params;
|
|
1957
1929
|
return apiConfig.httpClient.get(
|
|
1958
|
-
`/v1/businesses/${businessId}/workflows/${
|
|
1930
|
+
`/v1/businesses/${businessId}/workflows/${workflow_id}/executions`,
|
|
1959
1931
|
{
|
|
1960
1932
|
...options,
|
|
1961
1933
|
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
@@ -1965,7 +1937,7 @@ var createWorkflowApi = (apiConfig) => {
|
|
|
1965
1937
|
async getWorkflowExecution(params, options) {
|
|
1966
1938
|
const businessId = params.businessId || apiConfig.businessId;
|
|
1967
1939
|
return apiConfig.httpClient.get(
|
|
1968
|
-
`/v1/businesses/${businessId}/workflows/${params.
|
|
1940
|
+
`/v1/businesses/${businessId}/workflows/${params.workflow_id}/executions/${params.execution_id}`,
|
|
1969
1941
|
options
|
|
1970
1942
|
);
|
|
1971
1943
|
}
|
|
@@ -1991,17 +1963,17 @@ var createPlatformApi = (apiConfig) => {
|
|
|
1991
1963
|
var createShippingApi = (apiConfig) => {
|
|
1992
1964
|
return {
|
|
1993
1965
|
async getRates(params, options) {
|
|
1994
|
-
const {
|
|
1966
|
+
const { order_id, ...payload } = params;
|
|
1995
1967
|
return apiConfig.httpClient.post(
|
|
1996
|
-
`/v1/businesses/${apiConfig.businessId}/orders/${
|
|
1968
|
+
`/v1/businesses/${apiConfig.businessId}/orders/${order_id}/shipping/rates`,
|
|
1997
1969
|
payload,
|
|
1998
1970
|
options
|
|
1999
1971
|
);
|
|
2000
1972
|
},
|
|
2001
1973
|
async ship(params, options) {
|
|
2002
|
-
const {
|
|
1974
|
+
const { order_id, ...payload } = params;
|
|
2003
1975
|
return apiConfig.httpClient.post(
|
|
2004
|
-
`/v1/businesses/${apiConfig.businessId}/orders/${
|
|
1976
|
+
`/v1/businesses/${apiConfig.businessId}/orders/${order_id}/ship`,
|
|
2005
1977
|
payload,
|
|
2006
1978
|
options
|
|
2007
1979
|
);
|
|
@@ -2049,7 +2021,7 @@ var createAgentApi = (apiConfig) => {
|
|
|
2049
2021
|
},
|
|
2050
2022
|
async sendMessage(params, options) {
|
|
2051
2023
|
const body = { message: params.message };
|
|
2052
|
-
if (params.
|
|
2024
|
+
if (params.chat_id) body.chat_id = params.chat_id;
|
|
2053
2025
|
if (params.direct) body.direct = params.direct;
|
|
2054
2026
|
return apiConfig.httpClient.post(
|
|
2055
2027
|
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/messages`,
|
|
@@ -2071,13 +2043,13 @@ var createAgentApi = (apiConfig) => {
|
|
|
2071
2043
|
},
|
|
2072
2044
|
async getChat(params, options) {
|
|
2073
2045
|
return apiConfig.httpClient.get(
|
|
2074
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2046
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}`,
|
|
2075
2047
|
options
|
|
2076
2048
|
);
|
|
2077
2049
|
},
|
|
2078
2050
|
async updateChat(params, options) {
|
|
2079
2051
|
return apiConfig.httpClient.put(
|
|
2080
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2052
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}`,
|
|
2081
2053
|
{ status: params.status },
|
|
2082
2054
|
options
|
|
2083
2055
|
);
|
|
@@ -2086,7 +2058,7 @@ var createAgentApi = (apiConfig) => {
|
|
|
2086
2058
|
const body = { rating: params.rating };
|
|
2087
2059
|
if (params.comment) body.comment = params.comment;
|
|
2088
2060
|
return apiConfig.httpClient.post(
|
|
2089
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2061
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}/rate`,
|
|
2090
2062
|
body,
|
|
2091
2063
|
options
|
|
2092
2064
|
);
|
|
@@ -2103,7 +2075,7 @@ var createAgentApi = (apiConfig) => {
|
|
|
2103
2075
|
const queryParams = {};
|
|
2104
2076
|
if (params.limit) queryParams.limit = String(params.limit);
|
|
2105
2077
|
return apiConfig.httpClient.get(
|
|
2106
|
-
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.
|
|
2078
|
+
`/v1/businesses/${apiConfig.businessId}/agents/${params.id}/chats/${params.chat_id}/messages`,
|
|
2107
2079
|
{
|
|
2108
2080
|
...options,
|
|
2109
2081
|
params: Object.keys(queryParams).length > 0 ? queryParams : void 0
|
|
@@ -2416,6 +2388,57 @@ function validatePhoneNumber(phone) {
|
|
|
2416
2388
|
}
|
|
2417
2389
|
return { isValid: true };
|
|
2418
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
|
+
}
|
|
2419
2442
|
|
|
2420
2443
|
// src/utils/timezone.ts
|
|
2421
2444
|
var tzGroups = [
|
|
@@ -2569,28 +2592,6 @@ function nameToKey(name) {
|
|
|
2569
2592
|
return toKey(name);
|
|
2570
2593
|
}
|
|
2571
2594
|
|
|
2572
|
-
// src/utils/analytics.ts
|
|
2573
|
-
function injectGA4Script(measurementId) {
|
|
2574
|
-
if (typeof window === "undefined") return;
|
|
2575
|
-
if (document.querySelector(`script[src*="${measurementId}"]`)) return;
|
|
2576
|
-
window.dataLayer = window.dataLayer || [];
|
|
2577
|
-
window.gtag = function gtag(...args) {
|
|
2578
|
-
window.dataLayer.push(args);
|
|
2579
|
-
};
|
|
2580
|
-
window.gtag("js", /* @__PURE__ */ new Date());
|
|
2581
|
-
window.gtag("config", measurementId);
|
|
2582
|
-
const script = document.createElement("script");
|
|
2583
|
-
script.async = true;
|
|
2584
|
-
script.src = `https://www.googletagmanager.com/gtag/js?id=${measurementId}`;
|
|
2585
|
-
document.head.appendChild(script);
|
|
2586
|
-
}
|
|
2587
|
-
function track(eventName, params) {
|
|
2588
|
-
if (typeof window === "undefined") return;
|
|
2589
|
-
if (window.gtag) {
|
|
2590
|
-
window.gtag("event", eventName, params);
|
|
2591
|
-
}
|
|
2592
|
-
}
|
|
2593
|
-
|
|
2594
2595
|
// src/utils/inventory.ts
|
|
2595
2596
|
function getAvailableStock(variant) {
|
|
2596
2597
|
if (!variant?.inventory) return 0;
|
|
@@ -2604,15 +2605,15 @@ function hasStock(variant, quantity = 1) {
|
|
|
2604
2605
|
return getAvailableStock(variant) >= quantity;
|
|
2605
2606
|
}
|
|
2606
2607
|
function getInventoryAt(variant, locationId) {
|
|
2607
|
-
return variant?.inventory?.find((inv) => inv.
|
|
2608
|
+
return variant?.inventory?.find((inv) => inv.location_id === locationId);
|
|
2608
2609
|
}
|
|
2609
2610
|
function getFirstAvailableFCId(variant, quantity = 1) {
|
|
2610
2611
|
const inv = variant?.inventory?.find((i) => i.available >= quantity);
|
|
2611
|
-
return inv?.
|
|
2612
|
+
return inv?.location_id;
|
|
2612
2613
|
}
|
|
2613
2614
|
|
|
2614
2615
|
// src/index.ts
|
|
2615
|
-
var SDK_VERSION = "0.7.
|
|
2616
|
+
var SDK_VERSION = "0.7.84";
|
|
2616
2617
|
var SUPPORTED_FRAMEWORKS = [
|
|
2617
2618
|
"astro",
|
|
2618
2619
|
"react",
|
|
@@ -2652,7 +2653,6 @@ function createUtilitySurface(apiConfig) {
|
|
|
2652
2653
|
validateKey,
|
|
2653
2654
|
toKey,
|
|
2654
2655
|
nameToKey,
|
|
2655
|
-
track,
|
|
2656
2656
|
getAvailableStock,
|
|
2657
2657
|
getReservedStock,
|
|
2658
2658
|
hasStock,
|
|
@@ -2680,17 +2680,6 @@ async function createAdmin(config) {
|
|
|
2680
2680
|
const authApi = createAuthApi(apiConfig);
|
|
2681
2681
|
const businessApi = createBusinessApi(apiConfig);
|
|
2682
2682
|
const platformApi = createPlatformApi(apiConfig);
|
|
2683
|
-
if (typeof window !== "undefined" && apiConfig.businessId) {
|
|
2684
|
-
businessApi.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
|
|
2685
|
-
if (!configs) return;
|
|
2686
|
-
for (const c of Array.isArray(configs) ? configs : [configs]) {
|
|
2687
|
-
if (c.measurementId) {
|
|
2688
|
-
injectGA4Script(c.measurementId);
|
|
2689
|
-
}
|
|
2690
|
-
}
|
|
2691
|
-
}).catch(() => {
|
|
2692
|
-
});
|
|
2693
|
-
}
|
|
2694
2683
|
const cmsApi = createCmsApi(apiConfig);
|
|
2695
2684
|
const eshopApi = createEshopApi(apiConfig);
|
|
2696
2685
|
const bookingApi = createBookingApi(apiConfig);
|
|
@@ -2849,7 +2838,6 @@ async function createAdmin(config) {
|
|
|
2849
2838
|
}
|
|
2850
2839
|
},
|
|
2851
2840
|
analytics: {
|
|
2852
|
-
track,
|
|
2853
2841
|
query: analyticsApi.query
|
|
2854
2842
|
},
|
|
2855
2843
|
setBusinessId: (businessId) => {
|
|
@@ -2872,8 +2860,35 @@ async function createAdmin(config) {
|
|
|
2872
2860
|
};
|
|
2873
2861
|
return sdk;
|
|
2874
2862
|
}
|
|
2875
|
-
|
|
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) {
|
|
2876
2890
|
const locale = config.locale || "en";
|
|
2891
|
+
const market = config.market || "";
|
|
2877
2892
|
const getToken = config.getToken || defaultGetToken;
|
|
2878
2893
|
const setToken = config.setToken || defaultSetToken;
|
|
2879
2894
|
const logout = config.logout || defaultLogout;
|
|
@@ -2889,44 +2904,67 @@ async function createStorefront(config) {
|
|
|
2889
2904
|
httpClient,
|
|
2890
2905
|
businessId: config.businessId,
|
|
2891
2906
|
baseUrl: config.baseUrl,
|
|
2892
|
-
market
|
|
2907
|
+
market,
|
|
2893
2908
|
locale,
|
|
2894
2909
|
setToken,
|
|
2895
2910
|
getToken
|
|
2896
2911
|
};
|
|
2897
2912
|
const storefrontApi = createStorefrontApi(apiConfig);
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
if (
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
const
|
|
2906
|
-
|
|
2907
|
-
|
|
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;
|
|
2908
2927
|
}
|
|
2909
|
-
|
|
2910
|
-
|
|
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;
|
|
2911
2959
|
});
|
|
2912
|
-
return
|
|
2960
|
+
return initPromise;
|
|
2913
2961
|
}
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
});
|
|
2917
|
-
if (apiConfig.businessId) {
|
|
2918
|
-
storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
|
|
2919
|
-
if (!configs) return;
|
|
2920
|
-
for (const c of Array.isArray(configs) ? configs : [configs]) {
|
|
2921
|
-
if (c.measurementId) {
|
|
2922
|
-
injectGA4Script(c.measurementId);
|
|
2923
|
-
}
|
|
2924
|
-
}
|
|
2925
|
-
}).catch(() => {
|
|
2926
|
-
});
|
|
2927
|
-
}
|
|
2962
|
+
function setMarket(key) {
|
|
2963
|
+
apiConfig.market = key;
|
|
2928
2964
|
}
|
|
2929
2965
|
return {
|
|
2966
|
+
init,
|
|
2967
|
+
stores,
|
|
2930
2968
|
business: storefrontApi.business,
|
|
2931
2969
|
cms: storefrontApi.cms,
|
|
2932
2970
|
eshop: storefrontApi.eshop,
|
|
@@ -2934,16 +2972,11 @@ async function createStorefront(config) {
|
|
|
2934
2972
|
crm: storefrontApi.crm,
|
|
2935
2973
|
activity: storefrontApi.activity,
|
|
2936
2974
|
automation: storefrontApi.automation,
|
|
2937
|
-
analytics: {
|
|
2938
|
-
track
|
|
2939
|
-
},
|
|
2940
2975
|
setBusinessId: (businessId) => {
|
|
2941
2976
|
apiConfig.businessId = businessId;
|
|
2942
2977
|
},
|
|
2943
2978
|
getBusinessId: () => apiConfig.businessId,
|
|
2944
|
-
setMarket
|
|
2945
|
-
apiConfig.market = market;
|
|
2946
|
-
},
|
|
2979
|
+
setMarket,
|
|
2947
2980
|
getMarket: () => apiConfig.market,
|
|
2948
2981
|
setLocale: (locale2) => {
|
|
2949
2982
|
apiConfig.locale = locale2;
|