@uln/manage 0.0.0-stage → 0.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.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The sizes a site asks Manage to sign. Manage holds no site's size preferences: each site names the widths its
3
+ * layout needs and gets a signed URL per width (`PublicPhoto.variants`, `PublicFilm.posterVariants`). Client-safe:
4
+ * shared by the SDK, the HTTP content API and the service binding. Part of the public contract: only grows.
5
+ */
6
+ export interface MediaSizes {
7
+ /** Photo widths in pixels. Each becomes `photo.variants[String(width)]`, scaled down to fit that width. */
8
+ photoWidths?: readonly number[];
9
+ /** Film poster widths in pixels. Each becomes `film.posterVariants[String(width)]`. */
10
+ posterWidths?: readonly number[];
11
+ }
12
+ /** Largest width a site may ask for (Cloudflare's output limit is higher; nothing on a page needs more). */
13
+ export declare const MAX_MEDIA_WIDTH = 8192;
14
+ /** Most widths per list, so one request can't mint an unbounded number of URLs (or Images variants). */
15
+ export declare const MAX_MEDIA_WIDTHS = 12;
16
+ /** Sorted, de-duplicated widths; throws a message a site developer can act on for anything out of range. */
17
+ export declare function normalizeWidths(widths: readonly unknown[] | undefined, label: string): number[] | undefined;
18
+ export declare function normalizeMediaSizes(sizes: MediaSizes | undefined): MediaSizes;
19
+ /** As HTTP content API query parameters (`?photoWidths=480,960&posterWidths=640`). */
20
+ export declare function mediaSizesQuery(sizes: MediaSizes | undefined): string;
21
+ /** Read the HTTP content API's query parameters; throws a `RangeError` for a malformed value. */
22
+ export declare function parseMediaSizesQuery(params: URLSearchParams): MediaSizes;
@@ -0,0 +1,58 @@
1
+ /**
2
+ * The package report: which `@uln/*` packages a site was built with, at which versions. The site's build writes it
3
+ * (`ulnPackages()` from `@uln/manage/vite`) and serves it as a static file at {@link PACKAGE_REPORT_PATH}; Manage
4
+ * reads it from the live site, so what it shows is what is deployed. It names only package versions: nothing secret.
5
+ *
6
+ * It's also what an upgrade is planned from ({@link upgradePlan}): enough to tell which packages to bump, to which
7
+ * version, with which package manager and range style, and whether the bump may break.
8
+ *
9
+ * A contract with every site's build: change it only by adding optional fields. A breaking change gets a new `schema`.
10
+ */
11
+ export declare const PACKAGE_REPORT_PATH = "/.well-known/uln-packages.json";
12
+ export declare const ULN_SCOPE = "@uln/";
13
+ export type DependencyType = "dependencies" | "devDependencies" | "peerDependencies" | "optionalDependencies";
14
+ export declare const DEPENDENCY_TYPES: readonly DependencyType[];
15
+ export interface ReportedPackage {
16
+ /** The version installed when the site was built (from the package's own `package.json`). */
17
+ version: string;
18
+ /** The range the site's `package.json` asks for (`^0.3.5`). */
19
+ range: string;
20
+ /** Which section of the site's `package.json` names it. */
21
+ type: DependencyType;
22
+ }
23
+ export interface PackageReport {
24
+ schema: 1;
25
+ /** When the site was built (ISO 8601). */
26
+ builtAt: string;
27
+ /** The site's `packageManager` field (`pnpm@10.4.0`), when it has one. */
28
+ packageManager?: string;
29
+ /** Every `@uln/*` package the site's `package.json` depends on directly, by name. */
30
+ packages: Record<string, ReportedPackage>;
31
+ }
32
+ export declare function isVersion(value: unknown): value is string;
33
+ /** Negative if `a` is older than `b`, 0 if equal, positive if newer. Pre-release tags are ignored. */
34
+ export declare function compareVersions(a: string, b: string): number;
35
+ /**
36
+ * A report as a site serves it, checked field by field: anything malformed is dropped, so a site's file can't put
37
+ * arbitrary data on Manage's page. Null when it isn't a report at all.
38
+ */
39
+ export declare function parsePackageReport(value: unknown): PackageReport | null;
40
+ /** One package to bump. */
41
+ export interface PackageUpgrade {
42
+ name: string;
43
+ from: string;
44
+ to: string;
45
+ /** May need code changes: a new major, or before 1.0 a new minor (semver's rule for 0.x). */
46
+ breaking: boolean;
47
+ /** The range to write in `package.json`, keeping the site's style (`^0.3.2` → `^0.3.6`). */
48
+ range: string;
49
+ type: DependencyType;
50
+ }
51
+ /** The range for `to` in the style of `range`: its `^` or `~`, or an exact version. */
52
+ export declare function bumpedRange(range: string, to: string): string;
53
+ export declare function isBreaking(from: string, to: string): boolean;
54
+ /**
55
+ * What to bump to bring a site to the latest of every `@uln/*` package it reports, by name. What a future
56
+ * "upgrade with an agent" action runs from: each bump, its target range, and whether it may need code changes.
57
+ */
58
+ export declare function upgradePlan(report: PackageReport, latest: ReadonlyMap<string, string>): PackageUpgrade[];
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A film's preview clip, whatever video backend holds it: how long it may run, which part of the film it shows, and
3
+ * the run that prepares it. Client-safe (part of the record shapes in `./schema.ts`). Moved here from
4
+ * `@uln/hls/cloudflare`, which no longer exists: storing and cutting clips is Manage's job, playing them is `@uln/hls`'s.
5
+ */
6
+ import { z } from "zod";
7
+ export declare const PREVIEW_MAX_DURATION_SECONDS = 15;
8
+ /** The clip length when a film sets a start but no end. */
9
+ export declare const DEFAULT_PREVIEW_DURATION_SECONDS = 6;
10
+ /** Queued or processing preparations older than this are treated as stuck. */
11
+ export declare const STALE_PREVIEW_PREPARATION_MS: number;
12
+ /** A stored progressive MP4 preview: the backend's id for it, what it is, and which part of the film it shows. */
13
+ export declare const previewAssetSchema: z.ZodObject<{
14
+ key: z.ZodString;
15
+ version: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
16
+ contentType: z.ZodLiteral<"video/mp4">;
17
+ size: z.ZodNumber;
18
+ duration: z.ZodNumber;
19
+ sourceStart: z.ZodNumber;
20
+ source: z.ZodOptional<z.ZodEnum<{
21
+ automatic: "automatic";
22
+ manual: "manual";
23
+ }>>;
24
+ }, z.core.$strip>;
25
+ export type PreviewAsset = z.infer<typeof previewAssetSchema>;
26
+ /** A queued or running automatic preview, owned by one workflow run. */
27
+ export declare const previewPreparationSchema: z.ZodObject<{
28
+ workflowId: z.ZodString;
29
+ status: z.ZodEnum<{
30
+ failed: "failed";
31
+ processing: "processing";
32
+ queued: "queued";
33
+ }>;
34
+ sourceStart: z.ZodNumber;
35
+ requestedDuration: z.ZodNumber;
36
+ updatedAt: z.ZodString;
37
+ error: z.ZodOptional<z.ZodString>;
38
+ }, z.core.$strip>;
39
+ export type PreviewPreparation = z.infer<typeof previewPreparationSchema>;
40
+ export interface PreviewRange {
41
+ sourceStart: number;
42
+ requestedDuration: number;
43
+ }
44
+ /** The clip to cut for a film's preview start and end: never negative, at most 15 s, 6 s without an end. */
45
+ export declare function previewRange(previewStart?: number, previewEnd?: number): PreviewRange;
46
+ /** Convert a time on the clip's own timeline back to the film's. */
47
+ export declare function previewTimeInFilm(asset: Pick<PreviewAsset, "sourceStart">, clipTime: number): number;
48
+ /**
49
+ * A film needs an automatic preview queued when it has none and no live
50
+ * preparation: none yet, a failed one, or one stuck past the stale window.
51
+ */
52
+ export declare function needsPreviewBackfill(asset: PreviewAsset | undefined, preparation: PreviewPreparation | undefined, nowMs: number): boolean;
@@ -0,0 +1,52 @@
1
+ /**
2
+ * What a website receives: ready-to-display records with direct provider URLs, and no storage or workflow details.
3
+ * Nothing here says which backend (Cloudflare Stream, Mux) holds a video: the URLs are signed and played the same way.
4
+ * The one projection from Manage's content to these shapes, shared by the SDK's service-binding client
5
+ * (`sdk/index.ts`) and the HTTP content API (`worker/content-api.ts`). Client-safe: no Workers runtime, no database.
6
+ * Part of the public contract: only grows.
7
+ */
8
+ import type { FilmContent, ShootContent } from "./content-types.ts";
9
+ import type { Film, Photo, Shoot } from "./schema.ts";
10
+ /** Ready to display: metadata and direct provider URLs, with no storage/workflow details. */
11
+ export type PublicFilm = Omit<Film, "previewAsset" | "previewPreparation" | "frameImages" | "cachedFrames" | "processing" | "hidden" | "videoProvider" | "videoPlaybackId"> & {
12
+ playbackUrl: string;
13
+ posterUrl: string;
14
+ /** The poster at each width the site asked for (`MediaSizes.posterWidths`), keyed by width, e.g. `["640"]`. */
15
+ posterVariants?: Record<string, string>;
16
+ /** `posterVariants` as an `<img srcset>`, narrowest first. */
17
+ posterSrcset?: string;
18
+ /** The preview clip as one progressive MP4 (540p, silent). */
19
+ previewUrl?: string;
20
+ /**
21
+ * The same preview as an adaptive stream (HLS), encoded from the film at full quality, so the player picks the
22
+ * rendition that fits the card. Present for previews made since adaptive previews; may carry the film's audio.
23
+ */
24
+ previewPlaybackUrl?: string;
25
+ /** The preview clip's size in bytes, when known: lets a site choose to load it whole or stream it before asking. */
26
+ previewBytes?: number;
27
+ /** Unix milliseconds. Refresh this item before its earliest media URL expires. */
28
+ expiresAt: number | null;
29
+ };
30
+ export type PublicPhoto = Photo & {
31
+ /** The photo at its stored size. */
32
+ url: string;
33
+ /** The photo scaled down to each width the site asked for (`MediaSizes.photoWidths`), keyed by width. */
34
+ variants?: Record<string, string>;
35
+ /** `variants` as an `<img srcset>` (`url 480w, url 960w`), widest no wider than the photo itself. */
36
+ srcset?: string;
37
+ /** A tiny blurred preview (`data:image/webp;base64,…`, a few hundred bytes) to show until the photo loads. */
38
+ placeholder?: string;
39
+ /** The photo's average colour (`#rrggbb`), an even lighter placeholder. */
40
+ color?: string;
41
+ expiresAt: number | null;
42
+ };
43
+ export type PublicShoot = Omit<Shoot, "photos" | "hidden"> & {
44
+ photos: PublicPhoto[];
45
+ };
46
+ /**
47
+ * Width variants as a `srcset`, narrowest first. Images scales down only, so a width past the original's (`maxWidth`,
48
+ * when known) is served at the original's size: it is listed once, at its real width.
49
+ */
50
+ export declare function widthSrcset(variants: Record<string, string>, maxWidth?: number): string;
51
+ export declare function publicFilm({ film, playback, poster, posterVariants, preview, previewPlayback, }: FilmContent): PublicFilm;
52
+ export declare function publicShoot({ shoot, photos }: ShootContent): PublicShoot;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * The contract between Manage and client sites: how a site reads its catalog (its content). A site binds the catalog's `PublicCatalog` entrypoint with
3
+ * its site in the binding's props, and types the binding with this interface:
4
+ *
5
+ * ```jsonc
6
+ * // the site's wrangler.jsonc
7
+ * "services": [{ "binding": "CATALOG", "service": "manage", "entrypoint": "PublicCatalog", "props": { "site": "erikhe" } }]
8
+ * ```
9
+ *
10
+ * ```ts
11
+ * import type { PublicCatalogRpc } from "@uln/manage/rpc";
12
+ * const gallery = await (env.CATALOG as Service<PublicCatalogRpc>).filmsGallery();
13
+ * ```
14
+ *
15
+ * Change it only by adding: a new method or a new optional field. Removing or retyping anything breaks
16
+ * every site that reads it, and sites upgrade on their own schedule.
17
+ */
18
+ import type { FilmContent, FilmsContent, ShootContent, StillsContent } from "./content-types.ts";
19
+ import type { MediaSizes } from "./media-sizes.ts";
20
+ import type { PublicFilmsGallery, PublicStillsGallery, SiteContact } from "./schema.ts";
21
+ /** Set on the site's service binding; Manage never takes the site from a call's arguments. */
22
+ export interface PublicCatalogProps {
23
+ site: string;
24
+ /** Required by the signed-content methods; must exactly match this site's current origin in auth. */
25
+ origin?: string;
26
+ }
27
+ export interface PublicCatalogRpc {
28
+ /**
29
+ * Presentation metadata and direct provider URLs; refresh before `expiresAt`. `sizes` names the photo and poster
30
+ * widths the site's layout needs; each comes back signed under its width.
31
+ */
32
+ filmsContent(sizes?: MediaSizes): Promise<FilmsContent>;
33
+ stillsContent(sizes?: MediaSizes): Promise<StillsContent>;
34
+ contactsContent(): Promise<SiteContact[]>;
35
+ filmContent(id: string, sizes?: MediaSizes): Promise<FilmContent | undefined>;
36
+ shootContent(id: string, sizes?: MediaSizes): Promise<ShootContent | undefined>;
37
+ /** Playable films in visible categories, in the site's category order. */
38
+ filmsGallery(): Promise<PublicFilmsGallery>;
39
+ /** Visible shoots that have photos, grouped by category. */
40
+ stillsGallery(): Promise<PublicStillsGallery>;
41
+ /** Contact lines, in their saved order. */
42
+ siteContacts(): Promise<SiteContact[]>;
43
+ }
@@ -0,0 +1,180 @@
1
+ /**
2
+ * The catalog's record shapes, shared by the Manage Worker and every client site. Client-safe: no Workers
3
+ * runtime, no database. Sites import these types to read what the RPC returns.
4
+ */
5
+ import { z } from "zod";
6
+ import { type CategoryIndexGroup, type FilmCategory } from "./lib/category-order.ts";
7
+ import { type PreviewPreparation } from "./preview-asset.ts";
8
+ export declare const creditSchema: z.ZodObject<{
9
+ role: z.ZodString;
10
+ name: z.ZodString;
11
+ url: z.ZodOptional<z.ZodString>;
12
+ }, z.core.$strip>;
13
+ export type Credit = z.infer<typeof creditSchema>;
14
+ /**
15
+ * The video backends Manage can keep a site's videos in. Which one holds a video is recorded with it (D1's
16
+ * `video_provider` / `preview_provider`) and shown in Manage; sites never see it, only the signed URLs it serves.
17
+ */
18
+ export declare const VIDEO_PROVIDERS: readonly ["cloudflare", "mux"];
19
+ export declare const videoProviderSchema: z.ZodEnum<{
20
+ cloudflare: "cloudflare";
21
+ mux: "mux";
22
+ }>;
23
+ export type VideoProviderName = z.infer<typeof videoProviderSchema>;
24
+ /** Where a film's video comes from: a backend Manage uploaded it to, or an imported external HLS URL. */
25
+ export declare const filmVideoSourceSchema: z.ZodEnum<{
26
+ cloudflare: "cloudflare";
27
+ external: "external";
28
+ mux: "mux";
29
+ }>;
30
+ export type FilmVideoSource = z.infer<typeof filmVideoSourceSchema>;
31
+ /**
32
+ * A film's preview: the progressive MP4 (`key`, the backend's id for it), and, for previews made since adaptive
33
+ * previews, the backend's id of the same clip played as an adaptive stream (`playbackKey`). `provider` is the backend
34
+ * that holds both (Cloudflare Stream when absent, as for every preview made before Mux); a Mux preview also carries
35
+ * the signed `playbackId` its URLs are made from.
36
+ */
37
+ export declare const filmPreviewAssetSchema: z.ZodObject<{
38
+ key: z.ZodString;
39
+ version: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
40
+ contentType: z.ZodLiteral<"video/mp4">;
41
+ size: z.ZodNumber;
42
+ duration: z.ZodNumber;
43
+ sourceStart: z.ZodNumber;
44
+ source: z.ZodOptional<z.ZodEnum<{
45
+ automatic: "automatic";
46
+ manual: "manual";
47
+ }>>;
48
+ playbackKey: z.ZodOptional<z.ZodString>;
49
+ provider: z.ZodOptional<z.ZodEnum<{
50
+ cloudflare: "cloudflare";
51
+ mux: "mux";
52
+ }>>;
53
+ playbackId: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strip>;
55
+ export type FilmPreviewAsset = z.infer<typeof filmPreviewAssetSchema>;
56
+ export declare const filmPreviewPreparationSchema: z.ZodObject<{
57
+ workflowId: z.ZodString;
58
+ status: z.ZodEnum<{
59
+ failed: "failed";
60
+ processing: "processing";
61
+ queued: "queued";
62
+ }>;
63
+ sourceStart: z.ZodNumber;
64
+ requestedDuration: z.ZodNumber;
65
+ updatedAt: z.ZodString;
66
+ error: z.ZodOptional<z.ZodString>;
67
+ }, z.core.$strip>;
68
+ export type FilmPreviewPreparation = PreviewPreparation;
69
+ export declare const filmSchema: z.ZodObject<{
70
+ id: z.ZodString;
71
+ title: z.ZodString;
72
+ role: z.ZodString;
73
+ category: z.ZodString;
74
+ year: z.ZodOptional<z.ZodString>;
75
+ client: z.ZodOptional<z.ZodString>;
76
+ clientUrl: z.ZodOptional<z.ZodString>;
77
+ description: z.ZodOptional<z.ZodString>;
78
+ videoProvider: z.ZodOptional<z.ZodEnum<{
79
+ cloudflare: "cloudflare";
80
+ external: "external";
81
+ mux: "mux";
82
+ }>>;
83
+ videoPlaybackId: z.ZodOptional<z.ZodString>;
84
+ playbackUrl: z.ZodOptional<z.ZodURL>;
85
+ posterUrl: z.ZodOptional<z.ZodString>;
86
+ credits: z.ZodOptional<z.ZodArray<z.ZodObject<{
87
+ role: z.ZodString;
88
+ name: z.ZodString;
89
+ url: z.ZodOptional<z.ZodString>;
90
+ }, z.core.$strip>>>;
91
+ aspectRatio: z.ZodOptional<z.ZodNumber>;
92
+ frameImages: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
93
+ cachedFrames: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
94
+ hidden: z.ZodOptional<z.ZodBoolean>;
95
+ processing: z.ZodOptional<z.ZodBoolean>;
96
+ previewStart: z.ZodOptional<z.ZodNumber>;
97
+ previewEnd: z.ZodOptional<z.ZodNumber>;
98
+ previewAsset: z.ZodOptional<z.ZodObject<{
99
+ key: z.ZodString;
100
+ version: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
101
+ contentType: z.ZodLiteral<"video/mp4">;
102
+ size: z.ZodNumber;
103
+ duration: z.ZodNumber;
104
+ sourceStart: z.ZodNumber;
105
+ source: z.ZodOptional<z.ZodEnum<{
106
+ automatic: "automatic";
107
+ manual: "manual";
108
+ }>>;
109
+ playbackKey: z.ZodOptional<z.ZodString>;
110
+ provider: z.ZodOptional<z.ZodEnum<{
111
+ cloudflare: "cloudflare";
112
+ mux: "mux";
113
+ }>>;
114
+ playbackId: z.ZodOptional<z.ZodString>;
115
+ }, z.core.$strip>>;
116
+ previewPreparation: z.ZodOptional<z.ZodObject<{
117
+ workflowId: z.ZodString;
118
+ status: z.ZodEnum<{
119
+ failed: "failed";
120
+ processing: "processing";
121
+ queued: "queued";
122
+ }>;
123
+ sourceStart: z.ZodNumber;
124
+ requestedDuration: z.ZodNumber;
125
+ updatedAt: z.ZodString;
126
+ error: z.ZodOptional<z.ZodString>;
127
+ }, z.core.$strip>>;
128
+ }, z.core.$strip>;
129
+ export type Film = z.infer<typeof filmSchema>;
130
+ export declare const photoSchema: z.ZodObject<{
131
+ id: z.ZodString;
132
+ width: z.ZodNumber;
133
+ height: z.ZodNumber;
134
+ alt: z.ZodOptional<z.ZodString>;
135
+ }, z.core.$strip>;
136
+ export type Photo = z.infer<typeof photoSchema>;
137
+ export declare const shootSchema: z.ZodObject<{
138
+ id: z.ZodString;
139
+ title: z.ZodString;
140
+ category: z.ZodOptional<z.ZodString>;
141
+ year: z.ZodOptional<z.ZodString>;
142
+ role: z.ZodOptional<z.ZodString>;
143
+ description: z.ZodOptional<z.ZodString>;
144
+ credits: z.ZodOptional<z.ZodArray<z.ZodObject<{
145
+ role: z.ZodString;
146
+ name: z.ZodString;
147
+ url: z.ZodOptional<z.ZodString>;
148
+ }, z.core.$strip>>>;
149
+ tags: z.ZodOptional<z.ZodArray<z.ZodString>>;
150
+ url: z.ZodOptional<z.ZodString>;
151
+ client: z.ZodOptional<z.ZodString>;
152
+ clientUrl: z.ZodOptional<z.ZodString>;
153
+ photos: z.ZodArray<z.ZodObject<{
154
+ id: z.ZodString;
155
+ width: z.ZodNumber;
156
+ height: z.ZodNumber;
157
+ alt: z.ZodOptional<z.ZodString>;
158
+ }, z.core.$strip>>;
159
+ hidden: z.ZodOptional<z.ZodBoolean>;
160
+ }, z.core.$strip>;
161
+ export type Shoot = z.infer<typeof shootSchema>;
162
+ /** A contact line (`<label>: <email>`), e.g. representation by region. */
163
+ export interface SiteContact {
164
+ id: string;
165
+ label: string;
166
+ email: string;
167
+ }
168
+ export type { CategoryIndexGroup, FilmCategory } from "./lib/category-order.ts";
169
+ export type PublicFilmsGallery = {
170
+ films: Film[];
171
+ indexGroups: CategoryIndexGroup[];
172
+ };
173
+ export type PublicStillsGallery = {
174
+ shoots: Shoot[];
175
+ indexGroups: CategoryIndexGroup[];
176
+ };
177
+ /** The public films gallery: playable films in the visible categories, in category order. */
178
+ export declare function createPublicFilmsGallery(films: Film[], categories: FilmCategory[]): PublicFilmsGallery;
179
+ /** The public stills gallery: shoots that have photos, grouped by category. */
180
+ export declare function createPublicStillsGallery(shoots: Shoot[]): PublicStillsGallery;