@wervt/core 0.0.4 → 0.0.6
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 +2 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/manifest.d.ts +42 -9
- package/dist/manifest.js +19 -1
- package/dist/public-files.d.ts +9 -0
- package/dist/public-files.js +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -23,5 +23,7 @@ import { getAnthropic } from '@wervt/core/anthropic'
|
|
|
23
23
|
- `createTaskHandler(tasks)`: the routes the control plane runs tasks through.
|
|
24
24
|
- `useDb()`, `seedTable()` (`@wervt/core/db`): Drizzle on the app's database.
|
|
25
25
|
- `getAnthropic()` (`@wervt/core/anthropic`): Claude without an API key, through the app's identity.
|
|
26
|
+
- `publicFileResponse(request, files)`: answers the app's server-side fetches of its own `public/`
|
|
27
|
+
files from the runtime, as the isolate can't read them.
|
|
26
28
|
|
|
27
29
|
Failed platform calls throw a `WervtError` with the HTTP status to answer.
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ import { WervtError, errorResponse } from "./errors.js";
|
|
|
3
3
|
import { WorkloadIdentity, workloadIdentity } from "./identity.js";
|
|
4
4
|
import { IMAGE_FORMATS, ImageFormat, ImageGravity, ImageOptions, ImageSource, fetchImage, imageProcessingOptions, imageSourceKey, imageUrl, signImagePath } from "./image.js";
|
|
5
5
|
import { MailMessage, sendMail } from "./mail.js";
|
|
6
|
-
import { BUNDLE_MANIFEST, BrandManifest, BundleManifest, PreviewManifest, TaskSchedule, TasksManifest } from "./manifest.js";
|
|
6
|
+
import { BUNDLE_MANIFEST, BrandManifest, BundleManifest, CACHE_CONTROL_PATTERN, PUBLIC_PATH_PATTERN, PreviewManifest, PublicCacheRule, PublicCacheRules, TaskSchedule, TasksManifest, matchesPublicPath } from "./manifest.js";
|
|
7
7
|
import { appHeaders, callRuntime, runtimeUrl } from "./runtime.js";
|
|
8
|
+
import { PUBLIC_FILE_SERVICE, publicFileResponse } from "./public-files.js";
|
|
8
9
|
import { ShapeRequest, ShapeResponse, ShapeRowOf, parseTimestamp, proxyShape, shapeParser } from "./shape.js";
|
|
9
10
|
import { ACCOUNT_MERGED_TASK, AccountMergedPayload, TASK_HEADER, Task, TaskEvent, TaskResult, createTaskHandler, defineTask, isTaskRequest, taskRunResponse } from "./tasks.js";
|
|
10
11
|
import { AGENT_TOKEN_HEADER, AgentToken, USER_HEADER, USER_PROOF_HEADER, WervtRole, WervtUser, checkRole, getAgentToken, getUser, parseAgentToken, parseWervtUser, requireRole, userFromClaims } from "./user.js";
|
|
11
|
-
export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, type AccountMergedPayload, type AgentToken, BUNDLE_MANIFEST, type BrandManifest, type BundleManifest, IMAGE_FORMATS, type ImageFormat, type ImageGravity, type ImageOptions, type ImageSource, type MailMessage, type PreviewManifest, type ShapeRequest, type ShapeResponse, type ShapeRowOf, TASK_HEADER, type Task, type TaskEvent, type TaskResult, type TaskSchedule, type TasksManifest, USER_HEADER, USER_PROOF_HEADER, type WervtAccess, WervtError, type WervtInvite, type WervtRole, type WervtUser, type WorkloadIdentity, appAccess, appHeaders, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, requireRole, runtimeUrl, sendMail, shapeParser, signImagePath, taskRunResponse, userFromClaims, workloadIdentity };
|
|
12
|
+
export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, type AccountMergedPayload, type AgentToken, BUNDLE_MANIFEST, type BrandManifest, type BundleManifest, CACHE_CONTROL_PATTERN, IMAGE_FORMATS, type ImageFormat, type ImageGravity, type ImageOptions, type ImageSource, type MailMessage, PUBLIC_FILE_SERVICE, PUBLIC_PATH_PATTERN, type PreviewManifest, type PublicCacheRule, type PublicCacheRules, type ShapeRequest, type ShapeResponse, type ShapeRowOf, TASK_HEADER, type Task, type TaskEvent, type TaskResult, type TaskSchedule, type TasksManifest, USER_HEADER, USER_PROOF_HEADER, type WervtAccess, WervtError, type WervtInvite, type WervtRole, type WervtUser, type WorkloadIdentity, appAccess, appHeaders, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, matchesPublicPath, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, publicFileResponse, requireRole, runtimeUrl, sendMail, shapeParser, signImagePath, taskRunResponse, userFromClaims, workloadIdentity };
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,8 @@ import { appAccess } from "./access.js";
|
|
|
5
5
|
import { workloadIdentity } from "./identity.js";
|
|
6
6
|
import { IMAGE_FORMATS, fetchImage, imageProcessingOptions, imageSourceKey, imageUrl, signImagePath } from "./image.js";
|
|
7
7
|
import { sendMail } from "./mail.js";
|
|
8
|
-
import { BUNDLE_MANIFEST } from "./manifest.js";
|
|
8
|
+
import { BUNDLE_MANIFEST, CACHE_CONTROL_PATTERN, PUBLIC_PATH_PATTERN, matchesPublicPath } from "./manifest.js";
|
|
9
|
+
import { PUBLIC_FILE_SERVICE, publicFileResponse } from "./public-files.js";
|
|
9
10
|
import { parseTimestamp, proxyShape, shapeParser } from "./shape.js";
|
|
10
11
|
import { ACCOUNT_MERGED_TASK, TASK_HEADER, createTaskHandler, defineTask, isTaskRequest, taskRunResponse } from "./tasks.js";
|
|
11
|
-
export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, BUNDLE_MANIFEST, IMAGE_FORMATS, TASK_HEADER, USER_HEADER, USER_PROOF_HEADER, WervtError, appAccess, appHeaders, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, requireRole, runtimeUrl, sendMail, shapeParser, signImagePath, taskRunResponse, userFromClaims, workloadIdentity };
|
|
12
|
+
export { ACCOUNT_MERGED_TASK, AGENT_TOKEN_HEADER, BUNDLE_MANIFEST, CACHE_CONTROL_PATTERN, IMAGE_FORMATS, PUBLIC_FILE_SERVICE, PUBLIC_PATH_PATTERN, TASK_HEADER, USER_HEADER, USER_PROOF_HEADER, WervtError, appAccess, appHeaders, callRuntime, checkRole, createTaskHandler, defineTask, errorResponse, fetchImage, getAgentToken, getUser, imageProcessingOptions, imageSourceKey, imageUrl, isTaskRequest, matchesPublicPath, parseAgentToken, parseTimestamp, parseWervtUser, proxyShape, publicFileResponse, requireRole, runtimeUrl, sendMail, shapeParser, signImagePath, taskRunResponse, userFromClaims, workloadIdentity };
|
package/dist/manifest.d.ts
CHANGED
|
@@ -36,6 +36,41 @@ export interface BrandManifest {
|
|
|
36
36
|
/** The login's language (`de`, `en`). The visitor's browser decides when missing. */
|
|
37
37
|
lang?: string;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* How long files in `public/` may be cached. The runtime serves them itself, so the server's own
|
|
41
|
+
* headers (Nitro's `routeRules`) never apply to them. Bundles without any of these get Nuxt's
|
|
42
|
+
* `/_nuxt/` rules; naming any replaces all of them.
|
|
43
|
+
*
|
|
44
|
+
* A file's `cache-control`, first match wins: `noCache`, then `immutable`, then the first of
|
|
45
|
+
* `rules`; none sends no header. A prerendered page (`/about` answered with `about/index.html`)
|
|
46
|
+
* is always `no-cache`, as it changes with every release under the same URL.
|
|
47
|
+
*/
|
|
48
|
+
export interface PublicCacheRules {
|
|
49
|
+
/**
|
|
50
|
+
* Path prefixes of files that never change (hashed build assets), cached for a year, e.g.
|
|
51
|
+
* `['/assets/']`.
|
|
52
|
+
*/
|
|
53
|
+
immutable?: string[];
|
|
54
|
+
/** Paths browsers must check again every time, e.g. a file naming the newest build. */
|
|
55
|
+
noCache?: string[];
|
|
56
|
+
/** Any other `cache-control`, by path pattern (see `matchesPublicPath`). */
|
|
57
|
+
rules?: PublicCacheRule[];
|
|
58
|
+
}
|
|
59
|
+
export interface PublicCacheRule {
|
|
60
|
+
/** An exact path (`/favicon.svg`), with `*` for one segment and a final `/**` for the rest. */
|
|
61
|
+
path: string;
|
|
62
|
+
/** The header's value, e.g. `public, max-age=86400`. */
|
|
63
|
+
cacheControl: string;
|
|
64
|
+
}
|
|
65
|
+
/** What `PublicCacheRule.path` may be: `/images/**`, `/icons/*` or `/favicon.svg`. */
|
|
66
|
+
export declare const PUBLIC_PATH_PATTERN: RegExp;
|
|
67
|
+
/**
|
|
68
|
+
* What `PublicCacheRule.cacheControl` may be: comma-separated directives, each a token with an
|
|
69
|
+
* optional number or quoted list. Narrow on purpose, as the value ends up in a response header.
|
|
70
|
+
*/
|
|
71
|
+
export declare const CACHE_CONTROL_PATTERN: RegExp;
|
|
72
|
+
/** Whether `path` (`/images/a.avif`) matches a rule's `pattern` (`/images/**`). */
|
|
73
|
+
export declare function matchesPublicPath(pattern: string, path: string): boolean;
|
|
39
74
|
/** The bundle's `wervt-bundle.json`, next to `server/` and `public/`. */
|
|
40
75
|
export declare const BUNDLE_MANIFEST = "wervt-bundle.json";
|
|
41
76
|
export interface BundleManifest {
|
|
@@ -47,18 +82,16 @@ export interface BundleManifest {
|
|
|
47
82
|
* `true` without them gives an empty schema.
|
|
48
83
|
*/
|
|
49
84
|
database?: boolean;
|
|
50
|
-
public?:
|
|
51
|
-
/**
|
|
52
|
-
* Path prefixes of files that never change (hashed build assets), cached for a year, e.g.
|
|
53
|
-
* `['/assets/']`. Defaults to Nuxt's `/_nuxt/` for Nuxt and bundles without a framework.
|
|
54
|
-
*/
|
|
55
|
-
immutable?: string[];
|
|
56
|
-
/** Paths browsers must check again every time, e.g. a file naming the newest build. */
|
|
57
|
-
noCache?: string[];
|
|
58
|
-
};
|
|
85
|
+
public?: PublicCacheRules;
|
|
59
86
|
tasks?: TasksManifest;
|
|
60
87
|
/** Shape routes without parameters, requested once after a deploy to check they work. */
|
|
61
88
|
shapes?: string[];
|
|
62
89
|
preview?: PreviewManifest;
|
|
63
90
|
brand?: BrandManifest;
|
|
91
|
+
/**
|
|
92
|
+
* Path prefixes that take changing requests (POST, PUT, …) from pages of other apps on the
|
|
93
|
+
* base domain, e.g. `['/api/intake/']` for a widget embedded in other apps. The runtime answers
|
|
94
|
+
* those with 403 everywhere else, since the browser sends the visitor's login along.
|
|
95
|
+
*/
|
|
96
|
+
crossApp?: string[];
|
|
64
97
|
}
|
package/dist/manifest.js
CHANGED
|
@@ -1,4 +1,22 @@
|
|
|
1
1
|
// src/manifest.ts
|
|
2
|
+
/** What `PublicCacheRule.path` may be: `/images/**`, `/icons/*` or `/favicon.svg`. */
|
|
3
|
+
const PUBLIC_PATH_PATTERN = /^(?:\/(?:[^/*\s?#]+|\*))*(?:\/\*\*)?$/;
|
|
4
|
+
/**
|
|
5
|
+
* What `PublicCacheRule.cacheControl` may be: comma-separated directives, each a token with an
|
|
6
|
+
* optional number or quoted list. Narrow on purpose, as the value ends up in a response header.
|
|
7
|
+
*/
|
|
8
|
+
const CACHE_CONTROL_PATTERN = /^[a-z-]+(?:=(?:\d+|"[a-z, -]*"))?(?:, ?[a-z-]+(?:=(?:\d+|"[a-z, -]*"))?)*$/i;
|
|
9
|
+
/** Whether `path` (`/images/a.avif`) matches a rule's `pattern` (`/images/**`). */
|
|
10
|
+
function matchesPublicPath(pattern, path) {
|
|
11
|
+
const want = pattern.split("/");
|
|
12
|
+
const have = path.split("/");
|
|
13
|
+
for (let i = 0; i < want.length; i++) {
|
|
14
|
+
if (want[i] === "**") return true;
|
|
15
|
+
if (i >= have.length) return false;
|
|
16
|
+
if (want[i] === "*" ? have[i] === "" : want[i] !== have[i]) return false;
|
|
17
|
+
}
|
|
18
|
+
return want.length === have.length;
|
|
19
|
+
}
|
|
2
20
|
/** The bundle's `wervt-bundle.json`, next to `server/` and `public/`. */
|
|
3
21
|
const BUNDLE_MANIFEST = "wervt-bundle.json";
|
|
4
|
-
export { BUNDLE_MANIFEST };
|
|
22
|
+
export { BUNDLE_MANIFEST, CACHE_CONTROL_PATTERN, PUBLIC_PATH_PATTERN, matchesPublicPath };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** The runtime service that answers with a file of the calling app's active release. */
|
|
2
|
+
export declare const PUBLIC_FILE_SERVICE = "/_wervt/public-file";
|
|
3
|
+
/**
|
|
4
|
+
* The file `req` asks for, from the runtime, or `undefined` to let the server answer: not a GET
|
|
5
|
+
* or HEAD, a path that isn't in `files` (the build's public dir, as request paths), outside
|
|
6
|
+
* wervt, or the runtime didn't have it. Falling through keeps a route that answers under the same
|
|
7
|
+
* path working, as it did before.
|
|
8
|
+
*/
|
|
9
|
+
export declare function publicFileResponse(req: Request, files: ReadonlySet<string>): Promise<Response | undefined>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { appHeaders, runtimeUrl } from "./runtime.js";
|
|
2
|
+
// src/public-files.ts
|
|
3
|
+
/** The runtime service that answers with a file of the calling app's active release. */
|
|
4
|
+
const PUBLIC_FILE_SERVICE = "/_wervt/public-file";
|
|
5
|
+
const FORWARDED = [
|
|
6
|
+
"range",
|
|
7
|
+
"if-none-match",
|
|
8
|
+
"if-modified-since",
|
|
9
|
+
"if-range"
|
|
10
|
+
];
|
|
11
|
+
/**
|
|
12
|
+
* The file `req` asks for, from the runtime, or `undefined` to let the server answer: not a GET
|
|
13
|
+
* or HEAD, a path that isn't in `files` (the build's public dir, as request paths), outside
|
|
14
|
+
* wervt, or the runtime didn't have it. Falling through keeps a route that answers under the same
|
|
15
|
+
* path working, as it did before.
|
|
16
|
+
*/
|
|
17
|
+
async function publicFileResponse(req, files) {
|
|
18
|
+
if (req.method !== "GET" && req.method !== "HEAD") return void 0;
|
|
19
|
+
const runtime = runtimeUrl();
|
|
20
|
+
if (!runtime) return void 0;
|
|
21
|
+
let path;
|
|
22
|
+
try {
|
|
23
|
+
path = decodeURIComponent(new URL(req.url, "http://localhost").pathname);
|
|
24
|
+
} catch {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!files.has(path)) return void 0;
|
|
28
|
+
const url = new URL(PUBLIC_FILE_SERVICE, runtime);
|
|
29
|
+
url.searchParams.set("path", path);
|
|
30
|
+
const headers = new Headers(appHeaders());
|
|
31
|
+
for (const name of FORWARDED) {
|
|
32
|
+
const value = req.headers.get(name);
|
|
33
|
+
if (value) headers.set(name, value);
|
|
34
|
+
}
|
|
35
|
+
const res = await fetch(url, {
|
|
36
|
+
method: req.method,
|
|
37
|
+
headers,
|
|
38
|
+
signal: req.signal
|
|
39
|
+
}).catch(() => void 0);
|
|
40
|
+
if (res && (res.ok || res.status === 304 || res.status === 416)) return res;
|
|
41
|
+
await res?.body?.cancel();
|
|
42
|
+
}
|
|
43
|
+
export { PUBLIC_FILE_SERVICE, publicFileResponse };
|
package/package.json
CHANGED