@ciridae/artifacts-react 0.0.0-stage → 0.1.0-nightly.0.bootstrap
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 +20 -2
- package/dist/ArtifactFrame.d.ts +18 -0
- package/dist/ArtifactFrame.js +16 -0
- package/dist/artifactReference.d.ts +17 -0
- package/dist/artifactReference.js +8 -0
- package/dist/artifactSource.d.ts +46 -0
- package/dist/artifactSource.js +1 -0
- package/dist/artifactsSettings.d.ts +13 -0
- package/dist/artifactsSettings.js +28 -0
- package/dist/buildArtifactFrameDocument.d.ts +22 -0
- package/dist/buildArtifactFrameDocument.js +44 -0
- package/dist/entries/index.d.ts +6 -0
- package/dist/entries/index.js +4 -0
- package/dist/followArtifactSource.d.ts +16 -0
- package/dist/followArtifactSource.js +69 -0
- package/dist/generated/index.d.ts +1 -0
- package/dist/generated/index.js +2 -0
- package/dist/generated/types.gen.d.ts +635 -0
- package/dist/generated/types.gen.js +2 -0
- package/dist/parseServedArtifactSource.d.ts +15 -0
- package/dist/parseServedArtifactSource.js +69 -0
- package/dist/readArtifactSource.d.ts +18 -0
- package/dist/readArtifactSource.js +62 -0
- package/dist/useArtifactSource.d.ts +7 -0
- package/dist/useArtifactSource.js +24 -0
- package/package.json +40 -5
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ciridae/artifacts-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
React hook and sandboxed frame for Ciridae artifacts: an artifact's live or pinned source, shown as a page that cannot reach the app or the network.
|
|
4
|
+
|
|
5
|
+
Install from npm:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @ciridae/artifacts-react
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Use the published package for new and updated consumers.
|
|
12
|
+
|
|
13
|
+
Configure the package once, then read an artifact and draw its frame:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { ArtifactFrame, configureArtifacts, useArtifactSource } from "@ciridae/artifacts-react";
|
|
17
|
+
|
|
18
|
+
configureArtifacts({ routePrefix: "https://api.example.com/artifacts", getAuthHeaders });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The full guide is `packages/artifacts-react/README.md` in the Ciridae monorepo.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ShownArtifactSource } from "./artifactSource.js";
|
|
2
|
+
import { type ArtifactFrameColorScheme } from "./buildArtifactFrameDocument.js";
|
|
3
|
+
export interface ArtifactFrameProps {
|
|
4
|
+
shown: ShownArtifactSource;
|
|
5
|
+
/** The scheme the app is showing. Changing it starts the page again in the new scheme. */
|
|
6
|
+
colorScheme: ArtifactFrameColorScheme;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Draws a shown source as a page in a sandboxed frame that fills its container. The page's
|
|
10
|
+
* scripts run in an opaque origin: they cannot read the app, its storage or its cookies, open
|
|
11
|
+
* windows, or navigate anything, and the page's policy refuses every network request.
|
|
12
|
+
* `buildArtifactFrameDocument` says how.
|
|
13
|
+
*
|
|
14
|
+
* A new source version or color scheme mounts a new frame, so the page starts again. Changing
|
|
15
|
+
* `srcdoc` on a mounted frame would add an entry to the tab's history, and Back would then step
|
|
16
|
+
* through old versions of the page.
|
|
17
|
+
*/
|
|
18
|
+
export declare function ArtifactFrame({ shown, colorScheme }: ArtifactFrameProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { buildArtifactFrameDocument, } from "./buildArtifactFrameDocument.js";
|
|
3
|
+
/**
|
|
4
|
+
* Draws a shown source as a page in a sandboxed frame that fills its container. The page's
|
|
5
|
+
* scripts run in an opaque origin: they cannot read the app, its storage or its cookies, open
|
|
6
|
+
* windows, or navigate anything, and the page's policy refuses every network request.
|
|
7
|
+
* `buildArtifactFrameDocument` says how.
|
|
8
|
+
*
|
|
9
|
+
* A new source version or color scheme mounts a new frame, so the page starts again. Changing
|
|
10
|
+
* `srcdoc` on a mounted frame would add an entry to the tab's history, and Back would then step
|
|
11
|
+
* through old versions of the page.
|
|
12
|
+
*/
|
|
13
|
+
export function ArtifactFrame({ shown, colorScheme }) {
|
|
14
|
+
const frameDocument = buildArtifactFrameDocument({ source: shown.source, colorScheme });
|
|
15
|
+
return (_jsx("iframe", { title: shown.title, sandbox: "allow-scripts", referrerPolicy: "no-referrer", srcDoc: frameDocument, style: { display: "block", width: "100%", height: "100%", border: 0 } }, frameDocument));
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** An artifact's id, as the backend issues it: a UUID. Produced by `isArtifactId` or a served source. */
|
|
2
|
+
export type ArtifactId = string & {
|
|
3
|
+
readonly brand: "ArtifactId";
|
|
4
|
+
};
|
|
5
|
+
/** One published version of an artifact's source, counted from 1. Produced by `isSourceVersionNumber` or a served source. */
|
|
6
|
+
export type SourceVersionNumber = number & {
|
|
7
|
+
readonly brand: "SourceVersionNumber";
|
|
8
|
+
};
|
|
9
|
+
/** One source version of one artifact. It never moves to a newer version. */
|
|
10
|
+
export interface PinnedArtifactReference {
|
|
11
|
+
artifactId: ArtifactId;
|
|
12
|
+
sourceVersion: SourceVersionNumber;
|
|
13
|
+
}
|
|
14
|
+
/** An artifact id follows the artifact's live source; a pinned reference shows that version only. */
|
|
15
|
+
export type ArtifactReference = ArtifactId | PinnedArtifactReference;
|
|
16
|
+
export declare function isArtifactId(text: string): text is ArtifactId;
|
|
17
|
+
export declare function isSourceVersionNumber(value: number): value is SourceVersionNumber;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const UUID_TEXT = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
|
|
2
|
+
const LARGEST_SOURCE_VERSION_NUMBER = 2147483647;
|
|
3
|
+
export function isArtifactId(text) {
|
|
4
|
+
return UUID_TEXT.test(text);
|
|
5
|
+
}
|
|
6
|
+
export function isSourceVersionNumber(value) {
|
|
7
|
+
return Number.isInteger(value) && value >= 1 && value <= LARGEST_SOURCE_VERSION_NUMBER;
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { PinnedArtifactReference } from "./artifactReference.js";
|
|
2
|
+
/** What `useArtifactSource` shows for one reference. */
|
|
3
|
+
export type ArtifactSource = {
|
|
4
|
+
type: "opening";
|
|
5
|
+
}
|
|
6
|
+
/** No such artifact or version, or the person may not read it: the backend does not say which. */
|
|
7
|
+
| {
|
|
8
|
+
type: "not_found";
|
|
9
|
+
} | {
|
|
10
|
+
type: "failed";
|
|
11
|
+
failure: ArtifactReadFailure;
|
|
12
|
+
} | ShownArtifactSource;
|
|
13
|
+
export interface ShownArtifactSource {
|
|
14
|
+
type: "shown";
|
|
15
|
+
title: string;
|
|
16
|
+
/** The page's HTML, as the agent wrote it. `ArtifactFrame` draws it. */
|
|
17
|
+
source: string;
|
|
18
|
+
archiveState: ArtifactArchiveState;
|
|
19
|
+
/** The version served: the newest one for a live reference, the pinned one otherwise. */
|
|
20
|
+
sourceVersionReference: PinnedArtifactReference;
|
|
21
|
+
/** Whether the latest read reached the backend; a failed read keeps the last source shown. */
|
|
22
|
+
lastRead: {
|
|
23
|
+
type: "succeeded";
|
|
24
|
+
} | {
|
|
25
|
+
type: "failed";
|
|
26
|
+
failure: ArtifactReadFailure;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export type ArtifactArchiveState = {
|
|
30
|
+
type: "active";
|
|
31
|
+
} | {
|
|
32
|
+
type: "archived";
|
|
33
|
+
archivedAt: string;
|
|
34
|
+
};
|
|
35
|
+
export type ArtifactReadFailure = {
|
|
36
|
+
type: "auth_headers_failed";
|
|
37
|
+
cause: unknown;
|
|
38
|
+
} | {
|
|
39
|
+
type: "no_answer";
|
|
40
|
+
cause: unknown;
|
|
41
|
+
} | {
|
|
42
|
+
type: "answered_with_status";
|
|
43
|
+
status: number;
|
|
44
|
+
} | {
|
|
45
|
+
type: "unreadable_answer";
|
|
46
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** How the package reaches the host's backend. The host owns the URL and the authentication. */
|
|
2
|
+
export interface ArtifactsSettings {
|
|
3
|
+
/** Where the backend mounted the artifact routes, for example `https://api.example.com/artifacts`. */
|
|
4
|
+
routePrefix: string;
|
|
5
|
+
/** Headers that authenticate the person on each request, such as a bearer token. */
|
|
6
|
+
getAuthHeaders: () => Promise<Record<string, string>>;
|
|
7
|
+
}
|
|
8
|
+
export declare class ArtifactsNotConfiguredError extends Error {
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
/** Configure the package once, at app start, before any artifact is shown. */
|
|
12
|
+
export declare function configureArtifacts(settings: ArtifactsSettings): void;
|
|
13
|
+
export declare function readArtifactsSettings(): ArtifactsSettings;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export class ArtifactsNotConfiguredError extends Error {
|
|
2
|
+
constructor() {
|
|
3
|
+
super("Call configureArtifacts(...) before showing an artifact");
|
|
4
|
+
this.name = "ArtifactsNotConfiguredError";
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
let configuredArtifactsSettings = { type: "not_configured" };
|
|
8
|
+
/** Configure the package once, at app start, before any artifact is shown. */
|
|
9
|
+
export function configureArtifacts(settings) {
|
|
10
|
+
configuredArtifactsSettings = {
|
|
11
|
+
type: "configured",
|
|
12
|
+
settings: {
|
|
13
|
+
routePrefix: removeTrailingSlashes(settings.routePrefix),
|
|
14
|
+
getAuthHeaders: settings.getAuthHeaders,
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function readArtifactsSettings() {
|
|
19
|
+
if (configuredArtifactsSettings.type === "not_configured")
|
|
20
|
+
throw new ArtifactsNotConfiguredError();
|
|
21
|
+
return configuredArtifactsSettings.settings;
|
|
22
|
+
}
|
|
23
|
+
function removeTrailingSlashes(routePrefix) {
|
|
24
|
+
let end = routePrefix.length;
|
|
25
|
+
while (end > 0 && routePrefix[end - 1] === "/")
|
|
26
|
+
end--;
|
|
27
|
+
return routePrefix.slice(0, end);
|
|
28
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a framed document may load: its own inline scripts and styles, and images and fonts
|
|
3
|
+
* written into it as `data:` (or images it draws into `blob:`). Every request to a server, nested
|
|
4
|
+
* frame address, form submission and `<base>` address is refused. `form-action` and `base-uri`
|
|
5
|
+
* are named because they do not fall back to `default-src`.
|
|
6
|
+
*/
|
|
7
|
+
export declare const ARTIFACT_FRAME_CONTENT_SECURITY_POLICY = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; font-src data:; form-action 'none'; base-uri 'none'";
|
|
8
|
+
/** The app's light or dark scheme, which the app passes because a framed document cannot read it. */
|
|
9
|
+
export type ArtifactFrameColorScheme = "light" | "dark";
|
|
10
|
+
/**
|
|
11
|
+
* The document of the frame the app mounts: a holder that contains only the page's own frame.
|
|
12
|
+
*
|
|
13
|
+
* A browser checks a frame's navigation against the policy of the frame's parent document. The
|
|
14
|
+
* app's document usually has no such policy, so a page framed directly in the app could send
|
|
15
|
+
* out anything it holds by navigating itself to another address. The holder is a parent the
|
|
16
|
+
* package wrote, whose policy names no frame address, so the browser refuses every navigation
|
|
17
|
+
* of the page's frame; the sandbox stops the page from navigating the holder or the app.
|
|
18
|
+
*/
|
|
19
|
+
export declare function buildArtifactFrameDocument(page: {
|
|
20
|
+
source: string;
|
|
21
|
+
colorScheme: ArtifactFrameColorScheme;
|
|
22
|
+
}): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a framed document may load: its own inline scripts and styles, and images and fonts
|
|
3
|
+
* written into it as `data:` (or images it draws into `blob:`). Every request to a server, nested
|
|
4
|
+
* frame address, form submission and `<base>` address is refused. `form-action` and `base-uri`
|
|
5
|
+
* are named because they do not fall back to `default-src`.
|
|
6
|
+
*/
|
|
7
|
+
export const ARTIFACT_FRAME_CONTENT_SECURITY_POLICY = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; img-src data: blob:; font-src data:; form-action 'none'; base-uri 'none'";
|
|
8
|
+
/** First in each document, so the parser applies the policy before anything after it runs or loads. */
|
|
9
|
+
const POLICY_HEAD = `<meta http-equiv="Content-Security-Policy" content="${ARTIFACT_FRAME_CONTENT_SECURITY_POLICY}"><meta name="referrer" content="no-referrer">`;
|
|
10
|
+
/**
|
|
11
|
+
* The sandbox refuses a new window, so a link the person clicks does nothing. Without this,
|
|
12
|
+
* Chromium replaces the page with its blocked-content page when a link's navigation is refused.
|
|
13
|
+
*/
|
|
14
|
+
const LINKS_OPEN_A_NEW_WINDOW = `<base target="_blank">`;
|
|
15
|
+
const HOLDER_STYLE = `<style>html,body{margin:0;height:100%;overflow:hidden}iframe{display:block;width:100%;height:100%;border:0}</style>`;
|
|
16
|
+
/**
|
|
17
|
+
* The document of the frame the app mounts: a holder that contains only the page's own frame.
|
|
18
|
+
*
|
|
19
|
+
* A browser checks a frame's navigation against the policy of the frame's parent document. The
|
|
20
|
+
* app's document usually has no such policy, so a page framed directly in the app could send
|
|
21
|
+
* out anything it holds by navigating itself to another address. The holder is a parent the
|
|
22
|
+
* package wrote, whose policy names no frame address, so the browser refuses every navigation
|
|
23
|
+
* of the page's frame; the sandbox stops the page from navigating the holder or the app.
|
|
24
|
+
*/
|
|
25
|
+
export function buildArtifactFrameDocument(page) {
|
|
26
|
+
const head = `${POLICY_HEAD}${colorSchemeRule(page.colorScheme)}`;
|
|
27
|
+
const pageDocument = `${head}${LINKS_OPEN_A_NEW_WINDOW}${page.source}`;
|
|
28
|
+
return `${head}${HOLDER_STYLE}<iframe title="Page" sandbox="allow-scripts" referrerpolicy="no-referrer" srcdoc="${escapeAttributeValue(pageDocument)}"></iframe>`;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gives a document the app's scheme: an unstyled page gets that scheme's background and text
|
|
32
|
+
* colors, and `light-dark()` in the page's styles answers with it. Only Firefox passes the
|
|
33
|
+
* framing element's scheme into a sandboxed frame by itself; Chromium and WebKit give the page
|
|
34
|
+
* the browser's own preference, which is why `prefers-color-scheme` in a page cannot be trusted.
|
|
35
|
+
*
|
|
36
|
+
* It is an `!important` rule because agents often write `color-scheme: light dark` into a page,
|
|
37
|
+
* as a rule or a meta tag, and either would hand the choice back to the browser's preference.
|
|
38
|
+
*/
|
|
39
|
+
function colorSchemeRule(colorScheme) {
|
|
40
|
+
return `<style>:root{color-scheme:${colorScheme} !important}</style>`;
|
|
41
|
+
}
|
|
42
|
+
function escapeAttributeValue(text) {
|
|
43
|
+
return text.replaceAll("&", "&").replaceAll('"', """);
|
|
44
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { configureArtifacts, ArtifactsNotConfiguredError, type ArtifactsSettings, } from "../artifactsSettings.js";
|
|
2
|
+
export { isArtifactId, isSourceVersionNumber, type ArtifactId, type ArtifactReference, type PinnedArtifactReference, type SourceVersionNumber, } from "../artifactReference.js";
|
|
3
|
+
export type { ArtifactArchiveState, ArtifactReadFailure, ArtifactSource, ShownArtifactSource, } from "../artifactSource.js";
|
|
4
|
+
export { useArtifactSource } from "../useArtifactSource.js";
|
|
5
|
+
export { ArtifactFrame, type ArtifactFrameProps } from "../ArtifactFrame.js";
|
|
6
|
+
export type { ArtifactFrameColorScheme } from "../buildArtifactFrameDocument.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { configureArtifacts, ArtifactsNotConfiguredError, } from "../artifactsSettings.js";
|
|
2
|
+
export { isArtifactId, isSourceVersionNumber, } from "../artifactReference.js";
|
|
3
|
+
export { useArtifactSource } from "../useArtifactSource.js";
|
|
4
|
+
export { ArtifactFrame } from "../ArtifactFrame.js";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ArtifactReference } from "./artifactReference.js";
|
|
2
|
+
import type { ArtifactSource } from "./artifactSource.js";
|
|
3
|
+
export declare const REREAD_WHILE_VISIBLE_MS = 60000;
|
|
4
|
+
export declare const OPENING_ARTIFACT_SOURCE: {
|
|
5
|
+
readonly type: "opening";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Reads the reference at once, again when the window gains focus or the tab becomes visible, and
|
|
9
|
+
* every `REREAD_WHILE_VISIBLE_MS` while it is visible. One read runs at a time, and a request
|
|
10
|
+
* during a read is dropped, so returning to a tab reads once. A live reference moves to each
|
|
11
|
+
* newer version served; a pinned one always reads its own version. Returns the function that
|
|
12
|
+
* stops following.
|
|
13
|
+
*
|
|
14
|
+
* Throws `ArtifactsNotConfiguredError` when `configureArtifacts` has not run.
|
|
15
|
+
*/
|
|
16
|
+
export declare function followArtifactSource(reference: ArtifactReference, onChange: (source: ArtifactSource) => void): () => void;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { readArtifactsSettings } from "./artifactsSettings.js";
|
|
2
|
+
import { readArtifactSource } from "./readArtifactSource.js";
|
|
3
|
+
export const REREAD_WHILE_VISIBLE_MS = 60000;
|
|
4
|
+
export const OPENING_ARTIFACT_SOURCE = { type: "opening" };
|
|
5
|
+
/**
|
|
6
|
+
* Reads the reference at once, again when the window gains focus or the tab becomes visible, and
|
|
7
|
+
* every `REREAD_WHILE_VISIBLE_MS` while it is visible. One read runs at a time, and a request
|
|
8
|
+
* during a read is dropped, so returning to a tab reads once. A live reference moves to each
|
|
9
|
+
* newer version served; a pinned one always reads its own version. Returns the function that
|
|
10
|
+
* stops following.
|
|
11
|
+
*
|
|
12
|
+
* Throws `ArtifactsNotConfiguredError` when `configureArtifacts` has not run.
|
|
13
|
+
*/
|
|
14
|
+
export function followArtifactSource(reference, onChange) {
|
|
15
|
+
const settings = readArtifactsSettings();
|
|
16
|
+
let shown = OPENING_ARTIFACT_SOURCE;
|
|
17
|
+
let following = true;
|
|
18
|
+
let readInFlight = false;
|
|
19
|
+
let nextReadTimer;
|
|
20
|
+
const stopReading = new AbortController();
|
|
21
|
+
function readNow() {
|
|
22
|
+
if (!following || readInFlight)
|
|
23
|
+
return;
|
|
24
|
+
clearTimeout(nextReadTimer);
|
|
25
|
+
readInFlight = true;
|
|
26
|
+
void readArtifactSource(settings, reference, stopReading.signal).then((outcome) => {
|
|
27
|
+
readInFlight = false;
|
|
28
|
+
if (!following)
|
|
29
|
+
return;
|
|
30
|
+
shown = applyReadOutcome(shown, outcome);
|
|
31
|
+
onChange(shown);
|
|
32
|
+
scheduleNextRead();
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function scheduleNextRead() {
|
|
36
|
+
clearTimeout(nextReadTimer);
|
|
37
|
+
if (document.visibilityState === "hidden")
|
|
38
|
+
return;
|
|
39
|
+
nextReadTimer = setTimeout(readNow, REREAD_WHILE_VISIBLE_MS);
|
|
40
|
+
}
|
|
41
|
+
function onVisibilityChange() {
|
|
42
|
+
if (document.visibilityState === "hidden")
|
|
43
|
+
clearTimeout(nextReadTimer);
|
|
44
|
+
else
|
|
45
|
+
readNow();
|
|
46
|
+
}
|
|
47
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
48
|
+
window.addEventListener("focus", readNow);
|
|
49
|
+
readNow();
|
|
50
|
+
return () => {
|
|
51
|
+
following = false;
|
|
52
|
+
clearTimeout(nextReadTimer);
|
|
53
|
+
stopReading.abort();
|
|
54
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
55
|
+
window.removeEventListener("focus", readNow);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function applyReadOutcome(shown, outcome) {
|
|
59
|
+
switch (outcome.type) {
|
|
60
|
+
case "served":
|
|
61
|
+
return { type: "shown", ...outcome.served, lastRead: { type: "succeeded" } };
|
|
62
|
+
case "not_found":
|
|
63
|
+
return { type: "not_found" };
|
|
64
|
+
case "failed":
|
|
65
|
+
return shown.type === "shown"
|
|
66
|
+
? { ...shown, lastRead: { type: "failed", failure: outcome.failure } }
|
|
67
|
+
: { type: "failed", failure: outcome.failure };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { AccountReference, AgentActingForAccount, ArchiveArtifactData, ArchiveArtifactError, ArchiveArtifactErrors, ArchiveArtifactResponse, ArchiveArtifactResponses, ArtifactActive, ArtifactAlreadyExistsForOwnerKey, ArtifactArchived, ArtifactArchiveState, ArtifactCaller, ArtifactKeyText, ArtifactsCursor, ArtifactsNextPage, ArtifactSourceText, ArtifactSourceVersionReference, ArtifactsPageAfter, ArtifactTitleSubstring, ArtifactTitleText, AuthRoleKeyText, ClientOptions, ExpectedSourceVersionDoesNotMatch, FindArtifactIdByOwnerAndKeyData, FindArtifactIdByOwnerAndKeyError, FindArtifactIdByOwnerAndKeyErrors, FindArtifactIdByOwnerAndKeyResponse, FindArtifactIdByOwnerAndKeyResponses, FoundArtifactId, HttpValidationError, ListArtifactsData, ListArtifactsError, ListArtifactsErrors, ListArtifactSourceVersionsData, ListArtifactSourceVersionsError, ListArtifactSourceVersionsErrors, ListArtifactSourceVersionsResponse, ListArtifactSourceVersionsResponses, ListArtifactsResponse, ListArtifactsResponses, ListedArtifact, ListedArtifactSourceVersion, ListedArtifactSourceVersionsPage, ListedArtifactsPage, NoKey, NoMoreArtifactsPages, PersonCaller, PublishArtifactSourceRevisionData, PublishArtifactSourceRevisionError, PublishArtifactSourceRevisionErrors, PublishArtifactSourceRevisionResponse, PublishArtifactSourceRevisionResponses, PublishFirstArtifactSourceVersionData, PublishFirstArtifactSourceVersionError, PublishFirstArtifactSourceVersionErrors, PublishFirstArtifactSourceVersionResponse, PublishFirstArtifactSourceVersionResponses, PublishFirstSourceVersionRequestBody, PublishRevisionRequestBody, ReadArtifactSourceData, ReadArtifactSourceError, ReadArtifactSourceErrors, ReadArtifactSourceResponse, ReadArtifactSourceResponses, RenameArtifactData, RenameArtifactError, RenameArtifactErrors, RenameArtifactResponse, RenameArtifactResponses, RenameRequestBody, ServedArtifactSource, SourceVersionPublished, StorableArtifactSourceVersionNumber, TrustedAppBackend, UnarchiveArtifactData, UnarchiveArtifactError, UnarchiveArtifactErrors, UnarchiveArtifactResponse, UnarchiveArtifactResponses, ValidationError, } from "./types.gen.js";
|
|
@@ -0,0 +1,635 @@
|
|
|
1
|
+
export type ClientOptions = {
|
|
2
|
+
baseUrl: `${string}://artifacts_routes_openapi.json` | (string & {});
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* UserAccount
|
|
6
|
+
*
|
|
7
|
+
* The account of a person, by their Auth user id.
|
|
8
|
+
*/
|
|
9
|
+
export type AccountReference = {
|
|
10
|
+
/**
|
|
11
|
+
* Type
|
|
12
|
+
*/
|
|
13
|
+
type: "user";
|
|
14
|
+
/**
|
|
15
|
+
* User Id
|
|
16
|
+
*
|
|
17
|
+
* The user's Auth user id.
|
|
18
|
+
*/
|
|
19
|
+
user_id: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* AgentActingForAccount
|
|
23
|
+
*
|
|
24
|
+
* An agent instance working with the rights of the account it acts for and that account's Auth role; the host verifies every field.
|
|
25
|
+
*/
|
|
26
|
+
export type AgentActingForAccount = {
|
|
27
|
+
acting_account: AccountReference;
|
|
28
|
+
acting_account_role_key: AuthRoleKeyText;
|
|
29
|
+
/**
|
|
30
|
+
* Agent Definition Id
|
|
31
|
+
*/
|
|
32
|
+
agent_definition_id: string;
|
|
33
|
+
/**
|
|
34
|
+
* Agent Instance Id
|
|
35
|
+
*/
|
|
36
|
+
agent_instance_id: string;
|
|
37
|
+
/**
|
|
38
|
+
* Type
|
|
39
|
+
*/
|
|
40
|
+
type: "agent_acting_for_account";
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* ArtifactActive
|
|
44
|
+
*
|
|
45
|
+
* The artifact is in the lists and takes new source versions, titles, access grants and revocations.
|
|
46
|
+
*/
|
|
47
|
+
export type ArtifactActive = {
|
|
48
|
+
/**
|
|
49
|
+
* Type
|
|
50
|
+
*/
|
|
51
|
+
type: "active";
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* ArtifactAlreadyExistsForOwnerKey
|
|
55
|
+
*
|
|
56
|
+
* The owner already has an artifact under this key; it was left alone and nothing was written.
|
|
57
|
+
*/
|
|
58
|
+
export type ArtifactAlreadyExistsForOwnerKey = {
|
|
59
|
+
/**
|
|
60
|
+
* Artifact Definition Id
|
|
61
|
+
*/
|
|
62
|
+
artifact_definition_id: string;
|
|
63
|
+
/**
|
|
64
|
+
* Artifact Id
|
|
65
|
+
*/
|
|
66
|
+
artifact_id: string;
|
|
67
|
+
/**
|
|
68
|
+
* Type
|
|
69
|
+
*/
|
|
70
|
+
type: "artifact_already_exists_for_owner_key";
|
|
71
|
+
};
|
|
72
|
+
export type ArtifactArchiveState = ({
|
|
73
|
+
type: "active";
|
|
74
|
+
} & ArtifactActive) | ({
|
|
75
|
+
type: "archived";
|
|
76
|
+
} & ArtifactArchived);
|
|
77
|
+
/**
|
|
78
|
+
* ArtifactArchived
|
|
79
|
+
*
|
|
80
|
+
* The artifact has left the default list and takes no new source version, title, access grant or revocation.
|
|
81
|
+
*
|
|
82
|
+
* Whoever may view it still reads it by its id, and unarchiving restores
|
|
83
|
+
* everything, because nothing was removed.
|
|
84
|
+
*/
|
|
85
|
+
export type ArtifactArchived = {
|
|
86
|
+
/**
|
|
87
|
+
* Archived At
|
|
88
|
+
*/
|
|
89
|
+
archived_at: string;
|
|
90
|
+
/**
|
|
91
|
+
* Type
|
|
92
|
+
*/
|
|
93
|
+
type: "archived";
|
|
94
|
+
};
|
|
95
|
+
export type ArtifactCaller = ({
|
|
96
|
+
type: "person";
|
|
97
|
+
} & PersonCaller) | ({
|
|
98
|
+
type: "agent_acting_for_account";
|
|
99
|
+
} & AgentActingForAccount) | ({
|
|
100
|
+
type: "trusted_app_backend";
|
|
101
|
+
} & TrustedAppBackend);
|
|
102
|
+
export type ArtifactKeyText = string;
|
|
103
|
+
export type ArtifactSourceText = string;
|
|
104
|
+
/**
|
|
105
|
+
* ArtifactSourceVersionReference
|
|
106
|
+
*
|
|
107
|
+
* The address of one published source version; a read returns it and a revision passes it back.
|
|
108
|
+
*/
|
|
109
|
+
export type ArtifactSourceVersionReference = {
|
|
110
|
+
/**
|
|
111
|
+
* Artifact Id
|
|
112
|
+
*/
|
|
113
|
+
artifact_id: string;
|
|
114
|
+
source_version: StorableArtifactSourceVersionNumber;
|
|
115
|
+
};
|
|
116
|
+
export type ArtifactTitleSubstring = string;
|
|
117
|
+
export type ArtifactTitleText = string;
|
|
118
|
+
export type ArtifactsCursor = string;
|
|
119
|
+
export type ArtifactsNextPage = ({
|
|
120
|
+
type: "page_after";
|
|
121
|
+
} & ArtifactsPageAfter) | ({
|
|
122
|
+
type: "no_more_pages";
|
|
123
|
+
} & NoMoreArtifactsPages);
|
|
124
|
+
/**
|
|
125
|
+
* ArtifactsPageAfter
|
|
126
|
+
*
|
|
127
|
+
* The page that follows the one whose `next_page` this was.
|
|
128
|
+
*/
|
|
129
|
+
export type ArtifactsPageAfter = {
|
|
130
|
+
after: ArtifactsCursor;
|
|
131
|
+
/**
|
|
132
|
+
* Type
|
|
133
|
+
*/
|
|
134
|
+
type: "page_after";
|
|
135
|
+
};
|
|
136
|
+
export type AuthRoleKeyText = string;
|
|
137
|
+
/**
|
|
138
|
+
* ExpectedSourceVersionDoesNotMatch
|
|
139
|
+
*
|
|
140
|
+
* The revision was built on a source version that is no longer live; nothing was written, and the caller reads the live one and merges.
|
|
141
|
+
*/
|
|
142
|
+
export type ExpectedSourceVersionDoesNotMatch = {
|
|
143
|
+
live_source_version_reference: ArtifactSourceVersionReference;
|
|
144
|
+
/**
|
|
145
|
+
* Type
|
|
146
|
+
*/
|
|
147
|
+
type: "expected_source_version_does_not_match";
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* FoundArtifactId
|
|
151
|
+
*
|
|
152
|
+
* The id of the artifact an owner has under a key.
|
|
153
|
+
*/
|
|
154
|
+
export type FoundArtifactId = {
|
|
155
|
+
/**
|
|
156
|
+
* Artifact Id
|
|
157
|
+
*/
|
|
158
|
+
artifact_id: string;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* HTTPValidationError
|
|
162
|
+
*/
|
|
163
|
+
export type HttpValidationError = {
|
|
164
|
+
/**
|
|
165
|
+
* Detail
|
|
166
|
+
*/
|
|
167
|
+
detail?: Array<ValidationError>;
|
|
168
|
+
};
|
|
169
|
+
/**
|
|
170
|
+
* ListedArtifact
|
|
171
|
+
*
|
|
172
|
+
* An artifact's row, current title, archive state and live source version.
|
|
173
|
+
*/
|
|
174
|
+
export type ListedArtifact = {
|
|
175
|
+
archive_state: ArtifactArchiveState;
|
|
176
|
+
/**
|
|
177
|
+
* Artifact Definition Id
|
|
178
|
+
*/
|
|
179
|
+
artifact_definition_id: string;
|
|
180
|
+
/**
|
|
181
|
+
* Artifact Id
|
|
182
|
+
*/
|
|
183
|
+
artifact_id: string;
|
|
184
|
+
/**
|
|
185
|
+
* Key Unique Per Owner
|
|
186
|
+
*/
|
|
187
|
+
key_unique_per_owner: ArtifactKeyText | NoKey;
|
|
188
|
+
live_source_version_reference: ArtifactSourceVersionReference;
|
|
189
|
+
owner: AccountReference;
|
|
190
|
+
title: ArtifactTitleText;
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* ListedArtifactSourceVersion
|
|
194
|
+
*
|
|
195
|
+
* Which source version, who published it and when.
|
|
196
|
+
*/
|
|
197
|
+
export type ListedArtifactSourceVersion = {
|
|
198
|
+
/**
|
|
199
|
+
* Published At
|
|
200
|
+
*/
|
|
201
|
+
published_at: string;
|
|
202
|
+
published_by: ArtifactCaller;
|
|
203
|
+
source_version_reference: ArtifactSourceVersionReference;
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* ListedArtifactSourceVersionsPage
|
|
207
|
+
*
|
|
208
|
+
* A page of `list_artifact_source_versions`, in its order.
|
|
209
|
+
*/
|
|
210
|
+
export type ListedArtifactSourceVersionsPage = {
|
|
211
|
+
/**
|
|
212
|
+
* Items
|
|
213
|
+
*/
|
|
214
|
+
items: Array<ListedArtifactSourceVersion>;
|
|
215
|
+
next_page: ArtifactsNextPage;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* ListedArtifactsPage
|
|
219
|
+
*
|
|
220
|
+
* A page of `list_artifacts`, in its order.
|
|
221
|
+
*/
|
|
222
|
+
export type ListedArtifactsPage = {
|
|
223
|
+
/**
|
|
224
|
+
* Items
|
|
225
|
+
*/
|
|
226
|
+
items: Array<ListedArtifact>;
|
|
227
|
+
next_page: ArtifactsNextPage;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* NoKey
|
|
231
|
+
*
|
|
232
|
+
* No key: the create makes a new agent instance every call (the default), and a definition lists it in `agent_key_types` to take such agents.
|
|
233
|
+
*/
|
|
234
|
+
export type NoKey = {
|
|
235
|
+
/**
|
|
236
|
+
* Type
|
|
237
|
+
*/
|
|
238
|
+
type: "no_key";
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* NoMoreArtifactsPages
|
|
242
|
+
*
|
|
243
|
+
* The page was the list's last.
|
|
244
|
+
*/
|
|
245
|
+
export type NoMoreArtifactsPages = {
|
|
246
|
+
/**
|
|
247
|
+
* Type
|
|
248
|
+
*/
|
|
249
|
+
type: "no_more_pages";
|
|
250
|
+
};
|
|
251
|
+
/**
|
|
252
|
+
* PersonCaller
|
|
253
|
+
*
|
|
254
|
+
* A signed-in person, whose account both supplies the rights and did the work, with their Auth role in the project.
|
|
255
|
+
*/
|
|
256
|
+
export type PersonCaller = {
|
|
257
|
+
acting_account: AccountReference;
|
|
258
|
+
acting_account_role_key: AuthRoleKeyText;
|
|
259
|
+
/**
|
|
260
|
+
* Type
|
|
261
|
+
*/
|
|
262
|
+
type: "person";
|
|
263
|
+
};
|
|
264
|
+
/**
|
|
265
|
+
* PublishFirstSourceVersionRequestBody
|
|
266
|
+
*
|
|
267
|
+
* `POST /artifacts`.
|
|
268
|
+
*/
|
|
269
|
+
export type PublishFirstSourceVersionRequestBody = {
|
|
270
|
+
/**
|
|
271
|
+
* Artifact Definition Id
|
|
272
|
+
*/
|
|
273
|
+
artifact_definition_id: string;
|
|
274
|
+
/**
|
|
275
|
+
* Key Unique Per Owner
|
|
276
|
+
*
|
|
277
|
+
* A key text names the owner's one artifact under it, across definitions; `{"type": "no_key"}` makes a new artifact for each new `publication_request_id`.
|
|
278
|
+
*/
|
|
279
|
+
key_unique_per_owner: ArtifactKeyText | NoKey;
|
|
280
|
+
owner: AccountReference;
|
|
281
|
+
/**
|
|
282
|
+
* Publication Request Id
|
|
283
|
+
*/
|
|
284
|
+
publication_request_id: string;
|
|
285
|
+
source: ArtifactSourceText;
|
|
286
|
+
title: ArtifactTitleText;
|
|
287
|
+
};
|
|
288
|
+
/**
|
|
289
|
+
* PublishRevisionRequestBody
|
|
290
|
+
*
|
|
291
|
+
* `POST /artifacts/{artifact_id}/source-versions`: the number of the source version the revision was built on.
|
|
292
|
+
*/
|
|
293
|
+
export type PublishRevisionRequestBody = {
|
|
294
|
+
expected_source_version: StorableArtifactSourceVersionNumber;
|
|
295
|
+
/**
|
|
296
|
+
* Publication Request Id
|
|
297
|
+
*/
|
|
298
|
+
publication_request_id: string;
|
|
299
|
+
source: ArtifactSourceText;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* RenameRequestBody
|
|
303
|
+
*
|
|
304
|
+
* `PATCH /artifacts/{artifact_id}/title`.
|
|
305
|
+
*/
|
|
306
|
+
export type RenameRequestBody = {
|
|
307
|
+
title: ArtifactTitleText;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* ServedArtifactSource
|
|
311
|
+
*
|
|
312
|
+
* One source version's source, the artifact's current title and archive state, and the reference a revision passes back.
|
|
313
|
+
*/
|
|
314
|
+
export type ServedArtifactSource = {
|
|
315
|
+
archive_state: ArtifactArchiveState;
|
|
316
|
+
source: ArtifactSourceText;
|
|
317
|
+
source_version_reference: ArtifactSourceVersionReference;
|
|
318
|
+
title: ArtifactTitleText;
|
|
319
|
+
};
|
|
320
|
+
/**
|
|
321
|
+
* SourceVersionPublished
|
|
322
|
+
*
|
|
323
|
+
* The source version is stored and live; a retry of the same request gets this same value back.
|
|
324
|
+
*/
|
|
325
|
+
export type SourceVersionPublished = {
|
|
326
|
+
source_version_reference: ArtifactSourceVersionReference;
|
|
327
|
+
/**
|
|
328
|
+
* Type
|
|
329
|
+
*/
|
|
330
|
+
type: "source_version_published";
|
|
331
|
+
};
|
|
332
|
+
export type StorableArtifactSourceVersionNumber = number;
|
|
333
|
+
/**
|
|
334
|
+
* TrustedAppBackend
|
|
335
|
+
*
|
|
336
|
+
* The app's own code: it has no acting account, names every owner explicitly and may use every artifact. No mounted route produces it.
|
|
337
|
+
*/
|
|
338
|
+
export type TrustedAppBackend = {
|
|
339
|
+
/**
|
|
340
|
+
* Type
|
|
341
|
+
*/
|
|
342
|
+
type: "trusted_app_backend";
|
|
343
|
+
};
|
|
344
|
+
/**
|
|
345
|
+
* ValidationError
|
|
346
|
+
*/
|
|
347
|
+
export type ValidationError = {
|
|
348
|
+
/**
|
|
349
|
+
* Context
|
|
350
|
+
*/
|
|
351
|
+
ctx?: {
|
|
352
|
+
[key: string]: unknown;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* Input
|
|
356
|
+
*/
|
|
357
|
+
input?: unknown;
|
|
358
|
+
/**
|
|
359
|
+
* Location
|
|
360
|
+
*/
|
|
361
|
+
loc: Array<string | number>;
|
|
362
|
+
/**
|
|
363
|
+
* Message
|
|
364
|
+
*/
|
|
365
|
+
msg: string;
|
|
366
|
+
/**
|
|
367
|
+
* Error Type
|
|
368
|
+
*/
|
|
369
|
+
type: string;
|
|
370
|
+
};
|
|
371
|
+
export type ListArtifactsData = {
|
|
372
|
+
body?: never;
|
|
373
|
+
path?: never;
|
|
374
|
+
query?: {
|
|
375
|
+
/**
|
|
376
|
+
* Artifact Definition Id
|
|
377
|
+
*/
|
|
378
|
+
artifact_definition_id?: string | null;
|
|
379
|
+
/**
|
|
380
|
+
* Owner User Id
|
|
381
|
+
*/
|
|
382
|
+
owner_user_id?: string | null;
|
|
383
|
+
/**
|
|
384
|
+
* Key
|
|
385
|
+
*/
|
|
386
|
+
key?: ArtifactKeyText | null;
|
|
387
|
+
/**
|
|
388
|
+
* Archive State
|
|
389
|
+
*/
|
|
390
|
+
archive_state?: "active" | "archived";
|
|
391
|
+
/**
|
|
392
|
+
* Title Contains
|
|
393
|
+
*/
|
|
394
|
+
title_contains?: ArtifactTitleSubstring | null;
|
|
395
|
+
/**
|
|
396
|
+
* After
|
|
397
|
+
*/
|
|
398
|
+
after?: ArtifactsCursor | null;
|
|
399
|
+
};
|
|
400
|
+
url: "/artifacts";
|
|
401
|
+
};
|
|
402
|
+
export type ListArtifactsErrors = {
|
|
403
|
+
/**
|
|
404
|
+
* Validation Error
|
|
405
|
+
*/
|
|
406
|
+
422: HttpValidationError;
|
|
407
|
+
};
|
|
408
|
+
export type ListArtifactsError = ListArtifactsErrors[keyof ListArtifactsErrors];
|
|
409
|
+
export type ListArtifactsResponses = {
|
|
410
|
+
/**
|
|
411
|
+
* Successful Response
|
|
412
|
+
*/
|
|
413
|
+
200: ListedArtifactsPage;
|
|
414
|
+
};
|
|
415
|
+
export type ListArtifactsResponse = ListArtifactsResponses[keyof ListArtifactsResponses];
|
|
416
|
+
export type PublishFirstArtifactSourceVersionData = {
|
|
417
|
+
body: PublishFirstSourceVersionRequestBody;
|
|
418
|
+
path?: never;
|
|
419
|
+
query?: never;
|
|
420
|
+
url: "/artifacts";
|
|
421
|
+
};
|
|
422
|
+
export type PublishFirstArtifactSourceVersionErrors = {
|
|
423
|
+
/**
|
|
424
|
+
* Validation Error
|
|
425
|
+
*/
|
|
426
|
+
422: HttpValidationError;
|
|
427
|
+
};
|
|
428
|
+
export type PublishFirstArtifactSourceVersionError = PublishFirstArtifactSourceVersionErrors[keyof PublishFirstArtifactSourceVersionErrors];
|
|
429
|
+
export type PublishFirstArtifactSourceVersionResponses = {
|
|
430
|
+
/**
|
|
431
|
+
* Response Publish First Artifact Source Version
|
|
432
|
+
*
|
|
433
|
+
* Successful Response
|
|
434
|
+
*/
|
|
435
|
+
200: ({
|
|
436
|
+
type: "source_version_published";
|
|
437
|
+
} & SourceVersionPublished) | ({
|
|
438
|
+
type: "artifact_already_exists_for_owner_key";
|
|
439
|
+
} & ArtifactAlreadyExistsForOwnerKey);
|
|
440
|
+
};
|
|
441
|
+
export type PublishFirstArtifactSourceVersionResponse = PublishFirstArtifactSourceVersionResponses[keyof PublishFirstArtifactSourceVersionResponses];
|
|
442
|
+
export type FindArtifactIdByOwnerAndKeyData = {
|
|
443
|
+
body?: never;
|
|
444
|
+
path?: never;
|
|
445
|
+
query: {
|
|
446
|
+
/**
|
|
447
|
+
* Owner User Id
|
|
448
|
+
*
|
|
449
|
+
* The user's Auth user id.
|
|
450
|
+
*/
|
|
451
|
+
owner_user_id: string;
|
|
452
|
+
key: ArtifactKeyText;
|
|
453
|
+
};
|
|
454
|
+
url: "/artifacts/by-owner-and-key";
|
|
455
|
+
};
|
|
456
|
+
export type FindArtifactIdByOwnerAndKeyErrors = {
|
|
457
|
+
/**
|
|
458
|
+
* Validation Error
|
|
459
|
+
*/
|
|
460
|
+
422: HttpValidationError;
|
|
461
|
+
};
|
|
462
|
+
export type FindArtifactIdByOwnerAndKeyError = FindArtifactIdByOwnerAndKeyErrors[keyof FindArtifactIdByOwnerAndKeyErrors];
|
|
463
|
+
export type FindArtifactIdByOwnerAndKeyResponses = {
|
|
464
|
+
/**
|
|
465
|
+
* Successful Response
|
|
466
|
+
*/
|
|
467
|
+
200: FoundArtifactId;
|
|
468
|
+
};
|
|
469
|
+
export type FindArtifactIdByOwnerAndKeyResponse = FindArtifactIdByOwnerAndKeyResponses[keyof FindArtifactIdByOwnerAndKeyResponses];
|
|
470
|
+
export type ReadArtifactSourceData = {
|
|
471
|
+
body?: never;
|
|
472
|
+
path: {
|
|
473
|
+
/**
|
|
474
|
+
* Artifact Id
|
|
475
|
+
*/
|
|
476
|
+
artifact_id: string;
|
|
477
|
+
};
|
|
478
|
+
query?: {
|
|
479
|
+
/**
|
|
480
|
+
* Source Version
|
|
481
|
+
*/
|
|
482
|
+
source_version?: number | null;
|
|
483
|
+
};
|
|
484
|
+
url: "/artifacts/{artifact_id}";
|
|
485
|
+
};
|
|
486
|
+
export type ReadArtifactSourceErrors = {
|
|
487
|
+
/**
|
|
488
|
+
* Validation Error
|
|
489
|
+
*/
|
|
490
|
+
422: HttpValidationError;
|
|
491
|
+
};
|
|
492
|
+
export type ReadArtifactSourceError = ReadArtifactSourceErrors[keyof ReadArtifactSourceErrors];
|
|
493
|
+
export type ReadArtifactSourceResponses = {
|
|
494
|
+
/**
|
|
495
|
+
* Successful Response
|
|
496
|
+
*/
|
|
497
|
+
200: ServedArtifactSource;
|
|
498
|
+
};
|
|
499
|
+
export type ReadArtifactSourceResponse = ReadArtifactSourceResponses[keyof ReadArtifactSourceResponses];
|
|
500
|
+
export type ArchiveArtifactData = {
|
|
501
|
+
body?: never;
|
|
502
|
+
path: {
|
|
503
|
+
/**
|
|
504
|
+
* Artifact Id
|
|
505
|
+
*/
|
|
506
|
+
artifact_id: string;
|
|
507
|
+
};
|
|
508
|
+
query?: never;
|
|
509
|
+
url: "/artifacts/{artifact_id}/archive";
|
|
510
|
+
};
|
|
511
|
+
export type ArchiveArtifactErrors = {
|
|
512
|
+
/**
|
|
513
|
+
* Validation Error
|
|
514
|
+
*/
|
|
515
|
+
422: HttpValidationError;
|
|
516
|
+
};
|
|
517
|
+
export type ArchiveArtifactError = ArchiveArtifactErrors[keyof ArchiveArtifactErrors];
|
|
518
|
+
export type ArchiveArtifactResponses = {
|
|
519
|
+
/**
|
|
520
|
+
* Successful Response
|
|
521
|
+
*/
|
|
522
|
+
200: ArtifactArchived;
|
|
523
|
+
};
|
|
524
|
+
export type ArchiveArtifactResponse = ArchiveArtifactResponses[keyof ArchiveArtifactResponses];
|
|
525
|
+
export type ListArtifactSourceVersionsData = {
|
|
526
|
+
body?: never;
|
|
527
|
+
path: {
|
|
528
|
+
/**
|
|
529
|
+
* Artifact Id
|
|
530
|
+
*/
|
|
531
|
+
artifact_id: string;
|
|
532
|
+
};
|
|
533
|
+
query?: {
|
|
534
|
+
/**
|
|
535
|
+
* After
|
|
536
|
+
*/
|
|
537
|
+
after?: ArtifactsCursor | null;
|
|
538
|
+
};
|
|
539
|
+
url: "/artifacts/{artifact_id}/source-versions";
|
|
540
|
+
};
|
|
541
|
+
export type ListArtifactSourceVersionsErrors = {
|
|
542
|
+
/**
|
|
543
|
+
* Validation Error
|
|
544
|
+
*/
|
|
545
|
+
422: HttpValidationError;
|
|
546
|
+
};
|
|
547
|
+
export type ListArtifactSourceVersionsError = ListArtifactSourceVersionsErrors[keyof ListArtifactSourceVersionsErrors];
|
|
548
|
+
export type ListArtifactSourceVersionsResponses = {
|
|
549
|
+
/**
|
|
550
|
+
* Successful Response
|
|
551
|
+
*/
|
|
552
|
+
200: ListedArtifactSourceVersionsPage;
|
|
553
|
+
};
|
|
554
|
+
export type ListArtifactSourceVersionsResponse = ListArtifactSourceVersionsResponses[keyof ListArtifactSourceVersionsResponses];
|
|
555
|
+
export type PublishArtifactSourceRevisionData = {
|
|
556
|
+
body: PublishRevisionRequestBody;
|
|
557
|
+
path: {
|
|
558
|
+
/**
|
|
559
|
+
* Artifact Id
|
|
560
|
+
*/
|
|
561
|
+
artifact_id: string;
|
|
562
|
+
};
|
|
563
|
+
query?: never;
|
|
564
|
+
url: "/artifacts/{artifact_id}/source-versions";
|
|
565
|
+
};
|
|
566
|
+
export type PublishArtifactSourceRevisionErrors = {
|
|
567
|
+
/**
|
|
568
|
+
* Validation Error
|
|
569
|
+
*/
|
|
570
|
+
422: HttpValidationError;
|
|
571
|
+
};
|
|
572
|
+
export type PublishArtifactSourceRevisionError = PublishArtifactSourceRevisionErrors[keyof PublishArtifactSourceRevisionErrors];
|
|
573
|
+
export type PublishArtifactSourceRevisionResponses = {
|
|
574
|
+
/**
|
|
575
|
+
* Response Publish Artifact Source Revision
|
|
576
|
+
*
|
|
577
|
+
* Successful Response
|
|
578
|
+
*/
|
|
579
|
+
200: ({
|
|
580
|
+
type: "source_version_published";
|
|
581
|
+
} & SourceVersionPublished) | ({
|
|
582
|
+
type: "expected_source_version_does_not_match";
|
|
583
|
+
} & ExpectedSourceVersionDoesNotMatch);
|
|
584
|
+
};
|
|
585
|
+
export type PublishArtifactSourceRevisionResponse = PublishArtifactSourceRevisionResponses[keyof PublishArtifactSourceRevisionResponses];
|
|
586
|
+
export type RenameArtifactData = {
|
|
587
|
+
body: RenameRequestBody;
|
|
588
|
+
path: {
|
|
589
|
+
/**
|
|
590
|
+
* Artifact Id
|
|
591
|
+
*/
|
|
592
|
+
artifact_id: string;
|
|
593
|
+
};
|
|
594
|
+
query?: never;
|
|
595
|
+
url: "/artifacts/{artifact_id}/title";
|
|
596
|
+
};
|
|
597
|
+
export type RenameArtifactErrors = {
|
|
598
|
+
/**
|
|
599
|
+
* Validation Error
|
|
600
|
+
*/
|
|
601
|
+
422: HttpValidationError;
|
|
602
|
+
};
|
|
603
|
+
export type RenameArtifactError = RenameArtifactErrors[keyof RenameArtifactErrors];
|
|
604
|
+
export type RenameArtifactResponses = {
|
|
605
|
+
/**
|
|
606
|
+
* Successful Response
|
|
607
|
+
*/
|
|
608
|
+
204: void;
|
|
609
|
+
};
|
|
610
|
+
export type RenameArtifactResponse = RenameArtifactResponses[keyof RenameArtifactResponses];
|
|
611
|
+
export type UnarchiveArtifactData = {
|
|
612
|
+
body?: never;
|
|
613
|
+
path: {
|
|
614
|
+
/**
|
|
615
|
+
* Artifact Id
|
|
616
|
+
*/
|
|
617
|
+
artifact_id: string;
|
|
618
|
+
};
|
|
619
|
+
query?: never;
|
|
620
|
+
url: "/artifacts/{artifact_id}/unarchive";
|
|
621
|
+
};
|
|
622
|
+
export type UnarchiveArtifactErrors = {
|
|
623
|
+
/**
|
|
624
|
+
* Validation Error
|
|
625
|
+
*/
|
|
626
|
+
422: HttpValidationError;
|
|
627
|
+
};
|
|
628
|
+
export type UnarchiveArtifactError = UnarchiveArtifactErrors[keyof UnarchiveArtifactErrors];
|
|
629
|
+
export type UnarchiveArtifactResponses = {
|
|
630
|
+
/**
|
|
631
|
+
* Successful Response
|
|
632
|
+
*/
|
|
633
|
+
204: void;
|
|
634
|
+
};
|
|
635
|
+
export type UnarchiveArtifactResponse = UnarchiveArtifactResponses[keyof UnarchiveArtifactResponses];
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ShownArtifactSource } from "./artifactSource.js";
|
|
2
|
+
/** What one read serves, in the hook's field names. */
|
|
3
|
+
export type ShownArtifactSourceFields = Omit<ShownArtifactSource, "type" | "lastRead">;
|
|
4
|
+
export type ParsedServedArtifactSource = {
|
|
5
|
+
type: "readable";
|
|
6
|
+
served: ShownArtifactSourceFields;
|
|
7
|
+
} | {
|
|
8
|
+
type: "unreadable";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Reads `GET /artifacts/{artifact_id}`'s body into the generated `ServedArtifactSource` without a
|
|
12
|
+
* schema library, then into the hook's shape. Fields the parser does not know are left out, so a
|
|
13
|
+
* backend that adds one keeps open tabs working.
|
|
14
|
+
*/
|
|
15
|
+
export declare function parseServedArtifactSource(body: unknown): ParsedServedArtifactSource;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { isArtifactId, isSourceVersionNumber } from "./artifactReference.js";
|
|
2
|
+
const UNREADABLE = { type: "unreadable" };
|
|
3
|
+
/**
|
|
4
|
+
* Reads `GET /artifacts/{artifact_id}`'s body into the generated `ServedArtifactSource` without a
|
|
5
|
+
* schema library, then into the hook's shape. Fields the parser does not know are left out, so a
|
|
6
|
+
* backend that adds one keeps open tabs working.
|
|
7
|
+
*/
|
|
8
|
+
export function parseServedArtifactSource(body) {
|
|
9
|
+
const parsed = parseGeneratedServedArtifactSource(body);
|
|
10
|
+
if (parsed.type === "unreadable")
|
|
11
|
+
return UNREADABLE;
|
|
12
|
+
const { title, source, archive_state, source_version_reference } = parsed.value;
|
|
13
|
+
const { artifact_id, source_version } = source_version_reference;
|
|
14
|
+
if (!isArtifactId(artifact_id) || !isSourceVersionNumber(source_version))
|
|
15
|
+
return UNREADABLE;
|
|
16
|
+
return {
|
|
17
|
+
type: "readable",
|
|
18
|
+
served: {
|
|
19
|
+
title,
|
|
20
|
+
source,
|
|
21
|
+
archiveState: archive_state.type === "active"
|
|
22
|
+
? { type: "active" }
|
|
23
|
+
: { type: "archived", archivedAt: archive_state.archived_at },
|
|
24
|
+
sourceVersionReference: { artifactId: artifact_id, sourceVersion: source_version },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function parseGeneratedServedArtifactSource(body) {
|
|
29
|
+
if (!isJsonObject(body))
|
|
30
|
+
return UNREADABLE;
|
|
31
|
+
const { title, source, archive_state, source_version_reference, } = body;
|
|
32
|
+
const archiveState = parseArchiveState(archive_state);
|
|
33
|
+
const sourceVersionReference = parseSourceVersionReference(source_version_reference);
|
|
34
|
+
if (typeof title !== "string" ||
|
|
35
|
+
typeof source !== "string" ||
|
|
36
|
+
archiveState.type === "unreadable" ||
|
|
37
|
+
sourceVersionReference.type === "unreadable")
|
|
38
|
+
return UNREADABLE;
|
|
39
|
+
return {
|
|
40
|
+
type: "readable",
|
|
41
|
+
value: {
|
|
42
|
+
title,
|
|
43
|
+
source,
|
|
44
|
+
archive_state: archiveState.value,
|
|
45
|
+
source_version_reference: sourceVersionReference.value,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function parseArchiveState(body) {
|
|
50
|
+
if (!isJsonObject(body))
|
|
51
|
+
return UNREADABLE;
|
|
52
|
+
const { type, archived_at, } = body;
|
|
53
|
+
if (type === "active")
|
|
54
|
+
return { type: "readable", value: { type } };
|
|
55
|
+
if (type === "archived" && typeof archived_at === "string")
|
|
56
|
+
return { type: "readable", value: { type, archived_at } };
|
|
57
|
+
return UNREADABLE;
|
|
58
|
+
}
|
|
59
|
+
function parseSourceVersionReference(body) {
|
|
60
|
+
if (!isJsonObject(body))
|
|
61
|
+
return UNREADABLE;
|
|
62
|
+
const { artifact_id, source_version } = body;
|
|
63
|
+
if (typeof artifact_id !== "string" || typeof source_version !== "number")
|
|
64
|
+
return UNREADABLE;
|
|
65
|
+
return { type: "readable", value: { artifact_id, source_version } };
|
|
66
|
+
}
|
|
67
|
+
function isJsonObject(value) {
|
|
68
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
69
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ArtifactReference } from "./artifactReference.js";
|
|
2
|
+
import type { ArtifactReadFailure } from "./artifactSource.js";
|
|
3
|
+
import type { ArtifactsSettings } from "./artifactsSettings.js";
|
|
4
|
+
import { type ShownArtifactSourceFields } from "./parseServedArtifactSource.js";
|
|
5
|
+
export type ArtifactReadOutcome = {
|
|
6
|
+
type: "served";
|
|
7
|
+
served: ShownArtifactSourceFields;
|
|
8
|
+
} | {
|
|
9
|
+
type: "not_found";
|
|
10
|
+
} | {
|
|
11
|
+
type: "failed";
|
|
12
|
+
failure: ArtifactReadFailure;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* `GET {routePrefix}/{artifact_id}`, with `?source_version=N` for a pinned reference. Never
|
|
16
|
+
* rejects: every way the read can end is an outcome.
|
|
17
|
+
*/
|
|
18
|
+
export declare function readArtifactSource(settings: ArtifactsSettings, reference: ArtifactReference, signal: AbortSignal): Promise<ArtifactReadOutcome>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { parseServedArtifactSource, } from "./parseServedArtifactSource.js";
|
|
2
|
+
const READ_TIMEOUT_MS = 30000;
|
|
3
|
+
const HTTP_NOT_FOUND = 404;
|
|
4
|
+
/** The artifact routes' own 404 texts. Any other 404, such as a proxy's or an unmounted route's, is a failure. */
|
|
5
|
+
const ARTIFACT_NOT_FOUND_DETAILS = new Set([
|
|
6
|
+
"Artifact not found",
|
|
7
|
+
"Artifact source version not found",
|
|
8
|
+
]);
|
|
9
|
+
/**
|
|
10
|
+
* `GET {routePrefix}/{artifact_id}`, with `?source_version=N` for a pinned reference. Never
|
|
11
|
+
* rejects: every way the read can end is an outcome.
|
|
12
|
+
*/
|
|
13
|
+
export async function readArtifactSource(settings, reference, signal) {
|
|
14
|
+
let headers;
|
|
15
|
+
try {
|
|
16
|
+
headers = await settings.getAuthHeaders();
|
|
17
|
+
}
|
|
18
|
+
catch (cause) {
|
|
19
|
+
return { type: "failed", failure: { type: "auth_headers_failed", cause } };
|
|
20
|
+
}
|
|
21
|
+
let response;
|
|
22
|
+
try {
|
|
23
|
+
response = await fetch(`${settings.routePrefix}/${addressOf(reference)}`, {
|
|
24
|
+
headers,
|
|
25
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(READ_TIMEOUT_MS)]),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (cause) {
|
|
29
|
+
return { type: "failed", failure: { type: "no_answer", cause } };
|
|
30
|
+
}
|
|
31
|
+
const body = await readJsonBody(response);
|
|
32
|
+
if (response.status === HTTP_NOT_FOUND && body.type === "read" && isArtifactNotFound(body.json))
|
|
33
|
+
return { type: "not_found" };
|
|
34
|
+
if (!response.ok)
|
|
35
|
+
return { type: "failed", failure: { type: "answered_with_status", status: response.status } };
|
|
36
|
+
if (body.type === "unreadable")
|
|
37
|
+
return { type: "failed", failure: { type: "unreadable_answer" } };
|
|
38
|
+
const parsed = parseServedArtifactSource(body.json);
|
|
39
|
+
if (parsed.type === "unreadable")
|
|
40
|
+
return { type: "failed", failure: { type: "unreadable_answer" } };
|
|
41
|
+
return { type: "served", served: parsed.served };
|
|
42
|
+
}
|
|
43
|
+
function addressOf(reference) {
|
|
44
|
+
if (typeof reference === "string")
|
|
45
|
+
return encodeURIComponent(reference);
|
|
46
|
+
return `${encodeURIComponent(reference.artifactId)}?source_version=${String(reference.sourceVersion)}`;
|
|
47
|
+
}
|
|
48
|
+
async function readJsonBody(response) {
|
|
49
|
+
try {
|
|
50
|
+
const json = await response.json();
|
|
51
|
+
return { type: "read", json };
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
return { type: "unreadable" };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
function isArtifactNotFound(body) {
|
|
58
|
+
return (typeof body === "object" &&
|
|
59
|
+
body !== null &&
|
|
60
|
+
"detail" in body &&
|
|
61
|
+
ARTIFACT_NOT_FOUND_DETAILS.has(body.detail));
|
|
62
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ArtifactReference } from "./artifactReference.js";
|
|
2
|
+
import type { ArtifactSource } from "./artifactSource.js";
|
|
3
|
+
/**
|
|
4
|
+
* The artifact's source for this reference, read as `followArtifactSource` describes. A new
|
|
5
|
+
* reference shows `opening` until its first read ends, never the previous reference's source.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useArtifactSource(reference: ArtifactReference): ArtifactSource;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
import { followArtifactSource, OPENING_ARTIFACT_SOURCE } from "./followArtifactSource.js";
|
|
3
|
+
/**
|
|
4
|
+
* The artifact's source for this reference, read as `followArtifactSource` describes. A new
|
|
5
|
+
* reference shows `opening` until its first read ends, never the previous reference's source.
|
|
6
|
+
*/
|
|
7
|
+
export function useArtifactSource(reference) {
|
|
8
|
+
const artifactId = typeof reference === "string" ? reference : reference.artifactId;
|
|
9
|
+
const pinnedSourceVersion = typeof reference === "string" ? "live" : reference.sourceVersion;
|
|
10
|
+
const followedReferenceKey = `${artifactId}:${String(pinnedSourceVersion)}`;
|
|
11
|
+
const [followed, setFollowed] = useState({
|
|
12
|
+
referenceKey: followedReferenceKey,
|
|
13
|
+
source: OPENING_ARTIFACT_SOURCE,
|
|
14
|
+
});
|
|
15
|
+
useEffect(() => followArtifactSource(referenceOf(artifactId, pinnedSourceVersion), (source) => {
|
|
16
|
+
setFollowed({ referenceKey: followedReferenceKey, source });
|
|
17
|
+
}), [artifactId, pinnedSourceVersion, followedReferenceKey]);
|
|
18
|
+
return followed.referenceKey === followedReferenceKey ? followed.source : OPENING_ARTIFACT_SOURCE;
|
|
19
|
+
}
|
|
20
|
+
function referenceOf(artifactId, pinnedSourceVersion) {
|
|
21
|
+
return pinnedSourceVersion === "live"
|
|
22
|
+
? artifactId
|
|
23
|
+
: { artifactId, sourceVersion: pinnedSourceVersion };
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@ciridae/artifacts-react",
|
|
3
|
+
"version": "0.1.0-nightly.0.bootstrap",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"description": "React hook and sandboxed frame for Ciridae artifacts: read an artifact's live or pinned source and show it as a page that cannot reach the app or the network.",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=22.18"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/ciridae-ai/ciridae.git",
|
|
14
|
+
"directory": "packages/artifacts-react"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/ciridae-ai/ciridae#readme",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
},
|
|
20
|
+
"exports": {
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/entries/index.d.ts",
|
|
24
|
+
"default": "./dist/entries/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"README.md"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@types/react": ">=18",
|
|
33
|
+
"react": ">=18"
|
|
34
|
+
},
|
|
35
|
+
"peerDependenciesMeta": {
|
|
36
|
+
"@types/react": {
|
|
37
|
+
"optional": true
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {}
|
|
41
|
+
}
|