@devultur/convex 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
2
  import { DevulturMedia, MediaUrlOptions, Visibility, ProcessingPhase, FailureReason, MediaStatusValue } from '@devultur/core';
3
- import { BakeOutputFormat, MediaUploadState, MediaUploadError, UploadProgress } from '@devultur/react';
3
+ import { UploadProgress, BakeOutputFormat, MediaUploadState, MediaUploadError } from '@devultur/react';
4
4
  export { MediaUploadError, MediaUploadState, UploadProgress } from '@devultur/react';
5
5
  import { FunctionReference } from 'convex/server';
6
- import { A as AttachmentLabels, M as MediaLibraryLabels, P as PreviewLabels, a as MediaPickerLabels, b as MediaFetchError } from './preview-labels-B7HNa7Va.js';
7
- export { c as AttachmentKind, d as MediaFetchErrorCode, e as defaultAttachmentLabels, f as defaultMediaLibraryLabels, g as defaultMediaPickerLabels, h as defaultPreviewLabels, i as formatDuration, j as formatFileSize } from './preview-labels-B7HNa7Va.js';
8
6
  import { Value } from 'convex/values';
9
- import { M as MediaRecord } from './types-DZxN6Eij.js';
7
+ import { A as AttachmentLabels, M as MediaLibraryLabels, P as PreviewLabels, a as MediaPickerLabels, b as MediaFetchError } from './preview-labels-C2nUUY_f.js';
8
+ export { c as AttachmentKind, d as MediaFetchErrorCode, e as defaultAttachmentLabels, f as defaultMediaLibraryLabels, g as defaultMediaPickerLabels, h as defaultPreviewLabels, i as formatDuration, j as formatFileSize } from './preview-labels-C2nUUY_f.js';
9
+ import { M as MediaRecord } from './types-C0ruHUcu.js';
10
10
  import { P as PdfjsLoader } from './pdf-render-BwJGagvz.js';
11
11
  export { a as PdfjsModule } from './pdf-render-BwJGagvz.js';
12
12
 
@@ -40,6 +40,12 @@ interface MediaSession {
40
40
  tokenError: Error | null;
41
41
  /** Issues the viewer token again (after a failure, for example). Resolves to the new token, or `null`. */
42
42
  retryToken: () => Promise<string | null>;
43
+ /**
44
+ * Asks for the viewer token where it's issued lazily (`<DevulturViewerProvider lazyToken>`): the first private media
45
+ * shown calls it, and so must code that reads `token` itself. A no-op once asked, and where the token is issued
46
+ * right away (the default).
47
+ */
48
+ requestToken: () => void;
43
49
  baseUrl: string | null;
44
50
  /** Browser session secret → sent in `${SESSION_HEADER}` on every private delivery. */
45
51
  sessionSecret: string;
@@ -55,6 +61,75 @@ interface MediaSession {
55
61
  reissueToken: () => Promise<string | null>;
56
62
  }
57
63
 
64
+ type AnyAction = FunctionReference<"action">;
65
+ type AnyMutation = FunctionReference<"mutation">;
66
+ type AnyQuery = FunctionReference<"query">;
67
+ interface DevulturApi {
68
+ issueViewerToken: AnyAction;
69
+ createUploadUrl: AnyAction;
70
+ /** Records an upload in the component after its PUT, so it shows in `listMedia`. Optional (uploads still work). */
71
+ confirmUpload?: AnyAction;
72
+ deleteMedia: AnyAction;
73
+ /** Deletes the full folder of a video (raw/hls/thumbnails/captions). Required to delete videos. */
74
+ deleteVideo?: AnyAction;
75
+ /** Requests the transcode of an uploaded video. Required by `useMediaUpload` for auto-process. */
76
+ processVideo?: AnyAction;
77
+ getMedia?: AnyQuery;
78
+ /** The library, newest first. Required by `useMediaLibrary` and `<MediaLibrary>`. */
79
+ listMediaPage?: AnyQuery;
80
+ /** The library matching a search. Required by `useMediaLibrary` and `<MediaLibrary>` to search. */
81
+ searchMedia?: AnyQuery;
82
+ saveProgress?: AnyMutation;
83
+ loadProgress?: AnyQuery;
84
+ markComplete?: AnyMutation;
85
+ resetProgress?: AnyMutation;
86
+ }
87
+ interface UploadOptions {
88
+ /**
89
+ * Visibility override for this resource. Omitted → `config.upload.visibility` on your server, else the Worker's
90
+ * default by type. Your guard can still rewrite it.
91
+ */
92
+ visibility?: Visibility;
93
+ /** Progress of the PUT: bytes sent, total bytes and their fraction (0 to 1). */
94
+ onProgress?: (progress: UploadProgress) => void;
95
+ /** Aborts the PUT → `upload()` rejects with an `AbortError`. */
96
+ signal?: AbortSignal;
97
+ /** A PDF's page count to record with it, a hint (`countPdfPages` from `@devultur/convex/pdfjs` counts it). */
98
+ pageCount?: number;
99
+ }
100
+ /**
101
+ * The reference `upload()` resolves to: a `DevulturMedia` whose `key` is always set (the uploaded object's key; a
102
+ * video's raw file, what `processVideo` takes). It stores as-is in a `dv.media()` field.
103
+ */
104
+ type UploadedMedia = DevulturMedia & {
105
+ readonly key: string;
106
+ };
107
+ /**
108
+ * What `useDevultur()` returns. Under a `<DevulturViewerProvider>`, `uploadUrl`, `upload` and `deleteMedia` throw a
109
+ * `DevulturCapabilityError` (`capability_unavailable`).
110
+ */
111
+ interface DevulturContextValue extends MediaSession {
112
+ uploadUrl: (file: File) => Promise<{
113
+ url: string;
114
+ key: string;
115
+ }>;
116
+ /** Uploads a file (reporting progress), records it in the component, and returns the reference ready to save. */
117
+ upload: (file: File, options?: UploadOptions) => Promise<UploadedMedia>;
118
+ /** Deletes a media by reference: video → full folder; image/file → the object. */
119
+ deleteMedia: (media: DevulturMedia) => void;
120
+ }
121
+ declare function useDevultur(): DevulturContextValue;
122
+ /**
123
+ * `useDevultur()` for components that also render outside a provider: the same value under `<DevulturProvider>` or
124
+ * `<DevulturViewerProvider>`, and `null` outside both instead of throwing.
125
+ */
126
+ declare function useDevulturOptional(): DevulturContextValue | null;
127
+ /**
128
+ * The `api` passed to `<DevulturProvider>`: your app's exported Devultur functions. Under a `<DevulturViewerProvider>`
129
+ * it throws a `DevulturCapabilityError`.
130
+ */
131
+ declare function useDevulturApi(): DevulturApi;
132
+
58
133
  /** What `useDevultur()` can do only under a `<DevulturProvider>` given the matching actions. */
59
134
  type DevulturCapability = "upload" | "uploadUrl" | "deleteMedia" | "api";
60
135
  /**
@@ -528,6 +603,11 @@ interface PreviewProps {
528
603
  pdfWorkerSrc?: string;
529
604
  /** Overrides any string shown or announced; wins over `PdfPreviewProvider`'s `labels`. English by default. */
530
605
  labels?: Partial<PreviewLabels>;
606
+ /**
607
+ * A video's playback metrics (`<VideoPlayer metrics>`): anonymous, no cookies, sent to the media host. On by
608
+ * default; `false` turns them off.
609
+ */
610
+ metrics?: boolean;
531
611
  }
532
612
  /**
533
613
  * Renders a media inline by its content type: images in an `<img>`, PDFs on `<canvas>` pages with pdf.js under a
@@ -538,7 +618,7 @@ interface PreviewProps {
538
618
  * @example
539
619
  * <Preview media={document.file} maxBytes={20_000_000} className="h-[80vh] w-full" />
540
620
  */
541
- declare function Preview({ media, contentType, fallback, loading, labels, ...viewProps }: PreviewProps): React.JSX.Element | null;
621
+ declare function Preview({ media, contentType, fallback, loading, labels, metrics, ...viewProps }: PreviewProps): React.JSX.Element | null;
542
622
 
543
623
  /** How a content type renders inline: `<img>`, a PDF view (pdf.js canvases or `<iframe>`), `<audio>` or `<pre>`. */
544
624
  type PreviewKind = "image" | "pdf" | "audio" | "text";
@@ -577,60 +657,43 @@ interface MediaLibraryState {
577
657
  */
578
658
  declare function useMediaLibrary(options?: UseMediaLibraryOptions): MediaLibraryState;
579
659
 
580
- type AnyAction = FunctionReference<"action">;
581
- type AnyMutation = FunctionReference<"mutation">;
582
- type AnyQuery = FunctionReference<"query">;
583
- interface DevulturApi {
584
- issueViewerToken: AnyAction;
585
- createUploadUrl: AnyAction;
586
- /** Records an upload in the component after its PUT, so it shows in `listMedia`. Optional (uploads still work). */
587
- confirmUpload?: AnyAction;
588
- deleteMedia: AnyAction;
589
- /** Deletes the full folder of a video (raw/hls/thumbnails/captions). Required to delete videos. */
590
- deleteVideo?: AnyAction;
591
- /** Requests the transcode of an uploaded video. Required by `useMediaUpload` for auto-process. */
592
- processVideo?: AnyAction;
593
- getMedia?: AnyQuery;
594
- /** The library, newest first. Required by `useMediaLibrary` and `<MediaLibrary>`. */
595
- listMediaPage?: AnyQuery;
596
- /** The library matching a search. Required by `useMediaLibrary` and `<MediaLibrary>` to search. */
597
- searchMedia?: AnyQuery;
598
- saveProgress?: AnyMutation;
599
- loadProgress?: AnyQuery;
600
- markComplete?: AnyMutation;
601
- resetProgress?: AnyMutation;
602
- }
603
- interface UploadOptions {
604
- /** Visibility override for this resource. Omitted → inherits the router's default by type. */
605
- visibility?: Visibility;
606
- /** Progress of the PUT: bytes sent, total bytes and their fraction (0 to 1). */
607
- onProgress?: (progress: UploadProgress) => void;
608
- /** Aborts the PUT → `upload()` rejects with an `AbortError`. */
609
- signal?: AbortSignal;
610
- /** A PDF's page count to record with it, a hint (`countPdfPages` from `@devultur/convex/pdfjs` counts it). */
611
- pageCount?: number;
660
+ interface DevulturViewerProviderProps {
661
+ /** Media worker base (e.g. `https://media.your-domain.com`). */
662
+ baseUrl: string;
663
+ /**
664
+ * Your viewer token action. It receives `{ sessionSecret, ...tokenArgs }`, like `<DevulturProvider>`'s. Leave it
665
+ * out when every media is public: the provider then needs no Convex client, issues nothing, and a private media
666
+ * fails with `token_unavailable`.
667
+ */
668
+ issueViewerToken?: ViewerTokenAction;
669
+ /**
670
+ * `true` → the token is issued only once a private media is shown (and renewed from then on), so a page of public
671
+ * media calls nothing. Code that reads `token` itself then calls `requestToken()` first. Default `false`: issued
672
+ * as soon as the provider mounts.
673
+ */
674
+ lazyToken?: boolean;
675
+ /** Extra arguments for `issueViewerToken`, compared by value (see `<DevulturProvider tokenArgs>`). */
676
+ tokenArgs?: ViewerTokenArgs;
677
+ children: React.ReactNode;
612
678
  }
613
679
  /**
614
- * The reference `upload()` resolves to: a `DevulturMedia` whose `key` is always set (the uploaded object's key; a
615
- * video's raw file, what `processVideo` takes). It stores as-is in a `dv.media()` field.
616
- */
617
- type UploadedMedia = DevulturMedia & {
618
- readonly key: string;
619
- };
620
- /**
621
- * What `useDevultur()` returns. Under a `<DevulturViewerProvider>`, `uploadUrl`, `upload` and `deleteMedia` throw a
622
- * `DevulturCapabilityError` (`capability_unavailable`).
680
+ * A provider for apps that only display media: `<Image>`, `<Preview>`, `<DownloadLink>`, `useMediaObjectUrl` and the
681
+ * video hooks work, and it needs no upload or delete actions. It issues and renews the viewer token (with `lazyToken`,
682
+ * only once a private media is shown). Without `issueViewerToken` it needs no Convex client at all. `upload`, `uploadUrl` and `deleteMedia` throw a `DevulturCapabilityError`, as do the hooks that
683
+ * need the `api` (`useMediaUpload`, `useDevulturApi`, `<MediaLibrary>`, `<MediaPicker>`).
684
+ *
685
+ * @example
686
+ * <DevulturViewerProvider baseUrl={MEDIA_URL} issueViewerToken={api.admin.issueViewerToken} tokenArgs={{ workspaceId }}>
687
+ * <Preview media={document.file} />
688
+ * </DevulturViewerProvider>
689
+ *
690
+ * // Only public media: no token action, no Convex client.
691
+ * <DevulturViewerProvider baseUrl={MEDIA_URL}>
692
+ * <Image media={post.cover} alt="" />
693
+ * </DevulturViewerProvider>
623
694
  */
624
- interface DevulturContextValue extends MediaSession {
625
- uploadUrl: (file: File) => Promise<{
626
- url: string;
627
- key: string;
628
- }>;
629
- /** Uploads a file (reporting progress), records it in the component, and returns the reference ready to save. */
630
- upload: (file: File, options?: UploadOptions) => Promise<UploadedMedia>;
631
- /** Deletes a media by reference: video → full folder; image/file → the object. */
632
- deleteMedia: (media: DevulturMedia) => void;
633
- }
695
+ declare function DevulturViewerProvider({ issueViewerToken, ...props }: DevulturViewerProviderProps): React.JSX.Element;
696
+
634
697
  interface ProgressContextValue {
635
698
  save: (videoId: string, position: number) => Promise<void>;
636
699
  load: (videoId: string) => Promise<{
@@ -659,33 +722,6 @@ interface DevulturProviderProps {
659
722
  children: React.ReactNode;
660
723
  }
661
724
  declare function DevulturProvider({ api, baseUrl, tokenArgs, issueViewerToken, children }: DevulturProviderProps): React.JSX.Element;
662
- declare function useDevultur(): DevulturContextValue;
663
- /**
664
- * The `api` passed to `<DevulturProvider>`: your app's exported Devultur functions. Under a `<DevulturViewerProvider>`
665
- * it throws a `DevulturCapabilityError`.
666
- */
667
- declare function useDevulturApi(): DevulturApi;
668
- interface DevulturViewerProviderProps {
669
- /** Media worker base (e.g. `https://media.your-domain.com`). */
670
- baseUrl: string;
671
- /** Your viewer token action. It receives `{ sessionSecret, ...tokenArgs }`, like `<DevulturProvider>`'s. */
672
- issueViewerToken: ViewerTokenAction;
673
- /** Extra arguments for `issueViewerToken`, compared by value (see `<DevulturProvider tokenArgs>`). */
674
- tokenArgs?: ViewerTokenArgs;
675
- children: React.ReactNode;
676
- }
677
- /**
678
- * A provider for apps that only display media: it issues and renews the viewer token, so `<Image>`, `<Preview>`,
679
- * `<DownloadLink>`, `useMediaObjectUrl` and the video hooks work, and it needs no upload or delete actions. `upload`,
680
- * `uploadUrl` and `deleteMedia` throw a `DevulturCapabilityError`, as do the hooks that need the `api`
681
- * (`useMediaUpload`, `useDevulturApi`, `<MediaLibrary>`, `<MediaPicker>`).
682
- *
683
- * @example
684
- * <DevulturViewerProvider baseUrl={MEDIA_URL} issueViewerToken={api.admin.issueViewerToken} tokenArgs={{ workspaceId }}>
685
- * <Preview media={document.file} />
686
- * </DevulturViewerProvider>
687
- */
688
- declare function DevulturViewerProvider({ baseUrl, issueViewerToken, tokenArgs, children, }: DevulturViewerProviderProps): React.JSX.Element;
689
725
  declare function useDevulturProgress(): ProgressContextValue;
690
726
  /**
691
727
  * Ready-to-use delivery URL for a key, with the context's viewer token already injected. The consumer
@@ -798,7 +834,7 @@ declare function useVideoState(media: DevulturMedia | null | undefined, options?
798
834
  locales?: string[];
799
835
  }): VideoState;
800
836
  interface UseMediaUploadOptions {
801
- /** Resource visibility. Omitted → config default → private (secure-by-default). */
837
+ /** Resource visibility. Omitted → `config.upload.visibility`, else the Worker's default by type. Your guard can rewrite it. */
802
838
  visibility?: Visibility;
803
839
  /** Fires ONCE, at the persistence point (PUT done + transcode requested). */
804
840
  onComplete?: (media: DevulturMedia) => void;
@@ -829,4 +865,4 @@ interface UseMediaUploadReturn {
829
865
  */
830
866
  declare function useMediaUpload(options?: UseMediaUploadOptions): UseMediaUploadReturn;
831
867
 
832
- export { AttachmentCard, type AttachmentCardProps, AttachmentLabels, type CaptionTrack, CropUpload, type CropUploadLabels, type CropUploadProps, type CropUploadRenderProps, type DevulturApi, type DevulturCapability, DevulturCapabilityError, DevulturProvider, DevulturViewerProvider, DocumentLink, type DocumentLinkProps, DownloadLink, Image, type ImageProps, MediaFetchError, MediaLibrary, type MediaLibraryItemState, MediaLibraryLabels, type MediaLibraryPart, type MediaLibraryProps, type MediaLibraryState, type MediaLibraryStatus, type MediaObjectUrl, MediaPicker, MediaPickerLabels, type MediaPickerLibraryProps, type MediaPickerProps, type MediaPickerSelectionProps, type MediaPickerState, type MediaPickerUpload$1 as MediaPickerUpload, type MediaPickerUploadProps, type MediaPickerUploads, type PdfPreviewConfig, PdfPreviewProvider, PdfThumbnail, type PdfThumbnailProps, PdfjsLoader, Preview, type PreviewKind, PreviewLabels, type PreviewProps, type TokenStatus, type UploadedMedia, type UseMediaLibraryOptions, type UseMediaObjectUrlOptions, type UseMediaUploadOptions, type UseMediaUploadReturn, type VideoProps, type VideoState, type ViewerTokenArgs, type ViewerTokenResult, matchesAccept, useDevultur, useDevulturApi, useDevulturMedia, useDevulturProgress, useMediaLibrary, useMediaObjectUrl, useMediaPicker, useMediaUpload, useMediaUrl, useVideoProps, useVideoState };
868
+ export { AttachmentCard, type AttachmentCardProps, AttachmentLabels, type CaptionTrack, CropUpload, type CropUploadLabels, type CropUploadProps, type CropUploadRenderProps, type DevulturApi, type DevulturCapability, DevulturCapabilityError, type DevulturContextValue, DevulturProvider, DevulturViewerProvider, type DevulturViewerProviderProps, DocumentLink, type DocumentLinkProps, DownloadLink, Image, type ImageProps, MediaFetchError, MediaLibrary, type MediaLibraryItemState, MediaLibraryLabels, type MediaLibraryPart, type MediaLibraryProps, type MediaLibraryState, type MediaLibraryStatus, type MediaObjectUrl, MediaPicker, MediaPickerLabels, type MediaPickerLibraryProps, type MediaPickerProps, type MediaPickerSelectionProps, type MediaPickerState, type MediaPickerUpload$1 as MediaPickerUpload, type MediaPickerUploadProps, type MediaPickerUploads, type PdfPreviewConfig, PdfPreviewProvider, PdfThumbnail, type PdfThumbnailProps, PdfjsLoader, Preview, type PreviewKind, PreviewLabels, type PreviewProps, type TokenStatus, type UploadOptions, type UploadedMedia, type UseMediaLibraryOptions, type UseMediaObjectUrlOptions, type UseMediaUploadOptions, type UseMediaUploadReturn, type VideoProps, type VideoState, type ViewerTokenArgs, type ViewerTokenResult, matchesAccept, useDevultur, useDevulturApi, useDevulturMedia, useDevulturOptional, useDevulturProgress, useMediaLibrary, useMediaObjectUrl, useMediaPicker, useMediaUpload, useMediaUrl, useVideoProps, useVideoState };