@weft-framework/server 0.0.0-stage → 0.0.1

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
package/dist/log.js ADDED
@@ -0,0 +1,143 @@
1
+ import { Secret } from "./secret.js";
2
+ const RANK = { debug: 10, info: 20, warn: 30, error: 40 };
3
+ const DEFAULT_REDACT = /pass(word|phrase)?|secret|token|authori[sz]ation|cookie|api[-_]?key|private[-_]?key|credential/i;
4
+ const MAX_DEPTH = 6;
5
+ const MAX_STRING = 4096;
6
+ const MAX_KEYS = 100;
7
+ export function redact(value, keys = DEFAULT_REDACT) {
8
+ const seen = new WeakSet();
9
+ const walk = (v, depth) => {
10
+ if (v instanceof Secret)
11
+ return "[secret]";
12
+ if (v === null || typeof v === "boolean")
13
+ return v;
14
+ if (typeof v === "number")
15
+ return Number.isFinite(v) ? v : String(v);
16
+ if (typeof v === "string")
17
+ return v.length > MAX_STRING ? `${v.slice(0, MAX_STRING)}...[${v.length - MAX_STRING} more]` : v;
18
+ if (typeof v === "bigint")
19
+ return v.toString();
20
+ if (typeof v === "undefined" || typeof v === "function" || typeof v === "symbol")
21
+ return undefined;
22
+ if (v instanceof Date)
23
+ return Number.isNaN(v.getTime()) ? "Invalid Date" : v.toISOString();
24
+ if (v instanceof Uint8Array || v instanceof ArrayBuffer)
25
+ return `[${v.byteLength} bytes]`;
26
+ if (typeof v !== "object")
27
+ return undefined;
28
+ if (seen.has(v))
29
+ return "[circular]";
30
+ if (depth >= MAX_DEPTH)
31
+ return "[object]";
32
+ seen.add(v);
33
+ try {
34
+ if (v instanceof Error) {
35
+ const out = { name: v.name, message: walk(v.message, depth + 1) };
36
+ if (v.stack)
37
+ out.stack = walk(v.stack, depth + 1);
38
+ if ("code" in v)
39
+ out.code = walk(v.code, depth + 1);
40
+ if (v.cause !== undefined)
41
+ out.cause = walk(v.cause, depth + 1);
42
+ return out;
43
+ }
44
+ if (Array.isArray(v)) {
45
+ const list = v.slice(0, MAX_KEYS).map((x) => walk(x, depth + 1) ?? null);
46
+ if (v.length > MAX_KEYS)
47
+ list.push(`[${v.length - MAX_KEYS} more]`);
48
+ return list;
49
+ }
50
+ if (v instanceof Map)
51
+ return walk(Object.fromEntries([...v].slice(0, MAX_KEYS).map(([k, x]) => [String(k), x])), depth);
52
+ if (v instanceof Set)
53
+ return walk([...v], depth);
54
+ const out = {};
55
+ let n = 0;
56
+ for (const k of Object.keys(v)) {
57
+ if (++n > MAX_KEYS) {
58
+ out["..."] = `${Object.keys(v).length - MAX_KEYS} more keys`;
59
+ break;
60
+ }
61
+ keys.lastIndex = 0;
62
+ if (keys.test(k)) {
63
+ out[k] = "[redacted]";
64
+ continue;
65
+ }
66
+ let x;
67
+ try {
68
+ x = v[k];
69
+ }
70
+ catch {
71
+ x = "[unreadable]";
72
+ }
73
+ const w = walk(x, depth + 1);
74
+ if (w !== undefined)
75
+ out[k] = w;
76
+ }
77
+ return out;
78
+ }
79
+ finally {
80
+ seen.delete(v);
81
+ }
82
+ };
83
+ return walk(value, 0);
84
+ }
85
+ export function createLogger(o = {}) {
86
+ const level = o.level ?? "info";
87
+ if (!(level in RANK))
88
+ throw new Error(`createLogger: level is debug, info, warn or error`);
89
+ const keys = o.redactKeys ?? DEFAULT_REDACT;
90
+ if (!(keys instanceof RegExp))
91
+ throw new Error("createLogger: redactKeys is a regular expression");
92
+ const write = o.write ??
93
+ ((line, l) => {
94
+ if (l === "error")
95
+ console.error(line);
96
+ else
97
+ console.log(line);
98
+ });
99
+ const now = o.now ?? Date.now;
100
+ const make = (base) => {
101
+ const emit = (l, msg, fields) => {
102
+ if (RANK[l] < RANK[level])
103
+ return;
104
+ try {
105
+ const body = redact({ ...base, ...fields }, keys);
106
+ const head = { time: new Date(now()).toISOString(), level: l, msg: String(msg) };
107
+ const clash = {};
108
+ for (const k of Object.keys(head)) {
109
+ if (k in body) {
110
+ clash[k] = body[k];
111
+ delete body[k];
112
+ }
113
+ }
114
+ const line = JSON.stringify({ ...head, ...body, ...(Object.keys(clash).length ? { fields: clash } : {}) });
115
+ write(line, l);
116
+ }
117
+ catch {
118
+ }
119
+ };
120
+ return {
121
+ level,
122
+ debug: (m, f) => emit("debug", m, f),
123
+ info: (m, f) => emit("info", m, f),
124
+ warn: (m, f) => emit("warn", m, f),
125
+ error: (m, f) => emit("error", m, f),
126
+ child: (fields) => make({ ...base, ...fields }),
127
+ };
128
+ };
129
+ return make({ ...(o.base ?? {}) });
130
+ }
131
+ const ids = new WeakMap();
132
+ const INCOMING_ID = /^[A-Za-z0-9._:-]{8,128}$/;
133
+ export function assignRequestId(req, trustIncoming) {
134
+ const incoming = req.headers.get("x-request-id");
135
+ const id = trustIncoming && incoming && INCOMING_ID.test(incoming)
136
+ ? incoming
137
+ : Array.from(crypto.getRandomValues(new Uint8Array(12)), (b) => b.toString(16).padStart(2, "0")).join("");
138
+ ids.set(req, id);
139
+ return id;
140
+ }
141
+ export function requestIdOf(req) {
142
+ return ids.get(req) ?? null;
143
+ }
package/dist/mail.d.ts ADDED
@@ -0,0 +1,189 @@
1
+ import { type Component } from "@weft-framework/runtime";
2
+ import { type Job, type Jobs } from "./jobs.js";
3
+ import type { PageContext } from "./context.js";
4
+ import { type Secret } from "./secret.js";
5
+ type Fetch = (input: string, init: RequestInit) => Promise<Response>;
6
+ export type AddressInput = string | {
7
+ name?: string;
8
+ email: string;
9
+ };
10
+ export interface Address {
11
+ name: string;
12
+ email: string;
13
+ }
14
+ export interface AttachmentInput {
15
+ filename: string;
16
+ content: Uint8Array | string;
17
+ contentType?: string;
18
+ }
19
+ export interface MailMessage {
20
+ from?: AddressInput;
21
+ to: AddressInput | AddressInput[];
22
+ cc?: AddressInput | AddressInput[];
23
+ bcc?: AddressInput | AddressInput[];
24
+ replyTo?: AddressInput | AddressInput[];
25
+ subject: string;
26
+ text?: string;
27
+ html?: string | {
28
+ toString(): string;
29
+ };
30
+ headers?: Record<string, string>;
31
+ attachments?: AttachmentInput[];
32
+ tags?: Record<string, string>;
33
+ }
34
+ export interface Attachment {
35
+ filename: string;
36
+ content: Uint8Array;
37
+ contentType: string;
38
+ }
39
+ export interface OutgoingMail {
40
+ from: Address;
41
+ to: Address[];
42
+ cc: Address[];
43
+ bcc: Address[];
44
+ replyTo: Address[];
45
+ subject: string;
46
+ text: string;
47
+ html: string | null;
48
+ headers: [string, string][];
49
+ attachments: Attachment[];
50
+ tags: [string, string][];
51
+ messageId: string;
52
+ date: Date;
53
+ }
54
+ export type MailErrorCode = "invalid" | "rejected" | "unavailable";
55
+ export declare class MailError extends Error {
56
+ readonly code: MailErrorCode;
57
+ readonly permanent: boolean;
58
+ constructor(code: MailErrorCode, message: string, opts?: {
59
+ permanent?: boolean;
60
+ cause?: unknown;
61
+ });
62
+ }
63
+ export declare function parseAddress(input: AddressInput): Address;
64
+ export declare function prepareMail(m: MailMessage, o: {
65
+ from: Address;
66
+ maxBytes: number;
67
+ messageId?: string;
68
+ date?: Date;
69
+ }): OutgoingMail;
70
+ export declare function htmlToText(html: string): string;
71
+ export declare function quotedPrintable(text: string): string;
72
+ export declare function buildMime(m: OutgoingMail): string;
73
+ export interface SendResult {
74
+ id: string | null;
75
+ }
76
+ export interface MailTransport {
77
+ readonly name: string;
78
+ send(mail: OutgoingMail): Promise<SendResult>;
79
+ }
80
+ interface HttpOptions {
81
+ fetch?: Fetch;
82
+ timeoutMs?: number;
83
+ }
84
+ export declare function resend(o: HttpOptions & {
85
+ apiKey: string | Secret;
86
+ endpoint?: string;
87
+ }): MailTransport;
88
+ export declare function postmark(o: HttpOptions & {
89
+ serverToken: string | Secret;
90
+ messageStream?: string;
91
+ endpoint?: string;
92
+ }): MailTransport;
93
+ export interface AwsCredentials {
94
+ accessKeyId: string;
95
+ secretAccessKey: string | Secret;
96
+ sessionToken?: string | Secret;
97
+ }
98
+ export declare function signAwsRequest(r: {
99
+ method: string;
100
+ url: string;
101
+ region: string;
102
+ service: string;
103
+ credentials: AwsCredentials;
104
+ headers?: Record<string, string>;
105
+ body?: string;
106
+ now?: Date;
107
+ }): Promise<Record<string, string>>;
108
+ export declare function ses(o: HttpOptions & AwsCredentials & {
109
+ region: string;
110
+ configurationSet?: string;
111
+ endpoint?: string;
112
+ }): MailTransport;
113
+ export interface SmtpOptions {
114
+ host: string;
115
+ port?: number;
116
+ tls?: "implicit" | "starttls" | "none";
117
+ user?: string;
118
+ pass?: string | Secret;
119
+ name?: string;
120
+ timeoutMs?: number;
121
+ tlsOptions?: {
122
+ ca?: string | string[];
123
+ servername?: string;
124
+ };
125
+ }
126
+ export declare function smtp(o: SmtpOptions): MailTransport;
127
+ export interface SentMail {
128
+ mail: OutgoingMail;
129
+ raw: string;
130
+ at: Date;
131
+ }
132
+ export declare class Outbox implements MailTransport {
133
+ #private;
134
+ readonly name = "outbox";
135
+ readonly sent: SentMail[];
136
+ constructor(opts?: {
137
+ limit?: number;
138
+ });
139
+ send(mail: OutgoingMail): Promise<SendResult>;
140
+ last(email?: string): SentMail | undefined;
141
+ clear(): void;
142
+ }
143
+ export declare function mailPreview(req: Request, templates?: Record<string, EmailTemplate>): Response | null;
144
+ export interface MailOptions {
145
+ transport: MailTransport;
146
+ from: AddressInput;
147
+ jobs?: () => Jobs;
148
+ maxBytes?: number;
149
+ jobName?: string;
150
+ attempts?: number;
151
+ }
152
+ export interface Rendered {
153
+ html: string;
154
+ text: string;
155
+ }
156
+ export declare class Mail {
157
+ #private;
158
+ readonly job: Job<[string]>;
159
+ constructor(o: MailOptions);
160
+ prepare(message: MailMessage): OutgoingMail;
161
+ send(message: MailMessage): Promise<SendResult & {
162
+ messageId: string;
163
+ }>;
164
+ queue(ctx: PageContext | null, message: MailMessage, opts?: {
165
+ delayMs?: number;
166
+ key?: string;
167
+ }): Promise<string | false>;
168
+ render<P extends object>(component: Component<P>, props: P, opts?: {
169
+ title?: string;
170
+ lang?: string;
171
+ }): Rendered;
172
+ }
173
+ export declare function renderMail<P extends object>(component: Component<P>, props: P, opts?: {
174
+ title?: string;
175
+ lang?: string;
176
+ }): Rendered;
177
+ export interface EmailTemplate<P extends object = never> extends Template<P> {
178
+ previews: Record<string, object>;
179
+ file: string;
180
+ }
181
+ export interface Template<P extends object> {
182
+ component: Component<P>;
183
+ subject?: string | ((props: P) => string);
184
+ }
185
+ export declare function renderTemplate<P extends object>(t: Template<P>, props: P): Rendered & {
186
+ subject: string | null;
187
+ };
188
+ export declare function defineMail(o: MailOptions): Mail;
189
+ export {};