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/README.md CHANGED
@@ -383,6 +383,20 @@ import type {
383
383
  } from 'arky-sdk'
384
384
  ```
385
385
 
386
+ ## Adding a new endpoint
387
+
388
+ When adding a new SDK method, follow this checklist so the API surface stays typed end-to-end and request shapes stay aligned with the Rust DTOs on the server:
389
+
390
+ 1. **Define the entity** in `src/types/index.ts` if it does not already exist. Mirror the Rust response struct field-for-field.
391
+ 2. **Define the request params** in `src/types/api.ts`. Mirror the Rust DTO in `server/core/src/{module}/types/commands.rs` field-for-field. Two exceptions: `store_id?: string` and `market?: string` are optional in TS (the SDK auto-fills both from `apiConfig.storeId` and `apiConfig.market`). Do **not** use `[key: string]: any` index signatures.
392
+ 3. **Annotate the SDK method's return type** using the matching entity from `src/types/index.ts`.
393
+ 4. **Pass the response generic to the HTTP call**: `apiConfig.httpClient.post<EntityType>(...)`, `apiConfig.httpClient.get<PaginatedResponse<EntityType>>(...)`, etc. Never rely on inference.
394
+ 5. **Inject `market` from `apiConfig`**: when a body needs a `market` field, write `{ market: apiConfig.market, ...payload }`. Never hardcode `"booking"`, `"eshop"`, or any other market string in `src/api/*.ts`.
395
+ 6. **Re-export the entity** from `src/index.ts` if consumers (admin, storefront) will import it.
396
+ 7. **Bump `SDK_VERSION`** in `src/index.ts` and the `version` in `package.json`. Patch only.
397
+
398
+ A guardrail script (`scripts/check-no-any.mjs`) runs on `npm run build` (via `prebuild`) and fails red if `: any`, `as any`, or hardcoded `market: "..."` literals show up in `src/api/*.ts`.
399
+
386
400
  ## License
387
401
 
388
402
  MIT
package/dist/admin.cjs CHANGED
@@ -164,36 +164,31 @@ function buildQueryString(params) {
164
164
  }
165
165
 
166
166
  // src/services/createHttpClient.ts
167
- var STORAGE_KEYS = {
168
- access_token: "arky_token",
169
- refresh_token: "arky_refresh",
170
- access_expires_at: "arky_expires_at"
171
- };
167
+ var TOKEN_KEY = "arky_token";
168
+ var LEGACY_KEYS = ["arky_refresh", "arky_expires_at"];
172
169
  function defaultGetToken() {
173
170
  if (typeof window === "undefined") return { access_token: "" };
174
171
  return {
175
- access_token: localStorage.getItem(STORAGE_KEYS.access_token) || "",
176
- refresh_token: localStorage.getItem(STORAGE_KEYS.refresh_token) || "",
177
- access_expires_at: parseInt(localStorage.getItem(STORAGE_KEYS.access_expires_at) || "0", 10)
172
+ access_token: localStorage.getItem(TOKEN_KEY) || ""
178
173
  };
179
174
  }
180
175
  function defaultSetToken(tokens) {
181
176
  if (typeof window === "undefined") return;
182
177
  if (tokens.access_token) {
183
- localStorage.setItem(STORAGE_KEYS.access_token, tokens.access_token);
184
- localStorage.setItem(STORAGE_KEYS.refresh_token, tokens.refresh_token || "");
185
- localStorage.setItem(STORAGE_KEYS.access_expires_at, (tokens.access_expires_at || 0).toString());
178
+ localStorage.setItem(TOKEN_KEY, tokens.access_token);
186
179
  } else {
187
- Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
180
+ localStorage.removeItem(TOKEN_KEY);
188
181
  }
182
+ LEGACY_KEYS.forEach((key) => localStorage.removeItem(key));
189
183
  }
190
184
  function defaultLogout() {
191
185
  if (typeof window === "undefined") return;
192
- Object.values(STORAGE_KEYS).forEach((key) => localStorage.removeItem(key));
186
+ localStorage.removeItem(TOKEN_KEY);
187
+ LEGACY_KEYS.forEach((key) => localStorage.removeItem(key));
193
188
  }
194
189
  function defaultIsAuthenticated() {
195
190
  if (typeof window === "undefined") return false;
196
- const token = localStorage.getItem(STORAGE_KEYS.access_token) || "";
191
+ const token = localStorage.getItem(TOKEN_KEY) || "";
197
192
  return token.startsWith("customer_") || token.startsWith("account_");
198
193
  }
199
194
  function createHttpClient(cfg) {
@@ -375,10 +370,10 @@ var createAccountApi = (apiConfig) => {
375
370
  if (params.api_tokens !== void 0) payload.api_tokens = params.api_tokens;
376
371
  return apiConfig.httpClient.put("/v1/accounts", payload, options);
377
372
  },
378
- async deleteAccount(params, options) {
373
+ async deleteAccount(_params, options) {
379
374
  return apiConfig.httpClient.delete("/v1/accounts", options);
380
375
  },
381
- async getMe(params, options) {
376
+ async getMe(_params, options) {
382
377
  return apiConfig.httpClient.get("/v1/accounts/me", options);
383
378
  },
384
379
  async searchAccounts(params, options) {
@@ -400,9 +395,13 @@ var createAuthApi = (apiConfig) => {
400
395
  return apiConfig.httpClient.post("/v1/auth/code", params, options);
401
396
  },
402
397
  async verify(params, options) {
403
- const result = await apiConfig.httpClient.post("/v1/auth/verify", params, options);
398
+ const result = await apiConfig.httpClient.post(
399
+ "/v1/auth/verify",
400
+ params,
401
+ options
402
+ );
404
403
  if (result?.access_token) {
405
- apiConfig.setToken({ ...result, email: params.email, is_verified: true });
404
+ apiConfig.setToken({ access_token: result.access_token, refresh_token: result.refresh_token });
406
405
  }
407
406
  return result;
408
407
  },
@@ -413,9 +412,13 @@ var createAuthApi = (apiConfig) => {
413
412
  return apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/code`, params, options);
414
413
  },
415
414
  async storeVerify(storeId, params, options) {
416
- const result = await apiConfig.httpClient.post(`/v1/stores/${storeId}/auth/verify`, params, options);
415
+ const result = await apiConfig.httpClient.post(
416
+ `/v1/stores/${storeId}/auth/verify`,
417
+ params,
418
+ options
419
+ );
417
420
  if (result?.access_token) {
418
- apiConfig.setToken({ ...result, email: params.email, is_verified: true });
421
+ apiConfig.setToken({ access_token: result.access_token, refresh_token: result.refresh_token });
419
422
  }
420
423
  return result;
421
424
  },
@@ -444,7 +447,7 @@ var createStoreApi = (apiConfig) => {
444
447
  options
445
448
  );
446
449
  },
447
- async getStore(params, options) {
450
+ async getStore(_params, options) {
448
451
  return apiConfig.httpClient.get(
449
452
  `/v1/stores/${apiConfig.storeId}`,
450
453
  options
@@ -456,7 +459,7 @@ var createStoreApi = (apiConfig) => {
456
459
  params
457
460
  });
458
461
  },
459
- async getSubscriptionPlans(params, options) {
462
+ async getSubscriptionPlans(_params, options) {
460
463
  return apiConfig.httpClient.get("/v1/stores/plans", options);
461
464
  },
462
465
  async subscribe(params, options) {
@@ -608,7 +611,7 @@ var createMediaApi = (apiConfig) => {
608
611
  options
609
612
  );
610
613
  },
611
- async uploadStoreMedia(params, options) {
614
+ async uploadStoreMedia(params, _options) {
612
615
  const { store_id, files = [], urls = [] } = params;
613
616
  const target_store_id = store_id || apiConfig.storeId;
614
617
  const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
@@ -635,7 +638,7 @@ var createMediaApi = (apiConfig) => {
635
638
  options
636
639
  );
637
640
  },
638
- async getStoreMedia(params, options) {
641
+ async getStoreMedia(params, _options) {
639
642
  const { store_id, cursor, limit, ids, query, mime_type, sort_field, sort_direction } = params;
640
643
  const target_store_id = store_id || apiConfig.storeId;
641
644
  const url = `${apiConfig.baseUrl}/v1/stores/${target_store_id}/media`;
@@ -957,7 +960,7 @@ var createBookingApi = (apiConfig) => {
957
960
  const target_store_id = store_id || apiConfig.storeId;
958
961
  return apiConfig.httpClient.post(
959
962
  `/v1/stores/${target_store_id}/bookings`,
960
- { market: "booking", ...payload },
963
+ { market: apiConfig.market, ...payload },
961
964
  options
962
965
  );
963
966
  },
@@ -992,7 +995,7 @@ var createBookingApi = (apiConfig) => {
992
995
  const target_store_id = store_id || apiConfig.storeId;
993
996
  return apiConfig.httpClient.post(
994
997
  `/v1/stores/${target_store_id}/bookings/quote`,
995
- { market: "booking", ...payload },
998
+ { market: apiConfig.market, ...payload },
996
999
  options
997
1000
  );
998
1001
  },