@01.software/sdk 0.29.0 → 0.31.0
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 +331 -77
- 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 +1541 -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 +1518 -0
- package/dist/client.js.map +1 -0
- package/dist/collection-client-ByzY3hWK.d.ts +218 -0
- package/dist/collection-client-DFXXz0vk.d.cts +218 -0
- package/dist/{const-DAjQYNuM.d.ts → const-AytzliEu.d.cts} +5 -7
- package/dist/{const-Dsixdi6z.d.cts → const-BGCP-OJL.d.ts} +5 -7
- package/dist/index-BGEhoDUs.d.cts +106 -0
- package/dist/index-BGEhoDUs.d.ts +106 -0
- package/dist/index.cjs +1006 -1615
- 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 +932 -1559
- 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-Wa4-eC6x.d.cts} +794 -532
- package/dist/{payload-types-Ci-ZA7aM.d.ts → payload-types-Wa4-eC6x.d.ts} +794 -532
- package/dist/query.cjs +1841 -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 +1836 -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 +430 -846
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +137 -7
- package/dist/server.d.ts +137 -7
- package/dist/server.js +430 -864
- package/dist/server.js.map +1 -1
- package/dist/{server-Cv0Q4dPQ.d.ts → types-BX2mqDf6.d.ts} +270 -743
- package/dist/{types-BWq_WlbB.d.ts → types-CVA10VC-.d.ts} +6 -2
- package/dist/{types-zKjATmDK.d.cts → types-CmLG-7RL.d.cts} +6 -2
- package/dist/{server-C0C8dtms.d.cts → types-DChFjQGz.d.cts} +270 -743
- 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.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
|
|
|
@@ -244,8 +45,16 @@ var ValidationError = class extends SDKError {
|
|
|
244
45
|
}
|
|
245
46
|
};
|
|
246
47
|
var ApiError = class extends SDKError {
|
|
247
|
-
constructor(message, status, details, userMessage, suggestion) {
|
|
248
|
-
super(
|
|
48
|
+
constructor(message, status, details, userMessage, suggestion, requestId) {
|
|
49
|
+
super(
|
|
50
|
+
"API_ERROR",
|
|
51
|
+
message,
|
|
52
|
+
status,
|
|
53
|
+
details,
|
|
54
|
+
userMessage,
|
|
55
|
+
suggestion,
|
|
56
|
+
requestId
|
|
57
|
+
);
|
|
249
58
|
this.name = "ApiError";
|
|
250
59
|
}
|
|
251
60
|
};
|
|
@@ -276,19 +85,43 @@ var UsageLimitError = class extends SDKError {
|
|
|
276
85
|
};
|
|
277
86
|
var AuthError = class extends SDKError {
|
|
278
87
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
279
|
-
super(
|
|
88
|
+
super(
|
|
89
|
+
"auth_error",
|
|
90
|
+
message,
|
|
91
|
+
401,
|
|
92
|
+
details,
|
|
93
|
+
userMessage,
|
|
94
|
+
suggestion,
|
|
95
|
+
requestId
|
|
96
|
+
);
|
|
280
97
|
this.name = "AuthError";
|
|
281
98
|
}
|
|
282
99
|
};
|
|
283
100
|
var PermissionError = class extends SDKError {
|
|
284
101
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
285
|
-
super(
|
|
102
|
+
super(
|
|
103
|
+
"permission_error",
|
|
104
|
+
message,
|
|
105
|
+
403,
|
|
106
|
+
details,
|
|
107
|
+
userMessage,
|
|
108
|
+
suggestion,
|
|
109
|
+
requestId
|
|
110
|
+
);
|
|
286
111
|
this.name = "PermissionError";
|
|
287
112
|
}
|
|
288
113
|
};
|
|
289
114
|
var NotFoundError = class extends SDKError {
|
|
290
115
|
constructor(message, details, userMessage, suggestion, requestId) {
|
|
291
|
-
super(
|
|
116
|
+
super(
|
|
117
|
+
"not_found",
|
|
118
|
+
message,
|
|
119
|
+
404,
|
|
120
|
+
details,
|
|
121
|
+
userMessage,
|
|
122
|
+
suggestion,
|
|
123
|
+
requestId
|
|
124
|
+
);
|
|
292
125
|
this.name = "NotFoundError";
|
|
293
126
|
}
|
|
294
127
|
};
|
|
@@ -300,14 +133,22 @@ var ConflictError = class extends SDKError {
|
|
|
300
133
|
};
|
|
301
134
|
var RateLimitError = class extends SDKError {
|
|
302
135
|
constructor(message, retryAfter, details, userMessage, suggestion, requestId) {
|
|
303
|
-
super(
|
|
136
|
+
super(
|
|
137
|
+
"rate_limit_exceeded",
|
|
138
|
+
message,
|
|
139
|
+
429,
|
|
140
|
+
details,
|
|
141
|
+
userMessage,
|
|
142
|
+
suggestion,
|
|
143
|
+
requestId
|
|
144
|
+
);
|
|
304
145
|
this.name = "RateLimitError";
|
|
305
146
|
this.retryAfter = retryAfter;
|
|
306
147
|
}
|
|
307
148
|
};
|
|
308
149
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
309
150
|
var createValidationError = (message, details, userMessage, suggestion, status) => new ValidationError(message, details, userMessage, suggestion, status);
|
|
310
|
-
var createApiError = (message, status, details, userMessage, suggestion) => new ApiError(message, status, details, userMessage, suggestion);
|
|
151
|
+
var createApiError = (message, status, details, userMessage, suggestion, requestId) => new ApiError(message, status, details, userMessage, suggestion, requestId);
|
|
311
152
|
var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
|
|
312
153
|
var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
|
|
313
154
|
var createUsageLimitError = (message, usage, details, userMessage, suggestion) => new UsageLimitError(message, usage, details, userMessage, suggestion);
|
|
@@ -315,7 +156,14 @@ var createAuthError = (message, details, userMessage, suggestion, requestId) =>
|
|
|
315
156
|
var createPermissionError = (message, details, userMessage, suggestion, requestId) => new PermissionError(message, details, userMessage, suggestion, requestId);
|
|
316
157
|
var createNotFoundError = (message, details, userMessage, suggestion, requestId) => new NotFoundError(message, details, userMessage, suggestion, requestId);
|
|
317
158
|
var createConflictError = (message, details, userMessage, suggestion, requestId) => new ConflictError(message, details, userMessage, suggestion, requestId);
|
|
318
|
-
var createRateLimitError = (message, retryAfter, details, userMessage, suggestion, requestId) => new RateLimitError(
|
|
159
|
+
var createRateLimitError = (message, retryAfter, details, userMessage, suggestion, requestId) => new RateLimitError(
|
|
160
|
+
message,
|
|
161
|
+
retryAfter,
|
|
162
|
+
details,
|
|
163
|
+
userMessage,
|
|
164
|
+
suggestion,
|
|
165
|
+
requestId
|
|
166
|
+
);
|
|
319
167
|
|
|
320
168
|
// src/core/internal/utils/credentials.ts
|
|
321
169
|
function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
|
|
@@ -328,7 +176,10 @@ function requirePublishableKeyForSecret(apiName, publishableKey, secretKey) {
|
|
|
328
176
|
}
|
|
329
177
|
|
|
330
178
|
// src/core/client/types.ts
|
|
331
|
-
function resolveApiUrl() {
|
|
179
|
+
function resolveApiUrl(apiUrl) {
|
|
180
|
+
if (apiUrl) {
|
|
181
|
+
return apiUrl.replace(/\/$/, "");
|
|
182
|
+
}
|
|
332
183
|
if (typeof process !== "undefined" && process.env) {
|
|
333
184
|
const envUrl = process.env.SOFTWARE_API_URL || process.env.NEXT_PUBLIC_SOFTWARE_API_URL;
|
|
334
185
|
if (envUrl) {
|
|
@@ -352,6 +203,22 @@ function debugLog(debug, type, message, data) {
|
|
|
352
203
|
console.groupEnd();
|
|
353
204
|
}
|
|
354
205
|
}
|
|
206
|
+
function redactSensitiveHeader(value) {
|
|
207
|
+
const prefix = value.toLowerCase().startsWith("bearer ") ? "Bearer " : "";
|
|
208
|
+
return value.length > 20 ? `${prefix}...****${value.slice(-8)}` : "****";
|
|
209
|
+
}
|
|
210
|
+
function redactSensitiveHeaders(headers) {
|
|
211
|
+
const redacted = Object.fromEntries(headers.entries());
|
|
212
|
+
if (redacted.authorization) {
|
|
213
|
+
redacted.authorization = redactSensitiveHeader(redacted.authorization);
|
|
214
|
+
}
|
|
215
|
+
if (redacted["x-preview-token"]) {
|
|
216
|
+
redacted["x-preview-token"] = redactSensitiveHeader(
|
|
217
|
+
redacted["x-preview-token"]
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
return redacted;
|
|
221
|
+
}
|
|
355
222
|
function getErrorSuggestion(status) {
|
|
356
223
|
if (status === 400)
|
|
357
224
|
return "The request data failed validation. Check field values and types.";
|
|
@@ -426,6 +293,12 @@ async function parseErrorBody(response) {
|
|
|
426
293
|
return fallback;
|
|
427
294
|
}
|
|
428
295
|
}
|
|
296
|
+
function getParsedErrorSuggestion(status, parsed) {
|
|
297
|
+
if (status === 403 && parsed.reason === "origin_not_allowed") {
|
|
298
|
+
return "Add the request origin to the tenant Browser API origins, then retry the browser request.";
|
|
299
|
+
}
|
|
300
|
+
return getErrorSuggestion(status);
|
|
301
|
+
}
|
|
429
302
|
async function delay(ms) {
|
|
430
303
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
431
304
|
}
|
|
@@ -439,7 +312,7 @@ function createHttpStatusError(status, parsed, details, requestId) {
|
|
|
439
312
|
...parsed.errors && { errors: parsed.errors },
|
|
440
313
|
...parsed.body && { body: parsed.body }
|
|
441
314
|
};
|
|
442
|
-
const suggestion =
|
|
315
|
+
const suggestion = getParsedErrorSuggestion(status, parsed);
|
|
443
316
|
if (status === 400 || status === 422) {
|
|
444
317
|
return attachRequestId(
|
|
445
318
|
createValidationError(
|
|
@@ -509,6 +382,7 @@ function createHttpStatusError(status, parsed, details, requestId) {
|
|
|
509
382
|
}
|
|
510
383
|
async function httpFetch(url, options) {
|
|
511
384
|
const {
|
|
385
|
+
apiUrl,
|
|
512
386
|
publishableKey,
|
|
513
387
|
secretKey,
|
|
514
388
|
customerToken,
|
|
@@ -518,7 +392,7 @@ async function httpFetch(url, options) {
|
|
|
518
392
|
onUnauthorized,
|
|
519
393
|
...requestInit
|
|
520
394
|
} = options || {};
|
|
521
|
-
const baseUrl = resolveApiUrl();
|
|
395
|
+
const baseUrl = resolveApiUrl(apiUrl);
|
|
522
396
|
const retryConfig = {
|
|
523
397
|
maxRetries: retry?.maxRetries ?? 3,
|
|
524
398
|
retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
|
|
@@ -544,11 +418,7 @@ async function httpFetch(url, options) {
|
|
|
544
418
|
if (!headers.has("Content-Type") && requestInit.body && !(requestInit.body instanceof FormData)) {
|
|
545
419
|
headers.set("Content-Type", "application/json");
|
|
546
420
|
}
|
|
547
|
-
const redactedHeaders =
|
|
548
|
-
if (redactedHeaders["authorization"]) {
|
|
549
|
-
const token = redactedHeaders["authorization"];
|
|
550
|
-
redactedHeaders["authorization"] = token.length > 20 ? `Bearer ...****${token.slice(-8)}` : "****";
|
|
551
|
-
}
|
|
421
|
+
const redactedHeaders = redactSensitiveHeaders(headers);
|
|
552
422
|
debugLog(debug, "request", url, {
|
|
553
423
|
method: requestInit.method || "GET",
|
|
554
424
|
headers: redactedHeaders,
|
|
@@ -566,7 +436,7 @@ async function httpFetch(url, options) {
|
|
|
566
436
|
debugLog(debug, "response", url, {
|
|
567
437
|
status: response.status,
|
|
568
438
|
statusText: response.statusText,
|
|
569
|
-
headers:
|
|
439
|
+
headers: redactSensitiveHeaders(response.headers)
|
|
570
440
|
});
|
|
571
441
|
if (!response.ok) {
|
|
572
442
|
if (isUsageLimitExceededResponse(response)) {
|
|
@@ -707,7 +577,7 @@ async function httpFetch(url, options) {
|
|
|
707
577
|
|
|
708
578
|
// src/core/collection/http-client.ts
|
|
709
579
|
var HttpClient = class {
|
|
710
|
-
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId) {
|
|
580
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized, onRequestId, apiUrl) {
|
|
711
581
|
this.publishableKey = requirePublishableKeyForSecret(
|
|
712
582
|
"CollectionClient",
|
|
713
583
|
publishableKey,
|
|
@@ -717,9 +587,11 @@ var HttpClient = class {
|
|
|
717
587
|
this.getCustomerToken = getCustomerToken;
|
|
718
588
|
this.onUnauthorized = onUnauthorized;
|
|
719
589
|
this.onRequestId = onRequestId;
|
|
590
|
+
this.apiUrl = apiUrl;
|
|
720
591
|
}
|
|
721
592
|
get defaultOptions() {
|
|
722
593
|
const opts = {
|
|
594
|
+
apiUrl: this.apiUrl,
|
|
723
595
|
publishableKey: this.publishableKey,
|
|
724
596
|
secretKey: this.secretKey
|
|
725
597
|
};
|
|
@@ -757,85 +629,284 @@ var HttpClient = class {
|
|
|
757
629
|
}
|
|
758
630
|
}
|
|
759
631
|
/**
|
|
760
|
-
* Parse Payload CMS find response (list query)
|
|
761
|
-
* Returns native Payload response structure
|
|
632
|
+
* Parse Payload CMS find response (list query)
|
|
633
|
+
* Returns native Payload response structure
|
|
634
|
+
*/
|
|
635
|
+
async parseFindResponse(response) {
|
|
636
|
+
const contentType = response.headers.get("content-type");
|
|
637
|
+
try {
|
|
638
|
+
this.assertJsonResponse(response);
|
|
639
|
+
const jsonData = await response.json();
|
|
640
|
+
if (jsonData.docs === void 0) {
|
|
641
|
+
throw createApiError("Invalid find response.", response.status, {
|
|
642
|
+
jsonData
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
return {
|
|
646
|
+
docs: jsonData.docs,
|
|
647
|
+
totalDocs: jsonData.totalDocs ?? 0,
|
|
648
|
+
limit: jsonData.limit || 20,
|
|
649
|
+
totalPages: jsonData.totalPages ?? 0,
|
|
650
|
+
page: jsonData.page || 1,
|
|
651
|
+
pagingCounter: jsonData.pagingCounter || 1,
|
|
652
|
+
hasPrevPage: jsonData.hasPrevPage ?? false,
|
|
653
|
+
hasNextPage: jsonData.hasNextPage ?? false,
|
|
654
|
+
prevPage: jsonData.prevPage ?? null,
|
|
655
|
+
nextPage: jsonData.nextPage ?? null
|
|
656
|
+
};
|
|
657
|
+
} catch (error) {
|
|
658
|
+
if (error instanceof SDKError) throw error;
|
|
659
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
660
|
+
contentType,
|
|
661
|
+
error: error instanceof Error ? error.message : error
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Parse Payload CMS mutation response (create/update)
|
|
667
|
+
* Returns native Payload response structure
|
|
668
|
+
*/
|
|
669
|
+
async parseMutationResponse(response) {
|
|
670
|
+
const contentType = response.headers.get("content-type");
|
|
671
|
+
try {
|
|
672
|
+
this.assertJsonResponse(response);
|
|
673
|
+
const jsonData = await response.json();
|
|
674
|
+
if (jsonData.doc === void 0) {
|
|
675
|
+
throw createApiError("Invalid mutation response.", response.status, {
|
|
676
|
+
jsonData
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
return {
|
|
680
|
+
message: jsonData.message || "",
|
|
681
|
+
doc: jsonData.doc,
|
|
682
|
+
errors: jsonData.errors
|
|
683
|
+
};
|
|
684
|
+
} catch (error) {
|
|
685
|
+
if (error instanceof SDKError) throw error;
|
|
686
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
687
|
+
contentType,
|
|
688
|
+
error: error instanceof Error ? error.message : error
|
|
689
|
+
});
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
/**
|
|
693
|
+
* Parse Payload CMS document response (findById/delete)
|
|
694
|
+
* Returns document directly without wrapper
|
|
695
|
+
*/
|
|
696
|
+
async parseDocumentResponse(response) {
|
|
697
|
+
const contentType = response.headers.get("content-type");
|
|
698
|
+
try {
|
|
699
|
+
this.assertJsonResponse(response);
|
|
700
|
+
const jsonData = await response.json();
|
|
701
|
+
return jsonData;
|
|
702
|
+
} catch (error) {
|
|
703
|
+
if (error instanceof SDKError) throw error;
|
|
704
|
+
throw createApiError("Failed to parse response.", response.status, {
|
|
705
|
+
contentType,
|
|
706
|
+
error: error instanceof Error ? error.message : error
|
|
707
|
+
});
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
|
|
712
|
+
// src/utils/types.ts
|
|
713
|
+
var resolveRelation = (ref) => {
|
|
714
|
+
if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
|
|
715
|
+
return null;
|
|
716
|
+
return ref;
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// src/core/metadata/index.ts
|
|
720
|
+
function extractSeo(doc) {
|
|
721
|
+
const seo = doc.seo ?? {};
|
|
722
|
+
const og = seo.openGraph ?? {};
|
|
723
|
+
return {
|
|
724
|
+
title: seo.title ?? doc.title ?? null,
|
|
725
|
+
description: seo.description ?? null,
|
|
726
|
+
noIndex: seo.noIndex ?? null,
|
|
727
|
+
canonical: seo.canonical ?? null,
|
|
728
|
+
openGraph: {
|
|
729
|
+
title: og.title ?? null,
|
|
730
|
+
description: og.description ?? null,
|
|
731
|
+
image: og.image ?? null
|
|
732
|
+
}
|
|
733
|
+
};
|
|
734
|
+
}
|
|
735
|
+
function generateMetadata(input, options) {
|
|
736
|
+
const title = input.title ?? void 0;
|
|
737
|
+
const description = input.description ?? void 0;
|
|
738
|
+
const ogTitle = input.openGraph?.title ?? title;
|
|
739
|
+
const ogDescription = input.openGraph?.description ?? description;
|
|
740
|
+
const image = resolveMetaImage(input.openGraph?.image);
|
|
741
|
+
return {
|
|
742
|
+
title,
|
|
743
|
+
description,
|
|
744
|
+
...input.noIndex && { robots: { index: false, follow: false } },
|
|
745
|
+
...input.canonical && { alternates: { canonical: input.canonical } },
|
|
746
|
+
openGraph: {
|
|
747
|
+
...ogTitle && { title: ogTitle },
|
|
748
|
+
...ogDescription && { description: ogDescription },
|
|
749
|
+
...options?.siteName && { siteName: options.siteName },
|
|
750
|
+
...image && { images: [image] }
|
|
751
|
+
},
|
|
752
|
+
twitter: {
|
|
753
|
+
card: image ? "summary_large_image" : "summary",
|
|
754
|
+
...ogTitle && { title: ogTitle },
|
|
755
|
+
...ogDescription && { description: ogDescription },
|
|
756
|
+
...image && { images: [image.url] }
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
function resolveMetaImage(ref) {
|
|
761
|
+
const image = resolveRelation(ref);
|
|
762
|
+
if (!image) return null;
|
|
763
|
+
const sized = image.sizes?.["1536"];
|
|
764
|
+
const url = sized?.url || image.url;
|
|
765
|
+
if (!url) return null;
|
|
766
|
+
const width = sized?.url ? sized.width : image.width;
|
|
767
|
+
const height = sized?.url ? sized.height : image.height;
|
|
768
|
+
return {
|
|
769
|
+
url,
|
|
770
|
+
...width && { width },
|
|
771
|
+
...height && { height },
|
|
772
|
+
...image.alt && { alt: image.alt }
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// src/core/collection/query-builder.ts
|
|
777
|
+
var CollectionQueryBuilder = class {
|
|
778
|
+
constructor(api, collection) {
|
|
779
|
+
this.api = api;
|
|
780
|
+
this.collection = collection;
|
|
781
|
+
}
|
|
782
|
+
/**
|
|
783
|
+
* Find documents (list query)
|
|
784
|
+
* GET /api/{collection}
|
|
785
|
+
* @returns Payload CMS find response with docs array and pagination
|
|
786
|
+
*/
|
|
787
|
+
async find(options) {
|
|
788
|
+
return this.api.requestFind(
|
|
789
|
+
`/api/${String(this.collection)}`,
|
|
790
|
+
options
|
|
791
|
+
);
|
|
792
|
+
}
|
|
793
|
+
/**
|
|
794
|
+
* Find document by ID
|
|
795
|
+
* GET /api/{collection}/{id}
|
|
796
|
+
* @returns Document object directly (no wrapper)
|
|
797
|
+
*/
|
|
798
|
+
async findById(id, options) {
|
|
799
|
+
return this.api.requestFindById(
|
|
800
|
+
`/api/${String(this.collection)}/${String(id)}`,
|
|
801
|
+
options
|
|
802
|
+
);
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* Create a new document
|
|
806
|
+
* POST /api/{collection}
|
|
807
|
+
* @returns Payload CMS mutation response with doc and message
|
|
808
|
+
*/
|
|
809
|
+
async create(data, options) {
|
|
810
|
+
const endpoint = `/api/${String(this.collection)}`;
|
|
811
|
+
if (options?.file) {
|
|
812
|
+
return this.api.requestCreateWithFile(
|
|
813
|
+
endpoint,
|
|
814
|
+
data,
|
|
815
|
+
options.file,
|
|
816
|
+
options.filename
|
|
817
|
+
);
|
|
818
|
+
}
|
|
819
|
+
return this.api.requestCreate(endpoint, data);
|
|
820
|
+
}
|
|
821
|
+
/**
|
|
822
|
+
* Update a document by ID
|
|
823
|
+
* PATCH /api/{collection}/{id}
|
|
824
|
+
* @returns Payload CMS mutation response with doc and message
|
|
825
|
+
*/
|
|
826
|
+
async update(id, data, options) {
|
|
827
|
+
const endpoint = `/api/${String(this.collection)}/${String(id)}`;
|
|
828
|
+
if (options?.file) {
|
|
829
|
+
return this.api.requestUpdateWithFile(
|
|
830
|
+
endpoint,
|
|
831
|
+
data,
|
|
832
|
+
options.file,
|
|
833
|
+
options.filename
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
return this.api.requestUpdate(endpoint, data);
|
|
837
|
+
}
|
|
838
|
+
/**
|
|
839
|
+
* Count documents
|
|
840
|
+
* GET /api/{collection}/count
|
|
841
|
+
* @returns Count response with totalDocs
|
|
842
|
+
*/
|
|
843
|
+
async count(options) {
|
|
844
|
+
return this.api.requestCount(
|
|
845
|
+
`/api/${String(this.collection)}/count`,
|
|
846
|
+
options
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Find first matching document and return its Next.js Metadata.
|
|
851
|
+
* Applies depth: 1 (SEO image populate) and limit: 1 automatically.
|
|
852
|
+
* @returns Metadata or null if no document matches
|
|
853
|
+
*/
|
|
854
|
+
async findMetadata(options, metadataOptions) {
|
|
855
|
+
const { docs } = await this.find({ ...options, limit: 1, depth: 1 });
|
|
856
|
+
const doc = docs[0];
|
|
857
|
+
if (!doc) return null;
|
|
858
|
+
return generateMetadata(
|
|
859
|
+
extractSeo(doc),
|
|
860
|
+
metadataOptions
|
|
861
|
+
);
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Find document by ID and return its Next.js Metadata.
|
|
865
|
+
* Applies depth: 1 (SEO image populate) automatically.
|
|
866
|
+
* @returns Metadata (throws on 404)
|
|
867
|
+
*/
|
|
868
|
+
async findMetadataById(id, metadataOptions) {
|
|
869
|
+
const doc = await this.findById(id, { depth: 1 });
|
|
870
|
+
return generateMetadata(
|
|
871
|
+
extractSeo(doc),
|
|
872
|
+
metadataOptions
|
|
873
|
+
);
|
|
874
|
+
}
|
|
875
|
+
/**
|
|
876
|
+
* Update multiple documents (bulk update)
|
|
877
|
+
* PATCH /api/{collection}
|
|
878
|
+
* @returns Payload CMS find response with updated docs
|
|
762
879
|
*/
|
|
763
|
-
async
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
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
|
-
}
|
|
880
|
+
async updateMany(where, data) {
|
|
881
|
+
return this.api.requestUpdateMany(
|
|
882
|
+
`/api/${String(this.collection)}`,
|
|
883
|
+
{ where, data }
|
|
884
|
+
);
|
|
792
885
|
}
|
|
793
886
|
/**
|
|
794
|
-
*
|
|
795
|
-
*
|
|
887
|
+
* Delete a document by ID
|
|
888
|
+
* DELETE /api/{collection}/{id}
|
|
889
|
+
* @returns Deleted document object directly (no wrapper)
|
|
796
890
|
*/
|
|
797
|
-
async
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
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
|
-
}
|
|
891
|
+
async remove(id) {
|
|
892
|
+
return this.api.requestDelete(
|
|
893
|
+
`/api/${String(this.collection)}/${String(id)}`
|
|
894
|
+
);
|
|
819
895
|
}
|
|
820
896
|
/**
|
|
821
|
-
*
|
|
822
|
-
*
|
|
897
|
+
* Delete multiple documents (bulk delete)
|
|
898
|
+
* DELETE /api/{collection}
|
|
899
|
+
* @returns Payload CMS find response with deleted docs
|
|
823
900
|
*/
|
|
824
|
-
async
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
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
|
-
}
|
|
901
|
+
async removeMany(where) {
|
|
902
|
+
return this.api.requestDeleteMany(
|
|
903
|
+
`/api/${String(this.collection)}`,
|
|
904
|
+
{ where }
|
|
905
|
+
);
|
|
837
906
|
}
|
|
838
907
|
};
|
|
908
|
+
var ServerCollectionQueryBuilder = class extends CollectionQueryBuilder {
|
|
909
|
+
};
|
|
839
910
|
|
|
840
911
|
// src/core/collection/collection-client.ts
|
|
841
912
|
function buildPayloadFormData(data, file, filename) {
|
|
@@ -1014,7 +1085,7 @@ async function parseApiResponse(response, endpoint) {
|
|
|
1014
1085
|
if (reason === "validation_failed") {
|
|
1015
1086
|
throw attachRequestId(createValidationError(errorMessage, data, errorMessage), requestId);
|
|
1016
1087
|
}
|
|
1017
|
-
if (reason === "token_expired" || reason === "token_invalid" || reason === "key_invalid" || reason === "key_revoked") {
|
|
1088
|
+
if (reason === "token_expired" || reason === "token_invalid" || reason === "preview_token_invalid" || reason === "preview_token_required" || reason === "key_invalid" || reason === "key_revoked") {
|
|
1018
1089
|
throw attachRequestId(createAuthError(errorMessage, data, errorMessage), requestId);
|
|
1019
1090
|
}
|
|
1020
1091
|
if (reason === "forbidden") {
|
|
@@ -1046,6 +1117,7 @@ var CommunityClient = class {
|
|
|
1046
1117
|
options.secretKey
|
|
1047
1118
|
);
|
|
1048
1119
|
this.secretKey = options.secretKey;
|
|
1120
|
+
this.apiUrl = options.apiUrl;
|
|
1049
1121
|
this.customerToken = options.customerToken;
|
|
1050
1122
|
this.onUnauthorized = options.onUnauthorized;
|
|
1051
1123
|
this.onRequestId = options.onRequestId;
|
|
@@ -1060,6 +1132,7 @@ var CommunityClient = class {
|
|
|
1060
1132
|
try {
|
|
1061
1133
|
const response = await httpFetch(endpoint, {
|
|
1062
1134
|
method,
|
|
1135
|
+
apiUrl: this.apiUrl,
|
|
1063
1136
|
publishableKey: this.publishableKey,
|
|
1064
1137
|
secretKey: this.secretKey,
|
|
1065
1138
|
customerToken: token ?? void 0,
|
|
@@ -1220,6 +1293,7 @@ var BaseApi = class {
|
|
|
1220
1293
|
options.secretKey
|
|
1221
1294
|
);
|
|
1222
1295
|
this.secretKey = options.secretKey;
|
|
1296
|
+
this.apiUrl = options.apiUrl;
|
|
1223
1297
|
this.onRequestId = options.onRequestId;
|
|
1224
1298
|
}
|
|
1225
1299
|
async request(endpoint, body, options) {
|
|
@@ -1227,6 +1301,7 @@ var BaseApi = class {
|
|
|
1227
1301
|
try {
|
|
1228
1302
|
const response = await httpFetch(endpoint, {
|
|
1229
1303
|
method,
|
|
1304
|
+
apiUrl: this.apiUrl,
|
|
1230
1305
|
publishableKey: this.publishableKey,
|
|
1231
1306
|
secretKey: this.secretKey,
|
|
1232
1307
|
...body !== void 0 && { body: JSON.stringify(body) },
|
|
@@ -1269,6 +1344,7 @@ var CartApi = class {
|
|
|
1269
1344
|
options.secretKey
|
|
1270
1345
|
);
|
|
1271
1346
|
this.secretKey = options.secretKey;
|
|
1347
|
+
this.apiUrl = options.apiUrl;
|
|
1272
1348
|
this.customerToken = options.customerToken;
|
|
1273
1349
|
this.onUnauthorized = options.onUnauthorized;
|
|
1274
1350
|
this.onRequestId = options.onRequestId;
|
|
@@ -1278,6 +1354,7 @@ var CartApi = class {
|
|
|
1278
1354
|
try {
|
|
1279
1355
|
const response = await httpFetch(endpoint, {
|
|
1280
1356
|
method,
|
|
1357
|
+
apiUrl: this.apiUrl,
|
|
1281
1358
|
publishableKey: this.publishableKey,
|
|
1282
1359
|
secretKey: this.secretKey,
|
|
1283
1360
|
customerToken: token ?? void 0,
|
|
@@ -1437,7 +1514,61 @@ var OrderApi = class extends BaseApi {
|
|
|
1437
1514
|
}
|
|
1438
1515
|
};
|
|
1439
1516
|
|
|
1517
|
+
// src/core/preview/server-preview-client.ts
|
|
1518
|
+
var ServerPreviewClient = class extends BaseApi {
|
|
1519
|
+
constructor(options) {
|
|
1520
|
+
super("ServerPreviewClient", options);
|
|
1521
|
+
}
|
|
1522
|
+
async detail(params, options) {
|
|
1523
|
+
let response;
|
|
1524
|
+
try {
|
|
1525
|
+
response = await httpFetch("/api/preview/detail", {
|
|
1526
|
+
method: "POST",
|
|
1527
|
+
apiUrl: this.apiUrl,
|
|
1528
|
+
publishableKey: this.publishableKey,
|
|
1529
|
+
secretKey: this.secretKey,
|
|
1530
|
+
body: JSON.stringify(params),
|
|
1531
|
+
headers: { "X-Preview-Token": options.previewToken }
|
|
1532
|
+
});
|
|
1533
|
+
} catch (err) {
|
|
1534
|
+
const id = err instanceof SDKError ? err.requestId ?? null : null;
|
|
1535
|
+
this.onRequestId?.(id);
|
|
1536
|
+
if (err instanceof NotFoundError) return null;
|
|
1537
|
+
throw err;
|
|
1538
|
+
}
|
|
1539
|
+
const requestId = response.headers.get("x-request-id") ?? null;
|
|
1540
|
+
this.onRequestId?.(requestId);
|
|
1541
|
+
try {
|
|
1542
|
+
return await response.json();
|
|
1543
|
+
} catch (err) {
|
|
1544
|
+
if (err instanceof SyntaxError) {
|
|
1545
|
+
throw createApiError(
|
|
1546
|
+
"Invalid JSON response from /api/preview/detail",
|
|
1547
|
+
200,
|
|
1548
|
+
void 0,
|
|
1549
|
+
"Server returned an invalid response.",
|
|
1550
|
+
"Check if the API endpoint is available.",
|
|
1551
|
+
requestId ?? void 0
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
throw err;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
|
|
1440
1559
|
// src/core/commerce/server-commerce-client.ts
|
|
1560
|
+
var PreviewProductApi = class extends ProductApi {
|
|
1561
|
+
constructor(options) {
|
|
1562
|
+
super(options);
|
|
1563
|
+
this.previewApi = new ServerPreviewClient(options);
|
|
1564
|
+
}
|
|
1565
|
+
async previewDetail(params, options) {
|
|
1566
|
+
return this.previewApi.detail(
|
|
1567
|
+
{ collection: "products", id: params.id },
|
|
1568
|
+
options
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
};
|
|
1441
1572
|
var ServerCommerceClient = class {
|
|
1442
1573
|
constructor(options) {
|
|
1443
1574
|
const publishableKey = requirePublishableKeyForSecret(
|
|
@@ -1448,9 +1579,10 @@ var ServerCommerceClient = class {
|
|
|
1448
1579
|
const serverOptions = {
|
|
1449
1580
|
publishableKey,
|
|
1450
1581
|
secretKey: options.secretKey,
|
|
1582
|
+
apiUrl: options.apiUrl,
|
|
1451
1583
|
onRequestId: options.onRequestId
|
|
1452
1584
|
};
|
|
1453
|
-
const productApi = new
|
|
1585
|
+
const productApi = new PreviewProductApi(serverOptions);
|
|
1454
1586
|
const cartApi = new CartApi(serverOptions);
|
|
1455
1587
|
const discountApi = new DiscountApi(serverOptions);
|
|
1456
1588
|
const shippingApi = new ShippingApi(serverOptions);
|
|
@@ -1459,6 +1591,7 @@ var ServerCommerceClient = class {
|
|
|
1459
1591
|
stockCheck: productApi.stockCheck.bind(productApi),
|
|
1460
1592
|
listingGroups: productApi.listingGroups.bind(productApi),
|
|
1461
1593
|
detail: productApi.detail.bind(productApi),
|
|
1594
|
+
previewDetail: productApi.previewDetail.bind(productApi),
|
|
1462
1595
|
upsert: productApi.upsert.bind(productApi)
|
|
1463
1596
|
};
|
|
1464
1597
|
this.cart = {
|
|
@@ -1492,578 +1625,6 @@ var ServerCommerceClient = class {
|
|
|
1492
1625
|
}
|
|
1493
1626
|
};
|
|
1494
1627
|
|
|
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
1628
|
// src/core/client/client.server.ts
|
|
2068
1629
|
var ServerClient = class {
|
|
2069
1630
|
constructor(options) {
|
|
@@ -2093,9 +1654,14 @@ var ServerClient = class {
|
|
|
2093
1654
|
const serverOptions = {
|
|
2094
1655
|
publishableKey: this.config.publishableKey,
|
|
2095
1656
|
secretKey: this.config.secretKey,
|
|
1657
|
+
apiUrl: this.config.apiUrl,
|
|
2096
1658
|
onRequestId
|
|
2097
1659
|
};
|
|
2098
1660
|
this.commerce = new ServerCommerceClient(serverOptions);
|
|
1661
|
+
const previewApi = new ServerPreviewClient(serverOptions);
|
|
1662
|
+
this.preview = {
|
|
1663
|
+
detail: previewApi.detail.bind(previewApi)
|
|
1664
|
+
};
|
|
2099
1665
|
const communityClient = new CommunityClient(serverOptions);
|
|
2100
1666
|
const moderationApi = new ModerationApi(serverOptions);
|
|
2101
1667
|
this.community = Object.assign(communityClient, {
|
|
@@ -2109,10 +1675,9 @@ var ServerClient = class {
|
|
|
2109
1675
|
this.config.secretKey,
|
|
2110
1676
|
void 0,
|
|
2111
1677
|
void 0,
|
|
2112
|
-
onRequestId
|
|
1678
|
+
onRequestId,
|
|
1679
|
+
this.config.apiUrl
|
|
2113
1680
|
);
|
|
2114
|
-
this.queryClient = getQueryClient();
|
|
2115
|
-
this.query = new QueryHooks(this.queryClient, this.collections, void 0, this.commerce);
|
|
2116
1681
|
}
|
|
2117
1682
|
getState() {
|
|
2118
1683
|
return { ...this.state };
|
|
@@ -2132,6 +1697,7 @@ export {
|
|
|
2132
1697
|
ServerClient,
|
|
2133
1698
|
ServerCollectionClient,
|
|
2134
1699
|
ServerCommerceClient,
|
|
1700
|
+
ServerPreviewClient,
|
|
2135
1701
|
createServerClient
|
|
2136
1702
|
};
|
|
2137
1703
|
//# sourceMappingURL=server.js.map
|