@cauthyhq/node 0.0.0 → 1.0.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.
Files changed (62) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +180 -1
  4. package/dist/cauthy-B6Sm3T8M.d.ts +1035 -0
  5. package/dist/cauthy-ClP5orP4.d.mts +1035 -0
  6. package/dist/express.d.mts +25 -0
  7. package/dist/express.d.ts +25 -0
  8. package/dist/express.js +103 -0
  9. package/dist/express.js.map +1 -0
  10. package/dist/express.mjs +77 -0
  11. package/dist/express.mjs.map +1 -0
  12. package/dist/fastify.d.mts +38 -0
  13. package/dist/fastify.d.ts +38 -0
  14. package/dist/fastify.js +105 -0
  15. package/dist/fastify.js.map +1 -0
  16. package/dist/fastify.mjs +79 -0
  17. package/dist/fastify.mjs.map +1 -0
  18. package/dist/hono.d.mts +24 -0
  19. package/dist/hono.d.ts +24 -0
  20. package/dist/hono.js +51 -0
  21. package/dist/hono.js.map +1 -0
  22. package/dist/hono.mjs +25 -0
  23. package/dist/hono.mjs.map +1 -0
  24. package/dist/index.d.mts +138 -0
  25. package/dist/index.d.ts +138 -0
  26. package/dist/index.js +3474 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/index.mjs +3410 -0
  29. package/dist/index.mjs.map +1 -0
  30. package/dist/keys-D5k0omTb.d.mts +64 -0
  31. package/dist/keys-D5k0omTb.d.ts +64 -0
  32. package/dist/keys.d.mts +8 -0
  33. package/dist/keys.d.ts +8 -0
  34. package/dist/keys.js +157 -0
  35. package/dist/keys.js.map +1 -0
  36. package/dist/keys.mjs +129 -0
  37. package/dist/keys.mjs.map +1 -0
  38. package/dist/mcp.d.mts +151 -0
  39. package/dist/mcp.d.ts +151 -0
  40. package/dist/mcp.js +410 -0
  41. package/dist/mcp.js.map +1 -0
  42. package/dist/mcp.mjs +382 -0
  43. package/dist/mcp.mjs.map +1 -0
  44. package/dist/next.d.mts +24 -0
  45. package/dist/next.d.ts +24 -0
  46. package/dist/next.js +77 -0
  47. package/dist/next.js.map +1 -0
  48. package/dist/next.mjs +52 -0
  49. package/dist/next.mjs.map +1 -0
  50. package/dist/testing.d.mts +62 -0
  51. package/dist/testing.d.ts +62 -0
  52. package/dist/testing.js +182 -0
  53. package/dist/testing.js.map +1 -0
  54. package/dist/testing.mjs +156 -0
  55. package/dist/testing.mjs.map +1 -0
  56. package/dist/theme.d.mts +183 -0
  57. package/dist/theme.d.ts +183 -0
  58. package/dist/theme.js +531 -0
  59. package/dist/theme.js.map +1 -0
  60. package/dist/theme.mjs +496 -0
  61. package/dist/theme.mjs.map +1 -0
  62. package/package.json +185 -4
package/dist/hono.js ADDED
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/hono.ts
21
+ var hono_exports = {};
22
+ __export(hono_exports, {
23
+ cauthyHono: () => cauthyHono,
24
+ requireSession: () => requireSession
25
+ });
26
+ module.exports = __toCommonJS(hono_exports);
27
+ function cauthyHono(auth) {
28
+ const base = auth.options.basePath;
29
+ const key = auth.pact?.contract.jwksPath;
30
+ return async (c, next) => {
31
+ const path = new URL(c.req.url).pathname;
32
+ if (path === base || path.startsWith(`${base}/`) || path === key) return auth.handler(c.req.raw);
33
+ const resolved = await auth.resolve(c.req.raw);
34
+ c.set("session", resolved.session);
35
+ await next();
36
+ for (const cookie of resolved.cookies) c.header("set-cookie", cookie, { append: true });
37
+ };
38
+ }
39
+ var requireSession = async (c, next) => {
40
+ if (c.get("session") === null || c.get("session") === void 0) {
41
+ c.header("x-cauthy-session", "none");
42
+ return c.json({ error: "unauthenticated" }, 401);
43
+ }
44
+ await next();
45
+ };
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ cauthyHono,
49
+ requireSession
50
+ });
51
+ //# sourceMappingURL=hono.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hono.ts"],"sourcesContent":["// Hono: the routes, and who is signed in on every request.\n//\n// const app = new Hono<{ Variables: CauthyVariables }>()\n// app.use(cauthyHono(auth))\n//\n// app.get('/api/me', (c) => {\n// const session = c.get('session')\n// return session ? c.json(session.user) : c.json({ error: 'unauthenticated' }, 401)\n// })\n//\n// app.get('/api/books', requireSession, (c) => { … })\n//\n// A session that needs renewing is renewed on the spot, and its new cookie\n// leaves with whatever the route answers. It runs wherever Hono does.\n\nimport type { MiddlewareHandler } from 'hono'\nimport type { Cauthy } from './cauthy'\nimport type { Session } from './types'\n\n/** What the middleware keeps on the context: `new Hono<{ Variables: CauthyVariables }>()`. */\nexport interface CauthyVariables {\n /** Who is signed in, or null. */\n session: Session | null\n}\n\ntype Env = { Variables: CauthyVariables }\n\n/**\n * Serves the routes under the handler's `basePath` (and, by contract, the\n * application's published key), and sets `session` for\n * every other request. Mount it once, before the routes that use it.\n */\nexport function cauthyHono(auth: Cauthy): MiddlewareHandler<Env> {\n const base = auth.options.basePath\n // By contract the application also publishes its key, outside basePath.\n const key = auth.pact?.contract.jwksPath\n return async (c, next) => {\n const path = new URL(c.req.url).pathname\n if (path === base || path.startsWith(`${base}/`) || path === key) return auth.handler(c.req.raw)\n\n const resolved = await auth.resolve(c.req.raw)\n c.set('session', resolved.session)\n await next()\n for (const cookie of resolved.cookies) c.header('set-cookie', cookie, { append: true })\n }\n}\n\n/** For a route only a signed-in person may call: answers 401 otherwise. Needs `cauthyHono` mounted before it. */\nexport const requireSession: MiddlewareHandler<Env> = async (c, next) => {\n if (c.get('session') === null || c.get('session') === undefined) {\n c.header('x-cauthy-session', 'none')\n return c.json({ error: 'unauthenticated' }, 401)\n }\n await next()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCO,SAAS,WAAW,MAAsC;AAC/D,QAAM,OAAO,KAAK,QAAQ;AAE1B,QAAM,MAAM,KAAK,MAAM,SAAS;AAChC,SAAO,OAAO,GAAG,SAAS;AACxB,UAAM,OAAO,IAAI,IAAI,EAAE,IAAI,GAAG,EAAE;AAChC,QAAI,SAAS,QAAQ,KAAK,WAAW,GAAG,IAAI,GAAG,KAAK,SAAS,IAAK,QAAO,KAAK,QAAQ,EAAE,IAAI,GAAG;AAE/F,UAAM,WAAW,MAAM,KAAK,QAAQ,EAAE,IAAI,GAAG;AAC7C,MAAE,IAAI,WAAW,SAAS,OAAO;AACjC,UAAM,KAAK;AACX,eAAW,UAAU,SAAS,QAAS,GAAE,OAAO,cAAc,QAAQ,EAAE,QAAQ,KAAK,CAAC;AAAA,EACxF;AACF;AAGO,IAAM,iBAAyC,OAAO,GAAG,SAAS;AACvE,MAAI,EAAE,IAAI,SAAS,MAAM,QAAQ,EAAE,IAAI,SAAS,MAAM,QAAW;AAC/D,MAAE,OAAO,oBAAoB,MAAM;AACnC,WAAO,EAAE,KAAK,EAAE,OAAO,kBAAkB,GAAG,GAAG;AAAA,EACjD;AACA,QAAM,KAAK;AACb;","names":[]}
package/dist/hono.mjs ADDED
@@ -0,0 +1,25 @@
1
+ // src/hono.ts
2
+ function cauthyHono(auth) {
3
+ const base = auth.options.basePath;
4
+ const key = auth.pact?.contract.jwksPath;
5
+ return async (c, next) => {
6
+ const path = new URL(c.req.url).pathname;
7
+ if (path === base || path.startsWith(`${base}/`) || path === key) return auth.handler(c.req.raw);
8
+ const resolved = await auth.resolve(c.req.raw);
9
+ c.set("session", resolved.session);
10
+ await next();
11
+ for (const cookie of resolved.cookies) c.header("set-cookie", cookie, { append: true });
12
+ };
13
+ }
14
+ var requireSession = async (c, next) => {
15
+ if (c.get("session") === null || c.get("session") === void 0) {
16
+ c.header("x-cauthy-session", "none");
17
+ return c.json({ error: "unauthenticated" }, 401);
18
+ }
19
+ await next();
20
+ };
21
+ export {
22
+ cauthyHono,
23
+ requireSession
24
+ };
25
+ //# sourceMappingURL=hono.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hono.ts"],"sourcesContent":["// Hono: the routes, and who is signed in on every request.\n//\n// const app = new Hono<{ Variables: CauthyVariables }>()\n// app.use(cauthyHono(auth))\n//\n// app.get('/api/me', (c) => {\n// const session = c.get('session')\n// return session ? c.json(session.user) : c.json({ error: 'unauthenticated' }, 401)\n// })\n//\n// app.get('/api/books', requireSession, (c) => { … })\n//\n// A session that needs renewing is renewed on the spot, and its new cookie\n// leaves with whatever the route answers. It runs wherever Hono does.\n\nimport type { MiddlewareHandler } from 'hono'\nimport type { Cauthy } from './cauthy'\nimport type { Session } from './types'\n\n/** What the middleware keeps on the context: `new Hono<{ Variables: CauthyVariables }>()`. */\nexport interface CauthyVariables {\n /** Who is signed in, or null. */\n session: Session | null\n}\n\ntype Env = { Variables: CauthyVariables }\n\n/**\n * Serves the routes under the handler's `basePath` (and, by contract, the\n * application's published key), and sets `session` for\n * every other request. Mount it once, before the routes that use it.\n */\nexport function cauthyHono(auth: Cauthy): MiddlewareHandler<Env> {\n const base = auth.options.basePath\n // By contract the application also publishes its key, outside basePath.\n const key = auth.pact?.contract.jwksPath\n return async (c, next) => {\n const path = new URL(c.req.url).pathname\n if (path === base || path.startsWith(`${base}/`) || path === key) return auth.handler(c.req.raw)\n\n const resolved = await auth.resolve(c.req.raw)\n c.set('session', resolved.session)\n await next()\n for (const cookie of resolved.cookies) c.header('set-cookie', cookie, { append: true })\n }\n}\n\n/** For a route only a signed-in person may call: answers 401 otherwise. Needs `cauthyHono` mounted before it. */\nexport const requireSession: MiddlewareHandler<Env> = async (c, next) => {\n if (c.get('session') === null || c.get('session') === undefined) {\n c.header('x-cauthy-session', 'none')\n return c.json({ error: 'unauthenticated' }, 401)\n }\n await next()\n}\n"],"mappings":";AAgCO,SAAS,WAAW,MAAsC;AAC/D,QAAM,OAAO,KAAK,QAAQ;AAE1B,QAAM,MAAM,KAAK,MAAM,SAAS;AAChC,SAAO,OAAO,GAAG,SAAS;AACxB,UAAM,OAAO,IAAI,IAAI,EAAE,IAAI,GAAG,EAAE;AAChC,QAAI,SAAS,QAAQ,KAAK,WAAW,GAAG,IAAI,GAAG,KAAK,SAAS,IAAK,QAAO,KAAK,QAAQ,EAAE,IAAI,GAAG;AAE/F,UAAM,WAAW,MAAM,KAAK,QAAQ,EAAE,IAAI,GAAG;AAC7C,MAAE,IAAI,WAAW,SAAS,OAAO;AACjC,UAAM,KAAK;AACX,eAAW,UAAU,SAAS,QAAS,GAAE,OAAO,cAAc,QAAQ,EAAE,QAAQ,KAAK,CAAC;AAAA,EACxF;AACF;AAGO,IAAM,iBAAyC,OAAO,GAAG,SAAS;AACvE,MAAI,EAAE,IAAI,SAAS,MAAM,QAAQ,EAAE,IAAI,SAAS,MAAM,QAAW;AAC/D,MAAE,OAAO,oBAAoB,MAAM;AACnC,WAAO,EAAE,KAAK,EAAE,OAAO,kBAAkB,GAAG,GAAG;AAAA,EACjD;AACA,QAAM,KAAK;AACb;","names":[]}
@@ -0,0 +1,138 @@
1
+ export { A as AttributeType, a as CatalogResource, C as Cauthy, b as CauthyApiError, c as CauthyConfigError, d as CauthyEvent, e as CauthyOptions, f as CauthyPact, g as CauthySystem, h as CauthyTokenError, i as CauthyUnavailableError, j as CauthyWebhookError, k as CheckOf, l as CheckQuestion, m as CheckResult, n as CheckRule, o as ConditionalPermission, p as ContractOptions, J as JsonValue, M as MountTarget, N as NewMember, O as Organization, q as OrganizationMember, r as OrganizationRef, P as PactItem, s as PactStatus, t as PermissionOf, u as Permitted, v as Policy, w as PolicyDefinition, x as PolicyPermission, y as PolicyRole, z as PublicSession, B as PushPolicyOptions, R as ReplayStore, D as Resolved, E as ResolvedContract, F as RoleOf, G as STANDARD_VARIABLES, S as Session, H as SessionOrganization, I as SessionStatus, K as SessionUser, L as SystemKey, Q as SystemOptions, T as SystemPolicy, U as TokenIdentity, V as TokenRefusal, W as VerifyTokenOptions, X as VerifyWebhookOptions, Y as can, Z as createCauthy, _ as createSystem, $ as createTokenVerifier, a0 as definePolicy, a1 as failClosed, a2 as memoryReplayStore, a3 as policySource, a4 as pullCatalog, a5 as pullPolicy, a6 as pushCatalog, a7 as pushPolicy, a8 as readContract, a9 as remoteKeys, aa as verifyToken, ab as verifyWebhook } from './cauthy-ClP5orP4.mjs';
2
+ export { K as KeyStore, P as PactKeys, S as StoredKey } from './keys-D5k0omTb.mjs';
3
+ export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, StackmythTokens, ThemeFont, ThemeTexts, pushTheme, themeFromStackmyth, tokensFromStackmyth } from './theme.mjs';
4
+ import 'jose';
5
+
6
+ interface ConnectOptions {
7
+ /** The system's name, as its organizations are filed under: lowercase, digits, - or _. */
8
+ system: string;
9
+ /** The application's public address: `https://app.example.com`, or `http://localhost:3000` while developing. */
10
+ appUrl: string;
11
+ /** Shown to people on Cauthy's pages. Default: the system's name. */
12
+ name?: string;
13
+ /** Where the application serves the return from a sign-in. Default: `/api/auth/callback`. */
14
+ callbackPath?: string;
15
+ /** An https address of the application that receives Cauthy's events. */
16
+ eventsUrl?: string;
17
+ /** The events to receive. Default: all of them. */
18
+ events?: string[];
19
+ /** Where the application publishes its keys, to prove itself without a secret. */
20
+ jwksUri?: string;
21
+ /** Cauthy's address. Default: `CAUTHY_ISSUER`. */
22
+ issuer?: string;
23
+ /** The workspace's slug. Default: `CAUTHY_TENANT`. */
24
+ tenant?: string;
25
+ /** A personal access token with `systems:connect`. Default: `CAUTHY_TOKEN`. */
26
+ token?: string;
27
+ fetch?: typeof fetch;
28
+ /** How long the call may take, in milliseconds, before it fails with a `TimeoutError`. Default: 5000. */
29
+ timeoutMs?: number;
30
+ }
31
+ interface Connected {
32
+ system: string;
33
+ clientId: string;
34
+ /** Shown this once: Cauthy keeps only its hash. */
35
+ clientSecret: string;
36
+ redirectUris: string[];
37
+ /**
38
+ * The subscription to events, when `eventsUrl` was given. Its `secret` signs
39
+ * the HMAC header (X-Cauthy-Signature) and is shown this once; `auth.webhook`
40
+ * does not need it, as it verifies by Cauthy's published keys.
41
+ */
42
+ webhook: {
43
+ id: string;
44
+ url: string;
45
+ events: string[];
46
+ secret: string;
47
+ } | null;
48
+ /**
49
+ * Everything the application sets: what Cauthy answered, plus CAUTHY_SECRET,
50
+ * the key of the session cookie, generated here and known to nobody else.
51
+ */
52
+ env: Record<string, string>;
53
+ }
54
+ /** @deprecated Connect a system with the cauthy CLI (`npx cauthy init`); leaves in 2.0. */
55
+ declare function connectSystem(o: ConnectOptions): Promise<Connected>;
56
+
57
+ type AuthField = 'email' | 'password' | 'newPassword' | 'name' | 'code' | 'organization';
58
+ /** A value of a form that cannot be sent as it is. */
59
+ interface FieldProblem {
60
+ field: AuthField;
61
+ /**
62
+ * Stable, for translating: `required`, `invalid_email`, `too_short`,
63
+ * `too_long`, and for a new password the rule of the workspace it fails:
64
+ * `needs_lowercase`, `needs_uppercase`, `needs_digit`, `needs_symbol`,
65
+ * `needs_classes`.
66
+ */
67
+ code: 'required' | 'invalid_email' | PasswordReason;
68
+ message: string;
69
+ }
70
+ /** The shortest password Cauthy takes by default: a workspace's policy may ask otherwise (`methods().password`). */
71
+ declare const MIN_PASSWORD = 12;
72
+ /** A kind of character a workspace's password policy can ask for. */
73
+ type PasswordClass = 'lowercase' | 'uppercase' | 'digit' | 'symbol';
74
+ /** Why a new password is refused: the API's `weak_password` `meta.reasons`. */
75
+ type PasswordReason = 'too_short' | 'too_long' | 'needs_lowercase' | 'needs_uppercase' | 'needs_digit' | 'needs_symbol' | 'needs_classes' | 'breached';
76
+ /**
77
+ * What a new password must be in the workspace, as `methods().password` says
78
+ * it. Length is counted in bytes of UTF-8, as Cauthy counts it. A symbol is
79
+ * any character that is neither a letter nor a digit, a space included.
80
+ */
81
+ interface PasswordPolicy {
82
+ min: number;
83
+ max: number;
84
+ /** The kinds the password must each carry at least once. */
85
+ requires: PasswordClass[];
86
+ /** At least this many of the four kinds; 0 asks none. */
87
+ min_classes: number;
88
+ /** Cauthy refuses a password found in a published breach (checked by Cauthy alone). */
89
+ reject_breached: boolean;
90
+ }
91
+ /** The policy of a workspace that set none: what every one asked before they could choose. */
92
+ declare const DEFAULT_PASSWORD_POLICY: PasswordPolicy;
93
+ /**
94
+ * A password policy as Cauthy sent it — `{ min_length, max_length, … }` from
95
+ * the sign-in settings, or `{ min, max, … }` from `methods()` — made safe to
96
+ * use: the defaults where nothing is said, and never outside 8–128.
97
+ */
98
+ declare function passwordPolicyOf(raw: unknown): PasswordPolicy;
99
+ /**
100
+ * Every rule of the policy a new password fails, as the API names them;
101
+ * empty when it meets them all. Whether it was in a breach only Cauthy knows.
102
+ */
103
+ declare function passwordProblems(value: string, policy?: PasswordPolicy): PasswordReason[];
104
+ /** The languages the rule is said in. */
105
+ type PasswordLocale = 'en' | 'es';
106
+ /** What a new password must be, said for the person choosing it: "Between 12 and 128 characters. Include a digit." */
107
+ declare function describePasswordPolicy(policy?: PasswordPolicy, locale?: PasswordLocale): string;
108
+ /** Why a new password was refused, rule by rule, for the person who typed it. */
109
+ declare function explainPasswordProblems(reasons: readonly string[], policy?: PasswordPolicy, locale?: PasswordLocale): string;
110
+ declare function checkEmail(value: unknown): FieldProblem | null;
111
+ /** A password being typed to sign in: only that there is one. */
112
+ declare function checkPassword(value: unknown): FieldProblem | null;
113
+ /**
114
+ * A password being chosen for a new account, or a new one for an account.
115
+ * Held to the workspace's policy when it is given (`methods().password`),
116
+ * otherwise to the defaults: 12 to 128 characters.
117
+ */
118
+ declare function checkNewPassword(value: unknown, policy?: PasswordPolicy | null): FieldProblem | null;
119
+ declare function checkName(value: unknown): FieldProblem | null;
120
+ declare function checkCode(value: unknown): FieldProblem | null;
121
+
122
+ declare const PROTOCOL_VERSION = "1";
123
+ /**
124
+ * What the screen does after a sign-in answer:
125
+ *
126
+ * - `done`: signed in; go on.
127
+ * - `mfa`: ask for the second step (the code, or the push's approval).
128
+ * - `verify_email`: the address must be confirmed first.
129
+ * - `code`: a code (or link) was mailed; ask for the code.
130
+ * - `passkey`: run the passkey ceremony with the options in the answer.
131
+ * - `one_tap`: show Google's prompt with the client and nonce in the answer,
132
+ * then post the credential it gives.
133
+ * - `redirect`: go to the URL the answer carries. Reserved for answers that
134
+ * have one; no route of version 1 answers it yet.
135
+ */
136
+ type NextStep = 'done' | 'mfa' | 'verify_email' | 'code' | 'passkey' | 'one_tap' | 'redirect';
137
+
138
+ export { type AuthField, type ConnectOptions, type Connected, DEFAULT_PASSWORD_POLICY, type FieldProblem, MIN_PASSWORD, type NextStep, PROTOCOL_VERSION, type PasswordClass, type PasswordLocale, type PasswordPolicy, type PasswordReason, checkCode, checkEmail, checkName, checkNewPassword, checkPassword, connectSystem, describePasswordPolicy, explainPasswordProblems, passwordPolicyOf, passwordProblems };
@@ -0,0 +1,138 @@
1
+ export { A as AttributeType, a as CatalogResource, C as Cauthy, b as CauthyApiError, c as CauthyConfigError, d as CauthyEvent, e as CauthyOptions, f as CauthyPact, g as CauthySystem, h as CauthyTokenError, i as CauthyUnavailableError, j as CauthyWebhookError, k as CheckOf, l as CheckQuestion, m as CheckResult, n as CheckRule, o as ConditionalPermission, p as ContractOptions, J as JsonValue, M as MountTarget, N as NewMember, O as Organization, q as OrganizationMember, r as OrganizationRef, P as PactItem, s as PactStatus, t as PermissionOf, u as Permitted, v as Policy, w as PolicyDefinition, x as PolicyPermission, y as PolicyRole, z as PublicSession, B as PushPolicyOptions, R as ReplayStore, D as Resolved, E as ResolvedContract, F as RoleOf, G as STANDARD_VARIABLES, S as Session, H as SessionOrganization, I as SessionStatus, K as SessionUser, L as SystemKey, Q as SystemOptions, T as SystemPolicy, U as TokenIdentity, V as TokenRefusal, W as VerifyTokenOptions, X as VerifyWebhookOptions, Y as can, Z as createCauthy, _ as createSystem, $ as createTokenVerifier, a0 as definePolicy, a1 as failClosed, a2 as memoryReplayStore, a3 as policySource, a4 as pullCatalog, a5 as pullPolicy, a6 as pushCatalog, a7 as pushPolicy, a8 as readContract, a9 as remoteKeys, aa as verifyToken, ab as verifyWebhook } from './cauthy-B6Sm3T8M.js';
2
+ export { K as KeyStore, P as PactKeys, S as StoredKey } from './keys-D5k0omTb.js';
3
+ export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, StackmythTokens, ThemeFont, ThemeTexts, pushTheme, themeFromStackmyth, tokensFromStackmyth } from './theme.js';
4
+ import 'jose';
5
+
6
+ interface ConnectOptions {
7
+ /** The system's name, as its organizations are filed under: lowercase, digits, - or _. */
8
+ system: string;
9
+ /** The application's public address: `https://app.example.com`, or `http://localhost:3000` while developing. */
10
+ appUrl: string;
11
+ /** Shown to people on Cauthy's pages. Default: the system's name. */
12
+ name?: string;
13
+ /** Where the application serves the return from a sign-in. Default: `/api/auth/callback`. */
14
+ callbackPath?: string;
15
+ /** An https address of the application that receives Cauthy's events. */
16
+ eventsUrl?: string;
17
+ /** The events to receive. Default: all of them. */
18
+ events?: string[];
19
+ /** Where the application publishes its keys, to prove itself without a secret. */
20
+ jwksUri?: string;
21
+ /** Cauthy's address. Default: `CAUTHY_ISSUER`. */
22
+ issuer?: string;
23
+ /** The workspace's slug. Default: `CAUTHY_TENANT`. */
24
+ tenant?: string;
25
+ /** A personal access token with `systems:connect`. Default: `CAUTHY_TOKEN`. */
26
+ token?: string;
27
+ fetch?: typeof fetch;
28
+ /** How long the call may take, in milliseconds, before it fails with a `TimeoutError`. Default: 5000. */
29
+ timeoutMs?: number;
30
+ }
31
+ interface Connected {
32
+ system: string;
33
+ clientId: string;
34
+ /** Shown this once: Cauthy keeps only its hash. */
35
+ clientSecret: string;
36
+ redirectUris: string[];
37
+ /**
38
+ * The subscription to events, when `eventsUrl` was given. Its `secret` signs
39
+ * the HMAC header (X-Cauthy-Signature) and is shown this once; `auth.webhook`
40
+ * does not need it, as it verifies by Cauthy's published keys.
41
+ */
42
+ webhook: {
43
+ id: string;
44
+ url: string;
45
+ events: string[];
46
+ secret: string;
47
+ } | null;
48
+ /**
49
+ * Everything the application sets: what Cauthy answered, plus CAUTHY_SECRET,
50
+ * the key of the session cookie, generated here and known to nobody else.
51
+ */
52
+ env: Record<string, string>;
53
+ }
54
+ /** @deprecated Connect a system with the cauthy CLI (`npx cauthy init`); leaves in 2.0. */
55
+ declare function connectSystem(o: ConnectOptions): Promise<Connected>;
56
+
57
+ type AuthField = 'email' | 'password' | 'newPassword' | 'name' | 'code' | 'organization';
58
+ /** A value of a form that cannot be sent as it is. */
59
+ interface FieldProblem {
60
+ field: AuthField;
61
+ /**
62
+ * Stable, for translating: `required`, `invalid_email`, `too_short`,
63
+ * `too_long`, and for a new password the rule of the workspace it fails:
64
+ * `needs_lowercase`, `needs_uppercase`, `needs_digit`, `needs_symbol`,
65
+ * `needs_classes`.
66
+ */
67
+ code: 'required' | 'invalid_email' | PasswordReason;
68
+ message: string;
69
+ }
70
+ /** The shortest password Cauthy takes by default: a workspace's policy may ask otherwise (`methods().password`). */
71
+ declare const MIN_PASSWORD = 12;
72
+ /** A kind of character a workspace's password policy can ask for. */
73
+ type PasswordClass = 'lowercase' | 'uppercase' | 'digit' | 'symbol';
74
+ /** Why a new password is refused: the API's `weak_password` `meta.reasons`. */
75
+ type PasswordReason = 'too_short' | 'too_long' | 'needs_lowercase' | 'needs_uppercase' | 'needs_digit' | 'needs_symbol' | 'needs_classes' | 'breached';
76
+ /**
77
+ * What a new password must be in the workspace, as `methods().password` says
78
+ * it. Length is counted in bytes of UTF-8, as Cauthy counts it. A symbol is
79
+ * any character that is neither a letter nor a digit, a space included.
80
+ */
81
+ interface PasswordPolicy {
82
+ min: number;
83
+ max: number;
84
+ /** The kinds the password must each carry at least once. */
85
+ requires: PasswordClass[];
86
+ /** At least this many of the four kinds; 0 asks none. */
87
+ min_classes: number;
88
+ /** Cauthy refuses a password found in a published breach (checked by Cauthy alone). */
89
+ reject_breached: boolean;
90
+ }
91
+ /** The policy of a workspace that set none: what every one asked before they could choose. */
92
+ declare const DEFAULT_PASSWORD_POLICY: PasswordPolicy;
93
+ /**
94
+ * A password policy as Cauthy sent it — `{ min_length, max_length, … }` from
95
+ * the sign-in settings, or `{ min, max, … }` from `methods()` — made safe to
96
+ * use: the defaults where nothing is said, and never outside 8–128.
97
+ */
98
+ declare function passwordPolicyOf(raw: unknown): PasswordPolicy;
99
+ /**
100
+ * Every rule of the policy a new password fails, as the API names them;
101
+ * empty when it meets them all. Whether it was in a breach only Cauthy knows.
102
+ */
103
+ declare function passwordProblems(value: string, policy?: PasswordPolicy): PasswordReason[];
104
+ /** The languages the rule is said in. */
105
+ type PasswordLocale = 'en' | 'es';
106
+ /** What a new password must be, said for the person choosing it: "Between 12 and 128 characters. Include a digit." */
107
+ declare function describePasswordPolicy(policy?: PasswordPolicy, locale?: PasswordLocale): string;
108
+ /** Why a new password was refused, rule by rule, for the person who typed it. */
109
+ declare function explainPasswordProblems(reasons: readonly string[], policy?: PasswordPolicy, locale?: PasswordLocale): string;
110
+ declare function checkEmail(value: unknown): FieldProblem | null;
111
+ /** A password being typed to sign in: only that there is one. */
112
+ declare function checkPassword(value: unknown): FieldProblem | null;
113
+ /**
114
+ * A password being chosen for a new account, or a new one for an account.
115
+ * Held to the workspace's policy when it is given (`methods().password`),
116
+ * otherwise to the defaults: 12 to 128 characters.
117
+ */
118
+ declare function checkNewPassword(value: unknown, policy?: PasswordPolicy | null): FieldProblem | null;
119
+ declare function checkName(value: unknown): FieldProblem | null;
120
+ declare function checkCode(value: unknown): FieldProblem | null;
121
+
122
+ declare const PROTOCOL_VERSION = "1";
123
+ /**
124
+ * What the screen does after a sign-in answer:
125
+ *
126
+ * - `done`: signed in; go on.
127
+ * - `mfa`: ask for the second step (the code, or the push's approval).
128
+ * - `verify_email`: the address must be confirmed first.
129
+ * - `code`: a code (or link) was mailed; ask for the code.
130
+ * - `passkey`: run the passkey ceremony with the options in the answer.
131
+ * - `one_tap`: show Google's prompt with the client and nonce in the answer,
132
+ * then post the credential it gives.
133
+ * - `redirect`: go to the URL the answer carries. Reserved for answers that
134
+ * have one; no route of version 1 answers it yet.
135
+ */
136
+ type NextStep = 'done' | 'mfa' | 'verify_email' | 'code' | 'passkey' | 'one_tap' | 'redirect';
137
+
138
+ export { type AuthField, type ConnectOptions, type Connected, DEFAULT_PASSWORD_POLICY, type FieldProblem, MIN_PASSWORD, type NextStep, PROTOCOL_VERSION, type PasswordClass, type PasswordLocale, type PasswordPolicy, type PasswordReason, checkCode, checkEmail, checkName, checkNewPassword, checkPassword, connectSystem, describePasswordPolicy, explainPasswordProblems, passwordPolicyOf, passwordProblems };