@uln/manage 0.0.0-stage → 0.3.1

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/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ `@uln/manage` on npm. Each release has a `## <version> — <YYYY-MM-DD>` section here: the Release SDK workflow
4
+ publishes only a version that has one, and uses it as the GitHub release notes.
5
+
6
+ ## 0.3.1 — 2026-11-11
7
+
8
+ First release on npm (`pnpm add @uln/manage`).
9
+
10
+ - Renamed from `@uln/management`, the name of the bootstrap tarballs. To switch, `pnpm remove @uln/management`,
11
+ `pnpm add @uln/manage`, and change imports from `@uln/management`, `@uln/management/rpc` and
12
+ `@uln/management/vite` to `@uln/manage`, `@uln/manage/rpc` and `@uln/manage/vite`. Nothing else changes.
13
+ - The published types work under every TypeScript module resolution. Before, a site using `"moduleResolution":
14
+ "NodeNext"` (or `Node16`) got errors from the package's declarations, because their relative imports had no file
15
+ extension. `Bundler` resolution was unaffected.
16
+ - The package includes this changelog.
17
+
18
+ Contents, unchanged from 0.3.0:
19
+
20
+ - `createManagementClient(binding)` for a same-account service binding and `createHttpManagementClient({ apiKey })`
21
+ for a Worker in another account: `films()`, `film(id)`, `shoots()`, `shoot(id)`, `contacts()`, with optional
22
+ `sizes` for signed variants.
23
+ - `managementUrl(site)`, a link to the site in Manage.
24
+ - `@uln/manage/rpc`: the `PublicCatalogRpc` binding type.
25
+ - `@uln/manage/vite`: `ulnPackages()`, which writes `/.well-known/uln-packages.json` for Manage's SDK versions page.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # @uln/manage
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Content for ULN websites, supplied by Manage. Framework independent; no React, Workers runtime imports,
4
+ credentials, media transport or player code in the package. Keep using `@uln/auth` for authentication.
5
+
6
+ ```sh
7
+ pnpm add @uln/manage
8
+ ```
9
+
10
+ Bind your website Worker to Manage in the same account. Auth's directory supplies the permanent site id;
11
+ the binding fixes it so calls cannot request another site's content.
12
+
13
+ ```jsonc
14
+ "services": [{
15
+ "binding": "CATALOG", "service": "manage", "entrypoint": "PublicCatalog",
16
+ "props": { "site": "simwize", "origin": "https://simwize.uln.industries" }
17
+ }]
18
+ ```
19
+
20
+ ```ts
21
+ import { createManagementClient, managementUrl, type PublicCatalogRpc } from "@uln/manage";
22
+
23
+ // In server code, per request. Do not pass bindings or credentials to the browser.
24
+ const management = createManagementClient(env.CATALOG as PublicCatalogRpc);
25
+ const films = await management.films();
26
+ const shoots = await management.shoots({ photoWidths: [640, 1280, 1920] }); // the widths your layout shows
27
+ const film = await management.film("film-id");
28
+ const shoot = await management.shoot("shoot-id");
29
+ const contacts = await management.contacts();
30
+ const editUrl = managementUrl("simwize");
31
+
32
+ // No envelopes or metadata/media joins:
33
+ // films[0].title, films[0].playbackUrl, films[0].posterUrl, films[0].previewUrl
34
+ // shoot?.photos[0].url, shoot?.photos[0].variants?.["1280"], shoot?.photos[0].width, shoot?.photos[0].alt
35
+ ```
36
+
37
+ Lists and individual records use the same ready-to-display shapes:
38
+
39
+ - `films()` — film metadata, `playbackUrl`, `posterUrl`, optional `previewUrl` (MP4), `previewPlaybackUrl` (the same preview as adaptive HLS) and `posterVariants`, and `expiresAt`.
40
+ - `film(id)` — one complete public film, or `undefined` when missing or hidden.
41
+ - `shoots()` — ordered public shoots, each with its ordered `photos` (URL, dimensions, alt text and expiry).
42
+ - Every content method takes optional `sizes` (`photoWidths`, `posterWidths`): one signed URL per width comes back
43
+ in `photo.variants` / `film.posterVariants`. Manage holds no size preferences; each site asks for its own.
44
+ - `shoot(id)` — one complete public shoot with its photos, or `undefined` when missing or hidden.
45
+ - `contacts()` — ordered `{ id, label, email }` contact lines.
46
+
47
+ Pass URLs to your existing image/video components; media comes straight from the provider. Preview start
48
+ is the prepared clip's source start. Storage keys, encoding/workflow state and RPC envelopes stay behind the SDK.
49
+ The binding type is available from `@uln/manage/rpc`; existing RPC methods remain compatible but are not
50
+ part of the website client.
51
+
52
+ Access uses a same-account Cloudflare service binding, not a public HTTP content endpoint. A website whose Worker
53
+ runs in another Cloudflare account uses `createHttpManagementClient({ apiKey })` instead: the same client over
54
+ `https://manage.uln.industries/api/content/v1` (OpenAPI at `/api/content/v1/openapi.json`), with a per-site key an
55
+ admin creates in Manage and the site keeps in a server secret. The key fixes the site. The website client
56
+ runs on the server. Its fixed binding `site` **and** `origin` must match the same entry in auth’s site directory;
57
+ unknown sites, missing origins and mismatched origins are rejected. These deployment props are not browser
58
+ headers and callers cannot override them in an SDK method. Visitors do not need to sign in to view published
59
+ content. Editing still requires `@uln/auth` and site access.
60
+
61
+ CORS does not authenticate server-to-server RPC. Binding/deployment permissions are the trust boundary: an
62
+ operator who can configure bindings in this account is trusted. Provider-side allowed-origin/referrer settings
63
+ and R2 CORS must separately use auth’s registered origins. Signed URLs are transferable until expiry; origin
64
+ checks are not DRM. Metadata-only legacy RPC methods retain their existing site-registration checks for
65
+ compatibility; the SDK uses the origin-checked content methods, including `contactsContent()`.
66
+
67
+ All content methods are public projections: hidden films, hidden categories, encoding films, hidden shoots and
68
+ empty shoots are excluded. Editing and previewing unpublished content belong in Manage behind `@uln/auth`.
69
+ The client has no write methods and `managementUrl()` does not authorize access.
70
+
71
+ Signed URLs are bearer capabilities. `expiresAt` is Unix milliseconds; refresh content before that time, and
72
+ never cache a page or data response beyond the earliest URL expiry. Leave room for playback duration and cache
73
+ staleness. Manage currently issues six-hour provider links; do not hardcode that duration in consumers. Long-lived
74
+ pages must renew their content. Existing external HTTPS sources are explicitly represented with a null expiry;
75
+ new private providers need a server-side signing adapter before being supported. Never rewrite or strip signing
76
+ query parameters. Stream signs HLS and poster URLs, Images signs image URLs, R2 signs preview object GET URLs.
77
+
78
+ Consumers own layout, category navigation, slugs, languages and playback through `@uln/hls`. Neither Manage nor
79
+ this SDK proxies images, previews or video streams to client websites.
80
+
81
+ ## Reporting your @uln packages
82
+
83
+ Add `ulnPackages()` to the site's Vite config so admins can see, on Manage's **SDK versions** page, which `@uln/*`
84
+ packages the live site was built with and which need upgrading:
85
+
86
+ ```ts
87
+ // vite.config.ts
88
+ import { ulnPackages } from "@uln/manage/vite";
89
+
90
+ export default defineConfig({ plugins: [ulnPackages() /* , … */] });
91
+ ```
92
+
93
+ The build writes `/.well-known/uln-packages.json` into the client output (the dev server answers it too): each
94
+ `@uln/*` package in the site's `package.json`, the version installed, its range and dependency section, and the
95
+ site's `packageManager`. It is a static file, served like any other asset; it names package versions only. Server code
96
+ can import the same report: `import { report } from "virtual:uln-packages"`. The contract is `src/package-report.ts`.
97
+
98
+ ## Developing and publishing
99
+
100
+ The package is built from this repository: `sdk/` holds its entry points, and its types come from Manage's
101
+ canonical contract in `src/` (`src/rpc-types.ts`, `src/schema.ts`, `src/public-content.ts`). The tarball has
102
+ compiled ESM and declarations only, with no UI, database code, signer or credentials.
103
+
104
+ - `pnpm build:sdk` builds `sdk/dist`.
105
+ - `pnpm check:sdk` builds and packs the tarball, installs it in a throwaway consumer and checks it as a site
106
+ would use it: the tarball's contents, strict typechecking under NodeNext and Bundler resolution, and every entry
107
+ point loading under Node. CI runs it on every push.
108
+ - Every relative import reachable from the SDK's entry points keeps its `.ts` extension (the SDK build uses NodeNext
109
+ resolution and fails without one). Without it, the published declarations break for NodeNext sites.
110
+
111
+ To release:
112
+
113
+ 1. Bump `version` in `sdk/package.json` and `SDK_VERSION` in `sdk/version.ts` together (a test checks they match),
114
+ and add a `## <version> — <YYYY-MM-DD>` section at the top of `sdk/CHANGELOG.md` saying what changed for sites.
115
+ Pre-1.0, a breaking change is a minor bump, though the contract only grows.
116
+ 2. Once that's on `main`, run the **Release SDK** workflow (`.github/workflows/release-sdk.yml`) on `main`. It
117
+ runs every check, publishes `@uln/manage@<version>` to npm with Trusted Publishing (no npm token), tags
118
+ `sdk-v<version>` and creates a GitHub release from the changelog section. Re-running is safe.
119
+
120
+ Never run `npm publish` by hand. Publishing doesn't deploy Manage, and deploying Manage doesn't publish the SDK.
package/dist/index.js ADDED
@@ -0,0 +1,106 @@
1
+ function e(e) {
2
+ let t = new URLSearchParams();
3
+ e?.photoWidths?.length && t.set("photoWidths", e.photoWidths.join(",")), e?.posterWidths?.length && t.set("posterWidths", e.posterWidths.join(","));
4
+ let n = t.toString();
5
+ return n ? `?${n}` : "";
6
+ }
7
+ // src/content-api-spec.ts
8
+ var t = (e, t) => ({
9
+ name: e,
10
+ in: "query",
11
+ required: !1,
12
+ schema: {
13
+ type: "string",
14
+ pattern: "^\\d+(,\\d+)*$"
15
+ },
16
+ description: `${t} Comma-separated whole pixels from 1 to 8192, at most 12.`
17
+ });
18
+ t("photoWidths", "Photo widths the site displays; each comes back in `variants`."), t("posterWidths", "Poster widths the site displays; each comes back in `posterVariants`.");
19
+ // src/public-content.ts
20
+ function n({ film: e, playback: t, poster: n, posterVariants: r, preview: i, previewPlayback: a }) {
21
+ let o = [
22
+ t.expiresAt,
23
+ n.expiresAt,
24
+ i?.expiresAt,
25
+ a?.expiresAt
26
+ ].filter((e) => typeof e == "number"), s = o.length ? Math.min(...o) : null, { previewAsset: c, previewPreparation: l, frameImages: u, cachedFrames: d, processing: f, hidden: p, ...m } = e;
27
+ return {
28
+ ...m,
29
+ playbackUrl: t.url,
30
+ posterUrl: n.url,
31
+ ...r ? { posterVariants: Object.fromEntries(Object.entries(r).map(([e, t]) => [e, t.url])) } : {},
32
+ ...i ? {
33
+ previewUrl: i.url,
34
+ previewStart: c?.sourceStart ?? e.previewStart ?? 0,
35
+ ...c?.size ? { previewBytes: c.size } : {}
36
+ } : {},
37
+ ...a ? {
38
+ previewPlaybackUrl: a.url,
39
+ ...i ? {} : { previewStart: c?.sourceStart ?? e.previewStart ?? 0 }
40
+ } : {},
41
+ expiresAt: s
42
+ };
43
+ }
44
+ function r({ shoot: e, photos: t }) {
45
+ let { photos: n, hidden: r, ...i } = e;
46
+ return {
47
+ ...i,
48
+ photos: t.map(({ photo: e, image: t, variants: n }) => ({
49
+ ...e,
50
+ url: t.url,
51
+ ...n ? { variants: Object.fromEntries(Object.entries(n).map(([e, t]) => [e, t.url])) } : {},
52
+ expiresAt: t.expiresAt
53
+ }))
54
+ };
55
+ }
56
+ // sdk/index.ts
57
+ function i(e) {
58
+ return {
59
+ async films(t) {
60
+ return (await e.filmsContent(t)).films.map(n);
61
+ },
62
+ async film(t, r) {
63
+ let i = await e.filmContent(t, r);
64
+ return i ? n(i) : void 0;
65
+ },
66
+ async shoots(t) {
67
+ return (await e.stillsContent(t)).shoots.map(r);
68
+ },
69
+ async shoot(t, n) {
70
+ let i = await e.shootContent(t, n);
71
+ return i ? r(i) : void 0;
72
+ },
73
+ contacts: () => e.contactsContent()
74
+ };
75
+ }
76
+ function a(t) {
77
+ let n = `${new URL(t.origin ?? "https://manage.uln.industries").origin}/api/content/v1`, r = t.fetch ?? ((e, t) => fetch(e, t));
78
+ async function i(e, i, a = !1) {
79
+ let o = await r(`${n}${e}`, { headers: {
80
+ Authorization: `Bearer ${t.apiKey}`,
81
+ Accept: "application/json"
82
+ } });
83
+ if (a && o.status === 404) return;
84
+ if (!o.ok) {
85
+ let t = await o.json().catch(() => null), n = typeof t?.error == "string" ? t.error : o.statusText;
86
+ throw Error(`Manage content API ${e}: ${o.status} ${n}`);
87
+ }
88
+ let s = await o.json();
89
+ if (!(i in s)) throw Error(`Manage content API ${e}: response has no "${i}"`);
90
+ return s[i];
91
+ }
92
+ return {
93
+ films: (t) => i(`/films${e(t)}`, "films"),
94
+ film: (t, n) => i(`/films/${encodeURIComponent(t)}${e(n)}`, "film", !0),
95
+ shoots: (t) => i(`/shoots${e(t)}`, "shoots"),
96
+ shoot: (t, n) => i(`/shoots/${encodeURIComponent(t)}${e(n)}`, "shoot", !0),
97
+ contacts: () => i("/contacts", "contacts")
98
+ };
99
+ }
100
+ function o(e, t = "https://manage.uln.industries") {
101
+ if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(e)) throw Error("Invalid site id");
102
+ let n = new URL(t);
103
+ if (n.protocol !== "https:" && (n.protocol !== "http:" || n.hostname !== "localhost")) throw Error("Manage requires HTTPS (or localhost)");
104
+ return n.pathname = `/sites/${e}`, n.search = "", n.hash = "", n.toString();
105
+ }
106
+ export { a as createHttpManagementClient, i as createManagementClient, o as managementUrl };
package/dist/rpc.js ADDED
File without changes
@@ -0,0 +1,38 @@
1
+ import { type MediaSizes } from "../src/media-sizes.ts";
2
+ import { type PublicFilm, type PublicShoot } from "../src/public-content.ts";
3
+ import type { PublicCatalogRpc } from "../src/rpc-types.ts";
4
+ import type { SiteContact } from "../src/schema.ts";
5
+ export type { MediaSizes } from "../src/media-sizes.ts";
6
+ export type { PublicFilm, PublicPhoto, PublicShoot } from "../src/public-content.ts";
7
+ export type { PublicCatalogProps, PublicCatalogRpc } from "../src/rpc-types.ts";
8
+ export type { Credit, SiteContact } from "../src/schema.ts";
9
+ /**
10
+ * `sizes` names the widths the site's layout needs: each photo's `variants` and each film's `posterVariants` hold
11
+ * one signed URL per requested width. Ask for a small, stable set; Manage keeps no size preferences of its own.
12
+ */
13
+ export interface ManagementClient {
14
+ films(sizes?: MediaSizes): Promise<PublicFilm[]>;
15
+ film(id: string, sizes?: MediaSizes): Promise<PublicFilm | undefined>;
16
+ shoots(sizes?: MediaSizes): Promise<PublicShoot[]>;
17
+ shoot(id: string, sizes?: MediaSizes): Promise<PublicShoot | undefined>;
18
+ contacts(): Promise<SiteContact[]>;
19
+ }
20
+ type ContentBinding = Pick<PublicCatalogRpc, "filmsContent" | "filmContent" | "stillsContent" | "shootContent" | "contactsContent">;
21
+ /** Public lists only. The binding fixes the site and keeps its receiver; callers never pass a site id. */
22
+ export declare function createManagementClient(binding: ContentBinding): ManagementClient;
23
+ export interface HttpManagementClientOptions {
24
+ /** The site's Manage API key (`mk_<site>_…`), created by an admin on the site's API page in Manage. Server-only. */
25
+ apiKey: string;
26
+ /** Manage's origin. */
27
+ origin?: string;
28
+ /** Override for tests or instrumentation; defaults to the global `fetch`. */
29
+ fetch?: typeof fetch;
30
+ }
31
+ /**
32
+ * The same client over HTTP (`/api/content/v1`), for a website whose Worker can't bind Manage because it runs in
33
+ * another Cloudflare account. The key fixes the site. Call it from server code only: never ship the key to a browser.
34
+ * Missing or unpublished details return undefined; any other failure (bad key, Manage unavailable) rejects.
35
+ */
36
+ export declare function createHttpManagementClient(options: HttpManagementClientOptions): ManagementClient;
37
+ /** A navigation link, never an authorization decision. Manage checks access against auth. */
38
+ export declare function managementUrl(site: string, origin?: string): string;
@@ -0,0 +1 @@
1
+ export type { PublicCatalogProps, PublicCatalogRpc } from "../src/rpc-types.ts";
@@ -0,0 +1,12 @@
1
+ import type { Plugin } from "vite";
2
+ import { type PackageReport } from "../src/package-report.ts";
3
+ export { PACKAGE_REPORT_PATH, type PackageReport } from "../src/package-report.ts";
4
+ export interface UlnPackagesOptions {
5
+ /** The directory whose `package.json` names the site's dependencies. Defaults to Vite's `root`. */
6
+ root?: string;
7
+ }
8
+ /** The report for the site whose `package.json` is in `root`. Throws when there is no `package.json` there. */
9
+ export declare function packageReport(root: string, now?: Date): PackageReport;
10
+ /** The report as a module of the site's own code: `import { report } from "virtual:uln-packages"`. */
11
+ export declare const VIRTUAL_MODULE = "virtual:uln-packages";
12
+ export declare function ulnPackages(options?: UlnPackagesOptions): Plugin;