arky-sdk 0.7.89 → 0.7.91
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 +62 -72
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -7
- package/dist/index.d.ts +11 -7
- package/dist/index.js +62 -72
- 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.91";
|
|
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>;
|
|
@@ -616,9 +619,10 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
616
619
|
};
|
|
617
620
|
};
|
|
618
621
|
activity: {
|
|
622
|
+
track(params: Parameters<(params: TrackParams) => Promise<void>>[0]): Promise<void>;
|
|
619
623
|
COMMON_ACTIVITY_TYPES: readonly ["page_view", "product_view", "service_view", "provider_view", "cart_added", "cart_removed", "checkout_started", "purchase", "booking_created", "signin", "signup", "verified_email", "search", "share", "wishlist_added"];
|
|
620
|
-
track(params: TrackParams): Promise<void>;
|
|
621
624
|
};
|
|
625
|
+
ready: Promise<void>;
|
|
622
626
|
automation: {
|
|
623
627
|
agent: {
|
|
624
628
|
getAgents(params?: any, options?: RequestOptions): any;
|
|
@@ -654,7 +658,7 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
654
658
|
};
|
|
655
659
|
setBusinessId: (businessId: string) => void;
|
|
656
660
|
getBusinessId: () => string;
|
|
657
|
-
setMarket: (key: string) =>
|
|
661
|
+
setMarket: (key: string) => Promise<StorefrontSession>;
|
|
658
662
|
getMarket: () => string;
|
|
659
663
|
setLocale: (locale: string) => void;
|
|
660
664
|
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.91";
|
|
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>;
|
|
@@ -616,9 +619,10 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
616
619
|
};
|
|
617
620
|
};
|
|
618
621
|
activity: {
|
|
622
|
+
track(params: Parameters<(params: TrackParams) => Promise<void>>[0]): Promise<void>;
|
|
619
623
|
COMMON_ACTIVITY_TYPES: readonly ["page_view", "product_view", "service_view", "provider_view", "cart_added", "cart_removed", "checkout_started", "purchase", "booking_created", "signin", "signup", "verified_email", "search", "share", "wishlist_added"];
|
|
620
|
-
track(params: TrackParams): Promise<void>;
|
|
621
624
|
};
|
|
625
|
+
ready: Promise<void>;
|
|
622
626
|
automation: {
|
|
623
627
|
agent: {
|
|
624
628
|
getAgents(params?: any, options?: RequestOptions): any;
|
|
@@ -654,7 +658,7 @@ declare function createStorefront(config: HttpClientConfig & {
|
|
|
654
658
|
};
|
|
655
659
|
setBusinessId: (businessId: string) => void;
|
|
656
660
|
getBusinessId: () => string;
|
|
657
|
-
setMarket: (key: string) =>
|
|
661
|
+
setMarket: (key: string) => Promise<StorefrontSession>;
|
|
658
662
|
getMarket: () => string;
|
|
659
663
|
setLocale: (locale: string) => void;
|
|
660
664
|
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.91";
|
|
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,63 +2959,77 @@ function createStorefront(config) {
|
|
|
2983
2959
|
};
|
|
2984
2960
|
const storefrontApi = createStorefrontApi(apiConfig);
|
|
2985
2961
|
const stores = createStores();
|
|
2986
|
-
let
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2962
|
+
let sessionPromise = null;
|
|
2963
|
+
let resolveReady;
|
|
2964
|
+
const ready = new Promise((r) => {
|
|
2965
|
+
resolveReady = r;
|
|
2966
|
+
});
|
|
2967
|
+
function session(market2) {
|
|
2968
|
+
if (market2 !== void 0) apiConfig.market = market2;
|
|
2969
|
+
if (sessionPromise) return sessionPromise;
|
|
2970
|
+
sessionPromise = (async () => {
|
|
2990
2971
|
stores.loading.set(true);
|
|
2991
2972
|
stores.error.set(null);
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
const
|
|
3006
|
-
|
|
3007
|
-
|
|
3008
|
-
|
|
2973
|
+
try {
|
|
2974
|
+
const result = await storefrontApi.crm.customer.session({
|
|
2975
|
+
market: apiConfig.market
|
|
2976
|
+
});
|
|
2977
|
+
const s = {
|
|
2978
|
+
customer: result.customer,
|
|
2979
|
+
business: result.business,
|
|
2980
|
+
market: result.market || null
|
|
2981
|
+
};
|
|
2982
|
+
populateStores(stores, s);
|
|
2983
|
+
resolveReady();
|
|
2984
|
+
return s;
|
|
2985
|
+
} catch (err) {
|
|
2986
|
+
const status = err?.status || err?.response?.status;
|
|
2987
|
+
if (status === 401) {
|
|
2988
|
+
await setToken({ access_token: "", refresh_token: "", access_expires_at: 0 });
|
|
2989
|
+
const result = await storefrontApi.crm.customer.session({
|
|
2990
|
+
market: apiConfig.market
|
|
2991
|
+
});
|
|
2992
|
+
const s = {
|
|
2993
|
+
customer: result.customer,
|
|
2994
|
+
business: result.business,
|
|
2995
|
+
market: result.market || null
|
|
2996
|
+
};
|
|
2997
|
+
populateStores(stores, s);
|
|
2998
|
+
resolveReady();
|
|
2999
|
+
return s;
|
|
3000
|
+
}
|
|
3001
|
+
throw err;
|
|
3002
|
+
} finally {
|
|
3009
3003
|
stores.loading.set(false);
|
|
3010
|
-
return session2;
|
|
3011
3004
|
}
|
|
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
3005
|
})().catch((err) => {
|
|
3024
|
-
stores.error.set(err.message || "
|
|
3025
|
-
|
|
3026
|
-
initPromise = null;
|
|
3006
|
+
stores.error.set(err.message || "Session failed");
|
|
3007
|
+
sessionPromise = null;
|
|
3027
3008
|
throw err;
|
|
3028
3009
|
});
|
|
3029
|
-
return
|
|
3010
|
+
return sessionPromise;
|
|
3030
3011
|
}
|
|
3012
|
+
const activity = {
|
|
3013
|
+
...storefrontApi.activity,
|
|
3014
|
+
async track(params) {
|
|
3015
|
+
await ready;
|
|
3016
|
+
return storefrontApi.activity.track(params);
|
|
3017
|
+
}
|
|
3018
|
+
};
|
|
3031
3019
|
function setMarket(key) {
|
|
3032
|
-
|
|
3020
|
+
sessionPromise = null;
|
|
3021
|
+
return session(key);
|
|
3033
3022
|
}
|
|
3034
3023
|
return {
|
|
3035
|
-
|
|
3024
|
+
session,
|
|
3036
3025
|
stores,
|
|
3037
3026
|
business: storefrontApi.business,
|
|
3038
3027
|
cms: storefrontApi.cms,
|
|
3039
3028
|
eshop: storefrontApi.eshop,
|
|
3040
3029
|
booking: storefrontApi.booking,
|
|
3041
3030
|
crm: storefrontApi.crm,
|
|
3042
|
-
activity
|
|
3031
|
+
activity,
|
|
3032
|
+
ready,
|
|
3043
3033
|
automation: storefrontApi.automation,
|
|
3044
3034
|
setBusinessId: (businessId) => {
|
|
3045
3035
|
refresh_business_id = businessId;
|