@01.software/sdk 0.1.8 → 0.1.9

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
@@ -6,6 +6,8 @@ import * as _tanstack_react_query from '@tanstack/react-query';
6
6
  import { QueryClient } from '@tanstack/react-query';
7
7
  import { P as PublicCollection, C as CollectionType } from './webhook-E1YlE_k1.cjs';
8
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';
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}
package/dist/index.d.ts CHANGED
@@ -6,6 +6,8 @@ import * as _tanstack_react_query from '@tanstack/react-query';
6
6
  import { QueryClient } from '@tanstack/react-query';
7
7
  import { P as PublicCollection, C as CollectionType } from './webhook-xdgxEN8s.js';
8
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';
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}
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}
@@ -1710,11 +1771,6 @@ function handleWebhook(request, handler, options) {
1710
1771
  return __async(this, null, function* () {
1711
1772
  try {
1712
1773
  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
1774
  if (options == null ? void 0 : options.secret) {
1719
1775
  const signature = request.headers.get("x-webhook-signature") || "";
1720
1776
  const valid = yield verifySignature(rawBody, options.secret, signature);
@@ -1724,6 +1780,10 @@ function handleWebhook(request, handler, options) {
1724
1780
  { status: 401, headers: { "Content-Type": "application/json" } }
1725
1781
  );
1726
1782
  }
1783
+ } else {
1784
+ console.warn(
1785
+ "[@01.software/sdk] Webhook signature verification is disabled. Set { secret } in handleWebhook() options to enable HMAC-SHA256 verification."
1786
+ );
1727
1787
  }
1728
1788
  const body = JSON.parse(rawBody);
1729
1789
  if (!isValidWebhookEvent(body)) {
@@ -1767,13 +1827,6 @@ var generateOrderNumber = () => {
1767
1827
  return `${year}${month}${day}${random}`;
1768
1828
  };
1769
1829
 
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
1830
  // src/utils/order/formatOrderName.ts
1778
1831
  var formatOrderName = (options) => {
1779
1832
  var _a, _b;