@artemis-apps/contracts 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/activity.d.ts +150 -0
- package/dist/activity.js +159 -0
- package/dist/api-error.d.ts +8 -0
- package/dist/api-error.js +7 -0
- package/dist/app-protocol.d.ts +290 -0
- package/dist/app-protocol.js +357 -0
- package/dist/app-session-state.d.ts +98 -0
- package/dist/app-session-state.js +38 -0
- package/dist/core-api.d.ts +799 -0
- package/dist/core-api.js +345 -0
- package/dist/entities/account.entity.d.ts +34 -0
- package/dist/entities/account.entity.js +15 -0
- package/dist/entities/avatar.entity.d.ts +31 -0
- package/dist/entities/avatar.entity.js +30 -0
- package/dist/entities/entity-name.d.ts +3 -0
- package/dist/entities/entity-name.js +2 -0
- package/dist/entities.d.ts +350 -0
- package/dist/entities.js +200 -0
- package/dist/entity-shares.d.ts +86 -0
- package/dist/entity-shares.js +29 -0
- package/dist/entity-types.d.ts +153 -0
- package/dist/entity-types.js +248 -0
- package/dist/images.d.ts +6 -0
- package/dist/images.js +10 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +24 -0
- package/dist/marketplace.d.ts +183 -0
- package/dist/marketplace.js +162 -0
- package/dist/oidc.d.ts +25 -0
- package/dist/oidc.js +36 -0
- package/dist/permissions.d.ts +70 -0
- package/dist/permissions.js +101 -0
- package/dist/preferences.d.ts +30 -0
- package/dist/preferences.js +18 -0
- package/dist/return-path.d.ts +7 -0
- package/dist/return-path.js +21 -0
- package/dist/route-path.d.ts +5 -0
- package/dist/route-path.js +10 -0
- package/dist/storage.d.ts +43 -0
- package/dist/storage.js +39 -0
- package/dist/web-url.d.ts +7 -0
- package/dist/web-url.js +7 -0
- package/package.json +45 -3
- package/README.md +0 -3
package/dist/core-api.js
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AppIdSchema, AppManifestSchema, ProvidedTypeSchema, SupportedKindSchema, } from './app-protocol.js';
|
|
3
|
+
import { AccountSchema, AccountWithPermissionsSchema } from './entities/account.entity.js';
|
|
4
|
+
import { EntityTypeDefinitionSchema, EntityTypeIdSchema } from './entity-types.js';
|
|
5
|
+
import { AdminPermissionSchema, DelegablePermissionSchema } from './permissions.js';
|
|
6
|
+
import { AccountPreferencesSchema } from './preferences.js';
|
|
7
|
+
import { WebUrlSchema } from './web-url.js';
|
|
8
|
+
/* Contract between the core web client and the core API. */
|
|
9
|
+
/** Core web page the API redirects to when a browser must sign in (with `RETURN_TO_PARAM`). */
|
|
10
|
+
export const CORE_SIGN_IN_PAGE_PATH = '/sign-in';
|
|
11
|
+
/** Home of the core's Account interface (the signed-in account managing itself). */
|
|
12
|
+
export const CORE_ACCOUNT_PAGE_PATH = '/account';
|
|
13
|
+
/** Home of the core's Admin interface (platform administration). */
|
|
14
|
+
export const CORE_ADMIN_PAGE_PATH = '/admin';
|
|
15
|
+
/** Admin › Applications: where an administrator enrolls an app by pasting its manifest. */
|
|
16
|
+
export const CORE_ADMIN_APPS_PAGE_PATH = '/admin/apps';
|
|
17
|
+
/**
|
|
18
|
+
* Query parameter of `CORE_ADMIN_APPS_PAGE_PATH` naming an app URL to enroll: the page reads the
|
|
19
|
+
* app's manifest from there and opens its review. An unenrolled app links to it.
|
|
20
|
+
*/
|
|
21
|
+
export const ENROLL_PARAM = 'enroll';
|
|
22
|
+
/** The core's marketplace page (administrators): app repositories and installed apps. */
|
|
23
|
+
export const CORE_ADMIN_MARKETPLACE_PAGE_PATH = '/admin/marketplace';
|
|
24
|
+
/** Icons of the core's own interfaces (SVG, cacheable, embeddable cross-origin by apps). */
|
|
25
|
+
export const CORE_BRAND_ICON_PATHS = {
|
|
26
|
+
account: '/brand/account.svg',
|
|
27
|
+
admin: '/brand/admin.svg',
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The core API paths an app's relay forwards for its web client (`APP_PROTOCOL_PATHS.coreRelay`):
|
|
31
|
+
* entities, entity types, the directory, the launcher. Nothing else reaches the core that way.
|
|
32
|
+
*/
|
|
33
|
+
export const CORE_RELAYED_PATHS = [
|
|
34
|
+
'/api/entities',
|
|
35
|
+
'/api/entity-types',
|
|
36
|
+
'/api/directory',
|
|
37
|
+
'/api/launcher',
|
|
38
|
+
];
|
|
39
|
+
/** Route patterns of the core API. Fill `:params` with `fillPath`. */
|
|
40
|
+
export const CORE_API_PATHS = {
|
|
41
|
+
/** POST `RegistrationInput` → `CurrentAccountResponse` (and signs in). */
|
|
42
|
+
registrations: '/api/registrations',
|
|
43
|
+
/** POST `SignInInput` → `CurrentAccountResponse`. */
|
|
44
|
+
sessions: '/api/sessions',
|
|
45
|
+
/** GET → `CurrentAccountResponse`; DELETE signs out. */
|
|
46
|
+
currentSession: '/api/sessions/current',
|
|
47
|
+
/** The signed-in account managing itself. PATCH `AccountUpdate` → `AccountWithPermissions`; DELETE `AccountDeletion` → 204. */
|
|
48
|
+
currentAccount: '/api/account',
|
|
49
|
+
/** PUT `PasswordChange` → 204 (other browser sessions are signed out). */
|
|
50
|
+
currentAccountPassword: '/api/account/password',
|
|
51
|
+
/** PATCH `AccountPreferencesUpdate` → `AccountPreferences` (the language, in every app). */
|
|
52
|
+
currentAccountPreferences: '/api/account/preferences',
|
|
53
|
+
/** PUT multipart (`file`: an accepted image) → `AccountWithPermissions`: the photo becomes the avatar. */
|
|
54
|
+
currentAccountAvatarPhoto: '/api/account/avatar/photo',
|
|
55
|
+
/** POST `AvatarRegeneration` → `AccountWithPermissions`: the generated face of that seed (any photo is deleted). */
|
|
56
|
+
currentAccountAvatarRegeneration: '/api/account/avatar/regeneration',
|
|
57
|
+
/**
|
|
58
|
+
* GET → `Launcher`: what the account can open (Account, Admin, enrolled apps).
|
|
59
|
+
* Authenticated either by the core browser session cookie (core web client), or by
|
|
60
|
+
* `Authorization: Bearer <access token>` issued by the core to an enrolled app: apps' servers
|
|
61
|
+
* call it for their web clients. No CORS: browsers never call it cross-origin.
|
|
62
|
+
*/
|
|
63
|
+
launcher: '/api/launcher',
|
|
64
|
+
/** GET → `AccountList` (`admin:accounts:read`). */
|
|
65
|
+
accounts: '/api/accounts',
|
|
66
|
+
/**
|
|
67
|
+
* GET `DirectoryQuery` → `DirectoryAccountList`: other accounts, to share with them
|
|
68
|
+
* (`directory:read`). Authenticated like `launcher`; apps' servers call it for their web
|
|
69
|
+
* clients and to show who a resource is shared with.
|
|
70
|
+
*/
|
|
71
|
+
directory: '/api/directory/accounts',
|
|
72
|
+
/** PUT `PermissionsUpdate` → `AccountWithPermissions` (`admin:accounts:write`). */
|
|
73
|
+
accountPermissions: '/api/accounts/:accountId/permissions',
|
|
74
|
+
/**
|
|
75
|
+
* GET → `EnrolledAppList` (`admin:apps:read`); POST `EnrollmentRequest` → `EnrolledApp`:
|
|
76
|
+
* enrolls the app of a pasted manifest (`admin:apps:write`).
|
|
77
|
+
*/
|
|
78
|
+
apps: '/api/apps',
|
|
79
|
+
/** DELETE `?deleteFiles=` (`AppRevocationQuery`) → 204: revokes an app (`admin:apps:write`). */
|
|
80
|
+
app: '/api/apps/:appId',
|
|
81
|
+
/**
|
|
82
|
+
* POST → `EnrolledApp`: applies the app's pending update; DELETE → 204: declines it, the app
|
|
83
|
+
* keeps what it had (`admin:apps:write`).
|
|
84
|
+
*/
|
|
85
|
+
appPendingUpdate: '/api/apps/:appId/pending-update',
|
|
86
|
+
/**
|
|
87
|
+
* PUT `AppOrder` → 204 (`admin:apps:write`): the order of the apps, everywhere they are listed
|
|
88
|
+
* (the app switcher included).
|
|
89
|
+
*/
|
|
90
|
+
appOrder: '/api/apps/order',
|
|
91
|
+
/** POST `EnrollmentRequest` → `EnrollmentReview`: what enrolling it would do (`admin:apps:write`). */
|
|
92
|
+
enrollmentReviews: '/api/enrollment-reviews',
|
|
93
|
+
/**
|
|
94
|
+
* PUT `AppManifest` → 204: an enrolled app sends its manifest at each start, with its
|
|
95
|
+
* `client_credentials` token (see "Updates" in docs/architecture/enrollment.md).
|
|
96
|
+
*/
|
|
97
|
+
appManifest: '/api/app-manifest',
|
|
98
|
+
/** GET → `EntityTypeList`: every entity type the enrolled apps declare, merged by version. */
|
|
99
|
+
entityTypes: '/api/entity-types',
|
|
100
|
+
/** GET → `EntityHandlerList`: the apps handling actions on entities of the type, and how. */
|
|
101
|
+
entityHandlers: '/api/entity-types/:type/handlers',
|
|
102
|
+
/** GET → `EntityKindList`: the kinds the enrolled apps support for the type, and their icons. */
|
|
103
|
+
entityKinds: '/api/entity-types/:type/kinds',
|
|
104
|
+
/**
|
|
105
|
+
* GET → the blank template of a kind an app supports (its bytes and type, as the app serves
|
|
106
|
+
* them): what a new entity of that kind starts from.
|
|
107
|
+
*/
|
|
108
|
+
entityKindTemplate: '/api/entity-types/:type/kinds/:appId/:kind/template',
|
|
109
|
+
/**
|
|
110
|
+
* POST `?kind=` (and `?app=` to pick the handling app) → the answer of a `server` action
|
|
111
|
+
* (`preview`), run by a handling app on the entity. Called by a consumer for the account, or
|
|
112
|
+
* by the entity's provider as itself (its own token), for the owner.
|
|
113
|
+
*/
|
|
114
|
+
entityAction: '/api/entities/:type/:providerId/:ownerId/:entityId/actions/:action',
|
|
115
|
+
/**
|
|
116
|
+
* GET → `EntityList`: every entity of the type the account reaches, from every provider; the
|
|
117
|
+
* filter (`only`, `except`) chooses providers, other parameters go on to them.
|
|
118
|
+
*/
|
|
119
|
+
entities: '/api/entities/:type',
|
|
120
|
+
/**
|
|
121
|
+
* POST (the provider's body, passed through) → `EntityResult`: creates at that provider, in
|
|
122
|
+
* `?parent=<ownerId>:<id>` if any. Needs the type's `create` permission.
|
|
123
|
+
*/
|
|
124
|
+
providerEntities: '/api/entities/:type/:providerId',
|
|
125
|
+
/**
|
|
126
|
+
* GET → `EntityResult`; PATCH (body passed through; `?parent=<id>` moves it) → `EntityResult`;
|
|
127
|
+
* DELETE → 204. Each takes `?via=<type>:<id>` when acting through a share.
|
|
128
|
+
*/
|
|
129
|
+
entity: '/api/entities/:type/:providerId/:ownerId/:entityId',
|
|
130
|
+
/** Any method: one of the type's own operations; the provider's answer passes through. */
|
|
131
|
+
entityOperation: '/api/entities/:type/:providerId/:ownerId/:entityId/operations/:operation',
|
|
132
|
+
/** GET → `EntitySharing` (needs `read`). */
|
|
133
|
+
entityShares: '/api/entities/:type/:providerId/:ownerId/:entityId/shares',
|
|
134
|
+
/** PUT `ShareInput` → `EntitySharing`; DELETE → 204 (needs `share`, or one's own share). */
|
|
135
|
+
entityShare: '/api/entities/:type/:providerId/:ownerId/:entityId/shares/:accountId',
|
|
136
|
+
};
|
|
137
|
+
/** Where `oidc-provider` sends a browser to sign in or consent; the server decides which. */
|
|
138
|
+
export const CORE_INTERACTION_PATHS = {
|
|
139
|
+
/** GET: resolves the interaction, or redirects to the sign-in or the consent page. */
|
|
140
|
+
interaction: '/interaction/:uid',
|
|
141
|
+
/** GET → `ConsentRequest`. */
|
|
142
|
+
consentRequest: '/interaction/:uid/consent',
|
|
143
|
+
/** POST → `ConsentDecisionResult`: allows every permission asked. */
|
|
144
|
+
consent: '/interaction/:uid/consent/allow',
|
|
145
|
+
/** POST → `ConsentDecisionResult`: denies the app (`access_denied`). */
|
|
146
|
+
denial: '/interaction/:uid/consent/deny',
|
|
147
|
+
};
|
|
148
|
+
/** Core web page where an account allows an app (`:uid`: the interaction). */
|
|
149
|
+
export const CORE_CONSENT_PAGE_PATH = '/consent/:uid';
|
|
150
|
+
export const PASSWORD_MIN_LENGTH = 10;
|
|
151
|
+
/** Trimmed and lower-cased before validation, so the same address always matches. */
|
|
152
|
+
const emailAddress = z.string().trim().toLowerCase().pipe(z.email().max(254));
|
|
153
|
+
export const RegistrationInputSchema = z.object({
|
|
154
|
+
email: emailAddress,
|
|
155
|
+
name: z.string().trim().min(1).max(120),
|
|
156
|
+
password: z.string().min(PASSWORD_MIN_LENGTH).max(256),
|
|
157
|
+
});
|
|
158
|
+
export const SignInInputSchema = z.object({
|
|
159
|
+
email: emailAddress,
|
|
160
|
+
password: z.string().min(1).max(256),
|
|
161
|
+
});
|
|
162
|
+
/** Self-service profile changes. At least one field. */
|
|
163
|
+
export const AccountUpdateSchema = z
|
|
164
|
+
.object({
|
|
165
|
+
name: z.string().trim().min(1).max(120).optional(),
|
|
166
|
+
email: emailAddress.optional(),
|
|
167
|
+
})
|
|
168
|
+
.refine((update) => update.name !== undefined || update.email !== undefined, {
|
|
169
|
+
message: 'Nothing to update.',
|
|
170
|
+
});
|
|
171
|
+
export const PasswordChangeSchema = z.object({
|
|
172
|
+
currentPassword: z.string().min(1).max(256),
|
|
173
|
+
newPassword: z.string().min(PASSWORD_MIN_LENGTH).max(256),
|
|
174
|
+
});
|
|
175
|
+
/** Deleting one's own account requires the password again. */
|
|
176
|
+
export const AccountDeletionSchema = z.object({
|
|
177
|
+
password: z.string().min(1).max(256),
|
|
178
|
+
});
|
|
179
|
+
/** Where an entry of the app switcher leads. `account` and `admin` are the core's own interfaces. */
|
|
180
|
+
export const LAUNCHER_ENTRY_KINDS = ['account', 'admin', 'app'];
|
|
181
|
+
export const LauncherEntrySchema = z.object({
|
|
182
|
+
id: z.string(),
|
|
183
|
+
kind: z.enum(LAUNCHER_ENTRY_KINDS),
|
|
184
|
+
name: z.string(),
|
|
185
|
+
url: z.url(),
|
|
186
|
+
/** Absolute URL of the entry's icon (an app serves it at `APP_PROTOCOL_PATHS.icon`). */
|
|
187
|
+
iconUrl: z.url(),
|
|
188
|
+
});
|
|
189
|
+
export const LauncherSchema = z.object({
|
|
190
|
+
entries: z.array(LauncherEntrySchema),
|
|
191
|
+
});
|
|
192
|
+
/** The signed-in account of the core web client and its preferences, `null` when signed out. */
|
|
193
|
+
export const CurrentAccountResponseSchema = z.object({
|
|
194
|
+
current: AccountWithPermissionsSchema.nullable(),
|
|
195
|
+
preferences: AccountPreferencesSchema.nullable(),
|
|
196
|
+
});
|
|
197
|
+
export const AccountListSchema = z.object({
|
|
198
|
+
accounts: z.array(AccountWithPermissionsSchema),
|
|
199
|
+
});
|
|
200
|
+
/** The administration permissions an account holds after the update (all others are always held). */
|
|
201
|
+
export const PermissionsUpdateSchema = z.object({
|
|
202
|
+
permissions: z.array(AdminPermissionSchema),
|
|
203
|
+
});
|
|
204
|
+
/** What an app's manifest says it may do, as the core keeps it. */
|
|
205
|
+
export const AppCapabilitiesSchema = z.object({
|
|
206
|
+
name: z.string(),
|
|
207
|
+
description: z.string().nullable(),
|
|
208
|
+
url: z.url(),
|
|
209
|
+
permissions: z.array(DelegablePermissionSchema),
|
|
210
|
+
/** The entity types it declares (uses or provides). */
|
|
211
|
+
types: z.array(EntityTypeDefinitionSchema),
|
|
212
|
+
provides: z.record(EntityTypeIdSchema, ProvidedTypeSchema),
|
|
213
|
+
/** By type: the kinds it supports, their icons and templates. */
|
|
214
|
+
kinds: z.record(EntityTypeIdSchema, z.array(SupportedKindSchema)),
|
|
215
|
+
/** By type, then by action: the kinds it handles the action for. */
|
|
216
|
+
handles: z.record(EntityTypeIdSchema, z.record(z.string(), z.array(z.string()))),
|
|
217
|
+
/** Whether it shows in the app switcher. */
|
|
218
|
+
listed: z.boolean(),
|
|
219
|
+
});
|
|
220
|
+
export const EnrolledAppSchema = AppCapabilitiesSchema.extend({
|
|
221
|
+
/** The app's manifest id, also its OAuth `client_id`. */
|
|
222
|
+
id: AppIdSchema,
|
|
223
|
+
/** Absolute URL of its icon (`APP_PROTOCOL_PATHS.icon`). */
|
|
224
|
+
iconUrl: z.url(),
|
|
225
|
+
enrolledAt: z.iso.datetime(),
|
|
226
|
+
/**
|
|
227
|
+
* A manifest the app sent that widens its trust (more permissions, types or provided
|
|
228
|
+
* operations, another URL): it applies once an administrator approves it.
|
|
229
|
+
*/
|
|
230
|
+
pendingUpdate: AppCapabilitiesSchema.extend({ receivedAt: z.iso.datetime() }).nullable(),
|
|
231
|
+
});
|
|
232
|
+
export const EnrolledAppListSchema = z.object({
|
|
233
|
+
apps: z.array(EnrolledAppSchema),
|
|
234
|
+
});
|
|
235
|
+
/** Every enrolled app, by id, in its new order. */
|
|
236
|
+
export const AppOrderSchema = z.object({
|
|
237
|
+
appIds: z.array(AppIdSchema).max(1000),
|
|
238
|
+
});
|
|
239
|
+
/** `DELETE CORE_API_PATHS.app` query: whether the app's files on the core storage go with it. */
|
|
240
|
+
export const AppRevocationQuerySchema = z.object({
|
|
241
|
+
deleteFiles: z
|
|
242
|
+
.enum(['true', 'false'])
|
|
243
|
+
.default('false')
|
|
244
|
+
.transform((value) => value === 'true'),
|
|
245
|
+
});
|
|
246
|
+
export const ENROLLMENT_WARNING_CODES = [
|
|
247
|
+
'insecure_transport',
|
|
248
|
+
'replaces_enrolled_app',
|
|
249
|
+
'sensitive_permissions',
|
|
250
|
+
// The app lives on the core's origin (under `/apps/`): its pages can act as whoever is signed
|
|
251
|
+
// in to the core, administrators included.
|
|
252
|
+
'shares_core_origin',
|
|
253
|
+
];
|
|
254
|
+
export const EnrollmentWarningCodeSchema = z.enum(ENROLLMENT_WARNING_CODES);
|
|
255
|
+
/**
|
|
256
|
+
* What an administrator enrolls: a pasted manifest, or the URL of an app whose manifest the core
|
|
257
|
+
* reads itself (the app's unenrolled page links to the core with it, `ENROLL_PARAM`; the
|
|
258
|
+
* marketplace does the same once an app it installed runs).
|
|
259
|
+
*/
|
|
260
|
+
export const EnrollmentRequestSchema = z.union([
|
|
261
|
+
z.object({ manifest: AppManifestSchema }),
|
|
262
|
+
z.object({ url: WebUrlSchema }),
|
|
263
|
+
]);
|
|
264
|
+
/** The pasted manifest, checked against the app's live one, and what enrolling it would do. */
|
|
265
|
+
export const EnrollmentReviewSchema = z.object({
|
|
266
|
+
manifest: AppManifestSchema,
|
|
267
|
+
warnings: z.array(EnrollmentWarningCodeSchema),
|
|
268
|
+
});
|
|
269
|
+
/** What the consent screen shows: an app asking an account for permissions. */
|
|
270
|
+
export const ConsentRequestSchema = z.object({
|
|
271
|
+
app: z.object({
|
|
272
|
+
id: AppIdSchema,
|
|
273
|
+
name: z.string(),
|
|
274
|
+
description: z.string().nullable(),
|
|
275
|
+
url: z.url(),
|
|
276
|
+
iconUrl: z.url(),
|
|
277
|
+
}),
|
|
278
|
+
account: AccountSchema,
|
|
279
|
+
/** Everything the app receives once allowed. */
|
|
280
|
+
permissions: z.array(DelegablePermissionSchema),
|
|
281
|
+
/** Those the account never consented to for this app (all of them, the first time). */
|
|
282
|
+
newPermissions: z.array(DelegablePermissionSchema),
|
|
283
|
+
/** The types the app's type permissions belong to (their labels), as the core merged them. */
|
|
284
|
+
types: z.array(EntityTypeDefinitionSchema),
|
|
285
|
+
/** The types the app provides: their permissions also let it store the account's entities. */
|
|
286
|
+
provides: z.array(EntityTypeIdSchema),
|
|
287
|
+
});
|
|
288
|
+
/** Where the browser goes on, once the account allowed or denied. */
|
|
289
|
+
export const ConsentDecisionResultSchema = z.object({
|
|
290
|
+
redirectTo: z.url(),
|
|
291
|
+
});
|
|
292
|
+
/** Most accounts one directory search returns: a search narrows, it never lists everyone. */
|
|
293
|
+
export const DIRECTORY_SEARCH_LIMIT = 10;
|
|
294
|
+
/** Most accounts one directory lookup by ids resolves. */
|
|
295
|
+
export const DIRECTORY_MAX_IDS = 100;
|
|
296
|
+
const DIRECTORY_ID_SEPARATOR = ',';
|
|
297
|
+
/** `?search=`: accounts whose name or email contains the text, case-insensitively. */
|
|
298
|
+
export const DirectorySearchSchema = z.object({
|
|
299
|
+
search: z.string().trim().min(1).max(100),
|
|
300
|
+
});
|
|
301
|
+
/** `?ids=<id>,<id>`: the accounts that still exist among these ids. */
|
|
302
|
+
export const DirectoryLookupSchema = z.object({
|
|
303
|
+
ids: z
|
|
304
|
+
.string()
|
|
305
|
+
.transform((ids) => [...new Set(ids.split(DIRECTORY_ID_SEPARATOR).filter(Boolean))])
|
|
306
|
+
.pipe(z.array(z.uuidv4()).min(1).max(DIRECTORY_MAX_IDS)),
|
|
307
|
+
});
|
|
308
|
+
/** Either a search or a lookup. */
|
|
309
|
+
export const DirectoryQuerySchema = z.union([DirectorySearchSchema, DirectoryLookupSchema]);
|
|
310
|
+
/** The query string of a directory lookup, as `DirectoryQuerySchema` parses it. */
|
|
311
|
+
export function formatDirectoryQuery(query) {
|
|
312
|
+
const params = 'search' in query ? { search: query.search } : { ids: query.ids.join(DIRECTORY_ID_SEPARATOR) };
|
|
313
|
+
return new URLSearchParams(params).toString();
|
|
314
|
+
}
|
|
315
|
+
/** Accounts of the directory: identity only, never permissions. */
|
|
316
|
+
export const DirectoryAccountListSchema = z.object({
|
|
317
|
+
accounts: z.array(AccountSchema),
|
|
318
|
+
});
|
|
319
|
+
/** An app handling an action on one kind of entity of a type, as other apps offer it. */
|
|
320
|
+
export const EntityHandlerSchema = z.object({
|
|
321
|
+
appId: AppIdSchema,
|
|
322
|
+
appName: z.string(),
|
|
323
|
+
action: z.string(),
|
|
324
|
+
kind: z.string(),
|
|
325
|
+
/** Absolute URL of the kind's icon, served by the handling app. */
|
|
326
|
+
iconUrl: z.url(),
|
|
327
|
+
/** Absolute URL of the handle page (`APP_PROTOCOL_PATHS.handle`), its query to add. */
|
|
328
|
+
url: z.url(),
|
|
329
|
+
});
|
|
330
|
+
export const EntityHandlerListSchema = z.object({
|
|
331
|
+
handlers: z.array(EntityHandlerSchema),
|
|
332
|
+
});
|
|
333
|
+
/** A kind of entity an app supports, as other apps show it (an icon) and create it (a template). */
|
|
334
|
+
export const EntityKindSchema = z.object({
|
|
335
|
+
appId: AppIdSchema,
|
|
336
|
+
appName: z.string(),
|
|
337
|
+
kind: z.string(),
|
|
338
|
+
/** Absolute URL of the kind's icon, served by the app. */
|
|
339
|
+
iconUrl: z.url(),
|
|
340
|
+
/** Whether new entities of the kind can start from the app's template (`entityKindTemplate`). */
|
|
341
|
+
hasTemplate: z.boolean(),
|
|
342
|
+
});
|
|
343
|
+
export const EntityKindListSchema = z.object({
|
|
344
|
+
kinds: z.array(EntityKindSchema),
|
|
345
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Identity of a person on the platform, as every app sees it. */
|
|
3
|
+
export declare const AccountSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodUUID;
|
|
5
|
+
email: z.ZodEmail;
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<"generated">;
|
|
9
|
+
seed: z.ZodUUID;
|
|
10
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
11
|
+
kind: z.ZodLiteral<"file">;
|
|
12
|
+
fileId: z.ZodUUID;
|
|
13
|
+
url: z.ZodURL;
|
|
14
|
+
}, z.core.$strip>], "kind">;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export type Account = z.infer<typeof AccountSchema>;
|
|
17
|
+
/** An account together with the permissions granted to it (in the current context). */
|
|
18
|
+
export declare const AccountWithPermissionsSchema: z.ZodObject<{
|
|
19
|
+
account: z.ZodObject<{
|
|
20
|
+
id: z.ZodUUID;
|
|
21
|
+
email: z.ZodEmail;
|
|
22
|
+
name: z.ZodString;
|
|
23
|
+
avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
24
|
+
kind: z.ZodLiteral<"generated">;
|
|
25
|
+
seed: z.ZodUUID;
|
|
26
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
27
|
+
kind: z.ZodLiteral<"file">;
|
|
28
|
+
fileId: z.ZodUUID;
|
|
29
|
+
url: z.ZodURL;
|
|
30
|
+
}, z.core.$strip>], "kind">;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
permissions: z.ZodArray<z.ZodType<import("../permissions.ts").Permission, string, z.core.$ZodTypeInternals<import("../permissions.ts").Permission, string>>>;
|
|
33
|
+
}, z.core.$strip>;
|
|
34
|
+
export type AccountWithPermissions = z.infer<typeof AccountWithPermissionsSchema>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PermissionSchema } from '../permissions.js';
|
|
3
|
+
import { AvatarSchema } from './avatar.entity.js';
|
|
4
|
+
/** Identity of a person on the platform, as every app sees it. */
|
|
5
|
+
export const AccountSchema = z.object({
|
|
6
|
+
id: z.uuidv4(),
|
|
7
|
+
email: z.email(),
|
|
8
|
+
name: z.string().min(1).max(120),
|
|
9
|
+
avatar: AvatarSchema,
|
|
10
|
+
});
|
|
11
|
+
/** An account together with the permissions granted to it (in the current context). */
|
|
12
|
+
export const AccountWithPermissionsSchema = z.object({
|
|
13
|
+
account: AccountSchema,
|
|
14
|
+
permissions: z.array(PermissionSchema),
|
|
15
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The picture of an account or a contact. Never an external URL:
|
|
4
|
+
* - `generated`: drawn from a random seed (regenerating draws a new seed, the entity id never changes);
|
|
5
|
+
* - `file`: an image stored by the core's storage, served at a public, unguessable URL.
|
|
6
|
+
*/
|
|
7
|
+
export declare const AvatarSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<"generated">;
|
|
9
|
+
seed: z.ZodUUID;
|
|
10
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
11
|
+
kind: z.ZodLiteral<"file">;
|
|
12
|
+
fileId: z.ZodUUID;
|
|
13
|
+
url: z.ZodURL;
|
|
14
|
+
}, z.core.$strip>], "kind">;
|
|
15
|
+
export type Avatar = z.infer<typeof AvatarSchema>;
|
|
16
|
+
/** Storage form of an avatar: `generated:<seed>` or `file:<fileId>`. */
|
|
17
|
+
export type AvatarReference = `generated:${string}` | `file:${string}`;
|
|
18
|
+
export declare function formatAvatarReference(avatar: Avatar): AvatarReference;
|
|
19
|
+
/**
|
|
20
|
+
* Parses a stored reference. `resolveFileUrl` turns a file id into its public URL
|
|
21
|
+
* (it depends on where the core is).
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseAvatarReference(reference: string, resolveFileUrl: (fileId: string) => string): Avatar;
|
|
24
|
+
/**
|
|
25
|
+
* Body of an avatar regeneration: the seed of the face the person picked from the previews
|
|
26
|
+
* (drawn by the client, so what was shown is what gets saved).
|
|
27
|
+
*/
|
|
28
|
+
export declare const AvatarRegenerationSchema: z.ZodObject<{
|
|
29
|
+
seed: z.ZodUUID;
|
|
30
|
+
}, z.core.$strip>;
|
|
31
|
+
export type AvatarRegeneration = z.infer<typeof AvatarRegenerationSchema>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The picture of an account or a contact. Never an external URL:
|
|
4
|
+
* - `generated`: drawn from a random seed (regenerating draws a new seed, the entity id never changes);
|
|
5
|
+
* - `file`: an image stored by the core's storage, served at a public, unguessable URL.
|
|
6
|
+
*/
|
|
7
|
+
export const AvatarSchema = z.discriminatedUnion('kind', [
|
|
8
|
+
z.object({ kind: z.literal('generated'), seed: z.uuidv4() }),
|
|
9
|
+
z.object({ kind: z.literal('file'), fileId: z.uuidv4(), url: z.url() }),
|
|
10
|
+
]);
|
|
11
|
+
export function formatAvatarReference(avatar) {
|
|
12
|
+
return avatar.kind === 'generated' ? `generated:${avatar.seed}` : `file:${avatar.fileId}`;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Parses a stored reference. `resolveFileUrl` turns a file id into its public URL
|
|
16
|
+
* (it depends on where the core is).
|
|
17
|
+
*/
|
|
18
|
+
export function parseAvatarReference(reference, resolveFileUrl) {
|
|
19
|
+
const separator = reference.indexOf(':');
|
|
20
|
+
const kind = reference.slice(0, separator);
|
|
21
|
+
const value = reference.slice(separator + 1);
|
|
22
|
+
return AvatarSchema.parse(kind === 'file'
|
|
23
|
+
? { kind, fileId: value, url: resolveFileUrl(value) }
|
|
24
|
+
: { kind: 'generated', seed: value });
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Body of an avatar regeneration: the seed of the face the person picked from the previews
|
|
28
|
+
* (drawn by the client, so what was shown is what gets saved).
|
|
29
|
+
*/
|
|
30
|
+
export const AvatarRegenerationSchema = z.object({ seed: z.uuidv4() });
|