@01.software/sdk 0.8.0 → 0.10.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.
Files changed (48) hide show
  1. package/README.md +23 -25
  2. package/dist/{const-dv0zuAxG.d.cts → const-Dmgge6oQ.d.ts} +2 -2
  3. package/dist/{const-CCh99Gxu.d.ts → const-k0fqIBda.d.cts} +2 -2
  4. package/dist/index.cjs +52 -167
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +22 -34
  7. package/dist/index.d.ts +22 -34
  8. package/dist/index.js +52 -167
  9. package/dist/index.js.map +1 -1
  10. package/dist/{payload-types-FfZ2Zxp1.d.cts → payload-types-D0zFPijW.d.cts} +306 -112
  11. package/dist/{payload-types-FfZ2Zxp1.d.ts → payload-types-D0zFPijW.d.ts} +306 -112
  12. package/dist/{realtime-DupPIYx-.d.cts → realtime-D7HtUpqt.d.cts} +2 -2
  13. package/dist/{realtime-DupPIYx-.d.ts → realtime-D7HtUpqt.d.ts} +2 -2
  14. package/dist/realtime.cjs +8 -7
  15. package/dist/realtime.cjs.map +1 -1
  16. package/dist/realtime.d.cts +6 -6
  17. package/dist/realtime.d.ts +6 -6
  18. package/dist/realtime.js +8 -7
  19. package/dist/realtime.js.map +1 -1
  20. package/dist/{server-DxhuG-_s.d.cts → server-JR9TvKZ5.d.cts} +0 -2
  21. package/dist/{server-DxhuG-_s.d.ts → server-JR9TvKZ5.d.ts} +0 -2
  22. package/dist/ui/canvas/server.cjs +1 -2
  23. package/dist/ui/canvas/server.cjs.map +1 -1
  24. package/dist/ui/canvas/server.d.cts +1 -1
  25. package/dist/ui/canvas/server.d.ts +1 -1
  26. package/dist/ui/canvas/server.js +1 -2
  27. package/dist/ui/canvas/server.js.map +1 -1
  28. package/dist/ui/canvas.cjs +1 -2
  29. package/dist/ui/canvas.cjs.map +1 -1
  30. package/dist/ui/canvas.d.cts +2 -2
  31. package/dist/ui/canvas.d.ts +2 -2
  32. package/dist/ui/canvas.js +1 -2
  33. package/dist/ui/canvas.js.map +1 -1
  34. package/dist/ui/form.d.cts +1 -1
  35. package/dist/ui/form.d.ts +1 -1
  36. package/dist/ui/video.d.cts +1 -1
  37. package/dist/ui/video.d.ts +1 -1
  38. package/dist/{webhook-t7JGFLKQ.d.cts → webhook-DXr8B9E6.d.cts} +2 -2
  39. package/dist/{webhook-B9MDrH22.d.ts → webhook-caDRhnd7.d.ts} +2 -2
  40. package/dist/webhook.d.cts +3 -3
  41. package/dist/webhook.d.ts +3 -3
  42. package/package.json +1 -11
  43. package/dist/auth.cjs +0 -109
  44. package/dist/auth.cjs.map +0 -1
  45. package/dist/auth.d.cts +0 -36
  46. package/dist/auth.d.ts +0 -36
  47. package/dist/auth.js +0 -86
  48. package/dist/auth.js.map +0 -1
package/README.md CHANGED
@@ -20,7 +20,7 @@ pnpm add @01.software/sdk
20
20
  - Customer auth hooks (useCustomerMe, useCustomerLogin, etc.) with cache management
21
21
  - Automatic retry with exponential backoff (non-retryable: 401, 403, 404, 422)
22
22
  - Webhook handling with HMAC-SHA256 signature verification
23
- - Sub-path imports (`./auth`, `./webhook`, `./components`) for tree-shaking
23
+ - Sub-path imports (`./webhook`, `./realtime`, `./ui/*`) for tree-shaking
24
24
  - Type-safe read-only `from()` for Client (compile-time write prevention)
25
25
 
26
26
  ### Sub-path Imports
@@ -29,19 +29,15 @@ 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 & API Key utilities (smaller bundle)
33
- import {
34
- createServerToken,
35
- verifyServerToken,
36
- createApiKey,
37
- } from '@01.software/sdk/auth'
38
-
39
32
  // Webhook only - webhook handlers
40
33
  import {
41
34
  handleWebhook,
42
35
  createTypedWebhookHandler,
43
36
  } from '@01.software/sdk/webhook'
44
37
 
38
+ // Realtime only
39
+ import { createRealtimeClient } from '@01.software/sdk/realtime'
40
+
45
41
  // Components - sub-path imports per domain
46
42
  import { RichTextContent } from '@01.software/sdk/ui/rich-text'
47
43
  import { Image } from '@01.software/sdk/ui/image'
@@ -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
- clientKey: process.env.NEXT_PUBLIC_SOFTWARE_CLIENT_KEY,
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
- clientKey: process.env.NEXT_PUBLIC_SOFTWARE_CLIENT_KEY,
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
- clientKey: string, // Required
102
+ publishableKey: string, // Required
107
103
  })
108
104
  ```
109
105
 
110
- | Option | Type | Description |
111
- | ----------- | -------- | ---------------------------- |
112
- | `clientKey` | `string` | API client key |
113
- | `secretKey` | `string` | API secret key (server only) |
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
- clientKey: process.env.NEXT_PUBLIC_SOFTWARE_CLIENT_KEY,
310
+ publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY,
315
311
  customer: { persist: true },
316
312
  })
317
313
 
@@ -427,13 +423,13 @@ const handler = createTypedWebhookHandler('orders', async (event) => {
427
423
  | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
428
424
  | Tenant | `tenants`, `tenant-metadata`, `tenant-logos` |
429
425
  | Images | `images` (unified), `brand-logos` |
430
- | Products | `products`, `product-variants`, `product-options`, `product-categories`, `product-tags`, `product-collections`, `brands` |
431
- | Orders | `orders`, `order-products`, `returns`, `return-products`, `exchanges`, `exchange-products`, `fulfillments`, `fulfillment-items`, `transactions` |
426
+ | Products | `products`, `product-variants`, `product-options`, `product-option-values`, `product-categories`, `product-tags`, `product-collections`, `brands`, `brand-logos` |
427
+ | Orders | `orders`, `order-items`, `returns`, `return-items`, `fulfillments`, `fulfillment-items`, `transactions`, `order-status-logs` |
432
428
  | Customers | `customers`, `customer-addresses`, `customer-groups` |
433
429
  | Carts | `carts`, `cart-items` |
434
430
  | Commerce | `discounts`, `shipping-policies` |
435
- | Content | `posts`, `post-categories`, `post-tags`, `documents`, `document-categories`, `document-types` |
436
- | Playlists | `playlists`, `playlist-categories`, `playlist-tags`, `musics` |
431
+ | Content | `posts`, `post-authors`, `post-categories`, `post-tags`, `documents`, `document-categories`, `document-types` |
432
+ | Playlists | `playlists`, `playlist-categories`, `playlist-tags`, `tracks`, `playlist-tracks`, `track-categories`, `track-tags` |
437
433
  | Galleries | `galleries`, `gallery-items`, `gallery-categories`, `gallery-tags` |
438
434
  | Canvas | `canvases`, `canvas-node-types`, `canvas-edge-types`, `canvas-categories`, `canvas-tags` |
439
435
  | Videos | `videos`, `video-categories`, `video-tags` |
@@ -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:** `objectFor` is still available but deprecated. Use `resolveRelation` instead.
451
+ > **Note:** Prefer `resolveRelation`. It covers the same normalization use case directly.
456
452
 
457
453
  ### generateOrderNumber
458
454
 
@@ -539,12 +535,14 @@ Error classes: `SDKError`, `ApiError`, `NetworkError`, `ValidationError`, `Confi
539
535
  ## Environment Variables
540
536
 
541
537
  ```bash
542
- NEXT_PUBLIC_SOFTWARE_CLIENT_KEY=your_client_key
543
- SOFTWARE_SECRET_KEY=your_secret_key # Server only
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.
547
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
+
548
546
  ## Migration Guide
549
547
 
550
548
  ### v0.8.0 (Breaking Changes)
@@ -581,4 +579,4 @@ SOFTWARE_SECRET_KEY=your_secret_key # Server only
581
579
  - Added: `product-option-values`
582
580
 
583
581
  **Boolean field renames** (6 collections):
584
- - `status: 'active' | 'inactive'` → `isActive: boolean` on Musics, Forms, PostAuthors, CustomerGroups, ShippingPolicies, ProductVariants
582
+ - `status: 'active' | 'inactive'` → `isActive: boolean` on Forms, PostAuthors, CustomerGroups, ShippingPolicies, ProductVariants
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-FfZ2Zxp1.cjs';
1
+ import { C as Config } from './payload-types-D0zFPijW.js';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -9,7 +9,7 @@ type Collection = keyof Config['collections'];
9
9
  * Array of all public collection names for runtime use (e.g., Zod enum validation).
10
10
  * This is the single source of truth for which collections are publicly accessible via SDK.
11
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"];
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", "tracks", "playlist-tracks", "track-categories", "track-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
13
  /**
14
14
  * Public collections available for SDK access.
15
15
  * Derived from the COLLECTIONS array (single source of truth).
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-FfZ2Zxp1.js';
1
+ import { C as Config } from './payload-types-D0zFPijW.cjs';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -9,7 +9,7 @@ type Collection = keyof Config['collections'];
9
9
  * Array of all public collection names for runtime use (e.g., Zod enum validation).
10
10
  * This is the single source of truth for which collections are publicly accessible via SDK.
11
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"];
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", "tracks", "playlist-tracks", "track-categories", "track-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
13
  /**
14
14
  * Public collections available for SDK access.
15
15
  * Derived from the COLLECTIONS array (single source of truth).
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
- parseApiKey: () => parseApiKey,
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
- clientKey,
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 && clientKey) {
396
- authToken = await createServerToken(clientKey, secretKey);
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 (clientKey) {
406
- headers.set("X-Client-Key", clientKey);
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.clientKey = options.clientKey;
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
- clientKey: this.clientKey,
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
  });
@@ -673,28 +583,23 @@ var OrderApi = class extends BaseApi {
673
583
  // src/core/api/cart-api.ts
674
584
  var CartApi = class {
675
585
  constructor(options) {
676
- if (!options.clientKey) {
677
- throw createConfigError("clientKey is required for CartApi.");
678
- }
679
586
  if (!options.secretKey && !options.customerToken) {
680
587
  throw createConfigError(
681
588
  "Either secretKey or customerToken is required for CartApi."
682
589
  );
683
590
  }
684
- this.clientKey = options.clientKey;
591
+ this.publishableKey = options.publishableKey ?? "";
685
592
  this.secretKey = options.secretKey;
686
593
  this.customerToken = options.customerToken;
687
- this.baseUrl = options.baseUrl;
688
594
  this.onUnauthorized = options.onUnauthorized;
689
595
  }
690
596
  async execute(endpoint, method, body) {
691
597
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
692
598
  const response = await httpFetch(endpoint, {
693
599
  method,
694
- clientKey: this.clientKey,
600
+ publishableKey: this.publishableKey,
695
601
  secretKey: this.secretKey,
696
602
  customerToken: token ?? void 0,
697
- baseUrl: this.baseUrl,
698
603
  ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
699
604
  ...body !== void 0 && { body: JSON.stringify(body) }
700
605
  });
@@ -941,21 +846,16 @@ var CollectionQueryBuilder = class {
941
846
  // src/core/collection/http-client.ts
942
847
  var import_qs_esm = require("qs-esm");
943
848
  var HttpClient = class {
944
- constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
945
- if (!clientKey) {
946
- throw createValidationError("clientKey is required.");
947
- }
948
- this.clientKey = clientKey;
849
+ constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized) {
850
+ this.publishableKey = publishableKey;
949
851
  this.secretKey = secretKey;
950
- this.baseUrl = baseUrl;
951
852
  this.getCustomerToken = getCustomerToken;
952
853
  this.onUnauthorized = onUnauthorized;
953
854
  }
954
855
  get defaultOptions() {
955
856
  const opts = {
956
- clientKey: this.clientKey,
957
- secretKey: this.secretKey,
958
- baseUrl: this.baseUrl
857
+ publishableKey: this.publishableKey,
858
+ secretKey: this.secretKey
959
859
  };
960
860
  const token = this.getCustomerToken?.();
961
861
  if (token) {
@@ -1070,9 +970,6 @@ function buildPayloadFormData(data, file, filename) {
1070
970
  return formData;
1071
971
  }
1072
972
  var CollectionClient = class extends HttpClient {
1073
- constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
1074
- super(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized);
1075
- }
1076
973
  from(collection) {
1077
974
  return new CollectionQueryBuilder(this, collection);
1078
975
  }
@@ -1238,9 +1135,10 @@ var COLLECTIONS = [
1238
1135
  "playlists",
1239
1136
  "playlist-categories",
1240
1137
  "playlist-tags",
1241
- "musics",
1242
- "music-categories",
1243
- "music-tags",
1138
+ "tracks",
1139
+ "playlist-tracks",
1140
+ "track-categories",
1141
+ "track-tags",
1244
1142
  "galleries",
1245
1143
  "gallery-categories",
1246
1144
  "gallery-tags",
@@ -1274,23 +1172,18 @@ var COLLECTIONS = [
1274
1172
  // src/core/community/community-client.ts
1275
1173
  var CommunityClient = class {
1276
1174
  constructor(options) {
1277
- if (!options.clientKey) {
1278
- throw createConfigError("clientKey is required for CommunityClient.");
1279
- }
1280
- this.clientKey = options.clientKey;
1175
+ this.publishableKey = options.publishableKey ?? "";
1281
1176
  this.secretKey = options.secretKey;
1282
1177
  this.customerToken = options.customerToken;
1283
- this.baseUrl = options.baseUrl;
1284
1178
  this.onUnauthorized = options.onUnauthorized;
1285
1179
  }
1286
1180
  async execute(endpoint, method, body) {
1287
1181
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1288
1182
  const response = await httpFetch(endpoint, {
1289
1183
  method,
1290
- clientKey: this.clientKey,
1184
+ publishableKey: this.publishableKey,
1291
1185
  secretKey: this.secretKey,
1292
1186
  customerToken: token ?? void 0,
1293
- baseUrl: this.baseUrl,
1294
1187
  ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1295
1188
  ...body !== void 0 && { body: JSON.stringify(body) }
1296
1189
  });
@@ -1467,10 +1360,10 @@ function safeGetItem(key) {
1467
1360
  }
1468
1361
  }
1469
1362
  var CustomerAuth = class {
1470
- constructor(clientKey, baseUrl, options) {
1363
+ constructor(publishableKey, options) {
1471
1364
  this.refreshPromise = null;
1472
- this.clientKey = clientKey;
1473
- this.baseUrl = baseUrl;
1365
+ this.publishableKey = publishableKey;
1366
+ this.baseUrl = resolveApiUrl();
1474
1367
  const persist = options?.persist ?? true;
1475
1368
  if (persist) {
1476
1369
  const key = typeof persist === "string" ? persist : "customer-token";
@@ -1656,7 +1549,7 @@ var CustomerAuth = class {
1656
1549
  */
1657
1550
  async requestJson(path, init) {
1658
1551
  const headers = new Headers(init.headers);
1659
- headers.set("X-Client-Key", this.clientKey);
1552
+ headers.set("X-Publishable-Key", this.publishableKey);
1660
1553
  if (!headers.has("Content-Type") && init.body) {
1661
1554
  headers.set("Content-Type", "application/json");
1662
1555
  }
@@ -2136,11 +2029,11 @@ var QueryHooks = class extends CollectionHooks {
2136
2029
  // src/core/client/client.ts
2137
2030
  var Client = class {
2138
2031
  constructor(options) {
2139
- if (!options.clientKey) {
2140
- throw createConfigError("clientKey is required.");
2032
+ const publishableKey = options.publishableKey;
2033
+ if (!publishableKey) {
2034
+ throw createConfigError("publishableKey is required.");
2141
2035
  }
2142
- this.config = { ...options };
2143
- this.baseUrl = resolveApiUrl();
2036
+ this.config = { ...options, publishableKey };
2144
2037
  const metadata = {
2145
2038
  timestamp: Date.now(),
2146
2039
  userAgent: typeof window !== "undefined" ? window.navigator?.userAgent : "Node.js"
@@ -2148,8 +2041,7 @@ var Client = class {
2148
2041
  this.state = { metadata };
2149
2042
  this.queryClient = getQueryClient();
2150
2043
  this.customer = new CustomerAuth(
2151
- this.config.clientKey,
2152
- this.baseUrl,
2044
+ this.config.publishableKey,
2153
2045
  options.customer
2154
2046
  );
2155
2047
  const onUnauthorized = async () => {
@@ -2161,21 +2053,18 @@ var Client = class {
2161
2053
  }
2162
2054
  };
2163
2055
  this.cart = new CartApi({
2164
- clientKey: this.config.clientKey,
2056
+ publishableKey: this.config.publishableKey,
2165
2057
  customerToken: () => this.customer.getToken(),
2166
- baseUrl: this.baseUrl,
2167
2058
  onUnauthorized
2168
2059
  });
2169
2060
  this.community = new CommunityClient({
2170
- clientKey: this.config.clientKey,
2061
+ publishableKey: this.config.publishableKey,
2171
2062
  customerToken: () => this.customer.getToken(),
2172
- baseUrl: this.baseUrl,
2173
2063
  onUnauthorized
2174
2064
  });
2175
2065
  this.collections = new CollectionClient(
2176
- this.config.clientKey,
2066
+ this.config.publishableKey,
2177
2067
  void 0,
2178
- this.baseUrl,
2179
2068
  () => this.customer.getToken(),
2180
2069
  onUnauthorized
2181
2070
  );
@@ -2207,43 +2096,39 @@ var ServerClient = class {
2207
2096
  "ServerClient must not be used in a browser environment. This risks exposing your secretKey in client bundles. Use createClient() for browser code instead."
2208
2097
  );
2209
2098
  }
2210
- if (!options.clientKey) {
2211
- throw createConfigError("clientKey is required.");
2212
- }
2213
2099
  if (!options.secretKey) {
2214
2100
  throw createConfigError("secretKey is required.");
2215
2101
  }
2216
- this.config = { ...options };
2217
- this.baseUrl = resolveApiUrl();
2102
+ if (!options.publishableKey) {
2103
+ throw createConfigError(
2104
+ "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."
2105
+ );
2106
+ }
2107
+ this.config = { ...options, publishableKey: options.publishableKey };
2218
2108
  const metadata = {
2219
2109
  timestamp: Date.now(),
2220
2110
  userAgent: "Node.js"
2221
2111
  };
2222
2112
  this.state = { metadata };
2223
2113
  this.api = new OrderApi({
2224
- clientKey: this.config.clientKey,
2225
- secretKey: this.config.secretKey,
2226
- baseUrl: this.baseUrl
2114
+ publishableKey: this.config.publishableKey,
2115
+ secretKey: this.config.secretKey
2227
2116
  });
2228
2117
  this.cart = new CartApi({
2229
- clientKey: this.config.clientKey,
2230
- secretKey: this.config.secretKey,
2231
- baseUrl: this.baseUrl
2118
+ publishableKey: this.config.publishableKey,
2119
+ secretKey: this.config.secretKey
2232
2120
  });
2233
2121
  this.community = new CommunityClient({
2234
- clientKey: this.config.clientKey,
2235
- secretKey: this.config.secretKey,
2236
- baseUrl: this.baseUrl
2122
+ publishableKey: this.config.publishableKey,
2123
+ secretKey: this.config.secretKey
2237
2124
  });
2238
2125
  this.product = new ProductApi({
2239
- clientKey: this.config.clientKey,
2240
- secretKey: this.config.secretKey,
2241
- baseUrl: this.baseUrl
2126
+ publishableKey: this.config.publishableKey,
2127
+ secretKey: this.config.secretKey
2242
2128
  });
2243
2129
  this.collections = new CollectionClient(
2244
- this.config.clientKey,
2245
- this.config.secretKey,
2246
- this.baseUrl
2130
+ this.config.publishableKey,
2131
+ this.config.secretKey
2247
2132
  );
2248
2133
  this.queryClient = getQueryClient();
2249
2134
  this.query = new QueryHooks(this.queryClient, this.collections);
@@ -2269,9 +2154,9 @@ var MAX_RECONNECT_DELAY = 3e4;
2269
2154
  var RECONNECT_BACKOFF_FACTOR = 2;
2270
2155
  var MAX_NO_TOKEN_RETRIES = 5;
2271
2156
  var RealtimeConnection = class {
2272
- constructor(baseUrl, clientKey, getToken, collections) {
2157
+ constructor(baseUrl, publishableKey, getToken, collections) {
2273
2158
  this.baseUrl = baseUrl;
2274
- this.clientKey = clientKey;
2159
+ this.publishableKey = publishableKey;
2275
2160
  this.getToken = getToken;
2276
2161
  this.collections = collections;
2277
2162
  this.abortController = null;
@@ -2324,7 +2209,7 @@ var RealtimeConnection = class {
2324
2209
  try {
2325
2210
  const response = await fetch(url, {
2326
2211
  headers: {
2327
- "X-Client-Key": this.clientKey,
2212
+ "X-Publishable-Key": this.publishableKey,
2328
2213
  Authorization: `Bearer ${token}`
2329
2214
  },
2330
2215
  signal