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.d.cts
CHANGED
|
@@ -129,11 +129,12 @@ interface GetCountriesResponse {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
interface StorefrontStores {
|
|
132
|
+
customer: ReturnType<typeof atom<any>>;
|
|
132
133
|
business: ReturnType<typeof atom<any>>;
|
|
133
134
|
market: ReturnType<typeof atom<any>>;
|
|
134
135
|
loading: ReturnType<typeof atom<boolean>>;
|
|
135
136
|
error: ReturnType<typeof atom<string | null>>;
|
|
136
|
-
|
|
137
|
+
isLoggedIn: ReturnType<typeof computed>;
|
|
137
138
|
currency: ReturnType<typeof computed>;
|
|
138
139
|
currencySymbol: ReturnType<typeof computed>;
|
|
139
140
|
paymentMethods: ReturnType<typeof computed>;
|
|
@@ -172,7 +173,7 @@ declare function fetchSvgContent(mediaObject: any): Promise<string | null>;
|
|
|
172
173
|
declare function getSvgContentForAstro(mediaObject: any): Promise<string>;
|
|
173
174
|
declare function injectSvgIntoElement(mediaObject: any, targetElement: HTMLElement, className?: string): Promise<void>;
|
|
174
175
|
|
|
175
|
-
declare const SDK_VERSION = "0.7.
|
|
176
|
+
declare const SDK_VERSION = "0.7.90";
|
|
176
177
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
177
178
|
interface ApiConfig {
|
|
178
179
|
httpClient: any;
|
|
@@ -497,6 +498,7 @@ declare function createAdmin(config: HttpClientConfig & {
|
|
|
497
498
|
};
|
|
498
499
|
}>;
|
|
499
500
|
interface StorefrontSession {
|
|
501
|
+
customer: any;
|
|
500
502
|
business: any;
|
|
501
503
|
market: any;
|
|
502
504
|
}
|
|
@@ -504,13 +506,14 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
504
506
|
market?: string;
|
|
505
507
|
locale?: string;
|
|
506
508
|
}): {
|
|
507
|
-
|
|
509
|
+
session: (market?: string) => Promise<StorefrontSession>;
|
|
508
510
|
stores: {
|
|
511
|
+
customer: nanostores.PreinitializedWritableAtom<any> & object;
|
|
509
512
|
business: nanostores.PreinitializedWritableAtom<any> & object;
|
|
510
513
|
market: nanostores.PreinitializedWritableAtom<any> & object;
|
|
511
514
|
loading: nanostores.PreinitializedWritableAtom<boolean> & object;
|
|
512
515
|
error: nanostores.PreinitializedWritableAtom<string> & object;
|
|
513
|
-
|
|
516
|
+
isLoggedIn: nanostores.ReadableAtom<boolean>;
|
|
514
517
|
currency: nanostores.ReadableAtom<any>;
|
|
515
518
|
currencySymbol: nanostores.ReadableAtom<any>;
|
|
516
519
|
paymentMethods: nanostores.ReadableAtom<any>;
|
|
@@ -584,7 +587,7 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
584
587
|
};
|
|
585
588
|
crm: {
|
|
586
589
|
customer: {
|
|
587
|
-
|
|
590
|
+
session(params?: {
|
|
588
591
|
business_id?: string;
|
|
589
592
|
market?: string;
|
|
590
593
|
}, options?: RequestOptions): Promise<any>;
|
|
@@ -654,7 +657,7 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
654
657
|
};
|
|
655
658
|
setBusinessId: (businessId: string) => void;
|
|
656
659
|
getBusinessId: () => string;
|
|
657
|
-
setMarket: (key: string) =>
|
|
660
|
+
setMarket: (key: string) => Promise<StorefrontSession>;
|
|
658
661
|
getMarket: () => string;
|
|
659
662
|
setLocale: (locale: string) => void;
|
|
660
663
|
getLocale: () => string;
|
package/dist/index.d.ts
CHANGED
|
@@ -129,11 +129,12 @@ interface GetCountriesResponse {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
interface StorefrontStores {
|
|
132
|
+
customer: ReturnType<typeof atom<any>>;
|
|
132
133
|
business: ReturnType<typeof atom<any>>;
|
|
133
134
|
market: ReturnType<typeof atom<any>>;
|
|
134
135
|
loading: ReturnType<typeof atom<boolean>>;
|
|
135
136
|
error: ReturnType<typeof atom<string | null>>;
|
|
136
|
-
|
|
137
|
+
isLoggedIn: ReturnType<typeof computed>;
|
|
137
138
|
currency: ReturnType<typeof computed>;
|
|
138
139
|
currencySymbol: ReturnType<typeof computed>;
|
|
139
140
|
paymentMethods: ReturnType<typeof computed>;
|
|
@@ -172,7 +173,7 @@ declare function fetchSvgContent(mediaObject: any): Promise<string | null>;
|
|
|
172
173
|
declare function getSvgContentForAstro(mediaObject: any): Promise<string>;
|
|
173
174
|
declare function injectSvgIntoElement(mediaObject: any, targetElement: HTMLElement, className?: string): Promise<void>;
|
|
174
175
|
|
|
175
|
-
declare const SDK_VERSION = "0.7.
|
|
176
|
+
declare const SDK_VERSION = "0.7.90";
|
|
176
177
|
declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
|
|
177
178
|
interface ApiConfig {
|
|
178
179
|
httpClient: any;
|
|
@@ -497,6 +498,7 @@ declare function createAdmin(config: HttpClientConfig & {
|
|
|
497
498
|
};
|
|
498
499
|
}>;
|
|
499
500
|
interface StorefrontSession {
|
|
501
|
+
customer: any;
|
|
500
502
|
business: any;
|
|
501
503
|
market: any;
|
|
502
504
|
}
|
|
@@ -504,13 +506,14 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
504
506
|
market?: string;
|
|
505
507
|
locale?: string;
|
|
506
508
|
}): {
|
|
507
|
-
|
|
509
|
+
session: (market?: string) => Promise<StorefrontSession>;
|
|
508
510
|
stores: {
|
|
511
|
+
customer: nanostores.PreinitializedWritableAtom<any> & object;
|
|
509
512
|
business: nanostores.PreinitializedWritableAtom<any> & object;
|
|
510
513
|
market: nanostores.PreinitializedWritableAtom<any> & object;
|
|
511
514
|
loading: nanostores.PreinitializedWritableAtom<boolean> & object;
|
|
512
515
|
error: nanostores.PreinitializedWritableAtom<string> & object;
|
|
513
|
-
|
|
516
|
+
isLoggedIn: nanostores.ReadableAtom<boolean>;
|
|
514
517
|
currency: nanostores.ReadableAtom<any>;
|
|
515
518
|
currencySymbol: nanostores.ReadableAtom<any>;
|
|
516
519
|
paymentMethods: nanostores.ReadableAtom<any>;
|
|
@@ -584,7 +587,7 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
584
587
|
};
|
|
585
588
|
crm: {
|
|
586
589
|
customer: {
|
|
587
|
-
|
|
590
|
+
session(params?: {
|
|
588
591
|
business_id?: string;
|
|
589
592
|
market?: string;
|
|
590
593
|
}, options?: RequestOptions): Promise<any>;
|
|
@@ -654,7 +657,7 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
654
657
|
};
|
|
655
658
|
setBusinessId: (businessId: string) => void;
|
|
656
659
|
getBusinessId: () => string;
|
|
657
|
-
setMarket: (key: string) =>
|
|
660
|
+
setMarket: (key: string) => Promise<StorefrontSession>;
|
|
658
661
|
getMarket: () => string;
|
|
659
662
|
setLocale: (locale: string) => void;
|
|
660
663
|
getLocale: () => string;
|
package/dist/index.js
CHANGED
|
@@ -503,10 +503,10 @@ var createStorefrontApi = (apiConfig) => {
|
|
|
503
503
|
},
|
|
504
504
|
crm: {
|
|
505
505
|
customer: {
|
|
506
|
-
async
|
|
506
|
+
async session(params, options) {
|
|
507
507
|
const business_id = params?.business_id || apiConfig.businessId;
|
|
508
508
|
const result = await apiConfig.httpClient.post(
|
|
509
|
-
`${base(business_id)}/customers/
|
|
509
|
+
`${base(business_id)}/customers/session`,
|
|
510
510
|
{ business_id, market: params?.market || apiConfig.market || null },
|
|
511
511
|
options
|
|
512
512
|
);
|
|
@@ -2460,11 +2460,12 @@ function validatePhoneNumber(phone) {
|
|
|
2460
2460
|
return { isValid: true };
|
|
2461
2461
|
}
|
|
2462
2462
|
function createStores() {
|
|
2463
|
+
const $customer = atom(null);
|
|
2463
2464
|
const $business = atom(null);
|
|
2464
2465
|
const $market = atom(null);
|
|
2465
2466
|
const $loading = atom(false);
|
|
2466
2467
|
const $error = atom(null);
|
|
2467
|
-
const $
|
|
2468
|
+
const $isLoggedIn = computed($customer, (c) => !!c?.emails?.length);
|
|
2468
2469
|
const $currency = computed($market, (m) => m?.currency);
|
|
2469
2470
|
const $currencySymbol = computed($market, (m) => {
|
|
2470
2471
|
if (!m?.currency) return void 0;
|
|
@@ -2492,11 +2493,12 @@ function createStores() {
|
|
|
2492
2493
|
});
|
|
2493
2494
|
const $zones = computed($market, (m) => m?.zones || []);
|
|
2494
2495
|
return {
|
|
2496
|
+
customer: $customer,
|
|
2495
2497
|
business: $business,
|
|
2496
2498
|
market: $market,
|
|
2497
2499
|
loading: $loading,
|
|
2498
2500
|
error: $error,
|
|
2499
|
-
|
|
2501
|
+
isLoggedIn: $isLoggedIn,
|
|
2500
2502
|
currency: $currency,
|
|
2501
2503
|
currencySymbol: $currencySymbol,
|
|
2502
2504
|
paymentMethods: $paymentMethods,
|
|
@@ -2506,9 +2508,9 @@ function createStores() {
|
|
|
2506
2508
|
};
|
|
2507
2509
|
}
|
|
2508
2510
|
function populateStores(stores, data) {
|
|
2511
|
+
stores.customer.set(data.customer);
|
|
2509
2512
|
stores.business.set(data.business);
|
|
2510
2513
|
stores.market.set(data.market);
|
|
2511
|
-
stores.initialized.set(true);
|
|
2512
2514
|
}
|
|
2513
2515
|
|
|
2514
2516
|
// src/utils/timezone.ts
|
|
@@ -2684,7 +2686,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
|
|
|
2684
2686
|
}
|
|
2685
2687
|
|
|
2686
2688
|
// src/index.ts
|
|
2687
|
-
var SDK_VERSION = "0.7.
|
|
2689
|
+
var SDK_VERSION = "0.7.90";
|
|
2688
2690
|
var SUPPORTED_FRAMEWORKS = [
|
|
2689
2691
|
"astro",
|
|
2690
2692
|
"react",
|
|
@@ -2931,32 +2933,6 @@ async function createAdmin(config) {
|
|
|
2931
2933
|
};
|
|
2932
2934
|
return sdk;
|
|
2933
2935
|
}
|
|
2934
|
-
var SESSION_CACHE_TTL = 36e5;
|
|
2935
|
-
function getCachedSession(businessId) {
|
|
2936
|
-
if (typeof window === "undefined") return null;
|
|
2937
|
-
try {
|
|
2938
|
-
const raw = localStorage.getItem(`arky_session_${businessId}`);
|
|
2939
|
-
if (!raw) return null;
|
|
2940
|
-
const parsed = JSON.parse(raw);
|
|
2941
|
-
if (Date.now() - (parsed.timestamp || 0) > SESSION_CACHE_TTL) {
|
|
2942
|
-
localStorage.removeItem(`arky_session_${businessId}`);
|
|
2943
|
-
return null;
|
|
2944
|
-
}
|
|
2945
|
-
return { business: parsed.business, market: parsed.market };
|
|
2946
|
-
} catch {
|
|
2947
|
-
return null;
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
function setCachedSession(businessId, data) {
|
|
2951
|
-
if (typeof window === "undefined") return;
|
|
2952
|
-
try {
|
|
2953
|
-
localStorage.setItem(
|
|
2954
|
-
`arky_session_${businessId}`,
|
|
2955
|
-
JSON.stringify({ ...data, timestamp: Date.now() })
|
|
2956
|
-
);
|
|
2957
|
-
} catch {
|
|
2958
|
-
}
|
|
2959
|
-
}
|
|
2960
2936
|
function createStorefront(config) {
|
|
2961
2937
|
const locale = config.locale || "en";
|
|
2962
2938
|
const market = config.market || "";
|
|
@@ -2983,56 +2959,56 @@ function createStorefront(config) {
|
|
|
2983
2959
|
};
|
|
2984
2960
|
const storefrontApi = createStorefrontApi(apiConfig);
|
|
2985
2961
|
const stores = createStores();
|
|
2986
|
-
let
|
|
2987
|
-
function
|
|
2988
|
-
if (
|
|
2989
|
-
|
|
2962
|
+
let sessionPromise = null;
|
|
2963
|
+
function session(market2) {
|
|
2964
|
+
if (market2 !== void 0) apiConfig.market = market2;
|
|
2965
|
+
if (sessionPromise) return sessionPromise;
|
|
2966
|
+
sessionPromise = (async () => {
|
|
2990
2967
|
stores.loading.set(true);
|
|
2991
2968
|
stores.error.set(null);
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
2969
|
+
try {
|
|
2970
|
+
const result = await storefrontApi.crm.customer.session({
|
|
2971
|
+
market: apiConfig.market
|
|
2972
|
+
});
|
|
2973
|
+
const s = {
|
|
2974
|
+
customer: result.customer,
|
|
2975
|
+
business: result.business,
|
|
2976
|
+
market: result.market || null
|
|
2977
|
+
};
|
|
2978
|
+
populateStores(stores, s);
|
|
2979
|
+
return s;
|
|
2980
|
+
} catch (err) {
|
|
2981
|
+
const status = err?.status || err?.response?.status;
|
|
2982
|
+
if (status === 401) {
|
|
2983
|
+
await setToken({ access_token: "", refresh_token: "", access_expires_at: 0 });
|
|
2984
|
+
const result = await storefrontApi.crm.customer.session({
|
|
2985
|
+
market: apiConfig.market
|
|
2986
|
+
});
|
|
2987
|
+
const s = {
|
|
2988
|
+
customer: result.customer,
|
|
2989
|
+
business: result.business,
|
|
2990
|
+
market: result.market || null
|
|
2991
|
+
};
|
|
2992
|
+
populateStores(stores, s);
|
|
2993
|
+
return s;
|
|
2994
|
+
}
|
|
2995
|
+
throw err;
|
|
2996
|
+
} finally {
|
|
3009
2997
|
stores.loading.set(false);
|
|
3010
|
-
return session2;
|
|
3011
2998
|
}
|
|
3012
|
-
const result = await storefrontApi.crm.customer.initialize({
|
|
3013
|
-
market: apiConfig.market
|
|
3014
|
-
});
|
|
3015
|
-
const session = {
|
|
3016
|
-
business: result.business,
|
|
3017
|
-
market: result.market || null
|
|
3018
|
-
};
|
|
3019
|
-
populateStores(stores, session);
|
|
3020
|
-
setCachedSession(apiConfig.businessId, session);
|
|
3021
|
-
stores.loading.set(false);
|
|
3022
|
-
return session;
|
|
3023
2999
|
})().catch((err) => {
|
|
3024
|
-
stores.error.set(err.message || "
|
|
3025
|
-
|
|
3026
|
-
initPromise = null;
|
|
3000
|
+
stores.error.set(err.message || "Session failed");
|
|
3001
|
+
sessionPromise = null;
|
|
3027
3002
|
throw err;
|
|
3028
3003
|
});
|
|
3029
|
-
return
|
|
3004
|
+
return sessionPromise;
|
|
3030
3005
|
}
|
|
3031
3006
|
function setMarket(key) {
|
|
3032
|
-
|
|
3007
|
+
sessionPromise = null;
|
|
3008
|
+
return session(key);
|
|
3033
3009
|
}
|
|
3034
3010
|
return {
|
|
3035
|
-
|
|
3011
|
+
session,
|
|
3036
3012
|
stores,
|
|
3037
3013
|
business: storefrontApi.business,
|
|
3038
3014
|
cms: storefrontApi.cms,
|