@01.software/sdk 0.1.8 → 0.2.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/dist/index.d.cts CHANGED
@@ -1,11 +1,13 @@
1
- import { O as Order, a as OrderProduct, T as Transaction, F as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-DcOQUD4x.cjs';
2
- export { k as ApiUsage, ag as ApiUsageSelect, A as Audience, aa as AudiencesSelect, a$ as Auth, N as Author, aM as AuthorsSelect, m as BillingHistory, ai as BillingHistorySelect, s as Brand, B as BrandLogo, aq as BrandLogosSelect, ap as BrandsSelect, H as Cart, aF as CartItemsSelect, aE as CartsSelect, e as CodeBlock, b as Config, u as Customer, x as CustomerAddress, aB as CustomerAddressesSelect, c as CustomerAuthOperations, v as CustomerGroup, w as CustomerGroupImage, aD as CustomerGroupImagesSelect, aC as CustomerGroupsSelect, aA as CustomersSelect, J as Discount, aG as DiscountsSelect, W as Document, aO as DocumentCategoriesSelect, X as DocumentCategory, Y as DocumentImage, aP as DocumentImagesSelect, aN as DocumentsSelect, E as EmailLog, ab as EmailLogsSelect, z as Exchange, D as ExchangeProduct, aw as ExchangeProductsSelect, av as ExchangesSelect, a2 as Form, a3 as FormSubmission, aW as FormSubmissionsSelect, aV as FormsSelect, G as FulfillmentItem, ay as FulfillmentItemsSelect, ax as FulfillmentsSelect, aT as GalleriesSelect, a0 as Gallery, a1 as GalleryImage, aU as GalleryImagesSelect, I as IframeBlock, M as Media, a9 as MediaSelect, _ as Music, aS as MusicsSelect, as as OrderProductsSelect, ar 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, d as PlayerBlock, Z as Playlist, $ as PlaylistImage, aR as PlaylistImagesSelect, aQ as PlaylistsSelect, K as Post, aJ as PostCategoriesSelect, Q as PostCategory, L as PostImage, aL as PostImagesSelect, V as PostTag, aK as PostTagsSelect, aI as PostsSelect, n as Product, am as ProductCategoriesSelect, q as ProductCategory, o as ProductImage, ao as ProductImagesSelect, al as ProductOptionsSelect, r as ProductTag, an as ProductTagsSelect, p as ProductVariant, ak as ProductVariantsSelect, aj as ProductsSelect, y as ReturnProduct, au as ReturnProductsSelect, at as ReturnsSelect, aH as ShippingPoliciesSelect, t as ShippingPolicy, l as Subscription, ah as SubscriptionsSelect, S as SupportedTimezones, g as Tenant, j as TenantLogo, ae as TenantLogosSelect, ad as TenantMetadataSelect, h as TenantMetadatum, i as TenantOgImage, af as TenantOgImagesSelect, ac as TenantsSelect, az as TransactionsSelect, f as User, U as UserAuthOperations, a8 as UsersSelect } from './payload-types-DcOQUD4x.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-BnCTXZG0.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-BnCTXZG0.cjs';
1
+ import { O as Order, a as OrderProduct, T as Transaction, F as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-BWJZhklJ.cjs';
2
+ export { k as ApiUsage, af as ApiUsageSelect, A as Audience, a9 as AudiencesSelect, aZ as Auth, Q as Author, aM as AuthorsSelect, m as BillingHistory, ah as BillingHistorySelect, t as Brand, B as BrandLogo, aq as BrandLogosSelect, ap as BrandsSelect, J as Cart, aF as CartItemsSelect, aE as CartsSelect, e as CodeBlock, b as Config, v as Customer, y as CustomerAddress, aB as CustomerAddressesSelect, c as CustomerAuthOperations, w as CustomerGroup, x as CustomerGroupImage, aD as CustomerGroupImagesSelect, aC as CustomerGroupsSelect, aA as CustomersSelect, K as Discount, aG as DiscountsSelect, X as Document, aO as DocumentCategoriesSelect, Y as DocumentCategory, Z as DocumentImage, aP as DocumentImagesSelect, aN as DocumentsSelect, E as EmailLog, aa as EmailLogsSelect, D as Exchange, G as ExchangeProduct, aw as ExchangeProductsSelect, av as ExchangesSelect, a1 as Form, a2 as FormSubmission, aU as FormSubmissionsSelect, aT as FormsSelect, H as FulfillmentItem, ay as FulfillmentItemsSelect, ax as FulfillmentsSelect, I as IframeBlock, M as Media, a8 as MediaSelect, $ as Music, aS as MusicsSelect, as as OrderProductsSelect, ar as OrdersSelect, a3 as PayloadKv, aV as PayloadKvSelect, a4 as PayloadLockedDocument, aW as PayloadLockedDocumentsSelect, a6 as PayloadMigration, aY as PayloadMigrationsSelect, a5 as PayloadPreference, aX as PayloadPreferencesSelect, d as PlayerBlock, _ as Playlist, a0 as PlaylistImage, aR as PlaylistImagesSelect, aQ as PlaylistsSelect, L as Post, aJ as PostCategoriesSelect, V as PostCategory, N as PostImage, aL as PostImagesSelect, W as PostTag, aK as PostTagsSelect, aI as PostsSelect, n as Product, al as ProductCategoriesSelect, q as ProductCategory, s as ProductCollection, ao as ProductCollectionsSelect, o as ProductImage, an as ProductImagesSelect, ak as ProductOptionsSelect, r as ProductTag, am as ProductTagsSelect, p as ProductVariant, aj as ProductVariantsSelect, ai as ProductsSelect, z as ReturnProduct, au as ReturnProductsSelect, at as ReturnsSelect, aH as ShippingPoliciesSelect, u as ShippingPolicy, l as Subscription, ag as SubscriptionsSelect, S as SupportedTimezones, g as Tenant, j as TenantLogo, ad as TenantLogosSelect, ac as TenantMetadataSelect, h as TenantMetadatum, i as TenantOgImage, ae as TenantOgImagesSelect, ab as TenantsSelect, az as TransactionsSelect, f as User, U as UserAuthOperations, a7 as UsersSelect } from './payload-types-BWJZhklJ.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-BE80zCjC.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-BE80zCjC.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-E1YlE_k1.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-E1YlE_k1.cjs';
7
+ import { P as PublicCollection, C as CollectionType } from './webhook-DMxUpnQD.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-DMxUpnQD.cjs';
9
+ import { Metadata } from 'next';
10
+ import { GenerateMetadataOptions } from './metadata.cjs';
9
11
  export { RichTextContent, RichTextContentProps, RichTextData } from './components.cjs';
10
12
  import 'payload';
11
13
  import 'react';
@@ -251,7 +253,7 @@ declare class CollectionClient extends HttpClient {
251
253
  * Read-only subset of CollectionQueryBuilder.
252
254
  * BrowserClient.from() returns this type to prevent write operations at compile time.
253
255
  */
254
- type ReadOnlyQueryBuilder<T extends PublicCollection> = Pick<CollectionQueryBuilder<T>, 'find' | 'findById' | 'count'>;
256
+ type ReadOnlyQueryBuilder<T extends PublicCollection> = Pick<CollectionQueryBuilder<T>, 'find' | 'findById' | 'count' | 'findMetadata' | 'findMetadataById'>;
255
257
  declare class CollectionQueryBuilder<T extends PublicCollection> {
256
258
  private api;
257
259
  private collection;
@@ -288,6 +290,18 @@ declare class CollectionQueryBuilder<T extends PublicCollection> {
288
290
  count(options?: ApiQueryOptions): Promise<{
289
291
  totalDocs: number;
290
292
  }>;
293
+ /**
294
+ * Find first matching document and return its Next.js Metadata.
295
+ * Applies depth: 1 (image populate) and limit: 1 automatically.
296
+ * @returns Metadata or null if no document matches
297
+ */
298
+ findMetadata(options?: ApiQueryOptions, metadataOptions?: GenerateMetadataOptions): Promise<Metadata | null>;
299
+ /**
300
+ * Find document by ID and return its Next.js Metadata.
301
+ * Applies depth: 1 (image populate) automatically.
302
+ * @returns Metadata (throws on 404)
303
+ */
304
+ findMetadataById(id: number | string, metadataOptions?: GenerateMetadataOptions): Promise<Metadata>;
291
305
  /**
292
306
  * Update multiple documents (bulk update)
293
307
  * PATCH /api/{collection}
@@ -628,6 +642,43 @@ declare function createServerClient(options: ClientServerConfig): ServerClient;
628
642
 
629
643
  declare function getQueryClient(): QueryClient;
630
644
 
645
+ /** Common image data shape from Payload CMS upload collections */
646
+ interface ImageData {
647
+ url?: string | null;
648
+ width?: number | null;
649
+ height?: number | null;
650
+ alt?: string | null;
651
+ sizes?: Record<string, {
652
+ url?: string | null;
653
+ width?: number | null;
654
+ height?: number | null;
655
+ } | undefined>;
656
+ }
657
+ /** Pre-generated image size breakpoints (px) */
658
+ declare const IMAGE_SIZES: readonly [384, 768, 1536];
659
+ /**
660
+ * Returns the optimal image URL for a given display width.
661
+ *
662
+ * Picks the smallest pre-generated size whose width >= displayWidth × dpr.
663
+ * Falls back to the original URL when no matching size exists.
664
+ *
665
+ * @param image - Payload image document
666
+ * @param displayWidth - CSS pixel width the image will be displayed at
667
+ * @param dpr - Device pixel ratio (default: 1)
668
+ * @returns URL string, or empty string if no URL is available
669
+ */
670
+ declare function getImageUrl(image: ImageData, displayWidth: number, dpr?: number): string;
671
+ /**
672
+ * Generates an HTML `srcset` attribute string from pre-generated sizes.
673
+ *
674
+ * Includes all available sizes plus the original image.
675
+ * Example output: `"url-384 384w, url-768 768w, url-1536 1536w, url-original 2000w"`
676
+ *
677
+ * @param image - Payload image document
678
+ * @returns srcset string, or empty string if no URLs are available
679
+ */
680
+ declare function getImageSrcSet(image: ImageData): string;
681
+
631
682
  declare const generateOrderNumber: () => string;
632
683
 
633
684
  declare const formatOrderName: (options: ProductOption[]) => string;
@@ -645,4 +696,4 @@ declare const resolveRelation: <T>(ref: T | number | null | undefined) => T | nu
645
696
  /** @deprecated Use `resolveRelation` instead */
646
697
  declare const objectFor: <T>(ref: T | number | null | undefined) => T | null;
647
698
 
648
- 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 };
699
+ 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, IMAGE_SIZES, type ImageData, 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, getImageSrcSet, getImageUrl, getQueryClient, objectFor, resolveRelation };
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
- import { O as Order, a as OrderProduct, T as Transaction, F as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-DcOQUD4x.js';
2
- export { k as ApiUsage, ag as ApiUsageSelect, A as Audience, aa as AudiencesSelect, a$ as Auth, N as Author, aM as AuthorsSelect, m as BillingHistory, ai as BillingHistorySelect, s as Brand, B as BrandLogo, aq as BrandLogosSelect, ap as BrandsSelect, H as Cart, aF as CartItemsSelect, aE as CartsSelect, e as CodeBlock, b as Config, u as Customer, x as CustomerAddress, aB as CustomerAddressesSelect, c as CustomerAuthOperations, v as CustomerGroup, w as CustomerGroupImage, aD as CustomerGroupImagesSelect, aC as CustomerGroupsSelect, aA as CustomersSelect, J as Discount, aG as DiscountsSelect, W as Document, aO as DocumentCategoriesSelect, X as DocumentCategory, Y as DocumentImage, aP as DocumentImagesSelect, aN as DocumentsSelect, E as EmailLog, ab as EmailLogsSelect, z as Exchange, D as ExchangeProduct, aw as ExchangeProductsSelect, av as ExchangesSelect, a2 as Form, a3 as FormSubmission, aW as FormSubmissionsSelect, aV as FormsSelect, G as FulfillmentItem, ay as FulfillmentItemsSelect, ax as FulfillmentsSelect, aT as GalleriesSelect, a0 as Gallery, a1 as GalleryImage, aU as GalleryImagesSelect, I as IframeBlock, M as Media, a9 as MediaSelect, _ as Music, aS as MusicsSelect, as as OrderProductsSelect, ar 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, d as PlayerBlock, Z as Playlist, $ as PlaylistImage, aR as PlaylistImagesSelect, aQ as PlaylistsSelect, K as Post, aJ as PostCategoriesSelect, Q as PostCategory, L as PostImage, aL as PostImagesSelect, V as PostTag, aK as PostTagsSelect, aI as PostsSelect, n as Product, am as ProductCategoriesSelect, q as ProductCategory, o as ProductImage, ao as ProductImagesSelect, al as ProductOptionsSelect, r as ProductTag, an as ProductTagsSelect, p as ProductVariant, ak as ProductVariantsSelect, aj as ProductsSelect, y as ReturnProduct, au as ReturnProductsSelect, at as ReturnsSelect, aH as ShippingPoliciesSelect, t as ShippingPolicy, l as Subscription, ah as SubscriptionsSelect, S as SupportedTimezones, g as Tenant, j as TenantLogo, ae as TenantLogosSelect, ad as TenantMetadataSelect, h as TenantMetadatum, i as TenantOgImage, af as TenantOgImagesSelect, ac as TenantsSelect, az as TransactionsSelect, f as User, U as UserAuthOperations, a8 as UsersSelect } from './payload-types-DcOQUD4x.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-Cxfq94pG.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-Cxfq94pG.js';
1
+ import { O as Order, a as OrderProduct, T as Transaction, F as Fulfillment, R as Return, C as CartItem, P as ProductOption } from './payload-types-BWJZhklJ.js';
2
+ export { k as ApiUsage, af as ApiUsageSelect, A as Audience, a9 as AudiencesSelect, aZ as Auth, Q as Author, aM as AuthorsSelect, m as BillingHistory, ah as BillingHistorySelect, t as Brand, B as BrandLogo, aq as BrandLogosSelect, ap as BrandsSelect, J as Cart, aF as CartItemsSelect, aE as CartsSelect, e as CodeBlock, b as Config, v as Customer, y as CustomerAddress, aB as CustomerAddressesSelect, c as CustomerAuthOperations, w as CustomerGroup, x as CustomerGroupImage, aD as CustomerGroupImagesSelect, aC as CustomerGroupsSelect, aA as CustomersSelect, K as Discount, aG as DiscountsSelect, X as Document, aO as DocumentCategoriesSelect, Y as DocumentCategory, Z as DocumentImage, aP as DocumentImagesSelect, aN as DocumentsSelect, E as EmailLog, aa as EmailLogsSelect, D as Exchange, G as ExchangeProduct, aw as ExchangeProductsSelect, av as ExchangesSelect, a1 as Form, a2 as FormSubmission, aU as FormSubmissionsSelect, aT as FormsSelect, H as FulfillmentItem, ay as FulfillmentItemsSelect, ax as FulfillmentsSelect, I as IframeBlock, M as Media, a8 as MediaSelect, $ as Music, aS as MusicsSelect, as as OrderProductsSelect, ar as OrdersSelect, a3 as PayloadKv, aV as PayloadKvSelect, a4 as PayloadLockedDocument, aW as PayloadLockedDocumentsSelect, a6 as PayloadMigration, aY as PayloadMigrationsSelect, a5 as PayloadPreference, aX as PayloadPreferencesSelect, d as PlayerBlock, _ as Playlist, a0 as PlaylistImage, aR as PlaylistImagesSelect, aQ as PlaylistsSelect, L as Post, aJ as PostCategoriesSelect, V as PostCategory, N as PostImage, aL as PostImagesSelect, W as PostTag, aK as PostTagsSelect, aI as PostsSelect, n as Product, al as ProductCategoriesSelect, q as ProductCategory, s as ProductCollection, ao as ProductCollectionsSelect, o as ProductImage, an as ProductImagesSelect, ak as ProductOptionsSelect, r as ProductTag, am as ProductTagsSelect, p as ProductVariant, aj as ProductVariantsSelect, ai as ProductsSelect, z as ReturnProduct, au as ReturnProductsSelect, at as ReturnsSelect, aH as ShippingPoliciesSelect, u as ShippingPolicy, l as Subscription, ag as SubscriptionsSelect, S as SupportedTimezones, g as Tenant, j as TenantLogo, ad as TenantLogosSelect, ac as TenantMetadataSelect, h as TenantMetadatum, i as TenantOgImage, ae as TenantOgImagesSelect, ab as TenantsSelect, az as TransactionsSelect, f as User, U as UserAuthOperations, a7 as UsersSelect } from './payload-types-BWJZhklJ.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-BC0CWHt_.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-BC0CWHt_.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-xdgxEN8s.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-xdgxEN8s.js';
7
+ import { P as PublicCollection, C as CollectionType } from './webhook-CcdyGpCb.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-CcdyGpCb.js';
9
+ import { Metadata } from 'next';
10
+ import { GenerateMetadataOptions } from './metadata.js';
9
11
  export { RichTextContent, RichTextContentProps, RichTextData } from './components.js';
10
12
  import 'payload';
11
13
  import 'react';
@@ -251,7 +253,7 @@ declare class CollectionClient extends HttpClient {
251
253
  * Read-only subset of CollectionQueryBuilder.
252
254
  * BrowserClient.from() returns this type to prevent write operations at compile time.
253
255
  */
254
- type ReadOnlyQueryBuilder<T extends PublicCollection> = Pick<CollectionQueryBuilder<T>, 'find' | 'findById' | 'count'>;
256
+ type ReadOnlyQueryBuilder<T extends PublicCollection> = Pick<CollectionQueryBuilder<T>, 'find' | 'findById' | 'count' | 'findMetadata' | 'findMetadataById'>;
255
257
  declare class CollectionQueryBuilder<T extends PublicCollection> {
256
258
  private api;
257
259
  private collection;
@@ -288,6 +290,18 @@ declare class CollectionQueryBuilder<T extends PublicCollection> {
288
290
  count(options?: ApiQueryOptions): Promise<{
289
291
  totalDocs: number;
290
292
  }>;
293
+ /**
294
+ * Find first matching document and return its Next.js Metadata.
295
+ * Applies depth: 1 (image populate) and limit: 1 automatically.
296
+ * @returns Metadata or null if no document matches
297
+ */
298
+ findMetadata(options?: ApiQueryOptions, metadataOptions?: GenerateMetadataOptions): Promise<Metadata | null>;
299
+ /**
300
+ * Find document by ID and return its Next.js Metadata.
301
+ * Applies depth: 1 (image populate) automatically.
302
+ * @returns Metadata (throws on 404)
303
+ */
304
+ findMetadataById(id: number | string, metadataOptions?: GenerateMetadataOptions): Promise<Metadata>;
291
305
  /**
292
306
  * Update multiple documents (bulk update)
293
307
  * PATCH /api/{collection}
@@ -628,6 +642,43 @@ declare function createServerClient(options: ClientServerConfig): ServerClient;
628
642
 
629
643
  declare function getQueryClient(): QueryClient;
630
644
 
645
+ /** Common image data shape from Payload CMS upload collections */
646
+ interface ImageData {
647
+ url?: string | null;
648
+ width?: number | null;
649
+ height?: number | null;
650
+ alt?: string | null;
651
+ sizes?: Record<string, {
652
+ url?: string | null;
653
+ width?: number | null;
654
+ height?: number | null;
655
+ } | undefined>;
656
+ }
657
+ /** Pre-generated image size breakpoints (px) */
658
+ declare const IMAGE_SIZES: readonly [384, 768, 1536];
659
+ /**
660
+ * Returns the optimal image URL for a given display width.
661
+ *
662
+ * Picks the smallest pre-generated size whose width >= displayWidth × dpr.
663
+ * Falls back to the original URL when no matching size exists.
664
+ *
665
+ * @param image - Payload image document
666
+ * @param displayWidth - CSS pixel width the image will be displayed at
667
+ * @param dpr - Device pixel ratio (default: 1)
668
+ * @returns URL string, or empty string if no URL is available
669
+ */
670
+ declare function getImageUrl(image: ImageData, displayWidth: number, dpr?: number): string;
671
+ /**
672
+ * Generates an HTML `srcset` attribute string from pre-generated sizes.
673
+ *
674
+ * Includes all available sizes plus the original image.
675
+ * Example output: `"url-384 384w, url-768 768w, url-1536 1536w, url-original 2000w"`
676
+ *
677
+ * @param image - Payload image document
678
+ * @returns srcset string, or empty string if no URLs are available
679
+ */
680
+ declare function getImageSrcSet(image: ImageData): string;
681
+
631
682
  declare const generateOrderNumber: () => string;
632
683
 
633
684
  declare const formatOrderName: (options: ProductOption[]) => string;
@@ -645,4 +696,4 @@ declare const resolveRelation: <T>(ref: T | number | null | undefined) => T | nu
645
696
  /** @deprecated Use `resolveRelation` instead */
646
697
  declare const objectFor: <T>(ref: T | number | null | undefined) => T | null;
647
698
 
648
- 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 };
699
+ 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, IMAGE_SIZES, type ImageData, 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, getImageSrcSet, getImageUrl, getQueryClient, objectFor, resolveRelation };
package/dist/index.js CHANGED
@@ -631,6 +631,37 @@ var ProductApi = class {
631
631
  }
632
632
  };
633
633
 
634
+ // src/utils/types.ts
635
+ var resolveRelation = (ref) => {
636
+ if (typeof ref === "number" || ref === null || ref === void 0) return null;
637
+ return ref;
638
+ };
639
+ var objectFor = resolveRelation;
640
+
641
+ // src/core/metadata/index.ts
642
+ function generateMetadata(doc, options) {
643
+ var _a, _b, _c, _d;
644
+ const meta = doc == null ? void 0 : doc.meta;
645
+ const title = (_b = (_a = meta == null ? void 0 : meta.title) != null ? _a : options == null ? void 0 : options.title) != null ? _b : void 0;
646
+ const description = (_d = (_c = meta == null ? void 0 : meta.description) != null ? _c : options == null ? void 0 : options.description) != null ? _d : void 0;
647
+ const image = resolveMetaImage(meta == null ? void 0 : meta.image);
648
+ return {
649
+ title,
650
+ description,
651
+ openGraph: __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, title && { title }), description && { description }), (options == null ? void 0 : options.siteName) && { siteName: options.siteName }), image && { images: [image] }),
652
+ twitter: __spreadValues(__spreadValues(__spreadValues({
653
+ card: image ? "summary_large_image" : "summary"
654
+ }, title && { title }), description && { description }), image && { images: [image.url] })
655
+ };
656
+ }
657
+ function resolveMetaImage(ref) {
658
+ const media = resolveRelation(ref);
659
+ if (!(media == null ? void 0 : media.url)) return null;
660
+ return __spreadValues(__spreadValues(__spreadValues({
661
+ url: media.url
662
+ }, media.width && { width: media.width }), media.height && { height: media.height }), media.alt && { alt: media.alt });
663
+ }
664
+
634
665
  // src/core/collection/query-builder.ts
635
666
  var CollectionQueryBuilder = class {
636
667
  constructor(api, collection) {
@@ -702,6 +733,36 @@ var CollectionQueryBuilder = class {
702
733
  );
703
734
  });
704
735
  }
736
+ /**
737
+ * Find first matching document and return its Next.js Metadata.
738
+ * Applies depth: 1 (image populate) and limit: 1 automatically.
739
+ * @returns Metadata or null if no document matches
740
+ */
741
+ findMetadata(options, metadataOptions) {
742
+ return __async(this, null, function* () {
743
+ const { docs } = yield this.find(__spreadProps(__spreadValues({}, options), { limit: 1, depth: 1 }));
744
+ const doc = docs[0];
745
+ if (!doc) return null;
746
+ return generateMetadata(
747
+ doc,
748
+ metadataOptions
749
+ );
750
+ });
751
+ }
752
+ /**
753
+ * Find document by ID and return its Next.js Metadata.
754
+ * Applies depth: 1 (image populate) automatically.
755
+ * @returns Metadata (throws on 404)
756
+ */
757
+ findMetadataById(id, metadataOptions) {
758
+ return __async(this, null, function* () {
759
+ const doc = yield this.findById(id, { depth: 1 });
760
+ return generateMetadata(
761
+ doc,
762
+ metadataOptions
763
+ );
764
+ });
765
+ }
705
766
  /**
706
767
  * Update multiple documents (bulk update)
707
768
  * PATCH /api/{collection}
@@ -977,6 +1038,7 @@ var COLLECTIONS = [
977
1038
  "product-categories",
978
1039
  "product-tags",
979
1040
  "product-images",
1041
+ "product-collections",
980
1042
  "brands",
981
1043
  "brand-logos",
982
1044
  "orders",
@@ -1006,8 +1068,6 @@ var COLLECTIONS = [
1006
1068
  "playlists",
1007
1069
  "playlist-images",
1008
1070
  "musics",
1009
- "galleries",
1010
- "gallery-images",
1011
1071
  "forms",
1012
1072
  "form-submissions",
1013
1073
  "media"
@@ -1710,11 +1770,6 @@ function handleWebhook(request, handler, options) {
1710
1770
  return __async(this, null, function* () {
1711
1771
  try {
1712
1772
  const rawBody = yield request.text();
1713
- if (!(options == null ? void 0 : options.secret)) {
1714
- console.warn(
1715
- "[@01.software/sdk] Webhook signature verification is skipped because no secret was provided. Pass { secret } to handleWebhook() to enable signature verification."
1716
- );
1717
- }
1718
1773
  if (options == null ? void 0 : options.secret) {
1719
1774
  const signature = request.headers.get("x-webhook-signature") || "";
1720
1775
  const valid = yield verifySignature(rawBody, options.secret, signature);
@@ -1724,6 +1779,10 @@ function handleWebhook(request, handler, options) {
1724
1779
  { status: 401, headers: { "Content-Type": "application/json" } }
1725
1780
  );
1726
1781
  }
1782
+ } else {
1783
+ console.warn(
1784
+ "[@01.software/sdk] Webhook signature verification is disabled. Set { secret } in handleWebhook() options to enable HMAC-SHA256 verification."
1785
+ );
1727
1786
  }
1728
1787
  const body = JSON.parse(rawBody);
1729
1788
  if (!isValidWebhookEvent(body)) {
@@ -1755,6 +1814,39 @@ function createTypedWebhookHandler(collection, handler) {
1755
1814
  });
1756
1815
  }
1757
1816
 
1817
+ // src/utils/image.ts
1818
+ var IMAGE_SIZES = [384, 768, 1536];
1819
+ function getImageUrl(image, displayWidth, dpr = 1) {
1820
+ var _a;
1821
+ const target = displayWidth * dpr;
1822
+ const sizes = image.sizes;
1823
+ if (sizes) {
1824
+ for (const size of IMAGE_SIZES) {
1825
+ if (size >= target) {
1826
+ const entry = sizes[String(size)];
1827
+ if (entry == null ? void 0 : entry.url) return entry.url;
1828
+ }
1829
+ }
1830
+ }
1831
+ return (_a = image.url) != null ? _a : "";
1832
+ }
1833
+ function getImageSrcSet(image) {
1834
+ const parts = [];
1835
+ const sizes = image.sizes;
1836
+ if (sizes) {
1837
+ for (const size of IMAGE_SIZES) {
1838
+ const entry = sizes[String(size)];
1839
+ if ((entry == null ? void 0 : entry.url) && entry.width) {
1840
+ parts.push(`${entry.url} ${entry.width}w`);
1841
+ }
1842
+ }
1843
+ }
1844
+ if (image.url && image.width) {
1845
+ parts.push(`${image.url} ${image.width}w`);
1846
+ }
1847
+ return parts.join(", ");
1848
+ }
1849
+
1758
1850
  // src/utils/order/generateOrderNumber.ts
1759
1851
  var generateOrderNumber = () => {
1760
1852
  var _a;
@@ -1767,13 +1859,6 @@ var generateOrderNumber = () => {
1767
1859
  return `${year}${month}${day}${random}`;
1768
1860
  };
1769
1861
 
1770
- // src/utils/types.ts
1771
- var resolveRelation = (ref) => {
1772
- if (typeof ref === "number" || ref === null || ref === void 0) return null;
1773
- return ref;
1774
- };
1775
- var objectFor = resolveRelation;
1776
-
1777
1862
  // src/utils/order/formatOrderName.ts
1778
1863
  var formatOrderName = (options) => {
1779
1864
  var _a, _b;
@@ -1817,6 +1902,7 @@ export {
1817
1902
  CollectionQueryBuilder,
1818
1903
  ConfigError,
1819
1904
  CustomerAuth,
1905
+ IMAGE_SIZES,
1820
1906
  NetworkError,
1821
1907
  OrderApi,
1822
1908
  ProductApi,
@@ -1836,6 +1922,8 @@ export {
1836
1922
  decodeServerToken,
1837
1923
  formatOrderName,
1838
1924
  generateOrderNumber,
1925
+ getImageSrcSet,
1926
+ getImageUrl,
1839
1927
  getQueryClient,
1840
1928
  handleWebhook,
1841
1929
  isApiError,