arky-sdk 0.7.95 → 0.7.104

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 CHANGED
@@ -401,7 +401,7 @@ var createStorefrontApi = (apiConfig) => {
401
401
  const items = paramItems || groupCartToItems(cart);
402
402
  return apiConfig.httpClient.post(
403
403
  `${base(target_store_id)}/bookings/checkout`,
404
- { market: "booking", ...payload, items },
404
+ { market: apiConfig.market, ...payload, items },
405
405
  options
406
406
  );
407
407
  },
@@ -424,7 +424,7 @@ var createStorefrontApi = (apiConfig) => {
424
424
  const target_store_id = store_id || apiConfig.storeId;
425
425
  return apiConfig.httpClient.post(
426
426
  `${base(target_store_id)}/bookings/quote`,
427
- { market: "booking", ...payload },
427
+ { market: apiConfig.market, ...payload },
428
428
  options
429
429
  );
430
430
  },
@@ -503,61 +503,46 @@ var createStorefrontApi = (apiConfig) => {
503
503
  },
504
504
  crm: {
505
505
  customer: {
506
- async session(params, options) {
507
- const store_id = params?.store_id || apiConfig.storeId;
508
- const result = await apiConfig.httpClient.post(
509
- `${base(store_id)}/customers/session`,
510
- { store_id, market: params?.market || apiConfig.market || null },
511
- options
512
- );
513
- if (result?.token?.access_token) {
514
- apiConfig.setToken(result.token);
515
- }
516
- return result;
517
- },
518
- async connect(params, options) {
519
- const store_id = params.store_id || apiConfig.storeId;
506
+ async identify(params, options) {
507
+ const store_id = apiConfig.storeId;
520
508
  const result = await apiConfig.httpClient.post(
521
- `${base(store_id)}/customers/connect`,
522
- { email: params.email, store_id },
509
+ `${base(store_id)}/customers/identify`,
510
+ {
511
+ store_id,
512
+ market: params?.market || apiConfig.market || null,
513
+ email: params?.email,
514
+ verify: params?.verify ?? false
515
+ },
523
516
  options
524
517
  );
525
- if (result?.access_token) {
526
- apiConfig.setToken(result);
518
+ if (result?.token?.token) {
519
+ apiConfig.setToken({ access_token: result.token.token });
527
520
  }
528
521
  return result;
529
522
  },
530
- requestCode(params, options) {
531
- const store_id = params.store_id || apiConfig.storeId;
532
- return apiConfig.httpClient.post(
533
- `${base(store_id)}/customers/auth/code`,
534
- { email: params.email, store_id },
535
- options
536
- );
537
- },
538
523
  async verify(params, options) {
539
- const store_id = params.store_id || apiConfig.storeId;
524
+ const store_id = apiConfig.storeId;
540
525
  const result = await apiConfig.httpClient.post(
541
- `${base(store_id)}/customers/auth/verify`,
542
- { email: params.email, code: params.code, store_id },
526
+ `${base(store_id)}/customers/verify`,
527
+ { store_id, code: params.code },
543
528
  options
544
529
  );
545
- if (result?.access_token) {
546
- apiConfig.setToken(result);
530
+ if (result?.token) {
531
+ apiConfig.setToken({ access_token: result.token });
547
532
  }
548
533
  return result;
549
534
  },
550
- async refreshToken(params, options) {
551
- const store_id = params.store_id || apiConfig.storeId;
552
- const result = await apiConfig.httpClient.post(
553
- `${base(store_id)}/customers/auth/refresh`,
554
- { refresh_token: params.refresh_token },
555
- options
556
- );
557
- if (result?.access_token) {
558
- apiConfig.setToken(result);
535
+ async logout(options) {
536
+ const store_id = apiConfig.storeId;
537
+ try {
538
+ await apiConfig.httpClient.post(
539
+ `${base(store_id)}/customers/logout`,
540
+ {},
541
+ options
542
+ );
543
+ } finally {
544
+ apiConfig.setToken({ access_token: "" });
559
545
  }
560
- return result;
561
546
  },
562
547
  getMe(options) {
563
548
  return apiConfig.httpClient.get(`${base()}/customers/me`, options);
@@ -718,36 +703,31 @@ function buildQueryString(params) {
718
703
  }
719
704
 
720
705
  // src/services/createHttpClient.ts
721
- var STORAGE_KEYS = {
722
- access_token: "arky_token",
723
- refresh_token: "arky_refresh",
724
- access_expires_at: "arky_expires_at"
725
- };
706
+ var TOKEN_KEY = "arky_token";
707
+ var LEGACY_KEYS = ["arky_refresh", "arky_expires_at"];
726
708
  function defaultGetToken() {
727
709
  if (typeof window === "undefined") return { access_token: "" };
728
710
  return {
729
- access_token: localStorage.getItem(STORAGE_KEYS.access_token) || "",
730
- refresh_token: localStorage.getItem(STORAGE_KEYS.refresh_token) || "",
731
- access_expires_at: parseInt(localStorage.getItem(STORAGE_KEYS.access_expires_at) || "0", 10)
711
+ access_token: localStorage.getItem(TOKEN_KEY) || ""
732
712
  };
733
713
  }
734
714
  function defaultSetToken(tokens) {
735
715
  if (typeof window === "undefined") return;
736
716
  if (tokens.access_token) {
737
- localStorage.setItem(STORAGE_KEYS.access_token, tokens.access_token);
738
- localStorage.setItem(STORAGE_KEYS.refresh_token, tokens.refresh_token || "");
739
- localStorage.setItem(STORAGE_KEYS.access_expires_at, (tokens.access_expires_at || 0).toString());
717
+ localStorage.setItem(TOKEN_KEY, tokens.access_token);
740
718
  } else {
741
- Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
719
+ localStorage.removeItem(TOKEN_KEY);
742
720
  }
721
+ LEGACY_KEYS.forEach((key) => localStorage.removeItem(key));
743
722
  }
744
723
  function defaultLogout() {
745
724
  if (typeof window === "undefined") return;
746
- Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
725
+ localStorage.removeItem(TOKEN_KEY);
726
+ LEGACY_KEYS.forEach((key) => localStorage.removeItem(key));
747
727
  }
748
728
  function defaultIsAuthenticated() {
749
729
  if (typeof window === "undefined") return false;
750
- const token = localStorage.getItem(STORAGE_KEYS.access_token) || "";
730
+ const token = localStorage.getItem(TOKEN_KEY) || "";
751
731
  return token.startsWith("customer_") || token.startsWith("account_");
752
732
  }
753
733
  function createHttpClient(cfg) {
@@ -929,10 +909,10 @@ var createAccountApi = (apiConfig) => {
929
909
  if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
930
910
  return apiConfig.httpClient.put("/v1/accounts", payload, options);
931
911
  },
932
- async deleteAccount(params, options) {
912
+ async deleteAccount(_params, options) {
933
913
  return apiConfig.httpClient.delete("/v1/accounts", options);
934
914
  },
935
- async getMe(params, options) {
915
+ async getMe(_params, options) {
936
916
  return apiConfig.httpClient.get("/v1/accounts/me", options);
937
917
  },
938
918
  async searchAccounts(params, options) {
@@ -954,9 +934,13 @@ var createAuthApi = (apiConfig) => {
954
934
  return apiConfig.httpClient.post("/v1/auth/code", params, options);
955
935
  },
956
936
  async verify(params, options) {
957
- const result = await apiConfig.httpClient.post("/v1/auth/verify", params, options);
937
+ const result = await apiConfig.httpClient.post(
938
+ "/v1/auth/verify",
939
+ params,
940
+ options
941
+ );
958
942
  if (result?.access_token) {
959
- apiConfig.setToken({ ...result, email: params.email, is_verified: true });
943
+ apiConfig.setToken({ access_token: result.access_token, refresh_token: result.refresh_token });
960
944
  }
961
945
  return result;
962
946
  },
@@ -967,9 +951,13 @@ var createAuthApi = (apiConfig) => {
967
951
  return apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/code`, params, options);
968
952
  },
969
953
  async storeVerify(storeId, params, options) {
970
- const result = await apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/verify`, params, options);
954
+ const result = await apiConfig.httpClient.post(
955
+ `/v1/stores/${storeId}/auth/verify`,
956
+ params,
957
+ options
958
+ );
971
959
  if (result?.access_token) {
972
- apiConfig.setToken({ ...result, email: params.email, is_verified: true });
960
+ apiConfig.setToken({ access_token: result.access_token, refresh_token: result.refresh_token });
973
961
  }
974
962
  return result;
975
963
  },
@@ -998,7 +986,7 @@ var createStoreApi = (apiConfig) => {
998
986
  options
999
987
  );
1000
988
  },
1001
- async getStore(params, options) {
989
+ async getStore(_params, options) {
1002
990
  return apiConfig.httpClient.get(
1003
991
  `/v1/stores/${apiConfig.storeId}`,
1004
992
  options
@@ -1010,7 +998,7 @@ var createStoreApi = (apiConfig) => {
1010
998
  params
1011
999
  });
1012
1000
  },
1013
- async getSubscriptionPlans(params, options) {
1001
+ async getSubscriptionPlans(_params, options) {
1014
1002
  return apiConfig.httpClient.get("/v1/stores/plans", options);
1015
1003
  },
1016
1004
  async subscribe(params, options) {
@@ -1162,7 +1150,7 @@ var createMediaApi = (apiConfig) => {
1162
1150
  options
1163
1151
  );
1164
1152
  },
1165
- async uploadStoreMedia(params, options) {
1153
+ async uploadStoreMedia(params, _options) {
1166
1154
  const { store_id, files = [], urls = [] } = params;
1167
1155
  const target_store_id = store_id || apiConfig.storeId;
1168
1156
  const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
@@ -1189,7 +1177,7 @@ var createMediaApi = (apiConfig) => {
1189
1177
  options
1190
1178
  );
1191
1179
  },
1192
- async getStoreMedia(params, options) {
1180
+ async getStoreMedia(params, _options) {
1193
1181
  const { store_id, cursor, limit, ids, query, mime_type, sort_field, sort_direction } = params;
1194
1182
  const target_store_id = store_id || apiConfig.storeId;
1195
1183
  const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
@@ -1511,7 +1499,7 @@ var createBookingApi = (apiConfig) => {
1511
1499
  const target_store_id = store_id || apiConfig.storeId;
1512
1500
  return apiConfig.httpClient.post(
1513
1501
  `/v1/stores/${target_store_id}/bookings`,
1514
- { market: "booking", ...payload },
1502
+ { market: apiConfig.market, ...payload },
1515
1503
  options
1516
1504
  );
1517
1505
  },
@@ -1546,7 +1534,7 @@ var createBookingApi = (apiConfig) => {
1546
1534
  const target_store_id = store_id || apiConfig.storeId;
1547
1535
  return apiConfig.httpClient.post(
1548
1536
  `/v1/stores/${target_store_id}/bookings/quote`,
1549
- { market: "booking", ...payload },
1537
+ { market: apiConfig.market, ...payload },
1550
1538
  options
1551
1539
  );
1552
1540
  },
@@ -2633,7 +2621,7 @@ function getFirstAvailableFCId(variant, quantity = 1) {
2633
2621
  }
2634
2622
 
2635
2623
  // src/index.ts
2636
- var SDK_VERSION = "0.7.95";
2624
+ var SDK_VERSION = "0.7.104";
2637
2625
  var SUPPORTED_FRAMEWORKS = [
2638
2626
  "astro",
2639
2627
  "react",
@@ -2887,13 +2875,11 @@ function createStorefront(config) {
2887
2875
  const setToken = config.setToken || defaultSetToken;
2888
2876
  const logout = config.logout || defaultLogout;
2889
2877
  const isAuthenticated = config.isAuthenticated || defaultIsAuthenticated;
2890
- let refresh_store_id = config.storeId;
2891
2878
  const httpClient = createHttpClient({
2892
2879
  ...config,
2893
2880
  getToken,
2894
2881
  setToken,
2895
- logout,
2896
- refreshPath: () => `/v1/storefront/${refresh_store_id}/customers/auth/refresh`
2882
+ logout
2897
2883
  });
2898
2884
  const apiConfig = {
2899
2885
  httpClient,
@@ -2909,9 +2895,9 @@ function createStorefront(config) {
2909
2895
  let currentSession = null;
2910
2896
  const sessionListeners = /* @__PURE__ */ new Set();
2911
2897
  const customerApi = storefrontApi.crm.customer;
2912
- function emitSessionChange(session2) {
2898
+ function emitSessionChange(session) {
2913
2899
  for (const listener of sessionListeners) {
2914
- Promise.resolve().then(() => listener(session2)).catch(() => {
2900
+ Promise.resolve().then(() => listener(session)).catch(() => {
2915
2901
  });
2916
2902
  }
2917
2903
  }
@@ -2935,22 +2921,26 @@ function createStorefront(config) {
2935
2921
  clearSession();
2936
2922
  return result;
2937
2923
  }
2938
- function session(market2) {
2939
- if (market2 !== void 0) apiConfig.market = market2;
2940
- if (sessionPromise) return sessionPromise;
2941
- sessionPromise = (async () => {
2924
+ function identify(params) {
2925
+ if (params?.market !== void 0) apiConfig.market = params.market;
2926
+ const isBareCall = !params?.email && !params?.verify;
2927
+ if (isBareCall && sessionPromise) return sessionPromise;
2928
+ const promise = (async () => {
2942
2929
  try {
2943
- const result = await customerApi.session({
2944
- market: apiConfig.market
2930
+ const result = await customerApi.identify({
2931
+ market: apiConfig.market,
2932
+ email: params?.email,
2933
+ verify: params?.verify
2945
2934
  });
2946
2935
  return setCurrentSessionFromResult(result);
2947
2936
  } catch (err) {
2948
- const status = err?.statusCode || err?.status || err?.response?.status;
2949
- if (status === 401) {
2937
+ const e = err;
2938
+ const status = e?.statusCode || e?.status || e?.response?.status;
2939
+ if (isBareCall && status === 401) {
2950
2940
  currentSession = null;
2951
2941
  emitSessionChange(null);
2952
- await setToken({ access_token: "", refresh_token: "", access_expires_at: 0 });
2953
- const result = await customerApi.session({
2942
+ await setToken({ access_token: "" });
2943
+ const result = await customerApi.identify({
2954
2944
  market: apiConfig.market
2955
2945
  });
2956
2946
  return setCurrentSessionFromResult(result);
@@ -2958,10 +2948,11 @@ function createStorefront(config) {
2958
2948
  throw err;
2959
2949
  }
2960
2950
  })().catch((err) => {
2961
- sessionPromise = null;
2951
+ if (isBareCall) sessionPromise = null;
2962
2952
  throw err;
2963
2953
  });
2964
- return sessionPromise;
2954
+ if (isBareCall) sessionPromise = promise;
2955
+ return promise;
2965
2956
  }
2966
2957
  function setMarket(key) {
2967
2958
  apiConfig.market = key;
@@ -2980,10 +2971,6 @@ function createStorefront(config) {
2980
2971
  function getSession() {
2981
2972
  return currentSession;
2982
2973
  }
2983
- function logoutAndClearSession() {
2984
- clearSession();
2985
- return logout();
2986
- }
2987
2974
  function setTokenAndClearSession(tokens) {
2988
2975
  setToken(tokens);
2989
2976
  clearSession();
@@ -2992,17 +2979,33 @@ function createStorefront(config) {
2992
2979
  ...storefrontApi.crm,
2993
2980
  customer: {
2994
2981
  ...customerApi,
2995
- async session(params, options) {
2996
- const result = await customerApi.session(params, options);
2982
+ async identify(params, options) {
2983
+ const result = await customerApi.identify(params, options);
2997
2984
  setCurrentSessionFromResult(result);
2998
2985
  return result;
2999
2986
  },
3000
- connect: (params, options) => invalidateAfterAuth(customerApi.connect(params, options)),
3001
2987
  verify: (params, options) => invalidateAfterAuth(customerApi.verify(params, options))
3002
2988
  }
3003
2989
  };
2990
+ async function verify(params) {
2991
+ const result = await invalidateAfterAuth(customerApi.verify(params));
2992
+ return result;
2993
+ }
2994
+ async function me() {
2995
+ return customerApi.getMe();
2996
+ }
2997
+ async function logoutCustomer() {
2998
+ try {
2999
+ await customerApi.logout();
3000
+ } finally {
3001
+ clearSession();
3002
+ }
3003
+ }
3004
3004
  return {
3005
- session,
3005
+ identify,
3006
+ verify,
3007
+ me,
3008
+ logout: logoutCustomer,
3006
3009
  getSession,
3007
3010
  onSessionChange,
3008
3011
  store: storefrontApi.store,
@@ -3013,7 +3016,6 @@ function createStorefront(config) {
3013
3016
  activity: storefrontApi.activity,
3014
3017
  automation: storefrontApi.automation,
3015
3018
  setStoreId: (storeId) => {
3016
- refresh_store_id = storeId;
3017
3019
  apiConfig.storeId = storeId;
3018
3020
  clearSession();
3019
3021
  },
@@ -3025,7 +3027,6 @@ function createStorefront(config) {
3025
3027
  },
3026
3028
  getLocale: () => apiConfig.locale,
3027
3029
  isAuthenticated,
3028
- logout: logoutAndClearSession,
3029
3030
  setToken: setTokenAndClearSession,
3030
3031
  extractBlockValues,
3031
3032
  utils: createUtilitySurface(apiConfig)