cauthy-auth 0.0.0-stage → 0.2.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/LICENSE +201 -0
- package/README.md +52 -2
- package/dist/cauthy-BrIMaoj1.d.mts +102 -0
- package/dist/cauthy-CCZc9w8r.d.ts +102 -0
- package/dist/cli.js +380 -0
- package/dist/fastify.d.mts +22 -0
- package/dist/fastify.d.ts +22 -0
- package/dist/fastify.js +81 -0
- package/dist/fastify.js.map +1 -0
- package/dist/fastify.mjs +56 -0
- package/dist/fastify.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +748 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +714 -0
- package/dist/index.mjs.map +1 -0
- package/dist/permissions-B-a3eN0h.d.mts +52 -0
- package/dist/permissions-B-a3eN0h.d.ts +52 -0
- package/dist/react.d.mts +38 -0
- package/dist/react.d.ts +38 -0
- package/dist/react.js +125 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +98 -0
- package/dist/react.mjs.map +1 -0
- package/dist/theme.d.mts +82 -0
- package/dist/theme.d.ts +82 -0
- package/dist/theme.js +254 -0
- package/dist/theme.js.map +1 -0
- package/dist/theme.mjs +226 -0
- package/dist/theme.mjs.map +1 -0
- package/dist/types-CYmUVWzY.d.mts +106 -0
- package/dist/types-CYmUVWzY.d.ts +106 -0
- package/package.json +84 -4
package/dist/theme.mjs
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
// src/theme.ts
|
|
2
|
+
var MAX_RADIUS = 40;
|
|
3
|
+
function declarations(css) {
|
|
4
|
+
const text = css.replace(/\/\*[\s\S]*?\*\//g, "");
|
|
5
|
+
const out2 = [];
|
|
6
|
+
const within = [];
|
|
7
|
+
let chunk = "";
|
|
8
|
+
let quote = "";
|
|
9
|
+
let depth = 0;
|
|
10
|
+
const flush = () => {
|
|
11
|
+
const m = /^\s*(--[\w-]+)\s*:\s*([\s\S]+?)\s*$/.exec(chunk);
|
|
12
|
+
if (m) out2.push({ name: m[1], value: m[2].replace(/\s+/g, " ").replace(/\s*!important$/, ""), within: [...within] });
|
|
13
|
+
chunk = "";
|
|
14
|
+
};
|
|
15
|
+
for (const ch of text) {
|
|
16
|
+
if (quote) {
|
|
17
|
+
chunk += ch;
|
|
18
|
+
if (ch === quote) quote = "";
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (ch === '"' || ch === "'") {
|
|
22
|
+
quote = ch;
|
|
23
|
+
chunk += ch;
|
|
24
|
+
} else if (ch === "(") {
|
|
25
|
+
depth++;
|
|
26
|
+
chunk += ch;
|
|
27
|
+
} else if (ch === ")") {
|
|
28
|
+
depth = Math.max(0, depth - 1);
|
|
29
|
+
chunk += ch;
|
|
30
|
+
} else if (ch === "{" && depth === 0) {
|
|
31
|
+
within.push(chunk.trim().replace(/\s+/g, " "));
|
|
32
|
+
chunk = "";
|
|
33
|
+
} else if (ch === "}" && depth === 0) {
|
|
34
|
+
flush();
|
|
35
|
+
within.pop();
|
|
36
|
+
} else if (ch === ";" && depth === 0) {
|
|
37
|
+
flush();
|
|
38
|
+
} else {
|
|
39
|
+
chunk += ch;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return out2;
|
|
43
|
+
}
|
|
44
|
+
var DARK = /prefers-color-scheme:\s*dark|data-(mode|theme|color-scheme)=["']?dark|\.dark\b/i;
|
|
45
|
+
var LIGHT = /prefers-color-scheme:\s*light|data-(mode|theme|color-scheme)=["']?light|\.light\b/i;
|
|
46
|
+
var NAMED = /data-theme=["']?([\w-]+)/i;
|
|
47
|
+
function applies(d, o) {
|
|
48
|
+
for (const scope of d.within) {
|
|
49
|
+
if (o.mode === "light" && DARK.test(scope)) return false;
|
|
50
|
+
if (o.mode === "dark" && LIGHT.test(scope)) return false;
|
|
51
|
+
const named = NAMED.exec(scope);
|
|
52
|
+
if (named && !/^(dark|light)$/i.test(named[1]) && named[1] !== o.theme) return false;
|
|
53
|
+
if (!scope.startsWith("@") && !/:root|^html\b|^body\b|\[data-|^\*$|:host/.test(scope)) return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
function resolve(value, vars, seen = 0) {
|
|
58
|
+
if (seen > 16) return null;
|
|
59
|
+
let unresolved = false;
|
|
60
|
+
let out2 = value;
|
|
61
|
+
for (let guard = 0; guard < 32 && /var\(/.test(out2); guard++) {
|
|
62
|
+
out2 = out2.replace(/var\(\s*(--[\w-]+)\s*(?:,\s*([^()]*(?:\([^()]*\)[^()]*)*))?\)/, (_m, name, fallback) => {
|
|
63
|
+
const known = vars.get(name);
|
|
64
|
+
const next = known !== void 0 ? resolve(known, vars, seen + 1) : fallback !== void 0 ? resolve(fallback.trim(), vars, seen + 1) : null;
|
|
65
|
+
if (next === null) unresolved = true;
|
|
66
|
+
return next ?? "";
|
|
67
|
+
});
|
|
68
|
+
if (unresolved) return null;
|
|
69
|
+
}
|
|
70
|
+
return /var\(/.test(out2) ? null : out2.trim();
|
|
71
|
+
}
|
|
72
|
+
var clamp01 = (n) => Math.min(1, Math.max(0, n));
|
|
73
|
+
var hex2 = (n) => Math.round(clamp01(n) * 255).toString(16).padStart(2, "0");
|
|
74
|
+
var gamma = (c) => c <= 31308e-7 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
|
|
75
|
+
function out(r, g, b, a = 1) {
|
|
76
|
+
if (a >= 1) return `#${hex2(r)}${hex2(g)}${hex2(b)}`;
|
|
77
|
+
return `rgba(${Math.round(clamp01(r) * 255)}, ${Math.round(clamp01(g) * 255)}, ${Math.round(clamp01(b) * 255)}, ${Math.round(clamp01(a) * 1e3) / 1e3})`;
|
|
78
|
+
}
|
|
79
|
+
var alpha = (s) => s === void 0 ? 1 : s.endsWith("%") ? parseFloat(s) / 100 : parseFloat(s);
|
|
80
|
+
var KEYWORDS = { white: "#ffffff", black: "#000000" };
|
|
81
|
+
function toColor(value) {
|
|
82
|
+
const v = value.trim().toLowerCase();
|
|
83
|
+
if (KEYWORDS[v]) return KEYWORDS[v];
|
|
84
|
+
if (/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(v)) return v;
|
|
85
|
+
let m = /^rgba?\(\s*([\d.]+%?)[\s,]+([\d.]+%?)[\s,]+([\d.]+%?)(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(v);
|
|
86
|
+
if (m) {
|
|
87
|
+
const ch = (s) => s.endsWith("%") ? parseFloat(s) / 100 : parseFloat(s) / 255;
|
|
88
|
+
return out(ch(m[1]), ch(m[2]), ch(m[3]), alpha(m[4]));
|
|
89
|
+
}
|
|
90
|
+
m = /^hsla?\(\s*([\d.]+)(?:deg)?[\s,]+([\d.]+)%[\s,]+([\d.]+)%(?:\s*[,/]\s*([\d.]+%?))?\s*\)$/.exec(v);
|
|
91
|
+
if (m) {
|
|
92
|
+
const h = (parseFloat(m[1]) % 360 + 360) % 360;
|
|
93
|
+
const s = parseFloat(m[2]) / 100;
|
|
94
|
+
const l = parseFloat(m[3]) / 100;
|
|
95
|
+
const f = (n) => {
|
|
96
|
+
const k = (n + h / 30) % 12;
|
|
97
|
+
return l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1));
|
|
98
|
+
};
|
|
99
|
+
return out(f(0), f(8), f(4), alpha(m[4]));
|
|
100
|
+
}
|
|
101
|
+
m = /^oklch\(\s*([\d.]+%?)\s+([\d.]+%?)\s+([\d.]+)(?:deg)?(?:\s*\/\s*([\d.]+%?))?\s*\)$/.exec(v);
|
|
102
|
+
if (m) {
|
|
103
|
+
const L = m[1].endsWith("%") ? parseFloat(m[1]) / 100 : parseFloat(m[1]);
|
|
104
|
+
const C = m[2].endsWith("%") ? parseFloat(m[2]) / 100 * 0.4 : parseFloat(m[2]);
|
|
105
|
+
const H = parseFloat(m[3]) * Math.PI / 180;
|
|
106
|
+
const a = C * Math.cos(H);
|
|
107
|
+
const b = C * Math.sin(H);
|
|
108
|
+
const l = Math.pow(L + 0.3963377774 * a + 0.2158037573 * b, 3);
|
|
109
|
+
const mm = Math.pow(L - 0.1055613458 * a - 0.0638541728 * b, 3);
|
|
110
|
+
const s = Math.pow(L - 0.0894841775 * a - 1.291485548 * b, 3);
|
|
111
|
+
return out(
|
|
112
|
+
gamma(4.0767416621 * l - 3.3077115913 * mm + 0.2309699292 * s),
|
|
113
|
+
gamma(-1.2684380046 * l + 2.6097574011 * mm - 0.3413193965 * s),
|
|
114
|
+
gamma(-0.0041960863 * l - 0.7034186147 * mm + 1.707614701 * s),
|
|
115
|
+
alpha(m[4])
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
function toRadius(value) {
|
|
121
|
+
const m = /^([\d.]+)(px|rem|em)?$/.exec(value.trim());
|
|
122
|
+
if (!m) return null;
|
|
123
|
+
const px = parseFloat(m[1]) * (m[2] === "rem" || m[2] === "em" ? 16 : 1);
|
|
124
|
+
return Number.isFinite(px) ? Math.min(MAX_RADIUS, Math.max(0, Math.round(px))) : null;
|
|
125
|
+
}
|
|
126
|
+
function toFont(value) {
|
|
127
|
+
const v = value.trim();
|
|
128
|
+
return /^[A-Za-z0-9 ,'"_-]{1,200}$/.test(v) && (v.match(/"/g)?.length ?? 0) % 2 === 0 && (v.match(/'/g)?.length ?? 0) % 2 === 0 ? v : null;
|
|
129
|
+
}
|
|
130
|
+
var COLORS = [
|
|
131
|
+
["background", ["--sm-bg-surface", "--sm-surface"]],
|
|
132
|
+
["surface", ["--sm-bg-surface-raised", "--sm-surface-raised"]],
|
|
133
|
+
["text", ["--sm-text-primary", "--sm-surface-text"]],
|
|
134
|
+
["textMuted", ["--sm-text-secondary"]],
|
|
135
|
+
["border", ["--sm-border-default", "--sm-surface-border"]],
|
|
136
|
+
["primary", ["--sm-primary", "--sm-bg-interactive"]],
|
|
137
|
+
["primaryText", ["--sm-primary-text", "--sm-text-inverse"]],
|
|
138
|
+
["accent", ["--sm-text-brand", "--sm-border-focus", "--sm-accent"]],
|
|
139
|
+
["error", ["--sm-error-soft-text", "--sm-error"]],
|
|
140
|
+
["errorBackground", ["--sm-error-soft"]],
|
|
141
|
+
["success", ["--sm-success-soft-text", "--sm-success"]],
|
|
142
|
+
["successBackground", ["--sm-success-soft"]]
|
|
143
|
+
];
|
|
144
|
+
function themeFromStackmyth(css, options = {}) {
|
|
145
|
+
const o = { mode: options.mode ?? "light", theme: options.theme };
|
|
146
|
+
const vars = /* @__PURE__ */ new Map();
|
|
147
|
+
for (const sheet of Array.isArray(css) ? css : [css]) {
|
|
148
|
+
for (const d of declarations(sheet)) if (applies(d, o)) vars.set(d.name, d.value);
|
|
149
|
+
}
|
|
150
|
+
const theme = {};
|
|
151
|
+
const warnings = [];
|
|
152
|
+
const read = (tokens, to, what) => {
|
|
153
|
+
for (const token of tokens) {
|
|
154
|
+
const raw = vars.get(token);
|
|
155
|
+
if (raw === void 0) continue;
|
|
156
|
+
const value = resolve(raw, vars);
|
|
157
|
+
const got = value === null ? null : to(value);
|
|
158
|
+
if (got !== null) return got;
|
|
159
|
+
warnings.push(`${token}: "${raw}" is not ${what} Cauthy can take`);
|
|
160
|
+
}
|
|
161
|
+
return void 0;
|
|
162
|
+
};
|
|
163
|
+
for (const [field, tokens] of COLORS) {
|
|
164
|
+
const c = read(tokens, toColor, "a colour");
|
|
165
|
+
if (c !== void 0) theme[field] = c;
|
|
166
|
+
}
|
|
167
|
+
const radius = read(["--sm-radius-container", "--sm-radius-md"], toRadius, "a length");
|
|
168
|
+
if (radius !== void 0) theme.radius = radius;
|
|
169
|
+
const button = read(["--sm-radius-interactive", "--sm-radius-sm"], toRadius, "a length");
|
|
170
|
+
if (button !== void 0) theme.buttonRadius = button;
|
|
171
|
+
const font = read(["--sm-font-family"], toFont, "a font list");
|
|
172
|
+
if (font !== void 0) theme.fontFamily = font;
|
|
173
|
+
if (options.logoUrl) theme.logoUrl = options.logoUrl;
|
|
174
|
+
if (vars.size === 0) warnings.push("no custom properties were found: is this the stylesheet that declares the --sm-* tokens?");
|
|
175
|
+
else if (![...vars.keys()].some((k) => k.startsWith("--sm-"))) warnings.push("no --sm-* token was found in these stylesheets");
|
|
176
|
+
return { theme, warnings };
|
|
177
|
+
}
|
|
178
|
+
function toWire(theme) {
|
|
179
|
+
const names = {
|
|
180
|
+
background: "background",
|
|
181
|
+
surface: "surface",
|
|
182
|
+
text: "text",
|
|
183
|
+
textMuted: "text_muted",
|
|
184
|
+
border: "border",
|
|
185
|
+
primary: "primary",
|
|
186
|
+
primaryText: "primary_text",
|
|
187
|
+
accent: "accent",
|
|
188
|
+
error: "error",
|
|
189
|
+
errorBackground: "error_background",
|
|
190
|
+
success: "success",
|
|
191
|
+
successBackground: "success_background",
|
|
192
|
+
radius: "radius",
|
|
193
|
+
buttonRadius: "button_radius",
|
|
194
|
+
fontFamily: "font_family",
|
|
195
|
+
logoUrl: "logo_url"
|
|
196
|
+
};
|
|
197
|
+
const wire = {};
|
|
198
|
+
for (const [k, v] of Object.entries(theme)) if (v !== void 0 && v !== "") wire[names[k]] = v;
|
|
199
|
+
return wire;
|
|
200
|
+
}
|
|
201
|
+
async function pushTheme(o) {
|
|
202
|
+
const env = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
|
|
203
|
+
const issuer = (o.issuer ?? env("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
|
|
204
|
+
const clientId = o.clientId ?? env("CAUTHY_CLIENT_ID") ?? "";
|
|
205
|
+
const tenant = o.tenant ?? env("CAUTHY_TENANT") ?? "";
|
|
206
|
+
const token = o.token ?? env("CAUTHY_TOKEN") ?? "";
|
|
207
|
+
for (const [name, v] of Object.entries({ CAUTHY_ISSUER: issuer, CAUTHY_CLIENT_ID: clientId, CAUTHY_TENANT: tenant, CAUTHY_TOKEN: token })) {
|
|
208
|
+
if (v === "") throw new Error(`cauthy-auth: ${name} is required to push a theme`);
|
|
209
|
+
}
|
|
210
|
+
const res = await (o.fetch ?? fetch)(`${issuer}/v1/oauth/clients/${encodeURIComponent(clientId)}/theme`, {
|
|
211
|
+
method: "PUT",
|
|
212
|
+
headers: { authorization: `Bearer ${token}`, "x-tenant-key": tenant, "content-type": "application/json" },
|
|
213
|
+
body: JSON.stringify(toWire(o.theme))
|
|
214
|
+
});
|
|
215
|
+
if (!res.ok) {
|
|
216
|
+
const body = await res.json().catch(() => null);
|
|
217
|
+
throw new Error(`cauthy-auth: Cauthy refused the theme (${res.status}): ${body?.errors?.[0]?.message ?? res.statusText}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export {
|
|
221
|
+
pushTheme,
|
|
222
|
+
themeFromStackmyth,
|
|
223
|
+
toColor,
|
|
224
|
+
toWire
|
|
225
|
+
};
|
|
226
|
+
//# sourceMappingURL=theme.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/theme.ts"],"sourcesContent":["// An application's look, for Cauthy's hosted pages.\n//\n// Cauthy's pages — sign-in, sign-up, the account page — can take the colours,\n// corners, typeface and logo of the application that sends its people there,\n// so signing in reads as a page of the application. A theme is a short list of\n// values, which Cauthy checks one by one; it is never CSS.\n//\n// An application built with Stackmyth already has those values, as its\n// `--sm-*` tokens. `themeFromStackmyth` reads them out of its stylesheets.\n\n/** How an application looks on Cauthy's hosted pages. Every value is optional. */\nexport interface CauthyTheme {\n /** The page. Colours are `#rrggbb` or `rgba(r, g, b, a)`. */\n background?: string\n /** The card, and inputs. */\n surface?: string\n /** Headings and what is typed. */\n text?: string\n /** Paragraphs, labels, small print. */\n textMuted?: string\n border?: string\n /** The main button, and what is written on it. */\n primary?: string\n primaryText?: string\n /** Links, and the focus ring. */\n accent?: string\n error?: string\n errorBackground?: string\n success?: string\n successBackground?: string\n /** Corners of cards and inputs, in pixels (0–40). */\n radius?: number\n /** Corners of buttons, in pixels (0–40). */\n buttonRadius?: number\n /** A CSS font-family list. Cauthy loads no font files: put a system font after the application's own. */\n fontFamily?: string\n /** An image shown where \"Cauthy\" is, over https. */\n logoUrl?: string\n}\n\nexport interface StackmythThemeOptions {\n /**\n * The named theme to read, when the stylesheet keeps several under\n * `[data-theme=…]` (`\"vennet\"`). Without it only what applies to every\n * page (`:root`) is read.\n */\n theme?: string\n /** Which of the application's two modes to take. Default: `light`. */\n mode?: 'light' | 'dark'\n logoUrl?: string\n}\n\nexport interface ImportedTheme {\n theme: CauthyTheme\n /** Tokens that were there and could not be carried over, and why. */\n warnings: string[]\n}\n\nconst MAX_RADIUS = 40\n\n// ── Reading custom properties out of CSS ───────────────────────────────────\n\ninterface Declaration {\n name: string\n value: string\n /** The selectors and at-rules it sits inside, outermost first. */\n within: string[]\n}\n\nfunction declarations(css: string): Declaration[] {\n const text = css.replace(/\\/\\*[\\s\\S]*?\\*\\//g, '')\n const out: Declaration[] = []\n const within: string[] = []\n let chunk = ''\n let quote = ''\n let depth = 0 // parentheses, so a `;` inside url(…) does not end anything\n const flush = () => {\n const m = /^\\s*(--[\\w-]+)\\s*:\\s*([\\s\\S]+?)\\s*$/.exec(chunk)\n if (m) out.push({ name: m[1], value: m[2].replace(/\\s+/g, ' ').replace(/\\s*!important$/, ''), within: [...within] })\n chunk = ''\n }\n for (const ch of text) {\n if (quote) {\n chunk += ch\n if (ch === quote) quote = ''\n continue\n }\n if (ch === '\"' || ch === \"'\") {\n quote = ch\n chunk += ch\n } else if (ch === '(') {\n depth++\n chunk += ch\n } else if (ch === ')') {\n depth = Math.max(0, depth - 1)\n chunk += ch\n } else if (ch === '{' && depth === 0) {\n within.push(chunk.trim().replace(/\\s+/g, ' '))\n chunk = ''\n } else if (ch === '}' && depth === 0) {\n flush()\n within.pop()\n } else if (ch === ';' && depth === 0) {\n flush()\n } else {\n chunk += ch\n }\n }\n return out\n}\n\nconst DARK = /prefers-color-scheme:\\s*dark|data-(mode|theme|color-scheme)=[\"']?dark|\\.dark\\b/i\nconst LIGHT = /prefers-color-scheme:\\s*light|data-(mode|theme|color-scheme)=[\"']?light|\\.light\\b/i\nconst NAMED = /data-theme=[\"']?([\\w-]+)/i\n\n/** Whether a declaration applies to the page being themed. */\nfunction applies(d: Declaration, o: Required<Pick<StackmythThemeOptions, 'mode'>> & { theme?: string }): boolean {\n for (const scope of d.within) {\n if (o.mode === 'light' && DARK.test(scope)) return false\n if (o.mode === 'dark' && LIGHT.test(scope)) return false\n const named = NAMED.exec(scope)\n if (named && !/^(dark|light)$/i.test(named[1]) && named[1] !== o.theme) return false\n // Component-level rules (`.btn { --sm-… }`) are not the page's theme.\n if (!scope.startsWith('@') && !/:root|^html\\b|^body\\b|\\[data-|^\\*$|:host/.test(scope)) return false\n }\n return true\n}\n\n// ── Values ─────────────────────────────────────────────────────────────────\n\nfunction resolve(value: string, vars: Map<string, string>, seen = 0): string | null {\n if (seen > 16) return null\n let unresolved = false\n // Innermost var() first: fallbacks may hold another var().\n let out = value\n for (let guard = 0; guard < 32 && /var\\(/.test(out); guard++) {\n out = out.replace(/var\\(\\s*(--[\\w-]+)\\s*(?:,\\s*([^()]*(?:\\([^()]*\\)[^()]*)*))?\\)/, (_m, name: string, fallback?: string) => {\n const known = vars.get(name)\n const next = known !== undefined ? resolve(known, vars, seen + 1) : fallback !== undefined ? resolve(fallback.trim(), vars, seen + 1) : null\n if (next === null) unresolved = true\n return next ?? ''\n })\n if (unresolved) return null\n }\n return /var\\(/.test(out) ? null : out.trim()\n}\n\nconst clamp01 = (n: number) => Math.min(1, Math.max(0, n))\nconst hex2 = (n: number) => Math.round(clamp01(n) * 255).toString(16).padStart(2, '0')\nconst gamma = (c: number) => (c <= 0.0031308 ? 12.92 * c : 1.055 * Math.pow(c, 1 / 2.4) - 0.055)\n\nfunction out(r: number, g: number, b: number, a = 1): string {\n if (a >= 1) return `#${hex2(r)}${hex2(g)}${hex2(b)}`\n return `rgba(${Math.round(clamp01(r) * 255)}, ${Math.round(clamp01(g) * 255)}, ${Math.round(clamp01(b) * 255)}, ${Math.round(clamp01(a) * 1000) / 1000})`\n}\n\nconst alpha = (s: string | undefined) => (s === undefined ? 1 : s.endsWith('%') ? parseFloat(s) / 100 : parseFloat(s))\n\nconst KEYWORDS: Record<string, string> = { white: '#ffffff', black: '#000000' }\n\n/** A colour as Cauthy takes it — `#rrggbb` or `rgba(…)` — or null when it is none it can read. */\nexport function toColor(value: string): string | null {\n const v = value.trim().toLowerCase()\n if (KEYWORDS[v]) return KEYWORDS[v]\n if (/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/.test(v)) return v\n let m = /^rgba?\\(\\s*([\\d.]+%?)[\\s,]+([\\d.]+%?)[\\s,]+([\\d.]+%?)(?:\\s*[,/]\\s*([\\d.]+%?))?\\s*\\)$/.exec(v)\n if (m) {\n const ch = (s: string) => (s.endsWith('%') ? parseFloat(s) / 100 : parseFloat(s) / 255)\n return out(ch(m[1]), ch(m[2]), ch(m[3]), alpha(m[4]))\n }\n m = /^hsla?\\(\\s*([\\d.]+)(?:deg)?[\\s,]+([\\d.]+)%[\\s,]+([\\d.]+)%(?:\\s*[,/]\\s*([\\d.]+%?))?\\s*\\)$/.exec(v)\n if (m) {\n const h = ((parseFloat(m[1]) % 360) + 360) % 360\n const s = parseFloat(m[2]) / 100\n const l = parseFloat(m[3]) / 100\n const f = (n: number) => {\n const k = (n + h / 30) % 12\n return l - s * Math.min(l, 1 - l) * Math.max(-1, Math.min(k - 3, 9 - k, 1))\n }\n return out(f(0), f(8), f(4), alpha(m[4]))\n }\n m = /^oklch\\(\\s*([\\d.]+%?)\\s+([\\d.]+%?)\\s+([\\d.]+)(?:deg)?(?:\\s*\\/\\s*([\\d.]+%?))?\\s*\\)$/.exec(v)\n if (m) {\n const L = m[1].endsWith('%') ? parseFloat(m[1]) / 100 : parseFloat(m[1])\n const C = m[2].endsWith('%') ? (parseFloat(m[2]) / 100) * 0.4 : parseFloat(m[2])\n const H = (parseFloat(m[3]) * Math.PI) / 180\n const a = C * Math.cos(H)\n const b = C * Math.sin(H)\n const l = Math.pow(L + 0.3963377774 * a + 0.2158037573 * b, 3)\n const mm = Math.pow(L - 0.1055613458 * a - 0.0638541728 * b, 3)\n const s = Math.pow(L - 0.0894841775 * a - 1.291485548 * b, 3)\n return out(\n gamma(4.0767416621 * l - 3.3077115913 * mm + 0.2309699292 * s),\n gamma(-1.2684380046 * l + 2.6097574011 * mm - 0.3413193965 * s),\n gamma(-0.0041960863 * l - 0.7034186147 * mm + 1.707614701 * s),\n alpha(m[4]),\n )\n }\n return null\n}\n\n/** A length in pixels, within what Cauthy takes, or null. */\nfunction toRadius(value: string): number | null {\n const m = /^([\\d.]+)(px|rem|em)?$/.exec(value.trim())\n if (!m) return null\n const px = parseFloat(m[1]) * (m[2] === 'rem' || m[2] === 'em' ? 16 : 1)\n return Number.isFinite(px) ? Math.min(MAX_RADIUS, Math.max(0, Math.round(px))) : null\n}\n\n/** A font list as Cauthy takes it, or null. */\nfunction toFont(value: string): string | null {\n const v = value.trim()\n return /^[A-Za-z0-9 ,'\"_-]{1,200}$/.test(v) && (v.match(/\"/g)?.length ?? 0) % 2 === 0 && (v.match(/'/g)?.length ?? 0) % 2 === 0 ? v : null\n}\n\n// ── Stackmyth ──────────────────────────────────────────────────────────────\n\n/** Which Stackmyth token each value of a theme is read from, first found wins. */\nconst COLORS: [keyof CauthyTheme, string[]][] = [\n ['background', ['--sm-bg-surface', '--sm-surface']],\n ['surface', ['--sm-bg-surface-raised', '--sm-surface-raised']],\n ['text', ['--sm-text-primary', '--sm-surface-text']],\n ['textMuted', ['--sm-text-secondary']],\n ['border', ['--sm-border-default', '--sm-surface-border']],\n ['primary', ['--sm-primary', '--sm-bg-interactive']],\n ['primaryText', ['--sm-primary-text', '--sm-text-inverse']],\n ['accent', ['--sm-text-brand', '--sm-border-focus', '--sm-accent']],\n ['error', ['--sm-error-soft-text', '--sm-error']],\n ['errorBackground', ['--sm-error-soft']],\n ['success', ['--sm-success-soft-text', '--sm-success']],\n ['successBackground', ['--sm-success-soft']],\n]\n\n/**\n * Reads an application's Stackmyth theme out of its stylesheets.\n *\n * Give it the CSS that declares the tokens, in the order the application\n * loads it — Stackmyth's own (`@stackmyth/core/core.vars.css`, or a theme\n * file) and then the application's brand file that re-points them. Tokens\n * that point at the application's own variables are followed. The\n * application's dark mode is left out unless asked for.\n */\nexport function themeFromStackmyth(css: string | string[], options: StackmythThemeOptions = {}): ImportedTheme {\n const o = { mode: options.mode ?? 'light', theme: options.theme }\n const vars = new Map<string, string>()\n for (const sheet of Array.isArray(css) ? css : [css]) {\n for (const d of declarations(sheet)) if (applies(d, o)) vars.set(d.name, d.value)\n }\n const theme: CauthyTheme = {}\n const warnings: string[] = []\n\n const read = <T>(tokens: string[], to: (v: string) => T | null, what: string): T | undefined => {\n for (const token of tokens) {\n const raw = vars.get(token)\n if (raw === undefined) continue\n const value = resolve(raw, vars)\n const got = value === null ? null : to(value)\n if (got !== null) return got\n warnings.push(`${token}: \"${raw}\" is not ${what} Cauthy can take`)\n }\n return undefined\n }\n\n for (const [field, tokens] of COLORS) {\n const c = read(tokens, toColor, 'a colour')\n if (c !== undefined) (theme as Record<string, unknown>)[field] = c\n }\n const radius = read(['--sm-radius-container', '--sm-radius-md'], toRadius, 'a length')\n if (radius !== undefined) theme.radius = radius\n const button = read(['--sm-radius-interactive', '--sm-radius-sm'], toRadius, 'a length')\n if (button !== undefined) theme.buttonRadius = button\n const font = read(['--sm-font-family'], toFont, 'a font list')\n if (font !== undefined) theme.fontFamily = font\n if (options.logoUrl) theme.logoUrl = options.logoUrl\n\n if (vars.size === 0) warnings.push('no custom properties were found: is this the stylesheet that declares the --sm-* tokens?')\n else if (![...vars.keys()].some((k) => k.startsWith('--sm-'))) warnings.push('no --sm-* token was found in these stylesheets')\n return { theme, warnings }\n}\n\n// ── Sending it to Cauthy ───────────────────────────────────────────────────\n\n/** A theme as Cauthy's API names its values. */\nexport function toWire(theme: CauthyTheme): Record<string, string | number> {\n const names: Record<keyof CauthyTheme, string> = {\n background: 'background', surface: 'surface', text: 'text', textMuted: 'text_muted', border: 'border',\n primary: 'primary', primaryText: 'primary_text', accent: 'accent', error: 'error', errorBackground: 'error_background',\n success: 'success', successBackground: 'success_background', radius: 'radius', buttonRadius: 'button_radius',\n fontFamily: 'font_family', logoUrl: 'logo_url',\n }\n const wire: Record<string, string | number> = {}\n for (const [k, v] of Object.entries(theme)) if (v !== undefined && v !== '') wire[names[k as keyof CauthyTheme]] = v as string | number\n return wire\n}\n\nexport interface PushThemeOptions {\n /** Cauthy's address. Default: `CAUTHY_ISSUER`. */\n issuer?: string\n /** The application's client id. Default: `CAUTHY_CLIENT_ID`. */\n clientId?: string\n /** The workspace's slug. Default: `CAUTHY_TENANT`. */\n tenant?: string\n /**\n * A personal access token with `oauth_clients:manage`. Default:\n * `CAUTHY_TOKEN`. It belongs in the deploy pipeline, never in the application.\n */\n token?: string\n theme: CauthyTheme\n fetch?: typeof fetch\n}\n\n/**\n * Gives the application its look on Cauthy's pages. It replaces the theme: a\n * value left out goes back to Cauthy's own. Run it when the brand changes —\n * from a script or the deploy — not on every request.\n */\nexport async function pushTheme(o: PushThemeOptions): Promise<void> {\n const env = (n: string) => (typeof process !== 'undefined' ? process.env?.[n] : undefined)\n const issuer = (o.issuer ?? env('CAUTHY_ISSUER') ?? '').replace(/\\/+$/, '')\n const clientId = o.clientId ?? env('CAUTHY_CLIENT_ID') ?? ''\n const tenant = o.tenant ?? env('CAUTHY_TENANT') ?? ''\n const token = o.token ?? env('CAUTHY_TOKEN') ?? ''\n for (const [name, v] of Object.entries({ CAUTHY_ISSUER: issuer, CAUTHY_CLIENT_ID: clientId, CAUTHY_TENANT: tenant, CAUTHY_TOKEN: token })) {\n if (v === '') throw new Error(`cauthy-auth: ${name} is required to push a theme`)\n }\n const res = await (o.fetch ?? fetch)(`${issuer}/v1/oauth/clients/${encodeURIComponent(clientId)}/theme`, {\n method: 'PUT',\n headers: { authorization: `Bearer ${token}`, 'x-tenant-key': tenant, 'content-type': 'application/json' },\n body: JSON.stringify(toWire(o.theme)),\n })\n if (!res.ok) {\n const body = (await res.json().catch(() => null)) as { errors?: { message?: string }[] } | null\n throw new Error(`cauthy-auth: Cauthy refused the theme (${res.status}): ${body?.errors?.[0]?.message ?? res.statusText}`)\n }\n}\n"],"mappings":";AA0DA,IAAM,aAAa;AAWnB,SAAS,aAAa,KAA4B;AAChD,QAAM,OAAO,IAAI,QAAQ,qBAAqB,EAAE;AAChD,QAAMA,OAAqB,CAAC;AAC5B,QAAM,SAAmB,CAAC;AAC1B,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,MAAI,QAAQ;AACZ,QAAM,QAAQ,MAAM;AAClB,UAAM,IAAI,sCAAsC,KAAK,KAAK;AAC1D,QAAI,EAAG,CAAAA,KAAI,KAAK,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,EAAE,QAAQ,QAAQ,GAAG,EAAE,QAAQ,kBAAkB,EAAE,GAAG,QAAQ,CAAC,GAAG,MAAM,EAAE,CAAC;AACnH,YAAQ;AAAA,EACV;AACA,aAAW,MAAM,MAAM;AACrB,QAAI,OAAO;AACT,eAAS;AACT,UAAI,OAAO,MAAO,SAAQ;AAC1B;AAAA,IACF;AACA,QAAI,OAAO,OAAO,OAAO,KAAK;AAC5B,cAAQ;AACR,eAAS;AAAA,IACX,WAAW,OAAO,KAAK;AACrB;AACA,eAAS;AAAA,IACX,WAAW,OAAO,KAAK;AACrB,cAAQ,KAAK,IAAI,GAAG,QAAQ,CAAC;AAC7B,eAAS;AAAA,IACX,WAAW,OAAO,OAAO,UAAU,GAAG;AACpC,aAAO,KAAK,MAAM,KAAK,EAAE,QAAQ,QAAQ,GAAG,CAAC;AAC7C,cAAQ;AAAA,IACV,WAAW,OAAO,OAAO,UAAU,GAAG;AACpC,YAAM;AACN,aAAO,IAAI;AAAA,IACb,WAAW,OAAO,OAAO,UAAU,GAAG;AACpC,YAAM;AAAA,IACR,OAAO;AACL,eAAS;AAAA,IACX;AAAA,EACF;AACA,SAAOA;AACT;A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OAAM,IAAI,MAAM,gBAAgB,IAAI,8BAA8B;AAAA,EAClF;AACA,QAAM,MAAM,OAAO,EAAE,SAAS,OAAO,GAAG,MAAM,qBAAqB,mBAAmB,QAAQ,CAAC,UAAU;AAAA,IACvG,QAAQ;AAAA,IACR,SAAS,EAAE,eAAe,UAAU,KAAK,IAAI,gBAAgB,QAAQ,gBAAgB,mBAAmB;AAAA,IACxG,MAAM,KAAK,UAAU,OAAO,EAAE,KAAK,CAAC;AAAA,EACtC,CAAC;AACD,MAAI,CAAC,IAAI,IAAI;AACX,UAAM,OAAQ,MAAM,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI;AAC/C,UAAM,IAAI,MAAM,0CAA0C,IAAI,MAAM,MAAM,MAAM,SAAS,CAAC,GAAG,WAAW,IAAI,UAAU,EAAE;AAAA,EAC1H;AACF;","names":["out"]}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** How an application is set up to sign its people in with Cauthy. */
|
|
2
|
+
interface CauthyOptions {
|
|
3
|
+
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
4
|
+
issuer?: string;
|
|
5
|
+
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
6
|
+
clientId?: string;
|
|
7
|
+
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
8
|
+
clientSecret?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The key the session cookie is encrypted with: any string of 32 characters
|
|
11
|
+
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
12
|
+
*/
|
|
13
|
+
secret?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The system this application is, as its organizations are filed under in
|
|
16
|
+
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
17
|
+
* system's. Default: `CAUTHY_SYSTEM`.
|
|
18
|
+
*/
|
|
19
|
+
system?: string;
|
|
20
|
+
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
21
|
+
basePath?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The application's own public origin (`https://app.example.com`), for the
|
|
24
|
+
* redirect URI. Default: the origin of each request, which is right unless
|
|
25
|
+
* a proxy hides it.
|
|
26
|
+
*/
|
|
27
|
+
baseURL?: string;
|
|
28
|
+
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
29
|
+
afterSignIn?: string;
|
|
30
|
+
/** Where a person lands after signing out. Default: `/`. */
|
|
31
|
+
afterSignOut?: string;
|
|
32
|
+
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
33
|
+
cookieName?: string;
|
|
34
|
+
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
}
|
|
37
|
+
/** The person signed in. Every moment is UTC. */
|
|
38
|
+
interface SessionUser {
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
name: string;
|
|
42
|
+
emailVerified: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* True when the account ran out of time to confirm its address: let it read
|
|
45
|
+
* and refuse its writes.
|
|
46
|
+
*/
|
|
47
|
+
restricted: boolean;
|
|
48
|
+
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
49
|
+
emailVerifyBy?: string;
|
|
50
|
+
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
51
|
+
locale?: string;
|
|
52
|
+
}
|
|
53
|
+
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
54
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
55
|
+
[key: string]: JsonValue;
|
|
56
|
+
};
|
|
57
|
+
/** An organization the person belongs to, with their role in it. */
|
|
58
|
+
interface SessionOrganization {
|
|
59
|
+
id: string;
|
|
60
|
+
system: string;
|
|
61
|
+
name: string;
|
|
62
|
+
kind: string;
|
|
63
|
+
externalId?: string;
|
|
64
|
+
role: string;
|
|
65
|
+
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
66
|
+
metadata: Record<string, JsonValue>;
|
|
67
|
+
/**
|
|
68
|
+
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
69
|
+
* their role's permissions, what it inherits, and anything given to them
|
|
70
|
+
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
71
|
+
* Check with `can(organization, resource, action)`.
|
|
72
|
+
*/
|
|
73
|
+
permissions?: string[];
|
|
74
|
+
/** What the person is denied here, whatever else allows it. */
|
|
75
|
+
denied?: string[];
|
|
76
|
+
}
|
|
77
|
+
/** A signed-in person, as the server sees them. */
|
|
78
|
+
interface Session {
|
|
79
|
+
user: SessionUser;
|
|
80
|
+
/** The Cauthy tenant the account is of. */
|
|
81
|
+
tenantId: string;
|
|
82
|
+
/** The roles the account holds in that tenant. */
|
|
83
|
+
roles: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
86
|
+
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
87
|
+
*/
|
|
88
|
+
accessToken: string;
|
|
89
|
+
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
90
|
+
expiresAt: string;
|
|
91
|
+
}
|
|
92
|
+
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
93
|
+
interface PublicSession {
|
|
94
|
+
user: SessionUser;
|
|
95
|
+
tenantId: string;
|
|
96
|
+
roles: string[];
|
|
97
|
+
organizations: SessionOrganization[];
|
|
98
|
+
expiresAt: string;
|
|
99
|
+
}
|
|
100
|
+
/** Why there is no session. */
|
|
101
|
+
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
102
|
+
declare class CauthyConfigError extends Error {
|
|
103
|
+
constructor(message: string);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { CauthyConfigError as C, type JsonValue as J, type PublicSession as P, type Session as S, type CauthyOptions as a, type SessionOrganization as b, type SessionStatus as c, type SessionUser as d };
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/** How an application is set up to sign its people in with Cauthy. */
|
|
2
|
+
interface CauthyOptions {
|
|
3
|
+
/** Cauthy's public address, e.g. `https://id.example.com`. Default: `CAUTHY_ISSUER`. */
|
|
4
|
+
issuer?: string;
|
|
5
|
+
/** The application's OAuth client id. Default: `CAUTHY_CLIENT_ID`. */
|
|
6
|
+
clientId?: string;
|
|
7
|
+
/** Its secret, when the client is confidential. Default: `CAUTHY_CLIENT_SECRET`. */
|
|
8
|
+
clientSecret?: string;
|
|
9
|
+
/**
|
|
10
|
+
* The key the session cookie is encrypted with: any string of 32 characters
|
|
11
|
+
* or more, kept on the server. Default: `CAUTHY_SECRET`.
|
|
12
|
+
*/
|
|
13
|
+
secret?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The system this application is, as its organizations are filed under in
|
|
16
|
+
* Cauthy (`"pondari"`). When set, a session's organizations are that
|
|
17
|
+
* system's. Default: `CAUTHY_SYSTEM`.
|
|
18
|
+
*/
|
|
19
|
+
system?: string;
|
|
20
|
+
/** Where the routes are mounted. Default: `/api/auth`. */
|
|
21
|
+
basePath?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The application's own public origin (`https://app.example.com`), for the
|
|
24
|
+
* redirect URI. Default: the origin of each request, which is right unless
|
|
25
|
+
* a proxy hides it.
|
|
26
|
+
*/
|
|
27
|
+
baseURL?: string;
|
|
28
|
+
/** Where a person lands after signing in, when no `return_to` was asked. Default: `/`. */
|
|
29
|
+
afterSignIn?: string;
|
|
30
|
+
/** Where a person lands after signing out. Default: `/`. */
|
|
31
|
+
afterSignOut?: string;
|
|
32
|
+
/** Name of the session cookie. Default: `cauthy_session`. */
|
|
33
|
+
cookieName?: string;
|
|
34
|
+
/** `fetch` to reach Cauthy with. Default: the global one. */
|
|
35
|
+
fetch?: typeof fetch;
|
|
36
|
+
}
|
|
37
|
+
/** The person signed in. Every moment is UTC. */
|
|
38
|
+
interface SessionUser {
|
|
39
|
+
id: string;
|
|
40
|
+
email: string;
|
|
41
|
+
name: string;
|
|
42
|
+
emailVerified: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* True when the account ran out of time to confirm its address: let it read
|
|
45
|
+
* and refuse its writes.
|
|
46
|
+
*/
|
|
47
|
+
restricted: boolean;
|
|
48
|
+
/** When an unconfirmed address stops being enough (ISO 8601, UTC), if there is a deadline. */
|
|
49
|
+
emailVerifyBy?: string;
|
|
50
|
+
/** The language the person reads in ("es", "en-US"), when Cauthy knows it. */
|
|
51
|
+
locale?: string;
|
|
52
|
+
}
|
|
53
|
+
/** A value JSON can carry. What crosses from server to browser is typed as this, never `unknown`. */
|
|
54
|
+
type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
55
|
+
[key: string]: JsonValue;
|
|
56
|
+
};
|
|
57
|
+
/** An organization the person belongs to, with their role in it. */
|
|
58
|
+
interface SessionOrganization {
|
|
59
|
+
id: string;
|
|
60
|
+
system: string;
|
|
61
|
+
name: string;
|
|
62
|
+
kind: string;
|
|
63
|
+
externalId?: string;
|
|
64
|
+
role: string;
|
|
65
|
+
/** What the system keeps about the organization, as it filed it in Cauthy. */
|
|
66
|
+
metadata: Record<string, JsonValue>;
|
|
67
|
+
/**
|
|
68
|
+
* What the person may do here, as "resource:action" entries ("*" is any):
|
|
69
|
+
* their role's permissions, what it inherits, and anything given to them
|
|
70
|
+
* apart from it. Absent when the system keeps no catalog of roles in Cauthy.
|
|
71
|
+
* Check with `can(organization, resource, action)`.
|
|
72
|
+
*/
|
|
73
|
+
permissions?: string[];
|
|
74
|
+
/** What the person is denied here, whatever else allows it. */
|
|
75
|
+
denied?: string[];
|
|
76
|
+
}
|
|
77
|
+
/** A signed-in person, as the server sees them. */
|
|
78
|
+
interface Session {
|
|
79
|
+
user: SessionUser;
|
|
80
|
+
/** The Cauthy tenant the account is of. */
|
|
81
|
+
tenantId: string;
|
|
82
|
+
/** The roles the account holds in that tenant. */
|
|
83
|
+
roles: string[];
|
|
84
|
+
/**
|
|
85
|
+
* Cauthy's access token for this person: send it as `Authorization: Bearer`
|
|
86
|
+
* to another service that verifies Cauthy's tokens. Never give it to the browser.
|
|
87
|
+
*/
|
|
88
|
+
accessToken: string;
|
|
89
|
+
/** When the access token expires and the session is checked with Cauthy again (ISO 8601, UTC). */
|
|
90
|
+
expiresAt: string;
|
|
91
|
+
}
|
|
92
|
+
/** What the browser is told of a session: who, and their organizations — never a token. */
|
|
93
|
+
interface PublicSession {
|
|
94
|
+
user: SessionUser;
|
|
95
|
+
tenantId: string;
|
|
96
|
+
roles: string[];
|
|
97
|
+
organizations: SessionOrganization[];
|
|
98
|
+
expiresAt: string;
|
|
99
|
+
}
|
|
100
|
+
/** Why there is no session. */
|
|
101
|
+
type SessionStatus = 'authenticated' | 'unauthenticated' | 'expired';
|
|
102
|
+
declare class CauthyConfigError extends Error {
|
|
103
|
+
constructor(message: string);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { CauthyConfigError as C, type JsonValue as J, type PublicSession as P, type Session as S, type CauthyOptions as a, type SessionOrganization as b, type SessionStatus as c, type SessionUser as d };
|
package/package.json
CHANGED
|
@@ -1,6 +1,86 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cauthy-auth",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Sign in with Cauthy: one route to mount, getSession on the server, useSession in the browser. No database, no screens to build.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.mjs",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./fastify": {
|
|
16
|
+
"types": "./dist/fastify.d.ts",
|
|
17
|
+
"import": "./dist/fastify.mjs",
|
|
18
|
+
"require": "./dist/fastify.js"
|
|
19
|
+
},
|
|
20
|
+
"./react": {
|
|
21
|
+
"types": "./dist/react.d.ts",
|
|
22
|
+
"import": "./dist/react.mjs",
|
|
23
|
+
"require": "./dist/react.js"
|
|
24
|
+
},
|
|
25
|
+
"./theme": {
|
|
26
|
+
"types": "./dist/theme.d.ts",
|
|
27
|
+
"import": "./dist/theme.mjs",
|
|
28
|
+
"require": "./dist/theme.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"README.md"
|
|
34
|
+
],
|
|
35
|
+
"sideEffects": false,
|
|
36
|
+
"scripts": {
|
|
37
|
+
"dev": "tsup --watch",
|
|
38
|
+
"build": "tsup",
|
|
39
|
+
"lint": "tsc --noEmit",
|
|
40
|
+
"test": "vitest run",
|
|
41
|
+
"test:watch": "vitest",
|
|
42
|
+
"typecheck": "tsc --noEmit"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"jose": "^5.9.0"
|
|
46
|
+
},
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"fastify": ">=4",
|
|
49
|
+
"react": ">=18"
|
|
50
|
+
},
|
|
51
|
+
"peerDependenciesMeta": {
|
|
52
|
+
"fastify": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
55
|
+
"react": {
|
|
56
|
+
"optional": true
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/node": "^20.0.0",
|
|
61
|
+
"@types/react": "^19.0.0",
|
|
62
|
+
"fastify": "^5.6.0",
|
|
63
|
+
"react": "^19.0.0",
|
|
64
|
+
"tsup": "^8.5.0",
|
|
65
|
+
"typescript": "^5.4.0",
|
|
66
|
+
"vitest": "^3.2.0"
|
|
67
|
+
},
|
|
68
|
+
"publishConfig": {
|
|
69
|
+
"access": "public"
|
|
70
|
+
},
|
|
71
|
+
"engines": {
|
|
72
|
+
"node": ">=20.0.0"
|
|
73
|
+
},
|
|
74
|
+
"keywords": [
|
|
75
|
+
"cauthy",
|
|
76
|
+
"auth",
|
|
77
|
+
"authentication",
|
|
78
|
+
"oauth",
|
|
79
|
+
"oidc",
|
|
80
|
+
"session",
|
|
81
|
+
"sso"
|
|
82
|
+
],
|
|
83
|
+
"bin": {
|
|
84
|
+
"cauthy-auth": "dist/cli.js"
|
|
85
|
+
}
|
|
86
|
+
}
|