@artemis-apps/contracts 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 (44) hide show
  1. package/dist/activity.d.ts +150 -0
  2. package/dist/activity.js +159 -0
  3. package/dist/api-error.d.ts +8 -0
  4. package/dist/api-error.js +7 -0
  5. package/dist/app-protocol.d.ts +290 -0
  6. package/dist/app-protocol.js +357 -0
  7. package/dist/app-session-state.d.ts +98 -0
  8. package/dist/app-session-state.js +38 -0
  9. package/dist/core-api.d.ts +799 -0
  10. package/dist/core-api.js +345 -0
  11. package/dist/entities/account.entity.d.ts +34 -0
  12. package/dist/entities/account.entity.js +15 -0
  13. package/dist/entities/avatar.entity.d.ts +31 -0
  14. package/dist/entities/avatar.entity.js +30 -0
  15. package/dist/entities/entity-name.d.ts +3 -0
  16. package/dist/entities/entity-name.js +2 -0
  17. package/dist/entities.d.ts +350 -0
  18. package/dist/entities.js +200 -0
  19. package/dist/entity-shares.d.ts +86 -0
  20. package/dist/entity-shares.js +29 -0
  21. package/dist/entity-types.d.ts +153 -0
  22. package/dist/entity-types.js +248 -0
  23. package/dist/images.d.ts +6 -0
  24. package/dist/images.js +10 -0
  25. package/dist/index.d.ts +20 -0
  26. package/dist/index.js +24 -0
  27. package/dist/marketplace.d.ts +183 -0
  28. package/dist/marketplace.js +162 -0
  29. package/dist/oidc.d.ts +25 -0
  30. package/dist/oidc.js +36 -0
  31. package/dist/permissions.d.ts +70 -0
  32. package/dist/permissions.js +101 -0
  33. package/dist/preferences.d.ts +30 -0
  34. package/dist/preferences.js +18 -0
  35. package/dist/return-path.d.ts +7 -0
  36. package/dist/return-path.js +21 -0
  37. package/dist/route-path.d.ts +5 -0
  38. package/dist/route-path.js +10 -0
  39. package/dist/storage.d.ts +43 -0
  40. package/dist/storage.js +39 -0
  41. package/dist/web-url.d.ts +7 -0
  42. package/dist/web-url.js +7 -0
  43. package/package.json +45 -3
  44. package/README.md +0 -3
@@ -0,0 +1,357 @@
1
+ import { z } from 'zod';
2
+ import { EntityTypeDefinitionSchema, EntityTypeIdSchema, REQUIRED_OPERATIONS, } from './entity-types.js';
3
+ import { DelegablePermissionSchema, isTypePermission, parseTypePermission, typePermission, } from './permissions.js';
4
+ import { WebUrlSchema } from './web-url.js';
5
+ /**
6
+ * Conventions every app follows so that a core can enroll it without knowing it beforehand.
7
+ * Paths are relative to the app URL.
8
+ */
9
+ export const APP_PROTOCOL_PATHS = {
10
+ /** GET: the app manifest (`AppManifest`), the one an administrator pastes into the core. */
11
+ manifest: '/.well-known/artemis/app.json',
12
+ /** GET: the app icon (SVG), shown by the core's app switcher. */
13
+ icon: '/.well-known/artemis/icon.svg',
14
+ /**
15
+ * POST: the core pushes security events here (RFC 8935: `Content-Type:
16
+ * application/secevent+jwt`, a signed Security Event Token as body, `202` once handled).
17
+ */
18
+ events: '/.well-known/artemis/events',
19
+ /** GET: session state for the app web client (`AppSessionState`). */
20
+ session: '/api/platform/session',
21
+ /** GET: starts the OAuth sign-in flow (accepts `RETURN_TO_PARAM`). */
22
+ signIn: '/api/platform/sign-in',
23
+ /** GET: the OAuth redirect URI. */
24
+ callback: '/api/platform/callback',
25
+ /** POST: ends the app session (`SignOutResponse`). */
26
+ signOut: '/api/platform/sign-out',
27
+ /** POST `logout_token` (form): OIDC back-channel logout, sent by the core. */
28
+ backChannelLogout: '/api/platform/back-channel-logout',
29
+ /**
30
+ * Any method: the relay to the core's API for the app's web client. `<relay>/<path>` is
31
+ * forwarded to the core's `/api/<path>` with the session's access token, for the paths of
32
+ * `CORE_RELAYED_PATHS` only; the request and the answer pass through as they are.
33
+ */
34
+ coreRelay: '/api/core',
35
+ /**
36
+ * What the app provides (`docs/architecture/entities/`), called by the core only, with a
37
+ * provider token: GET (list) → `ProviderEntityList`; POST (create) → `ProviderEntity`.
38
+ */
39
+ providedEntities: '/api/platform/entities/:type',
40
+ /** GET (read), PATCH (update) → `ProviderEntity`; DELETE → 204. Called by the core only. */
41
+ providedEntity: '/api/platform/entities/:type/:entityId',
42
+ /** Any method: one of the type's own operations; its answer passes through the core. */
43
+ providedOperation: '/api/platform/entities/:type/:entityId/operations/:operation',
44
+ /**
45
+ * A web page of an app handling an action on entities of a type (`handles`): other apps' web
46
+ * clients send people there, the entity named in the query (`formatHandleQuery`).
47
+ */
48
+ handle: '/handle/:type/:action',
49
+ /**
50
+ * POST `HandledActionCall` → the action's answer (a picture, for `preview`): a `server`
51
+ * action of the app, called by the core only, with a token it signed for this app.
52
+ */
53
+ handledAction: '/api/platform/handlers/:type/:action',
54
+ };
55
+ /** Conventions of the core that apps rely on. Paths are relative to the core URL. */
56
+ export const CORE_PROTOCOL_PATHS = {
57
+ /** Page where the signed-in account manages itself (profile, password). */
58
+ accountPage: '/account',
59
+ /** OAuth / OpenID Connect issuer; discovery lives at `<issuer>/.well-known/openid-configuration`. */
60
+ oidcIssuer: '/oidc',
61
+ /**
62
+ * RP-initiated logout (under the issuer): ends the core's OIDC session and tells every app the
63
+ * browser signed in to (back-channel logout).
64
+ */
65
+ endSession: '/oidc/session/end',
66
+ };
67
+ /** The OAuth issuer identifier of a core. */
68
+ export function coreIssuerUrl(coreUrl) {
69
+ return new URL(CORE_PROTOCOL_PATHS.oidcIssuer, coreUrl).toString();
70
+ }
71
+ /** An app id: also its OAuth `client_id` and the owner of its cookies. */
72
+ export const AppIdSchema = z
73
+ .string()
74
+ .regex(/^[a-z][a-z0-9-]{1,31}$/, 'Expected a lowercase slug of 2 to 32 characters');
75
+ /** The only signing algorithm of the platform's clients (`private_key_jwt`). */
76
+ export const APP_KEY_ALGORITHM = 'ES256';
77
+ /**
78
+ * A public signing key of an app (JWK, EC P-256). Strict: a key carrying private parts (`d`)
79
+ * is refused, so a private key can never be published by mistake.
80
+ */
81
+ export const AppPublicKeySchema = z.strictObject({
82
+ kty: z.literal('EC'),
83
+ crv: z.literal('P-256'),
84
+ x: z.string().min(1),
85
+ y: z.string().min(1),
86
+ kid: z.string().min(1),
87
+ alg: z.literal(APP_KEY_ALGORITHM),
88
+ use: z.literal('sig'),
89
+ });
90
+ /**
91
+ * A path from an app's root (`/icons/document.svg`): the core makes it absolute. Never `//`
92
+ * first: that names another host (`//internal-host/x`), which the core would then fetch.
93
+ */
94
+ export const AppPathSchema = z
95
+ .string()
96
+ .max(200)
97
+ .regex(/^\/(?!\/)[A-Za-z0-9._~/-]*$/, 'Expected a path from the app root');
98
+ /**
99
+ * A kind of entity an app supports (`kinds` of its manifest), from its type's vocabulary: its
100
+ * icon, and the blank `template` new entities of the kind start from, when the app offers one.
101
+ * Paths are from the app's root. Office supports a `drive.item` of kind `document`: its icon is
102
+ * `/icons/document.svg`, a new one is a copy of `/templates/document.docx`.
103
+ */
104
+ export const SupportedKindSchema = z.strictObject({
105
+ kind: z.string().min(1).max(40),
106
+ icon: AppPathSchema,
107
+ template: AppPathSchema.optional(),
108
+ });
109
+ /** What an app declares about itself in code; the platform completes it into its `AppManifest`. */
110
+ export const AppManifestDeclarationSchema = z.object({
111
+ id: AppIdSchema,
112
+ name: z.string().trim().min(1).max(60),
113
+ description: z.string().trim().max(280).optional(),
114
+ /** The most the app may ever ask an account for: core permissions and type permissions. */
115
+ permissions: z.array(DelegablePermissionSchema).min(1),
116
+ /** Every entity type the app uses or provides, as its type packages define them. */
117
+ types: z.array(EntityTypeDefinitionSchema).max(50),
118
+ /**
119
+ * Whether the app shows in the app switcher (true when left out). An app with no page of its
120
+ * own to open (an editor other apps send people to) says `false`.
121
+ */
122
+ listed: z.boolean().optional(),
123
+ /** By type: the kinds the app supports, their icons and templates (see `SupportedKindSchema`). */
124
+ kinds: z.record(EntityTypeIdSchema, z.array(SupportedKindSchema).min(1).max(50)).optional(),
125
+ /**
126
+ * By type, then by action: the kinds the app handles the action for, among those it supports
127
+ * (their icons show next to the action).
128
+ */
129
+ handles: z
130
+ .record(EntityTypeIdSchema, z.record(z.string().min(1).max(40), z.array(z.string().min(1).max(40)).min(1).max(50)))
131
+ .optional(),
132
+ });
133
+ /** What an app provides of one type: the operations it implements (`list` and `read` at least). */
134
+ export const ProvidedTypeSchema = z.strictObject({
135
+ operations: z.array(z.string().min(1).max(40)).min(REQUIRED_OPERATIONS.length).max(40),
136
+ });
137
+ /** Everything a core needs to enroll an app: an administrator pastes it into the core. */
138
+ export const AppManifestSchema = z
139
+ .strictObject({
140
+ ...AppManifestDeclarationSchema.shape,
141
+ /** The app's URL: its origin, and the base path it lives under, if any (see `normalizeAppUrl`). */
142
+ url: WebUrlSchema,
143
+ /** By type: what the app provides to the platform (see `docs/architecture/entities/`). */
144
+ provides: z.record(EntityTypeIdSchema, ProvidedTypeSchema),
145
+ /** The keys the app signs its client authentication with (`private_key_jwt`). */
146
+ jwks: z.strictObject({ keys: z.array(AppPublicKeySchema).min(1).max(4) }),
147
+ })
148
+ .superRefine((manifest, context) => {
149
+ for (const problem of manifestProblems(manifest)) {
150
+ context.addIssue({ code: 'custom', message: problem });
151
+ }
152
+ });
153
+ /** What makes a manifest's types, permissions and provided types inconsistent (none: valid). */
154
+ export function manifestProblems(manifest) {
155
+ const problems = [];
156
+ const types = new Map(manifest.types.map((type) => [type.id, type]));
157
+ if (types.size !== manifest.types.length)
158
+ problems.push('A type is declared twice.');
159
+ for (const type of manifest.types) {
160
+ if (type.parent && !types.has(type.parent)) {
161
+ problems.push(`\`${type.id}\` lives in \`${type.parent}\`, which is not declared.`);
162
+ }
163
+ }
164
+ for (const permission of manifest.permissions) {
165
+ if (!isTypePermission(permission))
166
+ continue;
167
+ const { type, permission: name } = parseTypePermission(permission);
168
+ const declared = types.get(type);
169
+ if (!declared || !Object.hasOwn(declared.permissions, name)) {
170
+ problems.push(`\`${permission}\` is not a permission of a declared type.`);
171
+ }
172
+ }
173
+ for (const [typeId, supported] of Object.entries(manifest.kinds ?? {})) {
174
+ const type = types.get(typeId);
175
+ if (!type) {
176
+ problems.push(`\`${typeId}\` has kinds but is not declared.`);
177
+ continue;
178
+ }
179
+ const names = supported.map(({ kind }) => kind);
180
+ if (new Set(names).size !== names.length) {
181
+ problems.push(`A kind of \`${typeId}\` is supported twice.`);
182
+ }
183
+ for (const kind of names) {
184
+ if (!type.kinds.includes(kind))
185
+ problems.push(`\`${kind}\` is not a kind of \`${typeId}\`.`);
186
+ }
187
+ }
188
+ for (const [typeId, actions] of Object.entries(manifest.handles ?? {})) {
189
+ const type = types.get(typeId);
190
+ if (!type) {
191
+ problems.push(`\`${typeId}\` is handled but not declared.`);
192
+ continue;
193
+ }
194
+ const supported = new Set((manifest.kinds?.[typeId] ?? []).map(({ kind }) => kind));
195
+ for (const [action, handlers] of Object.entries(actions)) {
196
+ const permission = type.actions[action]?.permission;
197
+ if (permission === undefined) {
198
+ problems.push(`\`${action}\` is not an action of \`${typeId}\`.`);
199
+ continue;
200
+ }
201
+ if (!manifest.permissions.includes(typePermission(typeId, permission))) {
202
+ problems.push(`Handling \`${action}\` on \`${typeId}\` needs \`${typeId}:${permission}\`.`);
203
+ }
204
+ for (const kind of handlers) {
205
+ if (!supported.has(kind)) {
206
+ problems.push(`Handling \`${action}\` for \`${kind}\` needs supporting that kind (\`kinds\`).`);
207
+ }
208
+ }
209
+ }
210
+ }
211
+ for (const [typeId, provided] of Object.entries(manifest.provides)) {
212
+ const type = types.get(typeId);
213
+ if (!type) {
214
+ problems.push(`\`${typeId}\` is provided but not declared.`);
215
+ continue;
216
+ }
217
+ for (const operation of REQUIRED_OPERATIONS) {
218
+ if (!provided.operations.includes(operation)) {
219
+ problems.push(`Providing \`${typeId}\` is serving \`${operation}\`.`);
220
+ }
221
+ }
222
+ for (const operation of provided.operations) {
223
+ if (!Object.hasOwn(type.operations, operation)) {
224
+ problems.push(`\`${operation}\` is not an operation of \`${typeId}\`.`);
225
+ }
226
+ }
227
+ if (type.parent && !(type.parent in manifest.provides)) {
228
+ problems.push(`Providing \`${typeId}\` is providing \`${type.parent}\` too.`);
229
+ }
230
+ }
231
+ return problems;
232
+ }
233
+ /**
234
+ * Security events the core pushes to apps (RFC 8417 Security Event Tokens), by event type
235
+ * URI. Each token carries exactly one event, about its `sub`.
236
+ */
237
+ export const SECURITY_EVENTS = {
238
+ /** `sub` is the deleted account: the app forgets it. */
239
+ accountDeleted: 'urn:artemis:event:account-deleted',
240
+ /** `sub` is the app: the core revoked it, it is unenrolled. */
241
+ appRevoked: 'urn:artemis:event:app-revoked',
242
+ };
243
+ export const SecurityEventSchema = z.enum([
244
+ SECURITY_EVENTS.accountDeleted,
245
+ SECURITY_EVENTS.appRevoked,
246
+ ]);
247
+ /** The JWT `typ` of Security Event Tokens (RFC 8417). */
248
+ export const SECURITY_EVENT_TOKEN_TYPE = 'secevent+jwt';
249
+ /** The `Content-Type` of a pushed Security Event Token (RFC 8935). */
250
+ export const SECURITY_EVENT_CONTENT_TYPE = `application/${SECURITY_EVENT_TOKEN_TYPE}`;
251
+ export class InvalidAppUrlError extends Error {
252
+ name = 'InvalidAppUrlError';
253
+ }
254
+ /** A base path an app may live under: lowercase segments (`/apps/drive`), no trailing slash. */
255
+ const BASE_PATH_PATTERN = /^(\/[a-z0-9][a-z0-9._-]*)*$/;
256
+ /**
257
+ * An app is identified by its URL: an origin (scheme + host + port), alone or followed by the
258
+ * base path it lives under (`https://example.com/apps/drive`, when a gateway serves several apps
259
+ * on one host). Never a trailing slash, a query or a fragment.
260
+ * Throws `InvalidAppUrlError` for anything else (credentials, non-http schemes...).
261
+ */
262
+ export function normalizeAppUrl(input) {
263
+ let url;
264
+ try {
265
+ url = new URL(input.trim());
266
+ }
267
+ catch {
268
+ throw new InvalidAppUrlError('App URL is not a valid URL.');
269
+ }
270
+ if (url.protocol !== 'http:' && url.protocol !== 'https:') {
271
+ throw new InvalidAppUrlError('App URL must use http or https.');
272
+ }
273
+ if (url.username || url.password) {
274
+ throw new InvalidAppUrlError('App URL must not contain credentials.');
275
+ }
276
+ if (url.search || url.hash) {
277
+ throw new InvalidAppUrlError('App URL must not have a query or a fragment.');
278
+ }
279
+ const basePath = url.pathname.replace(/\/+$/, '');
280
+ if (!BASE_PATH_PATTERN.test(basePath)) {
281
+ throw new InvalidAppUrlError('App URL path must be made of lowercase segments.');
282
+ }
283
+ return `${url.origin}${basePath}`;
284
+ }
285
+ /** The base path of an app URL: `''` for an app at the root of its origin, else `/apps/drive`. */
286
+ export function appBasePath(appUrl) {
287
+ return new URL(appUrl).pathname.replace(/\/+$/, '');
288
+ }
289
+ export function isLoopbackUrl(url) {
290
+ const { hostname } = new URL(url);
291
+ return (hostname === 'localhost' ||
292
+ hostname.endsWith('.localhost') ||
293
+ hostname === '127.0.0.1' ||
294
+ hostname === '[::1]');
295
+ }
296
+ /**
297
+ * Whether `url` lies at or under the app URL `appUrl` (same origin, within its base path).
298
+ * `https://x.com/apps/drive` holds `https://x.com/apps/drive/api`, not `https://x.com/apps/drivex`.
299
+ */
300
+ export function isWithinAppUrl(url, appUrl) {
301
+ const target = new URL(url);
302
+ const app = new URL(appUrl);
303
+ if (target.origin !== app.origin)
304
+ return false;
305
+ const base = appBasePath(appUrl);
306
+ return base === '' || target.pathname === base || target.pathname.startsWith(`${base}/`);
307
+ }
308
+ /**
309
+ * An address on the app, from a path of its root (under its base path, if any). Throws for a
310
+ * path leading off the app (another origin, `..` out of its base path): whatever an app declares,
311
+ * the core only ever calls the app itself.
312
+ */
313
+ export function appEndpoint(appUrl, path) {
314
+ const base = new URL(appUrl);
315
+ const url = new URL(`${appBasePath(appUrl)}${path.startsWith('/') ? '' : '/'}${path}`, base);
316
+ if (!path.startsWith('/') || path.startsWith('//') || !isWithinAppUrl(url.href, appUrl)) {
317
+ throw new Error(`"${path}" leads off the app.`);
318
+ }
319
+ return url.toString();
320
+ }
321
+ /** Redirect URI registered for an enrolled app. Derived from the convention, never declared. */
322
+ export function appRedirectUri(appUrl) {
323
+ return appEndpoint(appUrl, APP_PROTOCOL_PATHS.callback);
324
+ }
325
+ /**
326
+ * The query of a handle page (`APP_PROTOCOL_PATHS.handle`): the entity the action is about, the
327
+ * share it is reached through, and its kind.
328
+ */
329
+ export const HANDLE_PARAMS = {
330
+ provider: 'provider',
331
+ owner: 'owner',
332
+ id: 'id',
333
+ /** `<type>:<id>` of the shared entity, when reached through a share. */
334
+ via: 'via',
335
+ kind: 'kind',
336
+ };
337
+ export function formatHandleQuery({ providerId, ownerId, id, via, kind }) {
338
+ const query = new URLSearchParams({
339
+ [HANDLE_PARAMS.provider]: providerId,
340
+ [HANDLE_PARAMS.owner]: ownerId,
341
+ [HANDLE_PARAMS.id]: id,
342
+ [HANDLE_PARAMS.kind]: kind,
343
+ });
344
+ if (via)
345
+ query.set(HANDLE_PARAMS.via, via);
346
+ return query.toString();
347
+ }
348
+ /** Reads a handle page's query back; `undefined` when it names no entity. */
349
+ export function parseHandleQuery(query) {
350
+ const providerId = query.get(HANDLE_PARAMS.provider);
351
+ const ownerId = query.get(HANDLE_PARAMS.owner);
352
+ const id = query.get(HANDLE_PARAMS.id);
353
+ const kind = query.get(HANDLE_PARAMS.kind);
354
+ if (!providerId || !ownerId || !id || !kind)
355
+ return undefined;
356
+ return { providerId, ownerId, id, kind, via: query.get(HANDLE_PARAMS.via) };
357
+ }
@@ -0,0 +1,98 @@
1
+ import { z } from 'zod';
2
+ /** What an app web client learns about its own state (`APP_PROTOCOL_PATHS.session`). */
3
+ export declare const AppSessionStateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
4
+ status: z.ZodLiteral<"unenrolled">;
5
+ manifest: z.ZodObject<{
6
+ id: z.ZodString;
7
+ name: z.ZodString;
8
+ description: z.ZodOptional<z.ZodString>;
9
+ permissions: z.ZodArray<z.ZodType<import("./permissions.ts").DelegablePermission, string, z.core.$ZodTypeInternals<import("./permissions.ts").DelegablePermission, string>>>;
10
+ types: z.ZodArray<z.ZodObject<{
11
+ id: z.ZodString;
12
+ version: z.ZodInt;
13
+ parent: z.ZodNullable<z.ZodString>;
14
+ titleFields: z.ZodArray<z.ZodString>;
15
+ schema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
16
+ permissions: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
17
+ operations: z.ZodRecord<z.ZodString, z.ZodString>;
18
+ kinds: z.ZodDefault<z.ZodArray<z.ZodString>>;
19
+ actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
20
+ permission: z.ZodString;
21
+ target: z.ZodEnum<{
22
+ page: "page";
23
+ server: "server";
24
+ }>;
25
+ }, z.core.$strict>>>;
26
+ messages: z.ZodRecord<z.ZodEnum<{
27
+ en: "en";
28
+ fr: "fr";
29
+ }> & z.core.$partial, z.ZodObject<{
30
+ name: z.ZodString;
31
+ plural: z.ZodString;
32
+ permissions: z.ZodRecord<z.ZodString, z.ZodObject<{
33
+ label: z.ZodString;
34
+ description: z.ZodString;
35
+ }, z.core.$strip>>;
36
+ operations: z.ZodRecord<z.ZodString, z.ZodString>;
37
+ kinds: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
38
+ actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
39
+ }, z.core.$strip>>;
40
+ }, z.core.$strict>>;
41
+ listed: z.ZodOptional<z.ZodBoolean>;
42
+ kinds: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodObject<{
43
+ kind: z.ZodString;
44
+ icon: z.ZodString;
45
+ template: z.ZodOptional<z.ZodString>;
46
+ }, z.core.$strict>>>>;
47
+ handles: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>>;
48
+ url: z.ZodURL;
49
+ provides: z.ZodRecord<z.ZodString, z.ZodObject<{
50
+ operations: z.ZodArray<z.ZodString>;
51
+ }, z.core.$strict>>;
52
+ jwks: z.ZodObject<{
53
+ keys: z.ZodArray<z.ZodObject<{
54
+ kty: z.ZodLiteral<"EC">;
55
+ crv: z.ZodLiteral<"P-256">;
56
+ x: z.ZodString;
57
+ y: z.ZodString;
58
+ kid: z.ZodString;
59
+ alg: z.ZodLiteral<"ES256">;
60
+ use: z.ZodLiteral<"sig">;
61
+ }, z.core.$strict>>;
62
+ }, z.core.$strict>;
63
+ }, z.core.$strict>;
64
+ coreUrl: z.ZodURL;
65
+ }, z.core.$strip>, z.ZodObject<{
66
+ status: z.ZodLiteral<"unauthenticated">;
67
+ signInUrl: z.ZodString;
68
+ }, z.core.$strip>, z.ZodObject<{
69
+ status: z.ZodLiteral<"authenticated">;
70
+ appId: z.ZodString;
71
+ account: z.ZodObject<{
72
+ id: z.ZodUUID;
73
+ email: z.ZodEmail;
74
+ name: z.ZodString;
75
+ avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
76
+ kind: z.ZodLiteral<"generated">;
77
+ seed: z.ZodUUID;
78
+ }, z.core.$strip>, z.ZodObject<{
79
+ kind: z.ZodLiteral<"file">;
80
+ fileId: z.ZodUUID;
81
+ url: z.ZodURL;
82
+ }, z.core.$strip>], "kind">;
83
+ }, z.core.$strip>;
84
+ permissions: z.ZodArray<z.ZodType<import("./permissions.ts").DelegablePermission, string, z.core.$ZodTypeInternals<import("./permissions.ts").DelegablePermission, string>>>;
85
+ preferences: z.ZodObject<{
86
+ locale: z.ZodEnum<{
87
+ en: "en";
88
+ fr: "fr";
89
+ }>;
90
+ }, z.core.$strip>;
91
+ administrator: z.ZodBoolean;
92
+ coreUrl: z.ZodURL;
93
+ }, z.core.$strip>], "status">;
94
+ export type AppSessionState = z.infer<typeof AppSessionStateSchema>;
95
+ export declare const SignOutResponseSchema: z.ZodObject<{
96
+ redirectTo: z.ZodURL;
97
+ }, z.core.$strip>;
98
+ export type SignOutResponse = z.infer<typeof SignOutResponseSchema>;
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+ import { AppManifestSchema } from './app-protocol.js';
3
+ import { AccountSchema } from './entities/account.entity.js';
4
+ import { DelegablePermissionSchema } from './permissions.js';
5
+ import { AccountPreferencesSchema } from './preferences.js';
6
+ /** What an app web client learns about its own state (`APP_PROTOCOL_PATHS.session`). */
7
+ export const AppSessionStateSchema = z.discriminatedUnion('status', [
8
+ z.object({
9
+ status: z.literal('unenrolled'),
10
+ /** What an administrator pastes into the core to enroll the app. */
11
+ manifest: AppManifestSchema,
12
+ /** Where the administrator enrolls it. */
13
+ coreUrl: z.url(),
14
+ }),
15
+ z.object({
16
+ status: z.literal('unauthenticated'),
17
+ signInUrl: z.string().min(1),
18
+ }),
19
+ z.object({
20
+ status: z.literal('authenticated'),
21
+ /** This app's manifest id. */
22
+ appId: z.string().min(1),
23
+ account: AccountSchema,
24
+ /** Permissions granted to this app for this account. */
25
+ permissions: z.array(DelegablePermissionSchema),
26
+ /** How the account wants the app to speak. */
27
+ preferences: AccountPreferencesSchema,
28
+ /**
29
+ * Whether the account administers the platform's apps (`admin:apps:write` in the core): the
30
+ * app shows it its own settings.
31
+ */
32
+ administrator: z.boolean(),
33
+ coreUrl: z.url(),
34
+ }),
35
+ ]);
36
+ export const SignOutResponseSchema = z.object({
37
+ redirectTo: z.url(),
38
+ });