@cauthyhq/node 1.2.1 → 1.3.1

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 (49) hide show
  1. package/CHANGELOG.md +31 -7
  2. package/README.md +10 -29
  3. package/dist/{cauthy-CCSSj3Lg.d.mts → cauthy-DHRZLndK.d.mts} +31 -147
  4. package/dist/{cauthy-C7gZ-pbv.d.ts → cauthy-JSYh7J2o.d.ts} +31 -147
  5. package/dist/express.d.mts +2 -5
  6. package/dist/express.d.ts +2 -5
  7. package/dist/express.js +1 -2
  8. package/dist/express.js.map +1 -1
  9. package/dist/express.mjs +1 -2
  10. package/dist/express.mjs.map +1 -1
  11. package/dist/fastify.d.mts +1 -3
  12. package/dist/fastify.d.ts +1 -3
  13. package/dist/fastify.js +0 -2
  14. package/dist/fastify.js.map +1 -1
  15. package/dist/fastify.mjs +0 -2
  16. package/dist/fastify.mjs.map +1 -1
  17. package/dist/hono.d.mts +2 -5
  18. package/dist/hono.d.ts +2 -5
  19. package/dist/hono.js +1 -2
  20. package/dist/hono.js.map +1 -1
  21. package/dist/hono.mjs +1 -2
  22. package/dist/hono.mjs.map +1 -1
  23. package/dist/index.d.mts +1 -3
  24. package/dist/index.d.ts +1 -3
  25. package/dist/index.js +159 -524
  26. package/dist/index.js.map +1 -1
  27. package/dist/index.mjs +152 -514
  28. package/dist/index.mjs.map +1 -1
  29. package/dist/mcp.js.map +1 -1
  30. package/dist/mcp.mjs.map +1 -1
  31. package/dist/next.d.mts +1 -3
  32. package/dist/next.d.ts +1 -3
  33. package/dist/testing.d.mts +11 -5
  34. package/dist/testing.d.ts +11 -5
  35. package/dist/testing.js +51 -49
  36. package/dist/testing.js.map +1 -1
  37. package/dist/testing.mjs +51 -49
  38. package/dist/testing.mjs.map +1 -1
  39. package/package.json +3 -15
  40. package/dist/identity-BTJ8NB_w.d.mts +0 -27
  41. package/dist/identity-BTJ8NB_w.d.ts +0 -27
  42. package/dist/keys-D5k0omTb.d.mts +0 -64
  43. package/dist/keys-D5k0omTb.d.ts +0 -64
  44. package/dist/keys.d.mts +0 -8
  45. package/dist/keys.d.ts +0 -8
  46. package/dist/keys.js +0 -157
  47. package/dist/keys.js.map +0 -1
  48. package/dist/keys.mjs +0 -129
  49. package/dist/keys.mjs.map +0 -1
package/dist/hono.mjs CHANGED
@@ -1,10 +1,9 @@
1
1
  // src/hono.ts
2
2
  function cauthyHono(auth) {
3
3
  const base = auth.options.basePath;
4
- const key = auth.pact?.contract.jwksPath;
5
4
  return async (c, next) => {
6
5
  const path = new URL(c.req.url).pathname;
7
- if (path === base || path.startsWith(`${base}/`) || path === key) return auth.handler(c.req.raw);
6
+ if (path === base || path.startsWith(`${base}/`)) return auth.handler(c.req.raw);
8
7
  const resolved = await auth.resolve(c.req.raw);
9
8
  c.set("session", resolved.session);
10
9
  await next();
package/dist/hono.mjs.map CHANGED
@@ -1 +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":[]}
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 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 return async (c, next) => {\n const path = new URL(c.req.url).pathname\n if (path === base || path.startsWith(`${base}/`)) 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":";AA+BO,SAAS,WAAW,MAAsC;AAC/D,QAAM,OAAO,KAAK,QAAQ;AAC1B,SAAO,OAAO,GAAG,SAAS;AACxB,UAAM,OAAO,IAAI,IAAI,EAAE,IAAI,GAAG,EAAE;AAChC,QAAI,SAAS,QAAQ,KAAK,WAAW,GAAG,IAAI,GAAG,EAAG,QAAO,KAAK,QAAQ,EAAE,IAAI,GAAG;AAE/E,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/index.d.mts CHANGED
@@ -1,6 +1,4 @@
1
- export { A as AttributeType, a as CatalogResource, C as Cauthy, b as CauthyApiError, c as CauthyConfigError, d as CauthyEvent, e as CauthyKeyError, f as CauthyKeyReason, g as CauthyOptions, h as CauthyPact, i as CauthySystem, j as CauthyTokenError, k as CauthyUnavailableError, l as CauthyWebhookError, m as CheckOf, n as CheckQuestion, o as CheckResult, p as CheckRule, q as ConditionalPermission, r as ContractOptions, J as JsonValue, M as MountTarget, N as NewMember, O as Organization, s as OrganizationMember, t as OrganizationRef, P as PactItem, u as PactStatus, v as PermissionOf, w as Permitted, x as Policy, y as PolicyDefinition, z as PolicyPermission, B as PolicyRole, D as PublicSession, E as PushPolicyOptions, R as ReplayStore, F as Resolved, G as ResolvedContract, H as RoleOf, I as STANDARD_VARIABLES, S as Session, K as SessionOrganization, L as SessionStatus, Q as SessionUser, T as SystemKey, U as SystemOptions, V as SystemPolicy, W as TokenIdentity, X as TokenRefusal, Y as VerifyTokenOptions, Z as VerifyWebhookOptions, _ as can, $ as createCauthy, a0 as createSystem, a1 as createTokenVerifier, a2 as createVerifierFromEnv, a3 as definePolicy, a4 as failClosed, a5 as memoryReplayStore, a6 as policySource, a7 as pullCatalog, a8 as pullPolicy, a9 as pushCatalog, aa as pushPolicy, ab as readContract, ac as remoteKeys, ad as verifyToken, ae as verifyWebhook } from './cauthy-CCSSj3Lg.mjs';
2
- export { I as Identity } from './identity-BTJ8NB_w.mjs';
3
- export { K as KeyStore, P as PactKeys, S as StoredKey } from './keys-D5k0omTb.mjs';
1
+ export { A as AttributeType, a as CatalogResource, C as Cauthy, b as CauthyApiError, c as CauthyConfigError, d as CauthyEvent, e as CauthyKeyError, f as CauthyKeyReason, g as CauthyOptions, h as CauthySystem, i as CauthyTokenError, j as CauthyUnavailableError, k as CauthyWebhookError, l as CheckOf, m as CheckQuestion, n as CheckResult, o as CheckRule, p as ConditionalPermission, I as Identity, J as JsonValue, M as MountTarget, N as NewMember, O as Organization, q as OrganizationMember, r as OrganizationRef, P as PermissionOf, s as Permitted, t as Policy, u as PolicyDefinition, v as PolicyPermission, w as PolicyRole, x as PublicSession, y as PushPolicyOptions, R as ReplayStore, z as Resolved, B as RoleOf, S as Session, D as SessionOrganization, E as SessionStatus, F as SessionUser, G as SystemKey, H as SystemOptions, K as SystemPolicy, T as TokenIdentity, L as TokenRefusal, V as VerifyTokenOptions, Q as VerifyWebhookOptions, U as can, W as createCauthy, X as createSystem, Y as createTokenVerifier, Z as createVerifierFromEnv, _ as definePolicy, $ as memoryReplayStore, a0 as policySource, a1 as pullCatalog, a2 as pullPolicy, a3 as pushCatalog, a4 as pushPolicy, a5 as remoteKeys, a6 as verifyToken, a7 as verifyWebhook } from './cauthy-DHRZLndK.mjs';
4
2
  export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, StackmythTokens, ThemeFont, ThemeTexts, pushTheme, themeFromStackmyth, tokensFromStackmyth } from './theme.mjs';
5
3
  import 'jose';
6
4
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- export { A as AttributeType, a as CatalogResource, C as Cauthy, b as CauthyApiError, c as CauthyConfigError, d as CauthyEvent, e as CauthyKeyError, f as CauthyKeyReason, g as CauthyOptions, h as CauthyPact, i as CauthySystem, j as CauthyTokenError, k as CauthyUnavailableError, l as CauthyWebhookError, m as CheckOf, n as CheckQuestion, o as CheckResult, p as CheckRule, q as ConditionalPermission, r as ContractOptions, J as JsonValue, M as MountTarget, N as NewMember, O as Organization, s as OrganizationMember, t as OrganizationRef, P as PactItem, u as PactStatus, v as PermissionOf, w as Permitted, x as Policy, y as PolicyDefinition, z as PolicyPermission, B as PolicyRole, D as PublicSession, E as PushPolicyOptions, R as ReplayStore, F as Resolved, G as ResolvedContract, H as RoleOf, I as STANDARD_VARIABLES, S as Session, K as SessionOrganization, L as SessionStatus, Q as SessionUser, T as SystemKey, U as SystemOptions, V as SystemPolicy, W as TokenIdentity, X as TokenRefusal, Y as VerifyTokenOptions, Z as VerifyWebhookOptions, _ as can, $ as createCauthy, a0 as createSystem, a1 as createTokenVerifier, a2 as createVerifierFromEnv, a3 as definePolicy, a4 as failClosed, a5 as memoryReplayStore, a6 as policySource, a7 as pullCatalog, a8 as pullPolicy, a9 as pushCatalog, aa as pushPolicy, ab as readContract, ac as remoteKeys, ad as verifyToken, ae as verifyWebhook } from './cauthy-C7gZ-pbv.js';
2
- export { I as Identity } from './identity-BTJ8NB_w.js';
3
- export { K as KeyStore, P as PactKeys, S as StoredKey } from './keys-D5k0omTb.js';
1
+ export { A as AttributeType, a as CatalogResource, C as Cauthy, b as CauthyApiError, c as CauthyConfigError, d as CauthyEvent, e as CauthyKeyError, f as CauthyKeyReason, g as CauthyOptions, h as CauthySystem, i as CauthyTokenError, j as CauthyUnavailableError, k as CauthyWebhookError, l as CheckOf, m as CheckQuestion, n as CheckResult, o as CheckRule, p as ConditionalPermission, I as Identity, J as JsonValue, M as MountTarget, N as NewMember, O as Organization, q as OrganizationMember, r as OrganizationRef, P as PermissionOf, s as Permitted, t as Policy, u as PolicyDefinition, v as PolicyPermission, w as PolicyRole, x as PublicSession, y as PushPolicyOptions, R as ReplayStore, z as Resolved, B as RoleOf, S as Session, D as SessionOrganization, E as SessionStatus, F as SessionUser, G as SystemKey, H as SystemOptions, K as SystemPolicy, T as TokenIdentity, L as TokenRefusal, V as VerifyTokenOptions, Q as VerifyWebhookOptions, U as can, W as createCauthy, X as createSystem, Y as createTokenVerifier, Z as createVerifierFromEnv, _ as definePolicy, $ as memoryReplayStore, a0 as policySource, a1 as pullCatalog, a2 as pullPolicy, a3 as pushCatalog, a4 as pushPolicy, a5 as remoteKeys, a6 as verifyToken, a7 as verifyWebhook } from './cauthy-JSYh7J2o.js';
4
2
  export { CauthyTheme, ImportedTheme, PushThemeOptions, StackmythThemeOptions, StackmythTokens, ThemeFont, ThemeTexts, pushTheme, themeFromStackmyth, tokensFromStackmyth } from './theme.js';
5
3
  import 'jose';
6
4