@01.software/sdk 0.2.3 → 0.2.5

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/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
- import { O as Order, a as OrderProduct, T as Transaction, b as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-COjt2QTn.cjs';
2
- export { l as ApiUsage, ag as ApiUsageSelect, A as Audience, aa as AudiencesSelect, a$ as Auth, n as BillingHistory, ai as BillingHistorySelect, u as Brand, B as BrandLogo, ar as BrandLogosSelect, aq as BrandsSelect, K as Cart, aG as CartItemsSelect, aF as CartsSelect, f as CodeBlock, c as Config, w as Customer, z as CustomerAddress, aC as CustomerAddressesSelect, d as CustomerAuthOperations, x as CustomerGroup, y as CustomerGroupImage, aE as CustomerGroupImagesSelect, aD as CustomerGroupsSelect, aB as CustomersSelect, L as Discount, aH as DiscountsSelect, Y as Document, aP as DocumentCategoriesSelect, $ as DocumentCategory, _ as DocumentImage, aR as DocumentImagesSelect, Z as DocumentType, aQ as DocumentTypesSelect, aO as DocumentsSelect, E as EmailLog, ab as EmailLogsSelect, G as Exchange, H as ExchangeProduct, ax as ExchangeProductsSelect, aw as ExchangesSelect, F as Form, a3 as FormSubmission, aW as FormSubmissionsSelect, aV as FormsSelect, J as FulfillmentItem, az as FulfillmentItemsSelect, ay as FulfillmentsSelect, I as IframeBlock, M as Media, a9 as MediaSelect, a1 as Music, aU as MusicsSelect, at as OrderProductsSelect, as as OrdersSelect, a4 as PayloadKv, aX as PayloadKvSelect, a5 as PayloadLockedDocument, aY as PayloadLockedDocumentsSelect, a7 as PayloadMigration, a_ as PayloadMigrationsSelect, a6 as PayloadPreference, aZ as PayloadPreferencesSelect, e as PlayerBlock, a0 as Playlist, a2 as PlaylistImage, aT as PlaylistImagesSelect, aS as PlaylistsSelect, N as Post, V as PostAuthor, aN as PostAuthorsSelect, aK as PostCategoriesSelect, W as PostCategory, Q as PostImage, aM as PostImagesSelect, X as PostTag, aL as PostTagsSelect, aJ as PostsSelect, o as Product, am as ProductCategoriesSelect, r as ProductCategory, t as ProductCollection, ap as ProductCollectionsSelect, p as ProductImage, ao as ProductImagesSelect, al as ProductOptionsSelect, s as ProductTag, an as ProductTagsSelect, q as ProductVariant, ak as ProductVariantsSelect, aj as ProductsSelect, D as ReturnProduct, av as ReturnProductsSelect, au as ReturnsSelect, aI as ShippingPoliciesSelect, v as ShippingPolicy, m as Subscription, ah as SubscriptionsSelect, S as SupportedTimezones, h as Tenant, k as TenantLogo, ae as TenantLogosSelect, ad as TenantMetadataSelect, i as TenantMetadatum, j as TenantOgImage, af as TenantOgImagesSelect, ac as TenantsSelect, aA as TransactionsSelect, g as User, U as UserAuthOperations, a8 as UsersSelect } from './payload-types-COjt2QTn.cjs';
3
- import { F as FetchOptions, A as ApiQueryOptions, P as PayloadFindResponse, a as PayloadMutationResponse, C as ClientBrowserConfig, b as ClientState, c as ClientServerConfig } from './auth-C7hwnGOb.cjs';
4
- export { t as API_URLS, f as ApiError, y as ApiQueryReactOptions, w as ClientMetadata, g as ConfigError, d as DebugConfig, D as DeepPartial, s as Environment, e as ErrorLogger, E as ExtractArrayType, J as JwtPayload, N as NetworkError, x as PaginationMeta, R as RetryConfig, S as SDKError, T as TimeoutError, U as UsageLimitError, V as ValidationError, q as createApiKey, o as createServerToken, p as decodeServerToken, k as isApiError, l as isConfigError, h as isNetworkError, i as isSDKError, m as isTimeoutError, n as isUsageLimitError, j as isValidationError, r as parseApiKey, u as resolveApiUrl, v as verifyServerToken } from './auth-C7hwnGOb.cjs';
1
+ import { O as Order, a as OrderProduct, T as Transaction, b as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-BFIUYPDZ.cjs';
2
+ export { k as ApiUsage, ae as ApiUsageSelect, A as Audience, aa as AudiencesSelect, b0 as Auth, m as BillingHistory, ag as BillingHistorySelect, u as Brand, B as BrandLogo, aq as BrandLogosSelect, ap as BrandsSelect, K as Cart, aG as CartItemsSelect, aF as CartsSelect, f as CodeBlock, a$ as CollectionsWidget, c as Config, w as Customer, z as CustomerAddress, aC as CustomerAddressesSelect, d as CustomerAuthOperations, x as CustomerGroup, y as CustomerGroupImage, aE as CustomerGroupImagesSelect, aD as CustomerGroupsSelect, aB as CustomersSelect, L as Discount, aH as DiscountsSelect, Y as Document, aP as DocumentCategoriesSelect, $ as DocumentCategory, _ as DocumentImage, aR as DocumentImagesSelect, Z as DocumentType, aQ as DocumentTypesSelect, aO as DocumentsSelect, E as EmailLog, ab as EmailLogsSelect, G as Exchange, H as ExchangeProduct, ax as ExchangeProductsSelect, aw as ExchangesSelect, F as Form, a3 as FormSubmission, aW as FormSubmissionsSelect, aV as FormsSelect, J as FulfillmentItem, az as FulfillmentItemsSelect, ay as FulfillmentsSelect, I as IframeBlock, M as Media, a9 as MediaSelect, a1 as Music, aT as MusicsSelect, at as OrderProductsSelect, as as OrdersSelect, a4 as PayloadKv, aX as PayloadKvSelect, a5 as PayloadLockedDocument, aY as PayloadLockedDocumentsSelect, a7 as PayloadMigration, a_ as PayloadMigrationsSelect, a6 as PayloadPreference, aZ as PayloadPreferencesSelect, e as PlayerBlock, a0 as Playlist, a2 as PlaylistImage, aU as PlaylistImagesSelect, aS as PlaylistsSelect, N as Post, V as PostAuthor, aK as PostAuthorsSelect, aL as PostCategoriesSelect, W as PostCategory, Q as PostImage, aN as PostImagesSelect, X as PostTag, aM as PostTagsSelect, aJ as PostsSelect, o as Product, am as ProductCategoriesSelect, r as ProductCategory, t as ProductCollection, ao as ProductCollectionsSelect, p as ProductImage, ar as ProductImagesSelect, al as ProductOptionsSelect, s as ProductTag, an as ProductTagsSelect, q as ProductVariant, ak as ProductVariantsSelect, aj as ProductsSelect, D as ReturnProduct, av as ReturnProductsSelect, au as ReturnsSelect, aI as ShippingPoliciesSelect, v as ShippingPolicy, l as Subscription, af as SubscriptionsSelect, S as SupportedTimezones, h as Tenant, n as TenantLogo, ah as TenantLogosSelect, ad as TenantMetadataSelect, i as TenantMetadatum, j as TenantOgImage, ai as TenantOgImagesSelect, ac as TenantsSelect, aA as TransactionsSelect, g as User, U as UserAuthOperations, a8 as UsersSelect } from './payload-types-BFIUYPDZ.cjs';
3
+ import { F as FetchOptions, A as ApiQueryOptions, P as PayloadFindResponse, a as PayloadMutationResponse, C as ClientBrowserConfig, b as ClientState, c as ClientServerConfig } from './auth-CP8gKMvj.cjs';
4
+ export { t as API_URLS, f as ApiError, y as ApiQueryReactOptions, w as ClientMetadata, g as ConfigError, d as DebugConfig, D as DeepPartial, s as Environment, e as ErrorLogger, E as ExtractArrayType, J as JwtPayload, N as NetworkError, x as PaginationMeta, R as RetryConfig, S as SDKError, T as TimeoutError, U as UsageLimitError, V as ValidationError, q as createApiKey, o as createServerToken, p as decodeServerToken, k as isApiError, l as isConfigError, h as isNetworkError, i as isSDKError, m as isTimeoutError, n as isUsageLimitError, j as isValidationError, r as parseApiKey, u as resolveApiUrl, v as verifyServerToken } from './auth-CP8gKMvj.cjs';
5
5
  import * as _tanstack_react_query from '@tanstack/react-query';
6
6
  import { QueryClient } from '@tanstack/react-query';
7
- import { P as PublicCollection, C as CollectionType } from './webhook-CxTZjVol.cjs';
8
- export { b as COLLECTIONS, a as Collection, c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-CxTZjVol.cjs';
7
+ import { P as PublicCollection, C as CollectionType } from './webhook-BM5spkSP.cjs';
8
+ export { b as COLLECTIONS, a as Collection, c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-BM5spkSP.cjs';
9
9
  import { Metadata } from 'next';
10
10
  import { GenerateMetadataOptions } from './metadata.cjs';
11
11
  export { b as IMAGE_SIZES, I as ImageData, a as ImagePalette, f as ImagePlaceholderOptions, d as getImageLqip, e as getImagePalette, h as getImagePlaceholderStyle, c as getImageSrcSet, g as getImageUrl } from './image-TT8lTsk5.cjs';
@@ -35,7 +35,7 @@ type UpdateTransactionParams = {
35
35
  receiptUrl: Transaction['receiptUrl'];
36
36
  };
37
37
  type CheckoutParams = {
38
- cartId: number;
38
+ cartId: string;
39
39
  paymentId: string;
40
40
  orderNumber: string;
41
41
  customerSnapshot: {
@@ -49,7 +49,7 @@ type CreateFulfillmentParams = {
49
49
  carrier?: string;
50
50
  trackingNumber?: string;
51
51
  items: Array<{
52
- orderProduct: number;
52
+ orderProduct: string;
53
53
  quantity: number;
54
54
  }>;
55
55
  };
@@ -61,13 +61,13 @@ type CreateReturnParams = {
61
61
  reason?: 'change_of_mind' | 'defective' | 'wrong_delivery' | 'damaged' | 'other';
62
62
  reasonDetail?: string;
63
63
  returnProducts: Array<{
64
- orderProduct: number;
64
+ orderProduct: string;
65
65
  quantity: number;
66
66
  }>;
67
67
  refundAmount: number;
68
68
  };
69
69
  type UpdateReturnParams = {
70
- returnId: number;
70
+ returnId: string;
71
71
  status: 'processing' | 'approved' | 'rejected' | 'completed';
72
72
  };
73
73
  type ReturnWithRefundParams = {
@@ -75,7 +75,7 @@ type ReturnWithRefundParams = {
75
75
  reason?: string;
76
76
  reasonDetail?: string;
77
77
  returnProducts: Array<{
78
- orderProduct: number;
78
+ orderProduct: string;
79
79
  quantity: number;
80
80
  }>;
81
81
  refundAmount: number;
@@ -109,18 +109,18 @@ interface CartApiOptions {
109
109
  baseUrl?: string;
110
110
  }
111
111
  type AddItemParams = {
112
- cartId: number;
113
- product: number;
114
- variant: number;
115
- option: number;
112
+ cartId: string;
113
+ product: string;
114
+ variant: string;
115
+ option: string;
116
116
  quantity: number;
117
117
  };
118
118
  type UpdateItemParams = {
119
- cartItemId: number;
119
+ cartItemId: string;
120
120
  quantity: number;
121
121
  };
122
122
  type RemoveItemParams = {
123
- cartItemId: number;
123
+ cartItemId: string;
124
124
  };
125
125
  declare class CartApi {
126
126
  private readonly clientKey;
@@ -143,12 +143,12 @@ interface ProductApiOptions {
143
143
  }
144
144
  type StockCheckParams = {
145
145
  items: Array<{
146
- optionId: number;
146
+ optionId: string;
147
147
  quantity: number;
148
148
  }>;
149
149
  };
150
150
  type StockCheckResult = {
151
- optionId: number;
151
+ optionId: string;
152
152
  available: boolean;
153
153
  availableStock: number;
154
154
  requestedQuantity: number;
@@ -343,6 +343,15 @@ interface CustomerRefreshResponse {
343
343
  token: string;
344
344
  }
345
345
  interface CustomerAuthOptions {
346
+ /**
347
+ * Automatically persist token in localStorage.
348
+ * - `true`: uses default key `'customer-token'`
349
+ * - `string`: uses the given string as localStorage key
350
+ *
351
+ * Handles SSR safely (no-op on server).
352
+ * When set, `token` and `onTokenChange` are ignored.
353
+ */
354
+ persist?: boolean | string;
346
355
  /** Initial token (e.g. from SSR cookie) */
347
356
  token?: string;
348
357
  /** Called when token changes (login/logout) — use to persist in localStorage/cookie */
@@ -644,15 +653,15 @@ declare const formatOrderName: (options: ProductOption[]) => string;
644
653
 
645
654
  /**
646
655
  * Resolves a Payload CMS relation field value.
647
- * When depth is 0, relation fields return just the ID (number).
656
+ * When depth is 0, relation fields return just the ID (string or number).
648
657
  * When depth > 0, they return the full document object (T).
649
658
  * This utility normalizes both cases to T | null.
650
659
  *
651
- * @param ref - The relation field value (T, number, null, or undefined)
660
+ * @param ref - The relation field value (T, string, number, null, or undefined)
652
661
  * @returns The resolved document object, or null if not populated
653
662
  */
654
- declare const resolveRelation: <T>(ref: T | number | null | undefined) => T | null;
663
+ declare const resolveRelation: <T>(ref: T | string | number | null | undefined) => T | null;
655
664
  /** @deprecated Use `resolveRelation` instead */
656
- declare const objectFor: <T>(ref: T | number | null | undefined) => T | null;
665
+ declare const objectFor: <T>(ref: T | string | number | null | undefined) => T | null;
657
666
 
658
667
  export { type AddItemParams, ApiQueryOptions, BrowserClient, BrowserClient as BrowserClientType, CartApi, type CartApiOptions, CartItem, type CheckoutParams, ClientBrowserConfig, ClientServerConfig, ClientState, CollectionClient, type CollectionDetailQueryParams, type CollectionInfiniteQueryParams, CollectionQueryBuilder, type CollectionQueryParams, CollectionType, type CreateFulfillmentParams, type CreateOrderParams, type CreateReturnParams, CustomerAuth, type CustomerAuthOptions, type CustomerAuthResponse, type CustomerLoginData, type CustomerProfile, type CustomerRefreshResponse, type CustomerRegisterData, Fulfillment, type GetOrderParams, Order, OrderApi, type OrderApiOptions, OrderProduct, PayloadFindResponse, PayloadMutationResponse, ProductApi, type ProductApiOptions, ProductOption, PublicCollection, QueryHooks, type ReadOnlyQueryBuilder, type ReadOnlyQueryHooks, type RemoveItemParams, Return, type ReturnWithRefundParams, ServerClient, ServerClient as ServerClientType, type StockCheckParams, type StockCheckResponse, type StockCheckResult, Transaction, type UpdateItemParams, type UpdateOrderParams, type UpdateReturnParams, type UpdateTransactionParams, collectionKeys, createBrowserClient, createServerClient, customerKeys, formatOrderName, generateOrderNumber, getQueryClient, objectFor, resolveRelation };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { O as Order, a as OrderProduct, T as Transaction, b as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-COjt2QTn.js';
2
- export { l as ApiUsage, ag as ApiUsageSelect, A as Audience, aa as AudiencesSelect, a$ as Auth, n as BillingHistory, ai as BillingHistorySelect, u as Brand, B as BrandLogo, ar as BrandLogosSelect, aq as BrandsSelect, K as Cart, aG as CartItemsSelect, aF as CartsSelect, f as CodeBlock, c as Config, w as Customer, z as CustomerAddress, aC as CustomerAddressesSelect, d as CustomerAuthOperations, x as CustomerGroup, y as CustomerGroupImage, aE as CustomerGroupImagesSelect, aD as CustomerGroupsSelect, aB as CustomersSelect, L as Discount, aH as DiscountsSelect, Y as Document, aP as DocumentCategoriesSelect, $ as DocumentCategory, _ as DocumentImage, aR as DocumentImagesSelect, Z as DocumentType, aQ as DocumentTypesSelect, aO as DocumentsSelect, E as EmailLog, ab as EmailLogsSelect, G as Exchange, H as ExchangeProduct, ax as ExchangeProductsSelect, aw as ExchangesSelect, F as Form, a3 as FormSubmission, aW as FormSubmissionsSelect, aV as FormsSelect, J as FulfillmentItem, az as FulfillmentItemsSelect, ay as FulfillmentsSelect, I as IframeBlock, M as Media, a9 as MediaSelect, a1 as Music, aU as MusicsSelect, at as OrderProductsSelect, as as OrdersSelect, a4 as PayloadKv, aX as PayloadKvSelect, a5 as PayloadLockedDocument, aY as PayloadLockedDocumentsSelect, a7 as PayloadMigration, a_ as PayloadMigrationsSelect, a6 as PayloadPreference, aZ as PayloadPreferencesSelect, e as PlayerBlock, a0 as Playlist, a2 as PlaylistImage, aT as PlaylistImagesSelect, aS as PlaylistsSelect, N as Post, V as PostAuthor, aN as PostAuthorsSelect, aK as PostCategoriesSelect, W as PostCategory, Q as PostImage, aM as PostImagesSelect, X as PostTag, aL as PostTagsSelect, aJ as PostsSelect, o as Product, am as ProductCategoriesSelect, r as ProductCategory, t as ProductCollection, ap as ProductCollectionsSelect, p as ProductImage, ao as ProductImagesSelect, al as ProductOptionsSelect, s as ProductTag, an as ProductTagsSelect, q as ProductVariant, ak as ProductVariantsSelect, aj as ProductsSelect, D as ReturnProduct, av as ReturnProductsSelect, au as ReturnsSelect, aI as ShippingPoliciesSelect, v as ShippingPolicy, m as Subscription, ah as SubscriptionsSelect, S as SupportedTimezones, h as Tenant, k as TenantLogo, ae as TenantLogosSelect, ad as TenantMetadataSelect, i as TenantMetadatum, j as TenantOgImage, af as TenantOgImagesSelect, ac as TenantsSelect, aA as TransactionsSelect, g as User, U as UserAuthOperations, a8 as UsersSelect } from './payload-types-COjt2QTn.js';
3
- import { F as FetchOptions, A as ApiQueryOptions, P as PayloadFindResponse, a as PayloadMutationResponse, C as ClientBrowserConfig, b as ClientState, c as ClientServerConfig } from './auth-C-9PVtsp.js';
4
- export { t as API_URLS, f as ApiError, y as ApiQueryReactOptions, w as ClientMetadata, g as ConfigError, d as DebugConfig, D as DeepPartial, s as Environment, e as ErrorLogger, E as ExtractArrayType, J as JwtPayload, N as NetworkError, x as PaginationMeta, R as RetryConfig, S as SDKError, T as TimeoutError, U as UsageLimitError, V as ValidationError, q as createApiKey, o as createServerToken, p as decodeServerToken, k as isApiError, l as isConfigError, h as isNetworkError, i as isSDKError, m as isTimeoutError, n as isUsageLimitError, j as isValidationError, r as parseApiKey, u as resolveApiUrl, v as verifyServerToken } from './auth-C-9PVtsp.js';
1
+ import { O as Order, a as OrderProduct, T as Transaction, b as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-BFIUYPDZ.js';
2
+ export { k as ApiUsage, ae as ApiUsageSelect, A as Audience, aa as AudiencesSelect, b0 as Auth, m as BillingHistory, ag as BillingHistorySelect, u as Brand, B as BrandLogo, aq as BrandLogosSelect, ap as BrandsSelect, K as Cart, aG as CartItemsSelect, aF as CartsSelect, f as CodeBlock, a$ as CollectionsWidget, c as Config, w as Customer, z as CustomerAddress, aC as CustomerAddressesSelect, d as CustomerAuthOperations, x as CustomerGroup, y as CustomerGroupImage, aE as CustomerGroupImagesSelect, aD as CustomerGroupsSelect, aB as CustomersSelect, L as Discount, aH as DiscountsSelect, Y as Document, aP as DocumentCategoriesSelect, $ as DocumentCategory, _ as DocumentImage, aR as DocumentImagesSelect, Z as DocumentType, aQ as DocumentTypesSelect, aO as DocumentsSelect, E as EmailLog, ab as EmailLogsSelect, G as Exchange, H as ExchangeProduct, ax as ExchangeProductsSelect, aw as ExchangesSelect, F as Form, a3 as FormSubmission, aW as FormSubmissionsSelect, aV as FormsSelect, J as FulfillmentItem, az as FulfillmentItemsSelect, ay as FulfillmentsSelect, I as IframeBlock, M as Media, a9 as MediaSelect, a1 as Music, aT as MusicsSelect, at as OrderProductsSelect, as as OrdersSelect, a4 as PayloadKv, aX as PayloadKvSelect, a5 as PayloadLockedDocument, aY as PayloadLockedDocumentsSelect, a7 as PayloadMigration, a_ as PayloadMigrationsSelect, a6 as PayloadPreference, aZ as PayloadPreferencesSelect, e as PlayerBlock, a0 as Playlist, a2 as PlaylistImage, aU as PlaylistImagesSelect, aS as PlaylistsSelect, N as Post, V as PostAuthor, aK as PostAuthorsSelect, aL as PostCategoriesSelect, W as PostCategory, Q as PostImage, aN as PostImagesSelect, X as PostTag, aM as PostTagsSelect, aJ as PostsSelect, o as Product, am as ProductCategoriesSelect, r as ProductCategory, t as ProductCollection, ao as ProductCollectionsSelect, p as ProductImage, ar as ProductImagesSelect, al as ProductOptionsSelect, s as ProductTag, an as ProductTagsSelect, q as ProductVariant, ak as ProductVariantsSelect, aj as ProductsSelect, D as ReturnProduct, av as ReturnProductsSelect, au as ReturnsSelect, aI as ShippingPoliciesSelect, v as ShippingPolicy, l as Subscription, af as SubscriptionsSelect, S as SupportedTimezones, h as Tenant, n as TenantLogo, ah as TenantLogosSelect, ad as TenantMetadataSelect, i as TenantMetadatum, j as TenantOgImage, ai as TenantOgImagesSelect, ac as TenantsSelect, aA as TransactionsSelect, g as User, U as UserAuthOperations, a8 as UsersSelect } from './payload-types-BFIUYPDZ.js';
3
+ import { F as FetchOptions, A as ApiQueryOptions, P as PayloadFindResponse, a as PayloadMutationResponse, C as ClientBrowserConfig, b as ClientState, c as ClientServerConfig } from './auth-j2yUrezU.js';
4
+ export { t as API_URLS, f as ApiError, y as ApiQueryReactOptions, w as ClientMetadata, g as ConfigError, d as DebugConfig, D as DeepPartial, s as Environment, e as ErrorLogger, E as ExtractArrayType, J as JwtPayload, N as NetworkError, x as PaginationMeta, R as RetryConfig, S as SDKError, T as TimeoutError, U as UsageLimitError, V as ValidationError, q as createApiKey, o as createServerToken, p as decodeServerToken, k as isApiError, l as isConfigError, h as isNetworkError, i as isSDKError, m as isTimeoutError, n as isUsageLimitError, j as isValidationError, r as parseApiKey, u as resolveApiUrl, v as verifyServerToken } from './auth-j2yUrezU.js';
5
5
  import * as _tanstack_react_query from '@tanstack/react-query';
6
6
  import { QueryClient } from '@tanstack/react-query';
7
- import { P as PublicCollection, C as CollectionType } from './webhook-DhK15oyO.js';
8
- export { b as COLLECTIONS, a as Collection, c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-DhK15oyO.js';
7
+ import { P as PublicCollection, C as CollectionType } from './webhook-BBp77Khg.js';
8
+ export { b as COLLECTIONS, a as Collection, c as WebhookEvent, d as WebhookHandler, W as WebhookOperation, e as WebhookOptions, f as createTypedWebhookHandler, h as handleWebhook, i as isValidWebhookEvent } from './webhook-BBp77Khg.js';
9
9
  import { Metadata } from 'next';
10
10
  import { GenerateMetadataOptions } from './metadata.js';
11
11
  export { b as IMAGE_SIZES, I as ImageData, a as ImagePalette, f as ImagePlaceholderOptions, d as getImageLqip, e as getImagePalette, h as getImagePlaceholderStyle, c as getImageSrcSet, g as getImageUrl } from './image-TT8lTsk5.js';
@@ -35,7 +35,7 @@ type UpdateTransactionParams = {
35
35
  receiptUrl: Transaction['receiptUrl'];
36
36
  };
37
37
  type CheckoutParams = {
38
- cartId: number;
38
+ cartId: string;
39
39
  paymentId: string;
40
40
  orderNumber: string;
41
41
  customerSnapshot: {
@@ -49,7 +49,7 @@ type CreateFulfillmentParams = {
49
49
  carrier?: string;
50
50
  trackingNumber?: string;
51
51
  items: Array<{
52
- orderProduct: number;
52
+ orderProduct: string;
53
53
  quantity: number;
54
54
  }>;
55
55
  };
@@ -61,13 +61,13 @@ type CreateReturnParams = {
61
61
  reason?: 'change_of_mind' | 'defective' | 'wrong_delivery' | 'damaged' | 'other';
62
62
  reasonDetail?: string;
63
63
  returnProducts: Array<{
64
- orderProduct: number;
64
+ orderProduct: string;
65
65
  quantity: number;
66
66
  }>;
67
67
  refundAmount: number;
68
68
  };
69
69
  type UpdateReturnParams = {
70
- returnId: number;
70
+ returnId: string;
71
71
  status: 'processing' | 'approved' | 'rejected' | 'completed';
72
72
  };
73
73
  type ReturnWithRefundParams = {
@@ -75,7 +75,7 @@ type ReturnWithRefundParams = {
75
75
  reason?: string;
76
76
  reasonDetail?: string;
77
77
  returnProducts: Array<{
78
- orderProduct: number;
78
+ orderProduct: string;
79
79
  quantity: number;
80
80
  }>;
81
81
  refundAmount: number;
@@ -109,18 +109,18 @@ interface CartApiOptions {
109
109
  baseUrl?: string;
110
110
  }
111
111
  type AddItemParams = {
112
- cartId: number;
113
- product: number;
114
- variant: number;
115
- option: number;
112
+ cartId: string;
113
+ product: string;
114
+ variant: string;
115
+ option: string;
116
116
  quantity: number;
117
117
  };
118
118
  type UpdateItemParams = {
119
- cartItemId: number;
119
+ cartItemId: string;
120
120
  quantity: number;
121
121
  };
122
122
  type RemoveItemParams = {
123
- cartItemId: number;
123
+ cartItemId: string;
124
124
  };
125
125
  declare class CartApi {
126
126
  private readonly clientKey;
@@ -143,12 +143,12 @@ interface ProductApiOptions {
143
143
  }
144
144
  type StockCheckParams = {
145
145
  items: Array<{
146
- optionId: number;
146
+ optionId: string;
147
147
  quantity: number;
148
148
  }>;
149
149
  };
150
150
  type StockCheckResult = {
151
- optionId: number;
151
+ optionId: string;
152
152
  available: boolean;
153
153
  availableStock: number;
154
154
  requestedQuantity: number;
@@ -343,6 +343,15 @@ interface CustomerRefreshResponse {
343
343
  token: string;
344
344
  }
345
345
  interface CustomerAuthOptions {
346
+ /**
347
+ * Automatically persist token in localStorage.
348
+ * - `true`: uses default key `'customer-token'`
349
+ * - `string`: uses the given string as localStorage key
350
+ *
351
+ * Handles SSR safely (no-op on server).
352
+ * When set, `token` and `onTokenChange` are ignored.
353
+ */
354
+ persist?: boolean | string;
346
355
  /** Initial token (e.g. from SSR cookie) */
347
356
  token?: string;
348
357
  /** Called when token changes (login/logout) — use to persist in localStorage/cookie */
@@ -644,15 +653,15 @@ declare const formatOrderName: (options: ProductOption[]) => string;
644
653
 
645
654
  /**
646
655
  * Resolves a Payload CMS relation field value.
647
- * When depth is 0, relation fields return just the ID (number).
656
+ * When depth is 0, relation fields return just the ID (string or number).
648
657
  * When depth > 0, they return the full document object (T).
649
658
  * This utility normalizes both cases to T | null.
650
659
  *
651
- * @param ref - The relation field value (T, number, null, or undefined)
660
+ * @param ref - The relation field value (T, string, number, null, or undefined)
652
661
  * @returns The resolved document object, or null if not populated
653
662
  */
654
- declare const resolveRelation: <T>(ref: T | number | null | undefined) => T | null;
663
+ declare const resolveRelation: <T>(ref: T | string | number | null | undefined) => T | null;
655
664
  /** @deprecated Use `resolveRelation` instead */
656
- declare const objectFor: <T>(ref: T | number | null | undefined) => T | null;
665
+ declare const objectFor: <T>(ref: T | string | number | null | undefined) => T | null;
657
666
 
658
667
  export { type AddItemParams, ApiQueryOptions, BrowserClient, BrowserClient as BrowserClientType, CartApi, type CartApiOptions, CartItem, type CheckoutParams, ClientBrowserConfig, ClientServerConfig, ClientState, CollectionClient, type CollectionDetailQueryParams, type CollectionInfiniteQueryParams, CollectionQueryBuilder, type CollectionQueryParams, CollectionType, type CreateFulfillmentParams, type CreateOrderParams, type CreateReturnParams, CustomerAuth, type CustomerAuthOptions, type CustomerAuthResponse, type CustomerLoginData, type CustomerProfile, type CustomerRefreshResponse, type CustomerRegisterData, Fulfillment, type GetOrderParams, Order, OrderApi, type OrderApiOptions, OrderProduct, PayloadFindResponse, PayloadMutationResponse, ProductApi, type ProductApiOptions, ProductOption, PublicCollection, QueryHooks, type ReadOnlyQueryBuilder, type ReadOnlyQueryHooks, type RemoveItemParams, Return, type ReturnWithRefundParams, ServerClient, ServerClient as ServerClientType, type StockCheckParams, type StockCheckResponse, type StockCheckResult, Transaction, type UpdateItemParams, type UpdateOrderParams, type UpdateReturnParams, type UpdateTransactionParams, collectionKeys, createBrowserClient, createServerClient, customerKeys, formatOrderName, generateOrderNumber, getQueryClient, objectFor, resolveRelation };
package/dist/index.js CHANGED
@@ -633,7 +633,8 @@ var ProductApi = class {
633
633
 
634
634
  // src/utils/types.ts
635
635
  var resolveRelation = (ref) => {
636
- if (typeof ref === "number" || ref === null || ref === void 0) return null;
636
+ if (typeof ref === "string" || typeof ref === "number" || ref === null || ref === void 0)
637
+ return null;
637
638
  return ref;
638
639
  };
639
640
  var objectFor = resolveRelation;
@@ -1078,11 +1079,21 @@ var COLLECTIONS = [
1078
1079
  var DEFAULT_TIMEOUT2 = 15e3;
1079
1080
  var CustomerAuth = class {
1080
1081
  constructor(clientKey, baseUrl, options) {
1081
- var _a;
1082
+ var _a, _b;
1082
1083
  this.clientKey = clientKey;
1083
1084
  this.baseUrl = baseUrl;
1084
- this.token = (_a = options == null ? void 0 : options.token) != null ? _a : null;
1085
- this.onTokenChange = options == null ? void 0 : options.onTokenChange;
1085
+ if (options == null ? void 0 : options.persist) {
1086
+ const key = typeof options.persist === "string" ? options.persist : "customer-token";
1087
+ const isBrowser = typeof window !== "undefined";
1088
+ this.token = isBrowser ? (_a = localStorage.getItem(key)) != null ? _a : null : null;
1089
+ this.onTokenChange = isBrowser ? (token) => {
1090
+ if (token) localStorage.setItem(key, token);
1091
+ else localStorage.removeItem(key);
1092
+ } : void 0;
1093
+ } else {
1094
+ this.token = (_b = options == null ? void 0 : options.token) != null ? _b : null;
1095
+ this.onTokenChange = options == null ? void 0 : options.onTokenChange;
1096
+ }
1086
1097
  }
1087
1098
  /**
1088
1099
  * Register a new customer account
@@ -1261,7 +1272,11 @@ var CustomerAuth = class {
1261
1272
  body.error
1262
1273
  );
1263
1274
  }
1264
- return res.json();
1275
+ try {
1276
+ return yield res.json();
1277
+ } catch (e) {
1278
+ throw new ApiError("Invalid JSON response from server", res.status, void 0, "INVALID_RESPONSE");
1279
+ }
1265
1280
  });
1266
1281
  }
1267
1282
  };
@@ -1272,7 +1287,9 @@ function makeQueryClient() {
1272
1287
  return new QueryClient({
1273
1288
  defaultOptions: {
1274
1289
  queries: {
1275
- // SSR/RSC: server-fetched data doesn't auto-refetch; use refetch()/invalidate() to refresh
1290
+ // Infinite staleTime: server-fetched data persists until explicitly invalidated.
1291
+ // For browser clients needing fresher data, override per-query:
1292
+ // useQuery({ ..., staleTime: 5 * 60 * 1000 })
1276
1293
  staleTime: Number.POSITIVE_INFINITY,
1277
1294
  refetchOnWindowFocus: false
1278
1295
  },