@openrails/contentkit-ui 0.87.0-rc.1 → 0.88.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/README.md +18 -11
- package/dist/client/beacons.js +5 -1
- package/dist/client/beacons.js.map +1 -1
- package/dist/client/contents.d.ts +8 -6
- package/dist/client/contents.js +10 -7
- package/dist/client/contents.js.map +1 -1
- package/dist/client/errors.d.ts +15 -3
- package/dist/client/errors.js +40 -14
- package/dist/client/errors.js.map +1 -1
- package/dist/client/generated/routes.d.ts +1 -1
- package/dist/client/generated/routes.js +1 -1
- package/dist/client/generated/routes.js.map +1 -1
- package/dist/client/generated/wire.d.ts +12 -3
- package/dist/client/generated/wire.js.map +1 -1
- package/dist/client/http.js +27 -27
- package/dist/client/http.js.map +1 -1
- package/dist/client/index.d.ts +2 -2
- package/dist/client/media/client.d.ts +10 -4
- package/dist/client/media/client.js +33 -7
- package/dist/client/media/client.js.map +1 -1
- package/dist/client/media/rules.d.ts +1 -1
- package/dist/client/media/rules.js +6 -6
- package/dist/client/media/rules.js.map +1 -1
- package/dist/client/media/transport.d.ts +1 -1
- package/dist/client/media/transport.js +16 -16
- package/dist/client/media/transport.js.map +1 -1
- package/dist/client/public.d.ts +2 -2
- package/dist/client/public.js +2 -2
- package/dist/client/public.js.map +1 -1
- package/dist/client.js +25 -25
- package/dist/components/admin/content-manager.js +233 -232
- package/dist/components/admin/content-manager.js.map +1 -1
- package/dist/components/content/card.d.ts +1 -1
- package/dist/components/content/card.js +132 -120
- package/dist/components/content/card.js.map +1 -1
- package/dist/components/content/editors.d.ts +8 -0
- package/dist/components/content/editors.js +299 -229
- package/dist/components/content/editors.js.map +1 -1
- package/dist/components/content/index.d.ts +1 -1
- package/dist/components/content/paywall.js +61 -61
- package/dist/components/content/paywall.js.map +1 -1
- package/dist/i18n/messages.js +49 -46
- package/dist/i18n/messages.js.map +1 -1
- package/dist/index.js +11 -11
- package/dist/locales/de.js +2 -1
- package/dist/locales/de.js.map +1 -1
- package/dist/locales/en.d.ts +1 -0
- package/dist/locales/en.js +2 -1
- package/dist/locales/en.js.map +1 -1
- package/dist/locales/es.js +2 -1
- package/dist/locales/es.js.map +1 -1
- package/dist/locales/ja.js +2 -1
- package/dist/locales/ja.js.map +1 -1
- package/dist/locales/ko.js +2 -1
- package/dist/locales/ko.js.map +1 -1
- package/dist/locales/zh.js +2 -1
- package/dist/locales/zh.js.map +1 -1
- package/dist/react/contents.d.ts +13 -5
- package/dist/react/contents.js +163 -149
- package/dist/react/contents.js.map +1 -1
- package/dist/react/detail.d.ts +7 -1
- package/dist/react/detail.js +9 -6
- package/dist/react/detail.js.map +1 -1
- package/dist/react/index.d.ts +1 -1
- package/dist/react/public.js +17 -16
- package/dist/react/public.js.map +1 -1
- package/dist/react.js +8 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,14 +93,16 @@ operation. This does not change the operation's result or its authentication.
|
|
|
93
93
|
`groups.uploadCover(group, file)` its cover; `client.kinds()` the content model.
|
|
94
94
|
- **Images of content and polls** go to the item's server-named upload path:
|
|
95
95
|
`media.uploadNamed(ref, file)` resolves the name content routes take
|
|
96
|
-
(`contents.setCover
|
|
97
|
-
|
|
96
|
+
(`contents.setCover(id, version, name)`: every file of a content lives in a
|
|
97
|
+
version); `media.uploadInline({kind, id, version}, file)` puts a body image
|
|
98
|
+
in the version's private files, copied into the other versions, and
|
|
99
|
+
resolves its reference (`ref`, `contentkit:i-{uuid}`, what the body stores:
|
|
98
100
|
`imageRef(name)`) and a URL that shows it now; `polls.uploadImage` and
|
|
99
101
|
`polls.uploadOptionImage` do both steps. Reads resolve references: a
|
|
100
|
-
content's `body` shows
|
|
101
|
-
each name to its URL. `folders` renames
|
|
102
|
-
files exist only while the item is live;
|
|
103
|
-
item's images to its editors (below).
|
|
102
|
+
content's `body` shows its images' signed URLs (the opened version's
|
|
103
|
+
private files) and `images` maps each name to its URL. `folders` renames
|
|
104
|
+
the poll media kind. Public image files exist only while the item is live;
|
|
105
|
+
`useContent` shows an unpublished item's images to its editors (below).
|
|
104
106
|
- **`client.config()`** says what the content module allows: which
|
|
105
107
|
interactions signed-out visitors may make (`content.Options.Anonymous`,
|
|
106
108
|
none by default) and the longest comment (`CommentMaxLength`, 2,200 by
|
|
@@ -587,11 +589,16 @@ const nav = useMemo(() => ({ pathname: location.pathname, search: location.searc
|
|
|
587
589
|
## Errors
|
|
588
590
|
|
|
589
591
|
Every call rejects with `ContentKitError`: `code` (the server's, or `network`,
|
|
590
|
-
`storage`, `aborted`, `resume_mismatch`, `decode`,
|
|
591
|
-
`status`, `retryAfter`, `details` (image and video limits),
|
|
592
|
-
(`not_uploaded`), `ban` (`comment_banned`)
|
|
593
|
-
|
|
594
|
-
|
|
592
|
+
`server_unavailable`, `storage`, `aborted`, `resume_mismatch`, `decode`,
|
|
593
|
+
`render_timeout`), `status`, `retryAfter`, `details` (image and video limits),
|
|
594
|
+
`blobs` (`not_uploaded`), `ban` (`comment_banned`), `action` (`rate_limited`)
|
|
595
|
+
and `unknownCode` (a code this client doesn't know; the message is the
|
|
596
|
+
server's), plus `refusal`, `isLimit`, `isCeiling`, `blocksQueue` and
|
|
597
|
+
`transient`. Every code has a message in every bundle (`useMessages().error(e)`).
|
|
598
|
+
|
|
599
|
+
Failures are classified like auth-ui's and billing-ui's (`transportFailure`):
|
|
600
|
+
no server reached is `network`; a 502, 503, 504 or 520–524 without an API
|
|
601
|
+
error body, or a timeout, is `server_unavailable`.
|
|
595
602
|
|
|
596
603
|
## Migrating from the two old packages
|
|
597
604
|
|
package/dist/client/beacons.js
CHANGED
|
@@ -62,7 +62,11 @@ var o = class {
|
|
|
62
62
|
let a = this.session(), o = [], { discovery: s } = this.client;
|
|
63
63
|
for (let e = 0; e < r.length; e += t) o.push(s.signals(r.slice(e, e + t), a, { keepalive: n }));
|
|
64
64
|
for (let e = 0; e < i.length; e += t) o.push(s.exposures(i.slice(e, e + t), a, { keepalive: n }));
|
|
65
|
-
(await Promise.allSettled(o)).some((t) => t.status === "rejected" && [
|
|
65
|
+
(await Promise.allSettled(o)).some((t) => t.status === "rejected" && [
|
|
66
|
+
"not_configured",
|
|
67
|
+
"unavailable",
|
|
68
|
+
"server_unavailable"
|
|
69
|
+
].includes(e(t.reason).code)) && this.pause();
|
|
66
70
|
}
|
|
67
71
|
signal(e) {
|
|
68
72
|
this.paused() || (e.type === "view" && (this.signals = this.signals.filter((t) => t.event_id !== e.event_id)), this.signals.push(e), this.schedule());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"beacons.js","names":[],"sources":["../../src/client/beacons.ts"],"sourcesContent":["import type { ContentKitClient } from \"./client.js\";\nimport { toContentKitError } from \"./errors.js\";\nimport type { ExposureInput, SignalInput } from \"./generated/wire.js\";\n\nexport interface BeaconOptions {\n /** A signed-out visitor's session; default one per browser tab. */\n session?: () => string | undefined;\n /** How long events gather before they are sent, ms. Default 2000. */\n delay?: number;\n /** How long beacons stay off after the site records no signals, ms, before the content model is read again. Default 60000. */\n recheck?: number;\n}\n\n/** Where a click or a view came from: the list render it was shown in. */\nexport interface Attribution {\n render_id?: string;\n surface?: string;\n /** 1-based position in that render. */\n position?: number;\n}\n\nexport interface ViewSession {\n /** Reports the view so far: pages read, seconds watched or percent scrolled; resume is where to pick up. */\n update(o: { progress?: number; duration_s?: number; resume?: string }): void;\n}\n\nconst MAX = 100;\nconst SESSION_KEY = \"contentkit.session\";\nexport const eventId = () => (typeof crypto !== \"undefined\" && \"randomUUID\" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`);\n\nlet unstored: string | undefined;\n\n/** A signed-out reader's session: one per browser tab, kept across reloads. */\nexport function readerSession(): string {\n try {\n const kept = sessionStorage.getItem(SESSION_KEY);\n if (kept) return kept;\n const made = eventId();\n sessionStorage.setItem(SESSION_KEY, made);\n return made;\n } catch {\n return (unstored ??= eventId());\n }\n}\n\n/**\n * Batched, best-effort signals and exposures: gathered for `delay`, sent in\n * one request each, flushed with keepalive when the page hides. While the\n * content model says the site records no signals (or a send is refused as\n * not_configured or unavailable) events are dropped; after `recheck` the\n * next event reads the model again, so signals resume when the site's\n * signal plane is back.\n */\nexport class Beacons {\n private signals: SignalInput[] = [];\n private exposures: ExposureInput[] = [];\n private timer: ReturnType<typeof setTimeout> | undefined;\n private offUntil = 0;\n private recorded: Promise<boolean> | undefined;\n private readonly session: () => string | undefined;\n private readonly delay: number;\n private readonly recheck: number;\n\n constructor(\n private readonly client: Pick<ContentKitClient, \"discovery\" | \"kinds\">,\n o: BeaconOptions = {},\n ) {\n this.session = o.session ?? readerSession;\n this.delay = o.delay ?? 2000;\n this.recheck = o.recheck ?? 60_000;\n if (typeof addEventListener === \"function\") {\n addEventListener(\"pagehide\", () => void this.flush(true));\n addEventListener(\"visibilitychange\", () => {\n if (typeof document !== \"undefined\" && document.visibilityState === \"hidden\") void this.flush(true);\n });\n }\n }\n\n /** A click on a listed card. */\n click(content: string, a: Attribution & { version_id?: string } = {}): void {\n this.signal({ content_id: content, type: \"click\", event_id: eventId(), occurred_at: new Date().toISOString(), ...a });\n }\n\n /** A consumption session of a content (or one version): each update a revision of one event. */\n view(content: string, version?: string, a: Attribution = {}): ViewSession {\n const event = eventId();\n let revision = 0;\n return {\n update: (o) => this.signal({ content_id: content, version_id: version, type: \"view\", event_id: event, revision: ++revision, occurred_at: new Date().toISOString(), ...a, ...o }),\n };\n }\n\n /** A result list served, rendered or shown. */\n exposure(e: ExposureInput): void {\n if (this.paused() || !e.shown.length) return;\n this.exposures.push(e);\n this.schedule();\n }\n\n /** Sends what has gathered now. */\n async flush(keepalive = false): Promise<void> {\n clearTimeout(this.timer);\n this.timer = undefined;\n const signals = this.signals.splice(0);\n const exposures = this.exposures.splice(0);\n if (this.paused() || (!signals.length && !exposures.length)) return;\n if (!(await this.recording())) {\n this.pause();\n return;\n }\n const session = this.session();\n const sends: Promise<void>[] = [];\n const { discovery } = this.client;\n for (let i = 0; i < signals.length; i += MAX) sends.push(discovery.signals(signals.slice(i, i + MAX), session, { keepalive }));\n for (let i = 0; i < exposures.length; i += MAX) sends.push(discovery.exposures(exposures.slice(i, i + MAX), session, { keepalive }));\n const done = await Promise.allSettled(sends);\n if (done.some((r) => r.status === \"rejected\" && [\"not_configured\", \"unavailable\"].includes(toContentKitError(r.reason).code))) this.pause();\n }\n\n private signal(s: SignalInput): void {\n if (this.paused()) return;\n // A view's later revision replaces its earlier one still waiting.\n if (s.type === \"view\") this.signals = this.signals.filter((x) => x.event_id !== s.event_id);\n this.signals.push(s);\n this.schedule();\n }\n\n /** Off until `recheck` passes; then the model is read again. */\n private paused(): boolean {\n if (this.offUntil > Date.now()) return true;\n this.offUntil = 0;\n return false;\n }\n\n private pause(): void {\n this.offUntil = Date.now() + this.recheck;\n this.recorded = undefined;\n }\n\n /** Whether the site records signals, asked at the first event and after a pause; an unreadable model sends anyway (a refusal still pauses them). */\n private recording(): Promise<boolean> {\n return (this.recorded ??= this.client.kinds().then(\n (m) => m.signals,\n () => true,\n ));\n }\n\n private schedule(): void {\n void this.recording();\n if (this.signals.length + this.exposures.length >= MAX) return void this.flush();\n this.timer ??= setTimeout(() => void this.flush(), this.delay);\n }\n}\n"],"mappings":";;AA0BA,IAAM,IAAM,KACN,IAAc,sBACP,UAAiB,OAAO,SAAW,OAAe,gBAAgB,SAAS,OAAO,WAAW,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,KAE1K;AAGJ,SAAgB,IAAwB;CACtC,IAAI;EACF,IAAM,IAAO,eAAe,QAAQ,CAAW;EAC/C,IAAI,GAAM,OAAO;EACjB,IAAM,IAAO,EAAQ;EAErB,OADA,eAAe,QAAQ,GAAa,CAAI,GACjC;CACT,QAAQ;EACN,OAAQ,MAAa,EAAQ;CAC/B;AACF;AAUA,IAAa,IAAb,MAAqB;CAWA;CAVnB,UAAiC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AK,UAAU,GAAI;GAC7B,KAAK,MAAM;GACX;EACF;EACA,IAAM,IAAU,KAAK,QAAQ,GACvB,IAAyB,CAAC,GAC1B,EAAE,iBAAc,KAAK;EAC3B,KAAK,IAAI,IAAI,GAAG,IAAI,EAAQ,QAAQ,KAAK,GAAK,EAAM,KAAK,EAAU,QAAQ,EAAQ,MAAM,GAAG,IAAI,CAAG,GAAG,GAAS,EAAE,aAAU,CAAC,CAAC;EAC7H,KAAK,IAAI,IAAI,GAAG,IAAI,EAAU,QAAQ,KAAK,GAAK,EAAM,KAAK,EAAU,UAAU,EAAU,MAAM,GAAG,IAAI,CAAG,GAAG,GAAS,EAAE,aAAU,CAAC,CAAC;EAEnI,CAAI,MADe,QAAQ,WAAW,CAAK,EAAA,CAClC,MAAM,MAAM,EAAE,WAAW,cAAc,CAAC,
|
|
1
|
+
{"version":3,"file":"beacons.js","names":[],"sources":["../../src/client/beacons.ts"],"sourcesContent":["import type { ContentKitClient } from \"./client.js\";\nimport { toContentKitError } from \"./errors.js\";\nimport type { ExposureInput, SignalInput } from \"./generated/wire.js\";\n\nexport interface BeaconOptions {\n /** A signed-out visitor's session; default one per browser tab. */\n session?: () => string | undefined;\n /** How long events gather before they are sent, ms. Default 2000. */\n delay?: number;\n /** How long beacons stay off after the site records no signals, ms, before the content model is read again. Default 60000. */\n recheck?: number;\n}\n\n/** Where a click or a view came from: the list render it was shown in. */\nexport interface Attribution {\n render_id?: string;\n surface?: string;\n /** 1-based position in that render. */\n position?: number;\n}\n\nexport interface ViewSession {\n /** Reports the view so far: pages read, seconds watched or percent scrolled; resume is where to pick up. */\n update(o: { progress?: number; duration_s?: number; resume?: string }): void;\n}\n\nconst MAX = 100;\nconst SESSION_KEY = \"contentkit.session\";\nexport const eventId = () => (typeof crypto !== \"undefined\" && \"randomUUID\" in crypto ? crypto.randomUUID() : `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`);\n\nlet unstored: string | undefined;\n\n/** A signed-out reader's session: one per browser tab, kept across reloads. */\nexport function readerSession(): string {\n try {\n const kept = sessionStorage.getItem(SESSION_KEY);\n if (kept) return kept;\n const made = eventId();\n sessionStorage.setItem(SESSION_KEY, made);\n return made;\n } catch {\n return (unstored ??= eventId());\n }\n}\n\n/**\n * Batched, best-effort signals and exposures: gathered for `delay`, sent in\n * one request each, flushed with keepalive when the page hides. While the\n * content model says the site records no signals (or a send is refused as\n * not_configured or unavailable) events are dropped; after `recheck` the\n * next event reads the model again, so signals resume when the site's\n * signal plane is back.\n */\nexport class Beacons {\n private signals: SignalInput[] = [];\n private exposures: ExposureInput[] = [];\n private timer: ReturnType<typeof setTimeout> | undefined;\n private offUntil = 0;\n private recorded: Promise<boolean> | undefined;\n private readonly session: () => string | undefined;\n private readonly delay: number;\n private readonly recheck: number;\n\n constructor(\n private readonly client: Pick<ContentKitClient, \"discovery\" | \"kinds\">,\n o: BeaconOptions = {},\n ) {\n this.session = o.session ?? readerSession;\n this.delay = o.delay ?? 2000;\n this.recheck = o.recheck ?? 60_000;\n if (typeof addEventListener === \"function\") {\n addEventListener(\"pagehide\", () => void this.flush(true));\n addEventListener(\"visibilitychange\", () => {\n if (typeof document !== \"undefined\" && document.visibilityState === \"hidden\") void this.flush(true);\n });\n }\n }\n\n /** A click on a listed card. */\n click(content: string, a: Attribution & { version_id?: string } = {}): void {\n this.signal({ content_id: content, type: \"click\", event_id: eventId(), occurred_at: new Date().toISOString(), ...a });\n }\n\n /** A consumption session of a content (or one version): each update a revision of one event. */\n view(content: string, version?: string, a: Attribution = {}): ViewSession {\n const event = eventId();\n let revision = 0;\n return {\n update: (o) => this.signal({ content_id: content, version_id: version, type: \"view\", event_id: event, revision: ++revision, occurred_at: new Date().toISOString(), ...a, ...o }),\n };\n }\n\n /** A result list served, rendered or shown. */\n exposure(e: ExposureInput): void {\n if (this.paused() || !e.shown.length) return;\n this.exposures.push(e);\n this.schedule();\n }\n\n /** Sends what has gathered now. */\n async flush(keepalive = false): Promise<void> {\n clearTimeout(this.timer);\n this.timer = undefined;\n const signals = this.signals.splice(0);\n const exposures = this.exposures.splice(0);\n if (this.paused() || (!signals.length && !exposures.length)) return;\n if (!(await this.recording())) {\n this.pause();\n return;\n }\n const session = this.session();\n const sends: Promise<void>[] = [];\n const { discovery } = this.client;\n for (let i = 0; i < signals.length; i += MAX) sends.push(discovery.signals(signals.slice(i, i + MAX), session, { keepalive }));\n for (let i = 0; i < exposures.length; i += MAX) sends.push(discovery.exposures(exposures.slice(i, i + MAX), session, { keepalive }));\n const done = await Promise.allSettled(sends);\n if (done.some((r) => r.status === \"rejected\" && [\"not_configured\", \"unavailable\", \"server_unavailable\"].includes(toContentKitError(r.reason).code))) this.pause();\n }\n\n private signal(s: SignalInput): void {\n if (this.paused()) return;\n // A view's later revision replaces its earlier one still waiting.\n if (s.type === \"view\") this.signals = this.signals.filter((x) => x.event_id !== s.event_id);\n this.signals.push(s);\n this.schedule();\n }\n\n /** Off until `recheck` passes; then the model is read again. */\n private paused(): boolean {\n if (this.offUntil > Date.now()) return true;\n this.offUntil = 0;\n return false;\n }\n\n private pause(): void {\n this.offUntil = Date.now() + this.recheck;\n this.recorded = undefined;\n }\n\n /** Whether the site records signals, asked at the first event and after a pause; an unreadable model sends anyway (a refusal still pauses them). */\n private recording(): Promise<boolean> {\n return (this.recorded ??= this.client.kinds().then(\n (m) => m.signals,\n () => true,\n ));\n }\n\n private schedule(): void {\n void this.recording();\n if (this.signals.length + this.exposures.length >= MAX) return void this.flush();\n this.timer ??= setTimeout(() => void this.flush(), this.delay);\n }\n}\n"],"mappings":";;AA0BA,IAAM,IAAM,KACN,IAAc,sBACP,UAAiB,OAAO,SAAW,OAAe,gBAAgB,SAAS,OAAO,WAAW,IAAI,GAAG,KAAK,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,GAAG,KAAK,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,KAE1K;AAGJ,SAAgB,IAAwB;CACtC,IAAI;EACF,IAAM,IAAO,eAA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AM,CAAC,CAAC,MAC3C,MAAM,EAAE,eACH,EACR;CACF;CAEA,WAAyB;EAEvB,IADA,KAAU,UAAU,GAChB,KAAK,QAAQ,SAAS,KAAK,UAAU,UAAU,GAAK,OAAO,KAAK,KAAK,MAAM;EAC/E,KAAK,UAAU,iBAAiB,KAAK,KAAK,MAAM,GAAG,KAAK,KAAK;CAC/D;AACF"}
|
|
@@ -9,8 +9,6 @@ export declare const IMAGE_SCHEME = "contentkit:";
|
|
|
9
9
|
* the image's current public file (`Content.images`).
|
|
10
10
|
*/
|
|
11
11
|
export declare const imageRef: (name: string) => string;
|
|
12
|
-
/** A content kind's body kind: the media folder of a content item's body images ({kind}.body, id), opened with the item. */
|
|
13
|
-
export declare const BODY_SUFFIX = ".body";
|
|
14
12
|
/** Matches every image reference; the name is group 1. */
|
|
15
13
|
export declare const imageRefs: () => RegExp;
|
|
16
14
|
/** GET /manage/contents filters, as the route names them. */
|
|
@@ -39,10 +37,14 @@ export declare class ContentsClient {
|
|
|
39
37
|
unpublish(id: string): Promise<Content>;
|
|
40
38
|
remove(id: string): Promise<void>;
|
|
41
39
|
restore(id: string): Promise<Content>;
|
|
42
|
-
/**
|
|
43
|
-
setCover(id: string, image: string | null): Promise<
|
|
44
|
-
/**
|
|
45
|
-
|
|
40
|
+
/** Selects a version's cover by the name ("i-{uuid}") of one of its cover uploads; null returns to its first. */
|
|
41
|
+
setCover(id: string, vid: string, image: string | null): Promise<Version>;
|
|
42
|
+
/**
|
|
43
|
+
* A body image uploaded to version vid (its private files), copied into
|
|
44
|
+
* every other version: the reference to store in the body and a URL that shows
|
|
45
|
+
* it to the editor now (null while none exists).
|
|
46
|
+
*/
|
|
47
|
+
inlineImage(id: string, vid: string, image: string, signal?: AbortSignal): Promise<InlineImage>;
|
|
46
48
|
addVersion(id: string, input: VersionInput): Promise<Version>;
|
|
47
49
|
updateVersion(id: string, vid: string, input: VersionInput): Promise<Version>;
|
|
48
50
|
removeVersion(id: string, vid: string): Promise<void>;
|
package/dist/client/contents.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { call as e } from "./route.js";
|
|
2
2
|
//#region src/client/contents.ts
|
|
3
|
-
var t = "contentkit:", n = (e) => t + e, r =
|
|
3
|
+
var t = "contentkit:", n = (e) => t + e, r = () => /contentkit:(i-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/g, i = class {
|
|
4
4
|
http;
|
|
5
5
|
constructor(e) {
|
|
6
6
|
this.http = e;
|
|
@@ -77,14 +77,17 @@ var t = "contentkit:", n = (e) => t + e, r = ".body", i = () => /contentkit:(i-[
|
|
|
77
77
|
restore(t) {
|
|
78
78
|
return this.write(e(this.http, "POST", "/contents/{id}/restore", { params: { id: t } }));
|
|
79
79
|
}
|
|
80
|
-
setCover(e, t) {
|
|
81
|
-
return this.
|
|
80
|
+
setCover(e, t, n) {
|
|
81
|
+
return this.updateVersion(e, t, { cover: n ?? "" });
|
|
82
82
|
}
|
|
83
|
-
inlineImage(t, n, r) {
|
|
83
|
+
inlineImage(t, n, r, i) {
|
|
84
84
|
return e(this.http, "POST", "/contents/{id}/images", {
|
|
85
85
|
params: { id: t },
|
|
86
|
-
body: {
|
|
87
|
-
|
|
86
|
+
body: {
|
|
87
|
+
image: r,
|
|
88
|
+
version: n
|
|
89
|
+
},
|
|
90
|
+
signal: i
|
|
88
91
|
});
|
|
89
92
|
}
|
|
90
93
|
addVersion(t, n) {
|
|
@@ -139,6 +142,6 @@ var t = "contentkit:", n = (e) => t + e, r = ".body", i = () => /contentkit:(i-[
|
|
|
139
142
|
}
|
|
140
143
|
};
|
|
141
144
|
//#endregion
|
|
142
|
-
export {
|
|
145
|
+
export { i as ContentsClient, t as IMAGE_SCHEME, n as imageRef, r as imageRefs };
|
|
143
146
|
|
|
144
147
|
//# sourceMappingURL=contents.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contents.js","names":[],"sources":["../../src/client/contents.ts"],"sourcesContent":["import type {\n CatalogText,\n Content,\n ContentInput,\n ContentPatch,\n Creator,\n InlineImage,\n Segment,\n Version,\n VersionInput,\n} from \"./generated/wire.js\";\nimport type { Http } from \"./http.js\";\nimport { call, type RouteQuery } from \"./route.js\";\n\n/** The URL scheme of an image reference in a content body. */\nexport const IMAGE_SCHEME = \"contentkit:\";\n\n/**\n * The reference a body stores for one of its images, by name\n * (\"contentkit:i-{uuid}\"), where the image's URL would go: reads resolve it to\n * the image's current public file (`Content.images`).\n */\nexport const imageRef = (name: string) => IMAGE_SCHEME + name;\n
|
|
1
|
+
{"version":3,"file":"contents.js","names":[],"sources":["../../src/client/contents.ts"],"sourcesContent":["import type {\n CatalogText,\n Content,\n ContentInput,\n ContentPatch,\n Creator,\n InlineImage,\n Segment,\n Version,\n VersionInput,\n} from \"./generated/wire.js\";\nimport type { Http } from \"./http.js\";\nimport { call, type RouteQuery } from \"./route.js\";\n\n/** The URL scheme of an image reference in a content body. */\nexport const IMAGE_SCHEME = \"contentkit:\";\n\n/**\n * The reference a body stores for one of its images, by name\n * (\"contentkit:i-{uuid}\"), where the image's URL would go: reads resolve it to\n * the image's current public file (`Content.images`).\n */\nexport const imageRef = (name: string) => IMAGE_SCHEME + name;\n\n/** Matches every image reference; the name is group 1. */\nexport const imageRefs = () => /contentkit:(i-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/g;\n\n/** GET /manage/contents filters, as the route names them. */\nexport type ManageQuery = RouteQuery<\"GET\", \"/manage/contents\">;\n\n/**\n * Content items: a viewer's reads, and the writes of their creators, their\n * owner group's editors and root:content:write holders.\n */\nexport class ContentsClient {\n constructor(private readonly http: Http) {}\n\n /** The item as the caller sees it; text in language, else the site's first, else any. */\n get(id: string, language?: string, signal?: AbortSignal): Promise<Content> {\n return call(this.http, \"GET\", \"/contents/{id}\", { params: { id }, query: { language }, signal });\n }\n version(id: string, vid: string, language?: string, signal?: AbortSignal): Promise<Version> {\n return call(this.http, \"GET\", \"/contents/{id}/versions/{vid}\", { params: { id, vid }, query: { language }, signal });\n }\n /** Items the caller manages, newest first: all for root:content:write holders, else theirs or an owner group's. */\n manage(q: ManageQuery = {}, signal?: AbortSignal): Promise<Content[]> {\n return call(this.http, \"GET\", \"/manage/contents\", { query: q, signal });\n }\n /** Creates a draft. */\n create(input: ContentInput): Promise<Content> {\n return this.write(call(this.http, \"POST\", \"/contents\", { body: input }));\n }\n update(id: string, patch: ContentPatch): Promise<Content> {\n return this.write(call(this.http, \"PATCH\", \"/contents/{id}\", { params: { id }, body: patch }));\n }\n /** Sets the text in one language; moderation \"held\" when the moderator holds the edit. */\n putText(id: string, language: string, text: CatalogText): Promise<Content> {\n return this.write(call(this.http, \"PUT\", \"/contents/{id}/text/{language}\", { params: { id, language }, body: text }));\n }\n deleteText(id: string, language: string): Promise<Content> {\n return this.write(call(this.http, \"DELETE\", \"/contents/{id}/text/{language}\", { params: { id, language } }));\n }\n setCreators(id: string, creators: Creator[]): Promise<Content> {\n return this.write(call(this.http, \"PUT\", \"/contents/{id}/creators\", { params: { id }, body: { creators } }));\n }\n /** Publishes now, or schedules for at; moderation \"held\" when the moderator holds it. */\n publish(id: string, at?: string): Promise<Content> {\n return this.write(call(this.http, \"POST\", \"/contents/{id}/publish\", { params: { id }, body: { publish_at: at } }));\n }\n unpublish(id: string): Promise<Content> {\n return this.write(call(this.http, \"POST\", \"/contents/{id}/unpublish\", { params: { id } }));\n }\n async remove(id: string): Promise<void> {\n const emit = this.http.captureChanges();\n await call(this.http, \"DELETE\", \"/contents/{id}\", { params: { id } });\n emit({ type: \"content.deleted\", id });\n }\n restore(id: string): Promise<Content> {\n return this.write(call(this.http, \"POST\", \"/contents/{id}/restore\", { params: { id } }));\n }\n /** Selects a version's cover by the name (\"i-{uuid}\") of one of its cover uploads; null returns to its first. */\n setCover(id: string, vid: string, image: string | null): Promise<Version> {\n return this.updateVersion(id, vid, { cover: image ?? \"\" });\n }\n /**\n * A body image uploaded to version vid (its private files), copied into\n * every other version: the reference to store in the body and a URL that shows\n * it to the editor now (null while none exists).\n */\n inlineImage(id: string, vid: string, image: string, signal?: AbortSignal): Promise<InlineImage> {\n return call(this.http, \"POST\", \"/contents/{id}/images\", { params: { id }, body: { image, version: vid }, signal });\n }\n addVersion(id: string, input: VersionInput): Promise<Version> {\n return this.writeVersion(id, call(this.http, \"POST\", \"/contents/{id}/versions\", { params: { id }, body: input }));\n }\n updateVersion(id: string, vid: string, input: VersionInput): Promise<Version> {\n return this.writeVersion(id, call(this.http, \"PATCH\", \"/contents/{id}/versions/{vid}\", { params: { id, vid }, body: input }));\n }\n async removeVersion(id: string, vid: string): Promise<void> {\n await this.writeVersion(id, call(this.http, \"DELETE\", \"/contents/{id}/versions/{vid}\", { params: { id, vid } }));\n }\n /** Orders the versions: ids lists each version that is not deleted, first first. */\n orderVersions(id: string, ids: string[]): Promise<Content> {\n return this.write(call(this.http, \"PUT\", \"/contents/{id}/versions/order\", { params: { id }, body: { ids } }));\n }\n /** Replaces a version's segments (chapters). */\n setSegments(id: string, vid: string, segments: Segment[]): Promise<Version> {\n return this.writeVersion(id, call(this.http, \"PUT\", \"/contents/{id}/versions/{vid}/segments\", { params: { id, vid }, body: { segments } }));\n }\n\n private async write(p: Promise<Content>): Promise<Content> {\n const emit = this.http.captureChanges();\n const content = await p;\n emit({ type: \"content.saved\", content });\n return content;\n }\n\n private async writeVersion<T>(id: string, p: Promise<T>): Promise<T> {\n const emit = this.http.captureChanges();\n const out = await p;\n emit({ type: \"content.changed\", id });\n return out;\n }\n}\n"],"mappings":";;AAeA,IAAa,IAAe,eAOf,KAAY,MAAiB,IAAe,GAG5C,UAAkB,gFASlB,IAAb,MAA4B;CACG;CAA7B,YAAY,GAA6B;EAAZ,KAAA,OAAA;CAAa;CAG1C,IAAI,GAAY,GAAmB,GAAwC;EACzE,OAAO,EAAK,KAAK,MAAM,OAAO,kBAAkB;GAAE,QAAQ,EAAE,MAAG;GA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C;GAAE,QAAQ,EAAE,MAAG;GAAG,MAAM,EAAE,OAAI;EAAE,CAAC,CAAC;CAC9G;CAEA,YAAY,GAAY,GAAa,GAAuC;EAC1E,OAAO,KAAK,aAAa,GAAI,EAAK,KAAK,MAAM,OAAO,0CAA0C;GAAE,QAAQ;IAAE;IAAI;GAAI;GAAG,MAAM,EAAE,YAAS;EAAE,CAAC,CAAC;CAC5I;CAEA,MAAc,MAAM,GAAuC;EACzD,IAAM,IAAO,KAAK,KAAK,eAAe,GAChC,IAAU,MAAM;EAEtB,OADA,EAAK;GAAE,MAAM;GAAiB;EAAQ,CAAC,GAChC;CACT;CAEA,MAAc,aAAgB,GAAY,GAA2B;EACnE,IAAM,IAAO,KAAK,KAAK,eAAe,GAChC,IAAM,MAAM;EAElB,OADA,EAAK;GAAE,MAAM;GAAmB;EAAG,CAAC,GAC7B;CACT;AACF"}
|
package/dist/client/errors.d.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ErrorCode } from './generated/error-codes.js';
|
|
2
2
|
import { BanNotice, ErrorDetails, Failure } from './generated/wire.js';
|
|
3
3
|
/**
|
|
4
|
-
* Codes raised in the browser: network (no
|
|
4
|
+
* Codes raised in the browser: network (no server reached), server_unavailable
|
|
5
|
+
* (a gateway or timeout answered instead of ContentKit), storage (the bucket
|
|
5
6
|
* refused a PUT), aborted (the caller's signal), resume_mismatch (saved state
|
|
6
7
|
* is not for this file), decode (not readable as an image) and render_timeout
|
|
7
8
|
* (still processing after the wait).
|
|
8
9
|
*/
|
|
9
|
-
export declare const CLIENT_ERROR_CODES: readonly ["network", "storage", "aborted", "resume_mismatch", "decode", "render_timeout"];
|
|
10
|
+
export declare const CLIENT_ERROR_CODES: readonly ["network", "server_unavailable", "storage", "aborted", "resume_mismatch", "decode", "render_timeout"];
|
|
10
11
|
export type ContentKitErrorCode = ErrorCode | (typeof CLIENT_ERROR_CODES)[number];
|
|
11
12
|
/** Every code a ContentKitError can carry: the server's registry, then the client's. */
|
|
12
13
|
export declare const ERROR_CODES: readonly ContentKitErrorCode[];
|
|
@@ -19,6 +20,7 @@ export interface ContentKitErrorInit extends ErrorOptions {
|
|
|
19
20
|
action?: string;
|
|
20
21
|
reason?: string;
|
|
21
22
|
availableAt?: string;
|
|
23
|
+
unknownCode?: string;
|
|
22
24
|
}
|
|
23
25
|
export declare class ContentKitError extends Error {
|
|
24
26
|
readonly code: ContentKitErrorCode;
|
|
@@ -34,6 +36,8 @@ export declare class ContentKitError extends Error {
|
|
|
34
36
|
readonly reason?: string;
|
|
35
37
|
/** A download_unavailable's opening time (RFC 3339), when a matter of time. */
|
|
36
38
|
readonly availableAt?: string;
|
|
39
|
+
/** A server code this client doesn't know (a newer server): `message` is the server's own and `code` its status's. */
|
|
40
|
+
readonly unknownCode?: string;
|
|
37
41
|
constructor(code: ContentKitErrorCode, message: string, init?: ContentKitErrorInit);
|
|
38
42
|
/**
|
|
39
43
|
* The request broke a rule the message states (a 4xx or a typed refusal),
|
|
@@ -50,8 +54,16 @@ export declare class ContentKitError extends Error {
|
|
|
50
54
|
get transient(): boolean;
|
|
51
55
|
}
|
|
52
56
|
export declare const isContentKitError: (e: unknown) => e is ContentKitError;
|
|
53
|
-
/** Anything a call can throw, as a ContentKitError
|
|
57
|
+
/** Anything a call can throw, as a ContentKitError: a transport failure's code, else internal_error. */
|
|
54
58
|
export declare function toContentKitError(e: unknown): ContentKitError;
|
|
59
|
+
/** A fetch that got no response: the caller's abort, a timeout, else no server reached. */
|
|
60
|
+
export declare function requestFailure(err: unknown, signal: AbortSignal | undefined, target: string): ContentKitError;
|
|
61
|
+
/**
|
|
62
|
+
* The client code of a request no server answered (mirrors auth-ui's and
|
|
63
|
+
* billing-ui's): network when none was reached, server_unavailable when a
|
|
64
|
+
* gateway or timeout answered. Recognizes the sibling SDKs' codes too.
|
|
65
|
+
*/
|
|
66
|
+
export declare function transportFailure(error: unknown): "network" | "server_unavailable" | undefined;
|
|
55
67
|
export declare function aborted(signal?: AbortSignal): ContentKitError;
|
|
56
68
|
export declare function throwIfAborted(signal?: AbortSignal): void;
|
|
57
69
|
/** Reads a response that is not 2xx. */
|
package/dist/client/errors.js
CHANGED
|
@@ -2,6 +2,7 @@ import { CONTENTKIT_ERROR_CODES as e } from "./generated/error-codes.js";
|
|
|
2
2
|
//#region src/client/errors.ts
|
|
3
3
|
var t = [
|
|
4
4
|
"network",
|
|
5
|
+
"server_unavailable",
|
|
5
6
|
"storage",
|
|
6
7
|
"aborted",
|
|
7
8
|
"resume_mismatch",
|
|
@@ -18,8 +19,9 @@ var t = [
|
|
|
18
19
|
action;
|
|
19
20
|
reason;
|
|
20
21
|
availableAt;
|
|
22
|
+
unknownCode;
|
|
21
23
|
constructor(e, t, n = {}) {
|
|
22
|
-
super(t, n.cause === void 0 ? void 0 : { cause: n.cause }), this.code = e, this.status = n.status ?? 0, this.retryAfter = n.retryAfter, this.details = n.details, this.blobs = n.blobs, this.ban = n.ban, this.action = n.action, this.reason = n.reason, this.availableAt = n.availableAt;
|
|
24
|
+
super(t, n.cause === void 0 ? void 0 : { cause: n.cause }), this.code = e, this.status = n.status ?? 0, this.retryAfter = n.retryAfter, this.details = n.details, this.blobs = n.blobs, this.ban = n.ban, this.action = n.action, this.reason = n.reason, this.availableAt = n.availableAt, this.unknownCode = n.unknownCode;
|
|
23
25
|
}
|
|
24
26
|
get refusal() {
|
|
25
27
|
return this.status >= 400 && this.status < 500 && this.code !== "storage" || this.code.startsWith("image_") || this.code === "decode";
|
|
@@ -34,19 +36,42 @@ var t = [
|
|
|
34
36
|
return this.isLimit || this.code === "unauthorized" || this.code === "forbidden";
|
|
35
37
|
}
|
|
36
38
|
get transient() {
|
|
37
|
-
return this.code === "network" || this.code === "internal_error" || this.code === "unavailable" || this.code === "storage" && (this.status >= 500 || this.status === 403 || this.status === 408 || this.status === 429);
|
|
39
|
+
return this.code === "network" || this.code === "server_unavailable" || this.code === "internal_error" || this.code === "unavailable" || this.code === "storage" && (this.status >= 500 || this.status === 403 || this.status === 408 || this.status === 429);
|
|
38
40
|
}
|
|
39
41
|
}, i = (e) => e instanceof r;
|
|
40
42
|
function a(e) {
|
|
41
|
-
return e instanceof r ? e : new r("
|
|
43
|
+
return e instanceof r ? e : new r(l(e) ?? "internal_error", e instanceof Error ? e.message : String(e), { cause: e });
|
|
42
44
|
}
|
|
43
|
-
function o(e) {
|
|
45
|
+
function o(e, t, n) {
|
|
46
|
+
let i = l(e);
|
|
47
|
+
return i !== "server_unavailable" && t?.aborted ? u(t) : i === "server_unavailable" ? new r(i, `${n} did not respond`, { cause: e }) : new r("network", `${n} unreachable`, { cause: e });
|
|
48
|
+
}
|
|
49
|
+
var s = /* @__PURE__ */ new Set([
|
|
50
|
+
502,
|
|
51
|
+
503,
|
|
52
|
+
504,
|
|
53
|
+
520,
|
|
54
|
+
521,
|
|
55
|
+
522,
|
|
56
|
+
523,
|
|
57
|
+
524
|
|
58
|
+
]), c = /fetch|network|load failed|connection/i;
|
|
59
|
+
function l(e) {
|
|
60
|
+
if (e instanceof TypeError) return globalThis.navigator?.onLine === !1 || c.test(e.message) ? "network" : void 0;
|
|
61
|
+
if (!e || typeof e != "object") return;
|
|
62
|
+
let { name: t, code: n, status: r } = e;
|
|
63
|
+
if (t === "TimeoutError") return "server_unavailable";
|
|
64
|
+
if (n === "network" || n === "network_error") return "network";
|
|
65
|
+
if (n === "server_unavailable") return n;
|
|
66
|
+
if (n === void 0 || n === "unknown_error" || n === "server_error") return typeof r == "number" && s.has(r) ? "server_unavailable" : void 0;
|
|
67
|
+
}
|
|
68
|
+
function u(e) {
|
|
44
69
|
return new r("aborted", "request canceled", { cause: e?.reason });
|
|
45
70
|
}
|
|
46
|
-
function
|
|
47
|
-
if (e?.aborted) throw
|
|
71
|
+
function d(e) {
|
|
72
|
+
if (e?.aborted) throw u(e);
|
|
48
73
|
}
|
|
49
|
-
var
|
|
74
|
+
var f = {
|
|
50
75
|
401: "unauthorized",
|
|
51
76
|
403: "forbidden",
|
|
52
77
|
404: "not_found",
|
|
@@ -57,14 +82,14 @@ var c = {
|
|
|
57
82
|
429: "rate_limited",
|
|
58
83
|
501: "not_configured",
|
|
59
84
|
503: "unavailable"
|
|
60
|
-
},
|
|
61
|
-
async function
|
|
85
|
+
}, p = new Set(n);
|
|
86
|
+
async function m(e) {
|
|
62
87
|
let t = {};
|
|
63
88
|
try {
|
|
64
89
|
t = await e.json();
|
|
65
90
|
} catch {}
|
|
66
91
|
let n = Number(e.headers.get("Retry-After")), i = t.retry_after ?? (Number.isFinite(n) && n > 0 ? n : void 0);
|
|
67
|
-
return new r(t.code &&
|
|
92
|
+
return new r(t.code && p.has(t.code) ? t.code : !t.code && s.has(e.status) ? "server_unavailable" : f[e.status] ?? (e.status >= 500 ? "internal_error" : "invalid_request"), t.error ?? `HTTP ${e.status}`, {
|
|
68
93
|
status: e.status,
|
|
69
94
|
retryAfter: i,
|
|
70
95
|
blobs: t.blobs,
|
|
@@ -72,13 +97,14 @@ async function u(e) {
|
|
|
72
97
|
ban: t.ban,
|
|
73
98
|
action: t.action,
|
|
74
99
|
reason: t.reason,
|
|
75
|
-
availableAt: t.available_at
|
|
100
|
+
availableAt: t.available_at,
|
|
101
|
+
unknownCode: t.code && !p.has(t.code) ? t.code : void 0
|
|
76
102
|
});
|
|
77
103
|
}
|
|
78
|
-
function
|
|
79
|
-
return new r(e.code &&
|
|
104
|
+
function h(e) {
|
|
105
|
+
return new r(e.code && p.has(e.code) ? e.code : "internal_error", e.message, { details: e.details });
|
|
80
106
|
}
|
|
81
107
|
//#endregion
|
|
82
|
-
export { t as CLIENT_ERROR_CODES, r as ContentKitError, n as ERROR_CODES,
|
|
108
|
+
export { t as CLIENT_ERROR_CODES, r as ContentKitError, n as ERROR_CODES, u as aborted, h as failureError, i as isContentKitError, m as readContentKitError, o as requestFailure, d as throwIfAborted, a as toContentKitError, l as transportFailure };
|
|
83
109
|
|
|
84
110
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["import { CONTENTKIT_ERROR_CODES, type ErrorCode } from \"./generated/error-codes.js\";\nimport type { BanNotice, ErrorDetails, ErrorReply, Failure } from \"./generated/wire.js\";\n\n/**\n * Codes raised in the browser: network (no response), storage (the bucket\n * refused a PUT), aborted (the caller's signal), resume_mismatch (saved state\n * is not for this file), decode (not readable as an image) and render_timeout\n * (still processing after the wait).\n */\nexport const CLIENT_ERROR_CODES = [\"network\", \"storage\", \"aborted\", \"resume_mismatch\", \"decode\", \"render_timeout\"] as const;\n\nexport type ContentKitErrorCode = ErrorCode | (typeof CLIENT_ERROR_CODES)[number];\n\n/** Every code a ContentKitError can carry: the server's registry, then the client's. */\nexport const ERROR_CODES: readonly ContentKitErrorCode[] = [...(Object.keys(CONTENTKIT_ERROR_CODES) as ErrorCode[]), ...CLIENT_ERROR_CODES];\n\nexport interface ContentKitErrorInit extends ErrorOptions {\n status?: number;\n retryAfter?: number;\n details?: ErrorDetails;\n blobs?: string[];\n ban?: BanNotice;\n action?: string;\n reason?: string;\n availableAt?: string;\n}\n\nexport class ContentKitError extends Error {\n override readonly name = \"ContentKitError\";\n /** HTTP status; 0 for client-side codes. */\n readonly status: number;\n readonly retryAfter?: number;\n readonly details?: ErrorDetails;\n readonly blobs?: string[];\n readonly ban?: BanNotice;\n readonly action?: string;\n /** A download_unavailable's code of the host's policy (\"release_window\"). */\n readonly reason?: string;\n /** A download_unavailable's opening time (RFC 3339), when a matter of time. */\n readonly availableAt?: string;\n\n constructor(\n readonly code: ContentKitErrorCode,\n message: string,\n init: ContentKitErrorInit = {},\n ) {\n super(message, init.cause === undefined ? undefined : { cause: init.cause });\n this.status = init.status ?? 0;\n this.retryAfter = init.retryAfter;\n this.details = init.details;\n this.blobs = init.blobs;\n this.ban = init.ban;\n this.action = init.action;\n this.reason = init.reason;\n this.availableAt = init.availableAt;\n }\n\n /**\n * The request broke a rule the message states (a 4xx or a typed refusal),\n * as opposed to a fault on the server or the network: show it as is.\n */\n get refusal(): boolean {\n return (this.status >= 400 && this.status < 500 && this.code !== \"storage\") || this.code.startsWith(\"image_\") || this.code === \"decode\";\n }\n\n /** Rate or quota refusals: stop starting new requests until the limit frees. */\n get isLimit(): boolean {\n return this.code === \"rate_limited\" || this.code === \"quota_exceeded\";\n }\n\n /** The commit would exceed the kind's file caps (too_many_files, 409): remove files first. */\n get isCeiling(): boolean {\n return this.code === \"too_many_files\";\n }\n\n /** Refusals that apply to every upload of this caller, not just this file. */\n get blocksQueue(): boolean {\n return this.isLimit || this.code === \"unauthorized\" || this.code === \"forbidden\";\n }\n\n /** Worth retrying the same request. */\n get transient(): boolean {\n return (\n this.code === \"network\" ||\n this.code === \"internal_error\" ||\n this.code === \"unavailable\" ||\n (this.code === \"storage\" && (this.status >= 500 || this.status === 403 || this.status === 408 || this.status === 429))\n );\n }\n}\n\nexport const isContentKitError = (e: unknown): e is ContentKitError => e instanceof ContentKitError;\n\n/** Anything a call can throw, as a ContentKitError (network when it is not one). */\nexport function toContentKitError(e: unknown): ContentKitError {\n if (e instanceof ContentKitError) return e;\n return new ContentKitError(\"network\", e instanceof Error ? e.message : String(e), { cause: e });\n}\n\nexport function aborted(signal?: AbortSignal): ContentKitError {\n return new ContentKitError(\"aborted\", \"request canceled\", { cause: signal?.reason });\n}\n\nexport function throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted) throw aborted(signal);\n}\n\nconst byStatus: Record<number, ContentKitErrorCode> = {\n 401: \"unauthorized\",\n 403: \"forbidden\",\n 404: \"not_found\",\n 409: \"conflict\",\n 410: \"gone\",\n 413: \"too_large\",\n 415: \"type_not_allowed\",\n 429: \"rate_limited\",\n 501: \"not_configured\",\n 503: \"unavailable\",\n};\n\nconst known = new Set<string>(ERROR_CODES);\n\n/** Reads a response that is not 2xx. */\nexport async function readContentKitError(res: Response): Promise<ContentKitError> {\n let body: Partial<ErrorReply> = {};\n try {\n body = (await res.json()) as Partial<ErrorReply>;\n } catch {\n // not JSON (a proxy error page)\n }\n const header = Number(res.headers.get(\"Retry-After\"));\n const retryAfter = body.retry_after ?? (Number.isFinite(header) && header > 0 ? header : undefined);\n const code = body.code && known.has(body.code) ? (body.code as ContentKitErrorCode) : (byStatus[res.status] ?? (res.status >= 500 ? \"internal_error\" : \"invalid_request\"));\n return new ContentKitError(code, body.error ?? `HTTP ${res.status}`, {\n status: res.status,\n retryAfter,\n blobs: body.blobs,\n details: body.details,\n ban: body.ban,\n action: body.action,\n reason: body.reason,\n availableAt: body.available_at,\n });\n}\n\n/** An upload's recorded processing failure: its typed refusal, else a processing fault. */\nexport function failureError(f: Failure): ContentKitError {\n const code = f.code && known.has(f.code) ? (f.code as ContentKitErrorCode) : \"internal_error\";\n return new ContentKitError(code, f.message, { details: f.details });\n}\n"],"mappings":";;AASA,IAAa,IAAqB;CAAC;CAAW;CAAW;CAAW;CAAmB;CAAU;AAAgB,GAKpG,IAA8C,CAAC,GAAI,OAAO,KAAK,CAAsB,GAAmB,GAAG,CAAkB,GAa7H,IAAb,cAAqC,MAAM;CAe9B;CAdX,OAAyB;CAEzB;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CAEA,YACE,GACA,GACA,IAA4B,CAAC,GAC7B;EASA,AARA,MAAM,GAAS,EAAK,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,OAAO,EAAK,MAAM,CAAC,GAJlE,KAAA,OAAA,GAKT,KAAK,SAAS,EAAK,UAAU,GAC7B,KAAK,aAAa,EAAK,YACvB,KAAK,UAAU,EAAK,SACpB,KAAK,QAAQ,EAAK,OAClB,KAAK,MAAM,EAAK,KAChB,KAAK,SAAS,EAAK,QACnB,KAAK,SAAS,EAAK,QACnB,KAAK,cAAc,EAAK;CAC1B;CAMA,IAAI,UAAmB;EACrB,OAAQ,KAAK,UAAU,OAAO,KAAK,SAAS,OAAO,KAAK,SAAS,aAAc,KAAK,KAAK,WAAW,QAAQ,KAAK,KAAK,SAAS;CACjI;CAGA,IAA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I,YAAY,EAAI,UAAU,MAAM,mBAAmB,oBACtH,EAAK,SAAS,QAAQ,EAAI,UAAU;EACnE,QAAQ,EAAI;EACZ;EACA,OAAO,EAAK;EACZ,SAAS,EAAK;EACd,KAAK,EAAK;EACV,QAAQ,EAAK;EACb,QAAQ,EAAK;EACb,aAAa,EAAK;CACpB,CAAC;AACH;AAGA,SAAgB,EAAa,GAA6B;CAExD,OAAO,IAAI,EADE,EAAE,QAAQ,EAAM,IAAI,EAAE,IAAI,IAAK,EAAE,OAA+B,kBAC5C,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;AACpE"}
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../src/client/errors.ts"],"sourcesContent":["import { CONTENTKIT_ERROR_CODES, type ErrorCode } from \"./generated/error-codes.js\";\nimport type { BanNotice, ErrorDetails, ErrorReply, Failure } from \"./generated/wire.js\";\n\n/**\n * Codes raised in the browser: network (no server reached), server_unavailable\n * (a gateway or timeout answered instead of ContentKit), storage (the bucket\n * refused a PUT), aborted (the caller's signal), resume_mismatch (saved state\n * is not for this file), decode (not readable as an image) and render_timeout\n * (still processing after the wait).\n */\nexport const CLIENT_ERROR_CODES = [\"network\", \"server_unavailable\", \"storage\", \"aborted\", \"resume_mismatch\", \"decode\", \"render_timeout\"] as const;\n\nexport type ContentKitErrorCode = ErrorCode | (typeof CLIENT_ERROR_CODES)[number];\n\n/** Every code a ContentKitError can carry: the server's registry, then the client's. */\nexport const ERROR_CODES: readonly ContentKitErrorCode[] = [...(Object.keys(CONTENTKIT_ERROR_CODES) as ErrorCode[]), ...CLIENT_ERROR_CODES];\n\nexport interface ContentKitErrorInit extends ErrorOptions {\n status?: number;\n retryAfter?: number;\n details?: ErrorDetails;\n blobs?: string[];\n ban?: BanNotice;\n action?: string;\n reason?: string;\n availableAt?: string;\n unknownCode?: string;\n}\n\nexport class ContentKitError extends Error {\n override readonly name = \"ContentKitError\";\n /** HTTP status; 0 for client-side codes. */\n readonly status: number;\n readonly retryAfter?: number;\n readonly details?: ErrorDetails;\n readonly blobs?: string[];\n readonly ban?: BanNotice;\n readonly action?: string;\n /** A download_unavailable's code of the host's policy (\"release_window\"). */\n readonly reason?: string;\n /** A download_unavailable's opening time (RFC 3339), when a matter of time. */\n readonly availableAt?: string;\n /** A server code this client doesn't know (a newer server): `message` is the server's own and `code` its status's. */\n readonly unknownCode?: string;\n\n constructor(\n readonly code: ContentKitErrorCode,\n message: string,\n init: ContentKitErrorInit = {},\n ) {\n super(message, init.cause === undefined ? undefined : { cause: init.cause });\n this.status = init.status ?? 0;\n this.retryAfter = init.retryAfter;\n this.details = init.details;\n this.blobs = init.blobs;\n this.ban = init.ban;\n this.action = init.action;\n this.reason = init.reason;\n this.availableAt = init.availableAt;\n this.unknownCode = init.unknownCode;\n }\n\n /**\n * The request broke a rule the message states (a 4xx or a typed refusal),\n * as opposed to a fault on the server or the network: show it as is.\n */\n get refusal(): boolean {\n return (this.status >= 400 && this.status < 500 && this.code !== \"storage\") || this.code.startsWith(\"image_\") || this.code === \"decode\";\n }\n\n /** Rate or quota refusals: stop starting new requests until the limit frees. */\n get isLimit(): boolean {\n return this.code === \"rate_limited\" || this.code === \"quota_exceeded\";\n }\n\n /** The commit would exceed the kind's file caps (too_many_files, 409): remove files first. */\n get isCeiling(): boolean {\n return this.code === \"too_many_files\";\n }\n\n /** Refusals that apply to every upload of this caller, not just this file. */\n get blocksQueue(): boolean {\n return this.isLimit || this.code === \"unauthorized\" || this.code === \"forbidden\";\n }\n\n /** Worth retrying the same request. */\n get transient(): boolean {\n return (\n this.code === \"network\" ||\n this.code === \"server_unavailable\" ||\n this.code === \"internal_error\" ||\n this.code === \"unavailable\" ||\n (this.code === \"storage\" && (this.status >= 500 || this.status === 403 || this.status === 408 || this.status === 429))\n );\n }\n}\n\nexport const isContentKitError = (e: unknown): e is ContentKitError => e instanceof ContentKitError;\n\n/** Anything a call can throw, as a ContentKitError: a transport failure's code, else internal_error. */\nexport function toContentKitError(e: unknown): ContentKitError {\n if (e instanceof ContentKitError) return e;\n return new ContentKitError(transportFailure(e) ?? \"internal_error\", e instanceof Error ? e.message : String(e), { cause: e });\n}\n\n/** A fetch that got no response: the caller's abort, a timeout, else no server reached. */\nexport function requestFailure(err: unknown, signal: AbortSignal | undefined, target: string): ContentKitError {\n const code = transportFailure(err);\n if (code !== \"server_unavailable\" && signal?.aborted) return aborted(signal);\n return code === \"server_unavailable\"\n ? new ContentKitError(code, `${target} did not respond`, { cause: err })\n : new ContentKitError(\"network\", `${target} unreachable`, { cause: err });\n}\n\n// A gateway answered for ContentKit: down, restarting or timed out (52x: Cloudflare).\nconst GATEWAY_STATUS = new Set([502, 503, 504, 520, 521, 522, 523, 524]);\n\n// fetch rejects with a TypeError when no server answers (offline, DNS,\n// connection refused, CORS); engines word it differently.\nconst FETCH_FAILURE = /fetch|network|load failed|connection/i;\n\n/**\n * The client code of a request no server answered (mirrors auth-ui's and\n * billing-ui's): network when none was reached, server_unavailable when a\n * gateway or timeout answered. Recognizes the sibling SDKs' codes too.\n */\nexport function transportFailure(error: unknown): \"network\" | \"server_unavailable\" | undefined {\n if (error instanceof TypeError) {\n const offline = globalThis.navigator?.onLine === false;\n return offline || FETCH_FAILURE.test(error.message) ? \"network\" : undefined;\n }\n if (!error || typeof error !== \"object\") return undefined;\n const { name, code, status } = error as { name?: unknown; code?: unknown; status?: unknown };\n if (name === \"TimeoutError\") return \"server_unavailable\";\n if (code === \"network\" || code === \"network_error\") return \"network\";\n if (code === \"server_unavailable\") return code;\n if (code === undefined || code === \"unknown_error\" || code === \"server_error\")\n return typeof status === \"number\" && GATEWAY_STATUS.has(status) ? \"server_unavailable\" : undefined;\n return undefined;\n}\n\nexport function aborted(signal?: AbortSignal): ContentKitError {\n return new ContentKitError(\"aborted\", \"request canceled\", { cause: signal?.reason });\n}\n\nexport function throwIfAborted(signal?: AbortSignal): void {\n if (signal?.aborted) throw aborted(signal);\n}\n\nconst byStatus: Record<number, ContentKitErrorCode> = {\n 401: \"unauthorized\",\n 403: \"forbidden\",\n 404: \"not_found\",\n 409: \"conflict\",\n 410: \"gone\",\n 413: \"too_large\",\n 415: \"type_not_allowed\",\n 429: \"rate_limited\",\n 501: \"not_configured\",\n 503: \"unavailable\",\n};\n\nconst known = new Set<string>(ERROR_CODES);\n\n/** Reads a response that is not 2xx. */\nexport async function readContentKitError(res: Response): Promise<ContentKitError> {\n let body: Partial<ErrorReply> = {};\n try {\n body = (await res.json()) as Partial<ErrorReply>;\n } catch {\n // not JSON (a proxy error page)\n }\n const header = Number(res.headers.get(\"Retry-After\"));\n const retryAfter = body.retry_after ?? (Number.isFinite(header) && header > 0 ? header : undefined);\n const code =\n body.code && known.has(body.code)\n ? (body.code as ContentKitErrorCode)\n : !body.code && GATEWAY_STATUS.has(res.status)\n ? \"server_unavailable\"\n : (byStatus[res.status] ?? (res.status >= 500 ? \"internal_error\" : \"invalid_request\"));\n return new ContentKitError(code, body.error ?? `HTTP ${res.status}`, {\n status: res.status,\n retryAfter,\n blobs: body.blobs,\n details: body.details,\n ban: body.ban,\n action: body.action,\n reason: body.reason,\n availableAt: body.available_at,\n unknownCode: body.code && !known.has(body.code) ? body.code : undefined,\n });\n}\n\n/** An upload's recorded processing failure: its typed refusal, else a processing fault. */\nexport function failureError(f: Failure): ContentKitError {\n const code = f.code && known.has(f.code) ? (f.code as ContentKitErrorCode) : \"internal_error\";\n return new ContentKitError(code, f.message, { details: f.details });\n}\n"],"mappings":";;AAUA,IAAa,IAAqB;CAAC;CAAW;CAAsB;CAAW;CAAW;CAAmB;CAAU;AAAgB,GAK1H,IAA8C,CAAC,GAAI,OAAO,KAAK,CAAsB,GAAmB,GAAG,CAAkB,GAc7H,IAAb,cAAqC,MAAM;CAiB9B;CAhBX,OAAyB;CAEzB;CACA;CACA;CACA;CACA;CACA;CAEA;CAEA;CAEA;CAEA,YACE,GACA,GACA,IAA4B,CAAC,GAC7B;EAUA,AATA,MAAM,GAAS,EAAK,UAAU,KAAA,IAAY,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CAOzF,OAAO,IAAI,EALT,EAAK,QAAQ,EAAM,IAAI,EAAK,IAAI,IAC3B,EAAK,OACN,CAAC,EAAK,QAAQ,EAAe,IAAI,EAAI,MAAM,IACzC,uBACC,EAAS,EAAI,YAAY,EAAI,UAAU,MAAM,mBAAmB,oBACxC,EAAK,SAAS,QAAQ,EAAI,UAAU;EACnE,QAAQ,EAAI;EACZ;EACA,OAAO,EAAK;EACZ,SAAS,EAAK;EACd,KAAK,EAAK;EACV,QAAQ,EAAK;EACb,QAAQ,EAAK;EACb,aAAa,EAAK;EAClB,aAAa,EAAK,QAAQ,CAAC,EAAM,IAAI,EAAK,IAAI,IAAI,EAAK,OAAO,KAAA;CAChE,CAAC;AACH;AAGA,SAAgB,EAAa,GAA6B;CAExD,OAAO,IAAI,EADE,EAAE,QAAQ,EAAM,IAAI,EAAE,IAAI,IAAK,EAAE,OAA+B,kBAC5C,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;AACpE"}
|
|
@@ -1038,7 +1038,7 @@ export declare const CONTENTKIT_ROUTES: readonly [{
|
|
|
1038
1038
|
readonly auth: "public";
|
|
1039
1039
|
readonly permission: null;
|
|
1040
1040
|
readonly query: readonly [];
|
|
1041
|
-
readonly request: "
|
|
1041
|
+
readonly request: "BodyImageInput";
|
|
1042
1042
|
readonly responses: {
|
|
1043
1043
|
readonly 200: "InlineImage";
|
|
1044
1044
|
};
|