@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.
- 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
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type TypePermission } from './permissions.ts';
|
|
3
|
+
/** The permission every type has, every other one builds on, and lists and reads need. */
|
|
4
|
+
export declare const READ_PERMISSION = "read";
|
|
5
|
+
/** The permission every type has: sharing what one holds. */
|
|
6
|
+
export declare const SHARE_PERMISSION = "share";
|
|
7
|
+
/** The operations every provider of a type serves. */
|
|
8
|
+
export declare const REQUIRED_OPERATIONS: readonly ['list', 'read'];
|
|
9
|
+
/** The writes most types have; a type may leave any out, and a provider may not implement them. */
|
|
10
|
+
export declare const STANDARD_OPERATIONS: readonly ['list', 'read', 'create', 'update', 'delete'];
|
|
11
|
+
export type StandardOperation = (typeof STANDARD_OPERATIONS)[number];
|
|
12
|
+
export declare const EntityTypeIdSchema: z.ZodString;
|
|
13
|
+
/** How a permission reads, on the consent screen and in share dialogs. */
|
|
14
|
+
export declare const PermissionMessagesSchema: z.ZodObject<{
|
|
15
|
+
label: z.ZodString;
|
|
16
|
+
description: z.ZodString;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export declare const EntityTypeMessagesSchema: z.ZodObject<{
|
|
19
|
+
name: z.ZodString;
|
|
20
|
+
plural: z.ZodString;
|
|
21
|
+
permissions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
22
|
+
label: z.ZodString;
|
|
23
|
+
description: z.ZodString;
|
|
24
|
+
}, z.core.$strip>>;
|
|
25
|
+
operations: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
26
|
+
kinds: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
27
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
28
|
+
}, z.core.$strip>;
|
|
29
|
+
export type EntityTypeMessages = z.infer<typeof EntityTypeMessagesSchema>;
|
|
30
|
+
export declare const EntityTypeDefinitionSchema: z.ZodObject<{
|
|
31
|
+
id: z.ZodString;
|
|
32
|
+
version: z.ZodInt;
|
|
33
|
+
parent: z.ZodNullable<z.ZodString>;
|
|
34
|
+
titleFields: z.ZodArray<z.ZodString>;
|
|
35
|
+
schema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
36
|
+
permissions: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
|
|
37
|
+
operations: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
38
|
+
kinds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
39
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
40
|
+
permission: z.ZodString;
|
|
41
|
+
target: z.ZodEnum<{
|
|
42
|
+
page: "page";
|
|
43
|
+
server: "server";
|
|
44
|
+
}>;
|
|
45
|
+
}, z.core.$strict>>>;
|
|
46
|
+
messages: z.ZodRecord<z.ZodEnum<{
|
|
47
|
+
en: "en";
|
|
48
|
+
fr: "fr";
|
|
49
|
+
}> & z.core.$partial, z.ZodObject<{
|
|
50
|
+
name: z.ZodString;
|
|
51
|
+
plural: z.ZodString;
|
|
52
|
+
permissions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
53
|
+
label: z.ZodString;
|
|
54
|
+
description: z.ZodString;
|
|
55
|
+
}, z.core.$strip>>;
|
|
56
|
+
operations: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
57
|
+
kinds: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
58
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
59
|
+
}, z.core.$strip>>;
|
|
60
|
+
}, z.core.$strict>;
|
|
61
|
+
export type EntityTypeDefinition = z.infer<typeof EntityTypeDefinitionSchema>;
|
|
62
|
+
/** What makes a definition unusable, as sentences (none: it is valid). */
|
|
63
|
+
export declare function entityTypeProblems(definition: {
|
|
64
|
+
id: string;
|
|
65
|
+
permissions: Record<string, string | null>;
|
|
66
|
+
operations: Record<string, string>;
|
|
67
|
+
kinds?: readonly string[];
|
|
68
|
+
actions?: Record<string, EntityAction>;
|
|
69
|
+
messages: Partial<Record<string, Partial<EntityTypeMessages>>>;
|
|
70
|
+
}): string[];
|
|
71
|
+
/** The permission an operation needs, or `undefined` when the type has no such operation. */
|
|
72
|
+
export declare function operationPermission(definition: Pick<EntityTypeDefinition, 'operations'>, operation: string): string | undefined;
|
|
73
|
+
/** Where an action runs: on a page of the handling app, or on its server (through the core). */
|
|
74
|
+
export declare const ACTION_TARGETS: readonly ['page', 'server'];
|
|
75
|
+
export type ActionTarget = (typeof ACTION_TARGETS)[number];
|
|
76
|
+
export interface EntityAction {
|
|
77
|
+
permission: string;
|
|
78
|
+
target: ActionTarget;
|
|
79
|
+
}
|
|
80
|
+
/** An action of the type, or `undefined` when it has no such action. */
|
|
81
|
+
export declare function entityAction(definition: Pick<EntityTypeDefinition, 'actions'>, action: string): EntityAction | undefined;
|
|
82
|
+
/** An action's label for a handling app: "Open with Office". */
|
|
83
|
+
export declare function actionLabel(messages: EntityTypeMessages, action: string, appName: string): string;
|
|
84
|
+
/** A permission and everything it builds on, down to `read`. */
|
|
85
|
+
export declare function permissionChain(definition: Pick<EntityTypeDefinition, 'permissions'>, permission: string): string[];
|
|
86
|
+
/** A set of permissions completed with everything they build on (unknown names dropped). */
|
|
87
|
+
export declare function closePermissions(definition: Pick<EntityTypeDefinition, 'permissions'>, permissions: readonly string[]): string[];
|
|
88
|
+
/** Every permission of the type: what an owner holds. */
|
|
89
|
+
export declare function allPermissions(definition: Pick<EntityTypeDefinition, 'permissions'>): string[];
|
|
90
|
+
/** The type permissions (scopes) of a type: `calendar.event:read`... */
|
|
91
|
+
export declare function typePermissionsOf(definition: EntityTypeDefinition): TypePermission[];
|
|
92
|
+
/** The messages of a type in a locale, English when it has none. */
|
|
93
|
+
export declare function entityTypeMessages(definition: Pick<EntityTypeDefinition, 'messages'>, locale: string): EntityTypeMessages;
|
|
94
|
+
export declare const SHARE_LEVELS: readonly ['reader', 'writer', 'manager'];
|
|
95
|
+
export type ShareLevel = (typeof SHARE_LEVELS)[number];
|
|
96
|
+
/** The permissions a level grants on entities of a type. */
|
|
97
|
+
export declare function levelPermissions(definition: Pick<EntityTypeDefinition, 'permissions'>, level: ShareLevel): string[];
|
|
98
|
+
/** The level a set of permissions amounts to, or `custom` when it matches none. */
|
|
99
|
+
export declare function shareLevelOf(definition: Pick<EntityTypeDefinition, 'permissions'>, permissions: readonly string[]): ShareLevel | 'custom';
|
|
100
|
+
/** The levels an account holding `held` may grant: those whose permissions it all holds. */
|
|
101
|
+
export declare function grantableLevels(definition: Pick<EntityTypeDefinition, 'permissions'>, held: readonly string[]): ShareLevel[];
|
|
102
|
+
export declare const EntityTypeListSchema: z.ZodObject<{
|
|
103
|
+
types: z.ZodArray<z.ZodObject<{
|
|
104
|
+
id: z.ZodString;
|
|
105
|
+
version: z.ZodInt;
|
|
106
|
+
parent: z.ZodNullable<z.ZodString>;
|
|
107
|
+
titleFields: z.ZodArray<z.ZodString>;
|
|
108
|
+
schema: z.ZodRecord<z.ZodString, z.ZodJSONSchema>;
|
|
109
|
+
permissions: z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodString>>;
|
|
110
|
+
operations: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
111
|
+
kinds: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
112
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
113
|
+
permission: z.ZodString;
|
|
114
|
+
target: z.ZodEnum<{
|
|
115
|
+
page: "page";
|
|
116
|
+
server: "server";
|
|
117
|
+
}>;
|
|
118
|
+
}, z.core.$strict>>>;
|
|
119
|
+
messages: z.ZodRecord<z.ZodEnum<{
|
|
120
|
+
en: "en";
|
|
121
|
+
fr: "fr";
|
|
122
|
+
}> & z.core.$partial, z.ZodObject<{
|
|
123
|
+
name: z.ZodString;
|
|
124
|
+
plural: z.ZodString;
|
|
125
|
+
permissions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
126
|
+
label: z.ZodString;
|
|
127
|
+
description: z.ZodString;
|
|
128
|
+
}, z.core.$strip>>;
|
|
129
|
+
operations: z.ZodRecord<z.ZodString, z.ZodString>;
|
|
130
|
+
kinds: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
131
|
+
actions: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
132
|
+
}, z.core.$strip>>;
|
|
133
|
+
}, z.core.$strict>>;
|
|
134
|
+
}, z.core.$strip>;
|
|
135
|
+
export type EntityTypeList = z.infer<typeof EntityTypeListSchema>;
|
|
136
|
+
export interface EntityTypeDeclaration {
|
|
137
|
+
id: string;
|
|
138
|
+
version: number;
|
|
139
|
+
parent: string | null;
|
|
140
|
+
titleFields: string[];
|
|
141
|
+
/** The zod schema of an entity's data: its JSON Schema goes into the definition. */
|
|
142
|
+
data: z.ZodType;
|
|
143
|
+
permissions: Record<string, string | null>;
|
|
144
|
+
operations: Record<string, string>;
|
|
145
|
+
kinds?: string[];
|
|
146
|
+
actions?: Record<string, EntityAction>;
|
|
147
|
+
messages: z.input<typeof EntityTypeDefinitionSchema>['messages'];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* A type package's definition, from its zod data schema: validated now, so a type package with
|
|
151
|
+
* an inconsistent definition fails its own tests rather than an enrollment.
|
|
152
|
+
*/
|
|
153
|
+
export declare function defineEntityType({ data, ...declaration }: EntityTypeDeclaration): EntityTypeDefinition;
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ENTITY_TYPE_ID_PATTERN, ENTITY_TYPE_NAME_PATTERN, typePermission, } from './permissions.js';
|
|
3
|
+
import { LOCALES } from './preferences.js';
|
|
4
|
+
/*
|
|
5
|
+
* Entity types (see docs/architecture/entities/entity-types.md): what apps bring to the
|
|
6
|
+
* platform, written once in a type package (`@artemis-apps/calendar-contracts`). The core keeps the
|
|
7
|
+
* definitions it receives in manifests and reads only their envelope: permissions, operations,
|
|
8
|
+
* parent, translations. It never reads an entity's data.
|
|
9
|
+
*/
|
|
10
|
+
/** The permission every type has, every other one builds on, and lists and reads need. */
|
|
11
|
+
export const READ_PERMISSION = 'read';
|
|
12
|
+
/** The permission every type has: sharing what one holds. */
|
|
13
|
+
export const SHARE_PERMISSION = 'share';
|
|
14
|
+
/** The operations every provider of a type serves. */
|
|
15
|
+
export const REQUIRED_OPERATIONS = ['list', 'read'];
|
|
16
|
+
/** The writes most types have; a type may leave any out, and a provider may not implement them. */
|
|
17
|
+
export const STANDARD_OPERATIONS = ['list', 'read', 'create', 'update', 'delete'];
|
|
18
|
+
export const EntityTypeIdSchema = z
|
|
19
|
+
.string()
|
|
20
|
+
.max(80)
|
|
21
|
+
.regex(ENTITY_TYPE_ID_PATTERN, 'Expected `<namespace>.<name>` in lowercase kebab-case');
|
|
22
|
+
const NameSchema = z
|
|
23
|
+
.string()
|
|
24
|
+
.max(40)
|
|
25
|
+
.regex(ENTITY_TYPE_NAME_PATTERN, 'Expected a lowercase kebab-case name');
|
|
26
|
+
const LabelSchema = z.string().trim().min(1).max(120);
|
|
27
|
+
/** How a permission reads, on the consent screen and in share dialogs. */
|
|
28
|
+
export const PermissionMessagesSchema = z.object({
|
|
29
|
+
label: LabelSchema,
|
|
30
|
+
description: z.string().trim().max(280),
|
|
31
|
+
});
|
|
32
|
+
export const EntityTypeMessagesSchema = z.object({
|
|
33
|
+
/** One entity: "Event". */
|
|
34
|
+
name: LabelSchema,
|
|
35
|
+
/** Several: "Events". */
|
|
36
|
+
plural: LabelSchema,
|
|
37
|
+
permissions: z.record(NameSchema, PermissionMessagesSchema),
|
|
38
|
+
operations: z.record(NameSchema, LabelSchema),
|
|
39
|
+
/** Each kind's name: "Document", "Spreadsheet". */
|
|
40
|
+
kinds: z.record(NameSchema, LabelSchema).default({}),
|
|
41
|
+
/**
|
|
42
|
+
* Each action's label, `{app}` standing for the handling app's name: "Open with {app}". An
|
|
43
|
+
* action whose label has no `{app}` names what it does alone ("New").
|
|
44
|
+
*/
|
|
45
|
+
actions: z.record(NameSchema, LabelSchema).default({}),
|
|
46
|
+
});
|
|
47
|
+
const LocaleKeySchema = z.enum(LOCALES);
|
|
48
|
+
export const EntityTypeDefinitionSchema = z
|
|
49
|
+
.strictObject({
|
|
50
|
+
id: EntityTypeIdSchema,
|
|
51
|
+
/** Raised by every change, which only adds; anything breaking is a new type id. */
|
|
52
|
+
version: z.int().min(1).max(1_000_000),
|
|
53
|
+
/** The type of an entity's parent: the same provider and owner always hold both. */
|
|
54
|
+
parent: EntityTypeIdSchema.nullable(),
|
|
55
|
+
/** The data fields naming an entity, joined by spaces (share dialogs, logs). */
|
|
56
|
+
titleFields: z
|
|
57
|
+
.array(z
|
|
58
|
+
.string()
|
|
59
|
+
.regex(/^[a-zA-Z][a-zA-Z0-9]*$/)
|
|
60
|
+
.max(40))
|
|
61
|
+
.min(1)
|
|
62
|
+
.max(4),
|
|
63
|
+
/** The JSON Schema of an entity's data, for people to read: the core never validates data. */
|
|
64
|
+
schema: z.record(z.string(), z.json()),
|
|
65
|
+
/** Each permission → the one it builds on (`null` for `read` only). */
|
|
66
|
+
permissions: z.record(NameSchema, NameSchema.nullable()),
|
|
67
|
+
/** Each operation → the permission it needs. */
|
|
68
|
+
operations: z.record(NameSchema, NameSchema),
|
|
69
|
+
/**
|
|
70
|
+
* The kinds of entities of the type that apps may handle apart (a drive item is a document,
|
|
71
|
+
* a spreadsheet...); the type package says how an entity's kind is known.
|
|
72
|
+
*/
|
|
73
|
+
kinds: z.array(NameSchema).max(50).default([]),
|
|
74
|
+
/**
|
|
75
|
+
* What other apps can do with an entity, by name (`open`, `new`, `preview`), the handling
|
|
76
|
+
* apps saying which they handle (`handles`). Each needs a permission on the entity (on the
|
|
77
|
+
* parent it creates in, for `new`), and runs on a `page` of the handling app (the browser
|
|
78
|
+
* goes there) or its `server` (the core calls it and passes its answer on).
|
|
79
|
+
*/
|
|
80
|
+
actions: z
|
|
81
|
+
.record(NameSchema, z.strictObject({ permission: NameSchema, target: z.enum(['page', 'server']) }))
|
|
82
|
+
.default({}),
|
|
83
|
+
/** English at least. */
|
|
84
|
+
messages: z
|
|
85
|
+
.partialRecord(LocaleKeySchema, EntityTypeMessagesSchema)
|
|
86
|
+
.refine((messages) => messages.en !== undefined, {
|
|
87
|
+
message: 'English messages are required.',
|
|
88
|
+
}),
|
|
89
|
+
})
|
|
90
|
+
.superRefine((definition, context) => {
|
|
91
|
+
for (const problem of entityTypeProblems(definition)) {
|
|
92
|
+
context.addIssue({ code: 'custom', message: problem });
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
/** What makes a definition unusable, as sentences (none: it is valid). */
|
|
96
|
+
export function entityTypeProblems(definition) {
|
|
97
|
+
const problems = [];
|
|
98
|
+
const { permissions, operations, kinds = [], actions = {} } = definition;
|
|
99
|
+
if (permissions[READ_PERMISSION] !== null) {
|
|
100
|
+
problems.push('`read` must be a permission building on nothing.');
|
|
101
|
+
}
|
|
102
|
+
if (!Object.hasOwn(permissions, SHARE_PERMISSION))
|
|
103
|
+
problems.push('`share` must be a permission.');
|
|
104
|
+
for (const [name, base] of Object.entries(permissions)) {
|
|
105
|
+
if (name !== READ_PERMISSION && base === null) {
|
|
106
|
+
problems.push(`\`${name}\` must build on another permission: only \`read\` is the root.`);
|
|
107
|
+
}
|
|
108
|
+
else if (base !== null && !Object.hasOwn(permissions, base)) {
|
|
109
|
+
problems.push(`\`${name}\` builds on \`${base}\`, which is not a permission of the type.`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
for (const name of Object.keys(permissions)) {
|
|
113
|
+
const seen = new Set();
|
|
114
|
+
let current = name;
|
|
115
|
+
while (current) {
|
|
116
|
+
if (seen.has(current)) {
|
|
117
|
+
problems.push(`\`${name}\` builds on itself.`);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
seen.add(current);
|
|
121
|
+
current = permissions[current];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const operation of REQUIRED_OPERATIONS) {
|
|
125
|
+
if (operations[operation] !== READ_PERMISSION) {
|
|
126
|
+
problems.push(`\`${operation}\` must be an operation needing \`read\`.`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
for (const [operation, permission] of Object.entries(operations)) {
|
|
130
|
+
if (!Object.hasOwn(permissions, permission)) {
|
|
131
|
+
problems.push(`\`${operation}\` needs \`${permission}\`, which is not a permission of the type.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (const [action, { permission }] of Object.entries(actions)) {
|
|
135
|
+
if (!Object.hasOwn(permissions, permission)) {
|
|
136
|
+
problems.push(`\`${action}\` needs \`${permission}\`, which is not a permission of the type.`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
if (new Set(kinds).size !== kinds.length)
|
|
140
|
+
problems.push('A kind is declared twice.');
|
|
141
|
+
for (const [locale, messages] of Object.entries(definition.messages)) {
|
|
142
|
+
for (const name of Object.keys(permissions)) {
|
|
143
|
+
if (!messages?.permissions?.[name]) {
|
|
144
|
+
problems.push(`The ${locale} messages lack the permission \`${name}\`.`);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
const english = definition.messages.en;
|
|
149
|
+
for (const kind of kinds) {
|
|
150
|
+
if (!english?.kinds?.[kind])
|
|
151
|
+
problems.push(`The en messages lack the kind \`${kind}\`.`);
|
|
152
|
+
}
|
|
153
|
+
for (const action of Object.keys(actions)) {
|
|
154
|
+
if (!english?.actions?.[action])
|
|
155
|
+
problems.push(`The en messages lack the action \`${action}\`.`);
|
|
156
|
+
}
|
|
157
|
+
return problems;
|
|
158
|
+
}
|
|
159
|
+
/** The permission an operation needs, or `undefined` when the type has no such operation. */
|
|
160
|
+
export function operationPermission(definition, operation) {
|
|
161
|
+
return Object.hasOwn(definition.operations, operation)
|
|
162
|
+
? definition.operations[operation]
|
|
163
|
+
: undefined;
|
|
164
|
+
}
|
|
165
|
+
/** Where an action runs: on a page of the handling app, or on its server (through the core). */
|
|
166
|
+
export const ACTION_TARGETS = ['page', 'server'];
|
|
167
|
+
/** An action of the type, or `undefined` when it has no such action. */
|
|
168
|
+
export function entityAction(definition, action) {
|
|
169
|
+
return Object.hasOwn(definition.actions, action) ? definition.actions[action] : undefined;
|
|
170
|
+
}
|
|
171
|
+
/** An action's label for a handling app: "Open with Office". */
|
|
172
|
+
export function actionLabel(messages, action, appName) {
|
|
173
|
+
return (messages.actions[action] ?? action).replaceAll('{app}', appName);
|
|
174
|
+
}
|
|
175
|
+
/** A permission and everything it builds on, down to `read`. */
|
|
176
|
+
export function permissionChain(definition, permission) {
|
|
177
|
+
const chain = [];
|
|
178
|
+
let current = permission;
|
|
179
|
+
while (current && Object.hasOwn(definition.permissions, current) && !chain.includes(current)) {
|
|
180
|
+
chain.push(current);
|
|
181
|
+
current = definition.permissions[current];
|
|
182
|
+
}
|
|
183
|
+
return chain;
|
|
184
|
+
}
|
|
185
|
+
/** A set of permissions completed with everything they build on (unknown names dropped). */
|
|
186
|
+
export function closePermissions(definition, permissions) {
|
|
187
|
+
const closed = new Set(permissions.flatMap((permission) => permissionChain(definition, permission)));
|
|
188
|
+
return Object.keys(definition.permissions).filter((permission) => closed.has(permission));
|
|
189
|
+
}
|
|
190
|
+
/** Every permission of the type: what an owner holds. */
|
|
191
|
+
export function allPermissions(definition) {
|
|
192
|
+
return Object.keys(definition.permissions);
|
|
193
|
+
}
|
|
194
|
+
/** The type permissions (scopes) of a type: `calendar.event:read`... */
|
|
195
|
+
export function typePermissionsOf(definition) {
|
|
196
|
+
return allPermissions(definition).map((permission) => typePermission(definition.id, permission));
|
|
197
|
+
}
|
|
198
|
+
/** The messages of a type in a locale, English when it has none. */
|
|
199
|
+
export function entityTypeMessages(definition, locale) {
|
|
200
|
+
const messages = definition.messages;
|
|
201
|
+
return messages[locale] ?? messages.en;
|
|
202
|
+
}
|
|
203
|
+
/*
|
|
204
|
+
* Share levels: words of web clients only. The core, the types and the providers know
|
|
205
|
+
* permissions; a web client offers three levels, worked out from the type.
|
|
206
|
+
*/
|
|
207
|
+
export const SHARE_LEVELS = ['reader', 'writer', 'manager'];
|
|
208
|
+
/** The permissions a level grants on entities of a type. */
|
|
209
|
+
export function levelPermissions(definition, level) {
|
|
210
|
+
const all = allPermissions(definition);
|
|
211
|
+
switch (level) {
|
|
212
|
+
case 'reader':
|
|
213
|
+
return [READ_PERMISSION];
|
|
214
|
+
case 'writer':
|
|
215
|
+
// Every permission that neither is `share` nor builds on it.
|
|
216
|
+
return all.filter((permission) => !permissionChain(definition, permission).includes(SHARE_PERMISSION));
|
|
217
|
+
case 'manager':
|
|
218
|
+
return all;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
/** The level a set of permissions amounts to, or `custom` when it matches none. */
|
|
222
|
+
export function shareLevelOf(definition, permissions) {
|
|
223
|
+
const held = new Set(closePermissions(definition, permissions));
|
|
224
|
+
for (const level of [...SHARE_LEVELS].reverse()) {
|
|
225
|
+
const expected = levelPermissions(definition, level);
|
|
226
|
+
if (expected.length === held.size && expected.every((permission) => held.has(permission))) {
|
|
227
|
+
return level;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return 'custom';
|
|
231
|
+
}
|
|
232
|
+
/** The levels an account holding `held` may grant: those whose permissions it all holds. */
|
|
233
|
+
export function grantableLevels(definition, held) {
|
|
234
|
+
return SHARE_LEVELS.filter((level) => levelPermissions(definition, level).every((permission) => held.includes(permission)));
|
|
235
|
+
}
|
|
236
|
+
export const EntityTypeListSchema = z.object({
|
|
237
|
+
types: z.array(EntityTypeDefinitionSchema),
|
|
238
|
+
});
|
|
239
|
+
/**
|
|
240
|
+
* A type package's definition, from its zod data schema: validated now, so a type package with
|
|
241
|
+
* an inconsistent definition fails its own tests rather than an enrollment.
|
|
242
|
+
*/
|
|
243
|
+
export function defineEntityType({ data, ...declaration }) {
|
|
244
|
+
return EntityTypeDefinitionSchema.parse({
|
|
245
|
+
...declaration,
|
|
246
|
+
schema: z.toJSONSchema(data, { io: 'output', unrepresentable: 'any' }),
|
|
247
|
+
});
|
|
248
|
+
}
|
package/dist/images.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Pictures accepted from people: anything else is refused. */
|
|
2
|
+
export declare const ACCEPTED_IMAGE_TYPES: readonly ['image/png', 'image/jpeg', 'image/webp'];
|
|
3
|
+
export type AcceptedImageType = (typeof ACCEPTED_IMAGE_TYPES)[number];
|
|
4
|
+
/** Largest picture accepted from people. */
|
|
5
|
+
export declare const MAX_IMAGE_UPLOAD_BYTES: number;
|
|
6
|
+
export declare const isAcceptedImageType: (type: string) => type is AcceptedImageType;
|
package/dist/images.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Pictures people upload (avatars, contact photos) and that apps derive (thumbnails). Apps
|
|
3
|
+
* normalise them on their own server (`@artemis-apps/server-kit/images`) before storing them: the core
|
|
4
|
+
* storage only keeps files.
|
|
5
|
+
*/
|
|
6
|
+
/** Pictures accepted from people: anything else is refused. */
|
|
7
|
+
export const ACCEPTED_IMAGE_TYPES = ['image/png', 'image/jpeg', 'image/webp'];
|
|
8
|
+
/** Largest picture accepted from people. */
|
|
9
|
+
export const MAX_IMAGE_UPLOAD_BYTES = 5 * 1024 * 1024;
|
|
10
|
+
export const isAcceptedImageType = (type) => ACCEPTED_IMAGE_TYPES.includes(type);
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { ACTIVITY_ACTIONS, ACTIVITY_CORE_APP_ID, ACTIVITY_DETAILS_MAX_LENGTH, ACTIVITY_LEVELS, ACTIVITY_PAGE_SIZE, type ActivityAction, ActivityActionSchema, type ActivityApp, ActivityAppSchema, type ActivityDetails, ActivityDetailsSchema, type ActivityEvent, type ActivityEventPage, ActivityEventPageSchema, type ActivityEventQuery, ActivityEventQuerySchema, ActivityEventSchema, type ActivityLevel, ActivityLevelSchema, type ActivityReport, ActivityReportSchema, activityLevelsFrom, activityNamespace, CORE_ACTIVITY_NAMESPACES, CORE_ACTIVITY_PATHS, formatActivityEventQuery, isActivityAction, isCoreActivityNamespace, } from './activity.ts';
|
|
2
|
+
export { type ApiErrorBody, ApiErrorBodySchema } from './api-error.ts';
|
|
3
|
+
export { APP_KEY_ALGORITHM, APP_PROTOCOL_PATHS, AppIdSchema, type AppManifest, type AppManifestDeclaration, AppManifestDeclarationSchema, AppManifestSchema, AppPathSchema, type AppProtocolPath, type AppPublicKey, AppPublicKeySchema, appBasePath, appEndpoint, appRedirectUri, CORE_PROTOCOL_PATHS, coreIssuerUrl, formatHandleQuery, HANDLE_PARAMS, type HandleTarget, InvalidAppUrlError, isLoopbackUrl, isWithinAppUrl, manifestProblems, normalizeAppUrl, type ProvidedType, ProvidedTypeSchema, parseHandleQuery, SECURITY_EVENT_CONTENT_TYPE, SECURITY_EVENT_TOKEN_TYPE, SECURITY_EVENTS, type SecurityEvent, SecurityEventSchema, type SupportedKind, SupportedKindSchema, } from './app-protocol.ts';
|
|
4
|
+
export { type AppSessionState, AppSessionStateSchema, type SignOutResponse, SignOutResponseSchema, } from './app-session-state.ts';
|
|
5
|
+
export { type AccountDeletion, AccountDeletionSchema, type AccountList, AccountListSchema, type AccountUpdate, AccountUpdateSchema, type AppCapabilities, AppCapabilitiesSchema, type AppOrder, AppOrderSchema, type AppRevocationQuery, AppRevocationQuerySchema, CORE_ACCOUNT_PAGE_PATH, CORE_ADMIN_APPS_PAGE_PATH, CORE_ADMIN_MARKETPLACE_PAGE_PATH, CORE_ADMIN_PAGE_PATH, CORE_API_PATHS, CORE_BRAND_ICON_PATHS, CORE_CONSENT_PAGE_PATH, CORE_INTERACTION_PATHS, CORE_RELAYED_PATHS, CORE_SIGN_IN_PAGE_PATH, type ConsentDecisionResult, ConsentDecisionResultSchema, type ConsentRequest, ConsentRequestSchema, type CurrentAccountResponse, CurrentAccountResponseSchema, DIRECTORY_MAX_IDS, DIRECTORY_SEARCH_LIMIT, type DirectoryAccountList, DirectoryAccountListSchema, DirectoryLookupSchema, type DirectoryQuery, DirectoryQuerySchema, type DirectorySearch, DirectorySearchSchema, ENROLL_PARAM, ENROLLMENT_WARNING_CODES, type EnrolledApp, type EnrolledAppList, EnrolledAppListSchema, EnrolledAppSchema, type EnrollmentRequest, EnrollmentRequestSchema, type EnrollmentReview, EnrollmentReviewSchema, type EnrollmentWarningCode, EnrollmentWarningCodeSchema, type EntityHandler, type EntityHandlerList, EntityHandlerListSchema, EntityHandlerSchema, type EntityKind, type EntityKindList, EntityKindListSchema, EntityKindSchema, formatDirectoryQuery, LAUNCHER_ENTRY_KINDS, type Launcher, type LauncherEntry, LauncherEntrySchema, LauncherSchema, PASSWORD_MIN_LENGTH, type PasswordChange, PasswordChangeSchema, type PermissionsUpdate, PermissionsUpdateSchema, type RegistrationInput, RegistrationInputSchema, type SignInInput, SignInInputSchema, } from './core-api.ts';
|
|
6
|
+
export { type Account, AccountSchema, type AccountWithPermissions, AccountWithPermissionsSchema, } from './entities/account.entity.ts';
|
|
7
|
+
export { type Avatar, type AvatarReference, type AvatarRegeneration, AvatarRegenerationSchema, AvatarSchema, formatAvatarReference, parseAvatarReference, } from './entities/avatar.entity.ts';
|
|
8
|
+
export { ENTITY_NAMES, type EntityName } from './entities/entity-name.ts';
|
|
9
|
+
export { ENTITY_GRANT, ENTITY_PARAMS, type Entity, type EntityAccess, EntityAccessSchema, type EntityGrantTarget, EntityGrantTargetSchema, EntityIdSchema, type EntityList, EntityListSchema, type EntityPointer, EntityPointerSchema, type EntityRef, EntityRefSchema, type EntityResult, EntityResultSchema, EntitySchema, entityListSchema, entityResultSchema, entitySchema, formatEntityListQuery, formatOwnedId, formatPointer, HANDLER_TOKEN_TYPE, type HandledActionCall, HandledActionCallSchema, isProviderSelected, MAX_ENTITY_BODY_BYTES, PROVIDER_TOKEN_TYPE, type ProviderEntity, type ProviderEntityList, ProviderEntityListSchema, ProviderEntitySchema, type ProviderFilter, type ProviderSummary, ProviderSummarySchema, type ProviderTokenClaims, ProviderTokenClaimsSchema, parseEntityListQuery, parseOwnedId, parsePointer, } from './entities.ts';
|
|
10
|
+
export { type EntityShare, EntityShareSchema, type EntitySharing, EntitySharingSchema, type ShareInput, ShareInputSchema, } from './entity-shares.ts';
|
|
11
|
+
export { ACTION_TARGETS, type ActionTarget, actionLabel, allPermissions, closePermissions, defineEntityType, type EntityAction, type EntityTypeDeclaration, type EntityTypeDefinition, EntityTypeDefinitionSchema, EntityTypeIdSchema, type EntityTypeList, EntityTypeListSchema, type EntityTypeMessages, EntityTypeMessagesSchema, entityAction, entityTypeMessages, entityTypeProblems, grantableLevels, levelPermissions, operationPermission, PermissionMessagesSchema, permissionChain, READ_PERMISSION, REQUIRED_OPERATIONS, SHARE_LEVELS, SHARE_PERMISSION, type ShareLevel, STANDARD_OPERATIONS, type StandardOperation, shareLevelOf, typePermissionsOf, } from './entity-types.ts';
|
|
12
|
+
export { ACCEPTED_IMAGE_TYPES, type AcceptedImageType, isAcceptedImageType, MAX_IMAGE_UPLOAD_BYTES, } from './images.ts';
|
|
13
|
+
export { APP_BUNDLE_SERVER, APP_PACKAGE_FILE, APP_RUNTIME, type AppPackage, type AppPackageInput, AppPackageSchema, type AppRepository, type AppRepositoryInput, AppRepositoryInputSchema, type AppRepositoryList, AppRepositoryListSchema, AppRepositorySchema, INSTALLATION_STATES, INSTALLED_APPS_PATH, type Installation, type InstallationList, InstallationListSchema, type InstallationRequest, InstallationRequestSchema, InstallationSchema, type InstallationState, InstallationStateSchema, InvalidRepositoryUrlError, installedAppUrl, MARKETPLACE_API_PATHS, repositoryFilesUrl, repositoryFileUrl, Sha256Schema, UninstallQuerySchema, } from './marketplace.ts';
|
|
14
|
+
export { ACCOUNT_CLAIM_NAMES, type AccountClaims, AccountClaimsSchema, APP_ADMINISTRATOR_CLAIM, OPENID_SCOPE, } from './oidc.ts';
|
|
15
|
+
export { ADMIN_NAMESPACE, ADMIN_PERMISSIONS, type AdminPermission, AdminPermissionSchema, CORE_PERMISSIONS, type CorePermission, CorePermissionSchema, DELEGABLE_CORE_PERMISSIONS, type DelegableCorePermission, type DelegablePermission, DelegablePermissionSchema, ENTITY_TYPE_ID_PATTERN, formatScope, hasPermissions, intersectPermissions, isAdminPermission, isBaseAccountPermission, isCorePermission, isDelegablePermission, isPermission, isTypePermission, type Permission, PermissionSchema, parseScope, parseTypePermission, permissionNamespace, type TypePermission, TypePermissionSchema, typePermission, } from './permissions.ts';
|
|
16
|
+
export { type AccountPreferences, AccountPreferencesSchema, type AccountPreferencesUpdate, AccountPreferencesUpdateSchema, DEFAULT_LOCALE, isLocale, LOCALES, type Locale, LocaleSchema, } from './preferences.ts';
|
|
17
|
+
export { RETURN_TO_PARAM, sanitizeReturnPath } from './return-path.ts';
|
|
18
|
+
export { fillPath, type PathParameters } from './route-path.ts';
|
|
19
|
+
export { CORE_STORAGE_PATHS, FILE_VISIBILITIES, type FileUploadFields, FileUploadFieldsSchema, type FileVisibility, FileVisibilitySchema, MAX_STORED_FILE_BYTES, type StoredFile, StoredFileSchema, } from './storage.ts';
|
|
20
|
+
export { WebUrlSchema } from './web-url.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Platform contracts: shared by the core and every app.
|
|
3
|
+
* App-specific contracts live behind their own subpath (e.g. `@artemis-apps/contacts-contracts/api`).
|
|
4
|
+
*/
|
|
5
|
+
export { ACTIVITY_ACTIONS, ACTIVITY_CORE_APP_ID, ACTIVITY_DETAILS_MAX_LENGTH, ACTIVITY_LEVELS, ACTIVITY_PAGE_SIZE, ActivityActionSchema, ActivityAppSchema, ActivityDetailsSchema, ActivityEventPageSchema, ActivityEventQuerySchema, ActivityEventSchema, ActivityLevelSchema, ActivityReportSchema, activityLevelsFrom, activityNamespace, CORE_ACTIVITY_NAMESPACES, CORE_ACTIVITY_PATHS, formatActivityEventQuery, isActivityAction, isCoreActivityNamespace, } from './activity.js';
|
|
6
|
+
export { ApiErrorBodySchema } from './api-error.js';
|
|
7
|
+
export { APP_KEY_ALGORITHM, APP_PROTOCOL_PATHS, AppIdSchema, AppManifestDeclarationSchema, AppManifestSchema, AppPathSchema, AppPublicKeySchema, appBasePath, appEndpoint, appRedirectUri, CORE_PROTOCOL_PATHS, coreIssuerUrl, formatHandleQuery, HANDLE_PARAMS, InvalidAppUrlError, isLoopbackUrl, isWithinAppUrl, manifestProblems, normalizeAppUrl, ProvidedTypeSchema, parseHandleQuery, SECURITY_EVENT_CONTENT_TYPE, SECURITY_EVENT_TOKEN_TYPE, SECURITY_EVENTS, SecurityEventSchema, SupportedKindSchema, } from './app-protocol.js';
|
|
8
|
+
export { AppSessionStateSchema, SignOutResponseSchema, } from './app-session-state.js';
|
|
9
|
+
export { AccountDeletionSchema, AccountListSchema, AccountUpdateSchema, AppCapabilitiesSchema, AppOrderSchema, AppRevocationQuerySchema, CORE_ACCOUNT_PAGE_PATH, CORE_ADMIN_APPS_PAGE_PATH, CORE_ADMIN_MARKETPLACE_PAGE_PATH, CORE_ADMIN_PAGE_PATH, CORE_API_PATHS, CORE_BRAND_ICON_PATHS, CORE_CONSENT_PAGE_PATH, CORE_INTERACTION_PATHS, CORE_RELAYED_PATHS, CORE_SIGN_IN_PAGE_PATH, ConsentDecisionResultSchema, ConsentRequestSchema, CurrentAccountResponseSchema, DIRECTORY_MAX_IDS, DIRECTORY_SEARCH_LIMIT, DirectoryAccountListSchema, DirectoryLookupSchema, DirectoryQuerySchema, DirectorySearchSchema, ENROLL_PARAM, ENROLLMENT_WARNING_CODES, EnrolledAppListSchema, EnrolledAppSchema, EnrollmentRequestSchema, EnrollmentReviewSchema, EnrollmentWarningCodeSchema, EntityHandlerListSchema, EntityHandlerSchema, EntityKindListSchema, EntityKindSchema, formatDirectoryQuery, LAUNCHER_ENTRY_KINDS, LauncherEntrySchema, LauncherSchema, PASSWORD_MIN_LENGTH, PasswordChangeSchema, PermissionsUpdateSchema, RegistrationInputSchema, SignInInputSchema, } from './core-api.js';
|
|
10
|
+
export { AccountSchema, AccountWithPermissionsSchema, } from './entities/account.entity.js';
|
|
11
|
+
export { AvatarRegenerationSchema, AvatarSchema, formatAvatarReference, parseAvatarReference, } from './entities/avatar.entity.js';
|
|
12
|
+
export { ENTITY_NAMES } from './entities/entity-name.js';
|
|
13
|
+
export { ENTITY_GRANT, ENTITY_PARAMS, EntityAccessSchema, EntityGrantTargetSchema, EntityIdSchema, EntityListSchema, EntityPointerSchema, EntityRefSchema, EntityResultSchema, EntitySchema, entityListSchema, entityResultSchema, entitySchema, formatEntityListQuery, formatOwnedId, formatPointer, HANDLER_TOKEN_TYPE, HandledActionCallSchema, isProviderSelected, MAX_ENTITY_BODY_BYTES, PROVIDER_TOKEN_TYPE, ProviderEntityListSchema, ProviderEntitySchema, ProviderSummarySchema, ProviderTokenClaimsSchema, parseEntityListQuery, parseOwnedId, parsePointer, } from './entities.js';
|
|
14
|
+
export { EntityShareSchema, EntitySharingSchema, ShareInputSchema, } from './entity-shares.js';
|
|
15
|
+
export { ACTION_TARGETS, actionLabel, allPermissions, closePermissions, defineEntityType, EntityTypeDefinitionSchema, EntityTypeIdSchema, EntityTypeListSchema, EntityTypeMessagesSchema, entityAction, entityTypeMessages, entityTypeProblems, grantableLevels, levelPermissions, operationPermission, PermissionMessagesSchema, permissionChain, READ_PERMISSION, REQUIRED_OPERATIONS, SHARE_LEVELS, SHARE_PERMISSION, STANDARD_OPERATIONS, shareLevelOf, typePermissionsOf, } from './entity-types.js';
|
|
16
|
+
export { ACCEPTED_IMAGE_TYPES, isAcceptedImageType, MAX_IMAGE_UPLOAD_BYTES, } from './images.js';
|
|
17
|
+
export { APP_BUNDLE_SERVER, APP_PACKAGE_FILE, APP_RUNTIME, AppPackageSchema, AppRepositoryInputSchema, AppRepositoryListSchema, AppRepositorySchema, INSTALLATION_STATES, INSTALLED_APPS_PATH, InstallationListSchema, InstallationRequestSchema, InstallationSchema, InstallationStateSchema, InvalidRepositoryUrlError, installedAppUrl, MARKETPLACE_API_PATHS, repositoryFilesUrl, repositoryFileUrl, Sha256Schema, UninstallQuerySchema, } from './marketplace.js';
|
|
18
|
+
export { ACCOUNT_CLAIM_NAMES, AccountClaimsSchema, APP_ADMINISTRATOR_CLAIM, OPENID_SCOPE, } from './oidc.js';
|
|
19
|
+
export { ADMIN_NAMESPACE, ADMIN_PERMISSIONS, AdminPermissionSchema, CORE_PERMISSIONS, CorePermissionSchema, DELEGABLE_CORE_PERMISSIONS, DelegablePermissionSchema, ENTITY_TYPE_ID_PATTERN, formatScope, hasPermissions, intersectPermissions, isAdminPermission, isBaseAccountPermission, isCorePermission, isDelegablePermission, isPermission, isTypePermission, PermissionSchema, parseScope, parseTypePermission, permissionNamespace, TypePermissionSchema, typePermission, } from './permissions.js';
|
|
20
|
+
export { AccountPreferencesSchema, AccountPreferencesUpdateSchema, DEFAULT_LOCALE, isLocale, LOCALES, LocaleSchema, } from './preferences.js';
|
|
21
|
+
export { RETURN_TO_PARAM, sanitizeReturnPath } from './return-path.js';
|
|
22
|
+
export { fillPath } from './route-path.js';
|
|
23
|
+
export { CORE_STORAGE_PATHS, FILE_VISIBILITIES, FileUploadFieldsSchema, FileVisibilitySchema, MAX_STORED_FILE_BYTES, StoredFileSchema, } from './storage.js';
|
|
24
|
+
export { WebUrlSchema } from './web-url.js';
|