cauthy-auth 0.24.0 → 0.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +31 -8
- package/dist/client.js +9 -2
- package/dist/client.js.map +1 -1
- package/dist/client.mjs +9 -2
- package/dist/client.mjs.map +1 -1
- package/dist/index.js +56 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +56 -14
- package/dist/index.mjs.map +1 -1
- package/dist/mcp.js +12 -3
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs +12 -3
- package/dist/mcp.mjs.map +1 -1
- package/dist/react.js +24 -4
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +24 -4
- package/dist/react.mjs.map +1 -1
- package/dist/svelte.js +9 -2
- package/dist/svelte.js.map +1 -1
- package/dist/svelte.mjs +9 -2
- package/dist/svelte.mjs.map +1 -1
- package/dist/theme.js +29 -4
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +27 -4
- package/dist/theme.mjs.map +1 -1
- package/dist/vue.js +9 -2
- package/dist/vue.js.map +1 -1
- package/dist/vue.mjs +9 -2
- package/dist/vue.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -105,10 +105,29 @@ async function unseal(sealed, key) {
|
|
|
105
105
|
// src/system.ts
|
|
106
106
|
var import_jose2 = require("jose");
|
|
107
107
|
|
|
108
|
+
// src/url.ts
|
|
109
|
+
function withoutTrailingSlashes(s) {
|
|
110
|
+
let end = s.length;
|
|
111
|
+
while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
|
|
112
|
+
return s.slice(0, end);
|
|
113
|
+
}
|
|
114
|
+
|
|
108
115
|
// src/theme.ts
|
|
109
116
|
var MAX_RADIUS = 40;
|
|
117
|
+
function withoutComments(css) {
|
|
118
|
+
let out2 = "";
|
|
119
|
+
let i = 0;
|
|
120
|
+
for (; ; ) {
|
|
121
|
+
const open = css.indexOf("/*", i);
|
|
122
|
+
if (open < 0) return out2 + css.slice(i);
|
|
123
|
+
out2 += css.slice(i, open);
|
|
124
|
+
const close = css.indexOf("*/", open + 2);
|
|
125
|
+
if (close < 0) return out2;
|
|
126
|
+
i = close + 2;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
110
129
|
function declarations(css) {
|
|
111
|
-
const text = css
|
|
130
|
+
const text = withoutComments(css);
|
|
112
131
|
const out2 = [];
|
|
113
132
|
const within = [];
|
|
114
133
|
let chunk = "";
|
|
@@ -203,7 +222,11 @@ function tokenValue(value) {
|
|
|
203
222
|
if (/^\(|[ ,(]\(/.test(v)) return null;
|
|
204
223
|
return v;
|
|
205
224
|
}
|
|
206
|
-
var
|
|
225
|
+
var THEME_SELECTOR = /^(?::root|html|body|\[data-(?:theme|mode|color-scheme)(?:=["']?[\w-]+["']?)?\])$/i;
|
|
226
|
+
var isThemeScope = (selectors) => {
|
|
227
|
+
const parts = selectors.split(/[\s,]+/).filter(Boolean);
|
|
228
|
+
return parts.length > 0 && parts.every((one) => THEME_SELECTOR.test(one));
|
|
229
|
+
};
|
|
207
230
|
function tokensFromStackmyth(css, options = {}) {
|
|
208
231
|
const mode = options.mode ?? "light";
|
|
209
232
|
const all = (Array.isArray(css) ? css : [css]).flatMap(declarations);
|
|
@@ -211,7 +234,7 @@ function tokensFromStackmyth(css, options = {}) {
|
|
|
211
234
|
const vars = /* @__PURE__ */ new Map();
|
|
212
235
|
for (const d of all) {
|
|
213
236
|
if (!applies(d, { mode, theme: named })) continue;
|
|
214
|
-
if (!d.within.every((w) => w.startsWith("@") ||
|
|
237
|
+
if (!d.within.every((w) => w.startsWith("@") || isThemeScope(w))) continue;
|
|
215
238
|
vars.set(d.name, d.value);
|
|
216
239
|
}
|
|
217
240
|
const inline = (value, depth = 0) => {
|
|
@@ -433,7 +456,7 @@ function fromWire(wire) {
|
|
|
433
456
|
}
|
|
434
457
|
async function pushTheme(o) {
|
|
435
458
|
const env4 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
|
|
436
|
-
const issuer = (o.issuer ?? env4("CAUTHY_ISSUER") ?? "")
|
|
459
|
+
const issuer = withoutTrailingSlashes(o.issuer ?? env4("CAUTHY_ISSUER") ?? "");
|
|
437
460
|
const clientId = o.clientId ?? env4("CAUTHY_CLIENT_ID") ?? "";
|
|
438
461
|
const tenant = o.tenant ?? env4("CAUTHY_TENANT") ?? "";
|
|
439
462
|
const token = o.token ?? env4("CAUTHY_TOKEN") ?? "";
|
|
@@ -501,7 +524,7 @@ async function loadKey(k) {
|
|
|
501
524
|
return jwk ? (0, import_jose2.importJWK)(jwk, "RS256") : (0, import_jose2.importPKCS8)(k.privateKey, "RS256", { extractable: true });
|
|
502
525
|
}
|
|
503
526
|
function createSystem(given = {}) {
|
|
504
|
-
const issuer = (given.issuer ?? env("CAUTHY_ISSUER") ?? "")
|
|
527
|
+
const issuer = withoutTrailingSlashes(given.issuer ?? env("CAUTHY_ISSUER") ?? "");
|
|
505
528
|
const clientId = given.clientId ?? env("CAUTHY_CLIENT_ID") ?? "";
|
|
506
529
|
const clientSecret = given.clientSecret ?? env("CAUTHY_CLIENT_SECRET") ?? "";
|
|
507
530
|
const envKey = env("CAUTHY_SYSTEM_KEY");
|
|
@@ -690,7 +713,7 @@ function keysOf(issuer) {
|
|
|
690
713
|
var hex = (s) => typeof s === "string" && s !== "" ? s : void 0;
|
|
691
714
|
async function verifyWebhook(request, options = {}) {
|
|
692
715
|
const env4 = typeof process !== "undefined" ? process.env?.CAUTHY_ISSUER : void 0;
|
|
693
|
-
const issuer = (options.issuer ?? env4 ?? "")
|
|
716
|
+
const issuer = withoutTrailingSlashes(options.issuer ?? env4 ?? "");
|
|
694
717
|
if (issuer === "") throw new CauthyWebhookError("issuer (CAUTHY_ISSUER) is not set");
|
|
695
718
|
const signature = request.headers.get("x-cauthy-signature-jwt");
|
|
696
719
|
if (!signature) throw new CauthyWebhookError("no signature");
|
|
@@ -783,7 +806,7 @@ function redirect(location, cookies = []) {
|
|
|
783
806
|
return new Response(null, { status: 302, headers: h });
|
|
784
807
|
}
|
|
785
808
|
function createCauthy(given = {}) {
|
|
786
|
-
const issuer = (given.issuer ?? env2("CAUTHY_ISSUER") ?? "")
|
|
809
|
+
const issuer = withoutTrailingSlashes(given.issuer ?? env2("CAUTHY_ISSUER") ?? "");
|
|
787
810
|
const clientId = given.clientId ?? env2("CAUTHY_CLIENT_ID") ?? "";
|
|
788
811
|
const clientSecret = given.clientSecret ?? env2("CAUTHY_CLIENT_SECRET");
|
|
789
812
|
const secret = given.secret ?? env2("CAUTHY_SECRET") ?? "";
|
|
@@ -807,7 +830,7 @@ function createCauthy(given = {}) {
|
|
|
807
830
|
verifyEmail: given.pages?.verifyEmail ? localPath(given.pages.verifyEmail, "/") : void 0
|
|
808
831
|
};
|
|
809
832
|
const ownSystem = createSystem({ issuer, clientId, clientSecret, key: given.systemKey, fetch: given.fetch });
|
|
810
|
-
const originOf = (request) => (given.baseURL ?? new URL(request.url).origin)
|
|
833
|
+
const originOf = (request) => withoutTrailingSlashes(given.baseURL ?? new URL(request.url).origin);
|
|
811
834
|
const attrs = (request, maxAge) => ({ secure: originOf(request).startsWith("https://"), maxAge });
|
|
812
835
|
async function token(form) {
|
|
813
836
|
const body2 = new URLSearchParams({ client_id: clientId, ...form });
|
|
@@ -943,6 +966,25 @@ function createCauthy(given = {}) {
|
|
|
943
966
|
orgCache.set(session.accessToken, { at: Date.now(), value });
|
|
944
967
|
return value;
|
|
945
968
|
}
|
|
969
|
+
const forgetting = (fn) => async (...args) => {
|
|
970
|
+
const out2 = await fn(...args);
|
|
971
|
+
orgCache.clear();
|
|
972
|
+
return out2;
|
|
973
|
+
};
|
|
974
|
+
const systemThatRefreshes = {
|
|
975
|
+
...ownSystem,
|
|
976
|
+
organizations: {
|
|
977
|
+
...ownSystem.organizations,
|
|
978
|
+
update: forgetting(ownSystem.organizations.update),
|
|
979
|
+
remove: forgetting(ownSystem.organizations.remove)
|
|
980
|
+
},
|
|
981
|
+
members: {
|
|
982
|
+
...ownSystem.members,
|
|
983
|
+
add: forgetting(ownSystem.members.add),
|
|
984
|
+
setRole: forgetting(ownSystem.members.setRole),
|
|
985
|
+
remove: forgetting(ownSystem.members.remove)
|
|
986
|
+
}
|
|
987
|
+
};
|
|
946
988
|
async function toPublic(session) {
|
|
947
989
|
let orgs = [];
|
|
948
990
|
try {
|
|
@@ -1806,7 +1848,7 @@ function createCauthy(given = {}) {
|
|
|
1806
1848
|
async function handler(request) {
|
|
1807
1849
|
const url = new URL(request.url);
|
|
1808
1850
|
if (url.pathname !== basePath && !url.pathname.startsWith(`${basePath}/`)) return new Response("Not found", { status: 404 });
|
|
1809
|
-
const route = url.pathname.slice(basePath.length)
|
|
1851
|
+
const route = withoutTrailingSlashes(url.pathname.slice(basePath.length)) || "/";
|
|
1810
1852
|
const get = request.method === "GET" || request.method === "HEAD";
|
|
1811
1853
|
const mine = await ownRoute(request, url, route);
|
|
1812
1854
|
if (mine !== null) return mine;
|
|
@@ -1853,7 +1895,7 @@ function createCauthy(given = {}) {
|
|
|
1853
1895
|
return {
|
|
1854
1896
|
handler,
|
|
1855
1897
|
webhook,
|
|
1856
|
-
system:
|
|
1898
|
+
system: systemThatRefreshes,
|
|
1857
1899
|
getSession,
|
|
1858
1900
|
status,
|
|
1859
1901
|
resolve: resolve2,
|
|
@@ -1953,7 +1995,7 @@ export type Permission = PermissionOf<typeof policy>
|
|
|
1953
1995
|
}
|
|
1954
1996
|
async function pullPolicy(o = {}) {
|
|
1955
1997
|
const env4 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
|
|
1956
|
-
const issuer = (o.issuer ?? env4("CAUTHY_ISSUER") ?? "")
|
|
1998
|
+
const issuer = withoutTrailingSlashes(o.issuer ?? env4("CAUTHY_ISSUER") ?? "");
|
|
1957
1999
|
const system = o.system ?? env4("CAUTHY_SYSTEM") ?? "";
|
|
1958
2000
|
const tenant = o.tenant ?? env4("CAUTHY_TENANT") ?? "";
|
|
1959
2001
|
const token = o.token ?? env4("CAUTHY_TOKEN") ?? "";
|
|
@@ -1969,7 +2011,7 @@ async function pullPolicy(o = {}) {
|
|
|
1969
2011
|
}
|
|
1970
2012
|
async function pushPolicy(o) {
|
|
1971
2013
|
const env4 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
|
|
1972
|
-
const issuer = (o.issuer ?? env4("CAUTHY_ISSUER") ?? "")
|
|
2014
|
+
const issuer = withoutTrailingSlashes(o.issuer ?? env4("CAUTHY_ISSUER") ?? "");
|
|
1973
2015
|
const system = o.system ?? env4("CAUTHY_SYSTEM") ?? "";
|
|
1974
2016
|
const tenant = o.tenant ?? env4("CAUTHY_TENANT") ?? "";
|
|
1975
2017
|
const token = o.token ?? env4("CAUTHY_TOKEN") ?? "";
|
|
@@ -1996,7 +2038,7 @@ function sessionSecret() {
|
|
|
1996
2038
|
}
|
|
1997
2039
|
async function connectSystem(o) {
|
|
1998
2040
|
const env4 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
|
|
1999
|
-
const issuer = (o.issuer ?? env4("CAUTHY_ISSUER") ?? "")
|
|
2041
|
+
const issuer = withoutTrailingSlashes(o.issuer ?? env4("CAUTHY_ISSUER") ?? "");
|
|
2000
2042
|
const tenant = o.tenant ?? env4("CAUTHY_TENANT") ?? "";
|
|
2001
2043
|
const token = o.token ?? env4("CAUTHY_TOKEN") ?? "";
|
|
2002
2044
|
for (const [name, v] of Object.entries({ CAUTHY_ISSUER: issuer, CAUTHY_TENANT: tenant, CAUTHY_TOKEN: token })) {
|
|
@@ -2059,7 +2101,7 @@ function bearer(from) {
|
|
|
2059
2101
|
return /^Bearer\s+/i.test(header) ? header.replace(/^Bearer\s+/i, "").trim() : "";
|
|
2060
2102
|
}
|
|
2061
2103
|
async function verifyToken(from, options = {}) {
|
|
2062
|
-
const issuer = (options.issuer ?? env3("CAUTHY_ISSUER") ?? "")
|
|
2104
|
+
const issuer = withoutTrailingSlashes(options.issuer ?? env3("CAUTHY_ISSUER") ?? "");
|
|
2063
2105
|
if (issuer === "") throw new CauthyTokenError("issuer (CAUTHY_ISSUER) is not set");
|
|
2064
2106
|
const token = bearer(from);
|
|
2065
2107
|
if (token === "") throw new CauthyTokenError("no token");
|