@01.software/sdk 0.2.9-dev.260306.4e16dd4 → 0.2.9-dev.260309.c56872d

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.js CHANGED
@@ -113,6 +113,19 @@ var TimeoutError = class extends SDKError {
113
113
  this.name = "TimeoutError";
114
114
  }
115
115
  };
116
+ var GoneError = class extends SDKError {
117
+ constructor(message = "The requested resource is no longer available.", details, userMessage, suggestion) {
118
+ super("GONE_ERROR", message, 410, details, userMessage, suggestion);
119
+ this.name = "GoneError";
120
+ }
121
+ };
122
+ var ServiceUnavailableError = class extends SDKError {
123
+ constructor(message = "Service temporarily unavailable.", retryAfter, details, userMessage, suggestion) {
124
+ super("SERVICE_UNAVAILABLE_ERROR", message, 503, details, userMessage, suggestion);
125
+ this.name = "ServiceUnavailableError";
126
+ this.retryAfter = retryAfter;
127
+ }
128
+ };
116
129
  var UsageLimitError = class extends SDKError {
117
130
  constructor(message, usage, details, userMessage, suggestion) {
118
131
  super("USAGE_LIMIT_ERROR", message, 429, details, userMessage, suggestion);
@@ -143,6 +156,12 @@ function isConfigError(error) {
143
156
  function isTimeoutError(error) {
144
157
  return error instanceof TimeoutError;
145
158
  }
159
+ function isGoneError(error) {
160
+ return error instanceof GoneError;
161
+ }
162
+ function isServiceUnavailableError(error) {
163
+ return error instanceof ServiceUnavailableError;
164
+ }
146
165
  function isUsageLimitError(error) {
147
166
  return error instanceof UsageLimitError;
148
167
  }
@@ -156,8 +175,8 @@ var createUsageLimitError = (message, usage, details, userMessage, suggestion) =
156
175
  // src/core/client/types.ts
157
176
  var API_URLS = {
158
177
  local: "http://localhost:3000",
159
- development: "https://dev.01.software",
160
- staging: "https://stg.01.software",
178
+ development: "https://api-dev.01.software",
179
+ staging: "https://api-stg.01.software",
161
180
  production: "https://api.01.software"
162
181
  };
163
182
  function resolveApiUrl(config) {
@@ -286,7 +305,8 @@ function _fetch(url, options) {
286
305
  timeout = DEFAULT_TIMEOUT,
287
306
  baseUrl = API_URLS.production,
288
307
  debug,
289
- retry
308
+ retry,
309
+ onUnauthorized
290
310
  } = _a, requestInit = __objRest(_a, [
291
311
  "clientKey",
292
312
  "secretKey",
@@ -294,7 +314,8 @@ function _fetch(url, options) {
294
314
  "timeout",
295
315
  "baseUrl",
296
316
  "debug",
297
- "retry"
317
+ "retry",
318
+ "onUnauthorized"
298
319
  ]);
299
320
  const retryConfig = {
300
321
  maxRetries: (_b = retry == null ? void 0 : retry.maxRetries) != null ? _b : 3,
@@ -308,6 +329,7 @@ function _fetch(url, options) {
308
329
  authToken = customerToken;
309
330
  }
310
331
  let lastError;
332
+ let hasRetried401 = false;
311
333
  for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt++) {
312
334
  try {
313
335
  const headers = new Headers(requestInit.headers);
@@ -355,6 +377,17 @@ function _fetch(url, options) {
355
377
  "Upgrade your tenant plan to increase the monthly API call limit."
356
378
  );
357
379
  }
380
+ if (response.status === 401 && onUnauthorized && customerToken && !hasRetried401) {
381
+ hasRetried401 = true;
382
+ try {
383
+ const newToken = yield onUnauthorized();
384
+ if (newToken) {
385
+ authToken = newToken;
386
+ continue;
387
+ }
388
+ } catch (e) {
389
+ }
390
+ }
358
391
  if (NON_RETRYABLE_STATUSES.includes(response.status)) {
359
392
  throw createNetworkError(
360
393
  `HTTP ${response.status}: ${response.statusText}`,
@@ -507,6 +540,9 @@ var OrderApi = class {
507
540
  createFulfillment(params) {
508
541
  return this.request("/api/orders/create-fulfillment", params);
509
542
  }
543
+ updateFulfillment(params) {
544
+ return this.request("/api/orders/update-fulfillment", params);
545
+ }
510
546
  returnWithRefund(params) {
511
547
  return this.request("/api/returns/return-refund", params);
512
548
  }
@@ -516,6 +552,18 @@ var OrderApi = class {
516
552
  updateReturn(params) {
517
553
  return this.request("/api/returns/update", params);
518
554
  }
555
+ validateDiscount(params) {
556
+ return this.request("/api/discounts/validate", params);
557
+ }
558
+ calculateShipping(params) {
559
+ return this.request("/api/shipping-policies/calculate", params);
560
+ }
561
+ createExchange(params) {
562
+ return this.request("/api/exchanges/create", params);
563
+ }
564
+ updateExchange(params) {
565
+ return this.request("/api/exchanges/update", params);
566
+ }
519
567
  };
520
568
 
521
569
  // src/core/api/cart-api.ts
@@ -531,18 +579,18 @@ var CartApi = class {
531
579
  this.secretKey = options.secretKey;
532
580
  this.customerToken = options.customerToken;
533
581
  this.baseUrl = options.baseUrl;
582
+ this.onUnauthorized = options.onUnauthorized;
534
583
  }
535
- request(endpoint, body) {
584
+ execute(endpoint, method, body) {
536
585
  return __async(this, null, function* () {
537
586
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
538
- const response = yield _fetch(endpoint, {
539
- method: "POST",
587
+ const response = yield _fetch(endpoint, __spreadValues(__spreadValues({
588
+ method,
540
589
  clientKey: this.clientKey,
541
590
  secretKey: this.secretKey,
542
591
  customerToken: token != null ? token : void 0,
543
- baseUrl: this.baseUrl,
544
- body: JSON.stringify(body)
545
- });
592
+ baseUrl: this.baseUrl
593
+ }, token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized }), body !== void 0 && { body: JSON.stringify(body) }));
546
594
  let data;
547
595
  try {
548
596
  data = yield response.json();
@@ -568,14 +616,26 @@ var CartApi = class {
568
616
  return data;
569
617
  });
570
618
  }
619
+ getCart(cartId) {
620
+ return this.execute(`/api/carts/${cartId}`, "GET");
621
+ }
571
622
  addItem(params) {
572
- return this.request("/api/carts/add-item", params);
623
+ return this.execute("/api/carts/add-item", "POST", params);
573
624
  }
574
625
  updateItem(params) {
575
- return this.request("/api/carts/update-item", params);
626
+ return this.execute("/api/carts/update-item", "POST", params);
576
627
  }
577
628
  removeItem(params) {
578
- return this.request("/api/carts/remove-item", params);
629
+ return this.execute("/api/carts/remove-item", "POST", params);
630
+ }
631
+ applyDiscount(params) {
632
+ return this.execute("/api/carts/apply-discount", "POST", params);
633
+ }
634
+ removeDiscount(params) {
635
+ return this.execute("/api/carts/remove-discount", "POST", params);
636
+ }
637
+ clearCart(params) {
638
+ return this.execute("/api/carts/clear", "POST", params);
579
639
  }
580
640
  };
581
641
 
@@ -840,7 +900,7 @@ var CollectionQueryBuilder = class {
840
900
  // src/core/collection/http-client.ts
841
901
  import { stringify } from "qs-esm";
842
902
  var HttpClient = class {
843
- constructor(clientKey, secretKey, baseUrl, getCustomerToken) {
903
+ constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
844
904
  if (!clientKey) {
845
905
  throw createValidationError("clientKey is required.");
846
906
  }
@@ -848,6 +908,7 @@ var HttpClient = class {
848
908
  this.secretKey = secretKey;
849
909
  this.baseUrl = baseUrl;
850
910
  this.getCustomerToken = getCustomerToken;
911
+ this.onUnauthorized = onUnauthorized;
851
912
  }
852
913
  get defaultOptions() {
853
914
  var _a;
@@ -855,6 +916,9 @@ var HttpClient = class {
855
916
  const token = (_a = this.getCustomerToken) == null ? void 0 : _a.call(this);
856
917
  if (token) {
857
918
  opts.customerToken = token;
919
+ if (this.onUnauthorized) {
920
+ opts.onUnauthorized = this.onUnauthorized;
921
+ }
858
922
  }
859
923
  return opts;
860
924
  }
@@ -960,8 +1024,8 @@ function buildPayloadFormData(data, file, filename) {
960
1024
  return formData;
961
1025
  }
962
1026
  var CollectionClient = class extends HttpClient {
963
- constructor(clientKey, secretKey, baseUrl, getCustomerToken) {
964
- super(clientKey, secretKey, baseUrl, getCustomerToken);
1027
+ constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
1028
+ super(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized);
965
1029
  }
966
1030
  from(collection) {
967
1031
  return new CollectionQueryBuilder(this, collection);
@@ -1137,8 +1201,16 @@ var COLLECTIONS = [
1137
1201
  "playlists",
1138
1202
  "playlist-images",
1139
1203
  "musics",
1204
+ "galleries",
1205
+ "gallery-images",
1206
+ "gallery-categories",
1140
1207
  "flows",
1141
1208
  "flow-images",
1209
+ "flow-node-types",
1210
+ "flow-edge-types",
1211
+ "videos",
1212
+ "live-streams",
1213
+ "live-stream-images",
1142
1214
  "forms",
1143
1215
  "form-submissions",
1144
1216
  "media"
@@ -1148,6 +1220,7 @@ var COLLECTIONS = [
1148
1220
  var DEFAULT_TIMEOUT2 = 15e3;
1149
1221
  var CustomerAuth = class {
1150
1222
  constructor(clientKey, baseUrl, options) {
1223
+ this.refreshPromise = null;
1151
1224
  var _a, _b;
1152
1225
  this.clientKey = clientKey;
1153
1226
  this.baseUrl = baseUrl;
@@ -1194,6 +1267,17 @@ var CustomerAuth = class {
1194
1267
  refreshToken() {
1195
1268
  return __async(this, null, function* () {
1196
1269
  if (!this.token) throw new ApiError("Not authenticated", 401);
1270
+ if (this.refreshPromise) return this.refreshPromise;
1271
+ this.refreshPromise = this._doRefreshToken();
1272
+ try {
1273
+ return yield this.refreshPromise;
1274
+ } finally {
1275
+ this.refreshPromise = null;
1276
+ }
1277
+ });
1278
+ }
1279
+ _doRefreshToken() {
1280
+ return __async(this, null, function* () {
1197
1281
  const result = yield this.requestJson("/api/customers/refresh", {
1198
1282
  method: "POST",
1199
1283
  headers: { Authorization: `Bearer ${this.token}` }
@@ -1252,6 +1336,20 @@ var CustomerAuth = class {
1252
1336
  });
1253
1337
  });
1254
1338
  }
1339
+ /**
1340
+ * Update the authenticated customer's profile (name, phone, marketingConsent)
1341
+ */
1342
+ updateProfile(data) {
1343
+ return __async(this, null, function* () {
1344
+ if (!this.token) throw new ApiError("Not authenticated", 401);
1345
+ const result = yield this.requestJson("/api/customers/me", {
1346
+ method: "PATCH",
1347
+ headers: { Authorization: `Bearer ${this.token}` },
1348
+ body: JSON.stringify(data)
1349
+ });
1350
+ return result.customer;
1351
+ });
1352
+ }
1255
1353
  /**
1256
1354
  * Change the password of the currently authenticated customer
1257
1355
  */
@@ -1276,6 +1374,23 @@ var CustomerAuth = class {
1276
1374
  });
1277
1375
  });
1278
1376
  }
1377
+ /**
1378
+ * Get the authenticated customer's orders with pagination and optional status filter
1379
+ */
1380
+ getMyOrders(options) {
1381
+ return __async(this, null, function* () {
1382
+ if (!this.token) throw new ApiError("Not authenticated", 401);
1383
+ const params = new URLSearchParams();
1384
+ if (options == null ? void 0 : options.page) params.set("page", String(options.page));
1385
+ if (options == null ? void 0 : options.limit) params.set("limit", String(options.limit));
1386
+ if (options == null ? void 0 : options.status) params.set("status", options.status);
1387
+ const qs = params.toString();
1388
+ return this.requestJson(`/api/customers/me/orders${qs ? `?${qs}` : ""}`, {
1389
+ method: "GET",
1390
+ headers: { Authorization: `Bearer ${this.token}` }
1391
+ });
1392
+ });
1393
+ }
1279
1394
  /**
1280
1395
  * Get the current token (or null if not authenticated)
1281
1396
  */
@@ -1550,7 +1665,7 @@ var QueryHooks = class {
1550
1665
  }),
1551
1666
  onSuccess: (data) => {
1552
1667
  var _a;
1553
- this.queryClient.invalidateQueries({ queryKey: collectionKeys(collection).lists() });
1668
+ this.queryClient.invalidateQueries({ queryKey: collectionKeys(collection).all });
1554
1669
  (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1555
1670
  },
1556
1671
  onError: options == null ? void 0 : options.onError,
@@ -1713,6 +1828,20 @@ var QueryHooks = class {
1713
1828
  onSettled: options == null ? void 0 : options.onSettled
1714
1829
  });
1715
1830
  }
1831
+ useCustomerUpdateProfile(options) {
1832
+ return useMutationOriginal({
1833
+ mutationFn: (data) => __async(this, null, function* () {
1834
+ return yield this.ensureCustomerAuth().updateProfile(data);
1835
+ }),
1836
+ onSuccess: (data) => {
1837
+ var _a;
1838
+ this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1839
+ (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1840
+ },
1841
+ onError: options == null ? void 0 : options.onError,
1842
+ onSettled: options == null ? void 0 : options.onSettled
1843
+ });
1844
+ }
1716
1845
  useCustomerChangePassword(options) {
1717
1846
  return useMutationOriginal({
1718
1847
  mutationFn: (data) => __async(this, null, function* () {
@@ -1751,16 +1880,27 @@ var BrowserClient = class {
1751
1880
  this.state = { metadata };
1752
1881
  this.queryClient = getQueryClient();
1753
1882
  this.customer = new CustomerAuth(this.config.clientKey, this.baseUrl, options.customer);
1883
+ const onUnauthorized = () => __async(this, null, function* () {
1884
+ var _a2;
1885
+ try {
1886
+ const result = yield this.customer.refreshToken();
1887
+ return (_a2 = result.token) != null ? _a2 : null;
1888
+ } catch (e) {
1889
+ return null;
1890
+ }
1891
+ });
1754
1892
  this.cart = new CartApi({
1755
1893
  clientKey: this.config.clientKey,
1756
1894
  customerToken: () => this.customer.getToken(),
1757
- baseUrl: this.baseUrl
1895
+ baseUrl: this.baseUrl,
1896
+ onUnauthorized
1758
1897
  });
1759
1898
  this.collections = new CollectionClient(
1760
1899
  this.config.clientKey,
1761
1900
  void 0,
1762
1901
  this.baseUrl,
1763
- () => this.customer.getToken()
1902
+ () => this.customer.getToken(),
1903
+ onUnauthorized
1764
1904
  );
1765
1905
  this.query = new QueryHooks(this.queryClient, this.collections, this.customer);
1766
1906
  }
@@ -1770,6 +1910,9 @@ var BrowserClient = class {
1770
1910
  getState() {
1771
1911
  return __spreadValues({}, this.state);
1772
1912
  }
1913
+ getConfig() {
1914
+ return __spreadValues({}, this.config);
1915
+ }
1773
1916
  };
1774
1917
  function createBrowserClient(options) {
1775
1918
  return new BrowserClient(options);
@@ -1834,7 +1977,7 @@ function createServerClient(options) {
1834
1977
  return new ServerClient(options);
1835
1978
  }
1836
1979
 
1837
- // src/core/webhook/index.tsx
1980
+ // src/core/webhook/index.ts
1838
1981
  function isValidWebhookEvent(data) {
1839
1982
  if (typeof data !== "object" || data === null) return false;
1840
1983
  const obj = data;
@@ -1987,12 +2130,46 @@ var generateOrderNumber = () => {
1987
2130
  };
1988
2131
 
1989
2132
  // src/utils/order/formatOrderName.ts
1990
- var formatOrderName = (options) => {
2133
+ var formatOrderName = (items) => {
1991
2134
  var _a, _b;
1992
- if (options.length === 0) return "";
1993
- const firstTitle = ((_b = resolveRelation((_a = options[0]) == null ? void 0 : _a.product)) == null ? void 0 : _b.title) || "";
1994
- return options.length === 1 ? firstTitle : `${firstTitle} \uC678 ${options.length - 1}\uAC74`;
2135
+ if (items.length === 0) return "";
2136
+ const firstTitle = ((_b = resolveRelation((_a = items[0]) == null ? void 0 : _a.product)) == null ? void 0 : _b.title) || "";
2137
+ return items.length === 1 ? firstTitle : `${firstTitle} \uC678 ${items.length - 1}\uAC74`;
1995
2138
  };
2139
+
2140
+ // src/utils/video.ts
2141
+ var MUX_IMAGE_BASE = "https://image.mux.com";
2142
+ var MUX_STREAM_BASE = "https://stream.mux.com";
2143
+ function getVideoThumbnail(playbackId, options) {
2144
+ var _a;
2145
+ const params = new URLSearchParams();
2146
+ params.set("width", String((_a = options == null ? void 0 : options.width) != null ? _a : 640));
2147
+ if (options == null ? void 0 : options.height) params.set("height", String(options.height));
2148
+ if ((options == null ? void 0 : options.time) != null) params.set("time", String(options.time));
2149
+ if (options == null ? void 0 : options.fitMode) params.set("fit_mode", options.fitMode);
2150
+ if (options == null ? void 0 : options.flipH) params.set("flip_h", "true");
2151
+ if (options == null ? void 0 : options.flipV) params.set("flip_v", "true");
2152
+ if (options == null ? void 0 : options.rotate) params.set("rotate", String(options.rotate));
2153
+ return `${MUX_IMAGE_BASE}/${playbackId}/thumbnail.jpg?${params}`;
2154
+ }
2155
+ function getVideoGif(playbackId, options) {
2156
+ var _a;
2157
+ const params = new URLSearchParams();
2158
+ params.set("width", String((_a = options == null ? void 0 : options.width) != null ? _a : 320));
2159
+ if ((options == null ? void 0 : options.start) != null) params.set("start", String(options.start));
2160
+ if ((options == null ? void 0 : options.end) != null) params.set("end", String(options.end));
2161
+ if (options == null ? void 0 : options.fps) params.set("fps", String(options.fps));
2162
+ return `${MUX_IMAGE_BASE}/${playbackId}/animated.gif?${params}`;
2163
+ }
2164
+ function getVideoStoryboard(playbackId) {
2165
+ return `${MUX_IMAGE_BASE}/${playbackId}/storyboard.vtt`;
2166
+ }
2167
+ function getVideoStreamUrl(playbackId) {
2168
+ return `${MUX_STREAM_BASE}/${playbackId}.m3u8`;
2169
+ }
2170
+ function getVideoMp4Url(playbackId, resolution = "high") {
2171
+ return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`;
2172
+ }
1996
2173
  export {
1997
2174
  ApiError,
1998
2175
  BrowserClient,
@@ -2002,12 +2179,14 @@ export {
2002
2179
  CollectionQueryBuilder,
2003
2180
  ConfigError,
2004
2181
  CustomerAuth,
2182
+ GoneError,
2005
2183
  IMAGE_SIZES,
2006
2184
  NetworkError,
2007
2185
  OrderApi,
2008
2186
  ProductApi,
2009
2187
  QueryHooks,
2010
2188
  ServerClient,
2189
+ ServiceUnavailableError,
2011
2190
  TimeoutError,
2012
2191
  UsageLimitError,
2013
2192
  ValidationError,
@@ -2027,11 +2206,18 @@ export {
2027
2206
  getImageSrcSet,
2028
2207
  getImageUrl,
2029
2208
  getQueryClient,
2209
+ getVideoGif,
2210
+ getVideoMp4Url,
2211
+ getVideoStoryboard,
2212
+ getVideoStreamUrl,
2213
+ getVideoThumbnail,
2030
2214
  handleWebhook,
2031
2215
  isApiError,
2032
2216
  isConfigError,
2217
+ isGoneError,
2033
2218
  isNetworkError,
2034
2219
  isSDKError,
2220
+ isServiceUnavailableError,
2035
2221
  isTimeoutError,
2036
2222
  isUsageLimitError,
2037
2223
  isValidWebhookEvent,