@01.software/sdk 0.1.0-dev.260211.a92d27b → 0.1.2
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 +151 -74
- package/dist/auth-AVOXtnYN.d.cts +267 -0
- package/dist/auth-c2UWJjPa.d.ts +267 -0
- package/dist/auth.cjs +129 -0
- package/dist/auth.cjs.map +1 -0
- package/dist/auth.d.cts +3 -0
- package/dist/auth.d.ts +3 -0
- package/dist/auth.js +107 -0
- package/dist/auth.js.map +1 -0
- package/dist/components.cjs +76 -0
- package/dist/components.cjs.map +1 -0
- package/dist/components.d.cts +28 -0
- package/dist/components.d.ts +28 -0
- package/dist/components.js +50 -0
- package/dist/components.js.map +1 -0
- package/dist/index.cjs +230 -96
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +73 -2844
- package/dist/index.d.ts +73 -2844
- package/dist/index.js +229 -94
- package/dist/index.js.map +1 -1
- package/dist/payload-types-DFzDtXGO.d.cts +2904 -0
- package/dist/payload-types-DFzDtXGO.d.ts +2904 -0
- package/dist/webhook-CGpSMkNA.d.ts +40 -0
- package/dist/webhook-DJCQSO6S.d.cts +40 -0
- package/dist/webhook.cjs +121 -0
- package/dist/webhook.cjs.map +1 -0
- package/dist/webhook.d.cts +2 -0
- package/dist/webhook.d.ts +2 -0
- package/dist/webhook.js +99 -0
- package/dist/webhook.js.map +1 -0
- package/package.json +35 -4
package/README.md
CHANGED
|
@@ -14,9 +14,28 @@ pnpm add @01.software/sdk
|
|
|
14
14
|
|
|
15
15
|
- Full TypeScript type inference
|
|
16
16
|
- Browser and server environment support
|
|
17
|
-
- React Query integration
|
|
18
|
-
-
|
|
19
|
-
-
|
|
17
|
+
- React Query integration (both BrowserClient and ServerClient)
|
|
18
|
+
- Mutation hooks (useCreate, useUpdate, useRemove) with automatic cache invalidation
|
|
19
|
+
- Automatic retry with exponential backoff (non-retryable: 401, 403, 404, 422)
|
|
20
|
+
- Webhook handling with HMAC-SHA256 signature verification
|
|
21
|
+
- Sub-path imports (`./auth`, `./webhook`, `./components`) for tree-shaking
|
|
22
|
+
- Type-safe read-only `from()` for BrowserClient (compile-time write prevention)
|
|
23
|
+
|
|
24
|
+
### Sub-path Imports
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// Main entry - clients, query builder, hooks, utilities
|
|
28
|
+
import { createBrowserClient, createServerClient } from '@01.software/sdk'
|
|
29
|
+
|
|
30
|
+
// Auth only - JWT & API Key utilities (smaller bundle)
|
|
31
|
+
import { createServerToken, verifyServerToken, createApiKey } from '@01.software/sdk/auth'
|
|
32
|
+
|
|
33
|
+
// Webhook only - webhook handlers
|
|
34
|
+
import { handleWebhook, createTypedWebhookHandler } from '@01.software/sdk/webhook'
|
|
35
|
+
|
|
36
|
+
// Components only - React components
|
|
37
|
+
import { RichTextContent } from '@01.software/sdk/components'
|
|
38
|
+
```
|
|
20
39
|
|
|
21
40
|
## Getting Started
|
|
22
41
|
|
|
@@ -29,8 +48,8 @@ const client = createBrowserClient({
|
|
|
29
48
|
clientKey: process.env.NEXT_PUBLIC_SOFTWARE_CLIENT_KEY,
|
|
30
49
|
})
|
|
31
50
|
|
|
32
|
-
// Query data
|
|
33
|
-
const {
|
|
51
|
+
// Query data (returns Payload native response)
|
|
52
|
+
const { docs } = await client.from('products').find({
|
|
34
53
|
limit: 10,
|
|
35
54
|
where: { status: { equals: 'published' } },
|
|
36
55
|
})
|
|
@@ -54,6 +73,12 @@ const order = await client.api.createOrder({
|
|
|
54
73
|
orderProducts: [...],
|
|
55
74
|
totalAmount: 10000,
|
|
56
75
|
})
|
|
76
|
+
|
|
77
|
+
// SSR prefetch (server)
|
|
78
|
+
await client.query.prefetchQuery({
|
|
79
|
+
collection: 'products',
|
|
80
|
+
options: { limit: 10 },
|
|
81
|
+
})
|
|
57
82
|
```
|
|
58
83
|
|
|
59
84
|
## API
|
|
@@ -63,84 +88,97 @@ const order = await client.api.createOrder({
|
|
|
63
88
|
```typescript
|
|
64
89
|
const client = createBrowserClient({
|
|
65
90
|
clientKey: string, // Required
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
retry?: RetryOptions,
|
|
69
|
-
errorLogger?: ErrorLogger,
|
|
91
|
+
environment?: Environment, // 'local' | 'development' | 'staging' | 'production'
|
|
92
|
+
baseUrl?: string, // Custom API URL (overrides environment)
|
|
70
93
|
})
|
|
71
94
|
```
|
|
72
95
|
|
|
73
|
-
| Option
|
|
74
|
-
|
|
|
75
|
-
| `clientKey`
|
|
76
|
-
| `secretKey`
|
|
77
|
-
| `
|
|
78
|
-
| `
|
|
79
|
-
| `retry` | `RetryOptions` | Retry configuration |
|
|
96
|
+
| Option | Type | Description |
|
|
97
|
+
| ------------- | ------------- | ---------------------------- |
|
|
98
|
+
| `clientKey` | `string` | API client key |
|
|
99
|
+
| `secretKey` | `string` | API secret key (server only) |
|
|
100
|
+
| `environment` | `Environment` | API environment |
|
|
101
|
+
| `baseUrl` | `string` | Custom API URL |
|
|
80
102
|
|
|
81
103
|
### Query Builder
|
|
82
104
|
|
|
83
105
|
Access collections via `client.from(collection)` method.
|
|
84
106
|
|
|
107
|
+
> **Note:** `BrowserClient.from()` returns a `ReadOnlyQueryBuilder` (only `find`, `findById`, `count`). Write operations (`create`, `update`, `remove`, `updateMany`, `removeMany`) are only available on `ServerClient.from()`.
|
|
108
|
+
|
|
85
109
|
```typescript
|
|
86
|
-
// List query
|
|
87
|
-
const {
|
|
110
|
+
// List query - returns PayloadFindResponse
|
|
111
|
+
const { docs, totalDocs, hasNextPage } = await client.from('products').find({
|
|
88
112
|
limit: 20,
|
|
89
113
|
page: 1,
|
|
90
114
|
sort: '-createdAt',
|
|
91
115
|
where: { status: { equals: 'published' } },
|
|
116
|
+
depth: 2,
|
|
117
|
+
select: { title: true, slug: true },
|
|
92
118
|
})
|
|
93
119
|
|
|
94
|
-
// Single item query
|
|
95
|
-
const
|
|
120
|
+
// Single item query - returns document directly
|
|
121
|
+
const product = await client.from('products').findById('id')
|
|
122
|
+
|
|
123
|
+
// Create (server only) - returns PayloadMutationResponse
|
|
124
|
+
const { doc, message } = await client.from('products').create({ name: 'Product' })
|
|
96
125
|
|
|
97
|
-
//
|
|
98
|
-
const {
|
|
126
|
+
// Update (server only) - returns PayloadMutationResponse
|
|
127
|
+
const { doc } = await client.from('products').update('id', { name: 'Updated' })
|
|
99
128
|
|
|
100
|
-
//
|
|
101
|
-
const
|
|
129
|
+
// Delete (server only) - returns document directly
|
|
130
|
+
const deletedDoc = await client.from('products').remove('id')
|
|
102
131
|
|
|
103
|
-
//
|
|
104
|
-
await client.from('products').
|
|
132
|
+
// Count
|
|
133
|
+
const { totalDocs } = await client.from('products').count()
|
|
134
|
+
|
|
135
|
+
// Bulk operations (server only)
|
|
136
|
+
await client.from('products').updateMany(where, data)
|
|
137
|
+
await client.from('products').removeMany(where)
|
|
105
138
|
```
|
|
106
139
|
|
|
107
|
-
### API Response
|
|
140
|
+
### API Response Types (Payload Native)
|
|
108
141
|
|
|
109
|
-
|
|
142
|
+
The SDK returns Payload CMS native response types without wrapping:
|
|
110
143
|
|
|
111
144
|
```typescript
|
|
112
|
-
//
|
|
113
|
-
interface
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
// find() returns PayloadFindResponse<T>
|
|
146
|
+
interface PayloadFindResponse<T> {
|
|
147
|
+
docs: T[]
|
|
148
|
+
totalDocs: number
|
|
149
|
+
limit: number
|
|
150
|
+
totalPages: number
|
|
151
|
+
page: number
|
|
152
|
+
pagingCounter: number
|
|
153
|
+
hasPrevPage: boolean
|
|
154
|
+
hasNextPage: boolean
|
|
155
|
+
prevPage: number | null
|
|
156
|
+
nextPage: number | null
|
|
118
157
|
}
|
|
119
158
|
|
|
120
|
-
//
|
|
121
|
-
interface
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
code: string
|
|
126
|
-
message: string
|
|
127
|
-
details?: unknown
|
|
128
|
-
}
|
|
159
|
+
// create() / update() returns PayloadMutationResponse<T>
|
|
160
|
+
interface PayloadMutationResponse<T> {
|
|
161
|
+
message: string
|
|
162
|
+
doc: T
|
|
163
|
+
errors?: unknown[]
|
|
129
164
|
}
|
|
130
|
-
```
|
|
131
165
|
|
|
132
|
-
|
|
166
|
+
// findById() / remove() returns T (document directly)
|
|
167
|
+
```
|
|
133
168
|
|
|
134
|
-
| Operation |
|
|
135
|
-
|
|
136
|
-
| `find()` | `
|
|
137
|
-
| `findById()` | `
|
|
138
|
-
| `create()` | `
|
|
139
|
-
| `update()` | `
|
|
140
|
-
| `remove()` | `
|
|
169
|
+
| Operation | Response Type |
|
|
170
|
+
|-----------|--------------|
|
|
171
|
+
| `find()` | `PayloadFindResponse<T>` - `{ docs, totalDocs, hasNextPage, ... }` |
|
|
172
|
+
| `findById()` | `T` - document object directly |
|
|
173
|
+
| `create()` | `PayloadMutationResponse<T>` - `{ doc, message }` |
|
|
174
|
+
| `update()` | `PayloadMutationResponse<T>` - `{ doc, message }` |
|
|
175
|
+
| `remove()` | `T` - deleted document object directly |
|
|
176
|
+
| `count()` | `{ totalDocs: number }` |
|
|
141
177
|
|
|
142
178
|
### React Query Hooks
|
|
143
179
|
|
|
180
|
+
Available on both `BrowserClient` and `ServerClient` via `client.query.*`.
|
|
181
|
+
|
|
144
182
|
```typescript
|
|
145
183
|
// List query
|
|
146
184
|
const { data, isLoading } = client.query.useQuery({
|
|
@@ -165,21 +203,40 @@ const { data, fetchNextPage, hasNextPage } = client.query.useInfiniteQuery({
|
|
|
165
203
|
collection: 'products',
|
|
166
204
|
options: { limit: 20 },
|
|
167
205
|
})
|
|
206
|
+
|
|
207
|
+
// Mutation hooks (auto-invalidate cache on success)
|
|
208
|
+
const { mutate: create } = client.query.useCreate({ collection: 'products' })
|
|
209
|
+
const { mutate: update } = client.query.useUpdate({ collection: 'products' })
|
|
210
|
+
const { mutate: remove } = client.query.useRemove({ collection: 'products' })
|
|
211
|
+
|
|
212
|
+
create({ title: 'New Product' })
|
|
213
|
+
update({ id: 'product_id', data: { title: 'Updated' } })
|
|
214
|
+
remove('product_id')
|
|
215
|
+
|
|
216
|
+
// SSR Prefetch
|
|
217
|
+
await client.query.prefetchQuery({ collection: 'products', options: { limit: 10 } })
|
|
218
|
+
await client.query.prefetchQueryById({ collection: 'products', id: 'product_id' })
|
|
219
|
+
await client.query.prefetchInfiniteQuery({ collection: 'products', pageSize: 20 })
|
|
220
|
+
|
|
221
|
+
// Cache utilities
|
|
222
|
+
client.query.invalidateQueries('products')
|
|
223
|
+
client.query.getQueryData('products', 'list', options)
|
|
224
|
+
client.query.setQueryData('products', 'detail', id, data)
|
|
168
225
|
```
|
|
169
226
|
|
|
170
227
|
### Server API
|
|
171
228
|
|
|
172
|
-
Available only in ServerClient.
|
|
229
|
+
Available only in ServerClient via `client.api.*`.
|
|
173
230
|
|
|
174
231
|
```typescript
|
|
175
232
|
// Create order
|
|
176
|
-
await client.api.createOrder(
|
|
233
|
+
await client.api.createOrder(params)
|
|
177
234
|
|
|
178
|
-
// Update order
|
|
179
|
-
await client.api.updateOrder(
|
|
235
|
+
// Update order status
|
|
236
|
+
await client.api.updateOrder({ orderNumber, status })
|
|
180
237
|
|
|
181
238
|
// Update transaction
|
|
182
|
-
await client.api.updateTransaction(
|
|
239
|
+
await client.api.updateTransaction({ paymentId, status, paymentMethod, receiptUrl })
|
|
183
240
|
```
|
|
184
241
|
|
|
185
242
|
### Webhook
|
|
@@ -194,6 +251,13 @@ export async function POST(request: Request) {
|
|
|
194
251
|
})
|
|
195
252
|
}
|
|
196
253
|
|
|
254
|
+
// With signature verification
|
|
255
|
+
export async function POST(request: Request) {
|
|
256
|
+
return handleWebhook(request, handler, {
|
|
257
|
+
secret: process.env.WEBHOOK_SECRET,
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
197
261
|
// Type-safe handler
|
|
198
262
|
const handler = createTypedWebhookHandler('orders', async (event) => {
|
|
199
263
|
// event.data is typed as Order
|
|
@@ -210,9 +274,22 @@ const handler = createTypedWebhookHandler('orders', async (event) => {
|
|
|
210
274
|
| Orders | `orders`, `order-products`, `returns`, `return-products`, `transactions` |
|
|
211
275
|
| Content | `posts`, `post-categories`, `post-tags`, `post-images`, `documents`, `document-categories`, `document-images` |
|
|
212
276
|
| Media | `playlists`, `playlist-images`, `musics`, `galleries`, `gallery-images`, `media` |
|
|
277
|
+
| Forms | `forms`, `form-submissions` |
|
|
213
278
|
|
|
214
279
|
## Utilities
|
|
215
280
|
|
|
281
|
+
### resolveRelation
|
|
282
|
+
|
|
283
|
+
Resolves a Payload CMS relation field value. When `depth` is 0, relation fields return just an ID (number). When `depth > 0`, they return the full object. This utility normalizes both cases.
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
import { resolveRelation } from '@01.software/sdk'
|
|
287
|
+
|
|
288
|
+
const author = resolveRelation(post.author) // Author | null
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
> **Note:** `objectFor` is still available but deprecated. Use `resolveRelation` instead.
|
|
292
|
+
|
|
216
293
|
### generateOrderNumber
|
|
217
294
|
|
|
218
295
|
```typescript
|
|
@@ -227,14 +304,14 @@ const orderNumber = generateOrderNumber()
|
|
|
227
304
|
```typescript
|
|
228
305
|
import { formatOrderName } from '@01.software/sdk'
|
|
229
306
|
|
|
230
|
-
formatOrderName([{ product: {
|
|
307
|
+
formatOrderName([{ product: { title: 'Product A' } }])
|
|
231
308
|
// "Product A"
|
|
232
309
|
|
|
233
310
|
formatOrderName([
|
|
234
|
-
{ product: {
|
|
235
|
-
{ product: {
|
|
311
|
+
{ product: { title: 'Product A' } },
|
|
312
|
+
{ product: { title: 'Product B' } },
|
|
236
313
|
])
|
|
237
|
-
// "Product A
|
|
314
|
+
// "Product A 외 1건"
|
|
238
315
|
```
|
|
239
316
|
|
|
240
317
|
### RichTextContent
|
|
@@ -257,23 +334,23 @@ import { RichTextContent } from '@01.software/sdk'
|
|
|
257
334
|
|
|
258
335
|
## Error Handling
|
|
259
336
|
|
|
337
|
+
The SDK throws typed errors instead of returning error responses:
|
|
338
|
+
|
|
260
339
|
```typescript
|
|
261
|
-
import {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
} else if (isErrorResponse(response)) {
|
|
272
|
-
console.error(response.error.message)
|
|
340
|
+
import { isNetworkError, isApiError, isValidationError } from '@01.software/sdk'
|
|
341
|
+
|
|
342
|
+
try {
|
|
343
|
+
const { docs } = await client.from('products').find()
|
|
344
|
+
} catch (error) {
|
|
345
|
+
if (isNetworkError(error)) {
|
|
346
|
+
console.error('Network issue:', error.message)
|
|
347
|
+
} else if (isApiError(error)) {
|
|
348
|
+
console.error('API error:', error.status, error.message)
|
|
349
|
+
}
|
|
273
350
|
}
|
|
274
351
|
```
|
|
275
352
|
|
|
276
|
-
Error classes: `SDKError`, `ApiError`, `NetworkError`, `ValidationError`, `TimeoutError`
|
|
353
|
+
Error classes: `SDKError`, `ApiError`, `NetworkError`, `ValidationError`, `ConfigError`, `TimeoutError`
|
|
277
354
|
|
|
278
355
|
## Environment Variables
|
|
279
356
|
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { Sort, Where } from 'payload';
|
|
2
|
+
import './payload-types-DFzDtXGO.cjs';
|
|
3
|
+
|
|
4
|
+
declare class SDKError extends Error {
|
|
5
|
+
readonly code: string;
|
|
6
|
+
readonly status?: number;
|
|
7
|
+
readonly details?: unknown;
|
|
8
|
+
readonly userMessage?: string;
|
|
9
|
+
readonly suggestion?: string;
|
|
10
|
+
constructor(code: string, message: string, status?: number, details?: unknown, userMessage?: string, suggestion?: string);
|
|
11
|
+
getUserMessage(): string;
|
|
12
|
+
toJSON(): {
|
|
13
|
+
name: string;
|
|
14
|
+
code: string;
|
|
15
|
+
message: string;
|
|
16
|
+
status: number | undefined;
|
|
17
|
+
details: unknown;
|
|
18
|
+
userMessage: string | undefined;
|
|
19
|
+
suggestion: string | undefined;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
declare class NetworkError extends SDKError {
|
|
23
|
+
constructor(message: string, status?: number, details?: unknown, userMessage?: string, suggestion?: string);
|
|
24
|
+
}
|
|
25
|
+
declare class ValidationError extends SDKError {
|
|
26
|
+
constructor(message: string, details?: unknown, userMessage?: string, suggestion?: string);
|
|
27
|
+
}
|
|
28
|
+
declare class ApiError extends SDKError {
|
|
29
|
+
constructor(message: string, status: number, details?: unknown, userMessage?: string, suggestion?: string);
|
|
30
|
+
}
|
|
31
|
+
declare class ConfigError extends SDKError {
|
|
32
|
+
constructor(message: string, details?: unknown, userMessage?: string, suggestion?: string);
|
|
33
|
+
}
|
|
34
|
+
declare class TimeoutError extends SDKError {
|
|
35
|
+
constructor(message?: string, details?: unknown, userMessage?: string, suggestion?: string);
|
|
36
|
+
}
|
|
37
|
+
declare class UsageLimitError extends SDKError {
|
|
38
|
+
readonly usage: {
|
|
39
|
+
limit: number;
|
|
40
|
+
current: number;
|
|
41
|
+
remaining: number;
|
|
42
|
+
};
|
|
43
|
+
constructor(message: string, usage: {
|
|
44
|
+
limit: number;
|
|
45
|
+
current: number;
|
|
46
|
+
remaining: number;
|
|
47
|
+
}, details?: unknown, userMessage?: string, suggestion?: string);
|
|
48
|
+
toJSON(): {
|
|
49
|
+
usage: {
|
|
50
|
+
limit: number;
|
|
51
|
+
current: number;
|
|
52
|
+
remaining: number;
|
|
53
|
+
};
|
|
54
|
+
name: string;
|
|
55
|
+
code: string;
|
|
56
|
+
message: string;
|
|
57
|
+
status: number | undefined;
|
|
58
|
+
details: unknown;
|
|
59
|
+
userMessage: string | undefined;
|
|
60
|
+
suggestion: string | undefined;
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
declare function isSDKError(error: unknown): error is SDKError;
|
|
64
|
+
declare function isNetworkError(error: unknown): error is NetworkError;
|
|
65
|
+
declare function isValidationError(error: unknown): error is ValidationError;
|
|
66
|
+
declare function isApiError(error: unknown): error is ApiError;
|
|
67
|
+
declare function isConfigError(error: unknown): error is ConfigError;
|
|
68
|
+
declare function isTimeoutError(error: unknown): error is TimeoutError;
|
|
69
|
+
declare function isUsageLimitError(error: unknown): error is UsageLimitError;
|
|
70
|
+
|
|
71
|
+
type Environment = 'local' | 'development' | 'staging' | 'production';
|
|
72
|
+
declare const API_URLS: Record<Environment, string>;
|
|
73
|
+
/**
|
|
74
|
+
* 환경에 맞는 API URL을 반환합니다.
|
|
75
|
+
* 우선순위: baseUrl > environment > 환경변수 > 기본값(production)
|
|
76
|
+
*/
|
|
77
|
+
declare function resolveApiUrl(config?: {
|
|
78
|
+
baseUrl?: string;
|
|
79
|
+
environment?: Environment;
|
|
80
|
+
}): string;
|
|
81
|
+
interface ClientBrowserConfig {
|
|
82
|
+
clientKey: string;
|
|
83
|
+
/**
|
|
84
|
+
* API 환경 설정.
|
|
85
|
+
* - 'local': localhost:3000
|
|
86
|
+
* - 'development': dev.01.software
|
|
87
|
+
* - 'staging': stg.01.software
|
|
88
|
+
* - 'production': api.01.software
|
|
89
|
+
*
|
|
90
|
+
* baseUrl이 설정되면 이 값은 무시됩니다.
|
|
91
|
+
* @default 'production'
|
|
92
|
+
*/
|
|
93
|
+
environment?: Environment;
|
|
94
|
+
/**
|
|
95
|
+
* 커스텀 API URL. 설정 시 environment 값은 무시됩니다.
|
|
96
|
+
* @example 'https://my-custom-api.example.com'
|
|
97
|
+
*/
|
|
98
|
+
baseUrl?: string;
|
|
99
|
+
}
|
|
100
|
+
interface ClientServerConfig extends ClientBrowserConfig {
|
|
101
|
+
secretKey: string;
|
|
102
|
+
}
|
|
103
|
+
interface ClientMetadata {
|
|
104
|
+
userAgent?: string;
|
|
105
|
+
timestamp: number;
|
|
106
|
+
}
|
|
107
|
+
interface ClientState {
|
|
108
|
+
metadata: ClientMetadata;
|
|
109
|
+
}
|
|
110
|
+
interface PaginationMeta {
|
|
111
|
+
page: number;
|
|
112
|
+
limit: number;
|
|
113
|
+
totalDocs: number;
|
|
114
|
+
totalPages: number;
|
|
115
|
+
hasNextPage: boolean;
|
|
116
|
+
hasPrevPage: boolean;
|
|
117
|
+
pagingCounter: number;
|
|
118
|
+
prevPage: number | null;
|
|
119
|
+
nextPage: number | null;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Payload CMS Find (List) Response
|
|
123
|
+
* GET /api/{collection}
|
|
124
|
+
*/
|
|
125
|
+
interface PayloadFindResponse<T = unknown> {
|
|
126
|
+
docs: T[];
|
|
127
|
+
totalDocs: number;
|
|
128
|
+
limit: number;
|
|
129
|
+
totalPages: number;
|
|
130
|
+
page: number;
|
|
131
|
+
pagingCounter: number;
|
|
132
|
+
hasPrevPage: boolean;
|
|
133
|
+
hasNextPage: boolean;
|
|
134
|
+
prevPage: number | null;
|
|
135
|
+
nextPage: number | null;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Payload CMS Create/Update Response
|
|
139
|
+
* POST /api/{collection}
|
|
140
|
+
* PATCH /api/{collection}/{id}
|
|
141
|
+
*/
|
|
142
|
+
interface PayloadMutationResponse<T = unknown> {
|
|
143
|
+
message: string;
|
|
144
|
+
doc: T;
|
|
145
|
+
errors?: unknown[];
|
|
146
|
+
}
|
|
147
|
+
interface ApiQueryOptions {
|
|
148
|
+
page?: number;
|
|
149
|
+
limit?: number;
|
|
150
|
+
sort?: Sort;
|
|
151
|
+
where?: Where;
|
|
152
|
+
depth?: number;
|
|
153
|
+
select?: Record<string, boolean>;
|
|
154
|
+
}
|
|
155
|
+
interface ApiQueryReactOptions {
|
|
156
|
+
keepPreviousData?: boolean;
|
|
157
|
+
}
|
|
158
|
+
interface DebugConfig {
|
|
159
|
+
logRequests?: boolean;
|
|
160
|
+
logResponses?: boolean;
|
|
161
|
+
logErrors?: boolean;
|
|
162
|
+
}
|
|
163
|
+
interface RetryConfig {
|
|
164
|
+
maxRetries?: number;
|
|
165
|
+
retryableStatuses?: number[];
|
|
166
|
+
retryDelay?: (attempt: number) => number;
|
|
167
|
+
}
|
|
168
|
+
interface ErrorLogger {
|
|
169
|
+
log(error: SDKError | Error, context?: Record<string, unknown>): void;
|
|
170
|
+
}
|
|
171
|
+
type DeepPartial<T> = {
|
|
172
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
173
|
+
};
|
|
174
|
+
type ExtractArrayType<T> = T extends (infer U)[] ? U : never;
|
|
175
|
+
|
|
176
|
+
interface FetchOptions extends RequestInit {
|
|
177
|
+
clientKey?: string;
|
|
178
|
+
secretKey?: string;
|
|
179
|
+
timeout?: number;
|
|
180
|
+
baseUrl?: string;
|
|
181
|
+
debug?: boolean | DebugConfig;
|
|
182
|
+
retry?: RetryConfig;
|
|
183
|
+
}
|
|
184
|
+
interface JwtPayload {
|
|
185
|
+
clientKey: string;
|
|
186
|
+
iat?: number;
|
|
187
|
+
exp?: number;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Creates a JWT token for server-side authentication.
|
|
191
|
+
* The token is valid for 1 hour by default.
|
|
192
|
+
*
|
|
193
|
+
* @param clientKey - Client API key
|
|
194
|
+
* @param secretKey - Secret key used for signing
|
|
195
|
+
* @param expiresIn - Token expiration time (default: '1h')
|
|
196
|
+
* @returns Promise<string> JWT token
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* const token = await createServerToken('client-key', 'secret-key')
|
|
201
|
+
* // Use in Authorization header: `Bearer ${token}`
|
|
202
|
+
* ```
|
|
203
|
+
*/
|
|
204
|
+
declare function createServerToken(clientKey: string, secretKey: string, expiresIn?: string): Promise<string>;
|
|
205
|
+
/**
|
|
206
|
+
* Verifies a JWT token and returns the payload.
|
|
207
|
+
*
|
|
208
|
+
* @param token - JWT token to verify
|
|
209
|
+
* @param secretKey - Secret key used for verification
|
|
210
|
+
* @returns Promise<JwtPayload> Verified payload containing clientKey
|
|
211
|
+
* @throws Error if token is invalid or expired
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* const payload = await verifyServerToken(token, 'secret-key')
|
|
216
|
+
* console.log(payload.clientKey)
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
declare function verifyServerToken(token: string, secretKey: string): Promise<JwtPayload>;
|
|
220
|
+
/**
|
|
221
|
+
* Decodes a JWT token without verification.
|
|
222
|
+
* WARNING: Use this only when you need to inspect token contents.
|
|
223
|
+
* Always use verifyServerToken for authentication.
|
|
224
|
+
*
|
|
225
|
+
* @param token - JWT token to decode
|
|
226
|
+
* @returns JwtPayload Decoded payload (unverified)
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* const payload = decodeServerToken(token)
|
|
231
|
+
* console.log(payload.clientKey) // Unverified!
|
|
232
|
+
* ```
|
|
233
|
+
*/
|
|
234
|
+
declare function decodeServerToken(token: string): JwtPayload;
|
|
235
|
+
/**
|
|
236
|
+
* Creates a Base64-encoded API key from clientKey and secretKey.
|
|
237
|
+
* Use this for MCP server authentication.
|
|
238
|
+
*
|
|
239
|
+
* @param clientKey - Client API key
|
|
240
|
+
* @param secretKey - Secret key
|
|
241
|
+
* @returns Base64-encoded API key
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* const apiKey = createApiKey('client-key', 'secret-key')
|
|
246
|
+
* // Use in x-api-key header
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
declare function createApiKey(clientKey: string, secretKey: string): string;
|
|
250
|
+
/**
|
|
251
|
+
* Parses a Base64-encoded API key to extract clientKey and secretKey.
|
|
252
|
+
*
|
|
253
|
+
* @param apiKey - Base64-encoded API key
|
|
254
|
+
* @returns Object containing clientKey and secretKey
|
|
255
|
+
* @throws Error if API key is invalid
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const { clientKey, secretKey } = parseApiKey(apiKey)
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
declare function parseApiKey(apiKey: string): {
|
|
263
|
+
clientKey: string;
|
|
264
|
+
secretKey: string;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
export { type ApiQueryOptions as A, type ClientBrowserConfig as C, type DeepPartial as D, type ExtractArrayType as E, type FetchOptions as F, type JwtPayload as J, NetworkError as N, type PayloadFindResponse as P, type RetryConfig as R, SDKError as S, TimeoutError as T, UsageLimitError as U, ValidationError as V, type PayloadMutationResponse as a, type ClientState as b, type ClientServerConfig as c, type DebugConfig as d, type ErrorLogger as e, ApiError as f, ConfigError as g, isNetworkError as h, isSDKError as i, isValidationError as j, isApiError as k, isConfigError as l, isTimeoutError as m, isUsageLimitError as n, createServerToken as o, decodeServerToken as p, createApiKey as q, parseApiKey as r, type Environment as s, API_URLS as t, resolveApiUrl as u, verifyServerToken as v, type ClientMetadata as w, type PaginationMeta as x, type ApiQueryReactOptions as y };
|