@01.software/sdk 0.2.9-dev.260309.c56872d → 0.2.9-dev.260311.892250f

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.
Files changed (58) hide show
  1. package/README.md +21 -8
  2. package/dist/auth.cjs +3 -1
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts +36 -3
  5. package/dist/auth.d.ts +36 -3
  6. package/dist/auth.js +3 -1
  7. package/dist/auth.js.map +1 -1
  8. package/dist/index.cjs +252 -258
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +324 -161
  11. package/dist/index.d.ts +324 -161
  12. package/dist/index.js +255 -258
  13. package/dist/index.js.map +1 -1
  14. package/dist/{payload-types-2wbfaDxp.d.cts → payload-types-BjvBwB8Z.d.cts} +1633 -507
  15. package/dist/{payload-types-2wbfaDxp.d.ts → payload-types-BjvBwB8Z.d.ts} +1633 -507
  16. package/dist/ui/code-block.cjs +182 -0
  17. package/dist/ui/code-block.cjs.map +1 -0
  18. package/dist/ui/code-block.d.cts +62 -0
  19. package/dist/ui/code-block.d.ts +62 -0
  20. package/dist/ui/code-block.js +152 -0
  21. package/dist/ui/code-block.js.map +1 -0
  22. package/dist/{flow.cjs → ui/flow.cjs} +120 -96
  23. package/dist/ui/flow.cjs.map +1 -0
  24. package/dist/{flow.d.cts → ui/flow.d.cts} +27 -11
  25. package/dist/{flow.d.ts → ui/flow.d.ts} +27 -11
  26. package/dist/{flow.js → ui/flow.js} +119 -94
  27. package/dist/ui/flow.js.map +1 -0
  28. package/dist/{components.cjs → ui/form.cjs} +27 -520
  29. package/dist/ui/form.cjs.map +1 -0
  30. package/dist/ui/form.d.cts +37 -0
  31. package/dist/ui/form.d.ts +37 -0
  32. package/dist/{components.js → ui/form.js} +20 -516
  33. package/dist/ui/form.js.map +1 -0
  34. package/dist/ui/image.cjs +208 -0
  35. package/dist/ui/image.cjs.map +1 -0
  36. package/dist/ui/image.d.cts +44 -0
  37. package/dist/ui/image.d.ts +44 -0
  38. package/dist/ui/image.js +180 -0
  39. package/dist/ui/image.js.map +1 -0
  40. package/dist/ui/rich-text.cjs +258 -0
  41. package/dist/ui/rich-text.cjs.map +1 -0
  42. package/dist/ui/rich-text.d.cts +110 -0
  43. package/dist/ui/rich-text.d.ts +110 -0
  44. package/dist/ui/rich-text.js +235 -0
  45. package/dist/ui/rich-text.js.map +1 -0
  46. package/dist/{webhook-I6ZDGW1d.d.ts → webhook-CszIpUKn.d.cts} +2 -2
  47. package/dist/{webhook-Byzl1A0g.d.cts → webhook-_LdLdjGa.d.ts} +2 -2
  48. package/dist/webhook.d.cts +2 -2
  49. package/dist/webhook.d.ts +2 -2
  50. package/package.json +66 -33
  51. package/dist/auth-BieKA-OQ.d.ts +0 -298
  52. package/dist/auth-CAV8xgZk.d.cts +0 -298
  53. package/dist/components.cjs.map +0 -1
  54. package/dist/components.d.cts +0 -240
  55. package/dist/components.d.ts +0 -240
  56. package/dist/components.js.map +0 -1
  57. package/dist/flow.cjs.map +0 -1
  58. package/dist/flow.js.map +0 -1
package/dist/index.cjs CHANGED
@@ -71,19 +71,23 @@ var __async = (__this, __arguments, generator) => {
71
71
  var src_exports = {};
72
72
  __export(src_exports, {
73
73
  ApiError: () => ApiError,
74
+ BaseApi: () => BaseApi,
74
75
  BrowserClient: () => BrowserClient,
75
76
  COLLECTIONS: () => COLLECTIONS,
76
77
  CartApi: () => CartApi,
77
78
  CollectionClient: () => CollectionClient,
79
+ CollectionHooks: () => CollectionHooks,
78
80
  CollectionQueryBuilder: () => CollectionQueryBuilder,
79
81
  ConfigError: () => ConfigError,
80
82
  CustomerAuth: () => CustomerAuth,
83
+ CustomerHooks: () => CustomerHooks,
81
84
  GoneError: () => GoneError,
82
85
  IMAGE_SIZES: () => IMAGE_SIZES,
83
86
  NetworkError: () => NetworkError,
84
87
  OrderApi: () => OrderApi,
85
88
  ProductApi: () => ProductApi,
86
89
  QueryHooks: () => QueryHooks,
90
+ SDKError: () => SDKError,
87
91
  ServerClient: () => ServerClient,
88
92
  ServiceUnavailableError: () => ServiceUnavailableError,
89
93
  TimeoutError: () => TimeoutError,
@@ -121,15 +125,92 @@ __export(src_exports, {
121
125
  isUsageLimitError: () => isUsageLimitError,
122
126
  isValidWebhookEvent: () => isValidWebhookEvent,
123
127
  isValidationError: () => isValidationError,
124
- objectFor: () => objectFor,
125
128
  parseApiKey: () => parseApiKey,
126
129
  resolveRelation: () => resolveRelation,
127
130
  verifyServerToken: () => verifyServerToken
128
131
  });
129
132
  module.exports = __toCommonJS(src_exports);
130
133
 
131
- // src/core/internal/utils/index.ts
134
+ // src/core/internal/utils/jwt.ts
132
135
  var import_jose = require("jose");
136
+ function createServerToken(clientKey, secretKey, expiresIn = "1h") {
137
+ return __async(this, null, function* () {
138
+ if (!clientKey || !secretKey) {
139
+ throw new Error("clientKey and secretKey are required.");
140
+ }
141
+ const secret = new TextEncoder().encode(secretKey);
142
+ return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
143
+ });
144
+ }
145
+ function verifyServerToken(token, secretKey) {
146
+ return __async(this, null, function* () {
147
+ if (!token || !secretKey) {
148
+ throw new Error("token and secretKey are required.");
149
+ }
150
+ const secret = new TextEncoder().encode(secretKey);
151
+ const { payload } = yield (0, import_jose.jwtVerify)(token, secret, {
152
+ algorithms: ["HS256"]
153
+ });
154
+ if (!payload.clientKey || typeof payload.clientKey !== "string") {
155
+ throw new Error("Invalid token payload: clientKey is missing");
156
+ }
157
+ return {
158
+ clientKey: payload.clientKey,
159
+ iat: payload.iat,
160
+ exp: payload.exp
161
+ };
162
+ });
163
+ }
164
+ function decodeServerToken(token) {
165
+ if (!token) {
166
+ throw new Error("token is required.");
167
+ }
168
+ const payload = (0, import_jose.decodeJwt)(token);
169
+ if (!payload.clientKey || typeof payload.clientKey !== "string") {
170
+ throw new Error("Invalid token payload: clientKey is missing");
171
+ }
172
+ return {
173
+ clientKey: payload.clientKey,
174
+ iat: payload.iat,
175
+ exp: payload.exp
176
+ };
177
+ }
178
+
179
+ // src/core/internal/utils/encoding.ts
180
+ function createApiKey(clientKey, secretKey) {
181
+ if (!clientKey || !secretKey) {
182
+ throw new Error("clientKey and secretKey are required.");
183
+ }
184
+ if (typeof Buffer !== "undefined") {
185
+ return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
186
+ }
187
+ return btoa(`${clientKey}:${secretKey}`);
188
+ }
189
+ function parseApiKey(apiKey) {
190
+ if (!apiKey) {
191
+ throw new Error("apiKey is required.");
192
+ }
193
+ try {
194
+ let decoded;
195
+ if (typeof Buffer !== "undefined") {
196
+ decoded = Buffer.from(apiKey, "base64").toString("utf-8");
197
+ } else {
198
+ decoded = atob(apiKey);
199
+ }
200
+ const colonIndex = decoded.indexOf(":");
201
+ if (colonIndex === -1) {
202
+ throw new Error("Invalid format: missing colon separator");
203
+ }
204
+ const clientKey = decoded.substring(0, colonIndex);
205
+ const secretKey = decoded.substring(colonIndex + 1);
206
+ if (!clientKey || !secretKey) {
207
+ throw new Error("Invalid format: empty clientKey or secretKey");
208
+ }
209
+ return { clientKey, secretKey };
210
+ } catch (e) {
211
+ throw new Error('Invalid API key. Expected Base64 encoded "clientKey:secretKey"');
212
+ }
213
+ }
133
214
 
134
215
  // src/core/internal/errors/index.ts
135
216
  var SDKError = class _SDKError extends Error {
@@ -270,87 +351,11 @@ function resolveApiUrl(config) {
270
351
  return API_URLS.production;
271
352
  }
272
353
 
273
- // src/core/internal/utils/index.ts
354
+ // src/core/internal/utils/http.ts
274
355
  var DEFAULT_TIMEOUT = 3e4;
275
356
  var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
276
357
  var NON_RETRYABLE_STATUSES = [401, 403, 404, 422];
277
358
  var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
278
- function createServerToken(clientKey, secretKey, expiresIn = "1h") {
279
- return __async(this, null, function* () {
280
- if (!clientKey || !secretKey) {
281
- throw new Error("clientKey and secretKey are required.");
282
- }
283
- const secret = new TextEncoder().encode(secretKey);
284
- return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
285
- });
286
- }
287
- function verifyServerToken(token, secretKey) {
288
- return __async(this, null, function* () {
289
- if (!token || !secretKey) {
290
- throw new Error("token and secretKey are required.");
291
- }
292
- const secret = new TextEncoder().encode(secretKey);
293
- const { payload } = yield (0, import_jose.jwtVerify)(token, secret, {
294
- algorithms: ["HS256"]
295
- });
296
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
297
- throw new Error("Invalid token payload: clientKey is missing");
298
- }
299
- return {
300
- clientKey: payload.clientKey,
301
- iat: payload.iat,
302
- exp: payload.exp
303
- };
304
- });
305
- }
306
- function decodeServerToken(token) {
307
- if (!token) {
308
- throw new Error("token is required.");
309
- }
310
- const payload = (0, import_jose.decodeJwt)(token);
311
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
312
- throw new Error("Invalid token payload: clientKey is missing");
313
- }
314
- return {
315
- clientKey: payload.clientKey,
316
- iat: payload.iat,
317
- exp: payload.exp
318
- };
319
- }
320
- function createApiKey(clientKey, secretKey) {
321
- if (!clientKey || !secretKey) {
322
- throw new Error("clientKey and secretKey are required.");
323
- }
324
- if (typeof Buffer !== "undefined") {
325
- return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
326
- }
327
- return btoa(`${clientKey}:${secretKey}`);
328
- }
329
- function parseApiKey(apiKey) {
330
- if (!apiKey) {
331
- throw new Error("apiKey is required.");
332
- }
333
- try {
334
- let decoded;
335
- if (typeof Buffer !== "undefined") {
336
- decoded = Buffer.from(apiKey, "base64").toString("utf-8");
337
- } else {
338
- decoded = atob(apiKey);
339
- }
340
- const colonIndex = decoded.indexOf(":");
341
- if (colonIndex === -1) {
342
- throw new Error("Invalid format: missing colon separator");
343
- }
344
- const clientKey = decoded.substring(0, colonIndex);
345
- const secretKey = decoded.substring(colonIndex + 1);
346
- if (!clientKey || !secretKey) {
347
- throw new Error("Invalid format: empty clientKey or secretKey");
348
- }
349
- return { clientKey, secretKey };
350
- } catch (e) {
351
- throw new Error('Invalid API key. Expected Base64 encoded "clientKey:secretKey"');
352
- }
353
- }
354
359
  function debugLog(debug, type, message, data) {
355
360
  if (!debug) return;
356
361
  const shouldLog = debug === true || type === "request" && debug.logRequests || type === "response" && debug.logResponses || type === "error" && debug.logErrors;
@@ -372,7 +377,7 @@ function delay(ms) {
372
377
  return new Promise((resolve) => setTimeout(resolve, ms));
373
378
  });
374
379
  }
375
- function _fetch(url, options) {
380
+ function httpFetch(url, options) {
376
381
  return __async(this, null, function* () {
377
382
  var _b, _c, _d;
378
383
  const _a = options || {}, {
@@ -552,14 +557,14 @@ function _fetch(url, options) {
552
557
  });
553
558
  }
554
559
 
555
- // src/core/api/order-api.ts
556
- var OrderApi = class {
557
- constructor(options) {
560
+ // src/core/api/base-api.ts
561
+ var BaseApi = class {
562
+ constructor(apiName, options) {
558
563
  if (!options.clientKey) {
559
- throw createConfigError("clientKey is required for OrderApi.");
564
+ throw createConfigError(`clientKey is required for ${apiName}.`);
560
565
  }
561
566
  if (!options.secretKey) {
562
- throw createConfigError("secretKey is required for OrderApi.");
567
+ throw createConfigError(`secretKey is required for ${apiName}.`);
563
568
  }
564
569
  this.clientKey = options.clientKey;
565
570
  this.secretKey = options.secretKey;
@@ -567,7 +572,7 @@ var OrderApi = class {
567
572
  }
568
573
  request(endpoint, body) {
569
574
  return __async(this, null, function* () {
570
- const response = yield _fetch(endpoint, {
575
+ const response = yield httpFetch(endpoint, {
571
576
  method: "POST",
572
577
  clientKey: this.clientKey,
573
578
  secretKey: this.secretKey,
@@ -599,6 +604,13 @@ var OrderApi = class {
599
604
  return data;
600
605
  });
601
606
  }
607
+ };
608
+
609
+ // src/core/api/order-api.ts
610
+ var OrderApi = class extends BaseApi {
611
+ constructor(options) {
612
+ super("OrderApi", options);
613
+ }
602
614
  createOrder(params) {
603
615
  return this.request("/api/orders/create", params);
604
616
  }
@@ -661,7 +673,7 @@ var CartApi = class {
661
673
  execute(endpoint, method, body) {
662
674
  return __async(this, null, function* () {
663
675
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
664
- const response = yield _fetch(endpoint, __spreadValues(__spreadValues({
676
+ const response = yield httpFetch(endpoint, __spreadValues(__spreadValues({
665
677
  method,
666
678
  clientKey: this.clientKey,
667
679
  secretKey: this.secretKey,
@@ -717,51 +729,9 @@ var CartApi = class {
717
729
  };
718
730
 
719
731
  // src/core/api/product-api.ts
720
- var ProductApi = class {
732
+ var ProductApi = class extends BaseApi {
721
733
  constructor(options) {
722
- if (!options.clientKey) {
723
- throw createConfigError("clientKey is required for ProductApi.");
724
- }
725
- if (!options.secretKey) {
726
- throw createConfigError("secretKey is required for ProductApi.");
727
- }
728
- this.clientKey = options.clientKey;
729
- this.secretKey = options.secretKey;
730
- this.baseUrl = options.baseUrl;
731
- }
732
- request(endpoint, body) {
733
- return __async(this, null, function* () {
734
- const response = yield _fetch(endpoint, {
735
- method: "POST",
736
- clientKey: this.clientKey,
737
- secretKey: this.secretKey,
738
- baseUrl: this.baseUrl,
739
- body: JSON.stringify(body)
740
- });
741
- let data;
742
- try {
743
- data = yield response.json();
744
- } catch (e) {
745
- throw createApiError(
746
- `Invalid JSON response from ${endpoint}`,
747
- response.status,
748
- void 0,
749
- "Server returned an invalid response.",
750
- "Check if the API endpoint is available."
751
- );
752
- }
753
- if (data.error) {
754
- const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
755
- throw createApiError(
756
- errorMessage,
757
- response.status,
758
- data,
759
- errorMessage,
760
- "An error occurred while processing the request."
761
- );
762
- }
763
- return data;
764
- });
734
+ super("ProductApi", options);
765
735
  }
766
736
  stockCheck(params) {
767
737
  return this.request("/api/products/stock-check", params);
@@ -770,42 +740,44 @@ var ProductApi = class {
770
740
 
771
741
  // src/utils/types.ts
772
742
  var resolveRelation = (ref) => {
773
- if (typeof ref === "string" || ref === null || ref === void 0)
743
+ if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
774
744
  return null;
775
745
  return ref;
776
746
  };
777
- var objectFor = resolveRelation;
778
747
 
779
748
  // src/core/metadata/index.ts
780
- var COLLECTION_META_FIELDS = {
781
- products: { description: "subtitle", image: "thumbnail" },
782
- posts: { description: "excerpt", image: "thumbnail" },
783
- documents: { description: "summary", image: "" },
784
- playlists: { description: "description", image: "image" }
785
- };
786
- var DEFAULT_META_FIELDS = { description: "description", image: "thumbnail" };
787
- function extractMetaFields(collection, doc) {
788
- var _a, _b, _c, _d;
789
- const mapping = (_a = COLLECTION_META_FIELDS[collection]) != null ? _a : DEFAULT_META_FIELDS;
749
+ function extractSeo(doc) {
750
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
751
+ const seo = (_a = doc.seo) != null ? _a : {};
752
+ const og = (_b = seo.openGraph) != null ? _b : {};
790
753
  return {
791
- title: (_b = doc.title) != null ? _b : null,
792
- description: mapping.description ? (_c = doc[mapping.description]) != null ? _c : null : null,
793
- image: mapping.image ? (_d = doc[mapping.image]) != null ? _d : null : null
754
+ title: (_d = (_c = seo.title) != null ? _c : doc.title) != null ? _d : null,
755
+ description: (_e = seo.description) != null ? _e : null,
756
+ noIndex: (_f = seo.noIndex) != null ? _f : null,
757
+ canonical: (_g = seo.canonical) != null ? _g : null,
758
+ openGraph: {
759
+ title: (_h = og.title) != null ? _h : null,
760
+ description: (_i = og.description) != null ? _i : null,
761
+ image: (_j = og.image) != null ? _j : null
762
+ }
794
763
  };
795
764
  }
796
765
  function generateMetadata(input, options) {
797
- var _a, _b, _c, _d;
798
- const title = (_b = (_a = input.title) != null ? _a : options == null ? void 0 : options.title) != null ? _b : void 0;
799
- const description = (_d = (_c = input.description) != null ? _c : options == null ? void 0 : options.description) != null ? _d : void 0;
800
- const image = resolveMetaImage(input.image);
801
- return {
766
+ var _a, _b, _c, _d, _e, _f, _g;
767
+ const title = (_a = input.title) != null ? _a : void 0;
768
+ const description = (_b = input.description) != null ? _b : void 0;
769
+ const ogTitle = (_d = (_c = input.openGraph) == null ? void 0 : _c.title) != null ? _d : title;
770
+ const ogDescription = (_f = (_e = input.openGraph) == null ? void 0 : _e.description) != null ? _f : description;
771
+ const image = resolveMetaImage((_g = input.openGraph) == null ? void 0 : _g.image);
772
+ return __spreadProps(__spreadValues(__spreadValues({
802
773
  title,
803
- description,
804
- openGraph: __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, title && { title }), description && { description }), (options == null ? void 0 : options.siteName) && { siteName: options.siteName }), image && { images: [image] }),
774
+ description
775
+ }, input.noIndex && { robots: { index: false, follow: false } }), input.canonical && { alternates: { canonical: input.canonical } }), {
776
+ openGraph: __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, ogTitle && { title: ogTitle }), ogDescription && { description: ogDescription }), (options == null ? void 0 : options.siteName) && { siteName: options.siteName }), image && { images: [image] }),
805
777
  twitter: __spreadValues(__spreadValues(__spreadValues({
806
778
  card: image ? "summary_large_image" : "summary"
807
- }, title && { title }), description && { description }), image && { images: [image.url] })
808
- };
779
+ }, ogTitle && { title: ogTitle }), ogDescription && { description: ogDescription }), image && { images: [image.url] })
780
+ });
809
781
  }
810
782
  function resolveMetaImage(ref) {
811
783
  var _a;
@@ -915,7 +887,7 @@ var CollectionQueryBuilder = class {
915
887
  const doc = docs[0];
916
888
  if (!doc) return null;
917
889
  return generateMetadata(
918
- extractMetaFields(String(this.collection), doc),
890
+ extractSeo(doc),
919
891
  metadataOptions
920
892
  );
921
893
  });
@@ -929,7 +901,7 @@ var CollectionQueryBuilder = class {
929
901
  return __async(this, null, function* () {
930
902
  const doc = yield this.findById(id, { depth: 1 });
931
903
  return generateMetadata(
932
- extractMetaFields(String(this.collection), doc),
904
+ extractSeo(doc),
933
905
  metadataOptions
934
906
  );
935
907
  });
@@ -1037,6 +1009,7 @@ var HttpClient = class {
1037
1009
  nextPage: (_b = jsonData.nextPage) != null ? _b : null
1038
1010
  };
1039
1011
  } catch (error) {
1012
+ if (error instanceof SDKError) throw error;
1040
1013
  throw createApiError("Failed to parse response.", response.status, {
1041
1014
  contentType,
1042
1015
  error: error instanceof Error ? error.message : error
@@ -1063,6 +1036,7 @@ var HttpClient = class {
1063
1036
  errors: jsonData.errors
1064
1037
  };
1065
1038
  } catch (error) {
1039
+ if (error instanceof SDKError) throw error;
1066
1040
  throw createApiError("Failed to parse response.", response.status, {
1067
1041
  contentType,
1068
1042
  error: error instanceof Error ? error.message : error
@@ -1082,6 +1056,7 @@ var HttpClient = class {
1082
1056
  const jsonData = yield response.json();
1083
1057
  return jsonData;
1084
1058
  } catch (error) {
1059
+ if (error instanceof SDKError) throw error;
1085
1060
  throw createApiError("Failed to parse response.", response.status, {
1086
1061
  contentType,
1087
1062
  error: error instanceof Error ? error.message : error
@@ -1117,7 +1092,7 @@ var CollectionClient = class extends HttpClient {
1117
1092
  requestFind(endpoint, options) {
1118
1093
  return __async(this, null, function* () {
1119
1094
  const url = this.buildUrl(endpoint, options);
1120
- const response = yield _fetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1095
+ const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1121
1096
  return this.parseFindResponse(response);
1122
1097
  });
1123
1098
  }
@@ -1128,7 +1103,7 @@ var CollectionClient = class extends HttpClient {
1128
1103
  requestFindById(endpoint, options) {
1129
1104
  return __async(this, null, function* () {
1130
1105
  const url = this.buildUrl(endpoint, options);
1131
- const response = yield _fetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1106
+ const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1132
1107
  return this.parseDocumentResponse(response);
1133
1108
  });
1134
1109
  }
@@ -1138,7 +1113,7 @@ var CollectionClient = class extends HttpClient {
1138
1113
  */
1139
1114
  requestCreate(endpoint, data) {
1140
1115
  return __async(this, null, function* () {
1141
- const response = yield _fetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1116
+ const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1142
1117
  method: "POST",
1143
1118
  body: data ? JSON.stringify(data) : void 0
1144
1119
  }));
@@ -1151,7 +1126,7 @@ var CollectionClient = class extends HttpClient {
1151
1126
  */
1152
1127
  requestUpdate(endpoint, data) {
1153
1128
  return __async(this, null, function* () {
1154
- const response = yield _fetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1129
+ const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1155
1130
  method: "PATCH",
1156
1131
  body: data ? JSON.stringify(data) : void 0
1157
1132
  }));
@@ -1165,7 +1140,7 @@ var CollectionClient = class extends HttpClient {
1165
1140
  requestCount(endpoint, options) {
1166
1141
  return __async(this, null, function* () {
1167
1142
  const url = this.buildUrl(endpoint, options);
1168
- const response = yield _fetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1143
+ const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
1169
1144
  return this.parseDocumentResponse(response);
1170
1145
  });
1171
1146
  }
@@ -1175,7 +1150,7 @@ var CollectionClient = class extends HttpClient {
1175
1150
  */
1176
1151
  requestUpdateMany(endpoint, data) {
1177
1152
  return __async(this, null, function* () {
1178
- const response = yield _fetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1153
+ const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1179
1154
  method: "PATCH",
1180
1155
  body: JSON.stringify(data)
1181
1156
  }));
@@ -1188,7 +1163,7 @@ var CollectionClient = class extends HttpClient {
1188
1163
  */
1189
1164
  requestDelete(endpoint) {
1190
1165
  return __async(this, null, function* () {
1191
- const response = yield _fetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1166
+ const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1192
1167
  method: "DELETE"
1193
1168
  }));
1194
1169
  return this.parseDocumentResponse(response);
@@ -1200,7 +1175,7 @@ var CollectionClient = class extends HttpClient {
1200
1175
  */
1201
1176
  requestDeleteMany(endpoint, data) {
1202
1177
  return __async(this, null, function* () {
1203
- const response = yield _fetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1178
+ const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1204
1179
  method: "DELETE",
1205
1180
  body: JSON.stringify(data)
1206
1181
  }));
@@ -1213,7 +1188,7 @@ var CollectionClient = class extends HttpClient {
1213
1188
  */
1214
1189
  requestCreateWithFile(endpoint, data, file, filename) {
1215
1190
  return __async(this, null, function* () {
1216
- const response = yield _fetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1191
+ const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1217
1192
  method: "POST",
1218
1193
  body: buildPayloadFormData(data, file, filename)
1219
1194
  }));
@@ -1226,7 +1201,7 @@ var CollectionClient = class extends HttpClient {
1226
1201
  */
1227
1202
  requestUpdateWithFile(endpoint, data, file, filename) {
1228
1203
  return __async(this, null, function* () {
1229
- const response = yield _fetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1204
+ const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
1230
1205
  method: "PATCH",
1231
1206
  body: buildPayloadFormData(data, file, filename)
1232
1207
  }));
@@ -1277,15 +1252,23 @@ var COLLECTIONS = [
1277
1252
  "post-images",
1278
1253
  "playlists",
1279
1254
  "playlist-images",
1255
+ "playlist-categories",
1256
+ "playlist-tags",
1280
1257
  "musics",
1281
1258
  "galleries",
1282
1259
  "gallery-images",
1283
1260
  "gallery-categories",
1261
+ "gallery-tags",
1284
1262
  "flows",
1285
1263
  "flow-images",
1286
1264
  "flow-node-types",
1287
1265
  "flow-edge-types",
1266
+ "flow-categories",
1267
+ "flow-tags",
1288
1268
  "videos",
1269
+ "video-images",
1270
+ "video-categories",
1271
+ "video-tags",
1289
1272
  "live-streams",
1290
1273
  "live-stream-images",
1291
1274
  "forms",
@@ -1572,8 +1555,10 @@ function getQueryClient() {
1572
1555
  return browserQueryClient;
1573
1556
  }
1574
1557
 
1575
- // src/core/query/query-hooks.ts
1558
+ // src/core/query/collection-hooks.ts
1576
1559
  var import_react_query2 = require("@tanstack/react-query");
1560
+
1561
+ // src/core/query/query-keys.ts
1577
1562
  function collectionKeys(collection) {
1578
1563
  return {
1579
1564
  all: [collection],
@@ -1589,20 +1574,13 @@ var customerKeys = {
1589
1574
  all: ["customer"],
1590
1575
  me: () => ["customer", "me"]
1591
1576
  };
1577
+
1578
+ // src/core/query/collection-hooks.ts
1592
1579
  var DEFAULT_PAGE_SIZE = 20;
1593
- var QueryHooks = class {
1594
- constructor(queryClient, collectionClient, customerAuth) {
1580
+ var CollectionHooks = class {
1581
+ constructor(queryClient, collectionClient) {
1595
1582
  this.queryClient = queryClient;
1596
1583
  this.collectionClient = collectionClient;
1597
- this.customerAuth = customerAuth;
1598
- }
1599
- ensureCustomerAuth() {
1600
- if (!this.customerAuth) {
1601
- throw createConfigError(
1602
- "Customer hooks require BrowserClient. Use createBrowserClient() instead of createServerClient()."
1603
- );
1604
- }
1605
- return this.customerAuth;
1606
1584
  }
1607
1585
  // ===== useQuery =====
1608
1586
  useQuery(params, options) {
@@ -1801,10 +1779,42 @@ var QueryHooks = class {
1801
1779
  );
1802
1780
  }
1803
1781
  }
1804
- // ===== Customer Query Hooks =====
1782
+ };
1783
+
1784
+ // src/core/query/customer-hooks.ts
1785
+ var import_react_query3 = require("@tanstack/react-query");
1786
+ function createMutation(mutationFn, callbacks, onSuccessExtra) {
1787
+ return (0, import_react_query3.useMutation)({
1788
+ mutationFn,
1789
+ onSuccess: (data) => {
1790
+ var _a;
1791
+ onSuccessExtra == null ? void 0 : onSuccessExtra(data);
1792
+ (_a = callbacks == null ? void 0 : callbacks.onSuccess) == null ? void 0 : _a.call(callbacks, data);
1793
+ },
1794
+ onError: callbacks == null ? void 0 : callbacks.onError,
1795
+ onSettled: callbacks == null ? void 0 : callbacks.onSettled
1796
+ });
1797
+ }
1798
+ var CustomerHooks = class {
1799
+ constructor(queryClient, customerAuth) {
1800
+ this.invalidateMe = () => {
1801
+ this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1802
+ };
1803
+ this.queryClient = queryClient;
1804
+ this.customerAuth = customerAuth;
1805
+ }
1806
+ ensureCustomerAuth() {
1807
+ if (!this.customerAuth) {
1808
+ throw createConfigError(
1809
+ "Customer hooks require BrowserClient. Use createBrowserClient() instead of createServerClient()."
1810
+ );
1811
+ }
1812
+ return this.customerAuth;
1813
+ }
1814
+ // ===== useCustomerMe =====
1805
1815
  useCustomerMe(options) {
1806
1816
  var _a, _b;
1807
- return (0, import_react_query2.useQuery)(__spreadProps(__spreadValues({
1817
+ return (0, import_react_query3.useQuery)(__spreadProps(__spreadValues({
1808
1818
  queryKey: customerKeys.me(),
1809
1819
  queryFn: () => __async(this, null, function* () {
1810
1820
  return yield this.ensureCustomerAuth().me();
@@ -1813,32 +1823,22 @@ var QueryHooks = class {
1813
1823
  enabled: ((_a = options == null ? void 0 : options.enabled) != null ? _a : true) && !!((_b = this.customerAuth) == null ? void 0 : _b.isAuthenticated())
1814
1824
  }));
1815
1825
  }
1826
+ // ===== Mutations =====
1816
1827
  useCustomerLogin(options) {
1817
- return (0, import_react_query2.useMutation)({
1818
- mutationFn: (data) => __async(this, null, function* () {
1819
- return yield this.ensureCustomerAuth().login(data);
1820
- }),
1821
- onSuccess: (data) => {
1822
- var _a;
1823
- this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1824
- (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1825
- },
1826
- onError: options == null ? void 0 : options.onError,
1827
- onSettled: options == null ? void 0 : options.onSettled
1828
- });
1828
+ return createMutation(
1829
+ (data) => this.ensureCustomerAuth().login(data),
1830
+ options,
1831
+ this.invalidateMe
1832
+ );
1829
1833
  }
1830
1834
  useCustomerRegister(options) {
1831
- return (0, import_react_query2.useMutation)({
1832
- mutationFn: (data) => __async(this, null, function* () {
1833
- return yield this.ensureCustomerAuth().register(data);
1834
- }),
1835
- onSuccess: options == null ? void 0 : options.onSuccess,
1836
- onError: options == null ? void 0 : options.onError,
1837
- onSettled: options == null ? void 0 : options.onSettled
1838
- });
1835
+ return createMutation(
1836
+ (data) => this.ensureCustomerAuth().register(data),
1837
+ options
1838
+ );
1839
1839
  }
1840
1840
  useCustomerLogout(options) {
1841
- return (0, import_react_query2.useMutation)({
1841
+ return (0, import_react_query3.useMutation)({
1842
1842
  mutationFn: () => __async(this, null, function* () {
1843
1843
  this.ensureCustomerAuth().logout();
1844
1844
  }),
@@ -1852,76 +1852,47 @@ var QueryHooks = class {
1852
1852
  });
1853
1853
  }
1854
1854
  useCustomerForgotPassword(options) {
1855
- return (0, import_react_query2.useMutation)({
1856
- mutationFn: (email) => __async(this, null, function* () {
1857
- yield this.ensureCustomerAuth().forgotPassword(email);
1855
+ return createMutation(
1856
+ (email) => this.ensureCustomerAuth().forgotPassword(email).then(() => {
1858
1857
  }),
1859
- onSuccess: options == null ? void 0 : options.onSuccess,
1860
- onError: options == null ? void 0 : options.onError,
1861
- onSettled: options == null ? void 0 : options.onSettled
1862
- });
1858
+ options
1859
+ );
1863
1860
  }
1864
1861
  useCustomerResetPassword(options) {
1865
- return (0, import_react_query2.useMutation)({
1866
- mutationFn: (data) => __async(this, null, function* () {
1867
- yield this.ensureCustomerAuth().resetPassword(data.token, data.password);
1862
+ return createMutation(
1863
+ (data) => this.ensureCustomerAuth().resetPassword(data.token, data.password).then(() => {
1868
1864
  }),
1869
- onSuccess: options == null ? void 0 : options.onSuccess,
1870
- onError: options == null ? void 0 : options.onError,
1871
- onSettled: options == null ? void 0 : options.onSettled
1872
- });
1865
+ options
1866
+ );
1873
1867
  }
1874
1868
  useCustomerVerifyEmail(options) {
1875
- return (0, import_react_query2.useMutation)({
1876
- mutationFn: (token) => __async(this, null, function* () {
1877
- yield this.ensureCustomerAuth().verifyEmail(token);
1869
+ return createMutation(
1870
+ (token) => this.ensureCustomerAuth().verifyEmail(token).then(() => {
1878
1871
  }),
1879
- onSuccess: () => {
1880
- var _a;
1881
- this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1882
- (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
1883
- },
1884
- onError: options == null ? void 0 : options.onError,
1885
- onSettled: options == null ? void 0 : options.onSettled
1886
- });
1872
+ options,
1873
+ this.invalidateMe
1874
+ );
1887
1875
  }
1888
1876
  useCustomerRefreshToken(options) {
1889
- return (0, import_react_query2.useMutation)({
1890
- mutationFn: () => __async(this, null, function* () {
1891
- return yield this.ensureCustomerAuth().refreshToken();
1892
- }),
1893
- onSuccess: (data) => {
1894
- var _a;
1895
- this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1896
- (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1897
- },
1898
- onError: options == null ? void 0 : options.onError,
1899
- onSettled: options == null ? void 0 : options.onSettled
1900
- });
1877
+ return createMutation(
1878
+ () => this.ensureCustomerAuth().refreshToken(),
1879
+ options,
1880
+ this.invalidateMe
1881
+ );
1901
1882
  }
1902
1883
  useCustomerUpdateProfile(options) {
1903
- return (0, import_react_query2.useMutation)({
1904
- mutationFn: (data) => __async(this, null, function* () {
1905
- return yield this.ensureCustomerAuth().updateProfile(data);
1906
- }),
1907
- onSuccess: (data) => {
1908
- var _a;
1909
- this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1910
- (_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
1911
- },
1912
- onError: options == null ? void 0 : options.onError,
1913
- onSettled: options == null ? void 0 : options.onSettled
1914
- });
1884
+ return createMutation(
1885
+ (data) => this.ensureCustomerAuth().updateProfile(data),
1886
+ options,
1887
+ this.invalidateMe
1888
+ );
1915
1889
  }
1916
1890
  useCustomerChangePassword(options) {
1917
- return (0, import_react_query2.useMutation)({
1918
- mutationFn: (data) => __async(this, null, function* () {
1919
- yield this.ensureCustomerAuth().changePassword(data.currentPassword, data.newPassword);
1891
+ return createMutation(
1892
+ (data) => this.ensureCustomerAuth().changePassword(data.currentPassword, data.newPassword).then(() => {
1920
1893
  }),
1921
- onSuccess: options == null ? void 0 : options.onSuccess,
1922
- onError: options == null ? void 0 : options.onError,
1923
- onSettled: options == null ? void 0 : options.onSettled
1924
- });
1894
+ options
1895
+ );
1925
1896
  }
1926
1897
  // ===== Customer Cache Utilities =====
1927
1898
  invalidateCustomerQueries() {
@@ -1935,6 +1906,29 @@ var QueryHooks = class {
1935
1906
  }
1936
1907
  };
1937
1908
 
1909
+ // src/core/query/query-hooks.ts
1910
+ var QueryHooks = class extends CollectionHooks {
1911
+ constructor(queryClient, collectionClient, customerAuth) {
1912
+ super(queryClient, collectionClient);
1913
+ // --- Customer hooks delegation ---
1914
+ this.useCustomerMe = (...args) => this._customer.useCustomerMe(...args);
1915
+ this.useCustomerLogin = (...args) => this._customer.useCustomerLogin(...args);
1916
+ this.useCustomerRegister = (...args) => this._customer.useCustomerRegister(...args);
1917
+ this.useCustomerLogout = (...args) => this._customer.useCustomerLogout(...args);
1918
+ this.useCustomerForgotPassword = (...args) => this._customer.useCustomerForgotPassword(...args);
1919
+ this.useCustomerResetPassword = (...args) => this._customer.useCustomerResetPassword(...args);
1920
+ this.useCustomerVerifyEmail = (...args) => this._customer.useCustomerVerifyEmail(...args);
1921
+ this.useCustomerRefreshToken = (...args) => this._customer.useCustomerRefreshToken(...args);
1922
+ this.useCustomerUpdateProfile = (...args) => this._customer.useCustomerUpdateProfile(...args);
1923
+ this.useCustomerChangePassword = (...args) => this._customer.useCustomerChangePassword(...args);
1924
+ // --- Customer cache delegation ---
1925
+ this.invalidateCustomerQueries = () => this._customer.invalidateCustomerQueries();
1926
+ this.getCustomerData = () => this._customer.getCustomerData();
1927
+ this.setCustomerData = (data) => this._customer.setCustomerData(data);
1928
+ this._customer = new CustomerHooks(queryClient, customerAuth);
1929
+ }
1930
+ };
1931
+
1938
1932
  // src/core/client/client.ts
1939
1933
  var BrowserClient = class {
1940
1934
  constructor(options) {