aui-auth 0.0.8 → 0.0.10
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/accounts.d.ts +58 -4
- package/dist/accounts.js +1 -1
- package/dist/cache-iIzAusyV.js +1 -0
- package/dist/codec-IJ2JySkR.js +1 -0
- package/dist/database/index.d.ts +2 -1
- package/dist/database/index.js +1 -1
- package/dist/database/pg.d.ts +1 -1
- package/dist/database/pg.js +1 -1
- package/dist/database/redis.d.ts +1 -1
- package/dist/database/redis.js +1 -1
- package/dist/device.d.ts +2 -1
- package/dist/device.js +1 -1
- package/dist/encoding-BhmNmloC.js +1 -0
- package/dist/errors-C7IxbL16.js +1 -0
- package/dist/errors-DpQsDn4O.d.ts +30 -0
- package/dist/fetch-C0ojJu8c.d.ts +9 -0
- package/dist/fetch-CM1mVzPm.js +1 -0
- package/dist/{index-Bte2SoPM.d.ts → index-DdBQue0N.d.ts} +20 -13
- package/dist/index.d.ts +4 -3
- package/dist/index.js +1 -1
- package/dist/next.d.ts +2 -2
- package/dist/next.js +1 -1
- package/dist/oidc-qInr-2mE.js +1 -0
- package/dist/testing.d.ts +1 -1
- package/dist/{types-Cx223pmJ.d.ts → types-B13HPcs5.d.ts} +1 -29
- package/dist/verify.d.ts +1 -1
- package/dist/verify.js +1 -1
- package/package.json +2 -2
- package/dist/cache-m-qvewq5.js +0 -1
- package/dist/oidc-0pw9wXd4.js +0 -1
- package/dist/oidc-CbVNB1IR.d.ts +0 -11
- package/dist/types-B_7rFOLg.js +0 -1
package/dist/accounts.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as AccountsFetchOptions } from "./
|
|
3
|
-
//#region src/accounts/
|
|
1
|
+
import { f as RevalidateInput, m as SignInInput } from "./types-B13HPcs5.js";
|
|
2
|
+
import { t as AccountsFetchOptions } from "./fetch-C0ojJu8c.js";
|
|
3
|
+
//#region src/accounts/organizations.d.ts
|
|
4
4
|
type AccountsOrganization = {
|
|
5
5
|
id: string;
|
|
6
6
|
name: string;
|
|
@@ -22,5 +22,59 @@ declare function organizationHooks(options: OrganizationHooksOptions): {
|
|
|
22
22
|
onSignIn: (input: SignInInput<OrganizationSessionData>) => Promise<OrganizationSessionData>;
|
|
23
23
|
onRevalidate: (input: RevalidateInput<OrganizationSessionData>) => Promise<OrganizationSessionData | null>;
|
|
24
24
|
};
|
|
25
|
+
/** Owners and admins manage an organization; every other role only takes part in it. */
|
|
26
|
+
declare function isOrganizationAdmin(role: string | null | undefined): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The organization a route's segment names: the active one when no segment is
|
|
29
|
+
* given or the segment is its slug or id, one of the viewer's other
|
|
30
|
+
* organizations otherwise, and none when the viewer is not in it. A segment
|
|
31
|
+
* can be a slug or an id and nothing about its shape says which, so it is
|
|
32
|
+
* matched against both. The list is only read when the active one does not
|
|
33
|
+
* match, and the organization it returns carries the viewer's role there.
|
|
34
|
+
*/
|
|
35
|
+
declare function resolveRouteOrganization<Organization extends Pick<AccountsOrganization, "id" | "slug">>(segment: string | undefined, active: Organization | null, organizations: () => Promise<readonly Organization[]>): Promise<Organization | null>;
|
|
25
36
|
//#endregion
|
|
26
|
-
|
|
37
|
+
//#region src/accounts/projects.d.ts
|
|
38
|
+
type OrganizationReference = {
|
|
39
|
+
id: string;
|
|
40
|
+
} | {
|
|
41
|
+
slug: string;
|
|
42
|
+
};
|
|
43
|
+
type AccountsProject = {
|
|
44
|
+
id: string;
|
|
45
|
+
organizationId: string;
|
|
46
|
+
slug: string;
|
|
47
|
+
name: string;
|
|
48
|
+
color: string;
|
|
49
|
+
icon: string | null;
|
|
50
|
+
plan: string;
|
|
51
|
+
createdBy: string;
|
|
52
|
+
updatedBy: string;
|
|
53
|
+
createdAt: Date;
|
|
54
|
+
updatedAt: Date;
|
|
55
|
+
/** The caller's role in the project's organization; null from an accounts that predates the field. */
|
|
56
|
+
viewerRole: string | null;
|
|
57
|
+
};
|
|
58
|
+
type AccountsProjectPatch = {
|
|
59
|
+
name?: string;
|
|
60
|
+
slug?: string;
|
|
61
|
+
color?: string;
|
|
62
|
+
icon?: string | null;
|
|
63
|
+
plan?: string;
|
|
64
|
+
};
|
|
65
|
+
type DuplicateProjectSlug = {
|
|
66
|
+
reason: "duplicate";
|
|
67
|
+
};
|
|
68
|
+
/** The projects of an organization, or none when it does not exist or the caller is not in it. */
|
|
69
|
+
declare function fetchProjects(options: AccountsFetchOptions, accessToken: string, organization: OrganizationReference): Promise<AccountsProject[]>;
|
|
70
|
+
/** One project by slug, or null when there is nothing there for this caller. */
|
|
71
|
+
declare function fetchProject(options: AccountsFetchOptions, accessToken: string, organization: OrganizationReference, slug: string): Promise<AccountsProject | null>;
|
|
72
|
+
/** A refusal (403) and a missing organization (404) throw; a taken slug is an answer. */
|
|
73
|
+
declare function createProject(options: AccountsFetchOptions, accessToken: string, organization: OrganizationReference, input: {
|
|
74
|
+
name: string;
|
|
75
|
+
slug: string;
|
|
76
|
+
}): Promise<AccountsProject | DuplicateProjectSlug>;
|
|
77
|
+
/** Null when the project is gone; a refusal (403) throws; a taken slug is an answer. */
|
|
78
|
+
declare function updateProject(options: AccountsFetchOptions, accessToken: string, organization: OrganizationReference, slug: string, patch: AccountsProjectPatch): Promise<AccountsProject | DuplicateProjectSlug | null>;
|
|
79
|
+
//#endregion
|
|
80
|
+
export { type AccountsOrganization, type AccountsProject, type AccountsProjectPatch, type DuplicateProjectSlug, type OrganizationHooksOptions, type OrganizationReference, type OrganizationSessionData, createProject, fetchOrganizations, fetchProject, fetchProjects, isOrganizationAdmin, organizationHooks, preferredOrganizationSlug, resolveRouteOrganization, selectOrganization, updateProject };
|
package/dist/accounts.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as e,t}from"./errors-C7IxbL16.js";import{n}from"./fetch-CM1mVzPm.js";async function r(e,r){let i=await n(e,`/api/oidc/organizations`,{headers:{Authorization:`Bearer ${r}`}});if(!i.ok)throw new t(`Failed to load organizations: ${i.status}`,i.status);return await i.json()}function i(e,t){if(t){let n=e.find(e=>e.slug===t);if(n)return n}return e[0]??null}function a(e){let[,t]=new URL(e,`http://localhost`).pathname.split(`/`);return t&&t!==`org`?t:null}function o(t){let n=t.preferredSlug??a;async function o(e){return{activeOrganization:i(await r(t,e.accessToken),n(e.redirectPath))}}async function s(n){let a;try{a=await r(t,n.accessToken)}catch(t){if(e(t))return null;throw t}let o=n.session.data.activeOrganization;if(!o)return{activeOrganization:i(a)};let s=a.find(e=>e.id===o.id)??null;return s?{activeOrganization:s}:null}return{onSignIn:o,onRevalidate:s}}function s(e){return e===`owner`||e===`admin`}async function c(e,t,n){let r=t=>t.slug===e||t.id===e;return e===void 0||t&&r(t)?t:(await n()).find(r)??null}function l(e){return`id`in e?`org_id=${encodeURIComponent(e.id)}`:`org_slug=${encodeURIComponent(e.slug)}`}function u(e){let n=e,r=e=>{let r=n?.[e];if(typeof r!=`string`)throw new t(`Accounts project has no ${e}`,502);return r},i=e=>{let n=new Date(r(e));if(Number.isNaN(n.getTime()))throw new t(`Accounts project has no ${e}`,502);return n};return{id:r(`id`),organizationId:r(`organizationId`),slug:r(`slug`),name:r(`name`),color:r(`color`),icon:typeof n?.icon==`string`?n.icon:null,plan:r(`plan`),createdBy:r(`createdBy`),updatedBy:r(`updatedBy`),createdAt:i(`createdAt`),updatedAt:i(`updatedAt`),viewerRole:typeof n?.viewerRole==`string`?n.viewerRole:null}}async function d(e,r,i,a={},o=[]){let s=await n(e,i,{method:a.method,headers:{Authorization:`Bearer ${r}`,...a.body===void 0?void 0:{"Content-Type":`application/json`}},body:a.body===void 0?void 0:JSON.stringify(a.body)});if(s.ok||o.includes(s.status))return s;throw new t(`Accounts request ${i} failed: ${s.status}`,s.status)}async function f(e,t,n){let r=await d(e,t,`/api/projects?${l(n)}`,{},[403,404]);return r.ok?(await r.json()).map(u):[]}async function p(e,t,n,r){let i=await d(e,t,`/api/projects/${encodeURIComponent(r)}?${l(n)}`,{},[403,404]);return i.ok?u(await i.json()):null}async function m(e,t,n,r){let i=await d(e,t,`/api/projects`,{method:`POST`,body:{...`id`in n?{org_id:n.id}:{org_slug:n.slug},name:r.name,slug:r.slug}},[409]);return i.status===409?{reason:`duplicate`}:u(await i.json())}async function h(e,t,n,r,i){let a=await d(e,t,`/api/projects/${encodeURIComponent(r)}?${l(n)}`,{method:`PATCH`,body:i},[404,409]);return a.status===409?{reason:`duplicate`}:a.status===404?null:u(await a.json())}export{m as createProject,r as fetchOrganizations,p as fetchProject,f as fetchProjects,s as isOrganizationAdmin,o as organizationHooks,a as preferredOrganizationSlug,c as resolveRouteOrganization,i as selectOrganization,h as updateProject};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e}from"./encoding-BhmNmloC.js";import{o as t}from"./errors-C7IxbL16.js";function n(e){if(!e)return;let t=e.split(`,`);return t[t.length-1].trim()||void 0}function r(e){let t=new URL(e.url);return`${n(e.headers.get(`x-forwarded-proto`))||t.protocol.replace(`:`,``)}://${n(e.headers.get(`x-forwarded-host`))||e.headers.get(`host`)||t.host}`}function i(e){return new URL(e).protocol===`https:`}function a(e,t){return t?`__Secure-${e}`:e}function o(e){let t=new Map;if(!e)return t;for(let n of e.split(`;`)){let e=n.indexOf(`=`);if(e===-1)continue;let r=n.slice(0,e).trim();!r||t.has(r)||t.set(r,n.slice(e+1).trim())}return t}function s(e,t){let n=o(e.headers.get(`cookie`));return n.get(a(t,!0))||n.get(a(t,!1))||null}function c(e,t,n,r){let i=[`${e}=${t}`,`Path=/`,`HttpOnly`,`SameSite=Lax`,`Max-Age=${r}`];return n&&i.push(`Secure`),i.join(`; `)}function l(e){let[t,...n]=e.split(`;`).map(e=>e.trim()),r=t.indexOf(`=`);if(r<1)return null;let i=new Map(n.map(e=>{let[t,n=``]=e.split(`=`);return[t.toLowerCase(),n]}));return{name:t.slice(0,r),value:t.slice(r+1),options:{path:i.get(`path`)||`/`,httpOnly:i.has(`httponly`),sameSite:`lax`,secure:i.has(`secure`),maxAge:Number(i.get(`max-age`)??0)}}}function u(e,t,n,r,o){let s=i(r);e.append(`set-cookie`,c(a(t,s),n,s,Math.floor(o/1e3)))}function d(e,t){if(t.length===0)return;let n=o(e.get(`cookie`));for(let e of t){let t=l(e);t&&(t.value?n.set(t.name,t.value):n.delete(t.name))}e.set(`cookie`,[...n].map(([e,t])=>`${e}=${t}`).join(`; `))}function f(e,t){let n=t===void 0||i(t);return[n,!n].map(t=>c(a(e,t),``,t,0))}function p(e,t,n){for(let r of f(t,n))e.append(`set-cookie`,r)}function m(e,t=307){return new Response(null,{status:t,headers:{location:e.toString()}})}function h(e,t){return`${e}_flow_${t}`}function g(e){return btoa(JSON.stringify(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function _(e){if(!e)return null;try{let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=JSON.parse(atob(t));return typeof n.verifier==`string`?{verifier:n.verifier,redirectPath:typeof n.redirectPath==`string`?n.redirectPath:`/`,silent:n.silent===!0}:null}catch{return null}}function v(e,t){if(!e)return`/`;let n;try{n=new URL(e,t)}catch{return`/`}return n.origin!==t||n.pathname.startsWith(`//`)?`/`:`${n.pathname}${n.search}${n.hash}`}const y=4096;function b(e){return`${e}_cache`}function x(e,t,n){if(!e.cache)return 0;let{lifetimes:r}=e,i=Math.min(t.lastValidatedAt+r.revalidateIntervalMs,t.tokens.accessTokenExpiresAt-r.refreshBeforeExpiryMs);return Math.min(e.cache.maxAgeMs,(i>n?i:n+r.retryIntervalMs)-n,t.createdAt+r.absoluteMaxAgeMs-n,t.lastValidatedAt+r.idleMaxAgeMs-n)}async function S(e,t,n){if(!e.cache)return null;let r=x(e,t,n);if(r<1e3)return null;let i={v:1,id:t.id,u:t.user,d:t.data,at:t.tokens.accessToken,ate:t.tokens.accessTokenExpiresAt,ca:t.createdAt,lv:t.lastValidatedAt,exp:n+r};return{value:await(await e.cache.codec()).encrypt(JSON.stringify(i)),maxAgeMs:r}}async function C(t,n,r,i){if(!t.cache||!n||!r)return null;let a;try{let e=await t.cache.codec();a=JSON.parse(await e.decrypt(n))}catch{return null}return a.v!==1||typeof a.exp!=`number`||a.exp<=i||a.id!==await e(r)?null:{id:a.id,user:a.u,tokens:{accessToken:a.at,refreshToken:null,idToken:null,accessTokenExpiresAt:a.ate},data:a.d,createdAt:a.ca,lastValidatedAt:a.lv,refreshLeaseUntil:null}}async function w(e,n,r,o){try{let t=await S(e,n,o);if(!t)return null;let s=i(r),l=c(a(b(e.cookieName),s),t.value,s,Math.floor(t.maxAgeMs/1e3));if(l.length>y)throw Error(`Cache cookie is ${l.length} bytes and browsers drop cookies over ${y}; the session data is too large to cache`);return l}catch(n){return t(e,`cache_cookie`,n),null}}function T(e,t){return e.cache?f(b(e.cookieName),t):[]}export{v as _,p as a,_ as c,d,o as f,r as g,m as h,C as i,g as l,s as m,b as n,f as o,l as p,w as r,a as s,T as t,h as u,c as v,u as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=Number.parseInt(e.slice(n,n+2),16);return t}function t(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function n(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r;try{r=atob(n)}catch{throw Error(`Malformed encrypted value`)}let i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i}function r(e){let r=null,i=()=>r??=crypto.subtle.importKey(`raw`,e,{name:`AES-GCM`},!1,[`encrypt`,`decrypt`]);return{async encrypt(e){let n=crypto.getRandomValues(new Uint8Array(12)),r=new Uint8Array(await crypto.subtle.encrypt({name:`AES-GCM`,iv:n},await i(),new TextEncoder().encode(e))),a=new Uint8Array(12+r.length);return a.set(n),a.set(r,12),t(a)},async decrypt(e){let t=n(e);if(t.length<28)throw Error(`Malformed encrypted value`);let r;try{r=await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.subarray(0,12)},await i(),t.subarray(12))}catch{throw Error(`Malformed encrypted value`)}return new TextDecoder().decode(r)}}}function i(t){if(!/^[0-9a-fA-F]{64}$/.test(t))throw Error(`AES-GCM codec key must be 64 hex characters (32 bytes)`);return r(e(t))}function a(e){let t=null;return()=>t??=crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e)).then(e=>r(new Uint8Array(e)))}export{a as n,i as t};
|
package/dist/database/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { n as createAesGcmCodec, t as SessionCodec } from "../codec-BPnk_EfF.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c as AccountsSessionPatch, d as AccountsUser, l as AccountsSessionStore, p as SessionSweepCutoffs, s as AccountsSession, u as AccountsTokens } from "../types-B13HPcs5.js";
|
|
3
|
+
import { r as SessionDecodeError } from "../errors-DpQsDn4O.js";
|
|
3
4
|
export { type AccountsSession, type AccountsSessionPatch, type AccountsSessionStore, type AccountsTokens, type AccountsUser, type SessionCodec, SessionDecodeError, type SessionSweepCutoffs, createAesGcmCodec };
|
package/dist/database/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{r as e}from"../errors-C7IxbL16.js";import{t}from"../codec-IJ2JySkR.js";export{e as SessionDecodeError,t as createAesGcmCodec};
|
package/dist/database/pg.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as SessionCodec } from "../codec-BPnk_EfF.js";
|
|
2
|
-
import {
|
|
2
|
+
import { l as AccountsSessionStore } from "../types-B13HPcs5.js";
|
|
3
3
|
//#region src/database/pg.d.ts
|
|
4
4
|
type PgQuery = (text: string, values?: unknown[]) => Promise<{
|
|
5
5
|
rows: Record<string, unknown>[];
|
package/dist/database/pg.js
CHANGED
package/dist/database/redis.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as SessionCodec } from "../codec-BPnk_EfF.js";
|
|
2
|
-
import {
|
|
2
|
+
import { l as AccountsSessionStore } from "../types-B13HPcs5.js";
|
|
3
3
|
//#region src/database/redis.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* The slice of a Redis client this store uses, so the package takes no Redis
|
package/dist/database/redis.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{r as e}from"../errors-C7IxbL16.js";const t=`refreshLeaseUntil`,n=`
|
|
2
2
|
local key, checkLease, expectedLease, ttl = KEYS[1], ARGV[1], ARGV[2], ARGV[3]
|
|
3
3
|
if redis.call('EXISTS', key) == 0 then return 0 end
|
|
4
4
|
if checkLease == '1' then
|
package/dist/device.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { d as
|
|
1
|
+
import { d as AccountsUser, u as AccountsTokens } from "./types-B13HPcs5.js";
|
|
2
|
+
import { i as isAccessDenied, n as OAuthTokenError, t as AccountsRequestError } from "./errors-DpQsDn4O.js";
|
|
2
3
|
//#region src/device/index.d.ts
|
|
3
4
|
declare const DEVICE_CODE_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code";
|
|
4
5
|
type DeviceLoginConfig = {
|
package/dist/device.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{i as e,n as t,t as n}from"./errors-C7IxbL16.js";import{a as r,n as i,r as a}from"./fetch-CM1mVzPm.js";import{c as o,i as s,l as c,o as l,s as u}from"./oidc-qInr-2mE.js";const d=`urn:ietf:params:oauth:grant-type:device_code`;function f(e,t){return new Promise((n,r)=>{if(t?.aborted){r(t.reason??Error(`Device login aborted`));return}let i=setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e);function a(){clearTimeout(i),r(t?.reason??Error(`Device login aborted`))}t?.addEventListener(`abort`,a,{once:!0})})}function p(e){let n=e.now??Date.now,p=e.sleep??f,m=e.scope??`openid profile email offline_access`,h=e.audience===void 0?a(e.issuer):e.audience||null,g=e.refreshBeforeExpiryMs??r.refreshBeforeExpiryMs,_={issuer:e.issuer,fetch:e.fetch,timeoutMs:e.requestTimeoutMs},v=t=>({..._,clientId:e.clientId,audience:t});async function y(t){let r=new URLSearchParams({client_id:e.clientId,scope:m});t&&r.set(`resource`,t);let a=await i(_,`/api/auth/device/code`,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:r});if(!a.ok){let e=await o(a);if(t&&l(e))return y(null);throw e}let s=await a.json();return{deviceCode:s.device_code,userCode:s.user_code,verificationUri:s.verification_uri,verificationUriComplete:s.verification_uri_complete,expiresAt:n()+s.expires_in*1e3,intervalMs:(s.interval??5)*1e3,resource:t}}async function b(e,t){let r=c(e,t?.tokens??null,n());return{user:t?.user??await s(_,r.accessToken),tokens:r}}return{start(){return y(h)},async wait(e,r={}){let i=e.intervalMs;for(;;){if(n()>=e.expiresAt)throw new t(400,`expired_token`,`The device code expired before it was approved`);await p(i,r.signal);try{return await b(await u(v(e.resource),{grant_type:d,device_code:e.deviceCode},void 0,e.resource!==null),null)}catch(e){if(e instanceof t){if(e.code===`authorization_pending`)continue;if(e.code===`slow_down`){i+=5e3;continue}}throw e}}},async refresh(e){let{refreshToken:n}=e.tokens;if(!n)throw new t(400,`invalid_grant`,`The credentials carry no refresh token`);return b(await u(v(h),{grant_type:`refresh_token`,refresh_token:n}),e)},async ensureFresh(e){return e.tokens.accessTokenExpiresAt-g>n()?e:this.refresh(e)}}}export{n as AccountsRequestError,d as DEVICE_CODE_GRANT_TYPE,t as OAuthTokenError,p as createDeviceLogin,e as isAccessDenied};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function t(t){return e(crypto.getRandomValues(new Uint8Array(t)))}async function n(t){let n=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(t));return e(new Uint8Array(n))}export{n,t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class extends Error{status;constructor(e,t){super(e),this.name=`AccountsRequestError`,this.status=t}},t=class extends Error{constructor(e){super(`Stored session could not be decoded`,{cause:e}),this.name=`SessionDecodeError`}},n=class extends e{code;description;constructor(e,t,n){super(`Token request failed: ${e} ${t} ${n}`,e),this.name=`OAuthTokenError`,this.code=t,this.description=n}};const r=new Set([408,425,429]);function i(t){return t instanceof e&&t.status>=400&&t.status<500&&!r.has(t.status)}function a({phase:e,error:t}){console.error(`[aui-auth] ${e}`,t)}function o(e,t,n){try{e.onError({phase:t,error:n})}catch{}}export{a,i,n,o,t as r,e as t};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/core/errors.d.ts
|
|
2
|
+
declare class AccountsRequestError extends Error {
|
|
3
|
+
readonly status: number;
|
|
4
|
+
constructor(message: string, status: number);
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* A stored session that cannot be turned back into one: a token the codec
|
|
8
|
+
* cannot decrypt because another key wrote it, a column that does not hold
|
|
9
|
+
* what it should. The session manager reads it as the session being over,
|
|
10
|
+
* removes the row and sends the user back to sign in, so a store that decodes
|
|
11
|
+
* what it stored raises this rather than the failure underneath; every other
|
|
12
|
+
* store failure is a fault and propagates.
|
|
13
|
+
*/
|
|
14
|
+
declare class SessionDecodeError extends Error {
|
|
15
|
+
constructor(cause: unknown);
|
|
16
|
+
}
|
|
17
|
+
declare class OAuthTokenError extends AccountsRequestError {
|
|
18
|
+
readonly code: string;
|
|
19
|
+
readonly description: string;
|
|
20
|
+
constructor(status: number, code: string, description: string);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Whether accounts rejected the token, the client, or the user, which ends
|
|
24
|
+
* the session, as opposed to failing to answer, which keeps it. Any 4xx but a
|
|
25
|
+
* timeout or a rate limit counts: the provider answers a revoked token or a
|
|
26
|
+
* disabled client with 400 as readily as with 401.
|
|
27
|
+
*/
|
|
28
|
+
declare function isAccessDenied(error: unknown): boolean;
|
|
29
|
+
//#endregion
|
|
30
|
+
export { isAccessDenied as i, OAuthTokenError as n, SessionDecodeError as r, AccountsRequestError as t };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/core/fetch.d.ts
|
|
2
|
+
type AccountsFetchOptions = {
|
|
3
|
+
issuer: string;
|
|
4
|
+
fetch?: typeof fetch;
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
};
|
|
7
|
+
declare function accountsEndpoint(issuer: string, path: string): string;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { accountsEndpoint as n, AccountsFetchOptions as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e,t}from"./errors-C7IxbL16.js";import{n}from"./codec-IJ2JySkR.js";const r={login:`/api/auth/login`,callback:`/api/auth/callback`,logout:`/api/auth/logout`,logoutComplete:`/api/auth/logout-complete`,error:`/auth/error`},i={absoluteMaxAgeMs:2592e6,idleMaxAgeMs:6048e5,revalidateIntervalMs:12e4,refreshBeforeExpiryMs:3e5,flowMaxAgeMs:6e5,refreshLeaseMs:2e4,leaseWaitMs:5e3,requestTimeoutMs:1e4,retryIntervalMs:1e4},a=Object.freeze({});function o(t){return{...t,scope:t.scope??`openid profile email offline_access`,onSignIn:t.onSignIn??(async()=>a),onRevalidate:t.onRevalidate??(async()=>a),onError:t.onError??e,revalidateUser:t.revalidateUser??!1,logout:t.logout??`global`,paths:{...r,...t.paths},lifetimes:{...i,...t.lifetimes},fetch:t.fetch??globalThis.fetch.bind(globalThis),now:t.now??Date.now,cache:t.cache?{codec:n(t.cache.secret),maxAgeMs:t.cache.maxAgeMs??6e4}:null,audience:t.audience===!1?null:t.audience??new URL(`/api/auth`,t.issuer).toString()}}function s(e,t){return new URL(t,e).toString()}function c(e){return s(e,`/api/auth`)}function l(e){return{issuer:e.issuer,fetch:e.fetch,timeoutMs:e.lifetimes.requestTimeoutMs}}async function u(e,n,r={},a){let o=e.fetch??globalThis.fetch.bind(globalThis),c=e.timeoutMs??i.requestTimeoutMs,l=a===void 0?c:Math.min(c,a-Date.now());if(l<=0)throw new t(`Accounts request deadline passed`,0);return o(s(e.issuer,n),{...r,cache:`no-store`,signal:AbortSignal.timeout(l)})}export{i as a,l as i,u as n,o,c as r,s as t};
|
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { a as AccountsLifetimes, d as AccountsUser, l as AccountsSessionStore, s as AccountsSession, t as AccountsAuthConfig } from "./types-B13HPcs5.js";
|
|
2
|
+
import { t as AccountsFetchOptions } from "./fetch-C0ojJu8c.js";
|
|
3
|
+
//#region src/core/resolve.d.ts
|
|
4
|
+
type SessionResolution<Data> = {
|
|
5
|
+
session: AccountsSession<Data> | null;
|
|
6
|
+
/**
|
|
7
|
+
* The Set-Cookie headers to attach to the response: the cache cookie while
|
|
8
|
+
* the session is alive, the cookies that clear a session that is gone.
|
|
9
|
+
*/
|
|
10
|
+
cookies: string[];
|
|
11
|
+
};
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/core/config.d.ts
|
|
14
|
+
declare const DEFAULT_LIFETIMES: AccountsLifetimes;
|
|
15
|
+
//#endregion
|
|
2
16
|
//#region src/core/cookies.d.ts
|
|
3
17
|
declare function requestOrigin(request: Request): string;
|
|
4
18
|
/**
|
|
@@ -10,6 +24,9 @@ declare function requestOrigin(request: Request): string;
|
|
|
10
24
|
declare function forwardCookies(headers: Headers, issued: readonly string[]): void;
|
|
11
25
|
declare function sanitizeRedirectPath(rawRedirect: string | null | undefined, origin: string): string;
|
|
12
26
|
//#endregion
|
|
27
|
+
//#region src/core/oidc.d.ts
|
|
28
|
+
declare function fetchUserInfo(options: AccountsFetchOptions, accessToken: string): Promise<AccountsUser>;
|
|
29
|
+
//#endregion
|
|
13
30
|
//#region src/core/cache.d.ts
|
|
14
31
|
declare function cacheCookieBase(sessionCookie: string): string;
|
|
15
32
|
//#endregion
|
|
@@ -29,16 +46,6 @@ type GuardResult<Data> = {
|
|
|
29
46
|
response: Response;
|
|
30
47
|
};
|
|
31
48
|
//#endregion
|
|
32
|
-
//#region src/core/resolve.d.ts
|
|
33
|
-
type SessionResolution<Data> = {
|
|
34
|
-
session: AccountsSession<Data> | null;
|
|
35
|
-
/**
|
|
36
|
-
* The Set-Cookie headers to attach to the response: the cache cookie while
|
|
37
|
-
* the session is alive, the cookies that clear a session that is gone.
|
|
38
|
-
*/
|
|
39
|
-
cookies: string[];
|
|
40
|
-
};
|
|
41
|
-
//#endregion
|
|
42
49
|
//#region src/core/store/memory.d.ts
|
|
43
50
|
declare function createMemorySessionStore<Data>(): AccountsSessionStore<Data> & {
|
|
44
51
|
rows: Map<string, AccountsSession<Data>>;
|
|
@@ -62,9 +69,9 @@ declare function createAccountsAuth<Data>(input: AccountsAuthConfig<Data>): {
|
|
|
62
69
|
sessionFromRequest: (request: Request) => Promise<AccountsSession<Data> | null>;
|
|
63
70
|
accessTokenFromCookies: (cookies: SessionCookies) => Promise<string | null>;
|
|
64
71
|
accessTokenFromRequest: (request: Request) => Promise<string | null>;
|
|
65
|
-
updateSessionData: (cookies: SessionCookies, update: (data: Data) => Data) => Promise<
|
|
72
|
+
updateSessionData: (cookies: SessionCookies, update: (data: Data) => Data) => Promise<SessionResolution<Data>>;
|
|
66
73
|
sweepSessions: () => Promise<number>;
|
|
67
74
|
};
|
|
68
75
|
type AccountsAuth<Data> = ReturnType<typeof createAccountsAuth<Data>>;
|
|
69
76
|
//#endregion
|
|
70
|
-
export {
|
|
77
|
+
export { GuardOptions as a, fetchUserInfo as c, sanitizeRedirectPath as d, DEFAULT_LIFETIMES as f, createMemorySessionStore as i, forwardCookies as l, SessionCookies as n, GuardResult as o, SessionResolution as p, createAccountsAuth as r, cacheCookieBase as s, AccountsAuth as t, requestOrigin as u };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as accountsEndpoint,
|
|
3
|
-
import {
|
|
1
|
+
import { a as AccountsLifetimes, c as AccountsSessionPatch, d as AccountsUser, f as RevalidateInput, i as AccountsErrorPhase, l as AccountsSessionStore, m as SignInInput, n as AccountsCacheConfig, o as AccountsPaths, p as SessionSweepCutoffs, r as AccountsErrorEvent, s as AccountsSession, t as AccountsAuthConfig, u as AccountsTokens } from "./types-B13HPcs5.js";
|
|
2
|
+
import { n as accountsEndpoint, t as AccountsFetchOptions } from "./fetch-C0ojJu8c.js";
|
|
3
|
+
import { i as isAccessDenied, n as OAuthTokenError, r as SessionDecodeError, t as AccountsRequestError } from "./errors-DpQsDn4O.js";
|
|
4
|
+
import { a as GuardOptions, c as fetchUserInfo, d as sanitizeRedirectPath, f as DEFAULT_LIFETIMES, i as createMemorySessionStore, l as forwardCookies, n as SessionCookies, o as GuardResult, p as SessionResolution, r as createAccountsAuth, s as cacheCookieBase, t as AccountsAuth, u as requestOrigin } from "./index-DdBQue0N.js";
|
|
4
5
|
export { AccountsAuth, type AccountsAuthConfig, type AccountsCacheConfig, type AccountsErrorEvent, type AccountsErrorPhase, type AccountsFetchOptions, type AccountsLifetimes, type AccountsPaths, AccountsRequestError, type AccountsSession, type AccountsSessionPatch, type AccountsSessionStore, type AccountsTokens, type AccountsUser, DEFAULT_LIFETIMES, type GuardOptions, type GuardResult, OAuthTokenError, type RevalidateInput, SessionCookies, SessionDecodeError, type SessionResolution, type SessionSweepCutoffs, type SignInInput, accountsEndpoint, cacheCookieBase, createAccountsAuth, createMemorySessionStore, fetchUserInfo, forwardCookies, isAccessDenied, requestOrigin, sanitizeRedirectPath };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,
|
|
1
|
+
import{_ as e,a as t,c as n,d as r,f as i,g as a,h as o,i as s,l as c,m as l,n as u,o as d,r as f,t as p,u as m,v as h,y as g}from"./cache-iIzAusyV.js";import{n as _,t as v}from"./encoding-BhmNmloC.js";import{i as y,n as b,o as x,r as S,t as C}from"./errors-C7IxbL16.js";import{a as w,i as T,o as E,r as D,t as O}from"./fetch-CM1mVzPm.js";import{a as k,i as A,l as j,n as M,r as N,t as P}from"./oidc-qInr-2mE.js";function F(e,t){return[...d(e.cookieName,t),...p(e,t)]}function I(e,t){return async function(n){let r=a(n),i=l(n,e.cookieName),o=l(n,u(e.cookieName)),c=await s(e,o,i,e.now());if(c)return{session:c,cookies:[]};let d={session:null,cookies:i!==null||o!==null?F(e,r):[]},p=await t.load(i);if(!p)return d;let{deferRevalidation:m}=e;if(m&&t.revalidationDue(p)&&L(e,m,t,p)){let t=await f(e,p,r,e.now());return{session:p,cookies:t?[t]:[]}}let h=p;try{let e=await t.revalidate(p);if(!e)return d;h=e}catch(t){x(e,`revalidate`,t)}let g=await f(e,h,r,e.now());return{session:h,cookies:g?[g]:[]}}}function L(e,t,n,r){try{return t(async()=>{try{await n.revalidate(r)}catch(t){x(e,`revalidate`,t)}}),!0}catch(t){return x(e,`revalidate`,t),!1}}function R(e,t){let n=I(e,t);return async function(t,i={}){let a=new URL(t.url);if([e.paths.login,e.paths.callback,e.paths.logout,e.paths.logoutComplete,e.paths.error,...i.publicPaths??[]].some(e=>a.pathname.startsWith(e)))return{kind:`ok`,session:null};let{session:o,cookies:s}=await n(t);return o?s.length>0?{kind:`ok`,session:o,cookies:s}:{kind:`ok`,session:o}:r(t,i,s)};function r(e,t,n){let r=n.length>0,a=new URL(e.url),s=(t.apiPaths??[`/api`,`/trpc`]).some(e=>a.pathname.startsWith(e))?Response.json({error:`Unauthorized`},{status:401}):o(i(e,t,r));for(let e of n)s.headers.append(`set-cookie`,e);return{kind:`response`,response:s}}function i(t,n,r){let i=new URL(t.url),o=new URL(e.paths.login,a(t));return o.searchParams.set(`redirect`,n.redirectPath?.(t)??`${i.pathname}${i.search}`),r&&o.searchParams.set(`silent`,`1`),o}}const z=/^[A-Za-z0-9_-]{1,128}$/,B=new Set([`login_required`,`consent_required`,`interaction_required`,`account_selection_required`]);function V(r,s){function u(e,t){let n=new URL(r.paths.login,e);return n.searchParams.set(`redirect`,t),n}function d(e,t,n){let i=new URL(r.paths.error,e);return i.searchParams.set(`reason`,t),n&&i.searchParams.set(`description`,n),i}function _(e,t){let n=m(r.cookieName,``),a=[...i(e.headers.get(`cookie`)).keys()].filter(e=>e.replace(/^__Secure-/,``).startsWith(n)),o=a.length-4;for(let e of a.slice(0,Math.max(0,o)))t.headers.append(`set-cookie`,h(e,``,e.startsWith(`__Secure-`),0))}async function v(e){try{let t=await s.load(e);t&&await s.end(t)}catch(e){x(r,`session_store`,e)}}async function y(t){let n=a(t),i=new URL(t.url).searchParams,s=e(i.get(`redirect`),n),l=i.get(`silent`)===`1`,{url:u,state:d,verifier:f}=await P(r,{origin:n,silent:l}),p=o(u);return _(t,p),g(p.headers,m(r.cookieName,d),c({verifier:f,redirectPath:s,silent:l}),n,r.lifetimes.flowMaxAgeMs),p}async function S(i){let c=a(i),h=new URL(i.url).searchParams,_=h.get(`state`),y=_&&z.test(_)?m(r.cookieName,_):null,S=y?n(l(i,y)):null,C=e=>(y&&t(e.headers,y,c),e);if(!S)return C(o(d(c,`invalid_state`,null)));let w=e(S.redirectPath,c),E=h.get(`iss`);if(E!==null&&E!==D(r.issuer))return C(o(d(c,`invalid_issuer`,null)));let O=h.get(`error`);if(O)return S.silent&&B.has(O)?C(o(u(c,w))):C(o(d(c,O,h.get(`error_description`))));let k=h.get(`code`);if(!k)return C(o(d(c,`invalid_request`,null)));let M,P,F;try{let e=await N(r,{code:k,verifier:S.verifier,redirectUri:new URL(r.paths.callback,c).toString()});M=j(e,null,r.now()),P=await A(T(r),M.accessToken),F=await r.onSignIn({user:P,accessToken:M.accessToken,redirectPath:w,previous:null})}catch(e){return x(r,`sign_in`,e),e instanceof b?C(o(d(c,e.code,e.description||null))):C(o(d(c,`accounts_unavailable`,null)))}let I=l(i,r.cookieName);if(F===null){let e=o(d(c,`access_denied`,null));I!==null&&(await v(I),t(e.headers,r.cookieName,c));for(let t of p(r,c))e.headers.append(`set-cookie`,t);return C(e)}let L,R;try{({cookieValue:L,session:R}=await s.start({user:P,tokens:M,data:F}))}catch(e){return x(r,`session_store`,e),C(o(d(c,`session_store_error`,null)))}I!==null&&await v(I);let V=o(new URL(w,c));g(V.headers,r.cookieName,L,c,r.lifetimes.absoluteMaxAgeMs);let H=await f(r,R,c,r.now());return H&&V.headers.append(`set-cookie`,H),C(V)}async function C(e){let t=a(e),n=await s.load(l(e,r.cookieName));n&&await s.end(n);let i=n?.tokens.idToken&&r.logout===`global`?M(r,{origin:t,idToken:n.tokens.idToken}):new URL(r.paths.logoutComplete,t).toString(),c=o(i,303);for(let e of F(r,t))c.headers.append(`set-cookie`,e);return c}return{login:y,callback:S,logout:C}}const H=e=>new Promise(t=>setTimeout(t,e));function U(e){let{store:t,lifetimes:n}=e;function r(e,t){return t-e.createdAt>=n.absoluteMaxAgeMs||t-e.lastValidatedAt>=n.idleMaxAgeMs}function i(e,t){return e.accessTokenExpiresAt-t<=n.refreshBeforeExpiryMs}function a(t){let r=e.now();return!i(t.tokens,r)&&r-t.lastValidatedAt>=n.revalidateIntervalMs}async function o(n){if(!n)return null;let i=await _(n),a;try{a=await t.read(i)}catch(n){if(!(n instanceof S))throw n;return x(e,`session_store`,n),await t.delete(i),null}return a?r(a,e.now())?(await t.delete(a.id),null):a:null}async function s(n){let r=v(32),i=e.now(),a={id:await _(r),user:n.user,tokens:n.tokens,data:n.data,createdAt:i,lastValidatedAt:i,refreshLeaseUntil:null};return await t.create(a),{session:a,cookieValue:r}}async function c(r){let a=e.now();if(!i(r.tokens,a))return r;if(!r.tokens.refreshToken)return await t.delete(r.id),null;let o=await t.claimRefreshLease(r.id,a+n.refreshLeaseMs,a);if(!o)return l(r.id,a);let s=o.refreshLeaseUntil??void 0;if(!i(o.tokens,a))return await t.update(o.id,{refreshLeaseUntil:null},s)??t.read(o.id);try{let r=await k(e,o.tokens.refreshToken,Math.max(n.refreshLeaseMs-1e3,n.refreshLeaseMs/2));return await t.update(o.id,{tokens:j(r,o.tokens,e.now()),refreshLeaseUntil:null},s)??t.read(o.id)}catch(n){if(y(n))return await t.delete(o.id,s)?null:await t.read(o.id)??null;let r=await t.update(o.id,{refreshLeaseUntil:null},s);if(o.tokens.accessTokenExpiresAt>e.now())return x(e,`refresh`,n),r??o;throw n}}async function l(r,a){for(;;){await H(100);let o=await t.read(r);if(!o)return null;let s=e.now();if(!i(o.tokens,s))return o;if(o.refreshLeaseUntil===null||o.refreshLeaseUntil<=s)return c(o);if(s-a>=n.leaseWaitMs){if(o.tokens.accessTokenExpiresAt>s)return o;throw new C(`Timed out waiting for the session refresh lease`,0)}}}async function u(r){let i;try{i=await c(r)}catch(t){x(e,`refresh`,t),i=r}if(!i)return null;if(e.now()-i.lastValidatedAt<n.revalidateIntervalMs||!d(i.tokens))return i;let a=e.revalidateUser?await p(i):i.user;if(!a)return f(i);if(!d(i.tokens))return i;let o=await e.onRevalidate({session:i,accessToken:i.tokens.accessToken,user:a});if(o===null)return f(i);let s={data:o,lastValidatedAt:e.now()};return a!==i.user&&(s.user=a),t.update(i.id,s)}function d(t){return t.accessTokenExpiresAt-e.now()>n.requestTimeoutMs}async function f(n){return n.tokens.accessTokenExpiresAt<=e.now()?n:(await t.delete(n.id),null)}async function p(t){try{return await A(T(e),t.tokens.accessToken)}catch(n){return y(n)?null:(x(e,`revalidate`,n),t.user)}}async function m(e){await t.delete(e.id)}async function h(){if(!t.sweep)return 0;let r=e.now();return t.sweep({createdBefore:r-n.absoluteMaxAgeMs,validatedBefore:r-n.idleMaxAgeMs})}return{load:o,start:s,ensureFreshTokens:c,revalidate:u,revalidationDue:a,end:m,sweep:h}}function W(){let e=new Map;return{rows:e,async create(t){e.set(t.id,structuredClone(t))},async read(t){let n=e.get(t);return n?structuredClone(n):null},async update(t,n,r){let i=e.get(t);if(!i||r!==void 0&&i.refreshLeaseUntil!==r)return null;let a=structuredClone({...i,...n});return e.set(t,a),structuredClone(a)},async claimRefreshLease(t,n,r){let i=e.get(t);if(!i||i.refreshLeaseUntil!==null&&i.refreshLeaseUntil>r)return null;let a={...i,refreshLeaseUntil:n};return e.set(t,a),structuredClone(a)},async delete(t,n){let r=e.get(t);return!r||n!==void 0&&r.refreshLeaseUntil!==n?!1:(e.delete(t),!0)},async sweep(t){let n=0;for(let[r,i]of e)(i.createdAt<t.createdBefore||i.lastValidatedAt<t.validatedBefore)&&(e.delete(r),n+=1);return n}}}function G(e){let t=E(e),n=U(t),r=V(t,n),i=R(t,n),a=I(t,n);function o(e){return{session:l(e,t.cookieName),cache:l(e,u(t.cookieName))}}async function c(e){return await s(t,e.cache,e.session,t.now())??n.load(e.session)}async function d(e){return c(o(e))}async function f(e){let r=await s(t,e.cache,e.session,t.now());if(r&&r.tokens.accessTokenExpiresAt>t.now())return r.tokens.accessToken;let i=await n.load(e.session);return i?(await n.ensureFreshTokens(i))?.tokens.accessToken??null:null}async function m(e){return f(o(e))}async function h(e,r){let i=await n.load(e.session),a=i&&await t.store.update(i.id,{data:r(i.data)});return a?{session:a,cookies:p(t)}:{session:null,cookies:[]}}function g(){return n.sweep()}return{cookieName:t.cookieName,handlers:r,guard:i,resolveSession:a,sessionFromCookies:c,sessionFromRequest:d,accessTokenFromCookies:f,accessTokenFromRequest:m,updateSessionData:h,sweepSessions:g}}export{C as AccountsRequestError,w as DEFAULT_LIFETIMES,b as OAuthTokenError,S as SessionDecodeError,O as accountsEndpoint,u as cacheCookieBase,G as createAccountsAuth,W as createMemorySessionStore,A as fetchUserInfo,r as forwardCookies,y as isAccessDenied,a as requestOrigin,e as sanitizeRedirectPath};
|
package/dist/next.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as AccountsAuth } from "./index-
|
|
1
|
+
import { s as AccountsSession } from "./types-B13HPcs5.js";
|
|
2
|
+
import { t as AccountsAuth } from "./index-DdBQue0N.js";
|
|
3
3
|
import { NextRequest, NextResponse } from "next/server";
|
|
4
4
|
//#region src/next/index.d.ts
|
|
5
5
|
/**
|
package/dist/next.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{d as e,n as t,s as
|
|
1
|
+
import{d as e,n as t,p as n,s as r}from"./cache-iIzAusyV.js";import{io as i}from"next/cache.js";import{cookies as a}from"next/headers";import{NextResponse as o}from"next/server";function s(t,n=[]){e(t.headers,n);let r=o.next({request:{headers:t.headers}});for(let e of n)r.headers.append(`set-cookie`,e);return r}async function c(e){await i();let n=await a(),o=e=>n.get(r(e,!0))?.value||n.get(r(e,!1))?.value||null;return{session:o(e),cache:o(t(e))}}async function l(e){let t=await a();for(let r of e){let e=n(r);if(e)try{t.set(e.name,e.value,e.options)}catch{}}}function u(e){let t=e.cookieName;return{async getSession(){return e.sessionFromCookies(await c(t))},async getAccessToken(){return e.accessTokenFromCookies(await c(t))},async updateSessionData(n){let r=await e.updateSessionData(await c(t),n);return await l(r.cookies),r.session}}}export{s as continueRequest,u as withNextRequestScope};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{n as e,t}from"./encoding-BhmNmloC.js";import{n,t as r}from"./errors-C7IxbL16.js";import{i,n as a,t as o}from"./fetch-CM1mVzPm.js";async function s(n,r){let i=t(24),a=t(32),s=new URL(o(n.issuer,`/api/auth/oauth2/authorize`));return s.searchParams.set(`client_id`,n.clientId),s.searchParams.set(`redirect_uri`,new URL(n.paths.callback,r.origin).toString()),s.searchParams.set(`response_type`,`code`),s.searchParams.set(`scope`,n.scope),s.searchParams.set(`state`,i),s.searchParams.set(`code_challenge`,await e(a)),s.searchParams.set(`code_challenge_method`,`S256`),r.silent&&s.searchParams.set(`prompt`,`none`),{url:s.toString(),state:i,verifier:a}}function c(e,t){let n=new URL(o(e.issuer,`/api/auth/oauth2/end-session`));return n.searchParams.set(`id_token_hint`,t.idToken),n.searchParams.set(`client_id`,e.clientId),n.searchParams.set(`post_logout_redirect_uri`,new URL(e.paths.logoutComplete,t.origin).toString()),n.toString()}function l(e){return{...i(e),clientId:e.clientId,clientSecret:e.clientSecret,audience:e.audience}}async function u(e){let t=await e.text().catch(()=>``),r=`unknown_error`,i=t;try{let e=JSON.parse(t);r=e.error??r,i=e.error_description??i}catch{}return new n(e.status,r,i)}function d(e){return e.code===`invalid_target`||e.code===`invalid_request`&&/resource/i.test(e.description)}async function f(e,t,n,r=!0){let i=new URLSearchParams({client_id:e.clientId,...t});e.clientSecret&&i.set(`client_secret`,e.clientSecret),e.audience&&r&&i.set(`resource`,e.audience);let o=await a(e,`/api/auth/oauth2/token`,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:i},n);if(!o.ok){let i=await u(o);if(r&&e.audience&&d(i))return f(e,t,n,!1);throw i}return await o.json()}function p(e,t){return f(l(e),{grant_type:`authorization_code`,code:t.code,code_verifier:t.verifier,redirect_uri:t.redirectUri})}function m(e,t,n){return f(l(e),{grant_type:`refresh_token`,refresh_token:t},n===void 0?void 0:Date.now()+n)}async function h(e,t){let n=await a(e,`/api/auth/oauth2/userinfo`,{headers:{Authorization:`Bearer ${t}`}});if(!n.ok)throw new r(`Failed to load user info: ${n.status}`,n.status);let i=await n.json();return{id:i.sub,email:i.email??``,name:i.name??i.email??i.sub,image:i.picture??null}}function g(e,t,n){return{accessToken:e.access_token,refreshToken:e.refresh_token??t?.refreshToken??null,idToken:e.id_token??t?.idToken??null,accessTokenExpiresAt:typeof e.expires_at==`number`?e.expires_at*1e3:n+(e.expires_in??3600)*1e3}}export{m as a,u as c,h as i,g as l,c as n,d as o,p as r,f as s,s as t};
|
package/dist/testing.d.ts
CHANGED
|
@@ -161,33 +161,5 @@ type AccountsCacheConfig = {
|
|
|
161
161
|
secret: string;
|
|
162
162
|
maxAgeMs?: number;
|
|
163
163
|
};
|
|
164
|
-
declare const DEFAULT_LIFETIMES: AccountsLifetimes;
|
|
165
|
-
declare class AccountsRequestError extends Error {
|
|
166
|
-
readonly status: number;
|
|
167
|
-
constructor(message: string, status: number);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* A stored session that cannot be turned back into one: a token the codec
|
|
171
|
-
* cannot decrypt because another key wrote it, a column that does not hold
|
|
172
|
-
* what it should. The session manager reads it as the session being over,
|
|
173
|
-
* removes the row and sends the user back to sign in, so a store that decodes
|
|
174
|
-
* what it stored raises this rather than the failure underneath; every other
|
|
175
|
-
* store failure is a fault and propagates.
|
|
176
|
-
*/
|
|
177
|
-
declare class SessionDecodeError extends Error {
|
|
178
|
-
constructor(cause: unknown);
|
|
179
|
-
}
|
|
180
|
-
declare class OAuthTokenError extends AccountsRequestError {
|
|
181
|
-
readonly code: string;
|
|
182
|
-
readonly description: string;
|
|
183
|
-
constructor(status: number, code: string, description: string);
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Whether accounts rejected the token, the client, or the user, which ends
|
|
187
|
-
* the session, as opposed to failing to answer, which keeps it. Any 4xx but a
|
|
188
|
-
* timeout or a rate limit counts: the provider answers a revoked token or a
|
|
189
|
-
* disabled client with 400 as readily as with 401.
|
|
190
|
-
*/
|
|
191
|
-
declare function isAccessDenied(error: unknown): boolean;
|
|
192
164
|
//#endregion
|
|
193
|
-
export {
|
|
165
|
+
export { AccountsLifetimes as a, AccountsSessionPatch as c, AccountsUser as d, RevalidateInput as f, AccountsErrorPhase as i, AccountsSessionStore as l, SignInInput as m, AccountsCacheConfig as n, AccountsPaths as o, SessionSweepCutoffs as p, AccountsErrorEvent as r, AccountsSession as s, AccountsAuthConfig as t, AccountsTokens as u };
|
package/dist/verify.d.ts
CHANGED
package/dist/verify.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t as e}from"./
|
|
1
|
+
import{t as e}from"./errors-C7IxbL16.js";import{n as t,r as n}from"./fetch-CM1mVzPm.js";function r(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=atob(t+`=`.repeat((4-t.length%4)%4)),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}function i(e){try{let t=JSON.parse(new TextDecoder().decode(r(e)));return typeof t==`object`&&t&&!Array.isArray(t)?t:null}catch{return null}}async function a(e){let t=typeof e==`object`&&e&&Array.isArray(e.keys)?e.keys:null;if(t===null)throw Error(`The key set has no keys array`);let n=new Map;for(let[e,r]of t.entries())if(!(typeof r!=`object`||!r||r.kty!==`OKP`||r.crv!==`Ed25519`||typeof r.x!=`string`))try{let t=await crypto.subtle.importKey(`jwk`,{kty:r.kty,crv:r.crv,x:r.x},{name:`Ed25519`},!1,[`verify`]);n.set(typeof r.kid==`string`?r.kid:`#${e}`,t)}catch{}return n}function o(o){let s=o.now??Date.now,c=n(o.issuer),l=new Set(Array.isArray(o.audience)?o.audience:[o.audience]),u=o.keysMaxAgeMs??6e5,d=o.keysRetryMs??3e4,f=o.clockSkewMs??3e4,p={issuer:o.issuer,fetch:o.fetch,timeoutMs:o.requestTimeoutMs},m=null,h=null;function g(){return h??=(async()=>{try{let n=await t(p,`/api/auth/jwks`);if(!n.ok)throw new e(`Failed to load the accounts key set: ${n.status}`,n.status);let r;try{r=await a(await n.json())}catch(t){throw new e(`Failed to read the accounts key set: ${t instanceof Error?t.message:String(t)}`,n.status)}return m={keys:r,loadedAt:s()},m}finally{h=null}})(),h}async function _(){try{return await g()}catch(e){if(m)return m;throw e}}let v=-1/0;async function y(e){let t=m&&s()-m.loadedAt<u?m:await _();if(e!==null&&!t.keys.has(e)&&s()-v>=d&&(v=s(),t=await _()),e===null)return[...t.keys.values()];let n=t.keys.get(e);return n?[n]:[]}return{async verify(e,t={}){let n=e.split(`.`);if(n.length!==3)return null;let a=i(n[0]),o=i(n[1]);if(!a||!o||a.alg!==`EdDSA`)return null;let u;try{u=r(n[2])}catch{return null}let d=new TextEncoder().encode(`${n[0]}.${n[1]}`),p=!1;for(let e of await y(typeof a.kid==`string`?a.kid:null))if(await crypto.subtle.verify(`Ed25519`,e,u,d)){p=!0;break}if(!p||o.iss!==c||!(Array.isArray(o.aud)?o.aud:typeof o.aud==`string`?[o.aud]:[]).some(e=>typeof e==`string`&&l.has(e)))return null;let m=s()/1e3,h=f/1e3;if(typeof o.exp!=`number`||o.exp+h<=m||typeof o.nbf==`number`&&o.nbf-h>m||typeof o.sub!=`string`||o.sub===``)return null;if(t.scopes?.length){let e=new Set(typeof o.scope==`string`?o.scope.split(` `):[]);if(!t.scopes.every(t=>e.has(t)))return null}return o}}}export{e as AccountsRequestError,o as createTokenVerifier};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aui-auth",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "Sign in through assistant-ui accounts: server side sessions for web apps (OIDC code flow with PKCE, tokens kept in the app's store, single flight refresh), the device grant for CLIs, and token verification for resource servers",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
|
-
"next": ">=
|
|
50
|
+
"next": ">=16.3"
|
|
51
51
|
},
|
|
52
52
|
"peerDependenciesMeta": {
|
|
53
53
|
"next": {
|
package/dist/cache-m-qvewq5.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{o as e}from"./types-B_7rFOLg.js";import{p as t}from"./oidc-0pw9wXd4.js";function n(e){if(!e)return;let t=e.split(`,`);return t[t.length-1].trim()||void 0}function r(e){let t=new URL(e.url);return`${n(e.headers.get(`x-forwarded-proto`))||t.protocol.replace(`:`,``)}://${n(e.headers.get(`x-forwarded-host`))||e.headers.get(`host`)||t.host}`}function i(e){return new URL(e).protocol===`https:`}function a(e,t){return t?`__Secure-${e}`:e}function o(e){let t=new Map;if(!e)return t;for(let n of e.split(`;`)){let e=n.indexOf(`=`);if(e===-1)continue;let r=n.slice(0,e).trim();!r||t.has(r)||t.set(r,n.slice(e+1).trim())}return t}function s(e,t){let n=o(e.headers.get(`cookie`));return n.get(a(t,!0))||n.get(a(t,!1))||null}function c(e,t,n,r){let i=[`${e}=${t}`,`Path=/`,`HttpOnly`,`SameSite=Lax`,`Max-Age=${r}`];return n&&i.push(`Secure`),i.join(`; `)}function l(e,t,n,r,o){let s=i(r);e.append(`set-cookie`,c(a(t,s),n,s,Math.floor(o/1e3)))}function u(e,t){if(t.length===0)return;let n=o(e.get(`cookie`));for(let e of t){let t=e.split(`;`)[0],r=t.indexOf(`=`);if(r<1)continue;let i=t.slice(0,r).trim(),a=t.slice(r+1).trim();a?n.set(i,a):n.delete(i)}e.set(`cookie`,[...n].map(([e,t])=>`${e}=${t}`).join(`; `))}function d(e,t){let n=i(t);return[n,!n].map(t=>c(a(e,t),``,t,0))}function f(e,t,n){for(let r of d(t,n))e.append(`set-cookie`,r)}function p(e,t=307){return new Response(null,{status:t,headers:{location:e.toString()}})}function m(e,t){return`${e}_flow_${t}`}function h(e){return btoa(JSON.stringify(e)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function g(e){if(!e)return null;try{let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=JSON.parse(atob(t));return typeof n.verifier==`string`?{verifier:n.verifier,redirectPath:typeof n.redirectPath==`string`?n.redirectPath:`/`,silent:n.silent===!0}:null}catch{return null}}function _(e,t){if(!e)return`/`;let n;try{n=new URL(e,t)}catch{return`/`}return n.origin!==t||n.pathname.startsWith(`//`)?`/`:`${n.pathname}${n.search}${n.hash}`}const v=4096;function y(e){return`${e}_cache`}function b(e,t,n){if(!e.cache)return 0;let{lifetimes:r}=e,i=Math.min(t.lastValidatedAt+r.revalidateIntervalMs,t.tokens.accessTokenExpiresAt-r.refreshBeforeExpiryMs);return Math.min(e.cache.maxAgeMs,(i>n?i:n+r.retryIntervalMs)-n,t.createdAt+r.absoluteMaxAgeMs-n,t.lastValidatedAt+r.idleMaxAgeMs-n)}async function x(e,t,n){if(!e.cache)return null;let r=b(e,t,n);if(r<1e3)return null;let i={v:1,id:t.id,u:t.user,d:t.data,at:t.tokens.accessToken,ate:t.tokens.accessTokenExpiresAt,ca:t.createdAt,lv:t.lastValidatedAt,exp:n+r};return{value:await(await e.cache.codec()).encrypt(JSON.stringify(i)),maxAgeMs:r}}async function S(e,n,r,i){if(!e.cache||!n||!r)return null;let a;try{let t=await e.cache.codec();a=JSON.parse(await t.decrypt(n))}catch{return null}return a.v!==1||typeof a.exp!=`number`||a.exp<=i||a.id!==await t(r)?null:{id:a.id,user:a.u,tokens:{accessToken:a.at,refreshToken:null,idToken:null,accessTokenExpiresAt:a.ate},data:a.d,createdAt:a.ca,lastValidatedAt:a.lv,refreshLeaseUntil:null}}async function C(t,n,r,o){try{let e=await x(t,n,o);if(!e)return null;let s=i(r),l=c(a(y(t.cookieName),s),e.value,s,Math.floor(e.maxAgeMs/1e3));if(l.length>v)throw Error(`Cache cookie is ${l.length} bytes and browsers drop cookies over ${v}; the session data is too large to cache`);return l}catch(n){return e(t,`cache_cookie`,n),null}}function w(e,t){return e.cache?d(y(e.cookieName),t):[]}export{c as _,f as a,g as c,u as d,o as f,_ as g,r as h,S as i,h as l,p as m,y as n,d as o,s as p,C as r,a as s,w as t,m as u,l as v};
|
package/dist/oidc-0pw9wXd4.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{n as e,r as t,t as n}from"./types-B_7rFOLg.js";function r(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function i(e){return r(crypto.getRandomValues(new Uint8Array(e)))}async function a(e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e));return r(new Uint8Array(t))}function o(e,t){return new URL(t,e).toString()}function s(e){return o(e,`/api/auth`)}function c(e){return{issuer:e.issuer,fetch:e.fetch,timeoutMs:e.lifetimes.requestTimeoutMs}}async function l(t,r,i={},a){let s=t.fetch??globalThis.fetch.bind(globalThis),c=t.timeoutMs??e.requestTimeoutMs,l=a===void 0?c:Math.min(c,a-Date.now());if(l<=0)throw new n(`Accounts request deadline passed`,0);return s(o(t.issuer,r),{...i,cache:`no-store`,signal:AbortSignal.timeout(l)})}async function u(e,t){let n=i(24),r=i(32),s=new URL(o(e.issuer,`/api/auth/oauth2/authorize`));return s.searchParams.set(`client_id`,e.clientId),s.searchParams.set(`redirect_uri`,new URL(e.paths.callback,t.origin).toString()),s.searchParams.set(`response_type`,`code`),s.searchParams.set(`scope`,e.scope),s.searchParams.set(`state`,n),s.searchParams.set(`code_challenge`,await a(r)),s.searchParams.set(`code_challenge_method`,`S256`),t.silent&&s.searchParams.set(`prompt`,`none`),{url:s.toString(),state:n,verifier:r}}function d(e,t){let n=new URL(o(e.issuer,`/api/auth/oauth2/end-session`));return n.searchParams.set(`id_token_hint`,t.idToken),n.searchParams.set(`client_id`,e.clientId),n.searchParams.set(`post_logout_redirect_uri`,new URL(e.paths.logoutComplete,t.origin).toString()),n.toString()}function f(e){return{...c(e),clientId:e.clientId,clientSecret:e.clientSecret,audience:e.audience}}async function p(e){let n=await e.text().catch(()=>``),r=`unknown_error`,i=n;try{let e=JSON.parse(n);r=e.error??r,i=e.error_description??i}catch{}return new t(e.status,r,i)}function m(e){return e.code===`invalid_target`||e.code===`invalid_request`&&/resource/i.test(e.description)}async function h(e,t,n,r=!0){let i=new URLSearchParams({client_id:e.clientId,...t});e.clientSecret&&i.set(`client_secret`,e.clientSecret),e.audience&&r&&i.set(`resource`,e.audience);let a=await l(e,`/api/auth/oauth2/token`,{method:`POST`,headers:{"Content-Type":`application/x-www-form-urlencoded`},body:i},n);if(!a.ok){let i=await p(a);if(r&&e.audience&&m(i))return h(e,t,n,!1);throw i}return await a.json()}function g(e,t){return h(f(e),{grant_type:`authorization_code`,code:t.code,code_verifier:t.verifier,redirect_uri:t.redirectUri})}function _(e,t,n){return h(f(e),{grant_type:`refresh_token`,refresh_token:t},n===void 0?void 0:Date.now()+n)}async function v(e,t){let r=await l(e,`/api/auth/oauth2/userinfo`,{headers:{Authorization:`Bearer ${t}`}});if(!r.ok)throw new n(`Failed to load user info: ${r.status}`,r.status);let i=await r.json();return{id:i.sub,email:i.email??``,name:i.name??i.email??i.sub,image:i.picture??null}}function y(e,t,n){return{accessToken:e.access_token,refreshToken:e.refresh_token??t?.refreshToken??null,idToken:e.id_token??t?.idToken??null,accessTokenExpiresAt:typeof e.expires_at==`number`?e.expires_at*1e3:n+(e.expires_in??3600)*1e3}}export{d as a,v as c,m as d,h as f,y as h,u as i,i as l,p as m,l as n,g as o,a as p,s as r,c as s,o as t,_ as u};
|
package/dist/oidc-CbVNB1IR.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { f as AccountsUser } from "./types-Cx223pmJ.js";
|
|
2
|
-
//#region src/core/oidc.d.ts
|
|
3
|
-
type AccountsFetchOptions = {
|
|
4
|
-
issuer: string;
|
|
5
|
-
fetch?: typeof fetch;
|
|
6
|
-
timeoutMs?: number;
|
|
7
|
-
};
|
|
8
|
-
declare function accountsEndpoint(issuer: string, path: string): string;
|
|
9
|
-
declare function fetchUserInfo(options: AccountsFetchOptions, accessToken: string): Promise<AccountsUser>;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { accountsEndpoint as n, fetchUserInfo as r, AccountsFetchOptions as t };
|
package/dist/types-B_7rFOLg.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e){let t=new Uint8Array(e.length/2);for(let n=0;n<e.length;n+=2)t[n/2]=Number.parseInt(e.slice(n,n+2),16);return t}function t(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/g,``)}function n(e){let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r;try{r=atob(n)}catch{throw Error(`Malformed encrypted value`)}let i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i}function r(e){let r=null,i=()=>r??=crypto.subtle.importKey(`raw`,e,{name:`AES-GCM`},!1,[`encrypt`,`decrypt`]);return{async encrypt(e){let n=crypto.getRandomValues(new Uint8Array(12)),r=new Uint8Array(await crypto.subtle.encrypt({name:`AES-GCM`,iv:n},await i(),new TextEncoder().encode(e))),a=new Uint8Array(12+r.length);return a.set(n),a.set(r,12),t(a)},async decrypt(e){let t=n(e);if(t.length<28)throw Error(`Malformed encrypted value`);let r;try{r=await crypto.subtle.decrypt({name:`AES-GCM`,iv:t.subarray(0,12)},await i(),t.subarray(12))}catch{throw Error(`Malformed encrypted value`)}return new TextDecoder().decode(r)}}}function i(t){if(!/^[0-9a-fA-F]{64}$/.test(t))throw Error(`AES-GCM codec key must be 64 hex characters (32 bytes)`);return r(e(t))}function a(e){let t=null;return()=>t??=crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e)).then(e=>r(new Uint8Array(e)))}const o={login:`/api/auth/login`,callback:`/api/auth/callback`,logout:`/api/auth/logout`,logoutComplete:`/api/auth/logout-complete`,error:`/auth/error`},s={absoluteMaxAgeMs:2592e6,idleMaxAgeMs:6048e5,revalidateIntervalMs:12e4,refreshBeforeExpiryMs:3e5,flowMaxAgeMs:6e5,refreshLeaseMs:2e4,leaseWaitMs:5e3,requestTimeoutMs:1e4,retryIntervalMs:1e4},c=Object.freeze({});function l({phase:e,error:t}){console.error(`[aui-auth] ${e}`,t)}function u(e,t,n){try{e.onError({phase:t,error:n})}catch{}}function d(e){return{...e,scope:e.scope??`openid profile email offline_access`,onSignIn:e.onSignIn??(async()=>c),onRevalidate:e.onRevalidate??(async()=>c),onError:e.onError??l,revalidateUser:e.revalidateUser??!1,logout:e.logout??`global`,paths:{...o,...e.paths},lifetimes:{...s,...e.lifetimes},fetch:e.fetch??globalThis.fetch.bind(globalThis),now:e.now??Date.now,cache:e.cache?{codec:a(e.cache.secret),maxAgeMs:e.cache.maxAgeMs??6e4}:null,audience:e.audience===!1?null:e.audience??new URL(`/api/auth`,e.issuer).toString()}}var f=class extends Error{status;constructor(e,t){super(e),this.name=`AccountsRequestError`,this.status=t}},p=class extends Error{constructor(e){super(`Stored session could not be decoded`,{cause:e}),this.name=`SessionDecodeError`}},m=class extends f{code;description;constructor(e,t,n){super(`Token request failed: ${e} ${t} ${n}`,e),this.name=`OAuthTokenError`,this.code=t,this.description=n}};const h=new Set([408,425,429]);function g(e){return e instanceof f&&e.status>=400&&e.status<500&&!h.has(e.status)}export{g as a,i as c,p as i,s as n,u as o,m as r,d as s,f as t};
|