@distinctagency/cms-client 1.22.0 → 1.24.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.mts CHANGED
@@ -7,7 +7,7 @@ import { SupabaseClient } from '@supabase/supabase-js';
7
7
  * report installed-version telemetry and to send `x-cms-client-version` on
8
8
  * outgoing requests.
9
9
  */
10
- declare const CMS_CLIENT_VERSION = "1.22.0";
10
+ declare const CMS_CLIENT_VERSION = "1.24.0";
11
11
 
12
12
  /** Field types supported by the CMS schema */
13
13
  type FieldType = "text" | "textarea" | "richtext" | "date" | "datetime" | "select" | "number" | "boolean" | "image" | "gallery" | "url" | "file" | "reference" | "multi-reference" | "computed" | "color" | "tags" | "json" | "embed" | "flipbook";
@@ -58,6 +58,10 @@ interface FieldDefinition {
58
58
  decimal_places?: number;
59
59
  /** For date fields: which parts of the date the editor collects. Defaults to `full`. Stored in partial-ISO form — see {@link DateGranularity}. */
60
60
  date_granularity?: DateGranularity;
61
+ /** For text/textarea/richtext fields: hard maximum character count. Enforced in the editor and on save. Undefined = no cap. */
62
+ max_length?: number;
63
+ /** For text/textarea/richtext fields: soft target character count. Exceeding it shows a warning but does not block saving. */
64
+ recommended_length?: number;
61
65
  }
62
66
  interface Tenant {
63
67
  id: string;
@@ -111,6 +115,8 @@ interface ContentType {
111
115
  schema: FieldDefinition[];
112
116
  seo_config?: ContentTypeSeoConfig | null;
113
117
  required_membership_tier_id?: string | null;
118
+ /** When true, this content type is a "page": it holds exactly one item, edited as a singleton document rather than a collection. */
119
+ is_singleton?: boolean;
114
120
  created_at: string;
115
121
  }
116
122
  interface ContentItem {
@@ -369,6 +375,30 @@ interface FlipbookPublic {
369
375
  toc: FlipbookTocEntryPublic[];
370
376
  download_url: string | null;
371
377
  }
378
+ interface GeocodeOptions {
379
+ /** Max results (1–10). Defaults to 5. */
380
+ limit?: number;
381
+ /** ISO 3166-1 alpha-2 country filter, e.g. "nz". */
382
+ country?: string;
383
+ /** Bias results toward this [longitude, latitude]. */
384
+ proximity?: [number, number];
385
+ /** Comma-separated Mapbox feature types, e.g. "address,place". */
386
+ types?: string;
387
+ /** IETF language tag, e.g. "en". */
388
+ language?: string;
389
+ }
390
+ interface GeocodeResult {
391
+ longitude: number;
392
+ latitude: number;
393
+ /** Full formatted place name from Mapbox. */
394
+ placeName: string;
395
+ /** Match confidence 0–1 (1 when Mapbox v6 omits it). */
396
+ relevance: number;
397
+ /** Primary Mapbox feature type (address, place, ...). */
398
+ type: string;
399
+ /** [west, south, east, north] when Mapbox provides one. */
400
+ bbox?: [number, number, number, number];
401
+ }
372
402
 
373
403
  /**
374
404
  * Creates a CMS query client authenticated with a tenant API key.
@@ -395,6 +425,18 @@ declare function createCmsClient(supabase: SupabaseClient, options: CmsClientOpt
395
425
  * Returns null if not found.
396
426
  */
397
427
  getContentItemBySlug(contentTypeSlug: string, itemSlug: string): Promise<ContentItem | null>;
428
+ /**
429
+ * Get the single published item for a singleton content type ("page").
430
+ *
431
+ * A singleton content type owns exactly one item. Use this for editable
432
+ * page copy (hero text, section headings, etc.) stored in the CMS.
433
+ * Returns null when the singleton has no published item yet — callers
434
+ * should fall back to their hardcoded defaults in that case.
435
+ *
436
+ * Wrap this in `unstable_cache` with a `cms:singleton:<slug>` tag on the
437
+ * consuming site to cache it and revalidate via the CMS webhook.
438
+ */
439
+ getSingleton(contentTypeSlug: string): Promise<ContentItem | null>;
398
440
  /**
399
441
  * Get a content type definition (including its field schema).
400
442
  */
@@ -503,6 +545,13 @@ interface TrackingConfigOptions {
503
545
  * handler so public-token changes take effect immediately.
504
546
  */
505
547
  declare const MAPBOX_CONFIG_TAG = "cms:mapbox-config";
548
+ /**
549
+ * Cache tag for a singleton "page" content type. Wrap `getSingleton(slug)` in
550
+ * `unstable_cache` tagged with `singletonTag(slug)`, then call
551
+ * `revalidateTag(singletonTag(slug))` from the CMS `content.updated` webhook
552
+ * (the webhook payload's `cache_tags` already include this value).
553
+ */
554
+ declare function singletonTag(slug: string): string;
506
555
  interface MapboxConfigOptions {
507
556
  /** Cache lifetime in seconds on Next.js. Defaults to 3600. `0` disables caching, `false` caches until tag revalidation. Ignored outside Next.js. */
508
557
  revalidate?: number | false;
@@ -658,6 +707,33 @@ declare function createEventsClient(supabase: SupabaseClient, options: {
658
707
  createBooking: (params: CreateBookingParams) => Promise<CreateBookingResult>;
659
708
  };
660
709
 
710
+ interface MapsClientOptions {
711
+ /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */
712
+ apiKey: string;
713
+ /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */
714
+ appUrl?: string;
715
+ }
716
+ /**
717
+ * Creates a typed client for Mapbox-backed helpers (forward geocoding, with
718
+ * more to come). Like `createShopClient`, it talks to CMS REST endpoints rather
719
+ * than Supabase directly — it doesn't need the `supabase` argument but accepts
720
+ * it for API symmetry. The Mapbox call runs server-side with the tenant's
721
+ * public token; the token is never exposed to the browser.
722
+ *
723
+ * ```ts
724
+ * const maps = createMapsClient(supabase, { apiKey: process.env.CMS_API_KEY! })
725
+ * const [best] = await maps.geocodeAddress("12 Queen St, Auckland")
726
+ * ```
727
+ */
728
+ declare function createMapsClient(_supabase: SupabaseClient, options: MapsClientOptions): {
729
+ /**
730
+ * Forward-geocode an address string. Returns matches ordered by relevance
731
+ * (`results[0]` is the best match), or [] when nothing matches. Throws on a
732
+ * configuration or upstream error.
733
+ */
734
+ geocodeAddress(query: string, options?: GeocodeOptions): Promise<GeocodeResult[]>;
735
+ };
736
+
661
737
  /**
662
738
  * Image helpers for CMS content.
663
739
  *
@@ -857,4 +933,4 @@ declare function revalidateAllTags(payload: Pick<WebhookEventPayload, "cache_tag
857
933
  expire?: number;
858
934
  }) => unknown): string[];
859
935
 
860
- export { type BookingStatus, CMS_CLIENT_VERSION, type CmsClientOptions, type CmsEvent, type CmsTicketTier, type ContentItem, type ContentQueryOptions, type ContentType, type ContentTypeSeoConfig, type CreateBookingParams, type CreateBookingResult, type CreateOrderParams, type CreateOrderResult, type DateGranularity, type DiscountType, type EmbedValue, type EventQueryOptions, type EventStatus, type EventWithTiers, type FieldDefinition, type FieldType, type FlipbookPagePublic, type FlipbookPublic, type FlipbookTocEntryPublic, type FormatPartialDateOptions, type GoogleReview, IMAGE_PRESETS, type ImageConfig, type ImageTransformOptions, MAPBOX_CONFIG_TAG, type MapboxConfig, type MapboxConfigOptions, type MediaFolder, type MediaItem, type Member, type MembershipTier, type OrderAddress, type OrderLineItem, type OrderStatus, type ParsedPartialDate, type PaymentStatus, type Product, type ProductCategory, type ProductOption, type ProductQueryOptions, type ProductStatus, type ProductVariant, type Profile, type ReviewQueryOptions, TRACKING_CONFIG_TAG, type Tenant, type TenantMembership, type TrackingConfig, type TrackingConfigOptions, WEBHOOK_EVENTS, type WebhookEvent, type WebhookEventPayload, createCmsClient, createEventsClient, createShopClient, formatPartialDate, getEmbedHtml, getSrcSet, getTransformUrl, parsePartialDate, revalidateAllTags, verifyWebhookSignature };
936
+ export { type BookingStatus, CMS_CLIENT_VERSION, type CmsClientOptions, type CmsEvent, type CmsTicketTier, type ContentItem, type ContentQueryOptions, type ContentType, type ContentTypeSeoConfig, type CreateBookingParams, type CreateBookingResult, type CreateOrderParams, type CreateOrderResult, type DateGranularity, type DiscountType, type EmbedValue, type EventQueryOptions, type EventStatus, type EventWithTiers, type FieldDefinition, type FieldType, type FlipbookPagePublic, type FlipbookPublic, type FlipbookTocEntryPublic, type FormatPartialDateOptions, type GeocodeOptions, type GeocodeResult, type GoogleReview, IMAGE_PRESETS, type ImageConfig, type ImageTransformOptions, MAPBOX_CONFIG_TAG, type MapboxConfig, type MapboxConfigOptions, type MapsClientOptions, type MediaFolder, type MediaItem, type Member, type MembershipTier, type OrderAddress, type OrderLineItem, type OrderStatus, type ParsedPartialDate, type PaymentStatus, type Product, type ProductCategory, type ProductOption, type ProductQueryOptions, type ProductStatus, type ProductVariant, type Profile, type ReviewQueryOptions, TRACKING_CONFIG_TAG, type Tenant, type TenantMembership, type TrackingConfig, type TrackingConfigOptions, WEBHOOK_EVENTS, type WebhookEvent, type WebhookEventPayload, createCmsClient, createEventsClient, createMapsClient, createShopClient, formatPartialDate, getEmbedHtml, getSrcSet, getTransformUrl, parsePartialDate, revalidateAllTags, singletonTag, verifyWebhookSignature };
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import { SupabaseClient } from '@supabase/supabase-js';
7
7
  * report installed-version telemetry and to send `x-cms-client-version` on
8
8
  * outgoing requests.
9
9
  */
10
- declare const CMS_CLIENT_VERSION = "1.22.0";
10
+ declare const CMS_CLIENT_VERSION = "1.24.0";
11
11
 
12
12
  /** Field types supported by the CMS schema */
13
13
  type FieldType = "text" | "textarea" | "richtext" | "date" | "datetime" | "select" | "number" | "boolean" | "image" | "gallery" | "url" | "file" | "reference" | "multi-reference" | "computed" | "color" | "tags" | "json" | "embed" | "flipbook";
@@ -58,6 +58,10 @@ interface FieldDefinition {
58
58
  decimal_places?: number;
59
59
  /** For date fields: which parts of the date the editor collects. Defaults to `full`. Stored in partial-ISO form — see {@link DateGranularity}. */
60
60
  date_granularity?: DateGranularity;
61
+ /** For text/textarea/richtext fields: hard maximum character count. Enforced in the editor and on save. Undefined = no cap. */
62
+ max_length?: number;
63
+ /** For text/textarea/richtext fields: soft target character count. Exceeding it shows a warning but does not block saving. */
64
+ recommended_length?: number;
61
65
  }
62
66
  interface Tenant {
63
67
  id: string;
@@ -111,6 +115,8 @@ interface ContentType {
111
115
  schema: FieldDefinition[];
112
116
  seo_config?: ContentTypeSeoConfig | null;
113
117
  required_membership_tier_id?: string | null;
118
+ /** When true, this content type is a "page": it holds exactly one item, edited as a singleton document rather than a collection. */
119
+ is_singleton?: boolean;
114
120
  created_at: string;
115
121
  }
116
122
  interface ContentItem {
@@ -369,6 +375,30 @@ interface FlipbookPublic {
369
375
  toc: FlipbookTocEntryPublic[];
370
376
  download_url: string | null;
371
377
  }
378
+ interface GeocodeOptions {
379
+ /** Max results (1–10). Defaults to 5. */
380
+ limit?: number;
381
+ /** ISO 3166-1 alpha-2 country filter, e.g. "nz". */
382
+ country?: string;
383
+ /** Bias results toward this [longitude, latitude]. */
384
+ proximity?: [number, number];
385
+ /** Comma-separated Mapbox feature types, e.g. "address,place". */
386
+ types?: string;
387
+ /** IETF language tag, e.g. "en". */
388
+ language?: string;
389
+ }
390
+ interface GeocodeResult {
391
+ longitude: number;
392
+ latitude: number;
393
+ /** Full formatted place name from Mapbox. */
394
+ placeName: string;
395
+ /** Match confidence 0–1 (1 when Mapbox v6 omits it). */
396
+ relevance: number;
397
+ /** Primary Mapbox feature type (address, place, ...). */
398
+ type: string;
399
+ /** [west, south, east, north] when Mapbox provides one. */
400
+ bbox?: [number, number, number, number];
401
+ }
372
402
 
373
403
  /**
374
404
  * Creates a CMS query client authenticated with a tenant API key.
@@ -395,6 +425,18 @@ declare function createCmsClient(supabase: SupabaseClient, options: CmsClientOpt
395
425
  * Returns null if not found.
396
426
  */
397
427
  getContentItemBySlug(contentTypeSlug: string, itemSlug: string): Promise<ContentItem | null>;
428
+ /**
429
+ * Get the single published item for a singleton content type ("page").
430
+ *
431
+ * A singleton content type owns exactly one item. Use this for editable
432
+ * page copy (hero text, section headings, etc.) stored in the CMS.
433
+ * Returns null when the singleton has no published item yet — callers
434
+ * should fall back to their hardcoded defaults in that case.
435
+ *
436
+ * Wrap this in `unstable_cache` with a `cms:singleton:<slug>` tag on the
437
+ * consuming site to cache it and revalidate via the CMS webhook.
438
+ */
439
+ getSingleton(contentTypeSlug: string): Promise<ContentItem | null>;
398
440
  /**
399
441
  * Get a content type definition (including its field schema).
400
442
  */
@@ -503,6 +545,13 @@ interface TrackingConfigOptions {
503
545
  * handler so public-token changes take effect immediately.
504
546
  */
505
547
  declare const MAPBOX_CONFIG_TAG = "cms:mapbox-config";
548
+ /**
549
+ * Cache tag for a singleton "page" content type. Wrap `getSingleton(slug)` in
550
+ * `unstable_cache` tagged with `singletonTag(slug)`, then call
551
+ * `revalidateTag(singletonTag(slug))` from the CMS `content.updated` webhook
552
+ * (the webhook payload's `cache_tags` already include this value).
553
+ */
554
+ declare function singletonTag(slug: string): string;
506
555
  interface MapboxConfigOptions {
507
556
  /** Cache lifetime in seconds on Next.js. Defaults to 3600. `0` disables caching, `false` caches until tag revalidation. Ignored outside Next.js. */
508
557
  revalidate?: number | false;
@@ -658,6 +707,33 @@ declare function createEventsClient(supabase: SupabaseClient, options: {
658
707
  createBooking: (params: CreateBookingParams) => Promise<CreateBookingResult>;
659
708
  };
660
709
 
710
+ interface MapsClientOptions {
711
+ /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */
712
+ apiKey: string;
713
+ /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */
714
+ appUrl?: string;
715
+ }
716
+ /**
717
+ * Creates a typed client for Mapbox-backed helpers (forward geocoding, with
718
+ * more to come). Like `createShopClient`, it talks to CMS REST endpoints rather
719
+ * than Supabase directly — it doesn't need the `supabase` argument but accepts
720
+ * it for API symmetry. The Mapbox call runs server-side with the tenant's
721
+ * public token; the token is never exposed to the browser.
722
+ *
723
+ * ```ts
724
+ * const maps = createMapsClient(supabase, { apiKey: process.env.CMS_API_KEY! })
725
+ * const [best] = await maps.geocodeAddress("12 Queen St, Auckland")
726
+ * ```
727
+ */
728
+ declare function createMapsClient(_supabase: SupabaseClient, options: MapsClientOptions): {
729
+ /**
730
+ * Forward-geocode an address string. Returns matches ordered by relevance
731
+ * (`results[0]` is the best match), or [] when nothing matches. Throws on a
732
+ * configuration or upstream error.
733
+ */
734
+ geocodeAddress(query: string, options?: GeocodeOptions): Promise<GeocodeResult[]>;
735
+ };
736
+
661
737
  /**
662
738
  * Image helpers for CMS content.
663
739
  *
@@ -857,4 +933,4 @@ declare function revalidateAllTags(payload: Pick<WebhookEventPayload, "cache_tag
857
933
  expire?: number;
858
934
  }) => unknown): string[];
859
935
 
860
- export { type BookingStatus, CMS_CLIENT_VERSION, type CmsClientOptions, type CmsEvent, type CmsTicketTier, type ContentItem, type ContentQueryOptions, type ContentType, type ContentTypeSeoConfig, type CreateBookingParams, type CreateBookingResult, type CreateOrderParams, type CreateOrderResult, type DateGranularity, type DiscountType, type EmbedValue, type EventQueryOptions, type EventStatus, type EventWithTiers, type FieldDefinition, type FieldType, type FlipbookPagePublic, type FlipbookPublic, type FlipbookTocEntryPublic, type FormatPartialDateOptions, type GoogleReview, IMAGE_PRESETS, type ImageConfig, type ImageTransformOptions, MAPBOX_CONFIG_TAG, type MapboxConfig, type MapboxConfigOptions, type MediaFolder, type MediaItem, type Member, type MembershipTier, type OrderAddress, type OrderLineItem, type OrderStatus, type ParsedPartialDate, type PaymentStatus, type Product, type ProductCategory, type ProductOption, type ProductQueryOptions, type ProductStatus, type ProductVariant, type Profile, type ReviewQueryOptions, TRACKING_CONFIG_TAG, type Tenant, type TenantMembership, type TrackingConfig, type TrackingConfigOptions, WEBHOOK_EVENTS, type WebhookEvent, type WebhookEventPayload, createCmsClient, createEventsClient, createShopClient, formatPartialDate, getEmbedHtml, getSrcSet, getTransformUrl, parsePartialDate, revalidateAllTags, verifyWebhookSignature };
936
+ export { type BookingStatus, CMS_CLIENT_VERSION, type CmsClientOptions, type CmsEvent, type CmsTicketTier, type ContentItem, type ContentQueryOptions, type ContentType, type ContentTypeSeoConfig, type CreateBookingParams, type CreateBookingResult, type CreateOrderParams, type CreateOrderResult, type DateGranularity, type DiscountType, type EmbedValue, type EventQueryOptions, type EventStatus, type EventWithTiers, type FieldDefinition, type FieldType, type FlipbookPagePublic, type FlipbookPublic, type FlipbookTocEntryPublic, type FormatPartialDateOptions, type GeocodeOptions, type GeocodeResult, type GoogleReview, IMAGE_PRESETS, type ImageConfig, type ImageTransformOptions, MAPBOX_CONFIG_TAG, type MapboxConfig, type MapboxConfigOptions, type MapsClientOptions, type MediaFolder, type MediaItem, type Member, type MembershipTier, type OrderAddress, type OrderLineItem, type OrderStatus, type ParsedPartialDate, type PaymentStatus, type Product, type ProductCategory, type ProductOption, type ProductQueryOptions, type ProductStatus, type ProductVariant, type Profile, type ReviewQueryOptions, TRACKING_CONFIG_TAG, type Tenant, type TenantMembership, type TrackingConfig, type TrackingConfigOptions, WEBHOOK_EVENTS, type WebhookEvent, type WebhookEventPayload, createCmsClient, createEventsClient, createMapsClient, createShopClient, formatPartialDate, getEmbedHtml, getSrcSet, getTransformUrl, parsePartialDate, revalidateAllTags, singletonTag, verifyWebhookSignature };
package/dist/index.js CHANGED
@@ -27,6 +27,7 @@ __export(src_exports, {
27
27
  WEBHOOK_EVENTS: () => WEBHOOK_EVENTS,
28
28
  createCmsClient: () => createCmsClient,
29
29
  createEventsClient: () => createEventsClient,
30
+ createMapsClient: () => createMapsClient,
30
31
  createShopClient: () => createShopClient,
31
32
  formatPartialDate: () => formatPartialDate,
32
33
  getEmbedHtml: () => getEmbedHtml,
@@ -34,12 +35,13 @@ __export(src_exports, {
34
35
  getTransformUrl: () => getTransformUrl,
35
36
  parsePartialDate: () => parsePartialDate,
36
37
  revalidateAllTags: () => revalidateAllTags,
38
+ singletonTag: () => singletonTag,
37
39
  verifyWebhookSignature: () => verifyWebhookSignature
38
40
  });
39
41
  module.exports = __toCommonJS(src_exports);
40
42
 
41
43
  // src/version.ts
42
- var CMS_CLIENT_VERSION = "1.22.0";
44
+ var CMS_CLIENT_VERSION = "1.24.0";
43
45
 
44
46
  // src/queries.ts
45
47
  var import_supabase_js = require("@supabase/supabase-js");
@@ -215,6 +217,27 @@ function createCmsClient(supabase, options) {
215
217
  }
216
218
  return data;
217
219
  },
220
+ /**
221
+ * Get the single published item for a singleton content type ("page").
222
+ *
223
+ * A singleton content type owns exactly one item. Use this for editable
224
+ * page copy (hero text, section headings, etc.) stored in the CMS.
225
+ * Returns null when the singleton has no published item yet — callers
226
+ * should fall back to their hardcoded defaults in that case.
227
+ *
228
+ * Wrap this in `unstable_cache` with a `cms:singleton:<slug>` tag on the
229
+ * consuming site to cache it and revalidate via the CMS webhook.
230
+ */
231
+ async getSingleton(contentTypeSlug) {
232
+ const contentTypeId = await getContentTypeId(contentTypeSlug);
233
+ const { data, error } = await client.from("content_items").select("*").eq("content_type_id", contentTypeId).eq("status", "published").order("updated_at", { ascending: false }).limit(1).maybeSingle();
234
+ if (error) {
235
+ throw new Error(
236
+ `Failed to fetch singleton ${contentTypeSlug}: ${error.message}`
237
+ );
238
+ }
239
+ return data ?? null;
240
+ },
218
241
  /**
219
242
  * Get a content type definition (including its field schema).
220
243
  */
@@ -417,6 +440,9 @@ function createCmsClient(supabase, options) {
417
440
  }
418
441
  var TRACKING_CONFIG_TAG = "cms:tracking-config";
419
442
  var MAPBOX_CONFIG_TAG = "cms:mapbox-config";
443
+ function singletonTag(slug) {
444
+ return `cms:singleton:${slug}`;
445
+ }
420
446
  function nullify(v) {
421
447
  if (!v) return null;
422
448
  const trimmed = v.trim();
@@ -601,6 +627,43 @@ function createEventsClient(supabase, options) {
601
627
  return { getEvents, getEventBySlug, createBooking };
602
628
  }
603
629
 
630
+ // src/maps.ts
631
+ var DEFAULT_APP_URL3 = "https://cms.distinctstudio.co.nz";
632
+ function createMapsClient(_supabase, options) {
633
+ const { apiKey } = options;
634
+ const appUrl = (options.appUrl ?? DEFAULT_APP_URL3).replace(/\/$/, "");
635
+ reportClientVersion(apiKey, appUrl);
636
+ return {
637
+ /**
638
+ * Forward-geocode an address string. Returns matches ordered by relevance
639
+ * (`results[0]` is the best match), or [] when nothing matches. Throws on a
640
+ * configuration or upstream error.
641
+ */
642
+ async geocodeAddress(query, options2 = {}) {
643
+ const q = query.trim();
644
+ if (!q) throw new Error("geocodeAddress: query is required");
645
+ const params = new URLSearchParams({ q });
646
+ if (options2.limit != null) params.set("limit", String(options2.limit));
647
+ if (options2.country) params.set("country", options2.country);
648
+ if (options2.proximity) params.set("proximity", `${options2.proximity[0]},${options2.proximity[1]}`);
649
+ if (options2.types) params.set("types", options2.types);
650
+ if (options2.language) params.set("language", options2.language);
651
+ const res = await fetch(`${appUrl}/api/mapbox/geocode?${params.toString()}`, {
652
+ headers: {
653
+ "x-cms-api-key": apiKey,
654
+ "x-cms-client-version": CMS_CLIENT_VERSION
655
+ }
656
+ });
657
+ if (!res.ok) {
658
+ const body = await res.json().catch(() => ({}));
659
+ throw new Error(body.error ?? `Geocoding failed (${res.status})`);
660
+ }
661
+ const data = await res.json();
662
+ return data.results ?? [];
663
+ }
664
+ };
665
+ }
666
+
604
667
  // src/cdn.ts
605
668
  function getTransformUrl(originalUrl, _options = {}) {
606
669
  return originalUrl;
@@ -743,6 +806,7 @@ function timingSafeEqualHex(a, b) {
743
806
  WEBHOOK_EVENTS,
744
807
  createCmsClient,
745
808
  createEventsClient,
809
+ createMapsClient,
746
810
  createShopClient,
747
811
  formatPartialDate,
748
812
  getEmbedHtml,
@@ -750,6 +814,7 @@ function timingSafeEqualHex(a, b) {
750
814
  getTransformUrl,
751
815
  parsePartialDate,
752
816
  revalidateAllTags,
817
+ singletonTag,
753
818
  verifyWebhookSignature
754
819
  });
755
820
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/version.ts","../src/queries.ts","../src/telemetry.ts","../src/embed.ts","../src/shop.ts","../src/events.ts","../src/cdn.ts","../src/date.ts","../src/webhooks.ts"],"sourcesContent":["// Server-safe exports — no React, no \"use client\"\nexport { CMS_CLIENT_VERSION } from \"./version\"\nexport { createCmsClient, TRACKING_CONFIG_TAG, MAPBOX_CONFIG_TAG } from \"./queries\"\nexport type { TrackingConfig, TrackingConfigOptions, MapboxConfig, MapboxConfigOptions } from \"./queries\"\nexport { getEmbedHtml } from \"./embed\"\nexport { createShopClient } from \"./shop\"\nexport { createEventsClient } from \"./events\"\nexport type {\n CmsEvent,\n CmsTicketTier,\n EventWithTiers,\n EventQueryOptions,\n CreateBookingParams,\n CreateBookingResult,\n EventStatus,\n BookingStatus,\n} from \"./events\"\nexport { getTransformUrl, getSrcSet, IMAGE_PRESETS } from \"./cdn\"\nexport type { ImageTransformOptions } from \"./cdn\"\nexport { parsePartialDate, formatPartialDate } from \"./date\"\nexport type { ParsedPartialDate, FormatPartialDateOptions } from \"./date\"\nexport { verifyWebhookSignature, revalidateAllTags, WEBHOOK_EVENTS } from \"./webhooks\"\nexport type { WebhookEvent, WebhookEventPayload } from \"./webhooks\"\nexport type {\n FieldType,\n FieldDefinition,\n DateGranularity,\n Tenant,\n Profile,\n ContentType,\n ContentItem,\n MediaItem,\n MediaFolder,\n ContentQueryOptions,\n CmsClientOptions,\n TenantMembership,\n ImageConfig,\n ContentTypeSeoConfig,\n Product,\n ProductStatus,\n ProductCategory,\n ProductVariant,\n ProductOption,\n OrderAddress,\n OrderStatus,\n PaymentStatus,\n OrderLineItem,\n DiscountType,\n CreateOrderParams,\n CreateOrderResult,\n ProductQueryOptions,\n MembershipTier,\n Member,\n GoogleReview,\n ReviewQueryOptions,\n EmbedValue,\n FlipbookPagePublic,\n FlipbookTocEntryPublic,\n FlipbookPublic,\n} from \"./types\"\n","/**\n * The version of @distinctagency/cms-client embedded in this build.\n *\n * Bump this in lock-step with package.json — the value is read by the SDK to\n * report installed-version telemetry and to send `x-cms-client-version` on\n * outgoing requests.\n */\nexport const CMS_CLIENT_VERSION = \"1.22.0\"\n","import { createClient as createSupabaseClient } from \"@supabase/supabase-js\"\nimport type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n CmsClientOptions,\n ContentItem,\n ContentQueryOptions,\n ContentType,\n GoogleReview,\n ReviewQueryOptions,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\n/**\n * Creates a CMS query client authenticated with a tenant API key.\n *\n * Usage:\n * ```ts\n * const cms = createCmsClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const events = await cms.getContentItems('events', { status: 'published' })\n * ```\n *\n * The API key is sent as an `x-cms-api-key` header on every request.\n * Supabase RLS policies validate it against the tenant's stored key.\n */\nexport function createCmsClient(\n supabase: SupabaseClient,\n options: CmsClientOptions\n) {\n const { apiKey } = options\n\n // Create a new Supabase client with the API key header injected globally\n const client = withApiKey(supabase, apiKey) as SupabaseClient\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, options.appUrl)\n\n /** Resolve the tenant ID from the API key (cached per request) */\n let tenantIdCache: string | null = null\n\n async function getTenantId(): Promise<string> {\n if (tenantIdCache) return tenantIdCache\n\n const { data, error } = await client\n .from(\"tenants\")\n .select(\"id\")\n .single()\n\n if (error || !data) {\n throw new Error(\n \"Invalid CMS API key — no tenant found. Check your apiKey.\"\n )\n }\n\n tenantIdCache = data.id\n return data.id\n }\n\n /** Resolve a content type from its slug (cached) */\n const contentTypeCache = new Map<string, ContentType>()\n\n async function getContentTypeBySlug(contentTypeSlug: string): Promise<ContentType> {\n if (contentTypeCache.has(contentTypeSlug)) return contentTypeCache.get(contentTypeSlug)!\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n const ct = data as ContentType\n contentTypeCache.set(contentTypeSlug, ct)\n return ct\n }\n\n async function getContentTypeId(contentTypeSlug: string): Promise<string> {\n const ct = await getContentTypeBySlug(contentTypeSlug)\n return ct.id\n }\n\n /** Check if a member token has access to a gated content type */\n async function checkMemberAccess(\n contentType: ContentType,\n memberToken?: string\n ): Promise<{ allowed: boolean; memberTierId: string | null }> {\n const requiredTierId = contentType.required_membership_tier_id\n if (!requiredTierId) return { allowed: true, memberTierId: null } // Public\n\n if (!memberToken) return { allowed: false, memberTierId: null } // Gated but no token\n\n // Verify the member's token and check their tier\n const { data: session } = await client\n .from(\"member_sessions\")\n .select(\"member_id\")\n .eq(\"token_hash\", memberToken) // Note: caller should hash the token\n .single()\n\n if (!session) return { allowed: false, memberTierId: null }\n\n const { data: member } = await client\n .from(\"members\")\n .select(\"membership_tier_id, status\")\n .eq(\"id\", session.member_id)\n .single()\n\n if (!member || member.status !== \"active\") return { allowed: false, memberTierId: null }\n\n // Check if the member's tier matches (or exceeds) the required tier\n // For now: exact match or the member has the required tier\n return {\n allowed: member.membership_tier_id === requiredTierId,\n memberTierId: member.membership_tier_id as string | null,\n }\n }\n\n async function getFlipbook(id: string): Promise<import(\"./types\").FlipbookPublic | null> {\n const { data, error } = await client\n .from(\"flipbooks\")\n .select(\"id, title, page_count, status, manifest, download_enabled, tenant_id\")\n .eq(\"id\", id)\n .single()\n if (error || !data) return null\n\n const manifest = data.manifest as\n | { pages: Array<{ image: string; thumb: string; w: number; h: number }>; toc: Array<{ title: string; page: number }> }\n | null\n if (!manifest) {\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? 0,\n status: data.status as \"pending_upload\" | \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: [],\n toc: [],\n download_url: null,\n }\n }\n\n // Browser-safe env lookup via globalThis. The client package builds without\n // @types/node so referring to `process` directly fails the dts build; reading\n // through globalThis sidesteps that and works in every JS environment that\n // matters (Node, browsers, edge runtimes).\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process\n const cdnBase = proc?.env?.NEXT_PUBLIC_R2_PUBLIC_URL ?? \"https://cdn.distinctstudio.co.nz\"\n const prefix = `flipbooks/${data.tenant_id as string}/${data.id as string}/`\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? manifest.pages.length,\n status: data.status as \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: manifest.pages.map((p) => ({\n url: `${cdnBase}/${prefix}${p.image}`,\n thumb_url: `${cdnBase}/${prefix}${p.thumb}`,\n w: p.w,\n h: p.h,\n })),\n toc: manifest.toc,\n download_url: data.download_enabled\n ? `${options.appUrl ?? \"\"}/api/flipbooks/${data.id as string}/download`\n : null,\n }\n }\n\n return {\n /**\n * List content items for a content type.\n * Defaults to published items ordered by most recent.\n */\n async getContentItems(\n contentTypeSlug: string,\n options: ContentQueryOptions = {}\n ): Promise<(ContentItem & { locked?: boolean })[]> {\n const contentType = await getContentTypeBySlug(contentTypeSlug)\n\n const {\n status = \"published\",\n orderBy = \"published_at\",\n orderDirection = \"desc\",\n limit = 100,\n offset = 0,\n memberToken,\n } = options\n\n // Check membership access\n const access = await checkMemberAccess(contentType, memberToken)\n\n // If gated and no access, check gating mode\n if (!access.allowed && contentType.required_membership_tier_id) {\n // Get tenant settings for gating mode\n const tenantId = await getTenantId()\n const { data: settings } = await client\n .from(\"tenant_settings\")\n .select(\"membership_gating_mode\")\n .eq(\"tenant_id\", tenantId)\n .single()\n\n const mode = (settings?.membership_gating_mode as string) ?? \"teaser\"\n\n if (mode === \"hide\") {\n return [] // Hide: return nothing\n }\n\n // Teaser mode: return items with locked flag, no body/data\n let query = client\n .from(\"content_items\")\n .select(\"id, title, slug, status, excerpt, seo_title, seo_description, featured_image, published_at, created_at, updated_at\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) query = query.eq(\"status\", status)\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n if (error) throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n\n return (data ?? []).map((item) => ({\n ...item,\n data: {},\n locked: true,\n })) as (ContentItem & { locked: boolean })[]\n }\n\n // Full access\n let query = client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n }\n\n return (data ?? []) as ContentItem[]\n },\n\n /**\n * Get a single content item by its slug.\n * Returns null if not found.\n */\n async getContentItemBySlug(\n contentTypeSlug: string,\n itemSlug: string\n ): Promise<ContentItem | null> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"slug\", itemSlug)\n .single()\n\n if (error) {\n if (error.code === \"PGRST116\") return null // not found\n throw new Error(\n `Failed to fetch ${contentTypeSlug}/${itemSlug}: ${error.message}`\n )\n }\n\n return data as ContentItem\n },\n\n /**\n * Get a content type definition (including its field schema).\n */\n async getContentType(contentTypeSlug: string): Promise<ContentType> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n return data as ContentType\n },\n\n /**\n * Get all slugs for a content type (for generateStaticParams).\n */\n async getAllSlugs(\n contentTypeSlug: string\n ): Promise<{ slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"slug\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"status\", \"published\")\n\n if (error) {\n throw new Error(\n `Failed to fetch slugs for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { slug: string }[]\n },\n\n /**\n * List all content types for this tenant.\n */\n async getContentTypes(): Promise<ContentType[]> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .order(\"name\")\n\n if (error) {\n throw new Error(`Failed to fetch content types: ${error.message}`)\n }\n\n return (data ?? []) as ContentType[]\n },\n\n /**\n * Get all slug redirects for a content type.\n * Use in next.config.js redirects() or middleware for 301s.\n * Returns: [{ old_slug, new_slug }, ...]\n */\n async getRedirects(\n contentTypeSlug: string\n ): Promise<{ old_slug: string; new_slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"slug_redirects\")\n .select(\"old_slug, new_slug\")\n .eq(\"content_type_id\", contentTypeId)\n\n if (error) {\n throw new Error(\n `Failed to fetch redirects for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { old_slug: string; new_slug: string }[]\n },\n\n /**\n * Get all custom path redirects for this tenant.\n * Use alongside getRedirects() in next.config.ts for full redirect coverage.\n */\n async getCustomRedirects(): Promise<\n { source_path: string; destination_path: string; permanent: boolean }[]\n > {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"custom_redirects\")\n .select(\"source_path, destination_path, permanent\")\n .eq(\"tenant_id\", tenantId)\n\n if (error) {\n throw new Error(`Failed to fetch custom redirects: ${error.message}`)\n }\n\n return (data ?? []) as {\n source_path: string\n destination_path: string\n permanent: boolean\n }[]\n },\n\n /**\n * Get form submissions for a specific form.\n * Useful for displaying testimonials, reviews, etc.\n */\n async getFormSubmissions(\n formSlug: string,\n options: { status?: string; limit?: number; offset?: number } = {}\n ): Promise<Record<string, unknown>[]> {\n const tenantId = await getTenantId()\n\n const { data: form } = await client\n .from(\"forms\")\n .select(\"id\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n if (!form) return []\n\n const { limit = 50, offset = 0, status } = options\n\n let query = client\n .from(\"form_submissions\")\n .select(\"*\")\n .eq(\"form_id\", form.id)\n .eq(\"is_spam\", false)\n .order(\"created_at\", { ascending: false })\n .range(offset, offset + limit - 1)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n const { data } = await query\n return (data ?? []) as Record<string, unknown>[]\n },\n\n /**\n * Get a form configuration by slug.\n */\n async getForm(\n formSlug: string\n ): Promise<Record<string, unknown> | null> {\n const tenantId = await getTenantId()\n\n const { data } = await client\n .from(\"forms\")\n .select(\"id, name, slug, description, is_active\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n return data as Record<string, unknown> | null\n },\n\n /**\n * Get a flipbook by ID, including CDN-resolved page image URLs.\n * Returns null if not found or manifest not yet ready.\n */\n getFlipbook,\n\n /**\n * Get Google Reviews for this tenant.\n * Defaults to approved reviews ordered by most recent.\n */\n async getReviews(\n options: ReviewQueryOptions = {}\n ): Promise<GoogleReview[]> {\n const tenantId = await getTenantId()\n\n const {\n status = \"approved\",\n minRating,\n limit = 50,\n offset = 0,\n orderBy = \"review_timestamp\",\n orderDirection = \"desc\",\n } = options\n\n let query = client\n .from(\"google_reviews\")\n .select(\"id, author_name, author_photo_url, rating, text, review_timestamp\")\n .eq(\"tenant_id\", tenantId)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n if (minRating) {\n query = query.gte(\"rating\", minRating)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch reviews: ${error.message}`)\n }\n\n return (data ?? []) as GoogleReview[]\n },\n\n /**\n * Get the tenant's third-party tracking IDs (Google Analytics, Google Tag Manager, Meta Pixel).\n * Each value is null when not configured. These IDs are public and safe to render in HTML.\n *\n * On Next.js, the result is cached and revalidated every hour by default\n * (`revalidate: 3600`) and tagged with `TRACKING_CONFIG_TAG`. Tenant sites\n * that want zero-lag updates can call `revalidateTag(TRACKING_CONFIG_TAG)`\n * from a webhook. Pass `revalidate: 0` to disable caching, `revalidate: false`\n * to cache indefinitely (tag-only invalidation), or any positive integer\n * (seconds) to override the interval. Outside Next.js the cache hints are\n * silently ignored — every call hits the network.\n */\n async getTrackingConfig(options: TrackingConfigOptions = {}): Promise<TrackingConfig> {\n const { revalidate = 3600, tags = [TRACKING_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n // Direct PostgREST fetch (instead of going through supabase-js) so that\n // Next.js sees the request and applies its `next` cache options. RLS\n // restricts the result to the tenant matching `x-cms-api-key`, so no\n // explicit tenant_id filter is needed.\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=google_analytics_id,google_tag_manager_id,google_ads_id,meta_pixel_id&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: {\n google_analytics_id: string | null\n google_tag_manager_id: string | null\n google_ads_id: string | null\n meta_pixel_id: string | null\n } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the all-null result so a transient\n // outage on the CMS never breaks page renders on the tenant site.\n }\n\n return {\n googleAnalyticsId: nullify(row?.google_analytics_id),\n googleTagManagerId: nullify(row?.google_tag_manager_id),\n googleAdsId: nullify(row?.google_ads_id),\n metaPixelId: nullify(row?.meta_pixel_id),\n }\n },\n\n /**\n * Get the tenant's Mapbox **public** token (`pk.*`) for rendering maps in the\n * browser. Returns `{ publicToken: null }` when not configured. The Mapbox\n * **secret** token is never exposed by the CMS — read it from your own\n * environment variables.\n *\n * Caching mirrors `getTrackingConfig()`: revalidated hourly by default and\n * tagged with `MAPBOX_CONFIG_TAG`. Call `revalidateTag(MAPBOX_CONFIG_TAG)`\n * from a `settings.mapbox_updated` webhook for zero-lag updates.\n */\n async getMapboxConfig(options: MapboxConfigOptions = {}): Promise<MapboxConfig> {\n const { revalidate = 3600, tags = [MAPBOX_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=mapbox_public_token&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: { mapbox_public_token: string | null } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the null result so a transient CMS\n // outage never breaks map rendering on the tenant site.\n }\n\n return { publicToken: nullify(row?.mapbox_public_token) }\n },\n }\n}\n\n/**\n * Cache tag applied to `getTrackingConfig()` fetches on Next.js. Call\n * `revalidateTag(TRACKING_CONFIG_TAG)` from a webhook handler on the tenant\n * site to make tracking-ID changes take effect immediately rather than\n * waiting for the next revalidation interval.\n */\nexport const TRACKING_CONFIG_TAG = \"cms:tracking-config\"\n\nexport interface TrackingConfigOptions {\n /**\n * Cache lifetime for the underlying fetch on Next.js, in seconds.\n * Defaults to 3600 (one hour). Set to `0` to disable caching, or `false`\n * to cache indefinitely until the tag is revalidated. Ignored outside\n * Next.js runtimes.\n */\n revalidate?: number | false\n /**\n * Cache tags for the underlying fetch on Next.js. Defaults to\n * `[TRACKING_CONFIG_TAG]`. Override to namespace by tenant if you share a\n * single Next.js process across multiple tenants (uncommon).\n */\n tags?: string[]\n}\n\n/**\n * Cache tag applied to `getMapboxConfig()` fetches on Next.js. Call\n * `revalidateTag(MAPBOX_CONFIG_TAG)` from a `settings.mapbox_updated` webhook\n * handler so public-token changes take effect immediately.\n */\nexport const MAPBOX_CONFIG_TAG = \"cms:mapbox-config\"\n\nexport interface MapboxConfigOptions {\n /** Cache lifetime in seconds on Next.js. Defaults to 3600. `0` disables caching, `false` caches until tag revalidation. Ignored outside Next.js. */\n revalidate?: number | false\n /** Cache tags applied to the fetch. Defaults to `[MAPBOX_CONFIG_TAG]`. */\n tags?: string[]\n}\n\nexport interface MapboxConfig {\n /** The tenant's Mapbox public token (`pk.*`), or null when not configured. */\n publicToken: string | null\n}\n\nfunction nullify(v: string | null | undefined): string | null {\n if (!v) return null\n const trimmed = v.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nexport interface TrackingConfig {\n googleAnalyticsId: string | null\n googleTagManagerId: string | null\n googleAdsId: string | null\n metaPixelId: string | null\n}\n\n/**\n * Creates a new Supabase client that includes the `x-cms-api-key`\n * header in every request, using the same URL and key as the original.\n */\nfunction withApiKey(supabase: SupabaseClient, apiKey: string) {\n // Extract URL and key from the existing client\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n return createSupabaseClient(supabaseUrl, supabaseKey, {\n global: {\n headers: {\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n },\n })\n}\n","import { CMS_CLIENT_VERSION } from \"./version\"\n\n/**\n * Reports the running SDK version to the CMS so the Super Admin UI can show\n * which client version each tenant site is on.\n *\n * Day-granular and process-local: at most one POST per (api key + day) per\n * Node process. Calls from browser code are ignored — the API key would be\n * exposed and the data is redundant with server-side reports.\n *\n * Fire-and-forget. Failures are silent — telemetry must never break a render.\n */\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\ninterface ReportRecord {\n date: string // YYYY-MM-DD\n version: string\n}\n\nconst reported = new Map<string, ReportRecord>()\n\nfunction todayKey(): string {\n return new Date().toISOString().slice(0, 10)\n}\n\nexport function reportClientVersion(apiKey: string, appUrl?: string): void {\n // Skip in browser contexts — server-side calls already cover the tenant.\n if (typeof window !== \"undefined\") return\n if (!apiKey) return\n\n const today = todayKey()\n const last = reported.get(apiKey)\n if (last && last.date === today && last.version === CMS_CLIENT_VERSION) return\n\n // Optimistically mark as reported so concurrent calls don't all fire. If the\n // request fails we'll retry tomorrow — that's acceptable for telemetry.\n reported.set(apiKey, { date: today, version: CMS_CLIENT_VERSION })\n\n const envAppUrl =\n typeof process !== \"undefined\" ? process.env?.NEXT_PUBLIC_CMS_URL : undefined\n const base = (appUrl ?? envAppUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n const url = `${base}/api/client-telemetry`\n\n // Fire and forget. Use a hand-rolled then() chain rather than async/await so\n // we don't accidentally surface an unhandled rejection.\n void fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n body: JSON.stringify({\n api_key: apiKey,\n version: CMS_CLIENT_VERSION,\n }),\n }).catch(() => {\n // Allow a retry on the next call by clearing the optimistic record.\n reported.delete(apiKey)\n })\n}\n","import type { EmbedValue } from \"./types\"\n\nfunction toCssAspectRatio(ratio: string): string {\n const parts = ratio.split(\":\")\n if (parts.length !== 2) return \"16/9\"\n const w = parseFloat(parts[0])\n const h = parseFloat(parts[1])\n if (!w || !h || w <= 0 || h <= 0) return \"16/9\"\n return `${w}/${h}`\n}\n\n/**\n * Generate responsive iframe HTML for an embed field value.\n * Returns an empty string if the value is invalid or the URL is not HTTPS.\n */\nexport function getEmbedHtml(value: unknown): string {\n if (!value || typeof value !== \"object\") return \"\"\n const embed = value as EmbedValue\n if (!embed.url || !embed.url.startsWith(\"https://\")) return \"\"\n\n const width = embed.width || \"100%\"\n const aspectRatio = toCssAspectRatio(embed.aspect_ratio || \"16:9\")\n\n return `<div style=\"position:relative;width:${width};aspect-ratio:${aspectRatio}\"><iframe src=\"${embed.url}\" style=\"position:absolute;inset:0;width:100%;height:100%\" frameborder=\"0\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\" allowfullscreen loading=\"lazy\"></iframe></div>`\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n Product,\n ProductCategory,\n ProductQueryOptions,\n CreateOrderParams,\n CreateOrderResult,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\nexport interface ShopClientOptions {\n /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */\n apiKey: string\n /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */\n appUrl?: string\n}\n\n/**\n * Creates a typed client for the eCommerce REST API (products, categories, orders).\n *\n * Unlike `createCmsClient`, the shop client talks to the CMS REST endpoints\n * (`/api/products`, `/api/product-categories`, `/api/orders/create`) rather than\n * Supabase directly — it doesn't need the `supabase` argument, but accepts it\n * for API symmetry with the rest of the SDK.\n *\n * Usage:\n * ```ts\n * const shop = createShopClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const products = await shop.getProducts({ category: \"electronics\", limit: 20 })\n * ```\n */\nexport function createShopClient(\n _supabase: SupabaseClient,\n options: ShopClientOptions\n) {\n const { apiKey } = options\n const appUrl = (options.appUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n function authHeaders(): HeadersInit {\n return {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n }\n }\n\n async function getJson<T>(path: string): Promise<T> {\n const res = await fetch(`${appUrl}${path}`, {\n headers: authHeaders(),\n // Caller controls Next.js caching by wrapping the call site.\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(\n body.error ?? `Shop request failed (${res.status}): ${path}`\n )\n }\n return res.json() as Promise<T>\n }\n\n return {\n /**\n * List published products. Includes nested `variants` and `options`.\n *\n * `category` filters by category slug (matches the FK `category_id`,\n * with a fallback to the legacy `category` text column).\n */\n async getProducts(queryOptions: ProductQueryOptions = {}): Promise<Product[]> {\n const params = new URLSearchParams()\n if (queryOptions.category) params.set(\"category\", queryOptions.category)\n if (queryOptions.tags?.length) params.set(\"tags\", queryOptions.tags.join(\",\"))\n if (queryOptions.limit) params.set(\"limit\", String(queryOptions.limit))\n if (queryOptions.offset) params.set(\"offset\", String(queryOptions.offset))\n if (queryOptions.sort) params.set(\"sort\", queryOptions.sort)\n if (queryOptions.order) params.set(\"order\", queryOptions.order)\n\n const qs = params.toString()\n const { products } = await getJson<{ products: Product[] }>(\n `/api/products${qs ? `?${qs}` : \"\"}`\n )\n return products ?? []\n },\n\n /**\n * Get a single published product by slug. Returns null if not found.\n * Includes nested `variants` and `options`.\n */\n async getProductBySlug(slug: string): Promise<Product | null> {\n const res = await fetch(`${appUrl}/api/products/${encodeURIComponent(slug)}`, {\n headers: authHeaders(),\n })\n if (res.status === 404) return null\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? `Failed to fetch product ${slug}`)\n }\n const { product } = (await res.json()) as { product: Product }\n return product ?? null\n },\n\n /**\n * List product categories for the tenant, ordered by sort_order then name.\n */\n async getCategories(): Promise<ProductCategory[]> {\n const { categories } = await getJson<{ categories: ProductCategory[] }>(\n `/api/product-categories`\n )\n return categories ?? []\n },\n\n /**\n * Get a single category by slug. Returns null if not found.\n */\n async getCategoryBySlug(slug: string): Promise<ProductCategory | null> {\n const all = await this.getCategories()\n return all.find((c) => c.slug === slug) ?? null\n },\n\n /**\n * Create a pending order and return a Stripe PaymentIntent client_secret\n * to confirm payment client-side.\n *\n * Stripe must be configured for the tenant; eCommerce must be enabled on\n * their billing plan. Validates stock for tracked variants and applies\n * any discount code before creating the PaymentIntent.\n */\n async createOrder(params: CreateOrderParams): Promise<CreateOrderResult> {\n const res = await fetch(`${appUrl}/api/orders/create`, {\n method: \"POST\",\n headers: authHeaders(),\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? \"Order creation failed\")\n }\n return res.json() as Promise<CreateOrderResult>\n },\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport { reportClientVersion } from \"./telemetry\"\n\nexport type EventStatus = \"draft\" | \"published\" | \"archived\"\nexport type BookingStatus = \"pending\" | \"confirmed\" | \"cancelled\" | \"refunded\"\n\nexport interface CmsEvent {\n id: string\n tenant_id: string\n title: string\n slug: string\n description: string | null\n short_description: string | null\n status: EventStatus\n start_at: string\n end_at: string | null\n venue_name: string | null\n venue_address: string | null\n hero_image: string | null\n gallery: string[]\n tags: string[]\n seo_title: string | null\n seo_description: string | null\n metadata: Record<string, unknown>\n sort_order: number\n published_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CmsTicketTier {\n id: string\n event_id: string\n tenant_id: string\n name: string\n description: string | null\n price_cents: number\n capacity: number | null\n sold_count: number\n sales_start_at: string | null\n sales_end_at: string | null\n is_active: boolean\n sort_order: number\n}\n\nexport interface EventWithTiers extends CmsEvent {\n tiers: CmsTicketTier[]\n}\n\nexport interface EventQueryOptions {\n /** Only include events with start_at >= now. Default false. */\n upcomingOnly?: boolean\n tag?: string\n limit?: number\n offset?: number\n sort?: \"start_at\" | \"sort_order\" | \"created_at\"\n order?: \"asc\" | \"desc\"\n}\n\nexport interface CreateBookingParams {\n event_slug: string\n ticket_tier_id?: string\n customer_email: string\n customer_name?: string\n customer_phone?: string\n quantity?: number\n success_url?: string\n cancel_url?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface CreateBookingResult {\n booking_id: string\n booking_number: string\n status: \"pending\" | \"confirmed\"\n /** Redirect the browser here for paid bookings. */\n checkout_url?: string\n /** Present on free bookings — used for attendance QR display. */\n qr_token?: string\n}\n\nexport function createEventsClient(\n supabase: SupabaseClient,\n options: { apiKey: string; appUrl?: string }\n) {\n const { apiKey, appUrl } = options\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n async function getEvents(\n queryOptions?: EventQueryOptions\n ): Promise<EventWithTiers[]> {\n let query = supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"status\", \"published\")\n .order(queryOptions?.sort ?? \"start_at\", {\n ascending: (queryOptions?.order ?? \"asc\") === \"asc\",\n })\n\n if (queryOptions?.upcomingOnly) {\n query = query.gte(\"start_at\", new Date().toISOString())\n }\n if (queryOptions?.tag) {\n query = query.contains(\"tags\", [queryOptions.tag])\n }\n if (queryOptions?.limit) {\n query = query.limit(queryOptions.limit)\n }\n if (queryOptions?.offset) {\n query = query.range(\n queryOptions.offset,\n queryOptions.offset + (queryOptions.limit ?? 50) - 1\n )\n }\n\n const { data } = await query\n return (data ?? []) as EventWithTiers[]\n }\n\n async function getEventBySlug(slug: string): Promise<EventWithTiers | null> {\n const { data } = await supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"slug\", slug)\n .eq(\"status\", \"published\")\n .single()\n return (data as EventWithTiers) ?? null\n }\n\n async function createBooking(\n params: CreateBookingParams\n ): Promise<CreateBookingResult> {\n const baseUrl = appUrl ?? \"\"\n const res = await fetch(`${baseUrl}/api/bookings/create`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const err = await res\n .json()\n .catch(() => ({ error: \"Booking creation failed\" }))\n throw new Error(err.error ?? \"Booking creation failed\")\n }\n return res.json() as Promise<CreateBookingResult>\n }\n\n return { getEvents, getEventBySlug, createBooking }\n}\n","/**\n * Image helpers for CMS content.\n *\n * Images are already optimised (WebP, max 2400px) on upload.\n * No server-side transforms needed — serve originals directly.\n *\n * These functions are kept for backward compatibility but no longer\n * call Supabase image transformation endpoints.\n */\n\nexport interface ImageTransformOptions {\n width?: number\n height?: number\n quality?: number\n resize?: \"contain\" | \"cover\" | \"fill\"\n format?: \"origin\"\n}\n\n/**\n * Returns the image URL directly.\n *\n * Previously this converted URLs to use Supabase's /render/image/\n * transform endpoint, but images are now pre-optimised on upload\n * (WebP, max 2400px, quality 82) so transforms are unnecessary.\n *\n * The function is kept for backward compatibility — existing code\n * that calls getTransformUrl() will continue to work without changes.\n */\nexport function getTransformUrl(\n originalUrl: string,\n _options: ImageTransformOptions = {}\n): string {\n return originalUrl\n}\n\n/**\n * Returns a simple srcSet using the original image.\n *\n * Previously generated multiple transformed widths, but since images\n * are now pre-optimised WebP, a single source is sufficient.\n * Modern browsers handle responsive display efficiently with a\n * well-sized WebP source.\n */\nexport function getSrcSet(\n originalUrl: string,\n _widths: number[] = [],\n _quality = 80\n): string {\n return `${originalUrl} 2400w`\n}\n\n/**\n * Common image size presets — kept for backward compatibility.\n * Since images are pre-optimised, these are informational only.\n */\nexport const IMAGE_PRESETS = {\n thumbnail: { width: 150, height: 150, resize: \"cover\" as const, quality: 70 },\n card: { width: 400, height: 300, resize: \"cover\" as const, quality: 80 },\n hero: { width: 1200, height: 630, resize: \"cover\" as const, quality: 85 },\n og: { width: 1200, height: 630, resize: \"cover\" as const, quality: 90 },\n avatar: { width: 80, height: 80, resize: \"cover\" as const, quality: 75 },\n full: { width: 1920, resize: \"contain\" as const, quality: 85 },\n} as const\n","import type { DateGranularity } from \"./types\"\n\nexport interface ParsedPartialDate {\n granularity: DateGranularity\n /** 4-digit year — absent for `month` and `day_month`. */\n year?: number\n /** 1-12 — absent for `year`. */\n month?: number\n /** 1-31 — present only for `full` and `day_month`. */\n day?: number\n}\n\n/**\n * Parses a partial-ISO date string (as produced by a `date` field) into its parts.\n * Returns `null` if the string doesn't match a known granularity shape.\n */\nexport function parsePartialDate(value: string): ParsedPartialDate | null {\n if (!value) return null\n let m: RegExpExecArray | null\n if ((m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"full\", year: +m[1], month: +m[2], day: +m[3] }\n if ((m = /^(\\d{4})-(\\d{2})$/.exec(value)))\n return { granularity: \"month_year\", year: +m[1], month: +m[2] }\n if ((m = /^(\\d{4})$/.exec(value))) return { granularity: \"year\", year: +m[1] }\n if ((m = /^--(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"day_month\", month: +m[1], day: +m[2] }\n if ((m = /^--(\\d{2})$/.exec(value))) return { granularity: \"month\", month: +m[1] }\n return null\n}\n\nexport interface FormatPartialDateOptions {\n /** BCP 47 locale(s) passed to Intl.DateTimeFormat. Defaults to the runtime locale. */\n locale?: string | string[]\n /** Month rendering style. Defaults to `long` (e.g. \"May\"). */\n month?: \"long\" | \"short\" | \"narrow\" | \"numeric\" | \"2-digit\"\n}\n\n/**\n * Formats a partial-ISO date string for display, honouring the value's granularity\n * and locale-correct part ordering (e.g. \"12 May\" vs \"May 12\"). Returns the raw\n * string unchanged if it isn't a recognised partial date.\n */\nexport function formatPartialDate(value: string, options: FormatPartialDateOptions = {}): string {\n const parsed = parsePartialDate(value)\n if (!parsed) return value\n\n const { locale, month = \"long\" } = options\n const monthIndex = parsed.month ? parsed.month - 1 : 0\n\n switch (parsed.granularity) {\n case \"year\":\n return String(parsed.year)\n case \"month\":\n return new Intl.DateTimeFormat(locale, { month }).format(new Date(2000, monthIndex, 1))\n case \"month_year\":\n return new Intl.DateTimeFormat(locale, { month, year: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, 1)\n )\n case \"day_month\":\n return new Intl.DateTimeFormat(locale, { month, day: \"numeric\" }).format(\n new Date(2000, monthIndex, parsed.day!)\n )\n case \"full\":\n return new Intl.DateTimeFormat(locale, { year: \"numeric\", month, day: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, parsed.day!)\n )\n }\n}\n","/**\n * Helpers for verifying outbound webhooks fired by the CMS.\n *\n * The CMS POSTs JSON to subscriber URLs and signs the raw body with\n * HMAC-SHA256 using the shared secret you set in the Webhooks tab. The hex\n * digest arrives in the `X-CMS-Signature` header.\n *\n * Use Web Crypto so this works in Node, Edge, Deno, and Bun runtimes.\n */\n\nexport interface WebhookEventPayload {\n event: string\n tenant_id: string\n content_type_slug?: string\n content_item_id?: string\n slug?: string\n title?: string\n status?: string\n /** Stable identifier of the resource that changed (e.g. product id, flipbook id, integration provider). */\n resource_id?: string\n /**\n * Cache tags the receiver should invalidate. Use {@link revalidateAllTags}\n * to wire this through Next.js's `revalidateTag()` in one line.\n * All tags are namespaced with the `cms:` prefix.\n */\n cache_tags?: string[]\n /** Free-form bag for event-specific extras (e.g. provider name, change counts). */\n data?: Record<string, unknown>\n timestamp: string\n /** Commerce + custom events may attach extra top-level fields. */\n [key: string]: unknown\n}\n\n/**\n * Verify the HMAC-SHA256 signature on a webhook delivery.\n *\n * Pass the **raw** request body (not a parsed JSON object) — re-stringifying\n * a parsed body can change whitespace and invalidate the signature.\n *\n * Returns `true` when the signature matches in constant time, `false`\n * otherwise. Never throws on a bad signature; only throws if the\n * `crypto.subtle` API is unavailable in the runtime.\n *\n * @example\n * const raw = await req.text()\n * const sig = req.headers.get(\"x-cms-signature\")\n * if (!await verifyWebhookSignature(process.env.CMS_WEBHOOK_SECRET!, raw, sig)) {\n * return new Response(\"bad signature\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n */\nexport async function verifyWebhookSignature(\n secret: string,\n rawBody: string,\n signature: string | null | undefined\n): Promise<boolean> {\n if (!signature || !secret) return false\n\n const subtle = (globalThis.crypto && globalThis.crypto.subtle) || null\n if (!subtle) {\n throw new Error(\n \"verifyWebhookSignature requires the Web Crypto API (globalThis.crypto.subtle). \" +\n \"Available in Node 18+, all Edge runtimes, Deno, and Bun.\"\n )\n }\n\n const encoder = new TextEncoder()\n const key = await subtle.importKey(\n \"raw\",\n encoder.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"]\n )\n const sigBuffer = await subtle.sign(\"HMAC\", key, encoder.encode(rawBody))\n const expected = bufferToHex(sigBuffer)\n\n return timingSafeEqualHex(expected, signature.trim())\n}\n\n/**\n * The webhook event names the CMS can fire. Use as a discriminator on the\n * `event` field of {@link WebhookEventPayload}.\n *\n * Most receivers don't need to switch on the event name — every payload\n * carries a `cache_tags` array. Pass it to {@link revalidateAllTags} to\n * invalidate the right Next.js caches in one line.\n */\nexport const WEBHOOK_EVENTS = [\n // Content\n \"content.published\",\n \"content.unpublished\",\n \"content.updated\",\n \"content.deleted\",\n \"content_type.updated\",\n \"content_type.deleted\",\n // Settings (diffed — only fires when a relevant field actually changed)\n \"settings.tracking_updated\",\n \"settings.brand_updated\",\n \"settings.integration_updated\",\n \"settings.mapbox_updated\",\n // Commerce\n \"products.updated\",\n \"product_categories.updated\",\n \"ticket_tiers.updated\",\n \"membership_tiers.updated\",\n \"order.created\",\n \"order.paid\",\n \"order.payment_failed\",\n \"order.refunded\",\n \"order.shipped\",\n \"booking.confirmed\",\n \"inventory.low_stock\",\n // Site\n \"redirects.updated\",\n \"reviews.synced\",\n \"flipbook.ready\",\n] as const\n\nexport type WebhookEvent = (typeof WEBHOOK_EVENTS)[number]\n\n/**\n * Invalidate every cache tag listed in a webhook payload. Call this from your\n * receiver and most events will Just Work without per-event branching.\n *\n * Pass Next.js's `revalidateTag` (or any function with the same shape) — the\n * SDK has no peer dep on `next/cache`, so the import stays in your code.\n *\n * **Next 16 compatibility.** In Next 16, `revalidateTag(tag)` was made into\n * `revalidateTag(tag, profile)`, and calling it with one argument emits a\n * deprecation warning. The cache profile controls expiry — `\"default\"` and\n * `\"max\"` both have non-zero `expire` values and will **not** invalidate the\n * cache. Immediate invalidation requires `{ expire: 0 }`, which isn't\n * documented in the function reference. This helper always passes\n * `{ expire: 0 }` as the second argument, so it does the right thing on Next 16\n * and is silently ignored by Next 14/15.\n *\n * @example\n * import { revalidateTag } from \"next/cache\"\n * import { revalidateAllTags } from \"@distinctagency/cms-client\"\n *\n * export async function POST(req: Request) {\n * const raw = await req.text()\n * if (!await verifyWebhookSignature(SECRET, raw, req.headers.get(\"x-cms-signature\"))) {\n * return new Response(\"bad sig\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n * revalidateAllTags(payload, revalidateTag)\n * return Response.json({ ok: true })\n * }\n */\nexport function revalidateAllTags(\n payload: Pick<WebhookEventPayload, \"cache_tags\">,\n revalidateTag: (tag: string, profile: { expire?: number }) => unknown\n): string[] {\n const tags = payload.cache_tags\n if (!Array.isArray(tags) || tags.length === 0) return []\n const invalidated: string[] = []\n for (const tag of tags) {\n if (typeof tag !== \"string\" || tag.length === 0) continue\n revalidateTag(tag, { expire: 0 })\n invalidated.push(tag)\n }\n return invalidated\n}\n\nfunction bufferToHex(buf: ArrayBuffer): string {\n const bytes = new Uint8Array(buf)\n let out = \"\"\n for (let i = 0; i < bytes.length; i++) {\n out += bytes[i].toString(16).padStart(2, \"0\")\n }\n return out\n}\n\n/**\n * Constant-time equality check on two hex strings. Returns false fast when\n * lengths differ — the length itself is not secret.\n */\nfunction timingSafeEqualHex(a: string, b: string): boolean {\n if (a.length !== b.length) return false\n let mismatch = 0\n for (let i = 0; i < a.length; i++) {\n mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i)\n }\n return mismatch === 0\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,qBAAqB;;;ACPlC,yBAAqD;;;ACarD,IAAM,kBAAkB;AAOxB,IAAM,WAAW,oBAAI,IAA0B;AAE/C,SAAS,WAAmB;AAC1B,UAAO,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE;AAC7C;AAEO,SAAS,oBAAoB,QAAgB,QAAuB;AAEzE,MAAI,OAAO,WAAW,YAAa;AACnC,MAAI,CAAC,OAAQ;AAEb,QAAM,QAAQ,SAAS;AACvB,QAAM,OAAO,SAAS,IAAI,MAAM;AAChC,MAAI,QAAQ,KAAK,SAAS,SAAS,KAAK,YAAY,mBAAoB;AAIxE,WAAS,IAAI,QAAQ,EAAE,MAAM,OAAO,SAAS,mBAAmB,CAAC;AAEjE,QAAM,YACJ,OAAO,YAAY,cAAc,QAAQ,KAAK,sBAAsB;AACtE,QAAM,QAAQ,UAAU,aAAa,iBAAiB,QAAQ,OAA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AAM,QAAQ,KAAK;AACrC,WAAO,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAAA,EAC9C;AACA,SAAO;AACT;AAMA,SAAS,mBAAmB,GAAW,GAAoB;AACzD,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,MAAI,WAAW;AACf,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,gBAAY,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC9C;AACA,SAAO,aAAa;AACtB;","names":["options","query","data","error","createSupabaseClient","DEFAULT_APP_URL"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/version.ts","../src/queries.ts","../src/telemetry.ts","../src/embed.ts","../src/shop.ts","../src/events.ts","../src/maps.ts","../src/cdn.ts","../src/date.ts","../src/webhooks.ts"],"sourcesContent":["// Server-safe exports — no React, no \"use client\"\nexport { CMS_CLIENT_VERSION } from \"./version\"\nexport { createCmsClient, TRACKING_CONFIG_TAG, MAPBOX_CONFIG_TAG, singletonTag } from \"./queries\"\nexport type { TrackingConfig, TrackingConfigOptions, MapboxConfig, MapboxConfigOptions } from \"./queries\"\nexport { getEmbedHtml } from \"./embed\"\nexport { createShopClient } from \"./shop\"\nexport { createEventsClient } from \"./events\"\nexport { createMapsClient } from \"./maps\"\nexport type { MapsClientOptions } from \"./maps\"\nexport type {\n CmsEvent,\n CmsTicketTier,\n EventWithTiers,\n EventQueryOptions,\n CreateBookingParams,\n CreateBookingResult,\n EventStatus,\n BookingStatus,\n} from \"./events\"\nexport { getTransformUrl, getSrcSet, IMAGE_PRESETS } from \"./cdn\"\nexport type { ImageTransformOptions } from \"./cdn\"\nexport { parsePartialDate, formatPartialDate } from \"./date\"\nexport type { ParsedPartialDate, FormatPartialDateOptions } from \"./date\"\nexport { verifyWebhookSignature, revalidateAllTags, WEBHOOK_EVENTS } from \"./webhooks\"\nexport type { WebhookEvent, WebhookEventPayload } from \"./webhooks\"\nexport type {\n FieldType,\n FieldDefinition,\n DateGranularity,\n Tenant,\n Profile,\n ContentType,\n ContentItem,\n MediaItem,\n MediaFolder,\n ContentQueryOptions,\n CmsClientOptions,\n TenantMembership,\n ImageConfig,\n ContentTypeSeoConfig,\n Product,\n ProductStatus,\n ProductCategory,\n ProductVariant,\n ProductOption,\n OrderAddress,\n OrderStatus,\n PaymentStatus,\n OrderLineItem,\n DiscountType,\n CreateOrderParams,\n CreateOrderResult,\n ProductQueryOptions,\n MembershipTier,\n Member,\n GoogleReview,\n ReviewQueryOptions,\n EmbedValue,\n FlipbookPagePublic,\n FlipbookTocEntryPublic,\n FlipbookPublic,\n GeocodeOptions,\n GeocodeResult,\n} from \"./types\"\n","/**\n * The version of @distinctagency/cms-client embedded in this build.\n *\n * Bump this in lock-step with package.json — the value is read by the SDK to\n * report installed-version telemetry and to send `x-cms-client-version` on\n * outgoing requests.\n */\nexport const CMS_CLIENT_VERSION = \"1.24.0\"\n","import { createClient as createSupabaseClient } from \"@supabase/supabase-js\"\nimport type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n CmsClientOptions,\n ContentItem,\n ContentQueryOptions,\n ContentType,\n GoogleReview,\n ReviewQueryOptions,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\n/**\n * Creates a CMS query client authenticated with a tenant API key.\n *\n * Usage:\n * ```ts\n * const cms = createCmsClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const events = await cms.getContentItems('events', { status: 'published' })\n * ```\n *\n * The API key is sent as an `x-cms-api-key` header on every request.\n * Supabase RLS policies validate it against the tenant's stored key.\n */\nexport function createCmsClient(\n supabase: SupabaseClient,\n options: CmsClientOptions\n) {\n const { apiKey } = options\n\n // Create a new Supabase client with the API key header injected globally\n const client = withApiKey(supabase, apiKey) as SupabaseClient\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, options.appUrl)\n\n /** Resolve the tenant ID from the API key (cached per request) */\n let tenantIdCache: string | null = null\n\n async function getTenantId(): Promise<string> {\n if (tenantIdCache) return tenantIdCache\n\n const { data, error } = await client\n .from(\"tenants\")\n .select(\"id\")\n .single()\n\n if (error || !data) {\n throw new Error(\n \"Invalid CMS API key — no tenant found. Check your apiKey.\"\n )\n }\n\n tenantIdCache = data.id\n return data.id\n }\n\n /** Resolve a content type from its slug (cached) */\n const contentTypeCache = new Map<string, ContentType>()\n\n async function getContentTypeBySlug(contentTypeSlug: string): Promise<ContentType> {\n if (contentTypeCache.has(contentTypeSlug)) return contentTypeCache.get(contentTypeSlug)!\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n const ct = data as ContentType\n contentTypeCache.set(contentTypeSlug, ct)\n return ct\n }\n\n async function getContentTypeId(contentTypeSlug: string): Promise<string> {\n const ct = await getContentTypeBySlug(contentTypeSlug)\n return ct.id\n }\n\n /** Check if a member token has access to a gated content type */\n async function checkMemberAccess(\n contentType: ContentType,\n memberToken?: string\n ): Promise<{ allowed: boolean; memberTierId: string | null }> {\n const requiredTierId = contentType.required_membership_tier_id\n if (!requiredTierId) return { allowed: true, memberTierId: null } // Public\n\n if (!memberToken) return { allowed: false, memberTierId: null } // Gated but no token\n\n // Verify the member's token and check their tier\n const { data: session } = await client\n .from(\"member_sessions\")\n .select(\"member_id\")\n .eq(\"token_hash\", memberToken) // Note: caller should hash the token\n .single()\n\n if (!session) return { allowed: false, memberTierId: null }\n\n const { data: member } = await client\n .from(\"members\")\n .select(\"membership_tier_id, status\")\n .eq(\"id\", session.member_id)\n .single()\n\n if (!member || member.status !== \"active\") return { allowed: false, memberTierId: null }\n\n // Check if the member's tier matches (or exceeds) the required tier\n // For now: exact match or the member has the required tier\n return {\n allowed: member.membership_tier_id === requiredTierId,\n memberTierId: member.membership_tier_id as string | null,\n }\n }\n\n async function getFlipbook(id: string): Promise<import(\"./types\").FlipbookPublic | null> {\n const { data, error } = await client\n .from(\"flipbooks\")\n .select(\"id, title, page_count, status, manifest, download_enabled, tenant_id\")\n .eq(\"id\", id)\n .single()\n if (error || !data) return null\n\n const manifest = data.manifest as\n | { pages: Array<{ image: string; thumb: string; w: number; h: number }>; toc: Array<{ title: string; page: number }> }\n | null\n if (!manifest) {\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? 0,\n status: data.status as \"pending_upload\" | \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: [],\n toc: [],\n download_url: null,\n }\n }\n\n // Browser-safe env lookup via globalThis. The client package builds without\n // @types/node so referring to `process` directly fails the dts build; reading\n // through globalThis sidesteps that and works in every JS environment that\n // matters (Node, browsers, edge runtimes).\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process\n const cdnBase = proc?.env?.NEXT_PUBLIC_R2_PUBLIC_URL ?? \"https://cdn.distinctstudio.co.nz\"\n const prefix = `flipbooks/${data.tenant_id as string}/${data.id as string}/`\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? manifest.pages.length,\n status: data.status as \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: manifest.pages.map((p) => ({\n url: `${cdnBase}/${prefix}${p.image}`,\n thumb_url: `${cdnBase}/${prefix}${p.thumb}`,\n w: p.w,\n h: p.h,\n })),\n toc: manifest.toc,\n download_url: data.download_enabled\n ? `${options.appUrl ?? \"\"}/api/flipbooks/${data.id as string}/download`\n : null,\n }\n }\n\n return {\n /**\n * List content items for a content type.\n * Defaults to published items ordered by most recent.\n */\n async getContentItems(\n contentTypeSlug: string,\n options: ContentQueryOptions = {}\n ): Promise<(ContentItem & { locked?: boolean })[]> {\n const contentType = await getContentTypeBySlug(contentTypeSlug)\n\n const {\n status = \"published\",\n orderBy = \"published_at\",\n orderDirection = \"desc\",\n limit = 100,\n offset = 0,\n memberToken,\n } = options\n\n // Check membership access\n const access = await checkMemberAccess(contentType, memberToken)\n\n // If gated and no access, check gating mode\n if (!access.allowed && contentType.required_membership_tier_id) {\n // Get tenant settings for gating mode\n const tenantId = await getTenantId()\n const { data: settings } = await client\n .from(\"tenant_settings\")\n .select(\"membership_gating_mode\")\n .eq(\"tenant_id\", tenantId)\n .single()\n\n const mode = (settings?.membership_gating_mode as string) ?? \"teaser\"\n\n if (mode === \"hide\") {\n return [] // Hide: return nothing\n }\n\n // Teaser mode: return items with locked flag, no body/data\n let query = client\n .from(\"content_items\")\n .select(\"id, title, slug, status, excerpt, seo_title, seo_description, featured_image, published_at, created_at, updated_at\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) query = query.eq(\"status\", status)\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n if (error) throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n\n return (data ?? []).map((item) => ({\n ...item,\n data: {},\n locked: true,\n })) as (ContentItem & { locked: boolean })[]\n }\n\n // Full access\n let query = client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n }\n\n return (data ?? []) as ContentItem[]\n },\n\n /**\n * Get a single content item by its slug.\n * Returns null if not found.\n */\n async getContentItemBySlug(\n contentTypeSlug: string,\n itemSlug: string\n ): Promise<ContentItem | null> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"slug\", itemSlug)\n .single()\n\n if (error) {\n if (error.code === \"PGRST116\") return null // not found\n throw new Error(\n `Failed to fetch ${contentTypeSlug}/${itemSlug}: ${error.message}`\n )\n }\n\n return data as ContentItem\n },\n\n /**\n * Get the single published item for a singleton content type (\"page\").\n *\n * A singleton content type owns exactly one item. Use this for editable\n * page copy (hero text, section headings, etc.) stored in the CMS.\n * Returns null when the singleton has no published item yet — callers\n * should fall back to their hardcoded defaults in that case.\n *\n * Wrap this in `unstable_cache` with a `cms:singleton:<slug>` tag on the\n * consuming site to cache it and revalidate via the CMS webhook.\n */\n async getSingleton(contentTypeSlug: string): Promise<ContentItem | null> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"status\", \"published\")\n .order(\"updated_at\", { ascending: false })\n .limit(1)\n .maybeSingle()\n\n if (error) {\n throw new Error(\n `Failed to fetch singleton ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data as ContentItem) ?? null\n },\n\n /**\n * Get a content type definition (including its field schema).\n */\n async getContentType(contentTypeSlug: string): Promise<ContentType> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n return data as ContentType\n },\n\n /**\n * Get all slugs for a content type (for generateStaticParams).\n */\n async getAllSlugs(\n contentTypeSlug: string\n ): Promise<{ slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"slug\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"status\", \"published\")\n\n if (error) {\n throw new Error(\n `Failed to fetch slugs for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { slug: string }[]\n },\n\n /**\n * List all content types for this tenant.\n */\n async getContentTypes(): Promise<ContentType[]> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .order(\"name\")\n\n if (error) {\n throw new Error(`Failed to fetch content types: ${error.message}`)\n }\n\n return (data ?? []) as ContentType[]\n },\n\n /**\n * Get all slug redirects for a content type.\n * Use in next.config.js redirects() or middleware for 301s.\n * Returns: [{ old_slug, new_slug }, ...]\n */\n async getRedirects(\n contentTypeSlug: string\n ): Promise<{ old_slug: string; new_slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"slug_redirects\")\n .select(\"old_slug, new_slug\")\n .eq(\"content_type_id\", contentTypeId)\n\n if (error) {\n throw new Error(\n `Failed to fetch redirects for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { old_slug: string; new_slug: string }[]\n },\n\n /**\n * Get all custom path redirects for this tenant.\n * Use alongside getRedirects() in next.config.ts for full redirect coverage.\n */\n async getCustomRedirects(): Promise<\n { source_path: string; destination_path: string; permanent: boolean }[]\n > {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"custom_redirects\")\n .select(\"source_path, destination_path, permanent\")\n .eq(\"tenant_id\", tenantId)\n\n if (error) {\n throw new Error(`Failed to fetch custom redirects: ${error.message}`)\n }\n\n return (data ?? []) as {\n source_path: string\n destination_path: string\n permanent: boolean\n }[]\n },\n\n /**\n * Get form submissions for a specific form.\n * Useful for displaying testimonials, reviews, etc.\n */\n async getFormSubmissions(\n formSlug: string,\n options: { status?: string; limit?: number; offset?: number } = {}\n ): Promise<Record<string, unknown>[]> {\n const tenantId = await getTenantId()\n\n const { data: form } = await client\n .from(\"forms\")\n .select(\"id\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n if (!form) return []\n\n const { limit = 50, offset = 0, status } = options\n\n let query = client\n .from(\"form_submissions\")\n .select(\"*\")\n .eq(\"form_id\", form.id)\n .eq(\"is_spam\", false)\n .order(\"created_at\", { ascending: false })\n .range(offset, offset + limit - 1)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n const { data } = await query\n return (data ?? []) as Record<string, unknown>[]\n },\n\n /**\n * Get a form configuration by slug.\n */\n async getForm(\n formSlug: string\n ): Promise<Record<string, unknown> | null> {\n const tenantId = await getTenantId()\n\n const { data } = await client\n .from(\"forms\")\n .select(\"id, name, slug, description, is_active\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n return data as Record<string, unknown> | null\n },\n\n /**\n * Get a flipbook by ID, including CDN-resolved page image URLs.\n * Returns null if not found or manifest not yet ready.\n */\n getFlipbook,\n\n /**\n * Get Google Reviews for this tenant.\n * Defaults to approved reviews ordered by most recent.\n */\n async getReviews(\n options: ReviewQueryOptions = {}\n ): Promise<GoogleReview[]> {\n const tenantId = await getTenantId()\n\n const {\n status = \"approved\",\n minRating,\n limit = 50,\n offset = 0,\n orderBy = \"review_timestamp\",\n orderDirection = \"desc\",\n } = options\n\n let query = client\n .from(\"google_reviews\")\n .select(\"id, author_name, author_photo_url, rating, text, review_timestamp\")\n .eq(\"tenant_id\", tenantId)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n if (minRating) {\n query = query.gte(\"rating\", minRating)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch reviews: ${error.message}`)\n }\n\n return (data ?? []) as GoogleReview[]\n },\n\n /**\n * Get the tenant's third-party tracking IDs (Google Analytics, Google Tag Manager, Meta Pixel).\n * Each value is null when not configured. These IDs are public and safe to render in HTML.\n *\n * On Next.js, the result is cached and revalidated every hour by default\n * (`revalidate: 3600`) and tagged with `TRACKING_CONFIG_TAG`. Tenant sites\n * that want zero-lag updates can call `revalidateTag(TRACKING_CONFIG_TAG)`\n * from a webhook. Pass `revalidate: 0` to disable caching, `revalidate: false`\n * to cache indefinitely (tag-only invalidation), or any positive integer\n * (seconds) to override the interval. Outside Next.js the cache hints are\n * silently ignored — every call hits the network.\n */\n async getTrackingConfig(options: TrackingConfigOptions = {}): Promise<TrackingConfig> {\n const { revalidate = 3600, tags = [TRACKING_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n // Direct PostgREST fetch (instead of going through supabase-js) so that\n // Next.js sees the request and applies its `next` cache options. RLS\n // restricts the result to the tenant matching `x-cms-api-key`, so no\n // explicit tenant_id filter is needed.\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=google_analytics_id,google_tag_manager_id,google_ads_id,meta_pixel_id&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: {\n google_analytics_id: string | null\n google_tag_manager_id: string | null\n google_ads_id: string | null\n meta_pixel_id: string | null\n } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the all-null result so a transient\n // outage on the CMS never breaks page renders on the tenant site.\n }\n\n return {\n googleAnalyticsId: nullify(row?.google_analytics_id),\n googleTagManagerId: nullify(row?.google_tag_manager_id),\n googleAdsId: nullify(row?.google_ads_id),\n metaPixelId: nullify(row?.meta_pixel_id),\n }\n },\n\n /**\n * Get the tenant's Mapbox **public** token (`pk.*`) for rendering maps in the\n * browser. Returns `{ publicToken: null }` when not configured. The Mapbox\n * **secret** token is never exposed by the CMS — read it from your own\n * environment variables.\n *\n * Caching mirrors `getTrackingConfig()`: revalidated hourly by default and\n * tagged with `MAPBOX_CONFIG_TAG`. Call `revalidateTag(MAPBOX_CONFIG_TAG)`\n * from a `settings.mapbox_updated` webhook for zero-lag updates.\n */\n async getMapboxConfig(options: MapboxConfigOptions = {}): Promise<MapboxConfig> {\n const { revalidate = 3600, tags = [MAPBOX_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=mapbox_public_token&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: { mapbox_public_token: string | null } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the null result so a transient CMS\n // outage never breaks map rendering on the tenant site.\n }\n\n return { publicToken: nullify(row?.mapbox_public_token) }\n },\n }\n}\n\n/**\n * Cache tag applied to `getTrackingConfig()` fetches on Next.js. Call\n * `revalidateTag(TRACKING_CONFIG_TAG)` from a webhook handler on the tenant\n * site to make tracking-ID changes take effect immediately rather than\n * waiting for the next revalidation interval.\n */\nexport const TRACKING_CONFIG_TAG = \"cms:tracking-config\"\n\nexport interface TrackingConfigOptions {\n /**\n * Cache lifetime for the underlying fetch on Next.js, in seconds.\n * Defaults to 3600 (one hour). Set to `0` to disable caching, or `false`\n * to cache indefinitely until the tag is revalidated. Ignored outside\n * Next.js runtimes.\n */\n revalidate?: number | false\n /**\n * Cache tags for the underlying fetch on Next.js. Defaults to\n * `[TRACKING_CONFIG_TAG]`. Override to namespace by tenant if you share a\n * single Next.js process across multiple tenants (uncommon).\n */\n tags?: string[]\n}\n\n/**\n * Cache tag applied to `getMapboxConfig()` fetches on Next.js. Call\n * `revalidateTag(MAPBOX_CONFIG_TAG)` from a `settings.mapbox_updated` webhook\n * handler so public-token changes take effect immediately.\n */\nexport const MAPBOX_CONFIG_TAG = \"cms:mapbox-config\"\n\n/**\n * Cache tag for a singleton \"page\" content type. Wrap `getSingleton(slug)` in\n * `unstable_cache` tagged with `singletonTag(slug)`, then call\n * `revalidateTag(singletonTag(slug))` from the CMS `content.updated` webhook\n * (the webhook payload's `cache_tags` already include this value).\n */\nexport function singletonTag(slug: string): string {\n return `cms:singleton:${slug}`\n}\n\nexport interface MapboxConfigOptions {\n /** Cache lifetime in seconds on Next.js. Defaults to 3600. `0` disables caching, `false` caches until tag revalidation. Ignored outside Next.js. */\n revalidate?: number | false\n /** Cache tags applied to the fetch. Defaults to `[MAPBOX_CONFIG_TAG]`. */\n tags?: string[]\n}\n\nexport interface MapboxConfig {\n /** The tenant's Mapbox public token (`pk.*`), or null when not configured. */\n publicToken: string | null\n}\n\nfunction nullify(v: string | null | undefined): string | null {\n if (!v) return null\n const trimmed = v.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nexport interface TrackingConfig {\n googleAnalyticsId: string | null\n googleTagManagerId: string | null\n googleAdsId: string | null\n metaPixelId: string | null\n}\n\n/**\n * Creates a new Supabase client that includes the `x-cms-api-key`\n * header in every request, using the same URL and key as the original.\n */\nfunction withApiKey(supabase: SupabaseClient, apiKey: string) {\n // Extract URL and key from the existing client\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n return createSupabaseClient(supabaseUrl, supabaseKey, {\n global: {\n headers: {\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n },\n })\n}\n","import { CMS_CLIENT_VERSION } from \"./version\"\n\n/**\n * Reports the running SDK version to the CMS so the Super Admin UI can show\n * which client version each tenant site is on.\n *\n * Day-granular and process-local: at most one POST per (api key + day) per\n * Node process. Calls from browser code are ignored — the API key would be\n * exposed and the data is redundant with server-side reports.\n *\n * Fire-and-forget. Failures are silent — telemetry must never break a render.\n */\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\ninterface ReportRecord {\n date: string // YYYY-MM-DD\n version: string\n}\n\nconst reported = new Map<string, ReportRecord>()\n\nfunction todayKey(): string {\n return new Date().toISOString().slice(0, 10)\n}\n\nexport function reportClientVersion(apiKey: string, appUrl?: string): void {\n // Skip in browser contexts — server-side calls already cover the tenant.\n if (typeof window !== \"undefined\") return\n if (!apiKey) return\n\n const today = todayKey()\n const last = reported.get(apiKey)\n if (last && last.date === today && last.version === CMS_CLIENT_VERSION) return\n\n // Optimistically mark as reported so concurrent calls don't all fire. If the\n // request fails we'll retry tomorrow — that's acceptable for telemetry.\n reported.set(apiKey, { date: today, version: CMS_CLIENT_VERSION })\n\n const envAppUrl =\n typeof process !== \"undefined\" ? process.env?.NEXT_PUBLIC_CMS_URL : undefined\n const base = (appUrl ?? envAppUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n const url = `${base}/api/client-telemetry`\n\n // Fire and forget. Use a hand-rolled then() chain rather than async/await so\n // we don't accidentally surface an unhandled rejection.\n void fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n body: JSON.stringify({\n api_key: apiKey,\n version: CMS_CLIENT_VERSION,\n }),\n }).catch(() => {\n // Allow a retry on the next call by clearing the optimistic record.\n reported.delete(apiKey)\n })\n}\n","import type { EmbedValue } from \"./types\"\n\nfunction toCssAspectRatio(ratio: string): string {\n const parts = ratio.split(\":\")\n if (parts.length !== 2) return \"16/9\"\n const w = parseFloat(parts[0])\n const h = parseFloat(parts[1])\n if (!w || !h || w <= 0 || h <= 0) return \"16/9\"\n return `${w}/${h}`\n}\n\n/**\n * Generate responsive iframe HTML for an embed field value.\n * Returns an empty string if the value is invalid or the URL is not HTTPS.\n */\nexport function getEmbedHtml(value: unknown): string {\n if (!value || typeof value !== \"object\") return \"\"\n const embed = value as EmbedValue\n if (!embed.url || !embed.url.startsWith(\"https://\")) return \"\"\n\n const width = embed.width || \"100%\"\n const aspectRatio = toCssAspectRatio(embed.aspect_ratio || \"16:9\")\n\n return `<div style=\"position:relative;width:${width};aspect-ratio:${aspectRatio}\"><iframe src=\"${embed.url}\" style=\"position:absolute;inset:0;width:100%;height:100%\" frameborder=\"0\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\" allowfullscreen loading=\"lazy\"></iframe></div>`\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n Product,\n ProductCategory,\n ProductQueryOptions,\n CreateOrderParams,\n CreateOrderResult,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\nexport interface ShopClientOptions {\n /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */\n apiKey: string\n /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */\n appUrl?: string\n}\n\n/**\n * Creates a typed client for the eCommerce REST API (products, categories, orders).\n *\n * Unlike `createCmsClient`, the shop client talks to the CMS REST endpoints\n * (`/api/products`, `/api/product-categories`, `/api/orders/create`) rather than\n * Supabase directly — it doesn't need the `supabase` argument, but accepts it\n * for API symmetry with the rest of the SDK.\n *\n * Usage:\n * ```ts\n * const shop = createShopClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const products = await shop.getProducts({ category: \"electronics\", limit: 20 })\n * ```\n */\nexport function createShopClient(\n _supabase: SupabaseClient,\n options: ShopClientOptions\n) {\n const { apiKey } = options\n const appUrl = (options.appUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n function authHeaders(): HeadersInit {\n return {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n }\n }\n\n async function getJson<T>(path: string): Promise<T> {\n const res = await fetch(`${appUrl}${path}`, {\n headers: authHeaders(),\n // Caller controls Next.js caching by wrapping the call site.\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(\n body.error ?? `Shop request failed (${res.status}): ${path}`\n )\n }\n return res.json() as Promise<T>\n }\n\n return {\n /**\n * List published products. Includes nested `variants` and `options`.\n *\n * `category` filters by category slug (matches the FK `category_id`,\n * with a fallback to the legacy `category` text column).\n */\n async getProducts(queryOptions: ProductQueryOptions = {}): Promise<Product[]> {\n const params = new URLSearchParams()\n if (queryOptions.category) params.set(\"category\", queryOptions.category)\n if (queryOptions.tags?.length) params.set(\"tags\", queryOptions.tags.join(\",\"))\n if (queryOptions.limit) params.set(\"limit\", String(queryOptions.limit))\n if (queryOptions.offset) params.set(\"offset\", String(queryOptions.offset))\n if (queryOptions.sort) params.set(\"sort\", queryOptions.sort)\n if (queryOptions.order) params.set(\"order\", queryOptions.order)\n\n const qs = params.toString()\n const { products } = await getJson<{ products: Product[] }>(\n `/api/products${qs ? `?${qs}` : \"\"}`\n )\n return products ?? []\n },\n\n /**\n * Get a single published product by slug. Returns null if not found.\n * Includes nested `variants` and `options`.\n */\n async getProductBySlug(slug: string): Promise<Product | null> {\n const res = await fetch(`${appUrl}/api/products/${encodeURIComponent(slug)}`, {\n headers: authHeaders(),\n })\n if (res.status === 404) return null\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? `Failed to fetch product ${slug}`)\n }\n const { product } = (await res.json()) as { product: Product }\n return product ?? null\n },\n\n /**\n * List product categories for the tenant, ordered by sort_order then name.\n */\n async getCategories(): Promise<ProductCategory[]> {\n const { categories } = await getJson<{ categories: ProductCategory[] }>(\n `/api/product-categories`\n )\n return categories ?? []\n },\n\n /**\n * Get a single category by slug. Returns null if not found.\n */\n async getCategoryBySlug(slug: string): Promise<ProductCategory | null> {\n const all = await this.getCategories()\n return all.find((c) => c.slug === slug) ?? null\n },\n\n /**\n * Create a pending order and return a Stripe PaymentIntent client_secret\n * to confirm payment client-side.\n *\n * Stripe must be configured for the tenant; eCommerce must be enabled on\n * their billing plan. Validates stock for tracked variants and applies\n * any discount code before creating the PaymentIntent.\n */\n async createOrder(params: CreateOrderParams): Promise<CreateOrderResult> {\n const res = await fetch(`${appUrl}/api/orders/create`, {\n method: \"POST\",\n headers: authHeaders(),\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? \"Order creation failed\")\n }\n return res.json() as Promise<CreateOrderResult>\n },\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport { reportClientVersion } from \"./telemetry\"\n\nexport type EventStatus = \"draft\" | \"published\" | \"archived\"\nexport type BookingStatus = \"pending\" | \"confirmed\" | \"cancelled\" | \"refunded\"\n\nexport interface CmsEvent {\n id: string\n tenant_id: string\n title: string\n slug: string\n description: string | null\n short_description: string | null\n status: EventStatus\n start_at: string\n end_at: string | null\n venue_name: string | null\n venue_address: string | null\n hero_image: string | null\n gallery: string[]\n tags: string[]\n seo_title: string | null\n seo_description: string | null\n metadata: Record<string, unknown>\n sort_order: number\n published_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CmsTicketTier {\n id: string\n event_id: string\n tenant_id: string\n name: string\n description: string | null\n price_cents: number\n capacity: number | null\n sold_count: number\n sales_start_at: string | null\n sales_end_at: string | null\n is_active: boolean\n sort_order: number\n}\n\nexport interface EventWithTiers extends CmsEvent {\n tiers: CmsTicketTier[]\n}\n\nexport interface EventQueryOptions {\n /** Only include events with start_at >= now. Default false. */\n upcomingOnly?: boolean\n tag?: string\n limit?: number\n offset?: number\n sort?: \"start_at\" | \"sort_order\" | \"created_at\"\n order?: \"asc\" | \"desc\"\n}\n\nexport interface CreateBookingParams {\n event_slug: string\n ticket_tier_id?: string\n customer_email: string\n customer_name?: string\n customer_phone?: string\n quantity?: number\n success_url?: string\n cancel_url?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface CreateBookingResult {\n booking_id: string\n booking_number: string\n status: \"pending\" | \"confirmed\"\n /** Redirect the browser here for paid bookings. */\n checkout_url?: string\n /** Present on free bookings — used for attendance QR display. */\n qr_token?: string\n}\n\nexport function createEventsClient(\n supabase: SupabaseClient,\n options: { apiKey: string; appUrl?: string }\n) {\n const { apiKey, appUrl } = options\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n async function getEvents(\n queryOptions?: EventQueryOptions\n ): Promise<EventWithTiers[]> {\n let query = supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"status\", \"published\")\n .order(queryOptions?.sort ?? \"start_at\", {\n ascending: (queryOptions?.order ?? \"asc\") === \"asc\",\n })\n\n if (queryOptions?.upcomingOnly) {\n query = query.gte(\"start_at\", new Date().toISOString())\n }\n if (queryOptions?.tag) {\n query = query.contains(\"tags\", [queryOptions.tag])\n }\n if (queryOptions?.limit) {\n query = query.limit(queryOptions.limit)\n }\n if (queryOptions?.offset) {\n query = query.range(\n queryOptions.offset,\n queryOptions.offset + (queryOptions.limit ?? 50) - 1\n )\n }\n\n const { data } = await query\n return (data ?? []) as EventWithTiers[]\n }\n\n async function getEventBySlug(slug: string): Promise<EventWithTiers | null> {\n const { data } = await supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"slug\", slug)\n .eq(\"status\", \"published\")\n .single()\n return (data as EventWithTiers) ?? null\n }\n\n async function createBooking(\n params: CreateBookingParams\n ): Promise<CreateBookingResult> {\n const baseUrl = appUrl ?? \"\"\n const res = await fetch(`${baseUrl}/api/bookings/create`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const err = await res\n .json()\n .catch(() => ({ error: \"Booking creation failed\" }))\n throw new Error(err.error ?? \"Booking creation failed\")\n }\n return res.json() as Promise<CreateBookingResult>\n }\n\n return { getEvents, getEventBySlug, createBooking }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type { GeocodeOptions, GeocodeResult } from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\nexport interface MapsClientOptions {\n /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */\n apiKey: string\n /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */\n appUrl?: string\n}\n\n/**\n * Creates a typed client for Mapbox-backed helpers (forward geocoding, with\n * more to come). Like `createShopClient`, it talks to CMS REST endpoints rather\n * than Supabase directly — it doesn't need the `supabase` argument but accepts\n * it for API symmetry. The Mapbox call runs server-side with the tenant's\n * public token; the token is never exposed to the browser.\n *\n * ```ts\n * const maps = createMapsClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const [best] = await maps.geocodeAddress(\"12 Queen St, Auckland\")\n * ```\n */\nexport function createMapsClient(_supabase: SupabaseClient, options: MapsClientOptions) {\n const { apiKey } = options\n const appUrl = (options.appUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n return {\n /**\n * Forward-geocode an address string. Returns matches ordered by relevance\n * (`results[0]` is the best match), or [] when nothing matches. Throws on a\n * configuration or upstream error.\n */\n async geocodeAddress(query: string, options: GeocodeOptions = {}): Promise<GeocodeResult[]> {\n const q = query.trim()\n if (!q) throw new Error(\"geocodeAddress: query is required\")\n\n const params = new URLSearchParams({ q })\n if (options.limit != null) params.set(\"limit\", String(options.limit))\n if (options.country) params.set(\"country\", options.country)\n if (options.proximity) params.set(\"proximity\", `${options.proximity[0]},${options.proximity[1]}`)\n if (options.types) params.set(\"types\", options.types)\n if (options.language) params.set(\"language\", options.language)\n\n const res = await fetch(`${appUrl}/api/mapbox/geocode?${params.toString()}`, {\n headers: {\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n })\n if (!res.ok) {\n const body = (await res.json().catch(() => ({}))) as { error?: string }\n throw new Error(body.error ?? `Geocoding failed (${res.status})`)\n }\n const data = (await res.json()) as { results?: GeocodeResult[] }\n return data.results ?? []\n },\n }\n}\n","/**\n * Image helpers for CMS content.\n *\n * Images are already optimised (WebP, max 2400px) on upload.\n * No server-side transforms needed — serve originals directly.\n *\n * These functions are kept for backward compatibility but no longer\n * call Supabase image transformation endpoints.\n */\n\nexport interface ImageTransformOptions {\n width?: number\n height?: number\n quality?: number\n resize?: \"contain\" | \"cover\" | \"fill\"\n format?: \"origin\"\n}\n\n/**\n * Returns the image URL directly.\n *\n * Previously this converted URLs to use Supabase's /render/image/\n * transform endpoint, but images are now pre-optimised on upload\n * (WebP, max 2400px, quality 82) so transforms are unnecessary.\n *\n * The function is kept for backward compatibility — existing code\n * that calls getTransformUrl() will continue to work without changes.\n */\nexport function getTransformUrl(\n originalUrl: string,\n _options: ImageTransformOptions = {}\n): string {\n return originalUrl\n}\n\n/**\n * Returns a simple srcSet using the original image.\n *\n * Previously generated multiple transformed widths, but since images\n * are now pre-optimised WebP, a single source is sufficient.\n * Modern browsers handle responsive display efficiently with a\n * well-sized WebP source.\n */\nexport function getSrcSet(\n originalUrl: string,\n _widths: number[] = [],\n _quality = 80\n): string {\n return `${originalUrl} 2400w`\n}\n\n/**\n * Common image size presets — kept for backward compatibility.\n * Since images are pre-optimised, these are informational only.\n */\nexport const IMAGE_PRESETS = {\n thumbnail: { width: 150, height: 150, resize: \"cover\" as const, quality: 70 },\n card: { width: 400, height: 300, resize: \"cover\" as const, quality: 80 },\n hero: { width: 1200, height: 630, resize: \"cover\" as const, quality: 85 },\n og: { width: 1200, height: 630, resize: \"cover\" as const, quality: 90 },\n avatar: { width: 80, height: 80, resize: \"cover\" as const, quality: 75 },\n full: { width: 1920, resize: \"contain\" as const, quality: 85 },\n} as const\n","import type { DateGranularity } from \"./types\"\n\nexport interface ParsedPartialDate {\n granularity: DateGranularity\n /** 4-digit year — absent for `month` and `day_month`. */\n year?: number\n /** 1-12 — absent for `year`. */\n month?: number\n /** 1-31 — present only for `full` and `day_month`. */\n day?: number\n}\n\n/**\n * Parses a partial-ISO date string (as produced by a `date` field) into its parts.\n * Returns `null` if the string doesn't match a known granularity shape.\n */\nexport function parsePartialDate(value: string): ParsedPartialDate | null {\n if (!value) return null\n let m: RegExpExecArray | null\n if ((m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"full\", year: +m[1], month: +m[2], day: +m[3] }\n if ((m = /^(\\d{4})-(\\d{2})$/.exec(value)))\n return { granularity: \"month_year\", year: +m[1], month: +m[2] }\n if ((m = /^(\\d{4})$/.exec(value))) return { granularity: \"year\", year: +m[1] }\n if ((m = /^--(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"day_month\", month: +m[1], day: +m[2] }\n if ((m = /^--(\\d{2})$/.exec(value))) return { granularity: \"month\", month: +m[1] }\n return null\n}\n\nexport interface FormatPartialDateOptions {\n /** BCP 47 locale(s) passed to Intl.DateTimeFormat. Defaults to the runtime locale. */\n locale?: string | string[]\n /** Month rendering style. Defaults to `long` (e.g. \"May\"). */\n month?: \"long\" | \"short\" | \"narrow\" | \"numeric\" | \"2-digit\"\n}\n\n/**\n * Formats a partial-ISO date string for display, honouring the value's granularity\n * and locale-correct part ordering (e.g. \"12 May\" vs \"May 12\"). Returns the raw\n * string unchanged if it isn't a recognised partial date.\n */\nexport function formatPartialDate(value: string, options: FormatPartialDateOptions = {}): string {\n const parsed = parsePartialDate(value)\n if (!parsed) return value\n\n const { locale, month = \"long\" } = options\n const monthIndex = parsed.month ? parsed.month - 1 : 0\n\n switch (parsed.granularity) {\n case \"year\":\n return String(parsed.year)\n case \"month\":\n return new Intl.DateTimeFormat(locale, { month }).format(new Date(2000, monthIndex, 1))\n case \"month_year\":\n return new Intl.DateTimeFormat(locale, { month, year: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, 1)\n )\n case \"day_month\":\n return new Intl.DateTimeFormat(locale, { month, day: \"numeric\" }).format(\n new Date(2000, monthIndex, parsed.day!)\n )\n case \"full\":\n return new Intl.DateTimeFormat(locale, { year: \"numeric\", month, day: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, parsed.day!)\n )\n }\n}\n","/**\n * Helpers for verifying outbound webhooks fired by the CMS.\n *\n * The CMS POSTs JSON to subscriber URLs and signs the raw body with\n * HMAC-SHA256 using the shared secret you set in the Webhooks tab. The hex\n * digest arrives in the `X-CMS-Signature` header.\n *\n * Use Web Crypto so this works in Node, Edge, Deno, and Bun runtimes.\n */\n\nexport interface WebhookEventPayload {\n event: string\n tenant_id: string\n content_type_slug?: string\n content_item_id?: string\n slug?: string\n title?: string\n status?: string\n /** Stable identifier of the resource that changed (e.g. product id, flipbook id, integration provider). */\n resource_id?: string\n /**\n * Cache tags the receiver should invalidate. Use {@link revalidateAllTags}\n * to wire this through Next.js's `revalidateTag()` in one line.\n * All tags are namespaced with the `cms:` prefix.\n */\n cache_tags?: string[]\n /** Free-form bag for event-specific extras (e.g. provider name, change counts). */\n data?: Record<string, unknown>\n timestamp: string\n /** Commerce + custom events may attach extra top-level fields. */\n [key: string]: unknown\n}\n\n/**\n * Verify the HMAC-SHA256 signature on a webhook delivery.\n *\n * Pass the **raw** request body (not a parsed JSON object) — re-stringifying\n * a parsed body can change whitespace and invalidate the signature.\n *\n * Returns `true` when the signature matches in constant time, `false`\n * otherwise. Never throws on a bad signature; only throws if the\n * `crypto.subtle` API is unavailable in the runtime.\n *\n * @example\n * const raw = await req.text()\n * const sig = req.headers.get(\"x-cms-signature\")\n * if (!await verifyWebhookSignature(process.env.CMS_WEBHOOK_SECRET!, raw, sig)) {\n * return new Response(\"bad signature\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n */\nexport async function verifyWebhookSignature(\n secret: string,\n rawBody: string,\n signature: string | null | undefined\n): Promise<boolean> {\n if (!signature || !secret) return false\n\n const subtle = (globalThis.crypto && globalThis.crypto.subtle) || null\n if (!subtle) {\n throw new Error(\n \"verifyWebhookSignature requires the Web Crypto API (globalThis.crypto.subtle). \" +\n \"Available in Node 18+, all Edge runtimes, Deno, and Bun.\"\n )\n }\n\n const encoder = new TextEncoder()\n const key = await subtle.importKey(\n \"raw\",\n encoder.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"]\n )\n const sigBuffer = await subtle.sign(\"HMAC\", key, encoder.encode(rawBody))\n const expected = bufferToHex(sigBuffer)\n\n return timingSafeEqualHex(expected, signature.trim())\n}\n\n/**\n * The webhook event names the CMS can fire. Use as a discriminator on the\n * `event` field of {@link WebhookEventPayload}.\n *\n * Most receivers don't need to switch on the event name — every payload\n * carries a `cache_tags` array. Pass it to {@link revalidateAllTags} to\n * invalidate the right Next.js caches in one line.\n */\nexport const WEBHOOK_EVENTS = [\n // Content\n \"content.published\",\n \"content.unpublished\",\n \"content.updated\",\n \"content.deleted\",\n \"content_type.updated\",\n \"content_type.deleted\",\n // Settings (diffed — only fires when a relevant field actually changed)\n \"settings.tracking_updated\",\n \"settings.brand_updated\",\n \"settings.integration_updated\",\n \"settings.mapbox_updated\",\n // Commerce\n \"products.updated\",\n \"product_categories.updated\",\n \"ticket_tiers.updated\",\n \"membership_tiers.updated\",\n \"order.created\",\n \"order.paid\",\n \"order.payment_failed\",\n \"order.refunded\",\n \"order.shipped\",\n \"booking.confirmed\",\n \"inventory.low_stock\",\n // Site\n \"redirects.updated\",\n \"reviews.synced\",\n \"flipbook.ready\",\n] as const\n\nexport type WebhookEvent = (typeof WEBHOOK_EVENTS)[number]\n\n/**\n * Invalidate every cache tag listed in a webhook payload. Call this from your\n * receiver and most events will Just Work without per-event branching.\n *\n * Pass Next.js's `revalidateTag` (or any function with the same shape) — the\n * SDK has no peer dep on `next/cache`, so the import stays in your code.\n *\n * **Next 16 compatibility.** In Next 16, `revalidateTag(tag)` was made into\n * `revalidateTag(tag, profile)`, and calling it with one argument emits a\n * deprecation warning. The cache profile controls expiry — `\"default\"` and\n * `\"max\"` both have non-zero `expire` values and will **not** invalidate the\n * cache. Immediate invalidation requires `{ expire: 0 }`, which isn't\n * documented in the function reference. This helper always passes\n * `{ expire: 0 }` as the second argument, so it does the right thing on Next 16\n * and is silently ignored by Next 14/15.\n *\n * @example\n * import { revalidateTag } from \"next/cache\"\n * import { revalidateAllTags } from \"@distinctagency/cms-client\"\n *\n * export async function POST(req: Request) {\n * const raw = await req.text()\n * if (!await verifyWebhookSignature(SECRET, raw, req.headers.get(\"x-cms-signature\"))) {\n * return new Response(\"bad sig\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n * revalidateAllTags(payload, revalidateTag)\n * return Response.json({ ok: true })\n * }\n */\nexport function revalidateAllTags(\n payload: Pick<WebhookEventPayload, \"cache_tags\">,\n revalidateTag: (tag: string, profile: { expire?: number }) => unknown\n): string[] {\n const tags = payload.cache_tags\n if (!Array.isArray(tags) || tags.length === 0) return []\n const invalidated: string[] = []\n for (const tag of tags) {\n if (typeof tag !== \"string\" || tag.length === 0) continue\n revalidateTag(tag, { expire: 0 })\n invalidated.push(tag)\n }\n return invalidated\n}\n\nfunction bufferToHex(buf: ArrayBuffer): string {\n const bytes = new Uint8Array(buf)\n let out = \"\"\n for (let i = 0; i < bytes.length; i++) {\n out += bytes[i].toString(16).padStart(2, \"0\")\n }\n return out\n}\n\n/**\n * Constant-time equality check on two hex strings. Returns false fast when\n * lengths differ — the length itself is not secret.\n */\nfunction timingSafeEqualHex(a: string, b: string): boolean {\n if (a.length !== b.length) return false\n let mismatch = 0\n for (let i = 0; i < a.length; i++) {\n mismatch |= a.charCodeAt(i) ^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AChC,MAAI,MAAM;AACV,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,WAAO,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG;AAAA,EAC9C;AACA,SAAO;AACT;AAMA,SAAS,mBAAmB,GAAW,GAAoB;AACzD,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,MAAI,WAAW;AACf,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,gBAAY,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC9C;AACA,SAAO,aAAa;AACtB;","names":["options","query","data","error","createSupabaseClient","DEFAULT_APP_URL","DEFAULT_APP_URL","options"]}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var CMS_CLIENT_VERSION = "1.22.0";
2
+ var CMS_CLIENT_VERSION = "1.24.0";
3
3
 
4
4
  // src/queries.ts
5
5
  import { createClient as createSupabaseClient } from "@supabase/supabase-js";
@@ -175,6 +175,27 @@ function createCmsClient(supabase, options) {
175
175
  }
176
176
  return data;
177
177
  },
178
+ /**
179
+ * Get the single published item for a singleton content type ("page").
180
+ *
181
+ * A singleton content type owns exactly one item. Use this for editable
182
+ * page copy (hero text, section headings, etc.) stored in the CMS.
183
+ * Returns null when the singleton has no published item yet — callers
184
+ * should fall back to their hardcoded defaults in that case.
185
+ *
186
+ * Wrap this in `unstable_cache` with a `cms:singleton:<slug>` tag on the
187
+ * consuming site to cache it and revalidate via the CMS webhook.
188
+ */
189
+ async getSingleton(contentTypeSlug) {
190
+ const contentTypeId = await getContentTypeId(contentTypeSlug);
191
+ const { data, error } = await client.from("content_items").select("*").eq("content_type_id", contentTypeId).eq("status", "published").order("updated_at", { ascending: false }).limit(1).maybeSingle();
192
+ if (error) {
193
+ throw new Error(
194
+ `Failed to fetch singleton ${contentTypeSlug}: ${error.message}`
195
+ );
196
+ }
197
+ return data ?? null;
198
+ },
178
199
  /**
179
200
  * Get a content type definition (including its field schema).
180
201
  */
@@ -377,6 +398,9 @@ function createCmsClient(supabase, options) {
377
398
  }
378
399
  var TRACKING_CONFIG_TAG = "cms:tracking-config";
379
400
  var MAPBOX_CONFIG_TAG = "cms:mapbox-config";
401
+ function singletonTag(slug) {
402
+ return `cms:singleton:${slug}`;
403
+ }
380
404
  function nullify(v) {
381
405
  if (!v) return null;
382
406
  const trimmed = v.trim();
@@ -561,6 +585,43 @@ function createEventsClient(supabase, options) {
561
585
  return { getEvents, getEventBySlug, createBooking };
562
586
  }
563
587
 
588
+ // src/maps.ts
589
+ var DEFAULT_APP_URL3 = "https://cms.distinctstudio.co.nz";
590
+ function createMapsClient(_supabase, options) {
591
+ const { apiKey } = options;
592
+ const appUrl = (options.appUrl ?? DEFAULT_APP_URL3).replace(/\/$/, "");
593
+ reportClientVersion(apiKey, appUrl);
594
+ return {
595
+ /**
596
+ * Forward-geocode an address string. Returns matches ordered by relevance
597
+ * (`results[0]` is the best match), or [] when nothing matches. Throws on a
598
+ * configuration or upstream error.
599
+ */
600
+ async geocodeAddress(query, options2 = {}) {
601
+ const q = query.trim();
602
+ if (!q) throw new Error("geocodeAddress: query is required");
603
+ const params = new URLSearchParams({ q });
604
+ if (options2.limit != null) params.set("limit", String(options2.limit));
605
+ if (options2.country) params.set("country", options2.country);
606
+ if (options2.proximity) params.set("proximity", `${options2.proximity[0]},${options2.proximity[1]}`);
607
+ if (options2.types) params.set("types", options2.types);
608
+ if (options2.language) params.set("language", options2.language);
609
+ const res = await fetch(`${appUrl}/api/mapbox/geocode?${params.toString()}`, {
610
+ headers: {
611
+ "x-cms-api-key": apiKey,
612
+ "x-cms-client-version": CMS_CLIENT_VERSION
613
+ }
614
+ });
615
+ if (!res.ok) {
616
+ const body = await res.json().catch(() => ({}));
617
+ throw new Error(body.error ?? `Geocoding failed (${res.status})`);
618
+ }
619
+ const data = await res.json();
620
+ return data.results ?? [];
621
+ }
622
+ };
623
+ }
624
+
564
625
  // src/cdn.ts
565
626
  function getTransformUrl(originalUrl, _options = {}) {
566
627
  return originalUrl;
@@ -702,6 +763,7 @@ export {
702
763
  WEBHOOK_EVENTS,
703
764
  createCmsClient,
704
765
  createEventsClient,
766
+ createMapsClient,
705
767
  createShopClient,
706
768
  formatPartialDate,
707
769
  getEmbedHtml,
@@ -709,6 +771,7 @@ export {
709
771
  getTransformUrl,
710
772
  parsePartialDate,
711
773
  revalidateAllTags,
774
+ singletonTag,
712
775
  verifyWebhookSignature
713
776
  };
714
777
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/version.ts","../src/queries.ts","../src/telemetry.ts","../src/embed.ts","../src/shop.ts","../src/events.ts","../src/cdn.ts","../src/date.ts","../src/webhooks.ts"],"sourcesContent":["/**\n * The version of @distinctagency/cms-client embedded in this build.\n *\n * Bump this in lock-step with package.json — the value is read by the SDK to\n * report installed-version telemetry and to send `x-cms-client-version` on\n * outgoing requests.\n */\nexport const CMS_CLIENT_VERSION = \"1.22.0\"\n","import { createClient as createSupabaseClient } from \"@supabase/supabase-js\"\nimport type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n CmsClientOptions,\n ContentItem,\n ContentQueryOptions,\n ContentType,\n GoogleReview,\n ReviewQueryOptions,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\n/**\n * Creates a CMS query client authenticated with a tenant API key.\n *\n * Usage:\n * ```ts\n * const cms = createCmsClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const events = await cms.getContentItems('events', { status: 'published' })\n * ```\n *\n * The API key is sent as an `x-cms-api-key` header on every request.\n * Supabase RLS policies validate it against the tenant's stored key.\n */\nexport function createCmsClient(\n supabase: SupabaseClient,\n options: CmsClientOptions\n) {\n const { apiKey } = options\n\n // Create a new Supabase client with the API key header injected globally\n const client = withApiKey(supabase, apiKey) as SupabaseClient\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, options.appUrl)\n\n /** Resolve the tenant ID from the API key (cached per request) */\n let tenantIdCache: string | null = null\n\n async function getTenantId(): Promise<string> {\n if (tenantIdCache) return tenantIdCache\n\n const { data, error } = await client\n .from(\"tenants\")\n .select(\"id\")\n .single()\n\n if (error || !data) {\n throw new Error(\n \"Invalid CMS API key — no tenant found. Check your apiKey.\"\n )\n }\n\n tenantIdCache = data.id\n return data.id\n }\n\n /** Resolve a content type from its slug (cached) */\n const contentTypeCache = new Map<string, ContentType>()\n\n async function getContentTypeBySlug(contentTypeSlug: string): Promise<ContentType> {\n if (contentTypeCache.has(contentTypeSlug)) return contentTypeCache.get(contentTypeSlug)!\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n const ct = data as ContentType\n contentTypeCache.set(contentTypeSlug, ct)\n return ct\n }\n\n async function getContentTypeId(contentTypeSlug: string): Promise<string> {\n const ct = await getContentTypeBySlug(contentTypeSlug)\n return ct.id\n }\n\n /** Check if a member token has access to a gated content type */\n async function checkMemberAccess(\n contentType: ContentType,\n memberToken?: string\n ): Promise<{ allowed: boolean; memberTierId: string | null }> {\n const requiredTierId = contentType.required_membership_tier_id\n if (!requiredTierId) return { allowed: true, memberTierId: null } // Public\n\n if (!memberToken) return { allowed: false, memberTierId: null } // Gated but no token\n\n // Verify the member's token and check their tier\n const { data: session } = await client\n .from(\"member_sessions\")\n .select(\"member_id\")\n .eq(\"token_hash\", memberToken) // Note: caller should hash the token\n .single()\n\n if (!session) return { allowed: false, memberTierId: null }\n\n const { data: member } = await client\n .from(\"members\")\n .select(\"membership_tier_id, status\")\n .eq(\"id\", session.member_id)\n .single()\n\n if (!member || member.status !== \"active\") return { allowed: false, memberTierId: null }\n\n // Check if the member's tier matches (or exceeds) the required tier\n // For now: exact match or the member has the required tier\n return {\n allowed: member.membership_tier_id === requiredTierId,\n memberTierId: member.membership_tier_id as string | null,\n }\n }\n\n async function getFlipbook(id: string): Promise<import(\"./types\").FlipbookPublic | null> {\n const { data, error } = await client\n .from(\"flipbooks\")\n .select(\"id, title, page_count, status, manifest, download_enabled, tenant_id\")\n .eq(\"id\", id)\n .single()\n if (error || !data) return null\n\n const manifest = data.manifest as\n | { pages: Array<{ image: string; thumb: string; w: number; h: number }>; toc: Array<{ title: string; page: number }> }\n | null\n if (!manifest) {\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? 0,\n status: data.status as \"pending_upload\" | \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: [],\n toc: [],\n download_url: null,\n }\n }\n\n // Browser-safe env lookup via globalThis. The client package builds without\n // @types/node so referring to `process` directly fails the dts build; reading\n // through globalThis sidesteps that and works in every JS environment that\n // matters (Node, browsers, edge runtimes).\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process\n const cdnBase = proc?.env?.NEXT_PUBLIC_R2_PUBLIC_URL ?? \"https://cdn.distinctstudio.co.nz\"\n const prefix = `flipbooks/${data.tenant_id as string}/${data.id as string}/`\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? manifest.pages.length,\n status: data.status as \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: manifest.pages.map((p) => ({\n url: `${cdnBase}/${prefix}${p.image}`,\n thumb_url: `${cdnBase}/${prefix}${p.thumb}`,\n w: p.w,\n h: p.h,\n })),\n toc: manifest.toc,\n download_url: data.download_enabled\n ? `${options.appUrl ?? \"\"}/api/flipbooks/${data.id as string}/download`\n : null,\n }\n }\n\n return {\n /**\n * List content items for a content type.\n * Defaults to published items ordered by most recent.\n */\n async getContentItems(\n contentTypeSlug: string,\n options: ContentQueryOptions = {}\n ): Promise<(ContentItem & { locked?: boolean })[]> {\n const contentType = await getContentTypeBySlug(contentTypeSlug)\n\n const {\n status = \"published\",\n orderBy = \"published_at\",\n orderDirection = \"desc\",\n limit = 100,\n offset = 0,\n memberToken,\n } = options\n\n // Check membership access\n const access = await checkMemberAccess(contentType, memberToken)\n\n // If gated and no access, check gating mode\n if (!access.allowed && contentType.required_membership_tier_id) {\n // Get tenant settings for gating mode\n const tenantId = await getTenantId()\n const { data: settings } = await client\n .from(\"tenant_settings\")\n .select(\"membership_gating_mode\")\n .eq(\"tenant_id\", tenantId)\n .single()\n\n const mode = (settings?.membership_gating_mode as string) ?? \"teaser\"\n\n if (mode === \"hide\") {\n return [] // Hide: return nothing\n }\n\n // Teaser mode: return items with locked flag, no body/data\n let query = client\n .from(\"content_items\")\n .select(\"id, title, slug, status, excerpt, seo_title, seo_description, featured_image, published_at, created_at, updated_at\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) query = query.eq(\"status\", status)\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n if (error) throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n\n return (data ?? []).map((item) => ({\n ...item,\n data: {},\n locked: true,\n })) as (ContentItem & { locked: boolean })[]\n }\n\n // Full access\n let query = client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n }\n\n return (data ?? []) as ContentItem[]\n },\n\n /**\n * Get a single content item by its slug.\n * Returns null if not found.\n */\n async getContentItemBySlug(\n contentTypeSlug: string,\n itemSlug: string\n ): Promise<ContentItem | null> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"slug\", itemSlug)\n .single()\n\n if (error) {\n if (error.code === \"PGRST116\") return null // not found\n throw new Error(\n `Failed to fetch ${contentTypeSlug}/${itemSlug}: ${error.message}`\n )\n }\n\n return data as ContentItem\n },\n\n /**\n * Get a content type definition (including its field schema).\n */\n async getContentType(contentTypeSlug: string): Promise<ContentType> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n return data as ContentType\n },\n\n /**\n * Get all slugs for a content type (for generateStaticParams).\n */\n async getAllSlugs(\n contentTypeSlug: string\n ): Promise<{ slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"slug\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"status\", \"published\")\n\n if (error) {\n throw new Error(\n `Failed to fetch slugs for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { slug: string }[]\n },\n\n /**\n * List all content types for this tenant.\n */\n async getContentTypes(): Promise<ContentType[]> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .order(\"name\")\n\n if (error) {\n throw new Error(`Failed to fetch content types: ${error.message}`)\n }\n\n return (data ?? []) as ContentType[]\n },\n\n /**\n * Get all slug redirects for a content type.\n * Use in next.config.js redirects() or middleware for 301s.\n * Returns: [{ old_slug, new_slug }, ...]\n */\n async getRedirects(\n contentTypeSlug: string\n ): Promise<{ old_slug: string; new_slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"slug_redirects\")\n .select(\"old_slug, new_slug\")\n .eq(\"content_type_id\", contentTypeId)\n\n if (error) {\n throw new Error(\n `Failed to fetch redirects for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { old_slug: string; new_slug: string }[]\n },\n\n /**\n * Get all custom path redirects for this tenant.\n * Use alongside getRedirects() in next.config.ts for full redirect coverage.\n */\n async getCustomRedirects(): Promise<\n { source_path: string; destination_path: string; permanent: boolean }[]\n > {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"custom_redirects\")\n .select(\"source_path, destination_path, permanent\")\n .eq(\"tenant_id\", tenantId)\n\n if (error) {\n throw new Error(`Failed to fetch custom redirects: ${error.message}`)\n }\n\n return (data ?? []) as {\n source_path: string\n destination_path: string\n permanent: boolean\n }[]\n },\n\n /**\n * Get form submissions for a specific form.\n * Useful for displaying testimonials, reviews, etc.\n */\n async getFormSubmissions(\n formSlug: string,\n options: { status?: string; limit?: number; offset?: number } = {}\n ): Promise<Record<string, unknown>[]> {\n const tenantId = await getTenantId()\n\n const { data: form } = await client\n .from(\"forms\")\n .select(\"id\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n if (!form) return []\n\n const { limit = 50, offset = 0, status } = options\n\n let query = client\n .from(\"form_submissions\")\n .select(\"*\")\n .eq(\"form_id\", form.id)\n .eq(\"is_spam\", false)\n .order(\"created_at\", { ascending: false })\n .range(offset, offset + limit - 1)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n const { data } = await query\n return (data ?? []) as Record<string, unknown>[]\n },\n\n /**\n * Get a form configuration by slug.\n */\n async getForm(\n formSlug: string\n ): Promise<Record<string, unknown> | null> {\n const tenantId = await getTenantId()\n\n const { data } = await client\n .from(\"forms\")\n .select(\"id, name, slug, description, is_active\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n return data as Record<string, unknown> | null\n },\n\n /**\n * Get a flipbook by ID, including CDN-resolved page image URLs.\n * Returns null if not found or manifest not yet ready.\n */\n getFlipbook,\n\n /**\n * Get Google Reviews for this tenant.\n * Defaults to approved reviews ordered by most recent.\n */\n async getReviews(\n options: ReviewQueryOptions = {}\n ): Promise<GoogleReview[]> {\n const tenantId = await getTenantId()\n\n const {\n status = \"approved\",\n minRating,\n limit = 50,\n offset = 0,\n orderBy = \"review_timestamp\",\n orderDirection = \"desc\",\n } = options\n\n let query = client\n .from(\"google_reviews\")\n .select(\"id, author_name, author_photo_url, rating, text, review_timestamp\")\n .eq(\"tenant_id\", tenantId)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n if (minRating) {\n query = query.gte(\"rating\", minRating)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch reviews: ${error.message}`)\n }\n\n return (data ?? []) as GoogleReview[]\n },\n\n /**\n * Get the tenant's third-party tracking IDs (Google Analytics, Google Tag Manager, Meta Pixel).\n * Each value is null when not configured. These IDs are public and safe to render in HTML.\n *\n * On Next.js, the result is cached and revalidated every hour by default\n * (`revalidate: 3600`) and tagged with `TRACKING_CONFIG_TAG`. Tenant sites\n * that want zero-lag updates can call `revalidateTag(TRACKING_CONFIG_TAG)`\n * from a webhook. Pass `revalidate: 0` to disable caching, `revalidate: false`\n * to cache indefinitely (tag-only invalidation), or any positive integer\n * (seconds) to override the interval. Outside Next.js the cache hints are\n * silently ignored — every call hits the network.\n */\n async getTrackingConfig(options: TrackingConfigOptions = {}): Promise<TrackingConfig> {\n const { revalidate = 3600, tags = [TRACKING_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n // Direct PostgREST fetch (instead of going through supabase-js) so that\n // Next.js sees the request and applies its `next` cache options. RLS\n // restricts the result to the tenant matching `x-cms-api-key`, so no\n // explicit tenant_id filter is needed.\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=google_analytics_id,google_tag_manager_id,google_ads_id,meta_pixel_id&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: {\n google_analytics_id: string | null\n google_tag_manager_id: string | null\n google_ads_id: string | null\n meta_pixel_id: string | null\n } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the all-null result so a transient\n // outage on the CMS never breaks page renders on the tenant site.\n }\n\n return {\n googleAnalyticsId: nullify(row?.google_analytics_id),\n googleTagManagerId: nullify(row?.google_tag_manager_id),\n googleAdsId: nullify(row?.google_ads_id),\n metaPixelId: nullify(row?.meta_pixel_id),\n }\n },\n\n /**\n * Get the tenant's Mapbox **public** token (`pk.*`) for rendering maps in the\n * browser. Returns `{ publicToken: null }` when not configured. The Mapbox\n * **secret** token is never exposed by the CMS — read it from your own\n * environment variables.\n *\n * Caching mirrors `getTrackingConfig()`: revalidated hourly by default and\n * tagged with `MAPBOX_CONFIG_TAG`. Call `revalidateTag(MAPBOX_CONFIG_TAG)`\n * from a `settings.mapbox_updated` webhook for zero-lag updates.\n */\n async getMapboxConfig(options: MapboxConfigOptions = {}): Promise<MapboxConfig> {\n const { revalidate = 3600, tags = [MAPBOX_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=mapbox_public_token&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: { mapbox_public_token: string | null } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the null result so a transient CMS\n // outage never breaks map rendering on the tenant site.\n }\n\n return { publicToken: nullify(row?.mapbox_public_token) }\n },\n }\n}\n\n/**\n * Cache tag applied to `getTrackingConfig()` fetches on Next.js. Call\n * `revalidateTag(TRACKING_CONFIG_TAG)` from a webhook handler on the tenant\n * site to make tracking-ID changes take effect immediately rather than\n * waiting for the next revalidation interval.\n */\nexport const TRACKING_CONFIG_TAG = \"cms:tracking-config\"\n\nexport interface TrackingConfigOptions {\n /**\n * Cache lifetime for the underlying fetch on Next.js, in seconds.\n * Defaults to 3600 (one hour). Set to `0` to disable caching, or `false`\n * to cache indefinitely until the tag is revalidated. Ignored outside\n * Next.js runtimes.\n */\n revalidate?: number | false\n /**\n * Cache tags for the underlying fetch on Next.js. Defaults to\n * `[TRACKING_CONFIG_TAG]`. Override to namespace by tenant if you share a\n * single Next.js process across multiple tenants (uncommon).\n */\n tags?: string[]\n}\n\n/**\n * Cache tag applied to `getMapboxConfig()` fetches on Next.js. Call\n * `revalidateTag(MAPBOX_CONFIG_TAG)` from a `settings.mapbox_updated` webhook\n * handler so public-token changes take effect immediately.\n */\nexport const MAPBOX_CONFIG_TAG = \"cms:mapbox-config\"\n\nexport interface MapboxConfigOptions {\n /** Cache lifetime in seconds on Next.js. Defaults to 3600. `0` disables caching, `false` caches until tag revalidation. Ignored outside Next.js. */\n revalidate?: number | false\n /** Cache tags applied to the fetch. Defaults to `[MAPBOX_CONFIG_TAG]`. */\n tags?: string[]\n}\n\nexport interface MapboxConfig {\n /** The tenant's Mapbox public token (`pk.*`), or null when not configured. */\n publicToken: string | null\n}\n\nfunction nullify(v: string | null | undefined): string | null {\n if (!v) return null\n const trimmed = v.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nexport interface TrackingConfig {\n googleAnalyticsId: string | null\n googleTagManagerId: string | null\n googleAdsId: string | null\n metaPixelId: string | null\n}\n\n/**\n * Creates a new Supabase client that includes the `x-cms-api-key`\n * header in every request, using the same URL and key as the original.\n */\nfunction withApiKey(supabase: SupabaseClient, apiKey: string) {\n // Extract URL and key from the existing client\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n return createSupabaseClient(supabaseUrl, supabaseKey, {\n global: {\n headers: {\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n },\n })\n}\n","import { CMS_CLIENT_VERSION } from \"./version\"\n\n/**\n * Reports the running SDK version to the CMS so the Super Admin UI can show\n * which client version each tenant site is on.\n *\n * Day-granular and process-local: at most one POST per (api key + day) per\n * Node process. Calls from browser code are ignored — the API key would be\n * exposed and the data is redundant with server-side reports.\n *\n * Fire-and-forget. Failures are silent — telemetry must never break a render.\n */\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\ninterface ReportRecord {\n date: string // YYYY-MM-DD\n version: string\n}\n\nconst reported = new Map<string, ReportRecord>()\n\nfunction todayKey(): string {\n return new Date().toISOString().slice(0, 10)\n}\n\nexport function reportClientVersion(apiKey: string, appUrl?: string): void {\n // Skip in browser contexts — server-side calls already cover the tenant.\n if (typeof window !== \"undefined\") return\n if (!apiKey) return\n\n const today = todayKey()\n const last = reported.get(apiKey)\n if (last && last.date === today && last.version === CMS_CLIENT_VERSION) return\n\n // Optimistically mark as reported so concurrent calls don't all fire. If the\n // request fails we'll retry tomorrow — that's acceptable for telemetry.\n reported.set(apiKey, { date: today, version: CMS_CLIENT_VERSION })\n\n const envAppUrl =\n typeof process !== \"undefined\" ? process.env?.NEXT_PUBLIC_CMS_URL : undefined\n const base = (appUrl ?? envAppUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n const url = `${base}/api/client-telemetry`\n\n // Fire and forget. Use a hand-rolled then() chain rather than async/await so\n // we don't accidentally surface an unhandled rejection.\n void fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n body: JSON.stringify({\n api_key: apiKey,\n version: CMS_CLIENT_VERSION,\n }),\n }).catch(() => {\n // Allow a retry on the next call by clearing the optimistic record.\n reported.delete(apiKey)\n })\n}\n","import type { EmbedValue } from \"./types\"\n\nfunction toCssAspectRatio(ratio: string): string {\n const parts = ratio.split(\":\")\n if (parts.length !== 2) return \"16/9\"\n const w = parseFloat(parts[0])\n const h = parseFloat(parts[1])\n if (!w || !h || w <= 0 || h <= 0) return \"16/9\"\n return `${w}/${h}`\n}\n\n/**\n * Generate responsive iframe HTML for an embed field value.\n * Returns an empty string if the value is invalid or the URL is not HTTPS.\n */\nexport function getEmbedHtml(value: unknown): string {\n if (!value || typeof value !== \"object\") return \"\"\n const embed = value as EmbedValue\n if (!embed.url || !embed.url.startsWith(\"https://\")) return \"\"\n\n const width = embed.width || \"100%\"\n const aspectRatio = toCssAspectRatio(embed.aspect_ratio || \"16:9\")\n\n return `<div style=\"position:relative;width:${width};aspect-ratio:${aspectRatio}\"><iframe src=\"${embed.url}\" style=\"position:absolute;inset:0;width:100%;height:100%\" frameborder=\"0\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\" allowfullscreen loading=\"lazy\"></iframe></div>`\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n Product,\n ProductCategory,\n ProductQueryOptions,\n CreateOrderParams,\n CreateOrderResult,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\nexport interface ShopClientOptions {\n /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */\n apiKey: string\n /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */\n appUrl?: string\n}\n\n/**\n * Creates a typed client for the eCommerce REST API (products, categories, orders).\n *\n * Unlike `createCmsClient`, the shop client talks to the CMS REST endpoints\n * (`/api/products`, `/api/product-categories`, `/api/orders/create`) rather than\n * Supabase directly — it doesn't need the `supabase` argument, but accepts it\n * for API symmetry with the rest of the SDK.\n *\n * Usage:\n * ```ts\n * const shop = createShopClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const products = await shop.getProducts({ category: \"electronics\", limit: 20 })\n * ```\n */\nexport function createShopClient(\n _supabase: SupabaseClient,\n options: ShopClientOptions\n) {\n const { apiKey } = options\n const appUrl = (options.appUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n function authHeaders(): HeadersInit {\n return {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n }\n }\n\n async function getJson<T>(path: string): Promise<T> {\n const res = await fetch(`${appUrl}${path}`, {\n headers: authHeaders(),\n // Caller controls Next.js caching by wrapping the call site.\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(\n body.error ?? `Shop request failed (${res.status}): ${path}`\n )\n }\n return res.json() as Promise<T>\n }\n\n return {\n /**\n * List published products. Includes nested `variants` and `options`.\n *\n * `category` filters by category slug (matches the FK `category_id`,\n * with a fallback to the legacy `category` text column).\n */\n async getProducts(queryOptions: ProductQueryOptions = {}): Promise<Product[]> {\n const params = new URLSearchParams()\n if (queryOptions.category) params.set(\"category\", queryOptions.category)\n if (queryOptions.tags?.length) params.set(\"tags\", queryOptions.tags.join(\",\"))\n if (queryOptions.limit) params.set(\"limit\", String(queryOptions.limit))\n if (queryOptions.offset) params.set(\"offset\", String(queryOptions.offset))\n if (queryOptions.sort) params.set(\"sort\", queryOptions.sort)\n if (queryOptions.order) params.set(\"order\", queryOptions.order)\n\n const qs = params.toString()\n const { products } = await getJson<{ products: Product[] }>(\n `/api/products${qs ? `?${qs}` : \"\"}`\n )\n return products ?? []\n },\n\n /**\n * Get a single published product by slug. Returns null if not found.\n * Includes nested `variants` and `options`.\n */\n async getProductBySlug(slug: string): Promise<Product | null> {\n const res = await fetch(`${appUrl}/api/products/${encodeURIComponent(slug)}`, {\n headers: authHeaders(),\n })\n if (res.status === 404) return null\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? `Failed to fetch product ${slug}`)\n }\n const { product } = (await res.json()) as { product: Product }\n return product ?? null\n },\n\n /**\n * List product categories for the tenant, ordered by sort_order then name.\n */\n async getCategories(): Promise<ProductCategory[]> {\n const { categories } = await getJson<{ categories: ProductCategory[] }>(\n `/api/product-categories`\n )\n return categories ?? []\n },\n\n /**\n * Get a single category by slug. Returns null if not found.\n */\n async getCategoryBySlug(slug: string): Promise<ProductCategory | null> {\n const all = await this.getCategories()\n return all.find((c) => c.slug === slug) ?? null\n },\n\n /**\n * Create a pending order and return a Stripe PaymentIntent client_secret\n * to confirm payment client-side.\n *\n * Stripe must be configured for the tenant; eCommerce must be enabled on\n * their billing plan. Validates stock for tracked variants and applies\n * any discount code before creating the PaymentIntent.\n */\n async createOrder(params: CreateOrderParams): Promise<CreateOrderResult> {\n const res = await fetch(`${appUrl}/api/orders/create`, {\n method: \"POST\",\n headers: authHeaders(),\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? \"Order creation failed\")\n }\n return res.json() as Promise<CreateOrderResult>\n },\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport { reportClientVersion } from \"./telemetry\"\n\nexport type EventStatus = \"draft\" | \"published\" | \"archived\"\nexport type BookingStatus = \"pending\" | \"confirmed\" | \"cancelled\" | \"refunded\"\n\nexport interface CmsEvent {\n id: string\n tenant_id: string\n title: string\n slug: string\n description: string | null\n short_description: string | null\n status: EventStatus\n start_at: string\n end_at: string | null\n venue_name: string | null\n venue_address: string | null\n hero_image: string | null\n gallery: string[]\n tags: string[]\n seo_title: string | null\n seo_description: string | null\n metadata: Record<string, unknown>\n sort_order: number\n published_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CmsTicketTier {\n id: string\n event_id: string\n tenant_id: string\n name: string\n description: string | null\n price_cents: number\n capacity: number | null\n sold_count: number\n sales_start_at: string | null\n sales_end_at: string | null\n is_active: boolean\n sort_order: number\n}\n\nexport interface EventWithTiers extends CmsEvent {\n tiers: CmsTicketTier[]\n}\n\nexport interface EventQueryOptions {\n /** Only include events with start_at >= now. Default false. */\n upcomingOnly?: boolean\n tag?: string\n limit?: number\n offset?: number\n sort?: \"start_at\" | \"sort_order\" | \"created_at\"\n order?: \"asc\" | \"desc\"\n}\n\nexport interface CreateBookingParams {\n event_slug: string\n ticket_tier_id?: string\n customer_email: string\n customer_name?: string\n customer_phone?: string\n quantity?: number\n success_url?: string\n cancel_url?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface CreateBookingResult {\n booking_id: string\n booking_number: string\n status: \"pending\" | \"confirmed\"\n /** Redirect the browser here for paid bookings. */\n checkout_url?: string\n /** Present on free bookings — used for attendance QR display. */\n qr_token?: string\n}\n\nexport function createEventsClient(\n supabase: SupabaseClient,\n options: { apiKey: string; appUrl?: string }\n) {\n const { apiKey, appUrl } = options\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n async function getEvents(\n queryOptions?: EventQueryOptions\n ): Promise<EventWithTiers[]> {\n let query = supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"status\", \"published\")\n .order(queryOptions?.sort ?? \"start_at\", {\n ascending: (queryOptions?.order ?? \"asc\") === \"asc\",\n })\n\n if (queryOptions?.upcomingOnly) {\n query = query.gte(\"start_at\", new Date().toISOString())\n }\n if (queryOptions?.tag) {\n query = query.contains(\"tags\", [queryOptions.tag])\n }\n if (queryOptions?.limit) {\n query = query.limit(queryOptions.limit)\n }\n if (queryOptions?.offset) {\n query = query.range(\n queryOptions.offset,\n queryOptions.offset + (queryOptions.limit ?? 50) - 1\n )\n }\n\n const { data } = await query\n return (data ?? []) as EventWithTiers[]\n }\n\n async function getEventBySlug(slug: string): Promise<EventWithTiers | null> {\n const { data } = await supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"slug\", slug)\n .eq(\"status\", \"published\")\n .single()\n return (data as EventWithTiers) ?? null\n }\n\n async function createBooking(\n params: CreateBookingParams\n ): Promise<CreateBookingResult> {\n const baseUrl = appUrl ?? \"\"\n const res = await fetch(`${baseUrl}/api/bookings/create`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const err = await res\n .json()\n .catch(() => ({ error: \"Booking creation failed\" }))\n throw new Error(err.error ?? \"Booking creation failed\")\n }\n return res.json() as Promise<CreateBookingResult>\n }\n\n return { getEvents, getEventBySlug, createBooking }\n}\n","/**\n * Image helpers for CMS content.\n *\n * Images are already optimised (WebP, max 2400px) on upload.\n * No server-side transforms needed — serve originals directly.\n *\n * These functions are kept for backward compatibility but no longer\n * call Supabase image transformation endpoints.\n */\n\nexport interface ImageTransformOptions {\n width?: number\n height?: number\n quality?: number\n resize?: \"contain\" | \"cover\" | \"fill\"\n format?: \"origin\"\n}\n\n/**\n * Returns the image URL directly.\n *\n * Previously this converted URLs to use Supabase's /render/image/\n * transform endpoint, but images are now pre-optimised on upload\n * (WebP, max 2400px, quality 82) so transforms are unnecessary.\n *\n * The function is kept for backward compatibility — existing code\n * that calls getTransformUrl() will continue to work without changes.\n */\nexport function getTransformUrl(\n originalUrl: string,\n _options: ImageTransformOptions = {}\n): string {\n return originalUrl\n}\n\n/**\n * Returns a simple srcSet using the original image.\n *\n * Previously generated multiple transformed widths, but since images\n * are now pre-optimised WebP, a single source is sufficient.\n * Modern browsers handle responsive display efficiently with a\n * well-sized WebP source.\n */\nexport function getSrcSet(\n originalUrl: string,\n _widths: number[] = [],\n _quality = 80\n): string {\n return `${originalUrl} 2400w`\n}\n\n/**\n * Common image size presets — kept for backward compatibility.\n * Since images are pre-optimised, these are informational only.\n */\nexport const IMAGE_PRESETS = {\n thumbnail: { width: 150, height: 150, resize: \"cover\" as const, quality: 70 },\n card: { width: 400, height: 300, resize: \"cover\" as const, quality: 80 },\n hero: { width: 1200, height: 630, resize: \"cover\" as const, quality: 85 },\n og: { width: 1200, height: 630, resize: \"cover\" as const, quality: 90 },\n avatar: { width: 80, height: 80, resize: \"cover\" as const, quality: 75 },\n full: { width: 1920, resize: \"contain\" as const, quality: 85 },\n} as const\n","import type { DateGranularity } from \"./types\"\n\nexport interface ParsedPartialDate {\n granularity: DateGranularity\n /** 4-digit year — absent for `month` and `day_month`. */\n year?: number\n /** 1-12 — absent for `year`. */\n month?: number\n /** 1-31 — present only for `full` and `day_month`. */\n day?: number\n}\n\n/**\n * Parses a partial-ISO date string (as produced by a `date` field) into its parts.\n * Returns `null` if the string doesn't match a known granularity shape.\n */\nexport function parsePartialDate(value: string): ParsedPartialDate | null {\n if (!value) return null\n let m: RegExpExecArray | null\n if ((m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"full\", year: +m[1], month: +m[2], day: +m[3] }\n if ((m = /^(\\d{4})-(\\d{2})$/.exec(value)))\n return { granularity: \"month_year\", year: +m[1], month: +m[2] }\n if ((m = /^(\\d{4})$/.exec(value))) return { granularity: \"year\", year: +m[1] }\n if ((m = /^--(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"day_month\", month: +m[1], day: +m[2] }\n if ((m = /^--(\\d{2})$/.exec(value))) return { granularity: \"month\", month: +m[1] }\n return null\n}\n\nexport interface FormatPartialDateOptions {\n /** BCP 47 locale(s) passed to Intl.DateTimeFormat. Defaults to the runtime locale. */\n locale?: string | string[]\n /** Month rendering style. Defaults to `long` (e.g. \"May\"). */\n month?: \"long\" | \"short\" | \"narrow\" | \"numeric\" | \"2-digit\"\n}\n\n/**\n * Formats a partial-ISO date string for display, honouring the value's granularity\n * and locale-correct part ordering (e.g. \"12 May\" vs \"May 12\"). Returns the raw\n * string unchanged if it isn't a recognised partial date.\n */\nexport function formatPartialDate(value: string, options: FormatPartialDateOptions = {}): string {\n const parsed = parsePartialDate(value)\n if (!parsed) return value\n\n const { locale, month = \"long\" } = options\n const monthIndex = parsed.month ? parsed.month - 1 : 0\n\n switch (parsed.granularity) {\n case \"year\":\n return String(parsed.year)\n case \"month\":\n return new Intl.DateTimeFormat(locale, { month }).format(new Date(2000, monthIndex, 1))\n case \"month_year\":\n return new Intl.DateTimeFormat(locale, { month, year: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, 1)\n )\n case \"day_month\":\n return new Intl.DateTimeFormat(locale, { month, day: \"numeric\" }).format(\n new Date(2000, monthIndex, parsed.day!)\n )\n case \"full\":\n return new Intl.DateTimeFormat(locale, { year: \"numeric\", month, day: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, parsed.day!)\n )\n }\n}\n","/**\n * Helpers for verifying outbound webhooks fired by the CMS.\n *\n * The CMS POSTs JSON to subscriber URLs and signs the raw body with\n * HMAC-SHA256 using the shared secret you set in the Webhooks tab. The hex\n * digest arrives in the `X-CMS-Signature` header.\n *\n * Use Web Crypto so this works in Node, Edge, Deno, and Bun runtimes.\n */\n\nexport interface WebhookEventPayload {\n event: string\n tenant_id: string\n content_type_slug?: string\n content_item_id?: string\n slug?: string\n title?: string\n status?: string\n /** Stable identifier of the resource that changed (e.g. product id, flipbook id, integration provider). */\n resource_id?: string\n /**\n * Cache tags the receiver should invalidate. Use {@link revalidateAllTags}\n * to wire this through Next.js's `revalidateTag()` in one line.\n * All tags are namespaced with the `cms:` prefix.\n */\n cache_tags?: string[]\n /** Free-form bag for event-specific extras (e.g. provider name, change counts). */\n data?: Record<string, unknown>\n timestamp: string\n /** Commerce + custom events may attach extra top-level fields. */\n [key: string]: unknown\n}\n\n/**\n * Verify the HMAC-SHA256 signature on a webhook delivery.\n *\n * Pass the **raw** request body (not a parsed JSON object) — re-stringifying\n * a parsed body can change whitespace and invalidate the signature.\n *\n * Returns `true` when the signature matches in constant time, `false`\n * otherwise. Never throws on a bad signature; only throws if the\n * `crypto.subtle` API is unavailable in the runtime.\n *\n * @example\n * const raw = await req.text()\n * const sig = req.headers.get(\"x-cms-signature\")\n * if (!await verifyWebhookSignature(process.env.CMS_WEBHOOK_SECRET!, raw, sig)) {\n * return new Response(\"bad signature\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n */\nexport async function verifyWebhookSignature(\n secret: string,\n rawBody: string,\n signature: string | null | undefined\n): Promise<boolean> {\n if (!signature || !secret) return false\n\n const subtle = (globalThis.crypto && globalThis.crypto.subtle) || null\n if (!subtle) {\n throw new Error(\n \"verifyWebhookSignature requires the Web Crypto API (globalThis.crypto.subtle). \" +\n \"Available in Node 18+, all Edge runtimes, Deno, and Bun.\"\n )\n }\n\n const encoder = new TextEncoder()\n const key = await subtle.importKey(\n \"raw\",\n encoder.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"]\n )\n const sigBuffer = await subtle.sign(\"HMAC\", key, encoder.encode(rawBody))\n const expected = bufferToHex(sigBuffer)\n\n return timingSafeEqualHex(expected, signature.trim())\n}\n\n/**\n * The webhook event names the CMS can fire. Use as a discriminator on the\n * `event` field of {@link WebhookEventPayload}.\n *\n * Most receivers don't need to switch on the event name — every payload\n * carries a `cache_tags` array. Pass it to {@link revalidateAllTags} to\n * invalidate the right Next.js caches in one line.\n */\nexport const WEBHOOK_EVENTS = [\n // Content\n \"content.published\",\n \"content.unpublished\",\n \"content.updated\",\n \"content.deleted\",\n \"content_type.updated\",\n \"content_type.deleted\",\n // Settings (diffed — only fires when a relevant field actually changed)\n \"settings.tracking_updated\",\n \"settings.brand_updated\",\n \"settings.integration_updated\",\n \"settings.mapbox_updated\",\n // Commerce\n \"products.updated\",\n \"product_categories.updated\",\n \"ticket_tiers.updated\",\n \"membership_tiers.updated\",\n \"order.created\",\n \"order.paid\",\n \"order.payment_failed\",\n \"order.refunded\",\n \"order.shipped\",\n \"booking.confirmed\",\n \"inventory.low_stock\",\n // Site\n \"redirects.updated\",\n \"reviews.synced\",\n \"flipbook.ready\",\n] as const\n\nexport type WebhookEvent = (typeof WEBHOOK_EVENTS)[number]\n\n/**\n * Invalidate every cache tag listed in a webhook payload. Call this from your\n * receiver and most events will Just Work without per-event branching.\n *\n * Pass Next.js's `revalidateTag` (or any function with the same shape) — the\n * SDK has no peer dep on `next/cache`, so the import stays in your code.\n *\n * **Next 16 compatibility.** In Next 16, `revalidateTag(tag)` was made into\n * `revalidateTag(tag, profile)`, and calling it with one argument emits a\n * deprecation warning. The cache profile controls expiry — `\"default\"` and\n * `\"max\"` both have non-zero `expire` values and will **not** invalidate the\n * cache. Immediate invalidation requires `{ expire: 0 }`, which isn't\n * documented in the function reference. This helper always passes\n * `{ expire: 0 }` as the second argument, so it does the right thing on Next 16\n * and is silently ignored by Next 14/15.\n *\n * @example\n * import { revalidateTag } from \"next/cache\"\n * import { revalidateAllTags } from \"@distinctagency/cms-client\"\n *\n * export async function POST(req: Request) {\n * const raw = await req.text()\n * if (!await verifyWebhookSignature(SECRET, raw, req.headers.get(\"x-cms-signature\"))) {\n * return new Response(\"bad sig\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n * revalidateAllTags(payload, revalidateTag)\n * return Response.json({ ok: true })\n * }\n */\nexport function revalidateAllTags(\n payload: Pick<WebhookEventPayload, \"cache_tags\">,\n revalidateTag: (tag: string, profile: { expire?: number }) => unknown\n): string[] {\n const tags = payload.cache_tags\n if (!Array.isArray(tags) || tags.length === 0) return []\n const invalidated: string[] = []\n for (const tag of tags) {\n if (typeof tag !== \"string\" || tag.length === 0) continue\n revalidateTag(tag, { expire: 0 })\n invalidated.push(tag)\n }\n return invalidated\n}\n\nfunction bufferToHex(buf: ArrayBuffer): string {\n const bytes = new Uint8Array(buf)\n let out = \"\"\n for (let i = 0; i < bytes.length; i++) {\n out += bytes[i].toString(16).padStart(2, \"0\")\n }\n return out\n}\n\n/**\n * Constant-time equality check on two hex strings. Returns false fast when\n * lengths differ — the length itself is not secret.\n */\nfunction timingSafeEqualHex(a: string, b: string): boolean {\n if (a.length !== b.length) return false\n let mismatch = 0\n for (let i = 0; i < a.length; i++) {\n mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i)\n }\n return mismatch === 0\n}\n"],"mappings":";AAOO,IAAM,qBAAqB;;;ACPlC,SAAS,gBAAgB,4BAA4B;;;ACarD,IAAM,kBAAkB;AAOxB,IAAM,WAAW,oBAAI,IAA0B;AAE/C,SAAS,WAAmB;AAC1B,UAAO,oBAAI,KAAK,GAAE,YAAY,EAAE,MAAM,GAAG,EAAE;AAC7C;AAEO,SAAS,oBAAoB,QAAgB,QAAuB;AAEzE,MAAI,OAAO,WAAW,YAAa;AACnC,MAAI,CAAC,OAAQ;AAEb,QAAM,QAAQ,SAAS;AACvB,QAAM,OAAO,SAAS,IAAI,MAAM;AAChC,MAAI,QAAQ,KAAK,SAAS,SAAS,KAAK,YAAY,mBAAoB;AAIxE,WAAS,IAAI,QAAQ,EAAE,MAAM,OAAO,SAAS,mBAAmB,CAAC;AAEjE,QAAM,YACJ,OAAO,YAAY,cAAc,QAAQ,KAAK,sBAAsB;AACtE,QAAM,QAAQ,UAAU,aAAa,iBAAiB,QAAQ,OAAO,EAAE;AACvE,QAAM,MAAM,GAAG,IAAI;AAInB,OAAK,MAAM,KAAK;AAAA,IACd,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,iBAAiB;AAAA,MACjB,wBAAwB;AAAA,IAC1B;AAAA,IACA,MAAM,KAAK,UAAU;AAAA,MACnB,SAAS;AAAA,M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AAI,EAAE,QAAQ,KAAK;AACjC,gBAAY,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC9C;AACA,SAAO,aAAa;AACtB;","names":["options","query","data","error","DEFAULT_APP_URL"]}
1
+ {"version":3,"sources":["../src/version.ts","../src/queries.ts","../src/telemetry.ts","../src/embed.ts","../src/shop.ts","../src/events.ts","../src/maps.ts","../src/cdn.ts","../src/date.ts","../src/webhooks.ts"],"sourcesContent":["/**\n * The version of @distinctagency/cms-client embedded in this build.\n *\n * Bump this in lock-step with package.json — the value is read by the SDK to\n * report installed-version telemetry and to send `x-cms-client-version` on\n * outgoing requests.\n */\nexport const CMS_CLIENT_VERSION = \"1.24.0\"\n","import { createClient as createSupabaseClient } from \"@supabase/supabase-js\"\nimport type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n CmsClientOptions,\n ContentItem,\n ContentQueryOptions,\n ContentType,\n GoogleReview,\n ReviewQueryOptions,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\n/**\n * Creates a CMS query client authenticated with a tenant API key.\n *\n * Usage:\n * ```ts\n * const cms = createCmsClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const events = await cms.getContentItems('events', { status: 'published' })\n * ```\n *\n * The API key is sent as an `x-cms-api-key` header on every request.\n * Supabase RLS policies validate it against the tenant's stored key.\n */\nexport function createCmsClient(\n supabase: SupabaseClient,\n options: CmsClientOptions\n) {\n const { apiKey } = options\n\n // Create a new Supabase client with the API key header injected globally\n const client = withApiKey(supabase, apiKey) as SupabaseClient\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, options.appUrl)\n\n /** Resolve the tenant ID from the API key (cached per request) */\n let tenantIdCache: string | null = null\n\n async function getTenantId(): Promise<string> {\n if (tenantIdCache) return tenantIdCache\n\n const { data, error } = await client\n .from(\"tenants\")\n .select(\"id\")\n .single()\n\n if (error || !data) {\n throw new Error(\n \"Invalid CMS API key — no tenant found. Check your apiKey.\"\n )\n }\n\n tenantIdCache = data.id\n return data.id\n }\n\n /** Resolve a content type from its slug (cached) */\n const contentTypeCache = new Map<string, ContentType>()\n\n async function getContentTypeBySlug(contentTypeSlug: string): Promise<ContentType> {\n if (contentTypeCache.has(contentTypeSlug)) return contentTypeCache.get(contentTypeSlug)!\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n const ct = data as ContentType\n contentTypeCache.set(contentTypeSlug, ct)\n return ct\n }\n\n async function getContentTypeId(contentTypeSlug: string): Promise<string> {\n const ct = await getContentTypeBySlug(contentTypeSlug)\n return ct.id\n }\n\n /** Check if a member token has access to a gated content type */\n async function checkMemberAccess(\n contentType: ContentType,\n memberToken?: string\n ): Promise<{ allowed: boolean; memberTierId: string | null }> {\n const requiredTierId = contentType.required_membership_tier_id\n if (!requiredTierId) return { allowed: true, memberTierId: null } // Public\n\n if (!memberToken) return { allowed: false, memberTierId: null } // Gated but no token\n\n // Verify the member's token and check their tier\n const { data: session } = await client\n .from(\"member_sessions\")\n .select(\"member_id\")\n .eq(\"token_hash\", memberToken) // Note: caller should hash the token\n .single()\n\n if (!session) return { allowed: false, memberTierId: null }\n\n const { data: member } = await client\n .from(\"members\")\n .select(\"membership_tier_id, status\")\n .eq(\"id\", session.member_id)\n .single()\n\n if (!member || member.status !== \"active\") return { allowed: false, memberTierId: null }\n\n // Check if the member's tier matches (or exceeds) the required tier\n // For now: exact match or the member has the required tier\n return {\n allowed: member.membership_tier_id === requiredTierId,\n memberTierId: member.membership_tier_id as string | null,\n }\n }\n\n async function getFlipbook(id: string): Promise<import(\"./types\").FlipbookPublic | null> {\n const { data, error } = await client\n .from(\"flipbooks\")\n .select(\"id, title, page_count, status, manifest, download_enabled, tenant_id\")\n .eq(\"id\", id)\n .single()\n if (error || !data) return null\n\n const manifest = data.manifest as\n | { pages: Array<{ image: string; thumb: string; w: number; h: number }>; toc: Array<{ title: string; page: number }> }\n | null\n if (!manifest) {\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? 0,\n status: data.status as \"pending_upload\" | \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: [],\n toc: [],\n download_url: null,\n }\n }\n\n // Browser-safe env lookup via globalThis. The client package builds without\n // @types/node so referring to `process` directly fails the dts build; reading\n // through globalThis sidesteps that and works in every JS environment that\n // matters (Node, browsers, edge runtimes).\n const proc = (globalThis as { process?: { env?: Record<string, string | undefined> } }).process\n const cdnBase = proc?.env?.NEXT_PUBLIC_R2_PUBLIC_URL ?? \"https://cdn.distinctstudio.co.nz\"\n const prefix = `flipbooks/${data.tenant_id as string}/${data.id as string}/`\n return {\n id: data.id as string,\n title: data.title as string,\n page_count: (data.page_count as number) ?? manifest.pages.length,\n status: data.status as \"pending\" | \"processing\" | \"ready\" | \"failed\",\n page_images: manifest.pages.map((p) => ({\n url: `${cdnBase}/${prefix}${p.image}`,\n thumb_url: `${cdnBase}/${prefix}${p.thumb}`,\n w: p.w,\n h: p.h,\n })),\n toc: manifest.toc,\n download_url: data.download_enabled\n ? `${options.appUrl ?? \"\"}/api/flipbooks/${data.id as string}/download`\n : null,\n }\n }\n\n return {\n /**\n * List content items for a content type.\n * Defaults to published items ordered by most recent.\n */\n async getContentItems(\n contentTypeSlug: string,\n options: ContentQueryOptions = {}\n ): Promise<(ContentItem & { locked?: boolean })[]> {\n const contentType = await getContentTypeBySlug(contentTypeSlug)\n\n const {\n status = \"published\",\n orderBy = \"published_at\",\n orderDirection = \"desc\",\n limit = 100,\n offset = 0,\n memberToken,\n } = options\n\n // Check membership access\n const access = await checkMemberAccess(contentType, memberToken)\n\n // If gated and no access, check gating mode\n if (!access.allowed && contentType.required_membership_tier_id) {\n // Get tenant settings for gating mode\n const tenantId = await getTenantId()\n const { data: settings } = await client\n .from(\"tenant_settings\")\n .select(\"membership_gating_mode\")\n .eq(\"tenant_id\", tenantId)\n .single()\n\n const mode = (settings?.membership_gating_mode as string) ?? \"teaser\"\n\n if (mode === \"hide\") {\n return [] // Hide: return nothing\n }\n\n // Teaser mode: return items with locked flag, no body/data\n let query = client\n .from(\"content_items\")\n .select(\"id, title, slug, status, excerpt, seo_title, seo_description, featured_image, published_at, created_at, updated_at\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) query = query.eq(\"status\", status)\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n if (error) throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n\n return (data ?? []).map((item) => ({\n ...item,\n data: {},\n locked: true,\n })) as (ContentItem & { locked: boolean })[]\n }\n\n // Full access\n let query = client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentType.id)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch ${contentTypeSlug}: ${error.message}`)\n }\n\n return (data ?? []) as ContentItem[]\n },\n\n /**\n * Get a single content item by its slug.\n * Returns null if not found.\n */\n async getContentItemBySlug(\n contentTypeSlug: string,\n itemSlug: string\n ): Promise<ContentItem | null> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"slug\", itemSlug)\n .single()\n\n if (error) {\n if (error.code === \"PGRST116\") return null // not found\n throw new Error(\n `Failed to fetch ${contentTypeSlug}/${itemSlug}: ${error.message}`\n )\n }\n\n return data as ContentItem\n },\n\n /**\n * Get the single published item for a singleton content type (\"page\").\n *\n * A singleton content type owns exactly one item. Use this for editable\n * page copy (hero text, section headings, etc.) stored in the CMS.\n * Returns null when the singleton has no published item yet — callers\n * should fall back to their hardcoded defaults in that case.\n *\n * Wrap this in `unstable_cache` with a `cms:singleton:<slug>` tag on the\n * consuming site to cache it and revalidate via the CMS webhook.\n */\n async getSingleton(contentTypeSlug: string): Promise<ContentItem | null> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"*\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"status\", \"published\")\n .order(\"updated_at\", { ascending: false })\n .limit(1)\n .maybeSingle()\n\n if (error) {\n throw new Error(\n `Failed to fetch singleton ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data as ContentItem) ?? null\n },\n\n /**\n * Get a content type definition (including its field schema).\n */\n async getContentType(contentTypeSlug: string): Promise<ContentType> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", contentTypeSlug)\n .single()\n\n if (error || !data) {\n throw new Error(`Content type not found: ${contentTypeSlug}`)\n }\n\n return data as ContentType\n },\n\n /**\n * Get all slugs for a content type (for generateStaticParams).\n */\n async getAllSlugs(\n contentTypeSlug: string\n ): Promise<{ slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"content_items\")\n .select(\"slug\")\n .eq(\"content_type_id\", contentTypeId)\n .eq(\"status\", \"published\")\n\n if (error) {\n throw new Error(\n `Failed to fetch slugs for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { slug: string }[]\n },\n\n /**\n * List all content types for this tenant.\n */\n async getContentTypes(): Promise<ContentType[]> {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"content_types\")\n .select(\"*\")\n .eq(\"tenant_id\", tenantId)\n .order(\"name\")\n\n if (error) {\n throw new Error(`Failed to fetch content types: ${error.message}`)\n }\n\n return (data ?? []) as ContentType[]\n },\n\n /**\n * Get all slug redirects for a content type.\n * Use in next.config.js redirects() or middleware for 301s.\n * Returns: [{ old_slug, new_slug }, ...]\n */\n async getRedirects(\n contentTypeSlug: string\n ): Promise<{ old_slug: string; new_slug: string }[]> {\n const contentTypeId = await getContentTypeId(contentTypeSlug)\n\n const { data, error } = await client\n .from(\"slug_redirects\")\n .select(\"old_slug, new_slug\")\n .eq(\"content_type_id\", contentTypeId)\n\n if (error) {\n throw new Error(\n `Failed to fetch redirects for ${contentTypeSlug}: ${error.message}`\n )\n }\n\n return (data ?? []) as { old_slug: string; new_slug: string }[]\n },\n\n /**\n * Get all custom path redirects for this tenant.\n * Use alongside getRedirects() in next.config.ts for full redirect coverage.\n */\n async getCustomRedirects(): Promise<\n { source_path: string; destination_path: string; permanent: boolean }[]\n > {\n const tenantId = await getTenantId()\n\n const { data, error } = await client\n .from(\"custom_redirects\")\n .select(\"source_path, destination_path, permanent\")\n .eq(\"tenant_id\", tenantId)\n\n if (error) {\n throw new Error(`Failed to fetch custom redirects: ${error.message}`)\n }\n\n return (data ?? []) as {\n source_path: string\n destination_path: string\n permanent: boolean\n }[]\n },\n\n /**\n * Get form submissions for a specific form.\n * Useful for displaying testimonials, reviews, etc.\n */\n async getFormSubmissions(\n formSlug: string,\n options: { status?: string; limit?: number; offset?: number } = {}\n ): Promise<Record<string, unknown>[]> {\n const tenantId = await getTenantId()\n\n const { data: form } = await client\n .from(\"forms\")\n .select(\"id\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n if (!form) return []\n\n const { limit = 50, offset = 0, status } = options\n\n let query = client\n .from(\"form_submissions\")\n .select(\"*\")\n .eq(\"form_id\", form.id)\n .eq(\"is_spam\", false)\n .order(\"created_at\", { ascending: false })\n .range(offset, offset + limit - 1)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n const { data } = await query\n return (data ?? []) as Record<string, unknown>[]\n },\n\n /**\n * Get a form configuration by slug.\n */\n async getForm(\n formSlug: string\n ): Promise<Record<string, unknown> | null> {\n const tenantId = await getTenantId()\n\n const { data } = await client\n .from(\"forms\")\n .select(\"id, name, slug, description, is_active\")\n .eq(\"tenant_id\", tenantId)\n .eq(\"slug\", formSlug)\n .single()\n\n return data as Record<string, unknown> | null\n },\n\n /**\n * Get a flipbook by ID, including CDN-resolved page image URLs.\n * Returns null if not found or manifest not yet ready.\n */\n getFlipbook,\n\n /**\n * Get Google Reviews for this tenant.\n * Defaults to approved reviews ordered by most recent.\n */\n async getReviews(\n options: ReviewQueryOptions = {}\n ): Promise<GoogleReview[]> {\n const tenantId = await getTenantId()\n\n const {\n status = \"approved\",\n minRating,\n limit = 50,\n offset = 0,\n orderBy = \"review_timestamp\",\n orderDirection = \"desc\",\n } = options\n\n let query = client\n .from(\"google_reviews\")\n .select(\"id, author_name, author_photo_url, rating, text, review_timestamp\")\n .eq(\"tenant_id\", tenantId)\n\n if (status) {\n query = query.eq(\"status\", status)\n }\n\n if (minRating) {\n query = query.gte(\"rating\", minRating)\n }\n\n query = query\n .order(orderBy, { ascending: orderDirection === \"asc\" })\n .range(offset, offset + limit - 1)\n\n const { data, error } = await query\n\n if (error) {\n throw new Error(`Failed to fetch reviews: ${error.message}`)\n }\n\n return (data ?? []) as GoogleReview[]\n },\n\n /**\n * Get the tenant's third-party tracking IDs (Google Analytics, Google Tag Manager, Meta Pixel).\n * Each value is null when not configured. These IDs are public and safe to render in HTML.\n *\n * On Next.js, the result is cached and revalidated every hour by default\n * (`revalidate: 3600`) and tagged with `TRACKING_CONFIG_TAG`. Tenant sites\n * that want zero-lag updates can call `revalidateTag(TRACKING_CONFIG_TAG)`\n * from a webhook. Pass `revalidate: 0` to disable caching, `revalidate: false`\n * to cache indefinitely (tag-only invalidation), or any positive integer\n * (seconds) to override the interval. Outside Next.js the cache hints are\n * silently ignored — every call hits the network.\n */\n async getTrackingConfig(options: TrackingConfigOptions = {}): Promise<TrackingConfig> {\n const { revalidate = 3600, tags = [TRACKING_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n // Direct PostgREST fetch (instead of going through supabase-js) so that\n // Next.js sees the request and applies its `next` cache options. RLS\n // restricts the result to the tenant matching `x-cms-api-key`, so no\n // explicit tenant_id filter is needed.\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=google_analytics_id,google_tag_manager_id,google_ads_id,meta_pixel_id&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: {\n google_analytics_id: string | null\n google_tag_manager_id: string | null\n google_ads_id: string | null\n meta_pixel_id: string | null\n } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the all-null result so a transient\n // outage on the CMS never breaks page renders on the tenant site.\n }\n\n return {\n googleAnalyticsId: nullify(row?.google_analytics_id),\n googleTagManagerId: nullify(row?.google_tag_manager_id),\n googleAdsId: nullify(row?.google_ads_id),\n metaPixelId: nullify(row?.meta_pixel_id),\n }\n },\n\n /**\n * Get the tenant's Mapbox **public** token (`pk.*`) for rendering maps in the\n * browser. Returns `{ publicToken: null }` when not configured. The Mapbox\n * **secret** token is never exposed by the CMS — read it from your own\n * environment variables.\n *\n * Caching mirrors `getTrackingConfig()`: revalidated hourly by default and\n * tagged with `MAPBOX_CONFIG_TAG`. Call `revalidateTag(MAPBOX_CONFIG_TAG)`\n * from a `settings.mapbox_updated` webhook for zero-lag updates.\n */\n async getMapboxConfig(options: MapboxConfigOptions = {}): Promise<MapboxConfig> {\n const { revalidate = 3600, tags = [MAPBOX_CONFIG_TAG] } = options\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n const url =\n `${supabaseUrl}/rest/v1/tenant_settings` +\n `?select=mapbox_public_token&limit=1`\n\n const init: RequestInit & { next?: { revalidate?: number | false; tags?: string[] } } = {\n headers: {\n apikey: supabaseKey,\n Authorization: `Bearer ${supabaseKey}`,\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n Accept: \"application/json\",\n },\n next: { revalidate, tags },\n }\n\n let row: { mapbox_public_token: string | null } | undefined\n\n try {\n const res = await fetch(url, init as RequestInit)\n if (res.ok) {\n const rows = (await res.json()) as Array<typeof row>\n row = rows?.[0]\n }\n } catch {\n // Network errors fall through to the null result so a transient CMS\n // outage never breaks map rendering on the tenant site.\n }\n\n return { publicToken: nullify(row?.mapbox_public_token) }\n },\n }\n}\n\n/**\n * Cache tag applied to `getTrackingConfig()` fetches on Next.js. Call\n * `revalidateTag(TRACKING_CONFIG_TAG)` from a webhook handler on the tenant\n * site to make tracking-ID changes take effect immediately rather than\n * waiting for the next revalidation interval.\n */\nexport const TRACKING_CONFIG_TAG = \"cms:tracking-config\"\n\nexport interface TrackingConfigOptions {\n /**\n * Cache lifetime for the underlying fetch on Next.js, in seconds.\n * Defaults to 3600 (one hour). Set to `0` to disable caching, or `false`\n * to cache indefinitely until the tag is revalidated. Ignored outside\n * Next.js runtimes.\n */\n revalidate?: number | false\n /**\n * Cache tags for the underlying fetch on Next.js. Defaults to\n * `[TRACKING_CONFIG_TAG]`. Override to namespace by tenant if you share a\n * single Next.js process across multiple tenants (uncommon).\n */\n tags?: string[]\n}\n\n/**\n * Cache tag applied to `getMapboxConfig()` fetches on Next.js. Call\n * `revalidateTag(MAPBOX_CONFIG_TAG)` from a `settings.mapbox_updated` webhook\n * handler so public-token changes take effect immediately.\n */\nexport const MAPBOX_CONFIG_TAG = \"cms:mapbox-config\"\n\n/**\n * Cache tag for a singleton \"page\" content type. Wrap `getSingleton(slug)` in\n * `unstable_cache` tagged with `singletonTag(slug)`, then call\n * `revalidateTag(singletonTag(slug))` from the CMS `content.updated` webhook\n * (the webhook payload's `cache_tags` already include this value).\n */\nexport function singletonTag(slug: string): string {\n return `cms:singleton:${slug}`\n}\n\nexport interface MapboxConfigOptions {\n /** Cache lifetime in seconds on Next.js. Defaults to 3600. `0` disables caching, `false` caches until tag revalidation. Ignored outside Next.js. */\n revalidate?: number | false\n /** Cache tags applied to the fetch. Defaults to `[MAPBOX_CONFIG_TAG]`. */\n tags?: string[]\n}\n\nexport interface MapboxConfig {\n /** The tenant's Mapbox public token (`pk.*`), or null when not configured. */\n publicToken: string | null\n}\n\nfunction nullify(v: string | null | undefined): string | null {\n if (!v) return null\n const trimmed = v.trim()\n return trimmed.length > 0 ? trimmed : null\n}\n\nexport interface TrackingConfig {\n googleAnalyticsId: string | null\n googleTagManagerId: string | null\n googleAdsId: string | null\n metaPixelId: string | null\n}\n\n/**\n * Creates a new Supabase client that includes the `x-cms-api-key`\n * header in every request, using the same URL and key as the original.\n */\nfunction withApiKey(supabase: SupabaseClient, apiKey: string) {\n // Extract URL and key from the existing client\n const supabaseUrl = (supabase as unknown as { supabaseUrl: string }).supabaseUrl\n const supabaseKey = (supabase as unknown as { supabaseKey: string }).supabaseKey\n\n return createSupabaseClient(supabaseUrl, supabaseKey, {\n global: {\n headers: {\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n },\n })\n}\n","import { CMS_CLIENT_VERSION } from \"./version\"\n\n/**\n * Reports the running SDK version to the CMS so the Super Admin UI can show\n * which client version each tenant site is on.\n *\n * Day-granular and process-local: at most one POST per (api key + day) per\n * Node process. Calls from browser code are ignored — the API key would be\n * exposed and the data is redundant with server-side reports.\n *\n * Fire-and-forget. Failures are silent — telemetry must never break a render.\n */\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\ninterface ReportRecord {\n date: string // YYYY-MM-DD\n version: string\n}\n\nconst reported = new Map<string, ReportRecord>()\n\nfunction todayKey(): string {\n return new Date().toISOString().slice(0, 10)\n}\n\nexport function reportClientVersion(apiKey: string, appUrl?: string): void {\n // Skip in browser contexts — server-side calls already cover the tenant.\n if (typeof window !== \"undefined\") return\n if (!apiKey) return\n\n const today = todayKey()\n const last = reported.get(apiKey)\n if (last && last.date === today && last.version === CMS_CLIENT_VERSION) return\n\n // Optimistically mark as reported so concurrent calls don't all fire. If the\n // request fails we'll retry tomorrow — that's acceptable for telemetry.\n reported.set(apiKey, { date: today, version: CMS_CLIENT_VERSION })\n\n const envAppUrl =\n typeof process !== \"undefined\" ? process.env?.NEXT_PUBLIC_CMS_URL : undefined\n const base = (appUrl ?? envAppUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n const url = `${base}/api/client-telemetry`\n\n // Fire and forget. Use a hand-rolled then() chain rather than async/await so\n // we don't accidentally surface an unhandled rejection.\n void fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n body: JSON.stringify({\n api_key: apiKey,\n version: CMS_CLIENT_VERSION,\n }),\n }).catch(() => {\n // Allow a retry on the next call by clearing the optimistic record.\n reported.delete(apiKey)\n })\n}\n","import type { EmbedValue } from \"./types\"\n\nfunction toCssAspectRatio(ratio: string): string {\n const parts = ratio.split(\":\")\n if (parts.length !== 2) return \"16/9\"\n const w = parseFloat(parts[0])\n const h = parseFloat(parts[1])\n if (!w || !h || w <= 0 || h <= 0) return \"16/9\"\n return `${w}/${h}`\n}\n\n/**\n * Generate responsive iframe HTML for an embed field value.\n * Returns an empty string if the value is invalid or the URL is not HTTPS.\n */\nexport function getEmbedHtml(value: unknown): string {\n if (!value || typeof value !== \"object\") return \"\"\n const embed = value as EmbedValue\n if (!embed.url || !embed.url.startsWith(\"https://\")) return \"\"\n\n const width = embed.width || \"100%\"\n const aspectRatio = toCssAspectRatio(embed.aspect_ratio || \"16:9\")\n\n return `<div style=\"position:relative;width:${width};aspect-ratio:${aspectRatio}\"><iframe src=\"${embed.url}\" style=\"position:absolute;inset:0;width:100%;height:100%\" frameborder=\"0\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\" allowfullscreen loading=\"lazy\"></iframe></div>`\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type {\n Product,\n ProductCategory,\n ProductQueryOptions,\n CreateOrderParams,\n CreateOrderResult,\n} from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\nexport interface ShopClientOptions {\n /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */\n apiKey: string\n /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */\n appUrl?: string\n}\n\n/**\n * Creates a typed client for the eCommerce REST API (products, categories, orders).\n *\n * Unlike `createCmsClient`, the shop client talks to the CMS REST endpoints\n * (`/api/products`, `/api/product-categories`, `/api/orders/create`) rather than\n * Supabase directly — it doesn't need the `supabase` argument, but accepts it\n * for API symmetry with the rest of the SDK.\n *\n * Usage:\n * ```ts\n * const shop = createShopClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const products = await shop.getProducts({ category: \"electronics\", limit: 20 })\n * ```\n */\nexport function createShopClient(\n _supabase: SupabaseClient,\n options: ShopClientOptions\n) {\n const { apiKey } = options\n const appUrl = (options.appUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n function authHeaders(): HeadersInit {\n return {\n \"Content-Type\": \"application/json\",\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n }\n }\n\n async function getJson<T>(path: string): Promise<T> {\n const res = await fetch(`${appUrl}${path}`, {\n headers: authHeaders(),\n // Caller controls Next.js caching by wrapping the call site.\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(\n body.error ?? `Shop request failed (${res.status}): ${path}`\n )\n }\n return res.json() as Promise<T>\n }\n\n return {\n /**\n * List published products. Includes nested `variants` and `options`.\n *\n * `category` filters by category slug (matches the FK `category_id`,\n * with a fallback to the legacy `category` text column).\n */\n async getProducts(queryOptions: ProductQueryOptions = {}): Promise<Product[]> {\n const params = new URLSearchParams()\n if (queryOptions.category) params.set(\"category\", queryOptions.category)\n if (queryOptions.tags?.length) params.set(\"tags\", queryOptions.tags.join(\",\"))\n if (queryOptions.limit) params.set(\"limit\", String(queryOptions.limit))\n if (queryOptions.offset) params.set(\"offset\", String(queryOptions.offset))\n if (queryOptions.sort) params.set(\"sort\", queryOptions.sort)\n if (queryOptions.order) params.set(\"order\", queryOptions.order)\n\n const qs = params.toString()\n const { products } = await getJson<{ products: Product[] }>(\n `/api/products${qs ? `?${qs}` : \"\"}`\n )\n return products ?? []\n },\n\n /**\n * Get a single published product by slug. Returns null if not found.\n * Includes nested `variants` and `options`.\n */\n async getProductBySlug(slug: string): Promise<Product | null> {\n const res = await fetch(`${appUrl}/api/products/${encodeURIComponent(slug)}`, {\n headers: authHeaders(),\n })\n if (res.status === 404) return null\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? `Failed to fetch product ${slug}`)\n }\n const { product } = (await res.json()) as { product: Product }\n return product ?? null\n },\n\n /**\n * List product categories for the tenant, ordered by sort_order then name.\n */\n async getCategories(): Promise<ProductCategory[]> {\n const { categories } = await getJson<{ categories: ProductCategory[] }>(\n `/api/product-categories`\n )\n return categories ?? []\n },\n\n /**\n * Get a single category by slug. Returns null if not found.\n */\n async getCategoryBySlug(slug: string): Promise<ProductCategory | null> {\n const all = await this.getCategories()\n return all.find((c) => c.slug === slug) ?? null\n },\n\n /**\n * Create a pending order and return a Stripe PaymentIntent client_secret\n * to confirm payment client-side.\n *\n * Stripe must be configured for the tenant; eCommerce must be enabled on\n * their billing plan. Validates stock for tracked variants and applies\n * any discount code before creating the PaymentIntent.\n */\n async createOrder(params: CreateOrderParams): Promise<CreateOrderResult> {\n const res = await fetch(`${appUrl}/api/orders/create`, {\n method: \"POST\",\n headers: authHeaders(),\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const body = await res.json().catch(() => ({}) as { error?: string })\n throw new Error(body.error ?? \"Order creation failed\")\n }\n return res.json() as Promise<CreateOrderResult>\n },\n }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport { reportClientVersion } from \"./telemetry\"\n\nexport type EventStatus = \"draft\" | \"published\" | \"archived\"\nexport type BookingStatus = \"pending\" | \"confirmed\" | \"cancelled\" | \"refunded\"\n\nexport interface CmsEvent {\n id: string\n tenant_id: string\n title: string\n slug: string\n description: string | null\n short_description: string | null\n status: EventStatus\n start_at: string\n end_at: string | null\n venue_name: string | null\n venue_address: string | null\n hero_image: string | null\n gallery: string[]\n tags: string[]\n seo_title: string | null\n seo_description: string | null\n metadata: Record<string, unknown>\n sort_order: number\n published_at: string | null\n created_at: string\n updated_at: string\n}\n\nexport interface CmsTicketTier {\n id: string\n event_id: string\n tenant_id: string\n name: string\n description: string | null\n price_cents: number\n capacity: number | null\n sold_count: number\n sales_start_at: string | null\n sales_end_at: string | null\n is_active: boolean\n sort_order: number\n}\n\nexport interface EventWithTiers extends CmsEvent {\n tiers: CmsTicketTier[]\n}\n\nexport interface EventQueryOptions {\n /** Only include events with start_at >= now. Default false. */\n upcomingOnly?: boolean\n tag?: string\n limit?: number\n offset?: number\n sort?: \"start_at\" | \"sort_order\" | \"created_at\"\n order?: \"asc\" | \"desc\"\n}\n\nexport interface CreateBookingParams {\n event_slug: string\n ticket_tier_id?: string\n customer_email: string\n customer_name?: string\n customer_phone?: string\n quantity?: number\n success_url?: string\n cancel_url?: string\n metadata?: Record<string, unknown>\n}\n\nexport interface CreateBookingResult {\n booking_id: string\n booking_number: string\n status: \"pending\" | \"confirmed\"\n /** Redirect the browser here for paid bookings. */\n checkout_url?: string\n /** Present on free bookings — used for attendance QR display. */\n qr_token?: string\n}\n\nexport function createEventsClient(\n supabase: SupabaseClient,\n options: { apiKey: string; appUrl?: string }\n) {\n const { apiKey, appUrl } = options\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n async function getEvents(\n queryOptions?: EventQueryOptions\n ): Promise<EventWithTiers[]> {\n let query = supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"status\", \"published\")\n .order(queryOptions?.sort ?? \"start_at\", {\n ascending: (queryOptions?.order ?? \"asc\") === \"asc\",\n })\n\n if (queryOptions?.upcomingOnly) {\n query = query.gte(\"start_at\", new Date().toISOString())\n }\n if (queryOptions?.tag) {\n query = query.contains(\"tags\", [queryOptions.tag])\n }\n if (queryOptions?.limit) {\n query = query.limit(queryOptions.limit)\n }\n if (queryOptions?.offset) {\n query = query.range(\n queryOptions.offset,\n queryOptions.offset + (queryOptions.limit ?? 50) - 1\n )\n }\n\n const { data } = await query\n return (data ?? []) as EventWithTiers[]\n }\n\n async function getEventBySlug(slug: string): Promise<EventWithTiers | null> {\n const { data } = await supabase\n .from(\"events\")\n .select(\"*, tiers:ticket_tiers(*)\")\n .eq(\"slug\", slug)\n .eq(\"status\", \"published\")\n .single()\n return (data as EventWithTiers) ?? null\n }\n\n async function createBooking(\n params: CreateBookingParams\n ): Promise<CreateBookingResult> {\n const baseUrl = appUrl ?? \"\"\n const res = await fetch(`${baseUrl}/api/bookings/create`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ api_key: apiKey, ...params }),\n })\n if (!res.ok) {\n const err = await res\n .json()\n .catch(() => ({ error: \"Booking creation failed\" }))\n throw new Error(err.error ?? \"Booking creation failed\")\n }\n return res.json() as Promise<CreateBookingResult>\n }\n\n return { getEvents, getEventBySlug, createBooking }\n}\n","import type { SupabaseClient } from \"@supabase/supabase-js\"\nimport type { GeocodeOptions, GeocodeResult } from \"./types\"\nimport { CMS_CLIENT_VERSION } from \"./version\"\nimport { reportClientVersion } from \"./telemetry\"\n\nconst DEFAULT_APP_URL = \"https://cms.distinctstudio.co.nz\"\n\nexport interface MapsClientOptions {\n /** Tenant API key (UUID). Sent as `x-cms-api-key` on every request. */\n apiKey: string\n /** CMS app base URL. Defaults to `https://cms.distinctstudio.co.nz`. */\n appUrl?: string\n}\n\n/**\n * Creates a typed client for Mapbox-backed helpers (forward geocoding, with\n * more to come). Like `createShopClient`, it talks to CMS REST endpoints rather\n * than Supabase directly — it doesn't need the `supabase` argument but accepts\n * it for API symmetry. The Mapbox call runs server-side with the tenant's\n * public token; the token is never exposed to the browser.\n *\n * ```ts\n * const maps = createMapsClient(supabase, { apiKey: process.env.CMS_API_KEY! })\n * const [best] = await maps.geocodeAddress(\"12 Queen St, Auckland\")\n * ```\n */\nexport function createMapsClient(_supabase: SupabaseClient, options: MapsClientOptions) {\n const { apiKey } = options\n const appUrl = (options.appUrl ?? DEFAULT_APP_URL).replace(/\\/$/, \"\")\n\n // Day-granular, fire-and-forget version ping (server-side only).\n reportClientVersion(apiKey, appUrl)\n\n return {\n /**\n * Forward-geocode an address string. Returns matches ordered by relevance\n * (`results[0]` is the best match), or [] when nothing matches. Throws on a\n * configuration or upstream error.\n */\n async geocodeAddress(query: string, options: GeocodeOptions = {}): Promise<GeocodeResult[]> {\n const q = query.trim()\n if (!q) throw new Error(\"geocodeAddress: query is required\")\n\n const params = new URLSearchParams({ q })\n if (options.limit != null) params.set(\"limit\", String(options.limit))\n if (options.country) params.set(\"country\", options.country)\n if (options.proximity) params.set(\"proximity\", `${options.proximity[0]},${options.proximity[1]}`)\n if (options.types) params.set(\"types\", options.types)\n if (options.language) params.set(\"language\", options.language)\n\n const res = await fetch(`${appUrl}/api/mapbox/geocode?${params.toString()}`, {\n headers: {\n \"x-cms-api-key\": apiKey,\n \"x-cms-client-version\": CMS_CLIENT_VERSION,\n },\n })\n if (!res.ok) {\n const body = (await res.json().catch(() => ({}))) as { error?: string }\n throw new Error(body.error ?? `Geocoding failed (${res.status})`)\n }\n const data = (await res.json()) as { results?: GeocodeResult[] }\n return data.results ?? []\n },\n }\n}\n","/**\n * Image helpers for CMS content.\n *\n * Images are already optimised (WebP, max 2400px) on upload.\n * No server-side transforms needed — serve originals directly.\n *\n * These functions are kept for backward compatibility but no longer\n * call Supabase image transformation endpoints.\n */\n\nexport interface ImageTransformOptions {\n width?: number\n height?: number\n quality?: number\n resize?: \"contain\" | \"cover\" | \"fill\"\n format?: \"origin\"\n}\n\n/**\n * Returns the image URL directly.\n *\n * Previously this converted URLs to use Supabase's /render/image/\n * transform endpoint, but images are now pre-optimised on upload\n * (WebP, max 2400px, quality 82) so transforms are unnecessary.\n *\n * The function is kept for backward compatibility — existing code\n * that calls getTransformUrl() will continue to work without changes.\n */\nexport function getTransformUrl(\n originalUrl: string,\n _options: ImageTransformOptions = {}\n): string {\n return originalUrl\n}\n\n/**\n * Returns a simple srcSet using the original image.\n *\n * Previously generated multiple transformed widths, but since images\n * are now pre-optimised WebP, a single source is sufficient.\n * Modern browsers handle responsive display efficiently with a\n * well-sized WebP source.\n */\nexport function getSrcSet(\n originalUrl: string,\n _widths: number[] = [],\n _quality = 80\n): string {\n return `${originalUrl} 2400w`\n}\n\n/**\n * Common image size presets — kept for backward compatibility.\n * Since images are pre-optimised, these are informational only.\n */\nexport const IMAGE_PRESETS = {\n thumbnail: { width: 150, height: 150, resize: \"cover\" as const, quality: 70 },\n card: { width: 400, height: 300, resize: \"cover\" as const, quality: 80 },\n hero: { width: 1200, height: 630, resize: \"cover\" as const, quality: 85 },\n og: { width: 1200, height: 630, resize: \"cover\" as const, quality: 90 },\n avatar: { width: 80, height: 80, resize: \"cover\" as const, quality: 75 },\n full: { width: 1920, resize: \"contain\" as const, quality: 85 },\n} as const\n","import type { DateGranularity } from \"./types\"\n\nexport interface ParsedPartialDate {\n granularity: DateGranularity\n /** 4-digit year — absent for `month` and `day_month`. */\n year?: number\n /** 1-12 — absent for `year`. */\n month?: number\n /** 1-31 — present only for `full` and `day_month`. */\n day?: number\n}\n\n/**\n * Parses a partial-ISO date string (as produced by a `date` field) into its parts.\n * Returns `null` if the string doesn't match a known granularity shape.\n */\nexport function parsePartialDate(value: string): ParsedPartialDate | null {\n if (!value) return null\n let m: RegExpExecArray | null\n if ((m = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"full\", year: +m[1], month: +m[2], day: +m[3] }\n if ((m = /^(\\d{4})-(\\d{2})$/.exec(value)))\n return { granularity: \"month_year\", year: +m[1], month: +m[2] }\n if ((m = /^(\\d{4})$/.exec(value))) return { granularity: \"year\", year: +m[1] }\n if ((m = /^--(\\d{2})-(\\d{2})$/.exec(value)))\n return { granularity: \"day_month\", month: +m[1], day: +m[2] }\n if ((m = /^--(\\d{2})$/.exec(value))) return { granularity: \"month\", month: +m[1] }\n return null\n}\n\nexport interface FormatPartialDateOptions {\n /** BCP 47 locale(s) passed to Intl.DateTimeFormat. Defaults to the runtime locale. */\n locale?: string | string[]\n /** Month rendering style. Defaults to `long` (e.g. \"May\"). */\n month?: \"long\" | \"short\" | \"narrow\" | \"numeric\" | \"2-digit\"\n}\n\n/**\n * Formats a partial-ISO date string for display, honouring the value's granularity\n * and locale-correct part ordering (e.g. \"12 May\" vs \"May 12\"). Returns the raw\n * string unchanged if it isn't a recognised partial date.\n */\nexport function formatPartialDate(value: string, options: FormatPartialDateOptions = {}): string {\n const parsed = parsePartialDate(value)\n if (!parsed) return value\n\n const { locale, month = \"long\" } = options\n const monthIndex = parsed.month ? parsed.month - 1 : 0\n\n switch (parsed.granularity) {\n case \"year\":\n return String(parsed.year)\n case \"month\":\n return new Intl.DateTimeFormat(locale, { month }).format(new Date(2000, monthIndex, 1))\n case \"month_year\":\n return new Intl.DateTimeFormat(locale, { month, year: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, 1)\n )\n case \"day_month\":\n return new Intl.DateTimeFormat(locale, { month, day: \"numeric\" }).format(\n new Date(2000, monthIndex, parsed.day!)\n )\n case \"full\":\n return new Intl.DateTimeFormat(locale, { year: \"numeric\", month, day: \"numeric\" }).format(\n new Date(parsed.year!, monthIndex, parsed.day!)\n )\n }\n}\n","/**\n * Helpers for verifying outbound webhooks fired by the CMS.\n *\n * The CMS POSTs JSON to subscriber URLs and signs the raw body with\n * HMAC-SHA256 using the shared secret you set in the Webhooks tab. The hex\n * digest arrives in the `X-CMS-Signature` header.\n *\n * Use Web Crypto so this works in Node, Edge, Deno, and Bun runtimes.\n */\n\nexport interface WebhookEventPayload {\n event: string\n tenant_id: string\n content_type_slug?: string\n content_item_id?: string\n slug?: string\n title?: string\n status?: string\n /** Stable identifier of the resource that changed (e.g. product id, flipbook id, integration provider). */\n resource_id?: string\n /**\n * Cache tags the receiver should invalidate. Use {@link revalidateAllTags}\n * to wire this through Next.js's `revalidateTag()` in one line.\n * All tags are namespaced with the `cms:` prefix.\n */\n cache_tags?: string[]\n /** Free-form bag for event-specific extras (e.g. provider name, change counts). */\n data?: Record<string, unknown>\n timestamp: string\n /** Commerce + custom events may attach extra top-level fields. */\n [key: string]: unknown\n}\n\n/**\n * Verify the HMAC-SHA256 signature on a webhook delivery.\n *\n * Pass the **raw** request body (not a parsed JSON object) — re-stringifying\n * a parsed body can change whitespace and invalidate the signature.\n *\n * Returns `true` when the signature matches in constant time, `false`\n * otherwise. Never throws on a bad signature; only throws if the\n * `crypto.subtle` API is unavailable in the runtime.\n *\n * @example\n * const raw = await req.text()\n * const sig = req.headers.get(\"x-cms-signature\")\n * if (!await verifyWebhookSignature(process.env.CMS_WEBHOOK_SECRET!, raw, sig)) {\n * return new Response(\"bad signature\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n */\nexport async function verifyWebhookSignature(\n secret: string,\n rawBody: string,\n signature: string | null | undefined\n): Promise<boolean> {\n if (!signature || !secret) return false\n\n const subtle = (globalThis.crypto && globalThis.crypto.subtle) || null\n if (!subtle) {\n throw new Error(\n \"verifyWebhookSignature requires the Web Crypto API (globalThis.crypto.subtle). \" +\n \"Available in Node 18+, all Edge runtimes, Deno, and Bun.\"\n )\n }\n\n const encoder = new TextEncoder()\n const key = await subtle.importKey(\n \"raw\",\n encoder.encode(secret),\n { name: \"HMAC\", hash: \"SHA-256\" },\n false,\n [\"sign\"]\n )\n const sigBuffer = await subtle.sign(\"HMAC\", key, encoder.encode(rawBody))\n const expected = bufferToHex(sigBuffer)\n\n return timingSafeEqualHex(expected, signature.trim())\n}\n\n/**\n * The webhook event names the CMS can fire. Use as a discriminator on the\n * `event` field of {@link WebhookEventPayload}.\n *\n * Most receivers don't need to switch on the event name — every payload\n * carries a `cache_tags` array. Pass it to {@link revalidateAllTags} to\n * invalidate the right Next.js caches in one line.\n */\nexport const WEBHOOK_EVENTS = [\n // Content\n \"content.published\",\n \"content.unpublished\",\n \"content.updated\",\n \"content.deleted\",\n \"content_type.updated\",\n \"content_type.deleted\",\n // Settings (diffed — only fires when a relevant field actually changed)\n \"settings.tracking_updated\",\n \"settings.brand_updated\",\n \"settings.integration_updated\",\n \"settings.mapbox_updated\",\n // Commerce\n \"products.updated\",\n \"product_categories.updated\",\n \"ticket_tiers.updated\",\n \"membership_tiers.updated\",\n \"order.created\",\n \"order.paid\",\n \"order.payment_failed\",\n \"order.refunded\",\n \"order.shipped\",\n \"booking.confirmed\",\n \"inventory.low_stock\",\n // Site\n \"redirects.updated\",\n \"reviews.synced\",\n \"flipbook.ready\",\n] as const\n\nexport type WebhookEvent = (typeof WEBHOOK_EVENTS)[number]\n\n/**\n * Invalidate every cache tag listed in a webhook payload. Call this from your\n * receiver and most events will Just Work without per-event branching.\n *\n * Pass Next.js's `revalidateTag` (or any function with the same shape) — the\n * SDK has no peer dep on `next/cache`, so the import stays in your code.\n *\n * **Next 16 compatibility.** In Next 16, `revalidateTag(tag)` was made into\n * `revalidateTag(tag, profile)`, and calling it with one argument emits a\n * deprecation warning. The cache profile controls expiry — `\"default\"` and\n * `\"max\"` both have non-zero `expire` values and will **not** invalidate the\n * cache. Immediate invalidation requires `{ expire: 0 }`, which isn't\n * documented in the function reference. This helper always passes\n * `{ expire: 0 }` as the second argument, so it does the right thing on Next 16\n * and is silently ignored by Next 14/15.\n *\n * @example\n * import { revalidateTag } from \"next/cache\"\n * import { revalidateAllTags } from \"@distinctagency/cms-client\"\n *\n * export async function POST(req: Request) {\n * const raw = await req.text()\n * if (!await verifyWebhookSignature(SECRET, raw, req.headers.get(\"x-cms-signature\"))) {\n * return new Response(\"bad sig\", { status: 401 })\n * }\n * const payload = JSON.parse(raw) as WebhookEventPayload\n * revalidateAllTags(payload, revalidateTag)\n * return Response.json({ ok: true })\n * }\n */\nexport function revalidateAllTags(\n payload: Pick<WebhookEventPayload, \"cache_tags\">,\n revalidateTag: (tag: string, profile: { expire?: number }) => unknown\n): string[] {\n const tags = payload.cache_tags\n if (!Array.isArray(tags) || tags.length === 0) return []\n const invalidated: string[] = []\n for (const tag of tags) {\n if (typeof tag !== \"string\" || tag.length === 0) continue\n revalidateTag(tag, { expire: 0 })\n invalidated.push(tag)\n }\n return invalidated\n}\n\nfunction bufferToHex(buf: ArrayBuffer): string {\n const bytes = new Uint8Array(buf)\n let out = \"\"\n for (let i = 0; i < bytes.length; i++) {\n out += bytes[i].toString(16).padStart(2, \"0\")\n }\n return out\n}\n\n/**\n * Constant-time equality check on two hex strings. Returns false fast when\n * lengths differ — the length itself is not secret.\n */\nfunction timingSafeEqualHex(a: string, b: string): boolean {\n if (a.length !== b.length) return false\n let mismatch = 0\n for (let i = 0; i < a.length; i++) {\n mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i)\n }\n return mismatch === 0\n}\n"],"mappings":";AAOO,IAAM,qBAAqB;;;ACPlC,SAAS,gBAAgB,4BAA4B;;;ACarD,IAAM,kBAAkB;AAOxB,IAAM,WAAW,oBAAI,IAA0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,KAAK;AACjC,gBAAY,EAAE,WAAW,CAAC,IAAI,EAAE,WAAW,CAAC;AAAA,EAC9C;AACA,SAAO,aAAa;AACtB;","names":["options","query","data","error","DEFAULT_APP_URL","DEFAULT_APP_URL","options"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@distinctagency/cms-client",
3
- "version": "1.22.0",
3
+ "version": "1.24.0",
4
4
  "description": "Client library for Distinct CMS — query content, products, and manage orders",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",