@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/README.md
CHANGED
|
@@ -43,12 +43,13 @@ const { data: products } = await client.from('products').find({
|
|
|
43
43
|
|
|
44
44
|
// React Query 훅 사용
|
|
45
45
|
function ProductList() {
|
|
46
|
-
const { data, isLoading } = client.query.
|
|
47
|
-
|
|
46
|
+
const { data, isLoading } = client.query.useQuery({
|
|
47
|
+
collection: 'products',
|
|
48
|
+
options: { limit: 10 }
|
|
48
49
|
})
|
|
49
50
|
|
|
50
51
|
if (isLoading) return <div>Loading...</div>
|
|
51
|
-
return <div>{data?.
|
|
52
|
+
return <div>{data?.map(p => p.name)}</div>
|
|
52
53
|
}
|
|
53
54
|
```
|
|
54
55
|
|
|
@@ -104,7 +105,7 @@ const client = createBrowserClient({
|
|
|
104
105
|
|
|
105
106
|
**주요 속성:**
|
|
106
107
|
|
|
107
|
-
- `query`: React Query 훅 (`
|
|
108
|
+
- `query`: React Query 훅 (`useQuery`, `useSuspenseQuery`, `useQueryById`, `useInfiniteQuery`)
|
|
108
109
|
- `collections`: 컬렉션 API 클라이언트
|
|
109
110
|
- `from()`: Supabase 스타일 쿼리 빌더
|
|
110
111
|
|
|
@@ -165,23 +166,31 @@ await client.from('products').remove('product_id')
|
|
|
165
166
|
|
|
166
167
|
```typescript
|
|
167
168
|
// 컬렉션 목록 조회
|
|
168
|
-
const { data, isLoading, error } = client.query.
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
const { data, isLoading, error, refetch } = client.query.useQuery({
|
|
170
|
+
collection: 'products',
|
|
171
|
+
options: {
|
|
172
|
+
limit: 10,
|
|
173
|
+
where: { status: { equals: 'published' } },
|
|
174
|
+
},
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// Suspense 모드 (서버 컴포넌트에서 사용)
|
|
178
|
+
const { data } = client.query.useSuspenseQuery({
|
|
179
|
+
collection: 'products',
|
|
180
|
+
options: { limit: 10 },
|
|
171
181
|
})
|
|
172
182
|
|
|
173
|
-
// 단일 항목 조회
|
|
174
|
-
const { data: product } = client.query.
|
|
175
|
-
|
|
183
|
+
// 단일 항목 조회 (ID 기반)
|
|
184
|
+
const { data: product } = client.query.useQueryById({
|
|
185
|
+
collection: 'products',
|
|
186
|
+
id: 'product_id',
|
|
176
187
|
})
|
|
177
188
|
|
|
178
189
|
// 무한 스크롤
|
|
179
|
-
const { data, fetchNextPage, hasNextPage } = client.query.
|
|
180
|
-
'products',
|
|
181
|
-
{
|
|
182
|
-
|
|
183
|
-
},
|
|
184
|
-
)
|
|
190
|
+
const { data, fetchNextPage, hasNextPage } = client.query.useInfiniteQuery({
|
|
191
|
+
collection: 'products',
|
|
192
|
+
options: { limit: 20 },
|
|
193
|
+
})
|
|
185
194
|
```
|
|
186
195
|
|
|
187
196
|
### 4. Webhook 처리
|
|
@@ -399,16 +408,15 @@ const { data } = await client.from('products').find({
|
|
|
399
408
|
### React Query 옵션
|
|
400
409
|
|
|
401
410
|
```typescript
|
|
402
|
-
const { data } = client.query.
|
|
403
|
-
'products',
|
|
411
|
+
const { data } = client.query.useQuery(
|
|
404
412
|
{
|
|
405
|
-
|
|
413
|
+
collection: 'products',
|
|
414
|
+
options: { limit: 10 },
|
|
406
415
|
},
|
|
407
416
|
{
|
|
408
417
|
staleTime: 5 * 60 * 1000, // 5분
|
|
409
|
-
|
|
418
|
+
gcTime: 10 * 60 * 1000, // 10분 (React Query v5에서 cacheTime → gcTime)
|
|
410
419
|
refetchOnWindowFocus: false,
|
|
411
|
-
keepPreviousData: true,
|
|
412
420
|
},
|
|
413
421
|
)
|
|
414
422
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -93,9 +93,13 @@ __export(index_exports, {
|
|
|
93
93
|
TimeoutError: () => TimeoutError,
|
|
94
94
|
UnifiedQueryClient: () => UnifiedQueryClient,
|
|
95
95
|
ValidationError: () => ValidationError,
|
|
96
|
+
collectionKeys: () => collectionKeys,
|
|
97
|
+
createApiKey: () => createApiKey,
|
|
96
98
|
createBrowserClient: () => createBrowserClient,
|
|
97
99
|
createServerClient: () => createServerClient,
|
|
100
|
+
createServerToken: () => createServerToken,
|
|
98
101
|
createTypedWebhookHandler: () => createTypedWebhookHandler,
|
|
102
|
+
decodeServerToken: () => decodeServerToken,
|
|
99
103
|
formatOrderName: () => formatOrderName,
|
|
100
104
|
generateOrderNumber: () => generateOrderNumber,
|
|
101
105
|
getQueryClient: () => getQueryClient,
|
|
@@ -109,7 +113,9 @@ __export(index_exports, {
|
|
|
109
113
|
isTimeoutError: () => isTimeoutError,
|
|
110
114
|
isValidWebhookEvent: () => isValidWebhookEvent,
|
|
111
115
|
isValidationError: () => isValidationError,
|
|
112
|
-
objectFor: () => objectFor
|
|
116
|
+
objectFor: () => objectFor,
|
|
117
|
+
parseApiKey: () => parseApiKey,
|
|
118
|
+
verifyServerToken: () => verifyServerToken
|
|
113
119
|
});
|
|
114
120
|
module.exports = __toCommonJS(index_exports);
|
|
115
121
|
|
|
@@ -247,19 +253,112 @@ var createNetworkError = (message, status, details, userMessage, suggestion) =>
|
|
|
247
253
|
var createValidationError = (message, details, userMessage, suggestion) => new ValidationError(message, details, userMessage, suggestion);
|
|
248
254
|
var createApiError = (message, status, details, userMessage, suggestion) => new ApiError(message, status, details, userMessage, suggestion);
|
|
249
255
|
|
|
256
|
+
// src/core/client/types.ts
|
|
257
|
+
var API_URLS = {
|
|
258
|
+
local: "http://localhost:3000",
|
|
259
|
+
development: "https://dev.01.software",
|
|
260
|
+
staging: "https://stg.01.software",
|
|
261
|
+
production: "https://api.01.software"
|
|
262
|
+
};
|
|
263
|
+
function resolveApiUrl(config) {
|
|
264
|
+
if (config == null ? void 0 : config.baseUrl) {
|
|
265
|
+
return config.baseUrl.replace(/\/$/, "");
|
|
266
|
+
}
|
|
267
|
+
const envUrl = process.env.SOFTWARE_API_URL || process.env.NEXT_PUBLIC_SOFTWARE_API_URL;
|
|
268
|
+
if (envUrl) {
|
|
269
|
+
return envUrl.replace(/\/$/, "");
|
|
270
|
+
}
|
|
271
|
+
if (config == null ? void 0 : config.environment) {
|
|
272
|
+
return API_URLS[config.environment];
|
|
273
|
+
}
|
|
274
|
+
return API_URLS.production;
|
|
275
|
+
}
|
|
276
|
+
function isSuccessResponse(response) {
|
|
277
|
+
return response.success === true;
|
|
278
|
+
}
|
|
279
|
+
function isErrorResponse(response) {
|
|
280
|
+
return response.success === false;
|
|
281
|
+
}
|
|
282
|
+
|
|
250
283
|
// src/core/internal/utils/index.ts
|
|
251
|
-
var API_URL = process.env.SOFTWARE_API_URL || "https://stg.01.software";
|
|
252
284
|
var DEFAULT_TIMEOUT = 3e4;
|
|
253
285
|
var DEFAULT_RETRYABLE_STATUSES = [408, 429, 500, 502, 503, 504];
|
|
254
|
-
function createServerToken(clientKey, secretKey) {
|
|
286
|
+
function createServerToken(clientKey, secretKey, expiresIn = "1h") {
|
|
255
287
|
return __async(this, null, function* () {
|
|
256
288
|
if (!clientKey || !secretKey) {
|
|
257
289
|
throw new Error("clientKey\uC640 secretKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
258
290
|
}
|
|
259
291
|
const secret = new TextEncoder().encode(secretKey);
|
|
260
|
-
return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(
|
|
292
|
+
return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
function verifyServerToken(token, secretKey) {
|
|
296
|
+
return __async(this, null, function* () {
|
|
297
|
+
if (!token || !secretKey) {
|
|
298
|
+
throw new Error("token\uACFC secretKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
299
|
+
}
|
|
300
|
+
const secret = new TextEncoder().encode(secretKey);
|
|
301
|
+
const { payload } = yield (0, import_jose.jwtVerify)(token, secret, {
|
|
302
|
+
algorithms: ["HS256"]
|
|
303
|
+
});
|
|
304
|
+
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
305
|
+
throw new Error("Invalid token payload: clientKey is missing");
|
|
306
|
+
}
|
|
307
|
+
return {
|
|
308
|
+
clientKey: payload.clientKey,
|
|
309
|
+
iat: payload.iat,
|
|
310
|
+
exp: payload.exp
|
|
311
|
+
};
|
|
261
312
|
});
|
|
262
313
|
}
|
|
314
|
+
function decodeServerToken(token) {
|
|
315
|
+
if (!token) {
|
|
316
|
+
throw new Error("token\uC740 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
317
|
+
}
|
|
318
|
+
const payload = (0, import_jose.decodeJwt)(token);
|
|
319
|
+
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
320
|
+
throw new Error("Invalid token payload: clientKey is missing");
|
|
321
|
+
}
|
|
322
|
+
return {
|
|
323
|
+
clientKey: payload.clientKey,
|
|
324
|
+
iat: payload.iat,
|
|
325
|
+
exp: payload.exp
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function createApiKey(clientKey, secretKey) {
|
|
329
|
+
if (!clientKey || !secretKey) {
|
|
330
|
+
throw new Error("clientKey\uC640 secretKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
331
|
+
}
|
|
332
|
+
if (typeof Buffer !== "undefined") {
|
|
333
|
+
return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
|
|
334
|
+
}
|
|
335
|
+
return btoa(`${clientKey}:${secretKey}`);
|
|
336
|
+
}
|
|
337
|
+
function parseApiKey(apiKey) {
|
|
338
|
+
if (!apiKey) {
|
|
339
|
+
throw new Error("apiKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
340
|
+
}
|
|
341
|
+
try {
|
|
342
|
+
let decoded;
|
|
343
|
+
if (typeof Buffer !== "undefined") {
|
|
344
|
+
decoded = Buffer.from(apiKey, "base64").toString("utf-8");
|
|
345
|
+
} else {
|
|
346
|
+
decoded = atob(apiKey);
|
|
347
|
+
}
|
|
348
|
+
const colonIndex = decoded.indexOf(":");
|
|
349
|
+
if (colonIndex === -1) {
|
|
350
|
+
throw new Error("Invalid format");
|
|
351
|
+
}
|
|
352
|
+
const clientKey = decoded.substring(0, colonIndex);
|
|
353
|
+
const secretKey = decoded.substring(colonIndex + 1);
|
|
354
|
+
if (!clientKey || !secretKey) {
|
|
355
|
+
throw new Error("Invalid format");
|
|
356
|
+
}
|
|
357
|
+
return { clientKey, secretKey };
|
|
358
|
+
} catch (e) {
|
|
359
|
+
throw new Error('Invalid API key. Expected Base64 encoded "clientKey:secretKey"');
|
|
360
|
+
}
|
|
361
|
+
}
|
|
263
362
|
function debugLog(debug, type, message, data) {
|
|
264
363
|
if (!debug) return;
|
|
265
364
|
const shouldLog = debug === true || type === "request" && debug.logRequests || type === "response" && debug.logResponses || type === "error" && debug.logErrors;
|
|
@@ -288,7 +387,7 @@ function _fetch(url, options) {
|
|
|
288
387
|
clientKey,
|
|
289
388
|
secretKey,
|
|
290
389
|
timeout = DEFAULT_TIMEOUT,
|
|
291
|
-
baseUrl =
|
|
390
|
+
baseUrl = API_URLS.production,
|
|
292
391
|
debug,
|
|
293
392
|
retry
|
|
294
393
|
} = _a, requestInit = __objRest(_a, [
|
|
@@ -413,13 +512,14 @@ function _fetch(url, options) {
|
|
|
413
512
|
|
|
414
513
|
// src/core/collection/base.ts
|
|
415
514
|
var BaseApiClient = class {
|
|
416
|
-
constructor(clientKey, secretKey) {
|
|
515
|
+
constructor(clientKey, secretKey, baseUrl) {
|
|
417
516
|
if (!clientKey) {
|
|
418
517
|
throw createValidationError("clientKey\uB294 \uD544\uC218\uC785\uB2C8\uB2E4.");
|
|
419
518
|
}
|
|
420
519
|
this.clientKey = clientKey;
|
|
421
520
|
this.secretKey = secretKey;
|
|
422
|
-
this.
|
|
521
|
+
this.baseUrl = baseUrl;
|
|
522
|
+
this.defaultOptions = { clientKey, secretKey, baseUrl };
|
|
423
523
|
}
|
|
424
524
|
get(endpoint, options) {
|
|
425
525
|
return __async(this, null, function* () {
|
|
@@ -492,8 +592,8 @@ var BaseApiClient = class {
|
|
|
492
592
|
|
|
493
593
|
// src/core/collection/collections-api.ts
|
|
494
594
|
var CollectionsApi = class extends BaseApiClient {
|
|
495
|
-
constructor(clientKey, secretKey) {
|
|
496
|
-
super(clientKey, secretKey);
|
|
595
|
+
constructor(clientKey, secretKey, baseUrl) {
|
|
596
|
+
super(clientKey, secretKey, baseUrl);
|
|
497
597
|
}
|
|
498
598
|
from(collection) {
|
|
499
599
|
return new CollectionQueryBuilder(this, collection);
|
|
@@ -515,36 +615,37 @@ var CollectionsApi = class extends BaseApiClient {
|
|
|
515
615
|
// src/core/collection/const.ts
|
|
516
616
|
var COLLECTIONS = [
|
|
517
617
|
"tenants",
|
|
618
|
+
"tenant-metadata",
|
|
619
|
+
"tenant-logos",
|
|
620
|
+
"tenant-og-images",
|
|
518
621
|
"products",
|
|
519
622
|
"product-variants",
|
|
520
623
|
"product-options",
|
|
521
624
|
"product-categories",
|
|
522
625
|
"product-tags",
|
|
523
626
|
"product-images",
|
|
627
|
+
"brands",
|
|
628
|
+
"brand-logos",
|
|
524
629
|
"orders",
|
|
525
630
|
"order-products",
|
|
526
631
|
"returns",
|
|
527
632
|
"return-products",
|
|
528
633
|
"transactions",
|
|
529
|
-
"
|
|
530
|
-
"
|
|
531
|
-
"
|
|
532
|
-
"playlist-images",
|
|
533
|
-
"musics",
|
|
634
|
+
"documents",
|
|
635
|
+
"document-categories",
|
|
636
|
+
"document-images",
|
|
534
637
|
"posts",
|
|
535
638
|
"post-categories",
|
|
536
639
|
"post-tags",
|
|
537
640
|
"post-images",
|
|
538
|
-
"
|
|
539
|
-
"
|
|
540
|
-
"
|
|
541
|
-
"entity-categories",
|
|
542
|
-
"entity-tags",
|
|
543
|
-
"entity-images",
|
|
544
|
-
"nodes",
|
|
641
|
+
"playlists",
|
|
642
|
+
"playlist-images",
|
|
643
|
+
"musics",
|
|
545
644
|
"galleries",
|
|
546
645
|
"gallery-images",
|
|
547
|
-
"forms"
|
|
646
|
+
"forms",
|
|
647
|
+
"form-submissions",
|
|
648
|
+
"media"
|
|
548
649
|
];
|
|
549
650
|
|
|
550
651
|
// src/core/query/get-query-client.ts
|
|
@@ -576,133 +677,178 @@ function getQueryClient() {
|
|
|
576
677
|
|
|
577
678
|
// src/core/query/UnifiedQuery.ts
|
|
578
679
|
var import_react_query2 = require("@tanstack/react-query");
|
|
680
|
+
function collectionKeys(collection) {
|
|
681
|
+
return {
|
|
682
|
+
all: [collection],
|
|
683
|
+
lists: () => [collection, "list"],
|
|
684
|
+
list: (options) => [collection, "list", options],
|
|
685
|
+
details: () => [collection, "detail"],
|
|
686
|
+
detail: (id, options) => [collection, "detail", id, options],
|
|
687
|
+
infinites: () => [collection, "infinite"],
|
|
688
|
+
infinite: (options) => [collection, "infinite", options]
|
|
689
|
+
};
|
|
690
|
+
}
|
|
579
691
|
var DEFAULT_PAGE_SIZE = 20;
|
|
580
692
|
var UnifiedQueryClient = class {
|
|
581
693
|
constructor(queryClient, options) {
|
|
582
694
|
this.queryClient = queryClient;
|
|
583
|
-
this.collectionsApi = new CollectionsApi(
|
|
584
|
-
(options == null ? void 0 : options.brandKey) || "",
|
|
585
|
-
options == null ? void 0 : options.brandSecret
|
|
586
|
-
);
|
|
695
|
+
this.collectionsApi = new CollectionsApi((options == null ? void 0 : options.clientKey) || "", void 0, options == null ? void 0 : options.baseUrl);
|
|
587
696
|
}
|
|
588
|
-
// =====
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
697
|
+
// ===== useQuery =====
|
|
698
|
+
useQuery(params, options) {
|
|
699
|
+
const { collection, options: queryOptions } = params;
|
|
700
|
+
return (0, import_react_query2.useQuery)(__spreadValues({
|
|
701
|
+
queryKey: collectionKeys(collection).list(queryOptions),
|
|
592
702
|
queryFn: () => __async(this, null, function* () {
|
|
703
|
+
var _a;
|
|
593
704
|
const response = yield this.collectionsApi.from(collection).find(queryOptions);
|
|
594
|
-
return response.data;
|
|
595
|
-
})
|
|
596
|
-
|
|
597
|
-
});
|
|
705
|
+
return (_a = response.data) != null ? _a : [];
|
|
706
|
+
})
|
|
707
|
+
}, options));
|
|
598
708
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
709
|
+
// ===== useSuspenseQuery =====
|
|
710
|
+
useSuspenseQuery(params, options) {
|
|
711
|
+
const { collection, options: queryOptions } = params;
|
|
712
|
+
return (0, import_react_query2.useSuspenseQuery)(__spreadValues({
|
|
713
|
+
queryKey: collectionKeys(collection).list(queryOptions),
|
|
602
714
|
queryFn: () => __async(this, null, function* () {
|
|
603
|
-
var _a
|
|
715
|
+
var _a;
|
|
604
716
|
const response = yield this.collectionsApi.from(collection).find(queryOptions);
|
|
605
|
-
return (
|
|
606
|
-
})
|
|
607
|
-
|
|
608
|
-
|
|
717
|
+
return (_a = response.data) != null ? _a : [];
|
|
718
|
+
})
|
|
719
|
+
}, options));
|
|
720
|
+
}
|
|
721
|
+
// ===== useQueryById =====
|
|
722
|
+
useQueryById(params, options) {
|
|
723
|
+
const { collection, id, options: queryOptions } = params;
|
|
724
|
+
return (0, import_react_query2.useQuery)(__spreadValues({
|
|
725
|
+
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
726
|
+
queryFn: () => __async(this, null, function* () {
|
|
727
|
+
var _a;
|
|
728
|
+
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
729
|
+
return (_a = response.data) != null ? _a : null;
|
|
730
|
+
})
|
|
731
|
+
}, options));
|
|
609
732
|
}
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
733
|
+
// ===== useSuspenseQueryById =====
|
|
734
|
+
useSuspenseQueryById(params, options) {
|
|
735
|
+
const { collection, id, options: queryOptions } = params;
|
|
736
|
+
return (0, import_react_query2.useSuspenseQuery)(__spreadValues({
|
|
737
|
+
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
738
|
+
queryFn: () => __async(this, null, function* () {
|
|
739
|
+
var _a;
|
|
740
|
+
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
741
|
+
return (_a = response.data) != null ? _a : null;
|
|
742
|
+
})
|
|
743
|
+
}, options));
|
|
744
|
+
}
|
|
745
|
+
// ===== useInfiniteQuery =====
|
|
746
|
+
useInfiniteQuery(params, options) {
|
|
747
|
+
const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
|
|
748
|
+
return (0, import_react_query2.useInfiniteQuery)(__spreadValues({
|
|
749
|
+
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
750
|
+
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
615
751
|
var _a;
|
|
616
752
|
const response = yield this.collectionsApi.from(collection).find(__spreadProps(__spreadValues({}, queryOptions), { page: pageParam, limit: pageSize }));
|
|
617
753
|
return (_a = response.data) != null ? _a : [];
|
|
618
754
|
}),
|
|
619
755
|
initialPageParam: 1,
|
|
620
|
-
getNextPageParam: (lastPage,
|
|
621
|
-
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return
|
|
622
|
-
return
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
placeholderData: (reactQueryOptions == null ? void 0 : reactQueryOptions.keepPreviousData) ? import_react_query2.keepPreviousData : void 0
|
|
626
|
-
});
|
|
756
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
|
|
757
|
+
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return void 0;
|
|
758
|
+
return lastPageParam + 1;
|
|
759
|
+
}
|
|
760
|
+
}, options));
|
|
627
761
|
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
762
|
+
// ===== useSuspenseInfiniteQuery =====
|
|
763
|
+
useSuspenseInfiniteQuery(params, options) {
|
|
764
|
+
const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
|
|
765
|
+
return (0, import_react_query2.useSuspenseInfiniteQuery)(__spreadValues({
|
|
766
|
+
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
767
|
+
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
632
768
|
var _a;
|
|
633
|
-
const response = yield this.collectionsApi.from(collection).
|
|
634
|
-
return (_a = response.data) != null ? _a :
|
|
769
|
+
const response = yield this.collectionsApi.from(collection).find(__spreadProps(__spreadValues({}, queryOptions), { page: pageParam, limit: pageSize }));
|
|
770
|
+
return (_a = response.data) != null ? _a : [];
|
|
635
771
|
}),
|
|
636
|
-
|
|
637
|
-
|
|
772
|
+
initialPageParam: 1,
|
|
773
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
|
|
774
|
+
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return void 0;
|
|
775
|
+
return lastPageParam + 1;
|
|
776
|
+
}
|
|
777
|
+
}, options));
|
|
638
778
|
}
|
|
639
|
-
// =====
|
|
640
|
-
|
|
779
|
+
// ===== prefetchQuery =====
|
|
780
|
+
prefetchQuery(params, options) {
|
|
641
781
|
return __async(this, null, function* () {
|
|
642
|
-
|
|
643
|
-
|
|
782
|
+
const { collection, options: queryOptions } = params;
|
|
783
|
+
return this.queryClient.prefetchQuery(__spreadValues({
|
|
784
|
+
queryKey: collectionKeys(collection).list(queryOptions),
|
|
644
785
|
queryFn: () => __async(this, null, function* () {
|
|
786
|
+
var _a;
|
|
645
787
|
const response = yield this.collectionsApi.from(collection).find(queryOptions);
|
|
646
|
-
return response.data;
|
|
788
|
+
return (_a = response.data) != null ? _a : [];
|
|
647
789
|
})
|
|
648
|
-
});
|
|
790
|
+
}, options));
|
|
649
791
|
});
|
|
650
792
|
}
|
|
651
|
-
|
|
793
|
+
// ===== prefetchQueryById =====
|
|
794
|
+
prefetchQueryById(params, options) {
|
|
652
795
|
return __async(this, null, function* () {
|
|
653
|
-
|
|
654
|
-
|
|
796
|
+
const { collection, id, options: queryOptions } = params;
|
|
797
|
+
return this.queryClient.prefetchQuery(__spreadValues({
|
|
798
|
+
queryKey: collectionKeys(collection).detail(id, queryOptions),
|
|
655
799
|
queryFn: () => __async(this, null, function* () {
|
|
656
|
-
var _a
|
|
657
|
-
const response = yield this.collectionsApi.from(collection).
|
|
658
|
-
return (
|
|
800
|
+
var _a;
|
|
801
|
+
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
802
|
+
return (_a = response.data) != null ? _a : null;
|
|
659
803
|
})
|
|
660
|
-
});
|
|
804
|
+
}, options));
|
|
661
805
|
});
|
|
662
806
|
}
|
|
663
|
-
|
|
807
|
+
// ===== prefetchInfiniteQuery =====
|
|
808
|
+
prefetchInfiniteQuery(params, options) {
|
|
664
809
|
return __async(this, null, function* () {
|
|
665
|
-
|
|
810
|
+
var _a;
|
|
811
|
+
const { collection, options: queryOptions, pageSize = DEFAULT_PAGE_SIZE } = params;
|
|
666
812
|
return this.queryClient.prefetchInfiniteQuery({
|
|
667
|
-
queryKey:
|
|
668
|
-
queryFn: (_0) => __async(this, [_0], function* ({ pageParam
|
|
669
|
-
var
|
|
813
|
+
queryKey: collectionKeys(collection).infinite(queryOptions),
|
|
814
|
+
queryFn: (_0) => __async(this, [_0], function* ({ pageParam }) {
|
|
815
|
+
var _a2;
|
|
670
816
|
const response = yield this.collectionsApi.from(collection).find(__spreadProps(__spreadValues({}, queryOptions), { page: pageParam, limit: pageSize }));
|
|
671
|
-
return (
|
|
817
|
+
return (_a2 = response.data) != null ? _a2 : [];
|
|
672
818
|
}),
|
|
673
819
|
initialPageParam: 1,
|
|
674
|
-
getNextPageParam: (lastPage, _allPages,
|
|
675
|
-
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return
|
|
676
|
-
return
|
|
820
|
+
getNextPageParam: (lastPage, _allPages, lastPageParam) => {
|
|
821
|
+
if (!Array.isArray(lastPage) || lastPage.length < pageSize) return void 0;
|
|
822
|
+
return lastPageParam + 1;
|
|
677
823
|
},
|
|
678
|
-
pages:
|
|
679
|
-
|
|
680
|
-
});
|
|
681
|
-
}
|
|
682
|
-
prefetchById(collection, id, queryOptions) {
|
|
683
|
-
return __async(this, null, function* () {
|
|
684
|
-
return this.queryClient.prefetchQuery({
|
|
685
|
-
queryKey: [collection, "detail", id],
|
|
686
|
-
queryFn: () => __async(this, null, function* () {
|
|
687
|
-
var _a;
|
|
688
|
-
const response = yield this.collectionsApi.from(collection).findById(id, queryOptions);
|
|
689
|
-
return (_a = response.data) != null ? _a : null;
|
|
690
|
-
})
|
|
824
|
+
pages: (_a = options == null ? void 0 : options.pages) != null ? _a : 1,
|
|
825
|
+
staleTime: options == null ? void 0 : options.staleTime
|
|
691
826
|
});
|
|
692
827
|
});
|
|
693
828
|
}
|
|
694
|
-
// ===== Cache
|
|
695
|
-
invalidateQueries(collection,
|
|
696
|
-
const queryKey =
|
|
829
|
+
// ===== Cache Utilities =====
|
|
830
|
+
invalidateQueries(collection, type) {
|
|
831
|
+
const queryKey = type ? [collection, type] : [collection];
|
|
697
832
|
return this.queryClient.invalidateQueries({ queryKey });
|
|
698
833
|
}
|
|
699
|
-
getQueryData(collection,
|
|
700
|
-
|
|
701
|
-
|
|
834
|
+
getQueryData(collection, type, idOrOptions, options) {
|
|
835
|
+
if (type === "list") {
|
|
836
|
+
return this.queryClient.getQueryData(collectionKeys(collection).list(idOrOptions));
|
|
837
|
+
}
|
|
838
|
+
return this.queryClient.getQueryData(collectionKeys(collection).detail(idOrOptions, options));
|
|
702
839
|
}
|
|
703
|
-
setQueryData(collection,
|
|
704
|
-
|
|
705
|
-
|
|
840
|
+
setQueryData(collection, type, dataOrId, dataOrOptions, options) {
|
|
841
|
+
if (type === "list") {
|
|
842
|
+
this.queryClient.setQueryData(
|
|
843
|
+
collectionKeys(collection).list(dataOrOptions),
|
|
844
|
+
dataOrId
|
|
845
|
+
);
|
|
846
|
+
} else {
|
|
847
|
+
this.queryClient.setQueryData(
|
|
848
|
+
collectionKeys(collection).detail(dataOrId, options),
|
|
849
|
+
dataOrOptions
|
|
850
|
+
);
|
|
851
|
+
}
|
|
706
852
|
}
|
|
707
853
|
};
|
|
708
854
|
|
|
@@ -714,6 +860,7 @@ var BrowserClient = class {
|
|
|
714
860
|
throw new Error("clientKey is required.");
|
|
715
861
|
}
|
|
716
862
|
this.config = __spreadValues({}, options);
|
|
863
|
+
this.baseUrl = resolveApiUrl(options);
|
|
717
864
|
const metadata = {
|
|
718
865
|
timestamp: Date.now(),
|
|
719
866
|
userAgent: typeof window !== "undefined" ? (_a = window.navigator) == null ? void 0 : _a.userAgent : "Node.js"
|
|
@@ -721,9 +868,10 @@ var BrowserClient = class {
|
|
|
721
868
|
this.state = { metadata };
|
|
722
869
|
this.queryClient = getQueryClient();
|
|
723
870
|
this.query = new UnifiedQueryClient(this.queryClient, {
|
|
724
|
-
|
|
871
|
+
clientKey: this.config.clientKey,
|
|
872
|
+
baseUrl: this.baseUrl
|
|
725
873
|
});
|
|
726
|
-
this.collections = new CollectionsApi(this.config.clientKey);
|
|
874
|
+
this.collections = new CollectionsApi(this.config.clientKey, void 0, this.baseUrl);
|
|
727
875
|
}
|
|
728
876
|
from(collection) {
|
|
729
877
|
return this.collections.from(collection);
|
|
@@ -793,6 +941,7 @@ var ServerClient = class {
|
|
|
793
941
|
throw new Error("secretKey is required.");
|
|
794
942
|
}
|
|
795
943
|
this.config = __spreadValues({}, options);
|
|
944
|
+
this.baseUrl = resolveApiUrl(options);
|
|
796
945
|
const metadata = {
|
|
797
946
|
timestamp: Date.now(),
|
|
798
947
|
userAgent: typeof window !== "undefined" ? (_a = window.navigator) == null ? void 0 : _a.userAgent : "Node.js"
|
|
@@ -800,11 +949,13 @@ var ServerClient = class {
|
|
|
800
949
|
this.state = { metadata };
|
|
801
950
|
this.api = new ApiClient({
|
|
802
951
|
clientKey: this.config.clientKey,
|
|
803
|
-
secretKey: this.config.secretKey
|
|
952
|
+
secretKey: this.config.secretKey,
|
|
953
|
+
baseUrl: this.baseUrl
|
|
804
954
|
});
|
|
805
955
|
this.collections = new CollectionsApi(
|
|
806
956
|
this.config.clientKey,
|
|
807
|
-
this.config.secretKey
|
|
957
|
+
this.config.secretKey,
|
|
958
|
+
this.baseUrl
|
|
808
959
|
);
|
|
809
960
|
}
|
|
810
961
|
from(collection) {
|
|
@@ -910,12 +1061,4 @@ function RichTextContent({
|
|
|
910
1061
|
}
|
|
911
1062
|
);
|
|
912
1063
|
}
|
|
913
|
-
|
|
914
|
-
// src/core/client/types.ts
|
|
915
|
-
function isSuccessResponse(response) {
|
|
916
|
-
return response.success === true;
|
|
917
|
-
}
|
|
918
|
-
function isErrorResponse(response) {
|
|
919
|
-
return response.success === false;
|
|
920
|
-
}
|
|
921
1064
|
//# sourceMappingURL=index.cjs.map
|