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 CHANGED
@@ -5,6 +5,13 @@
5
5
  var import_node_fs = require("fs");
6
6
  var import_node_path2 = require("path");
7
7
 
8
+ // src/url.ts
9
+ function withoutTrailingSlashes(s) {
10
+ let end = s.length;
11
+ while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
12
+ return s.slice(0, end);
13
+ }
14
+
8
15
  // src/connect.ts
9
16
  function sessionSecret() {
10
17
  const bytes = crypto.getRandomValues(new Uint8Array(32));
@@ -14,7 +21,7 @@ function sessionSecret() {
14
21
  }
15
22
  async function connectSystem(o) {
16
23
  const env2 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
17
- const issuer = (o.issuer ?? env2("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
24
+ const issuer = withoutTrailingSlashes(o.issuer ?? env2("CAUTHY_ISSUER") ?? "");
18
25
  const tenant = o.tenant ?? env2("CAUTHY_TENANT") ?? "";
19
26
  const token = o.token ?? env2("CAUTHY_TOKEN") ?? "";
20
27
  for (const [name, v] of Object.entries({ CAUTHY_ISSUER: issuer, CAUTHY_TENANT: tenant, CAUTHY_TOKEN: token })) {
@@ -396,7 +403,7 @@ export type Permission = PermissionOf<typeof policy>
396
403
  }
397
404
  async function pullPolicy(o = {}) {
398
405
  const env2 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
399
- const issuer = (o.issuer ?? env2("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
406
+ const issuer = withoutTrailingSlashes(o.issuer ?? env2("CAUTHY_ISSUER") ?? "");
400
407
  const system = o.system ?? env2("CAUTHY_SYSTEM") ?? "";
401
408
  const tenant = o.tenant ?? env2("CAUTHY_TENANT") ?? "";
402
409
  const token = o.token ?? env2("CAUTHY_TOKEN") ?? "";
@@ -412,7 +419,7 @@ async function pullPolicy(o = {}) {
412
419
  }
413
420
  async function pushPolicy(o) {
414
421
  const env2 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
415
- const issuer = (o.issuer ?? env2("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
422
+ const issuer = withoutTrailingSlashes(o.issuer ?? env2("CAUTHY_ISSUER") ?? "");
416
423
  const system = o.system ?? env2("CAUTHY_SYSTEM") ?? "";
417
424
  const tenant = o.tenant ?? env2("CAUTHY_TENANT") ?? "";
418
425
  const token = o.token ?? env2("CAUTHY_TOKEN") ?? "";
@@ -435,8 +442,20 @@ var import_jose = require("jose");
435
442
 
436
443
  // src/theme.ts
437
444
  var MAX_RADIUS = 40;
445
+ function withoutComments(css) {
446
+ let out2 = "";
447
+ let i = 0;
448
+ for (; ; ) {
449
+ const open = css.indexOf("/*", i);
450
+ if (open < 0) return out2 + css.slice(i);
451
+ out2 += css.slice(i, open);
452
+ const close = css.indexOf("*/", open + 2);
453
+ if (close < 0) return out2;
454
+ i = close + 2;
455
+ }
456
+ }
438
457
  function declarations(css) {
439
- const text = css.replace(/\/\*[\s\S]*?\*\//g, "");
458
+ const text = withoutComments(css);
440
459
  const out2 = [];
441
460
  const within = [];
442
461
  let chunk = "";
@@ -531,7 +550,11 @@ function tokenValue(value) {
531
550
  if (/^\(|[ ,(]\(/.test(v)) return null;
532
551
  return v;
533
552
  }
534
- var THEME_SCOPE = /^(?:\s*(?::root|html|body|\[data-(?:theme|mode|color-scheme)(?:=["']?[\w-]+["']?)?\])\s*,?)+$/i;
553
+ var THEME_SELECTOR = /^(?::root|html|body|\[data-(?:theme|mode|color-scheme)(?:=["']?[\w-]+["']?)?\])$/i;
554
+ var isThemeScope = (selectors) => {
555
+ const parts = selectors.split(/[\s,]+/).filter(Boolean);
556
+ return parts.length > 0 && parts.every((one) => THEME_SELECTOR.test(one));
557
+ };
535
558
  function tokensFromStackmyth(css, options = {}) {
536
559
  const mode = options.mode ?? "light";
537
560
  const all = (Array.isArray(css) ? css : [css]).flatMap(declarations);
@@ -539,7 +562,7 @@ function tokensFromStackmyth(css, options = {}) {
539
562
  const vars = /* @__PURE__ */ new Map();
540
563
  for (const d of all) {
541
564
  if (!applies(d, { mode, theme: named })) continue;
542
- if (!d.within.every((w) => w.startsWith("@") || THEME_SCOPE.test(w))) continue;
565
+ if (!d.within.every((w) => w.startsWith("@") || isThemeScope(w))) continue;
543
566
  vars.set(d.name, d.value);
544
567
  }
545
568
  const inline = (value, depth = 0) => {
@@ -818,7 +841,7 @@ function fromWire(wire) {
818
841
  }
819
842
  async function pushTheme(o) {
820
843
  const env2 = (n) => typeof process !== "undefined" ? process.env?.[n] : void 0;
821
- const issuer = (o.issuer ?? env2("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
844
+ const issuer = withoutTrailingSlashes(o.issuer ?? env2("CAUTHY_ISSUER") ?? "");
822
845
  const clientId = o.clientId ?? env2("CAUTHY_CLIENT_ID") ?? "";
823
846
  const tenant = o.tenant ?? env2("CAUTHY_TENANT") ?? "";
824
847
  const token = o.token ?? env2("CAUTHY_TOKEN") ?? "";
@@ -886,7 +909,7 @@ async function loadKey(k) {
886
909
  return jwk ? (0, import_jose.importJWK)(jwk, "RS256") : (0, import_jose.importPKCS8)(k.privateKey, "RS256", { extractable: true });
887
910
  }
888
911
  function createSystem(given = {}) {
889
- const issuer = (given.issuer ?? env("CAUTHY_ISSUER") ?? "").replace(/\/+$/, "");
912
+ const issuer = withoutTrailingSlashes(given.issuer ?? env("CAUTHY_ISSUER") ?? "");
890
913
  const clientId = given.clientId ?? env("CAUTHY_CLIENT_ID") ?? "";
891
914
  const clientSecret = given.clientSecret ?? env("CAUTHY_CLIENT_SECRET") ?? "";
892
915
  const envKey = env("CAUTHY_SYSTEM_KEY");
package/dist/client.js CHANGED
@@ -109,6 +109,13 @@ function ceremonyError(e) {
109
109
  return { code: "passkey_failed", message: "The passkey could not be used. Try again, or sign in another way." };
110
110
  }
111
111
 
112
+ // src/url.ts
113
+ function withoutTrailingSlashes(s) {
114
+ let end = s.length;
115
+ while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
116
+ return s.slice(0, end);
117
+ }
118
+
112
119
  // src/theme.ts
113
120
  function fromWire(wire) {
114
121
  const names = {
@@ -185,7 +192,7 @@ function firstProblem(...checks) {
185
192
  // src/store.ts
186
193
  var AHEAD_MS = 6e4;
187
194
  function createSessionStore(options = {}) {
188
- const base = (options.basePath ?? "/api/auth").replace(/\/+$/, "");
195
+ const base = withoutTrailingSlashes(options.basePath ?? "/api/auth");
189
196
  const doFetch = (...args) => (options.fetch ?? fetch)(...args);
190
197
  const first = options.initialSession;
191
198
  let state = { session: first ?? null, status: first === void 0 ? "loading" : first === null ? "unauthenticated" : "authenticated" };
@@ -311,7 +318,7 @@ function loadGoogleIdentity() {
311
318
  var PASSKEY_SECONDS = 300;
312
319
  var UNAVAILABLE = { code: "unavailable", message: "Sign-in is unavailable right now. Try again in a moment." };
313
320
  function createAuthClient(options = {}) {
314
- const base = (options.basePath ?? "/api/auth").replace(/\/+$/, "");
321
+ const base = withoutTrailingSlashes(options.basePath ?? "/api/auth");
315
322
  const doFetch = (...args) => (options.fetch ?? fetch)(...args);
316
323
  const locale = () => {
317
324
  const said = typeof options.locale === "function" ? options.locale() : options.locale;