@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.
- package/README.md +273 -73
- package/dist/analytics/react.cjs +4 -1
- package/dist/analytics/react.cjs.map +1 -1
- package/dist/analytics/react.js +4 -1
- package/dist/analytics/react.js.map +1 -1
- package/dist/analytics.cjs +4 -1
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.js +4 -1
- package/dist/analytics.js.map +1 -1
- package/dist/client.cjs +1476 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.cts +28 -0
- package/dist/client.d.ts +28 -0
- package/dist/client.js +1453 -0
- package/dist/client.js.map +1 -0
- package/dist/collection-client-B9d9kr1d.d.ts +218 -0
- package/dist/collection-client-QPbwimkU.d.cts +218 -0
- package/dist/{const-DAjQYNuM.d.ts → const-B75IFDRi.d.ts} +2 -4
- package/dist/{const-Dsixdi6z.d.cts → const-VZuk2tWc.d.cts} +2 -4
- package/dist/index-B2WbhEgT.d.cts +106 -0
- package/dist/index-B2WbhEgT.d.ts +106 -0
- package/dist/index.cjs +784 -1530
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -115
- package/dist/index.d.ts +11 -115
- package/dist/index.js +784 -1548
- package/dist/index.js.map +1 -1
- package/dist/metadata.cjs +91 -0
- package/dist/metadata.cjs.map +1 -0
- package/dist/metadata.d.cts +58 -0
- package/dist/metadata.d.ts +58 -0
- package/dist/metadata.js +68 -0
- package/dist/metadata.js.map +1 -0
- package/dist/{payload-types-Ci-ZA7aM.d.cts → payload-types-DPjO_IbQ.d.cts} +9 -3
- package/dist/{payload-types-Ci-ZA7aM.d.ts → payload-types-DPjO_IbQ.d.ts} +9 -3
- package/dist/query.cjs +1791 -0
- package/dist/query.cjs.map +1 -0
- package/dist/query.d.cts +244 -0
- package/dist/query.d.ts +244 -0
- package/dist/query.js +1786 -0
- package/dist/query.js.map +1 -0
- package/dist/realtime.cjs +4 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js +4 -1
- package/dist/realtime.js.map +1 -1
- package/dist/{server-BINWywT8.d.cts → server-CrsPyqEc.d.cts} +14 -31
- package/dist/{server-BINWywT8.d.ts → server-CrsPyqEc.d.ts} +14 -31
- package/dist/server.cjs +299 -840
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +112 -7
- package/dist/server.d.ts +112 -7
- package/dist/server.js +299 -858
- package/dist/server.js.map +1 -1
- package/dist/{types-BWq_WlbB.d.ts → types-1fBLrYU7.d.ts} +1 -1
- package/dist/{types-zKjATmDK.d.cts → types-BwT0eeaz.d.cts} +1 -1
- package/dist/{server-Cv0Q4dPQ.d.ts → types-Dlb2mwpX.d.cts} +228 -741
- package/dist/{server-C0C8dtms.d.cts → types-DuSKPiY5.d.ts} +228 -741
- package/dist/ui/canvas/server.cjs +7 -6
- package/dist/ui/canvas/server.cjs.map +1 -1
- package/dist/ui/canvas/server.d.cts +1 -3
- package/dist/ui/canvas/server.d.ts +1 -3
- package/dist/ui/canvas/server.js +7 -6
- package/dist/ui/canvas/server.js.map +1 -1
- package/dist/ui/canvas.cjs +11 -10
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.d.cts +29 -6
- package/dist/ui/canvas.d.ts +29 -6
- package/dist/ui/canvas.js +11 -10
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/webhook.d.cts +3 -3
- package/dist/webhook.d.ts +3 -3
- package/package.json +84 -15
package/dist/server.cjs
CHANGED
|
@@ -30,205 +30,6 @@ __export(server_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(server_exports);
|
|
32
32
|
|
|
33
|
-
// src/utils/types.ts
|
|
34
|
-
var resolveRelation = (ref) => {
|
|
35
|
-
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
36
|
-
return null;
|
|
37
|
-
return ref;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
// src/core/metadata/index.ts
|
|
41
|
-
function extractSeo(doc) {
|
|
42
|
-
const seo = doc.seo ?? {};
|
|
43
|
-
const og = seo.openGraph ?? {};
|
|
44
|
-
return {
|
|
45
|
-
title: seo.title ?? doc.title ?? null,
|
|
46
|
-
description: seo.description ?? null,
|
|
47
|
-
noIndex: seo.noIndex ?? null,
|
|
48
|
-
canonical: seo.canonical ?? null,
|
|
49
|
-
openGraph: {
|
|
50
|
-
title: og.title ?? null,
|
|
51
|
-
description: og.description ?? null,
|
|
52
|
-
image: og.image ?? null
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
function generateMetadata(input, options) {
|
|
57
|
-
const title = input.title ?? void 0;
|
|
58
|
-
const description = input.description ?? void 0;
|
|
59
|
-
const ogTitle = input.openGraph?.title ?? title;
|
|
60
|
-
const ogDescription = input.openGraph?.description ?? description;
|
|
61
|
-
const image = resolveMetaImage(input.openGraph?.image);
|
|
62
|
-
return {
|
|
63
|
-
title,
|
|
64
|
-
description,
|
|
65
|
-
...input.noIndex && { robots: { index: false, follow: false } },
|
|
66
|
-
...input.canonical && { alternates: { canonical: input.canonical } },
|
|
67
|
-
openGraph: {
|
|
68
|
-
...ogTitle && { title: ogTitle },
|
|
69
|
-
...ogDescription && { description: ogDescription },
|
|
70
|
-
...options?.siteName && { siteName: options.siteName },
|
|
71
|
-
...image && { images: [image] }
|
|
72
|
-
},
|
|
73
|
-
twitter: {
|
|
74
|
-
card: image ? "summary_large_image" : "summary",
|
|
75
|
-
...ogTitle && { title: ogTitle },
|
|
76
|
-
...ogDescription && { description: ogDescription },
|
|
77
|
-
...image && { images: [image.url] }
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function resolveMetaImage(ref) {
|
|
82
|
-
const image = resolveRelation(ref);
|
|
83
|
-
if (!image) return null;
|
|
84
|
-
const sized = image.sizes?.["1536"];
|
|
85
|
-
const url = sized?.url || image.url;
|
|
86
|
-
if (!url) return null;
|
|
87
|
-
const width = sized?.url ? sized.width : image.width;
|
|
88
|
-
const height = sized?.url ? sized.height : image.height;
|
|
89
|
-
return {
|
|
90
|
-
url,
|
|
91
|
-
...width && { width },
|
|
92
|
-
...height && { height },
|
|
93
|
-
...image.alt && { alt: image.alt }
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// src/core/collection/query-builder.ts
|
|
98
|
-
var CollectionQueryBuilder = class {
|
|
99
|
-
constructor(api, collection) {
|
|
100
|
-
this.api = api;
|
|
101
|
-
this.collection = collection;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Find documents (list query)
|
|
105
|
-
* GET /api/{collection}
|
|
106
|
-
* @returns Payload CMS find response with docs array and pagination
|
|
107
|
-
*/
|
|
108
|
-
async find(options) {
|
|
109
|
-
return this.api.requestFind(
|
|
110
|
-
`/api/${String(this.collection)}`,
|
|
111
|
-
options
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Find document by ID
|
|
116
|
-
* GET /api/{collection}/{id}
|
|
117
|
-
* @returns Document object directly (no wrapper)
|
|
118
|
-
*/
|
|
119
|
-
async findById(id, options) {
|
|
120
|
-
return this.api.requestFindById(
|
|
121
|
-
`/api/${String(this.collection)}/${String(id)}`,
|
|
122
|
-
options
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Create a new document
|
|
127
|
-
* POST /api/{collection}
|
|
128
|
-
* @returns Payload CMS mutation response with doc and message
|
|
129
|
-
*/
|
|
130
|
-
async create(data, options) {
|
|
131
|
-
const endpoint = `/api/${String(this.collection)}`;
|
|
132
|
-
if (options?.file) {
|
|
133
|
-
return this.api.requestCreateWithFile(
|
|
134
|
-
endpoint,
|
|
135
|
-
data,
|
|
136
|
-
options.file,
|
|
137
|
-
options.filename
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
return this.api.requestCreate(endpoint, data);
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Update a document by ID
|
|
144
|
-
* PATCH /api/{collection}/{id}
|
|
145
|
-
* @returns Payload CMS mutation response with doc and message
|
|
146
|
-
*/
|
|
147
|
-
async update(id, data, options) {
|
|
148
|
-
const endpoint = `/api/${String(this.collection)}/${String(id)}`;
|
|
149
|
-
if (options?.file) {
|
|
150
|
-
return this.api.requestUpdateWithFile(
|
|
151
|
-
endpoint,
|
|
152
|
-
data,
|
|
153
|
-
options.file,
|
|
154
|
-
options.filename
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
return this.api.requestUpdate(endpoint, data);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Count documents
|
|
161
|
-
* GET /api/{collection}/count
|
|
162
|
-
* @returns Count response with totalDocs
|
|
163
|
-
*/
|
|
164
|
-
async count(options) {
|
|
165
|
-
return this.api.requestCount(
|
|
166
|
-
`/api/${String(this.collection)}/count`,
|
|
167
|
-
options
|
|
168
|
-
);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Find first matching document and return its Next.js Metadata.
|
|
172
|
-
* Applies depth: 1 (SEO image populate) and limit: 1 automatically.
|
|
173
|
-
* @returns Metadata or null if no document matches
|
|
174
|
-
*/
|
|
175
|
-
async findMetadata(options, metadataOptions) {
|
|
176
|
-
const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
|
|
177
|
-
const doc = docs[0];
|
|
178
|
-
if (!doc) return null;
|
|
179
|
-
return generateMetadata(
|
|
180
|
-
extractSeo(doc),
|
|
181
|
-
metadataOptions
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Find document by ID and return its Next.js Metadata.
|
|
186
|
-
* Applies depth: 1 (SEO image populate) automatically.
|
|
187
|
-
* @returns Metadata (throws on 404)
|
|
188
|
-
*/
|
|
189
|
-
async findMetadataById(id, metadataOptions) {
|
|
190
|
-
const doc = await this.findById(id, { depth: 1 });
|
|
191
|
-
return generateMetadata(
|
|
192
|
-
extractSeo(doc),
|
|
193
|
-
metadataOptions
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Update multiple documents (bulk update)
|
|
198
|
-
* PATCH /api/{collection}
|
|
199
|
-
* @returns Payload CMS find response with updated docs
|
|
200
|
-
*/
|
|
201
|
-
async updateMany(where, data) {
|
|
202
|
-
return this.api.requestUpdateMany(
|
|
203
|
-
`/api/${String(this.collection)}`,
|
|
204
|
-
{ where, data }
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Delete a document by ID
|
|
209
|
-
* DELETE /api/{collection}/{id}
|
|
210
|
-
* @returns Deleted document object directly (no wrapper)
|
|
211
|
-
*/
|
|
212
|
-
async remove(id) {
|
|
213
|
-
return this.api.requestDelete(
|
|
214
|
-
`/api/${String(this.collection)}/${String(id)}`
|
|
215
|
-
);
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Delete multiple documents (bulk delete)
|
|
219
|
-
* DELETE /api/{collection}
|
|
220
|
-
* @returns Payload CMS find response with deleted docs
|
|
221
|
-
*/
|
|
222
|
-
async removeMany(where) {
|
|
223
|
-
return this.api.requestDeleteMany(
|
|
224
|
-
`/api/${String(this.collection)}`,
|
|
225
|
-
{ where }
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
};
|
|
229
|
-
var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
|
|
230
|
-
};
|
|
231
|
-
|
|
232
33
|
// src/core/collection/http-client.ts
|
|
233
34
|
var import_qs_esm = require("qs-esm");
|
|
234
35
|
|
|
@@ -360,7 +161,10 @@ function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
|
|
|
360
161
|
}
|
|
361
162
|
|
|
362
163
|
// src/core/client/types.ts
|
|
363
|
-
function resolveApiUrl() {
|
|
164
|
+
function resolveApiUrl(apiUrl) {
|
|
165
|
+
if (apiUrl) {
|
|
166
|
+
return apiUrl.replace(/\/$/, "");
|
|
167
|
+
}
|
|
364
168
|
if (typeof process !== "undefined" && process.env) {
|
|
365
169
|
const envUrl = process.env.SOFTWARE_API_URL || process.env.NEXT_PUBLIC_SOFTWARE_API_URL;
|
|
366
170
|
if (envUrl) {
|
|
@@ -541,6 +345,7 @@ function createHttpStatusError(status, parsed, details, requestId) {
|
|
|
541
345
|
}
|
|
542
346
|
async function httpFetch(url, options) {
|
|
543
347
|
const {
|
|
348
|
+
apiUrl,
|
|
544
349
|
publishableKey,
|
|
545
350
|
secretKey,
|
|
546
351
|
customerToken,
|
|
@@ -550,7 +355,7 @@ async function httpFetch(url, options) {
|
|
|
550
355
|
onUnauthorized,
|
|
551
356
|
...requestInit
|
|
552
357
|
} = options || {};
|
|
553
|
-
const baseUrl = resolveApiUrl();
|
|
358
|
+
const baseUrl = resolveApiUrl(apiUrl);
|
|
554
359
|
const retryConfig = {
|
|
555
360
|
maxRetries: retry?.maxRetries ?? 3,
|
|
556
361
|
retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
|
|
@@ -739,7 +544,7 @@ async function httpFetch(url, options) {
|
|
|
739
544
|
|
|
740
545
|
// src/core/collection/http-client.ts
|
|
741
546
|
var HttpClient = class {
|
|
742
|
-
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId) {
|
|
547
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
743
548
|
this.publishableKey = requirePublishableKeyForSecret(
|
|
744
549
|
"CollectionClient",
|
|
745
550
|
publishableKey,
|
|
@@ -749,9 +554,11 @@ var HttpClient = class {
|
|
|
749
554
|
this.getCustomerToken = getCustomerToken;
|
|
750
555
|
this.onUnauthorized = onUnauthorized;
|
|
751
556
|
this.onRequestId = onRequestId;
|
|
557
|
+
this.apiUrl = apiUrl;
|
|
752
558
|
}
|
|
753
559
|
get defaultOptions() {
|
|
754
560
|
const opts = {
|
|
561
|
+
apiUrl: this.apiUrl,
|
|
755
562
|
publishableKey: this.publishableKey,
|
|
756
563
|
secretKey: this.secretKey
|
|
757
564
|
};
|
|
@@ -775,99 +582,298 @@ var HttpClient = class {
|
|
|
775
582
|
throw err;
|
|
776
583
|
}
|
|
777
584
|
}
|
|
778
|
-
buildUrl(endpoint, options) {
|
|
779
|
-
if (!options) return endpoint;
|
|
780
|
-
const queryString = (0, import_qs_esm.stringify)(options, { addQueryPrefix: true });
|
|
781
|
-
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
585
|
+
buildUrl(endpoint, options) {
|
|
586
|
+
if (!options) return endpoint;
|
|
587
|
+
const queryString = (0, import_qs_esm.stringify)(options, { addQueryPrefix: true });
|
|
588
|
+
return queryString ? `${endpoint}${queryString}` : endpoint;
|
|
589
|
+
}
|
|
590
|
+
assertJsonResponse(response) {
|
|
591
|
+
const contentType = response.headers.get("content-type");
|
|
592
|
+
if (!contentType?.includes("application/json")) {
|
|
593
|
+
throw createApiError("Response is not in JSON format.", response.status, {
|
|
594
|
+
contentType
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
/**
|
|
599
|
+
* Parse Payload CMS find response (list query)
|
|
600
|
+
* Returns native Payload response structure
|
|
601
|
+
*/
|
|
602
|
+
async parseFindResponse(response) {
|
|
603
|
+
const contentType = response.headers.get("content-type");
|
|
604
|
+
try {
|
|
605
|
+
this.assertJsonResponse(response);
|
|
606
|
+
const jsonData = await response.json();
|
|
607
|
+
if (jsonData.docs === void 0) {
|
|
608
|
+
throw createApiError("Invalid find response.", response.status, {
|
|
609
|
+
jsonData
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
docs: jsonData.docs,
|
|
614
|
+
totalDocs: jsonData.totalDocs ?? 0,
|
|
615
|
+
limit: jsonData.limit || 20,
|
|
616
|
+
totalPages: jsonData.totalPages ?? 0,
|
|
617
|
+
page: jsonData.page || 1,
|
|
618
|
+
pagingCounter: jsonData.pagingCounter || 1,
|
|
619
|
+
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
620
|
+
hasNextPage: jsonData.hasNextPage ?? false,
|
|
621
|
+
prevPage: jsonData.prevPage ?? null,
|
|
622
|
+
nextPage: jsonData.nextPage ?? null
|
|
623
|
+
};
|
|
624
|
+
} catch (error) {
|
|
625
|
+
if (error instanceof SDKError) throw error;
|
|
626
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
627
|
+
contentType,
|
|
628
|
+
error: error instanceof Error ? error.message : error
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Parse Payload CMS mutation response (create/update)
|
|
634
|
+
* Returns native Payload response structure
|
|
635
|
+
*/
|
|
636
|
+
async parseMutationResponse(response) {
|
|
637
|
+
const contentType = response.headers.get("content-type");
|
|
638
|
+
try {
|
|
639
|
+
this.assertJsonResponse(response);
|
|
640
|
+
const jsonData = await response.json();
|
|
641
|
+
if (jsonData.doc === void 0) {
|
|
642
|
+
throw createApiError("Invalid mutation response.", response.status, {
|
|
643
|
+
jsonData
|
|
644
|
+
});
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
message: jsonData.message || "",
|
|
648
|
+
doc: jsonData.doc,
|
|
649
|
+
errors: jsonData.errors
|
|
650
|
+
};
|
|
651
|
+
} catch (error) {
|
|
652
|
+
if (error instanceof SDKError) throw error;
|
|
653
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
654
|
+
contentType,
|
|
655
|
+
error: error instanceof Error ? error.message : error
|
|
656
|
+
});
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Parse Payload CMS document response (findById/delete)
|
|
661
|
+
* Returns document directly without wrapper
|
|
662
|
+
*/
|
|
663
|
+
async parseDocumentResponse(response) {
|
|
664
|
+
const contentType = response.headers.get("content-type");
|
|
665
|
+
try {
|
|
666
|
+
this.assertJsonResponse(response);
|
|
667
|
+
const jsonData = await response.json();
|
|
668
|
+
return jsonData;
|
|
669
|
+
} catch (error) {
|
|
670
|
+
if (error instanceof SDKError) throw error;
|
|
671
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
672
|
+
contentType,
|
|
673
|
+
error: error instanceof Error ? error.message : error
|
|
674
|
+
});
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
// src/utils/types.ts
|
|
680
|
+
var resolveRelation = (ref) => {
|
|
681
|
+
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
682
|
+
return null;
|
|
683
|
+
return ref;
|
|
684
|
+
};
|
|
685
|
+
|
|
686
|
+
// src/core/metadata/index.ts
|
|
687
|
+
function extractSeo(doc) {
|
|
688
|
+
const seo = doc.seo ?? {};
|
|
689
|
+
const og = seo.openGraph ?? {};
|
|
690
|
+
return {
|
|
691
|
+
title: seo.title ?? doc.title ?? null,
|
|
692
|
+
description: seo.description ?? null,
|
|
693
|
+
noIndex: seo.noIndex ?? null,
|
|
694
|
+
canonical: seo.canonical ?? null,
|
|
695
|
+
openGraph: {
|
|
696
|
+
title: og.title ?? null,
|
|
697
|
+
description: og.description ?? null,
|
|
698
|
+
image: og.image ?? null
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
function generateMetadata(input, options) {
|
|
703
|
+
const title = input.title ?? void 0;
|
|
704
|
+
const description = input.description ?? void 0;
|
|
705
|
+
const ogTitle = input.openGraph?.title ?? title;
|
|
706
|
+
const ogDescription = input.openGraph?.description ?? description;
|
|
707
|
+
const image = resolveMetaImage(input.openGraph?.image);
|
|
708
|
+
return {
|
|
709
|
+
title,
|
|
710
|
+
description,
|
|
711
|
+
...input.noIndex && { robots: { index: false, follow: false } },
|
|
712
|
+
...input.canonical && { alternates: { canonical: input.canonical } },
|
|
713
|
+
openGraph: {
|
|
714
|
+
...ogTitle && { title: ogTitle },
|
|
715
|
+
...ogDescription && { description: ogDescription },
|
|
716
|
+
...options?.siteName && { siteName: options.siteName },
|
|
717
|
+
...image && { images: [image] }
|
|
718
|
+
},
|
|
719
|
+
twitter: {
|
|
720
|
+
card: image ? "summary_large_image" : "summary",
|
|
721
|
+
...ogTitle && { title: ogTitle },
|
|
722
|
+
...ogDescription && { description: ogDescription },
|
|
723
|
+
...image && { images: [image.url] }
|
|
724
|
+
}
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
function resolveMetaImage(ref) {
|
|
728
|
+
const image = resolveRelation(ref);
|
|
729
|
+
if (!image) return null;
|
|
730
|
+
const sized = image.sizes?.["1536"];
|
|
731
|
+
const url = sized?.url || image.url;
|
|
732
|
+
if (!url) return null;
|
|
733
|
+
const width = sized?.url ? sized.width : image.width;
|
|
734
|
+
const height = sized?.url ? sized.height : image.height;
|
|
735
|
+
return {
|
|
736
|
+
url,
|
|
737
|
+
...width && { width },
|
|
738
|
+
...height && { height },
|
|
739
|
+
...image.alt && { alt: image.alt }
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// src/core/collection/query-builder.ts
|
|
744
|
+
var CollectionQueryBuilder = class {
|
|
745
|
+
constructor(api, collection) {
|
|
746
|
+
this.api = api;
|
|
747
|
+
this.collection = collection;
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Find documents (list query)
|
|
751
|
+
* GET /api/{collection}
|
|
752
|
+
* @returns Payload CMS find response with docs array and pagination
|
|
753
|
+
*/
|
|
754
|
+
async find(options) {
|
|
755
|
+
return this.api.requestFind(
|
|
756
|
+
`/api/${String(this.collection)}`,
|
|
757
|
+
options
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Find document by ID
|
|
762
|
+
* GET /api/{collection}/{id}
|
|
763
|
+
* @returns Document object directly (no wrapper)
|
|
764
|
+
*/
|
|
765
|
+
async findById(id, options) {
|
|
766
|
+
return this.api.requestFindById(
|
|
767
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
768
|
+
options
|
|
769
|
+
);
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Create a new document
|
|
773
|
+
* POST /api/{collection}
|
|
774
|
+
* @returns Payload CMS mutation response with doc and message
|
|
775
|
+
*/
|
|
776
|
+
async create(data, options) {
|
|
777
|
+
const endpoint = `/api/${String(this.collection)}`;
|
|
778
|
+
if (options?.file) {
|
|
779
|
+
return this.api.requestCreateWithFile(
|
|
780
|
+
endpoint,
|
|
781
|
+
data,
|
|
782
|
+
options.file,
|
|
783
|
+
options.filename
|
|
784
|
+
);
|
|
785
|
+
}
|
|
786
|
+
return this.api.requestCreate(endpoint, data);
|
|
787
|
+
}
|
|
788
|
+
/**
|
|
789
|
+
* Update a document by ID
|
|
790
|
+
* PATCH /api/{collection}/{id}
|
|
791
|
+
* @returns Payload CMS mutation response with doc and message
|
|
792
|
+
*/
|
|
793
|
+
async update(id, data, options) {
|
|
794
|
+
const endpoint = `/api/${String(this.collection)}/${String(id)}`;
|
|
795
|
+
if (options?.file) {
|
|
796
|
+
return this.api.requestUpdateWithFile(
|
|
797
|
+
endpoint,
|
|
798
|
+
data,
|
|
799
|
+
options.file,
|
|
800
|
+
options.filename
|
|
801
|
+
);
|
|
802
|
+
}
|
|
803
|
+
return this.api.requestUpdate(endpoint, data);
|
|
804
|
+
}
|
|
805
|
+
/**
|
|
806
|
+
* Count documents
|
|
807
|
+
* GET /api/{collection}/count
|
|
808
|
+
* @returns Count response with totalDocs
|
|
809
|
+
*/
|
|
810
|
+
async count(options) {
|
|
811
|
+
return this.api.requestCount(
|
|
812
|
+
`/api/${String(this.collection)}/count`,
|
|
813
|
+
options
|
|
814
|
+
);
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Find first matching document and return its Next.js Metadata.
|
|
818
|
+
* Applies depth: 1 (SEO image populate) and limit: 1 automatically.
|
|
819
|
+
* @returns Metadata or null if no document matches
|
|
820
|
+
*/
|
|
821
|
+
async findMetadata(options, metadataOptions) {
|
|
822
|
+
const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
|
|
823
|
+
const doc = docs[0];
|
|
824
|
+
if (!doc) return null;
|
|
825
|
+
return generateMetadata(
|
|
826
|
+
extractSeo(doc),
|
|
827
|
+
metadataOptions
|
|
828
|
+
);
|
|
782
829
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
}
|
|
830
|
+
/**
|
|
831
|
+
* Find document by ID and return its Next.js Metadata.
|
|
832
|
+
* Applies depth: 1 (SEO image populate) automatically.
|
|
833
|
+
* @returns Metadata (throws on 404)
|
|
834
|
+
*/
|
|
835
|
+
async findMetadataById(id, metadataOptions) {
|
|
836
|
+
const doc = await this.findById(id, { depth: 1 });
|
|
837
|
+
return generateMetadata(
|
|
838
|
+
extractSeo(doc),
|
|
839
|
+
metadataOptions
|
|
840
|
+
);
|
|
790
841
|
}
|
|
791
842
|
/**
|
|
792
|
-
*
|
|
793
|
-
*
|
|
843
|
+
* Update multiple documents (bulk update)
|
|
844
|
+
* PATCH /api/{collection}
|
|
845
|
+
* @returns Payload CMS find response with updated docs
|
|
794
846
|
*/
|
|
795
|
-
async
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
if (jsonData.docs === void 0) {
|
|
801
|
-
throw createApiError("Invalid find response.", response.status, {
|
|
802
|
-
jsonData
|
|
803
|
-
});
|
|
804
|
-
}
|
|
805
|
-
return {
|
|
806
|
-
docs: jsonData.docs,
|
|
807
|
-
totalDocs: jsonData.totalDocs ?? 0,
|
|
808
|
-
limit: jsonData.limit || 20,
|
|
809
|
-
totalPages: jsonData.totalPages ?? 0,
|
|
810
|
-
page: jsonData.page || 1,
|
|
811
|
-
pagingCounter: jsonData.pagingCounter || 1,
|
|
812
|
-
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
813
|
-
hasNextPage: jsonData.hasNextPage ?? false,
|
|
814
|
-
prevPage: jsonData.prevPage ?? null,
|
|
815
|
-
nextPage: jsonData.nextPage ?? null
|
|
816
|
-
};
|
|
817
|
-
} catch (error) {
|
|
818
|
-
if (error instanceof SDKError) throw error;
|
|
819
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
820
|
-
contentType,
|
|
821
|
-
error: error instanceof Error ? error.message : error
|
|
822
|
-
});
|
|
823
|
-
}
|
|
847
|
+
async updateMany(where, data) {
|
|
848
|
+
return this.api.requestUpdateMany(
|
|
849
|
+
`/api/${String(this.collection)}`,
|
|
850
|
+
{ where, data }
|
|
851
|
+
);
|
|
824
852
|
}
|
|
825
853
|
/**
|
|
826
|
-
*
|
|
827
|
-
*
|
|
854
|
+
* Delete a document by ID
|
|
855
|
+
* DELETE /api/{collection}/{id}
|
|
856
|
+
* @returns Deleted document object directly (no wrapper)
|
|
828
857
|
*/
|
|
829
|
-
async
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
const jsonData = await response.json();
|
|
834
|
-
if (jsonData.doc === void 0) {
|
|
835
|
-
throw createApiError("Invalid mutation response.", response.status, {
|
|
836
|
-
jsonData
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
return {
|
|
840
|
-
message: jsonData.message || "",
|
|
841
|
-
doc: jsonData.doc,
|
|
842
|
-
errors: jsonData.errors
|
|
843
|
-
};
|
|
844
|
-
} catch (error) {
|
|
845
|
-
if (error instanceof SDKError) throw error;
|
|
846
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
847
|
-
contentType,
|
|
848
|
-
error: error instanceof Error ? error.message : error
|
|
849
|
-
});
|
|
850
|
-
}
|
|
858
|
+
async remove(id) {
|
|
859
|
+
return this.api.requestDelete(
|
|
860
|
+
`/api/${String(this.collection)}/${String(id)}`
|
|
861
|
+
);
|
|
851
862
|
}
|
|
852
863
|
/**
|
|
853
|
-
*
|
|
854
|
-
*
|
|
864
|
+
* Delete multiple documents (bulk delete)
|
|
865
|
+
* DELETE /api/{collection}
|
|
866
|
+
* @returns Payload CMS find response with deleted docs
|
|
855
867
|
*/
|
|
856
|
-
async
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
return jsonData;
|
|
862
|
-
} catch (error) {
|
|
863
|
-
if (error instanceof SDKError) throw error;
|
|
864
|
-
throw createApiError("Failed to parse response.", response.status, {
|
|
865
|
-
contentType,
|
|
866
|
-
error: error instanceof Error ? error.message : error
|
|
867
|
-
});
|
|
868
|
-
}
|
|
868
|
+
async removeMany(where) {
|
|
869
|
+
return this.api.requestDeleteMany(
|
|
870
|
+
`/api/${String(this.collection)}`,
|
|
871
|
+
{ where }
|
|
872
|
+
);
|
|
869
873
|
}
|
|
870
874
|
};
|
|
875
|
+
var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
|
|
876
|
+
};
|
|
871
877
|
|
|
872
878
|
// src/core/collection/collection-client.ts
|
|
873
879
|
function buildPayloadFormData(data, file, filename) {
|
|
@@ -1078,6 +1084,7 @@ var CommunityClient = class {
|
|
|
1078
1084
|
options.secretKey
|
|
1079
1085
|
);
|
|
1080
1086
|
this.secretKey = options.secretKey;
|
|
1087
|
+
this.apiUrl = options.apiUrl;
|
|
1081
1088
|
this.customerToken = options.customerToken;
|
|
1082
1089
|
this.onUnauthorized = options.onUnauthorized;
|
|
1083
1090
|
this.onRequestId = options.onRequestId;
|
|
@@ -1092,6 +1099,7 @@ var CommunityClient = class {
|
|
|
1092
1099
|
try {
|
|
1093
1100
|
const response = await httpFetch(endpoint, {
|
|
1094
1101
|
method,
|
|
1102
|
+
apiUrl: this.apiUrl,
|
|
1095
1103
|
publishableKey: this.publishableKey,
|
|
1096
1104
|
secretKey: this.secretKey,
|
|
1097
1105
|
customerToken: token ?? void 0,
|
|
@@ -1252,6 +1260,7 @@ var BaseApi = class {
|
|
|
1252
1260
|
options.secretKey
|
|
1253
1261
|
);
|
|
1254
1262
|
this.secretKey = options.secretKey;
|
|
1263
|
+
this.apiUrl = options.apiUrl;
|
|
1255
1264
|
this.onRequestId = options.onRequestId;
|
|
1256
1265
|
}
|
|
1257
1266
|
async request(endpoint, body, options) {
|
|
@@ -1259,6 +1268,7 @@ var BaseApi = class {
|
|
|
1259
1268
|
try {
|
|
1260
1269
|
const response = await httpFetch(endpoint, {
|
|
1261
1270
|
method,
|
|
1271
|
+
apiUrl: this.apiUrl,
|
|
1262
1272
|
publishableKey: this.publishableKey,
|
|
1263
1273
|
secretKey: this.secretKey,
|
|
1264
1274
|
...body !== void 0 && { body: JSON.stringify(body) },
|
|
@@ -1301,6 +1311,7 @@ var CartApi = class {
|
|
|
1301
1311
|
options.secretKey
|
|
1302
1312
|
);
|
|
1303
1313
|
this.secretKey = options.secretKey;
|
|
1314
|
+
this.apiUrl = options.apiUrl;
|
|
1304
1315
|
this.customerToken = options.customerToken;
|
|
1305
1316
|
this.onUnauthorized = options.onUnauthorized;
|
|
1306
1317
|
this.onRequestId = options.onRequestId;
|
|
@@ -1310,6 +1321,7 @@ var CartApi = class {
|
|
|
1310
1321
|
try {
|
|
1311
1322
|
const response = await httpFetch(endpoint, {
|
|
1312
1323
|
method,
|
|
1324
|
+
apiUrl: this.apiUrl,
|
|
1313
1325
|
publishableKey: this.publishableKey,
|
|
1314
1326
|
secretKey: this.secretKey,
|
|
1315
1327
|
customerToken: token ?? void 0,
|
|
@@ -1480,6 +1492,7 @@ var ServerCommerceClient = class {
|
|
|
1480
1492
|
const serverOptions = {
|
|
1481
1493
|
publishableKey,
|
|
1482
1494
|
secretKey: options.secretKey,
|
|
1495
|
+
apiUrl: options.apiUrl,
|
|
1483
1496
|
onRequestId: options.onRequestId
|
|
1484
1497
|
};
|
|
1485
1498
|
const productApi = new ProductApi(serverOptions);
|
|
@@ -1524,560 +1537,6 @@ var ServerCommerceClient = class {
|
|
|
1524
1537
|
}
|
|
1525
1538
|
};
|
|
1526
1539
|
|
|
1527
|
-
// src/core/query/get-query-client.ts
|
|
1528
|
-
var import_react_query = require("@tanstack/react-query");
|
|
1529
|
-
function makeQueryClient() {
|
|
1530
|
-
return new import_react_query.QueryClient({
|
|
1531
|
-
defaultOptions: {
|
|
1532
|
-
queries: {
|
|
1533
|
-
// Infinite staleTime: server-fetched data persists until explicitly invalidated.
|
|
1534
|
-
// For browser clients needing fresher data, override per-query:
|
|
1535
|
-
// useQuery({ ..., staleTime: 5 * 60 * 1000 })
|
|
1536
|
-
staleTime: Number.POSITIVE_INFINITY,
|
|
1537
|
-
refetchOnWindowFocus: false
|
|
1538
|
-
},
|
|
1539
|
-
dehydrate: {
|
|
1540
|
-
shouldDehydrateQuery: (query) => (0, import_react_query.defaultShouldDehydrateQuery)(query) || query.state.status === "pending",
|
|
1541
|
-
shouldRedactErrors: () => false
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1544
|
-
});
|
|
1545
|
-
}
|
|
1546
|
-
var browserQueryClient;
|
|
1547
|
-
function getQueryClient() {
|
|
1548
|
-
if (import_react_query.isServer) {
|
|
1549
|
-
return makeQueryClient();
|
|
1550
|
-
}
|
|
1551
|
-
if (!browserQueryClient) {
|
|
1552
|
-
browserQueryClient = makeQueryClient();
|
|
1553
|
-
}
|
|
1554
|
-
return browserQueryClient;
|
|
1555
|
-
}
|
|
1556
|
-
|
|
1557
|
-
// src/core/query/query-hooks.ts
|
|
1558
|
-
var import_react_query4 = require("@tanstack/react-query");
|
|
1559
|
-
|
|
1560
|
-
// src/core/query/collection-hooks.ts
|
|
1561
|
-
var import_react_query2 = require("@tanstack/react-query");
|
|
1562
|
-
|
|
1563
|
-
// src/core/query/query-keys.ts
|
|
1564
|
-
function collectionKeys(collection) {
|
|
1565
|
-
return {
|
|
1566
|
-
all: [collection],
|
|
1567
|
-
lists: () => [collection, "list"],
|
|
1568
|
-
list: (options) => [collection, "list", options],
|
|
1569
|
-
details: () => [collection, "detail"],
|
|
1570
|
-
detail: (id, options) => [collection, "detail", id, options],
|
|
1571
|
-
infinites: () => [collection, "infinite"],
|
|
1572
|
-
infinite: (options) => [collection, "infinite", options]
|
|
1573
|
-
};
|
|
1574
|
-
}
|
|
1575
|
-
var customerKeys = {
|
|
1576
|
-
all: ["customer"],
|
|
1577
|
-
me: () => ["customer", "me"]
|
|
1578
|
-
};
|
|
1579
|
-
var productKeys = {
|
|
1580
|
-
listingGroups: (options) => ["products", "listing-groups", "list", options],
|
|
1581
|
-
listingGroupsInfinite: (options) => ["products", "listing-groups", "infinite", options],
|
|
1582
|
-
detail: (params) => ["products", "detail", params],
|
|
1583
|
-
detailAll: () => ["products", "detail"]
|
|
1584
|
-
};
|
|
1585
|
-
|
|
1586
|
-
// src/core/query/collection-hooks.ts
|
|
1587
|
-
var PRODUCT_DETAIL_INVALIDATING_COLLECTIONS = /* @__PURE__ */ new Set([
|
|
1588
|
-
"products",
|
|
1589
|
-
"product-variants",
|
|
1590
|
-
"product-options",
|
|
1591
|
-
"product-option-values",
|
|
1592
|
-
"product-categories",
|
|
1593
|
-
"product-tags",
|
|
1594
|
-
"product-collections",
|
|
1595
|
-
"brands",
|
|
1596
|
-
"brand-logos",
|
|
1597
|
-
"images"
|
|
1598
|
-
]);
|
|
1599
|
-
var DEFAULT_PAGE_SIZE = 20;
|
|
1600
|
-
var CollectionHooks = class {
|
|
1601
|
-
constructor(queryClient, collectionClient) {
|
|
1602
|
-
this.queryClient = queryClient;
|
|
1603
|
-
this.collectionClient = collectionClient;
|
|
1604
|
-
}
|
|
1605
|
-
// ===== useQuery =====
|
|
1606
|
-
useQuery(params, options) {
|
|
1607
|
-
const { collection, options: queryOptions } = params;
|
|
1608
|
-
const { placeholderData, ...restOptions } = options ?? {};
|
|
1609
|
-
return (0, import_react_query2.useQuery)({
|
|
1610
|
-
queryKey: collectionKeys(collection).list(queryOptions),
|
|
1611
|
-
queryFn: async () => {
|
|
1612
|
-
return await this.collectionClient.from(collection).find(queryOptions);
|
|
1613
|
-
},
|
|
1614
|
-
...restOptions,
|
|
1615
|
-
// NonFunctionGuard<T> incompatible with generic union types — safe cast
|
|
1616
|
-
...placeholderData !== void 0 && {
|
|
1617
|
-
placeholderData
|
|
1618
|
-
}
|
|
1619
|
-
});
|
|
1620
|
-
}
|
|
1621
|
-
// ===== useSuspenseQuery =====
|
|
1622
|
-
useSuspenseQuery(params, options) {
|
|
1623
|
-
const { collection, options: queryOptions } = params;
|
|
1624
|
-
return (0, import_react_query2.useSuspenseQuery)({
|
|
1625
|
-
queryKey: collectionKeys(collection).list(queryOptions),
|
|
1626
|
-
queryFn: async () => {
|
|
1627
|
-
return await this.collectionClient.from(collection).find(queryOptions);
|
|
1628
|
-
},
|
|
1629
|
-
...options
|
|
1630
|
-
});
|
|
1631
|
-
}
|
|
1632
|
-
// ===== useQueryById =====
|
|
1633
|
-
useQueryById(params, options) {
|
|
1634
|
-
const { collection, id, options: queryOptions } = params;
|
|
1635
|
-
const { placeholderData, ...restOptions } = options ?? {};
|
|
1636
|
-
return (0, import_react_query2.useQuery)({
|
|
1637
|
-
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
1638
|
-
queryFn: async () => {
|
|
1639
|
-
return await this.collectionClient.from(collection).findById(id, queryOptions);
|
|
1640
|
-
},
|
|
1641
|
-
...restOptions,
|
|
1642
|
-
// NonFunctionGuard<T> incompatible with generic union types — safe cast
|
|
1643
|
-
...placeholderData !== void 0 && {
|
|
1644
|
-
placeholderData
|
|
1645
|
-
}
|
|
1646
|
-
});
|
|
1647
|
-
}
|
|
1648
|
-
// ===== useSuspenseQueryById =====
|
|
1649
|
-
useSuspenseQueryById(params, options) {
|
|
1650
|
-
const { collection, id, options: queryOptions } = params;
|
|
1651
|
-
return (0, import_react_query2.useSuspenseQuery)({
|
|
1652
|
-
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
1653
|
-
queryFn: async () => {
|
|
1654
|
-
return await this.collectionClient.from(collection).findById(id, queryOptions);
|
|
1655
|
-
},
|
|
1656
|
-
...options
|
|
1657
|
-
});
|
|
1658
|
-
}
|
|
1659
|
-
// ===== useInfiniteQuery =====
|
|
1660
|
-
useInfiniteQuery(params, options) {
|
|
1661
|
-
const {
|
|
1662
|
-
collection,
|
|
1663
|
-
options: queryOptions,
|
|
1664
|
-
pageSize = DEFAULT_PAGE_SIZE
|
|
1665
|
-
} = params;
|
|
1666
|
-
return (0, import_react_query2.useInfiniteQuery)({
|
|
1667
|
-
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1668
|
-
queryFn: async ({ pageParam }) => {
|
|
1669
|
-
const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
|
|
1670
|
-
return response;
|
|
1671
|
-
},
|
|
1672
|
-
initialPageParam: 1,
|
|
1673
|
-
getNextPageParam: (lastPage) => {
|
|
1674
|
-
return lastPage.hasNextPage ? lastPage.nextPage : void 0;
|
|
1675
|
-
},
|
|
1676
|
-
...options
|
|
1677
|
-
});
|
|
1678
|
-
}
|
|
1679
|
-
// ===== useSuspenseInfiniteQuery =====
|
|
1680
|
-
useSuspenseInfiniteQuery(params, options) {
|
|
1681
|
-
const {
|
|
1682
|
-
collection,
|
|
1683
|
-
options: queryOptions,
|
|
1684
|
-
pageSize = DEFAULT_PAGE_SIZE
|
|
1685
|
-
} = params;
|
|
1686
|
-
return (0, import_react_query2.useSuspenseInfiniteQuery)({
|
|
1687
|
-
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1688
|
-
queryFn: async ({ pageParam }) => {
|
|
1689
|
-
const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
|
|
1690
|
-
return response;
|
|
1691
|
-
},
|
|
1692
|
-
initialPageParam: 1,
|
|
1693
|
-
getNextPageParam: (lastPage) => {
|
|
1694
|
-
return lastPage.hasNextPage ? lastPage.nextPage : void 0;
|
|
1695
|
-
},
|
|
1696
|
-
...options
|
|
1697
|
-
});
|
|
1698
|
-
}
|
|
1699
|
-
// ===== prefetchQuery =====
|
|
1700
|
-
async prefetchQuery(params, options) {
|
|
1701
|
-
const { collection, options: queryOptions } = params;
|
|
1702
|
-
return this.queryClient.prefetchQuery({
|
|
1703
|
-
queryKey: collectionKeys(collection).list(queryOptions),
|
|
1704
|
-
queryFn: async () => {
|
|
1705
|
-
return await this.collectionClient.from(collection).find(queryOptions);
|
|
1706
|
-
},
|
|
1707
|
-
...options
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
// ===== prefetchQueryById =====
|
|
1711
|
-
async prefetchQueryById(params, options) {
|
|
1712
|
-
const { collection, id, options: queryOptions } = params;
|
|
1713
|
-
return this.queryClient.prefetchQuery({
|
|
1714
|
-
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
1715
|
-
queryFn: async () => {
|
|
1716
|
-
return await this.collectionClient.from(collection).findById(id, queryOptions);
|
|
1717
|
-
},
|
|
1718
|
-
...options
|
|
1719
|
-
});
|
|
1720
|
-
}
|
|
1721
|
-
// ===== prefetchInfiniteQuery =====
|
|
1722
|
-
async prefetchInfiniteQuery(params, options) {
|
|
1723
|
-
const {
|
|
1724
|
-
collection,
|
|
1725
|
-
options: queryOptions,
|
|
1726
|
-
pageSize = DEFAULT_PAGE_SIZE
|
|
1727
|
-
} = params;
|
|
1728
|
-
return this.queryClient.prefetchInfiniteQuery({
|
|
1729
|
-
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
1730
|
-
queryFn: async ({ pageParam }) => {
|
|
1731
|
-
const response = await this.collectionClient.from(collection).find({ ...queryOptions, page: pageParam, limit: pageSize });
|
|
1732
|
-
return response;
|
|
1733
|
-
},
|
|
1734
|
-
initialPageParam: 1,
|
|
1735
|
-
getNextPageParam: (lastPage) => {
|
|
1736
|
-
return lastPage.hasNextPage ? lastPage.nextPage : void 0;
|
|
1737
|
-
},
|
|
1738
|
-
pages: options?.pages ?? 1,
|
|
1739
|
-
staleTime: options?.staleTime
|
|
1740
|
-
});
|
|
1741
|
-
}
|
|
1742
|
-
// ===== Mutation Hooks =====
|
|
1743
|
-
useCreate(params, options) {
|
|
1744
|
-
const { collection } = params;
|
|
1745
|
-
return (0, import_react_query2.useMutation)({
|
|
1746
|
-
mutationFn: async (variables) => {
|
|
1747
|
-
return await this.collectionClient.from(collection).create(
|
|
1748
|
-
variables.data,
|
|
1749
|
-
variables.file ? { file: variables.file, filename: variables.filename } : void 0
|
|
1750
|
-
);
|
|
1751
|
-
},
|
|
1752
|
-
onSuccess: (data) => {
|
|
1753
|
-
this.queryClient.invalidateQueries({
|
|
1754
|
-
queryKey: collectionKeys(collection).all
|
|
1755
|
-
});
|
|
1756
|
-
if (PRODUCT_DETAIL_INVALIDATING_COLLECTIONS.has(collection)) {
|
|
1757
|
-
this.queryClient.invalidateQueries({ queryKey: ["products", "detail"] });
|
|
1758
|
-
}
|
|
1759
|
-
options?.onSuccess?.(data);
|
|
1760
|
-
},
|
|
1761
|
-
onError: options?.onError,
|
|
1762
|
-
onSettled: options?.onSettled
|
|
1763
|
-
});
|
|
1764
|
-
}
|
|
1765
|
-
useUpdate(params, options) {
|
|
1766
|
-
const { collection } = params;
|
|
1767
|
-
return (0, import_react_query2.useMutation)({
|
|
1768
|
-
mutationFn: async (variables) => {
|
|
1769
|
-
return await this.collectionClient.from(collection).update(
|
|
1770
|
-
variables.id,
|
|
1771
|
-
variables.data,
|
|
1772
|
-
variables.file ? { file: variables.file, filename: variables.filename } : void 0
|
|
1773
|
-
);
|
|
1774
|
-
},
|
|
1775
|
-
onSuccess: (data) => {
|
|
1776
|
-
this.queryClient.invalidateQueries({
|
|
1777
|
-
queryKey: collectionKeys(collection).all
|
|
1778
|
-
});
|
|
1779
|
-
if (PRODUCT_DETAIL_INVALIDATING_COLLECTIONS.has(collection)) {
|
|
1780
|
-
this.queryClient.invalidateQueries({ queryKey: ["products", "detail"] });
|
|
1781
|
-
}
|
|
1782
|
-
options?.onSuccess?.(data);
|
|
1783
|
-
},
|
|
1784
|
-
onError: options?.onError,
|
|
1785
|
-
onSettled: options?.onSettled
|
|
1786
|
-
});
|
|
1787
|
-
}
|
|
1788
|
-
useRemove(params, options) {
|
|
1789
|
-
const { collection } = params;
|
|
1790
|
-
return (0, import_react_query2.useMutation)({
|
|
1791
|
-
mutationFn: async (id) => {
|
|
1792
|
-
return await this.collectionClient.from(collection).remove(id);
|
|
1793
|
-
},
|
|
1794
|
-
onSuccess: (data) => {
|
|
1795
|
-
this.queryClient.invalidateQueries({
|
|
1796
|
-
queryKey: collectionKeys(collection).all
|
|
1797
|
-
});
|
|
1798
|
-
if (PRODUCT_DETAIL_INVALIDATING_COLLECTIONS.has(collection)) {
|
|
1799
|
-
this.queryClient.invalidateQueries({ queryKey: ["products", "detail"] });
|
|
1800
|
-
}
|
|
1801
|
-
options?.onSuccess?.(data);
|
|
1802
|
-
},
|
|
1803
|
-
onError: options?.onError,
|
|
1804
|
-
onSettled: options?.onSettled
|
|
1805
|
-
});
|
|
1806
|
-
}
|
|
1807
|
-
// ===== Cache Utilities =====
|
|
1808
|
-
invalidateQueries(collection, type) {
|
|
1809
|
-
const queryKey = type ? [collection, type] : [collection];
|
|
1810
|
-
return this.queryClient.invalidateQueries({ queryKey });
|
|
1811
|
-
}
|
|
1812
|
-
getQueryData(collection, type, idOrOptions, options) {
|
|
1813
|
-
if (type === "list") {
|
|
1814
|
-
return this.queryClient.getQueryData(
|
|
1815
|
-
collectionKeys(collection).list(idOrOptions)
|
|
1816
|
-
);
|
|
1817
|
-
}
|
|
1818
|
-
return this.queryClient.getQueryData(
|
|
1819
|
-
collectionKeys(collection).detail(idOrOptions, options)
|
|
1820
|
-
);
|
|
1821
|
-
}
|
|
1822
|
-
setQueryData(collection, type, dataOrId, dataOrOptions, options) {
|
|
1823
|
-
if (type === "list") {
|
|
1824
|
-
this.queryClient.setQueryData(
|
|
1825
|
-
collectionKeys(collection).list(dataOrOptions),
|
|
1826
|
-
dataOrId
|
|
1827
|
-
);
|
|
1828
|
-
} else {
|
|
1829
|
-
this.queryClient.setQueryData(
|
|
1830
|
-
collectionKeys(collection).detail(dataOrId, options),
|
|
1831
|
-
dataOrOptions
|
|
1832
|
-
);
|
|
1833
|
-
}
|
|
1834
|
-
}
|
|
1835
|
-
};
|
|
1836
|
-
|
|
1837
|
-
// src/core/query/customer-hooks.ts
|
|
1838
|
-
var import_react_query3 = require("@tanstack/react-query");
|
|
1839
|
-
function createMutation(mutationFn, callbacks, onSuccessExtra) {
|
|
1840
|
-
return (0, import_react_query3.useMutation)({
|
|
1841
|
-
mutationFn,
|
|
1842
|
-
onSuccess: (data) => {
|
|
1843
|
-
onSuccessExtra?.(data);
|
|
1844
|
-
callbacks?.onSuccess?.(data);
|
|
1845
|
-
},
|
|
1846
|
-
onError: callbacks?.onError,
|
|
1847
|
-
onSettled: callbacks?.onSettled
|
|
1848
|
-
});
|
|
1849
|
-
}
|
|
1850
|
-
var CustomerHooks = class {
|
|
1851
|
-
constructor(queryClient, customerAuth) {
|
|
1852
|
-
this.invalidateMe = () => {
|
|
1853
|
-
this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
|
|
1854
|
-
};
|
|
1855
|
-
this.queryClient = queryClient;
|
|
1856
|
-
this.customerAuth = customerAuth;
|
|
1857
|
-
}
|
|
1858
|
-
ensureCustomerAuth() {
|
|
1859
|
-
if (!this.customerAuth) {
|
|
1860
|
-
throw createConfigError(
|
|
1861
|
-
"Customer hooks require Client. Use createClient() instead of createServerClient()."
|
|
1862
|
-
);
|
|
1863
|
-
}
|
|
1864
|
-
return this.customerAuth;
|
|
1865
|
-
}
|
|
1866
|
-
// ===== useCustomerMe =====
|
|
1867
|
-
useCustomerMe(options) {
|
|
1868
|
-
return (0, import_react_query3.useQuery)({
|
|
1869
|
-
queryKey: customerKeys.me(),
|
|
1870
|
-
queryFn: async () => {
|
|
1871
|
-
return await this.ensureCustomerAuth().me();
|
|
1872
|
-
},
|
|
1873
|
-
...options,
|
|
1874
|
-
enabled: (options?.enabled ?? true) && !!this.customerAuth?.isAuthenticated()
|
|
1875
|
-
});
|
|
1876
|
-
}
|
|
1877
|
-
// ===== Mutations =====
|
|
1878
|
-
useCustomerLogin(options) {
|
|
1879
|
-
return createMutation(
|
|
1880
|
-
(data) => this.ensureCustomerAuth().login(data),
|
|
1881
|
-
options,
|
|
1882
|
-
this.invalidateMe
|
|
1883
|
-
);
|
|
1884
|
-
}
|
|
1885
|
-
useCustomerRegister(options) {
|
|
1886
|
-
return createMutation(
|
|
1887
|
-
(data) => this.ensureCustomerAuth().register(data),
|
|
1888
|
-
options
|
|
1889
|
-
);
|
|
1890
|
-
}
|
|
1891
|
-
useCustomerLogout(options) {
|
|
1892
|
-
return (0, import_react_query3.useMutation)({
|
|
1893
|
-
mutationFn: async () => {
|
|
1894
|
-
this.ensureCustomerAuth().logout();
|
|
1895
|
-
},
|
|
1896
|
-
onSuccess: () => {
|
|
1897
|
-
this.queryClient.removeQueries({ queryKey: customerKeys.all });
|
|
1898
|
-
options?.onSuccess?.();
|
|
1899
|
-
},
|
|
1900
|
-
onError: options?.onError,
|
|
1901
|
-
onSettled: options?.onSettled
|
|
1902
|
-
});
|
|
1903
|
-
}
|
|
1904
|
-
useCustomerForgotPassword(options) {
|
|
1905
|
-
return createMutation(
|
|
1906
|
-
(email) => this.ensureCustomerAuth().forgotPassword(email).then(() => {
|
|
1907
|
-
}),
|
|
1908
|
-
options
|
|
1909
|
-
);
|
|
1910
|
-
}
|
|
1911
|
-
useCustomerResetPassword(options) {
|
|
1912
|
-
return createMutation(
|
|
1913
|
-
(data) => this.ensureCustomerAuth().resetPassword(data.token, data.password).then(() => {
|
|
1914
|
-
}),
|
|
1915
|
-
options
|
|
1916
|
-
);
|
|
1917
|
-
}
|
|
1918
|
-
useCustomerRefreshToken(options) {
|
|
1919
|
-
return createMutation(
|
|
1920
|
-
() => this.ensureCustomerAuth().refreshToken(),
|
|
1921
|
-
options,
|
|
1922
|
-
this.invalidateMe
|
|
1923
|
-
);
|
|
1924
|
-
}
|
|
1925
|
-
useCustomerUpdateProfile(options) {
|
|
1926
|
-
return createMutation(
|
|
1927
|
-
(data) => this.ensureCustomerAuth().updateProfile(data),
|
|
1928
|
-
options,
|
|
1929
|
-
this.invalidateMe
|
|
1930
|
-
);
|
|
1931
|
-
}
|
|
1932
|
-
useCustomerChangePassword(options) {
|
|
1933
|
-
return createMutation(
|
|
1934
|
-
(data) => this.ensureCustomerAuth().changePassword(data.currentPassword, data.newPassword).then(() => {
|
|
1935
|
-
}),
|
|
1936
|
-
options
|
|
1937
|
-
);
|
|
1938
|
-
}
|
|
1939
|
-
// ===== Customer Cache Utilities =====
|
|
1940
|
-
invalidateCustomerQueries() {
|
|
1941
|
-
return this.queryClient.invalidateQueries({ queryKey: customerKeys.all });
|
|
1942
|
-
}
|
|
1943
|
-
getCustomerData() {
|
|
1944
|
-
return this.queryClient.getQueryData(customerKeys.me());
|
|
1945
|
-
}
|
|
1946
|
-
setCustomerData(data) {
|
|
1947
|
-
this.queryClient.setQueryData(customerKeys.me(), data);
|
|
1948
|
-
}
|
|
1949
|
-
};
|
|
1950
|
-
|
|
1951
|
-
// src/core/query/query-hooks.ts
|
|
1952
|
-
var QueryHooks = class extends CollectionHooks {
|
|
1953
|
-
constructor(queryClient, collectionClient, customerAuth, commerceClient) {
|
|
1954
|
-
super(queryClient, collectionClient);
|
|
1955
|
-
// --- Customer hooks delegation ---
|
|
1956
|
-
this.useCustomerMe = (...args) => this._customer.useCustomerMe(...args);
|
|
1957
|
-
this.useCustomerLogin = (...args) => this._customer.useCustomerLogin(...args);
|
|
1958
|
-
this.useCustomerRegister = (...args) => this._customer.useCustomerRegister(...args);
|
|
1959
|
-
this.useCustomerLogout = (...args) => this._customer.useCustomerLogout(...args);
|
|
1960
|
-
this.useCustomerForgotPassword = (...args) => this._customer.useCustomerForgotPassword(...args);
|
|
1961
|
-
this.useCustomerResetPassword = (...args) => this._customer.useCustomerResetPassword(...args);
|
|
1962
|
-
this.useCustomerRefreshToken = (...args) => this._customer.useCustomerRefreshToken(...args);
|
|
1963
|
-
this.useCustomerUpdateProfile = (...args) => this._customer.useCustomerUpdateProfile(...args);
|
|
1964
|
-
this.useCustomerChangePassword = (...args) => this._customer.useCustomerChangePassword(...args);
|
|
1965
|
-
// --- Customer cache delegation ---
|
|
1966
|
-
this.invalidateCustomerQueries = () => this._customer.invalidateCustomerQueries();
|
|
1967
|
-
this.getCustomerData = () => this._customer.getCustomerData();
|
|
1968
|
-
this.setCustomerData = (data) => this._customer.setCustomerData(data);
|
|
1969
|
-
this._customer = new CustomerHooks(queryClient, customerAuth);
|
|
1970
|
-
this._commerce = commerceClient;
|
|
1971
|
-
}
|
|
1972
|
-
useProductListingGroupsQuery(params, options) {
|
|
1973
|
-
const queryOptions = params.options;
|
|
1974
|
-
const { placeholderData, ...restOptions } = options ?? {};
|
|
1975
|
-
return (0, import_react_query4.useQuery)({
|
|
1976
|
-
queryKey: productKeys.listingGroups(queryOptions),
|
|
1977
|
-
queryFn: async () => this.collectionClient.requestFindEndpoint(
|
|
1978
|
-
"/api/products/listing-groups/query",
|
|
1979
|
-
{ options: queryOptions }
|
|
1980
|
-
),
|
|
1981
|
-
...restOptions,
|
|
1982
|
-
...placeholderData !== void 0 && {
|
|
1983
|
-
placeholderData
|
|
1984
|
-
}
|
|
1985
|
-
});
|
|
1986
|
-
}
|
|
1987
|
-
useSuspenseProductListingGroupsQuery(params, options) {
|
|
1988
|
-
const queryOptions = params.options;
|
|
1989
|
-
return (0, import_react_query4.useSuspenseQuery)({
|
|
1990
|
-
queryKey: productKeys.listingGroups(queryOptions),
|
|
1991
|
-
queryFn: async () => this.collectionClient.requestFindEndpoint(
|
|
1992
|
-
"/api/products/listing-groups/query",
|
|
1993
|
-
{ options: queryOptions }
|
|
1994
|
-
),
|
|
1995
|
-
...options
|
|
1996
|
-
});
|
|
1997
|
-
}
|
|
1998
|
-
useInfiniteProductListingGroupsQuery(params, options) {
|
|
1999
|
-
const {
|
|
2000
|
-
options: queryOptions,
|
|
2001
|
-
pageSize = 20
|
|
2002
|
-
} = params;
|
|
2003
|
-
return (0, import_react_query4.useInfiniteQuery)({
|
|
2004
|
-
queryKey: productKeys.listingGroupsInfinite(queryOptions),
|
|
2005
|
-
queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
|
|
2006
|
-
"/api/products/listing-groups/query",
|
|
2007
|
-
{
|
|
2008
|
-
options: { ...queryOptions, page: pageParam, limit: pageSize }
|
|
2009
|
-
}
|
|
2010
|
-
),
|
|
2011
|
-
initialPageParam: 1,
|
|
2012
|
-
getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
|
|
2013
|
-
...options
|
|
2014
|
-
});
|
|
2015
|
-
}
|
|
2016
|
-
useSuspenseInfiniteProductListingGroupsQuery(params, options) {
|
|
2017
|
-
const {
|
|
2018
|
-
options: queryOptions,
|
|
2019
|
-
pageSize = 20
|
|
2020
|
-
} = params;
|
|
2021
|
-
return (0, import_react_query4.useSuspenseInfiniteQuery)({
|
|
2022
|
-
queryKey: productKeys.listingGroupsInfinite(queryOptions),
|
|
2023
|
-
queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
|
|
2024
|
-
"/api/products/listing-groups/query",
|
|
2025
|
-
{
|
|
2026
|
-
options: { ...queryOptions, page: pageParam, limit: pageSize }
|
|
2027
|
-
}
|
|
2028
|
-
),
|
|
2029
|
-
initialPageParam: 1,
|
|
2030
|
-
getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
|
|
2031
|
-
...options
|
|
2032
|
-
});
|
|
2033
|
-
}
|
|
2034
|
-
async prefetchProductListingGroupsQuery(params, options) {
|
|
2035
|
-
const queryOptions = params.options;
|
|
2036
|
-
return this.queryClient.prefetchQuery({
|
|
2037
|
-
queryKey: productKeys.listingGroups(queryOptions),
|
|
2038
|
-
queryFn: async () => this.collectionClient.requestFindEndpoint(
|
|
2039
|
-
"/api/products/listing-groups/query",
|
|
2040
|
-
{ options: queryOptions }
|
|
2041
|
-
),
|
|
2042
|
-
...options
|
|
2043
|
-
});
|
|
2044
|
-
}
|
|
2045
|
-
async prefetchInfiniteProductListingGroupsQuery(params, options) {
|
|
2046
|
-
const {
|
|
2047
|
-
options: queryOptions,
|
|
2048
|
-
pageSize = 20
|
|
2049
|
-
} = params;
|
|
2050
|
-
return this.queryClient.prefetchInfiniteQuery({
|
|
2051
|
-
queryKey: productKeys.listingGroupsInfinite(queryOptions),
|
|
2052
|
-
queryFn: async ({ pageParam }) => this.collectionClient.requestFindEndpoint(
|
|
2053
|
-
"/api/products/listing-groups/query",
|
|
2054
|
-
{
|
|
2055
|
-
options: { ...queryOptions, page: pageParam, limit: pageSize }
|
|
2056
|
-
}
|
|
2057
|
-
),
|
|
2058
|
-
initialPageParam: 1,
|
|
2059
|
-
getNextPageParam: (lastPage) => lastPage.hasNextPage ? lastPage.nextPage : void 0,
|
|
2060
|
-
pages: options?.pages ?? 1,
|
|
2061
|
-
staleTime: options?.staleTime
|
|
2062
|
-
});
|
|
2063
|
-
}
|
|
2064
|
-
useProductDetail(params, options) {
|
|
2065
|
-
const discriminator = "slug" in params ? params.slug : params.id;
|
|
2066
|
-
const enabled = options?.enabled !== false && Boolean(discriminator);
|
|
2067
|
-
return (0, import_react_query4.useQuery)({
|
|
2068
|
-
queryKey: productKeys.detail(params),
|
|
2069
|
-
queryFn: () => this._commerce.product.detail(params),
|
|
2070
|
-
enabled
|
|
2071
|
-
});
|
|
2072
|
-
}
|
|
2073
|
-
useProductDetailBySlug(slug, options) {
|
|
2074
|
-
return this.useProductDetail({ slug }, options);
|
|
2075
|
-
}
|
|
2076
|
-
useProductDetailById(id, options) {
|
|
2077
|
-
return this.useProductDetail({ id }, options);
|
|
2078
|
-
}
|
|
2079
|
-
};
|
|
2080
|
-
|
|
2081
1540
|
// src/core/client/client.server.ts
|
|
2082
1541
|
var ServerClient = class {
|
|
2083
1542
|
constructor(options) {
|
|
@@ -2107,6 +1566,7 @@ var ServerClient = class {
|
|
|
2107
1566
|
const serverOptions = {
|
|
2108
1567
|
publishableKey: this.config.publishableKey,
|
|
2109
1568
|
secretKey: this.config.secretKey,
|
|
1569
|
+
apiUrl: this.config.apiUrl,
|
|
2110
1570
|
onRequestId
|
|
2111
1571
|
};
|
|
2112
1572
|
this.commerce = new ServerCommerceClient(serverOptions);
|
|
@@ -2123,10 +1583,9 @@ var ServerClient = class {
|
|
|
2123
1583
|
this.config.secretKey,
|
|
2124
1584
|
void 0,
|
|
2125
1585
|
void 0,
|
|
2126
|
-
onRequestId
|
|
1586
|
+
onRequestId,
|
|
1587
|
+
this.config.apiUrl
|
|
2127
1588
|
);
|
|
2128
|
-
this.queryClient = getQueryClient();
|
|
2129
|
-
this.query = new QueryHooks(this.queryClient, this.collections, void 0, this.commerce);
|
|
2130
1589
|
}
|
|
2131
1590
|
getState() {
|
|
2132
1591
|
return { ...this.state };
|