@trypattern/sdk 0.0.0-stage → 0.1.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.
- package/README.md +127 -2
- package/dist/access.d.ts +31 -0
- package/dist/access.js +72 -0
- package/dist/actions.d.ts +57 -0
- package/dist/actions.js +198 -0
- package/dist/api.d.ts +30 -0
- package/dist/api.js +60 -0
- package/dist/app.d.ts +115 -0
- package/dist/app.js +266 -0
- package/dist/appInfo.d.ts +35 -0
- package/dist/appInfo.js +67 -0
- package/dist/appTitle.d.ts +6 -0
- package/dist/appTitle.js +3 -0
- package/dist/appearance.d.ts +7 -0
- package/dist/appearance.js +2 -0
- package/dist/auth/sessionApi.d.ts +41 -0
- package/dist/auth/sessionApi.js +158 -0
- package/dist/auth/sessionStore.d.ts +20 -0
- package/dist/auth/sessionStore.js +40 -0
- package/dist/auth/user.d.ts +11 -0
- package/dist/auth/user.js +9 -0
- package/dist/builtins/Account.d.ts +25 -0
- package/dist/builtins/Account.js +15 -0
- package/dist/builtins/AppSettings.d.ts +12 -0
- package/dist/builtins/AppSettings.js +31 -0
- package/dist/builtins/Palette.d.ts +29 -0
- package/dist/builtins/Palette.js +63 -0
- package/dist/builtins/SignIn.d.ts +28 -0
- package/dist/builtins/SignIn.js +60 -0
- package/dist/builtins/Toasts.d.ts +32 -0
- package/dist/builtins/Toasts.js +25 -0
- package/dist/builtins/actions.d.ts +2 -0
- package/dist/builtins/actions.js +45 -0
- package/dist/cache.d.ts +24 -0
- package/dist/cache.js +112 -0
- package/dist/cli/app.d.ts +2 -0
- package/dist/cli/app.js +1406 -0
- package/dist/cli/publishing.d.ts +21 -0
- package/dist/cli/publishing.js +493 -0
- package/dist/cli/screenshot.d.ts +1 -0
- package/dist/cli/screenshot.js +96 -0
- package/dist/cli/tools.d.ts +12 -0
- package/dist/cli/tools.js +35 -0
- package/dist/clock.d.ts +6 -0
- package/dist/clock.js +31 -0
- package/dist/components/AppFrame.d.ts +14 -0
- package/dist/components/AppFrame.js +64 -0
- package/dist/components/AppearancePicker.d.ts +1 -0
- package/dist/components/AppearancePicker.js +12 -0
- package/dist/components/Avatar.d.ts +9 -0
- package/dist/components/Avatar.js +63 -0
- package/dist/components/Badge.d.ts +11 -0
- package/dist/components/Badge.js +87 -0
- package/dist/components/Button.d.ts +24 -0
- package/dist/components/Button.js +252 -0
- package/dist/components/Card.d.ts +12 -0
- package/dist/components/Card.js +38 -0
- package/dist/components/CommandMenu.d.ts +23 -0
- package/dist/components/CommandMenu.js +214 -0
- package/dist/components/CommandPalette.d.ts +1 -0
- package/dist/components/CommandPalette.js +7 -0
- package/dist/components/Content.d.ts +7 -0
- package/dist/components/Content.js +24 -0
- package/dist/components/ContextMenu.d.ts +8 -0
- package/dist/components/ContextMenu.js +23 -0
- package/dist/components/CopyButton.d.ts +11 -0
- package/dist/components/CopyButton.js +16 -0
- package/dist/components/Dialog.d.ts +11 -0
- package/dist/components/Dialog.js +81 -0
- package/dist/components/Divider.d.ts +7 -0
- package/dist/components/Divider.js +30 -0
- package/dist/components/EmptyState.d.ts +8 -0
- package/dist/components/EmptyState.js +24 -0
- package/dist/components/Form.d.ts +9 -0
- package/dist/components/Form.js +23 -0
- package/dist/components/Icon.d.ts +10 -0
- package/dist/components/Icon.js +22 -0
- package/dist/components/IconButton.d.ts +14 -0
- package/dist/components/IconButton.js +53 -0
- package/dist/components/Kbd.d.ts +6 -0
- package/dist/components/Kbd.js +67 -0
- package/dist/components/Link.d.ts +14 -0
- package/dist/components/Link.js +44 -0
- package/dist/components/ListRow.d.ts +12 -0
- package/dist/components/ListRow.js +62 -0
- package/dist/components/LoadingRows.d.ts +5 -0
- package/dist/components/LoadingRows.js +6 -0
- package/dist/components/Menu.d.ts +12 -0
- package/dist/components/Menu.js +33 -0
- package/dist/components/MenuItems.d.ts +21 -0
- package/dist/components/MenuItems.js +32 -0
- package/dist/components/Placement.d.ts +21 -0
- package/dist/components/Placement.js +1 -0
- package/dist/components/Popup.d.ts +8 -0
- package/dist/components/Popup.js +43 -0
- package/dist/components/PopupItem.d.ts +8 -0
- package/dist/components/PopupItem.js +51 -0
- package/dist/components/PropertyRow.d.ts +7 -0
- package/dist/components/PropertyRow.js +23 -0
- package/dist/components/RadioGroup.d.ts +18 -0
- package/dist/components/RadioGroup.js +85 -0
- package/dist/components/Row.d.ts +16 -0
- package/dist/components/Row.js +27 -0
- package/dist/components/Screen.d.ts +13 -0
- package/dist/components/Screen.js +56 -0
- package/dist/components/Scrim.d.ts +8 -0
- package/dist/components/Scrim.js +40 -0
- package/dist/components/ScrollArea.d.ts +15 -0
- package/dist/components/ScrollArea.js +13 -0
- package/dist/components/SegmentedControl.d.ts +17 -0
- package/dist/components/SegmentedControl.js +68 -0
- package/dist/components/Select.d.ts +17 -0
- package/dist/components/Select.js +107 -0
- package/dist/components/SettingsRow.d.ts +8 -0
- package/dist/components/SettingsRow.js +32 -0
- package/dist/components/Sidebar.d.ts +20 -0
- package/dist/components/Sidebar.js +137 -0
- package/dist/components/SignInScreen.d.ts +1 -0
- package/dist/components/SignInScreen.js +40 -0
- package/dist/components/Size.d.ts +1 -0
- package/dist/components/Size.js +1 -0
- package/dist/components/Skeleton.d.ts +8 -0
- package/dist/components/Skeleton.js +48 -0
- package/dist/components/Spinner.d.ts +6 -0
- package/dist/components/Spinner.js +54 -0
- package/dist/components/Stack.d.ts +14 -0
- package/dist/components/Stack.js +19 -0
- package/dist/components/Switch.d.ts +10 -0
- package/dist/components/Switch.js +72 -0
- package/dist/components/Text.d.ts +21 -0
- package/dist/components/Text.js +77 -0
- package/dist/components/TextField.d.ts +25 -0
- package/dist/components/TextField.js +68 -0
- package/dist/components/Toaster.d.ts +1 -0
- package/dist/components/Toaster.js +83 -0
- package/dist/components/Tooltip.d.ts +8 -0
- package/dist/components/Tooltip.js +43 -0
- package/dist/components/controlLook.d.ts +70 -0
- package/dist/components/controlLook.js +80 -0
- package/dist/components/frame.d.ts +4 -0
- package/dist/components/frame.js +2 -0
- package/dist/components/icons.d.ts +59 -0
- package/dist/components/icons.js +111 -0
- package/dist/components/interaction.d.ts +12 -0
- package/dist/components/interaction.js +22 -0
- package/dist/components/spacing.d.ts +118 -0
- package/dist/components/spacing.js +46 -0
- package/dist/components/tones.d.ts +28 -0
- package/dist/components/tones.js +12 -0
- package/dist/entityStore.d.ts +46 -0
- package/dist/entityStore.js +160 -0
- package/dist/flows/accessFlows.d.ts +9 -0
- package/dist/flows/accessFlows.js +167 -0
- package/dist/flows/browser.d.ts +34 -0
- package/dist/flows/browser.js +167 -0
- package/dist/flows/contactSheet.d.ts +1 -0
- package/dist/flows/contactSheet.js +63 -0
- package/dist/flows/flowBrowser.d.ts +25 -0
- package/dist/flows/flowBrowser.js +23 -0
- package/dist/flows/flowSetup.d.ts +3 -0
- package/dist/flows/flowSetup.js +35 -0
- package/dist/flows/flows.d.ts +47 -0
- package/dist/flows/flows.js +175 -0
- package/dist/flows/screenshotName.d.ts +1 -0
- package/dist/flows/screenshotName.js +6 -0
- package/dist/gate.d.ts +8 -0
- package/dist/gate.js +52 -0
- package/dist/hooks/appContext.d.ts +15 -0
- package/dist/hooks/appContext.js +5 -0
- package/dist/hooks/appHooks.d.ts +21 -0
- package/dist/hooks/appHooks.js +24 -0
- package/dist/hooks/useAnimatesOnChange.d.ts +1 -0
- package/dist/hooks/useAnimatesOnChange.js +14 -0
- package/dist/hooks/useStoreState.d.ts +6 -0
- package/dist/hooks/useStoreState.js +5 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +21 -0
- package/dist/memoryApi.d.ts +19 -0
- package/dist/memoryApi.js +42 -0
- package/dist/model.d.ts +94 -0
- package/dist/model.js +243 -0
- package/dist/page.d.ts +11 -0
- package/dist/page.js +9 -0
- package/dist/platform.d.ts +1 -0
- package/dist/platform.js +5 -0
- package/dist/publishWire.d.ts +271 -0
- package/dist/publishWire.js +168 -0
- package/dist/react.d.ts +49 -0
- package/dist/react.js +40 -0
- package/dist/registered.d.ts +60 -0
- package/dist/registered.js +19 -0
- package/dist/routes.d.ts +38 -0
- package/dist/routes.js +21 -0
- package/dist/rules/checkAllFiles.d.ts +1 -0
- package/dist/rules/checkAllFiles.js +749 -0
- package/dist/rules/checkApiRouting.d.ts +1 -0
- package/dist/rules/checkApiRouting.js +112 -0
- package/dist/rules/lintPlugin.d.ts +252 -0
- package/dist/rules/lintPlugin.js +1159 -0
- package/dist/rules/messages.d.ts +48 -0
- package/dist/rules/messages.js +48 -0
- package/dist/rules/themeTokens.d.ts +6 -0
- package/dist/rules/themeTokens.js +64 -0
- package/dist/schema.d.ts +4 -0
- package/dist/schema.js +2 -0
- package/dist/server/auth.d.ts +115 -0
- package/dist/server/auth.js +134 -0
- package/dist/server/authService.d.ts +9 -0
- package/dist/server/authService.js +50 -0
- package/dist/server/createServer.d.ts +402 -0
- package/dist/server/createServer.js +82 -0
- package/dist/server/env.d.ts +15 -0
- package/dist/server/env.js +1 -0
- package/dist/server/index.d.ts +13 -0
- package/dist/server/index.js +9 -0
- package/dist/server/services.d.ts +9 -0
- package/dist/server/services.js +47 -0
- package/dist/server/session.d.ts +29 -0
- package/dist/server/session.js +65 -0
- package/dist/server/sessions.d.ts +92 -0
- package/dist/server/sessions.js +47 -0
- package/dist/server/settings.d.ts +49 -0
- package/dist/server/settings.js +25 -0
- package/dist/server/signInWire.d.ts +53 -0
- package/dist/server/signInWire.js +23 -0
- package/dist/server/tables.d.ts +242 -0
- package/dist/server/tables.js +246 -0
- package/dist/server/users.d.ts +189 -0
- package/dist/server/users.js +49 -0
- package/dist/serviceClients.d.ts +5 -0
- package/dist/serviceClients.js +70 -0
- package/dist/services.d.ts +53 -0
- package/dist/services.js +30 -0
- package/dist/shortcuts.d.ts +3 -0
- package/dist/shortcuts.js +40 -0
- package/dist/start.d.ts +20 -0
- package/dist/start.js +145 -0
- package/dist/state.d.ts +14 -0
- package/dist/state.js +17 -0
- package/dist/store.d.ts +45 -0
- package/dist/store.js +208 -0
- package/dist/subscribers.d.ts +5 -0
- package/dist/subscribers.js +13 -0
- package/dist/table.d.ts +143 -0
- package/dist/table.js +91 -0
- package/dist/tables.d.ts +77 -0
- package/dist/tables.js +216 -0
- package/dist/theme/reset.css +84 -0
- package/dist/theme/scales.d.ts +76 -0
- package/dist/theme/scales.js +82 -0
- package/dist/theme/tokens.stylex.d.ts +218 -0
- package/dist/theme/tokens.stylex.js +233 -0
- package/dist/vite/commandBridge.d.ts +2 -0
- package/dist/vite/commandBridge.js +46 -0
- package/dist/vite/designManifest.d.ts +25 -0
- package/dist/vite/designManifest.js +191 -0
- package/dist/vite/localWorker.d.ts +4 -0
- package/dist/vite/localWorker.js +60 -0
- package/dist/vite/projectFile.d.ts +9 -0
- package/dist/vite/projectFile.js +17 -0
- package/dist/vite/rootAlias.d.ts +2 -0
- package/dist/vite/rootAlias.js +15 -0
- package/dist/vite/vite.d.ts +8 -0
- package/dist/vite/vite.js +95 -0
- package/dist/wire.d.ts +7 -0
- package/dist/wire.js +1 -0
- package/package.json +103 -3
- package/presets/lintPlugin.js +7 -0
- package/presets/oxlint.json +167 -0
- package/presets/register.d.ts +21 -0
- package/presets/server.d.ts +2 -0
- package/presets/tsconfig.app.json +29 -0
- package/presets/tsconfig.server.json +27 -0
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import type { Tables } from '../table.ts';
|
|
3
|
+
import type { ServerBindings, ServerEnv } from './env.ts';
|
|
4
|
+
export declare function createServer<Group extends Tables, Bindings extends ServerBindings = ServerBindings>({ tables, admins, routes }: {
|
|
5
|
+
tables: Group;
|
|
6
|
+
admins: readonly string[];
|
|
7
|
+
routes?: Hono<ServerEnv<Bindings>>;
|
|
8
|
+
}): import("hono/hono-base").HonoBase<ServerEnv, (((({
|
|
9
|
+
"/api/health": {
|
|
10
|
+
$get: {
|
|
11
|
+
input: {};
|
|
12
|
+
output: {
|
|
13
|
+
ok: true;
|
|
14
|
+
};
|
|
15
|
+
outputFormat: "json";
|
|
16
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
} | import("hono/types").MergeSchemaPath<{
|
|
20
|
+
"/google": {
|
|
21
|
+
$get: {
|
|
22
|
+
input: {};
|
|
23
|
+
output: {
|
|
24
|
+
error: string;
|
|
25
|
+
};
|
|
26
|
+
outputFormat: "json";
|
|
27
|
+
status: 503;
|
|
28
|
+
} | {
|
|
29
|
+
input: {};
|
|
30
|
+
output: undefined;
|
|
31
|
+
outputFormat: "redirect";
|
|
32
|
+
status: 302;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
} & {
|
|
36
|
+
"/finish": {
|
|
37
|
+
$get: {
|
|
38
|
+
input: {};
|
|
39
|
+
output: undefined;
|
|
40
|
+
outputFormat: "redirect";
|
|
41
|
+
status: 302;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
} & {
|
|
45
|
+
"/email": {
|
|
46
|
+
$post: {
|
|
47
|
+
input: {};
|
|
48
|
+
output: {
|
|
49
|
+
error: string;
|
|
50
|
+
};
|
|
51
|
+
outputFormat: "json";
|
|
52
|
+
status: 400;
|
|
53
|
+
} | {
|
|
54
|
+
input: {};
|
|
55
|
+
output: {
|
|
56
|
+
error: string;
|
|
57
|
+
};
|
|
58
|
+
outputFormat: "json";
|
|
59
|
+
status: 503;
|
|
60
|
+
} | {
|
|
61
|
+
input: {};
|
|
62
|
+
output: {
|
|
63
|
+
error: string;
|
|
64
|
+
};
|
|
65
|
+
outputFormat: "json";
|
|
66
|
+
status: 429;
|
|
67
|
+
} | {
|
|
68
|
+
input: {};
|
|
69
|
+
output: {
|
|
70
|
+
ok: true;
|
|
71
|
+
};
|
|
72
|
+
outputFormat: "json";
|
|
73
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
} & {
|
|
77
|
+
"/email/verify": {
|
|
78
|
+
$post: {
|
|
79
|
+
input: {};
|
|
80
|
+
output: {
|
|
81
|
+
isAdmin: boolean;
|
|
82
|
+
id: string;
|
|
83
|
+
name: string;
|
|
84
|
+
email: string;
|
|
85
|
+
avatarUrl: string | null;
|
|
86
|
+
};
|
|
87
|
+
outputFormat: "json";
|
|
88
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
89
|
+
} | {
|
|
90
|
+
input: {};
|
|
91
|
+
output: {
|
|
92
|
+
error: string;
|
|
93
|
+
};
|
|
94
|
+
outputFormat: "json";
|
|
95
|
+
status: 401;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
} & {
|
|
99
|
+
"/sign-out": {
|
|
100
|
+
$post: {
|
|
101
|
+
input: {};
|
|
102
|
+
output: {
|
|
103
|
+
ok: true;
|
|
104
|
+
};
|
|
105
|
+
outputFormat: "json";
|
|
106
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
109
|
+
}, "/api/auth">) & {
|
|
110
|
+
"/api/app": {
|
|
111
|
+
$get: {
|
|
112
|
+
input: {};
|
|
113
|
+
output: {
|
|
114
|
+
title: string;
|
|
115
|
+
};
|
|
116
|
+
outputFormat: "json";
|
|
117
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
}) & {
|
|
121
|
+
"/api/app": {
|
|
122
|
+
$put: {
|
|
123
|
+
input: {};
|
|
124
|
+
output: {
|
|
125
|
+
error: string;
|
|
126
|
+
};
|
|
127
|
+
outputFormat: "json";
|
|
128
|
+
status: 401;
|
|
129
|
+
} | {
|
|
130
|
+
input: {};
|
|
131
|
+
output: {
|
|
132
|
+
error: string;
|
|
133
|
+
};
|
|
134
|
+
outputFormat: "json";
|
|
135
|
+
status: 403;
|
|
136
|
+
} | {
|
|
137
|
+
input: {};
|
|
138
|
+
output: {
|
|
139
|
+
error: string;
|
|
140
|
+
};
|
|
141
|
+
outputFormat: "json";
|
|
142
|
+
status: 400;
|
|
143
|
+
} | {
|
|
144
|
+
input: {};
|
|
145
|
+
output: {
|
|
146
|
+
title: string;
|
|
147
|
+
};
|
|
148
|
+
outputFormat: "json";
|
|
149
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
}) & {
|
|
153
|
+
"/api/me": {
|
|
154
|
+
$get: {
|
|
155
|
+
input: {};
|
|
156
|
+
output: {
|
|
157
|
+
error: string;
|
|
158
|
+
};
|
|
159
|
+
outputFormat: "json";
|
|
160
|
+
status: 401;
|
|
161
|
+
} | {
|
|
162
|
+
input: {};
|
|
163
|
+
output: {
|
|
164
|
+
isAdmin: boolean;
|
|
165
|
+
id: string;
|
|
166
|
+
name: string;
|
|
167
|
+
email: string;
|
|
168
|
+
avatarUrl: string | null;
|
|
169
|
+
};
|
|
170
|
+
outputFormat: "json";
|
|
171
|
+
status: 200;
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
}) | import("hono/types").MergeSchemaPath<{
|
|
175
|
+
"/:table": {
|
|
176
|
+
$get: {
|
|
177
|
+
input: {
|
|
178
|
+
param: {
|
|
179
|
+
table: string;
|
|
180
|
+
};
|
|
181
|
+
};
|
|
182
|
+
output: {
|
|
183
|
+
error: "forbidden" | "Signed out" | "No such row";
|
|
184
|
+
};
|
|
185
|
+
outputFormat: "json";
|
|
186
|
+
status: 401 | 403 | 404;
|
|
187
|
+
} | {
|
|
188
|
+
input: {
|
|
189
|
+
param: {
|
|
190
|
+
table: string;
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
output: {}[];
|
|
194
|
+
outputFormat: "json";
|
|
195
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
196
|
+
} | {
|
|
197
|
+
input: {
|
|
198
|
+
param: {
|
|
199
|
+
table: string;
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
output: {
|
|
203
|
+
error: string;
|
|
204
|
+
};
|
|
205
|
+
outputFormat: "json";
|
|
206
|
+
status: 404;
|
|
207
|
+
};
|
|
208
|
+
};
|
|
209
|
+
} & {
|
|
210
|
+
"/:table/public": {
|
|
211
|
+
$get: {
|
|
212
|
+
input: {
|
|
213
|
+
param: {
|
|
214
|
+
table: string;
|
|
215
|
+
};
|
|
216
|
+
};
|
|
217
|
+
output: {}[];
|
|
218
|
+
outputFormat: "json";
|
|
219
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
220
|
+
} | {
|
|
221
|
+
input: {
|
|
222
|
+
param: {
|
|
223
|
+
table: string;
|
|
224
|
+
};
|
|
225
|
+
};
|
|
226
|
+
output: {
|
|
227
|
+
error: string;
|
|
228
|
+
};
|
|
229
|
+
outputFormat: "json";
|
|
230
|
+
status: 404;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
} & {
|
|
234
|
+
"/:table": {
|
|
235
|
+
$post: {
|
|
236
|
+
input: {
|
|
237
|
+
param: {
|
|
238
|
+
table: string;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
output: {
|
|
242
|
+
error: "forbidden" | "Signed out" | "No such row";
|
|
243
|
+
};
|
|
244
|
+
outputFormat: "json";
|
|
245
|
+
status: 401 | 403 | 404;
|
|
246
|
+
} | {
|
|
247
|
+
input: {
|
|
248
|
+
param: {
|
|
249
|
+
table: string;
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
output: {};
|
|
253
|
+
outputFormat: "json";
|
|
254
|
+
status: 201;
|
|
255
|
+
} | {
|
|
256
|
+
input: {
|
|
257
|
+
param: {
|
|
258
|
+
table: string;
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
output: {
|
|
262
|
+
error: string;
|
|
263
|
+
};
|
|
264
|
+
outputFormat: "json";
|
|
265
|
+
status: 404;
|
|
266
|
+
} | {
|
|
267
|
+
input: {
|
|
268
|
+
param: {
|
|
269
|
+
table: string;
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
output: {
|
|
273
|
+
error: string;
|
|
274
|
+
};
|
|
275
|
+
outputFormat: "json";
|
|
276
|
+
status: 400;
|
|
277
|
+
} | {
|
|
278
|
+
input: {
|
|
279
|
+
param: {
|
|
280
|
+
table: string;
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
output: {
|
|
284
|
+
error: string;
|
|
285
|
+
unique: readonly (readonly string[])[];
|
|
286
|
+
};
|
|
287
|
+
outputFormat: "json";
|
|
288
|
+
status: 409;
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
} & {
|
|
292
|
+
"/:table/:id": {
|
|
293
|
+
$put: {
|
|
294
|
+
input: {
|
|
295
|
+
param: {
|
|
296
|
+
table: string;
|
|
297
|
+
} & {
|
|
298
|
+
id: string;
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
output: {
|
|
302
|
+
error: "forbidden" | "Signed out" | "No such row";
|
|
303
|
+
};
|
|
304
|
+
outputFormat: "json";
|
|
305
|
+
status: 401 | 403 | 404;
|
|
306
|
+
} | {
|
|
307
|
+
input: {
|
|
308
|
+
param: {
|
|
309
|
+
table: string;
|
|
310
|
+
} & {
|
|
311
|
+
id: string;
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
output: {
|
|
315
|
+
error: string;
|
|
316
|
+
unique: readonly (readonly string[])[];
|
|
317
|
+
};
|
|
318
|
+
outputFormat: "json";
|
|
319
|
+
status: 409;
|
|
320
|
+
} | {
|
|
321
|
+
input: {
|
|
322
|
+
param: {
|
|
323
|
+
table: string;
|
|
324
|
+
} & {
|
|
325
|
+
id: string;
|
|
326
|
+
};
|
|
327
|
+
};
|
|
328
|
+
output: {};
|
|
329
|
+
outputFormat: "json";
|
|
330
|
+
status: 200;
|
|
331
|
+
} | {
|
|
332
|
+
input: {
|
|
333
|
+
param: {
|
|
334
|
+
table: string;
|
|
335
|
+
} & {
|
|
336
|
+
id: string;
|
|
337
|
+
};
|
|
338
|
+
};
|
|
339
|
+
output: {
|
|
340
|
+
error: string;
|
|
341
|
+
};
|
|
342
|
+
outputFormat: "json";
|
|
343
|
+
status: 404;
|
|
344
|
+
} | {
|
|
345
|
+
input: {
|
|
346
|
+
param: {
|
|
347
|
+
table: string;
|
|
348
|
+
} & {
|
|
349
|
+
id: string;
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
output: {
|
|
353
|
+
error: string;
|
|
354
|
+
};
|
|
355
|
+
outputFormat: "json";
|
|
356
|
+
status: 400;
|
|
357
|
+
};
|
|
358
|
+
};
|
|
359
|
+
} & {
|
|
360
|
+
"/:table/:id": {
|
|
361
|
+
$delete: {
|
|
362
|
+
input: {
|
|
363
|
+
param: {
|
|
364
|
+
table: string;
|
|
365
|
+
} & {
|
|
366
|
+
id: string;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
output: {
|
|
370
|
+
error: "forbidden" | "Signed out" | "No such row";
|
|
371
|
+
};
|
|
372
|
+
outputFormat: "json";
|
|
373
|
+
status: 401 | 403 | 404;
|
|
374
|
+
} | {
|
|
375
|
+
input: {
|
|
376
|
+
param: {
|
|
377
|
+
table: string;
|
|
378
|
+
} & {
|
|
379
|
+
id: string;
|
|
380
|
+
};
|
|
381
|
+
};
|
|
382
|
+
output: {
|
|
383
|
+
error: string;
|
|
384
|
+
};
|
|
385
|
+
outputFormat: "json";
|
|
386
|
+
status: 404;
|
|
387
|
+
} | {
|
|
388
|
+
input: {
|
|
389
|
+
param: {
|
|
390
|
+
table: string;
|
|
391
|
+
} & {
|
|
392
|
+
id: string;
|
|
393
|
+
};
|
|
394
|
+
};
|
|
395
|
+
output: {
|
|
396
|
+
ok: true;
|
|
397
|
+
};
|
|
398
|
+
outputFormat: "json";
|
|
399
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
400
|
+
};
|
|
401
|
+
};
|
|
402
|
+
}, "/api/tables">, "/api", "/api/me">;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { csrf } from 'hono/csrf';
|
|
3
|
+
import { adminEmails } from "../access.js";
|
|
4
|
+
import { appTitle } from "../appTitle.js";
|
|
5
|
+
import { auth, devSignIn } from "./auth.js";
|
|
6
|
+
import { forgetSession, issuePass, needsRecheck, readPass, rememberUser } from "./session.js";
|
|
7
|
+
import { renewSession } from "./sessions.js";
|
|
8
|
+
import { readTitle, writeTitle } from "./settings.js";
|
|
9
|
+
import { serveTables } from "./tables.js";
|
|
10
|
+
import { findUser } from "./users.js";
|
|
11
|
+
const PUBLIC_PATHS = ['/api/health', '/api/auth/'];
|
|
12
|
+
const VIEWER_OPTIONAL_PATHS = ['/api/tables/'];
|
|
13
|
+
const APP_PATH = '/api/app';
|
|
14
|
+
function knowAdmins(admins) {
|
|
15
|
+
const emails = adminEmails(admins);
|
|
16
|
+
return (c, next) => {
|
|
17
|
+
c.set('admins', emails);
|
|
18
|
+
return next();
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
async function attachViewer(c, next) {
|
|
22
|
+
if (PUBLIC_PATHS.some((path) => c.req.path.startsWith(path)))
|
|
23
|
+
return next();
|
|
24
|
+
const isOptional = c.req.path === APP_PATH ||
|
|
25
|
+
VIEWER_OPTIONAL_PATHS.some((path) => c.req.path.startsWith(path));
|
|
26
|
+
let pass = await readPass(c);
|
|
27
|
+
if (pass !== undefined && needsRecheck(pass)) {
|
|
28
|
+
const user = await renewSession(c.env.DB, pass.sessionId);
|
|
29
|
+
pass =
|
|
30
|
+
user === undefined ? undefined : await issuePass(c, user, pass.sessionId);
|
|
31
|
+
}
|
|
32
|
+
if (pass === undefined) {
|
|
33
|
+
forgetSession(c);
|
|
34
|
+
if (!isOptional)
|
|
35
|
+
return c.json({ error: 'Signed out' }, 401);
|
|
36
|
+
c.set('viewer', null);
|
|
37
|
+
return next();
|
|
38
|
+
}
|
|
39
|
+
c.set('viewer', {
|
|
40
|
+
userId: pass.userId,
|
|
41
|
+
isAdmin: c.get('admins').has(pass.email.toLowerCase())
|
|
42
|
+
});
|
|
43
|
+
return next();
|
|
44
|
+
}
|
|
45
|
+
export function createServer({ tables, admins, routes }) {
|
|
46
|
+
const authRoutes = import.meta.env.DEV ? auth.route('/', devSignIn) : auth;
|
|
47
|
+
const server = new Hono()
|
|
48
|
+
.basePath('/api')
|
|
49
|
+
.use(csrf())
|
|
50
|
+
.use(knowAdmins(admins))
|
|
51
|
+
.use(attachViewer)
|
|
52
|
+
.get('/health', (c) => c.json({ ok: true }))
|
|
53
|
+
.route('/auth', authRoutes)
|
|
54
|
+
.get('/app', async (c) => c.json({ title: await readTitle(c.env.DB) }))
|
|
55
|
+
.put('/app', async (c) => {
|
|
56
|
+
const viewer = c.get('viewer');
|
|
57
|
+
if (viewer === null)
|
|
58
|
+
return c.json({ error: 'Signed out' }, 401);
|
|
59
|
+
if (!viewer.isAdmin)
|
|
60
|
+
return c.json({ error: 'forbidden' }, 403);
|
|
61
|
+
const body = await c.req.json().catch(() => undefined);
|
|
62
|
+
const title = appTitle.safeParse(Reflect.get(Object(body), 'title'));
|
|
63
|
+
if (!title.success) {
|
|
64
|
+
return c.json({ error: 'title must be 1 to 60 characters' }, 400);
|
|
65
|
+
}
|
|
66
|
+
await writeTitle(c.env.DB, title.data);
|
|
67
|
+
return c.json({ title: title.data });
|
|
68
|
+
})
|
|
69
|
+
.get('/me', async (c) => {
|
|
70
|
+
const viewer = c.get('viewer');
|
|
71
|
+
const user = viewer === null ? undefined : await findUser(c.env.DB, viewer.userId);
|
|
72
|
+
if (user === undefined) {
|
|
73
|
+
forgetSession(c);
|
|
74
|
+
return c.json({ error: 'Signed out' }, 401);
|
|
75
|
+
}
|
|
76
|
+
rememberUser(c, user);
|
|
77
|
+
return c.json({ ...user, isAdmin: viewer?.isAdmin ?? false }, 200);
|
|
78
|
+
})
|
|
79
|
+
.route('/tables', serveTables(tables));
|
|
80
|
+
const own = routes;
|
|
81
|
+
return (own === undefined ? server : server.route('/', own)).notFound((c) => c.json({ error: `No route for ${c.req.path}` }, 404));
|
|
82
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { D1Database } from '@cloudflare/workers-types';
|
|
2
|
+
import type { Viewer } from '../access.ts';
|
|
3
|
+
export type { Viewer };
|
|
4
|
+
export type ServerBindings = {
|
|
5
|
+
DB: D1Database;
|
|
6
|
+
SESSION_SECRET: string;
|
|
7
|
+
AUTH_SECRET?: string;
|
|
8
|
+
};
|
|
9
|
+
export type ServerEnv<Bindings extends ServerBindings = ServerBindings> = {
|
|
10
|
+
Bindings: Bindings;
|
|
11
|
+
Variables: {
|
|
12
|
+
viewer: Viewer | null;
|
|
13
|
+
admins: ReadonlySet<string>;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { createServer } from './createServer.ts';
|
|
2
|
+
export type { ServerBindings, ServerEnv, Viewer } from './env.ts';
|
|
3
|
+
export { seedSql, serveTables, sqlTable, sqlTables } from './tables.ts';
|
|
4
|
+
export { refused } from '../services.ts';
|
|
5
|
+
export { serveServices } from './services.ts';
|
|
6
|
+
export type { ServiceHandlers } from './services.ts';
|
|
7
|
+
export { sessionCookieFor } from './session.ts';
|
|
8
|
+
export { sessions } from './sessions.ts';
|
|
9
|
+
export { readTitle, seedTitleSql, settings, writeTitle } from './settings.ts';
|
|
10
|
+
export { exchangeReply, exchangeRequest, sendCodeReply, sendCodeRequest, verifiedIdentity, verifyCodeReply, verifyCodeRequest } from './signInWire.ts';
|
|
11
|
+
export type { VerifiedIdentity } from './signInWire.ts';
|
|
12
|
+
export { findUser, users } from './users.ts';
|
|
13
|
+
export type { D1Database } from '@cloudflare/workers-types';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { createServer } from "./createServer.js";
|
|
2
|
+
export { seedSql, serveTables, sqlTable, sqlTables } from "./tables.js";
|
|
3
|
+
export { refused } from "../services.js";
|
|
4
|
+
export { serveServices } from "./services.js";
|
|
5
|
+
export { sessionCookieFor } from "./session.js";
|
|
6
|
+
export { sessions } from "./sessions.js";
|
|
7
|
+
export { readTitle, seedTitleSql, settings, writeTitle } from "./settings.js";
|
|
8
|
+
export { exchangeReply, exchangeRequest, sendCodeReply, sendCodeRequest, verifiedIdentity, verifyCodeReply, verifyCodeRequest } from "./signInWire.js";
|
|
9
|
+
export { findUser, users } from "./users.js";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Context, Env } from 'hono';
|
|
2
|
+
import { Hono } from 'hono';
|
|
3
|
+
import type { CallInput, CallReply, Services } from '../services.ts';
|
|
4
|
+
export type ServiceHandlers<Group extends Services, E extends Env> = {
|
|
5
|
+
readonly [Name in keyof Group]: {
|
|
6
|
+
readonly [Call in keyof Group[Name]]: (c: Context<E>, input: CallInput<Group[Name][Call]>) => CallReply<Group[Name][Call]> | Promise<CallReply<Group[Name][Call]>>;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export declare function serveServices<Group extends Services, E extends Env>(services: Group, handlers: ServiceHandlers<Group, E>): Hono<E>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ServiceRefused, paramNamesOf } from "../services.js";
|
|
4
|
+
async function inputOf(c, call) {
|
|
5
|
+
const raw = call.method === 'get' ? c.req.query() : await c.req.json().catch(() => ({}));
|
|
6
|
+
return call.input.safeParse(raw);
|
|
7
|
+
}
|
|
8
|
+
const BUILT_IN_PATHS = ['/auth', '/health', '/tables', '/app', '/me'];
|
|
9
|
+
function builtInPathOf(path) {
|
|
10
|
+
return BUILT_IN_PATHS.find((prefix) => path === prefix || path.startsWith(`${prefix}/`));
|
|
11
|
+
}
|
|
12
|
+
export function serveServices(services, handlers) {
|
|
13
|
+
for (const [group, calls] of Object.entries(services)) {
|
|
14
|
+
for (const [name, call] of Object.entries(calls)) {
|
|
15
|
+
const taken = builtInPathOf(call.path);
|
|
16
|
+
if (taken !== undefined) {
|
|
17
|
+
throw new Error(`${group}.${name} is served at ${call.path}, under Pattern's own ${taken}, where some calls are open to anyone signed out. Give it a path of its own.`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const server = new Hono();
|
|
22
|
+
for (const [group, calls] of Object.entries(services)) {
|
|
23
|
+
for (const [name, call] of Object.entries(calls)) {
|
|
24
|
+
const handler = Reflect.get(Reflect.get(handlers, group), name);
|
|
25
|
+
server.on(call.method.toUpperCase(), call.path, async (c) => {
|
|
26
|
+
const parsed = await inputOf(c, call);
|
|
27
|
+
if (!parsed.success) {
|
|
28
|
+
return c.json({ error: z.prettifyError(parsed.error) }, 400);
|
|
29
|
+
}
|
|
30
|
+
const params = Object.fromEntries(paramNamesOf(call.path).map((key) => [key, c.req.param(key) ?? '']));
|
|
31
|
+
try {
|
|
32
|
+
const reply = await handler(c, {
|
|
33
|
+
...params,
|
|
34
|
+
...parsed.data
|
|
35
|
+
});
|
|
36
|
+
return c.json(call.reply.parse(reply));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (!(error instanceof ServiceRefused))
|
|
40
|
+
throw error;
|
|
41
|
+
return c.json({ error: error.message }, error.status);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return server;
|
|
47
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Context } from 'hono';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import type { StoredUser } from '../auth/user.ts';
|
|
4
|
+
import type { ServerEnv } from './env.ts';
|
|
5
|
+
declare const passSchema: z.ZodObject<{
|
|
6
|
+
sessionId: z.ZodString;
|
|
7
|
+
userId: z.ZodString;
|
|
8
|
+
email: z.ZodString;
|
|
9
|
+
recheckAt: z.ZodNumber;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
export type Pass = z.infer<typeof passSchema>;
|
|
12
|
+
export declare function rememberUser(c: Context<ServerEnv>, user: StoredUser): void;
|
|
13
|
+
export declare function issuePass(c: Context<ServerEnv>, user: StoredUser, sessionId: string): Promise<{
|
|
14
|
+
sessionId: string;
|
|
15
|
+
userId: string;
|
|
16
|
+
email: string;
|
|
17
|
+
recheckAt: number;
|
|
18
|
+
}>;
|
|
19
|
+
export declare function startSession(c: Context<ServerEnv>, user: StoredUser): Promise<void>;
|
|
20
|
+
export declare function sessionCookieFor(env: ServerEnv['Bindings'], user: StoredUser): Promise<string>;
|
|
21
|
+
export declare function readPass(c: Context<ServerEnv>): Promise<{
|
|
22
|
+
sessionId: string;
|
|
23
|
+
userId: string;
|
|
24
|
+
email: string;
|
|
25
|
+
recheckAt: number;
|
|
26
|
+
} | undefined>;
|
|
27
|
+
export declare const needsRecheck: (pass: Pass) => boolean;
|
|
28
|
+
export declare function forgetSession(c: Context<ServerEnv>): void;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { deleteCookie, getSignedCookie, setCookie, setSignedCookie } from 'hono/cookie';
|
|
2
|
+
import { serializeSigned } from 'hono/utils/cookie';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { USER_COOKIE } from "../auth/user.js";
|
|
5
|
+
import { createSession } from "./sessions.js";
|
|
6
|
+
const SESSION_COOKIE = 'pattern_session';
|
|
7
|
+
const RECHECK_SECONDS = 15 * 60;
|
|
8
|
+
const SESSION_SECONDS = 30 * 86_400;
|
|
9
|
+
const cookieOptions = {
|
|
10
|
+
path: '/',
|
|
11
|
+
secure: true,
|
|
12
|
+
sameSite: 'Lax',
|
|
13
|
+
maxAge: SESSION_SECONDS
|
|
14
|
+
};
|
|
15
|
+
const passSchema = z.object({
|
|
16
|
+
sessionId: z.string(),
|
|
17
|
+
userId: z.string(),
|
|
18
|
+
email: z.string(),
|
|
19
|
+
recheckAt: z.number()
|
|
20
|
+
});
|
|
21
|
+
const nowInSeconds = () => Math.floor(Date.now() / 1000);
|
|
22
|
+
export function rememberUser(c, user) {
|
|
23
|
+
setCookie(c, USER_COOKIE, JSON.stringify(user), cookieOptions);
|
|
24
|
+
}
|
|
25
|
+
export async function issuePass(c, user, sessionId) {
|
|
26
|
+
const pass = {
|
|
27
|
+
sessionId,
|
|
28
|
+
userId: user.id,
|
|
29
|
+
email: user.email,
|
|
30
|
+
recheckAt: nowInSeconds() + RECHECK_SECONDS
|
|
31
|
+
};
|
|
32
|
+
await setSignedCookie(c, SESSION_COOKIE, JSON.stringify(pass), c.env.SESSION_SECRET, { ...cookieOptions, httpOnly: true });
|
|
33
|
+
rememberUser(c, user);
|
|
34
|
+
return pass;
|
|
35
|
+
}
|
|
36
|
+
export async function startSession(c, user) {
|
|
37
|
+
await issuePass(c, user, await createSession(c.env.DB, user.id));
|
|
38
|
+
}
|
|
39
|
+
export async function sessionCookieFor(env, user) {
|
|
40
|
+
const pass = {
|
|
41
|
+
sessionId: await createSession(env.DB, user.id),
|
|
42
|
+
userId: user.id,
|
|
43
|
+
email: user.email,
|
|
44
|
+
recheckAt: nowInSeconds() + RECHECK_SECONDS
|
|
45
|
+
};
|
|
46
|
+
const cookie = await serializeSigned(SESSION_COOKIE, JSON.stringify(pass), env.SESSION_SECRET);
|
|
47
|
+
return cookie.split(';')[0] ?? cookie;
|
|
48
|
+
}
|
|
49
|
+
export async function readPass(c) {
|
|
50
|
+
const value = await getSignedCookie(c, c.env.SESSION_SECRET, SESSION_COOKIE);
|
|
51
|
+
if (typeof value !== 'string')
|
|
52
|
+
return undefined;
|
|
53
|
+
try {
|
|
54
|
+
const parsed = passSchema.safeParse(JSON.parse(value));
|
|
55
|
+
return parsed.success ? parsed.data : undefined;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export const needsRecheck = (pass) => pass.recheckAt <= nowInSeconds();
|
|
62
|
+
export function forgetSession(c) {
|
|
63
|
+
deleteCookie(c, SESSION_COOKIE, { path: '/' });
|
|
64
|
+
deleteCookie(c, USER_COOKIE, { path: '/' });
|
|
65
|
+
}
|