arky-sdk 0.9.20 → 0.10.0

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/admin.d.cts CHANGED
@@ -1,3 +1,5 @@
1
- export { a3 as AdminSession, a0 as ApiConfig, A as AuthStateListener, a6 as CreateAdminConfig, a7 as createAdmin } from './admin-DB_GYW2b.cjs';
2
- export { am as AuthStorage, al as HttpClientConfig } from './api-C_2AMzmc.cjs';
3
- import './inventory-DgPpeRWU.cjs';
1
+ export { AdminSession, ApiConfig, AuthStateListener, CreateAdminConfig, createAdmin } from './index.cjs';
2
+ export { aE as AuthStorage, aG as HttpClientConfig } from './index-B0Pd1s-2.cjs';
3
+ import './inventory-t9OBR0CC.cjs';
4
+ import 'nanostores';
5
+ import '@stripe/stripe-js';
package/dist/admin.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export { a3 as AdminSession, a0 as ApiConfig, A as AuthStateListener, a6 as CreateAdminConfig, a7 as createAdmin } from './admin-CTtJoarO.js';
2
- export { am as AuthStorage, al as HttpClientConfig } from './api-C_2AMzmc.js';
3
- import './inventory-DdgZ5MI_.js';
1
+ export { AdminSession, ApiConfig, AuthStateListener, CreateAdminConfig, createAdmin } from './index.js';
2
+ export { aE as AuthStorage, aG as HttpClientConfig } from './index-B0Pd1s-2.js';
3
+ import './inventory-C2EZEnV9.js';
4
+ import 'nanostores';
5
+ import '@stripe/stripe-js';
package/dist/admin.js CHANGED
@@ -1,3 +1,5 @@
1
+ import 'nanostores';
2
+
1
3
  // src/utils/queryParams.ts
2
4
  function buildQueryString(params) {
3
5
  const queryParts = Object.entries(params).flatMap(
@@ -25,6 +27,15 @@ function requestError(name, message, details = {}) {
25
27
  function isRecord(value) {
26
28
  return typeof value === "object" && value !== null;
27
29
  }
30
+ function omitStorefrontRouting(value) {
31
+ if (!isRecord(value) || Array.isArray(value)) return value;
32
+ const prototype = Object.getPrototypeOf(value);
33
+ if (prototype !== Object.prototype && prototype !== null) return value;
34
+ const result = { ...value };
35
+ delete result.store_id;
36
+ delete result.market;
37
+ return result;
38
+ }
28
39
  function isTokenSet(value) {
29
40
  return isRecord(value) && typeof value.access_token === "string" && (value.refresh_token === void 0 || typeof value.refresh_token === "string") && (value.access_expires_at === void 0 || typeof value.access_expires_at === "number");
30
41
  }
@@ -100,10 +111,25 @@ function createHttpClient(cfg) {
100
111
  if (!retried && options?.transformRequest) {
101
112
  body = options.transformRequest(body);
102
113
  }
114
+ if (cfg.storefrontMode) {
115
+ body = omitStorefrontRouting(body);
116
+ }
117
+ const forcedHeaders = typeof cfg.forcedHeaders === "function" ? cfg.forcedHeaders() : cfg.forcedHeaders || {};
118
+ const callerHeaders = { ...options?.headers || {} };
119
+ const protectedHeaderNames = new Set(
120
+ Object.keys(forcedHeaders).map((name) => name.toLowerCase())
121
+ );
122
+ if (cfg.storefrontMode) protectedHeaderNames.add("authorization");
123
+ for (const name of Object.keys(callerHeaders)) {
124
+ if (protectedHeaderNames.has(name.toLowerCase())) {
125
+ delete callerHeaders[name];
126
+ }
127
+ }
103
128
  const headers = {
104
129
  Accept: "application/json",
105
130
  "Content-Type": "application/json",
106
- ...options?.headers || {}
131
+ ...callerHeaders,
132
+ ...forcedHeaders
107
133
  };
108
134
  let tokens = authStorage.getTokens();
109
135
  const nowSec = Date.now() / 1e3;
@@ -114,7 +140,8 @@ function createHttpClient(cfg) {
114
140
  if (tokens?.access_token) {
115
141
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
116
142
  }
117
- const finalPath = options?.params ? path + buildQueryString(options.params) : path;
143
+ const requestParams = cfg.storefrontMode ? omitStorefrontRouting(options?.params) : options?.params;
144
+ const finalPath = requestParams ? path + buildQueryString(requestParams) : path;
118
145
  const fetchOptions = {
119
146
  method,
120
147
  headers,
@@ -145,8 +172,19 @@ function createHttpClient(cfg) {
145
172
  throw err;
146
173
  }
147
174
  if (res.status === 401 && !retried) {
148
- await ensureFreshToken();
149
- return request(method, path, body, options, true);
175
+ if (cfg.onUnauthorized) {
176
+ const recovered = await cfg.onUnauthorized({
177
+ hadAuthorization: Boolean(tokens?.access_token),
178
+ authorizationToken: tokens?.access_token || null,
179
+ path
180
+ });
181
+ if (recovered) {
182
+ return request(method, path, body, options, true);
183
+ }
184
+ } else {
185
+ await ensureFreshToken();
186
+ return request(method, path, body, options, true);
187
+ }
150
188
  }
151
189
  try {
152
190
  const contentLength = res.headers.get("content-length");
@@ -362,6 +400,14 @@ var createStoreApi = (apiConfig, _updateSession) => {
362
400
  params
363
401
  });
364
402
  },
403
+ async regeneratePublishableKey(params = {}, options) {
404
+ const store_id = params.store_id || apiConfig.storeId;
405
+ return apiConfig.httpClient.post(
406
+ `/v1/stores/${store_id}/publishable-key/regenerate`,
407
+ {},
408
+ options
409
+ );
410
+ },
365
411
  async getSubscriptionPlans(_params, options) {
366
412
  return apiConfig.httpClient.get("/v1/stores/plans", options);
367
413
  },
@@ -1260,7 +1306,10 @@ var createMarketApi = (apiConfig) => {
1260
1306
  async delete(params, options) {
1261
1307
  return apiConfig.httpClient.delete(
1262
1308
  `/v1/stores/${apiConfig.storeId}/markets/${params.id}`,
1263
- options
1309
+ {
1310
+ ...options,
1311
+ params: params.replacement_default_market_id ? { replacement_default_market_id: params.replacement_default_market_id } : options?.params
1312
+ }
1264
1313
  );
1265
1314
  }
1266
1315
  };
@@ -3506,6 +3555,7 @@ function createAdmin(config) {
3506
3555
  update: storeApi.updateStore,
3507
3556
  get: storeApi.getStore,
3508
3557
  find: storeApi.getStores,
3558
+ regeneratePublishableKey: storeApi.regeneratePublishableKey,
3509
3559
  subscription: {
3510
3560
  get: storeApi.getSubscription,
3511
3561
  getPlans: storeApi.getSubscriptionPlans,