@01.software/sdk 0.7.1 → 0.9.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 +54 -18
- package/dist/const-DZ04SC2y.d.cts +19 -0
- package/dist/const-hXu9oG66.d.ts +19 -0
- package/dist/index.cjs +57 -180
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +47 -64
- package/dist/index.d.ts +47 -64
- package/dist/index.js +57 -180
- package/dist/index.js.map +1 -1
- package/dist/{payload-types-Cp10MoF6.d.cts → payload-types-DICC2-Zr.d.cts} +916 -475
- package/dist/{payload-types-Cp10MoF6.d.ts → payload-types-DICC2-Zr.d.ts} +916 -475
- package/dist/{realtime-DupPIYx-.d.cts → realtime-D7HtUpqt.d.cts} +2 -2
- package/dist/{realtime-DupPIYx-.d.ts → realtime-D7HtUpqt.d.ts} +2 -2
- package/dist/realtime.cjs +8 -7
- package/dist/realtime.cjs.map +1 -1
- package/dist/realtime.d.cts +6 -6
- package/dist/realtime.d.ts +6 -6
- package/dist/realtime.js +8 -7
- package/dist/realtime.js.map +1 -1
- package/dist/{server-DxhuG-_s.d.cts → server-JR9TvKZ5.d.cts} +0 -2
- package/dist/{server-DxhuG-_s.d.ts → server-JR9TvKZ5.d.ts} +0 -2
- package/dist/ui/canvas/server.cjs +1 -2
- 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 +1 -2
- package/dist/ui/canvas/server.js.map +1 -1
- package/dist/ui/canvas.cjs +1 -2
- 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 +1 -2
- 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.cjs +1 -1
- package/dist/ui/video.cjs.map +1 -1
- package/dist/ui/video.d.cts +1 -1
- package/dist/ui/video.d.ts +1 -1
- package/dist/ui/video.js +1 -1
- package/dist/ui/video.js.map +1 -1
- package/dist/{webhook-BKhMTlFN.d.ts → webhook-BD9ivfyR.d.ts} +2 -2
- package/dist/{webhook-CiWsseVz.d.cts → webhook-D8ogsafv.d.cts} +2 -2
- package/dist/webhook.d.cts +3 -3
- package/dist/webhook.d.ts +3 -3
- package/package.json +1 -11
- package/dist/auth.cjs +0 -109
- package/dist/auth.cjs.map +0 -1
- package/dist/auth.d.cts +0 -36
- package/dist/auth.d.ts +0 -36
- package/dist/auth.js +0 -86
- package/dist/auth.js.map +0 -1
- package/dist/const-B8iE-mDN.d.cts +0 -19
- package/dist/const-Chw71pKS.d.ts +0 -19
package/README.md
CHANGED
|
@@ -29,12 +29,8 @@ pnpm add @01.software/sdk
|
|
|
29
29
|
// Main entry - clients, query builder, hooks, utilities
|
|
30
30
|
import { createClient, createServerClient } from '@01.software/sdk'
|
|
31
31
|
|
|
32
|
-
// Auth only - JWT
|
|
33
|
-
import {
|
|
34
|
-
createServerToken,
|
|
35
|
-
verifyServerToken,
|
|
36
|
-
createApiKey,
|
|
37
|
-
} from '@01.software/sdk/auth'
|
|
32
|
+
// Auth only - customer JWT utilities (smaller bundle)
|
|
33
|
+
import { verifyCustomerToken } from '@01.software/sdk/auth'
|
|
38
34
|
|
|
39
35
|
// Webhook only - webhook handlers
|
|
40
36
|
import {
|
|
@@ -59,7 +55,7 @@ import { VideoPlayer } from '@01.software/sdk/ui/video'
|
|
|
59
55
|
import { createClient } from '@01.software/sdk'
|
|
60
56
|
|
|
61
57
|
const client = createClient({
|
|
62
|
-
|
|
58
|
+
publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY,
|
|
63
59
|
})
|
|
64
60
|
|
|
65
61
|
// Query data (returns Payload native response)
|
|
@@ -75,8 +71,8 @@ const { docs } = await client.from('products').find({
|
|
|
75
71
|
import { createServerClient } from '@01.software/sdk'
|
|
76
72
|
|
|
77
73
|
const client = createServerClient({
|
|
78
|
-
|
|
79
|
-
secretKey: process.env.SOFTWARE_SECRET_KEY,
|
|
74
|
+
publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY,
|
|
75
|
+
secretKey: process.env.SOFTWARE_SECRET_KEY, // sk01_... opaque API key from Console
|
|
80
76
|
})
|
|
81
77
|
|
|
82
78
|
// Create order (server only)
|
|
@@ -103,14 +99,14 @@ await client.query.prefetchQuery({
|
|
|
103
99
|
|
|
104
100
|
```typescript
|
|
105
101
|
const client = createClient({
|
|
106
|
-
|
|
102
|
+
publishableKey: string, // Required
|
|
107
103
|
})
|
|
108
104
|
```
|
|
109
105
|
|
|
110
|
-
| Option
|
|
111
|
-
|
|
|
112
|
-
| `
|
|
113
|
-
| `secretKey`
|
|
106
|
+
| Option | Type | Description |
|
|
107
|
+
| ---------------- | -------- | ---------------------------- |
|
|
108
|
+
| `publishableKey` | `string` | API publishable key |
|
|
109
|
+
| `secretKey` | `string` | API secret key (server only) |
|
|
114
110
|
|
|
115
111
|
API URL은 환경변수로 오버라이드 가능합니다:
|
|
116
112
|
|
|
@@ -311,7 +307,7 @@ Available on Client via `client.customer.*`.
|
|
|
311
307
|
|
|
312
308
|
```typescript
|
|
313
309
|
const client = createClient({
|
|
314
|
-
|
|
310
|
+
publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY,
|
|
315
311
|
customer: { persist: true },
|
|
316
312
|
})
|
|
317
313
|
|
|
@@ -452,7 +448,7 @@ import { resolveRelation } from '@01.software/sdk'
|
|
|
452
448
|
const author = resolveRelation(post.author) // Author | null
|
|
453
449
|
```
|
|
454
450
|
|
|
455
|
-
> **Note:** `
|
|
451
|
+
> **Note:** Prefer `resolveRelation`. It covers the same normalization use case directly.
|
|
456
452
|
|
|
457
453
|
### generateOrderNumber
|
|
458
454
|
|
|
@@ -539,8 +535,48 @@ Error classes: `SDKError`, `ApiError`, `NetworkError`, `ValidationError`, `Confi
|
|
|
539
535
|
## Environment Variables
|
|
540
536
|
|
|
541
537
|
```bash
|
|
542
|
-
|
|
543
|
-
SOFTWARE_SECRET_KEY=
|
|
538
|
+
NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY=your_publishable_key
|
|
539
|
+
SOFTWARE_SECRET_KEY=sk01_... # Server only — opaque API key from Console
|
|
544
540
|
```
|
|
545
541
|
|
|
546
542
|
> `secretKey` should only be used in server environments. Never expose it to the browser.
|
|
543
|
+
|
|
544
|
+
> **SDK 0.9.0**: Server auth now uses opaque bearer tokens (`sk01_...`). Generate API keys from the Console. `createServerToken`, `createApiKey`, and `parseApiKey` are no longer part of the SDK surface.
|
|
545
|
+
|
|
546
|
+
## Migration Guide
|
|
547
|
+
|
|
548
|
+
### v0.8.0 (Breaking Changes)
|
|
549
|
+
|
|
550
|
+
**Field renames** — update any code that reads these fields from API responses:
|
|
551
|
+
|
|
552
|
+
| Collection | Old | New |
|
|
553
|
+
|---|---|---|
|
|
554
|
+
| Customers | `socialId` | `providerUserId` |
|
|
555
|
+
| Customers | `isVerified` | `isEmailVerified` |
|
|
556
|
+
| Customers | `loginAttempts` | `loginAttemptCount` |
|
|
557
|
+
| Customers | `resetPasswordExpiry` | `resetPasswordExpiresAt` |
|
|
558
|
+
| Orders, Carts | `shippingFee` | `shippingAmount` |
|
|
559
|
+
| Carts | `itemsTotal` | `subtotalAmount` |
|
|
560
|
+
| Transactions | `paymentId` | `pgPaymentId` |
|
|
561
|
+
| Discounts | `type` | `discountType` |
|
|
562
|
+
| Discounts | `value` | `discountValue` |
|
|
563
|
+
| Discounts | `usageLimit` | `maxUses` |
|
|
564
|
+
| Discounts | `usageCount` | `usesCount` |
|
|
565
|
+
| Discounts | `perCustomerLimit` | `maxUsesPerCustomer` |
|
|
566
|
+
| ShippingPolicies | `baseFee` | `baseAmount` |
|
|
567
|
+
| ShippingPolicies | `freeShippingThreshold` | `freeShippingMinAmount` |
|
|
568
|
+
| Documents | `effectiveDate` | `effectiveAt` |
|
|
569
|
+
| Documents | `expiryDate` | `expiresAt` |
|
|
570
|
+
| Posts | `readTime` | `readingMinutes` |
|
|
571
|
+
| ApiUsage | `count` | `apiCallCount` |
|
|
572
|
+
| ApiUsage | `storageUsed` | `storageUsedBytes` |
|
|
573
|
+
| ApiUsage | `totalDocuments` | `documentCount` |
|
|
574
|
+
|
|
575
|
+
**Collection renames:**
|
|
576
|
+
- `order-products` → `order-items`
|
|
577
|
+
- `return-products` → `return-items`
|
|
578
|
+
- Removed: `exchanges`, `exchange-products`
|
|
579
|
+
- Added: `product-option-values`
|
|
580
|
+
|
|
581
|
+
**Boolean field renames** (6 collections):
|
|
582
|
+
- `status: 'active' | 'inactive'` → `isActive: boolean` on Musics, Forms, PostAuthors, CustomerGroups, ShippingPolicies, ProductVariants
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { C as Config } from './payload-types-DICC2-Zr.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Collection type derived from Payload Config.
|
|
5
|
+
* This ensures type safety and automatic synchronization with payload-types.ts
|
|
6
|
+
*/
|
|
7
|
+
type Collection = keyof Config['collections'];
|
|
8
|
+
/**
|
|
9
|
+
* Array of all public collection names for runtime use (e.g., Zod enum validation).
|
|
10
|
+
* This is the single source of truth for which collections are publicly accessible via SDK.
|
|
11
|
+
*/
|
|
12
|
+
declare const COLLECTIONS: readonly ["tenants", "tenant-metadata", "tenant-logos", "products", "product-variants", "product-options", "product-option-values", "product-categories", "product-tags", "product-collections", "brands", "brand-logos", "orders", "order-items", "returns", "return-items", "fulfillments", "fulfillment-items", "transactions", "customers", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "musics", "music-categories", "music-tags", "galleries", "gallery-categories", "gallery-tags", "gallery-items", "links", "link-categories", "link-tags", "canvases", "canvas-node-types", "canvas-edge-types", "canvas-categories", "canvas-tags", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans"];
|
|
13
|
+
/**
|
|
14
|
+
* Public collections available for SDK access.
|
|
15
|
+
* Derived from the COLLECTIONS array (single source of truth).
|
|
16
|
+
*/
|
|
17
|
+
type PublicCollection = (typeof COLLECTIONS)[number];
|
|
18
|
+
|
|
19
|
+
export { type Collection as C, type PublicCollection as P, COLLECTIONS as a };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { C as Config } from './payload-types-DICC2-Zr.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Collection type derived from Payload Config.
|
|
5
|
+
* This ensures type safety and automatic synchronization with payload-types.ts
|
|
6
|
+
*/
|
|
7
|
+
type Collection = keyof Config['collections'];
|
|
8
|
+
/**
|
|
9
|
+
* Array of all public collection names for runtime use (e.g., Zod enum validation).
|
|
10
|
+
* This is the single source of truth for which collections are publicly accessible via SDK.
|
|
11
|
+
*/
|
|
12
|
+
declare const COLLECTIONS: readonly ["tenants", "tenant-metadata", "tenant-logos", "products", "product-variants", "product-options", "product-option-values", "product-categories", "product-tags", "product-collections", "brands", "brand-logos", "orders", "order-items", "returns", "return-items", "fulfillments", "fulfillment-items", "transactions", "customers", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "musics", "music-categories", "music-tags", "galleries", "gallery-categories", "gallery-tags", "gallery-items", "links", "link-categories", "link-tags", "canvases", "canvas-node-types", "canvas-edge-types", "canvas-categories", "canvas-tags", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans"];
|
|
13
|
+
/**
|
|
14
|
+
* Public collections available for SDK access.
|
|
15
|
+
* Derived from the COLLECTIONS array (single source of truth).
|
|
16
|
+
*/
|
|
17
|
+
type PublicCollection = (typeof COLLECTIONS)[number];
|
|
18
|
+
|
|
19
|
+
export { type Collection as C, type PublicCollection as P, COLLECTIONS as a };
|
package/dist/index.cjs
CHANGED
|
@@ -46,13 +46,10 @@ __export(src_exports, {
|
|
|
46
46
|
UsageLimitError: () => UsageLimitError,
|
|
47
47
|
ValidationError: () => ValidationError,
|
|
48
48
|
collectionKeys: () => collectionKeys,
|
|
49
|
-
createApiKey: () => createApiKey,
|
|
50
49
|
createClient: () => createClient,
|
|
51
50
|
createServerClient: () => createServerClient,
|
|
52
|
-
createServerToken: () => createServerToken,
|
|
53
51
|
createTypedWebhookHandler: () => createTypedWebhookHandler,
|
|
54
52
|
customerKeys: () => customerKeys,
|
|
55
|
-
decodeServerToken: () => decodeServerToken,
|
|
56
53
|
formatOrderName: () => formatOrderName,
|
|
57
54
|
generateOrderNumber: () => generateOrderNumber,
|
|
58
55
|
getImageLqip: () => getImageLqip,
|
|
@@ -77,91 +74,10 @@ __export(src_exports, {
|
|
|
77
74
|
isUsageLimitError: () => isUsageLimitError,
|
|
78
75
|
isValidWebhookEvent: () => isValidWebhookEvent,
|
|
79
76
|
isValidationError: () => isValidationError,
|
|
80
|
-
|
|
81
|
-
resolveRelation: () => resolveRelation,
|
|
82
|
-
verifyServerToken: () => verifyServerToken
|
|
77
|
+
resolveRelation: () => resolveRelation
|
|
83
78
|
});
|
|
84
79
|
module.exports = __toCommonJS(src_exports);
|
|
85
80
|
|
|
86
|
-
// src/core/internal/utils/jwt.ts
|
|
87
|
-
var import_jose = require("jose");
|
|
88
|
-
async function createServerToken(clientKey, secretKey, expiresIn = "1h") {
|
|
89
|
-
if (!clientKey || !secretKey) {
|
|
90
|
-
throw new Error("clientKey and secretKey are required.");
|
|
91
|
-
}
|
|
92
|
-
const secret = new TextEncoder().encode(secretKey);
|
|
93
|
-
return new import_jose.SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
|
|
94
|
-
}
|
|
95
|
-
async function verifyServerToken(token, secretKey) {
|
|
96
|
-
if (!token || !secretKey) {
|
|
97
|
-
throw new Error("token and secretKey are required.");
|
|
98
|
-
}
|
|
99
|
-
const secret = new TextEncoder().encode(secretKey);
|
|
100
|
-
const { payload } = await (0, import_jose.jwtVerify)(token, secret, {
|
|
101
|
-
algorithms: ["HS256"]
|
|
102
|
-
});
|
|
103
|
-
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
104
|
-
throw new Error("Invalid token payload: clientKey is missing");
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
clientKey: payload.clientKey,
|
|
108
|
-
iat: payload.iat,
|
|
109
|
-
exp: payload.exp
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
function decodeServerToken(token) {
|
|
113
|
-
if (!token) {
|
|
114
|
-
throw new Error("token is required.");
|
|
115
|
-
}
|
|
116
|
-
const payload = (0, import_jose.decodeJwt)(token);
|
|
117
|
-
if (!payload.clientKey || typeof payload.clientKey !== "string") {
|
|
118
|
-
throw new Error("Invalid token payload: clientKey is missing");
|
|
119
|
-
}
|
|
120
|
-
return {
|
|
121
|
-
clientKey: payload.clientKey,
|
|
122
|
-
iat: payload.iat,
|
|
123
|
-
exp: payload.exp
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/core/internal/utils/encoding.ts
|
|
128
|
-
function createApiKey(clientKey, secretKey) {
|
|
129
|
-
if (!clientKey || !secretKey) {
|
|
130
|
-
throw new Error("clientKey and secretKey are required.");
|
|
131
|
-
}
|
|
132
|
-
if (typeof Buffer !== "undefined") {
|
|
133
|
-
return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
|
|
134
|
-
}
|
|
135
|
-
return btoa(`${clientKey}:${secretKey}`);
|
|
136
|
-
}
|
|
137
|
-
function parseApiKey(apiKey) {
|
|
138
|
-
if (!apiKey) {
|
|
139
|
-
throw new Error("apiKey is required.");
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
let decoded;
|
|
143
|
-
if (typeof Buffer !== "undefined") {
|
|
144
|
-
decoded = Buffer.from(apiKey, "base64").toString("utf-8");
|
|
145
|
-
} else {
|
|
146
|
-
decoded = atob(apiKey);
|
|
147
|
-
}
|
|
148
|
-
const colonIndex = decoded.indexOf(":");
|
|
149
|
-
if (colonIndex === -1) {
|
|
150
|
-
throw new Error("Invalid format: missing colon separator");
|
|
151
|
-
}
|
|
152
|
-
const clientKey = decoded.substring(0, colonIndex);
|
|
153
|
-
const secretKey = decoded.substring(colonIndex + 1);
|
|
154
|
-
if (!clientKey || !secretKey) {
|
|
155
|
-
throw new Error("Invalid format: empty clientKey or secretKey");
|
|
156
|
-
}
|
|
157
|
-
return { clientKey, secretKey };
|
|
158
|
-
} catch {
|
|
159
|
-
throw new Error(
|
|
160
|
-
'Invalid API key. Expected Base64 encoded "clientKey:secretKey"'
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
81
|
// src/core/internal/errors/index.ts
|
|
166
82
|
var SDKError = class extends Error {
|
|
167
83
|
constructor(code, message, status, details, userMessage, suggestion) {
|
|
@@ -282,7 +198,6 @@ function isUsageLimitError(error) {
|
|
|
282
198
|
return error instanceof UsageLimitError;
|
|
283
199
|
}
|
|
284
200
|
var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
|
|
285
|
-
var createValidationError = (message, details, userMessage, suggestion) => new ValidationError(message, details, userMessage, suggestion);
|
|
286
201
|
var createApiError = (message, status, details, userMessage, suggestion) => new ApiError(message, status, details, userMessage, suggestion);
|
|
287
202
|
var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
|
|
288
203
|
var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
|
|
@@ -376,24 +291,24 @@ async function delay(ms) {
|
|
|
376
291
|
}
|
|
377
292
|
async function httpFetch(url, options) {
|
|
378
293
|
const {
|
|
379
|
-
|
|
294
|
+
publishableKey,
|
|
380
295
|
secretKey,
|
|
381
296
|
customerToken,
|
|
382
297
|
timeout = DEFAULT_TIMEOUT,
|
|
383
|
-
baseUrl = resolveApiUrl(),
|
|
384
298
|
debug,
|
|
385
299
|
retry,
|
|
386
300
|
onUnauthorized,
|
|
387
301
|
...requestInit
|
|
388
302
|
} = options || {};
|
|
303
|
+
const baseUrl = resolveApiUrl();
|
|
389
304
|
const retryConfig = {
|
|
390
305
|
maxRetries: retry?.maxRetries ?? 3,
|
|
391
306
|
retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
|
|
392
307
|
retryDelay: retry?.retryDelay ?? ((attempt) => Math.min(1e3 * 2 ** attempt, 1e4))
|
|
393
308
|
};
|
|
394
309
|
let authToken;
|
|
395
|
-
if (secretKey
|
|
396
|
-
authToken =
|
|
310
|
+
if (secretKey) {
|
|
311
|
+
authToken = secretKey;
|
|
397
312
|
} else if (customerToken) {
|
|
398
313
|
authToken = customerToken;
|
|
399
314
|
}
|
|
@@ -402,8 +317,8 @@ async function httpFetch(url, options) {
|
|
|
402
317
|
for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt++) {
|
|
403
318
|
try {
|
|
404
319
|
const headers = new Headers(requestInit.headers);
|
|
405
|
-
if (
|
|
406
|
-
headers.set("X-
|
|
320
|
+
if (publishableKey) {
|
|
321
|
+
headers.set("X-Publishable-Key", publishableKey);
|
|
407
322
|
}
|
|
408
323
|
if (authToken) {
|
|
409
324
|
headers.set("Authorization", `Bearer ${authToken}`);
|
|
@@ -594,23 +509,18 @@ async function parseApiResponse(response, endpoint) {
|
|
|
594
509
|
// src/core/api/base-api.ts
|
|
595
510
|
var BaseApi = class {
|
|
596
511
|
constructor(apiName, options) {
|
|
597
|
-
if (!options.clientKey) {
|
|
598
|
-
throw createConfigError(`clientKey is required for ${apiName}.`);
|
|
599
|
-
}
|
|
600
512
|
if (!options.secretKey) {
|
|
601
513
|
throw createConfigError(`secretKey is required for ${apiName}.`);
|
|
602
514
|
}
|
|
603
|
-
this.
|
|
515
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
604
516
|
this.secretKey = options.secretKey;
|
|
605
|
-
this.baseUrl = options.baseUrl;
|
|
606
517
|
}
|
|
607
518
|
async request(endpoint, body, options) {
|
|
608
519
|
const method = options?.method ?? "POST";
|
|
609
520
|
const response = await httpFetch(endpoint, {
|
|
610
521
|
method,
|
|
611
|
-
|
|
522
|
+
publishableKey: this.publishableKey,
|
|
612
523
|
secretKey: this.secretKey,
|
|
613
|
-
baseUrl: this.baseUrl,
|
|
614
524
|
...body !== void 0 && { body: JSON.stringify(body) },
|
|
615
525
|
...options?.headers && { headers: options.headers }
|
|
616
526
|
});
|
|
@@ -668,39 +578,28 @@ var OrderApi = class extends BaseApi {
|
|
|
668
578
|
params
|
|
669
579
|
);
|
|
670
580
|
}
|
|
671
|
-
createExchange(params) {
|
|
672
|
-
return this.request("/api/exchanges/create", params);
|
|
673
|
-
}
|
|
674
|
-
updateExchange(params) {
|
|
675
|
-
return this.request("/api/exchanges/update", params);
|
|
676
|
-
}
|
|
677
581
|
};
|
|
678
582
|
|
|
679
583
|
// src/core/api/cart-api.ts
|
|
680
584
|
var CartApi = class {
|
|
681
585
|
constructor(options) {
|
|
682
|
-
if (!options.clientKey) {
|
|
683
|
-
throw createConfigError("clientKey is required for CartApi.");
|
|
684
|
-
}
|
|
685
586
|
if (!options.secretKey && !options.customerToken) {
|
|
686
587
|
throw createConfigError(
|
|
687
588
|
"Either secretKey or customerToken is required for CartApi."
|
|
688
589
|
);
|
|
689
590
|
}
|
|
690
|
-
this.
|
|
591
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
691
592
|
this.secretKey = options.secretKey;
|
|
692
593
|
this.customerToken = options.customerToken;
|
|
693
|
-
this.baseUrl = options.baseUrl;
|
|
694
594
|
this.onUnauthorized = options.onUnauthorized;
|
|
695
595
|
}
|
|
696
596
|
async execute(endpoint, method, body) {
|
|
697
597
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
698
598
|
const response = await httpFetch(endpoint, {
|
|
699
599
|
method,
|
|
700
|
-
|
|
600
|
+
publishableKey: this.publishableKey,
|
|
701
601
|
secretKey: this.secretKey,
|
|
702
602
|
customerToken: token ?? void 0,
|
|
703
|
-
baseUrl: this.baseUrl,
|
|
704
603
|
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
705
604
|
...body !== void 0 && { body: JSON.stringify(body) }
|
|
706
605
|
});
|
|
@@ -947,21 +846,16 @@ var CollectionQueryBuilder = class {
|
|
|
947
846
|
// src/core/collection/http-client.ts
|
|
948
847
|
var import_qs_esm = require("qs-esm");
|
|
949
848
|
var HttpClient = class {
|
|
950
|
-
constructor(
|
|
951
|
-
|
|
952
|
-
throw createValidationError("clientKey is required.");
|
|
953
|
-
}
|
|
954
|
-
this.clientKey = clientKey;
|
|
849
|
+
constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized) {
|
|
850
|
+
this.publishableKey = publishableKey;
|
|
955
851
|
this.secretKey = secretKey;
|
|
956
|
-
this.baseUrl = baseUrl;
|
|
957
852
|
this.getCustomerToken = getCustomerToken;
|
|
958
853
|
this.onUnauthorized = onUnauthorized;
|
|
959
854
|
}
|
|
960
855
|
get defaultOptions() {
|
|
961
856
|
const opts = {
|
|
962
|
-
|
|
963
|
-
secretKey: this.secretKey
|
|
964
|
-
baseUrl: this.baseUrl
|
|
857
|
+
publishableKey: this.publishableKey,
|
|
858
|
+
secretKey: this.secretKey
|
|
965
859
|
};
|
|
966
860
|
const token = this.getCustomerToken?.();
|
|
967
861
|
if (token) {
|
|
@@ -1076,9 +970,6 @@ function buildPayloadFormData(data, file, filename) {
|
|
|
1076
970
|
return formData;
|
|
1077
971
|
}
|
|
1078
972
|
var CollectionClient = class extends HttpClient {
|
|
1079
|
-
constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
|
|
1080
|
-
super(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized);
|
|
1081
|
-
}
|
|
1082
973
|
from(collection) {
|
|
1083
974
|
return new CollectionQueryBuilder(this, collection);
|
|
1084
975
|
}
|
|
@@ -1214,17 +1105,16 @@ var COLLECTIONS = [
|
|
|
1214
1105
|
"products",
|
|
1215
1106
|
"product-variants",
|
|
1216
1107
|
"product-options",
|
|
1108
|
+
"product-option-values",
|
|
1217
1109
|
"product-categories",
|
|
1218
1110
|
"product-tags",
|
|
1219
1111
|
"product-collections",
|
|
1220
1112
|
"brands",
|
|
1221
1113
|
"brand-logos",
|
|
1222
1114
|
"orders",
|
|
1223
|
-
"order-
|
|
1115
|
+
"order-items",
|
|
1224
1116
|
"returns",
|
|
1225
|
-
"return-
|
|
1226
|
-
"exchanges",
|
|
1227
|
-
"exchange-products",
|
|
1117
|
+
"return-items",
|
|
1228
1118
|
"fulfillments",
|
|
1229
1119
|
"fulfillment-items",
|
|
1230
1120
|
"transactions",
|
|
@@ -1281,23 +1171,18 @@ var COLLECTIONS = [
|
|
|
1281
1171
|
// src/core/community/community-client.ts
|
|
1282
1172
|
var CommunityClient = class {
|
|
1283
1173
|
constructor(options) {
|
|
1284
|
-
|
|
1285
|
-
throw createConfigError("clientKey is required for CommunityClient.");
|
|
1286
|
-
}
|
|
1287
|
-
this.clientKey = options.clientKey;
|
|
1174
|
+
this.publishableKey = options.publishableKey ?? "";
|
|
1288
1175
|
this.secretKey = options.secretKey;
|
|
1289
1176
|
this.customerToken = options.customerToken;
|
|
1290
|
-
this.baseUrl = options.baseUrl;
|
|
1291
1177
|
this.onUnauthorized = options.onUnauthorized;
|
|
1292
1178
|
}
|
|
1293
1179
|
async execute(endpoint, method, body) {
|
|
1294
1180
|
const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
|
|
1295
1181
|
const response = await httpFetch(endpoint, {
|
|
1296
1182
|
method,
|
|
1297
|
-
|
|
1183
|
+
publishableKey: this.publishableKey,
|
|
1298
1184
|
secretKey: this.secretKey,
|
|
1299
1185
|
customerToken: token ?? void 0,
|
|
1300
|
-
baseUrl: this.baseUrl,
|
|
1301
1186
|
...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
|
|
1302
1187
|
...body !== void 0 && { body: JSON.stringify(body) }
|
|
1303
1188
|
});
|
|
@@ -1345,32 +1230,32 @@ var CommunityClient = class {
|
|
|
1345
1230
|
}
|
|
1346
1231
|
// Comments
|
|
1347
1232
|
createComment(params) {
|
|
1348
|
-
const { threadId, parentId,
|
|
1349
|
-
const body = { thread: threadId,
|
|
1233
|
+
const { threadId, parentId, body: commentBody } = params;
|
|
1234
|
+
const body = { thread: threadId, body: commentBody };
|
|
1350
1235
|
if (parentId !== void 0) {
|
|
1351
1236
|
body.parent = parentId;
|
|
1352
1237
|
}
|
|
1353
1238
|
return this.execute("/api/comments", "POST", body);
|
|
1354
1239
|
}
|
|
1355
1240
|
listComments(params) {
|
|
1356
|
-
const { threadId, page, limit,
|
|
1241
|
+
const { threadId, page, limit, rootComment } = params;
|
|
1357
1242
|
const urlParams = new URLSearchParams();
|
|
1358
1243
|
urlParams.set("where[thread][equals]", threadId);
|
|
1359
1244
|
urlParams.set("sort", "-createdAt");
|
|
1360
1245
|
if (limit !== void 0) urlParams.set("limit", String(limit));
|
|
1361
1246
|
if (page !== void 0) urlParams.set("page", String(page));
|
|
1362
|
-
if (
|
|
1247
|
+
if (rootComment !== void 0) urlParams.set("where[rootComment][equals]", rootComment);
|
|
1363
1248
|
return this.execute(
|
|
1364
1249
|
`/api/comments?${urlParams.toString()}`,
|
|
1365
1250
|
"GET"
|
|
1366
1251
|
);
|
|
1367
1252
|
}
|
|
1368
1253
|
updateComment(params) {
|
|
1369
|
-
const { commentId,
|
|
1254
|
+
const { commentId, body } = params;
|
|
1370
1255
|
return this.execute(
|
|
1371
1256
|
`/api/comments/${commentId}`,
|
|
1372
1257
|
"PATCH",
|
|
1373
|
-
{
|
|
1258
|
+
{ body }
|
|
1374
1259
|
);
|
|
1375
1260
|
}
|
|
1376
1261
|
deleteComment(params) {
|
|
@@ -1474,10 +1359,10 @@ function safeGetItem(key) {
|
|
|
1474
1359
|
}
|
|
1475
1360
|
}
|
|
1476
1361
|
var CustomerAuth = class {
|
|
1477
|
-
constructor(
|
|
1362
|
+
constructor(publishableKey, options) {
|
|
1478
1363
|
this.refreshPromise = null;
|
|
1479
|
-
this.
|
|
1480
|
-
this.baseUrl =
|
|
1364
|
+
this.publishableKey = publishableKey;
|
|
1365
|
+
this.baseUrl = resolveApiUrl();
|
|
1481
1366
|
const persist = options?.persist ?? true;
|
|
1482
1367
|
if (persist) {
|
|
1483
1368
|
const key = typeof persist === "string" ? persist : "customer-token";
|
|
@@ -1663,7 +1548,7 @@ var CustomerAuth = class {
|
|
|
1663
1548
|
*/
|
|
1664
1549
|
async requestJson(path, init) {
|
|
1665
1550
|
const headers = new Headers(init.headers);
|
|
1666
|
-
headers.set("X-
|
|
1551
|
+
headers.set("X-Publishable-Key", this.publishableKey);
|
|
1667
1552
|
if (!headers.has("Content-Type") && init.body) {
|
|
1668
1553
|
headers.set("Content-Type", "application/json");
|
|
1669
1554
|
}
|
|
@@ -2143,11 +2028,11 @@ var QueryHooks = class extends CollectionHooks {
|
|
|
2143
2028
|
// src/core/client/client.ts
|
|
2144
2029
|
var Client = class {
|
|
2145
2030
|
constructor(options) {
|
|
2146
|
-
|
|
2147
|
-
|
|
2031
|
+
const publishableKey = options.publishableKey;
|
|
2032
|
+
if (!publishableKey) {
|
|
2033
|
+
throw createConfigError("publishableKey is required.");
|
|
2148
2034
|
}
|
|
2149
|
-
this.config = { ...options };
|
|
2150
|
-
this.baseUrl = resolveApiUrl();
|
|
2035
|
+
this.config = { ...options, publishableKey };
|
|
2151
2036
|
const metadata = {
|
|
2152
2037
|
timestamp: Date.now(),
|
|
2153
2038
|
userAgent: typeof window !== "undefined" ? window.navigator?.userAgent : "Node.js"
|
|
@@ -2155,8 +2040,7 @@ var Client = class {
|
|
|
2155
2040
|
this.state = { metadata };
|
|
2156
2041
|
this.queryClient = getQueryClient();
|
|
2157
2042
|
this.customer = new CustomerAuth(
|
|
2158
|
-
this.config.
|
|
2159
|
-
this.baseUrl,
|
|
2043
|
+
this.config.publishableKey,
|
|
2160
2044
|
options.customer
|
|
2161
2045
|
);
|
|
2162
2046
|
const onUnauthorized = async () => {
|
|
@@ -2168,21 +2052,18 @@ var Client = class {
|
|
|
2168
2052
|
}
|
|
2169
2053
|
};
|
|
2170
2054
|
this.cart = new CartApi({
|
|
2171
|
-
|
|
2055
|
+
publishableKey: this.config.publishableKey,
|
|
2172
2056
|
customerToken: () => this.customer.getToken(),
|
|
2173
|
-
baseUrl: this.baseUrl,
|
|
2174
2057
|
onUnauthorized
|
|
2175
2058
|
});
|
|
2176
2059
|
this.community = new CommunityClient({
|
|
2177
|
-
|
|
2060
|
+
publishableKey: this.config.publishableKey,
|
|
2178
2061
|
customerToken: () => this.customer.getToken(),
|
|
2179
|
-
baseUrl: this.baseUrl,
|
|
2180
2062
|
onUnauthorized
|
|
2181
2063
|
});
|
|
2182
2064
|
this.collections = new CollectionClient(
|
|
2183
|
-
this.config.
|
|
2065
|
+
this.config.publishableKey,
|
|
2184
2066
|
void 0,
|
|
2185
|
-
this.baseUrl,
|
|
2186
2067
|
() => this.customer.getToken(),
|
|
2187
2068
|
onUnauthorized
|
|
2188
2069
|
);
|
|
@@ -2214,43 +2095,39 @@ var ServerClient = class {
|
|
|
2214
2095
|
"ServerClient must not be used in a browser environment. This risks exposing your secretKey in client bundles. Use createClient() for browser code instead."
|
|
2215
2096
|
);
|
|
2216
2097
|
}
|
|
2217
|
-
if (!options.clientKey) {
|
|
2218
|
-
throw createConfigError("clientKey is required.");
|
|
2219
|
-
}
|
|
2220
2098
|
if (!options.secretKey) {
|
|
2221
2099
|
throw createConfigError("secretKey is required.");
|
|
2222
2100
|
}
|
|
2223
|
-
|
|
2224
|
-
|
|
2101
|
+
if (!options.publishableKey) {
|
|
2102
|
+
throw createConfigError(
|
|
2103
|
+
"publishableKey is required. It is used for rate limiting and monthly quota enforcement via the X-Publishable-Key header. Get it from Console > Settings > API Keys."
|
|
2104
|
+
);
|
|
2105
|
+
}
|
|
2106
|
+
this.config = { ...options, publishableKey: options.publishableKey };
|
|
2225
2107
|
const metadata = {
|
|
2226
2108
|
timestamp: Date.now(),
|
|
2227
2109
|
userAgent: "Node.js"
|
|
2228
2110
|
};
|
|
2229
2111
|
this.state = { metadata };
|
|
2230
2112
|
this.api = new OrderApi({
|
|
2231
|
-
|
|
2232
|
-
secretKey: this.config.secretKey
|
|
2233
|
-
baseUrl: this.baseUrl
|
|
2113
|
+
publishableKey: this.config.publishableKey,
|
|
2114
|
+
secretKey: this.config.secretKey
|
|
2234
2115
|
});
|
|
2235
2116
|
this.cart = new CartApi({
|
|
2236
|
-
|
|
2237
|
-
secretKey: this.config.secretKey
|
|
2238
|
-
baseUrl: this.baseUrl
|
|
2117
|
+
publishableKey: this.config.publishableKey,
|
|
2118
|
+
secretKey: this.config.secretKey
|
|
2239
2119
|
});
|
|
2240
2120
|
this.community = new CommunityClient({
|
|
2241
|
-
|
|
2242
|
-
secretKey: this.config.secretKey
|
|
2243
|
-
baseUrl: this.baseUrl
|
|
2121
|
+
publishableKey: this.config.publishableKey,
|
|
2122
|
+
secretKey: this.config.secretKey
|
|
2244
2123
|
});
|
|
2245
2124
|
this.product = new ProductApi({
|
|
2246
|
-
|
|
2247
|
-
secretKey: this.config.secretKey
|
|
2248
|
-
baseUrl: this.baseUrl
|
|
2125
|
+
publishableKey: this.config.publishableKey,
|
|
2126
|
+
secretKey: this.config.secretKey
|
|
2249
2127
|
});
|
|
2250
2128
|
this.collections = new CollectionClient(
|
|
2251
|
-
this.config.
|
|
2252
|
-
this.config.secretKey
|
|
2253
|
-
this.baseUrl
|
|
2129
|
+
this.config.publishableKey,
|
|
2130
|
+
this.config.secretKey
|
|
2254
2131
|
);
|
|
2255
2132
|
this.queryClient = getQueryClient();
|
|
2256
2133
|
this.query = new QueryHooks(this.queryClient, this.collections);
|
|
@@ -2276,9 +2153,9 @@ var MAX_RECONNECT_DELAY = 3e4;
|
|
|
2276
2153
|
var RECONNECT_BACKOFF_FACTOR = 2;
|
|
2277
2154
|
var MAX_NO_TOKEN_RETRIES = 5;
|
|
2278
2155
|
var RealtimeConnection = class {
|
|
2279
|
-
constructor(baseUrl,
|
|
2156
|
+
constructor(baseUrl, publishableKey, getToken, collections) {
|
|
2280
2157
|
this.baseUrl = baseUrl;
|
|
2281
|
-
this.
|
|
2158
|
+
this.publishableKey = publishableKey;
|
|
2282
2159
|
this.getToken = getToken;
|
|
2283
2160
|
this.collections = collections;
|
|
2284
2161
|
this.abortController = null;
|
|
@@ -2331,7 +2208,7 @@ var RealtimeConnection = class {
|
|
|
2331
2208
|
try {
|
|
2332
2209
|
const response = await fetch(url, {
|
|
2333
2210
|
headers: {
|
|
2334
|
-
"X-
|
|
2211
|
+
"X-Publishable-Key": this.publishableKey,
|
|
2335
2212
|
Authorization: `Bearer ${token}`
|
|
2336
2213
|
},
|
|
2337
2214
|
signal
|