@01.software/sdk 0.12.1 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -57
- package/dist/{const-CRjjFJ3o.d.ts → const-DSTPrI77.d.ts} +1 -1
- package/dist/{const-CZOY2tsf.d.cts → const-DqcpKgSA.d.cts} +1 -1
- package/dist/index.cjs +794 -504
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +639 -439
- package/dist/index.d.ts +639 -439
- package/dist/index.js +794 -504
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-D4IWd3ZB.d.cts → payload-types-DqX4iuTW.d.cts} +1 -1
- package/dist/{payload-types-D4IWd3ZB.d.ts → payload-types-DqX4iuTW.d.ts} +1 -1
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +2 -2
- package/dist/realtime.d.ts +2 -2
- package/dist/realtime.js.map +1 -1
- package/dist/{server-JR9TvKZ5.d.cts → server-DLdbWJVv.d.cts} +5 -3
- package/dist/{server-JR9TvKZ5.d.ts → server-DLdbWJVv.d.ts} +5 -3
- package/dist/ui/canvas/server.cjs +4 -4
- package/dist/ui/canvas/server.cjs.map +1 -1
- package/dist/ui/canvas/server.d.cts +1 -1
- package/dist/ui/canvas/server.d.ts +1 -1
- package/dist/ui/canvas/server.js +4 -4
- package/dist/ui/canvas/server.js.map +1 -1
- package/dist/ui/canvas.cjs +4 -4
- package/dist/ui/canvas.cjs.map +1 -1
- package/dist/ui/canvas.d.cts +2 -2
- package/dist/ui/canvas.d.ts +2 -2
- package/dist/ui/canvas.js +4 -4
- package/dist/ui/canvas.js.map +1 -1
- package/dist/ui/form.d.cts +1 -1
- package/dist/ui/form.d.ts +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/{webhook-D_7bYIKj.d.ts → webhook-CX21PpBt.d.ts} +2 -2
- package/dist/{webhook-C1q3iC6W.d.cts → webhook-mXjcW86I.d.cts} +2 -2
- package/dist/webhook.d.cts +3 -3
- package/dist/webhook.d.ts +3 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ pnpm add @01.software/sdk
|
|
|
21
21
|
- Automatic retry with exponential backoff (non-retryable: 401, 403, 404, 422)
|
|
22
22
|
- Webhook handling with HMAC-SHA256 signature verification
|
|
23
23
|
- Sub-path imports (`./webhook`, `./realtime`, `./ui/*`) for tree-shaking
|
|
24
|
-
- Type-safe read-only `from()` for Client (compile-time write prevention)
|
|
24
|
+
- Type-safe read-only `collections.from()` for Client (compile-time write prevention)
|
|
25
25
|
|
|
26
26
|
### Sub-path Imports
|
|
27
27
|
|
|
@@ -59,7 +59,7 @@ const client = createClient({
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
// Query data (returns Payload native response)
|
|
62
|
-
const { docs } = await client.from('products').find({
|
|
62
|
+
const { docs } = await client.collections.from('products').find({
|
|
63
63
|
limit: 10,
|
|
64
64
|
where: { status: { equals: 'published' } },
|
|
65
65
|
})
|
|
@@ -76,18 +76,18 @@ const client = createServerClient({
|
|
|
76
76
|
})
|
|
77
77
|
|
|
78
78
|
// Create order (server only)
|
|
79
|
-
const order = await
|
|
79
|
+
const order = await server.commerce.orders.create({
|
|
80
80
|
orderNumber: generateOrderNumber(),
|
|
81
81
|
customerSnapshot: { email: 'user@example.com' },
|
|
82
82
|
shippingAddress: { recipientName: 'John', phone: '010-1234-5678', postalCode: '12345', address1: 'Seoul', address2: 'Apt 101' },
|
|
83
|
-
|
|
83
|
+
orderItems: [...],
|
|
84
84
|
totalAmount: 10000,
|
|
85
|
-
|
|
85
|
+
pgPaymentId: 'pay_123', // optional (omit for free orders)
|
|
86
86
|
discountCode: 'WELCOME10', // optional
|
|
87
87
|
})
|
|
88
88
|
|
|
89
89
|
// SSR prefetch (server)
|
|
90
|
-
await
|
|
90
|
+
await server.query.prefetchQuery({
|
|
91
91
|
collection: 'products',
|
|
92
92
|
options: { limit: 10 },
|
|
93
93
|
})
|
|
@@ -101,6 +101,12 @@ await client.query.prefetchQuery({
|
|
|
101
101
|
const client = createClient({
|
|
102
102
|
publishableKey: string, // Required
|
|
103
103
|
})
|
|
104
|
+
|
|
105
|
+
const server = createServerClient({
|
|
106
|
+
publishableKey: string,
|
|
107
|
+
secretKey: string, // sk01_... or pat01_...
|
|
108
|
+
tenantId: string, // required when secretKey is pat01_
|
|
109
|
+
})
|
|
104
110
|
```
|
|
105
111
|
|
|
106
112
|
| Option | Type | Description |
|
|
@@ -115,13 +121,13 @@ API URL은 환경변수로 오버라이드 가능합니다:
|
|
|
115
121
|
|
|
116
122
|
### Query Builder
|
|
117
123
|
|
|
118
|
-
Access collections via `client.from(
|
|
124
|
+
Access collections via `client.collections.from(slug)`.
|
|
119
125
|
|
|
120
|
-
> **Note:** `
|
|
126
|
+
> **Note:** `client.collections.from()` returns a `ReadOnlyQueryBuilder` (only `find`, `findById`, `count`, `findMetadata`, `findMetadataById`). Write operations (`create`, `update`, `remove`, `updateMany`, `removeMany`) are only available on `server.collections.from()`.
|
|
121
127
|
|
|
122
128
|
```typescript
|
|
123
129
|
// List query - returns PayloadFindResponse
|
|
124
|
-
const { docs, totalDocs, hasNextPage } = await client.from('products').find({
|
|
130
|
+
const { docs, totalDocs, hasNextPage } = await client.collections.from('products').find({
|
|
125
131
|
limit: 20,
|
|
126
132
|
page: 1,
|
|
127
133
|
sort: '-createdAt',
|
|
@@ -131,57 +137,57 @@ const { docs, totalDocs, hasNextPage } = await client.from('products').find({
|
|
|
131
137
|
})
|
|
132
138
|
|
|
133
139
|
// Query with populate/joins control
|
|
134
|
-
const { docs } = await client.from('products').find({
|
|
140
|
+
const { docs } = await client.collections.from('products').find({
|
|
135
141
|
select: { title: true, slug: true, price: true, thumbnail: true },
|
|
136
142
|
joins: false, // disable joins for lightweight list
|
|
137
143
|
})
|
|
138
144
|
|
|
139
145
|
// Override relationship populate
|
|
140
|
-
const product = await client.from('products').findById(id, {
|
|
146
|
+
const product = await client.collections.from('products').findById(id, {
|
|
141
147
|
populate: { brands: { name: true, logo: true } },
|
|
142
148
|
joins: { variants: { limit: 50 } },
|
|
143
149
|
})
|
|
144
150
|
|
|
145
151
|
// Single item query - returns document directly
|
|
146
|
-
const product = await client.from('products').findById('id')
|
|
152
|
+
const product = await client.collections.from('products').findById('id')
|
|
147
153
|
|
|
148
154
|
// Create (server only) - returns PayloadMutationResponse
|
|
149
|
-
const { doc, message } = await
|
|
155
|
+
const { doc, message } = await server.collections
|
|
150
156
|
.from('products')
|
|
151
157
|
.create({ name: 'Product' })
|
|
152
158
|
|
|
153
159
|
// Create with file upload (server only) - uses multipart/form-data
|
|
154
|
-
const { doc } = await
|
|
160
|
+
const { doc } = await server.collections
|
|
155
161
|
.from('images')
|
|
156
162
|
.create({ alt: 'Hero image' }, { file: imageFile, filename: 'hero.jpg' })
|
|
157
163
|
|
|
158
164
|
// Update (server only) - returns PayloadMutationResponse
|
|
159
|
-
const { doc } = await
|
|
165
|
+
const { doc } = await server.collections.from('products').update('id', { name: 'Updated' })
|
|
160
166
|
|
|
161
167
|
// Update with file replacement (server only)
|
|
162
|
-
await
|
|
168
|
+
await server.collections.from('images').update('id', { alt: 'New alt' }, { file: newFile })
|
|
163
169
|
|
|
164
170
|
// Delete (server only) - returns document directly
|
|
165
|
-
const deletedDoc = await
|
|
171
|
+
const deletedDoc = await server.collections.from('products').remove('id')
|
|
166
172
|
|
|
167
173
|
// Count
|
|
168
|
-
const { totalDocs } = await client.from('products').count()
|
|
174
|
+
const { totalDocs } = await client.collections.from('products').count()
|
|
169
175
|
|
|
170
176
|
// SEO Metadata (fetch + generate in one call, depth: 1 auto-applied)
|
|
171
|
-
const metadata = await client
|
|
177
|
+
const metadata = await client.collections
|
|
172
178
|
.from('products')
|
|
173
179
|
.findMetadata(
|
|
174
180
|
{ where: { slug: { equals: 'my-product' } } },
|
|
175
181
|
{ siteName: 'My Store' },
|
|
176
182
|
)
|
|
177
183
|
|
|
178
|
-
const metadataById = await client.from('products').findMetadataById('id', {
|
|
184
|
+
const metadataById = await client.collections.from('products').findMetadataById('id', {
|
|
179
185
|
siteName: 'My Store',
|
|
180
186
|
})
|
|
181
187
|
|
|
182
188
|
// Bulk operations (server only)
|
|
183
|
-
await
|
|
184
|
-
await
|
|
189
|
+
await server.collections.from('products').updateMany(where, data)
|
|
190
|
+
await server.collections.from('products').removeMany(where)
|
|
185
191
|
```
|
|
186
192
|
|
|
187
193
|
### API Response Types (Payload Native)
|
|
@@ -303,7 +309,7 @@ client.query.setCustomerData(profile)
|
|
|
303
309
|
|
|
304
310
|
### Customer Auth
|
|
305
311
|
|
|
306
|
-
Available on Client via `client.customer.*`.
|
|
312
|
+
Available on Client via `client.customer.auth.*`.
|
|
307
313
|
|
|
308
314
|
```typescript
|
|
309
315
|
const client = createClient({
|
|
@@ -312,83 +318,114 @@ const client = createClient({
|
|
|
312
318
|
})
|
|
313
319
|
|
|
314
320
|
// Register & login
|
|
315
|
-
const { customer } = await client.customer.register({
|
|
321
|
+
const { customer } = await client.customer.auth.register({
|
|
316
322
|
name: 'John',
|
|
317
323
|
email: 'john@example.com',
|
|
318
324
|
password: 'secure123',
|
|
319
325
|
})
|
|
320
|
-
const { token, customer } = await client.customer.login({
|
|
326
|
+
const { token, customer } = await client.customer.auth.login({
|
|
321
327
|
email: 'john@example.com',
|
|
322
328
|
password: 'secure123',
|
|
323
329
|
})
|
|
324
330
|
|
|
325
331
|
// Profile & token management
|
|
326
|
-
const profile = await client.customer.me()
|
|
327
|
-
client.customer.isAuthenticated()
|
|
328
|
-
client.customer.logout()
|
|
332
|
+
const profile = await client.customer.auth.me()
|
|
333
|
+
client.customer.auth.isAuthenticated()
|
|
334
|
+
client.customer.auth.logout()
|
|
329
335
|
|
|
330
|
-
//
|
|
331
|
-
const orders = await client.
|
|
336
|
+
// Authenticated customer's own orders (Client-only)
|
|
337
|
+
const orders = await client.commerce.orders.listMine({
|
|
332
338
|
page: 1,
|
|
333
339
|
limit: 10,
|
|
334
340
|
status: 'paid',
|
|
335
341
|
})
|
|
336
342
|
|
|
337
343
|
// Password & email
|
|
338
|
-
await client.customer.forgotPassword('john@example.com')
|
|
339
|
-
await client.customer.resetPassword(token, newPassword)
|
|
340
|
-
await client.customer.changePassword(currentPassword, newPassword)
|
|
341
|
-
await client.customer.verifyEmail(verificationToken)
|
|
344
|
+
await client.customer.auth.forgotPassword('john@example.com')
|
|
345
|
+
await client.customer.auth.resetPassword(token, newPassword)
|
|
346
|
+
await client.customer.auth.changePassword(currentPassword, newPassword)
|
|
347
|
+
await client.customer.auth.verifyEmail(verificationToken)
|
|
342
348
|
```
|
|
343
349
|
|
|
344
|
-
###
|
|
350
|
+
### Commerce Orders (ServerClient-only writes)
|
|
345
351
|
|
|
346
|
-
Available
|
|
352
|
+
Available on ServerClient via `server.commerce.orders.*`. Only `checkout` and `listMine` are also on Client.
|
|
347
353
|
|
|
348
354
|
```typescript
|
|
349
355
|
// Orders
|
|
350
|
-
await
|
|
351
|
-
await
|
|
352
|
-
await
|
|
353
|
-
|
|
356
|
+
await server.commerce.orders.create(params)
|
|
357
|
+
await server.commerce.orders.update({ orderNumber, status })
|
|
358
|
+
await server.commerce.orders.checkout({ cartId, pgPaymentId?, orderNumber, customerSnapshot, discountCode? })
|
|
359
|
+
|
|
360
|
+
// Single-order lookup (getOrder endpoint removed — use collection find)
|
|
361
|
+
const { docs: [order] } = await server.collections.from('orders').find({
|
|
362
|
+
where: { orderNumber: { equals: 'ORD-...' } },
|
|
363
|
+
limit: 1,
|
|
364
|
+
depth: 1,
|
|
365
|
+
})
|
|
354
366
|
|
|
355
367
|
// Fulfillment & transactions
|
|
356
|
-
await
|
|
357
|
-
await
|
|
368
|
+
await server.commerce.orders.createFulfillment({ orderNumber, carrier, trackingNumber, items })
|
|
369
|
+
await server.commerce.orders.bulkImportFulfillments({ items: [{ orderNumber, carrier?, trackingNumber? }] })
|
|
370
|
+
await server.commerce.orders.updateTransaction({ pgPaymentId, status, paymentMethod, receiptUrl })
|
|
358
371
|
|
|
359
372
|
// Returns
|
|
360
|
-
await
|
|
361
|
-
await
|
|
362
|
-
await
|
|
373
|
+
await server.commerce.orders.createReturn({ orderNumber, returnItems, refundAmount, reason? })
|
|
374
|
+
await server.commerce.orders.updateReturn({ returnId, status })
|
|
375
|
+
await server.commerce.orders.returnWithRefund({ orderNumber, returnItems, refundAmount, pgPaymentId })
|
|
376
|
+
```
|
|
377
|
+
|
|
378
|
+
### Commerce Discounts / Shipping
|
|
379
|
+
|
|
380
|
+
Available on both Client (customer JWT) and ServerClient (secretKey).
|
|
381
|
+
|
|
382
|
+
```typescript
|
|
383
|
+
await client.commerce.discounts.validate({ code, orderAmount })
|
|
384
|
+
await client.commerce.shipping.calculate({ shippingPolicyId?, orderAmount, postalCode? })
|
|
385
|
+
// calculateShipping returns: { shippingAmount, baseShippingAmount, extraShippingAmount, freeShipping, freeShippingMinAmount, isJeju, isRemoteIsland }
|
|
363
386
|
```
|
|
364
387
|
|
|
365
|
-
### Product
|
|
388
|
+
### Commerce Product
|
|
366
389
|
|
|
367
|
-
Available
|
|
390
|
+
Available on both Client and ServerClient via `commerce.product.*`.
|
|
368
391
|
|
|
369
392
|
```typescript
|
|
370
|
-
// Batch stock check
|
|
371
|
-
const { results, allAvailable } = await client.product.stockCheck({
|
|
393
|
+
// Batch stock check (point-in-time read, NOT a reservation)
|
|
394
|
+
const { results, allAvailable } = await client.commerce.product.stockCheck({
|
|
372
395
|
items: [
|
|
373
|
-
{
|
|
374
|
-
{ optionId: 3, quantity: 1 },
|
|
396
|
+
{ variantId: '...', quantity: 2 },
|
|
375
397
|
],
|
|
376
398
|
})
|
|
377
399
|
```
|
|
378
400
|
|
|
379
|
-
### Cart
|
|
401
|
+
### Commerce Cart
|
|
380
402
|
|
|
381
|
-
Available
|
|
403
|
+
Available on both Client and ServerClient via `commerce.cart.*`.
|
|
382
404
|
|
|
383
405
|
```typescript
|
|
384
406
|
// Add item to cart
|
|
385
|
-
await client.cart.addItem({ cartId, product, variant, option, quantity })
|
|
407
|
+
await client.commerce.cart.addItem({ cartId, product, variant, option, quantity })
|
|
386
408
|
|
|
387
409
|
// Update item quantity
|
|
388
|
-
await client.cart.updateItem({ cartItemId, quantity })
|
|
410
|
+
await client.commerce.cart.updateItem({ cartItemId, quantity })
|
|
389
411
|
|
|
390
412
|
// Remove item from cart
|
|
391
|
-
await client.cart.removeItem({ cartItemId })
|
|
413
|
+
await client.commerce.cart.removeItem({ cartItemId })
|
|
414
|
+
|
|
415
|
+
// Other cart operations
|
|
416
|
+
await client.commerce.cart.get(cartId)
|
|
417
|
+
await client.commerce.cart.applyDiscount({ cartId, discountCode })
|
|
418
|
+
await client.commerce.cart.removeDiscount({ cartId })
|
|
419
|
+
await client.commerce.cart.clear({ cartId })
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Community Moderation (ServerClient-only)
|
|
423
|
+
|
|
424
|
+
Available only on ServerClient via `server.community.moderation.*`.
|
|
425
|
+
|
|
426
|
+
```typescript
|
|
427
|
+
await server.community.moderation.banCustomer({ customerId, isPermanent?, bannedUntil?, reason? })
|
|
428
|
+
await server.community.moderation.unbanCustomer({ customerId })
|
|
392
429
|
```
|
|
393
430
|
|
|
394
431
|
### Webhook
|
|
@@ -520,7 +557,7 @@ The SDK throws typed errors instead of returning error responses:
|
|
|
520
557
|
import { isNetworkError, isApiError, isValidationError } from '@01.software/sdk'
|
|
521
558
|
|
|
522
559
|
try {
|
|
523
|
-
const { docs } = await client.from('products').find()
|
|
560
|
+
const { docs } = await client.collections.from('products').find()
|
|
524
561
|
} catch (error) {
|
|
525
562
|
if (isNetworkError(error)) {
|
|
526
563
|
console.error('Network issue:', error.message)
|