@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,183 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The file an app repository describes its app in, at its root (or the folder it names). */
|
|
3
|
+
export declare const APP_PACKAGE_FILE = "artemis-app.json";
|
|
4
|
+
/**
|
|
5
|
+
* What the core gives the apps it runs, which their bundles count on: Node 26, and the native
|
|
6
|
+
* modules `better-sqlite3` and `sharp`, which a bundle leaves out (it can't ship binaries for every
|
|
7
|
+
* system). A package names the runtime it was built for; the core runs only its own.
|
|
8
|
+
*/
|
|
9
|
+
export declare const APP_RUNTIME = 1;
|
|
10
|
+
/**
|
|
11
|
+
* The server of a bundle, from its root. A bundle is laid out like an app's folder in this
|
|
12
|
+
* repository (`api/dist/server.mjs`, `api/drizzle/`, `web/dist/`...), so the defaults of the
|
|
13
|
+
* app's configuration find everything without being told.
|
|
14
|
+
*/
|
|
15
|
+
export declare const APP_BUNDLE_SERVER = "api/dist/server.mjs";
|
|
16
|
+
/** Where the apps the core runs live, on its own host: `<core URL>/apps/<id>`. */
|
|
17
|
+
export declare const INSTALLED_APPS_PATH = "/apps";
|
|
18
|
+
/** The public URL of an app the core runs. */
|
|
19
|
+
export declare function installedAppUrl(coreUrl: string, appId: string): string;
|
|
20
|
+
/** The SHA-256 of a file, in lowercase hexadecimal. */
|
|
21
|
+
export declare const Sha256Schema: z.ZodString;
|
|
22
|
+
/**
|
|
23
|
+
* What an app repository says of its app (`APP_PACKAGE_FILE`): how it shows in the marketplace,
|
|
24
|
+
* and the bundle the core runs. Its server is an app of the platform (`@artemis-apps/app-server`),
|
|
25
|
+
* configured by `PORT`, `PUBLIC_URL`, `CORE_URL` and `CORE_INTERNAL_URL`, which the core sets; it
|
|
26
|
+
* runs in its own data folder.
|
|
27
|
+
*/
|
|
28
|
+
export declare const AppPackageSchema: z.ZodObject<{
|
|
29
|
+
id: z.ZodString;
|
|
30
|
+
name: z.ZodString;
|
|
31
|
+
description: z.ZodOptional<z.ZodString>;
|
|
32
|
+
version: z.ZodString;
|
|
33
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
34
|
+
runtime: z.ZodNumber;
|
|
35
|
+
bundle: z.ZodObject<{
|
|
36
|
+
url: z.ZodUnion<readonly [z.ZodURL, z.ZodString]>;
|
|
37
|
+
sha256: z.ZodString;
|
|
38
|
+
}, z.core.$strict>;
|
|
39
|
+
}, z.core.$strict>;
|
|
40
|
+
export type AppPackage = z.infer<typeof AppPackageSchema>;
|
|
41
|
+
export type AppPackageInput = z.input<typeof AppPackageSchema>;
|
|
42
|
+
export declare class InvalidRepositoryUrlError extends Error {
|
|
43
|
+
readonly name = "InvalidRepositoryUrlError";
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Where a repository's files are read: a GitHub repository (`https://github.com/owner/repo`,
|
|
47
|
+
* its default branch) or one of its folders (`…/tree/<ref>/<folder>`) is read from
|
|
48
|
+
* `raw.githubusercontent.com`; any other http(s) URL is the folder holding the files itself.
|
|
49
|
+
*/
|
|
50
|
+
export declare function repositoryFilesUrl(repositoryUrl: string): string;
|
|
51
|
+
/** A file of the repository (a path from the package file's folder), or an absolute URL as is. */
|
|
52
|
+
export declare function repositoryFileUrl(repositoryUrl: string, path: string): string;
|
|
53
|
+
export declare const AppRepositoryInputSchema: z.ZodObject<{
|
|
54
|
+
url: z.ZodURL;
|
|
55
|
+
}, z.core.$strip>;
|
|
56
|
+
export type AppRepositoryInput = z.input<typeof AppRepositoryInputSchema>;
|
|
57
|
+
/** A repository as the marketplace lists it, with what it offers now. */
|
|
58
|
+
export declare const AppRepositorySchema: z.ZodObject<{
|
|
59
|
+
id: z.ZodString;
|
|
60
|
+
url: z.ZodString;
|
|
61
|
+
addedAt: z.ZodISODateTime;
|
|
62
|
+
listing: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
63
|
+
status: z.ZodLiteral<"available">;
|
|
64
|
+
package: z.ZodObject<{
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
name: z.ZodString;
|
|
67
|
+
description: z.ZodOptional<z.ZodString>;
|
|
68
|
+
version: z.ZodString;
|
|
69
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
70
|
+
runtime: z.ZodNumber;
|
|
71
|
+
bundle: z.ZodObject<{
|
|
72
|
+
url: z.ZodUnion<readonly [z.ZodURL, z.ZodString]>;
|
|
73
|
+
sha256: z.ZodString;
|
|
74
|
+
}, z.core.$strict>;
|
|
75
|
+
}, z.core.$strict>;
|
|
76
|
+
iconUrl: z.ZodNullable<z.ZodString>;
|
|
77
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
78
|
+
status: z.ZodLiteral<"unavailable">;
|
|
79
|
+
reason: z.ZodString;
|
|
80
|
+
}, z.core.$strip>], "status">;
|
|
81
|
+
}, z.core.$strip>;
|
|
82
|
+
export type AppRepository = z.infer<typeof AppRepositorySchema>;
|
|
83
|
+
export declare const AppRepositoryListSchema: z.ZodObject<{
|
|
84
|
+
repositories: z.ZodArray<z.ZodObject<{
|
|
85
|
+
id: z.ZodString;
|
|
86
|
+
url: z.ZodString;
|
|
87
|
+
addedAt: z.ZodISODateTime;
|
|
88
|
+
listing: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
89
|
+
status: z.ZodLiteral<"available">;
|
|
90
|
+
package: z.ZodObject<{
|
|
91
|
+
id: z.ZodString;
|
|
92
|
+
name: z.ZodString;
|
|
93
|
+
description: z.ZodOptional<z.ZodString>;
|
|
94
|
+
version: z.ZodString;
|
|
95
|
+
icon: z.ZodOptional<z.ZodString>;
|
|
96
|
+
runtime: z.ZodNumber;
|
|
97
|
+
bundle: z.ZodObject<{
|
|
98
|
+
url: z.ZodUnion<readonly [z.ZodURL, z.ZodString]>;
|
|
99
|
+
sha256: z.ZodString;
|
|
100
|
+
}, z.core.$strict>;
|
|
101
|
+
}, z.core.$strict>;
|
|
102
|
+
iconUrl: z.ZodNullable<z.ZodString>;
|
|
103
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
104
|
+
status: z.ZodLiteral<"unavailable">;
|
|
105
|
+
reason: z.ZodString;
|
|
106
|
+
}, z.core.$strip>], "status">;
|
|
107
|
+
}, z.core.$strip>>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
export type AppRepositoryList = z.infer<typeof AppRepositoryListSchema>;
|
|
110
|
+
/**
|
|
111
|
+
* Where an installed app stands: its bundle being downloaded (`installing`), its server starting
|
|
112
|
+
* or answering, stopped (being updated, or uninstalled), or failed (it can't be downloaded, or
|
|
113
|
+
* its server keeps exiting).
|
|
114
|
+
*/
|
|
115
|
+
export declare const INSTALLATION_STATES: readonly ['installing', 'starting', 'running', 'stopped', 'failed'];
|
|
116
|
+
export declare const InstallationStateSchema: z.ZodEnum<{
|
|
117
|
+
failed: "failed";
|
|
118
|
+
installing: "installing";
|
|
119
|
+
running: "running";
|
|
120
|
+
starting: "starting";
|
|
121
|
+
stopped: "stopped";
|
|
122
|
+
}>;
|
|
123
|
+
export type InstallationState = z.infer<typeof InstallationStateSchema>;
|
|
124
|
+
/** An app the core runs. */
|
|
125
|
+
export declare const InstallationSchema: z.ZodObject<{
|
|
126
|
+
appId: z.ZodString;
|
|
127
|
+
repositoryId: z.ZodNullable<z.ZodString>;
|
|
128
|
+
name: z.ZodString;
|
|
129
|
+
version: z.ZodString;
|
|
130
|
+
url: z.ZodString;
|
|
131
|
+
state: z.ZodEnum<{
|
|
132
|
+
failed: "failed";
|
|
133
|
+
installing: "installing";
|
|
134
|
+
running: "running";
|
|
135
|
+
starting: "starting";
|
|
136
|
+
stopped: "stopped";
|
|
137
|
+
}>;
|
|
138
|
+
error: z.ZodNullable<z.ZodString>;
|
|
139
|
+
enrolled: z.ZodBoolean;
|
|
140
|
+
installedAt: z.ZodISODateTime;
|
|
141
|
+
}, z.core.$strip>;
|
|
142
|
+
export type Installation = z.infer<typeof InstallationSchema>;
|
|
143
|
+
export declare const InstallationListSchema: z.ZodObject<{
|
|
144
|
+
installations: z.ZodArray<z.ZodObject<{
|
|
145
|
+
appId: z.ZodString;
|
|
146
|
+
repositoryId: z.ZodNullable<z.ZodString>;
|
|
147
|
+
name: z.ZodString;
|
|
148
|
+
version: z.ZodString;
|
|
149
|
+
url: z.ZodString;
|
|
150
|
+
state: z.ZodEnum<{
|
|
151
|
+
failed: "failed";
|
|
152
|
+
installing: "installing";
|
|
153
|
+
running: "running";
|
|
154
|
+
starting: "starting";
|
|
155
|
+
stopped: "stopped";
|
|
156
|
+
}>;
|
|
157
|
+
error: z.ZodNullable<z.ZodString>;
|
|
158
|
+
enrolled: z.ZodBoolean;
|
|
159
|
+
installedAt: z.ZodISODateTime;
|
|
160
|
+
}, z.core.$strip>>;
|
|
161
|
+
}, z.core.$strip>;
|
|
162
|
+
export type InstallationList = z.infer<typeof InstallationListSchema>;
|
|
163
|
+
export declare const InstallationRequestSchema: z.ZodObject<{
|
|
164
|
+
repositoryId: z.ZodString;
|
|
165
|
+
}, z.core.$strip>;
|
|
166
|
+
export type InstallationRequest = z.infer<typeof InstallationRequestSchema>;
|
|
167
|
+
export declare const UninstallQuerySchema: z.ZodObject<{
|
|
168
|
+
deleteData: z.ZodDefault<z.ZodCodec<z.ZodString, z.ZodBoolean>>;
|
|
169
|
+
}, z.core.$strip>;
|
|
170
|
+
/** The core's marketplace API (administrators). */
|
|
171
|
+
export declare const MARKETPLACE_API_PATHS: {
|
|
172
|
+
/** GET → `AppRepositoryList`; POST `AppRepositoryInput` → `AppRepository`. */
|
|
173
|
+
readonly repositories: '/api/marketplace/repositories';
|
|
174
|
+
/** DELETE → 204. */
|
|
175
|
+
readonly repository: '/api/marketplace/repositories/:repositoryId';
|
|
176
|
+
/** GET → `InstallationList`; POST `InstallationRequest` → `Installation` (202). */
|
|
177
|
+
readonly installations: '/api/marketplace/installations';
|
|
178
|
+
/**
|
|
179
|
+
* PUT → `Installation` (202): runs the repository's current version, or starts the installed
|
|
180
|
+
* one again; DELETE `?deleteData` → 204.
|
|
181
|
+
*/
|
|
182
|
+
readonly installation: '/api/marketplace/installations/:appId';
|
|
183
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { AppIdSchema } from './app-protocol.js';
|
|
3
|
+
import { WebUrlSchema } from './web-url.js';
|
|
4
|
+
/*
|
|
5
|
+
* The marketplace (docs/architecture/marketplace.md): administrators list the app repositories
|
|
6
|
+
* they trust; each describes its app in `APP_PACKAGE_FILE`, with the bundle to download. The core
|
|
7
|
+
* unpacks it, runs its server as a process of its own, serves it at `/apps/<id>`, and enrolls it.
|
|
8
|
+
*/
|
|
9
|
+
/** The file an app repository describes its app in, at its root (or the folder it names). */
|
|
10
|
+
export const APP_PACKAGE_FILE = 'artemis-app.json';
|
|
11
|
+
/**
|
|
12
|
+
* What the core gives the apps it runs, which their bundles count on: Node 26, and the native
|
|
13
|
+
* modules `better-sqlite3` and `sharp`, which a bundle leaves out (it can't ship binaries for every
|
|
14
|
+
* system). A package names the runtime it was built for; the core runs only its own.
|
|
15
|
+
*/
|
|
16
|
+
export const APP_RUNTIME = 1;
|
|
17
|
+
/**
|
|
18
|
+
* The server of a bundle, from its root. A bundle is laid out like an app's folder in this
|
|
19
|
+
* repository (`api/dist/server.mjs`, `api/drizzle/`, `web/dist/`...), so the defaults of the
|
|
20
|
+
* app's configuration find everything without being told.
|
|
21
|
+
*/
|
|
22
|
+
export const APP_BUNDLE_SERVER = 'api/dist/server.mjs';
|
|
23
|
+
/** Where the apps the core runs live, on its own host: `<core URL>/apps/<id>`. */
|
|
24
|
+
export const INSTALLED_APPS_PATH = '/apps';
|
|
25
|
+
/** The public URL of an app the core runs. */
|
|
26
|
+
export function installedAppUrl(coreUrl, appId) {
|
|
27
|
+
return `${new URL(coreUrl).origin}${INSTALLED_APPS_PATH}/${appId}`;
|
|
28
|
+
}
|
|
29
|
+
/** A relative path of the repository, from the package file's folder. */
|
|
30
|
+
const RepositoryPathSchema = z
|
|
31
|
+
.string()
|
|
32
|
+
.max(300)
|
|
33
|
+
.regex(/^(?!\/)[A-Za-z0-9._/-]+$/, 'Expected a relative path')
|
|
34
|
+
.refine((path) => !path.split('/').includes('..'), 'Expected no `..`');
|
|
35
|
+
/** The SHA-256 of a file, in lowercase hexadecimal. */
|
|
36
|
+
export const Sha256Schema = z.string().regex(/^[0-9a-f]{64}$/, 'Expected a SHA-256 in hexadecimal');
|
|
37
|
+
/**
|
|
38
|
+
* What an app repository says of its app (`APP_PACKAGE_FILE`): how it shows in the marketplace,
|
|
39
|
+
* and the bundle the core runs. Its server is an app of the platform (`@artemis-apps/app-server`),
|
|
40
|
+
* configured by `PORT`, `PUBLIC_URL`, `CORE_URL` and `CORE_INTERNAL_URL`, which the core sets; it
|
|
41
|
+
* runs in its own data folder.
|
|
42
|
+
*/
|
|
43
|
+
export const AppPackageSchema = z.strictObject({
|
|
44
|
+
id: AppIdSchema,
|
|
45
|
+
name: z.string().trim().min(1).max(60),
|
|
46
|
+
description: z.string().trim().max(280).optional(),
|
|
47
|
+
/** Shown to compare with what is installed; any text (`1.4.0`). */
|
|
48
|
+
version: z.string().trim().min(1).max(40),
|
|
49
|
+
/** The app's icon (SVG), a path of the repository. */
|
|
50
|
+
icon: RepositoryPathSchema.refine((path) => path.endsWith('.svg'), 'Expected an SVG file').optional(),
|
|
51
|
+
/** The runtime the bundle was built for (`APP_RUNTIME`). */
|
|
52
|
+
runtime: z.number().int().positive(),
|
|
53
|
+
/** A `.tar.gz` of the app's built files (`APP_BUNDLE_SERVER` and what it reads). */
|
|
54
|
+
bundle: z.strictObject({
|
|
55
|
+
/** An https URL, or a path of the repository. */
|
|
56
|
+
url: z.union([WebUrlSchema, RepositoryPathSchema]),
|
|
57
|
+
/** The bundle is refused unless it has this hash. */
|
|
58
|
+
sha256: Sha256Schema,
|
|
59
|
+
}),
|
|
60
|
+
});
|
|
61
|
+
export class InvalidRepositoryUrlError extends Error {
|
|
62
|
+
name = 'InvalidRepositoryUrlError';
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Where a repository's files are read: a GitHub repository (`https://github.com/owner/repo`,
|
|
66
|
+
* its default branch) or one of its folders (`…/tree/<ref>/<folder>`) is read from
|
|
67
|
+
* `raw.githubusercontent.com`; any other http(s) URL is the folder holding the files itself.
|
|
68
|
+
*/
|
|
69
|
+
export function repositoryFilesUrl(repositoryUrl) {
|
|
70
|
+
let url;
|
|
71
|
+
try {
|
|
72
|
+
url = new URL(repositoryUrl.trim());
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
throw new InvalidRepositoryUrlError('The repository URL is not a valid URL.');
|
|
76
|
+
}
|
|
77
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') {
|
|
78
|
+
throw new InvalidRepositoryUrlError('The repository URL must use https.');
|
|
79
|
+
}
|
|
80
|
+
if (url.username || url.password || url.search || url.hash) {
|
|
81
|
+
throw new InvalidRepositoryUrlError('The repository URL must be a plain address.');
|
|
82
|
+
}
|
|
83
|
+
const segments = url.pathname.split('/').filter(Boolean);
|
|
84
|
+
if (url.hostname === 'github.com') {
|
|
85
|
+
const [owner, repository, tree, ref, ...folder] = segments;
|
|
86
|
+
if (!owner || !repository || (tree !== undefined && (tree !== 'tree' || !ref))) {
|
|
87
|
+
throw new InvalidRepositoryUrlError('Expected https://github.com/<owner>/<repository>[/tree/<branch>/<folder>].');
|
|
88
|
+
}
|
|
89
|
+
const name = repository.replace(/\.git$/, '');
|
|
90
|
+
return `https://raw.githubusercontent.com/${[owner, name, ref ?? 'HEAD', ...folder].join('/')}/`;
|
|
91
|
+
}
|
|
92
|
+
return `${url.origin}/${segments.length ? `${segments.join('/')}/` : ''}`;
|
|
93
|
+
}
|
|
94
|
+
/** A file of the repository (a path from the package file's folder), or an absolute URL as is. */
|
|
95
|
+
export function repositoryFileUrl(repositoryUrl, path) {
|
|
96
|
+
return new URL(path, repositoryFilesUrl(repositoryUrl)).href;
|
|
97
|
+
}
|
|
98
|
+
export const AppRepositoryInputSchema = z.object({ url: WebUrlSchema });
|
|
99
|
+
/** A repository as the marketplace lists it, with what it offers now. */
|
|
100
|
+
export const AppRepositorySchema = z.object({
|
|
101
|
+
id: z.string(),
|
|
102
|
+
url: z.string(),
|
|
103
|
+
addedAt: z.iso.datetime(),
|
|
104
|
+
/** Its app, or why it could not be read (or can't run here). */
|
|
105
|
+
listing: z.discriminatedUnion('status', [
|
|
106
|
+
z.object({
|
|
107
|
+
status: z.literal('available'),
|
|
108
|
+
package: AppPackageSchema,
|
|
109
|
+
/** The icon, read from the repository. */
|
|
110
|
+
iconUrl: z.string().nullable(),
|
|
111
|
+
}),
|
|
112
|
+
z.object({ status: z.literal('unavailable'), reason: z.string() }),
|
|
113
|
+
]),
|
|
114
|
+
});
|
|
115
|
+
export const AppRepositoryListSchema = z.object({ repositories: z.array(AppRepositorySchema) });
|
|
116
|
+
/**
|
|
117
|
+
* Where an installed app stands: its bundle being downloaded (`installing`), its server starting
|
|
118
|
+
* or answering, stopped (being updated, or uninstalled), or failed (it can't be downloaded, or
|
|
119
|
+
* its server keeps exiting).
|
|
120
|
+
*/
|
|
121
|
+
export const INSTALLATION_STATES = [
|
|
122
|
+
'installing',
|
|
123
|
+
'starting',
|
|
124
|
+
'running',
|
|
125
|
+
'stopped',
|
|
126
|
+
'failed',
|
|
127
|
+
];
|
|
128
|
+
export const InstallationStateSchema = z.enum(INSTALLATION_STATES);
|
|
129
|
+
/** An app the core runs. */
|
|
130
|
+
export const InstallationSchema = z.object({
|
|
131
|
+
appId: AppIdSchema,
|
|
132
|
+
repositoryId: z.string().nullable(),
|
|
133
|
+
name: z.string(),
|
|
134
|
+
version: z.string(),
|
|
135
|
+
url: z.string(),
|
|
136
|
+
state: InstallationStateSchema,
|
|
137
|
+
/** Why it failed, when it did. */
|
|
138
|
+
error: z.string().nullable(),
|
|
139
|
+
/** Whether the app is enrolled: the core enrolls it once it runs, unless revoked since. */
|
|
140
|
+
enrolled: z.boolean(),
|
|
141
|
+
installedAt: z.iso.datetime(),
|
|
142
|
+
});
|
|
143
|
+
export const InstallationListSchema = z.object({ installations: z.array(InstallationSchema) });
|
|
144
|
+
export const InstallationRequestSchema = z.object({ repositoryId: z.string().min(1) });
|
|
145
|
+
export const UninstallQuerySchema = z.object({
|
|
146
|
+
/** Also delete the app's data folder and its files on the core: nothing of it stays. */
|
|
147
|
+
deleteData: z.stringbool().default(false),
|
|
148
|
+
});
|
|
149
|
+
/** The core's marketplace API (administrators). */
|
|
150
|
+
export const MARKETPLACE_API_PATHS = {
|
|
151
|
+
/** GET → `AppRepositoryList`; POST `AppRepositoryInput` → `AppRepository`. */
|
|
152
|
+
repositories: '/api/marketplace/repositories',
|
|
153
|
+
/** DELETE → 204. */
|
|
154
|
+
repository: '/api/marketplace/repositories/:repositoryId',
|
|
155
|
+
/** GET → `InstallationList`; POST `InstallationRequest` → `Installation` (202). */
|
|
156
|
+
installations: '/api/marketplace/installations',
|
|
157
|
+
/**
|
|
158
|
+
* PUT → `Installation` (202): runs the repository's current version, or starts the installed
|
|
159
|
+
* one again; DELETE `?deleteData` → 204.
|
|
160
|
+
*/
|
|
161
|
+
installation: '/api/marketplace/installations/:appId',
|
|
162
|
+
};
|
package/dist/oidc.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* OpenID Connect profile of the core. Protocol mechanics belong to `oidc-provider` (core)
|
|
4
|
+
* and `openid-client` (apps); this file only fixes what both sides must agree on.
|
|
5
|
+
*/
|
|
6
|
+
/** Scope every app requests in addition to its permissions. */
|
|
7
|
+
export declare const OPENID_SCOPE = "openid";
|
|
8
|
+
/**
|
|
9
|
+
* Claims identifying the signed-in account, always present in ID tokens.
|
|
10
|
+
* The avatar travels as `picture` (standard claim: public URL of an uploaded image) or
|
|
11
|
+
* `avatar_seed` (seed of a generated avatar); exactly one of them is set.
|
|
12
|
+
*/
|
|
13
|
+
/** The ID token claim saying the account administers the platform's apps. */
|
|
14
|
+
export declare const APP_ADMINISTRATOR_CLAIM = "artemis_app_administrator";
|
|
15
|
+
export declare const AccountClaimsSchema: z.ZodObject<{
|
|
16
|
+
sub: z.ZodUUID;
|
|
17
|
+
email: z.ZodEmail;
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
picture: z.ZodOptional<z.ZodURL>;
|
|
20
|
+
avatar_seed: z.ZodOptional<z.ZodUUID>;
|
|
21
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
22
|
+
artemis_app_administrator: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
}, z.core.$strip>;
|
|
24
|
+
export type AccountClaims = z.infer<typeof AccountClaimsSchema>;
|
|
25
|
+
export declare const ACCOUNT_CLAIM_NAMES: readonly ['email', 'name', 'picture', 'avatar_seed', 'locale', "artemis_app_administrator"];
|
package/dist/oidc.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* OpenID Connect profile of the core. Protocol mechanics belong to `oidc-provider` (core)
|
|
4
|
+
* and `openid-client` (apps); this file only fixes what both sides must agree on.
|
|
5
|
+
*/
|
|
6
|
+
/** Scope every app requests in addition to its permissions. */
|
|
7
|
+
export const OPENID_SCOPE = 'openid';
|
|
8
|
+
/**
|
|
9
|
+
* Claims identifying the signed-in account, always present in ID tokens.
|
|
10
|
+
* The avatar travels as `picture` (standard claim: public URL of an uploaded image) or
|
|
11
|
+
* `avatar_seed` (seed of a generated avatar); exactly one of them is set.
|
|
12
|
+
*/
|
|
13
|
+
/** The ID token claim saying the account administers the platform's apps. */
|
|
14
|
+
export const APP_ADMINISTRATOR_CLAIM = 'artemis_app_administrator';
|
|
15
|
+
export const AccountClaimsSchema = z.object({
|
|
16
|
+
sub: z.uuidv4(),
|
|
17
|
+
email: z.email(),
|
|
18
|
+
name: z.string().min(1),
|
|
19
|
+
picture: z.url().optional(),
|
|
20
|
+
avatar_seed: z.uuidv4().optional(),
|
|
21
|
+
/** The account's language (`AccountPreferences`): a standard OIDC claim. */
|
|
22
|
+
locale: z.string().optional(),
|
|
23
|
+
/**
|
|
24
|
+
* Whether the account administers the platform's apps (it holds `admin:apps:write` in the
|
|
25
|
+
* core). Not a permission granted to the app: what the app lets it configure about itself.
|
|
26
|
+
*/
|
|
27
|
+
[APP_ADMINISTRATOR_CLAIM]: z.boolean().optional(),
|
|
28
|
+
});
|
|
29
|
+
export const ACCOUNT_CLAIM_NAMES = [
|
|
30
|
+
'email',
|
|
31
|
+
'name',
|
|
32
|
+
'picture',
|
|
33
|
+
'avatar_seed',
|
|
34
|
+
'locale',
|
|
35
|
+
APP_ADMINISTRATOR_CLAIM,
|
|
36
|
+
];
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The core's own permissions. */
|
|
3
|
+
export declare const CORE_PERMISSIONS: readonly ['account:read', 'account:write', 'admin:accounts:read', 'admin:accounts:write', 'admin:apps:read', 'admin:apps:write', 'admin:logs:read', 'directory:read'];
|
|
4
|
+
export type CorePermission = (typeof CORE_PERMISSIONS)[number];
|
|
5
|
+
export declare const CorePermissionSchema: z.ZodEnum<{
|
|
6
|
+
"account:read": "account:read";
|
|
7
|
+
"account:write": "account:write";
|
|
8
|
+
"admin:accounts:read": "admin:accounts:read";
|
|
9
|
+
"admin:accounts:write": "admin:accounts:write";
|
|
10
|
+
"admin:apps:read": "admin:apps:read";
|
|
11
|
+
"admin:apps:write": "admin:apps:write";
|
|
12
|
+
"admin:logs:read": "admin:logs:read";
|
|
13
|
+
"directory:read": "directory:read";
|
|
14
|
+
}>;
|
|
15
|
+
/** Namespace of platform administration. Only ever granted to accounts, never to apps. */
|
|
16
|
+
export declare const ADMIN_NAMESPACE = "admin";
|
|
17
|
+
export type AdminPermission = Extract<CorePermission, `${typeof ADMIN_NAMESPACE}:${string}`>;
|
|
18
|
+
/** Core permissions an app may request and receive. */
|
|
19
|
+
export type DelegableCorePermission = Exclude<CorePermission, AdminPermission>;
|
|
20
|
+
/** A permission on an entity type: `<namespace>.<name>:<permission>`. */
|
|
21
|
+
export type TypePermission = `${string}.${string}:${string}`;
|
|
22
|
+
/** Anything an app may request in its manifest and receive in its tokens. */
|
|
23
|
+
export type DelegablePermission = DelegableCorePermission | TypePermission;
|
|
24
|
+
export type Permission = CorePermission | TypePermission;
|
|
25
|
+
/** `<namespace>.<name>`: an entity type id. */
|
|
26
|
+
export declare const ENTITY_TYPE_ID_PATTERN: RegExp;
|
|
27
|
+
/** A permission or operation name within a type. */
|
|
28
|
+
export declare const ENTITY_TYPE_NAME_PATTERN: RegExp;
|
|
29
|
+
export declare function isAdminPermission(permission: string): permission is AdminPermission;
|
|
30
|
+
export declare function isCorePermission(value: string): value is CorePermission;
|
|
31
|
+
export declare function isTypePermission(value: string): value is TypePermission;
|
|
32
|
+
export declare function isPermission(value: string): value is Permission;
|
|
33
|
+
export declare function isDelegablePermission(value: string): value is DelegablePermission;
|
|
34
|
+
export declare const TypePermissionSchema: z.ZodType<TypePermission, string>;
|
|
35
|
+
/** The delegable core permissions. */
|
|
36
|
+
export declare const DELEGABLE_CORE_PERMISSIONS: readonly DelegableCorePermission[];
|
|
37
|
+
export declare const DelegablePermissionSchema: z.ZodType<DelegablePermission, string>;
|
|
38
|
+
export declare const PermissionSchema: z.ZodType<Permission, string>;
|
|
39
|
+
/** Platform administration: the only permissions granted account by account, by an administrator. */
|
|
40
|
+
export declare const ADMIN_PERMISSIONS: readonly AdminPermission[];
|
|
41
|
+
export declare const AdminPermissionSchema: z.ZodEnum<{
|
|
42
|
+
"admin:accounts:read": "admin:accounts:read";
|
|
43
|
+
"admin:accounts:write": "admin:accounts:write";
|
|
44
|
+
"admin:apps:read": "admin:apps:read";
|
|
45
|
+
"admin:apps:write": "admin:apps:write";
|
|
46
|
+
"admin:logs:read": "admin:logs:read";
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* Whether an account holds a permission without anyone granting it: its own profile, the
|
|
50
|
+
* directory, and every permission of every type over its own entities. Only administration is
|
|
51
|
+
* granted; which entities of others it reaches is up to sharing.
|
|
52
|
+
*/
|
|
53
|
+
export declare function isBaseAccountPermission(permission: string): boolean;
|
|
54
|
+
/** A type permission: the entity type and the permission within it. */
|
|
55
|
+
export declare function typePermission(type: string, permission: string): TypePermission;
|
|
56
|
+
/** Splits a type permission (`calendar.event:write` → `calendar.event`, `write`). */
|
|
57
|
+
export declare function parseTypePermission(permission: TypePermission): {
|
|
58
|
+
type: string;
|
|
59
|
+
permission: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* The namespace a permission belongs to: a core namespace (`account`, `admin`, `directory`), or
|
|
63
|
+
* the namespace of a type (`calendar` for `calendar.event:write`).
|
|
64
|
+
*/
|
|
65
|
+
export declare function permissionNamespace(permission: Permission): string;
|
|
66
|
+
/** Parses an OAuth `scope` string. Unknown values are dropped, duplicates removed. */
|
|
67
|
+
export declare function parseScope(scope: string | null | undefined): Permission[];
|
|
68
|
+
export declare function formatScope(permissions: readonly string[]): string;
|
|
69
|
+
export declare function hasPermissions(granted: readonly string[], required: readonly string[]): boolean;
|
|
70
|
+
export declare function intersectPermissions<T extends string>(left: readonly T[], right: readonly string[]): T[];
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/*
|
|
3
|
+
* Permissions, which double as OAuth scopes. Two kinds:
|
|
4
|
+
* - core permissions, `<namespace>:<resource>:<action>` or `<namespace>:<action>`: the core's own
|
|
5
|
+
* (accounts, administration, the directory), listed below;
|
|
6
|
+
* - type permissions, `<type>:<permission>` (`calendar.event:write`): declared by the entity
|
|
7
|
+
* types apps bring (see `entity-types.ts`), unknown to the core until an app declares them.
|
|
8
|
+
*
|
|
9
|
+
* Non-admin permissions are relative to the connected account. They never name one entity:
|
|
10
|
+
* which entities of others an account reaches is decided by sharing.
|
|
11
|
+
*/
|
|
12
|
+
/** The core's own permissions. */
|
|
13
|
+
export const CORE_PERMISSIONS = [
|
|
14
|
+
'account:read',
|
|
15
|
+
'account:write',
|
|
16
|
+
'admin:accounts:read',
|
|
17
|
+
'admin:accounts:write',
|
|
18
|
+
'admin:apps:read',
|
|
19
|
+
'admin:apps:write',
|
|
20
|
+
'admin:logs:read',
|
|
21
|
+
'directory:read',
|
|
22
|
+
];
|
|
23
|
+
export const CorePermissionSchema = z.enum(CORE_PERMISSIONS);
|
|
24
|
+
/** Namespace of platform administration. Only ever granted to accounts, never to apps. */
|
|
25
|
+
export const ADMIN_NAMESPACE = 'admin';
|
|
26
|
+
const SEGMENT = '[a-z][a-z0-9-]*';
|
|
27
|
+
/** `<namespace>.<name>`: an entity type id. */
|
|
28
|
+
export const ENTITY_TYPE_ID_PATTERN = new RegExp(`^${SEGMENT}\\.${SEGMENT}$`);
|
|
29
|
+
/** A permission or operation name within a type. */
|
|
30
|
+
export const ENTITY_TYPE_NAME_PATTERN = new RegExp(`^${SEGMENT}$`);
|
|
31
|
+
const TYPE_PERMISSION_PATTERN = new RegExp(`^${SEGMENT}\\.${SEGMENT}:${SEGMENT}$`);
|
|
32
|
+
export function isAdminPermission(permission) {
|
|
33
|
+
return permission.startsWith(`${ADMIN_NAMESPACE}:`);
|
|
34
|
+
}
|
|
35
|
+
export function isCorePermission(value) {
|
|
36
|
+
return CORE_PERMISSIONS.includes(value);
|
|
37
|
+
}
|
|
38
|
+
export function isTypePermission(value) {
|
|
39
|
+
return value.length <= 120 && TYPE_PERMISSION_PATTERN.test(value);
|
|
40
|
+
}
|
|
41
|
+
export function isPermission(value) {
|
|
42
|
+
return isCorePermission(value) || isTypePermission(value);
|
|
43
|
+
}
|
|
44
|
+
export function isDelegablePermission(value) {
|
|
45
|
+
return isPermission(value) && !isAdminPermission(value);
|
|
46
|
+
}
|
|
47
|
+
export const TypePermissionSchema = z.string().refine(isTypePermission, {
|
|
48
|
+
message: 'Expected `<namespace>.<name>:<permission>` in lowercase kebab-case',
|
|
49
|
+
});
|
|
50
|
+
/** The delegable core permissions. */
|
|
51
|
+
export const DELEGABLE_CORE_PERMISSIONS = CORE_PERMISSIONS.filter((permission) => !isAdminPermission(permission));
|
|
52
|
+
export const DelegablePermissionSchema = z.string().refine(isDelegablePermission, {
|
|
53
|
+
message: 'Expected a delegable core permission or a type permission',
|
|
54
|
+
});
|
|
55
|
+
export const PermissionSchema = z.string().refine(isPermission, {
|
|
56
|
+
message: 'Expected a core permission or a type permission',
|
|
57
|
+
});
|
|
58
|
+
/** Platform administration: the only permissions granted account by account, by an administrator. */
|
|
59
|
+
export const ADMIN_PERMISSIONS = CORE_PERMISSIONS.filter((permission) => isAdminPermission(permission));
|
|
60
|
+
export const AdminPermissionSchema = z.enum(ADMIN_PERMISSIONS);
|
|
61
|
+
/**
|
|
62
|
+
* Whether an account holds a permission without anyone granting it: its own profile, the
|
|
63
|
+
* directory, and every permission of every type over its own entities. Only administration is
|
|
64
|
+
* granted; which entities of others it reaches is up to sharing.
|
|
65
|
+
*/
|
|
66
|
+
export function isBaseAccountPermission(permission) {
|
|
67
|
+
return isDelegablePermission(permission);
|
|
68
|
+
}
|
|
69
|
+
/** A type permission: the entity type and the permission within it. */
|
|
70
|
+
export function typePermission(type, permission) {
|
|
71
|
+
return `${type}:${permission}`;
|
|
72
|
+
}
|
|
73
|
+
/** Splits a type permission (`calendar.event:write` → `calendar.event`, `write`). */
|
|
74
|
+
export function parseTypePermission(permission) {
|
|
75
|
+
const separator = permission.lastIndexOf(':');
|
|
76
|
+
return { type: permission.slice(0, separator), permission: permission.slice(separator + 1) };
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The namespace a permission belongs to: a core namespace (`account`, `admin`, `directory`), or
|
|
80
|
+
* the namespace of a type (`calendar` for `calendar.event:write`).
|
|
81
|
+
*/
|
|
82
|
+
export function permissionNamespace(permission) {
|
|
83
|
+
const end = isTypePermission(permission) ? permission.indexOf('.') : permission.indexOf(':');
|
|
84
|
+
return permission.slice(0, end);
|
|
85
|
+
}
|
|
86
|
+
const SCOPE_SEPARATOR = ' ';
|
|
87
|
+
/** Parses an OAuth `scope` string. Unknown values are dropped, duplicates removed. */
|
|
88
|
+
export function parseScope(scope) {
|
|
89
|
+
if (!scope)
|
|
90
|
+
return [];
|
|
91
|
+
return [...new Set(scope.split(SCOPE_SEPARATOR).filter(isPermission))];
|
|
92
|
+
}
|
|
93
|
+
export function formatScope(permissions) {
|
|
94
|
+
return [...new Set(permissions)].join(SCOPE_SEPARATOR);
|
|
95
|
+
}
|
|
96
|
+
export function hasPermissions(granted, required) {
|
|
97
|
+
return required.every((permission) => granted.includes(permission));
|
|
98
|
+
}
|
|
99
|
+
export function intersectPermissions(left, right) {
|
|
100
|
+
return left.filter((permission) => right.includes(permission));
|
|
101
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The languages of the platform. Texts missing in one fall back to English. */
|
|
3
|
+
export declare const LOCALES: readonly ['en', 'fr'];
|
|
4
|
+
export declare const LocaleSchema: z.ZodEnum<{
|
|
5
|
+
en: "en";
|
|
6
|
+
fr: "fr";
|
|
7
|
+
}>;
|
|
8
|
+
export type Locale = z.infer<typeof LocaleSchema>;
|
|
9
|
+
/** A new account's language, and every text's fallback. */
|
|
10
|
+
export declare const DEFAULT_LOCALE: Locale;
|
|
11
|
+
export declare function isLocale(value: unknown): value is Locale;
|
|
12
|
+
/**
|
|
13
|
+
* How an account wants the platform to look and speak, in every app. Apps receive them in the
|
|
14
|
+
* account's ID token claims (`locale`), refreshed with it.
|
|
15
|
+
*/
|
|
16
|
+
export declare const AccountPreferencesSchema: z.ZodObject<{
|
|
17
|
+
locale: z.ZodEnum<{
|
|
18
|
+
en: "en";
|
|
19
|
+
fr: "fr";
|
|
20
|
+
}>;
|
|
21
|
+
}, z.core.$strip>;
|
|
22
|
+
export type AccountPreferences = z.infer<typeof AccountPreferencesSchema>;
|
|
23
|
+
/** PATCH on the current account's preferences: what changes. */
|
|
24
|
+
export declare const AccountPreferencesUpdateSchema: z.ZodObject<{
|
|
25
|
+
locale: z.ZodOptional<z.ZodEnum<{
|
|
26
|
+
en: "en";
|
|
27
|
+
fr: "fr";
|
|
28
|
+
}>>;
|
|
29
|
+
}, z.core.$strip>;
|
|
30
|
+
export type AccountPreferencesUpdate = z.infer<typeof AccountPreferencesUpdateSchema>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** The languages of the platform. Texts missing in one fall back to English. */
|
|
3
|
+
export const LOCALES = ['en', 'fr'];
|
|
4
|
+
export const LocaleSchema = z.enum(LOCALES);
|
|
5
|
+
/** A new account's language, and every text's fallback. */
|
|
6
|
+
export const DEFAULT_LOCALE = 'en';
|
|
7
|
+
export function isLocale(value) {
|
|
8
|
+
return LOCALES.includes(value);
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* How an account wants the platform to look and speak, in every app. Apps receive them in the
|
|
12
|
+
* account's ID token claims (`locale`), refreshed with it.
|
|
13
|
+
*/
|
|
14
|
+
export const AccountPreferencesSchema = z.object({
|
|
15
|
+
locale: LocaleSchema,
|
|
16
|
+
});
|
|
17
|
+
/** PATCH on the current account's preferences: what changes. */
|
|
18
|
+
export const AccountPreferencesUpdateSchema = AccountPreferencesSchema.partial();
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Query parameter carrying the path to come back to after a redirect-based flow. */
|
|
2
|
+
export declare const RETURN_TO_PARAM = "return_to";
|
|
3
|
+
/**
|
|
4
|
+
* Keeps only same-origin relative paths, preventing open redirects.
|
|
5
|
+
* Returns `fallback` for absolute URLs, protocol-relative URLs or garbage.
|
|
6
|
+
*/
|
|
7
|
+
export declare function sanitizeReturnPath(value: string | null | undefined, fallback?: string): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/** Query parameter carrying the path to come back to after a redirect-based flow. */
|
|
2
|
+
export const RETURN_TO_PARAM = 'return_to';
|
|
3
|
+
const PLACEHOLDER_ORIGIN = 'http://return-path.invalid';
|
|
4
|
+
/**
|
|
5
|
+
* Keeps only same-origin relative paths, preventing open redirects.
|
|
6
|
+
* Returns `fallback` for absolute URLs, protocol-relative URLs or garbage.
|
|
7
|
+
*/
|
|
8
|
+
export function sanitizeReturnPath(value, fallback = '/') {
|
|
9
|
+
if (!value?.startsWith('/') || value.startsWith('//') || value.startsWith('/\\')) {
|
|
10
|
+
return fallback;
|
|
11
|
+
}
|
|
12
|
+
try {
|
|
13
|
+
const url = new URL(value, PLACEHOLDER_ORIGIN);
|
|
14
|
+
if (url.origin !== PLACEHOLDER_ORIGIN)
|
|
15
|
+
return fallback;
|
|
16
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return fallback;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
type PathParameterNames<Pattern extends string> = Pattern extends `${string}:${infer Name}/${infer Rest}` ? Name | PathParameterNames<`/${Rest}`> : Pattern extends `${string}:${infer Name}` ? Name : never;
|
|
2
|
+
export type PathParameters<Pattern extends string> = Record<PathParameterNames<Pattern>, string>;
|
|
3
|
+
/** Turns a route pattern (`/api/apps/:appId`) into a concrete, encoded path. */
|
|
4
|
+
export declare function fillPath<Pattern extends string>(pattern: Pattern, parameters: PathParameters<Pattern>): string;
|
|
5
|
+
export {};
|