cauthy-auth 0.1.0 → 0.3.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 CHANGED
@@ -44,7 +44,18 @@ Built with Stackmyth? Give Cauthy's pages your application's look from its own t
44
44
  npx cauthy-auth theme --css node_modules/@stackmyth/core/core.vars.css --css src/styles/brand-theme.css --push
45
45
  ```
46
46
 
47
- Register your application in Cauthy with the redirect URI `https://<your app>/api/auth/callback`. `CAUTHY_SECRET` is any string of 32 characters or more: it encrypts the session cookie.
47
+ Connect your application to Cauthy in one step, from Cauthy's dashboard ("Connect a System") or from a terminal. It makes the client, registers `https://<your app>/api/auth/callback`, and prints every variable to set, `CAUTHY_SECRET` included:
48
+
49
+ ```bash
50
+ npx cauthy-auth init --system ledger --app-url https://app.example.com
51
+ ```
52
+
53
+ The same client is your application's own identity: it manages its organizations with no person's token.
54
+
55
+ ```ts
56
+ const org = await auth.system.organizations.create({ name: 'Acme' })
57
+ await auth.system.members.add(org.id, { role: 'owner', email: 'ana@acme.com' })
58
+ ```
48
59
 
49
60
  The full guide is in Cauthy's documentation, under "Auth SDK".
50
61
 
@@ -0,0 +1,108 @@
1
+ import { J as JsonValue, S as Session, f as SessionStatus, e as SessionOrganization, c as CauthySystem, P as PublicSession, b as CauthyOptions } from './system-BWLddIt2.js';
2
+ import { JWTVerifyGetKey } from 'jose';
3
+
4
+ /** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
5
+ interface CauthyEvent {
6
+ /** This delivery's id: the same event delivered again carries the same one. */
7
+ id: string;
8
+ /** What happened: "organization.member_added". */
9
+ type: string;
10
+ tenantId: string;
11
+ createdAt: string;
12
+ /** The person it happened to, when it is about one. */
13
+ userId?: string;
14
+ /** Who did it. */
15
+ actorId?: string;
16
+ /** What the event says: for an organization, its id, system, external_id, role… */
17
+ data: Record<string, JsonValue>;
18
+ }
19
+ declare class CauthyWebhookError extends Error {
20
+ readonly reason: string;
21
+ constructor(reason: string);
22
+ }
23
+ interface VerifyWebhookOptions {
24
+ /** Cauthy's address. Default: `CAUTHY_ISSUER`. */
25
+ issuer?: string;
26
+ /**
27
+ * This endpoint's own public address, exactly as it is registered in Cauthy.
28
+ * Default: the request's URL, which is right unless a proxy changes it.
29
+ */
30
+ url?: string;
31
+ /** Cauthy's keys. Default: fetched from the issuer and cached. */
32
+ jwks?: JWTVerifyGetKey;
33
+ /** The moment to verify at. Default: now. */
34
+ now?: Date;
35
+ }
36
+ /**
37
+ * Verifies a delivery and answers the event it carries. Throws
38
+ * `CauthyWebhookError` for anything that is not a delivery Cauthy made for
39
+ * this endpoint just now: answer it 401 and nothing else.
40
+ */
41
+ declare function verifyWebhook(request: Request, options?: VerifyWebhookOptions): Promise<CauthyEvent>;
42
+
43
+ /** What `resolve` answers: who is there, and the cookies that must go back. */
44
+ interface Resolved {
45
+ session: Session | null;
46
+ status: SessionStatus;
47
+ /** `Set-Cookie` values to send with the response. Empty when nothing changed. */
48
+ cookies: string[];
49
+ }
50
+ interface Cauthy {
51
+ /** Serves the routes under `basePath`: login, callback, session, refresh, logout, account. */
52
+ handler(request: Request): Promise<Response>;
53
+ /**
54
+ * Who is signed in, or null.
55
+ *
56
+ * Give it the response's headers and a session that needs renewing is
57
+ * renewed on the spot, its new cookie added to them. Without them an
58
+ * expired session reads as null (see `status`): renewing changes the
59
+ * cookie, and a cookie nobody sends back is a session lost.
60
+ */
61
+ getSession(request: Request, responseHeaders?: Headers): Promise<Session | null>;
62
+ /** Whether somebody is signed in, nobody is, or the session must be renewed first. */
63
+ status(request: Request): Promise<SessionStatus>;
64
+ /**
65
+ * The session, renewed when it has to be, and the cookies to send back.
66
+ * The caller MUST send `cookies` with its response.
67
+ */
68
+ resolve(request: Request): Promise<Resolved>;
69
+ /**
70
+ * For a route only a signed-in person may see: the session, or the response
71
+ * to give instead — a redirect to sign in (or to renew) for a page, a 401
72
+ * for anything else.
73
+ */
74
+ protect(request: Request): Promise<{
75
+ session: Session;
76
+ response?: undefined;
77
+ } | {
78
+ session?: undefined;
79
+ response: Response;
80
+ }>;
81
+ /** The organizations the person belongs to (of `system`, when set), with their role in each. */
82
+ organizations(session: Session): Promise<SessionOrganization[]>;
83
+ /**
84
+ * Verifies a webhook delivery from Cauthy and answers the event it carries;
85
+ * throws `CauthyWebhookError` for anything else. No secret is involved: the
86
+ * delivery is signed with Cauthy's own key.
87
+ */
88
+ webhook(request: Request, options?: Pick<VerifyWebhookOptions, 'jwks' | 'now' | 'url'>): Promise<CauthyEvent>;
89
+ /**
90
+ * The application acting on its own, with no person's token: its
91
+ * organizations, their members, invitations. Needs the client's secret, or
92
+ * `systemKey`.
93
+ */
94
+ system: CauthySystem;
95
+ /** What the browser may be told of a session. */
96
+ toPublic(session: Session): Promise<PublicSession>;
97
+ /** Paths of this application that start a sign-in, a sign-out, or open the account page. */
98
+ urls: {
99
+ signIn(returnTo?: string): string;
100
+ signOut(): string;
101
+ account(returnTo?: string): string;
102
+ session: string;
103
+ };
104
+ options: Readonly<Required<Pick<CauthyOptions, 'issuer' | 'clientId' | 'basePath' | 'afterSignIn' | 'afterSignOut' | 'cookieName'>>>;
105
+ }
106
+ declare function createCauthy(given?: CauthyOptions): Cauthy;
107
+
108
+ export { type Cauthy as C, type Resolved as R, type VerifyWebhookOptions as V, type CauthyEvent as a, CauthyWebhookError as b, createCauthy as c, verifyWebhook as v };
@@ -0,0 +1,108 @@
1
+ import { J as JsonValue, S as Session, f as SessionStatus, e as SessionOrganization, c as CauthySystem, P as PublicSession, b as CauthyOptions } from './system-BWLddIt2.mjs';
2
+ import { JWTVerifyGetKey } from 'jose';
3
+
4
+ /** Something that happened in Cauthy, as a subscriber is told. Moments are UTC. */
5
+ interface CauthyEvent {
6
+ /** This delivery's id: the same event delivered again carries the same one. */
7
+ id: string;
8
+ /** What happened: "organization.member_added". */
9
+ type: string;
10
+ tenantId: string;
11
+ createdAt: string;
12
+ /** The person it happened to, when it is about one. */
13
+ userId?: string;
14
+ /** Who did it. */
15
+ actorId?: string;
16
+ /** What the event says: for an organization, its id, system, external_id, role… */
17
+ data: Record<string, JsonValue>;
18
+ }
19
+ declare class CauthyWebhookError extends Error {
20
+ readonly reason: string;
21
+ constructor(reason: string);
22
+ }
23
+ interface VerifyWebhookOptions {
24
+ /** Cauthy's address. Default: `CAUTHY_ISSUER`. */
25
+ issuer?: string;
26
+ /**
27
+ * This endpoint's own public address, exactly as it is registered in Cauthy.
28
+ * Default: the request's URL, which is right unless a proxy changes it.
29
+ */
30
+ url?: string;
31
+ /** Cauthy's keys. Default: fetched from the issuer and cached. */
32
+ jwks?: JWTVerifyGetKey;
33
+ /** The moment to verify at. Default: now. */
34
+ now?: Date;
35
+ }
36
+ /**
37
+ * Verifies a delivery and answers the event it carries. Throws
38
+ * `CauthyWebhookError` for anything that is not a delivery Cauthy made for
39
+ * this endpoint just now: answer it 401 and nothing else.
40
+ */
41
+ declare function verifyWebhook(request: Request, options?: VerifyWebhookOptions): Promise<CauthyEvent>;
42
+
43
+ /** What `resolve` answers: who is there, and the cookies that must go back. */
44
+ interface Resolved {
45
+ session: Session | null;
46
+ status: SessionStatus;
47
+ /** `Set-Cookie` values to send with the response. Empty when nothing changed. */
48
+ cookies: string[];
49
+ }
50
+ interface Cauthy {
51
+ /** Serves the routes under `basePath`: login, callback, session, refresh, logout, account. */
52
+ handler(request: Request): Promise<Response>;
53
+ /**
54
+ * Who is signed in, or null.
55
+ *
56
+ * Give it the response's headers and a session that needs renewing is
57
+ * renewed on the spot, its new cookie added to them. Without them an
58
+ * expired session reads as null (see `status`): renewing changes the
59
+ * cookie, and a cookie nobody sends back is a session lost.
60
+ */
61
+ getSession(request: Request, responseHeaders?: Headers): Promise<Session | null>;
62
+ /** Whether somebody is signed in, nobody is, or the session must be renewed first. */
63
+ status(request: Request): Promise<SessionStatus>;
64
+ /**
65
+ * The session, renewed when it has to be, and the cookies to send back.
66
+ * The caller MUST send `cookies` with its response.
67
+ */
68
+ resolve(request: Request): Promise<Resolved>;
69
+ /**
70
+ * For a route only a signed-in person may see: the session, or the response
71
+ * to give instead — a redirect to sign in (or to renew) for a page, a 401
72
+ * for anything else.
73
+ */
74
+ protect(request: Request): Promise<{
75
+ session: Session;
76
+ response?: undefined;
77
+ } | {
78
+ session?: undefined;
79
+ response: Response;
80
+ }>;
81
+ /** The organizations the person belongs to (of `system`, when set), with their role in each. */
82
+ organizations(session: Session): Promise<SessionOrganization[]>;
83
+ /**
84
+ * Verifies a webhook delivery from Cauthy and answers the event it carries;
85
+ * throws `CauthyWebhookError` for anything else. No secret is involved: the
86
+ * delivery is signed with Cauthy's own key.
87
+ */
88
+ webhook(request: Request, options?: Pick<VerifyWebhookOptions, 'jwks' | 'now' | 'url'>): Promise<CauthyEvent>;
89
+ /**
90
+ * The application acting on its own, with no person's token: its
91
+ * organizations, their members, invitations. Needs the client's secret, or
92
+ * `systemKey`.
93
+ */
94
+ system: CauthySystem;
95
+ /** What the browser may be told of a session. */
96
+ toPublic(session: Session): Promise<PublicSession>;
97
+ /** Paths of this application that start a sign-in, a sign-out, or open the account page. */
98
+ urls: {
99
+ signIn(returnTo?: string): string;
100
+ signOut(): string;
101
+ account(returnTo?: string): string;
102
+ session: string;
103
+ };
104
+ options: Readonly<Required<Pick<CauthyOptions, 'issuer' | 'clientId' | 'basePath' | 'afterSignIn' | 'afterSignOut' | 'cookieName'>>>;
105
+ }
106
+ declare function createCauthy(given?: CauthyOptions): Cauthy;
107
+
108
+ export { type Cauthy as C, type Resolved as R, type VerifyWebhookOptions as V, type CauthyEvent as a, CauthyWebhookError as b, createCauthy as c, verifyWebhook as v };
package/dist/cli.js CHANGED
@@ -4,6 +4,74 @@
4
4
  // src/cli.ts
5
5
  var import_node_fs = require("fs");
6
6
 
7
+ // src/connect.ts
8
+ function sessionSecret() {
9
+ const bytes = crypto.getRandomValues(new Uint8Array(32));
10
+ let s = "";
11
+ for (const b of bytes) s += String.fromCharCode(b);
12
+ return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
13
+ }
14
+ async function connectSystem(o) {
15
+ const env = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
16
+ const issuer = (o.issuer ?? env("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
17
+ const tenant = o.tenant ?? env("CAUTHY_TENANT") ?? "";
18
+ const token = o.token ?? env("CAUTHY_TOKEN") ?? "";
19
+ for (const [name, v] of Object.entries({ CAUTHY_ISSUER: issuer, CAUTHY_TENANT: tenant, CAUTHY_TOKEN: token })) {
20
+ if (v === "") throw new Error(`cauthy-auth: ${name} is required to connect a system`);
21
+ }
22
+ const res = await (o.fetch ?? fetch)(`${issuer}/v1/connect`, {
23
+ method: "POST",
24
+ headers: { authorization: `Bearer ${token}`, "x-tenant-key": tenant, "content-type": "application/json" },
25
+ body: JSON.stringify({
26
+ system: o.system,
27
+ app_url: o.appUrl,
28
+ name: o.name,
29
+ callback_path: o.callbackPath,
30
+ events_url: o.eventsUrl,
31
+ events: o.events,
32
+ jwks_uri: o.jwksUri
33
+ })
34
+ });
35
+ const body = await res.json().catch(() => null);
36
+ if (!res.ok || !body?.data) {
37
+ const why = (body?.errors ?? []).map((e) => e.message).filter(Boolean).join("; ") || res.statusText;
38
+ throw new Error(`cauthy-auth: Cauthy did not connect the system (${res.status}): ${why}`);
39
+ }
40
+ const d = body.data;
41
+ return {
42
+ system: d.system,
43
+ clientId: d.client.client_id,
44
+ clientSecret: d.client_secret,
45
+ redirectUris: d.client.redirect_uris,
46
+ webhook: d.webhook,
47
+ env: { ...d.env, CAUTHY_SECRET: sessionSecret() }
48
+ };
49
+ }
50
+ function envFile(env) {
51
+ return Object.entries(env).map(([k, v]) => `${k}=${v}`).join("\n") + "\n";
52
+ }
53
+
54
+ // src/permissions.ts
55
+ async function pushPolicy(o) {
56
+ const env = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
57
+ const issuer = (o.issuer ?? env("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
58
+ const system = o.system ?? env("CAUTHY_SYSTEM") ?? "";
59
+ const tenant = o.tenant ?? env("CAUTHY_TENANT") ?? "";
60
+ const token = o.token ?? env("CAUTHY_TOKEN") ?? "";
61
+ for (const [name, v] of Object.entries({ CAUTHY_ISSUER: issuer, CAUTHY_SYSTEM: system, CAUTHY_TENANT: tenant, CAUTHY_TOKEN: token })) {
62
+ if (v === "") throw new Error(`cauthy-auth: ${name} is required to push a policy`);
63
+ }
64
+ const res = await (o.fetch ?? fetch)(`${issuer}/v1/systems/${encodeURIComponent(system)}/policy`, {
65
+ method: "PUT",
66
+ headers: { authorization: `Bearer ${token}`, "x-tenant-key": tenant, "content-type": "application/json" },
67
+ body: JSON.stringify({ roles: o.roles })
68
+ });
69
+ if (!res.ok) {
70
+ const body = await res.json().catch(() => null);
71
+ throw new Error(`cauthy-auth: Cauthy refused the policy (${res.status}): ${body?.errors?.[0]?.message ?? res.statusText}`);
72
+ }
73
+ }
74
+
7
75
  // src/theme.ts
8
76
  var MAX_RADIUS = 40;
9
77
  function declarations(css) {
@@ -225,7 +293,137 @@ async function pushTheme(o) {
225
293
  }
226
294
 
227
295
  // src/cli.ts
228
- var HELP = `cauthy-auth theme [options]
296
+ var INIT_HELP = `cauthy-auth init --system <name> --app-url <address> [options]
297
+
298
+ Connects an application to Cauthy: makes its client, registers where its people
299
+ come back to and where it hears events, and prints the variables to set.
300
+
301
+ --system <name> The system's name: lowercase letters, digits, - or _.
302
+ --app-url <address> The application's public address: https://app.example.com,
303
+ or http://localhost:3000 while developing.
304
+ --name <name> Shown to people on Cauthy's pages. Default: the system's name.
305
+ --callback-path <path> Where the application serves the return from a sign-in.
306
+ Default: /api/auth/callback.
307
+ --events-url <address> An https address of the application that receives
308
+ Cauthy's events (verify them with auth.webhook).
309
+ --jwks-uri <address> Where the application publishes its keys, to prove
310
+ itself with a signature instead of its secret.
311
+ --write <file> Append the variables to this file instead of printing
312
+ them (they include the client's secret, shown once).
313
+
314
+ Needs CAUTHY_ISSUER, CAUTHY_TENANT (the workspace's slug) and CAUTHY_TOKEN (a
315
+ personal access token with systems:connect).
316
+ `;
317
+ async function init(argv) {
318
+ if (argv.includes("--help") || argv.includes("-h")) {
319
+ process.stdout.write(INIT_HELP);
320
+ return;
321
+ }
322
+ const given = {};
323
+ const flags = ["--system", "--app-url", "--name", "--callback-path", "--events-url", "--jwks-uri", "--write"];
324
+ for (let i = 0; i < argv.length; i++) {
325
+ const arg = argv[i];
326
+ if (!flags.includes(arg)) fail(`unknown option ${arg}
327
+
328
+ ${INIT_HELP}`);
329
+ given[arg] = argv[++i] ?? fail(`${arg} needs a value`);
330
+ }
331
+ if (!given["--system"] || !given["--app-url"]) fail("give --system and --app-url\n\n" + INIT_HELP);
332
+ const done = await connectSystem({
333
+ system: given["--system"],
334
+ appUrl: given["--app-url"],
335
+ name: given["--name"],
336
+ callbackPath: given["--callback-path"],
337
+ eventsUrl: given["--events-url"],
338
+ jwksUri: given["--jwks-uri"]
339
+ });
340
+ const vars = envFile(done.env);
341
+ process.stdout.write(`Connected: the system ${done.system} is the client ${done.clientId}.
342
+ `);
343
+ process.stdout.write(` people come back to ${done.redirectUris.join(", ")}
344
+ `);
345
+ if (done.webhook) process.stdout.write(` events are sent to ${done.webhook.url}
346
+ `);
347
+ if (given["--write"]) {
348
+ (0, import_node_fs.appendFileSync)(given["--write"], vars, { mode: 384 });
349
+ process.stdout.write(`
350
+ The variables were added to ${given["--write"]}. Keep that file out of the repository.
351
+ `);
352
+ } else {
353
+ process.stdout.write(`
354
+ Set these where the application runs. The secret is shown this once:
355
+
356
+ ${vars}`);
357
+ }
358
+ process.stdout.write(`
359
+ Then, in the application:
360
+
361
+ import { createCauthy } from 'cauthy-auth'
362
+ export const auth = createCauthy()
363
+
364
+ and serve auth.handler(request) under ${(given["--callback-path"] ?? "/api/auth/callback").replace(/\/callback$/, "")}/*.
365
+ `);
366
+ }
367
+ var POLICY_HELP = `cauthy-auth policy --file <roles.json> [--system <name>] [--push]
368
+
369
+ Loads a system's catalog of roles into Cauthy from a file:
370
+
371
+ { "roles": [ { "role": "accountant", "name": "Accountant", "inherits": ["reader"],
372
+ "permissions": [ { "resource": "ledger", "action": "write" },
373
+ { "kind": "business", "resource": "books.close", "action": "write" } ] } ] }
374
+
375
+ --file <file> The catalog, as JSON.
376
+ --system <name> The system it is of. Default: CAUTHY_SYSTEM.
377
+ --push Send it to Cauthy, REPLACING the catalog it has. Without it
378
+ the catalog is only checked and shown.
379
+
380
+ Use it to load a first catalog. Afterwards the catalog is Cauthy's, edited in
381
+ its dashboard: pushing again overwrites what was edited there.
382
+
383
+ To push: CAUTHY_ISSUER, CAUTHY_TENANT (the workspace's slug) and CAUTHY_TOKEN
384
+ (a personal access token with organizations:manage).
385
+ `;
386
+ async function policy(argv) {
387
+ if (argv.includes("--help") || argv.includes("-h")) {
388
+ process.stdout.write(POLICY_HELP);
389
+ return;
390
+ }
391
+ let file;
392
+ let system;
393
+ let push = false;
394
+ for (let i = 0; i < argv.length; i++) {
395
+ const arg = argv[i];
396
+ const value = () => argv[++i] ?? fail(`${arg} needs a value`);
397
+ if (arg === "--file") file = value();
398
+ else if (arg === "--system") system = value();
399
+ else if (arg === "--push") push = true;
400
+ else fail(`unknown option ${arg}
401
+
402
+ ${POLICY_HELP}`);
403
+ }
404
+ if (!file) fail("give the catalog with --file\n\n" + POLICY_HELP);
405
+ let roles;
406
+ try {
407
+ const parsed = JSON.parse((0, import_node_fs.readFileSync)(file, "utf8"));
408
+ const list = Array.isArray(parsed) ? parsed : parsed.roles;
409
+ if (!Array.isArray(list)) throw new Error('no "roles" list');
410
+ roles = list;
411
+ } catch (err) {
412
+ return fail(`cannot read ${file}: ${err instanceof Error ? err.message : String(err)}`);
413
+ }
414
+ const permissions = roles.reduce((n, r) => n + (r.permissions?.length ?? 0), 0);
415
+ process.stdout.write(`${roles.length} roles, ${permissions} permissions: ${roles.map((r) => r.role).join(", ")}
416
+ `);
417
+ if (push) {
418
+ await pushPolicy({ system, roles });
419
+ process.stdout.write("Sent to Cauthy: this is now the catalog of the system.\n");
420
+ } else {
421
+ process.stdout.write("Not sent. Add --push to give it to Cauthy.\n");
422
+ }
423
+ }
424
+ var HELP = `cauthy-auth init \u2026 connect an application to Cauthy (cauthy-auth init --help)
425
+ cauthy-auth policy \u2026 load a system's catalog of roles (cauthy-auth policy --help)
426
+ cauthy-auth theme [options]
229
427
 
230
428
  Reads the application's Stackmyth theme and gives it to Cauthy's hosted pages.
231
429
 
@@ -247,6 +445,8 @@ function fail(message) {
247
445
  process.exit(1);
248
446
  }
249
447
  async function main(argv) {
448
+ if (argv[0] === "policy") return policy(argv.slice(1));
449
+ if (argv[0] === "init") return init(argv.slice(1));
250
450
  if (argv[0] !== "theme" || argv.includes("--help") || argv.includes("-h")) {
251
451
  process.stdout.write(HELP);
252
452
  process.exit(argv[0] === "theme" || argv.length === 0 || argv.includes("--help") || argv.includes("-h") ? 0 : 1);
@@ -298,4 +498,4 @@ ${HELP}`);
298
498
  process.stdout.write("Not sent. Add --push to give it to Cauthy.\n");
299
499
  }
300
500
  }
301
- main(process.argv.slice(2)).catch((err) => fail(err instanceof Error ? err.message.replace(/^@cauthy\/auth: /, "") : String(err)));
501
+ main(process.argv.slice(2)).catch((err) => fail(err instanceof Error ? err.message.replace(/^cauthy-auth: /, "") : String(err)));
@@ -1,6 +1,7 @@
1
1
  import { FastifyReply, FastifyPluginAsync } from 'fastify';
2
- import { C as Cauthy } from './cauthy-DsUNqjg6.mjs';
3
- import { S as Session } from './types-BwCjBn-K.mjs';
2
+ import { C as Cauthy } from './cauthy-mNADGlNl.mjs';
3
+ import { S as Session } from './system-BWLddIt2.mjs';
4
+ import 'jose';
4
5
 
5
6
  declare module 'fastify' {
6
7
  interface FastifyRequest {
package/dist/fastify.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { FastifyReply, FastifyPluginAsync } from 'fastify';
2
- import { C as Cauthy } from './cauthy-By2cryXN.js';
3
- import { S as Session } from './types-BwCjBn-K.js';
2
+ import { C as Cauthy } from './cauthy-C5_lopMQ.js';
3
+ import { S as Session } from './system-BWLddIt2.js';
4
+ import 'jose';
4
5
 
5
6
  declare module 'fastify' {
6
7
  interface FastifyRequest {
package/dist/index.d.mts CHANGED
@@ -1,3 +1,49 @@
1
- export { C as Cauthy, R as Resolved, c as createCauthy } from './cauthy-DsUNqjg6.mjs';
2
- export { C as CauthyConfigError, a as CauthyOptions, J as JsonValue, P as PublicSession, S as Session, b as SessionOrganization, c as SessionStatus, d as SessionUser } from './types-BwCjBn-K.mjs';
1
+ export { C as Cauthy, a as CauthyEvent, b as CauthyWebhookError, R as Resolved, V as VerifyWebhookOptions, c as createCauthy, v as verifyWebhook } from './cauthy-mNADGlNl.mjs';
2
+ export { C as CauthyApiError, a as CauthyConfigError, b as CauthyOptions, c as CauthySystem, J as JsonValue, N as NewMember, O as Organization, d as OrganizationMember, P as PublicSession, S as Session, e as SessionOrganization, f as SessionStatus, g as SessionUser, h as SystemKey, i as SystemOptions, j as createSystem } from './system-BWLddIt2.mjs';
3
3
  export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, pushTheme, themeFromStackmyth } from './theme.mjs';
4
+ export { P as Permitted, a as PolicyPermission, b as PolicyRole, c as PushPolicyOptions, d as can, p as pushPolicy } from './permissions-B-a3eN0h.mjs';
5
+ import 'jose';
6
+
7
+ interface ConnectOptions {
8
+ /** The system's name, as its organizations are filed under: lowercase, digits, - or _. */
9
+ system: string;
10
+ /** The application's public address: `https://app.example.com`, or `http://localhost:3000` while developing. */
11
+ appUrl: string;
12
+ /** Shown to people on Cauthy's pages. Default: the system's name. */
13
+ name?: string;
14
+ /** Where the application serves the return from a sign-in. Default: `/api/auth/callback`. */
15
+ callbackPath?: string;
16
+ /** An https address of the application that receives Cauthy's events. */
17
+ eventsUrl?: string;
18
+ /** The events to receive. Default: all of them. */
19
+ events?: string[];
20
+ /** Where the application publishes its keys, to prove itself without a secret. */
21
+ jwksUri?: string;
22
+ /** Cauthy's address. Default: `CAUTHY_ISSUER`. */
23
+ issuer?: string;
24
+ /** The workspace's slug. Default: `CAUTHY_TENANT`. */
25
+ tenant?: string;
26
+ /** A personal access token with `systems:connect`. Default: `CAUTHY_TOKEN`. */
27
+ token?: string;
28
+ fetch?: typeof fetch;
29
+ }
30
+ interface Connected {
31
+ system: string;
32
+ clientId: string;
33
+ /** Shown this once: Cauthy keeps only its hash. */
34
+ clientSecret: string;
35
+ redirectUris: string[];
36
+ webhook: {
37
+ id: string;
38
+ url: string;
39
+ events: string[];
40
+ } | null;
41
+ /**
42
+ * Everything the application sets: what Cauthy answered, plus CAUTHY_SECRET,
43
+ * the key of the session cookie, generated here and known to nobody else.
44
+ */
45
+ env: Record<string, string>;
46
+ }
47
+ declare function connectSystem(o: ConnectOptions): Promise<Connected>;
48
+
49
+ export { type ConnectOptions, type Connected, connectSystem };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,49 @@
1
- export { C as Cauthy, R as Resolved, c as createCauthy } from './cauthy-By2cryXN.js';
2
- export { C as CauthyConfigError, a as CauthyOptions, J as JsonValue, P as PublicSession, S as Session, b as SessionOrganization, c as SessionStatus, d as SessionUser } from './types-BwCjBn-K.js';
1
+ export { C as Cauthy, a as CauthyEvent, b as CauthyWebhookError, R as Resolved, V as VerifyWebhookOptions, c as createCauthy, v as verifyWebhook } from './cauthy-C5_lopMQ.js';
2
+ export { C as CauthyApiError, a as CauthyConfigError, b as CauthyOptions, c as CauthySystem, J as JsonValue, N as NewMember, O as Organization, d as OrganizationMember, P as PublicSession, S as Session, e as SessionOrganization, f as SessionStatus, g as SessionUser, h as SystemKey, i as SystemOptions, j as createSystem } from './system-BWLddIt2.js';
3
3
  export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, pushTheme, themeFromStackmyth } from './theme.js';
4
+ export { P as Permitted, a as PolicyPermission, b as PolicyRole, c as PushPolicyOptions, d as can, p as pushPolicy } from './permissions-B-a3eN0h.js';
5
+ import 'jose';
6
+
7
+ interface ConnectOptions {
8
+ /** The system's name, as its organizations are filed under: lowercase, digits, - or _. */
9
+ system: string;
10
+ /** The application's public address: `https://app.example.com`, or `http://localhost:3000` while developing. */
11
+ appUrl: string;
12
+ /** Shown to people on Cauthy's pages. Default: the system's name. */
13
+ name?: string;
14
+ /** Where the application serves the return from a sign-in. Default: `/api/auth/callback`. */
15
+ callbackPath?: string;
16
+ /** An https address of the application that receives Cauthy's events. */
17
+ eventsUrl?: string;
18
+ /** The events to receive. Default: all of them. */
19
+ events?: string[];
20
+ /** Where the application publishes its keys, to prove itself without a secret. */
21
+ jwksUri?: string;
22
+ /** Cauthy's address. Default: `CAUTHY_ISSUER`. */
23
+ issuer?: string;
24
+ /** The workspace's slug. Default: `CAUTHY_TENANT`. */
25
+ tenant?: string;
26
+ /** A personal access token with `systems:connect`. Default: `CAUTHY_TOKEN`. */
27
+ token?: string;
28
+ fetch?: typeof fetch;
29
+ }
30
+ interface Connected {
31
+ system: string;
32
+ clientId: string;
33
+ /** Shown this once: Cauthy keeps only its hash. */
34
+ clientSecret: string;
35
+ redirectUris: string[];
36
+ webhook: {
37
+ id: string;
38
+ url: string;
39
+ events: string[];
40
+ } | null;
41
+ /**
42
+ * Everything the application sets: what Cauthy answered, plus CAUTHY_SECRET,
43
+ * the key of the session cookie, generated here and known to nobody else.
44
+ */
45
+ env: Record<string, string>;
46
+ }
47
+ declare function connectSystem(o: ConnectOptions): Promise<Connected>;
48
+
49
+ export { type ConnectOptions, type Connected, connectSystem };