@hugex/artifact 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/catalog.d.ts CHANGED
@@ -7,6 +7,22 @@
7
7
  * | openssl dgst -sha384 -binary | openssl base64 -A
8
8
  * Prefix the digest with `sha384-`.
9
9
  *
10
+ * SRI regeneration per catalog entry:
11
+ * - daisyui: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/daisyui@5.7.47/daisyui.css' | openssl dgst -sha384 -binary | openssl base64 -A
12
+ * - lucide: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/lucide@1.55.0/dist/umd/lucide.min.js' | openssl dgst -sha384 -binary | openssl base64 -A
13
+ * - echarts: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/echarts@6.1.0/dist/echarts.esm.min.js' | openssl dgst -sha384 -binary | openssl base64 -A
14
+ * - tabulator-tables (mjs): curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/tabulator-tables@6.6.1/dist/js/tabulator_esm.min.mjs' | openssl dgst -sha384 -binary | openssl base64 -A
15
+ * - tabulator-tables (css): curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/tabulator-tables@6.6.1/dist/css/tabulator.min.css' | openssl dgst -sha384 -binary | openssl base64 -A
16
+ * - luxon: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/luxon@3.7.2/build/es6/luxon.mjs' | openssl dgst -sha384 -binary | openssl base64 -A
17
+ * - sortablejs: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/sortablejs@1.15.7/modular/sortable.esm.js' | openssl dgst -sha384 -binary | openssl base64 -A
18
+ * - marked: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/marked@18.1.0/lib/marked.esm.js' | openssl dgst -sha384 -binary | openssl base64 -A
19
+ * - dompurify: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/dompurify@3.4.16/dist/purify.es.mjs' | openssl dgst -sha384 -binary | openssl base64 -A
20
+ * - alpinejs: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/alpinejs@3.17.4/dist/cdn.min.js' | openssl dgst -sha384 -binary | openssl base64 -A
21
+ * - preact: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/preact@10.26.9/dist/preact.module.js' | openssl dgst -sha384 -binary | openssl base64 -A
22
+ * - htm: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/htm@3.1.1/dist/htm.mjs' | openssl dgst -sha384 -binary | openssl base64 -A
23
+ * - chart.js: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/chart.js@4.5.0/auto/auto.js' | openssl dgst -sha384 -binary | openssl base64 -A
24
+ * - @tailwindcss/browser: curl -fsSL -H 'Accept-Encoding: identity' 'https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4.1.16/dist/index.global.js' | openssl dgst -sha384 -binary | openssl base64 -A
25
+ *
10
26
  * react and react-dom are not listed. react@19.2.0 publishes only CJS
11
27
  * (`index.js` → `cjs/react.production.js`); there is no stable static ESM
12
28
  * browser entry. jsDelivr `+esm` is generated per request and cannot be pinned
@@ -21,17 +37,30 @@ export interface CatalogSpecifier {
21
37
  url: string;
22
38
  integrity: string;
23
39
  }
40
+ export interface CatalogStylesheet {
41
+ url: string;
42
+ integrity: string;
43
+ }
44
+ export interface CatalogScript {
45
+ url: string;
46
+ integrity: string;
47
+ defer?: boolean;
48
+ }
24
49
  export interface CatalogEntry {
25
50
  /** Name accepted in artifact.json `libs`. */
26
51
  name: string;
27
52
  version: string;
28
- /** Primary file URL (also the classic script URL when `kind` is `classic`). */
53
+ /** Primary file URL (also the classic script or stylesheet URL). */
29
54
  url: string;
30
55
  integrity: string;
31
- kind: "module" | "classic";
56
+ kind: "module" | "classic" | "stylesheet";
32
57
  /** Import-map specifiers contributed when this entry is selected. */
33
58
  specifiers: Record<string, CatalogSpecifier>;
34
- /** Other catalog names that must be on the import map (bare imports). */
59
+ /** Stylesheet URLs and SRIs contributed when this entry is selected. */
60
+ stylesheets?: CatalogStylesheet[];
61
+ /** Classic script tags contributed when this entry is selected. */
62
+ scripts?: CatalogScript[];
63
+ /** Other catalog names that must be included (bare imports or companion entries). */
35
64
  needs?: string[];
36
65
  }
37
66
  export declare const CATALOG: readonly CatalogEntry[];
@@ -43,6 +72,8 @@ export declare function tailwindBrowser(): {
43
72
  export interface ResolvedImports {
44
73
  imports: Record<string, string>;
45
74
  integrity: Record<string, string>;
75
+ stylesheets: CatalogStylesheet[];
76
+ scripts: CatalogScript[];
46
77
  warnings: string[];
47
78
  }
48
79
  /** Unknown names become warnings. Bare deps of a known lib are pulled in without a warning. */
@@ -1,9 +1,11 @@
1
1
  import { DurableObject } from "cloudflare:workers";
2
- import type { ArtifactEnv, ArtifactFile, ArtifactLogEntry, ArtifactMeta, ArtifactRpc, ArtifactVersion, CreateArtifactInput, QueryResult, SettingsInput, WriteInput, WriteResult } from "../types";
2
+ import type { AllowsWorkerInput, AllowsWorkerResult, ArtifactEnv, ArtifactFile, ArtifactLogEntry, ArtifactMeta, ArtifactRpc, ArtifactVersion, CreateArtifactInput, QueryResult, SettingsInput, WorkerGrant, WriteInput, WriteResult } from "../types";
3
3
  /**
4
4
  * One instance per artifact (`idFromName(slug)`).
5
- * Supervisor SQLite holds meta, files, versions, and logs.
6
- * `server.js` runs in a facet named `app`, loaded with `globalOutbound: null` and `env: {}`.
5
+ * Supervisor SQLite holds meta, files, versions, logs, and Worker grants.
6
+ * `server.js` runs in a facet named `app`, loaded with `globalOutbound: null`. Its `env` is
7
+ * `{ HX }` (the tenant's `ArtifactWorkerGateway`, from `ctx.exports`) when the tenant exports
8
+ * it, and `{}` otherwise.
7
9
  */
8
10
  export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements ArtifactRpc {
9
11
  /** Bumped when an activation window expires so a late health check cannot publish. */
@@ -39,6 +41,32 @@ export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements Ar
39
41
  limit?: number;
40
42
  source?: ArtifactLogEntry["source"];
41
43
  }): Promise<ArtifactLogEntry[] | null>;
44
+ delete(input: {
45
+ author: string;
46
+ }): Promise<{
47
+ ok: true;
48
+ oraSyncFailed?: boolean;
49
+ } | null>;
50
+ allowsWorker(input: AllowsWorkerInput): Promise<AllowsWorkerResult>;
51
+ listWorkerGrants(): Promise<WorkerGrant[] | null>;
52
+ grantWorker(input: {
53
+ flowId: string;
54
+ grantedBy: string;
55
+ expectUuid: string;
56
+ expectOwner: string;
57
+ }): Promise<WorkerGrant | null>;
58
+ revokeWorker(input: {
59
+ flowId: string;
60
+ expectUuid: string;
61
+ }): Promise<{
62
+ removed: boolean;
63
+ } | null>;
64
+ /** Harness / diagnostics: supervisor SQLite size and row counts. */
65
+ storageStats(): Promise<{
66
+ databaseSize: number;
67
+ blobCount: number;
68
+ versionCount: number;
69
+ } | null>;
42
70
  query(sql: string): Promise<QueryResult>;
43
71
  fetch(request: Request): Promise<Response>;
44
72
  webSocketMessage(_ws: WebSocket, message: string | ArrayBuffer): Promise<void>;
@@ -55,9 +83,12 @@ export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements Ar
55
83
  private activateCode;
56
84
  /** Version row + files, or nothing. Hashes are already computed. Quota is checked before the inserts. */
57
85
  private persistNewVersion;
86
+ private runRetention;
58
87
  private markFailed;
59
88
  /** Active/previous/meta move together, and the index is marked dirty in the same transaction. */
60
89
  private promote;
90
+ private workerGateway;
91
+ private hasWorkerGateway;
61
92
  private runtimeId;
62
93
  private loadApp;
63
94
  private facetOf;
@@ -73,6 +104,8 @@ export declare class ArtifactDO extends DurableObject<ArtifactEnv> implements Ar
73
104
  private forwardApi;
74
105
  private broadcastReload;
75
106
  private closeStaleSockets;
107
+ private closeAllSockets;
108
+ private destroyFacet;
76
109
  private browserLogAllowed;
77
110
  private writeLog;
78
111
  /**
@@ -0,0 +1,28 @@
1
+ export type SqlExec = (sql: string, ...bindings: (string | number | null)[]) => void;
2
+ export type SqlRow = {
3
+ hash?: string;
4
+ id?: string;
5
+ version?: string | null;
6
+ createdAt?: string;
7
+ };
8
+ export type SqlQuery = (sql: string, ...bindings: (string | number | null)[]) => SqlRow[];
9
+ /** True when `file` still stores inline `content` (pre-dedup schema). */
10
+ export declare function fileTableHasContentColumn(columnNames: string[]): boolean;
11
+ /**
12
+ * Moves legacy `file.content` into `blob` and rebuilds `file` as (version, path, hash).
13
+ * Idempotent when `content` is already gone.
14
+ */
15
+ export declare function migrateLegacyFileStorage(exec: SqlExec, query: SqlQuery, columnNames: string[]): void;
16
+ /** Version ids that must survive retention pruning. */
17
+ export declare function versionIdsToKeep(input: {
18
+ activeVersion: string | null;
19
+ versionRows: {
20
+ id: string;
21
+ createdAt: string;
22
+ }[];
23
+ logVersionIds: string[];
24
+ keepVersions: number;
25
+ }): Set<string>;
26
+ /** Estimated byte growth from new blob rows only (for quota projection). */
27
+ export declare function newBlobFootprint(files: ReadonlyMap<string, string>, hashes: ReadonlyMap<string, string>, existingBlobHashes: ReadonlySet<string>): number;
28
+ export declare function pruneOldVersions(exec: SqlExec, query: SqlQuery, activeVersion: string | null, keepVersions?: number): void;
@@ -6,6 +6,15 @@
6
6
  */
7
7
  import type { ArtifactIndexEntry } from "../types";
8
8
  export declare const ORA_INDEX_TIMEOUT_MS = 5000;
9
+ export declare function deleteArtifactOra(env: {
10
+ HX_ORA_URL?: string;
11
+ HX_API_KEY?: string;
12
+ }, uuid: string, fetchImpl?: typeof fetch, timeoutMs?: number): Promise<{
13
+ ok: true;
14
+ } | {
15
+ ok: false;
16
+ error: string;
17
+ }>;
9
18
  export declare function pushArtifactIndex(env: {
10
19
  HX_ORA_URL?: string;
11
20
  HX_API_KEY?: string;
package/dist/hash.d.ts CHANGED
@@ -12,12 +12,20 @@ export declare function truncateUtf8(text: string, maxBytes: number): string;
12
12
  */
13
13
  export declare function hashFileSet(files: ReadonlyMap<string, string> | Record<string, string>): Promise<string>;
14
14
  export declare function sameFileSet(a: ReadonlyMap<string, string>, b: ReadonlyMap<string, string>): boolean;
15
- /** Stable config mixed into runtimeId. `globalOutbound: null` and empty env are part of the contract. */
16
- export declare function artifactWorkerConfig(compatibilityDate?: string): {
15
+ /** Name of the tenant entrypoint the loader binds as `env.HX` when `ctx.exports` has it. */
16
+ export declare const ARTIFACT_GATEWAY_EXPORT = "ArtifactWorkerGateway";
17
+ /**
18
+ * Stable config mixed into runtimeId. `globalOutbound: null` is part of the contract.
19
+ * `env` describes the bindings: empty, or `HX` bound to the tenant gateway (props are set by
20
+ * the loader per artifact, so only the entrypoint name enters the hash).
21
+ */
22
+ export declare function artifactWorkerConfig(compatibilityDate?: string, opts?: {
23
+ gateway?: boolean;
24
+ }): {
17
25
  compatibilityDate: string;
18
26
  mainModule: string;
19
27
  globalOutbound: null;
20
- env: Record<string, never>;
28
+ env: Record<string, string>;
21
29
  };
22
30
  /**
23
31
  * runtimeId = sha256(server modules + package version + compatibilityDate + config).
@@ -13,6 +13,14 @@ export type ArtifactRoute = {
13
13
  key: string;
14
14
  internalPath: string;
15
15
  basePath: string;
16
+ }
17
+ /** `<base>/__hx/agent/<flowId>/<sessionId>`: same-origin proxy to a granted Worker. */
18
+ | {
19
+ kind: "agent";
20
+ slug: string;
21
+ key: string;
22
+ flowId: string;
23
+ sessionId: string;
16
24
  };
17
25
  export interface RouteInput {
18
26
  pathname: string;
package/dist/host.d.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { artifactDevPrefix } from "./dev-prefix";
2
- import type { ArtifactEnv } from "./types";
2
+ import type { ArtifactEnv, ArtifactHostOptions } from "./types";
3
3
  export { artifactDevPrefix };
4
4
  /**
5
5
  * Terminal on `ARTIFACT_HOST`. On localhost, 127.0.0.1, or [::1], mounts the same
6
6
  * routes under `ARTIFACT_DEV_PATH` (for example `/app/...`). Any other hostname
7
7
  * ignores that variable. Returns null when the path is unrelated.
8
+ * `options.agentProxy` turns on `<base>/__hx/agent/<flowId>/<sessionId>`.
8
9
  */
9
- export declare function handleArtifactHost(request: Request, env: ArtifactEnv, ctx: ExecutionContext): Promise<Response | null>;
10
+ export declare function handleArtifactHost(request: Request, env: ArtifactEnv, ctx: ExecutionContext, options?: ArtifactHostOptions): Promise<Response | null>;