arky-sdk 0.7.89 → 0.7.90
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 +47 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.js +47 -71
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -505,10 +505,10 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
505
505
|
},
|
|
506
506
|
crm: {
|
|
507
507
|
customer: {
|
|
508
|
-
async
|
|
508
|
+
async session(params, options) {
|
|
509
509
|
const business_id = params?.business_id || apiConfig.businessId;
|
|
510
510
|
const result = await apiConfig.httpClient.post(
|
|
511
|
-
`${base(business_id)}/customers/
|
|
511
|
+
`${base(business_id)}/customers/session`,
|
|
512
512
|
{ business_id, market: params?.market || apiConfig.market || null },
|
|
513
513
|
options
|
|
514
514
|
);
|
|
@@ -2462,11 +2462,12 @@ function validatePhoneNumber(phone) {
|
|
|
2462
2462
|
return { isValid: true };
|
|
2463
2463
|
}
|
|
2464
2464
|
function createStores() {
|
|
2465
|
+
const $customer = nanostores.atom(null);
|
|
2465
2466
|
const $business = nanostores.atom(null);
|
|
2466
2467
|
const $market = nanostores.atom(null);
|
|
2467
2468
|
const $loading = nanostores.atom(false);
|
|
2468
2469
|
const $error = nanostores.atom(null);
|
|
2469
|
-
const $
|
|
2470
|
+
const $isLoggedIn = nanostores.computed($customer, (c) => !!c?.emails?.length);
|
|
2470
2471
|
const $currency = nanostores.computed($market, (m) => m?.currency);
|
|
2471
2472
|
const $currencySymbol = nanostores.computed($market, (m) => {
|
|
2472
2473
|
if (!m?.currency) return void 0;
|
|
@@ -2494,11 +2495,12 @@ function createStores() {
|
|
|
2494
2495
|
});
|
|
2495
2496
|
const $zones = nanostores.computed($market, (m) => m?.zones || []);
|
|
2496
2497
|
return {
|
|
2498
|
+
customer: $customer,
|
|
2497
2499
|
business: $business,
|
|
2498
2500
|
market: $market,
|
|
2499
2501
|
loading: $loading,
|
|
2500
2502
|
error: $error,
|
|
2501
|
-
|
|
2503
|
+
isLoggedIn: $isLoggedIn,
|
|
2502
2504
|
currency: $currency,
|
|
2503
2505
|
currencySymbol: $currencySymbol,
|
|
2504
2506
|
paymentMethods: $paymentMethods,
|
|
@@ -2508,9 +2510,9 @@ function createStores() {
|
|
|
2508
2510
|
};
|
|
2509
2511
|
}
|
|
2510
2512
|
function populateStores(stores, data) {
|
|
2513
|
+
stores.customer.set(data.customer);
|
|
2511
2514
|
stores.business.set(data.business);
|
|
2512
2515
|
stores.market.set(data.market);
|
|
2513
|
-
stores.initialized.set(true);
|
|
2514
2516
|
}
|
|
2515
2517
|
|
|
2516
2518
|
// src/utils/timezone.ts
|
|
@@ -2686,7 +2688,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
|
|
|
2686
2688
|
}
|
|
2687
2689
|
|
|
2688
2690
|
// src/index.ts
|
|
2689
|
-
var SDK_VERSION = "0.7.
|
|
2691
|
+
var SDK_VERSION = "0.7.90";
|
|
2690
2692
|
var SUPPORTED_FRAMEWORKS = [
|
|
2691
2693
|
"astro",
|
|
2692
2694
|
"react",
|
|
@@ -2933,32 +2935,6 @@ async function createAdmin(config) {
|
|
|
2933
2935
|
};
|
|
2934
2936
|
return sdk;
|
|
2935
2937
|
}
|
|
2936
|
-
var SESSION_CACHE_TTL = 36e5;
|
|
2937
|
-
function getCachedSession(businessId) {
|
|
2938
|
-
if (typeof window === "undefined") return null;
|
|
2939
|
-
try {
|
|
2940
|
-
const raw = localStorage.getItem(`arky_session_${businessId}`);
|
|
2941
|
-
if (!raw) return null;
|
|
2942
|
-
const parsed = JSON.parse(raw);
|
|
2943
|
-
if (Date.now() - (parsed.timestamp || 0) > SESSION_CACHE_TTL) {
|
|
2944
|
-
localStorage.removeItem(`arky_session_${businessId}`);
|
|
2945
|
-
return null;
|
|
2946
|
-
}
|
|
2947
|
-
return { business: parsed.business, market: parsed.market };
|
|
2948
|
-
} catch {
|
|
2949
|
-
return null;
|
|
2950
|
-
}
|
|
2951
|
-
}
|
|
2952
|
-
function setCachedSession(businessId, data) {
|
|
2953
|
-
if (typeof window === "undefined") return;
|
|
2954
|
-
try {
|
|
2955
|
-
localStorage.setItem(
|
|
2956
|
-
`arky_session_${businessId}`,
|
|
2957
|
-
JSON.stringify({ ...data, timestamp: Date.now() })
|
|
2958
|
-
);
|
|
2959
|
-
} catch {
|
|
2960
|
-
}
|
|
2961
|
-
}
|
|
2962
2938
|
function createStorefront(config) {
|
|
2963
2939
|
const locale = config.locale || "en";
|
|
2964
2940
|
const market = config.market || "";
|
|
@@ -2985,56 +2961,56 @@ function createStorefront(config) {
|
|
|
2985
2961
|
};
|
|
2986
2962
|
const storefrontApi = createStorefrontApi(apiConfig);
|
|
2987
2963
|
const stores = createStores();
|
|
2988
|
-
let
|
|
2989
|
-
function
|
|
2990
|
-
if (
|
|
2991
|
-
|
|
2964
|
+
let sessionPromise = null;
|
|
2965
|
+
function session(market2) {
|
|
2966
|
+
if (market2 !== void 0) apiConfig.market = market2;
|
|
2967
|
+
if (sessionPromise) return sessionPromise;
|
|
2968
|
+
sessionPromise = (async () => {
|
|
2992
2969
|
stores.loading.set(true);
|
|
2993
2970
|
stores.error.set(null);
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
2971
|
+
try {
|
|
2972
|
+
const result = await storefrontApi.crm.customer.session({
|
|
2973
|
+
market: apiConfig.market
|
|
2974
|
+
});
|
|
2975
|
+
const s = {
|
|
2976
|
+
customer: result.customer,
|
|
2977
|
+
business: result.business,
|
|
2978
|
+
market: result.market || null
|
|
2979
|
+
};
|
|
2980
|
+
populateStores(stores, s);
|
|
2981
|
+
return s;
|
|
2982
|
+
} catch (err) {
|
|
2983
|
+
const status = err?.status || err?.response?.status;
|
|
2984
|
+
if (status === 401) {
|
|
2985
|
+
await setToken({ access_token: "", refresh_token: "", access_expires_at: 0 });
|
|
2986
|
+
const result = await storefrontApi.crm.customer.session({
|
|
2987
|
+
market: apiConfig.market
|
|
2988
|
+
});
|
|
2989
|
+
const s = {
|
|
2990
|
+
customer: result.customer,
|
|
2991
|
+
business: result.business,
|
|
2992
|
+
market: result.market || null
|
|
2993
|
+
};
|
|
2994
|
+
populateStores(stores, s);
|
|
2995
|
+
return s;
|
|
2996
|
+
}
|
|
2997
|
+
throw err;
|
|
2998
|
+
} finally {
|
|
3011
2999
|
stores.loading.set(false);
|
|
3012
|
-
return session2;
|
|
3013
3000
|
}
|
|
3014
|
-
const result = await storefrontApi.crm.customer.initialize({
|
|
3015
|
-
market: apiConfig.market
|
|
3016
|
-
});
|
|
3017
|
-
const session = {
|
|
3018
|
-
business: result.business,
|
|
3019
|
-
market: result.market || null
|
|
3020
|
-
};
|
|
3021
|
-
populateStores(stores, session);
|
|
3022
|
-
setCachedSession(apiConfig.businessId, session);
|
|
3023
|
-
stores.loading.set(false);
|
|
3024
|
-
return session;
|
|
3025
3001
|
})().catch((err) => {
|
|
3026
|
-
stores.error.set(err.message || "
|
|
3027
|
-
|
|
3028
|
-
initPromise = null;
|
|
3002
|
+
stores.error.set(err.message || "Session failed");
|
|
3003
|
+
sessionPromise = null;
|
|
3029
3004
|
throw err;
|
|
3030
3005
|
});
|
|
3031
|
-
return
|
|
3006
|
+
return sessionPromise;
|
|
3032
3007
|
}
|
|
3033
3008
|
function setMarket(key) {
|
|
3034
|
-
|
|
3009
|
+
sessionPromise = null;
|
|
3010
|
+
return session(key);
|
|
3035
3011
|
}
|
|
3036
3012
|
return {
|
|
3037
|
-
|
|
3013
|
+
session,
|
|
3038
3014
|
stores,
|
|
3039
3015
|
business: storefrontApi.business,
|
|
3040
3016
|
cms: storefrontApi.cms,
|