cauthy-auth 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/{cauthy-BrIMaoj1.d.mts → cauthy--iqtLWNa.d.ts} +7 -1
- package/dist/{cauthy-CCZc9w8r.d.ts → cauthy-Dg-DNIo9.d.mts} +7 -1
- package/dist/cli.js +129 -4
- package/dist/fastify.d.mts +3 -2
- package/dist/fastify.d.ts +3 -2
- package/dist/index.d.mts +47 -3
- package/dist/index.d.ts +47 -3
- package/dist/index.js +495 -244
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +489 -241
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +4 -2
- package/dist/react.d.ts +4 -2
- package/dist/system-CL3Q30FT.d.ts +243 -0
- package/dist/system-CdvktS7x.d.mts +243 -0
- package/dist/theme.d.mts +16 -3
- package/dist/theme.d.ts +16 -3
- package/dist/theme.js +32 -2
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +31 -2
- package/dist/theme.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/types-CYmUVWzY.d.mts +0 -106
- package/dist/types-CYmUVWzY.d.ts +0 -106
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { JWK } from 'jose';
|
|
2
|
+
import { CauthyTheme } from './theme.js';
|
|
3
|
+
|
|
4
|
+
/** How an application is set up to sign its people in with Cauthy. */
|
|
5
|
+
interface CauthyOptions {
|
|
6
|
+
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
7
|
+
issuer?: string;
|
|
8
|
+
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
9
|
+
clientId?: string;
|
|
10
|
+
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
11
|
+
clientSecret?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The key the session cookie is encrypted with: any string of 32 characters
|
|
14
|
+
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
15
|
+
*/
|
|
16
|
+
secret?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The system this application is, as its organizations are filed under in
|
|
19
|
+
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
20
|
+
* system's. Default: `CAUTHY_SYSTEM`.
|
|
21
|
+
*/
|
|
22
|
+
system?: string;
|
|
23
|
+
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
24
|
+
basePath?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The application's own public origin (`https://app.example.com`), for the
|
|
27
|
+
* redirect URI. Default: the origin of each request, which is right unless
|
|
28
|
+
* a proxy hides it.
|
|
29
|
+
*/
|
|
30
|
+
baseURL?: string;
|
|
31
|
+
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
32
|
+
afterSignIn?: string;
|
|
33
|
+
/** Where a person lands after signing out. Default: `/`. */
|
|
34
|
+
afterSignOut?: string;
|
|
35
|
+
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
36
|
+
cookieName?: string;
|
|
37
|
+
/**
|
|
38
|
+
* A key the application proves who it is with when it acts on its own
|
|
39
|
+
* (`auth.system`), instead of its secret. Default: `CAUTHY_SYSTEM_KEY` and
|
|
40
|
+
* `CAUTHY_SYSTEM_KEY_ID`.
|
|
41
|
+
*/
|
|
42
|
+
systemKey?: SystemKey;
|
|
43
|
+
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
44
|
+
fetch?: typeof fetch;
|
|
45
|
+
}
|
|
46
|
+
/** The person signed in. Every moment is UTC. */
|
|
47
|
+
interface SessionUser {
|
|
48
|
+
id: string;
|
|
49
|
+
email: string;
|
|
50
|
+
name: string;
|
|
51
|
+
emailVerified: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* True when the account ran out of time to confirm its address: let it read
|
|
54
|
+
* and refuse its writes.
|
|
55
|
+
*/
|
|
56
|
+
restricted: boolean;
|
|
57
|
+
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
58
|
+
emailVerifyBy?: string;
|
|
59
|
+
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
60
|
+
locale?: string;
|
|
61
|
+
}
|
|
62
|
+
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
63
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
64
|
+
[key: string]: JsonValue;
|
|
65
|
+
};
|
|
66
|
+
/** An organization the person belongs to, with their role in it. */
|
|
67
|
+
interface SessionOrganization {
|
|
68
|
+
id: string;
|
|
69
|
+
system: string;
|
|
70
|
+
name: string;
|
|
71
|
+
kind: string;
|
|
72
|
+
externalId?: string;
|
|
73
|
+
role: string;
|
|
74
|
+
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
75
|
+
metadata: Record<string, JsonValue>;
|
|
76
|
+
/**
|
|
77
|
+
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
78
|
+
* their role's permissions, what it inherits, and anything given to them
|
|
79
|
+
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
80
|
+
* Check with `can(organization, resource, action)`.
|
|
81
|
+
*/
|
|
82
|
+
permissions?: string[];
|
|
83
|
+
/** What the person is denied here, whatever else allows it. */
|
|
84
|
+
denied?: string[];
|
|
85
|
+
}
|
|
86
|
+
/** A signed-in person, as the server sees them. */
|
|
87
|
+
interface Session {
|
|
88
|
+
user: SessionUser;
|
|
89
|
+
/** The Cauthy tenant the account is of. */
|
|
90
|
+
tenantId: string;
|
|
91
|
+
/** The roles the account holds in that tenant. */
|
|
92
|
+
roles: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
95
|
+
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
96
|
+
*/
|
|
97
|
+
accessToken: string;
|
|
98
|
+
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
99
|
+
expiresAt: string;
|
|
100
|
+
}
|
|
101
|
+
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
102
|
+
interface PublicSession {
|
|
103
|
+
user: SessionUser;
|
|
104
|
+
tenantId: string;
|
|
105
|
+
roles: string[];
|
|
106
|
+
organizations: SessionOrganization[];
|
|
107
|
+
expiresAt: string;
|
|
108
|
+
}
|
|
109
|
+
/** Why there is no session. */
|
|
110
|
+
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
111
|
+
declare class CauthyConfigError extends Error {
|
|
112
|
+
constructor(message: string);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The key an application signs its assertions with. */
|
|
116
|
+
interface SystemKey {
|
|
117
|
+
/** The private key: PKCS#8 PEM, or a JWK (as an object or its JSON). RSA, for RS256. */
|
|
118
|
+
privateKey: string | JWK;
|
|
119
|
+
/** The id the public key is published under (`kid`). */
|
|
120
|
+
keyId: string;
|
|
121
|
+
}
|
|
122
|
+
interface SystemOptions {
|
|
123
|
+
/** Cauthy's address. Default: `CAUTHY_ISSUER`. */
|
|
124
|
+
issuer?: string;
|
|
125
|
+
/** The application's client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
126
|
+
clientId?: string;
|
|
127
|
+
/** Its secret. Default: `CAUTHY_CLIENT_SECRET`. Not needed with `key`. */
|
|
128
|
+
clientSecret?: string;
|
|
129
|
+
/**
|
|
130
|
+
* The key to prove who the application is with, instead of the secret.
|
|
131
|
+
* Default: `CAUTHY_SYSTEM_KEY` (the private key) and `CAUTHY_SYSTEM_KEY_ID`.
|
|
132
|
+
*/
|
|
133
|
+
key?: SystemKey;
|
|
134
|
+
fetch?: typeof fetch;
|
|
135
|
+
}
|
|
136
|
+
/** Cauthy refused a request of the application's own. */
|
|
137
|
+
declare class CauthyApiError extends Error {
|
|
138
|
+
readonly status: number;
|
|
139
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
140
|
+
readonly code: string;
|
|
141
|
+
constructor(status: number,
|
|
142
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
143
|
+
code: string, message: string);
|
|
144
|
+
}
|
|
145
|
+
/** An organization of the application's system. Every moment is UTC. */
|
|
146
|
+
interface Organization {
|
|
147
|
+
id: string;
|
|
148
|
+
system: string;
|
|
149
|
+
name: string;
|
|
150
|
+
kind: string;
|
|
151
|
+
/** The id the application knows it by. */
|
|
152
|
+
externalId?: string;
|
|
153
|
+
status: 'active' | 'archived';
|
|
154
|
+
metadata: Record<string, JsonValue>;
|
|
155
|
+
members: number;
|
|
156
|
+
createdAt: string;
|
|
157
|
+
updatedAt: string;
|
|
158
|
+
}
|
|
159
|
+
interface OrganizationMember {
|
|
160
|
+
userId: string;
|
|
161
|
+
email: string;
|
|
162
|
+
name: string;
|
|
163
|
+
/** The account's status: a disabled member is still listed. */
|
|
164
|
+
status: string;
|
|
165
|
+
role: string;
|
|
166
|
+
/** True when the address had no account: one was made and invited. */
|
|
167
|
+
invited?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/** Who to add: an account by its id, or anybody by their address (invited when new). */
|
|
170
|
+
type NewMember = {
|
|
171
|
+
role: string;
|
|
172
|
+
name?: string;
|
|
173
|
+
locale?: string;
|
|
174
|
+
} & ({
|
|
175
|
+
userId: string;
|
|
176
|
+
email?: undefined;
|
|
177
|
+
} | {
|
|
178
|
+
email: string;
|
|
179
|
+
userId?: undefined;
|
|
180
|
+
});
|
|
181
|
+
interface CauthySystem {
|
|
182
|
+
/** The application's own token, asked for when needed and kept until it is about to run out. */
|
|
183
|
+
token(): Promise<string>;
|
|
184
|
+
/** Any route the application's token may call; answers what Cauthy put under `data`. */
|
|
185
|
+
request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
|
|
186
|
+
organizations: {
|
|
187
|
+
list(query?: {
|
|
188
|
+
q?: string;
|
|
189
|
+
status?: 'active' | 'archived';
|
|
190
|
+
limit?: number;
|
|
191
|
+
offset?: number;
|
|
192
|
+
}): Promise<{
|
|
193
|
+
items: Organization[];
|
|
194
|
+
total: number;
|
|
195
|
+
}>;
|
|
196
|
+
create(input: {
|
|
197
|
+
name: string;
|
|
198
|
+
kind?: string;
|
|
199
|
+
externalId?: string;
|
|
200
|
+
metadata?: Record<string, JsonValue>;
|
|
201
|
+
}): Promise<Organization>;
|
|
202
|
+
get(id: string): Promise<Organization>;
|
|
203
|
+
update(id: string, patch: {
|
|
204
|
+
name?: string;
|
|
205
|
+
kind?: string;
|
|
206
|
+
status?: 'active' | 'archived';
|
|
207
|
+
metadata?: Record<string, JsonValue>;
|
|
208
|
+
}): Promise<Organization>;
|
|
209
|
+
/** Removes the organization and every membership of it, for good. */
|
|
210
|
+
remove(id: string): Promise<void>;
|
|
211
|
+
};
|
|
212
|
+
members: {
|
|
213
|
+
list(organizationId: string): Promise<OrganizationMember[]>;
|
|
214
|
+
add(organizationId: string, member: NewMember): Promise<OrganizationMember>;
|
|
215
|
+
setRole(organizationId: string, userId: string, role: string): Promise<OrganizationMember>;
|
|
216
|
+
remove(organizationId: string, userId: string): Promise<void>;
|
|
217
|
+
};
|
|
218
|
+
/** Invites a person who has no account yet; answers the account made for them. */
|
|
219
|
+
invite(person: {
|
|
220
|
+
email: string;
|
|
221
|
+
name?: string;
|
|
222
|
+
locale?: string;
|
|
223
|
+
}): Promise<{
|
|
224
|
+
id: string;
|
|
225
|
+
email: string;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* How the application looks on Cauthy's pages: read it, set it, or take it
|
|
229
|
+
* back to Cauthy's own with `null`. Of its own sign-in client — this one,
|
|
230
|
+
* unless another is named (a system whose identity is a separate client).
|
|
231
|
+
*/
|
|
232
|
+
theme: {
|
|
233
|
+
get(clientId?: string): Promise<CauthyTheme>;
|
|
234
|
+
set(theme: CauthyTheme | null, clientId?: string): Promise<void>;
|
|
235
|
+
};
|
|
236
|
+
/** The public half of `key`, to serve at the address Cauthy was given (`jwks_uri`). Empty with a secret. */
|
|
237
|
+
publicJwks(): Promise<{
|
|
238
|
+
keys: JWK[];
|
|
239
|
+
}>;
|
|
240
|
+
}
|
|
241
|
+
declare function createSystem(given?: SystemOptions): CauthySystem;
|
|
242
|
+
|
|
243
|
+
export { CauthyApiError as C, type JsonValue as J, type NewMember as N, type Organization as O, type PublicSession as P, type Session as S, CauthyConfigError as a, type CauthyOptions as b, type CauthySystem as c, type OrganizationMember as d, type SessionOrganization as e, type SessionStatus as f, type SessionUser as g, type SystemKey as h, type SystemOptions as i, createSystem as j };
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { JWK } from 'jose';
|
|
2
|
+
import { CauthyTheme } from './theme.mjs';
|
|
3
|
+
|
|
4
|
+
/** How an application is set up to sign its people in with Cauthy. */
|
|
5
|
+
interface CauthyOptions {
|
|
6
|
+
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
7
|
+
issuer?: string;
|
|
8
|
+
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
9
|
+
clientId?: string;
|
|
10
|
+
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
11
|
+
clientSecret?: string;
|
|
12
|
+
/**
|
|
13
|
+
* The key the session cookie is encrypted with: any string of 32 characters
|
|
14
|
+
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
15
|
+
*/
|
|
16
|
+
secret?: string;
|
|
17
|
+
/**
|
|
18
|
+
* The system this application is, as its organizations are filed under in
|
|
19
|
+
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
20
|
+
* system's. Default: `CAUTHY_SYSTEM`.
|
|
21
|
+
*/
|
|
22
|
+
system?: string;
|
|
23
|
+
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
24
|
+
basePath?: string;
|
|
25
|
+
/**
|
|
26
|
+
* The application's own public origin (`https://app.example.com`), for the
|
|
27
|
+
* redirect URI. Default: the origin of each request, which is right unless
|
|
28
|
+
* a proxy hides it.
|
|
29
|
+
*/
|
|
30
|
+
baseURL?: string;
|
|
31
|
+
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
32
|
+
afterSignIn?: string;
|
|
33
|
+
/** Where a person lands after signing out. Default: `/`. */
|
|
34
|
+
afterSignOut?: string;
|
|
35
|
+
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
36
|
+
cookieName?: string;
|
|
37
|
+
/**
|
|
38
|
+
* A key the application proves who it is with when it acts on its own
|
|
39
|
+
* (`auth.system`), instead of its secret. Default: `CAUTHY_SYSTEM_KEY` and
|
|
40
|
+
* `CAUTHY_SYSTEM_KEY_ID`.
|
|
41
|
+
*/
|
|
42
|
+
systemKey?: SystemKey;
|
|
43
|
+
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
44
|
+
fetch?: typeof fetch;
|
|
45
|
+
}
|
|
46
|
+
/** The person signed in. Every moment is UTC. */
|
|
47
|
+
interface SessionUser {
|
|
48
|
+
id: string;
|
|
49
|
+
email: string;
|
|
50
|
+
name: string;
|
|
51
|
+
emailVerified: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* True when the account ran out of time to confirm its address: let it read
|
|
54
|
+
* and refuse its writes.
|
|
55
|
+
*/
|
|
56
|
+
restricted: boolean;
|
|
57
|
+
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
58
|
+
emailVerifyBy?: string;
|
|
59
|
+
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
60
|
+
locale?: string;
|
|
61
|
+
}
|
|
62
|
+
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
63
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
64
|
+
[key: string]: JsonValue;
|
|
65
|
+
};
|
|
66
|
+
/** An organization the person belongs to, with their role in it. */
|
|
67
|
+
interface SessionOrganization {
|
|
68
|
+
id: string;
|
|
69
|
+
system: string;
|
|
70
|
+
name: string;
|
|
71
|
+
kind: string;
|
|
72
|
+
externalId?: string;
|
|
73
|
+
role: string;
|
|
74
|
+
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
75
|
+
metadata: Record<string, JsonValue>;
|
|
76
|
+
/**
|
|
77
|
+
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
78
|
+
* their role's permissions, what it inherits, and anything given to them
|
|
79
|
+
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
80
|
+
* Check with `can(organization, resource, action)`.
|
|
81
|
+
*/
|
|
82
|
+
permissions?: string[];
|
|
83
|
+
/** What the person is denied here, whatever else allows it. */
|
|
84
|
+
denied?: string[];
|
|
85
|
+
}
|
|
86
|
+
/** A signed-in person, as the server sees them. */
|
|
87
|
+
interface Session {
|
|
88
|
+
user: SessionUser;
|
|
89
|
+
/** The Cauthy tenant the account is of. */
|
|
90
|
+
tenantId: string;
|
|
91
|
+
/** The roles the account holds in that tenant. */
|
|
92
|
+
roles: string[];
|
|
93
|
+
/**
|
|
94
|
+
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
95
|
+
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
96
|
+
*/
|
|
97
|
+
accessToken: string;
|
|
98
|
+
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
99
|
+
expiresAt: string;
|
|
100
|
+
}
|
|
101
|
+
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
102
|
+
interface PublicSession {
|
|
103
|
+
user: SessionUser;
|
|
104
|
+
tenantId: string;
|
|
105
|
+
roles: string[];
|
|
106
|
+
organizations: SessionOrganization[];
|
|
107
|
+
expiresAt: string;
|
|
108
|
+
}
|
|
109
|
+
/** Why there is no session. */
|
|
110
|
+
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
111
|
+
declare class CauthyConfigError extends Error {
|
|
112
|
+
constructor(message: string);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** The key an application signs its assertions with. */
|
|
116
|
+
interface SystemKey {
|
|
117
|
+
/** The private key: PKCS#8 PEM, or a JWK (as an object or its JSON). RSA, for RS256. */
|
|
118
|
+
privateKey: string | JWK;
|
|
119
|
+
/** The id the public key is published under (`kid`). */
|
|
120
|
+
keyId: string;
|
|
121
|
+
}
|
|
122
|
+
interface SystemOptions {
|
|
123
|
+
/** Cauthy's address. Default: `CAUTHY_ISSUER`. */
|
|
124
|
+
issuer?: string;
|
|
125
|
+
/** The application's client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
126
|
+
clientId?: string;
|
|
127
|
+
/** Its secret. Default: `CAUTHY_CLIENT_SECRET`. Not needed with `key`. */
|
|
128
|
+
clientSecret?: string;
|
|
129
|
+
/**
|
|
130
|
+
* The key to prove who the application is with, instead of the secret.
|
|
131
|
+
* Default: `CAUTHY_SYSTEM_KEY` (the private key) and `CAUTHY_SYSTEM_KEY_ID`.
|
|
132
|
+
*/
|
|
133
|
+
key?: SystemKey;
|
|
134
|
+
fetch?: typeof fetch;
|
|
135
|
+
}
|
|
136
|
+
/** Cauthy refused a request of the application's own. */
|
|
137
|
+
declare class CauthyApiError extends Error {
|
|
138
|
+
readonly status: number;
|
|
139
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
140
|
+
readonly code: string;
|
|
141
|
+
constructor(status: number,
|
|
142
|
+
/** Cauthy's code for what went wrong: `organization_not_found`, `other_system`, `outside_system_scope`… */
|
|
143
|
+
code: string, message: string);
|
|
144
|
+
}
|
|
145
|
+
/** An organization of the application's system. Every moment is UTC. */
|
|
146
|
+
interface Organization {
|
|
147
|
+
id: string;
|
|
148
|
+
system: string;
|
|
149
|
+
name: string;
|
|
150
|
+
kind: string;
|
|
151
|
+
/** The id the application knows it by. */
|
|
152
|
+
externalId?: string;
|
|
153
|
+
status: 'active' | 'archived';
|
|
154
|
+
metadata: Record<string, JsonValue>;
|
|
155
|
+
members: number;
|
|
156
|
+
createdAt: string;
|
|
157
|
+
updatedAt: string;
|
|
158
|
+
}
|
|
159
|
+
interface OrganizationMember {
|
|
160
|
+
userId: string;
|
|
161
|
+
email: string;
|
|
162
|
+
name: string;
|
|
163
|
+
/** The account's status: a disabled member is still listed. */
|
|
164
|
+
status: string;
|
|
165
|
+
role: string;
|
|
166
|
+
/** True when the address had no account: one was made and invited. */
|
|
167
|
+
invited?: boolean;
|
|
168
|
+
}
|
|
169
|
+
/** Who to add: an account by its id, or anybody by their address (invited when new). */
|
|
170
|
+
type NewMember = {
|
|
171
|
+
role: string;
|
|
172
|
+
name?: string;
|
|
173
|
+
locale?: string;
|
|
174
|
+
} & ({
|
|
175
|
+
userId: string;
|
|
176
|
+
email?: undefined;
|
|
177
|
+
} | {
|
|
178
|
+
email: string;
|
|
179
|
+
userId?: undefined;
|
|
180
|
+
});
|
|
181
|
+
interface CauthySystem {
|
|
182
|
+
/** The application's own token, asked for when needed and kept until it is about to run out. */
|
|
183
|
+
token(): Promise<string>;
|
|
184
|
+
/** Any route the application's token may call; answers what Cauthy put under `data`. */
|
|
185
|
+
request<T = unknown>(method: string, path: string, body?: unknown): Promise<T>;
|
|
186
|
+
organizations: {
|
|
187
|
+
list(query?: {
|
|
188
|
+
q?: string;
|
|
189
|
+
status?: 'active' | 'archived';
|
|
190
|
+
limit?: number;
|
|
191
|
+
offset?: number;
|
|
192
|
+
}): Promise<{
|
|
193
|
+
items: Organization[];
|
|
194
|
+
total: number;
|
|
195
|
+
}>;
|
|
196
|
+
create(input: {
|
|
197
|
+
name: string;
|
|
198
|
+
kind?: string;
|
|
199
|
+
externalId?: string;
|
|
200
|
+
metadata?: Record<string, JsonValue>;
|
|
201
|
+
}): Promise<Organization>;
|
|
202
|
+
get(id: string): Promise<Organization>;
|
|
203
|
+
update(id: string, patch: {
|
|
204
|
+
name?: string;
|
|
205
|
+
kind?: string;
|
|
206
|
+
status?: 'active' | 'archived';
|
|
207
|
+
metadata?: Record<string, JsonValue>;
|
|
208
|
+
}): Promise<Organization>;
|
|
209
|
+
/** Removes the organization and every membership of it, for good. */
|
|
210
|
+
remove(id: string): Promise<void>;
|
|
211
|
+
};
|
|
212
|
+
members: {
|
|
213
|
+
list(organizationId: string): Promise<OrganizationMember[]>;
|
|
214
|
+
add(organizationId: string, member: NewMember): Promise<OrganizationMember>;
|
|
215
|
+
setRole(organizationId: string, userId: string, role: string): Promise<OrganizationMember>;
|
|
216
|
+
remove(organizationId: string, userId: string): Promise<void>;
|
|
217
|
+
};
|
|
218
|
+
/** Invites a person who has no account yet; answers the account made for them. */
|
|
219
|
+
invite(person: {
|
|
220
|
+
email: string;
|
|
221
|
+
name?: string;
|
|
222
|
+
locale?: string;
|
|
223
|
+
}): Promise<{
|
|
224
|
+
id: string;
|
|
225
|
+
email: string;
|
|
226
|
+
}>;
|
|
227
|
+
/**
|
|
228
|
+
* How the application looks on Cauthy's pages: read it, set it, or take it
|
|
229
|
+
* back to Cauthy's own with `null`. Of its own sign-in client — this one,
|
|
230
|
+
* unless another is named (a system whose identity is a separate client).
|
|
231
|
+
*/
|
|
232
|
+
theme: {
|
|
233
|
+
get(clientId?: string): Promise<CauthyTheme>;
|
|
234
|
+
set(theme: CauthyTheme | null, clientId?: string): Promise<void>;
|
|
235
|
+
};
|
|
236
|
+
/** The public half of `key`, to serve at the address Cauthy was given (`jwks_uri`). Empty with a secret. */
|
|
237
|
+
publicJwks(): Promise<{
|
|
238
|
+
keys: JWK[];
|
|
239
|
+
}>;
|
|
240
|
+
}
|
|
241
|
+
declare function createSystem(given?: SystemOptions): CauthySystem;
|
|
242
|
+
|
|
243
|
+
export { CauthyApiError as C, type JsonValue as J, type NewMember as N, type Organization as O, type PublicSession as P, type Session as S, CauthyConfigError as a, type CauthyOptions as b, type CauthySystem as c, type OrganizationMember as d, type SessionOrganization as e, type SessionStatus as f, type SessionUser as g, type SystemKey as h, type SystemOptions as i, createSystem as j };
|
package/dist/theme.d.mts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
/** How an application looks on Cauthy's hosted pages. Every value is optional. */
|
|
2
|
+
/** One font file the application serves: a family in one weight (or a range) and one style. */
|
|
3
|
+
interface ThemeFont {
|
|
4
|
+
family: string;
|
|
5
|
+
/** An https address of a `.woff2` file. It must answer with `Access-Control-Allow-Origin` for Cauthy's origin. */
|
|
6
|
+
url: string;
|
|
7
|
+
/** `400`, or `"100 900"` for a variable font. Default: 400. */
|
|
8
|
+
weight?: number | string;
|
|
9
|
+
style?: 'normal' | 'italic';
|
|
10
|
+
}
|
|
2
11
|
interface CauthyTheme {
|
|
3
12
|
/** The page. Colours are `#rrggbb` or `rgba(r, g, b, a)`. */
|
|
4
13
|
background?: string;
|
|
@@ -22,8 +31,10 @@ interface CauthyTheme {
|
|
|
22
31
|
radius?: number;
|
|
23
32
|
/** Corners of buttons, in pixels (0–40). */
|
|
24
33
|
buttonRadius?: number;
|
|
25
|
-
/** A CSS font-family list
|
|
34
|
+
/** A CSS font-family list: the application's typeface first, a system font after it. */
|
|
26
35
|
fontFamily?: string;
|
|
36
|
+
/** The files of the typefaces `fontFamily` names, for people who do not have them installed. */
|
|
37
|
+
fonts?: ThemeFont[];
|
|
27
38
|
/** An image shown where "Cauthy" is, over https. */
|
|
28
39
|
logoUrl?: string;
|
|
29
40
|
}
|
|
@@ -56,7 +67,9 @@ declare function toColor(value: string): string | null;
|
|
|
56
67
|
*/
|
|
57
68
|
declare function themeFromStackmyth(css: string | string[], options?: StackmythThemeOptions): ImportedTheme;
|
|
58
69
|
/** A theme as Cauthy's API names its values. */
|
|
59
|
-
declare function toWire(theme: CauthyTheme): Record<string, string | number>;
|
|
70
|
+
declare function toWire(theme: CauthyTheme): Record<string, string | number | ThemeFont[]>;
|
|
71
|
+
/** A theme as Cauthy answers it, in this package's names. */
|
|
72
|
+
declare function fromWire(wire: Record<string, unknown>): CauthyTheme;
|
|
60
73
|
interface PushThemeOptions {
|
|
61
74
|
/** Cauthy's address. Default: `CAUTHY_ISSUER`. */
|
|
62
75
|
issuer?: string;
|
|
@@ -79,4 +92,4 @@ interface PushThemeOptions {
|
|
|
79
92
|
*/
|
|
80
93
|
declare function pushTheme(o: PushThemeOptions): Promise<void>;
|
|
81
94
|
|
|
82
|
-
export { type CauthyTheme, type ImportedTheme, type PushThemeOptions, type StackmythThemeOptions, pushTheme, themeFromStackmyth, toColor, toWire };
|
|
95
|
+
export { type CauthyTheme, type ImportedTheme, type PushThemeOptions, type StackmythThemeOptions, type ThemeFont, fromWire, pushTheme, themeFromStackmyth, toColor, toWire };
|
package/dist/theme.d.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
/** How an application looks on Cauthy's hosted pages. Every value is optional. */
|
|
2
|
+
/** One font file the application serves: a family in one weight (or a range) and one style. */
|
|
3
|
+
interface ThemeFont {
|
|
4
|
+
family: string;
|
|
5
|
+
/** An https address of a `.woff2` file. It must answer with `Access-Control-Allow-Origin` for Cauthy's origin. */
|
|
6
|
+
url: string;
|
|
7
|
+
/** `400`, or `"100 900"` for a variable font. Default: 400. */
|
|
8
|
+
weight?: number | string;
|
|
9
|
+
style?: 'normal' | 'italic';
|
|
10
|
+
}
|
|
2
11
|
interface CauthyTheme {
|
|
3
12
|
/** The page. Colours are `#rrggbb` or `rgba(r, g, b, a)`. */
|
|
4
13
|
background?: string;
|
|
@@ -22,8 +31,10 @@ interface CauthyTheme {
|
|
|
22
31
|
radius?: number;
|
|
23
32
|
/** Corners of buttons, in pixels (0–40). */
|
|
24
33
|
buttonRadius?: number;
|
|
25
|
-
/** A CSS font-family list
|
|
34
|
+
/** A CSS font-family list: the application's typeface first, a system font after it. */
|
|
26
35
|
fontFamily?: string;
|
|
36
|
+
/** The files of the typefaces `fontFamily` names, for people who do not have them installed. */
|
|
37
|
+
fonts?: ThemeFont[];
|
|
27
38
|
/** An image shown where "Cauthy" is, over https. */
|
|
28
39
|
logoUrl?: string;
|
|
29
40
|
}
|
|
@@ -56,7 +67,9 @@ declare function toColor(value: string): string | null;
|
|
|
56
67
|
*/
|
|
57
68
|
declare function themeFromStackmyth(css: string | string[], options?: StackmythThemeOptions): ImportedTheme;
|
|
58
69
|
/** A theme as Cauthy's API names its values. */
|
|
59
|
-
declare function toWire(theme: CauthyTheme): Record<string, string | number>;
|
|
70
|
+
declare function toWire(theme: CauthyTheme): Record<string, string | number | ThemeFont[]>;
|
|
71
|
+
/** A theme as Cauthy answers it, in this package's names. */
|
|
72
|
+
declare function fromWire(wire: Record<string, unknown>): CauthyTheme;
|
|
60
73
|
interface PushThemeOptions {
|
|
61
74
|
/** Cauthy's address. Default: `CAUTHY_ISSUER`. */
|
|
62
75
|
issuer?: string;
|
|
@@ -79,4 +92,4 @@ interface PushThemeOptions {
|
|
|
79
92
|
*/
|
|
80
93
|
declare function pushTheme(o: PushThemeOptions): Promise<void>;
|
|
81
94
|
|
|
82
|
-
export { type CauthyTheme, type ImportedTheme, type PushThemeOptions, type StackmythThemeOptions, pushTheme, themeFromStackmyth, toColor, toWire };
|
|
95
|
+
export { type CauthyTheme, type ImportedTheme, type PushThemeOptions, type StackmythThemeOptions, type ThemeFont, fromWire, pushTheme, themeFromStackmyth, toColor, toWire };
|
package/dist/theme.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/theme.ts
|
|
21
21
|
var theme_exports = {};
|
|
22
22
|
__export(theme_exports, {
|
|
23
|
+
fromWire: () => fromWire,
|
|
23
24
|
pushTheme: () => pushTheme,
|
|
24
25
|
themeFromStackmyth: () => themeFromStackmyth,
|
|
25
26
|
toColor: () => toColor,
|
|
@@ -219,12 +220,40 @@ function toWire(theme) {
|
|
|
219
220
|
radius: "radius",
|
|
220
221
|
buttonRadius: "button_radius",
|
|
221
222
|
fontFamily: "font_family",
|
|
222
|
-
logoUrl: "logo_url"
|
|
223
|
+
logoUrl: "logo_url",
|
|
224
|
+
fonts: "fonts"
|
|
223
225
|
};
|
|
224
226
|
const wire = {};
|
|
225
|
-
for (const [k, v] of Object.entries(theme))
|
|
227
|
+
for (const [k, v] of Object.entries(theme)) {
|
|
228
|
+
if (v === void 0 || v === "" || Array.isArray(v) && v.length === 0) continue;
|
|
229
|
+
wire[names[k]] = v;
|
|
230
|
+
}
|
|
226
231
|
return wire;
|
|
227
232
|
}
|
|
233
|
+
function fromWire(wire) {
|
|
234
|
+
const names = {
|
|
235
|
+
background: "background",
|
|
236
|
+
surface: "surface",
|
|
237
|
+
text: "text",
|
|
238
|
+
text_muted: "textMuted",
|
|
239
|
+
border: "border",
|
|
240
|
+
primary: "primary",
|
|
241
|
+
primary_text: "primaryText",
|
|
242
|
+
accent: "accent",
|
|
243
|
+
error: "error",
|
|
244
|
+
error_background: "errorBackground",
|
|
245
|
+
success: "success",
|
|
246
|
+
success_background: "successBackground",
|
|
247
|
+
radius: "radius",
|
|
248
|
+
button_radius: "buttonRadius",
|
|
249
|
+
font_family: "fontFamily",
|
|
250
|
+
logo_url: "logoUrl",
|
|
251
|
+
fonts: "fonts"
|
|
252
|
+
};
|
|
253
|
+
const theme = {};
|
|
254
|
+
for (const [k, v] of Object.entries(wire ?? {})) if (names[k] && v !== void 0 && v !== null && v !== "") theme[names[k]] = v;
|
|
255
|
+
return theme;
|
|
256
|
+
}
|
|
228
257
|
async function pushTheme(o) {
|
|
229
258
|
const env = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
|
|
230
259
|
const issuer = (o.issuer ?? env("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
|
|
@@ -246,6 +275,7 @@ async function pushTheme(o) {
|
|
|
246
275
|
}
|
|
247
276
|
// Annotate the CommonJS export names for ESM import in node:
|
|
248
277
|
0 && (module.exports = {
|
|
278
|
+
fromWire,
|
|
249
279
|
pushTheme,
|
|
250
280
|
themeFromStackmyth,
|
|
251
281
|
toColor,
|