@01.software/sdk 0.2.9-dev.260310.cf511cb → 0.2.9-dev.260311.892250f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -8
- package/dist/auth.cjs +3 -1
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +36 -3
- package/dist/auth.d.ts +36 -3
- package/dist/auth.js +3 -1
- package/dist/auth.js.map +1 -1
- package/dist/index.cjs +214 -231
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +321 -155
- package/dist/index.d.ts +321 -155
- package/dist/index.js +217 -231
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-Cq93wqIe.d.cts → payload-types-BjvBwB8Z.d.cts} +1601 -1373
- package/dist/{payload-types-Cq93wqIe.d.ts → payload-types-BjvBwB8Z.d.ts} +1601 -1373
- package/dist/ui/code-block.cjs +182 -0
- package/dist/ui/code-block.cjs.map +1 -0
- package/dist/ui/code-block.d.cts +62 -0
- package/dist/ui/code-block.d.ts +62 -0
- package/dist/ui/code-block.js +152 -0
- package/dist/ui/code-block.js.map +1 -0
- package/dist/{flow.cjs → ui/flow.cjs} +120 -96
- package/dist/ui/flow.cjs.map +1 -0
- package/dist/{flow.d.cts → ui/flow.d.cts} +27 -11
- package/dist/{flow.d.ts → ui/flow.d.ts} +27 -11
- package/dist/{flow.js → ui/flow.js} +119 -94
- package/dist/ui/flow.js.map +1 -0
- package/dist/{components.cjs → ui/form.cjs} +27 -520
- package/dist/ui/form.cjs.map +1 -0
- package/dist/ui/form.d.cts +37 -0
- package/dist/ui/form.d.ts +37 -0
- package/dist/{components.js → ui/form.js} +20 -516
- package/dist/ui/form.js.map +1 -0
- package/dist/ui/image.cjs +208 -0
- package/dist/ui/image.cjs.map +1 -0
- package/dist/ui/image.d.cts +44 -0
- package/dist/ui/image.d.ts +44 -0
- package/dist/ui/image.js +180 -0
- package/dist/ui/image.js.map +1 -0
- package/dist/ui/rich-text.cjs +258 -0
- package/dist/ui/rich-text.cjs.map +1 -0
- package/dist/ui/rich-text.d.cts +110 -0
- package/dist/ui/rich-text.d.ts +110 -0
- package/dist/ui/rich-text.js +235 -0
- package/dist/ui/rich-text.js.map +1 -0
- package/dist/{webhook-NRdVwXN7.d.cts → webhook-CszIpUKn.d.cts} +2 -2
- package/dist/{webhook-C_7s0K66.d.ts → webhook-_LdLdjGa.d.ts} +2 -2
- package/dist/webhook.d.cts +2 -2
- package/dist/webhook.d.ts +2 -2
- package/package.json +47 -12
- package/dist/auth-CVVo5UT5.d.ts +0 -298
- package/dist/auth-CqgrT1qd.d.cts +0 -298
- package/dist/components.cjs.map +0 -1
- package/dist/components.d.cts +0 -240
- package/dist/components.d.ts +0 -240
- package/dist/components.js.map +0 -1
- package/dist/flow.cjs.map +0 -1
- package/dist/flow.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -71,13 +71,16 @@ var __async = (__this, __arguments, generator) => {
|
|
|
71
71
|
var src_exports = {};
|
|
72
72
|
__export(src_exports, {
|
|
73
73
|
ApiError: () => ApiError,
|
|
74
|
+
BaseApi: () => BaseApi,
|
|
74
75
|
BrowserClient: () => BrowserClient,
|
|
75
76
|
COLLECTIONS: () => COLLECTIONS,
|
|
76
77
|
CartApi: () => CartApi,
|
|
77
78
|
CollectionClient: () => CollectionClient,
|
|
79
|
+
CollectionHooks: () => CollectionHooks,
|
|
78
80
|
CollectionQueryBuilder: () => CollectionQueryBuilder,
|
|
79
81
|
ConfigError: () => ConfigError,
|
|
80
82
|
CustomerAuth: () => CustomerAuth,
|
|
83
|
+
CustomerHooks: () => CustomerHooks,
|
|
81
84
|
GoneError: () => GoneError,
|
|
82
85
|
IMAGE_SIZES: () => IMAGE_SIZES,
|
|
83
86
|
NetworkError: () => NetworkError,
|
|
@@ -128,8 +131,86 @@ __export(src_exports, {
|
|
|
128
131
|
});
|
|
129
132
|
module.exports = __toCommonJS(src_exports);
|
|
130
133
|
|
|
131
|
-
// src/core/internal/utils/
|
|
134
|
+
// src/core/internal/utils/jwt.ts
|
|
132
135
|
var import_jose = require("jose");
|
|
136
|
+
function createServerToken(clientKey, secretKey, expiresIn = "1h") {
|
|
137
|
+
return __async(this, null, function* () {
|
|
138
|
+
if (!clientKey || !secretKey) {
|
|
139
|
+
throw new Error("clientKey and secretKey are required.");
|
|
140
|
+
}
|
|
141
|
+
const secret = new TextEncoder().encode(secretKey);
|
|
142
|
+
return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
function verifyServerToken(token, secretKey) {
|
|
146
|
+
return __async(this, null, function* () {
|
|
147
|
+
if (!token || !secretKey) {
|
|
148
|
+
throw new Error("token and secretKey are required.");
|
|
149
|
+
}
|
|
150
|
+
const secret = new TextEncoder().encode(secretKey);
|
|
151
|
+
const { payload } = yield (0, import_jose.jwtVerify)(token, secret, {
|
|
152
|
+
algorithms: ["HS256"]
|
|
153
|
+
});
|
|
154
|
+
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
155
|
+
throw new Error("Invalid token payload: clientKey is missing");
|
|
156
|
+
}
|
|
157
|
+
return {
|
|
158
|
+
clientKey: payload.clientKey,
|
|
159
|
+
iat: payload.iat,
|
|
160
|
+
exp: payload.exp
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function decodeServerToken(token) {
|
|
165
|
+
if (!token) {
|
|
166
|
+
throw new Error("token is required.");
|
|
167
|
+
}
|
|
168
|
+
const payload = (0, import_jose.decodeJwt)(token);
|
|
169
|
+
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
170
|
+
throw new Error("Invalid token payload: clientKey is missing");
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
clientKey: payload.clientKey,
|
|
174
|
+
iat: payload.iat,
|
|
175
|
+
exp: payload.exp
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/core/internal/utils/encoding.ts
|
|
180
|
+
function createApiKey(clientKey, secretKey) {
|
|
181
|
+
if (!clientKey || !secretKey) {
|
|
182
|
+
throw new Error("clientKey and secretKey are required.");
|
|
183
|
+
}
|
|
184
|
+
if (typeof Buffer !== "undefined") {
|
|
185
|
+
return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
|
|
186
|
+
}
|
|
187
|
+
return btoa(`${clientKey}:${secretKey}`);
|
|
188
|
+
}
|
|
189
|
+
function parseApiKey(apiKey) {
|
|
190
|
+
if (!apiKey) {
|
|
191
|
+
throw new Error("apiKey is required.");
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
let decoded;
|
|
195
|
+
if (typeof Buffer !== "undefined") {
|
|
196
|
+
decoded = Buffer.from(apiKey, "base64").toString("utf-8");
|
|
197
|
+
} else {
|
|
198
|
+
decoded = atob(apiKey);
|
|
199
|
+
}
|
|
200
|
+
const colonIndex = decoded.indexOf(":");
|
|
201
|
+
if (colonIndex === -1) {
|
|
202
|
+
throw new Error("Invalid format: missing colon separator");
|
|
203
|
+
}
|
|
204
|
+
const clientKey = decoded.substring(0, colonIndex);
|
|
205
|
+
const secretKey = decoded.substring(colonIndex + 1);
|
|
206
|
+
if (!clientKey || !secretKey) {
|
|
207
|
+
throw new Error("Invalid format: empty clientKey or secretKey");
|
|
208
|
+
}
|
|
209
|
+
return { clientKey, secretKey };
|
|
210
|
+
} catch (e) {
|
|
211
|
+
throw new Error('Invalid API key. Expected Base64 encoded "clientKey:secretKey"');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
133
214
|
|
|
134
215
|
// src/core/internal/errors/index.ts
|
|
135
216
|
var SDKError = class _SDKError extends Error {
|
|
@@ -270,87 +351,11 @@ function resolveApiUrl(config) {
|
|
|
270
351
|
return API_URLS.production;
|
|
271
352
|
}
|
|
272
353
|
|
|
273
|
-
// src/core/internal/utils/
|
|
354
|
+
// src/core/internal/utils/http.ts
|
|
274
355
|
var DEFAULT_TIMEOUT = 3e4;
|
|
275
356
|
var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
|
|
276
357
|
var NON_RETRYABLE_STATUSES = [401, 403, 404, 422];
|
|
277
358
|
var SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
|
|
278
|
-
function createServerToken(clientKey, secretKey, expiresIn = "1h") {
|
|
279
|
-
return __async(this, null, function* () {
|
|
280
|
-
if (!clientKey || !secretKey) {
|
|
281
|
-
throw new Error("clientKey and secretKey are required.");
|
|
282
|
-
}
|
|
283
|
-
const secret = new TextEncoder().encode(secretKey);
|
|
284
|
-
return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
function verifyServerToken(token, secretKey) {
|
|
288
|
-
return __async(this, null, function* () {
|
|
289
|
-
if (!token || !secretKey) {
|
|
290
|
-
throw new Error("token and secretKey are required.");
|
|
291
|
-
}
|
|
292
|
-
const secret = new TextEncoder().encode(secretKey);
|
|
293
|
-
const { payload } = yield (0, import_jose.jwtVerify)(token, secret, {
|
|
294
|
-
algorithms: ["HS256"]
|
|
295
|
-
});
|
|
296
|
-
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
297
|
-
throw new Error("Invalid token payload: clientKey is missing");
|
|
298
|
-
}
|
|
299
|
-
return {
|
|
300
|
-
clientKey: payload.clientKey,
|
|
301
|
-
iat: payload.iat,
|
|
302
|
-
exp: payload.exp
|
|
303
|
-
};
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
function decodeServerToken(token) {
|
|
307
|
-
if (!token) {
|
|
308
|
-
throw new Error("token is required.");
|
|
309
|
-
}
|
|
310
|
-
const payload = (0, import_jose.decodeJwt)(token);
|
|
311
|
-
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
312
|
-
throw new Error("Invalid token payload: clientKey is missing");
|
|
313
|
-
}
|
|
314
|
-
return {
|
|
315
|
-
clientKey: payload.clientKey,
|
|
316
|
-
iat: payload.iat,
|
|
317
|
-
exp: payload.exp
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
function createApiKey(clientKey, secretKey) {
|
|
321
|
-
if (!clientKey || !secretKey) {
|
|
322
|
-
throw new Error("clientKey and secretKey are required.");
|
|
323
|
-
}
|
|
324
|
-
if (typeof Buffer !== "undefined") {
|
|
325
|
-
return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
|
|
326
|
-
}
|
|
327
|
-
return btoa(`${clientKey}:${secretKey}`);
|
|
328
|
-
}
|
|
329
|
-
function parseApiKey(apiKey) {
|
|
330
|
-
if (!apiKey) {
|
|
331
|
-
throw new Error("apiKey is required.");
|
|
332
|
-
}
|
|
333
|
-
try {
|
|
334
|
-
let decoded;
|
|
335
|
-
if (typeof Buffer !== "undefined") {
|
|
336
|
-
decoded = Buffer.from(apiKey, "base64").toString("utf-8");
|
|
337
|
-
} else {
|
|
338
|
-
decoded = atob(apiKey);
|
|
339
|
-
}
|
|
340
|
-
const colonIndex = decoded.indexOf(":");
|
|
341
|
-
if (colonIndex === -1) {
|
|
342
|
-
throw new Error("Invalid format: missing colon separator");
|
|
343
|
-
}
|
|
344
|
-
const clientKey = decoded.substring(0, colonIndex);
|
|
345
|
-
const secretKey = decoded.substring(colonIndex + 1);
|
|
346
|
-
if (!clientKey || !secretKey) {
|
|
347
|
-
throw new Error("Invalid format: empty clientKey or secretKey");
|
|
348
|
-
}
|
|
349
|
-
return { clientKey, secretKey };
|
|
350
|
-
} catch (e) {
|
|
351
|
-
throw new Error('Invalid API key. Expected Base64 encoded "clientKey:secretKey"');
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
359
|
function debugLog(debug, type, message, data) {
|
|
355
360
|
if (!debug) return;
|
|
356
361
|
const shouldLog = debug === true || type === "request" && debug.logRequests || type === "response" && debug.logResponses || type === "error" && debug.logErrors;
|
|
@@ -372,7 +377,7 @@ function delay(ms) {
|
|
|
372
377
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
373
378
|
});
|
|
374
379
|
}
|
|
375
|
-
function
|
|
380
|
+
function httpFetch(url, options) {
|
|
376
381
|
return __async(this, null, function* () {
|
|
377
382
|
var _b, _c, _d;
|
|
378
383
|
const _a = options || {}, {
|
|
@@ -552,14 +557,14 @@ function _fetch(url, options) {
|
|
|
552
557
|
});
|
|
553
558
|
}
|
|
554
559
|
|
|
555
|
-
// src/core/api/
|
|
556
|
-
var
|
|
557
|
-
constructor(options) {
|
|
560
|
+
// src/core/api/base-api.ts
|
|
561
|
+
var BaseApi = class {
|
|
562
|
+
constructor(apiName, options) {
|
|
558
563
|
if (!options.clientKey) {
|
|
559
|
-
throw createConfigError(
|
|
564
|
+
throw createConfigError(`clientKey is required for ${apiName}.`);
|
|
560
565
|
}
|
|
561
566
|
if (!options.secretKey) {
|
|
562
|
-
throw createConfigError(
|
|
567
|
+
throw createConfigError(`secretKey is required for ${apiName}.`);
|
|
563
568
|
}
|
|
564
569
|
this.clientKey = options.clientKey;
|
|
565
570
|
this.secretKey = options.secretKey;
|
|
@@ -567,7 +572,7 @@ var OrderApi = class {
|
|
|
567
572
|
}
|
|
568
573
|
request(endpoint, body) {
|
|
569
574
|
return __async(this, null, function* () {
|
|
570
|
-
const response = yield
|
|
575
|
+
const response = yield httpFetch(endpoint, {
|
|
571
576
|
method: "POST",
|
|
572
577
|
clientKey: this.clientKey,
|
|
573
578
|
secretKey: this.secretKey,
|
|
@@ -599,6 +604,13 @@ var OrderApi = class {
|
|
|
599
604
|
return data;
|
|
600
605
|
});
|
|
601
606
|
}
|
|
607
|
+
};
|
|
608
|
+
|
|
609
|
+
// src/core/api/order-api.ts
|
|
610
|
+
var OrderApi = class extends BaseApi {
|
|
611
|
+
constructor(options) {
|
|
612
|
+
super("OrderApi", options);
|
|
613
|
+
}
|
|
602
614
|
createOrder(params) {
|
|
603
615
|
return this.request("/api/orders/create", params);
|
|
604
616
|
}
|
|
@@ -661,7 +673,7 @@ var CartApi = class {
|
|
|
661
673
|
execute(endpoint, method, body) {
|
|
662
674
|
return __async(this, null, function* () {
|
|
663
675
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
664
|
-
const response = yield
|
|
676
|
+
const response = yield httpFetch(endpoint, __spreadValues(__spreadValues({
|
|
665
677
|
method,
|
|
666
678
|
clientKey: this.clientKey,
|
|
667
679
|
secretKey: this.secretKey,
|
|
@@ -717,51 +729,9 @@ var CartApi = class {
|
|
|
717
729
|
};
|
|
718
730
|
|
|
719
731
|
// src/core/api/product-api.ts
|
|
720
|
-
var ProductApi = class {
|
|
732
|
+
var ProductApi = class extends BaseApi {
|
|
721
733
|
constructor(options) {
|
|
722
|
-
|
|
723
|
-
throw createConfigError("clientKey is required for ProductApi.");
|
|
724
|
-
}
|
|
725
|
-
if (!options.secretKey) {
|
|
726
|
-
throw createConfigError("secretKey is required for ProductApi.");
|
|
727
|
-
}
|
|
728
|
-
this.clientKey = options.clientKey;
|
|
729
|
-
this.secretKey = options.secretKey;
|
|
730
|
-
this.baseUrl = options.baseUrl;
|
|
731
|
-
}
|
|
732
|
-
request(endpoint, body) {
|
|
733
|
-
return __async(this, null, function* () {
|
|
734
|
-
const response = yield _fetch(endpoint, {
|
|
735
|
-
method: "POST",
|
|
736
|
-
clientKey: this.clientKey,
|
|
737
|
-
secretKey: this.secretKey,
|
|
738
|
-
baseUrl: this.baseUrl,
|
|
739
|
-
body: JSON.stringify(body)
|
|
740
|
-
});
|
|
741
|
-
let data;
|
|
742
|
-
try {
|
|
743
|
-
data = yield response.json();
|
|
744
|
-
} catch (e) {
|
|
745
|
-
throw createApiError(
|
|
746
|
-
`Invalid JSON response from ${endpoint}`,
|
|
747
|
-
response.status,
|
|
748
|
-
void 0,
|
|
749
|
-
"Server returned an invalid response.",
|
|
750
|
-
"Check if the API endpoint is available."
|
|
751
|
-
);
|
|
752
|
-
}
|
|
753
|
-
if (data.error) {
|
|
754
|
-
const errorMessage = typeof data.error === "string" ? data.error : "Unknown API error";
|
|
755
|
-
throw createApiError(
|
|
756
|
-
errorMessage,
|
|
757
|
-
response.status,
|
|
758
|
-
data,
|
|
759
|
-
errorMessage,
|
|
760
|
-
"An error occurred while processing the request."
|
|
761
|
-
);
|
|
762
|
-
}
|
|
763
|
-
return data;
|
|
764
|
-
});
|
|
734
|
+
super("ProductApi", options);
|
|
765
735
|
}
|
|
766
736
|
stockCheck(params) {
|
|
767
737
|
return this.request("/api/products/stock-check", params);
|
|
@@ -1122,7 +1092,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1122
1092
|
requestFind(endpoint, options) {
|
|
1123
1093
|
return __async(this, null, function* () {
|
|
1124
1094
|
const url = this.buildUrl(endpoint, options);
|
|
1125
|
-
const response = yield
|
|
1095
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
|
|
1126
1096
|
return this.parseFindResponse(response);
|
|
1127
1097
|
});
|
|
1128
1098
|
}
|
|
@@ -1133,7 +1103,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1133
1103
|
requestFindById(endpoint, options) {
|
|
1134
1104
|
return __async(this, null, function* () {
|
|
1135
1105
|
const url = this.buildUrl(endpoint, options);
|
|
1136
|
-
const response = yield
|
|
1106
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
|
|
1137
1107
|
return this.parseDocumentResponse(response);
|
|
1138
1108
|
});
|
|
1139
1109
|
}
|
|
@@ -1143,7 +1113,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1143
1113
|
*/
|
|
1144
1114
|
requestCreate(endpoint, data) {
|
|
1145
1115
|
return __async(this, null, function* () {
|
|
1146
|
-
const response = yield
|
|
1116
|
+
const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1147
1117
|
method: "POST",
|
|
1148
1118
|
body: data ? JSON.stringify(data) : void 0
|
|
1149
1119
|
}));
|
|
@@ -1156,7 +1126,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1156
1126
|
*/
|
|
1157
1127
|
requestUpdate(endpoint, data) {
|
|
1158
1128
|
return __async(this, null, function* () {
|
|
1159
|
-
const response = yield
|
|
1129
|
+
const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1160
1130
|
method: "PATCH",
|
|
1161
1131
|
body: data ? JSON.stringify(data) : void 0
|
|
1162
1132
|
}));
|
|
@@ -1170,7 +1140,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1170
1140
|
requestCount(endpoint, options) {
|
|
1171
1141
|
return __async(this, null, function* () {
|
|
1172
1142
|
const url = this.buildUrl(endpoint, options);
|
|
1173
|
-
const response = yield
|
|
1143
|
+
const response = yield httpFetch(url, __spreadProps(__spreadValues({}, this.defaultOptions), { method: "GET" }));
|
|
1174
1144
|
return this.parseDocumentResponse(response);
|
|
1175
1145
|
});
|
|
1176
1146
|
}
|
|
@@ -1180,7 +1150,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1180
1150
|
*/
|
|
1181
1151
|
requestUpdateMany(endpoint, data) {
|
|
1182
1152
|
return __async(this, null, function* () {
|
|
1183
|
-
const response = yield
|
|
1153
|
+
const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1184
1154
|
method: "PATCH",
|
|
1185
1155
|
body: JSON.stringify(data)
|
|
1186
1156
|
}));
|
|
@@ -1193,7 +1163,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1193
1163
|
*/
|
|
1194
1164
|
requestDelete(endpoint) {
|
|
1195
1165
|
return __async(this, null, function* () {
|
|
1196
|
-
const response = yield
|
|
1166
|
+
const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1197
1167
|
method: "DELETE"
|
|
1198
1168
|
}));
|
|
1199
1169
|
return this.parseDocumentResponse(response);
|
|
@@ -1205,7 +1175,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1205
1175
|
*/
|
|
1206
1176
|
requestDeleteMany(endpoint, data) {
|
|
1207
1177
|
return __async(this, null, function* () {
|
|
1208
|
-
const response = yield
|
|
1178
|
+
const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1209
1179
|
method: "DELETE",
|
|
1210
1180
|
body: JSON.stringify(data)
|
|
1211
1181
|
}));
|
|
@@ -1218,7 +1188,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1218
1188
|
*/
|
|
1219
1189
|
requestCreateWithFile(endpoint, data, file, filename) {
|
|
1220
1190
|
return __async(this, null, function* () {
|
|
1221
|
-
const response = yield
|
|
1191
|
+
const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1222
1192
|
method: "POST",
|
|
1223
1193
|
body: buildPayloadFormData(data, file, filename)
|
|
1224
1194
|
}));
|
|
@@ -1231,7 +1201,7 @@ var CollectionClient = class extends HttpClient {
|
|
|
1231
1201
|
*/
|
|
1232
1202
|
requestUpdateWithFile(endpoint, data, file, filename) {
|
|
1233
1203
|
return __async(this, null, function* () {
|
|
1234
|
-
const response = yield
|
|
1204
|
+
const response = yield httpFetch(endpoint, __spreadProps(__spreadValues({}, this.defaultOptions), {
|
|
1235
1205
|
method: "PATCH",
|
|
1236
1206
|
body: buildPayloadFormData(data, file, filename)
|
|
1237
1207
|
}));
|
|
@@ -1283,6 +1253,7 @@ var COLLECTIONS = [
|
|
|
1283
1253
|
"playlists",
|
|
1284
1254
|
"playlist-images",
|
|
1285
1255
|
"playlist-categories",
|
|
1256
|
+
"playlist-tags",
|
|
1286
1257
|
"musics",
|
|
1287
1258
|
"galleries",
|
|
1288
1259
|
"gallery-images",
|
|
@@ -1292,6 +1263,7 @@ var COLLECTIONS = [
|
|
|
1292
1263
|
"flow-images",
|
|
1293
1264
|
"flow-node-types",
|
|
1294
1265
|
"flow-edge-types",
|
|
1266
|
+
"flow-categories",
|
|
1295
1267
|
"flow-tags",
|
|
1296
1268
|
"videos",
|
|
1297
1269
|
"video-images",
|
|
@@ -1583,8 +1555,10 @@ function getQueryClient() {
|
|
|
1583
1555
|
return browserQueryClient;
|
|
1584
1556
|
}
|
|
1585
1557
|
|
|
1586
|
-
// src/core/query/
|
|
1558
|
+
// src/core/query/collection-hooks.ts
|
|
1587
1559
|
var import_react_query2 = require("@tanstack/react-query");
|
|
1560
|
+
|
|
1561
|
+
// src/core/query/query-keys.ts
|
|
1588
1562
|
function collectionKeys(collection) {
|
|
1589
1563
|
return {
|
|
1590
1564
|
all: [collection],
|
|
@@ -1600,20 +1574,13 @@ var customerKeys = {
|
|
|
1600
1574
|
all: ["customer"],
|
|
1601
1575
|
me: () => ["customer", "me"]
|
|
1602
1576
|
};
|
|
1577
|
+
|
|
1578
|
+
// src/core/query/collection-hooks.ts
|
|
1603
1579
|
var DEFAULT_PAGE_SIZE = 20;
|
|
1604
|
-
var
|
|
1605
|
-
constructor(queryClient, collectionClient
|
|
1580
|
+
var CollectionHooks = class {
|
|
1581
|
+
constructor(queryClient, collectionClient) {
|
|
1606
1582
|
this.queryClient = queryClient;
|
|
1607
1583
|
this.collectionClient = collectionClient;
|
|
1608
|
-
this.customerAuth = customerAuth;
|
|
1609
|
-
}
|
|
1610
|
-
ensureCustomerAuth() {
|
|
1611
|
-
if (!this.customerAuth) {
|
|
1612
|
-
throw createConfigError(
|
|
1613
|
-
"Customer hooks require BrowserClient. Use createBrowserClient() instead of createServerClient()."
|
|
1614
|
-
);
|
|
1615
|
-
}
|
|
1616
|
-
return this.customerAuth;
|
|
1617
1584
|
}
|
|
1618
1585
|
// ===== useQuery =====
|
|
1619
1586
|
useQuery(params, options) {
|
|
@@ -1812,10 +1779,42 @@ var QueryHooks = class {
|
|
|
1812
1779
|
);
|
|
1813
1780
|
}
|
|
1814
1781
|
}
|
|
1815
|
-
|
|
1782
|
+
};
|
|
1783
|
+
|
|
1784
|
+
// src/core/query/customer-hooks.ts
|
|
1785
|
+
var import_react_query3 = require("@tanstack/react-query");
|
|
1786
|
+
function createMutation(mutationFn, callbacks, onSuccessExtra) {
|
|
1787
|
+
return (0, import_react_query3.useMutation)({
|
|
1788
|
+
mutationFn,
|
|
1789
|
+
onSuccess: (data) => {
|
|
1790
|
+
var _a;
|
|
1791
|
+
onSuccessExtra == null ? void 0 : onSuccessExtra(data);
|
|
1792
|
+
(_a = callbacks == null ? void 0 : callbacks.onSuccess) == null ? void 0 : _a.call(callbacks, data);
|
|
1793
|
+
},
|
|
1794
|
+
onError: callbacks == null ? void 0 : callbacks.onError,
|
|
1795
|
+
onSettled: callbacks == null ? void 0 : callbacks.onSettled
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
var CustomerHooks = class {
|
|
1799
|
+
constructor(queryClient, customerAuth) {
|
|
1800
|
+
this.invalidateMe = () => {
|
|
1801
|
+
this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
|
|
1802
|
+
};
|
|
1803
|
+
this.queryClient = queryClient;
|
|
1804
|
+
this.customerAuth = customerAuth;
|
|
1805
|
+
}
|
|
1806
|
+
ensureCustomerAuth() {
|
|
1807
|
+
if (!this.customerAuth) {
|
|
1808
|
+
throw createConfigError(
|
|
1809
|
+
"Customer hooks require BrowserClient. Use createBrowserClient() instead of createServerClient()."
|
|
1810
|
+
);
|
|
1811
|
+
}
|
|
1812
|
+
return this.customerAuth;
|
|
1813
|
+
}
|
|
1814
|
+
// ===== useCustomerMe =====
|
|
1816
1815
|
useCustomerMe(options) {
|
|
1817
1816
|
var _a, _b;
|
|
1818
|
-
return (0,
|
|
1817
|
+
return (0, import_react_query3.useQuery)(__spreadProps(__spreadValues({
|
|
1819
1818
|
queryKey: customerKeys.me(),
|
|
1820
1819
|
queryFn: () => __async(this, null, function* () {
|
|
1821
1820
|
return yield this.ensureCustomerAuth().me();
|
|
@@ -1824,32 +1823,22 @@ var QueryHooks = class {
|
|
|
1824
1823
|
enabled: ((_a = options == null ? void 0 : options.enabled) != null ? _a : true) && !!((_b = this.customerAuth) == null ? void 0 : _b.isAuthenticated())
|
|
1825
1824
|
}));
|
|
1826
1825
|
}
|
|
1826
|
+
// ===== Mutations =====
|
|
1827
1827
|
useCustomerLogin(options) {
|
|
1828
|
-
return (
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
var _a;
|
|
1834
|
-
this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
|
|
1835
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1836
|
-
},
|
|
1837
|
-
onError: options == null ? void 0 : options.onError,
|
|
1838
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1839
|
-
});
|
|
1828
|
+
return createMutation(
|
|
1829
|
+
(data) => this.ensureCustomerAuth().login(data),
|
|
1830
|
+
options,
|
|
1831
|
+
this.invalidateMe
|
|
1832
|
+
);
|
|
1840
1833
|
}
|
|
1841
1834
|
useCustomerRegister(options) {
|
|
1842
|
-
return (
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
onSuccess: options == null ? void 0 : options.onSuccess,
|
|
1847
|
-
onError: options == null ? void 0 : options.onError,
|
|
1848
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1849
|
-
});
|
|
1835
|
+
return createMutation(
|
|
1836
|
+
(data) => this.ensureCustomerAuth().register(data),
|
|
1837
|
+
options
|
|
1838
|
+
);
|
|
1850
1839
|
}
|
|
1851
1840
|
useCustomerLogout(options) {
|
|
1852
|
-
return (0,
|
|
1841
|
+
return (0, import_react_query3.useMutation)({
|
|
1853
1842
|
mutationFn: () => __async(this, null, function* () {
|
|
1854
1843
|
this.ensureCustomerAuth().logout();
|
|
1855
1844
|
}),
|
|
@@ -1863,76 +1852,47 @@ var QueryHooks = class {
|
|
|
1863
1852
|
});
|
|
1864
1853
|
}
|
|
1865
1854
|
useCustomerForgotPassword(options) {
|
|
1866
|
-
return (
|
|
1867
|
-
|
|
1868
|
-
yield this.ensureCustomerAuth().forgotPassword(email);
|
|
1855
|
+
return createMutation(
|
|
1856
|
+
(email) => this.ensureCustomerAuth().forgotPassword(email).then(() => {
|
|
1869
1857
|
}),
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1873
|
-
});
|
|
1858
|
+
options
|
|
1859
|
+
);
|
|
1874
1860
|
}
|
|
1875
1861
|
useCustomerResetPassword(options) {
|
|
1876
|
-
return (
|
|
1877
|
-
|
|
1878
|
-
yield this.ensureCustomerAuth().resetPassword(data.token, data.password);
|
|
1862
|
+
return createMutation(
|
|
1863
|
+
(data) => this.ensureCustomerAuth().resetPassword(data.token, data.password).then(() => {
|
|
1879
1864
|
}),
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1883
|
-
});
|
|
1865
|
+
options
|
|
1866
|
+
);
|
|
1884
1867
|
}
|
|
1885
1868
|
useCustomerVerifyEmail(options) {
|
|
1886
|
-
return (
|
|
1887
|
-
|
|
1888
|
-
yield this.ensureCustomerAuth().verifyEmail(token);
|
|
1869
|
+
return createMutation(
|
|
1870
|
+
(token) => this.ensureCustomerAuth().verifyEmail(token).then(() => {
|
|
1889
1871
|
}),
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options);
|
|
1894
|
-
},
|
|
1895
|
-
onError: options == null ? void 0 : options.onError,
|
|
1896
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1897
|
-
});
|
|
1872
|
+
options,
|
|
1873
|
+
this.invalidateMe
|
|
1874
|
+
);
|
|
1898
1875
|
}
|
|
1899
1876
|
useCustomerRefreshToken(options) {
|
|
1900
|
-
return (
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
var _a;
|
|
1906
|
-
this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
|
|
1907
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1908
|
-
},
|
|
1909
|
-
onError: options == null ? void 0 : options.onError,
|
|
1910
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1911
|
-
});
|
|
1877
|
+
return createMutation(
|
|
1878
|
+
() => this.ensureCustomerAuth().refreshToken(),
|
|
1879
|
+
options,
|
|
1880
|
+
this.invalidateMe
|
|
1881
|
+
);
|
|
1912
1882
|
}
|
|
1913
1883
|
useCustomerUpdateProfile(options) {
|
|
1914
|
-
return (
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
var _a;
|
|
1920
|
-
this.queryClient.invalidateQueries({ queryKey: customerKeys.me() });
|
|
1921
|
-
(_a = options == null ? void 0 : options.onSuccess) == null ? void 0 : _a.call(options, data);
|
|
1922
|
-
},
|
|
1923
|
-
onError: options == null ? void 0 : options.onError,
|
|
1924
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1925
|
-
});
|
|
1884
|
+
return createMutation(
|
|
1885
|
+
(data) => this.ensureCustomerAuth().updateProfile(data),
|
|
1886
|
+
options,
|
|
1887
|
+
this.invalidateMe
|
|
1888
|
+
);
|
|
1926
1889
|
}
|
|
1927
1890
|
useCustomerChangePassword(options) {
|
|
1928
|
-
return (
|
|
1929
|
-
|
|
1930
|
-
yield this.ensureCustomerAuth().changePassword(data.currentPassword, data.newPassword);
|
|
1891
|
+
return createMutation(
|
|
1892
|
+
(data) => this.ensureCustomerAuth().changePassword(data.currentPassword, data.newPassword).then(() => {
|
|
1931
1893
|
}),
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
onSettled: options == null ? void 0 : options.onSettled
|
|
1935
|
-
});
|
|
1894
|
+
options
|
|
1895
|
+
);
|
|
1936
1896
|
}
|
|
1937
1897
|
// ===== Customer Cache Utilities =====
|
|
1938
1898
|
invalidateCustomerQueries() {
|
|
@@ -1946,6 +1906,29 @@ var QueryHooks = class {
|
|
|
1946
1906
|
}
|
|
1947
1907
|
};
|
|
1948
1908
|
|
|
1909
|
+
// src/core/query/query-hooks.ts
|
|
1910
|
+
var QueryHooks = class extends CollectionHooks {
|
|
1911
|
+
constructor(queryClient, collectionClient, customerAuth) {
|
|
1912
|
+
super(queryClient, collectionClient);
|
|
1913
|
+
// --- Customer hooks delegation ---
|
|
1914
|
+
this.useCustomerMe = (...args) => this._customer.useCustomerMe(...args);
|
|
1915
|
+
this.useCustomerLogin = (...args) => this._customer.useCustomerLogin(...args);
|
|
1916
|
+
this.useCustomerRegister = (...args) => this._customer.useCustomerRegister(...args);
|
|
1917
|
+
this.useCustomerLogout = (...args) => this._customer.useCustomerLogout(...args);
|
|
1918
|
+
this.useCustomerForgotPassword = (...args) => this._customer.useCustomerForgotPassword(...args);
|
|
1919
|
+
this.useCustomerResetPassword = (...args) => this._customer.useCustomerResetPassword(...args);
|
|
1920
|
+
this.useCustomerVerifyEmail = (...args) => this._customer.useCustomerVerifyEmail(...args);
|
|
1921
|
+
this.useCustomerRefreshToken = (...args) => this._customer.useCustomerRefreshToken(...args);
|
|
1922
|
+
this.useCustomerUpdateProfile = (...args) => this._customer.useCustomerUpdateProfile(...args);
|
|
1923
|
+
this.useCustomerChangePassword = (...args) => this._customer.useCustomerChangePassword(...args);
|
|
1924
|
+
// --- Customer cache delegation ---
|
|
1925
|
+
this.invalidateCustomerQueries = () => this._customer.invalidateCustomerQueries();
|
|
1926
|
+
this.getCustomerData = () => this._customer.getCustomerData();
|
|
1927
|
+
this.setCustomerData = (data) => this._customer.setCustomerData(data);
|
|
1928
|
+
this._customer = new CustomerHooks(queryClient, customerAuth);
|
|
1929
|
+
}
|
|
1930
|
+
};
|
|
1931
|
+
|
|
1949
1932
|
// src/core/client/client.ts
|
|
1950
1933
|
var BrowserClient = class {
|
|
1951
1934
|
constructor(options) {
|