@01.software/sdk 0.51.0 → 0.65.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.
Files changed (67) hide show
  1. package/CHANGELOG.md +313 -0
  2. package/README.md +228 -102
  3. package/dist/client.cjs +556 -60
  4. package/dist/client.cjs.map +1 -1
  5. package/dist/client.d.cts +6 -6
  6. package/dist/client.d.ts +6 -6
  7. package/dist/client.js +556 -60
  8. package/dist/client.js.map +1 -1
  9. package/dist/{collection-client-CWAeuzV4.d.cts → collection-client-B7rsTtVj.d.cts} +6 -6
  10. package/dist/{collection-client-hYvVfHIm.d.ts → collection-client-C2sMvfme.d.ts} +6 -6
  11. package/dist/{const-JD8obaKg.d.ts → const-CRxPTDGt.d.ts} +2 -2
  12. package/dist/{const-D8LixhAJ.d.cts → const-D6ZRQLxI.d.cts} +2 -2
  13. package/dist/{index-B0Hjh3Ey.d.ts → index-1auUEYrl.d.ts} +24 -7
  14. package/dist/{index-Bu0kCc6o.d.cts → index-Bbpf5t-l.d.cts} +24 -7
  15. package/dist/index.cjs +573 -260
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.d.cts +19 -12
  18. package/dist/index.d.ts +19 -12
  19. package/dist/index.js +573 -260
  20. package/dist/index.js.map +1 -1
  21. package/dist/{payload-types-BOsckg8B.d.cts → payload-types-BnIET0xU.d.cts} +567 -438
  22. package/dist/{payload-types-BOsckg8B.d.ts → payload-types-BnIET0xU.d.ts} +567 -438
  23. package/dist/query.cjs +62 -3
  24. package/dist/query.cjs.map +1 -1
  25. package/dist/query.d.cts +5 -5
  26. package/dist/query.d.ts +5 -5
  27. package/dist/query.js +62 -3
  28. package/dist/query.js.map +1 -1
  29. package/dist/realtime.d.cts +2 -2
  30. package/dist/realtime.d.ts +2 -2
  31. package/dist/server.cjs +557 -20
  32. package/dist/server.cjs.map +1 -1
  33. package/dist/server.d.cts +14 -8
  34. package/dist/server.d.ts +14 -8
  35. package/dist/server.js +557 -20
  36. package/dist/server.js.map +1 -1
  37. package/dist/{types-5ZlcAFuU.d.ts → types-D1y4TgQm.d.ts} +2 -2
  38. package/dist/{types-Bj8j7VHU.d.ts → types-DnRC3nLG.d.ts} +464 -16
  39. package/dist/{types-B14sEt1z.d.cts → types-Dp1oYpD3.d.cts} +2 -2
  40. package/dist/{types-CM5qiR2k.d.cts → types-Dzn0LD2N.d.cts} +464 -16
  41. package/dist/ui/form.d.cts +1 -1
  42. package/dist/ui/form.d.ts +1 -1
  43. package/dist/ui/video.cjs +4 -2
  44. package/dist/ui/video.cjs.map +1 -1
  45. package/dist/ui/video.d.cts +4 -2
  46. package/dist/ui/video.d.ts +4 -2
  47. package/dist/ui/video.js +4 -2
  48. package/dist/ui/video.js.map +1 -1
  49. package/dist/webhook.cjs +13 -2
  50. package/dist/webhook.cjs.map +1 -1
  51. package/dist/webhook.d.cts +5 -5
  52. package/dist/webhook.d.ts +5 -5
  53. package/dist/webhook.js +13 -2
  54. package/dist/webhook.js.map +1 -1
  55. package/package.json +9 -28
  56. package/dist/analytics/react.cjs +0 -344
  57. package/dist/analytics/react.cjs.map +0 -1
  58. package/dist/analytics/react.d.cts +0 -24
  59. package/dist/analytics/react.d.ts +0 -24
  60. package/dist/analytics/react.js +0 -319
  61. package/dist/analytics/react.js.map +0 -1
  62. package/dist/analytics.cjs +0 -238
  63. package/dist/analytics.cjs.map +0 -1
  64. package/dist/analytics.d.cts +0 -39
  65. package/dist/analytics.d.ts +0 -39
  66. package/dist/analytics.js +0 -215
  67. package/dist/analytics.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { F as Form } from '../payload-types-BOsckg8B.cjs';
2
+ import { F as Form } from '../payload-types-BnIET0xU.cjs';
3
3
  import { RichTextData } from './rich-text.cjs';
4
4
  import '@payloadcms/richtext-lexical';
5
5
  import '@payloadcms/richtext-lexical/lexical';
package/dist/ui/form.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { F as Form } from '../payload-types-BOsckg8B.js';
2
+ import { F as Form } from '../payload-types-BnIET0xU.js';
3
3
  import { RichTextData } from './rich-text.js';
4
4
  import '@payloadcms/richtext-lexical';
5
5
  import '@payloadcms/richtext-lexical/lexical';
package/dist/ui/video.cjs CHANGED
@@ -93,6 +93,7 @@ function resolvePoster(props) {
93
93
  if (url) return url;
94
94
  }
95
95
  }
96
+ if (props.streamUrl) return void 0;
96
97
  const playbackId = resolvePlaybackId(props.video);
97
98
  if (!playbackId) return void 0;
98
99
  return getVideoThumbnail(playbackId, {
@@ -112,6 +113,7 @@ var VideoPlayer = (0, import_react.forwardRef)(
112
113
  function VideoPlayer2(props, ref) {
113
114
  const {
114
115
  video,
116
+ streamUrl,
115
117
  accentColor,
116
118
  primaryColor,
117
119
  secondaryColor,
@@ -142,7 +144,7 @@ var VideoPlayer = (0, import_react.forwardRef)(
142
144
  const poster = resolvePoster(props);
143
145
  const aspectRatio = resolveAspectRatio(video);
144
146
  const status = resolveStatus(video);
145
- if (!playbackId || typeof video !== "string" && status !== "ready") {
147
+ if (!streamUrl && !playbackId || typeof video !== "string" && status !== "ready") {
146
148
  return /* @__PURE__ */ import_react.default.createElement(
147
149
  "div",
148
150
  {
@@ -166,7 +168,7 @@ var VideoPlayer = (0, import_react.forwardRef)(
166
168
  import_mux_player_react.default,
167
169
  {
168
170
  ref,
169
- playbackId,
171
+ ...streamUrl ? { src: streamUrl } : { playbackId },
170
172
  streamType,
171
173
  accentColor,
172
174
  primaryColor,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ui/Video/index.tsx","../../src/utils/video.ts"],"sourcesContent":["'use client'\n\nimport React, { forwardRef, type CSSProperties } from 'react'\nimport MuxPlayer from '@mux/mux-player-react'\nimport type {\n MuxPlayerRefAttributes,\n MuxPlayerProps,\n} from '@mux/mux-player-react'\nimport type { Video, Image } from '../../payload-types'\nimport { getVideoThumbnail } from '../../utils/video'\n\n// Re-export video utilities for convenience\nexport {\n getVideoThumbnail,\n getVideoGif,\n getVideoStreamUrl,\n getVideoMp4Url,\n getVideoStoryboard,\n type VideoThumbnailOptions,\n type VideoGifOptions,\n} from '../../utils/video'\n\n// ── CSS custom properties ──\n\nexport interface VideoPlayerCSSProperties extends CSSProperties {\n [key: `--${string}`]: string | undefined\n}\n\n// ── Props ──\n\nexport interface VideoPlayerProps {\n /** Video document or playbackId string */\n video: Video | string\n\n // ── Theming ──\n /** Theme accent color */\n accentColor?: string\n /** Theme primary color (controls) */\n primaryColor?: string\n /** Theme secondary color (time display, etc.) */\n secondaryColor?: string\n\n // ── Playback ──\n /** Title overlay (auto-resolved from Video.title if omitted) */\n title?: string\n /** Autoplay behavior */\n autoPlay?: boolean | 'muted' | 'any'\n /** Loop playback */\n loop?: boolean\n /** Muted by default */\n muted?: boolean\n /** Preload strategy (default: 'metadata') */\n preload?: 'auto' | 'metadata' | 'none'\n /** Start time in seconds */\n startTime?: number\n /** Stream type (default: 'on-demand') */\n streamType?: 'on-demand' | 'live' | 'll-live'\n /** Audio-only mode */\n audio?: boolean\n /** Disable keyboard shortcuts */\n noHotKeys?: boolean\n /** Max resolution cap */\n maxResolution?: '720p' | '1080p' | '1440p' | '2160p'\n\n // ── Poster ──\n /** Thumbnail time for auto-generated poster (default: 0) */\n thumbnailTime?: number\n /** Custom poster URL (overrides auto-generated thumbnail) */\n poster?: string\n\n // ── Placeholder (when video not ready) ──\n /** Placeholder text when video is not ready */\n placeholder?: string\n /** CSS class for the placeholder */\n placeholderClassName?: string\n /** Inline styles for the placeholder */\n placeholderStyle?: CSSProperties\n\n // ── Styling ──\n /** CSS class */\n className?: string\n /** Inline styles (supports --mux CSS custom properties) */\n style?: VideoPlayerCSSProperties\n\n // ── Events ──\n onPlay?: () => void\n onPause?: () => void\n onEnded?: () => void\n onTimeUpdate?: () => void\n onLoadedData?: () => void\n onError?: () => void\n\n // ── Escape hatch ──\n /** Extra props forwarded directly to MuxPlayer */\n playerProps?: Omit<\n MuxPlayerProps,\n | 'playbackId'\n | 'streamType'\n | 'accentColor'\n | 'primaryColor'\n | 'secondaryColor'\n | 'title'\n | 'autoPlay'\n | 'loop'\n | 'muted'\n | 'preload'\n | 'startTime'\n | 'poster'\n | 'audio'\n | 'nohotkeys'\n | 'maxResolution'\n | 'className'\n | 'style'\n >\n}\n\n// ── Helpers ──\n\nfunction resolvePlaybackId(video: Video | string): string | null {\n if (typeof video === 'string') return video\n return video.muxPlaybackId ?? null\n}\n\nfunction resolveTitle(props: VideoPlayerProps): string | undefined {\n if (props.title !== undefined) return props.title\n if (typeof props.video !== 'string') return props.video.title ?? undefined\n return undefined\n}\n\nfunction resolvePoster(props: VideoPlayerProps): string | undefined {\n // 1. Explicit poster URL (highest priority)\n if (props.poster) return props.poster\n\n // 2. Video.thumbnail uploaded image\n if (typeof props.video !== 'string' && props.video.thumbnail) {\n const thumb = props.video.thumbnail\n if (typeof thumb === 'object' && thumb !== null && 'url' in thumb) {\n const url = (thumb as Image).url\n if (url) return url\n }\n }\n\n // 3. Auto-generate from Mux image API\n const playbackId = resolvePlaybackId(props.video)\n if (!playbackId) return undefined\n return getVideoThumbnail(playbackId, {\n width: 1280,\n time: props.thumbnailTime ?? 0,\n })\n}\n\nfunction resolveAspectRatio(video: Video | string): string | undefined {\n if (typeof video === 'string') return undefined\n return video.aspectRatio ?? undefined\n}\n\nfunction resolveStatus(video: Video | string): string {\n if (typeof video === 'string') return 'ready'\n return video.muxStatus ?? 'waiting'\n}\n\n// ── Component ──\n\n/**\n * Mux video player component.\n * Requires `@mux/mux-player-react` (optional peer dependency).\n *\n * @example Basic usage\n * ```tsx\n * import { VideoPlayer } from '@01.software/sdk/ui/video'\n *\n * <VideoPlayer video={videoDoc} />\n * ```\n *\n * @example With playback ID string\n * ```tsx\n * <VideoPlayer video=\"abc123def\" autoPlay=\"muted\" loop />\n * ```\n *\n * @example Custom theming with CSS custom properties\n * ```tsx\n * <VideoPlayer\n * video={videoDoc}\n * accentColor=\"#f43f5e\"\n * primaryColor=\"#fff\"\n * className=\"rounded-lg overflow-hidden\"\n * style={{ '--controls-backdrop-color': 'rgba(0,0,0,0.6)' }}\n * />\n * ```\n *\n * @example Audio-only mode\n * ```tsx\n * <VideoPlayer video={videoDoc} audio />\n * ```\n */\nexport const VideoPlayer: React.ForwardRefExoticComponent<\n VideoPlayerProps & React.RefAttributes<MuxPlayerRefAttributes>\n> = forwardRef<MuxPlayerRefAttributes, VideoPlayerProps>(\n function VideoPlayer(props, ref) {\n const {\n video,\n accentColor,\n primaryColor,\n secondaryColor,\n autoPlay,\n loop,\n muted,\n preload = 'metadata',\n startTime,\n streamType = 'on-demand',\n audio,\n noHotKeys,\n maxResolution,\n placeholder,\n placeholderClassName,\n placeholderStyle,\n className,\n style,\n onPlay,\n onPause,\n onEnded,\n onTimeUpdate,\n onLoadedData,\n onError,\n playerProps,\n } = props\n\n const playbackId = resolvePlaybackId(video)\n const title = resolveTitle(props)\n const poster = resolvePoster(props)\n const aspectRatio = resolveAspectRatio(video)\n const status = resolveStatus(video)\n\n // Show placeholder when no playbackId or video not ready\n if (!playbackId || (typeof video !== 'string' && status !== 'ready')) {\n return (\n <div\n className={placeholderClassName ?? className}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n aspectRatio: aspectRatio ?? '16/9',\n backgroundColor: '#000',\n color: '#888',\n fontSize: 14,\n width: '100%',\n ...placeholderStyle,\n }}\n >\n {placeholder ??\n (status === 'preparing'\n ? 'Video is processing...'\n : status === 'errored'\n ? 'Video processing failed'\n : 'Video not available')}\n </div>\n )\n }\n\n return (\n <MuxPlayer\n ref={ref}\n playbackId={playbackId}\n streamType={streamType}\n accentColor={accentColor}\n primaryColor={primaryColor}\n secondaryColor={secondaryColor}\n title={title}\n autoPlay={autoPlay}\n loop={loop}\n muted={muted}\n preload={preload}\n startTime={startTime}\n poster={poster}\n audio={audio}\n nohotkeys={noHotKeys}\n maxResolution={maxResolution}\n className={className}\n style={{\n aspectRatio: aspectRatio ?? '16/9',\n width: '100%',\n ...style,\n }}\n onPlay={onPlay}\n onPause={onPause}\n onEnded={onEnded}\n onTimeUpdate={onTimeUpdate}\n onLoadedData={onLoadedData}\n onError={onError}\n {...playerProps}\n />\n )\n },\n)\n\n// ── Type Exports ──\n\nexport type { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react'\nexport type { Video as VideoData } from '../../payload-types'\n","const MUX_IMAGE_BASE = 'https://image.mux.com'\nconst MUX_STREAM_BASE = 'https://stream.mux.com'\n\n// ── Thumbnail ──\n\nexport interface VideoThumbnailOptions {\n /** Width in pixels (default: 640) */\n width?: number\n /** Height in pixels (auto if omitted) */\n height?: number\n /** Time offset in seconds (default: 0) */\n time?: number\n /** Fit mode (default: 'smartcrop') */\n fitMode?: 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'pad'\n /** Flip horizontally */\n flipH?: boolean\n /** Flip vertically */\n flipV?: boolean\n /** Rotation in degrees (90, 180, 270) */\n rotate?: 90 | 180 | 270\n}\n\n/**\n * Returns a Mux thumbnail URL for a video.\n *\n * @example\n * ```ts\n * getVideoThumbnail('abc123')\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=640'\n *\n * getVideoThumbnail('abc123', { width: 320, time: 5 })\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=320&time=5'\n * ```\n */\nexport function getVideoThumbnail(\n playbackId: string,\n options?: VideoThumbnailOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 640))\n if (options?.height) params.set('height', String(options.height))\n if (options?.time != null) params.set('time', String(options.time))\n if (options?.fitMode) params.set('fit_mode', options.fitMode)\n if (options?.flipH) params.set('flip_h', 'true')\n if (options?.flipV) params.set('flip_v', 'true')\n if (options?.rotate) params.set('rotate', String(options.rotate))\n return `${MUX_IMAGE_BASE}/${playbackId}/thumbnail.jpg?${params}`\n}\n\n// ── Animated GIF ──\n\nexport interface VideoGifOptions {\n /** Width in pixels (default: 320) */\n width?: number\n /** Start time in seconds (default: 0) */\n start?: number\n /** End time in seconds (default: start + 5) */\n end?: number\n /** Frames per second (default: 15) */\n fps?: number\n}\n\n/**\n * Returns a Mux animated GIF URL for a video.\n *\n * @example\n * ```ts\n * getVideoGif('abc123')\n * // => 'https://image.mux.com/abc123/animated.gif?width=320'\n *\n * getVideoGif('abc123', { width: 240, start: 2, end: 6 })\n * // => 'https://image.mux.com/abc123/animated.gif?width=240&start=2&end=6'\n * ```\n */\nexport function getVideoGif(\n playbackId: string,\n options?: VideoGifOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 320))\n if (options?.start != null) params.set('start', String(options.start))\n if (options?.end != null) params.set('end', String(options.end))\n if (options?.fps) params.set('fps', String(options.fps))\n return `${MUX_IMAGE_BASE}/${playbackId}/animated.gif?${params}`\n}\n\n// ── Storyboard ──\n\n/**\n * Returns a Mux storyboard VTT URL for timeline hover previews.\n *\n * @example\n * ```ts\n * getVideoStoryboard('abc123')\n * // => 'https://image.mux.com/abc123/storyboard.vtt'\n * ```\n */\nexport function getVideoStoryboard(playbackId: string): string {\n return `${MUX_IMAGE_BASE}/${playbackId}/storyboard.vtt`\n}\n\n// ── Stream / Playback URLs ──\n\n/**\n * Returns the HLS stream URL for a video.\n *\n * @example\n * ```ts\n * getVideoStreamUrl('abc123')\n * // => 'https://stream.mux.com/abc123.m3u8'\n * ```\n */\nexport function getVideoStreamUrl(playbackId: string): string {\n return `${MUX_STREAM_BASE}/${playbackId}.m3u8`\n}\n\n/**\n * Returns a Mux MP4 download URL for a video.\n * Only available if the asset was created with `mp4_support` enabled.\n *\n * @example\n * ```ts\n * getVideoMp4Url('abc123', 'high')\n * // => 'https://stream.mux.com/abc123/high.mp4'\n * ```\n */\nexport function getVideoMp4Url(\n playbackId: string,\n resolution: 'high' | 'medium' | 'low' = 'high',\n): string {\n return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,UAAM,aAAa,kBAAkB,KAAK;AAC1C,UAAM,QAAQ,aAAa,KAAK;AAChC,UAAM,SAAS,cAAc,KAAK;AAClC,UAAM,cAAc,mBAAmB,KAAK;AAC5C,UAAM,SAAS,cAAc,KAAK;AAGlC,QAAI,CAAC,cAAe,OAAO,UAAU,YAAY,WAAW,SAAU;AACpE,aACE,6BAAAC,QAAA;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,wBAAwB;AAAA,UACnC,OAAO;AAAA,YACL,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,gBAAgB;AAAA,YAChB,aAAa,eAAe;AAAA,YAC5B,iBAAiB;AAAA,YACjB,OAAO;AAAA,YACP,UAAU;AAAA,YACV,OAAO;AAAA,YACP,GAAG;AAAA,UACL;AAAA;AAAA,QAEC,gBACE,WAAW,cACR,2BACA,WAAW,YACT,4BACA;AAAA,MACV;AAAA,IAEJ;AAEA,WACE,6BAAAA,QAAA;AAAA,MAAC,wBAAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,OAAO;AAAA,UACL,aAAa,eAAe;AAAA,UAC5B,OAAO;AAAA,UACP,GAAG;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACF;","names":["VideoPlayer","React","MuxPlayer"]}
1
+ {"version":3,"sources":["../../src/ui/Video/index.tsx","../../src/utils/video.ts"],"sourcesContent":["'use client'\n\nimport React, { forwardRef, type CSSProperties } from 'react'\nimport MuxPlayer from '@mux/mux-player-react'\nimport type {\n MuxPlayerRefAttributes,\n MuxPlayerProps,\n} from '@mux/mux-player-react'\nimport type { Video, Image } from '../../payload-types'\nimport { getVideoThumbnail } from '../../utils/video'\n\n// Re-export video utilities for convenience\nexport {\n getVideoThumbnail,\n getVideoGif,\n getVideoStreamUrl,\n getVideoMp4Url,\n getVideoStoryboard,\n type VideoThumbnailOptions,\n type VideoGifOptions,\n} from '../../utils/video'\n\n// ── CSS custom properties ──\n\nexport interface VideoPlayerCSSProperties extends CSSProperties {\n [key: `--${string}`]: string | undefined\n}\n\n// ── Props ──\n\nexport interface VideoPlayerProps {\n /** Video document or playbackId string */\n video: Video | string\n /** HLS URL from client.video.playback(video.id); required for gated Free VOD. */\n streamUrl?: string\n\n // ── Theming ──\n /** Theme accent color */\n accentColor?: string\n /** Theme primary color (controls) */\n primaryColor?: string\n /** Theme secondary color (time display, etc.) */\n secondaryColor?: string\n\n // ── Playback ──\n /** Title overlay (auto-resolved from Video.title if omitted) */\n title?: string\n /** Autoplay behavior */\n autoPlay?: boolean | 'muted' | 'any'\n /** Loop playback */\n loop?: boolean\n /** Muted by default */\n muted?: boolean\n /** Preload strategy (default: 'metadata') */\n preload?: 'auto' | 'metadata' | 'none'\n /** Start time in seconds */\n startTime?: number\n /** Stream type (default: 'on-demand') */\n streamType?: 'on-demand' | 'live' | 'll-live'\n /** Audio-only mode */\n audio?: boolean\n /** Disable keyboard shortcuts */\n noHotKeys?: boolean\n /** Max resolution cap */\n maxResolution?: '720p' | '1080p' | '1440p' | '2160p'\n\n // ── Poster ──\n /** Thumbnail time for auto-generated poster (default: 0) */\n thumbnailTime?: number\n /** Custom poster URL (overrides auto-generated thumbnail) */\n poster?: string\n\n // ── Placeholder (when video not ready) ──\n /** Placeholder text when video is not ready */\n placeholder?: string\n /** CSS class for the placeholder */\n placeholderClassName?: string\n /** Inline styles for the placeholder */\n placeholderStyle?: CSSProperties\n\n // ── Styling ──\n /** CSS class */\n className?: string\n /** Inline styles (supports --mux CSS custom properties) */\n style?: VideoPlayerCSSProperties\n\n // ── Events ──\n onPlay?: () => void\n onPause?: () => void\n onEnded?: () => void\n onTimeUpdate?: () => void\n onLoadedData?: () => void\n onError?: () => void\n\n // ── Escape hatch ──\n /** Extra props forwarded directly to MuxPlayer */\n playerProps?: Omit<\n MuxPlayerProps,\n | 'playbackId'\n | 'src'\n | 'streamType'\n | 'accentColor'\n | 'primaryColor'\n | 'secondaryColor'\n | 'title'\n | 'autoPlay'\n | 'loop'\n | 'muted'\n | 'preload'\n | 'startTime'\n | 'poster'\n | 'audio'\n | 'nohotkeys'\n | 'maxResolution'\n | 'className'\n | 'style'\n >\n}\n\n// ── Helpers ──\n\nfunction resolvePlaybackId(video: Video | string): string | null {\n if (typeof video === 'string') return video\n return video.muxPlaybackId ?? null\n}\n\nfunction resolveTitle(props: VideoPlayerProps): string | undefined {\n if (props.title !== undefined) return props.title\n if (typeof props.video !== 'string') return props.video.title ?? undefined\n return undefined\n}\n\nfunction resolvePoster(props: VideoPlayerProps): string | undefined {\n // 1. Explicit poster URL (highest priority)\n if (props.poster) return props.poster\n\n // 2. Video.thumbnail uploaded image\n if (typeof props.video !== 'string' && props.video.thumbnail) {\n const thumb = props.video.thumbnail\n if (typeof thumb === 'object' && thumb !== null && 'url' in thumb) {\n const url = (thumb as Image).url\n if (url) return url\n }\n }\n\n // 3. Auto-generate from Mux image API\n if (props.streamUrl) return undefined\n const playbackId = resolvePlaybackId(props.video)\n if (!playbackId) return undefined\n return getVideoThumbnail(playbackId, {\n width: 1280,\n time: props.thumbnailTime ?? 0,\n })\n}\n\nfunction resolveAspectRatio(video: Video | string): string | undefined {\n if (typeof video === 'string') return undefined\n return video.aspectRatio ?? undefined\n}\n\nfunction resolveStatus(video: Video | string): string {\n if (typeof video === 'string') return 'ready'\n return video.muxStatus ?? 'waiting'\n}\n\n// ── Component ──\n\n/**\n * Mux video player component.\n * Requires `@mux/mux-player-react` (optional peer dependency).\n *\n * @example Basic usage\n * ```tsx\n * import { VideoPlayer } from '@01.software/sdk/ui/video'\n *\n * <VideoPlayer video={videoDoc} />\n * ```\n *\n * @example With playback ID string\n * ```tsx\n * <VideoPlayer video=\"abc123def\" autoPlay=\"muted\" loop />\n * ```\n *\n * @example Custom theming with CSS custom properties\n * ```tsx\n * <VideoPlayer\n * video={videoDoc}\n * accentColor=\"#f43f5e\"\n * primaryColor=\"#fff\"\n * className=\"rounded-lg overflow-hidden\"\n * style={{ '--controls-backdrop-color': 'rgba(0,0,0,0.6)' }}\n * />\n * ```\n *\n * @example Audio-only mode\n * ```tsx\n * <VideoPlayer video={videoDoc} audio />\n * ```\n */\nexport const VideoPlayer: React.ForwardRefExoticComponent<\n VideoPlayerProps & React.RefAttributes<MuxPlayerRefAttributes>\n> = forwardRef<MuxPlayerRefAttributes, VideoPlayerProps>(\n function VideoPlayer(props, ref) {\n const {\n video,\n streamUrl,\n accentColor,\n primaryColor,\n secondaryColor,\n autoPlay,\n loop,\n muted,\n preload = 'metadata',\n startTime,\n streamType = 'on-demand',\n audio,\n noHotKeys,\n maxResolution,\n placeholder,\n placeholderClassName,\n placeholderStyle,\n className,\n style,\n onPlay,\n onPause,\n onEnded,\n onTimeUpdate,\n onLoadedData,\n onError,\n playerProps,\n } = props\n\n const playbackId = resolvePlaybackId(video)\n const title = resolveTitle(props)\n const poster = resolvePoster(props)\n const aspectRatio = resolveAspectRatio(video)\n const status = resolveStatus(video)\n\n // Show placeholder when no playbackId or video not ready\n if (\n (!streamUrl && !playbackId) ||\n (typeof video !== 'string' && status !== 'ready')\n ) {\n return (\n <div\n className={placeholderClassName ?? className}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n aspectRatio: aspectRatio ?? '16/9',\n backgroundColor: '#000',\n color: '#888',\n fontSize: 14,\n width: '100%',\n ...placeholderStyle,\n }}\n >\n {placeholder ??\n (status === 'preparing'\n ? 'Video is processing...'\n : status === 'errored'\n ? 'Video processing failed'\n : 'Video not available')}\n </div>\n )\n }\n\n return (\n <MuxPlayer\n ref={ref}\n {...(streamUrl ? { src: streamUrl } : { playbackId: playbackId! })}\n streamType={streamType}\n accentColor={accentColor}\n primaryColor={primaryColor}\n secondaryColor={secondaryColor}\n title={title}\n autoPlay={autoPlay}\n loop={loop}\n muted={muted}\n preload={preload}\n startTime={startTime}\n poster={poster}\n audio={audio}\n nohotkeys={noHotKeys}\n maxResolution={maxResolution}\n className={className}\n style={{\n aspectRatio: aspectRatio ?? '16/9',\n width: '100%',\n ...style,\n }}\n onPlay={onPlay}\n onPause={onPause}\n onEnded={onEnded}\n onTimeUpdate={onTimeUpdate}\n onLoadedData={onLoadedData}\n onError={onError}\n {...playerProps}\n />\n )\n },\n)\n\n// ── Type Exports ──\n\nexport type { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react'\nexport type { Video as VideoData } from '../../payload-types'\n","const MUX_IMAGE_BASE = 'https://image.mux.com'\nconst MUX_STREAM_BASE = 'https://stream.mux.com'\n\n// ── Thumbnail ──\n\nexport interface VideoThumbnailOptions {\n /** Width in pixels (default: 640) */\n width?: number\n /** Height in pixels (auto if omitted) */\n height?: number\n /** Time offset in seconds (default: 0) */\n time?: number\n /** Fit mode (default: 'smartcrop') */\n fitMode?: 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'pad'\n /** Flip horizontally */\n flipH?: boolean\n /** Flip vertically */\n flipV?: boolean\n /** Rotation in degrees (90, 180, 270) */\n rotate?: 90 | 180 | 270\n}\n\n/**\n * Returns a Mux thumbnail URL for a video.\n *\n * @example\n * ```ts\n * getVideoThumbnail('abc123')\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=640'\n *\n * getVideoThumbnail('abc123', { width: 320, time: 5 })\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=320&time=5'\n * ```\n */\nexport function getVideoThumbnail(\n playbackId: string,\n options?: VideoThumbnailOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 640))\n if (options?.height) params.set('height', String(options.height))\n if (options?.time != null) params.set('time', String(options.time))\n if (options?.fitMode) params.set('fit_mode', options.fitMode)\n if (options?.flipH) params.set('flip_h', 'true')\n if (options?.flipV) params.set('flip_v', 'true')\n if (options?.rotate) params.set('rotate', String(options.rotate))\n return `${MUX_IMAGE_BASE}/${playbackId}/thumbnail.jpg?${params}`\n}\n\n// ── Animated GIF ──\n\nexport interface VideoGifOptions {\n /** Width in pixels (default: 320) */\n width?: number\n /** Start time in seconds (default: 0) */\n start?: number\n /** End time in seconds (default: start + 5) */\n end?: number\n /** Frames per second (default: 15) */\n fps?: number\n}\n\n/**\n * Returns a Mux animated GIF URL for a video.\n *\n * @example\n * ```ts\n * getVideoGif('abc123')\n * // => 'https://image.mux.com/abc123/animated.gif?width=320'\n *\n * getVideoGif('abc123', { width: 240, start: 2, end: 6 })\n * // => 'https://image.mux.com/abc123/animated.gif?width=240&start=2&end=6'\n * ```\n */\nexport function getVideoGif(\n playbackId: string,\n options?: VideoGifOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 320))\n if (options?.start != null) params.set('start', String(options.start))\n if (options?.end != null) params.set('end', String(options.end))\n if (options?.fps) params.set('fps', String(options.fps))\n return `${MUX_IMAGE_BASE}/${playbackId}/animated.gif?${params}`\n}\n\n// ── Storyboard ──\n\n/**\n * Returns a Mux storyboard VTT URL for timeline hover previews.\n *\n * @example\n * ```ts\n * getVideoStoryboard('abc123')\n * // => 'https://image.mux.com/abc123/storyboard.vtt'\n * ```\n */\nexport function getVideoStoryboard(playbackId: string): string {\n return `${MUX_IMAGE_BASE}/${playbackId}/storyboard.vtt`\n}\n\n// ── Stream / Playback URLs ──\n\n/**\n * Returns the HLS stream URL for a video.\n *\n * @example\n * ```ts\n * getVideoStreamUrl('abc123')\n * // => 'https://stream.mux.com/abc123.m3u8'\n * ```\n */\nexport function getVideoStreamUrl(playbackId: string): string {\n return `${MUX_STREAM_BASE}/${playbackId}.m3u8`\n}\n\n/**\n * Returns a Mux MP4 download URL for a video.\n * Only available if the asset was created with `mp4_support` enabled.\n *\n * @example\n * ```ts\n * getVideoMp4Url('abc123', 'high')\n * // => 'https://stream.mux.com/abc123/high.mp4'\n * ```\n */\nexport function getVideoMp4Url(\n playbackId: string,\n resolution: 'high' | 'medium' | 'low' = 'high',\n): string {\n return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAsD;AACtD,8BAAsB;;;ACHtB,IAAM,iBAAiB;AACvB,IAAM,kBAAkB;AAiCjB,SAAS,kBACd,YACA,SACQ;AACR,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,SAAS,OAAO,SAAS,SAAS,GAAG,CAAC;AACjD,MAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,OAAO,QAAQ,MAAM,CAAC;AAChE,MAAI,SAAS,QAAQ,KAAM,QAAO,IAAI,QAAQ,OAAO,QAAQ,IAAI,CAAC;AAClE,MAAI,SAAS,QAAS,QAAO,IAAI,YAAY,QAAQ,OAAO;AAC5D,MAAI,SAAS,MAAO,QAAO,IAAI,UAAU,MAAM;AAC/C,MAAI,SAAS,MAAO,QAAO,IAAI,UAAU,MAAM;AAC/C,MAAI,SAAS,OAAQ,QAAO,IAAI,UAAU,OAAO,QAAQ,MAAM,CAAC;AAChE,SAAO,GAAG,cAAc,IAAI,UAAU,kBAAkB,MAAM;AAChE;AA2BO,SAAS,YACd,YACA,SACQ;AACR,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,SAAS,OAAO,SAAS,SAAS,GAAG,CAAC;AACjD,MAAI,SAAS,SAAS,KAAM,QAAO,IAAI,SAAS,OAAO,QAAQ,KAAK,CAAC;AACrE,MAAI,SAAS,OAAO,KAAM,QAAO,IAAI,OAAO,OAAO,QAAQ,GAAG,CAAC;AAC/D,MAAI,SAAS,IAAK,Q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WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,OAAO;AAAA,UACL,aAAa,eAAe;AAAA,UAC5B,OAAO;AAAA,UACP,GAAG;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACF;","names":["VideoPlayer","React","MuxPlayer"]}
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties } from 'react';
2
2
  import { MuxPlayerProps, MuxPlayerRefAttributes } from '@mux/mux-player-react';
3
3
  export { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react';
4
- import { V as Video } from '../payload-types-BOsckg8B.cjs';
4
+ import { V as Video } from '../payload-types-BnIET0xU.cjs';
5
5
  export { V as VideoGifOptions, a as VideoThumbnailOptions, g as getVideoGif, b as getVideoMp4Url, c as getVideoStoryboard, d as getVideoStreamUrl, e as getVideoThumbnail } from '../video-WR_TFO9a.cjs';
6
6
 
7
7
  interface VideoPlayerCSSProperties extends CSSProperties {
@@ -10,6 +10,8 @@ interface VideoPlayerCSSProperties extends CSSProperties {
10
10
  interface VideoPlayerProps {
11
11
  /** Video document or playbackId string */
12
12
  video: Video | string;
13
+ /** HLS URL from client.video.playback(video.id); required for gated Free VOD. */
14
+ streamUrl?: string;
13
15
  /** Theme accent color */
14
16
  accentColor?: string;
15
17
  /** Theme primary color (controls) */
@@ -57,7 +59,7 @@ interface VideoPlayerProps {
57
59
  onLoadedData?: () => void;
58
60
  onError?: () => void;
59
61
  /** Extra props forwarded directly to MuxPlayer */
60
- playerProps?: Omit<MuxPlayerProps, 'playbackId' | 'streamType' | 'accentColor' | 'primaryColor' | 'secondaryColor' | 'title' | 'autoPlay' | 'loop' | 'muted' | 'preload' | 'startTime' | 'poster' | 'audio' | 'nohotkeys' | 'maxResolution' | 'className' | 'style'>;
62
+ playerProps?: Omit<MuxPlayerProps, 'playbackId' | 'src' | 'streamType' | 'accentColor' | 'primaryColor' | 'secondaryColor' | 'title' | 'autoPlay' | 'loop' | 'muted' | 'preload' | 'startTime' | 'poster' | 'audio' | 'nohotkeys' | 'maxResolution' | 'className' | 'style'>;
61
63
  }
62
64
  /**
63
65
  * Mux video player component.
@@ -1,7 +1,7 @@
1
1
  import React, { CSSProperties } from 'react';
2
2
  import { MuxPlayerProps, MuxPlayerRefAttributes } from '@mux/mux-player-react';
3
3
  export { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react';
4
- import { V as Video } from '../payload-types-BOsckg8B.js';
4
+ import { V as Video } from '../payload-types-BnIET0xU.js';
5
5
  export { V as VideoGifOptions, a as VideoThumbnailOptions, g as getVideoGif, b as getVideoMp4Url, c as getVideoStoryboard, d as getVideoStreamUrl, e as getVideoThumbnail } from '../video-WR_TFO9a.js';
6
6
 
7
7
  interface VideoPlayerCSSProperties extends CSSProperties {
@@ -10,6 +10,8 @@ interface VideoPlayerCSSProperties extends CSSProperties {
10
10
  interface VideoPlayerProps {
11
11
  /** Video document or playbackId string */
12
12
  video: Video | string;
13
+ /** HLS URL from client.video.playback(video.id); required for gated Free VOD. */
14
+ streamUrl?: string;
13
15
  /** Theme accent color */
14
16
  accentColor?: string;
15
17
  /** Theme primary color (controls) */
@@ -57,7 +59,7 @@ interface VideoPlayerProps {
57
59
  onLoadedData?: () => void;
58
60
  onError?: () => void;
59
61
  /** Extra props forwarded directly to MuxPlayer */
60
- playerProps?: Omit<MuxPlayerProps, 'playbackId' | 'streamType' | 'accentColor' | 'primaryColor' | 'secondaryColor' | 'title' | 'autoPlay' | 'loop' | 'muted' | 'preload' | 'startTime' | 'poster' | 'audio' | 'nohotkeys' | 'maxResolution' | 'className' | 'style'>;
62
+ playerProps?: Omit<MuxPlayerProps, 'playbackId' | 'src' | 'streamType' | 'accentColor' | 'primaryColor' | 'secondaryColor' | 'title' | 'autoPlay' | 'loop' | 'muted' | 'preload' | 'startTime' | 'poster' | 'audio' | 'nohotkeys' | 'maxResolution' | 'className' | 'style'>;
61
63
  }
62
64
  /**
63
65
  * Mux video player component.
package/dist/ui/video.js CHANGED
@@ -55,6 +55,7 @@ function resolvePoster(props) {
55
55
  if (url) return url;
56
56
  }
57
57
  }
58
+ if (props.streamUrl) return void 0;
58
59
  const playbackId = resolvePlaybackId(props.video);
59
60
  if (!playbackId) return void 0;
60
61
  return getVideoThumbnail(playbackId, {
@@ -74,6 +75,7 @@ var VideoPlayer = forwardRef(
74
75
  function VideoPlayer2(props, ref) {
75
76
  const {
76
77
  video,
78
+ streamUrl,
77
79
  accentColor,
78
80
  primaryColor,
79
81
  secondaryColor,
@@ -104,7 +106,7 @@ var VideoPlayer = forwardRef(
104
106
  const poster = resolvePoster(props);
105
107
  const aspectRatio = resolveAspectRatio(video);
106
108
  const status = resolveStatus(video);
107
- if (!playbackId || typeof video !== "string" && status !== "ready") {
109
+ if (!streamUrl && !playbackId || typeof video !== "string" && status !== "ready") {
108
110
  return /* @__PURE__ */ React.createElement(
109
111
  "div",
110
112
  {
@@ -128,7 +130,7 @@ var VideoPlayer = forwardRef(
128
130
  MuxPlayer,
129
131
  {
130
132
  ref,
131
- playbackId,
133
+ ...streamUrl ? { src: streamUrl } : { playbackId },
132
134
  streamType,
133
135
  accentColor,
134
136
  primaryColor,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/ui/Video/index.tsx","../../src/utils/video.ts"],"sourcesContent":["'use client'\n\nimport React, { forwardRef, type CSSProperties } from 'react'\nimport MuxPlayer from '@mux/mux-player-react'\nimport type {\n MuxPlayerRefAttributes,\n MuxPlayerProps,\n} from '@mux/mux-player-react'\nimport type { Video, Image } from '../../payload-types'\nimport { getVideoThumbnail } from '../../utils/video'\n\n// Re-export video utilities for convenience\nexport {\n getVideoThumbnail,\n getVideoGif,\n getVideoStreamUrl,\n getVideoMp4Url,\n getVideoStoryboard,\n type VideoThumbnailOptions,\n type VideoGifOptions,\n} from '../../utils/video'\n\n// ── CSS custom properties ──\n\nexport interface VideoPlayerCSSProperties extends CSSProperties {\n [key: `--${string}`]: string | undefined\n}\n\n// ── Props ──\n\nexport interface VideoPlayerProps {\n /** Video document or playbackId string */\n video: Video | string\n\n // ── Theming ──\n /** Theme accent color */\n accentColor?: string\n /** Theme primary color (controls) */\n primaryColor?: string\n /** Theme secondary color (time display, etc.) */\n secondaryColor?: string\n\n // ── Playback ──\n /** Title overlay (auto-resolved from Video.title if omitted) */\n title?: string\n /** Autoplay behavior */\n autoPlay?: boolean | 'muted' | 'any'\n /** Loop playback */\n loop?: boolean\n /** Muted by default */\n muted?: boolean\n /** Preload strategy (default: 'metadata') */\n preload?: 'auto' | 'metadata' | 'none'\n /** Start time in seconds */\n startTime?: number\n /** Stream type (default: 'on-demand') */\n streamType?: 'on-demand' | 'live' | 'll-live'\n /** Audio-only mode */\n audio?: boolean\n /** Disable keyboard shortcuts */\n noHotKeys?: boolean\n /** Max resolution cap */\n maxResolution?: '720p' | '1080p' | '1440p' | '2160p'\n\n // ── Poster ──\n /** Thumbnail time for auto-generated poster (default: 0) */\n thumbnailTime?: number\n /** Custom poster URL (overrides auto-generated thumbnail) */\n poster?: string\n\n // ── Placeholder (when video not ready) ──\n /** Placeholder text when video is not ready */\n placeholder?: string\n /** CSS class for the placeholder */\n placeholderClassName?: string\n /** Inline styles for the placeholder */\n placeholderStyle?: CSSProperties\n\n // ── Styling ──\n /** CSS class */\n className?: string\n /** Inline styles (supports --mux CSS custom properties) */\n style?: VideoPlayerCSSProperties\n\n // ── Events ──\n onPlay?: () => void\n onPause?: () => void\n onEnded?: () => void\n onTimeUpdate?: () => void\n onLoadedData?: () => void\n onError?: () => void\n\n // ── Escape hatch ──\n /** Extra props forwarded directly to MuxPlayer */\n playerProps?: Omit<\n MuxPlayerProps,\n | 'playbackId'\n | 'streamType'\n | 'accentColor'\n | 'primaryColor'\n | 'secondaryColor'\n | 'title'\n | 'autoPlay'\n | 'loop'\n | 'muted'\n | 'preload'\n | 'startTime'\n | 'poster'\n | 'audio'\n | 'nohotkeys'\n | 'maxResolution'\n | 'className'\n | 'style'\n >\n}\n\n// ── Helpers ──\n\nfunction resolvePlaybackId(video: Video | string): string | null {\n if (typeof video === 'string') return video\n return video.muxPlaybackId ?? null\n}\n\nfunction resolveTitle(props: VideoPlayerProps): string | undefined {\n if (props.title !== undefined) return props.title\n if (typeof props.video !== 'string') return props.video.title ?? undefined\n return undefined\n}\n\nfunction resolvePoster(props: VideoPlayerProps): string | undefined {\n // 1. Explicit poster URL (highest priority)\n if (props.poster) return props.poster\n\n // 2. Video.thumbnail uploaded image\n if (typeof props.video !== 'string' && props.video.thumbnail) {\n const thumb = props.video.thumbnail\n if (typeof thumb === 'object' && thumb !== null && 'url' in thumb) {\n const url = (thumb as Image).url\n if (url) return url\n }\n }\n\n // 3. Auto-generate from Mux image API\n const playbackId = resolvePlaybackId(props.video)\n if (!playbackId) return undefined\n return getVideoThumbnail(playbackId, {\n width: 1280,\n time: props.thumbnailTime ?? 0,\n })\n}\n\nfunction resolveAspectRatio(video: Video | string): string | undefined {\n if (typeof video === 'string') return undefined\n return video.aspectRatio ?? undefined\n}\n\nfunction resolveStatus(video: Video | string): string {\n if (typeof video === 'string') return 'ready'\n return video.muxStatus ?? 'waiting'\n}\n\n// ── Component ──\n\n/**\n * Mux video player component.\n * Requires `@mux/mux-player-react` (optional peer dependency).\n *\n * @example Basic usage\n * ```tsx\n * import { VideoPlayer } from '@01.software/sdk/ui/video'\n *\n * <VideoPlayer video={videoDoc} />\n * ```\n *\n * @example With playback ID string\n * ```tsx\n * <VideoPlayer video=\"abc123def\" autoPlay=\"muted\" loop />\n * ```\n *\n * @example Custom theming with CSS custom properties\n * ```tsx\n * <VideoPlayer\n * video={videoDoc}\n * accentColor=\"#f43f5e\"\n * primaryColor=\"#fff\"\n * className=\"rounded-lg overflow-hidden\"\n * style={{ '--controls-backdrop-color': 'rgba(0,0,0,0.6)' }}\n * />\n * ```\n *\n * @example Audio-only mode\n * ```tsx\n * <VideoPlayer video={videoDoc} audio />\n * ```\n */\nexport const VideoPlayer: React.ForwardRefExoticComponent<\n VideoPlayerProps & React.RefAttributes<MuxPlayerRefAttributes>\n> = forwardRef<MuxPlayerRefAttributes, VideoPlayerProps>(\n function VideoPlayer(props, ref) {\n const {\n video,\n accentColor,\n primaryColor,\n secondaryColor,\n autoPlay,\n loop,\n muted,\n preload = 'metadata',\n startTime,\n streamType = 'on-demand',\n audio,\n noHotKeys,\n maxResolution,\n placeholder,\n placeholderClassName,\n placeholderStyle,\n className,\n style,\n onPlay,\n onPause,\n onEnded,\n onTimeUpdate,\n onLoadedData,\n onError,\n playerProps,\n } = props\n\n const playbackId = resolvePlaybackId(video)\n const title = resolveTitle(props)\n const poster = resolvePoster(props)\n const aspectRatio = resolveAspectRatio(video)\n const status = resolveStatus(video)\n\n // Show placeholder when no playbackId or video not ready\n if (!playbackId || (typeof video !== 'string' && status !== 'ready')) {\n return (\n <div\n className={placeholderClassName ?? className}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n aspectRatio: aspectRatio ?? '16/9',\n backgroundColor: '#000',\n color: '#888',\n fontSize: 14,\n width: '100%',\n ...placeholderStyle,\n }}\n >\n {placeholder ??\n (status === 'preparing'\n ? 'Video is processing...'\n : status === 'errored'\n ? 'Video processing failed'\n : 'Video not available')}\n </div>\n )\n }\n\n return (\n <MuxPlayer\n ref={ref}\n playbackId={playbackId}\n streamType={streamType}\n accentColor={accentColor}\n primaryColor={primaryColor}\n secondaryColor={secondaryColor}\n title={title}\n autoPlay={autoPlay}\n loop={loop}\n muted={muted}\n preload={preload}\n startTime={startTime}\n poster={poster}\n audio={audio}\n nohotkeys={noHotKeys}\n maxResolution={maxResolution}\n className={className}\n style={{\n aspectRatio: aspectRatio ?? '16/9',\n width: '100%',\n ...style,\n }}\n onPlay={onPlay}\n onPause={onPause}\n onEnded={onEnded}\n onTimeUpdate={onTimeUpdate}\n onLoadedData={onLoadedData}\n onError={onError}\n {...playerProps}\n />\n )\n },\n)\n\n// ── Type Exports ──\n\nexport type { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react'\nexport type { Video as VideoData } from '../../payload-types'\n","const MUX_IMAGE_BASE = 'https://image.mux.com'\nconst MUX_STREAM_BASE = 'https://stream.mux.com'\n\n// ── Thumbnail ──\n\nexport interface VideoThumbnailOptions {\n /** Width in pixels (default: 640) */\n width?: number\n /** Height in pixels (auto if omitted) */\n height?: number\n /** Time offset in seconds (default: 0) */\n time?: number\n /** Fit mode (default: 'smartcrop') */\n fitMode?: 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'pad'\n /** Flip horizontally */\n flipH?: boolean\n /** Flip vertically */\n flipV?: boolean\n /** Rotation in degrees (90, 180, 270) */\n rotate?: 90 | 180 | 270\n}\n\n/**\n * Returns a Mux thumbnail URL for a video.\n *\n * @example\n * ```ts\n * getVideoThumbnail('abc123')\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=640'\n *\n * getVideoThumbnail('abc123', { width: 320, time: 5 })\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=320&time=5'\n * ```\n */\nexport function getVideoThumbnail(\n playbackId: string,\n options?: VideoThumbnailOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 640))\n if (options?.height) params.set('height', String(options.height))\n if (options?.time != null) params.set('time', String(options.time))\n if (options?.fitMode) params.set('fit_mode', options.fitMode)\n if (options?.flipH) params.set('flip_h', 'true')\n if (options?.flipV) params.set('flip_v', 'true')\n if (options?.rotate) params.set('rotate', String(options.rotate))\n return `${MUX_IMAGE_BASE}/${playbackId}/thumbnail.jpg?${params}`\n}\n\n// ── Animated GIF ──\n\nexport interface VideoGifOptions {\n /** Width in pixels (default: 320) */\n width?: number\n /** Start time in seconds (default: 0) */\n start?: number\n /** End time in seconds (default: start + 5) */\n end?: number\n /** Frames per second (default: 15) */\n fps?: number\n}\n\n/**\n * Returns a Mux animated GIF URL for a video.\n *\n * @example\n * ```ts\n * getVideoGif('abc123')\n * // => 'https://image.mux.com/abc123/animated.gif?width=320'\n *\n * getVideoGif('abc123', { width: 240, start: 2, end: 6 })\n * // => 'https://image.mux.com/abc123/animated.gif?width=240&start=2&end=6'\n * ```\n */\nexport function getVideoGif(\n playbackId: string,\n options?: VideoGifOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 320))\n if (options?.start != null) params.set('start', String(options.start))\n if (options?.end != null) params.set('end', String(options.end))\n if (options?.fps) params.set('fps', String(options.fps))\n return `${MUX_IMAGE_BASE}/${playbackId}/animated.gif?${params}`\n}\n\n// ── Storyboard ──\n\n/**\n * Returns a Mux storyboard VTT URL for timeline hover previews.\n *\n * @example\n * ```ts\n * getVideoStoryboard('abc123')\n * // => 'https://image.mux.com/abc123/storyboard.vtt'\n * ```\n */\nexport function getVideoStoryboard(playbackId: string): string {\n return `${MUX_IMAGE_BASE}/${playbackId}/storyboard.vtt`\n}\n\n// ── Stream / Playback URLs ──\n\n/**\n * Returns the HLS stream URL for a video.\n *\n * @example\n * ```ts\n * getVideoStreamUrl('abc123')\n * // => 'https://stream.mux.com/abc123.m3u8'\n * ```\n */\nexport function getVideoStreamUrl(playbackId: string): string {\n return `${MUX_STREAM_BASE}/${playbackId}.m3u8`\n}\n\n/**\n * Returns a Mux MP4 download URL for a video.\n * Only available if the asset was created with `mp4_support` enabled.\n *\n * @example\n * ```ts\n * getVideoMp4Url('abc123', 'high')\n * // => 'https://stream.mux.com/abc123/high.mp4'\n * ```\n */\nexport function getVideoMp4Url(\n playbackId: string,\n resolution: 'high' | 'medium' | 'low' = 'high',\n): string {\n return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`\n}\n"],"mappings":";;;AAEA,OAAO,SAAS,kBAAsC;AACtD,OAAO,eAAe;;;ACHtB,IAAM,iBAAiB;AACvB,IAAM,kBAAkB;AAiCjB,SAAS,kBACd,YACA,SACQ;AACR,QAAM,SAAS,IAAI,gBAAgB;AACnC,SAAO,IAAI,SAAS,OAAO,SAAS,SAAS,G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GlC,QAAI,CAAC,cAAe,OAAO,UAAU,YAAY,WAAW,SAAU;AACpE,aACE;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,wBAAwB;AAAA,UACnC,OAAO;AAAA,YACL,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,gBAAgB;AAAA,YAChB,aAAa,eAAe;AAAA,YAC5B,iBAAiB;AAAA,YACjB,OAAO;AAAA,YACP,UAAU;AAAA,YACV,OAAO;AAAA,YACP,GAAG;AAAA,UACL;AAAA;AAAA,QAEC,gBACE,WAAW,cACR,2BACA,WAAW,YACT,4BACA;AAAA,MACV;AAAA,IAEJ;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,OAAO;AAAA,UACL,aAAa,eAAe;AAAA,UAC5B,OAAO;AAAA,UACP,GAAG;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACF;","names":["VideoPlayer"]}
1
+ {"version":3,"sources":["../../src/ui/Video/index.tsx","../../src/utils/video.ts"],"sourcesContent":["'use client'\n\nimport React, { forwardRef, type CSSProperties } from 'react'\nimport MuxPlayer from '@mux/mux-player-react'\nimport type {\n MuxPlayerRefAttributes,\n MuxPlayerProps,\n} from '@mux/mux-player-react'\nimport type { Video, Image } from '../../payload-types'\nimport { getVideoThumbnail } from '../../utils/video'\n\n// Re-export video utilities for convenience\nexport {\n getVideoThumbnail,\n getVideoGif,\n getVideoStreamUrl,\n getVideoMp4Url,\n getVideoStoryboard,\n type VideoThumbnailOptions,\n type VideoGifOptions,\n} from '../../utils/video'\n\n// ── CSS custom properties ──\n\nexport interface VideoPlayerCSSProperties extends CSSProperties {\n [key: `--${string}`]: string | undefined\n}\n\n// ── Props ──\n\nexport interface VideoPlayerProps {\n /** Video document or playbackId string */\n video: Video | string\n /** HLS URL from client.video.playback(video.id); required for gated Free VOD. */\n streamUrl?: string\n\n // ── Theming ──\n /** Theme accent color */\n accentColor?: string\n /** Theme primary color (controls) */\n primaryColor?: string\n /** Theme secondary color (time display, etc.) */\n secondaryColor?: string\n\n // ── Playback ──\n /** Title overlay (auto-resolved from Video.title if omitted) */\n title?: string\n /** Autoplay behavior */\n autoPlay?: boolean | 'muted' | 'any'\n /** Loop playback */\n loop?: boolean\n /** Muted by default */\n muted?: boolean\n /** Preload strategy (default: 'metadata') */\n preload?: 'auto' | 'metadata' | 'none'\n /** Start time in seconds */\n startTime?: number\n /** Stream type (default: 'on-demand') */\n streamType?: 'on-demand' | 'live' | 'll-live'\n /** Audio-only mode */\n audio?: boolean\n /** Disable keyboard shortcuts */\n noHotKeys?: boolean\n /** Max resolution cap */\n maxResolution?: '720p' | '1080p' | '1440p' | '2160p'\n\n // ── Poster ──\n /** Thumbnail time for auto-generated poster (default: 0) */\n thumbnailTime?: number\n /** Custom poster URL (overrides auto-generated thumbnail) */\n poster?: string\n\n // ── Placeholder (when video not ready) ──\n /** Placeholder text when video is not ready */\n placeholder?: string\n /** CSS class for the placeholder */\n placeholderClassName?: string\n /** Inline styles for the placeholder */\n placeholderStyle?: CSSProperties\n\n // ── Styling ──\n /** CSS class */\n className?: string\n /** Inline styles (supports --mux CSS custom properties) */\n style?: VideoPlayerCSSProperties\n\n // ── Events ──\n onPlay?: () => void\n onPause?: () => void\n onEnded?: () => void\n onTimeUpdate?: () => void\n onLoadedData?: () => void\n onError?: () => void\n\n // ── Escape hatch ──\n /** Extra props forwarded directly to MuxPlayer */\n playerProps?: Omit<\n MuxPlayerProps,\n | 'playbackId'\n | 'src'\n | 'streamType'\n | 'accentColor'\n | 'primaryColor'\n | 'secondaryColor'\n | 'title'\n | 'autoPlay'\n | 'loop'\n | 'muted'\n | 'preload'\n | 'startTime'\n | 'poster'\n | 'audio'\n | 'nohotkeys'\n | 'maxResolution'\n | 'className'\n | 'style'\n >\n}\n\n// ── Helpers ──\n\nfunction resolvePlaybackId(video: Video | string): string | null {\n if (typeof video === 'string') return video\n return video.muxPlaybackId ?? null\n}\n\nfunction resolveTitle(props: VideoPlayerProps): string | undefined {\n if (props.title !== undefined) return props.title\n if (typeof props.video !== 'string') return props.video.title ?? undefined\n return undefined\n}\n\nfunction resolvePoster(props: VideoPlayerProps): string | undefined {\n // 1. Explicit poster URL (highest priority)\n if (props.poster) return props.poster\n\n // 2. Video.thumbnail uploaded image\n if (typeof props.video !== 'string' && props.video.thumbnail) {\n const thumb = props.video.thumbnail\n if (typeof thumb === 'object' && thumb !== null && 'url' in thumb) {\n const url = (thumb as Image).url\n if (url) return url\n }\n }\n\n // 3. Auto-generate from Mux image API\n if (props.streamUrl) return undefined\n const playbackId = resolvePlaybackId(props.video)\n if (!playbackId) return undefined\n return getVideoThumbnail(playbackId, {\n width: 1280,\n time: props.thumbnailTime ?? 0,\n })\n}\n\nfunction resolveAspectRatio(video: Video | string): string | undefined {\n if (typeof video === 'string') return undefined\n return video.aspectRatio ?? undefined\n}\n\nfunction resolveStatus(video: Video | string): string {\n if (typeof video === 'string') return 'ready'\n return video.muxStatus ?? 'waiting'\n}\n\n// ── Component ──\n\n/**\n * Mux video player component.\n * Requires `@mux/mux-player-react` (optional peer dependency).\n *\n * @example Basic usage\n * ```tsx\n * import { VideoPlayer } from '@01.software/sdk/ui/video'\n *\n * <VideoPlayer video={videoDoc} />\n * ```\n *\n * @example With playback ID string\n * ```tsx\n * <VideoPlayer video=\"abc123def\" autoPlay=\"muted\" loop />\n * ```\n *\n * @example Custom theming with CSS custom properties\n * ```tsx\n * <VideoPlayer\n * video={videoDoc}\n * accentColor=\"#f43f5e\"\n * primaryColor=\"#fff\"\n * className=\"rounded-lg overflow-hidden\"\n * style={{ '--controls-backdrop-color': 'rgba(0,0,0,0.6)' }}\n * />\n * ```\n *\n * @example Audio-only mode\n * ```tsx\n * <VideoPlayer video={videoDoc} audio />\n * ```\n */\nexport const VideoPlayer: React.ForwardRefExoticComponent<\n VideoPlayerProps & React.RefAttributes<MuxPlayerRefAttributes>\n> = forwardRef<MuxPlayerRefAttributes, VideoPlayerProps>(\n function VideoPlayer(props, ref) {\n const {\n video,\n streamUrl,\n accentColor,\n primaryColor,\n secondaryColor,\n autoPlay,\n loop,\n muted,\n preload = 'metadata',\n startTime,\n streamType = 'on-demand',\n audio,\n noHotKeys,\n maxResolution,\n placeholder,\n placeholderClassName,\n placeholderStyle,\n className,\n style,\n onPlay,\n onPause,\n onEnded,\n onTimeUpdate,\n onLoadedData,\n onError,\n playerProps,\n } = props\n\n const playbackId = resolvePlaybackId(video)\n const title = resolveTitle(props)\n const poster = resolvePoster(props)\n const aspectRatio = resolveAspectRatio(video)\n const status = resolveStatus(video)\n\n // Show placeholder when no playbackId or video not ready\n if (\n (!streamUrl && !playbackId) ||\n (typeof video !== 'string' && status !== 'ready')\n ) {\n return (\n <div\n className={placeholderClassName ?? className}\n style={{\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n aspectRatio: aspectRatio ?? '16/9',\n backgroundColor: '#000',\n color: '#888',\n fontSize: 14,\n width: '100%',\n ...placeholderStyle,\n }}\n >\n {placeholder ??\n (status === 'preparing'\n ? 'Video is processing...'\n : status === 'errored'\n ? 'Video processing failed'\n : 'Video not available')}\n </div>\n )\n }\n\n return (\n <MuxPlayer\n ref={ref}\n {...(streamUrl ? { src: streamUrl } : { playbackId: playbackId! })}\n streamType={streamType}\n accentColor={accentColor}\n primaryColor={primaryColor}\n secondaryColor={secondaryColor}\n title={title}\n autoPlay={autoPlay}\n loop={loop}\n muted={muted}\n preload={preload}\n startTime={startTime}\n poster={poster}\n audio={audio}\n nohotkeys={noHotKeys}\n maxResolution={maxResolution}\n className={className}\n style={{\n aspectRatio: aspectRatio ?? '16/9',\n width: '100%',\n ...style,\n }}\n onPlay={onPlay}\n onPause={onPause}\n onEnded={onEnded}\n onTimeUpdate={onTimeUpdate}\n onLoadedData={onLoadedData}\n onError={onError}\n {...playerProps}\n />\n )\n },\n)\n\n// ── Type Exports ──\n\nexport type { MuxPlayerRefAttributes as VideoPlayerRef } from '@mux/mux-player-react'\nexport type { Video as VideoData } from '../../payload-types'\n","const MUX_IMAGE_BASE = 'https://image.mux.com'\nconst MUX_STREAM_BASE = 'https://stream.mux.com'\n\n// ── Thumbnail ──\n\nexport interface VideoThumbnailOptions {\n /** Width in pixels (default: 640) */\n width?: number\n /** Height in pixels (auto if omitted) */\n height?: number\n /** Time offset in seconds (default: 0) */\n time?: number\n /** Fit mode (default: 'smartcrop') */\n fitMode?: 'preserve' | 'stretch' | 'crop' | 'smartcrop' | 'pad'\n /** Flip horizontally */\n flipH?: boolean\n /** Flip vertically */\n flipV?: boolean\n /** Rotation in degrees (90, 180, 270) */\n rotate?: 90 | 180 | 270\n}\n\n/**\n * Returns a Mux thumbnail URL for a video.\n *\n * @example\n * ```ts\n * getVideoThumbnail('abc123')\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=640'\n *\n * getVideoThumbnail('abc123', { width: 320, time: 5 })\n * // => 'https://image.mux.com/abc123/thumbnail.jpg?width=320&time=5'\n * ```\n */\nexport function getVideoThumbnail(\n playbackId: string,\n options?: VideoThumbnailOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 640))\n if (options?.height) params.set('height', String(options.height))\n if (options?.time != null) params.set('time', String(options.time))\n if (options?.fitMode) params.set('fit_mode', options.fitMode)\n if (options?.flipH) params.set('flip_h', 'true')\n if (options?.flipV) params.set('flip_v', 'true')\n if (options?.rotate) params.set('rotate', String(options.rotate))\n return `${MUX_IMAGE_BASE}/${playbackId}/thumbnail.jpg?${params}`\n}\n\n// ── Animated GIF ──\n\nexport interface VideoGifOptions {\n /** Width in pixels (default: 320) */\n width?: number\n /** Start time in seconds (default: 0) */\n start?: number\n /** End time in seconds (default: start + 5) */\n end?: number\n /** Frames per second (default: 15) */\n fps?: number\n}\n\n/**\n * Returns a Mux animated GIF URL for a video.\n *\n * @example\n * ```ts\n * getVideoGif('abc123')\n * // => 'https://image.mux.com/abc123/animated.gif?width=320'\n *\n * getVideoGif('abc123', { width: 240, start: 2, end: 6 })\n * // => 'https://image.mux.com/abc123/animated.gif?width=240&start=2&end=6'\n * ```\n */\nexport function getVideoGif(\n playbackId: string,\n options?: VideoGifOptions,\n): string {\n const params = new URLSearchParams()\n params.set('width', String(options?.width ?? 320))\n if (options?.start != null) params.set('start', String(options.start))\n if (options?.end != null) params.set('end', String(options.end))\n if (options?.fps) params.set('fps', String(options.fps))\n return `${MUX_IMAGE_BASE}/${playbackId}/animated.gif?${params}`\n}\n\n// ── Storyboard ──\n\n/**\n * Returns a Mux storyboard VTT URL for timeline hover previews.\n *\n * @example\n * ```ts\n * getVideoStoryboard('abc123')\n * // => 'https://image.mux.com/abc123/storyboard.vtt'\n * ```\n */\nexport function getVideoStoryboard(playbackId: string): string {\n return `${MUX_IMAGE_BASE}/${playbackId}/storyboard.vtt`\n}\n\n// ── Stream / Playback URLs ──\n\n/**\n * Returns the HLS stream URL for a video.\n *\n * @example\n * ```ts\n * getVideoStreamUrl('abc123')\n * // => 'https://stream.mux.com/abc123.m3u8'\n * ```\n */\nexport function getVideoStreamUrl(playbackId: string): string {\n return `${MUX_STREAM_BASE}/${playbackId}.m3u8`\n}\n\n/**\n * Returns a Mux MP4 download URL for a video.\n * Only available if the asset was created with `mp4_support` enabled.\n *\n * @example\n * ```ts\n * getVideoMp4Url('abc123', 'high')\n * // => 'https://stream.mux.com/abc123/high.mp4'\n * ```\n */\nexport function getVideoMp4Url(\n playbackId: string,\n resolution: 'high' | 'medium' | 'low' = 'high',\n): string {\n return `${MUX_STREAM_BASE}/${playbackId}/${resolution}.mp4`\n}\n"],"mappings":";;;AAEA,OAAO,SAAS,kBAAsC;AACtD,OAA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AAAA,MACA;AAAA,MACA;AAAA,IACF,IAAI;AAEJ,UAAM,aAAa,kBAAkB,KAAK;AAC1C,UAAM,QAAQ,aAAa,KAAK;AAChC,UAAM,SAAS,cAAc,KAAK;AAClC,UAAM,cAAc,mBAAmB,KAAK;AAC5C,UAAM,SAAS,cAAc,KAAK;AAGlC,QACG,CAAC,aAAa,CAAC,cACf,OAAO,UAAU,YAAY,WAAW,SACzC;AACA,aACE;AAAA,QAAC;AAAA;AAAA,UACC,WAAW,wBAAwB;AAAA,UACnC,OAAO;AAAA,YACL,SAAS;AAAA,YACT,YAAY;AAAA,YACZ,gBAAgB;AAAA,YAChB,aAAa,eAAe;AAAA,YAC5B,iBAAiB;AAAA,YACjB,OAAO;AAAA,YACP,UAAU;AAAA,YACV,OAAO;AAAA,YACP,GAAG;AAAA,UACL;AAAA;AAAA,QAEC,gBACE,WAAW,cACR,2BACA,WAAW,YACT,4BACA;AAAA,MACV;AAAA,IAEJ;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACC,GAAI,YAAY,EAAE,KAAK,UAAU,IAAI,EAAE,WAAwB;AAAA,QAChE;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,WAAW;AAAA,QACX;AAAA,QACA;AAAA,QACA,OAAO;AAAA,UACL,aAAa,eAAe;AAAA,UAC5B,OAAO;AAAA,UACP,GAAG;AAAA,QACL;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACF;","names":["VideoPlayer"]}
package/dist/webhook.cjs CHANGED
@@ -159,7 +159,11 @@ var COMMERCE_NOTIFICATION_EVENTS = [
159
159
  "returnCanceled",
160
160
  "returnCompleted",
161
161
  "paymentReconciliationRequired",
162
- "paymentRefundRequiresAttention"
162
+ "paymentRefundRequiresAttention",
163
+ "membershipActivated",
164
+ "membershipPastDue",
165
+ "membershipExpired",
166
+ "membershipCancelled"
163
167
  ];
164
168
  function isStringOrNumber(value) {
165
169
  return typeof value === "string" || typeof value === "number";
@@ -189,7 +193,7 @@ function isCommerceNotificationEventName(value) {
189
193
  return typeof value === "string" && COMMERCE_NOTIFICATION_EVENTS.includes(value);
190
194
  }
191
195
  function isCommerceNotificationSourceCollection(value) {
192
- return value === "orders" || value === "fulfillments" || value === "returns" || value === "payment-sessions" || value === "payment-refund-attempts";
196
+ return value === "orders" || value === "fulfillments" || value === "returns" || value === "payment-sessions" || value === "payment-refund-attempts" || value === "customer-memberships";
193
197
  }
194
198
  function isCommerceNotificationData(value) {
195
199
  if (!isRecord(value)) return false;
@@ -209,6 +213,10 @@ function isPaymentIncidentNotificationData(value, event) {
209
213
  const expectedReason = reconciliation ? "orderless_capture" : "local_commit_ambiguous";
210
214
  return value.source?.collection === expectedCollection && typeof value.source.id === "string" && value.source.id.length > 0 && typeof value.paymentSessionId === "string" && value.paymentSessionId.length > 0 && isRecord(value.providerObject) && typeof value.providerObject.provider === "string" && value.providerObject.provider.length > 0 && (value.providerObject.kind === "payment" || value.providerObject.kind === "refund") && typeof value.providerObject.id === "string" && value.providerObject.id.length > 0 && isRecord(value.money) && Number.isSafeInteger(value.money.amountMinor) && Number(value.money.amountMinor) > 0 && typeof value.money.currency === "string" && value.money.currency.length > 0 && value.status === expectedStatus && value.reason === expectedReason && typeof value.observedAt === "string" && value.observedAt.length > 0 && !Number.isNaN(Date.parse(value.observedAt)) && (value.checkoutId === void 0 || typeof value.checkoutId === "string" && value.checkoutId.length > 0) && (value.orderId === void 0 || typeof value.orderId === "string" && value.orderId.length > 0) && (reconciliation ? value.source.id === value.paymentSessionId && value.providerObject.kind === "payment" && value.refundAttemptId === void 0 : typeof value.refundAttemptId === "string" && value.refundAttemptId.length > 0 && value.source.id === value.refundAttemptId);
211
215
  }
216
+ function isMembershipNotificationData(value, event) {
217
+ const expectedStatus = event === "membershipActivated" ? "active" : event === "membershipPastDue" ? "past_due" : event === "membershipExpired" ? "expired" : "cancelled";
218
+ return typeof value.membershipId === "string" && value.membershipId.length > 0 && typeof value.planId === "string" && value.planId.length > 0 && typeof value.customerId === "string" && value.customerId.length > 0 && typeof value.fromStatus === "string" && value.fromStatus.length > 0 && value.fromStatus !== value.toStatus && value.toStatus === expectedStatus && typeof value.occurredAt === "string" && !Number.isNaN(Date.parse(value.occurredAt));
219
+ }
212
220
  function isWebhookCommerceNotificationChange(value) {
213
221
  if (!isRecord(value)) return false;
214
222
  return value.type === "notification" && value.source === "commerce-notifications" && isCommerceNotificationEventName(value.event) && isCommerceNotificationSourceCollection(value.sourceCollection) && isStringOrNumber(value.sourceId);
@@ -257,6 +265,9 @@ function isCommerceNotificationWebhookEvent(event) {
257
265
  const notificationSourceId = notification.event === "paymentReconciliationRequired" ? notification.paymentSessionId : notification.refundAttemptId;
258
266
  return sourceCollection === expectedCollection && typeof notification.paymentSessionId === "string" && notification.paymentSessionId === incidentData.paymentSessionId && typeof notificationSourceId === "string" && notificationSourceId === incidentData.source.id && matchesOptionalId(changeSourceId, incidentData.source.id);
259
267
  }
268
+ if (notification.event === "membershipActivated" || notification.event === "membershipPastDue" || notification.event === "membershipExpired" || notification.event === "membershipCancelled") {
269
+ return sourceCollection === "customer-memberships" && isMembershipNotificationData(data, notification.event) && typeof notification.membershipId === "string" && notification.membershipId === data.membershipId && matchesOptionalId(changeSourceId, data.membershipId);
270
+ }
260
271
  if (notification.event === "orderPaid" || notification.event === "orderCanceled" || notification.event === "orderDelivered") {
261
272
  return sourceCollection === "orders" && typeof notification.orderId === "string" && notification.orderId.length > 0 && matchesOptionalId(data.orderId, sourceId) && matchesOptionalId(notification.orderId, sourceId) && matchesOptionalId(data.orderId, notification.orderId) && matchesOptionalId(changeSourceId, data.orderId ?? notification.orderId);
262
273
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/webhook.ts","../src/core/webhook/validation.ts","../src/core/webhook/receiver.ts","../src/core/webhook/index.ts"],"sourcesContent":["export {\n handleWebhook,\n createTypedWebhookHandler,\n createCommerceEmailWebhookHandler,\n createCommerceNotificationWebhookHandler,\n createCustomerAuthWebhookHandler,\n defineCommerceEmailConfig,\n getCommerceNotificationIdempotencyKey,\n isValidWebhookEvent,\n isCommerceNotificationWebhookEvent,\n isCustomerPasswordResetWebhookEvent,\n isOrderChangedWebhookEvent,\n isWebhookCollection,\n isWebhookOperation,\n CUSTOMER_PASSWORD_RESET_OPERATION,\n COMMERCE_NOTIFICATION_EVENT_TYPE,\n COMMERCE_NOTIFICATION_EVENTS,\n COMMERCE_NOTIFICATION_OPERATION,\n ORDER_CHANGED_EVENT_TYPE,\n} from './core/webhook'\nexport type {\n CollectionWebhookOperation,\n CommerceEmailChannel,\n CommerceEmailConfig,\n CommerceEmailEventConfig,\n CommerceEmailEventHandlers,\n CommerceEmailHandlerContext,\n CommerceNotification,\n CommerceNotificationData,\n CommerceNotificationEventName,\n CommerceNotificationEventHandlers,\n CommerceNotificationHandlerContext,\n CommerceNotificationSource,\n CommerceNotificationSourceCollection,\n CommerceNotificationWebhookEvent,\n CustomerAuthWebhookEvent,\n CustomerAuthWebhookHandlers,\n CustomerPasswordResetWebhookData,\n CustomerPasswordResetWebhookEvent,\n OrderChangedWebhookEvent,\n PaymentIncidentMoney,\n PaymentIncidentNotificationData,\n PaymentIncidentNotificationEventName,\n PaymentIncidentNotificationReason,\n PaymentIncidentNotificationSourceCollection,\n PaymentIncidentNotificationStatus,\n PaymentIncidentProviderObject,\n WebhookChange,\n WebhookCommerceNotificationChange,\n WebhookEvent,\n WebhookHandler,\n WebhookKnownOperation,\n WebhookOperation,\n WebhookOptions,\n WebhookOrderChange,\n WebhookOrderMoved,\n WebhookOrderScope,\n} from './core/webhook'\nexport {\n handleSignedWebhook,\n handleUnsignedWebhook,\n} from './core/webhook/receiver'\nexport type { SignedWebhookOptions } from './core/webhook/receiver'\nexport type {\n WebhookSigningSecretReveal,\n WebhookWithoutSecret,\n} from './webhook-types'\n","export function isValidWebhookEventData(data: unknown): boolean {\n if (typeof data !== 'object' || data === null) return false\n const event = data as Record<string, unknown>\n return (\n typeof event.collection === 'string' &&\n typeof event.operation === 'string' &&\n event.operation.length > 0 &&\n typeof event.data === 'object' &&\n event.data !== null\n )\n}\n","import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\nimport type { WebhookEvent, WebhookHandler } from './index'\nimport { isValidWebhookEventData } from './validation'\n\nexport interface SignedWebhookOptions {\n /** Nonblank HMAC-SHA256 signing secret for this receiver. */\n secret: string\n /**\n * Max accepted skew for signed webhook delivery timestamps. Default: 300s.\n * Must be a number between 0 and 86400 inclusive; anything else is a\n * configuration error, because an unbounded or effectively unbounded window\n * would accept an arbitrarily old replay.\n */\n toleranceSeconds?: number\n}\n\nasync function verifySignature(\n rawBody: Uint8Array,\n secret: string,\n signature: string,\n timestamp: string,\n deliveryId: string,\n): Promise<boolean> {\n const encoder = new TextEncoder()\n const signedPrefix = encoder.encode(`${timestamp}.${deliveryId}.`)\n const signedPayload = new Uint8Array(signedPrefix.length + rawBody.length)\n signedPayload.set(signedPrefix)\n signedPayload.set(rawBody, signedPrefix.length)\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['verify'],\n )\n if (signature.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(signature)) {\n return false\n }\n const sigBytes = new Uint8Array(\n (signature.match(/.{2}/g) ?? []).map((byte) => parseInt(byte, 16)),\n )\n return crypto.subtle.verify('HMAC', key, sigBytes, signedPayload)\n}\n\nfunction timestampIsFresh(\n timestamp: string,\n toleranceSeconds: number,\n): boolean {\n if (!/^\\d+$/.test(timestamp)) return false\n const timestampMs = Number(timestamp)\n if (!Number.isFinite(timestampMs)) return false\n const skewMs = Math.abs(Date.now() - timestampMs)\n return skewMs <= toleranceSeconds * 1000\n}\n\n/**\n * Upper bound for the signed replay window. A merely finite tolerance is not\n * enough: `Number.MAX_VALUE * 1000` overflows to `Infinity`, and even without\n * overflow a value of that size accepts an arbitrarily old capture. The sender's\n * retry and dead-letter lifecycle completes far inside a day, so anything beyond\n * this is a misconfiguration rather than clock-skew tolerance.\n */\nconst MAX_TOLERANCE_SECONDS = 86_400\n\n/**\n * A signed receiver's replay window must stay bounded. A non-finite, negative,\n * or over-bound tolerance would silently accept an old capture, so it is a\n * configuration error rather than a request-authentication failure.\n */\nfunction toleranceIsValid(\n toleranceSeconds: unknown,\n): toleranceSeconds is number {\n return (\n typeof toleranceSeconds === 'number' &&\n Number.isFinite(toleranceSeconds) &&\n toleranceSeconds >= 0 &&\n toleranceSeconds <= MAX_TOLERANCE_SECONDS\n )\n}\n\nasync function processWebhookRequest<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(\n request: Request,\n handler: WebhookHandler<T, TData>,\n verify?: (rawBody: Uint8Array) => Promise<Response | undefined>,\n): Promise<Response> {\n try {\n const rawBody = new Uint8Array(await request.arrayBuffer())\n const verificationFailure = await verify?.(rawBody)\n if (verificationFailure) return verificationFailure\n\n const body = JSON.parse(new TextDecoder().decode(rawBody))\n if (!isValidWebhookEventData(body)) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook event format' }),\n { status: 400, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n await handler(body as WebhookEvent<T, TData>)\n return new Response(\n JSON.stringify({ success: true, message: 'Webhook processed' }),\n { status: 200, headers: { 'Content-Type': 'application/json' } },\n )\n } catch (error) {\n console.error('Webhook processing error:', error)\n return new Response(JSON.stringify({ error: 'Internal server error' }), {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n}\n\nexport async function handleSignedWebhook<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(\n request: Request,\n handler: WebhookHandler<T, TData>,\n options: SignedWebhookOptions,\n): Promise<Response> {\n // Read each configuration value exactly once. Re-reading `options` would let\n // a getter return a valid secret to the guard and a different one to the\n // verifier, so the validated bytes are the only bytes this receiver uses.\n const secret: unknown = options?.secret\n const configuredTolerance: unknown = options?.toleranceSeconds\n // `??` so an absent or null tolerance keeps the documented default, exactly as\n // before this change; only a present, out-of-contract value is rejected.\n const toleranceSeconds = configuredTolerance ?? 300\n\n if (typeof secret !== 'string' || secret.trim().length === 0) {\n return new Response(\n JSON.stringify({ error: 'Webhook signing secret is not configured' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n // Reported separately so a tolerance mistake is not misdiagnosed as a bad secret.\n if (!toleranceIsValid(toleranceSeconds)) {\n return new Response(\n JSON.stringify({ error: 'Webhook signature tolerance is not valid' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n return processWebhookRequest(request, handler, async (rawBody) => {\n const signature = request.headers.get('x-webhook-signature') || ''\n const timestamp = request.headers.get('x-webhook-timestamp') || ''\n const deliveryId = request.headers.get('x-webhook-delivery-id') || ''\n const valid =\n Boolean(timestamp && deliveryId) &&\n timestampIsFresh(timestamp, toleranceSeconds) &&\n (await verifySignature(rawBody, secret, signature, timestamp, deliveryId))\n\n if (!valid) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook signature' }),\n { status: 401, headers: { 'Content-Type': 'application/json' } },\n )\n }\n })\n}\n\n/** Process a webhook only when its endpoint is intentionally unsigned. */\nexport async function handleUnsignedWebhook<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(request: Request, handler: WebhookHandler<T, TData>): Promise<Response> {\n return processWebhookRequest(request, handler)\n}\n","import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\nimport { handleSignedWebhook as handleSignedWebhookInternal } from './receiver'\nimport { isValidWebhookEventData } from './validation'\n\nexport type WebhookOperation = string\n\n/**\n * Semantic event type for manual Admin Panel ordering changes.\n *\n * Order-change webhooks remain `operation: \"update\"` events for compatibility.\n * Do not filter on or emit `operation: \"reorder\"`; use this event type with\n * `isOrderChangedWebhookEvent()` to distinguish ordering from normal content\n * updates.\n */\nexport const ORDER_CHANGED_EVENT_TYPE = 'collection.orderChanged' as const\n\n/** Semantic event type for v1 commerce notification webhooks. */\nexport const COMMERCE_NOTIFICATION_EVENT_TYPE = 'commerce.notification' as const\n\n/** Collection webhook operations emitted for tenant collection writes. */\nexport type CollectionWebhookOperation = 'create' | 'update'\n\n/** Describes the ordered area affected by an order-change webhook. */\nexport type WebhookOrderScope =\n | { kind: 'collection'; collection: string }\n | { kind: 'join'; collection: string; field: string; id: string | number }\n\n/** Identifies the public moved document for the ordered scope. */\nexport type WebhookOrderMoved = {\n collection: string\n id: string | number\n relatedCollection?: string\n relatedId?: string | number\n}\n\n/** Metadata attached to `collection.orderChanged` webhook events. */\nexport type WebhookOrderChange = {\n type: 'order'\n source: 'payload-orderable'\n /**\n * Diagnostic Payload order field name.\n *\n * This may contain hidden implementation field names. Application routing\n * should use `change.scope` and `change.moved` instead.\n */\n orderableFieldName?: string\n previousOrder?: string | null\n nextOrder?: string | null\n scope: WebhookOrderScope\n moved: WebhookOrderMoved\n}\n\n/** Known semantic webhook change metadata. */\nexport type WebhookChange =\n | WebhookOrderChange\n | WebhookCommerceNotificationChange\n\nexport interface WebhookEvent<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n> {\n collection: T\n operation: WebhookOperation\n data: TData\n eventType?: string\n change?: unknown\n timestamp?: string\n deliveryId?: string\n}\n\nexport type WebhookHandler<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n> = (event: WebhookEvent<T, TData>) => Promise<void> | void\n\n/** @deprecated Use the signed receiver options from `@01.software/sdk/webhook`. */\nexport interface WebhookOptions {\n /** Nonblank HMAC-SHA256 signing secret for this receiver. */\n secret: string\n /** Max accepted skew for signed webhook delivery timestamps. Default: 300s. */\n toleranceSeconds?: number\n}\n\nexport function isValidWebhookEvent(data: unknown): data is WebhookEvent {\n return isValidWebhookEventData(data)\n}\n\n/** Webhook event emitted when manual Admin Panel ordering changes. */\nexport type OrderChangedWebhookEvent<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n> = WebhookEvent<T, TData> & {\n operation: 'update'\n eventType: typeof ORDER_CHANGED_EVENT_TYPE\n change: WebhookOrderChange\n}\n\nexport const COMMERCE_NOTIFICATION_OPERATION = 'notification' as const\n\nexport const COMMERCE_NOTIFICATION_EVENTS = [\n 'orderPaid',\n 'orderCanceled',\n 'fulfillmentShipped',\n 'orderDelivered',\n 'returnRequested',\n 'returnApproved',\n 'returnRejected',\n 'returnCanceled',\n 'returnCompleted',\n 'paymentReconciliationRequired',\n 'paymentRefundRequiresAttention',\n] as const\n\nexport type CommerceNotificationEventName =\n (typeof COMMERCE_NOTIFICATION_EVENTS)[number]\n\nexport type CustomerCommerceNotificationEventName = Exclude<\n CommerceNotificationEventName,\n PaymentIncidentNotificationEventName\n>\n\nexport type CommerceNotificationSourceCollection =\n | 'orders'\n | 'fulfillments'\n | 'returns'\n | 'payment-sessions'\n | 'payment-refund-attempts'\n\nexport type CommerceNotificationSource = {\n collection: CommerceNotificationSourceCollection\n id: string | number\n}\n\nexport type PaymentIncidentNotificationEventName =\n | 'paymentReconciliationRequired'\n | 'paymentRefundRequiresAttention'\n\nexport type PaymentIncidentNotificationSourceCollection =\n | 'payment-sessions'\n | 'payment-refund-attempts'\n\nexport type PaymentIncidentNotificationReason =\n | 'orderless_capture'\n | 'local_commit_ambiguous'\n\nexport type PaymentIncidentNotificationStatus =\n | 'reconciliation_required'\n | 'requires_attention'\n\nexport type PaymentIncidentProviderObject = {\n provider: string\n kind: 'payment' | 'refund'\n id: string\n}\n\nexport type PaymentIncidentMoney = {\n amountMinor: number\n currency: string\n}\n\ntype PaymentIncidentNotificationBase = {\n paymentSessionId: string\n checkoutId?: string\n orderId?: string\n providerObject: PaymentIncidentProviderObject\n money: PaymentIncidentMoney\n observedAt: string\n}\n\nexport type PaymentReconciliationRequiredNotificationData =\n PaymentIncidentNotificationBase & {\n source: {\n collection: 'payment-sessions'\n id: string\n }\n providerObject: PaymentIncidentProviderObject & { kind: 'payment' }\n status: 'reconciliation_required'\n reason: 'orderless_capture'\n refundAttemptId?: never\n }\n\nexport type PaymentRefundRequiresAttentionNotificationData =\n PaymentIncidentNotificationBase & {\n source: { collection: 'payment-refund-attempts'; id: string }\n refundAttemptId: string\n status: 'requires_attention'\n reason: 'local_commit_ambiguous'\n }\n\nexport type PaymentIncidentNotificationData =\n | PaymentReconciliationRequiredNotificationData\n | PaymentRefundRequiresAttentionNotificationData\n\nexport type CommerceNotificationData = {\n source?: CommerceNotificationSource\n orderId?: string | number\n orderNumber?: string\n status?: string\n totalAmount?: number\n currency?: string\n fulfillmentId?: string | number\n fulfillmentStatus?: string\n shippedAt?: string\n returnId?: string | number\n returnStatus?: string\n refundAmount?: number\n completedAt?: string\n paymentSessionId?: string\n checkoutId?: string\n refundAttemptId?: string\n providerObject?: PaymentIncidentProviderObject\n money?: PaymentIncidentMoney\n reason?: PaymentIncidentNotificationReason\n observedAt?: string\n}\n\nexport type CommerceNotification = {\n event: CommerceNotificationEventName\n intentId: string\n dedupeKey: string\n orderId?: string\n fulfillmentId?: string\n returnId?: string\n paymentSessionId?: string\n refundAttemptId?: string\n}\n\nexport type WebhookCommerceNotificationChange = {\n type: 'notification'\n source: 'commerce-notifications'\n event: CommerceNotificationEventName\n sourceCollection: CommerceNotificationSourceCollection\n sourceId: string | number\n}\n\n/** Webhook event emitted for v1 commerce notification deliveries. */\nexport type CommerceNotificationWebhookEvent = WebhookEvent<\n CommerceNotificationSourceCollection,\n CommerceNotificationData\n> & {\n operation: typeof COMMERCE_NOTIFICATION_OPERATION\n eventType: typeof COMMERCE_NOTIFICATION_EVENT_TYPE\n change?: WebhookCommerceNotificationChange\n notification: CommerceNotification\n}\n\nexport type CommerceEmailChannel = 'webhook' | 'provider'\n\nexport type CommerceEmailEventConfig = {\n enabled: boolean\n channel: CommerceEmailChannel\n template?: string\n}\n\nexport type CommerceEmailConfig = {\n version: 1\n commerceNotifications: Partial<\n Record<CustomerCommerceNotificationEventName, CommerceEmailEventConfig>\n >\n}\n\nexport type CommerceNotificationHandlerContext = {\n event: CommerceNotificationWebhookEvent\n idempotencyKey: string\n}\n\ntype MaybePromise<T> = T | Promise<T>\n\nexport type CommerceNotificationEventHandlers = Partial<\n Record<\n CommerceNotificationEventName,\n (context: CommerceNotificationHandlerContext) => MaybePromise<void>\n >\n> & {\n unhandled?: (event: WebhookEvent<string, unknown>) => MaybePromise<void>\n}\n\nexport type CommerceEmailHandlerContext = CommerceNotificationHandlerContext\n\nexport type CommerceEmailEventHandlers = Partial<\n Record<\n CustomerCommerceNotificationEventName,\n (context: CommerceEmailHandlerContext) => MaybePromise<void>\n >\n> & {\n unhandled?: (event: WebhookEvent<string, unknown>) => MaybePromise<void>\n}\n\nfunction isStringOrNumber(value: unknown): value is string | number {\n return typeof value === 'string' || typeof value === 'number'\n}\n\nfunction isWebhookOrderScope(value: unknown): value is WebhookOrderScope {\n if (!isRecord(value)) return false\n\n if (value.kind === 'collection') {\n return typeof value.collection === 'string'\n }\n\n if (value.kind === 'join') {\n return (\n typeof value.collection === 'string' &&\n typeof value.field === 'string' &&\n isStringOrNumber(value.id)\n )\n }\n\n return false\n}\n\nfunction isWebhookOrderMoved(value: unknown): value is WebhookOrderMoved {\n if (!isRecord(value)) return false\n\n return (\n typeof value.collection === 'string' &&\n isStringOrNumber(value.id) &&\n (value.relatedCollection === undefined ||\n typeof value.relatedCollection === 'string') &&\n (value.relatedId === undefined || isStringOrNumber(value.relatedId))\n )\n}\n\nfunction hasOptionalOrderValue(\n value: Record<string, unknown>,\n key: string,\n): boolean {\n return (\n value[key] === undefined ||\n value[key] === null ||\n typeof value[key] === 'string'\n )\n}\n\nfunction isWebhookOrderChange(value: unknown): value is WebhookOrderChange {\n if (!isRecord(value)) return false\n\n return (\n value.type === 'order' &&\n value.source === 'payload-orderable' &&\n (value.orderableFieldName === undefined ||\n typeof value.orderableFieldName === 'string') &&\n hasOptionalOrderValue(value, 'previousOrder') &&\n hasOptionalOrderValue(value, 'nextOrder') &&\n isWebhookOrderScope(value.scope) &&\n isWebhookOrderMoved(value.moved)\n )\n}\n\nfunction isCommerceNotificationEventName(\n value: unknown,\n): value is CommerceNotificationEventName {\n return (\n typeof value === 'string' &&\n (COMMERCE_NOTIFICATION_EVENTS as readonly string[]).includes(value)\n )\n}\n\nfunction isCommerceNotificationSourceCollection(\n value: unknown,\n): value is CommerceNotificationSourceCollection {\n return (\n value === 'orders' ||\n value === 'fulfillments' ||\n value === 'returns' ||\n value === 'payment-sessions' ||\n value === 'payment-refund-attempts'\n )\n}\n\nfunction isCommerceNotificationData(\n value: unknown,\n): value is CommerceNotificationData {\n if (!isRecord(value)) return false\n if (\n value.source !== undefined &&\n (!isRecord(value.source) ||\n !isCommerceNotificationSourceCollection(value.source.collection) ||\n !isStringOrNumber(value.source.id))\n ) {\n return false\n }\n\n return (\n (value.orderId === undefined || isStringOrNumber(value.orderId)) &&\n (value.orderNumber === undefined ||\n typeof value.orderNumber === 'string') &&\n (value.status === undefined || typeof value.status === 'string') &&\n (value.totalAmount === undefined ||\n typeof value.totalAmount === 'number') &&\n (value.currency === undefined || typeof value.currency === 'string') &&\n (value.fulfillmentId === undefined ||\n isStringOrNumber(value.fulfillmentId)) &&\n (value.fulfillmentStatus === undefined ||\n typeof value.fulfillmentStatus === 'string') &&\n (value.shippedAt === undefined || typeof value.shippedAt === 'string') &&\n (value.returnId === undefined || isStringOrNumber(value.returnId)) &&\n (value.returnStatus === undefined ||\n typeof value.returnStatus === 'string') &&\n (value.refundAmount === undefined ||\n typeof value.refundAmount === 'number') &&\n (value.completedAt === undefined ||\n typeof value.completedAt === 'string') &&\n (value.paymentSessionId === undefined ||\n typeof value.paymentSessionId === 'string') &&\n (value.checkoutId === undefined || typeof value.checkoutId === 'string') &&\n (value.refundAttemptId === undefined ||\n typeof value.refundAttemptId === 'string') &&\n (value.reason === undefined || typeof value.reason === 'string') &&\n (value.observedAt === undefined || typeof value.observedAt === 'string') &&\n (value.providerObject === undefined ||\n (isRecord(value.providerObject) &&\n typeof value.providerObject.provider === 'string' &&\n (value.providerObject.kind === 'payment' ||\n value.providerObject.kind === 'refund') &&\n typeof value.providerObject.id === 'string')) &&\n (value.money === undefined ||\n (isRecord(value.money) &&\n Number.isSafeInteger(value.money.amountMinor) &&\n Number(value.money.amountMinor) > 0 &&\n typeof value.money.currency === 'string'))\n )\n}\n\nfunction isCommerceNotification(value: unknown): value is CommerceNotification {\n if (!isRecord(value)) return false\n return (\n isCommerceNotificationEventName(value.event) &&\n typeof value.intentId === 'string' &&\n value.intentId.length > 0 &&\n typeof value.dedupeKey === 'string' &&\n value.dedupeKey.length > 0 &&\n (value.orderId === undefined || typeof value.orderId === 'string') &&\n (value.fulfillmentId === undefined ||\n typeof value.fulfillmentId === 'string') &&\n (value.returnId === undefined || typeof value.returnId === 'string') &&\n (value.paymentSessionId === undefined ||\n typeof value.paymentSessionId === 'string') &&\n (value.refundAttemptId === undefined ||\n typeof value.refundAttemptId === 'string')\n )\n}\n\nfunction isPaymentIncidentNotificationData(\n value: CommerceNotificationData,\n event: PaymentIncidentNotificationEventName,\n): boolean {\n const reconciliation = event === 'paymentReconciliationRequired'\n const expectedCollection = reconciliation\n ? 'payment-sessions'\n : 'payment-refund-attempts'\n const expectedStatus = reconciliation\n ? 'reconciliation_required'\n : 'requires_attention'\n const expectedReason = reconciliation\n ? 'orderless_capture'\n : 'local_commit_ambiguous'\n\n return (\n value.source?.collection === expectedCollection &&\n typeof value.source.id === 'string' &&\n value.source.id.length > 0 &&\n typeof value.paymentSessionId === 'string' &&\n value.paymentSessionId.length > 0 &&\n isRecord(value.providerObject) &&\n typeof value.providerObject.provider === 'string' &&\n value.providerObject.provider.length > 0 &&\n (value.providerObject.kind === 'payment' ||\n value.providerObject.kind === 'refund') &&\n typeof value.providerObject.id === 'string' &&\n value.providerObject.id.length > 0 &&\n isRecord(value.money) &&\n Number.isSafeInteger(value.money.amountMinor) &&\n Number(value.money.amountMinor) > 0 &&\n typeof value.money.currency === 'string' &&\n value.money.currency.length > 0 &&\n value.status === expectedStatus &&\n value.reason === expectedReason &&\n typeof value.observedAt === 'string' &&\n value.observedAt.length > 0 &&\n !Number.isNaN(Date.parse(value.observedAt)) &&\n (value.checkoutId === undefined ||\n (typeof value.checkoutId === 'string' && value.checkoutId.length > 0)) &&\n (value.orderId === undefined ||\n (typeof value.orderId === 'string' && value.orderId.length > 0)) &&\n (reconciliation\n ? value.source.id === value.paymentSessionId &&\n value.providerObject.kind === 'payment' &&\n value.refundAttemptId === undefined\n : typeof value.refundAttemptId === 'string' &&\n value.refundAttemptId.length > 0 &&\n value.source.id === value.refundAttemptId)\n )\n}\n\nfunction isWebhookCommerceNotificationChange(\n value: unknown,\n): value is WebhookCommerceNotificationChange {\n if (!isRecord(value)) return false\n return (\n value.type === 'notification' &&\n value.source === 'commerce-notifications' &&\n isCommerceNotificationEventName(value.event) &&\n isCommerceNotificationSourceCollection(value.sourceCollection) &&\n isStringOrNumber(value.sourceId)\n )\n}\n\nfunction matchesOptionalId(\n actual: string | number | undefined,\n expected: string | number | undefined,\n): boolean {\n return actual === undefined || expected === undefined || actual === expected\n}\n\n/**\n * Returns true for semantic order-change webhooks emitted as update events.\n *\n * Use this guard with `ORDER_CHANGED_EVENT_TYPE` instead of filtering on\n * `operation: \"reorder\"`. Tenant order-change webhooks intentionally keep\n * `operation: \"update\"` for compatibility with existing webhook handlers.\n */\nexport function isOrderChangedWebhookEvent(\n event: unknown,\n): event is OrderChangedWebhookEvent<string, unknown> {\n if (\n !isValidWebhookEvent(event) ||\n event.operation !== 'update' ||\n event.eventType !== ORDER_CHANGED_EVENT_TYPE ||\n !isWebhookOrderChange(event.change)\n ) {\n return false\n }\n\n if (event.collection !== event.change.scope.collection) {\n return false\n }\n\n if (\n event.change.scope.kind === 'collection' &&\n event.change.moved.collection !== event.change.scope.collection\n ) {\n return false\n }\n\n return true\n}\n\n/**\n * Returns true for semantic commerce notification webhooks.\n *\n * Use `notification.intentId` and `notification.dedupeKey` for semantic\n * idempotency. `deliveryId`, when present, identifies a delivery attempt for\n * observability and is not the semantic notification identity.\n */\nexport function isCommerceNotificationWebhookEvent(\n event: unknown,\n): event is CommerceNotificationWebhookEvent {\n if (\n !isValidWebhookEvent(event) ||\n event.operation !== COMMERCE_NOTIFICATION_OPERATION ||\n event.eventType !== COMMERCE_NOTIFICATION_EVENT_TYPE ||\n !isCommerceNotificationData(event.data) ||\n !isCommerceNotification((event as { notification?: unknown }).notification)\n ) {\n return false\n }\n\n const notification = (event as unknown as CommerceNotificationWebhookEvent)\n .notification\n const data = event.data\n const change = event.change\n const sourceCollection = data.source?.collection ?? event.collection\n const sourceId = data.source?.id\n\n if (!isCommerceNotificationSourceCollection(sourceCollection)) return false\n if (\n data.source !== undefined &&\n event.collection !== data.source.collection\n ) {\n return false\n }\n\n if (change !== undefined) {\n if (!isWebhookCommerceNotificationChange(change)) return false\n if (change.sourceCollection !== sourceCollection) return false\n if (change.event !== notification.event) return false\n if (!matchesOptionalId(change.sourceId, sourceId)) return false\n }\n const changeSourceId = isWebhookCommerceNotificationChange(change)\n ? change.sourceId\n : undefined\n\n if (\n notification.event === 'paymentReconciliationRequired' ||\n notification.event === 'paymentRefundRequiresAttention'\n ) {\n if (!isPaymentIncidentNotificationData(data, notification.event)) {\n return false\n }\n const incidentData = data as PaymentIncidentNotificationData\n const expectedCollection =\n notification.event === 'paymentReconciliationRequired'\n ? 'payment-sessions'\n : 'payment-refund-attempts'\n const notificationSourceId =\n notification.event === 'paymentReconciliationRequired'\n ? notification.paymentSessionId\n : notification.refundAttemptId\n return (\n sourceCollection === expectedCollection &&\n typeof notification.paymentSessionId === 'string' &&\n notification.paymentSessionId === incidentData.paymentSessionId &&\n typeof notificationSourceId === 'string' &&\n notificationSourceId === incidentData.source.id &&\n matchesOptionalId(changeSourceId, incidentData.source.id)\n )\n }\n\n if (\n notification.event === 'orderPaid' ||\n notification.event === 'orderCanceled' ||\n notification.event === 'orderDelivered'\n ) {\n return (\n sourceCollection === 'orders' &&\n typeof notification.orderId === 'string' &&\n notification.orderId.length > 0 &&\n matchesOptionalId(data.orderId, sourceId) &&\n matchesOptionalId(notification.orderId, sourceId) &&\n matchesOptionalId(data.orderId, notification.orderId) &&\n matchesOptionalId(changeSourceId, data.orderId ?? notification.orderId)\n )\n }\n\n if (notification.event === 'fulfillmentShipped') {\n return (\n sourceCollection === 'fulfillments' &&\n matchesOptionalId(data.fulfillmentId, sourceId) &&\n typeof notification.fulfillmentId === 'string' &&\n notification.fulfillmentId.length > 0 &&\n matchesOptionalId(notification.fulfillmentId, sourceId) &&\n matchesOptionalId(data.fulfillmentId, notification.fulfillmentId) &&\n matchesOptionalId(changeSourceId, notification.fulfillmentId)\n )\n }\n\n if (\n notification.event === 'returnRequested' ||\n notification.event === 'returnApproved' ||\n notification.event === 'returnRejected' ||\n notification.event === 'returnCanceled' ||\n notification.event === 'returnCompleted'\n ) {\n return (\n sourceCollection === 'returns' &&\n matchesOptionalId(data.returnId, sourceId) &&\n typeof notification.returnId === 'string' &&\n notification.returnId.length > 0 &&\n matchesOptionalId(notification.returnId, sourceId) &&\n matchesOptionalId(data.returnId, notification.returnId) &&\n matchesOptionalId(changeSourceId, notification.returnId)\n )\n }\n\n return false\n}\n\nexport function getCommerceNotificationIdempotencyKey(\n event: Pick<CommerceNotificationWebhookEvent, 'notification'>,\n): string {\n return `${event.notification.intentId}:${event.notification.dedupeKey}`\n}\n\nexport function defineCommerceEmailConfig<TConfig extends CommerceEmailConfig>(\n config: TConfig,\n): TConfig {\n return config\n}\n\nexport function createCommerceNotificationWebhookHandler(\n handlers: CommerceNotificationEventHandlers,\n): WebhookHandler<string, unknown> {\n return async (event) => {\n if (!isCommerceNotificationWebhookEvent(event)) {\n await handlers.unhandled?.(event)\n return\n }\n\n const handler = handlers[event.notification.event]\n if (!handler) {\n await handlers.unhandled?.(event)\n return\n }\n\n await handler({\n event,\n idempotencyKey: getCommerceNotificationIdempotencyKey(event),\n })\n }\n}\n\nexport function createCommerceEmailWebhookHandler(\n handlers: CommerceEmailEventHandlers,\n): WebhookHandler<string, unknown> {\n return createCommerceNotificationWebhookHandler(handlers)\n}\n\n/** Narrows a webhook event to a specific collection. */\nexport function isWebhookCollection<TCollection extends string>(\n event: unknown,\n collection: TCollection,\n): event is WebhookEvent<TCollection, unknown> {\n return isValidWebhookEvent(event) && event.collection === collection\n}\n\n/** Narrows a webhook event to a specific operation. */\nexport function isWebhookOperation<TOperation extends string>(\n event: unknown,\n operation: TOperation,\n): event is WebhookEvent<string, unknown> & { operation: TOperation } {\n return isValidWebhookEvent(event) && event.operation === operation\n}\n\nexport const CUSTOMER_PASSWORD_RESET_OPERATION = 'password-reset' as const\n\nexport type WebhookKnownOperation =\n | CollectionWebhookOperation\n | typeof CUSTOMER_PASSWORD_RESET_OPERATION\n | typeof COMMERCE_NOTIFICATION_OPERATION\n\nexport interface CustomerPasswordResetWebhookData {\n customerId: string | number\n email: string\n name: string\n resetPasswordToken: string\n resetPasswordExpiresAt: string\n}\n\nexport type CustomerPasswordResetWebhookEvent = WebhookEvent<\n 'customers',\n CustomerPasswordResetWebhookData\n> & {\n operation: typeof CUSTOMER_PASSWORD_RESET_OPERATION\n}\n\nexport type CustomerAuthWebhookEvent = CustomerPasswordResetWebhookEvent\n\nexport interface CustomerAuthWebhookHandlers {\n passwordReset?: (\n data: CustomerPasswordResetWebhookData,\n event: CustomerPasswordResetWebhookEvent,\n ) => MaybePromise<void>\n unhandled?: (event: WebhookEvent<string, unknown>) => MaybePromise<void>\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\n}\n\nfunction hasString(value: Record<string, unknown>, key: string): boolean {\n return typeof value[key] === 'string'\n}\n\nfunction hasStringOrNumber(\n value: Record<string, unknown>,\n key: string,\n): boolean {\n return typeof value[key] === 'string' || typeof value[key] === 'number'\n}\n\nexport function isCustomerPasswordResetWebhookEvent(\n event: WebhookEvent<string, unknown>,\n): event is CustomerPasswordResetWebhookEvent {\n if (\n event.collection !== 'customers' ||\n event.operation !== CUSTOMER_PASSWORD_RESET_OPERATION ||\n !isRecord(event.data)\n ) {\n return false\n }\n\n return (\n hasStringOrNumber(event.data, 'customerId') &&\n hasString(event.data, 'email') &&\n hasString(event.data, 'name') &&\n hasString(event.data, 'resetPasswordToken') &&\n hasString(event.data, 'resetPasswordExpiresAt')\n )\n}\n\nexport function createCustomerAuthWebhookHandler(\n handlers: CustomerAuthWebhookHandlers,\n): WebhookHandler<string, unknown> {\n return async (event) => {\n if (isCustomerPasswordResetWebhookEvent(event) && handlers.passwordReset) {\n await handlers.passwordReset(event.data, event)\n return\n }\n\n await handlers.unhandled?.(event)\n }\n}\n\n/**\n * @deprecated Import `handleSignedWebhook()` from `@01.software/sdk/webhook`.\n * This compatibility alias is signed and fails closed when its required secret\n * is missing or blank.\n */\nexport async function handleWebhook<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(\n request: Request,\n handler: WebhookHandler<T, TData>,\n options: WebhookOptions,\n): Promise<Response> {\n return handleSignedWebhookInternal(request, handler, options)\n}\n\nexport function createTypedWebhookHandler<T extends Collection>(\n collection: T,\n handler: (event: WebhookEvent<T>) => Promise<void> | void,\n): WebhookHandler<T> {\n return async (event: WebhookEvent<T>) => {\n if (event.collection !== collection) {\n throw new Error(\n `Expected collection \"${collection}\", got \"${event.collection}\"`,\n )\n }\n return handler(event)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,wBAAwB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AAO,OAAO,MAAM,GAAG,MAAM;AAC/B;AAEA,SAAS,kBACP,OACA,KACS;AACT,SAAO,OAAO,MAAM,GAAG,MAAM,YAAY,OAAO,MAAM,GAAG,MAAM;AACjE;AAEO,SAAS,oCACd,OAC4C;AAC5C,MACE,MAAM,eAAe,eACrB,MAAM,cAAc,qCACpB,CAAC,SAAS,MAAM,IAAI,GACpB;AACA,WAAO;AAAA,EACT;AAEA,SACE,kBAAkB,MAAM,MAAM,YAAY,KAC1C,UAAU,MAAM,MAAM,OAAO,KAC7B,UAAU,MAAM,MAAM,MAAM,KAC5B,UAAU,MAAM,MAAM,oBAAoB,KAC1C,UAAU,MAAM,MAAM,wBAAwB;AAElD;AAEO,SAAS,iCACd,UACiC;AACjC,SAAO,OAAO,UAAU;AACtB,QAAI,oCAAoC,KAAK,KAAK,SAAS,eAAe;AACxE,YAAM,SAAS,cAAc,MAAM,MAAM,KAAK;AAC9C;AAAA,IACF;AAEA,UAAM,SAAS,YAAY,KAAK;AAAA,EAClC;AACF;AAOA,eAAsB,cAIpB,SACA,SACA,SACmB;AACnB,SAAO,oBAA4B,SAAS,SAAS,OAAO;AAC9D;AAEO,SAAS,0BACd,YACA,SACmB;AACnB,SAAO,OAAO,UAA2B;AACvC,QAAI,MAAM,eAAe,YAAY;AACnC,YAAM,IAAI;AAAA,QACR,wBAAwB,UAAU,WAAW,MAAM,UAAU;AAAA,MAC/D;AAAA,IACF;AACA,WAAO,QAAQ,KAAK;AAAA,EACtB;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/webhook.ts","../src/core/webhook/validation.ts","../src/core/webhook/receiver.ts","../src/core/webhook/index.ts"],"sourcesContent":["export {\n handleWebhook,\n createTypedWebhookHandler,\n createCommerceEmailWebhookHandler,\n createCommerceNotificationWebhookHandler,\n createCustomerAuthWebhookHandler,\n defineCommerceEmailConfig,\n getCommerceNotificationIdempotencyKey,\n isValidWebhookEvent,\n isCommerceNotificationWebhookEvent,\n isCustomerPasswordResetWebhookEvent,\n isOrderChangedWebhookEvent,\n isWebhookCollection,\n isWebhookOperation,\n CUSTOMER_PASSWORD_RESET_OPERATION,\n COMMERCE_NOTIFICATION_EVENT_TYPE,\n COMMERCE_NOTIFICATION_EVENTS,\n COMMERCE_NOTIFICATION_OPERATION,\n ORDER_CHANGED_EVENT_TYPE,\n} from './core/webhook'\nexport type {\n CollectionWebhookOperation,\n CommerceEmailChannel,\n CommerceEmailConfig,\n CommerceEmailEventConfig,\n CommerceEmailEventHandlers,\n CommerceEmailHandlerContext,\n CommerceNotification,\n CommerceNotificationData,\n CommerceNotificationEventName,\n CommerceNotificationEventHandlers,\n CommerceNotificationHandlerContext,\n CommerceNotificationSource,\n CommerceNotificationSourceCollection,\n CommerceNotificationWebhookEvent,\n CustomerAuthWebhookEvent,\n CustomerAuthWebhookHandlers,\n CustomerPasswordResetWebhookData,\n CustomerPasswordResetWebhookEvent,\n OrderChangedWebhookEvent,\n PaymentIncidentMoney,\n PaymentIncidentNotificationData,\n PaymentIncidentNotificationEventName,\n PaymentIncidentNotificationReason,\n PaymentIncidentNotificationSourceCollection,\n PaymentIncidentNotificationStatus,\n PaymentIncidentProviderObject,\n MembershipNotificationData,\n MembershipNotificationEventName,\n WebhookChange,\n WebhookCommerceNotificationChange,\n WebhookEvent,\n WebhookHandler,\n WebhookKnownOperation,\n WebhookOperation,\n WebhookOptions,\n WebhookOrderChange,\n WebhookOrderMoved,\n WebhookOrderScope,\n} from './core/webhook'\nexport {\n handleSignedWebhook,\n handleUnsignedWebhook,\n} from './core/webhook/receiver'\nexport type { SignedWebhookOptions } from './core/webhook/receiver'\nexport type {\n WebhookSigningSecretReveal,\n WebhookWithoutSecret,\n} from './webhook-types'\n","export function isValidWebhookEventData(data: unknown): boolean {\n if (typeof data !== 'object' || data === null) return false\n const event = data as Record<string, unknown>\n return (\n typeof event.collection === 'string' &&\n typeof event.operation === 'string' &&\n event.operation.length > 0 &&\n typeof event.data === 'object' &&\n event.data !== null\n )\n}\n","import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\nimport type { WebhookEvent, WebhookHandler } from './index'\nimport { isValidWebhookEventData } from './validation'\n\nexport interface SignedWebhookOptions {\n /** Nonblank HMAC-SHA256 signing secret for this receiver. */\n secret: string\n /**\n * Max accepted skew for signed webhook delivery timestamps. Default: 300s.\n * Must be a number between 0 and 86400 inclusive; anything else is a\n * configuration error, because an unbounded or effectively unbounded window\n * would accept an arbitrarily old replay.\n */\n toleranceSeconds?: number\n}\n\nasync function verifySignature(\n rawBody: Uint8Array,\n secret: string,\n signature: string,\n timestamp: string,\n deliveryId: string,\n): Promise<boolean> {\n const encoder = new TextEncoder()\n const signedPrefix = encoder.encode(`${timestamp}.${deliveryId}.`)\n const signedPayload = new Uint8Array(signedPrefix.length + rawBody.length)\n signedPayload.set(signedPrefix)\n signedPayload.set(rawBody, signedPrefix.length)\n const key = await crypto.subtle.importKey(\n 'raw',\n encoder.encode(secret),\n { name: 'HMAC', hash: 'SHA-256' },\n false,\n ['verify'],\n )\n if (signature.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(signature)) {\n return false\n }\n const sigBytes = new Uint8Array(\n (signature.match(/.{2}/g) ?? []).map((byte) => parseInt(byte, 16)),\n )\n return crypto.subtle.verify('HMAC', key, sigBytes, signedPayload)\n}\n\nfunction timestampIsFresh(\n timestamp: string,\n toleranceSeconds: number,\n): boolean {\n if (!/^\\d+$/.test(timestamp)) return false\n const timestampMs = Number(timestamp)\n if (!Number.isFinite(timestampMs)) return false\n const skewMs = Math.abs(Date.now() - timestampMs)\n return skewMs <= toleranceSeconds * 1000\n}\n\n/**\n * Upper bound for the signed replay window. A merely finite tolerance is not\n * enough: `Number.MAX_VALUE * 1000` overflows to `Infinity`, and even without\n * overflow a value of that size accepts an arbitrarily old capture. The sender's\n * retry and dead-letter lifecycle completes far inside a day, so anything beyond\n * this is a misconfiguration rather than clock-skew tolerance.\n */\nconst MAX_TOLERANCE_SECONDS = 86_400\n\n/**\n * A signed receiver's replay window must stay bounded. A non-finite, negative,\n * or over-bound tolerance would silently accept an old capture, so it is a\n * configuration error rather than a request-authentication failure.\n */\nfunction toleranceIsValid(\n toleranceSeconds: unknown,\n): toleranceSeconds is number {\n return (\n typeof toleranceSeconds === 'number' &&\n Number.isFinite(toleranceSeconds) &&\n toleranceSeconds >= 0 &&\n toleranceSeconds <= MAX_TOLERANCE_SECONDS\n )\n}\n\nasync function processWebhookRequest<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(\n request: Request,\n handler: WebhookHandler<T, TData>,\n verify?: (rawBody: Uint8Array) => Promise<Response | undefined>,\n): Promise<Response> {\n try {\n const rawBody = new Uint8Array(await request.arrayBuffer())\n const verificationFailure = await verify?.(rawBody)\n if (verificationFailure) return verificationFailure\n\n const body = JSON.parse(new TextDecoder().decode(rawBody))\n if (!isValidWebhookEventData(body)) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook event format' }),\n { status: 400, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n await handler(body as WebhookEvent<T, TData>)\n return new Response(\n JSON.stringify({ success: true, message: 'Webhook processed' }),\n { status: 200, headers: { 'Content-Type': 'application/json' } },\n )\n } catch (error) {\n console.error('Webhook processing error:', error)\n return new Response(JSON.stringify({ error: 'Internal server error' }), {\n status: 500,\n headers: { 'Content-Type': 'application/json' },\n })\n }\n}\n\nexport async function handleSignedWebhook<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(\n request: Request,\n handler: WebhookHandler<T, TData>,\n options: SignedWebhookOptions,\n): Promise<Response> {\n // Read each configuration value exactly once. Re-reading `options` would let\n // a getter return a valid secret to the guard and a different one to the\n // verifier, so the validated bytes are the only bytes this receiver uses.\n const secret: unknown = options?.secret\n const configuredTolerance: unknown = options?.toleranceSeconds\n // `??` so an absent or null tolerance keeps the documented default, exactly as\n // before this change; only a present, out-of-contract value is rejected.\n const toleranceSeconds = configuredTolerance ?? 300\n\n if (typeof secret !== 'string' || secret.trim().length === 0) {\n return new Response(\n JSON.stringify({ error: 'Webhook signing secret is not configured' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n // Reported separately so a tolerance mistake is not misdiagnosed as a bad secret.\n if (!toleranceIsValid(toleranceSeconds)) {\n return new Response(\n JSON.stringify({ error: 'Webhook signature tolerance is not valid' }),\n { status: 500, headers: { 'Content-Type': 'application/json' } },\n )\n }\n\n return processWebhookRequest(request, handler, async (rawBody) => {\n const signature = request.headers.get('x-webhook-signature') || ''\n const timestamp = request.headers.get('x-webhook-timestamp') || ''\n const deliveryId = request.headers.get('x-webhook-delivery-id') || ''\n const valid =\n Boolean(timestamp && deliveryId) &&\n timestampIsFresh(timestamp, toleranceSeconds) &&\n (await verifySignature(rawBody, secret, signature, timestamp, deliveryId))\n\n if (!valid) {\n return new Response(\n JSON.stringify({ error: 'Invalid webhook signature' }),\n { status: 401, headers: { 'Content-Type': 'application/json' } },\n )\n }\n })\n}\n\n/** Process a webhook only when its endpoint is intentionally unsigned. */\nexport async function handleUnsignedWebhook<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(request: Request, handler: WebhookHandler<T, TData>): Promise<Response> {\n return processWebhookRequest(request, handler)\n}\n","import type { Collection } from '../client/types'\nimport type { CollectionType } from '../collection/types'\nimport { handleSignedWebhook as handleSignedWebhookInternal } from './receiver'\nimport { isValidWebhookEventData } from './validation'\n\nexport type WebhookOperation = string\n\n/**\n * Semantic event type for manual Admin Panel ordering changes.\n *\n * Order-change webhooks remain `operation: \"update\"` events for compatibility.\n * Do not filter on or emit `operation: \"reorder\"`; use this event type with\n * `isOrderChangedWebhookEvent()` to distinguish ordering from normal content\n * updates.\n */\nexport const ORDER_CHANGED_EVENT_TYPE = 'collection.orderChanged' as const\n\n/** Semantic event type for v1 commerce notification webhooks. */\nexport const COMMERCE_NOTIFICATION_EVENT_TYPE = 'commerce.notification' as const\n\n/** Collection webhook operations emitted for tenant collection writes. */\nexport type CollectionWebhookOperation = 'create' | 'update'\n\n/** Describes the ordered area affected by an order-change webhook. */\nexport type WebhookOrderScope =\n | { kind: 'collection'; collection: string }\n | { kind: 'join'; collection: string; field: string; id: string | number }\n\n/** Identifies the public moved document for the ordered scope. */\nexport type WebhookOrderMoved = {\n collection: string\n id: string | number\n relatedCollection?: string\n relatedId?: string | number\n}\n\n/** Metadata attached to `collection.orderChanged` webhook events. */\nexport type WebhookOrderChange = {\n type: 'order'\n source: 'payload-orderable'\n /**\n * Diagnostic Payload order field name.\n *\n * This may contain hidden implementation field names. Application routing\n * should use `change.scope` and `change.moved` instead.\n */\n orderableFieldName?: string\n previousOrder?: string | null\n nextOrder?: string | null\n scope: WebhookOrderScope\n moved: WebhookOrderMoved\n}\n\n/** Known semantic webhook change metadata. */\nexport type WebhookChange =\n | WebhookOrderChange\n | WebhookCommerceNotificationChange\n\nexport interface WebhookEvent<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n> {\n collection: T\n operation: WebhookOperation\n data: TData\n eventType?: string\n change?: unknown\n timestamp?: string\n deliveryId?: string\n}\n\nexport type WebhookHandler<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n> = (event: WebhookEvent<T, TData>) => Promise<void> | void\n\n/** @deprecated Use the signed receiver options from `@01.software/sdk/webhook`. */\nexport interface WebhookOptions {\n /** Nonblank HMAC-SHA256 signing secret for this receiver. */\n secret: string\n /** Max accepted skew for signed webhook delivery timestamps. Default: 300s. */\n toleranceSeconds?: number\n}\n\nexport function isValidWebhookEvent(data: unknown): data is WebhookEvent {\n return isValidWebhookEventData(data)\n}\n\n/** Webhook event emitted when manual Admin Panel ordering changes. */\nexport type OrderChangedWebhookEvent<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n> = WebhookEvent<T, TData> & {\n operation: 'update'\n eventType: typeof ORDER_CHANGED_EVENT_TYPE\n change: WebhookOrderChange\n}\n\nexport const COMMERCE_NOTIFICATION_OPERATION = 'notification' as const\n\nexport const COMMERCE_NOTIFICATION_EVENTS = [\n 'orderPaid',\n 'orderCanceled',\n 'fulfillmentShipped',\n 'orderDelivered',\n 'returnRequested',\n 'returnApproved',\n 'returnRejected',\n 'returnCanceled',\n 'returnCompleted',\n 'paymentReconciliationRequired',\n 'paymentRefundRequiresAttention',\n 'membershipActivated',\n 'membershipPastDue',\n 'membershipExpired',\n 'membershipCancelled',\n] as const\n\nexport type CommerceNotificationEventName =\n (typeof COMMERCE_NOTIFICATION_EVENTS)[number]\n\nexport type CustomerCommerceNotificationEventName = Exclude<\n CommerceNotificationEventName,\n PaymentIncidentNotificationEventName | MembershipNotificationEventName\n>\n\nexport type CommerceNotificationSourceCollection =\n | 'orders'\n | 'fulfillments'\n | 'returns'\n | 'payment-sessions'\n | 'payment-refund-attempts'\n | 'customer-memberships'\n\nexport type CommerceNotificationSource = {\n collection: CommerceNotificationSourceCollection\n id: string | number\n}\n\nexport type PaymentIncidentNotificationEventName =\n | 'paymentReconciliationRequired'\n | 'paymentRefundRequiresAttention'\n\nexport type MembershipNotificationEventName =\n | 'membershipActivated'\n | 'membershipPastDue'\n | 'membershipExpired'\n | 'membershipCancelled'\n\nexport type MembershipNotificationData = {\n membershipId: string\n planId: string\n /** Tenant-scoped pseudonymous identifier; this is not a PII-free claim. */\n customerId: string\n fromStatus: string\n toStatus: 'active' | 'past_due' | 'expired' | 'cancelled'\n occurredAt: string\n}\n\nexport type PaymentIncidentNotificationSourceCollection =\n | 'payment-sessions'\n | 'payment-refund-attempts'\n\nexport type PaymentIncidentNotificationReason =\n | 'orderless_capture'\n | 'local_commit_ambiguous'\n\nexport type PaymentIncidentNotificationStatus =\n | 'reconciliation_required'\n | 'requires_attention'\n\nexport type PaymentIncidentProviderObject = {\n provider: string\n kind: 'payment' | 'refund'\n id: string\n}\n\nexport type PaymentIncidentMoney = {\n amountMinor: number\n currency: string\n}\n\ntype PaymentIncidentNotificationBase = {\n paymentSessionId: string\n checkoutId?: string\n orderId?: string\n providerObject: PaymentIncidentProviderObject\n money: PaymentIncidentMoney\n observedAt: string\n}\n\nexport type PaymentReconciliationRequiredNotificationData =\n PaymentIncidentNotificationBase & {\n source: {\n collection: 'payment-sessions'\n id: string\n }\n providerObject: PaymentIncidentProviderObject & { kind: 'payment' }\n status: 'reconciliation_required'\n reason: 'orderless_capture'\n refundAttemptId?: never\n }\n\nexport type PaymentRefundRequiresAttentionNotificationData =\n PaymentIncidentNotificationBase & {\n source: { collection: 'payment-refund-attempts'; id: string }\n refundAttemptId: string\n status: 'requires_attention'\n reason: 'local_commit_ambiguous'\n }\n\nexport type PaymentIncidentNotificationData =\n | PaymentReconciliationRequiredNotificationData\n | PaymentRefundRequiresAttentionNotificationData\n\nexport type CommerceNotificationData = {\n source?: CommerceNotificationSource\n orderId?: string | number\n orderNumber?: string\n status?: string\n totalAmount?: number\n currency?: string\n fulfillmentId?: string | number\n fulfillmentStatus?: string\n shippedAt?: string\n returnId?: string | number\n returnStatus?: string\n refundAmount?: number\n completedAt?: string\n paymentSessionId?: string\n checkoutId?: string\n refundAttemptId?: string\n providerObject?: PaymentIncidentProviderObject\n money?: PaymentIncidentMoney\n reason?: PaymentIncidentNotificationReason\n observedAt?: string\n membershipId?: string\n planId?: string\n customerId?: string\n fromStatus?: string\n toStatus?: string\n occurredAt?: string\n}\n\nexport type CommerceNotification = {\n event: CommerceNotificationEventName\n intentId: string\n dedupeKey: string\n orderId?: string\n fulfillmentId?: string\n returnId?: string\n paymentSessionId?: string\n refundAttemptId?: string\n membershipId?: string\n}\n\nexport type WebhookCommerceNotificationChange = {\n type: 'notification'\n source: 'commerce-notifications'\n event: CommerceNotificationEventName\n sourceCollection: CommerceNotificationSourceCollection\n sourceId: string | number\n}\n\n/** Webhook event emitted for v1 commerce notification deliveries. */\nexport type CommerceNotificationWebhookEvent = WebhookEvent<\n CommerceNotificationSourceCollection,\n CommerceNotificationData\n> & {\n operation: typeof COMMERCE_NOTIFICATION_OPERATION\n eventType: typeof COMMERCE_NOTIFICATION_EVENT_TYPE\n change?: WebhookCommerceNotificationChange\n notification: CommerceNotification\n}\n\nexport type CommerceEmailChannel = 'webhook' | 'provider'\n\nexport type CommerceEmailEventConfig = {\n enabled: boolean\n channel: CommerceEmailChannel\n template?: string\n}\n\nexport type CommerceEmailConfig = {\n version: 1\n commerceNotifications: Partial<\n Record<CustomerCommerceNotificationEventName, CommerceEmailEventConfig>\n >\n}\n\nexport type CommerceNotificationHandlerContext = {\n event: CommerceNotificationWebhookEvent\n idempotencyKey: string\n}\n\ntype MaybePromise<T> = T | Promise<T>\n\nexport type CommerceNotificationEventHandlers = Partial<\n Record<\n CommerceNotificationEventName,\n (context: CommerceNotificationHandlerContext) => MaybePromise<void>\n >\n> & {\n unhandled?: (event: WebhookEvent<string, unknown>) => MaybePromise<void>\n}\n\nexport type CommerceEmailHandlerContext = CommerceNotificationHandlerContext\n\nexport type CommerceEmailEventHandlers = Partial<\n Record<\n CustomerCommerceNotificationEventName,\n (context: CommerceEmailHandlerContext) => MaybePromise<void>\n >\n> & {\n unhandled?: (event: WebhookEvent<string, unknown>) => MaybePromise<void>\n}\n\nfunction isStringOrNumber(value: unknown): value is string | number {\n return typeof value === 'string' || typeof value === 'number'\n}\n\nfunction isWebhookOrderScope(value: unknown): value is WebhookOrderScope {\n if (!isRecord(value)) return false\n\n if (value.kind === 'collection') {\n return typeof value.collection === 'string'\n }\n\n if (value.kind === 'join') {\n return (\n typeof value.collection === 'string' &&\n typeof value.field === 'string' &&\n isStringOrNumber(value.id)\n )\n }\n\n return false\n}\n\nfunction isWebhookOrderMoved(value: unknown): value is WebhookOrderMoved {\n if (!isRecord(value)) return false\n\n return (\n typeof value.collection === 'string' &&\n isStringOrNumber(value.id) &&\n (value.relatedCollection === undefined ||\n typeof value.relatedCollection === 'string') &&\n (value.relatedId === undefined || isStringOrNumber(value.relatedId))\n )\n}\n\nfunction hasOptionalOrderValue(\n value: Record<string, unknown>,\n key: string,\n): boolean {\n return (\n value[key] === undefined ||\n value[key] === null ||\n typeof value[key] === 'string'\n )\n}\n\nfunction isWebhookOrderChange(value: unknown): value is WebhookOrderChange {\n if (!isRecord(value)) return false\n\n return (\n value.type === 'order' &&\n value.source === 'payload-orderable' &&\n (value.orderableFieldName === undefined ||\n typeof value.orderableFieldName === 'string') &&\n hasOptionalOrderValue(value, 'previousOrder') &&\n hasOptionalOrderValue(value, 'nextOrder') &&\n isWebhookOrderScope(value.scope) &&\n isWebhookOrderMoved(value.moved)\n )\n}\n\nfunction isCommerceNotificationEventName(\n value: unknown,\n): value is CommerceNotificationEventName {\n return (\n typeof value === 'string' &&\n (COMMERCE_NOTIFICATION_EVENTS as readonly string[]).includes(value)\n )\n}\n\nfunction isCommerceNotificationSourceCollection(\n value: unknown,\n): value is CommerceNotificationSourceCollection {\n return (\n value === 'orders' ||\n value === 'fulfillments' ||\n value === 'returns' ||\n value === 'payment-sessions' ||\n value === 'payment-refund-attempts' ||\n value === 'customer-memberships'\n )\n}\n\nfunction isCommerceNotificationData(\n value: unknown,\n): value is CommerceNotificationData {\n if (!isRecord(value)) return false\n if (\n value.source !== undefined &&\n (!isRecord(value.source) ||\n !isCommerceNotificationSourceCollection(value.source.collection) ||\n !isStringOrNumber(value.source.id))\n ) {\n return false\n }\n\n return (\n (value.orderId === undefined || isStringOrNumber(value.orderId)) &&\n (value.orderNumber === undefined ||\n typeof value.orderNumber === 'string') &&\n (value.status === undefined || typeof value.status === 'string') &&\n (value.totalAmount === undefined ||\n typeof value.totalAmount === 'number') &&\n (value.currency === undefined || typeof value.currency === 'string') &&\n (value.fulfillmentId === undefined ||\n isStringOrNumber(value.fulfillmentId)) &&\n (value.fulfillmentStatus === undefined ||\n typeof value.fulfillmentStatus === 'string') &&\n (value.shippedAt === undefined || typeof value.shippedAt === 'string') &&\n (value.returnId === undefined || isStringOrNumber(value.returnId)) &&\n (value.returnStatus === undefined ||\n typeof value.returnStatus === 'string') &&\n (value.refundAmount === undefined ||\n typeof value.refundAmount === 'number') &&\n (value.completedAt === undefined ||\n typeof value.completedAt === 'string') &&\n (value.paymentSessionId === undefined ||\n typeof value.paymentSessionId === 'string') &&\n (value.checkoutId === undefined || typeof value.checkoutId === 'string') &&\n (value.refundAttemptId === undefined ||\n typeof value.refundAttemptId === 'string') &&\n (value.reason === undefined || typeof value.reason === 'string') &&\n (value.observedAt === undefined || typeof value.observedAt === 'string') &&\n (value.providerObject === undefined ||\n (isRecord(value.providerObject) &&\n typeof value.providerObject.provider === 'string' &&\n (value.providerObject.kind === 'payment' ||\n value.providerObject.kind === 'refund') &&\n typeof value.providerObject.id === 'string')) &&\n (value.money === undefined ||\n (isRecord(value.money) &&\n Number.isSafeInteger(value.money.amountMinor) &&\n Number(value.money.amountMinor) > 0 &&\n typeof value.money.currency === 'string'))\n )\n}\n\nfunction isCommerceNotification(value: unknown): value is CommerceNotification {\n if (!isRecord(value)) return false\n return (\n isCommerceNotificationEventName(value.event) &&\n typeof value.intentId === 'string' &&\n value.intentId.length > 0 &&\n typeof value.dedupeKey === 'string' &&\n value.dedupeKey.length > 0 &&\n (value.orderId === undefined || typeof value.orderId === 'string') &&\n (value.fulfillmentId === undefined ||\n typeof value.fulfillmentId === 'string') &&\n (value.returnId === undefined || typeof value.returnId === 'string') &&\n (value.paymentSessionId === undefined ||\n typeof value.paymentSessionId === 'string') &&\n (value.refundAttemptId === undefined ||\n typeof value.refundAttemptId === 'string')\n )\n}\n\nfunction isPaymentIncidentNotificationData(\n value: CommerceNotificationData,\n event: PaymentIncidentNotificationEventName,\n): boolean {\n const reconciliation = event === 'paymentReconciliationRequired'\n const expectedCollection = reconciliation\n ? 'payment-sessions'\n : 'payment-refund-attempts'\n const expectedStatus = reconciliation\n ? 'reconciliation_required'\n : 'requires_attention'\n const expectedReason = reconciliation\n ? 'orderless_capture'\n : 'local_commit_ambiguous'\n\n return (\n value.source?.collection === expectedCollection &&\n typeof value.source.id === 'string' &&\n value.source.id.length > 0 &&\n typeof value.paymentSessionId === 'string' &&\n value.paymentSessionId.length > 0 &&\n isRecord(value.providerObject) &&\n typeof value.providerObject.provider === 'string' &&\n value.providerObject.provider.length > 0 &&\n (value.providerObject.kind === 'payment' ||\n value.providerObject.kind === 'refund') &&\n typeof value.providerObject.id === 'string' &&\n value.providerObject.id.length > 0 &&\n isRecord(value.money) &&\n Number.isSafeInteger(value.money.amountMinor) &&\n Number(value.money.amountMinor) > 0 &&\n typeof value.money.currency === 'string' &&\n value.money.currency.length > 0 &&\n value.status === expectedStatus &&\n value.reason === expectedReason &&\n typeof value.observedAt === 'string' &&\n value.observedAt.length > 0 &&\n !Number.isNaN(Date.parse(value.observedAt)) &&\n (value.checkoutId === undefined ||\n (typeof value.checkoutId === 'string' && value.checkoutId.length > 0)) &&\n (value.orderId === undefined ||\n (typeof value.orderId === 'string' && value.orderId.length > 0)) &&\n (reconciliation\n ? value.source.id === value.paymentSessionId &&\n value.providerObject.kind === 'payment' &&\n value.refundAttemptId === undefined\n : typeof value.refundAttemptId === 'string' &&\n value.refundAttemptId.length > 0 &&\n value.source.id === value.refundAttemptId)\n )\n}\n\nfunction isMembershipNotificationData(\n value: CommerceNotificationData,\n event: MembershipNotificationEventName,\n): boolean {\n const expectedStatus =\n event === 'membershipActivated'\n ? 'active'\n : event === 'membershipPastDue'\n ? 'past_due'\n : event === 'membershipExpired'\n ? 'expired'\n : 'cancelled'\n return (\n typeof value.membershipId === 'string' &&\n value.membershipId.length > 0 &&\n typeof value.planId === 'string' &&\n value.planId.length > 0 &&\n typeof value.customerId === 'string' &&\n value.customerId.length > 0 &&\n typeof value.fromStatus === 'string' &&\n value.fromStatus.length > 0 &&\n value.fromStatus !== value.toStatus &&\n value.toStatus === expectedStatus &&\n typeof value.occurredAt === 'string' &&\n !Number.isNaN(Date.parse(value.occurredAt))\n )\n}\n\nfunction isWebhookCommerceNotificationChange(\n value: unknown,\n): value is WebhookCommerceNotificationChange {\n if (!isRecord(value)) return false\n return (\n value.type === 'notification' &&\n value.source === 'commerce-notifications' &&\n isCommerceNotificationEventName(value.event) &&\n isCommerceNotificationSourceCollection(value.sourceCollection) &&\n isStringOrNumber(value.sourceId)\n )\n}\n\nfunction matchesOptionalId(\n actual: string | number | undefined,\n expected: string | number | undefined,\n): boolean {\n return actual === undefined || expected === undefined || actual === expected\n}\n\n/**\n * Returns true for semantic order-change webhooks emitted as update events.\n *\n * Use this guard with `ORDER_CHANGED_EVENT_TYPE` instead of filtering on\n * `operation: \"reorder\"`. Tenant order-change webhooks intentionally keep\n * `operation: \"update\"` for compatibility with existing webhook handlers.\n */\nexport function isOrderChangedWebhookEvent(\n event: unknown,\n): event is OrderChangedWebhookEvent<string, unknown> {\n if (\n !isValidWebhookEvent(event) ||\n event.operation !== 'update' ||\n event.eventType !== ORDER_CHANGED_EVENT_TYPE ||\n !isWebhookOrderChange(event.change)\n ) {\n return false\n }\n\n if (event.collection !== event.change.scope.collection) {\n return false\n }\n\n if (\n event.change.scope.kind === 'collection' &&\n event.change.moved.collection !== event.change.scope.collection\n ) {\n return false\n }\n\n return true\n}\n\n/**\n * Returns true for semantic commerce notification webhooks.\n *\n * Use `notification.intentId` and `notification.dedupeKey` for semantic\n * idempotency. `deliveryId`, when present, identifies a delivery attempt for\n * observability and is not the semantic notification identity.\n */\nexport function isCommerceNotificationWebhookEvent(\n event: unknown,\n): event is CommerceNotificationWebhookEvent {\n if (\n !isValidWebhookEvent(event) ||\n event.operation !== COMMERCE_NOTIFICATION_OPERATION ||\n event.eventType !== COMMERCE_NOTIFICATION_EVENT_TYPE ||\n !isCommerceNotificationData(event.data) ||\n !isCommerceNotification((event as { notification?: unknown }).notification)\n ) {\n return false\n }\n\n const notification = (event as unknown as CommerceNotificationWebhookEvent)\n .notification\n const data = event.data\n const change = event.change\n const sourceCollection = data.source?.collection ?? event.collection\n const sourceId = data.source?.id\n\n if (!isCommerceNotificationSourceCollection(sourceCollection)) return false\n if (\n data.source !== undefined &&\n event.collection !== data.source.collection\n ) {\n return false\n }\n\n if (change !== undefined) {\n if (!isWebhookCommerceNotificationChange(change)) return false\n if (change.sourceCollection !== sourceCollection) return false\n if (change.event !== notification.event) return false\n if (!matchesOptionalId(change.sourceId, sourceId)) return false\n }\n const changeSourceId = isWebhookCommerceNotificationChange(change)\n ? change.sourceId\n : undefined\n\n if (\n notification.event === 'paymentReconciliationRequired' ||\n notification.event === 'paymentRefundRequiresAttention'\n ) {\n if (!isPaymentIncidentNotificationData(data, notification.event)) {\n return false\n }\n const incidentData = data as PaymentIncidentNotificationData\n const expectedCollection =\n notification.event === 'paymentReconciliationRequired'\n ? 'payment-sessions'\n : 'payment-refund-attempts'\n const notificationSourceId =\n notification.event === 'paymentReconciliationRequired'\n ? notification.paymentSessionId\n : notification.refundAttemptId\n return (\n sourceCollection === expectedCollection &&\n typeof notification.paymentSessionId === 'string' &&\n notification.paymentSessionId === incidentData.paymentSessionId &&\n typeof notificationSourceId === 'string' &&\n notificationSourceId === incidentData.source.id &&\n matchesOptionalId(changeSourceId, incidentData.source.id)\n )\n }\n\n if (\n notification.event === 'membershipActivated' ||\n notification.event === 'membershipPastDue' ||\n notification.event === 'membershipExpired' ||\n notification.event === 'membershipCancelled'\n ) {\n return (\n sourceCollection === 'customer-memberships' &&\n isMembershipNotificationData(data, notification.event) &&\n typeof notification.membershipId === 'string' &&\n notification.membershipId === data.membershipId &&\n matchesOptionalId(changeSourceId, data.membershipId)\n )\n }\n\n if (\n notification.event === 'orderPaid' ||\n notification.event === 'orderCanceled' ||\n notification.event === 'orderDelivered'\n ) {\n return (\n sourceCollection === 'orders' &&\n typeof notification.orderId === 'string' &&\n notification.orderId.length > 0 &&\n matchesOptionalId(data.orderId, sourceId) &&\n matchesOptionalId(notification.orderId, sourceId) &&\n matchesOptionalId(data.orderId, notification.orderId) &&\n matchesOptionalId(changeSourceId, data.orderId ?? notification.orderId)\n )\n }\n\n if (notification.event === 'fulfillmentShipped') {\n return (\n sourceCollection === 'fulfillments' &&\n matchesOptionalId(data.fulfillmentId, sourceId) &&\n typeof notification.fulfillmentId === 'string' &&\n notification.fulfillmentId.length > 0 &&\n matchesOptionalId(notification.fulfillmentId, sourceId) &&\n matchesOptionalId(data.fulfillmentId, notification.fulfillmentId) &&\n matchesOptionalId(changeSourceId, notification.fulfillmentId)\n )\n }\n\n if (\n notification.event === 'returnRequested' ||\n notification.event === 'returnApproved' ||\n notification.event === 'returnRejected' ||\n notification.event === 'returnCanceled' ||\n notification.event === 'returnCompleted'\n ) {\n return (\n sourceCollection === 'returns' &&\n matchesOptionalId(data.returnId, sourceId) &&\n typeof notification.returnId === 'string' &&\n notification.returnId.length > 0 &&\n matchesOptionalId(notification.returnId, sourceId) &&\n matchesOptionalId(data.returnId, notification.returnId) &&\n matchesOptionalId(changeSourceId, notification.returnId)\n )\n }\n\n return false\n}\n\nexport function getCommerceNotificationIdempotencyKey(\n event: Pick<CommerceNotificationWebhookEvent, 'notification'>,\n): string {\n return `${event.notification.intentId}:${event.notification.dedupeKey}`\n}\n\nexport function defineCommerceEmailConfig<TConfig extends CommerceEmailConfig>(\n config: TConfig,\n): TConfig {\n return config\n}\n\nexport function createCommerceNotificationWebhookHandler(\n handlers: CommerceNotificationEventHandlers,\n): WebhookHandler<string, unknown> {\n return async (event) => {\n if (!isCommerceNotificationWebhookEvent(event)) {\n await handlers.unhandled?.(event)\n return\n }\n\n const handler = handlers[event.notification.event]\n if (!handler) {\n await handlers.unhandled?.(event)\n return\n }\n\n await handler({\n event,\n idempotencyKey: getCommerceNotificationIdempotencyKey(event),\n })\n }\n}\n\nexport function createCommerceEmailWebhookHandler(\n handlers: CommerceEmailEventHandlers,\n): WebhookHandler<string, unknown> {\n return createCommerceNotificationWebhookHandler(handlers)\n}\n\n/** Narrows a webhook event to a specific collection. */\nexport function isWebhookCollection<TCollection extends string>(\n event: unknown,\n collection: TCollection,\n): event is WebhookEvent<TCollection, unknown> {\n return isValidWebhookEvent(event) && event.collection === collection\n}\n\n/** Narrows a webhook event to a specific operation. */\nexport function isWebhookOperation<TOperation extends string>(\n event: unknown,\n operation: TOperation,\n): event is WebhookEvent<string, unknown> & { operation: TOperation } {\n return isValidWebhookEvent(event) && event.operation === operation\n}\n\nexport const CUSTOMER_PASSWORD_RESET_OPERATION = 'password-reset' as const\n\nexport type WebhookKnownOperation =\n | CollectionWebhookOperation\n | typeof CUSTOMER_PASSWORD_RESET_OPERATION\n | typeof COMMERCE_NOTIFICATION_OPERATION\n\nexport interface CustomerPasswordResetWebhookData {\n customerId: string | number\n email: string\n name: string\n resetPasswordToken: string\n resetPasswordExpiresAt: string\n}\n\nexport type CustomerPasswordResetWebhookEvent = WebhookEvent<\n 'customers',\n CustomerPasswordResetWebhookData\n> & {\n operation: typeof CUSTOMER_PASSWORD_RESET_OPERATION\n}\n\nexport type CustomerAuthWebhookEvent = CustomerPasswordResetWebhookEvent\n\nexport interface CustomerAuthWebhookHandlers {\n passwordReset?: (\n data: CustomerPasswordResetWebhookData,\n event: CustomerPasswordResetWebhookEvent,\n ) => MaybePromise<void>\n unhandled?: (event: WebhookEvent<string, unknown>) => MaybePromise<void>\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null\n}\n\nfunction hasString(value: Record<string, unknown>, key: string): boolean {\n return typeof value[key] === 'string'\n}\n\nfunction hasStringOrNumber(\n value: Record<string, unknown>,\n key: string,\n): boolean {\n return typeof value[key] === 'string' || typeof value[key] === 'number'\n}\n\nexport function isCustomerPasswordResetWebhookEvent(\n event: WebhookEvent<string, unknown>,\n): event is CustomerPasswordResetWebhookEvent {\n if (\n event.collection !== 'customers' ||\n event.operation !== CUSTOMER_PASSWORD_RESET_OPERATION ||\n !isRecord(event.data)\n ) {\n return false\n }\n\n return (\n hasStringOrNumber(event.data, 'customerId') &&\n hasString(event.data, 'email') &&\n hasString(event.data, 'name') &&\n hasString(event.data, 'resetPasswordToken') &&\n hasString(event.data, 'resetPasswordExpiresAt')\n )\n}\n\nexport function createCustomerAuthWebhookHandler(\n handlers: CustomerAuthWebhookHandlers,\n): WebhookHandler<string, unknown> {\n return async (event) => {\n if (isCustomerPasswordResetWebhookEvent(event) && handlers.passwordReset) {\n await handlers.passwordReset(event.data, event)\n return\n }\n\n await handlers.unhandled?.(event)\n }\n}\n\n/**\n * @deprecated Import `handleSignedWebhook()` from `@01.software/sdk/webhook`.\n * This compatibility alias is signed and fails closed when its required secret\n * is missing or blank.\n */\nexport async function handleWebhook<\n T extends Collection | string = Collection,\n TData = T extends Collection ? CollectionType<T> : Record<string, unknown>,\n>(\n request: Request,\n handler: WebhookHandler<T, TData>,\n options: WebhookOptions,\n): Promise<Response> {\n return handleSignedWebhookInternal(request, handler, options)\n}\n\nexport function createTypedWebhookHandler<T extends Collection>(\n collection: T,\n handler: (event: WebhookEvent<T>) => Promise<void> | void,\n): WebhookHandler<T> {\n return async (event: WebhookEvent<T>) => {\n if (event.collection !== collection) {\n throw new Error(\n `Expected collection \"${collection}\", got \"${event.collection}\"`,\n )\n }\n return handler(event)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,wBAAwB,MAAwB;AAC9D,MAAI,OAAO,SAAS,YAAY,SAAS,KAAM,QAAO;AACtD,QAAM,QAAQ;AACd,SACE,OAAO,MAAM,eAAe,YAC5B,OAAO,MAAM,cAAc,YAC3B,MAAM,UAAU,SAAS,KACzB,OAAO,MAAM,SAAS,YACtB,MAAM,SAAS;AAEnB;;;ACOA,eAAe,gBACb,SACA,QACA,WACA,WACA,YACkB;AAClB,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,eAAe,QAAQ,OAAO,GAAG,SAAS,IAAI,UAAU,GAAG;AACjE,QAAM,gBAAgB,IAAI,WAAW,aAA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