@01.software/sdk 0.29.0 → 0.30.1

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 (78) hide show
  1. package/README.md +273 -73
  2. package/dist/analytics/react.cjs +4 -1
  3. package/dist/analytics/react.cjs.map +1 -1
  4. package/dist/analytics/react.js +4 -1
  5. package/dist/analytics/react.js.map +1 -1
  6. package/dist/analytics.cjs +4 -1
  7. package/dist/analytics.cjs.map +1 -1
  8. package/dist/analytics.js +4 -1
  9. package/dist/analytics.js.map +1 -1
  10. package/dist/client.cjs +1476 -0
  11. package/dist/client.cjs.map +1 -0
  12. package/dist/client.d.cts +28 -0
  13. package/dist/client.d.ts +28 -0
  14. package/dist/client.js +1453 -0
  15. package/dist/client.js.map +1 -0
  16. package/dist/collection-client-B9d9kr1d.d.ts +218 -0
  17. package/dist/collection-client-QPbwimkU.d.cts +218 -0
  18. package/dist/{const-DAjQYNuM.d.ts → const-B75IFDRi.d.ts} +2 -4
  19. package/dist/{const-Dsixdi6z.d.cts → const-VZuk2tWc.d.cts} +2 -4
  20. package/dist/index-B2WbhEgT.d.cts +106 -0
  21. package/dist/index-B2WbhEgT.d.ts +106 -0
  22. package/dist/index.cjs +784 -1530
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +11 -115
  25. package/dist/index.d.ts +11 -115
  26. package/dist/index.js +784 -1548
  27. package/dist/index.js.map +1 -1
  28. package/dist/metadata.cjs +91 -0
  29. package/dist/metadata.cjs.map +1 -0
  30. package/dist/metadata.d.cts +58 -0
  31. package/dist/metadata.d.ts +58 -0
  32. package/dist/metadata.js +68 -0
  33. package/dist/metadata.js.map +1 -0
  34. package/dist/{payload-types-Ci-ZA7aM.d.cts → payload-types-DPjO_IbQ.d.cts} +9 -3
  35. package/dist/{payload-types-Ci-ZA7aM.d.ts → payload-types-DPjO_IbQ.d.ts} +9 -3
  36. package/dist/query.cjs +1791 -0
  37. package/dist/query.cjs.map +1 -0
  38. package/dist/query.d.cts +244 -0
  39. package/dist/query.d.ts +244 -0
  40. package/dist/query.js +1786 -0
  41. package/dist/query.js.map +1 -0
  42. package/dist/realtime.cjs +4 -1
  43. package/dist/realtime.cjs.map +1 -1
  44. package/dist/realtime.d.cts +2 -2
  45. package/dist/realtime.d.ts +2 -2
  46. package/dist/realtime.js +4 -1
  47. package/dist/realtime.js.map +1 -1
  48. package/dist/{server-BINWywT8.d.cts → server-CrsPyqEc.d.cts} +14 -31
  49. package/dist/{server-BINWywT8.d.ts → server-CrsPyqEc.d.ts} +14 -31
  50. package/dist/server.cjs +299 -840
  51. package/dist/server.cjs.map +1 -1
  52. package/dist/server.d.cts +112 -7
  53. package/dist/server.d.ts +112 -7
  54. package/dist/server.js +299 -858
  55. package/dist/server.js.map +1 -1
  56. package/dist/{types-BWq_WlbB.d.ts → types-1fBLrYU7.d.ts} +1 -1
  57. package/dist/{types-zKjATmDK.d.cts → types-BwT0eeaz.d.cts} +1 -1
  58. package/dist/{server-Cv0Q4dPQ.d.ts → types-Dlb2mwpX.d.cts} +228 -741
  59. package/dist/{server-C0C8dtms.d.cts → types-DuSKPiY5.d.ts} +228 -741
  60. package/dist/ui/canvas/server.cjs +7 -6
  61. package/dist/ui/canvas/server.cjs.map +1 -1
  62. package/dist/ui/canvas/server.d.cts +1 -3
  63. package/dist/ui/canvas/server.d.ts +1 -3
  64. package/dist/ui/canvas/server.js +7 -6
  65. package/dist/ui/canvas/server.js.map +1 -1
  66. package/dist/ui/canvas.cjs +11 -10
  67. package/dist/ui/canvas.cjs.map +1 -1
  68. package/dist/ui/canvas.d.cts +29 -6
  69. package/dist/ui/canvas.d.ts +29 -6
  70. package/dist/ui/canvas.js +11 -10
  71. package/dist/ui/canvas.js.map +1 -1
  72. package/dist/ui/form.d.cts +1 -1
  73. package/dist/ui/form.d.ts +1 -1
  74. package/dist/ui/video.d.cts +1 -1
  75. package/dist/ui/video.d.ts +1 -1
  76. package/dist/webhook.d.cts +3 -3
  77. package/dist/webhook.d.ts +3 -3
  78. package/package.json +84 -15
package/dist/server.js CHANGED
@@ -1,202 +1,3 @@
1
- // src/utils/types.ts
2
- var resolveRelation = (ref) => {
3
- if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
4
- return null;
5
- return ref;
6
- };
7
-
8
- // src/core/metadata/index.ts
9
- function extractSeo(doc) {
10
- const seo = doc.seo ?? {};
11
- const og = seo.openGraph ?? {};
12
- return {
13
- title: seo.title ?? doc.title ?? null,
14
- description: seo.description ?? null,
15
- noIndex: seo.noIndex ?? null,
16
- canonical: seo.canonical ?? null,
17
- openGraph: {
18
- title: og.title ?? null,
19
- description: og.description ?? null,
20
- image: og.image ?? null
21
- }
22
- };
23
- }
24
- function generateMetadata(input, options) {
25
- const title = input.title ?? void 0;
26
- const description = input.description ?? void 0;
27
- const ogTitle = input.openGraph?.title ?? title;
28
- const ogDescription = input.openGraph?.description ?? description;
29
- const image = resolveMetaImage(input.openGraph?.image);
30
- return {
31
- title,
32
- description,
33
- ...input.noIndex && { robots: { index: false, follow: false } },
34
- ...input.canonical && { alternates: { canonical: input.canonical } },
35
- openGraph: {
36
- ...ogTitle && { title: ogTitle },
37
- ...ogDescription && { description: ogDescription },
38
- ...options?.siteName && { siteName: options.siteName },
39
- ...image && { images: [image] }
40
- },
41
- twitter: {
42
- card: image ? "summary_large_image" : "summary",
43
- ...ogTitle && { title: ogTitle },
44
- ...ogDescription && { description: ogDescription },
45
- ...image && { images: [image.url] }
46
- }
47
- };
48
- }
49
- function resolveMetaImage(ref) {
50
- const image = resolveRelation(ref);
51
- if (!image) return null;
52
- const sized = image.sizes?.["1536"];
53
- const url = sized?.url || image.url;
54
- if (!url) return null;
55
- const width = sized?.url ? sized.width : image.width;
56
- const height = sized?.url ? sized.height : image.height;
57
- return {
58
- url,
59
- ...width && { width },
60
- ...height && { height },
61
- ...image.alt && { alt: image.alt }
62
- };
63
- }
64
-
65
- // src/core/collection/query-builder.ts
66
- var CollectionQueryBuilder = class {
67
- constructor(api, collection) {
68
- this.api = api;
69
- this.collection = collection;
70
- }
71
- /**
72
- * Find documents (list query)
73
- * GET /api/{collection}
74
- * @returns Payload CMS find response with docs array and pagination
75
- */
76
- async find(options) {
77
- return this.api.requestFind(
78
- `/api/${String(this.collection)}`,
79
- options
80
- );
81
- }
82
- /**
83
- * Find document by ID
84
- * GET /api/{collection}/{id}
85
- * @returns Document object directly (no wrapper)
86
- */
87
- async findById(id, options) {
88
- return this.api.requestFindById(
89
- `/api/${String(this.collection)}/${String(id)}`,
90
- options
91
- );
92
- }
93
- /**
94
- * Create a new document
95
- * POST /api/{collection}
96
- * @returns Payload CMS mutation response with doc and message
97
- */
98
- async create(data, options) {
99
- const endpoint = `/api/${String(this.collection)}`;
100
- if (options?.file) {
101
- return this.api.requestCreateWithFile(
102
- endpoint,
103
- data,
104
- options.file,
105
- options.filename
106
- );
107
- }
108
- return this.api.requestCreate(endpoint, data);
109
- }
110
- /**
111
- * Update a document by ID
112
- * PATCH /api/{collection}/{id}
113
- * @returns Payload CMS mutation response with doc and message
114
- */
115
- async update(id, data, options) {
116
- const endpoint = `/api/${String(this.collection)}/${String(id)}`;
117
- if (options?.file) {
118
- return this.api.requestUpdateWithFile(
119
- endpoint,
120
- data,
121
- options.file,
122
- options.filename
123
- );
124
- }
125
- return this.api.requestUpdate(endpoint, data);
126
- }
127
- /**
128
- * Count documents
129
- * GET /api/{collection}/count
130
- * @returns Count response with totalDocs
131
- */
132
- async count(options) {
133
- return this.api.requestCount(
134
- `/api/${String(this.collection)}/count`,
135
- options
136
- );
137
- }
138
- /**
139
- * Find first matching document and return its Next.js Metadata.
140
- * Applies depth: 1 (SEO image populate) and limit: 1 automatically.
141
- * @returns Metadata or null if no document matches
142
- */
143
- async findMetadata(options, metadataOptions) {
144
- const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
145
- const doc = docs[0];
146
- if (!doc) return null;
147
- return generateMetadata(
148
- extractSeo(doc),
149
- metadataOptions
150
- );
151
- }
152
- /**
153
- * Find document by ID and return its Next.js Metadata.
154
- * Applies depth: 1 (SEO image populate) automatically.
155
- * @returns Metadata (throws on 404)
156
- */
157
- async findMetadataById(id, metadataOptions) {
158
- const doc = await this.findById(id, { depth: 1 });
159
- return generateMetadata(
160
- extractSeo(doc),
161
- metadataOptions
162
- );
163
- }
164
- /**
165
- * Update multiple documents (bulk update)
166
- * PATCH /api/{collection}
167
- * @returns Payload CMS find response with updated docs
168
- */
169
- async updateMany(where, data) {
170
- return this.api.requestUpdateMany(
171
- `/api/${String(this.collection)}`,
172
- { where, data }
173
- );
174
- }
175
- /**
176
- * Delete a document by ID
177
- * DELETE /api/{collection}/{id}
178
- * @returns Deleted document object directly (no wrapper)
179
- */
180
- async remove(id) {
181
- return this.api.requestDelete(
182
- `/api/${String(this.collection)}/${String(id)}`
183
- );
184
- }
185
- /**
186
- * Delete multiple documents (bulk delete)
187
- * DELETE /api/{collection}
188
- * @returns Payload CMS find response with deleted docs
189
- */
190
- async removeMany(where) {
191
- return this.api.requestDeleteMany(
192
- `/api/${String(this.collection)}`,
193
- { where }
194
- );
195
- }
196
- };
197
- var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
198
- };
199
-
200
1
  // src/core/collection/http-client.ts
201
2
  import { stringify } from "qs-esm";
202
3
 
@@ -328,7 +129,10 @@ function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
328
129
  }
329
130
 
330
131
  // src/core/client/types.ts
331
- function resolveApiUrl() {
132
+ function resolveApiUrl(apiUrl) {
133
+ if (apiUrl) {
134
+ return apiUrl.replace(/\/$/, "");
135
+ }
332
136
  if (typeof process !== "undefined" && process.env) {
333
137
  const envUrl = process.env.SOFTWARE_API_URL || process.env.NEXT_PUBLIC_SOFTWARE_API_URL;
334
138
  if (envUrl) {
@@ -509,6 +313,7 @@ function createHttpStatusError(status, parsed, details, requestId) {
509
313
  }
510
314
  async function httpFetch(url, options) {
511
315
  const {
316
+ apiUrl,
512
317
  publishableKey,
513
318
  secretKey,
514
319
  customerToken,
@@ -518,7 +323,7 @@ async function httpFetch(url, options) {
518
323
  onUnauthorized,
519
324
  ...requestInit
520
325
  } = options || {};
521
- const baseUrl = resolveApiUrl();
326
+ const baseUrl = resolveApiUrl(apiUrl);
522
327
  const retryConfig = {
523
328
  maxRetries: retry?.maxRetries ?? 3,
524
329
  retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
@@ -707,7 +512,7 @@ async function httpFetch(url, options) {
707
512
 
708
513
  // src/core/collection/http-client.ts
709
514
  var HttpClient = class {
710
- constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId) {
515
+ constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
711
516
  this.publishableKey = requirePublishableKeyForSecret(
712
517
  "CollectionClient",
713
518
  publishableKey,
@@ -717,9 +522,11 @@ var HttpClient = class {
717
522
  this.getCustomerToken = getCustomerToken;
718
523
  this.onUnauthorized = onUnauthorized;
719
524
  this.onRequestId = onRequestId;
525
+ this.apiUrl = apiUrl;
720
526
  }
721
527
  get defaultOptions() {
722
528
  const opts = {
529
+ apiUrl: this.apiUrl,
723
530
  publishableKey: this.publishableKey,
724
531
  secretKey: this.secretKey
725
532
  };
@@ -743,99 +550,298 @@ var HttpClient = class {
743
550
  throw err;
744
551
  }
745
552
  }
746
- buildUrl(endpoint, options) {
747
- if (!options) return endpoint;
748
- const queryString = stringify(options, { addQueryPrefix: true });
749
- return queryString ? `${endpoint}${queryString}` : endpoint;
553
+ buildUrl(endpoint, options) {
554
+ if (!options) return endpoint;
555
+ const queryString = stringify(options, { addQueryPrefix: true });
556
+ return queryString ? `${endpoint}${queryString}` : endpoint;
557
+ }
558
+ assertJsonResponse(response) {
559
+ const contentType = response.headers.get("content-type");
560
+ if (!contentType?.includes("application/json")) {
561
+ throw createApiError("Response is not in JSON format.", response.status, {
562
+ contentType
563
+ });
564
+ }
565
+ }
566
+ /**
567
+ * Parse Payload CMS find response (list query)
568
+ * Returns native Payload response structure
569
+ */
570
+ async parseFindResponse(response) {
571
+ const contentType = response.headers.get("content-type");
572
+ try {
573
+ this.assertJsonResponse(response);
574
+ const jsonData = await response.json();
575
+ if (jsonData.docs === void 0) {
576
+ throw createApiError("Invalid find response.", response.status, {
577
+ jsonData
578
+ });
579
+ }
580
+ return {
581
+ docs: jsonData.docs,
582
+ totalDocs: jsonData.totalDocs ?? 0,
583
+ limit: jsonData.limit || 20,
584
+ totalPages: jsonData.totalPages ?? 0,
585
+ page: jsonData.page || 1,
586
+ pagingCounter: jsonData.pagingCounter || 1,
587
+ hasPrevPage: jsonData.hasPrevPage ?? false,
588
+ hasNextPage: jsonData.hasNextPage ?? false,
589
+ prevPage: jsonData.prevPage ?? null,
590
+ nextPage: jsonData.nextPage ?? null
591
+ };
592
+ } catch (error) {
593
+ if (error instanceof SDKError) throw error;
594
+ throw createApiError("Failed to parse response.", response.status, {
595
+ contentType,
596
+ error: error instanceof Error ? error.message : error
597
+ });
598
+ }
599
+ }
600
+ /**
601
+ * Parse Payload CMS mutation response (create/update)
602
+ * Returns native Payload response structure
603
+ */
604
+ async parseMutationResponse(response) {
605
+ const contentType = response.headers.get("content-type");
606
+ try {
607
+ this.assertJsonResponse(response);
608
+ const jsonData = await response.json();
609
+ if (jsonData.doc === void 0) {
610
+ throw createApiError("Invalid mutation response.", response.status, {
611
+ jsonData
612
+ });
613
+ }
614
+ return {
615
+ message: jsonData.message || "",
616
+ doc: jsonData.doc,
617
+ errors: jsonData.errors
618
+ };
619
+ } catch (error) {
620
+ if (error instanceof SDKError) throw error;
621
+ throw createApiError("Failed to parse response.", response.status, {
622
+ contentType,
623
+ error: error instanceof Error ? error.message : error
624
+ });
625
+ }
626
+ }
627
+ /**
628
+ * Parse Payload CMS document response (findById/delete)
629
+ * Returns document directly without wrapper
630
+ */
631
+ async parseDocumentResponse(response) {
632
+ const contentType = response.headers.get("content-type");
633
+ try {
634
+ this.assertJsonResponse(response);
635
+ const jsonData = await response.json();
636
+ return jsonData;
637
+ } catch (error) {
638
+ if (error instanceof SDKError) throw error;
639
+ throw createApiError("Failed to parse response.", response.status, {
640
+ contentType,
641
+ error: error instanceof Error ? error.message : error
642
+ });
643
+ }
644
+ }
645
+ };
646
+
647
+ // src/utils/types.ts
648
+ var resolveRelation = (ref) => {
649
+ if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
650
+ return null;
651
+ return ref;
652
+ };
653
+
654
+ // src/core/metadata/index.ts
655
+ function extractSeo(doc) {
656
+ const seo = doc.seo ?? {};
657
+ const og = seo.openGraph ?? {};
658
+ return {
659
+ title: seo.title ?? doc.title ?? null,
660
+ description: seo.description ?? null,
661
+ noIndex: seo.noIndex ?? null,
662
+ canonical: seo.canonical ?? null,
663
+ openGraph: {
664
+ title: og.title ?? null,
665
+ description: og.description ?? null,
666
+ image: og.image ?? null
667
+ }
668
+ };
669
+ }
670
+ function generateMetadata(input, options) {
671
+ const title = input.title ?? void 0;
672
+ const description = input.description ?? void 0;
673
+ const ogTitle = input.openGraph?.title ?? title;
674
+ const ogDescription = input.openGraph?.description ?? description;
675
+ const image = resolveMetaImage(input.openGraph?.image);
676
+ return {
677
+ title,
678
+ description,
679
+ ...input.noIndex && { robots: { index: false, follow: false } },
680
+ ...input.canonical && { alternates: { canonical: input.canonical } },
681
+ openGraph: {
682
+ ...ogTitle && { title: ogTitle },
683
+ ...ogDescription && { description: ogDescription },
684
+ ...options?.siteName && { siteName: options.siteName },
685
+ ...image && { images: [image] }
686
+ },
687
+ twitter: {
688
+ card: image ? "summary_large_image" : "summary",
689
+ ...ogTitle && { title: ogTitle },
690
+ ...ogDescription && { description: ogDescription },
691
+ ...image && { images: [image.url] }
692
+ }
693
+ };
694
+ }
695
+ function resolveMetaImage(ref) {
696
+ const image = resolveRelation(ref);
697
+ if (!image) return null;
698
+ const sized = image.sizes?.["1536"];
699
+ const url = sized?.url || image.url;
700
+ if (!url) return null;
701
+ const width = sized?.url ? sized.width : image.width;
702
+ const height = sized?.url ? sized.height : image.height;
703
+ return {
704
+ url,
705
+ ...width && { width },
706
+ ...height && { height },
707
+ ...image.alt && { alt: image.alt }
708
+ };
709
+ }
710
+
711
+ // src/core/collection/query-builder.ts
712
+ var CollectionQueryBuilder = class {
713
+ constructor(api, collection) {
714
+ this.api = api;
715
+ this.collection = collection;
716
+ }
717
+ /**
718
+ * Find documents (list query)
719
+ * GET /api/{collection}
720
+ * @returns Payload CMS find response with docs array and pagination
721
+ */
722
+ async find(options) {
723
+ return this.api.requestFind(
724
+ `/api/${String(this.collection)}`,
725
+ options
726
+ );
727
+ }
728
+ /**
729
+ * Find document by ID
730
+ * GET /api/{collection}/{id}
731
+ * @returns Document object directly (no wrapper)
732
+ */
733
+ async findById(id, options) {
734
+ return this.api.requestFindById(
735
+ `/api/${String(this.collection)}/${String(id)}`,
736
+ options
737
+ );
738
+ }
739
+ /**
740
+ * Create a new document
741
+ * POST /api/{collection}
742
+ * @returns Payload CMS mutation response with doc and message
743
+ */
744
+ async create(data, options) {
745
+ const endpoint = `/api/${String(this.collection)}`;
746
+ if (options?.file) {
747
+ return this.api.requestCreateWithFile(
748
+ endpoint,
749
+ data,
750
+ options.file,
751
+ options.filename
752
+ );
753
+ }
754
+ return this.api.requestCreate(endpoint, data);
755
+ }
756
+ /**
757
+ * Update a document by ID
758
+ * PATCH /api/{collection}/{id}
759
+ * @returns Payload CMS mutation response with doc and message
760
+ */
761
+ async update(id, data, options) {
762
+ const endpoint = `/api/${String(this.collection)}/${String(id)}`;
763
+ if (options?.file) {
764
+ return this.api.requestUpdateWithFile(
765
+ endpoint,
766
+ data,
767
+ options.file,
768
+ options.filename
769
+ );
770
+ }
771
+ return this.api.requestUpdate(endpoint, data);
772
+ }
773
+ /**
774
+ * Count documents
775
+ * GET /api/{collection}/count
776
+ * @returns Count response with totalDocs
777
+ */
778
+ async count(options) {
779
+ return this.api.requestCount(
780
+ `/api/${String(this.collection)}/count`,
781
+ options
782
+ );
783
+ }
784
+ /**
785
+ * Find first matching document and return its Next.js Metadata.
786
+ * Applies depth: 1 (SEO image populate) and limit: 1 automatically.
787
+ * @returns Metadata or null if no document matches
788
+ */
789
+ async findMetadata(options, metadataOptions) {
790
+ const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
791
+ const doc = docs[0];
792
+ if (!doc) return null;
793
+ return generateMetadata(
794
+ extractSeo(doc),
795
+ metadataOptions
796
+ );
750
797
  }
751
- assertJsonResponse(response) {
752
- const contentType = response.headers.get("content-type");
753
- if (!contentType?.includes("application/json")) {
754
- throw createApiError("Response is not in JSON format.", response.status, {
755
- contentType
756
- });
757
- }
798
+ /**
799
+ * Find document by ID and return its Next.js Metadata.
800
+ * Applies depth: 1 (SEO image populate) automatically.
801
+ * @returns Metadata (throws on 404)
802
+ */
803
+ async findMetadataById(id, metadataOptions) {
804
+ const doc = await this.findById(id, { depth: 1 });
805
+ return generateMetadata(
806
+ extractSeo(doc),
807
+ metadataOptions
808
+ );
758
809
  }
759
810
  /**
760
- * Parse Payload CMS find response (list query)
761
- * Returns native Payload response structure
811
+ * Update multiple documents (bulk update)
812
+ * PATCH /api/{collection}
813
+ * @returns Payload CMS find response with updated docs
762
814
  */
763
- async parseFindResponse(response) {
764
- const contentType = response.headers.get("content-type");
765
- try {
766
- this.assertJsonResponse(response);
767
- const jsonData = await response.json();
768
- if (jsonData.docs === void 0) {
769
- throw createApiError("Invalid find response.", response.status, {
770
- jsonData
771
- });
772
- }
773
- return {
774
- docs: jsonData.docs,
775
- totalDocs: jsonData.totalDocs ?? 0,
776
- limit: jsonData.limit || 20,
777
- totalPages: jsonData.totalPages ?? 0,
778
- page: jsonData.page || 1,
779
- pagingCounter: jsonData.pagingCounter || 1,
780
- hasPrevPage: jsonData.hasPrevPage ?? false,
781
- hasNextPage: jsonData.hasNextPage ?? false,
782
- prevPage: jsonData.prevPage ?? null,
783
- nextPage: jsonData.nextPage ?? null
784
- };
785
- } catch (error) {
786
- if (error instanceof SDKError) throw error;
787
- throw createApiError("Failed to parse response.", response.status, {
788
- contentType,
789
- error: error instanceof Error ? error.message : error
790
- });
791
- }
815
+ async updateMany(where, data) {
816
+ return this.api.requestUpdateMany(
817
+ `/api/${String(this.collection)}`,
818
+ { where, data }
819
+ );
792
820
  }
793
821
  /**
794
- * Parse Payload CMS mutation response (create/update)
795
- * Returns native Payload response structure
822
+ * Delete a document by ID
823
+ * DELETE /api/{collection}/{id}
824
+ * @returns Deleted document object directly (no wrapper)
796
825
  */
797
- async parseMutationResponse(response) {
798
- const contentType = response.headers.get("content-type");
799
- try {
800
- this.assertJsonResponse(response);
801
- const jsonData = await response.json();
802
- if (jsonData.doc === void 0) {
803
- throw createApiError("Invalid mutation response.", response.status, {
804
- jsonData
805
- });
806
- }
807
- return {
808
- message: jsonData.message || "",
809
- doc: jsonData.doc,
810
- errors: jsonData.errors
811
- };
812
- } catch (error) {
813
- if (error instanceof SDKError) throw error;
814
- throw createApiError("Failed to parse response.", response.status, {
815
- contentType,
816
- error: error instanceof Error ? error.message : error
817
- });
818
- }
826
+ async remove(id) {
827
+ return this.api.requestDelete(
828
+ `/api/${String(this.collection)}/${String(id)}`
829
+ );
819
830
  }
820
831
  /**
821
- * Parse Payload CMS document response (findById/delete)
822
- * Returns document directly without wrapper
832
+ * Delete multiple documents (bulk delete)
833
+ * DELETE /api/{collection}
834
+ * @returns Payload CMS find response with deleted docs
823
835
  */
824
- async parseDocumentResponse(response) {
825
- const contentType = response.headers.get("content-type");
826
- try {
827
- this.assertJsonResponse(response);
828
- const jsonData = await response.json();
829
- return jsonData;
830
- } catch (error) {
831
- if (error instanceof SDKError) throw error;
832
- throw createApiError("Failed to parse response.", response.status, {
833
- contentType,
834
- error: error instanceof Error ? error.message : error
835
- });
836
- }
836
+ async removeMany(where) {
837
+ return this.api.requestDeleteMany(
838
+ `/api/${String(this.collection)}`,
839
+ { where }
840
+ );
837
841
  }
838
842
  };
843
+ var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
844
+ };
839
845
 
840
846
  // src/core/collection/collection-client.ts
841
847
  function buildPayloadFormData(data, file, filename) {
@@ -1046,6 +1052,7 @@ var CommunityClient = class {
1046
1052
  options.secretKey
1047
1053
  );
1048
1054
  this.secretKey = options.secretKey;
1055
+ this.apiUrl = options.apiUrl;
1049
1056
  this.customerToken = options.customerToken;
1050
1057
  this.onUnauthorized = options.onUnauthorized;
1051
1058
  this.onRequestId = options.onRequestId;
@@ -1060,6 +1067,7 @@ var CommunityClient = class {
1060
1067
  try {
1061
1068
  const response = await httpFetch(endpoint, {
1062
1069
  method,
1070
+ apiUrl: this.apiUrl,
1063
1071
  publishableKey: this.publishableKey,
1064
1072
  secretKey: this.secretKey,
1065
1073
  customerToken: token ?? void 0,
@@ -1220,6 +1228,7 @@ var BaseApi = class {
1220
1228
  options.secretKey
1221
1229
  );
1222
1230
  this.secretKey = options.secretKey;
1231
+ this.apiUrl = options.apiUrl;
1223
1232
  this.onRequestId = options.onRequestId;
1224
1233
  }
1225
1234
  async request(endpoint, body, options) {
@@ -1227,6 +1236,7 @@ var BaseApi = class {
1227
1236
  try {
1228
1237
  const response = await httpFetch(endpoint, {
1229
1238
  method,
1239
+ apiUrl: this.apiUrl,
1230
1240
  publishableKey: this.publishableKey,
1231
1241
  secretKey: this.secretKey,
1232
1242
  ...body !== void 0 && { body: JSON.stringify(body) },
@@ -1269,6 +1279,7 @@ var CartApi = class {
1269
1279
  options.secretKey
1270
1280
  );
1271
1281
  this.secretKey = options.secretKey;
1282
+ this.apiUrl = options.apiUrl;
1272
1283
  this.customerToken = options.customerToken;
1273
1284
  this.onUnauthorized = options.onUnauthorized;
1274
1285
  this.onRequestId = options.onRequestId;
@@ -1278,6 +1289,7 @@ var CartApi = class {
1278
1289
  try {
1279
1290
  const response = await httpFetch(endpoint, {
1280
1291
  method,
1292
+ apiUrl: this.apiUrl,
1281
1293
  publishableKey: this.publishableKey,
1282
1294
  secretKey: this.secretKey,
1283
1295
  customerToken: token ?? void 0,
@@ -1448,6 +1460,7 @@ var ServerCommerceClient = class {
1448
1460
  const serverOptions = {
1449
1461
  publishableKey,
1450
1462
  secretKey: options.secretKey,
1463
+ apiUrl: options.apiUrl,
1451
1464
  onRequestId: options.onRequestId
1452
1465
  };
1453
1466
  const productApi = new ProductApi(serverOptions);
@@ -1492,578 +1505,6 @@ var ServerCommerceClient = class {
1492
1505
  }
1493
1506
  };
1494
1507
 
1495
- // src/core/query/get-query-client.ts
1496
- import {
1497
- isServer,
1498
- QueryClient,
1499
- defaultShouldDehydrateQuery
1500
- } from "@tanstack/react-query";
1501
- function makeQueryClient() {
1502
- return new QueryClient({
1503
- defaultOptions: {
1504
- queries: {
1505
- // Infinite staleTime: server-fetched data persists until explicitly invalidated.
1506
- // For browser clients needing fresher data, override per-query:
1507
- // useQuery({ ..., staleTime: 5 * 60 * 1000 })
1508
- staleTime: Number.POSITIVE_INFINITY,
1509
- refetchOnWindowFocus: false
1510
- },
1511
- dehydrate: {
1512
- shouldDehydrateQuery: (query) => defaultShouldDehydrateQuery(query) || query.state.status === "pending",
1513
- shouldRedactErrors: () => false
1514
- }
1515
- }
1516
- });
1517
- }
1518
- var browserQueryClient;
1519
- function getQueryClient() {
1520
- if (isServer) {
1521
- return makeQueryClient();
1522
- }
1523
- if (!browserQueryClient) {
1524
- browserQueryClient = makeQueryClient();
1525
- }
1526
- return browserQueryClient;
1527
- }
1528
-
1529
- // src/core/query/query-hooks.ts
1530
- import {
1531
- useInfiniteQuery as useInfiniteQueryOriginal2,
1532
- useQuery as useQueryOriginal3,
1533
- useSuspenseInfiniteQuery as useSuspenseInfiniteQueryOriginal2,
1534
- useSuspenseQuery as useSuspenseQueryOriginal2
1535
- } from "@tanstack/react-query";
1536
-
1537
- // src/core/query/collection-hooks.ts
1538
- import {
1539
- useQuery as useQueryOriginal,
1540
- useSuspenseQuery as useSuspenseQueryOriginal,
1541
- useInfiniteQuery as useInfiniteQueryOriginal,
1542
- useSuspenseInfiniteQuery as useSuspenseInfiniteQueryOriginal,
1543
- useMutation as useMutationOriginal
1544
- } from "@tanstack/react-query";
1545
-
1546
- // src/core/query/query-keys.ts
1547
- function collectionKeys(collection) {
1548
- return {
1549
- all: [collection],
1550
- lists: () => [collection, "list"],
1551
- list: (options) => [collection, "list", options],
1552
- details: () => [collection, "detail"],
1553
- detail: (id, options) => [collection, "detail", id, options],
1554
- infinites: () => [collection, "infinite"],
1555
- infinite: (options) => [collection, "infinite", options]
1556
- };
1557
- }
1558
- var customerKeys = {
1559
- all: ["customer"],
1560
- me: () => ["customer", "me"]
1561
- };
1562
- var productKeys = {
1563
- listingGroups: (options) => ["products", "listing-groups", "list", options],
1564
- listingGroupsInfinite: (options) => ["products", "listing-groups", "infinite", options],
1565
- detail: (params) => ["products", "detail", params],
1566
- detailAll: () => ["products", "detail"]
1567
- };
1568
-
1569
- // src/core/query/collection-hooks.ts
1570
- var PRODUCT_DETAIL_INVALIDATING_COLLECTIONS = /* @__PURE__ */ new Set([
1571
- "products",
1572
- "product-variants",
1573
- "product-options",
1574
- "product-option-values",
1575
- "product-categories",
1576
- "product-tags",
1577
- "product-collections",
1578
- "brands",
1579
- "brand-logos",
1580
- "images"
1581
- ]);
1582
- var DEFAULT_PAGE_SIZE = 20;
1583
- var CollectionHooks = class {
1584
- constructor(queryClient, collectionClient) {
1585
- this.queryClient = queryClient;
1586
- this.collectionClient = collectionClient;
1587
- }
1588
- // ===== useQuery =====
1589
- useQuery(params, options) {
1590
- const { collection, options: queryOptions } = params;
1591
- const { placeholderData, ...restOptions } = options ?? {};
1592
- return useQueryOriginal({
1593
- queryKey: collectionKeys(collection).list(queryOptions),
1594
- queryFn: async () => {
1595
- return await this.collectionClient.from(collection).find(queryOptions);
1596
- },
1597
- ...restOptions,
1598
- // NonFunctionGuard<T> incompatible with generic union types — safe cast
1599
- ...placeholderData !== void 0 && {
1600
- placeholderData
1601
- }
1602
- });
1603
- }
1604
- // ===== useSuspenseQuery =====
1605
- useSuspenseQuery(params, options) {
1606
- const { collection, options: queryOptions } = params;
1607
- return useSuspenseQueryOriginal({
1608
- queryKey: collectionKeys(collection).list(queryOptions),
1609
- queryFn: async () => {
1610
- return await this.collectionClient.from(collection).find(queryOptions);
1611
- },
1612
- ...options
1613
- });
1614
- }
1615
- // ===== useQueryById =====
1616
- useQueryById(params, options) {
1617
- const { collection, id, options: queryOptions } = params;
1618
- const { placeholderData, ...restOptions } = options ?? {};
1619
- return useQueryOriginal({
1620
- queryKey: collectionKeys(collection).detail(id, queryOptions),
1621
- queryFn: async () => {
1622
- return await this.collectionClient.from(collection).findById(id, queryOptions);
1623
- },
1624
- ...restOptions,
1625
- // NonFunctionGuard<T> incompatible with generic union types — safe cast
1626
- ...placeholderData !== void 0 && {
1627
- placeholderData
1628
- }
1629
- });
1630
- }
1631
- // ===== useSuspenseQueryById =====
1632
- useSuspenseQueryById(params, options) {
1633
- const { collection, id, options: queryOptions } = params;
1634
- return useSuspenseQueryOriginal({
1635
- queryKey: collectionKeys(collection).detail(id, queryOptions),
1636
- queryFn: async () => {
1637
- return await this.collectionClient.from(collection).findById(id, queryOptions);
1638
- },
1639
- ...options
1640
- });
1641
- }
1642
- // ===== useInfiniteQuery =====
1643
- useInfiniteQuery(params, options) {
1644
- const {
1645
- collection,
1646
- options: queryOptions,
1647
- pageSize = DEFAULT_PAGE_SIZE
1648
- } = params;
1649
- return useInfiniteQueryOriginal({
1650
- queryKey: collectionKeys(collection).infinite(queryOptions),
1651
- queryFn: async ({ pageParam }) => {
1652
- const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
1653
- return response;
1654
- },
1655
- initialPageParam: 1,
1656
- getNextPageParam: (lastPage) => {
1657
- return lastPage.hasNextPage ? lastPage.nextPage : void 0;
1658
- },
1659
- ...options
1660
- });
1661
- }
1662
- // ===== useSuspenseInfiniteQuery =====
1663
- useSuspenseInfiniteQuery(params, options) {
1664
- const {
1665
- collection,
1666
- options: queryOptions,
1667
- pageSize = DEFAULT_PAGE_SIZE
1668
- } = params;
1669
- return useSuspenseInfiniteQueryOriginal({
1670
- queryKey: collectionKeys(collection).infinite(queryOptions),
1671
- queryFn: async ({ pageParam }) => {
1672
- const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
1673
- return response;
1674
- },
1675
- initialPageParam: 1,
1676
- getNextPageParam: (lastPage) => {
1677
- return lastPage.hasNextPage ? lastPage.nextPage : void 0;
1678
- },
1679
- ...options
1680
- });
1681
- }
1682
- // ===== prefetchQuery =====
1683
- async prefetchQuery(params, options) {
1684
- const { collection, options: queryOptions } = params;
1685
- return this.queryClient.prefetchQuery({
1686
- queryKey: collectionKeys(collection).list(queryOptions),
1687
- queryFn: async () => {
1688
- return await this.collectionClient.from(collection).find(queryOptions);
1689
- },
1690
- ...options
1691
- });
1692
- }
1693
- // ===== prefetchQueryById =====
1694
- async prefetchQueryById(params, options) {
1695
- const { collection, id, options: queryOptions } = params;
1696
- return this.queryClient.prefetchQuery({
1697
- queryKey: collectionKeys(collection).detail(id, queryOptions),
1698
- queryFn: async () => {
1699
- return await this.collectionClient.from(collection).findById(id, queryOptions);
1700
- },
1701
- ...options
1702
- });
1703
- }
1704
- // ===== prefetchInfiniteQuery =====
1705
- async prefetchInfiniteQuery(params, options) {
1706
- const {
1707
- collection,
1708
- options: queryOptions,
1709
- pageSize = DEFAULT_PAGE_SIZE
1710
- } = params;
1711
- return this.queryClient.prefetchInfiniteQuery({
1712
- queryKey: collectionKeys(collection).infinite(queryOptions),
1713
- queryFn: async ({ pageParam }) => {
1714
- const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
1715
- return response;
1716
- },
1717
- initialPageParam: 1,
1718
- getNextPageParam: (lastPage) => {
1719
- return lastPage.hasNextPage ? lastPage.nextPage : void 0;
1720
- },
1721
- pages: options?.pages ?? 1,
1722
- staleTime: options?.staleTime
1723
- });
1724
- }
1725
- // ===== Mutation Hooks =====
1726
- useCreate(params, options) {
1727
- const { collection } = params;
1728
- return useMutationOriginal({
1729
- mutationFn: async (variables) => {
1730
- return await this.collectionClient.from(collection).create(
1731
- variables.data,
1732
- variables.file ? { file: variables.file, filename: variables.filename } : void 0
1733
- );
1734
- },
1735
- onSuccess: (data) => {
1736
- this.queryClient.invalidateQueries({
1737
- queryKey: collectionKeys(collection).all
1738
- });
1739
- if (PRODUCT_DETAIL_INVALIDATING_COLLECTIONS.has(collection)) {
1740
- this.queryClient.invalidateQueries({ queryKey: ["products", "detail"] });
1741
- }
1742
- options?.onSuccess?.(data);
1743
- },
1744
- onError: options?.onError,
1745
- onSettled: options?.onSettled
1746
- });
1747
- }
1748
- useUpdate(params, options) {
1749
- const { collection } = params;
1750
- return useMutationOriginal({
1751
- mutationFn: async (variables) => {
1752
- return await this.collectionClient.from(collection).update(
1753
- variables.id,
1754
- variables.data,
1755
- variables.file ? { file: variables.file, filename: variables.filename } : void 0
1756
- );
1757
- },
1758
- onSuccess: (data) => {
1759
- this.queryClient.invalidateQueries({
1760
- queryKey: collectionKeys(collection).all
1761
- });
1762
- if (PRODUCT_DETAIL_INVALIDATING_COLLECTIONS.has(collection)) {
1763
- this.queryClient.invalidateQueries({ queryKey: ["products", "detail"] });
1764
- }
1765
- options?.onSuccess?.(data);
1766
- },
1767
- onError: options?.onError,
1768
- onSettled: options?.onSettled
1769
- });
1770
- }
1771
- useRemove(params, options) {
1772
- const { collection } = params;
1773
- return useMutationOriginal({
1774
- mutationFn: async (id) => {
1775
- return await this.collectionClient.from(collection).remove(id);
1776
- },
1777
- onSuccess: (data) => {
1778
- this.queryClient.invalidateQueries({
1779
- queryKey: collectionKeys(collection).all
1780
- });
1781
- if (PRODUCT_DETAIL_INVALIDATING_COLLECTIONS.has(collection)) {
1782
- this.queryClient.invalidateQueries({ queryKey: ["products", "detail"] });
1783
- }
1784
- options?.onSuccess?.(data);
1785
- },
1786
- onError: options?.onError,
1787
- onSettled: options?.onSettled
1788
- });
1789
- }
1790
- // ===== Cache Utilities =====
1791
- invalidateQueries(collection, type) {
1792
- const queryKey = type ? [collection, type] : [collection];
1793
- return this.queryClient.invalidateQueries({ queryKey });
1794
- }
1795
- getQueryData(collection, type, idOrOptions, options) {
1796
- if (type === "list") {
1797
- return this.queryClient.getQueryData(
1798
- collectionKeys(collection).list(idOrOptions)
1799
- );
1800
- }
1801
- return this.queryClient.getQueryData(
1802
- collectionKeys(collection).detail(idOrOptions, options)
1803
- );
1804
- }
1805
- setQueryData(collection, type, dataOrId, dataOrOptions, options) {
1806
- if (type === "list") {
1807
- this.queryClient.setQueryData(
1808
- collectionKeys(collection).list(dataOrOptions),
1809
- dataOrId
1810
- );
1811
- } else {
1812
- this.queryClient.setQueryData(
1813
- collectionKeys(collection).detail(dataOrId, options),
1814
- dataOrOptions
1815
- );
1816
- }
1817
- }
1818
- };
1819
-
1820
- // src/core/query/customer-hooks.ts
1821
- import {
1822
- useQuery as useQueryOriginal2,
1823
- useMutation as useMutationOriginal2
1824
- } from "@tanstack/react-query";
1825
- function createMutation(mutationFn, callbacks, onSuccessExtra) {
1826
- return useMutationOriginal2({
1827
- mutationFn,
1828
- onSuccess: (data) => {
1829
- onSuccessExtra?.(data);
1830
- callbacks?.onSuccess?.(data);
1831
- },
1832
- onError: callbacks?.onError,
1833
- onSettled: callbacks?.onSettled
1834
- });
1835
- }
1836
- var CustomerHooks = class {
1837
- constructor(queryClient, customerAuth) {
1838
- this.invalidateMe = () => {
1839
- this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
1840
- };
1841
- this.queryClient = queryClient;
1842
- this.customerAuth = customerAuth;
1843
- }
1844
- ensureCustomerAuth() {
1845
- if (!this.customerAuth) {
1846
- throw createConfigError(
1847
- "Customer hooks require Client. Use createClient() instead of createServerClient()."
1848
- );
1849
- }
1850
- return this.customerAuth;
1851
- }
1852
- // ===== useCustomerMe =====
1853
- useCustomerMe(options) {
1854
- return useQueryOriginal2({
1855
- queryKey: customerKeys.me(),
1856
- queryFn: async () => {
1857
- return await this.ensureCustomerAuth().me();
1858
- },
1859
- ...options,
1860
- enabled: (options?.enabled ?? true) && !!this.customerAuth?.isAuthenticated()
1861
- });
1862
- }
1863
- // ===== Mutations =====
1864
- useCustomerLogin(options) {
1865
- return createMutation(
1866
- (data) => this.ensureCustomerAuth().login(data),
1867
- options,
1868
- this.invalidateMe
1869
- );
1870
- }
1871
- useCustomerRegister(options) {
1872
- return createMutation(
1873
- (data) => this.ensureCustomerAuth().register(data),
1874
- options
1875
- );
1876
- }
1877
- useCustomerLogout(options) {
1878
- return useMutationOriginal2({
1879
- mutationFn: async () => {
1880
- this.ensureCustomerAuth().logout();
1881
- },
1882
- onSuccess: () => {
1883
- this.queryClient.removeQueries({ queryKey: customerKeys.all });
1884
- options?.onSuccess?.();
1885
- },
1886
- onError: options?.onError,
1887
- onSettled: options?.onSettled
1888
- });
1889
- }
1890
- useCustomerForgotPassword(options) {
1891
- return createMutation(
1892
- (email) => this.ensureCustomerAuth().forgotPassword(email).then(() => {
1893
- }),
1894
- options
1895
- );
1896
- }
1897
- useCustomerResetPassword(options) {
1898
- return createMutation(
1899
- (data) => this.ensureCustomerAuth().resetPassword(data.token, data.password).then(() => {
1900
- }),
1901
- options
1902
- );
1903
- }
1904
- useCustomerRefreshToken(options) {
1905
- return createMutation(
1906
- () => this.ensureCustomerAuth().refreshToken(),
1907
- options,
1908
- this.invalidateMe
1909
- );
1910
- }
1911
- useCustomerUpdateProfile(options) {
1912
- return createMutation(
1913
- (data) => this.ensureCustomerAuth().updateProfile(data),
1914
- options,
1915
- this.invalidateMe
1916
- );
1917
- }
1918
- useCustomerChangePassword(options) {
1919
- return createMutation(
1920
- (data) => this.ensureCustomerAuth().changePassword(data.currentPassword, data.newPassword).then(() => {
1921
- }),
1922
- options
1923
- );
1924
- }
1925
- // ===== Customer Cache Utilities =====
1926
- invalidateCustomerQueries() {
1927
- return this.queryClient.invalidateQueries({ queryKey: customerKeys.all });
1928
- }
1929
- getCustomerData() {
1930
- return this.queryClient.getQueryData(customerKeys.me());
1931
- }
1932
- setCustomerData(data) {
1933
- this.queryClient.setQueryData(customerKeys.me(), data);
1934
- }
1935
- };
1936
-
1937
- // src/core/query/query-hooks.ts
1938
- var QueryHooks = class extends CollectionHooks {
1939
- constructor(queryClient, collectionClient, customerAuth, commerceClient) {
1940
- super(queryClient, collectionClient);
1941
- // --- Customer hooks delegation ---
1942
- this.useCustomerMe = (...args) => this._customer.useCustomerMe(...args);
1943
- this.useCustomerLogin = (...args) => this._customer.useCustomerLogin(...args);
1944
- this.useCustomerRegister = (...args) => this._customer.useCustomerRegister(...args);
1945
- this.useCustomerLogout = (...args) => this._customer.useCustomerLogout(...args);
1946
- this.useCustomerForgotPassword = (...args) => this._customer.useCustomerForgotPassword(...args);
1947
- this.useCustomerResetPassword = (...args) => this._customer.useCustomerResetPassword(...args);
1948
- this.useCustomerRefreshToken = (...args) => this._customer.useCustomerRefreshToken(...args);
1949
- this.useCustomerUpdateProfile = (...args) => this._customer.useCustomerUpdateProfile(...args);
1950
- this.useCustomerChangePassword = (...args) => this._customer.useCustomerChangePassword(...args);
1951
- // --- Customer cache delegation ---
1952
- this.invalidateCustomerQueries = () => this._customer.invalidateCustomerQueries();
1953
- this.getCustomerData = () => this._customer.getCustomerData();
1954
- this.setCustomerData = (data) => this._customer.setCustomerData(data);
1955
- this._customer = new CustomerHooks(queryClient, customerAuth);
1956
- this._commerce = commerceClient;
1957
- }
1958
- useProductListingGroupsQuery(params, options) {
1959
- const queryOptions = params.options;
1960
- const { placeholderData, ...restOptions } = options ?? {};
1961
- return useQueryOriginal3({
1962
- queryKey: productKeys.listingGroups(queryOptions),
1963
- queryFn: async () => this.collectionClient.requestFindEndpoint(
1964
- "/api/products/listing-groups/query",
1965
- { options: queryOptions }
1966
- ),
1967
- ...restOptions,
1968
- ...placeholderData !== void 0 && {
1969
- placeholderData
1970
- }
1971
- });
1972
- }
1973
- useSuspenseProductListingGroupsQuery(params, options) {
1974
- const queryOptions = params.options;
1975
- return useSuspenseQueryOriginal2({
1976
- queryKey: productKeys.listingGroups(queryOptions),
1977
- queryFn: async () => this.collectionClient.requestFindEndpoint(
1978
- "/api/products/listing-groups/query",
1979
- { options: queryOptions }
1980
- ),
1981
- ...options
1982
- });
1983
- }
1984
- useInfiniteProductListingGroupsQuery(params, options) {
1985
- const {
1986
- options: queryOptions,
1987
- pageSize = 20
1988
- } = params;
1989
- return useInfiniteQueryOriginal2({
1990
- queryKey: productKeys.listingGroupsInfinite(queryOptions),
1991
- queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
1992
- "/api/products/listing-groups/query",
1993
- {
1994
- options: { ...queryOptions, page: pageParam, limit: pageSize }
1995
- }
1996
- ),
1997
- initialPageParam: 1,
1998
- getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
1999
- ...options
2000
- });
2001
- }
2002
- useSuspenseInfiniteProductListingGroupsQuery(params, options) {
2003
- const {
2004
- options: queryOptions,
2005
- pageSize = 20
2006
- } = params;
2007
- return useSuspenseInfiniteQueryOriginal2({
2008
- queryKey: productKeys.listingGroupsInfinite(queryOptions),
2009
- queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
2010
- "/api/products/listing-groups/query",
2011
- {
2012
- options: { ...queryOptions, page: pageParam, limit: pageSize }
2013
- }
2014
- ),
2015
- initialPageParam: 1,
2016
- getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
2017
- ...options
2018
- });
2019
- }
2020
- async prefetchProductListingGroupsQuery(params, options) {
2021
- const queryOptions = params.options;
2022
- return this.queryClient.prefetchQuery({
2023
- queryKey: productKeys.listingGroups(queryOptions),
2024
- queryFn: async () => this.collectionClient.requestFindEndpoint(
2025
- "/api/products/listing-groups/query",
2026
- { options: queryOptions }
2027
- ),
2028
- ...options
2029
- });
2030
- }
2031
- async prefetchInfiniteProductListingGroupsQuery(params, options) {
2032
- const {
2033
- options: queryOptions,
2034
- pageSize = 20
2035
- } = params;
2036
- return this.queryClient.prefetchInfiniteQuery({
2037
- queryKey: productKeys.listingGroupsInfinite(queryOptions),
2038
- queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
2039
- "/api/products/listing-groups/query",
2040
- {
2041
- options: { ...queryOptions, page: pageParam, limit: pageSize }
2042
- }
2043
- ),
2044
- initialPageParam: 1,
2045
- getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
2046
- pages: options?.pages ?? 1,
2047
- staleTime: options?.staleTime
2048
- });
2049
- }
2050
- useProductDetail(params, options) {
2051
- const discriminator = "slug" in params ? params.slug : params.id;
2052
- const enabled = options?.enabled !== false && Boolean(discriminator);
2053
- return useQueryOriginal3({
2054
- queryKey: productKeys.detail(params),
2055
- queryFn: () => this._commerce.product.detail(params),
2056
- enabled
2057
- });
2058
- }
2059
- useProductDetailBySlug(slug, options) {
2060
- return this.useProductDetail({ slug }, options);
2061
- }
2062
- useProductDetailById(id, options) {
2063
- return this.useProductDetail({ id }, options);
2064
- }
2065
- };
2066
-
2067
1508
  // src/core/client/client.server.ts
2068
1509
  var ServerClient = class {
2069
1510
  constructor(options) {
@@ -2093,6 +1534,7 @@ var ServerClient = class {
2093
1534
  const serverOptions = {
2094
1535
  publishableKey: this.config.publishableKey,
2095
1536
  secretKey: this.config.secretKey,
1537
+ apiUrl: this.config.apiUrl,
2096
1538
  onRequestId
2097
1539
  };
2098
1540
  this.commerce = new ServerCommerceClient(serverOptions);
@@ -2109,10 +1551,9 @@ var ServerClient = class {
2109
1551
  this.config.secretKey,
2110
1552
  void 0,
2111
1553
  void 0,
2112
- onRequestId
1554
+ onRequestId,
1555
+ this.config.apiUrl
2113
1556
  );
2114
- this.queryClient = getQueryClient();
2115
- this.query = new QueryHooks(this.queryClient, this.collections, void 0, this.commerce);
2116
1557
  }
2117
1558
  getState() {
2118
1559
  return { ...this.state };