@01.software/sdk 0.16.0 → 0.18.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 CHANGED
@@ -79,7 +79,7 @@ const { docs } = await client.collections.from('products').find({
79
79
  import { createServerClient } from '@01.software/sdk'
80
80
 
81
81
  const client = createServerClient({
82
- publishableKey: process.env.NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY,
82
+ publishableKey: process.env.SOFTWARE_PUBLISHABLE_KEY,
83
83
  secretKey: process.env.SOFTWARE_SECRET_KEY, // sk01_... opaque API key from Console
84
84
  })
85
85
 
@@ -113,7 +113,7 @@ const client = createClient({
113
113
  const server = createServerClient({
114
114
  publishableKey: string,
115
115
  secretKey: string, // sk01_... or pat01_...
116
- tenantId: string, // required when secretKey is pat01_
116
+ tenantId?: string, // for PAT workflows, must match the pinned tenant when supplied
117
117
  })
118
118
  ```
119
119
 
@@ -121,6 +121,7 @@ const server = createServerClient({
121
121
  | ---------------- | -------- | ---------------------------- |
122
122
  | `publishableKey` | `string` | API publishable key |
123
123
  | `secretKey` | `string` | API secret key (server only) |
124
+ | `tenantId` | `string` | Optional generally; required when a PAT must disambiguate multi-tenant access. Must match the pinned tenant when supplied. |
124
125
 
125
126
  API URL은 환경변수로 오버라이드 가능합니다:
126
127
 
@@ -306,7 +307,6 @@ login({ email: 'user@example.com', password: 'password' })
306
307
  // Other customer mutations
307
308
  client.query.useCustomerForgotPassword()
308
309
  client.query.useCustomerResetPassword()
309
- client.query.useCustomerVerifyEmail()
310
310
  client.query.useCustomerChangePassword()
311
311
 
312
312
  // Customer cache utilities
@@ -348,11 +348,10 @@ const orders = await client.commerce.orders.listMine({
348
348
  status: 'paid',
349
349
  })
350
350
 
351
- // Password & email
351
+ // Password
352
352
  await client.customer.auth.forgotPassword('john@example.com')
353
353
  await client.customer.auth.resetPassword(token, newPassword)
354
354
  await client.customer.auth.changePassword(currentPassword, newPassword)
355
- await client.customer.auth.verifyEmail(verificationToken)
356
355
  ```
357
356
 
358
357
  ### Commerce Orders (ServerClient-only writes)
@@ -439,7 +438,11 @@ await server.community.moderation.unbanCustomer({ customerId })
439
438
  ### Webhook
440
439
 
441
440
  ```typescript
442
- import { handleWebhook, createTypedWebhookHandler } from '@01.software/sdk'
441
+ import {
442
+ handleWebhook,
443
+ createCustomerAuthWebhookHandler,
444
+ createTypedWebhookHandler,
445
+ } from '@01.software/sdk'
443
446
 
444
447
  // Basic handler
445
448
  export async function POST(request: Request) {
@@ -460,26 +463,37 @@ const handler = createTypedWebhookHandler('orders', async (event) => {
460
463
  // event.data is typed as Order
461
464
  console.log(event.data.orderNumber)
462
465
  })
466
+
467
+ // Customer auth helper
468
+ const customerAuthHandler = createCustomerAuthWebhookHandler({
469
+ passwordReset: async ({ email, resetPasswordToken }) => {
470
+ await sendPasswordResetEmail(email, resetPasswordToken)
471
+ },
472
+ })
463
473
  ```
464
474
 
465
475
  ## Supported Collections
466
476
 
467
- | Category | Collections |
468
- | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------- |
469
- | Tenant | `tenants`, `tenant-metadata`, `tenant-logos` |
470
- | Images | `images` (unified), `brand-logos` |
471
- | Products | `products`, `product-variants`, `product-options`, `product-option-values`, `product-categories`, `product-tags`, `product-collections`, `brands`, `brand-logos` |
472
- | Orders | `orders`, `order-items`, `returns`, `return-items`, `fulfillments`, `fulfillment-items`, `transactions`, `order-status-logs` |
473
- | Customers | `customers`, `customer-addresses`, `customer-groups` |
474
- | Carts | `carts`, `cart-items` |
475
- | Commerce | `discounts`, `shipping-policies` |
476
- | Content | `posts`, `post-authors`, `post-categories`, `post-tags`, `documents`, `document-categories`, `document-types` |
477
- | Playlists | `playlists`, `playlist-categories`, `playlist-tags`, `tracks`, `track-categories`, `track-tags` |
478
- | Galleries | `galleries`, `gallery-items`, `gallery-categories`, `gallery-tags` |
479
- | Canvas | `canvases`, `canvas-node-types`, `canvas-edge-types`, `canvas-categories`, `canvas-tags` |
480
- | Videos | `videos`, `video-categories`, `video-tags` |
481
- | Live Streams | `live-streams` |
482
- | Forms | `forms`, `form-submissions` |
477
+ Source of truth: `packages/sdk/src/core/collection/const.ts` (`COLLECTIONS`: 74).
478
+
479
+ | Category | Collections |
480
+ | --- | --- |
481
+ | Tenant | `tenants`, `tenant-metadata`, `tenant-logos` |
482
+ | Products | `products`, `product-variants`, `product-options`, `product-option-values`, `product-categories`, `product-tags`, `product-collections`, `brands`, `brand-logos` |
483
+ | Orders | `orders`, `order-items`, `returns`, `return-items`, `fulfillments`, `fulfillment-items`, `transactions` |
484
+ | Customers | `customers`, `customer-profiles`, `customer-addresses`, `customer-groups` |
485
+ | Carts | `carts`, `cart-items` |
486
+ | Commerce | `discounts`, `promotions`, `shipping-policies` |
487
+ | Content | `documents`, `document-categories`, `document-types`, `posts`, `post-authors`, `post-categories`, `post-tags`, `links`, `link-categories`, `link-tags` |
488
+ | Playlists / Tracks | `playlists`, `playlist-categories`, `playlist-tags`, `tracks`, `track-categories`, `track-tags` |
489
+ | Galleries | `galleries`, `gallery-categories`, `gallery-tags`, `gallery-items` |
490
+ | Canvas | `canvases`, `canvas-node-types`, `canvas-edge-types`, `canvas-categories`, `canvas-tags`, `canvas-nodes`, `canvas-edges` |
491
+ | Videos | `videos`, `video-categories`, `video-tags` |
492
+ | Live Streams | `live-streams` |
493
+ | Media | `images` |
494
+ | Forms | `forms`, `form-submissions` |
495
+ | Community | `threads`, `comments`, `reactions`, `reaction-types`, `bookmarks`, `thread-categories`, `reports`, `community-bans` |
496
+ | Events | `event-calendars`, `events`, `event-occurrences`, `event-tags` |
483
497
 
484
498
  ## Utilities
485
499
 
@@ -581,6 +595,7 @@ Error classes: `SDKError`, `ApiError`, `NetworkError`, `ValidationError`, `Confi
581
595
 
582
596
  ```bash
583
597
  NEXT_PUBLIC_SOFTWARE_PUBLISHABLE_KEY=your_publishable_key
598
+ SOFTWARE_PUBLISHABLE_KEY=your_publishable_key
584
599
  SOFTWARE_SECRET_KEY=sk01_... # Server only — opaque API key from Console
585
600
  ```
586
601
 
@@ -597,7 +612,7 @@ New error codes propagated via `SDKError.code` (no breaking change; existing cal
597
612
  | Code | Phase | Trigger |
598
613
  |---|---|---|
599
614
  | `account_suspended` | P1 | Suspended session / `sk01_` / `pat01_` / customer JWT — 401 |
600
- | `pat_tenant_header_forbidden` | P1 | `pat01_` with `X-Tenant-Id` header — 401 (header rejected) |
615
+ | `pat_tenant_header_forbidden` | P1 | `pat01_` request with a forbidden or mismatched `X-Tenant-Id` header — 401 |
601
616
  | `tenant_mismatch` | P3 | Cross-tenant FK rejection (forms / community / orders) |
602
617
  | `server_derived` | P3 | Body-driven write into a server-derived state field — 422 |
603
618
  | `scope_denied` | P5 | `pat01_` whose `ApiKeys.scopes` lacks the operation |
@@ -613,7 +628,6 @@ P5 also adds JWT-`jti` revocation: `revokeCustomerJti(jti, ttl)` on the server i
613
628
  | Collection | Old | New |
614
629
  |---|---|---|
615
630
  | Customers | `socialId` | `providerUserId` |
616
- | Customers | `isVerified` | `isEmailVerified` |
617
631
  | Customers | `loginAttempts` | `loginAttemptCount` |
618
632
  | Customers | `resetPasswordExpiry` | `resetPasswordExpiresAt` |
619
633
  | Orders, Carts | `shippingFee` | `shippingAmount` |
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-DRvL_bS2.cjs';
1
+ import { C as Config } from './payload-types-Cwnj_qN4.js';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -9,12 +9,12 @@ type Collection = keyof Config['collections'];
9
9
  * Internal collections that should not be exposed via SDK.
10
10
  * Includes Payload system collections and admin-only collections.
11
11
  */
12
- declare const INTERNAL_COLLECTIONS: readonly ["users", "payload-kv", "payload-locked-documents", "payload-preferences", "payload-migrations", "field-configs", "system-media", "track-assets", "audiences", "email-logs", "tenant-auth-settings", "tenant-community-settings", "api-usage", "tenant-analytics-daily", "analytics-event-schemas", "subscriptions", "billing-history", "order-status-logs", "api-keys", "personal-access-tokens", "tenant-entitlements", "webhook-events", "webhook-deliveries", "audit-logs", "plans", "webhooks"];
12
+ declare const INTERNAL_COLLECTIONS: readonly ["users", "payload-kv", "payload-locked-documents", "payload-preferences", "payload-migrations", "field-configs", "system-media", "track-assets", "audiences", "email-logs", "api-usage", "tenant-analytics-daily", "analytics-event-schemas", "subscriptions", "billing-history", "order-status-logs", "api-keys", "personal-access-tokens", "tenant-entitlements", "webhook-events", "webhook-deliveries", "audit-logs", "plans", "webhooks", "event-registrations"];
13
13
  /**
14
14
  * Array of all public collection names for runtime use (e.g., Zod enum validation).
15
15
  * This is the single source of truth for which collections are publicly accessible via SDK.
16
16
  */
17
- 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", "promotions", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "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", "canvas-nodes", "canvas-edges", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans"];
17
+ 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-profiles", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "promotions", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "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", "canvas-nodes", "canvas-edges", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans", "event-calendars", "events", "event-occurrences", "event-tags"];
18
18
  /**
19
19
  * Public collections available for SDK access.
20
20
  * Derived from the COLLECTIONS array (single source of truth).
@@ -1,4 +1,4 @@
1
- import { C as Config } from './payload-types-DRvL_bS2.js';
1
+ import { C as Config } from './payload-types-Cwnj_qN4.cjs';
2
2
 
3
3
  /**
4
4
  * Collection type derived from Payload Config.
@@ -9,12 +9,12 @@ type Collection = keyof Config['collections'];
9
9
  * Internal collections that should not be exposed via SDK.
10
10
  * Includes Payload system collections and admin-only collections.
11
11
  */
12
- declare const INTERNAL_COLLECTIONS: readonly ["users", "payload-kv", "payload-locked-documents", "payload-preferences", "payload-migrations", "field-configs", "system-media", "track-assets", "audiences", "email-logs", "tenant-auth-settings", "tenant-community-settings", "api-usage", "tenant-analytics-daily", "analytics-event-schemas", "subscriptions", "billing-history", "order-status-logs", "api-keys", "personal-access-tokens", "tenant-entitlements", "webhook-events", "webhook-deliveries", "audit-logs", "plans", "webhooks"];
12
+ declare const INTERNAL_COLLECTIONS: readonly ["users", "payload-kv", "payload-locked-documents", "payload-preferences", "payload-migrations", "field-configs", "system-media", "track-assets", "audiences", "email-logs", "api-usage", "tenant-analytics-daily", "analytics-event-schemas", "subscriptions", "billing-history", "order-status-logs", "api-keys", "personal-access-tokens", "tenant-entitlements", "webhook-events", "webhook-deliveries", "audit-logs", "plans", "webhooks", "event-registrations"];
13
13
  /**
14
14
  * Array of all public collection names for runtime use (e.g., Zod enum validation).
15
15
  * This is the single source of truth for which collections are publicly accessible via SDK.
16
16
  */
17
- 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", "promotions", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "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", "canvas-nodes", "canvas-edges", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans"];
17
+ 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-profiles", "customer-addresses", "customer-groups", "carts", "cart-items", "discounts", "promotions", "shipping-policies", "documents", "document-categories", "document-types", "posts", "post-authors", "post-categories", "post-tags", "playlists", "playlist-categories", "playlist-tags", "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", "canvas-nodes", "canvas-edges", "videos", "video-categories", "video-tags", "live-streams", "images", "forms", "form-submissions", "threads", "comments", "reactions", "reaction-types", "bookmarks", "thread-categories", "reports", "community-bans", "event-calendars", "events", "event-occurrences", "event-tags"];
18
18
  /**
19
19
  * Public collections available for SDK access.
20
20
  * Derived from the COLLECTIONS array (single source of truth).
package/dist/index.cjs CHANGED
@@ -24,6 +24,7 @@ __export(src_exports, {
24
24
  AuthError: () => AuthError,
25
25
  BaseApi: () => BaseApi,
26
26
  COLLECTIONS: () => COLLECTIONS,
27
+ CUSTOMER_PASSWORD_RESET_OPERATION: () => CUSTOMER_PASSWORD_RESET_OPERATION,
27
28
  CartApi: () => CartApi,
28
29
  Client: () => Client,
29
30
  CollectionClient: () => CollectionClient,
@@ -65,6 +66,7 @@ __export(src_exports, {
65
66
  createAuthError: () => createAuthError,
66
67
  createClient: () => createClient,
67
68
  createConflictError: () => createConflictError,
69
+ createCustomerAuthWebhookHandler: () => createCustomerAuthWebhookHandler,
68
70
  createNotFoundError: () => createNotFoundError,
69
71
  createPermissionError: () => createPermissionError,
70
72
  createRateLimitError: () => createRateLimitError,
@@ -91,6 +93,7 @@ __export(src_exports, {
91
93
  isAuthError: () => isAuthError,
92
94
  isConfigError: () => isConfigError,
93
95
  isConflictError: () => isConflictError,
96
+ isCustomerPasswordResetWebhookEvent: () => isCustomerPasswordResetWebhookEvent,
94
97
  isGoneError: () => isGoneError,
95
98
  isNetworkError: () => isNetworkError,
96
99
  isNotFoundError: () => isNotFoundError,
@@ -1077,8 +1080,6 @@ var INTERNAL_COLLECTIONS = [
1077
1080
  "track-assets",
1078
1081
  "audiences",
1079
1082
  "email-logs",
1080
- "tenant-auth-settings",
1081
- "tenant-community-settings",
1082
1083
  "api-usage",
1083
1084
  "tenant-analytics-daily",
1084
1085
  "analytics-event-schemas",
@@ -1092,7 +1093,8 @@ var INTERNAL_COLLECTIONS = [
1092
1093
  "webhook-deliveries",
1093
1094
  "audit-logs",
1094
1095
  "plans",
1095
- "webhooks"
1096
+ "webhooks",
1097
+ "event-registrations"
1096
1098
  ];
1097
1099
  var COLLECTIONS = [
1098
1100
  "tenants",
@@ -1115,6 +1117,7 @@ var COLLECTIONS = [
1115
1117
  "fulfillment-items",
1116
1118
  "transactions",
1117
1119
  "customers",
1120
+ "customer-profiles",
1118
1121
  "customer-addresses",
1119
1122
  "customer-groups",
1120
1123
  "carts",
@@ -1164,7 +1167,12 @@ var COLLECTIONS = [
1164
1167
  "bookmarks",
1165
1168
  "thread-categories",
1166
1169
  "reports",
1167
- "community-bans"
1170
+ "community-bans",
1171
+ // Events
1172
+ "event-calendars",
1173
+ "events",
1174
+ "event-occurrences",
1175
+ "event-tags"
1168
1176
  ];
1169
1177
 
1170
1178
  // src/core/api/parse-response.ts
@@ -1580,15 +1588,6 @@ var CustomerAuth = class {
1580
1588
  body: JSON.stringify({ currentPassword, newPassword })
1581
1589
  });
1582
1590
  }
1583
- /**
1584
- * Verify email using the verification token
1585
- */
1586
- async verifyEmail(token) {
1587
- await this.requestJson("/api/customers/verify-email", {
1588
- method: "POST",
1589
- body: JSON.stringify({ token })
1590
- });
1591
- }
1592
1591
  /**
1593
1592
  * Get the authenticated customer's orders with pagination and optional status filter
1594
1593
  */
@@ -2308,14 +2307,6 @@ var CustomerHooks = class {
2308
2307
  options
2309
2308
  );
2310
2309
  }
2311
- useCustomerVerifyEmail(options) {
2312
- return createMutation(
2313
- (token) => this.ensureCustomerAuth().verifyEmail(token).then(() => {
2314
- }),
2315
- options,
2316
- this.invalidateMe
2317
- );
2318
- }
2319
2310
  useCustomerRefreshToken(options) {
2320
2311
  return createMutation(
2321
2312
  () => this.ensureCustomerAuth().refreshToken(),
@@ -2360,7 +2351,6 @@ var QueryHooks = class extends CollectionHooks {
2360
2351
  this.useCustomerLogout = (...args) => this._customer.useCustomerLogout(...args);
2361
2352
  this.useCustomerForgotPassword = (...args) => this._customer.useCustomerForgotPassword(...args);
2362
2353
  this.useCustomerResetPassword = (...args) => this._customer.useCustomerResetPassword(...args);
2363
- this.useCustomerVerifyEmail = (...args) => this._customer.useCustomerVerifyEmail(...args);
2364
2354
  this.useCustomerRefreshToken = (...args) => this._customer.useCustomerRefreshToken(...args);
2365
2355
  this.useCustomerUpdateProfile = (...args) => this._customer.useCustomerUpdateProfile(...args);
2366
2356
  this.useCustomerChangePassword = (...args) => this._customer.useCustomerChangePassword(...args);
@@ -2744,7 +2734,32 @@ var RealtimeConnection = class {
2744
2734
  function isValidWebhookEvent(data) {
2745
2735
  if (typeof data !== "object" || data === null) return false;
2746
2736
  const obj = data;
2747
- return typeof obj.collection === "string" && (obj.operation === "create" || obj.operation === "update") && typeof obj.data === "object" && obj.data !== null;
2737
+ return typeof obj.collection === "string" && typeof obj.operation === "string" && obj.operation.length > 0 && typeof obj.data === "object" && obj.data !== null;
2738
+ }
2739
+ var CUSTOMER_PASSWORD_RESET_OPERATION = "password-reset";
2740
+ function isRecord(value) {
2741
+ return typeof value === "object" && value !== null;
2742
+ }
2743
+ function hasString(value, key) {
2744
+ return typeof value[key] === "string";
2745
+ }
2746
+ function hasStringOrNumber(value, key) {
2747
+ return typeof value[key] === "string" || typeof value[key] === "number";
2748
+ }
2749
+ function isCustomerPasswordResetWebhookEvent(event) {
2750
+ if (event.collection !== "customers" || event.operation !== CUSTOMER_PASSWORD_RESET_OPERATION || !isRecord(event.data)) {
2751
+ return false;
2752
+ }
2753
+ return hasStringOrNumber(event.data, "customerId") && hasString(event.data, "email") && hasString(event.data, "name") && hasString(event.data, "resetPasswordToken") && hasString(event.data, "resetPasswordExpiresAt");
2754
+ }
2755
+ function createCustomerAuthWebhookHandler(handlers) {
2756
+ return async (event) => {
2757
+ if (isCustomerPasswordResetWebhookEvent(event) && handlers.passwordReset) {
2758
+ await handlers.passwordReset(event.data, event);
2759
+ return;
2760
+ }
2761
+ await handlers.unhandled?.(event);
2762
+ };
2748
2763
  }
2749
2764
  async function verifySignature(payload, secret, signature) {
2750
2765
  const encoder = new TextEncoder();