@01.software/sdk 0.1.0-dev.260109.7cf07c9 → 0.1.0-dev.260119.0a66443
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 +29 -21
- package/dist/index.cjs +261 -118
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +315 -30
- package/dist/index.d.ts +315 -30
- package/dist/index.js +266 -122
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -102,7 +102,7 @@ var CollectionQueryBuilder = class {
|
|
|
102
102
|
import { stringify } from "qs-esm";
|
|
103
103
|
|
|
104
104
|
// src/core/internal/utils/index.ts
|
|
105
|
-
import { SignJWT } from "jose";
|
|
105
|
+
import { SignJWT, jwtVerify, decodeJwt } from "jose";
|
|
106
106
|
|
|
107
107
|
// src/core/internal/errors/index.ts
|
|
108
108
|
var SDKError = class _SDKError extends Error {
|
|
@@ -185,19 +185,112 @@ var createNetworkError = (message, status, details, userMessage, suggestion) =>
|
|
|
185
185
|
var createValidationError = (message, details, userMessage, suggestion) => new ValidationError(message, details, userMessage, suggestion);
|
|
186
186
|
var createApiError = (message, status, details, userMessage, suggestion) => new ApiError(message, status, details, userMessage, suggestion);
|
|
187
187
|
|
|
188
|
+
// src/core/client/types.ts
|
|
189
|
+
var API_URLS = {
|
|
190
|
+
local: "http://localhost:3000",
|
|
191
|
+
development: "https://dev.01.software",
|
|
192
|
+
staging: "https://stg.01.software",
|
|
193
|
+
production: "https://api.01.software"
|
|
194
|
+
};
|
|
195
|
+
function resolveApiUrl(config) {
|
|
196
|
+
if (config == null ? void 0 : config.baseUrl) {
|
|
197
|
+
return config.baseUrl.replace(/\/$/, "");
|
|
198
|
+
}
|
|
199
|
+
const envUrl = process.env.SOFTWARE_API_URL || process.env.NEXT_PUBLIC_SOFTWARE_API_URL;
|
|
200
|
+
if (envUrl) {
|
|
201
|
+
return envUrl.replace(/\/$/, "");
|
|
202
|
+
}
|
|
203
|
+
if (config == null ? void 0 : config.environment) {
|
|
204
|
+
return API_URLS[config.environment];
|
|
205
|
+
}
|
|
206
|
+
return API_URLS.production;
|
|
207
|
+
}
|
|
208
|
+
function isSuccessResponse(response) {
|
|
209
|
+
return response.success === true;
|
|
210
|
+
}
|
|
211
|
+
function isErrorResponse(response) {
|
|
212
|
+
return response.success === false;
|
|
213
|
+
}
|
|
214
|
+
|
|
188
215
|
// src/core/internal/utils/index.ts
|
|
189
|
-
var API_URL = process.env.SOFTWARE_API_URL || "https://stg.01.software";
|
|
190
216
|
var DEFAULT_TIMEOUT = 3e4;
|
|
191
217
|
var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
|
|
192
|
-
function createServerToken(clientKey, secretKey) {
|
|
218
|
+
function createServerToken(clientKey, secretKey, expiresIn = "1h") {
|
|
193
219
|
return __async(this, null, function* () {
|
|
194
220
|
if (!clientKey || !secretKey) {
|
|
195
221
|
throw new Error("clientKey\uC640 secretKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
196
222
|
}
|
|
197
223
|
const secret = new TextEncoder().encode(secretKey);
|
|
198
|
-
return new SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(
|
|
224
|
+
return new SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function verifyServerToken(token, secretKey) {
|
|
228
|
+
return __async(this, null, function* () {
|
|
229
|
+
if (!token || !secretKey) {
|
|
230
|
+
throw new Error("token\uACFC secretKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
231
|
+
}
|
|
232
|
+
const secret = new TextEncoder().encode(secretKey);
|
|
233
|
+
const { payload } = yield jwtVerify(token, secret, {
|
|
234
|
+
algorithms: ["HS256"]
|
|
235
|
+
});
|
|
236
|
+
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
237
|
+
throw new Error("Invalid token payload: clientKey is missing");
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
clientKey: payload.clientKey,
|
|
241
|
+
iat: payload.iat,
|
|
242
|
+
exp: payload.exp
|
|
243
|
+
};
|
|
199
244
|
});
|
|
200
245
|
}
|
|
246
|
+
function decodeServerToken(token) {
|
|
247
|
+
if (!token) {
|
|
248
|
+
throw new Error("token\uC740 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
249
|
+
}
|
|
250
|
+
const payload = decodeJwt(token);
|
|
251
|
+
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
252
|
+
throw new Error("Invalid token payload: clientKey is missing");
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
clientKey: payload.clientKey,
|
|
256
|
+
iat: payload.iat,
|
|
257
|
+
exp: payload.exp
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function createApiKey(clientKey, secretKey) {
|
|
261
|
+
if (!clientKey || !secretKey) {
|
|
262
|
+
throw new Error("clientKey\uC640 secretKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
263
|
+
}
|
|
264
|
+
if (typeof Buffer !== "undefined") {
|
|
265
|
+
return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
|
|
266
|
+
}
|
|
267
|
+
return btoa(`${clientKey}:${secretKey}`);
|
|
268
|
+
}
|
|
269
|
+
function parseApiKey(apiKey) {
|
|
270
|
+
if (!apiKey) {
|
|
271
|
+
throw new Error("apiKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
272
|
+
}
|
|
273
|
+
try {
|
|
274
|
+
let decoded;
|
|
275
|
+
if (typeof Buffer !== "undefined") {
|
|
276
|
+
decoded = Buffer.from(apiKey, "base64").toString("utf-8");
|
|
277
|
+
} else {
|
|
278
|
+
decoded = atob(apiKey);
|
|
279
|
+
}
|
|
280
|
+
const colonIndex = decoded.indexOf(":");
|
|
281
|
+
if (colonIndex === -1) {
|
|
282
|
+
throw new Error("Invalid format");
|
|
283
|
+
}
|
|
284
|
+
const clientKey = decoded.substring(0, colonIndex);
|
|
285
|
+
const secretKey = decoded.substring(colonIndex + 1);
|
|
286
|
+
if (!clientKey || !secretKey) {
|
|
287
|
+
throw new Error("Invalid format");
|
|
288
|
+
}
|
|
289
|
+
return { clientKey, secretKey };
|
|
290
|
+
} catch (e) {
|
|
291
|
+
throw new Error('Invalid API key. Expected Base64 encoded "clientKey:secretKey"');
|
|
292
|
+
}
|
|
293
|
+
}
|
|
201
294
|
function debugLog(debug, type, message, data) {
|
|
202
295
|
if (!debug) return;
|
|
203
296
|
const shouldLog = debug === true || type === "request" && debug.logRequests || type === "response" && debug.logResponses || type === "error" && debug.logErrors;
|
|
@@ -226,7 +319,7 @@ function _fetch(url, options) {
|
|
|
226
319
|
clientKey,
|
|
227
320
|
secretKey,
|
|
228
321
|
timeout = DEFAULT_TIMEOUT,
|
|
229
|
-
baseUrl =
|
|
322
|
+
baseUrl = API_URLS.production,
|
|
230
323
|
debug,
|
|
231
324
|
retry
|
|
232
325
|
} = _a, requestInit = __objRest(_a, [
|
|
@@ -351,13 +444,14 @@ function _fetch(url, options) {
|
|
|
351
444
|
|
|
352
445
|
// src/core/collection/base.ts
|
|
353
446
|
var BaseApiClient = class {
|
|
354
|
-
constructor(clientKey, secretKey) {
|
|
447
|
+
constructor(clientKey, secretKey, baseUrl) {
|
|
355
448
|
if (!clientKey) {
|
|
356
449
|
throw createValidationError("clientKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
357
450
|
}
|
|
358
451
|
this.clientKey = clientKey;
|
|
359
452
|
this.secretKey = secretKey;
|
|
360
|
-
this.
|
|
453
|
+
this.baseUrl = baseUrl;
|
|
454
|
+
this.defaultOptions = { clientKey, secretKey, baseUrl };
|
|
361
455
|
}
|
|
362
456
|
get(endpoint, options) {
|
|
363
457
|
return __async(this, null, function* () {
|
|
@@ -430,8 +524,8 @@ var BaseApiClient = class {
|
|
|
430
524
|
|
|
431
525
|
// src/core/collection/collections-api.ts
|
|
432
526
|
var CollectionsApi = class extends BaseApiClient {
|
|
433
|
-
constructor(clientKey, secretKey) {
|
|
434
|
-
super(clientKey, secretKey);
|
|
527
|
+
constructor(clientKey, secretKey, baseUrl) {
|
|
528
|
+
super(clientKey, secretKey, baseUrl);
|
|
435
529
|
}
|
|
436
530
|
from(collection) {
|
|
437
531
|
return new CollectionQueryBuilder(this, collection);
|
|
@@ -453,36 +547,37 @@ var CollectionsApi = class extends BaseApiClient {
|
|
|
453
547
|
// src/core/collection/const.ts
|
|
454
548
|
var COLLECTIONS = [
|
|
455
549
|
"tenants",
|
|
550
|
+
"tenant-metadata",
|
|
551
|
+
"tenant-logos",
|
|
552
|
+
"tenant-og-images",
|
|
456
553
|
"products",
|
|
457
554
|
"product-variants",
|
|
458
555
|
"product-options",
|
|
459
556
|
"product-categories",
|
|
460
557
|
"product-tags",
|
|
461
558
|
"product-images",
|
|
559
|
+
"brands",
|
|
560
|
+
"brand-logos",
|
|
462
561
|
"orders",
|
|
463
562
|
"order-products",
|
|
464
563
|
"returns",
|
|
465
564
|
"return-products",
|
|
466
565
|
"transactions",
|
|
467
|
-
"
|
|
468
|
-
"
|
|
469
|
-
"
|
|
470
|
-
"playlist-images",
|
|
471
|
-
"musics",
|
|
566
|
+
"documents",
|
|
567
|
+
"document-categories",
|
|
568
|
+
"document-images",
|
|
472
569
|
"posts",
|
|
473
570
|
"post-categories",
|
|
474
571
|
"post-tags",
|
|
475
572
|
"post-images",
|
|
476
|
-
"
|
|
477
|
-
"
|
|
478
|
-
"
|
|
479
|
-
"entity-categories",
|
|
480
|
-
"entity-tags",
|
|
481
|
-
"entity-images",
|
|
482
|
-
"nodes",
|
|
573
|
+
"playlists",
|
|
574
|
+
"playlist-images",
|
|
575
|
+
"musics",
|
|
483
576
|
"galleries",
|
|
484
577
|
"gallery-images",
|
|
485
|
-
"forms"
|
|
578
|
+
"forms",
|
|
579
|
+
"form-submissions",
|
|
580
|
+
"media"
|
|
486
581
|
];
|
|
487
582
|
|
|
488
583
|
// src/core/query/get-query-client.ts
|
|
@@ -514,137 +609,183 @@ function getQueryClient() {
|
|
|
514
609
|
|
|
515
610
|
// src/core/query/UnifiedQuery.ts
|
|
516
611
|
import {
|
|
517
|
-
useQuery,
|
|
518
|
-
|
|
519
|
-
|
|
612
|
+
useQuery as useQueryOriginal,
|
|
613
|
+
useSuspenseQuery as useSuspenseQueryOriginal,
|
|
614
|
+
useInfiniteQuery as useInfiniteQueryOriginal,
|
|
615
|
+
useSuspenseInfiniteQuery as useSuspenseInfiniteQueryOriginal
|
|
520
616
|
} from "@tanstack/react-query";
|
|
617
|
+
function collectionKeys(collection) {
|
|
618
|
+
return {
|
|
619
|
+
all: [collection],
|
|
620
|
+
lists: () => [collection, "list"],
|
|
621
|
+
list: (options) => [collection, "list", options],
|
|
622
|
+
details: () => [collection, "detail"],
|
|
623
|
+
detail: (id, options) => [collection, "detail", id, options],
|
|
624
|
+
infinites: () => [collection, "infinite"],
|
|
625
|
+
infinite: (options) => [collection, "infinite", options]
|
|
626
|
+
};
|
|
627
|
+
}
|
|
521
628
|
var DEFAULT_PAGE_SIZE = 20;
|
|
522
629
|
var UnifiedQueryClient = class {
|
|
523
630
|
constructor(queryClient, options) {
|
|
524
631
|
this.queryClient = queryClient;
|
|
525
|
-
this.collectionsApi = new CollectionsApi(
|
|
526
|
-
(options == null ? void 0 : options.brandKey) || "",
|
|
527
|
-
options == null ? void 0 : options.brandSecret
|
|
528
|
-
);
|
|
632
|
+
this.collectionsApi = new CollectionsApi((options == null ? void 0 : options.clientKey) || "", void 0, options == null ? void 0 : options.baseUrl);
|
|
529
633
|
}
|
|
530
|
-
// =====
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
634
|
+
// ===== useQuery =====
|
|
635
|
+
useQuery(params, options) {
|
|
636
|
+
const { collection, options: queryOptions } = params;
|
|
637
|
+
return useQueryOriginal(__spreadValues({
|
|
638
|
+
queryKey: collectionKeys(collection).list(queryOptions),
|
|
534
639
|
queryFn: () => __async(this, null, function* () {
|
|
640
|
+
var _a;
|
|
535
641
|
const response = yield this.collectionsApi.from(collection).find(queryOptions);
|
|
536
|
-
return response.data;
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
});
|
|
642
|
+
return (_a = response.data) != null ? _a : [];
|
|
643
|
+
})
|
|
644
|
+
}, options));
|
|
540
645
|
}
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
646
|
+
// ===== useSuspenseQuery =====
|
|
647
|
+
useSuspenseQuery(params, options) {
|
|
648
|
+
const { collection, options: queryOptions } = params;
|
|
649
|
+
return useSuspenseQueryOriginal(__spreadValues({
|
|
650
|
+
queryKey: collectionKeys(collection).list(queryOptions),
|
|
544
651
|
queryFn: () => __async(this, null, function* () {
|
|
545
|
-
var _a
|
|
652
|
+
var _a;
|
|
546
653
|
const response = yield this.collectionsApi.from(collection).find(queryOptions);
|
|
547
|
-
return (
|
|
548
|
-
})
|
|
549
|
-
|
|
550
|
-
|
|
654
|
+
return (_a = response.data) != null ? _a : [];
|
|
655
|
+
})
|
|
656
|
+
}, options));
|
|
657
|
+
}
|
|
658
|
+
// ===== useQueryById =====
|
|
659
|
+
useQueryById(params, options) {
|
|
660
|
+
const { collection, id, options: queryOptions } = params;
|
|
661
|
+
return useQueryOriginal(__spreadValues({
|
|
662
|
+
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
663
|
+
queryFn: () => __async(this, null, function* () {
|
|
664
|
+
var _a;
|
|
665
|
+
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
666
|
+
return (_a = response.data) != null ? _a : null;
|
|
667
|
+
})
|
|
668
|
+
}, options));
|
|
551
669
|
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
670
|
+
// ===== useSuspenseQueryById =====
|
|
671
|
+
useSuspenseQueryById(params, options) {
|
|
672
|
+
const { collection, id, options: queryOptions } = params;
|
|
673
|
+
return useSuspenseQueryOriginal(__spreadValues({
|
|
674
|
+
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
675
|
+
queryFn: () => __async(this, null, function* () {
|
|
676
|
+
var _a;
|
|
677
|
+
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
678
|
+
return (_a = response.data) != null ? _a : null;
|
|
679
|
+
})
|
|
680
|
+
}, options));
|
|
681
|
+
}
|
|
682
|
+
// ===== useInfiniteQuery =====
|
|
683
|
+
useInfiniteQuery(params, options) {
|
|
684
|
+
const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
|
|
685
|
+
return useInfiniteQueryOriginal(__spreadValues({
|
|
686
|
+
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
687
|
+
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
557
688
|
var _a;
|
|
558
689
|
const response = yield this.collectionsApi.from(collection).find(__spreadProps(__spreadValues({}, queryOptions), { page: pageParam, limit: pageSize }));
|
|
559
690
|
return (_a = response.data) != null ? _a : [];
|
|
560
691
|
}),
|
|
561
692
|
initialPageParam: 1,
|
|
562
|
-
getNextPageParam: (lastPage,
|
|
563
|
-
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return
|
|
564
|
-
return
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
placeholderData: (reactQueryOptions == null ? void 0 : reactQueryOptions.keepPreviousData) ? keepPreviousData : void 0
|
|
568
|
-
});
|
|
693
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
|
|
694
|
+
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return void 0;
|
|
695
|
+
return lastPageParam + 1;
|
|
696
|
+
}
|
|
697
|
+
}, options));
|
|
569
698
|
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
699
|
+
// ===== useSuspenseInfiniteQuery =====
|
|
700
|
+
useSuspenseInfiniteQuery(params, options) {
|
|
701
|
+
const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
|
|
702
|
+
return useSuspenseInfiniteQueryOriginal(__spreadValues({
|
|
703
|
+
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
704
|
+
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
574
705
|
var _a;
|
|
575
|
-
const response = yield this.collectionsApi.from(collection).
|
|
576
|
-
return (_a = response.data) != null ? _a :
|
|
706
|
+
const response = yield this.collectionsApi.from(collection).find(__spreadProps(__spreadValues({}, queryOptions), { page: pageParam, limit: pageSize }));
|
|
707
|
+
return (_a = response.data) != null ? _a : [];
|
|
577
708
|
}),
|
|
578
|
-
|
|
579
|
-
|
|
709
|
+
initialPageParam: 1,
|
|
710
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
|
|
711
|
+
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return void 0;
|
|
712
|
+
return lastPageParam + 1;
|
|
713
|
+
}
|
|
714
|
+
}, options));
|
|
580
715
|
}
|
|
581
|
-
// =====
|
|
582
|
-
|
|
716
|
+
// ===== prefetchQuery =====
|
|
717
|
+
prefetchQuery(params, options) {
|
|
583
718
|
return __async(this, null, function* () {
|
|
584
|
-
|
|
585
|
-
|
|
719
|
+
const { collection, options: queryOptions } = params;
|
|
720
|
+
return this.queryClient.prefetchQuery(__spreadValues({
|
|
721
|
+
queryKey: collectionKeys(collection).list(queryOptions),
|
|
586
722
|
queryFn: () => __async(this, null, function* () {
|
|
723
|
+
var _a;
|
|
587
724
|
const response = yield this.collectionsApi.from(collection).find(queryOptions);
|
|
588
|
-
return response.data;
|
|
725
|
+
return (_a = response.data) != null ? _a : [];
|
|
589
726
|
})
|
|
590
|
-
});
|
|
727
|
+
}, options));
|
|
591
728
|
});
|
|
592
729
|
}
|
|
593
|
-
|
|
730
|
+
// ===== prefetchQueryById =====
|
|
731
|
+
prefetchQueryById(params, options) {
|
|
594
732
|
return __async(this, null, function* () {
|
|
595
|
-
|
|
596
|
-
|
|
733
|
+
const { collection, id, options: queryOptions } = params;
|
|
734
|
+
return this.queryClient.prefetchQuery(__spreadValues({
|
|
735
|
+
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
597
736
|
queryFn: () => __async(this, null, function* () {
|
|
598
|
-
var _a
|
|
599
|
-
const response = yield this.collectionsApi.from(collection).
|
|
600
|
-
return (
|
|
737
|
+
var _a;
|
|
738
|
+
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
739
|
+
return (_a = response.data) != null ? _a : null;
|
|
601
740
|
})
|
|
602
|
-
});
|
|
741
|
+
}, options));
|
|
603
742
|
});
|
|
604
743
|
}
|
|
605
|
-
|
|
744
|
+
// ===== prefetchInfiniteQuery =====
|
|
745
|
+
prefetchInfiniteQuery(params, options) {
|
|
606
746
|
return __async(this, null, function* () {
|
|
607
|
-
|
|
747
|
+
var _a;
|
|
748
|
+
const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
|
|
608
749
|
return this.queryClient.prefetchInfiniteQuery({
|
|
609
|
-
queryKey:
|
|
610
|
-
queryFn: (_0) => __async(this, [_0], function* ({ pageParam
|
|
611
|
-
var
|
|
750
|
+
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
751
|
+
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
752
|
+
var _a2;
|
|
612
753
|
const response = yield this.collectionsApi.from(collection).find(__spreadProps(__spreadValues({}, queryOptions), { page: pageParam, limit: pageSize }));
|
|
613
|
-
return (
|
|
754
|
+
return (_a2 = response.data) != null ? _a2 : [];
|
|
614
755
|
}),
|
|
615
756
|
initialPageParam: 1,
|
|
616
|
-
getNextPageParam: (lastPage, _allPages,
|
|
617
|
-
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return
|
|
618
|
-
return
|
|
757
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
|
|
758
|
+
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return void 0;
|
|
759
|
+
return lastPageParam + 1;
|
|
619
760
|
},
|
|
620
|
-
pages:
|
|
621
|
-
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
prefetchById(collection, id, queryOptions) {
|
|
625
|
-
return __async(this, null, function* () {
|
|
626
|
-
return this.queryClient.prefetchQuery({
|
|
627
|
-
queryKey: [collection, "detail", id],
|
|
628
|
-
queryFn: () => __async(this, null, function* () {
|
|
629
|
-
var _a;
|
|
630
|
-
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
631
|
-
return (_a = response.data) != null ? _a : null;
|
|
632
|
-
})
|
|
761
|
+
pages: (_a = options == null ? void 0 : options.pages) != null ? _a : 1,
|
|
762
|
+
staleTime: options == null ? void 0 : options.staleTime
|
|
633
763
|
});
|
|
634
764
|
});
|
|
635
765
|
}
|
|
636
|
-
// ===== Cache
|
|
637
|
-
invalidateQueries(collection,
|
|
638
|
-
const queryKey =
|
|
766
|
+
// ===== Cache Utilities =====
|
|
767
|
+
invalidateQueries(collection, type) {
|
|
768
|
+
const queryKey = type ? [collection, type] : [collection];
|
|
639
769
|
return this.queryClient.invalidateQueries({ queryKey });
|
|
640
770
|
}
|
|
641
|
-
getQueryData(collection,
|
|
642
|
-
|
|
643
|
-
|
|
771
|
+
getQueryData(collection, type, idOrOptions, options) {
|
|
772
|
+
if (type === "list") {
|
|
773
|
+
return this.queryClient.getQueryData(collectionKeys(collection).list(idOrOptions));
|
|
774
|
+
}
|
|
775
|
+
return this.queryClient.getQueryData(collectionKeys(collection).detail(idOrOptions, options));
|
|
644
776
|
}
|
|
645
|
-
setQueryData(collection,
|
|
646
|
-
|
|
647
|
-
|
|
777
|
+
setQueryData(collection, type, dataOrId, dataOrOptions, options) {
|
|
778
|
+
if (type === "list") {
|
|
779
|
+
this.queryClient.setQueryData(
|
|
780
|
+
collectionKeys(collection).list(dataOrOptions),
|
|
781
|
+
dataOrId
|
|
782
|
+
);
|
|
783
|
+
} else {
|
|
784
|
+
this.queryClient.setQueryData(
|
|
785
|
+
collectionKeys(collection).detail(dataOrId, options),
|
|
786
|
+
dataOrOptions
|
|
787
|
+
);
|
|
788
|
+
}
|
|
648
789
|
}
|
|
649
790
|
};
|
|
650
791
|
|
|
@@ -656,6 +797,7 @@ var BrowserClient = class {
|
|
|
656
797
|
throw new Error("clientKey is required.");
|
|
657
798
|
}
|
|
658
799
|
this.config = __spreadValues({}, options);
|
|
800
|
+
this.baseUrl = resolveApiUrl(options);
|
|
659
801
|
const metadata = {
|
|
660
802
|
timestamp: Date.now(),
|
|
661
803
|
userAgent: typeof window !== "undefined" ? (_a = window.navigator) == null ? void 0 : _a.userAgent : "Node.js"
|
|
@@ -663,9 +805,10 @@ var BrowserClient = class {
|
|
|
663
805
|
this.state = { metadata };
|
|
664
806
|
this.queryClient = getQueryClient();
|
|
665
807
|
this.query = new UnifiedQueryClient(this.queryClient, {
|
|
666
|
-
|
|
808
|
+
clientKey: this.config.clientKey,
|
|
809
|
+
baseUrl: this.baseUrl
|
|
667
810
|
});
|
|
668
|
-
this.collections = new CollectionsApi(this.config.clientKey);
|
|
811
|
+
this.collections = new CollectionsApi(this.config.clientKey, void 0, this.baseUrl);
|
|
669
812
|
}
|
|
670
813
|
from(collection) {
|
|
671
814
|
return this.collections.from(collection);
|
|
@@ -735,6 +878,7 @@ var ServerClient = class {
|
|
|
735
878
|
throw new Error("secretKey is required.");
|
|
736
879
|
}
|
|
737
880
|
this.config = __spreadValues({}, options);
|
|
881
|
+
this.baseUrl = resolveApiUrl(options);
|
|
738
882
|
const metadata = {
|
|
739
883
|
timestamp: Date.now(),
|
|
740
884
|
userAgent: typeof window !== "undefined" ? (_a = window.navigator) == null ? void 0 : _a.userAgent : "Node.js"
|
|
@@ -742,11 +886,13 @@ var ServerClient = class {
|
|
|
742
886
|
this.state = { metadata };
|
|
743
887
|
this.api = new ApiClient({
|
|
744
888
|
clientKey: this.config.clientKey,
|
|
745
|
-
secretKey: this.config.secretKey
|
|
889
|
+
secretKey: this.config.secretKey,
|
|
890
|
+
baseUrl: this.baseUrl
|
|
746
891
|
});
|
|
747
892
|
this.collections = new CollectionsApi(
|
|
748
893
|
this.config.clientKey,
|
|
749
|
-
this.config.secretKey
|
|
894
|
+
this.config.secretKey,
|
|
895
|
+
this.baseUrl
|
|
750
896
|
);
|
|
751
897
|
}
|
|
752
898
|
from(collection) {
|
|
@@ -856,14 +1002,6 @@ function RichTextContent({
|
|
|
856
1002
|
}
|
|
857
1003
|
);
|
|
858
1004
|
}
|
|
859
|
-
|
|
860
|
-
// src/core/client/types.ts
|
|
861
|
-
function isSuccessResponse(response) {
|
|
862
|
-
return response.success === true;
|
|
863
|
-
}
|
|
864
|
-
function isErrorResponse(response) {
|
|
865
|
-
return response.success === false;
|
|
866
|
-
}
|
|
867
1005
|
export {
|
|
868
1006
|
ApiClient,
|
|
869
1007
|
ApiError,
|
|
@@ -878,9 +1016,13 @@ export {
|
|
|
878
1016
|
TimeoutError,
|
|
879
1017
|
UnifiedQueryClient,
|
|
880
1018
|
ValidationError,
|
|
1019
|
+
collectionKeys,
|
|
1020
|
+
createApiKey,
|
|
881
1021
|
createBrowserClient,
|
|
882
1022
|
createServerClient,
|
|
1023
|
+
createServerToken,
|
|
883
1024
|
createTypedWebhookHandler,
|
|
1025
|
+
decodeServerToken,
|
|
884
1026
|
formatOrderName,
|
|
885
1027
|
generateOrderNumber,
|
|
886
1028
|
getQueryClient,
|
|
@@ -894,6 +1036,8 @@ export {
|
|
|
894
1036
|
isTimeoutError,
|
|
895
1037
|
isValidWebhookEvent,
|
|
896
1038
|
isValidationError,
|
|
897
|
-
objectFor
|
|
1039
|
+
objectFor,
|
|
1040
|
+
parseApiKey,
|
|
1041
|
+
verifyServerToken
|
|
898
1042
|
};
|
|
899
1043
|
//# sourceMappingURL=index.js.map
|