@artemis-apps/app-server 0.0.0-stage → 0.1.0
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/dist/account-deletion/account-deletion.service.d.ts +18 -0
- package/dist/account-deletion/account-deletion.service.js +18 -0
- package/dist/activity/core-activity.client.d.ts +20 -0
- package/dist/activity/core-activity.client.js +32 -0
- package/dist/core-api/core-api.client.d.ts +25 -0
- package/dist/core-api/core-api.client.js +63 -0
- package/dist/enrollment/enrollment.service.d.ts +30 -0
- package/dist/enrollment/enrollment.service.js +103 -0
- package/dist/entity-grants/entity-grant.service.d.ts +22 -0
- package/dist/entity-grants/entity-grant.service.js +49 -0
- package/dist/events/security-event.routes.d.ts +24 -0
- package/dist/events/security-event.routes.js +28 -0
- package/dist/handlers/handler.routes.d.ts +32 -0
- package/dist/handlers/handler.routes.js +74 -0
- package/dist/icon/app-icon.routes.d.ts +15 -0
- package/dist/icon/app-icon.routes.js +18 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +4 -0
- package/dist/keys/app-key.entity.d.ts +67 -0
- package/dist/keys/app-key.entity.js +10 -0
- package/dist/keys/app-key.repository.d.ts +14 -0
- package/dist/keys/app-key.repository.js +38 -0
- package/dist/manifest/manifest.routes.d.ts +115 -0
- package/dist/manifest/manifest.routes.js +9 -0
- package/dist/oidc/account-claims.d.ts +5 -0
- package/dist/oidc/account-claims.js +22 -0
- package/dist/oidc/oidc.client.d.ts +64 -0
- package/dist/oidc/oidc.client.js +205 -0
- package/dist/platform.config.d.ts +22 -0
- package/dist/platform.config.js +0 -0
- package/dist/platform.d.ts +387 -0
- package/dist/platform.js +125 -0
- package/dist/platform.tables.d.ts +448 -0
- package/dist/platform.tables.js +9 -0
- package/dist/providers/provider.routes.d.ts +78 -0
- package/dist/providers/provider.routes.js +208 -0
- package/dist/relay/core-relay.routes.d.ts +26 -0
- package/dist/relay/core-relay.routes.js +64 -0
- package/dist/session/app-session.entity.d.ts +301 -0
- package/dist/session/app-session.entity.js +26 -0
- package/dist/session/app-session.repository.d.ts +34 -0
- package/dist/session/app-session.repository.js +87 -0
- package/dist/session/app-sign-in-attempt.entity.d.ts +82 -0
- package/dist/session/app-sign-in-attempt.entity.js +8 -0
- package/dist/session/app-sign-in-attempt.repository.d.ts +15 -0
- package/dist/session/app-sign-in-attempt.repository.js +29 -0
- package/dist/session/app.cookies.d.ts +22 -0
- package/dist/session/app.cookies.js +18 -0
- package/dist/session/require-permissions.middleware.d.ts +36 -0
- package/dist/session/require-permissions.middleware.js +34 -0
- package/dist/session/session.routes.d.ts +204 -0
- package/dist/session/session.routes.js +92 -0
- package/dist/session/session.service.d.ts +50 -0
- package/dist/session/session.service.js +137 -0
- package/dist/storage/core-storage.client.d.ts +27 -0
- package/dist/storage/core-storage.client.js +71 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.js +3 -0
- package/dist/testing/platform-fixtures.d.ts +24 -0
- package/dist/testing/platform-fixtures.js +25 -0
- package/dist/testing/test-core.d.ts +73 -0
- package/dist/testing/test-core.js +134 -0
- package/package.json +45 -3
- package/README.md +0 -3
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { type Logger } from '@artemis-apps/server-kit';
|
|
2
|
+
import { type AccountDeletionHandler } from './account-deletion/account-deletion.service.ts';
|
|
3
|
+
import { type Handlers } from './handlers/handler.routes.ts';
|
|
4
|
+
import type { PlatformConfig } from './platform.config.ts';
|
|
5
|
+
import type { PlatformDatabase } from './platform.tables.ts';
|
|
6
|
+
import { type Providers } from './providers/provider.routes.ts';
|
|
7
|
+
export interface PlatformOptions {
|
|
8
|
+
/** The app database; its schema must include `platformTables`. */
|
|
9
|
+
database: PlatformDatabase;
|
|
10
|
+
config: PlatformConfig;
|
|
11
|
+
/** Where platform failures are logged (e.g. an activity report the core refused). */
|
|
12
|
+
logger?: Logger;
|
|
13
|
+
/**
|
|
14
|
+
* Drops what a deleted account owned in the app, once the core announced its deletion. The
|
|
15
|
+
* platform already signed it out.
|
|
16
|
+
*/
|
|
17
|
+
onAccountDeleted?: AccountDeletionHandler;
|
|
18
|
+
/**
|
|
19
|
+
* What the app provides, by entity type (declared in its manifest's `types`): its manifest's
|
|
20
|
+
* `provides` follow from it.
|
|
21
|
+
*/
|
|
22
|
+
providers?: Providers;
|
|
23
|
+
/**
|
|
24
|
+
* The `server` actions the app runs for other apps (a preview), by entity type then by action:
|
|
25
|
+
* exactly those its manifest's `handles` declares on `server` actions.
|
|
26
|
+
*/
|
|
27
|
+
handlers?: Handlers;
|
|
28
|
+
}
|
|
29
|
+
/** URLs normalized and the declaration validated once, so every component compares like with like. */
|
|
30
|
+
export declare function normalizePlatformConfig(config: PlatformConfig): PlatformConfig;
|
|
31
|
+
/**
|
|
32
|
+
* Makes a Hono server an app of the platform: key and manifest, enrollment, sign-in, security
|
|
33
|
+
* events, the relay to the core for its web client, what it provides, a permission guard,
|
|
34
|
+
* storage and activity.
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPlatform({ database, config: rawConfig, logger, onAccountDeleted, providers, handlers, }: PlatformOptions): {
|
|
37
|
+
/** Mount at `/`: every path comes from `APP_PROTOCOL_PATHS`. */
|
|
38
|
+
routes: import("hono/hono-base").HonoBase<import("hono/types").BlankEnv, import("hono/types").BlankSchema | import("hono/types").MergeSchemaPath<import("hono/types").BlankSchema, "/"> | import("hono/types").MergeSchemaPath<{
|
|
39
|
+
"/.well-known/artemis/app.json": {
|
|
40
|
+
$get: {
|
|
41
|
+
output: {
|
|
42
|
+
id: string;
|
|
43
|
+
name: string;
|
|
44
|
+
description?: string | undefined;
|
|
45
|
+
permissions: import("@artemis-apps/contracts").DelegablePermission[];
|
|
46
|
+
types: {
|
|
47
|
+
id: string;
|
|
48
|
+
version: number;
|
|
49
|
+
parent: string | null;
|
|
50
|
+
titleFields: string[];
|
|
51
|
+
schema: {
|
|
52
|
+
[x: string]: string | number | boolean | import("hono/utils/types").JSONValue[] | {
|
|
53
|
+
[x: string]: string | number | boolean | import("hono/utils/types").JSONValue[] | /*elided*/ any | null;
|
|
54
|
+
} | null;
|
|
55
|
+
};
|
|
56
|
+
permissions: {
|
|
57
|
+
[x: string]: string | null;
|
|
58
|
+
};
|
|
59
|
+
operations: {
|
|
60
|
+
[x: string]: string;
|
|
61
|
+
};
|
|
62
|
+
kinds: string[];
|
|
63
|
+
actions: {
|
|
64
|
+
[x: string]: {
|
|
65
|
+
permission: string;
|
|
66
|
+
target: "page" | "server";
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
messages: {
|
|
70
|
+
en?: {
|
|
71
|
+
name: string;
|
|
72
|
+
plural: string;
|
|
73
|
+
permissions: {
|
|
74
|
+
[x: string]: {
|
|
75
|
+
label: string;
|
|
76
|
+
description: string;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
operations: {
|
|
80
|
+
[x: string]: string;
|
|
81
|
+
};
|
|
82
|
+
kinds: {
|
|
83
|
+
[x: string]: string;
|
|
84
|
+
};
|
|
85
|
+
actions: {
|
|
86
|
+
[x: string]: string;
|
|
87
|
+
};
|
|
88
|
+
} | undefined;
|
|
89
|
+
fr?: {
|
|
90
|
+
name: string;
|
|
91
|
+
plural: string;
|
|
92
|
+
permissions: {
|
|
93
|
+
[x: string]: {
|
|
94
|
+
label: string;
|
|
95
|
+
description: string;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
operations: {
|
|
99
|
+
[x: string]: string;
|
|
100
|
+
};
|
|
101
|
+
kinds: {
|
|
102
|
+
[x: string]: string;
|
|
103
|
+
};
|
|
104
|
+
actions: {
|
|
105
|
+
[x: string]: string;
|
|
106
|
+
};
|
|
107
|
+
} | undefined;
|
|
108
|
+
};
|
|
109
|
+
}[];
|
|
110
|
+
listed?: boolean | undefined;
|
|
111
|
+
kinds?: {
|
|
112
|
+
[x: string]: {
|
|
113
|
+
kind: string;
|
|
114
|
+
icon: string;
|
|
115
|
+
template?: string | undefined;
|
|
116
|
+
}[];
|
|
117
|
+
} | undefined;
|
|
118
|
+
handles?: {
|
|
119
|
+
[x: string]: {
|
|
120
|
+
[x: string]: string[];
|
|
121
|
+
};
|
|
122
|
+
} | undefined;
|
|
123
|
+
url: string;
|
|
124
|
+
provides: {
|
|
125
|
+
[x: string]: {
|
|
126
|
+
operations: string[];
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
jwks: {
|
|
130
|
+
keys: {
|
|
131
|
+
kty: "EC";
|
|
132
|
+
crv: "P-256";
|
|
133
|
+
x: string;
|
|
134
|
+
y: string;
|
|
135
|
+
kid: string;
|
|
136
|
+
alg: "ES256";
|
|
137
|
+
use: "sig";
|
|
138
|
+
}[];
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
outputFormat: "json";
|
|
142
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
143
|
+
input: {};
|
|
144
|
+
};
|
|
145
|
+
};
|
|
146
|
+
}, "/"> | import("hono/types").MergeSchemaPath<{
|
|
147
|
+
"/.well-known/artemis/events": {
|
|
148
|
+
$post: {
|
|
149
|
+
output: null;
|
|
150
|
+
outputFormat: "body";
|
|
151
|
+
status: 202;
|
|
152
|
+
input: {};
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
}, "/"> | import("hono/types").MergeSchemaPath<{
|
|
156
|
+
"/.well-known/artemis/icon.svg": {
|
|
157
|
+
$get: {
|
|
158
|
+
output: string;
|
|
159
|
+
outputFormat: "body";
|
|
160
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
161
|
+
input: {};
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
}, "/"> | import("hono/types").MergeSchemaPath<{
|
|
165
|
+
"/api/core/*": {
|
|
166
|
+
$all: {
|
|
167
|
+
output: {};
|
|
168
|
+
outputFormat: string;
|
|
169
|
+
status: import("hono/utils/http-status").StatusCode;
|
|
170
|
+
input: {};
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
}, "/"> | import("hono/types").MergeSchemaPath<{
|
|
174
|
+
"/api/platform/session": {
|
|
175
|
+
$get: {
|
|
176
|
+
output: {
|
|
177
|
+
status: "unenrolled";
|
|
178
|
+
manifest: {
|
|
179
|
+
id: string;
|
|
180
|
+
name: string;
|
|
181
|
+
description?: string | undefined;
|
|
182
|
+
permissions: import("@artemis-apps/contracts").DelegablePermission[];
|
|
183
|
+
types: {
|
|
184
|
+
id: string;
|
|
185
|
+
version: number;
|
|
186
|
+
parent: string | null;
|
|
187
|
+
titleFields: string[];
|
|
188
|
+
schema: {
|
|
189
|
+
[x: string]: string | number | boolean | import("hono/utils/types").JSONValue[] | {
|
|
190
|
+
[x: string]: string | number | boolean | import("hono/utils/types").JSONValue[] | any | null;
|
|
191
|
+
} | null;
|
|
192
|
+
};
|
|
193
|
+
permissions: {
|
|
194
|
+
[x: string]: string | null;
|
|
195
|
+
};
|
|
196
|
+
operations: {
|
|
197
|
+
[x: string]: string;
|
|
198
|
+
};
|
|
199
|
+
kinds: string[];
|
|
200
|
+
actions: {
|
|
201
|
+
[x: string]: {
|
|
202
|
+
permission: string;
|
|
203
|
+
target: "page" | "server";
|
|
204
|
+
};
|
|
205
|
+
};
|
|
206
|
+
messages: {
|
|
207
|
+
en?: {
|
|
208
|
+
name: string;
|
|
209
|
+
plural: string;
|
|
210
|
+
permissions: {
|
|
211
|
+
[x: string]: {
|
|
212
|
+
label: string;
|
|
213
|
+
description: string;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
operations: {
|
|
217
|
+
[x: string]: string;
|
|
218
|
+
};
|
|
219
|
+
kinds: {
|
|
220
|
+
[x: string]: string;
|
|
221
|
+
};
|
|
222
|
+
actions: {
|
|
223
|
+
[x: string]: string;
|
|
224
|
+
};
|
|
225
|
+
} | undefined;
|
|
226
|
+
fr?: {
|
|
227
|
+
name: string;
|
|
228
|
+
plural: string;
|
|
229
|
+
permissions: {
|
|
230
|
+
[x: string]: {
|
|
231
|
+
label: string;
|
|
232
|
+
description: string;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
operations: {
|
|
236
|
+
[x: string]: string;
|
|
237
|
+
};
|
|
238
|
+
kinds: {
|
|
239
|
+
[x: string]: string;
|
|
240
|
+
};
|
|
241
|
+
actions: {
|
|
242
|
+
[x: string]: string;
|
|
243
|
+
};
|
|
244
|
+
} | undefined;
|
|
245
|
+
};
|
|
246
|
+
}[];
|
|
247
|
+
listed?: boolean | undefined;
|
|
248
|
+
kinds?: {
|
|
249
|
+
[x: string]: {
|
|
250
|
+
kind: string;
|
|
251
|
+
icon: string;
|
|
252
|
+
template?: string | undefined;
|
|
253
|
+
}[];
|
|
254
|
+
} | undefined;
|
|
255
|
+
handles?: {
|
|
256
|
+
[x: string]: {
|
|
257
|
+
[x: string]: string[];
|
|
258
|
+
};
|
|
259
|
+
} | undefined;
|
|
260
|
+
url: string;
|
|
261
|
+
provides: {
|
|
262
|
+
[x: string]: {
|
|
263
|
+
operations: string[];
|
|
264
|
+
};
|
|
265
|
+
};
|
|
266
|
+
jwks: {
|
|
267
|
+
keys: {
|
|
268
|
+
kty: "EC";
|
|
269
|
+
crv: "P-256";
|
|
270
|
+
x: string;
|
|
271
|
+
y: string;
|
|
272
|
+
kid: string;
|
|
273
|
+
alg: "ES256";
|
|
274
|
+
use: "sig";
|
|
275
|
+
}[];
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
coreUrl: string;
|
|
279
|
+
};
|
|
280
|
+
outputFormat: "json";
|
|
281
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
282
|
+
input: {};
|
|
283
|
+
} | {
|
|
284
|
+
output: {
|
|
285
|
+
status: "unauthenticated";
|
|
286
|
+
signInUrl: string;
|
|
287
|
+
};
|
|
288
|
+
outputFormat: "json";
|
|
289
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
290
|
+
input: {};
|
|
291
|
+
} | {
|
|
292
|
+
output: {
|
|
293
|
+
status: "authenticated";
|
|
294
|
+
appId: string;
|
|
295
|
+
account: {
|
|
296
|
+
id: string;
|
|
297
|
+
email: string;
|
|
298
|
+
name: string;
|
|
299
|
+
avatar: {
|
|
300
|
+
kind: "generated";
|
|
301
|
+
seed: string;
|
|
302
|
+
} | {
|
|
303
|
+
kind: "file";
|
|
304
|
+
fileId: string;
|
|
305
|
+
url: string;
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
permissions: import("@artemis-apps/contracts").DelegablePermission[];
|
|
309
|
+
preferences: {
|
|
310
|
+
locale: "en" | "fr";
|
|
311
|
+
};
|
|
312
|
+
administrator: boolean;
|
|
313
|
+
coreUrl: string;
|
|
314
|
+
};
|
|
315
|
+
outputFormat: "json";
|
|
316
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
317
|
+
input: {};
|
|
318
|
+
};
|
|
319
|
+
};
|
|
320
|
+
} & {
|
|
321
|
+
"/api/platform/sign-in": {
|
|
322
|
+
$get: {
|
|
323
|
+
output: undefined;
|
|
324
|
+
outputFormat: "redirect";
|
|
325
|
+
status: 302;
|
|
326
|
+
input: {};
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
} & {
|
|
330
|
+
"/api/platform/callback": {
|
|
331
|
+
$get: {
|
|
332
|
+
output: undefined;
|
|
333
|
+
outputFormat: "redirect";
|
|
334
|
+
status: 302;
|
|
335
|
+
input: {};
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
} & {
|
|
339
|
+
"/api/platform/sign-out": {
|
|
340
|
+
$post: {
|
|
341
|
+
output: {
|
|
342
|
+
redirectTo: string;
|
|
343
|
+
};
|
|
344
|
+
outputFormat: "json";
|
|
345
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
346
|
+
input: {};
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
} & {
|
|
350
|
+
"/api/platform/back-channel-logout": {
|
|
351
|
+
$post: {
|
|
352
|
+
output: null;
|
|
353
|
+
outputFormat: "body";
|
|
354
|
+
status: 200;
|
|
355
|
+
input: {};
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
}, "/">, "/", "/">;
|
|
359
|
+
requirePermissions: (...required: import("@artemis-apps/contracts").DelegablePermission[]) => import("hono").MiddlewareHandler<import("./index.ts").RequirePermissionsEnv, string, {}, Response>;
|
|
360
|
+
/** Guards the app's own settings: administrators of the platform's apps only. */
|
|
361
|
+
requireAdministrator: import("hono").MiddlewareHandler<import("./index.ts").RequirePermissionsEnv, string, {}, Response>;
|
|
362
|
+
/** The app's files on the core storage, with its own token. */
|
|
363
|
+
storage: {
|
|
364
|
+
upload({ file, visibility }: import("./index.ts").FileUpload): Promise<import("@artemis-apps/contracts").StoredFile>;
|
|
365
|
+
read(fileId: string): Promise<Response>;
|
|
366
|
+
delete(fileId: string): Promise<void>;
|
|
367
|
+
publicUrl(fileId: string): string;
|
|
368
|
+
};
|
|
369
|
+
/** The app's events, reported to the core's activity log (fire and forget). */
|
|
370
|
+
activity: {
|
|
371
|
+
record(report: import("@artemis-apps/contracts").ActivityReport): Promise<void>;
|
|
372
|
+
};
|
|
373
|
+
/** Grants of one entity, for work that outlives the account's session. */
|
|
374
|
+
entityGrants: {
|
|
375
|
+
exchange(session: import("./index.ts").AppSession, target: import("@artemis-apps/contracts").EntityGrantTarget, permissions: readonly import("@artemis-apps/contracts").TypePermission[]): Promise<import("./index.ts").EntityGrant>;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* The core's API, called by the app's server: as the app itself, for a session's account
|
|
379
|
+
* (its token renewed once when refused), or with an entity grant.
|
|
380
|
+
*/
|
|
381
|
+
core: {
|
|
382
|
+
asApp: (path: string, init?: RequestInit) => Promise<Response>;
|
|
383
|
+
forAccount: (session: import("./index.ts").AppSession, path: string, init?: RequestInit) => Promise<Response>;
|
|
384
|
+
withToken: (accessToken: string, path: string, init?: RequestInit) => Promise<Response>;
|
|
385
|
+
};
|
|
386
|
+
};
|
|
387
|
+
export type Platform = ReturnType<typeof createPlatform>;
|
package/dist/platform.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { AppManifestDeclarationSchema, AppManifestSchema, appBasePath, normalizeAppUrl, } from '@artemis-apps/contracts';
|
|
2
|
+
import { createRoutedFetch, createSilentLogger } from '@artemis-apps/server-kit';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
import { createAccountDeletionService, } from './account-deletion/account-deletion.service.js';
|
|
5
|
+
import { createCoreActivityClient } from './activity/core-activity.client.js';
|
|
6
|
+
import { createCoreApiClient } from './core-api/core-api.client.js';
|
|
7
|
+
import { createEnrollmentService } from './enrollment/enrollment.service.js';
|
|
8
|
+
import { createEntityGrantService } from './entity-grants/entity-grant.service.js';
|
|
9
|
+
import { createSecurityEventRoutes } from './events/security-event.routes.js';
|
|
10
|
+
import { createHandlerRoutes } from './handlers/handler.routes.js';
|
|
11
|
+
import { createAppIconRoutes } from './icon/app-icon.routes.js';
|
|
12
|
+
import { createAppKeyRepository } from './keys/app-key.repository.js';
|
|
13
|
+
import { createManifestRoutes } from './manifest/manifest.routes.js';
|
|
14
|
+
import { createOidcClient } from './oidc/oidc.client.js';
|
|
15
|
+
import { createProviderRoutes, providedTypes, } from './providers/provider.routes.js';
|
|
16
|
+
import { createCoreRelayRoutes } from './relay/core-relay.routes.js';
|
|
17
|
+
import { createAppCookies } from './session/app.cookies.js';
|
|
18
|
+
import { createAppSessionRepository } from './session/app-session.repository.js';
|
|
19
|
+
import { createAppSignInAttemptRepository } from './session/app-sign-in-attempt.repository.js';
|
|
20
|
+
import { createRequireAdministrator, createRequirePermissions, } from './session/require-permissions.middleware.js';
|
|
21
|
+
import { createSessionRoutes } from './session/session.routes.js';
|
|
22
|
+
import { createSessionService } from './session/session.service.js';
|
|
23
|
+
import { createCoreStorageClient } from './storage/core-storage.client.js';
|
|
24
|
+
/** URLs normalized and the declaration validated once, so every component compares like with like. */
|
|
25
|
+
export function normalizePlatformConfig(config) {
|
|
26
|
+
const coreUrl = normalizeAppUrl(config.coreUrl);
|
|
27
|
+
const { coreInternalUrl } = config;
|
|
28
|
+
return {
|
|
29
|
+
...config,
|
|
30
|
+
appUrl: normalizeAppUrl(config.appUrl),
|
|
31
|
+
coreUrl,
|
|
32
|
+
manifest: AppManifestDeclarationSchema.parse(config.manifest),
|
|
33
|
+
// Every request to the core goes through `fetch`: reaching it internally is decided here.
|
|
34
|
+
fetch: coreInternalUrl
|
|
35
|
+
? createRoutedFetch({
|
|
36
|
+
routes: () => [{ publicUrl: coreUrl, internalOrigin: coreInternalUrl }],
|
|
37
|
+
fetch: config.fetch,
|
|
38
|
+
})
|
|
39
|
+
: config.fetch,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Makes a Hono server an app of the platform: key and manifest, enrollment, sign-in, security
|
|
44
|
+
* events, the relay to the core for its web client, what it provides, a permission guard,
|
|
45
|
+
* storage and activity.
|
|
46
|
+
*/
|
|
47
|
+
export function createPlatform({ database, config: rawConfig, logger = createSilentLogger(), onAccountDeleted, providers = {}, handlers = {}, }) {
|
|
48
|
+
const config = normalizePlatformConfig(rawConfig);
|
|
49
|
+
const { types } = config.manifest;
|
|
50
|
+
const provides = providedTypes(types, providers);
|
|
51
|
+
const appKey = createAppKeyRepository(database).findOrCreate();
|
|
52
|
+
const completeManifest = appKey.then(({ publicJwk }) => AppManifestSchema.parse({
|
|
53
|
+
...config.manifest,
|
|
54
|
+
url: config.appUrl,
|
|
55
|
+
provides,
|
|
56
|
+
jwks: { keys: [publicJwk] },
|
|
57
|
+
}));
|
|
58
|
+
const manifest = () => completeManifest;
|
|
59
|
+
const sessions = createAppSessionRepository(database);
|
|
60
|
+
const signInAttempts = createAppSignInAttemptRepository(database);
|
|
61
|
+
const oidcClient = createOidcClient({ config, appKey });
|
|
62
|
+
const enrollment = createEnrollmentService({
|
|
63
|
+
config,
|
|
64
|
+
oidcClient,
|
|
65
|
+
manifest,
|
|
66
|
+
sessions,
|
|
67
|
+
signInAttempts,
|
|
68
|
+
logger,
|
|
69
|
+
});
|
|
70
|
+
const sessionService = createSessionService({
|
|
71
|
+
config,
|
|
72
|
+
oidcClient,
|
|
73
|
+
enrollment,
|
|
74
|
+
sessions,
|
|
75
|
+
signInAttempts,
|
|
76
|
+
});
|
|
77
|
+
const coreApi = createCoreApiClient({ config, enrollment, sessionService });
|
|
78
|
+
const cookies = createAppCookies({ config });
|
|
79
|
+
const requirePermissions = createRequirePermissions({
|
|
80
|
+
appId: config.manifest.id,
|
|
81
|
+
sessionService,
|
|
82
|
+
sessionCookie: cookies.session,
|
|
83
|
+
});
|
|
84
|
+
const accountDeletionService = createAccountDeletionService({
|
|
85
|
+
sessions,
|
|
86
|
+
onAccountDeleted,
|
|
87
|
+
logger,
|
|
88
|
+
});
|
|
89
|
+
const routes = new Hono()
|
|
90
|
+
.route('/', createManifestRoutes({ manifest }))
|
|
91
|
+
.route('/', createSecurityEventRoutes({
|
|
92
|
+
appId: config.manifest.id,
|
|
93
|
+
oidcClient,
|
|
94
|
+
enrollment,
|
|
95
|
+
accountDeletionService,
|
|
96
|
+
}))
|
|
97
|
+
.route('/', createAppIconRoutes({ icon: config.icon }))
|
|
98
|
+
.route('/', createSessionRoutes({ config, manifest, enrollment, sessionService, oidcClient, cookies }))
|
|
99
|
+
.route('/', createCoreRelayRoutes({
|
|
100
|
+
basePath: appBasePath(config.appUrl),
|
|
101
|
+
coreApi,
|
|
102
|
+
sessionService,
|
|
103
|
+
sessionCookie: cookies.session,
|
|
104
|
+
}))
|
|
105
|
+
.route('/', createProviderRoutes({ types, providers, oidcClient }))
|
|
106
|
+
.route('/', createHandlerRoutes({ manifest: config.manifest, handlers, oidcClient }));
|
|
107
|
+
return {
|
|
108
|
+
/** Mount at `/`: every path comes from `APP_PROTOCOL_PATHS`. */
|
|
109
|
+
routes,
|
|
110
|
+
requirePermissions,
|
|
111
|
+
/** Guards the app's own settings: administrators of the platform's apps only. */
|
|
112
|
+
requireAdministrator: createRequireAdministrator(requirePermissions),
|
|
113
|
+
/** The app's files on the core storage, with its own token. */
|
|
114
|
+
storage: createCoreStorageClient({ coreUrl: config.coreUrl, coreApi }),
|
|
115
|
+
/** The app's events, reported to the core's activity log (fire and forget). */
|
|
116
|
+
activity: createCoreActivityClient({ coreApi, logger }),
|
|
117
|
+
/** Grants of one entity, for work that outlives the account's session. */
|
|
118
|
+
entityGrants: createEntityGrantService({ oidcClient, sessionService }),
|
|
119
|
+
/**
|
|
120
|
+
* The core's API, called by the app's server: as the app itself, for a session's account
|
|
121
|
+
* (its token renewed once when refused), or with an entity grant.
|
|
122
|
+
*/
|
|
123
|
+
core: { asApp: coreApi.asApp, forAccount: coreApi.forAccount, withToken: coreApi.withToken },
|
|
124
|
+
};
|
|
125
|
+
}
|