@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/dist/index.js CHANGED
@@ -1,82 +1,3 @@
1
- // src/core/internal/utils/jwt.ts
2
- import { SignJWT, jwtVerify, decodeJwt } from "jose";
3
- async function createServerToken(clientKey, secretKey, expiresIn = "1h") {
4
- if (!clientKey || !secretKey) {
5
- throw new Error("clientKey and secretKey are required.");
6
- }
7
- const secret = new TextEncoder().encode(secretKey);
8
- return new SignJWT({ clientKey }).setProtectedHeader({ alg: "HS256" }).setIssuedAt().setExpirationTime(expiresIn).sign(secret);
9
- }
10
- async function verifyServerToken(token, secretKey) {
11
- if (!token || !secretKey) {
12
- throw new Error("token and secretKey are required.");
13
- }
14
- const secret = new TextEncoder().encode(secretKey);
15
- const { payload } = await jwtVerify(token, secret, {
16
- algorithms: ["HS256"]
17
- });
18
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
19
- throw new Error("Invalid token payload: clientKey is missing");
20
- }
21
- return {
22
- clientKey: payload.clientKey,
23
- iat: payload.iat,
24
- exp: payload.exp
25
- };
26
- }
27
- function decodeServerToken(token) {
28
- if (!token) {
29
- throw new Error("token is required.");
30
- }
31
- const payload = decodeJwt(token);
32
- if (!payload.clientKey || typeof payload.clientKey !== "string") {
33
- throw new Error("Invalid token payload: clientKey is missing");
34
- }
35
- return {
36
- clientKey: payload.clientKey,
37
- iat: payload.iat,
38
- exp: payload.exp
39
- };
40
- }
41
-
42
- // src/core/internal/utils/encoding.ts
43
- function createApiKey(clientKey, secretKey) {
44
- if (!clientKey || !secretKey) {
45
- throw new Error("clientKey and secretKey are required.");
46
- }
47
- if (typeof Buffer !== "undefined") {
48
- return Buffer.from(`${clientKey}:${secretKey}`).toString("base64");
49
- }
50
- return btoa(`${clientKey}:${secretKey}`);
51
- }
52
- function parseApiKey(apiKey) {
53
- if (!apiKey) {
54
- throw new Error("apiKey is required.");
55
- }
56
- try {
57
- let decoded;
58
- if (typeof Buffer !== "undefined") {
59
- decoded = Buffer.from(apiKey, "base64").toString("utf-8");
60
- } else {
61
- decoded = atob(apiKey);
62
- }
63
- const colonIndex = decoded.indexOf(":");
64
- if (colonIndex === -1) {
65
- throw new Error("Invalid format: missing colon separator");
66
- }
67
- const clientKey = decoded.substring(0, colonIndex);
68
- const secretKey = decoded.substring(colonIndex + 1);
69
- if (!clientKey || !secretKey) {
70
- throw new Error("Invalid format: empty clientKey or secretKey");
71
- }
72
- return { clientKey, secretKey };
73
- } catch {
74
- throw new Error(
75
- 'Invalid API key. Expected Base64 encoded "clientKey:secretKey"'
76
- );
77
- }
78
- }
79
-
80
1
  // src/core/internal/errors/index.ts
81
2
  var SDKError = class extends Error {
82
3
  constructor(code, message, status, details, userMessage, suggestion) {
@@ -197,7 +118,6 @@ function isUsageLimitError(error) {
197
118
  return error instanceof UsageLimitError;
198
119
  }
199
120
  var createNetworkError = (message, status, details, userMessage, suggestion) => new NetworkError(message, status, details, userMessage, suggestion);
200
- var createValidationError = (message, details, userMessage, suggestion) => new ValidationError(message, details, userMessage, suggestion);
201
121
  var createApiError = (message, status, details, userMessage, suggestion) => new ApiError(message, status, details, userMessage, suggestion);
202
122
  var createConfigError = (message, details, userMessage, suggestion) => new ConfigError(message, details, userMessage, suggestion);
203
123
  var createTimeoutError = (message, details, userMessage, suggestion) => new TimeoutError(message, details, userMessage, suggestion);
@@ -291,24 +211,24 @@ async function delay(ms) {
291
211
  }
292
212
  async function httpFetch(url, options) {
293
213
  const {
294
- clientKey,
214
+ publishableKey,
295
215
  secretKey,
296
216
  customerToken,
297
217
  timeout = DEFAULT_TIMEOUT,
298
- baseUrl = resolveApiUrl(),
299
218
  debug,
300
219
  retry,
301
220
  onUnauthorized,
302
221
  ...requestInit
303
222
  } = options || {};
223
+ const baseUrl = resolveApiUrl();
304
224
  const retryConfig = {
305
225
  maxRetries: retry?.maxRetries ?? 3,
306
226
  retryableStatuses: retry?.retryableStatuses ?? DEFAULT_RETRYABLE_STATUSES,
307
227
  retryDelay: retry?.retryDelay ?? ((attempt) => Math.min(1e3 * 2 ** attempt, 1e4))
308
228
  };
309
229
  let authToken;
310
- if (secretKey && clientKey) {
311
- authToken = await createServerToken(clientKey, secretKey);
230
+ if (secretKey) {
231
+ authToken = secretKey;
312
232
  } else if (customerToken) {
313
233
  authToken = customerToken;
314
234
  }
@@ -317,8 +237,8 @@ async function httpFetch(url, options) {
317
237
  for (let attempt = 0; attempt <= retryConfig.maxRetries; attempt++) {
318
238
  try {
319
239
  const headers = new Headers(requestInit.headers);
320
- if (clientKey) {
321
- headers.set("X-Client-Key", clientKey);
240
+ if (publishableKey) {
241
+ headers.set("X-Publishable-Key", publishableKey);
322
242
  }
323
243
  if (authToken) {
324
244
  headers.set("Authorization", `Bearer ${authToken}`);
@@ -509,23 +429,18 @@ async function parseApiResponse(response, endpoint) {
509
429
  // src/core/api/base-api.ts
510
430
  var BaseApi = class {
511
431
  constructor(apiName, options) {
512
- if (!options.clientKey) {
513
- throw createConfigError(`clientKey is required for ${apiName}.`);
514
- }
515
432
  if (!options.secretKey) {
516
433
  throw createConfigError(`secretKey is required for ${apiName}.`);
517
434
  }
518
- this.clientKey = options.clientKey;
435
+ this.publishableKey = options.publishableKey ?? "";
519
436
  this.secretKey = options.secretKey;
520
- this.baseUrl = options.baseUrl;
521
437
  }
522
438
  async request(endpoint, body, options) {
523
439
  const method = options?.method ?? "POST";
524
440
  const response = await httpFetch(endpoint, {
525
441
  method,
526
- clientKey: this.clientKey,
442
+ publishableKey: this.publishableKey,
527
443
  secretKey: this.secretKey,
528
- baseUrl: this.baseUrl,
529
444
  ...body !== void 0 && { body: JSON.stringify(body) },
530
445
  ...options?.headers && { headers: options.headers }
531
446
  });
@@ -588,28 +503,23 @@ var OrderApi = class extends BaseApi {
588
503
  // src/core/api/cart-api.ts
589
504
  var CartApi = class {
590
505
  constructor(options) {
591
- if (!options.clientKey) {
592
- throw createConfigError("clientKey is required for CartApi.");
593
- }
594
506
  if (!options.secretKey && !options.customerToken) {
595
507
  throw createConfigError(
596
508
  "Either secretKey or customerToken is required for CartApi."
597
509
  );
598
510
  }
599
- this.clientKey = options.clientKey;
511
+ this.publishableKey = options.publishableKey ?? "";
600
512
  this.secretKey = options.secretKey;
601
513
  this.customerToken = options.customerToken;
602
- this.baseUrl = options.baseUrl;
603
514
  this.onUnauthorized = options.onUnauthorized;
604
515
  }
605
516
  async execute(endpoint, method, body) {
606
517
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
607
518
  const response = await httpFetch(endpoint, {
608
519
  method,
609
- clientKey: this.clientKey,
520
+ publishableKey: this.publishableKey,
610
521
  secretKey: this.secretKey,
611
522
  customerToken: token ?? void 0,
612
- baseUrl: this.baseUrl,
613
523
  ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
614
524
  ...body !== void 0 && { body: JSON.stringify(body) }
615
525
  });
@@ -856,21 +766,16 @@ var CollectionQueryBuilder = class {
856
766
  // src/core/collection/http-client.ts
857
767
  import { stringify } from "qs-esm";
858
768
  var HttpClient = class {
859
- constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
860
- if (!clientKey) {
861
- throw createValidationError("clientKey is required.");
862
- }
863
- this.clientKey = clientKey;
769
+ constructor(publishableKey, secretKey, getCustomerToken, onUnauthorized) {
770
+ this.publishableKey = publishableKey;
864
771
  this.secretKey = secretKey;
865
- this.baseUrl = baseUrl;
866
772
  this.getCustomerToken = getCustomerToken;
867
773
  this.onUnauthorized = onUnauthorized;
868
774
  }
869
775
  get defaultOptions() {
870
776
  const opts = {
871
- clientKey: this.clientKey,
872
- secretKey: this.secretKey,
873
- baseUrl: this.baseUrl
777
+ publishableKey: this.publishableKey,
778
+ secretKey: this.secretKey
874
779
  };
875
780
  const token = this.getCustomerToken?.();
876
781
  if (token) {
@@ -985,9 +890,6 @@ function buildPayloadFormData(data, file, filename) {
985
890
  return formData;
986
891
  }
987
892
  var CollectionClient = class extends HttpClient {
988
- constructor(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized) {
989
- super(clientKey, secretKey, baseUrl, getCustomerToken, onUnauthorized);
990
- }
991
893
  from(collection) {
992
894
  return new CollectionQueryBuilder(this, collection);
993
895
  }
@@ -1153,9 +1055,10 @@ var COLLECTIONS = [
1153
1055
  "playlists",
1154
1056
  "playlist-categories",
1155
1057
  "playlist-tags",
1156
- "musics",
1157
- "music-categories",
1158
- "music-tags",
1058
+ "tracks",
1059
+ "playlist-tracks",
1060
+ "track-categories",
1061
+ "track-tags",
1159
1062
  "galleries",
1160
1063
  "gallery-categories",
1161
1064
  "gallery-tags",
@@ -1189,23 +1092,18 @@ var COLLECTIONS = [
1189
1092
  // src/core/community/community-client.ts
1190
1093
  var CommunityClient = class {
1191
1094
  constructor(options) {
1192
- if (!options.clientKey) {
1193
- throw createConfigError("clientKey is required for CommunityClient.");
1194
- }
1195
- this.clientKey = options.clientKey;
1095
+ this.publishableKey = options.publishableKey ?? "";
1196
1096
  this.secretKey = options.secretKey;
1197
1097
  this.customerToken = options.customerToken;
1198
- this.baseUrl = options.baseUrl;
1199
1098
  this.onUnauthorized = options.onUnauthorized;
1200
1099
  }
1201
1100
  async execute(endpoint, method, body) {
1202
1101
  const token = typeof this.customerToken === "function" ? this.customerToken() : this.customerToken;
1203
1102
  const response = await httpFetch(endpoint, {
1204
1103
  method,
1205
- clientKey: this.clientKey,
1104
+ publishableKey: this.publishableKey,
1206
1105
  secretKey: this.secretKey,
1207
1106
  customerToken: token ?? void 0,
1208
- baseUrl: this.baseUrl,
1209
1107
  ...token && this.onUnauthorized && { onUnauthorized: this.onUnauthorized },
1210
1108
  ...body !== void 0 && { body: JSON.stringify(body) }
1211
1109
  });
@@ -1382,10 +1280,10 @@ function safeGetItem(key) {
1382
1280
  }
1383
1281
  }
1384
1282
  var CustomerAuth = class {
1385
- constructor(clientKey, baseUrl, options) {
1283
+ constructor(publishableKey, options) {
1386
1284
  this.refreshPromise = null;
1387
- this.clientKey = clientKey;
1388
- this.baseUrl = baseUrl;
1285
+ this.publishableKey = publishableKey;
1286
+ this.baseUrl = resolveApiUrl();
1389
1287
  const persist = options?.persist ?? true;
1390
1288
  if (persist) {
1391
1289
  const key = typeof persist === "string" ? persist : "customer-token";
@@ -1571,7 +1469,7 @@ var CustomerAuth = class {
1571
1469
  */
1572
1470
  async requestJson(path, init) {
1573
1471
  const headers = new Headers(init.headers);
1574
- headers.set("X-Client-Key", this.clientKey);
1472
+ headers.set("X-Publishable-Key", this.publishableKey);
1575
1473
  if (!headers.has("Content-Type") && init.body) {
1576
1474
  headers.set("Content-Type", "application/json");
1577
1475
  }
@@ -2064,11 +1962,11 @@ var QueryHooks = class extends CollectionHooks {
2064
1962
  // src/core/client/client.ts
2065
1963
  var Client = class {
2066
1964
  constructor(options) {
2067
- if (!options.clientKey) {
2068
- throw createConfigError("clientKey is required.");
1965
+ const publishableKey = options.publishableKey;
1966
+ if (!publishableKey) {
1967
+ throw createConfigError("publishableKey is required.");
2069
1968
  }
2070
- this.config = { ...options };
2071
- this.baseUrl = resolveApiUrl();
1969
+ this.config = { ...options, publishableKey };
2072
1970
  const metadata = {
2073
1971
  timestamp: Date.now(),
2074
1972
  userAgent: typeof window !== "undefined" ? window.navigator?.userAgent : "Node.js"
@@ -2076,8 +1974,7 @@ var Client = class {
2076
1974
  this.state = { metadata };
2077
1975
  this.queryClient = getQueryClient();
2078
1976
  this.customer = new CustomerAuth(
2079
- this.config.clientKey,
2080
- this.baseUrl,
1977
+ this.config.publishableKey,
2081
1978
  options.customer
2082
1979
  );
2083
1980
  const onUnauthorized = async () => {
@@ -2089,21 +1986,18 @@ var Client = class {
2089
1986
  }
2090
1987
  };
2091
1988
  this.cart = new CartApi({
2092
- clientKey: this.config.clientKey,
1989
+ publishableKey: this.config.publishableKey,
2093
1990
  customerToken: () => this.customer.getToken(),
2094
- baseUrl: this.baseUrl,
2095
1991
  onUnauthorized
2096
1992
  });
2097
1993
  this.community = new CommunityClient({
2098
- clientKey: this.config.clientKey,
1994
+ publishableKey: this.config.publishableKey,
2099
1995
  customerToken: () => this.customer.getToken(),
2100
- baseUrl: this.baseUrl,
2101
1996
  onUnauthorized
2102
1997
  });
2103
1998
  this.collections = new CollectionClient(
2104
- this.config.clientKey,
1999
+ this.config.publishableKey,
2105
2000
  void 0,
2106
- this.baseUrl,
2107
2001
  () => this.customer.getToken(),
2108
2002
  onUnauthorized
2109
2003
  );
@@ -2135,43 +2029,39 @@ var ServerClient = class {
2135
2029
  "ServerClient must not be used in a browser environment. This risks exposing your secretKey in client bundles. Use createClient() for browser code instead."
2136
2030
  );
2137
2031
  }
2138
- if (!options.clientKey) {
2139
- throw createConfigError("clientKey is required.");
2140
- }
2141
2032
  if (!options.secretKey) {
2142
2033
  throw createConfigError("secretKey is required.");
2143
2034
  }
2144
- this.config = { ...options };
2145
- this.baseUrl = resolveApiUrl();
2035
+ if (!options.publishableKey) {
2036
+ throw createConfigError(
2037
+ "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."
2038
+ );
2039
+ }
2040
+ this.config = { ...options, publishableKey: options.publishableKey };
2146
2041
  const metadata = {
2147
2042
  timestamp: Date.now(),
2148
2043
  userAgent: "Node.js"
2149
2044
  };
2150
2045
  this.state = { metadata };
2151
2046
  this.api = new OrderApi({
2152
- clientKey: this.config.clientKey,
2153
- secretKey: this.config.secretKey,
2154
- baseUrl: this.baseUrl
2047
+ publishableKey: this.config.publishableKey,
2048
+ secretKey: this.config.secretKey
2155
2049
  });
2156
2050
  this.cart = new CartApi({
2157
- clientKey: this.config.clientKey,
2158
- secretKey: this.config.secretKey,
2159
- baseUrl: this.baseUrl
2051
+ publishableKey: this.config.publishableKey,
2052
+ secretKey: this.config.secretKey
2160
2053
  });
2161
2054
  this.community = new CommunityClient({
2162
- clientKey: this.config.clientKey,
2163
- secretKey: this.config.secretKey,
2164
- baseUrl: this.baseUrl
2055
+ publishableKey: this.config.publishableKey,
2056
+ secretKey: this.config.secretKey
2165
2057
  });
2166
2058
  this.product = new ProductApi({
2167
- clientKey: this.config.clientKey,
2168
- secretKey: this.config.secretKey,
2169
- baseUrl: this.baseUrl
2059
+ publishableKey: this.config.publishableKey,
2060
+ secretKey: this.config.secretKey
2170
2061
  });
2171
2062
  this.collections = new CollectionClient(
2172
- this.config.clientKey,
2173
- this.config.secretKey,
2174
- this.baseUrl
2063
+ this.config.publishableKey,
2064
+ this.config.secretKey
2175
2065
  );
2176
2066
  this.queryClient = getQueryClient();
2177
2067
  this.query = new QueryHooks(this.queryClient, this.collections);
@@ -2197,9 +2087,9 @@ var MAX_RECONNECT_DELAY = 3e4;
2197
2087
  var RECONNECT_BACKOFF_FACTOR = 2;
2198
2088
  var MAX_NO_TOKEN_RETRIES = 5;
2199
2089
  var RealtimeConnection = class {
2200
- constructor(baseUrl, clientKey, getToken, collections) {
2090
+ constructor(baseUrl, publishableKey, getToken, collections) {
2201
2091
  this.baseUrl = baseUrl;
2202
- this.clientKey = clientKey;
2092
+ this.publishableKey = publishableKey;
2203
2093
  this.getToken = getToken;
2204
2094
  this.collections = collections;
2205
2095
  this.abortController = null;
@@ -2252,7 +2142,7 @@ var RealtimeConnection = class {
2252
2142
  try {
2253
2143
  const response = await fetch(url, {
2254
2144
  headers: {
2255
- "X-Client-Key": this.clientKey,
2145
+ "X-Publishable-Key": this.publishableKey,
2256
2146
  Authorization: `Bearer ${token}`
2257
2147
  },
2258
2148
  signal
@@ -2546,13 +2436,10 @@ export {
2546
2436
  UsageLimitError,
2547
2437
  ValidationError,
2548
2438
  collectionKeys,
2549
- createApiKey,
2550
2439
  createClient,
2551
2440
  createServerClient,
2552
- createServerToken,
2553
2441
  createTypedWebhookHandler,
2554
2442
  customerKeys,
2555
- decodeServerToken,
2556
2443
  formatOrderName,
2557
2444
  generateOrderNumber,
2558
2445
  getImageLqip,
@@ -2577,8 +2464,6 @@ export {
2577
2464
  isUsageLimitError,
2578
2465
  isValidWebhookEvent,
2579
2466
  isValidationError,
2580
- parseApiKey,
2581
- resolveRelation,
2582
- verifyServerToken
2467
+ resolveRelation
2583
2468
  };
2584
2469
  //# sourceMappingURL=index.js.map