@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.
Files changed (273) hide show
  1. package/README.md +127 -2
  2. package/dist/access.d.ts +31 -0
  3. package/dist/access.js +72 -0
  4. package/dist/actions.d.ts +57 -0
  5. package/dist/actions.js +198 -0
  6. package/dist/api.d.ts +30 -0
  7. package/dist/api.js +60 -0
  8. package/dist/app.d.ts +115 -0
  9. package/dist/app.js +266 -0
  10. package/dist/appInfo.d.ts +35 -0
  11. package/dist/appInfo.js +67 -0
  12. package/dist/appTitle.d.ts +6 -0
  13. package/dist/appTitle.js +3 -0
  14. package/dist/appearance.d.ts +7 -0
  15. package/dist/appearance.js +2 -0
  16. package/dist/auth/sessionApi.d.ts +41 -0
  17. package/dist/auth/sessionApi.js +158 -0
  18. package/dist/auth/sessionStore.d.ts +20 -0
  19. package/dist/auth/sessionStore.js +40 -0
  20. package/dist/auth/user.d.ts +11 -0
  21. package/dist/auth/user.js +9 -0
  22. package/dist/builtins/Account.d.ts +25 -0
  23. package/dist/builtins/Account.js +15 -0
  24. package/dist/builtins/AppSettings.d.ts +12 -0
  25. package/dist/builtins/AppSettings.js +31 -0
  26. package/dist/builtins/Palette.d.ts +29 -0
  27. package/dist/builtins/Palette.js +63 -0
  28. package/dist/builtins/SignIn.d.ts +28 -0
  29. package/dist/builtins/SignIn.js +60 -0
  30. package/dist/builtins/Toasts.d.ts +32 -0
  31. package/dist/builtins/Toasts.js +25 -0
  32. package/dist/builtins/actions.d.ts +2 -0
  33. package/dist/builtins/actions.js +45 -0
  34. package/dist/cache.d.ts +24 -0
  35. package/dist/cache.js +112 -0
  36. package/dist/cli/app.d.ts +2 -0
  37. package/dist/cli/app.js +1406 -0
  38. package/dist/cli/publishing.d.ts +21 -0
  39. package/dist/cli/publishing.js +493 -0
  40. package/dist/cli/screenshot.d.ts +1 -0
  41. package/dist/cli/screenshot.js +96 -0
  42. package/dist/cli/tools.d.ts +12 -0
  43. package/dist/cli/tools.js +35 -0
  44. package/dist/clock.d.ts +6 -0
  45. package/dist/clock.js +31 -0
  46. package/dist/components/AppFrame.d.ts +14 -0
  47. package/dist/components/AppFrame.js +64 -0
  48. package/dist/components/AppearancePicker.d.ts +1 -0
  49. package/dist/components/AppearancePicker.js +12 -0
  50. package/dist/components/Avatar.d.ts +9 -0
  51. package/dist/components/Avatar.js +63 -0
  52. package/dist/components/Badge.d.ts +11 -0
  53. package/dist/components/Badge.js +87 -0
  54. package/dist/components/Button.d.ts +24 -0
  55. package/dist/components/Button.js +252 -0
  56. package/dist/components/Card.d.ts +12 -0
  57. package/dist/components/Card.js +38 -0
  58. package/dist/components/CommandMenu.d.ts +23 -0
  59. package/dist/components/CommandMenu.js +214 -0
  60. package/dist/components/CommandPalette.d.ts +1 -0
  61. package/dist/components/CommandPalette.js +7 -0
  62. package/dist/components/Content.d.ts +7 -0
  63. package/dist/components/Content.js +24 -0
  64. package/dist/components/ContextMenu.d.ts +8 -0
  65. package/dist/components/ContextMenu.js +23 -0
  66. package/dist/components/CopyButton.d.ts +11 -0
  67. package/dist/components/CopyButton.js +16 -0
  68. package/dist/components/Dialog.d.ts +11 -0
  69. package/dist/components/Dialog.js +81 -0
  70. package/dist/components/Divider.d.ts +7 -0
  71. package/dist/components/Divider.js +30 -0
  72. package/dist/components/EmptyState.d.ts +8 -0
  73. package/dist/components/EmptyState.js +24 -0
  74. package/dist/components/Form.d.ts +9 -0
  75. package/dist/components/Form.js +23 -0
  76. package/dist/components/Icon.d.ts +10 -0
  77. package/dist/components/Icon.js +22 -0
  78. package/dist/components/IconButton.d.ts +14 -0
  79. package/dist/components/IconButton.js +53 -0
  80. package/dist/components/Kbd.d.ts +6 -0
  81. package/dist/components/Kbd.js +67 -0
  82. package/dist/components/Link.d.ts +14 -0
  83. package/dist/components/Link.js +44 -0
  84. package/dist/components/ListRow.d.ts +12 -0
  85. package/dist/components/ListRow.js +62 -0
  86. package/dist/components/LoadingRows.d.ts +5 -0
  87. package/dist/components/LoadingRows.js +6 -0
  88. package/dist/components/Menu.d.ts +12 -0
  89. package/dist/components/Menu.js +33 -0
  90. package/dist/components/MenuItems.d.ts +21 -0
  91. package/dist/components/MenuItems.js +32 -0
  92. package/dist/components/Placement.d.ts +21 -0
  93. package/dist/components/Placement.js +1 -0
  94. package/dist/components/Popup.d.ts +8 -0
  95. package/dist/components/Popup.js +43 -0
  96. package/dist/components/PopupItem.d.ts +8 -0
  97. package/dist/components/PopupItem.js +51 -0
  98. package/dist/components/PropertyRow.d.ts +7 -0
  99. package/dist/components/PropertyRow.js +23 -0
  100. package/dist/components/RadioGroup.d.ts +18 -0
  101. package/dist/components/RadioGroup.js +85 -0
  102. package/dist/components/Row.d.ts +16 -0
  103. package/dist/components/Row.js +27 -0
  104. package/dist/components/Screen.d.ts +13 -0
  105. package/dist/components/Screen.js +56 -0
  106. package/dist/components/Scrim.d.ts +8 -0
  107. package/dist/components/Scrim.js +40 -0
  108. package/dist/components/ScrollArea.d.ts +15 -0
  109. package/dist/components/ScrollArea.js +13 -0
  110. package/dist/components/SegmentedControl.d.ts +17 -0
  111. package/dist/components/SegmentedControl.js +68 -0
  112. package/dist/components/Select.d.ts +17 -0
  113. package/dist/components/Select.js +107 -0
  114. package/dist/components/SettingsRow.d.ts +8 -0
  115. package/dist/components/SettingsRow.js +32 -0
  116. package/dist/components/Sidebar.d.ts +20 -0
  117. package/dist/components/Sidebar.js +137 -0
  118. package/dist/components/SignInScreen.d.ts +1 -0
  119. package/dist/components/SignInScreen.js +40 -0
  120. package/dist/components/Size.d.ts +1 -0
  121. package/dist/components/Size.js +1 -0
  122. package/dist/components/Skeleton.d.ts +8 -0
  123. package/dist/components/Skeleton.js +48 -0
  124. package/dist/components/Spinner.d.ts +6 -0
  125. package/dist/components/Spinner.js +54 -0
  126. package/dist/components/Stack.d.ts +14 -0
  127. package/dist/components/Stack.js +19 -0
  128. package/dist/components/Switch.d.ts +10 -0
  129. package/dist/components/Switch.js +72 -0
  130. package/dist/components/Text.d.ts +21 -0
  131. package/dist/components/Text.js +77 -0
  132. package/dist/components/TextField.d.ts +25 -0
  133. package/dist/components/TextField.js +68 -0
  134. package/dist/components/Toaster.d.ts +1 -0
  135. package/dist/components/Toaster.js +83 -0
  136. package/dist/components/Tooltip.d.ts +8 -0
  137. package/dist/components/Tooltip.js +43 -0
  138. package/dist/components/controlLook.d.ts +70 -0
  139. package/dist/components/controlLook.js +80 -0
  140. package/dist/components/frame.d.ts +4 -0
  141. package/dist/components/frame.js +2 -0
  142. package/dist/components/icons.d.ts +59 -0
  143. package/dist/components/icons.js +111 -0
  144. package/dist/components/interaction.d.ts +12 -0
  145. package/dist/components/interaction.js +22 -0
  146. package/dist/components/spacing.d.ts +118 -0
  147. package/dist/components/spacing.js +46 -0
  148. package/dist/components/tones.d.ts +28 -0
  149. package/dist/components/tones.js +12 -0
  150. package/dist/entityStore.d.ts +46 -0
  151. package/dist/entityStore.js +160 -0
  152. package/dist/flows/accessFlows.d.ts +9 -0
  153. package/dist/flows/accessFlows.js +167 -0
  154. package/dist/flows/browser.d.ts +34 -0
  155. package/dist/flows/browser.js +167 -0
  156. package/dist/flows/contactSheet.d.ts +1 -0
  157. package/dist/flows/contactSheet.js +63 -0
  158. package/dist/flows/flowBrowser.d.ts +25 -0
  159. package/dist/flows/flowBrowser.js +23 -0
  160. package/dist/flows/flowSetup.d.ts +3 -0
  161. package/dist/flows/flowSetup.js +35 -0
  162. package/dist/flows/flows.d.ts +47 -0
  163. package/dist/flows/flows.js +175 -0
  164. package/dist/flows/screenshotName.d.ts +1 -0
  165. package/dist/flows/screenshotName.js +6 -0
  166. package/dist/gate.d.ts +8 -0
  167. package/dist/gate.js +52 -0
  168. package/dist/hooks/appContext.d.ts +15 -0
  169. package/dist/hooks/appContext.js +5 -0
  170. package/dist/hooks/appHooks.d.ts +21 -0
  171. package/dist/hooks/appHooks.js +24 -0
  172. package/dist/hooks/useAnimatesOnChange.d.ts +1 -0
  173. package/dist/hooks/useAnimatesOnChange.js +14 -0
  174. package/dist/hooks/useStoreState.d.ts +6 -0
  175. package/dist/hooks/useStoreState.js +5 -0
  176. package/dist/index.d.ts +44 -0
  177. package/dist/index.js +21 -0
  178. package/dist/memoryApi.d.ts +19 -0
  179. package/dist/memoryApi.js +42 -0
  180. package/dist/model.d.ts +94 -0
  181. package/dist/model.js +243 -0
  182. package/dist/page.d.ts +11 -0
  183. package/dist/page.js +9 -0
  184. package/dist/platform.d.ts +1 -0
  185. package/dist/platform.js +5 -0
  186. package/dist/publishWire.d.ts +271 -0
  187. package/dist/publishWire.js +168 -0
  188. package/dist/react.d.ts +49 -0
  189. package/dist/react.js +40 -0
  190. package/dist/registered.d.ts +60 -0
  191. package/dist/registered.js +19 -0
  192. package/dist/routes.d.ts +38 -0
  193. package/dist/routes.js +21 -0
  194. package/dist/rules/checkAllFiles.d.ts +1 -0
  195. package/dist/rules/checkAllFiles.js +749 -0
  196. package/dist/rules/checkApiRouting.d.ts +1 -0
  197. package/dist/rules/checkApiRouting.js +112 -0
  198. package/dist/rules/lintPlugin.d.ts +252 -0
  199. package/dist/rules/lintPlugin.js +1159 -0
  200. package/dist/rules/messages.d.ts +48 -0
  201. package/dist/rules/messages.js +48 -0
  202. package/dist/rules/themeTokens.d.ts +6 -0
  203. package/dist/rules/themeTokens.js +64 -0
  204. package/dist/schema.d.ts +4 -0
  205. package/dist/schema.js +2 -0
  206. package/dist/server/auth.d.ts +115 -0
  207. package/dist/server/auth.js +134 -0
  208. package/dist/server/authService.d.ts +9 -0
  209. package/dist/server/authService.js +50 -0
  210. package/dist/server/createServer.d.ts +402 -0
  211. package/dist/server/createServer.js +82 -0
  212. package/dist/server/env.d.ts +15 -0
  213. package/dist/server/env.js +1 -0
  214. package/dist/server/index.d.ts +13 -0
  215. package/dist/server/index.js +9 -0
  216. package/dist/server/services.d.ts +9 -0
  217. package/dist/server/services.js +47 -0
  218. package/dist/server/session.d.ts +29 -0
  219. package/dist/server/session.js +65 -0
  220. package/dist/server/sessions.d.ts +92 -0
  221. package/dist/server/sessions.js +47 -0
  222. package/dist/server/settings.d.ts +49 -0
  223. package/dist/server/settings.js +25 -0
  224. package/dist/server/signInWire.d.ts +53 -0
  225. package/dist/server/signInWire.js +23 -0
  226. package/dist/server/tables.d.ts +242 -0
  227. package/dist/server/tables.js +246 -0
  228. package/dist/server/users.d.ts +189 -0
  229. package/dist/server/users.js +49 -0
  230. package/dist/serviceClients.d.ts +5 -0
  231. package/dist/serviceClients.js +70 -0
  232. package/dist/services.d.ts +53 -0
  233. package/dist/services.js +30 -0
  234. package/dist/shortcuts.d.ts +3 -0
  235. package/dist/shortcuts.js +40 -0
  236. package/dist/start.d.ts +20 -0
  237. package/dist/start.js +145 -0
  238. package/dist/state.d.ts +14 -0
  239. package/dist/state.js +17 -0
  240. package/dist/store.d.ts +45 -0
  241. package/dist/store.js +208 -0
  242. package/dist/subscribers.d.ts +5 -0
  243. package/dist/subscribers.js +13 -0
  244. package/dist/table.d.ts +143 -0
  245. package/dist/table.js +91 -0
  246. package/dist/tables.d.ts +77 -0
  247. package/dist/tables.js +216 -0
  248. package/dist/theme/reset.css +84 -0
  249. package/dist/theme/scales.d.ts +76 -0
  250. package/dist/theme/scales.js +82 -0
  251. package/dist/theme/tokens.stylex.d.ts +218 -0
  252. package/dist/theme/tokens.stylex.js +233 -0
  253. package/dist/vite/commandBridge.d.ts +2 -0
  254. package/dist/vite/commandBridge.js +46 -0
  255. package/dist/vite/designManifest.d.ts +25 -0
  256. package/dist/vite/designManifest.js +191 -0
  257. package/dist/vite/localWorker.d.ts +4 -0
  258. package/dist/vite/localWorker.js +60 -0
  259. package/dist/vite/projectFile.d.ts +9 -0
  260. package/dist/vite/projectFile.js +17 -0
  261. package/dist/vite/rootAlias.d.ts +2 -0
  262. package/dist/vite/rootAlias.js +15 -0
  263. package/dist/vite/vite.d.ts +8 -0
  264. package/dist/vite/vite.js +95 -0
  265. package/dist/wire.d.ts +7 -0
  266. package/dist/wire.js +1 -0
  267. package/package.json +103 -3
  268. package/presets/lintPlugin.js +7 -0
  269. package/presets/oxlint.json +167 -0
  270. package/presets/register.d.ts +21 -0
  271. package/presets/server.d.ts +2 -0
  272. package/presets/tsconfig.app.json +29 -0
  273. 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
+ }