@weft-framework/server 0.0.0-stage → 0.0.3

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.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/dist/account.d.ts +124 -0
  4. package/dist/account.js +344 -0
  5. package/dist/action.d.ts +43 -0
  6. package/dist/action.js +135 -0
  7. package/dist/admin.d.ts +99 -0
  8. package/dist/admin.js +431 -0
  9. package/dist/api.d.ts +21 -0
  10. package/dist/api.js +72 -0
  11. package/dist/app.d.ts +202 -0
  12. package/dist/app.js +3692 -0
  13. package/dist/assets.d.ts +4 -0
  14. package/dist/assets.js +91 -0
  15. package/dist/auth.d.ts +150 -0
  16. package/dist/auth.js +215 -0
  17. package/dist/backup.d.ts +46 -0
  18. package/dist/backup.js +345 -0
  19. package/dist/build.d.ts +33 -0
  20. package/dist/build.js +274 -0
  21. package/dist/bun.d.ts +30 -0
  22. package/dist/bun.js +53 -0
  23. package/dist/calendar.d.ts +161 -0
  24. package/dist/calendar.js +690 -0
  25. package/dist/compiler.d.ts +13 -0
  26. package/dist/compiler.js +58 -0
  27. package/dist/compress.d.ts +6 -0
  28. package/dist/compress.js +78 -0
  29. package/dist/config.d.ts +26 -0
  30. package/dist/config.js +317 -0
  31. package/dist/context.d.ts +9 -0
  32. package/dist/context.js +1 -0
  33. package/dist/contract.d.ts +18 -0
  34. package/dist/contract.js +171 -0
  35. package/dist/datamap.d.ts +24 -0
  36. package/dist/datamap.js +365 -0
  37. package/dist/db-backup.d.ts +27 -0
  38. package/dist/db-backup.js +115 -0
  39. package/dist/dev-events.d.ts +14 -0
  40. package/dist/dev-events.js +135 -0
  41. package/dist/dev.d.ts +1 -0
  42. package/dist/dev.js +240 -0
  43. package/dist/devtools-client.d.ts +1 -0
  44. package/dist/devtools-client.js +362 -0
  45. package/dist/devtools.d.ts +87 -0
  46. package/dist/devtools.js +68 -0
  47. package/dist/edge.d.ts +3 -0
  48. package/dist/edge.js +7 -0
  49. package/dist/email-signin.d.ts +92 -0
  50. package/dist/email-signin.js +259 -0
  51. package/dist/env.d.ts +1 -0
  52. package/dist/env.js +15 -0
  53. package/dist/explain.d.ts +12 -0
  54. package/dist/explain.js +217 -0
  55. package/dist/files.d.ts +6 -0
  56. package/dist/files.js +170 -0
  57. package/dist/grants.d.ts +69 -0
  58. package/dist/grants.js +206 -0
  59. package/dist/image/bitmap.d.ts +11 -0
  60. package/dist/image/bitmap.js +172 -0
  61. package/dist/image/jpeg.d.ts +10 -0
  62. package/dist/image/jpeg.js +697 -0
  63. package/dist/image/png.d.ts +8 -0
  64. package/dist/image/png.js +282 -0
  65. package/dist/image/transform.d.ts +20 -0
  66. package/dist/image/transform.js +52 -0
  67. package/dist/image/worker.d.ts +1 -0
  68. package/dist/image/worker.js +11 -0
  69. package/dist/images.d.ts +39 -0
  70. package/dist/images.js +283 -0
  71. package/dist/index.d.ts +64 -0
  72. package/dist/index.js +31 -0
  73. package/dist/inspect-hub.d.ts +42 -0
  74. package/dist/inspect-hub.js +14 -0
  75. package/dist/inspector.d.ts +51 -0
  76. package/dist/inspector.js +193 -0
  77. package/dist/job-admin.d.ts +55 -0
  78. package/dist/job-admin.js +89 -0
  79. package/dist/jobs.d.ts +222 -0
  80. package/dist/jobs.js +789 -0
  81. package/dist/live.d.ts +72 -0
  82. package/dist/live.js +481 -0
  83. package/dist/load-config.d.ts +2 -0
  84. package/dist/load-config.js +41 -0
  85. package/dist/log.d.ts +20 -0
  86. package/dist/log.js +143 -0
  87. package/dist/mail.d.ts +189 -0
  88. package/dist/mail.js +999 -0
  89. package/dist/media.d.ts +129 -0
  90. package/dist/media.js +470 -0
  91. package/dist/meta.d.ts +54 -0
  92. package/dist/meta.js +146 -0
  93. package/dist/middleware.d.ts +20 -0
  94. package/dist/middleware.js +101 -0
  95. package/dist/migrate.d.ts +12 -0
  96. package/dist/migrate.js +88 -0
  97. package/dist/node.d.ts +26 -0
  98. package/dist/node.js +96 -0
  99. package/dist/notice.d.ts +21 -0
  100. package/dist/notice.js +48 -0
  101. package/dist/npm.d.ts +16 -0
  102. package/dist/npm.js +347 -0
  103. package/dist/oauth.d.ts +76 -0
  104. package/dist/oauth.js +408 -0
  105. package/dist/otel.d.ts +57 -0
  106. package/dist/otel.js +293 -0
  107. package/dist/passkey.d.ts +99 -0
  108. package/dist/passkey.js +572 -0
  109. package/dist/password.d.ts +8 -0
  110. package/dist/password.js +65 -0
  111. package/dist/pdf.d.ts +46 -0
  112. package/dist/pdf.js +332 -0
  113. package/dist/personal-data.d.ts +22 -0
  114. package/dist/personal-data.js +148 -0
  115. package/dist/pointers.d.ts +9 -0
  116. package/dist/pointers.js +148 -0
  117. package/dist/postcss.d.ts +3 -0
  118. package/dist/postcss.js +89 -0
  119. package/dist/presence.d.ts +27 -0
  120. package/dist/presence.js +161 -0
  121. package/dist/preview.d.ts +25 -0
  122. package/dist/preview.js +353 -0
  123. package/dist/production.d.ts +16 -0
  124. package/dist/production.js +119 -0
  125. package/dist/project.d.ts +23 -0
  126. package/dist/project.js +536 -0
  127. package/dist/regions.d.ts +47 -0
  128. package/dist/regions.js +511 -0
  129. package/dist/replay.d.ts +44 -0
  130. package/dist/replay.js +259 -0
  131. package/dist/router.d.ts +29 -0
  132. package/dist/router.js +146 -0
  133. package/dist/rules-diff.d.ts +18 -0
  134. package/dist/rules-diff.js +165 -0
  135. package/dist/rules-test.d.ts +17 -0
  136. package/dist/rules-test.js +108 -0
  137. package/dist/saml.d.ts +160 -0
  138. package/dist/saml.js +959 -0
  139. package/dist/seal.d.ts +35 -0
  140. package/dist/seal.js +107 -0
  141. package/dist/secret.d.ts +14 -0
  142. package/dist/secret.js +110 -0
  143. package/dist/security.d.ts +53 -0
  144. package/dist/security.js +250 -0
  145. package/dist/seed.d.ts +16 -0
  146. package/dist/seed.js +94 -0
  147. package/dist/seo.d.ts +42 -0
  148. package/dist/seo.js +175 -0
  149. package/dist/settings.d.ts +79 -0
  150. package/dist/settings.js +212 -0
  151. package/dist/shared.d.ts +15 -0
  152. package/dist/shared.js +283 -0
  153. package/dist/shell.d.ts +12 -0
  154. package/dist/shell.js +118 -0
  155. package/dist/storage.d.ts +13 -0
  156. package/dist/storage.js +55 -0
  157. package/dist/support.d.ts +83 -0
  158. package/dist/support.js +236 -0
  159. package/dist/sync.d.ts +35 -0
  160. package/dist/sync.js +167 -0
  161. package/dist/tailwind.d.ts +14 -0
  162. package/dist/tailwind.js +117 -0
  163. package/dist/two-factor.d.ts +103 -0
  164. package/dist/two-factor.js +435 -0
  165. package/dist/uploads.d.ts +185 -0
  166. package/dist/uploads.js +991 -0
  167. package/dist/webhooks.d.ts +169 -0
  168. package/dist/webhooks.js +758 -0
  169. package/dist/webpush.d.ts +97 -0
  170. package/dist/webpush.js +372 -0
  171. package/dist/wizard.d.ts +141 -0
  172. package/dist/wizard.js +410 -0
  173. package/dist/workflows.d.ts +134 -0
  174. package/dist/workflows.js +511 -0
  175. package/package.json +186 -4
@@ -0,0 +1,108 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { realpathSync, rmSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { parseArgs } from "node:util";
6
+ import { fuzzRules } from "@weft-framework/data";
7
+ import { CompileError, findCompiler } from "./compiler.js";
8
+ import { ConfigError } from "./config.js";
9
+ import { ProjectError, loadProject } from "./project.js";
10
+ export class RulesTestError extends Error {
11
+ }
12
+ const EXPLAIN = Symbol.for("weft.access.explain");
13
+ const short = (v) => {
14
+ const s = JSON.stringify(v) ?? String(v);
15
+ return s.length > 200 ? s.slice(0, 199) + "…" : s;
16
+ };
17
+ export function rulesReportText(r) {
18
+ const bad = r.findings.filter((f) => f.kind === "hole" || f.kind === "missing");
19
+ const head = `Model ${r.model}: ${r.checks} checks, read passed ${r.passed.read}, write passed ${r.passed.write}`;
20
+ const lines = [`${head}: ${bad.length ? "FAILED" : "ok"}`];
21
+ const dead = r.findings.filter((f) => f.kind === "unreachable");
22
+ const closed = dead.length === 2;
23
+ if (closed) {
24
+ lines.push(" note: closed to every generated actor (a library's model, whose rules admit only its own code?)");
25
+ }
26
+ for (const f of r.findings) {
27
+ if (closed && f.kind === "unreachable")
28
+ continue;
29
+ const level = f.kind === "hole" || f.kind === "missing" ? "error" : "warning";
30
+ lines.push(` ${level} (${f.kind}, ${f.rule}, ${f.store}): ${f.message}`);
31
+ if ("actor" in f)
32
+ lines.push(` actor: ${short(f.actor)}`);
33
+ if ("row" in f)
34
+ lines.push(` row: ${short(f.row)}`);
35
+ }
36
+ return lines.join("\n");
37
+ }
38
+ export async function testRules(root, opts) {
39
+ root = resolve(root);
40
+ const outDir = join(root, ".weft", "rules", randomUUID());
41
+ try {
42
+ const project = await loadProject(root, { compiler: opts.compiler, outDir, browserAssets: false, cacheKey: outDir });
43
+ const { openSqlite } = await import("@weft-framework/data/sqlite");
44
+ let models = Object.values(project.models).filter((m) => typeof m[EXPLAIN] !== "function");
45
+ if (opts.model !== undefined) {
46
+ models = models.filter((m) => m.name === opts.model);
47
+ if (models.length === 0)
48
+ throw new RulesTestError(`no model ${opts.model} in src/models`);
49
+ }
50
+ models.sort((a, b) => a.name.localeCompare(b.name));
51
+ const reports = models.map((m) => fuzzRules(m, { runs: opts.runs, seed: opts.seed, database: () => openSqlite(":memory:") }));
52
+ const ok = reports.every((r) => !r.findings.some((f) => f.kind === "hole" || f.kind === "missing"));
53
+ const text = reports.length ? reports.map(rulesReportText).join("\n\n") + "\n" : "No models in src/models.\n";
54
+ return { reports, ok, text };
55
+ }
56
+ finally {
57
+ rmSync(outDir, { recursive: true, force: true });
58
+ }
59
+ }
60
+ const whole = (name, v) => {
61
+ if (v === undefined)
62
+ return undefined;
63
+ const n = Number(v);
64
+ if (!Number.isSafeInteger(n) || n < (name === "--seed" ? 0 : 1))
65
+ throw new RulesTestError(`${name} is a whole number`);
66
+ return n;
67
+ };
68
+ async function main() {
69
+ try {
70
+ const { values, positionals } = parseArgs({
71
+ allowPositionals: true,
72
+ options: { runs: { type: "string" }, seed: { type: "string" }, model: { type: "string" } },
73
+ });
74
+ const root = resolve(positionals[0] ?? ".");
75
+ const result = await testRules(root, {
76
+ compiler: findCompiler(root),
77
+ runs: whole("--runs", values.runs),
78
+ seed: whole("--seed", values.seed),
79
+ model: values.model,
80
+ });
81
+ process.stdout.write(result.text);
82
+ if (!result.ok)
83
+ process.exit(1);
84
+ }
85
+ catch (err) {
86
+ if (err instanceof CompileError) {
87
+ console.error(err.diagnostics);
88
+ }
89
+ else if (err instanceof RulesTestError || err instanceof ProjectError || err instanceof ConfigError) {
90
+ console.error(`[weft] ${err.message}`);
91
+ }
92
+ else {
93
+ console.error("[weft] test rules:", err instanceof Error ? err.message : err);
94
+ }
95
+ process.exit(1);
96
+ }
97
+ }
98
+ function isEntry() {
99
+ try {
100
+ return !!process.argv[1] && realpathSync(process.argv[1]) === realpathSync(fileURLToPath(import.meta.url));
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ }
106
+ if (isEntry()) {
107
+ await main();
108
+ }
package/dist/saml.d.ts ADDED
@@ -0,0 +1,160 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ import { type Identity } from "./oauth.js";
3
+ import { type Secret } from "./secret.js";
4
+ type Maybe<T> = T | Promise<T>;
5
+ export interface SamlConnection {
6
+ id: string;
7
+ tenant?: string | null;
8
+ idpEntityId: string;
9
+ ssoUrl: string;
10
+ sloUrl?: string;
11
+ sloResponseUrl?: string;
12
+ certificates: string[];
13
+ ignoreCertificateExpiry?: boolean;
14
+ emailDomains?: string[];
15
+ subjectAttribute?: string;
16
+ nameIdFormat?: string;
17
+ allowSha1?: boolean;
18
+ signRequests?: boolean;
19
+ }
20
+ export interface SamlReplayStore {
21
+ claim(key: string, untilMs: number): Maybe<boolean>;
22
+ }
23
+ export interface SamlSpKey {
24
+ privateKey: Secret | string;
25
+ certificate: string;
26
+ }
27
+ export interface SamlLogoutSubject {
28
+ connection: string;
29
+ tenant: string | null;
30
+ nameId: string;
31
+ sessionIndexes: string[];
32
+ }
33
+ export interface SamlOptions {
34
+ connection(id: string): Maybe<SamlConnection | null | undefined>;
35
+ sp?: {
36
+ keys: SamlSpKey[];
37
+ };
38
+ userFor?(subject: SamlLogoutSubject): Maybe<string | null | undefined>;
39
+ attributes?: {
40
+ email?: string[];
41
+ name?: string[];
42
+ };
43
+ skewSeconds?: number;
44
+ maxAgeSeconds?: number;
45
+ replay?: SamlReplayStore;
46
+ now?: () => number;
47
+ }
48
+ export interface SamlCert {
49
+ readonly pem: string;
50
+ readonly subject: string;
51
+ readonly notBefore: number;
52
+ readonly notAfter: number;
53
+ readonly fingerprint256: string;
54
+ }
55
+ export interface CheckedSamlConnection extends Omit<SamlConnection, "certificates" | "emailDomains" | "sloUrl" | "sloResponseUrl"> {
56
+ readonly certificates: readonly SamlCert[];
57
+ readonly emailDomains: readonly string[];
58
+ readonly sloUrl: string | null;
59
+ readonly sloResponseUrl: string | null;
60
+ }
61
+ export interface SamlCertificateInfo {
62
+ use: "idp-signing" | "sp";
63
+ subject: string;
64
+ fingerprint256: string;
65
+ notBefore: Date;
66
+ notAfter: Date;
67
+ daysLeft: number;
68
+ valid: boolean;
69
+ }
70
+ export interface SamlResult {
71
+ identity: Identity;
72
+ inResponseTo: string;
73
+ assertionId: string;
74
+ expires: number;
75
+ }
76
+ export interface SamlSessionRef {
77
+ c: string;
78
+ n: string;
79
+ f: string | null;
80
+ s: string | null;
81
+ nq?: string;
82
+ spnq?: string;
83
+ }
84
+ export type SamlLogoutMessage = {
85
+ kind: "request";
86
+ id: string;
87
+ nameId: string;
88
+ sessionIndexes: string[];
89
+ relay: string | null;
90
+ expires: number;
91
+ } | {
92
+ kind: "response";
93
+ inResponseTo: string | null;
94
+ success: boolean;
95
+ };
96
+ export interface Saml {
97
+ startPath(id: string, next?: string): string;
98
+ logoutPath(): string;
99
+ spEntityId(base: string, id: string): string;
100
+ acsUrl(base: string, id: string): string;
101
+ sloUrl(base: string, id: string): string;
102
+ metadata(base: string, connection: CheckedSamlConnection): string;
103
+ describeCertificates(connection: SamlConnection | CheckedSamlConnection): SamlCertificateInfo[];
104
+ resolve(id: string): Promise<CheckedSamlConnection | null>;
105
+ authorize(connection: CheckedSamlConnection, o: {
106
+ requestId: string;
107
+ base: string;
108
+ }): string;
109
+ verify(connection: CheckedSamlConnection, response: string, o: {
110
+ base: string;
111
+ }): SamlResult;
112
+ logoutRequest(connection: CheckedSamlConnection, ref: SamlSessionRef, o: {
113
+ requestId: string;
114
+ base: string;
115
+ }): string | null;
116
+ logoutResponse(connection: CheckedSamlConnection, o: {
117
+ inResponseTo: string;
118
+ base: string;
119
+ relay: string | null;
120
+ }): string | null;
121
+ readLogout(connection: CheckedSamlConnection, o: {
122
+ search: string;
123
+ form: URLSearchParams | null;
124
+ base: string;
125
+ }): SamlLogoutMessage;
126
+ userFor(subject: SamlLogoutSubject): Promise<string | null>;
127
+ claim(key: string, untilMs: number): Promise<boolean>;
128
+ newRequestId(): string;
129
+ }
130
+ export declare const SAML_ID: RegExp;
131
+ export declare const MAX_SAML_RESPONSE: number;
132
+ interface SpKey {
133
+ key: KeyObject;
134
+ cert: SamlCert;
135
+ }
136
+ export declare function checkSamlConnection(c: SamlConnection): CheckedSamlConnection;
137
+ interface VerifyOptions {
138
+ acsUrl: string;
139
+ spEntityId: string;
140
+ now: number;
141
+ skewMs: number;
142
+ maxAgeMs: number;
143
+ emailNames: string[];
144
+ nameNames: string[];
145
+ keys: readonly SpKey[];
146
+ }
147
+ export declare function verifySamlResponse(c: CheckedSamlConnection, response: string, o: VerifyOptions): SamlResult;
148
+ export declare function samlSessionRef(identity: Identity): SamlSessionRef | null;
149
+ export interface IdpMetadata {
150
+ entityId: string;
151
+ ssoUrl: string;
152
+ sloUrl: string | null;
153
+ sloResponseUrl: string | null;
154
+ certificates: string[];
155
+ }
156
+ export declare function parseIdpMetadata(xml: string, o?: {
157
+ entityId?: string;
158
+ }): IdpMetadata;
159
+ export declare function defineSaml(o: SamlOptions): Saml;
160
+ export {};