arky-sdk 0.7.95 → 0.7.102
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/README.md +14 -0
- package/dist/admin.cjs +29 -26
- package/dist/admin.cjs.map +1 -1
- package/dist/admin.js +29 -26
- package/dist/admin.js.map +1 -1
- package/dist/index.cjs +98 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +424 -251
- package/dist/index.d.ts +424 -251
- package/dist/index.js +98 -97
- package/dist/index.js.map +1 -1
- package/dist/storefront.cjs +77 -84
- package/dist/storefront.cjs.map +1 -1
- package/dist/storefront.js +77 -84
- package/dist/storefront.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2275 -2112
- package/dist/types.d.ts +2275 -2112
- package/dist/types.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -399,7 +399,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
399
399
|
const items = paramItems || groupCartToItems(cart);
|
|
400
400
|
return apiConfig.httpClient.post(
|
|
401
401
|
`${base(target_store_id)}/bookings/checkout`,
|
|
402
|
-
{ market:
|
|
402
|
+
{ market: apiConfig.market, ...payload, items },
|
|
403
403
|
options
|
|
404
404
|
);
|
|
405
405
|
},
|
|
@@ -422,7 +422,7 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
422
422
|
const target_store_id = store_id || apiConfig.storeId;
|
|
423
423
|
return apiConfig.httpClient.post(
|
|
424
424
|
`${base(target_store_id)}/bookings/quote`,
|
|
425
|
-
{ market:
|
|
425
|
+
{ market: apiConfig.market, ...payload },
|
|
426
426
|
options
|
|
427
427
|
);
|
|
428
428
|
},
|
|
@@ -501,61 +501,46 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
501
501
|
},
|
|
502
502
|
crm: {
|
|
503
503
|
customer: {
|
|
504
|
-
async
|
|
505
|
-
const store_id =
|
|
506
|
-
const result = await apiConfig.httpClient.post(
|
|
507
|
-
`${base(store_id)}/customers/session`,
|
|
508
|
-
{ store_id, market: params?.market || apiConfig.market || null },
|
|
509
|
-
options
|
|
510
|
-
);
|
|
511
|
-
if (result?.token?.access_token) {
|
|
512
|
-
apiConfig.setToken(result.token);
|
|
513
|
-
}
|
|
514
|
-
return result;
|
|
515
|
-
},
|
|
516
|
-
async connect(params, options) {
|
|
517
|
-
const store_id = params.store_id || apiConfig.storeId;
|
|
504
|
+
async identify(params, options) {
|
|
505
|
+
const store_id = apiConfig.storeId;
|
|
518
506
|
const result = await apiConfig.httpClient.post(
|
|
519
|
-
`${base(store_id)}/customers/
|
|
520
|
-
{
|
|
507
|
+
`${base(store_id)}/customers/identify`,
|
|
508
|
+
{
|
|
509
|
+
store_id,
|
|
510
|
+
market: params?.market || apiConfig.market || null,
|
|
511
|
+
email: params?.email,
|
|
512
|
+
verify: params?.verify ?? false
|
|
513
|
+
},
|
|
521
514
|
options
|
|
522
515
|
);
|
|
523
|
-
if (result?.
|
|
524
|
-
apiConfig.setToken(result);
|
|
516
|
+
if (result?.token?.token) {
|
|
517
|
+
apiConfig.setToken({ access_token: result.token.token });
|
|
525
518
|
}
|
|
526
519
|
return result;
|
|
527
520
|
},
|
|
528
|
-
requestCode(params, options) {
|
|
529
|
-
const store_id = params.store_id || apiConfig.storeId;
|
|
530
|
-
return apiConfig.httpClient.post(
|
|
531
|
-
`${base(store_id)}/customers/auth/code`,
|
|
532
|
-
{ email: params.email, store_id },
|
|
533
|
-
options
|
|
534
|
-
);
|
|
535
|
-
},
|
|
536
521
|
async verify(params, options) {
|
|
537
|
-
const store_id =
|
|
522
|
+
const store_id = apiConfig.storeId;
|
|
538
523
|
const result = await apiConfig.httpClient.post(
|
|
539
|
-
`${base(store_id)}/customers/
|
|
540
|
-
{
|
|
524
|
+
`${base(store_id)}/customers/verify`,
|
|
525
|
+
{ store_id, code: params.code },
|
|
541
526
|
options
|
|
542
527
|
);
|
|
543
|
-
if (result?.
|
|
544
|
-
apiConfig.setToken(result);
|
|
528
|
+
if (result?.token) {
|
|
529
|
+
apiConfig.setToken({ access_token: result.token });
|
|
545
530
|
}
|
|
546
531
|
return result;
|
|
547
532
|
},
|
|
548
|
-
async
|
|
549
|
-
const store_id =
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
533
|
+
async logout(options) {
|
|
534
|
+
const store_id = apiConfig.storeId;
|
|
535
|
+
try {
|
|
536
|
+
await apiConfig.httpClient.post(
|
|
537
|
+
`${base(store_id)}/customers/logout`,
|
|
538
|
+
{},
|
|
539
|
+
options
|
|
540
|
+
);
|
|
541
|
+
} finally {
|
|
542
|
+
apiConfig.setToken({ access_token: "" });
|
|
557
543
|
}
|
|
558
|
-
return result;
|
|
559
544
|
},
|
|
560
545
|
getMe(options) {
|
|
561
546
|
return apiConfig.httpClient.get(`${base()}/customers/me`, options);
|
|
@@ -716,36 +701,31 @@ function buildQueryString(params) {
|
|
|
716
701
|
}
|
|
717
702
|
|
|
718
703
|
// src/services/createHttpClient.ts
|
|
719
|
-
var
|
|
720
|
-
|
|
721
|
-
refresh_token: "arky_refresh",
|
|
722
|
-
access_expires_at: "arky_expires_at"
|
|
723
|
-
};
|
|
704
|
+
var TOKEN_KEY = "arky_token";
|
|
705
|
+
var LEGACY_KEYS = ["arky_refresh", "arky_expires_at"];
|
|
724
706
|
function defaultGetToken() {
|
|
725
707
|
if (typeof window === "undefined") return { access_token: "" };
|
|
726
708
|
return {
|
|
727
|
-
access_token: localStorage.getItem(
|
|
728
|
-
refresh_token: localStorage.getItem(STORAGE_KEYS.refresh_token) || "",
|
|
729
|
-
access_expires_at: parseInt(localStorage.getItem(STORAGE_KEYS.access_expires_at) || "0", 10)
|
|
709
|
+
access_token: localStorage.getItem(TOKEN_KEY) || ""
|
|
730
710
|
};
|
|
731
711
|
}
|
|
732
712
|
function defaultSetToken(tokens) {
|
|
733
713
|
if (typeof window === "undefined") return;
|
|
734
714
|
if (tokens.access_token) {
|
|
735
|
-
localStorage.setItem(
|
|
736
|
-
localStorage.setItem(STORAGE_KEYS.refresh_token, tokens.refresh_token || "");
|
|
737
|
-
localStorage.setItem(STORAGE_KEYS.access_expires_at, (tokens.access_expires_at || 0).toString());
|
|
715
|
+
localStorage.setItem(TOKEN_KEY, tokens.access_token);
|
|
738
716
|
} else {
|
|
739
|
-
|
|
717
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
740
718
|
}
|
|
719
|
+
LEGACY_KEYS.forEach((key) => localStorage.removeItem(key));
|
|
741
720
|
}
|
|
742
721
|
function defaultLogout() {
|
|
743
722
|
if (typeof window === "undefined") return;
|
|
744
|
-
|
|
723
|
+
localStorage.removeItem(TOKEN_KEY);
|
|
724
|
+
LEGACY_KEYS.forEach((key) => localStorage.removeItem(key));
|
|
745
725
|
}
|
|
746
726
|
function defaultIsAuthenticated() {
|
|
747
727
|
if (typeof window === "undefined") return false;
|
|
748
|
-
const token = localStorage.getItem(
|
|
728
|
+
const token = localStorage.getItem(TOKEN_KEY) || "";
|
|
749
729
|
return token.startsWith("customer_") || token.startsWith("account_");
|
|
750
730
|
}
|
|
751
731
|
function createHttpClient(cfg) {
|
|
@@ -927,10 +907,10 @@ var createAccountApi = (apiConfig) => {
|
|
|
927
907
|
if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
|
|
928
908
|
return apiConfig.httpClient.put("/v1/accounts", payload, options);
|
|
929
909
|
},
|
|
930
|
-
async deleteAccount(
|
|
910
|
+
async deleteAccount(_params, options) {
|
|
931
911
|
return apiConfig.httpClient.delete("/v1/accounts", options);
|
|
932
912
|
},
|
|
933
|
-
async getMe(
|
|
913
|
+
async getMe(_params, options) {
|
|
934
914
|
return apiConfig.httpClient.get("/v1/accounts/me", options);
|
|
935
915
|
},
|
|
936
916
|
async searchAccounts(params, options) {
|
|
@@ -952,9 +932,13 @@ var createAuthApi = (apiConfig) => {
|
|
|
952
932
|
return apiConfig.httpClient.post("/v1/auth/code", params, options);
|
|
953
933
|
},
|
|
954
934
|
async verify(params, options) {
|
|
955
|
-
const result = await apiConfig.httpClient.post(
|
|
935
|
+
const result = await apiConfig.httpClient.post(
|
|
936
|
+
"/v1/auth/verify",
|
|
937
|
+
params,
|
|
938
|
+
options
|
|
939
|
+
);
|
|
956
940
|
if (result?.access_token) {
|
|
957
|
-
apiConfig.setToken({
|
|
941
|
+
apiConfig.setToken({ access_token: result.access_token, refresh_token: result.refresh_token });
|
|
958
942
|
}
|
|
959
943
|
return result;
|
|
960
944
|
},
|
|
@@ -965,9 +949,13 @@ var createAuthApi = (apiConfig) => {
|
|
|
965
949
|
return apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/code`, params, options);
|
|
966
950
|
},
|
|
967
951
|
async storeVerify(storeId, params, options) {
|
|
968
|
-
const result = await apiConfig.httpClient.post(
|
|
952
|
+
const result = await apiConfig.httpClient.post(
|
|
953
|
+
`/v1/stores/${storeId}/auth/verify`,
|
|
954
|
+
params,
|
|
955
|
+
options
|
|
956
|
+
);
|
|
969
957
|
if (result?.access_token) {
|
|
970
|
-
apiConfig.setToken({
|
|
958
|
+
apiConfig.setToken({ access_token: result.access_token, refresh_token: result.refresh_token });
|
|
971
959
|
}
|
|
972
960
|
return result;
|
|
973
961
|
},
|
|
@@ -996,7 +984,7 @@ var createStoreApi = (apiConfig) => {
|
|
|
996
984
|
options
|
|
997
985
|
);
|
|
998
986
|
},
|
|
999
|
-
async getStore(
|
|
987
|
+
async getStore(_params, options) {
|
|
1000
988
|
return apiConfig.httpClient.get(
|
|
1001
989
|
`/v1/stores/${apiConfig.storeId}`,
|
|
1002
990
|
options
|
|
@@ -1008,7 +996,7 @@ var createStoreApi = (apiConfig) => {
|
|
|
1008
996
|
params
|
|
1009
997
|
});
|
|
1010
998
|
},
|
|
1011
|
-
async getSubscriptionPlans(
|
|
999
|
+
async getSubscriptionPlans(_params, options) {
|
|
1012
1000
|
return apiConfig.httpClient.get("/v1/stores/plans", options);
|
|
1013
1001
|
},
|
|
1014
1002
|
async subscribe(params, options) {
|
|
@@ -1160,7 +1148,7 @@ var createMediaApi = (apiConfig) => {
|
|
|
1160
1148
|
options
|
|
1161
1149
|
);
|
|
1162
1150
|
},
|
|
1163
|
-
async uploadStoreMedia(params,
|
|
1151
|
+
async uploadStoreMedia(params, _options) {
|
|
1164
1152
|
const { store_id, files = [], urls = [] } = params;
|
|
1165
1153
|
const target_store_id = store_id || apiConfig.storeId;
|
|
1166
1154
|
const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
|
|
@@ -1187,7 +1175,7 @@ var createMediaApi = (apiConfig) => {
|
|
|
1187
1175
|
options
|
|
1188
1176
|
);
|
|
1189
1177
|
},
|
|
1190
|
-
async getStoreMedia(params,
|
|
1178
|
+
async getStoreMedia(params, _options) {
|
|
1191
1179
|
const { store_id, cursor, limit, ids, query, mime_type, sort_field, sort_direction } = params;
|
|
1192
1180
|
const target_store_id = store_id || apiConfig.storeId;
|
|
1193
1181
|
const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
|
|
@@ -1509,7 +1497,7 @@ var createBookingApi = (apiConfig) => {
|
|
|
1509
1497
|
const target_store_id = store_id || apiConfig.storeId;
|
|
1510
1498
|
return apiConfig.httpClient.post(
|
|
1511
1499
|
`/v1/stores/${target_store_id}/bookings`,
|
|
1512
|
-
{ market:
|
|
1500
|
+
{ market: apiConfig.market, ...payload },
|
|
1513
1501
|
options
|
|
1514
1502
|
);
|
|
1515
1503
|
},
|
|
@@ -1544,7 +1532,7 @@ var createBookingApi = (apiConfig) => {
|
|
|
1544
1532
|
const target_store_id = store_id || apiConfig.storeId;
|
|
1545
1533
|
return apiConfig.httpClient.post(
|
|
1546
1534
|
`/v1/stores/${target_store_id}/bookings/quote`,
|
|
1547
|
-
{ market:
|
|
1535
|
+
{ market: apiConfig.market, ...payload },
|
|
1548
1536
|
options
|
|
1549
1537
|
);
|
|
1550
1538
|
},
|
|
@@ -2631,7 +2619,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
|
|
|
2631
2619
|
}
|
|
2632
2620
|
|
|
2633
2621
|
// src/index.ts
|
|
2634
|
-
var SDK_VERSION = "0.7.
|
|
2622
|
+
var SDK_VERSION = "0.7.102";
|
|
2635
2623
|
var SUPPORTED_FRAMEWORKS = [
|
|
2636
2624
|
"astro",
|
|
2637
2625
|
"react",
|
|
@@ -2885,13 +2873,11 @@ function createStorefront(config) {
|
|
|
2885
2873
|
const setToken = config.setToken || defaultSetToken;
|
|
2886
2874
|
const logout = config.logout || defaultLogout;
|
|
2887
2875
|
const isAuthenticated = config.isAuthenticated || defaultIsAuthenticated;
|
|
2888
|
-
let refresh_store_id = config.storeId;
|
|
2889
2876
|
const httpClient = createHttpClient({
|
|
2890
2877
|
...config,
|
|
2891
2878
|
getToken,
|
|
2892
2879
|
setToken,
|
|
2893
|
-
logout
|
|
2894
|
-
refreshPath: () => `/v1/storefront/${refresh_store_id}/customers/auth/refresh`
|
|
2880
|
+
logout
|
|
2895
2881
|
});
|
|
2896
2882
|
const apiConfig = {
|
|
2897
2883
|
httpClient,
|
|
@@ -2907,9 +2893,9 @@ function createStorefront(config) {
|
|
|
2907
2893
|
let currentSession = null;
|
|
2908
2894
|
const sessionListeners = /* @__PURE__ */ new Set();
|
|
2909
2895
|
const customerApi = storefrontApi.crm.customer;
|
|
2910
|
-
function emitSessionChange(
|
|
2896
|
+
function emitSessionChange(session) {
|
|
2911
2897
|
for (const listener of sessionListeners) {
|
|
2912
|
-
Promise.resolve().then(() => listener(
|
|
2898
|
+
Promise.resolve().then(() => listener(session)).catch(() => {
|
|
2913
2899
|
});
|
|
2914
2900
|
}
|
|
2915
2901
|
}
|
|
@@ -2933,22 +2919,26 @@ function createStorefront(config) {
|
|
|
2933
2919
|
clearSession();
|
|
2934
2920
|
return result;
|
|
2935
2921
|
}
|
|
2936
|
-
function
|
|
2937
|
-
if (
|
|
2938
|
-
|
|
2939
|
-
|
|
2922
|
+
function identify(params) {
|
|
2923
|
+
if (params?.market !== void 0) apiConfig.market = params.market;
|
|
2924
|
+
const isBareCall = !params?.email && !params?.verify;
|
|
2925
|
+
if (isBareCall && sessionPromise) return sessionPromise;
|
|
2926
|
+
const promise = (async () => {
|
|
2940
2927
|
try {
|
|
2941
|
-
const result = await customerApi.
|
|
2942
|
-
market: apiConfig.market
|
|
2928
|
+
const result = await customerApi.identify({
|
|
2929
|
+
market: apiConfig.market,
|
|
2930
|
+
email: params?.email,
|
|
2931
|
+
verify: params?.verify
|
|
2943
2932
|
});
|
|
2944
2933
|
return setCurrentSessionFromResult(result);
|
|
2945
2934
|
} catch (err) {
|
|
2946
|
-
const
|
|
2947
|
-
|
|
2935
|
+
const e = err;
|
|
2936
|
+
const status = e?.statusCode || e?.status || e?.response?.status;
|
|
2937
|
+
if (isBareCall && status === 401) {
|
|
2948
2938
|
currentSession = null;
|
|
2949
2939
|
emitSessionChange(null);
|
|
2950
|
-
await setToken({ access_token: ""
|
|
2951
|
-
const result = await customerApi.
|
|
2940
|
+
await setToken({ access_token: "" });
|
|
2941
|
+
const result = await customerApi.identify({
|
|
2952
2942
|
market: apiConfig.market
|
|
2953
2943
|
});
|
|
2954
2944
|
return setCurrentSessionFromResult(result);
|
|
@@ -2956,10 +2946,11 @@ function createStorefront(config) {
|
|
|
2956
2946
|
throw err;
|
|
2957
2947
|
}
|
|
2958
2948
|
})().catch((err) => {
|
|
2959
|
-
sessionPromise = null;
|
|
2949
|
+
if (isBareCall) sessionPromise = null;
|
|
2960
2950
|
throw err;
|
|
2961
2951
|
});
|
|
2962
|
-
|
|
2952
|
+
if (isBareCall) sessionPromise = promise;
|
|
2953
|
+
return promise;
|
|
2963
2954
|
}
|
|
2964
2955
|
function setMarket(key) {
|
|
2965
2956
|
apiConfig.market = key;
|
|
@@ -2978,10 +2969,6 @@ function createStorefront(config) {
|
|
|
2978
2969
|
function getSession() {
|
|
2979
2970
|
return currentSession;
|
|
2980
2971
|
}
|
|
2981
|
-
function logoutAndClearSession() {
|
|
2982
|
-
clearSession();
|
|
2983
|
-
return logout();
|
|
2984
|
-
}
|
|
2985
2972
|
function setTokenAndClearSession(tokens) {
|
|
2986
2973
|
setToken(tokens);
|
|
2987
2974
|
clearSession();
|
|
@@ -2990,17 +2977,33 @@ function createStorefront(config) {
|
|
|
2990
2977
|
...storefrontApi.crm,
|
|
2991
2978
|
customer: {
|
|
2992
2979
|
...customerApi,
|
|
2993
|
-
async
|
|
2994
|
-
const result = await customerApi.
|
|
2980
|
+
async identify(params, options) {
|
|
2981
|
+
const result = await customerApi.identify(params, options);
|
|
2995
2982
|
setCurrentSessionFromResult(result);
|
|
2996
2983
|
return result;
|
|
2997
2984
|
},
|
|
2998
|
-
connect: (params, options) => invalidateAfterAuth(customerApi.connect(params, options)),
|
|
2999
2985
|
verify: (params, options) => invalidateAfterAuth(customerApi.verify(params, options))
|
|
3000
2986
|
}
|
|
3001
2987
|
};
|
|
2988
|
+
async function verify(params) {
|
|
2989
|
+
const result = await invalidateAfterAuth(customerApi.verify(params));
|
|
2990
|
+
return result;
|
|
2991
|
+
}
|
|
2992
|
+
async function me() {
|
|
2993
|
+
return customerApi.getMe();
|
|
2994
|
+
}
|
|
2995
|
+
async function logoutCustomer() {
|
|
2996
|
+
try {
|
|
2997
|
+
await customerApi.logout();
|
|
2998
|
+
} finally {
|
|
2999
|
+
clearSession();
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
3002
|
return {
|
|
3003
|
-
|
|
3003
|
+
identify,
|
|
3004
|
+
verify,
|
|
3005
|
+
me,
|
|
3006
|
+
logout: logoutCustomer,
|
|
3004
3007
|
getSession,
|
|
3005
3008
|
onSessionChange,
|
|
3006
3009
|
store: storefrontApi.store,
|
|
@@ -3011,7 +3014,6 @@ function createStorefront(config) {
|
|
|
3011
3014
|
activity: storefrontApi.activity,
|
|
3012
3015
|
automation: storefrontApi.automation,
|
|
3013
3016
|
setStoreId: (storeId) => {
|
|
3014
|
-
refresh_store_id = storeId;
|
|
3015
3017
|
apiConfig.storeId = storeId;
|
|
3016
3018
|
clearSession();
|
|
3017
3019
|
},
|
|
@@ -3023,7 +3025,6 @@ function createStorefront(config) {
|
|
|
3023
3025
|
},
|
|
3024
3026
|
getLocale: () => apiConfig.locale,
|
|
3025
3027
|
isAuthenticated,
|
|
3026
|
-
logout: logoutAndClearSession,
|
|
3027
3028
|
setToken: setTokenAndClearSession,
|
|
3028
3029
|
extractBlockValues,
|
|
3029
3030
|
utils: createUtilitySurface(apiConfig)
|