@01.software/sdk 0.8.0 → 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.
Files changed (48) hide show
  1. package/README.md +16 -18
  2. package/dist/{const-dv0zuAxG.d.cts → const-DZ04SC2y.d.cts} +1 -1
  3. package/dist/{const-CCh99Gxu.d.ts → const-hXu9oG66.d.ts} +1 -1
  4. package/dist/index.cjs +48 -164
  5. package/dist/index.cjs.map +1 -1
  6. package/dist/index.d.cts +21 -33
  7. package/dist/index.d.ts +21 -33
  8. package/dist/index.js +48 -164
  9. package/dist/index.js.map +1 -1
  10. package/dist/{payload-types-FfZ2Zxp1.d.cts → payload-types-DICC2-Zr.d.cts} +120 -25
  11. package/dist/{payload-types-FfZ2Zxp1.d.ts → payload-types-DICC2-Zr.d.ts} +120 -25
  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-B9MDrH22.d.ts → webhook-BD9ivfyR.d.ts} +2 -2
  39. package/dist/{webhook-t7JGFLKQ.d.cts → webhook-D8ogsafv.d.cts} +2 -2
  40. package/dist/webhook.d.cts +3 -3
  41. package/dist/webhook.d.ts +3 -3
  42. package/package.json +3 -13
  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
@@ -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 & API Key utilities (smaller bundle)
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
- 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
 
@@ -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)
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-FfZ2Zxp1.cjs';
1
+ import { C as Config } from './payload-types-DICC2-Zr.cjs';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-FfZ2Zxp1.js';
1
+ import { C as Config } from './payload-types-DICC2-Zr.js';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
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
  }
@@ -1274,23 +1171,18 @@ var COLLECTIONS = [
1274
1171
  // src/core/community/community-client.ts
1275
1172
  var CommunityClient = class {
1276
1173
  constructor(options) {
1277
- if (!options.clientKey) {
1278
- throw createConfigError("clientKey is required for CommunityClient.");
1279
- }
1280
- this.clientKey = options.clientKey;
1174
+ this.publishableKey = options.publishableKey ?? "";
1281
1175
  this.secretKey = options.secretKey;
1282
1176
  this.customerToken = options.customerToken;
1283
- this.baseUrl = options.baseUrl;
1284
1177
  this.onUnauthorized = options.onUnauthorized;
1285
1178
  }
1286
1179
  async execute(endpoint, method, body) {
1287
1180
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1288
1181
  const response = await httpFetch(endpoint, {
1289
1182
  method,
1290
- clientKey: this.clientKey,
1183
+ publishableKey: this.publishableKey,
1291
1184
  secretKey: this.secretKey,
1292
1185
  customerToken: token ?? void 0,
1293
- baseUrl: this.baseUrl,
1294
1186
  ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1295
1187
  ...body !== void 0 && { body: JSON.stringify(body) }
1296
1188
  });
@@ -1467,10 +1359,10 @@ function safeGetItem(key) {
1467
1359
  }
1468
1360
  }
1469
1361
  var CustomerAuth = class {
1470
- constructor(clientKey, baseUrl, options) {
1362
+ constructor(publishableKey, options) {
1471
1363
  this.refreshPromise = null;
1472
- this.clientKey = clientKey;
1473
- this.baseUrl = baseUrl;
1364
+ this.publishableKey = publishableKey;
1365
+ this.baseUrl = resolveApiUrl();
1474
1366
  const persist = options?.persist ?? true;
1475
1367
  if (persist) {
1476
1368
  const key = typeof persist === "string" ? persist : "customer-token";
@@ -1656,7 +1548,7 @@ var CustomerAuth = class {
1656
1548
  */
1657
1549
  async requestJson(path, init) {
1658
1550
  const headers = new Headers(init.headers);
1659
- headers.set("X-Client-Key", this.clientKey);
1551
+ headers.set("X-Publishable-Key", this.publishableKey);
1660
1552
  if (!headers.has("Content-Type") && init.body) {
1661
1553
  headers.set("Content-Type", "application/json");
1662
1554
  }
@@ -2136,11 +2028,11 @@ var QueryHooks = class extends CollectionHooks {
2136
2028
  // src/core/client/client.ts
2137
2029
  var Client = class {
2138
2030
  constructor(options) {
2139
- if (!options.clientKey) {
2140
- throw createConfigError("clientKey is required.");
2031
+ const publishableKey = options.publishableKey;
2032
+ if (!publishableKey) {
2033
+ throw createConfigError("publishableKey is required.");
2141
2034
  }
2142
- this.config = { ...options };
2143
- this.baseUrl = resolveApiUrl();
2035
+ this.config = { ...options, publishableKey };
2144
2036
  const metadata = {
2145
2037
  timestamp: Date.now(),
2146
2038
  userAgent: typeof window !== "undefined" ? window.navigator?.userAgent : "Node.js"
@@ -2148,8 +2040,7 @@ var Client = class {
2148
2040
  this.state = { metadata };
2149
2041
  this.queryClient = getQueryClient();
2150
2042
  this.customer = new CustomerAuth(
2151
- this.config.clientKey,
2152
- this.baseUrl,
2043
+ this.config.publishableKey,
2153
2044
  options.customer
2154
2045
  );
2155
2046
  const onUnauthorized = async () => {
@@ -2161,21 +2052,18 @@ var Client = class {
2161
2052
  }
2162
2053
  };
2163
2054
  this.cart = new CartApi({
2164
- clientKey: this.config.clientKey,
2055
+ publishableKey: this.config.publishableKey,
2165
2056
  customerToken: () => this.customer.getToken(),
2166
- baseUrl: this.baseUrl,
2167
2057
  onUnauthorized
2168
2058
  });
2169
2059
  this.community = new CommunityClient({
2170
- clientKey: this.config.clientKey,
2060
+ publishableKey: this.config.publishableKey,
2171
2061
  customerToken: () => this.customer.getToken(),
2172
- baseUrl: this.baseUrl,
2173
2062
  onUnauthorized
2174
2063
  });
2175
2064
  this.collections = new CollectionClient(
2176
- this.config.clientKey,
2065
+ this.config.publishableKey,
2177
2066
  void 0,
2178
- this.baseUrl,
2179
2067
  () => this.customer.getToken(),
2180
2068
  onUnauthorized
2181
2069
  );
@@ -2207,43 +2095,39 @@ var ServerClient = class {
2207
2095
  "ServerClient must not be used in a browser environment. This risks exposing your secretKey in client bundles. Use createClient() for browser code instead."
2208
2096
  );
2209
2097
  }
2210
- if (!options.clientKey) {
2211
- throw createConfigError("clientKey is required.");
2212
- }
2213
2098
  if (!options.secretKey) {
2214
2099
  throw createConfigError("secretKey is required.");
2215
2100
  }
2216
- this.config = { ...options };
2217
- this.baseUrl = resolveApiUrl();
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 };
2218
2107
  const metadata = {
2219
2108
  timestamp: Date.now(),
2220
2109
  userAgent: "Node.js"
2221
2110
  };
2222
2111
  this.state = { metadata };
2223
2112
  this.api = new OrderApi({
2224
- clientKey: this.config.clientKey,
2225
- secretKey: this.config.secretKey,
2226
- baseUrl: this.baseUrl
2113
+ publishableKey: this.config.publishableKey,
2114
+ secretKey: this.config.secretKey
2227
2115
  });
2228
2116
  this.cart = new CartApi({
2229
- clientKey: this.config.clientKey,
2230
- secretKey: this.config.secretKey,
2231
- baseUrl: this.baseUrl
2117
+ publishableKey: this.config.publishableKey,
2118
+ secretKey: this.config.secretKey
2232
2119
  });
2233
2120
  this.community = new CommunityClient({
2234
- clientKey: this.config.clientKey,
2235
- secretKey: this.config.secretKey,
2236
- baseUrl: this.baseUrl
2121
+ publishableKey: this.config.publishableKey,
2122
+ secretKey: this.config.secretKey
2237
2123
  });
2238
2124
  this.product = new ProductApi({
2239
- clientKey: this.config.clientKey,
2240
- secretKey: this.config.secretKey,
2241
- baseUrl: this.baseUrl
2125
+ publishableKey: this.config.publishableKey,
2126
+ secretKey: this.config.secretKey
2242
2127
  });
2243
2128
  this.collections = new CollectionClient(
2244
- this.config.clientKey,
2245
- this.config.secretKey,
2246
- this.baseUrl
2129
+ this.config.publishableKey,
2130
+ this.config.secretKey
2247
2131
  );
2248
2132
  this.queryClient = getQueryClient();
2249
2133
  this.query = new QueryHooks(this.queryClient, this.collections);
@@ -2269,9 +2153,9 @@ var MAX_RECONNECT_DELAY = 3e4;
2269
2153
  var RECONNECT_BACKOFF_FACTOR = 2;
2270
2154
  var MAX_NO_TOKEN_RETRIES = 5;
2271
2155
  var RealtimeConnection = class {
2272
- constructor(baseUrl, clientKey, getToken, collections) {
2156
+ constructor(baseUrl, publishableKey, getToken, collections) {
2273
2157
  this.baseUrl = baseUrl;
2274
- this.clientKey = clientKey;
2158
+ this.publishableKey = publishableKey;
2275
2159
  this.getToken = getToken;
2276
2160
  this.collections = collections;
2277
2161
  this.abortController = null;
@@ -2324,7 +2208,7 @@ var RealtimeConnection = class {
2324
2208
  try {
2325
2209
  const response = await fetch(url, {
2326
2210
  headers: {
2327
- "X-Client-Key": this.clientKey,
2211
+ "X-Publishable-Key": this.publishableKey,
2328
2212
  Authorization: `Bearer ${token}`
2329
2213
  },
2330
2214
  signal