@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,350 @@
1
+ import { z } from 'zod';
2
+ /** An entity's id within its provider and owner: any text (a bridge keeps its source's ids). */
3
+ export declare const EntityIdSchema: z.ZodString;
4
+ /** An entity of a known provider and owner: its type and id (a parent, a shared entity). */
5
+ export declare const EntityPointerSchema: z.ZodObject<{
6
+ type: z.ZodString;
7
+ id: z.ZodString;
8
+ }, z.core.$strip>;
9
+ export type EntityPointer = z.infer<typeof EntityPointerSchema>;
10
+ /** Everything naming one entity on the platform. */
11
+ export declare const EntityRefSchema: z.ZodObject<{
12
+ type: z.ZodString;
13
+ providerId: z.ZodString;
14
+ ownerId: z.ZodString;
15
+ id: z.ZodString;
16
+ }, z.core.$strip>;
17
+ export type EntityRef = z.infer<typeof EntityRefSchema>;
18
+ /** What the calling account holds on an entity, added by the core. */
19
+ export declare const EntityAccessSchema: z.ZodObject<{
20
+ permissions: z.ZodArray<z.ZodString>;
21
+ via: z.ZodNullable<z.ZodObject<{
22
+ type: z.ZodString;
23
+ id: z.ZodString;
24
+ }, z.core.$strip>>;
25
+ }, z.core.$strip>;
26
+ export type EntityAccess = z.infer<typeof EntityAccessSchema>;
27
+ /** One entity as its provider answers it: the core adds the type, provider and owner. */
28
+ export declare const ProviderEntitySchema: z.ZodObject<{
29
+ id: z.ZodString;
30
+ parentId: z.ZodNullable<z.ZodString>;
31
+ url: z.ZodNullable<z.ZodURL>;
32
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
33
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
34
+ data: z.ZodUnknown;
35
+ }, z.core.$strip>;
36
+ export type ProviderEntity = z.infer<typeof ProviderEntitySchema>;
37
+ export declare const ProviderEntityListSchema: z.ZodObject<{
38
+ entities: z.ZodArray<z.ZodObject<{
39
+ id: z.ZodString;
40
+ parentId: z.ZodNullable<z.ZodString>;
41
+ url: z.ZodNullable<z.ZodURL>;
42
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
43
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
44
+ data: z.ZodUnknown;
45
+ }, z.core.$strip>>;
46
+ }, z.core.$strip>;
47
+ export type ProviderEntityList = z.infer<typeof ProviderEntityListSchema>;
48
+ /** An app providing a type, as consumers show it ("Open in Google", a storage location). */
49
+ export declare const ProviderSummarySchema: z.ZodObject<{
50
+ id: z.ZodString;
51
+ name: z.ZodString;
52
+ url: z.ZodURL;
53
+ iconUrl: z.ZodURL;
54
+ operations: z.ZodArray<z.ZodString>;
55
+ available: z.ZodBoolean;
56
+ consented: z.ZodBoolean;
57
+ }, z.core.$strip>;
58
+ export type ProviderSummary = z.infer<typeof ProviderSummarySchema>;
59
+ /** The envelope of an entity whose data follows `data`. */
60
+ export declare function entitySchema<Data extends z.ZodType>(data: Data): z.ZodObject<{
61
+ type: z.ZodString;
62
+ providerId: z.ZodString;
63
+ ownerId: z.ZodString;
64
+ id: z.ZodString;
65
+ parent: z.ZodNullable<z.ZodObject<{
66
+ type: z.ZodString;
67
+ id: z.ZodString;
68
+ }, z.core.$strip>>;
69
+ url: z.ZodNullable<z.ZodURL>;
70
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
71
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
72
+ data: Data;
73
+ access: z.ZodObject<{
74
+ permissions: z.ZodArray<z.ZodString>;
75
+ via: z.ZodNullable<z.ZodObject<{
76
+ type: z.ZodString;
77
+ id: z.ZodString;
78
+ }, z.core.$strip>>;
79
+ }, z.core.$strip>;
80
+ }, z.core.$strip>;
81
+ export declare const EntitySchema: z.ZodObject<{
82
+ type: z.ZodString;
83
+ providerId: z.ZodString;
84
+ ownerId: z.ZodString;
85
+ id: z.ZodString;
86
+ parent: z.ZodNullable<z.ZodObject<{
87
+ type: z.ZodString;
88
+ id: z.ZodString;
89
+ }, z.core.$strip>>;
90
+ url: z.ZodNullable<z.ZodURL>;
91
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
92
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
93
+ data: z.ZodUnknown;
94
+ access: z.ZodObject<{
95
+ permissions: z.ZodArray<z.ZodString>;
96
+ via: z.ZodNullable<z.ZodObject<{
97
+ type: z.ZodString;
98
+ id: z.ZodString;
99
+ }, z.core.$strip>>;
100
+ }, z.core.$strip>;
101
+ }, z.core.$strip>;
102
+ export interface Entity<Data = unknown> extends Omit<z.infer<typeof EntitySchema>, 'data'> {
103
+ data: Data;
104
+ }
105
+ /** Every entity of a type the account reaches, from every provider. */
106
+ export declare function entityListSchema<Data extends z.ZodType>(data: Data): z.ZodObject<{
107
+ providers: z.ZodArray<z.ZodObject<{
108
+ id: z.ZodString;
109
+ name: z.ZodString;
110
+ url: z.ZodURL;
111
+ iconUrl: z.ZodURL;
112
+ operations: z.ZodArray<z.ZodString>;
113
+ available: z.ZodBoolean;
114
+ consented: z.ZodBoolean;
115
+ }, z.core.$strip>>;
116
+ entities: z.ZodArray<z.ZodObject<{
117
+ type: z.ZodString;
118
+ providerId: z.ZodString;
119
+ ownerId: z.ZodString;
120
+ id: z.ZodString;
121
+ parent: z.ZodNullable<z.ZodObject<{
122
+ type: z.ZodString;
123
+ id: z.ZodString;
124
+ }, z.core.$strip>>;
125
+ url: z.ZodNullable<z.ZodURL>;
126
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
127
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
128
+ data: Data;
129
+ access: z.ZodObject<{
130
+ permissions: z.ZodArray<z.ZodString>;
131
+ via: z.ZodNullable<z.ZodObject<{
132
+ type: z.ZodString;
133
+ id: z.ZodString;
134
+ }, z.core.$strip>>;
135
+ }, z.core.$strip>;
136
+ }, z.core.$strip>>;
137
+ }, z.core.$strip>;
138
+ export declare const EntityListSchema: z.ZodObject<{
139
+ providers: z.ZodArray<z.ZodObject<{
140
+ id: z.ZodString;
141
+ name: z.ZodString;
142
+ url: z.ZodURL;
143
+ iconUrl: z.ZodURL;
144
+ operations: z.ZodArray<z.ZodString>;
145
+ available: z.ZodBoolean;
146
+ consented: z.ZodBoolean;
147
+ }, z.core.$strip>>;
148
+ entities: z.ZodArray<z.ZodObject<{
149
+ type: z.ZodString;
150
+ providerId: z.ZodString;
151
+ ownerId: z.ZodString;
152
+ id: z.ZodString;
153
+ parent: z.ZodNullable<z.ZodObject<{
154
+ type: z.ZodString;
155
+ id: z.ZodString;
156
+ }, z.core.$strip>>;
157
+ url: z.ZodNullable<z.ZodURL>;
158
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
159
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
160
+ data: z.ZodUnknown;
161
+ access: z.ZodObject<{
162
+ permissions: z.ZodArray<z.ZodString>;
163
+ via: z.ZodNullable<z.ZodObject<{
164
+ type: z.ZodString;
165
+ id: z.ZodString;
166
+ }, z.core.$strip>>;
167
+ }, z.core.$strip>;
168
+ }, z.core.$strip>>;
169
+ }, z.core.$strip>;
170
+ export interface EntityList<Data = unknown> {
171
+ providers: ProviderSummary[];
172
+ entities: Entity<Data>[];
173
+ }
174
+ /** One entity, with its provider (read, created, updated). */
175
+ export declare function entityResultSchema<Data extends z.ZodType>(data: Data): z.ZodObject<{
176
+ provider: z.ZodObject<{
177
+ id: z.ZodString;
178
+ name: z.ZodString;
179
+ url: z.ZodURL;
180
+ iconUrl: z.ZodURL;
181
+ operations: z.ZodArray<z.ZodString>;
182
+ available: z.ZodBoolean;
183
+ consented: z.ZodBoolean;
184
+ }, z.core.$strip>;
185
+ entity: z.ZodObject<{
186
+ type: z.ZodString;
187
+ providerId: z.ZodString;
188
+ ownerId: z.ZodString;
189
+ id: z.ZodString;
190
+ parent: z.ZodNullable<z.ZodObject<{
191
+ type: z.ZodString;
192
+ id: z.ZodString;
193
+ }, z.core.$strip>>;
194
+ url: z.ZodNullable<z.ZodURL>;
195
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
196
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
197
+ data: Data;
198
+ access: z.ZodObject<{
199
+ permissions: z.ZodArray<z.ZodString>;
200
+ via: z.ZodNullable<z.ZodObject<{
201
+ type: z.ZodString;
202
+ id: z.ZodString;
203
+ }, z.core.$strip>>;
204
+ }, z.core.$strip>;
205
+ }, z.core.$strip>;
206
+ }, z.core.$strip>;
207
+ export declare const EntityResultSchema: z.ZodObject<{
208
+ provider: z.ZodObject<{
209
+ id: z.ZodString;
210
+ name: z.ZodString;
211
+ url: z.ZodURL;
212
+ iconUrl: z.ZodURL;
213
+ operations: z.ZodArray<z.ZodString>;
214
+ available: z.ZodBoolean;
215
+ consented: z.ZodBoolean;
216
+ }, z.core.$strip>;
217
+ entity: z.ZodObject<{
218
+ type: z.ZodString;
219
+ providerId: z.ZodString;
220
+ ownerId: z.ZodString;
221
+ id: z.ZodString;
222
+ parent: z.ZodNullable<z.ZodObject<{
223
+ type: z.ZodString;
224
+ id: z.ZodString;
225
+ }, z.core.$strip>>;
226
+ url: z.ZodNullable<z.ZodURL>;
227
+ createdAt: z.ZodNullable<z.ZodISODateTime>;
228
+ updatedAt: z.ZodNullable<z.ZodISODateTime>;
229
+ data: z.ZodUnknown;
230
+ access: z.ZodObject<{
231
+ permissions: z.ZodArray<z.ZodString>;
232
+ via: z.ZodNullable<z.ZodObject<{
233
+ type: z.ZodString;
234
+ id: z.ZodString;
235
+ }, z.core.$strip>>;
236
+ }, z.core.$strip>;
237
+ }, z.core.$strip>;
238
+ }, z.core.$strip>;
239
+ export interface EntityResult<Data = unknown> {
240
+ provider: ProviderSummary;
241
+ entity: Entity<Data>;
242
+ }
243
+ /**
244
+ * Parameters the core reads on entity calls. Every other parameter of a list goes on to the
245
+ * providers as it is (a range of dates, a `search`).
246
+ */
247
+ export declare const ENTITY_PARAMS: {
248
+ /** Lists: only these providers (comma-separated app ids). */
249
+ readonly only: 'only';
250
+ /** Lists: every provider but these. */
251
+ readonly except: 'except';
252
+ /** Acting through a share: `<type>:<id>` of the shared entity. */
253
+ readonly via: 'via';
254
+ /** Creating in a parent (`<ownerId>:<id>`), or moving to one (`<id>`, the same owner). */
255
+ readonly parent: 'parent';
256
+ };
257
+ /** `<type>:<id>`: the type has no `:`, the id may. */
258
+ export declare function formatPointer({ type, id }: EntityPointer): string;
259
+ export declare function parsePointer(value: string | undefined): EntityPointer | undefined;
260
+ /** A parent to create in: `<ownerId>:<id>` (owner ids have no `:`). */
261
+ export declare function formatOwnedId({ ownerId, id }: {
262
+ ownerId: string;
263
+ id: string;
264
+ }): string;
265
+ export declare function parseOwnedId(value: string | undefined): {
266
+ ownerId: string;
267
+ id: string;
268
+ } | undefined;
269
+ /** Which providers a list asks. */
270
+ export interface ProviderFilter {
271
+ only?: readonly string[];
272
+ except?: readonly string[];
273
+ }
274
+ /** The query string of a list: the provider filter, and what goes on to the providers. */
275
+ export declare function formatEntityListQuery({ only, except }?: ProviderFilter, params?: Record<string, string>): string;
276
+ /** Reads a list query back: the provider filter, and the parameters for the providers. */
277
+ export declare function parseEntityListQuery(query: Record<string, string>): {
278
+ filter: ProviderFilter;
279
+ params: Record<string, string>;
280
+ };
281
+ /** Whether a filter lets a provider be asked. */
282
+ export declare function isProviderSelected({ only, except }: ProviderFilter, providerId: string): boolean;
283
+ /** The JWT `typ` of the access tokens the core mints for a provider (RFC 9068). */
284
+ export declare const PROVIDER_TOKEN_TYPE = "at+jwt";
285
+ /**
286
+ * The claims of a provider token beyond RFC 9068's: `sub` is the owner, `act.sub` the account
287
+ * acting (RFC 8693) when it isn't the owner, `client_id` the consumer app, `scope` the one type
288
+ * permission, and `within` the shared entity the call is limited to.
289
+ */
290
+ export declare const ProviderTokenClaimsSchema: z.ZodObject<{
291
+ sub: z.ZodString;
292
+ client_id: z.ZodString;
293
+ scope: z.ZodString;
294
+ act: z.ZodOptional<z.ZodObject<{
295
+ sub: z.ZodString;
296
+ }, z.core.$strip>>;
297
+ within: z.ZodOptional<z.ZodObject<{
298
+ type: z.ZodString;
299
+ id: z.ZodString;
300
+ }, z.core.$strip>>;
301
+ }, z.core.$strip>;
302
+ export type ProviderTokenClaims = z.infer<typeof ProviderTokenClaimsSchema>;
303
+ /** Largest body the core passes on to a provider (a file being created, with its fields). */
304
+ export declare const MAX_ENTITY_BODY_BYTES: number;
305
+ export declare const ENTITY_GRANT: {
306
+ readonly grantType: 'urn:ietf:params:oauth:grant-type:token-exchange';
307
+ /** `subject_token_type` and `requested_token_type`. */
308
+ readonly tokenType: 'urn:ietf:params:oauth:token-type:access_token';
309
+ /** The token request's parameter naming the entity: an `EntityGrantTarget` as JSON. */
310
+ readonly entityParam: 'artemis_entity';
311
+ /** How long the granted token lasts. */
312
+ readonly ttlSeconds: number;
313
+ };
314
+ /** The entity a grant is for, and the share it is reached through. */
315
+ export declare const EntityGrantTargetSchema: z.ZodObject<{
316
+ type: z.ZodString;
317
+ providerId: z.ZodString;
318
+ ownerId: z.ZodString;
319
+ id: z.ZodString;
320
+ via: z.ZodNullable<z.ZodObject<{
321
+ type: z.ZodString;
322
+ id: z.ZodString;
323
+ }, z.core.$strip>>;
324
+ }, z.core.$strip>;
325
+ export type EntityGrantTarget = z.infer<typeof EntityGrantTargetSchema>;
326
+ /**
327
+ * The core calling a handling app's `server` action (`APP_PROTOCOL_PATHS.handledAction`): the
328
+ * entity, its kind, and a grant (an access token for the core, limited to that entity and the
329
+ * action's permission) the app reaches the entity with.
330
+ */
331
+ export declare const HandledActionCallSchema: z.ZodObject<{
332
+ entity: z.ZodObject<{
333
+ type: z.ZodString;
334
+ providerId: z.ZodString;
335
+ ownerId: z.ZodString;
336
+ id: z.ZodString;
337
+ via: z.ZodNullable<z.ZodObject<{
338
+ type: z.ZodString;
339
+ id: z.ZodString;
340
+ }, z.core.$strip>>;
341
+ }, z.core.$strip>;
342
+ kind: z.ZodString;
343
+ grant: z.ZodObject<{
344
+ accessToken: z.ZodString;
345
+ expiresAt: z.ZodISODateTime;
346
+ }, z.core.$strip>;
347
+ }, z.core.$strip>;
348
+ export type HandledActionCall = z.infer<typeof HandledActionCallSchema>;
349
+ /** The JWT `typ` of the tokens the core signs to call an app's `server` action. */
350
+ export declare const HANDLER_TOKEN_TYPE = "artemis-handler+jwt";
@@ -0,0 +1,200 @@
1
+ import { z } from 'zod';
2
+ import { EntityTypeIdSchema } from './entity-types.js';
3
+ import { WebUrlSchema } from './web-url.js';
4
+ /*
5
+ * Entities on the wire (see docs/architecture/entities/): the envelope the core understands,
6
+ * around data it never reads. The data follows the entity's type package.
7
+ */
8
+ /** An entity's id within its provider and owner: any text (a bridge keeps its source's ids). */
9
+ export const EntityIdSchema = z.string().min(1).max(300);
10
+ /** An entity of a known provider and owner: its type and id (a parent, a shared entity). */
11
+ export const EntityPointerSchema = z.object({
12
+ type: EntityTypeIdSchema,
13
+ id: EntityIdSchema,
14
+ });
15
+ /** Everything naming one entity on the platform. */
16
+ export const EntityRefSchema = z.object({
17
+ type: EntityTypeIdSchema,
18
+ providerId: z.string().min(1),
19
+ ownerId: z.string().min(1),
20
+ id: EntityIdSchema,
21
+ });
22
+ /** What the calling account holds on an entity, added by the core. */
23
+ export const EntityAccessSchema = z.object({
24
+ /** Every permission of the type for its owner; otherwise those of the share. */
25
+ permissions: z.array(z.string()),
26
+ /** The shared entity the access comes through (itself or an ancestor); `null` for the owner. */
27
+ via: EntityPointerSchema.nullable(),
28
+ });
29
+ /* Provider → core: what an app's `APP_PROTOCOL_PATHS.providedEntit…` routes answer. */
30
+ /** One entity as its provider answers it: the core adds the type, provider and owner. */
31
+ export const ProviderEntitySchema = z.object({
32
+ id: EntityIdSchema,
33
+ /** Its parent, of the type's parent type, at the same provider and owner. */
34
+ parentId: EntityIdSchema.nullable(),
35
+ /** Where the provider's web client shows it, or `null`. */
36
+ url: WebUrlSchema.nullable(),
37
+ createdAt: z.iso.datetime({ offset: true }).nullable(),
38
+ updatedAt: z.iso.datetime({ offset: true }).nullable(),
39
+ data: z.unknown(),
40
+ });
41
+ export const ProviderEntityListSchema = z.object({
42
+ entities: z.array(ProviderEntitySchema),
43
+ });
44
+ /* Core → consumer. */
45
+ /** An app providing a type, as consumers show it ("Open in Google", a storage location). */
46
+ export const ProviderSummarySchema = z.object({
47
+ id: z.string(),
48
+ name: z.string(),
49
+ /** Its home page. */
50
+ url: WebUrlSchema,
51
+ /** Absolute URL of its icon (`APP_PROTOCOL_PATHS.icon`). */
52
+ iconUrl: WebUrlSchema,
53
+ /** The operations it implements for the type (`list` and `read` always). */
54
+ operations: z.array(z.string()),
55
+ /** `false` when it could not be reached or answered off contract: its entities are missing. */
56
+ available: z.boolean(),
57
+ /**
58
+ * The account allowed it: it stores the account's own entities, so it can take new ones. A
59
+ * provider only holding entities shared with the account is `false`.
60
+ */
61
+ consented: z.boolean(),
62
+ });
63
+ /** The envelope of an entity whose data follows `data`. */
64
+ export function entitySchema(data) {
65
+ return z.object({
66
+ type: EntityTypeIdSchema,
67
+ providerId: z.string(),
68
+ ownerId: z.string(),
69
+ id: EntityIdSchema,
70
+ parent: EntityPointerSchema.nullable(),
71
+ url: WebUrlSchema.nullable(),
72
+ createdAt: z.iso.datetime({ offset: true }).nullable(),
73
+ updatedAt: z.iso.datetime({ offset: true }).nullable(),
74
+ data,
75
+ access: EntityAccessSchema,
76
+ });
77
+ }
78
+ export const EntitySchema = entitySchema(z.unknown());
79
+ /** Every entity of a type the account reaches, from every provider. */
80
+ export function entityListSchema(data) {
81
+ return z.object({
82
+ providers: z.array(ProviderSummarySchema),
83
+ entities: z.array(entitySchema(data)),
84
+ });
85
+ }
86
+ export const EntityListSchema = entityListSchema(z.unknown());
87
+ /** One entity, with its provider (read, created, updated). */
88
+ export function entityResultSchema(data) {
89
+ return z.object({ provider: ProviderSummarySchema, entity: entitySchema(data) });
90
+ }
91
+ export const EntityResultSchema = entityResultSchema(z.unknown());
92
+ /* Query parameters. */
93
+ /**
94
+ * Parameters the core reads on entity calls. Every other parameter of a list goes on to the
95
+ * providers as it is (a range of dates, a `search`).
96
+ */
97
+ export const ENTITY_PARAMS = {
98
+ /** Lists: only these providers (comma-separated app ids). */
99
+ only: 'only',
100
+ /** Lists: every provider but these. */
101
+ except: 'except',
102
+ /** Acting through a share: `<type>:<id>` of the shared entity. */
103
+ via: 'via',
104
+ /** Creating in a parent (`<ownerId>:<id>`), or moving to one (`<id>`, the same owner). */
105
+ parent: 'parent',
106
+ };
107
+ const LIST_SEPARATOR = ',';
108
+ /** `<type>:<id>`: the type has no `:`, the id may. */
109
+ export function formatPointer({ type, id }) {
110
+ return `${type}:${id}`;
111
+ }
112
+ export function parsePointer(value) {
113
+ if (!value)
114
+ return undefined;
115
+ const separator = value.indexOf(':');
116
+ const parsed = EntityPointerSchema.safeParse({
117
+ type: value.slice(0, separator),
118
+ id: value.slice(separator + 1),
119
+ });
120
+ return separator > 0 && parsed.success ? parsed.data : undefined;
121
+ }
122
+ /** A parent to create in: `<ownerId>:<id>` (owner ids have no `:`). */
123
+ export function formatOwnedId({ ownerId, id }) {
124
+ return `${ownerId}:${id}`;
125
+ }
126
+ export function parseOwnedId(value) {
127
+ if (!value)
128
+ return undefined;
129
+ const separator = value.indexOf(':');
130
+ if (separator <= 0 || separator === value.length - 1)
131
+ return undefined;
132
+ return { ownerId: value.slice(0, separator), id: value.slice(separator + 1) };
133
+ }
134
+ /** The query string of a list: the provider filter, and what goes on to the providers. */
135
+ export function formatEntityListQuery({ only, except } = {}, params = {}) {
136
+ const query = new URLSearchParams(params);
137
+ if (only)
138
+ query.set(ENTITY_PARAMS.only, only.join(LIST_SEPARATOR));
139
+ if (except)
140
+ query.set(ENTITY_PARAMS.except, except.join(LIST_SEPARATOR));
141
+ return query.toString();
142
+ }
143
+ /** Reads a list query back: the provider filter, and the parameters for the providers. */
144
+ export function parseEntityListQuery(query) {
145
+ const { [ENTITY_PARAMS.only]: only, [ENTITY_PARAMS.except]: except, [ENTITY_PARAMS.via]: _via, [ENTITY_PARAMS.parent]: _parent, ...params } = query;
146
+ const ids = (list) => list?.split(LIST_SEPARATOR).filter(Boolean);
147
+ return { filter: { only: ids(only), except: ids(except) }, params };
148
+ }
149
+ /** Whether a filter lets a provider be asked. */
150
+ export function isProviderSelected({ only, except }, providerId) {
151
+ return (!only || only.includes(providerId)) && !except?.includes(providerId);
152
+ }
153
+ /* Core → provider: the access token of one call. */
154
+ /** The JWT `typ` of the access tokens the core mints for a provider (RFC 9068). */
155
+ export const PROVIDER_TOKEN_TYPE = 'at+jwt';
156
+ /**
157
+ * The claims of a provider token beyond RFC 9068's: `sub` is the owner, `act.sub` the account
158
+ * acting (RFC 8693) when it isn't the owner, `client_id` the consumer app, `scope` the one type
159
+ * permission, and `within` the shared entity the call is limited to.
160
+ */
161
+ export const ProviderTokenClaimsSchema = z.object({
162
+ sub: z.string().min(1),
163
+ client_id: z.string().min(1),
164
+ scope: z.string().min(1),
165
+ act: z.object({ sub: z.string().min(1) }).optional(),
166
+ within: EntityPointerSchema.optional(),
167
+ });
168
+ /** Largest body the core passes on to a provider (a file being created, with its fields). */
169
+ export const MAX_ENTITY_BODY_BYTES = 51 * 1024 * 1024;
170
+ /*
171
+ * Entity grants: an app exchanges an account's access token for one limited to one entity
172
+ * (OAuth 2.0 Token Exchange, RFC 8693), for work that outlives the account's presence: an editor
173
+ * saving a document after its last editor left. The core issues it only for permissions the
174
+ * account holds on the entity, and accepts it on that entity's calls only.
175
+ */
176
+ export const ENTITY_GRANT = {
177
+ grantType: 'urn:ietf:params:oauth:grant-type:token-exchange',
178
+ /** `subject_token_type` and `requested_token_type`. */
179
+ tokenType: 'urn:ietf:params:oauth:token-type:access_token',
180
+ /** The token request's parameter naming the entity: an `EntityGrantTarget` as JSON. */
181
+ entityParam: 'artemis_entity',
182
+ /** How long the granted token lasts. */
183
+ ttlSeconds: 12 * 60 * 60,
184
+ };
185
+ /** The entity a grant is for, and the share it is reached through. */
186
+ export const EntityGrantTargetSchema = EntityRefSchema.extend({
187
+ via: EntityPointerSchema.nullable(),
188
+ });
189
+ /**
190
+ * The core calling a handling app's `server` action (`APP_PROTOCOL_PATHS.handledAction`): the
191
+ * entity, its kind, and a grant (an access token for the core, limited to that entity and the
192
+ * action's permission) the app reaches the entity with.
193
+ */
194
+ export const HandledActionCallSchema = z.object({
195
+ entity: EntityGrantTargetSchema,
196
+ kind: z.string().min(1).max(40),
197
+ grant: z.object({ accessToken: z.string().min(1), expiresAt: z.iso.datetime() }),
198
+ });
199
+ /** The JWT `typ` of the tokens the core signs to call an app's `server` action. */
200
+ export const HANDLER_TOKEN_TYPE = 'artemis-handler+jwt';
@@ -0,0 +1,86 @@
1
+ import { z } from 'zod';
2
+ /** One account an entity is shared with. */
3
+ export declare const EntityShareSchema: z.ZodObject<{
4
+ account: z.ZodObject<{
5
+ id: z.ZodUUID;
6
+ email: z.ZodEmail;
7
+ name: z.ZodString;
8
+ avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
9
+ kind: z.ZodLiteral<"generated">;
10
+ seed: z.ZodUUID;
11
+ }, z.core.$strip>, z.ZodObject<{
12
+ kind: z.ZodLiteral<"file">;
13
+ fileId: z.ZodUUID;
14
+ url: z.ZodURL;
15
+ }, z.core.$strip>], "kind">;
16
+ }, z.core.$strip>;
17
+ permissions: z.ZodArray<z.ZodString>;
18
+ grantedBy: z.ZodNullable<z.ZodObject<{
19
+ id: z.ZodUUID;
20
+ email: z.ZodEmail;
21
+ name: z.ZodString;
22
+ avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
23
+ kind: z.ZodLiteral<"generated">;
24
+ seed: z.ZodUUID;
25
+ }, z.core.$strip>, z.ZodObject<{
26
+ kind: z.ZodLiteral<"file">;
27
+ fileId: z.ZodUUID;
28
+ url: z.ZodURL;
29
+ }, z.core.$strip>], "kind">;
30
+ }, z.core.$strip>>;
31
+ grantedAt: z.ZodISODateTime;
32
+ }, z.core.$strip>;
33
+ export type EntityShare = z.infer<typeof EntityShareSchema>;
34
+ /** Who reaches an entity directly, as the share dialog shows it. */
35
+ export declare const EntitySharingSchema: z.ZodObject<{
36
+ owner: z.ZodNullable<z.ZodObject<{
37
+ id: z.ZodUUID;
38
+ email: z.ZodEmail;
39
+ name: z.ZodString;
40
+ avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
41
+ kind: z.ZodLiteral<"generated">;
42
+ seed: z.ZodUUID;
43
+ }, z.core.$strip>, z.ZodObject<{
44
+ kind: z.ZodLiteral<"file">;
45
+ fileId: z.ZodUUID;
46
+ url: z.ZodURL;
47
+ }, z.core.$strip>], "kind">;
48
+ }, z.core.$strip>>;
49
+ shares: z.ZodArray<z.ZodObject<{
50
+ account: z.ZodObject<{
51
+ id: z.ZodUUID;
52
+ email: z.ZodEmail;
53
+ name: z.ZodString;
54
+ avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
55
+ kind: z.ZodLiteral<"generated">;
56
+ seed: z.ZodUUID;
57
+ }, z.core.$strip>, z.ZodObject<{
58
+ kind: z.ZodLiteral<"file">;
59
+ fileId: z.ZodUUID;
60
+ url: z.ZodURL;
61
+ }, z.core.$strip>], "kind">;
62
+ }, z.core.$strip>;
63
+ permissions: z.ZodArray<z.ZodString>;
64
+ grantedBy: z.ZodNullable<z.ZodObject<{
65
+ id: z.ZodUUID;
66
+ email: z.ZodEmail;
67
+ name: z.ZodString;
68
+ avatar: z.ZodDiscriminatedUnion<[z.ZodObject<{
69
+ kind: z.ZodLiteral<"generated">;
70
+ seed: z.ZodUUID;
71
+ }, z.core.$strip>, z.ZodObject<{
72
+ kind: z.ZodLiteral<"file">;
73
+ fileId: z.ZodUUID;
74
+ url: z.ZodURL;
75
+ }, z.core.$strip>], "kind">;
76
+ }, z.core.$strip>>;
77
+ grantedAt: z.ZodISODateTime;
78
+ }, z.core.$strip>>;
79
+ permissions: z.ZodArray<z.ZodString>;
80
+ }, z.core.$strip>;
81
+ export type EntitySharing = z.infer<typeof EntitySharingSchema>;
82
+ /** PUT on a share: the permissions one account receives (completed by the core). */
83
+ export declare const ShareInputSchema: z.ZodObject<{
84
+ permissions: z.ZodArray<z.ZodString>;
85
+ }, z.core.$strip>;
86
+ export type ShareInput = z.infer<typeof ShareInputSchema>;
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import { AccountSchema } from './entities/account.entity.js';
3
+ /*
4
+ * Shares, kept by the core for every entity type alike (see
5
+ * docs/architecture/entities/permissions-and-sharing.md). A share gives one account a set of
6
+ * permissions of the entity's type, on the entity and its descendants.
7
+ */
8
+ /** One account an entity is shared with. */
9
+ export const EntityShareSchema = z.object({
10
+ account: AccountSchema,
11
+ /** Complete: everything its permissions build on is included. */
12
+ permissions: z.array(z.string()).min(1),
13
+ /** Who granted it, `null` once that account no longer exists. */
14
+ grantedBy: AccountSchema.nullable(),
15
+ grantedAt: z.iso.datetime(),
16
+ });
17
+ /** Who reaches an entity directly, as the share dialog shows it. */
18
+ export const EntitySharingSchema = z.object({
19
+ /** `null` once the owner's account no longer exists. */
20
+ owner: AccountSchema.nullable(),
21
+ /** Shares of this entity only: those of an ancestor are listed on the ancestor. */
22
+ shares: z.array(EntityShareSchema),
23
+ /** The calling account's own permissions on the entity. */
24
+ permissions: z.array(z.string()),
25
+ });
26
+ /** PUT on a share: the permissions one account receives (completed by the core). */
27
+ export const ShareInputSchema = z.object({
28
+ permissions: z.array(z.string().min(1).max(40)).min(1).max(40),
29
+ });