@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/bun.js ADDED
@@ -0,0 +1,53 @@
1
+ export function forwarded(req) {
2
+ const first = (name) => req.headers.get(name)?.split(",")[0].trim() || undefined;
3
+ const proto = first("x-forwarded-proto");
4
+ const host = first("x-forwarded-host");
5
+ if (!proto && !host) {
6
+ return req;
7
+ }
8
+ const url = new URL(req.url);
9
+ if (proto === "http" || proto === "https") {
10
+ url.protocol = `${proto}:`;
11
+ }
12
+ if (host) {
13
+ try {
14
+ const parsed = new URL(`http://${host}`);
15
+ if (parsed.username === "" && parsed.password === "" && parsed.pathname === "/" && !parsed.search) {
16
+ url.hostname = parsed.hostname;
17
+ url.port = parsed.port;
18
+ }
19
+ }
20
+ catch {
21
+ }
22
+ }
23
+ return url.href === req.url ? req : new Request(url, req);
24
+ }
25
+ export function serveBun(app, opts = {}, bun) {
26
+ const api = bun ?? globalThis.Bun;
27
+ if (!api) {
28
+ throw new Error("serveBun: not running on Bun (no global `Bun`)");
29
+ }
30
+ const onError = opts.onError ?? ((err) => console.error("[weft]", err));
31
+ const server = api.serve({
32
+ port: opts.port ?? 3000,
33
+ hostname: opts.hostname ?? "127.0.0.1",
34
+ idleTimeout: Math.min(255, Math.max(0, opts.idleTimeout ?? 60)),
35
+ fetch: (req, srv) => app.fetch(opts.trustProxy ? forwarded(req) : req, srv),
36
+ error(err) {
37
+ onError(err);
38
+ return new Response("Internal Server Error", { status: 500, headers: { "content-type": "text/plain" } });
39
+ },
40
+ websocket: {
41
+ open: (ws) => app.websocket.open(ws),
42
+ message: (ws, data) => app.websocket.message(ws, data),
43
+ close: (ws) => app.websocket.close(ws),
44
+ sendPings: true,
45
+ },
46
+ });
47
+ return {
48
+ url: server.url.href,
49
+ close: async () => {
50
+ await server.stop(true);
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,161 @@
1
+ import type { SqlDatabase } from "@weft-framework/data";
2
+ import type { PageContext } from "./context.js";
3
+ import type { Job, JobContext, Jobs } from "./jobs.js";
4
+ export declare function isTimeZone(tz: unknown): tz is string;
5
+ export interface WallTime {
6
+ year: number;
7
+ month: number;
8
+ day: number;
9
+ hour: number;
10
+ minute: number;
11
+ weekday: number;
12
+ date: string;
13
+ time: string;
14
+ }
15
+ export declare function wallTime(ms: number, tz: string): WallTime;
16
+ export declare function zonedTime(tz: string, date: string, time?: string): number;
17
+ declare const WEEKDAYS: readonly ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
18
+ export type Weekday = (typeof WEEKDAYS)[number];
19
+ export interface Recurrence {
20
+ freq: "daily" | "weekly" | "monthly" | "yearly";
21
+ interval?: number;
22
+ count?: number;
23
+ until?: string;
24
+ byDay?: readonly string[];
25
+ byMonthDay?: readonly number[];
26
+ byMonth?: readonly number[];
27
+ except?: readonly string[];
28
+ }
29
+ export interface EventTime {
30
+ date: string;
31
+ time: string;
32
+ duration: number;
33
+ timeZone: string;
34
+ repeat?: Recurrence;
35
+ }
36
+ export interface Occurrence {
37
+ start: number;
38
+ end: number;
39
+ date: string;
40
+ }
41
+ export declare function parseRecurrence(text: string): Recurrence;
42
+ export declare function occurrences(e: EventTime, from: number, to: number, max?: number): Occurrence[];
43
+ type Ranges = readonly (readonly [string, string])[];
44
+ declare const DAY_KEYS: readonly ["mon", "tue", "wed", "thu", "fri", "sat", "sun"];
45
+ export interface Availability {
46
+ timeZone: string;
47
+ hours: Partial<Record<(typeof DAY_KEYS)[number], Ranges>>;
48
+ dates?: Readonly<Record<string, Ranges>>;
49
+ duration: number;
50
+ step?: number;
51
+ bufferBefore?: number;
52
+ bufferAfter?: number;
53
+ minNotice?: number;
54
+ maxDaysAhead?: number;
55
+ capacity?: number;
56
+ }
57
+ export interface Slot {
58
+ start: number;
59
+ end: number;
60
+ }
61
+ export interface Busy {
62
+ start: number;
63
+ end: number;
64
+ }
65
+ export declare function checkAvailability(a: Availability): Required<Omit<Availability, "dates">> & Pick<Availability, "dates">;
66
+ export declare function availableSlots(a: Availability, o: {
67
+ from: number;
68
+ to: number;
69
+ now: number;
70
+ busy?: readonly Busy[];
71
+ max?: number;
72
+ }): Slot[];
73
+ export interface Booking {
74
+ id: string;
75
+ resource: string;
76
+ owner: string;
77
+ start: number;
78
+ end: number;
79
+ blockStart: number;
80
+ blockEnd: number;
81
+ status: "active" | "cancelled";
82
+ note: string;
83
+ created: number;
84
+ reminders: string[];
85
+ }
86
+ export interface BookingStore {
87
+ insert(b: Booking, capacity: number): boolean | Promise<boolean>;
88
+ get(id: string): Booking | null | Promise<Booking | null>;
89
+ move(id: string, to: Pick<Booking, "start" | "end" | "blockStart" | "blockEnd">, capacity: number): boolean | Promise<boolean>;
90
+ update(id: string, patch: Partial<Pick<Booking, "status" | "reminders">>): void | Promise<void>;
91
+ overlapping(resource: string, from: number, to: number): Booking[] | Promise<Booking[]>;
92
+ byOwner(owner: string, from: number, to: number): Booking[] | Promise<Booking[]>;
93
+ }
94
+ export interface BookingsOptions {
95
+ name: string;
96
+ store: BookingStore;
97
+ resource(id: string, ctx: PageContext | null): Availability | null | Promise<Availability | null>;
98
+ allow?(ctx: PageContext, resource: string): boolean | Promise<boolean>;
99
+ manage?(ctx: PageContext, resource: string): boolean | Promise<boolean>;
100
+ changeUntil?: number;
101
+ reminders?: {
102
+ before: readonly number[];
103
+ send(job: JobContext, booking: Booking, minutesBefore: number): unknown;
104
+ };
105
+ now?(): number;
106
+ }
107
+ export type BookResult = {
108
+ ok: true;
109
+ booking: Booking;
110
+ } | {
111
+ ok: false;
112
+ reason: "not-found" | "forbidden" | "unavailable" | "too-late" | "invalid";
113
+ };
114
+ export interface Bookings {
115
+ readonly name: string;
116
+ readonly job: Job<[string, number]>;
117
+ use(jobs: Jobs): this;
118
+ slots(ctx: PageContext | null, resource: string, range: {
119
+ from: number;
120
+ to: number;
121
+ }): Promise<Slot[]>;
122
+ book(ctx: PageContext, resource: string, start: number, o?: {
123
+ note?: string;
124
+ }): Promise<BookResult>;
125
+ cancel(ctx: PageContext, id: string): Promise<BookResult>;
126
+ reschedule(ctx: PageContext, id: string, start: number): Promise<BookResult>;
127
+ mine(ctx: PageContext, range: {
128
+ from: number;
129
+ to: number;
130
+ }): Promise<Booking[]>;
131
+ forResource(ctx: PageContext, resource: string, range: {
132
+ from: number;
133
+ to: number;
134
+ }): Promise<Booking[] | null>;
135
+ get(ctx: PageContext, id: string): Promise<Booking | null>;
136
+ }
137
+ export declare function defineBookings(o: BookingsOptions): Bookings;
138
+ export declare class MemoryBookingStore implements BookingStore {
139
+ private readonly rows;
140
+ private count;
141
+ insert(b: Booking, capacity: number): boolean;
142
+ get(id: string): Booking | null;
143
+ move(id: string, to: Pick<Booking, "start" | "end" | "blockStart" | "blockEnd">, capacity: number): boolean;
144
+ update(id: string, patch: Partial<Pick<Booking, "status" | "reminders">>): void;
145
+ overlapping(resource: string, from: number, to: number): Booking[];
146
+ byOwner(owner: string, from: number, to: number): Booking[];
147
+ }
148
+ export declare class SqlBookingStore implements BookingStore {
149
+ private readonly db;
150
+ private readonly t;
151
+ constructor(db: SqlDatabase, table?: string);
152
+ private row;
153
+ private busyCount;
154
+ insert(b: Booking, capacity: number): boolean;
155
+ get(id: string): Booking | null;
156
+ move(id: string, to: Pick<Booking, "start" | "end" | "blockStart" | "blockEnd">, capacity: number): boolean;
157
+ update(id: string, patch: Partial<Pick<Booking, "status" | "reminders">>): void;
158
+ overlapping(resource: string, from: number, to: number): Booking[];
159
+ byOwner(owner: string, from: number, to: number): Booking[];
160
+ }
161
+ export { DAY_KEYS as WEEKDAY_KEYS };