arky-sdk 0.7.63 → 0.7.65

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.d.cts CHANGED
@@ -5,7 +5,7 @@ import { f as formatPayment, a as formatMinor, g as getCurrencySymbol, b as getC
5
5
  interface AuthTokens {
6
6
  accessToken: string;
7
7
  refreshToken?: string;
8
- expiresAt?: number;
8
+ accessExpiresAt?: number;
9
9
  accountId?: string;
10
10
  }
11
11
  interface HttpClientConfig {
@@ -148,7 +148,7 @@ declare global {
148
148
  }
149
149
  declare function track(eventName: string, params?: Record<string, any>): void;
150
150
 
151
- declare const SDK_VERSION = "0.7.63";
151
+ declare const SDK_VERSION = "0.7.65";
152
152
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
153
153
  interface ApiConfig {
154
154
  httpClient: any;
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ import { f as formatPayment, a as formatMinor, g as getCurrencySymbol, b as getC
5
5
  interface AuthTokens {
6
6
  accessToken: string;
7
7
  refreshToken?: string;
8
- expiresAt?: number;
8
+ accessExpiresAt?: number;
9
9
  accountId?: string;
10
10
  }
11
11
  interface HttpClientConfig {
@@ -148,7 +148,7 @@ declare global {
148
148
  }
149
149
  declare function track(eventName: string, params?: Record<string, any>): void;
150
150
 
151
- declare const SDK_VERSION = "0.7.63";
151
+ declare const SDK_VERSION = "0.7.65";
152
152
  declare const SUPPORTED_FRAMEWORKS: readonly ["astro", "react", "vue", "svelte", "vanilla"];
153
153
  interface ApiConfig {
154
154
  httpClient: any;
package/dist/index.js CHANGED
@@ -87,9 +87,9 @@ function createHttpClient(cfg) {
87
87
  "Content-Type": "application/json",
88
88
  ...options?.headers || {}
89
89
  };
90
- let { accessToken, expiresAt } = await cfg.getToken();
90
+ let { accessToken, accessExpiresAt } = await cfg.getToken();
91
91
  const nowSec = Date.now() / 1e3;
92
- if (expiresAt && nowSec > expiresAt) {
92
+ if (accessExpiresAt && nowSec > accessExpiresAt) {
93
93
  await ensureFreshToken();
94
94
  const tokens = await cfg.getToken();
95
95
  accessToken = tokens.accessToken;
@@ -2712,7 +2712,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
2712
2712
  }
2713
2713
 
2714
2714
  // src/index.ts
2715
- var SDK_VERSION = "0.7.63";
2715
+ var SDK_VERSION = "0.7.65";
2716
2716
  var SUPPORTED_FRAMEWORKS = [
2717
2717
  "astro",
2718
2718
  "react",
@@ -2983,16 +2983,36 @@ async function createStorefront(config) {
2983
2983
  getToken: config.getToken
2984
2984
  };
2985
2985
  const storefrontApi = createStorefrontApi(apiConfig);
2986
- if (typeof window !== "undefined" && apiConfig.businessId) {
2987
- storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
2988
- if (!configs) return;
2989
- for (const c of Array.isArray(configs) ? configs : [configs]) {
2990
- if (c.measurementId) {
2991
- injectGA4Script(c.measurementId);
2992
- }
2986
+ let sessionPromise = null;
2987
+ function ensureSession() {
2988
+ if (typeof window === "undefined") return Promise.resolve();
2989
+ if (sessionPromise) return sessionPromise;
2990
+ sessionPromise = (async () => {
2991
+ const tokens = await apiConfig.getToken();
2992
+ if (tokens.accessToken) return;
2993
+ const result = await storefrontApi.crm.customer.initialize();
2994
+ if (result?.accessToken) {
2995
+ apiConfig.setToken(result);
2993
2996
  }
2994
- }).catch(() => {
2997
+ })().finally(() => {
2998
+ sessionPromise = null;
2999
+ });
3000
+ return sessionPromise;
3001
+ }
3002
+ if (typeof window !== "undefined") {
3003
+ ensureSession().catch(() => {
2995
3004
  });
3005
+ if (apiConfig.businessId) {
3006
+ storefrontApi.business.getIntegrationConfig({ businessId: apiConfig.businessId, type: "analytics" }).then((configs) => {
3007
+ if (!configs) return;
3008
+ for (const c of Array.isArray(configs) ? configs : [configs]) {
3009
+ if (c.measurementId) {
3010
+ injectGA4Script(c.measurementId);
3011
+ }
3012
+ }
3013
+ }).catch(() => {
3014
+ });
3015
+ }
2996
3016
  }
2997
3017
  return {
2998
3018
  business: storefrontApi.business,