@softwarepatterns/am 0.0.1 → 0.0.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/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +514 -41
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/types/auth.d.ts +369 -35
- package/dist/types/index.d.ts +2 -2
- package/dist/types/types.d.ts +137 -6
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function t(t){return t.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}function
|
|
1
|
+
const t=Symbol("state");function e(t){return t?"localStorage"===t?function(){try{return"undefined"==typeof window?null:window.localStorage?window.localStorage:null}catch{return null}}():t:null}function n(t,e){return t?function(t){if(!t)return null;try{return JSON.parse(t)}catch{return null}}(t.getItem(e)):null}function r(t,e,n){if(t)try{t.setItem(e,JSON.stringify(n))}catch{}}function s(t,e){if(t)try{t.removeItem(e)}catch{}}function o(t,e,o){if(!t)return;const i=n(t,e),c=a(i)?i:null;null===i||c||s(t,e),c&&c.expiresAt>=o.expiresAt||r(t,e,o)}function i(t,e,o){if(!t)return;const i=n(t,e),a=c(i)?i:null;null===i||a||s(t,e),a&&a.lastUpdatedAt>=o.lastUpdatedAt||r(t,e,o)}function a(t){return!!t&&"string"==typeof t.accessToken&&"string"==typeof t.refreshToken&&"number"==typeof t.expiresAt&&"number"==typeof t.expiresIn&&"Bearer"===t.tokenType}function c(t){return!!t&&"string"==typeof t.id&&"string"==typeof t.accountId&&"string"==typeof t.status&&"number"==typeof t.lastUpdatedAt&&("object"==typeof t.identity||null===t.identity)}function u(e){return e[t]}function l(t){return t.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}function f(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(t=>f(t));const e=t,n={};for(const t of Object.keys(e))Object.prototype.hasOwnProperty.call(e,t)&&(n[l(t)]=f(e[t]));return n}function p(t){return t.replace(/[A-Z]/g,t=>`_${t.toLowerCase()}`)}function h(t){if(null===t||"object"!=typeof t)return t;if(Array.isArray(t))return t.map(t=>h(t));const e=t,n={};for(const t of Object.keys(e))Object.prototype.hasOwnProperty.call(e,t)&&(n[p(t)]=h(e[t]));return n}class y extends Error{constructor(t){super(t.title),this.name="AuthError",this.problem=Object.freeze(t)}get type(){return this.problem.type}get title(){return this.problem.title}get status(){return this.problem.status}get code(){return this.problem.code}get detail(){return this.problem.detail}get invalidParams(){return this.problem.invalidParams}}const g={fetchFn:function(){const t=globalThis.fetch;return"function"==typeof t?t.bind(globalThis):async()=>{throw new Error("Missing fetch implementation. Provide config.fetchFn or use a runtime with global fetch.")}}(),baseUrl:"https://api.accountmaker.com",earlyRefreshMs:6e4,storage:null,tokensStorageKey:"am_tokens",profileStorageKey:"am_profile"};const d=async t=>{if(204===t.status)return;const e=f(await async function(t){const e=t.headers.get("Content-Type")||"";if(!e.includes("application/json")&&!e.includes("+json"))return null;try{return await t.json()}catch{return null}}(t));if(!t.ok)throw new y(function(t,e){return function(t){return(t.headers.get("Content-Type")||"").includes("application/problem+json")}(t)&&e&&"object"==typeof e&&"string"==typeof e.type&&"string"==typeof e.title&&"number"==typeof e.status?e:function(t,e){return{type:"about:blank",title:t.statusText||"Request failed",status:t.status,detail:"string"==typeof e?e:void 0}}(t,e)}(t,e));return e},w=async({fetchFn:t,baseUrl:e},n,r={})=>{const s=new URLSearchParams(h(r)).toString(),o=s?`${e}${n}?${s}`:`${e}${n}`,i=await t(o,{method:"GET",headers:{Accept:"application/json"}});return d(i)},m=async({fetchFn:t,baseUrl:e},n,r)=>{const s=await t(`${e}${n}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(h(r))});return d(s)},k=async(t,e,n={})=>{const r=await t.config.fetchFn(e,{...n,headers:{...n.headers||{},Authorization:`Bearer ${t.tokens.accessToken}`}});return d(r)},b=t=>{const e=Math.min(Math.max(t.config.earlyRefreshMs,0),3e5);return Date.now()>=t.tokens.expiresAt-e},S=async t=>{if(!t.cleared){t.refreshPromise||(t.refreshPromise=async function(t){const{fetchFn:n,baseUrl:r}=t.config,s=await n(`${r}/auth/refresh`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(h({refreshToken:t.tokens.refreshToken}))}),i=j(await d(s));t.tokens=i;const a=e(t.config.storage);o(a,t.config.tokensStorageKey,i),await(t.config.onRefresh?.(i))}(t));try{await t.refreshPromise}finally{t.refreshPromise=null}}},T=t=>t instanceof y&&401===t.status,P=async(t,e,n={})=>{b(t)&&await S(t);try{return await k(t,e,n)}catch(r){if(!T(r))throw r;if(t.cleared)throw r;try{return await S(t),await k(t,e,n)}catch(e){if(t.config.onUnauthenticated&&!t.cleared&&T(e))try{await t.config.onUnauthenticated(e)}catch{}throw e}}},A=async(t,e,n={})=>{const r=new URLSearchParams(h(n)).toString(),s=t.config.baseUrl,o=r?`${s}${e}?${r}`:`${s}${e}`;return await P(t,o,{method:"GET",headers:{Accept:"application/json"}})},j=t=>{const e="number"==typeof t.expiresIn?t.expiresIn:0;return{...t,expiresAt:Date.now()+1e3*e}},I=t=>({...t,lastUpdatedAt:Date.now()});const U=t=>({tokens:j(t.tokens),profile:I(t.profile)});class ${constructor(n,r){const s={...g,...r},a={...n,config:s,refreshPromise:null,profilePromise:null,cleared:!1};!function(e,n){e[t]=n}(this,a);const c=e(s.storage);o(c,s.tokensStorageKey,a.tokens),a.profile&&i(c,s.profileStorageKey,a.profile)}static restoreSession(t={}){const r={...g,...t},o=e(r.storage);if(!o)return null;const i=n(o,r.tokensStorageKey),u=a(i)?i:null;if(!u)return null!==i&&s(o,r.tokensStorageKey),s(o,r.profileStorageKey),null;const l=n(o,r.profileStorageKey),f=c(l)?l:null;return null===l||f||s(o,r.profileStorageKey),new $({tokens:u,profile:f},r)}clear(){const t=u(this);!function(t){const n=e(t.storage);s(n,t.profileStorageKey),s(n,t.tokensStorageKey)}(t.config),t.cleared=!0}accessToken(){return u(this).tokens.accessToken}refreshToken(){return u(this).tokens.refreshToken}idToken(){return u(this).tokens.idToken}expiresIn(){return u(this).tokens.expiresIn}expiresAt(){return new Date(u(this).tokens.expiresAt)}profile(){return u(this).profile}toJSON(){const t=u(this);return{tokens:t.tokens,profile:t.profile}}static fromJSON(t,e){return new $(t,e)}isExpired(){return b(u(this))}async fetch(t,e={}){return P(u(this),t,e)}async refresh(){return S(u(this))}async refetchProfile(){const t=u(this);if(!t.cleared){t.profilePromise||(t.profilePromise=async function(t){const n=I(await A(t,"/auth/me",{}));t.profile=n,i(e(t.config.storage),t.config.profileStorageKey,n),await(t.config.onProfileRefetch?.(n))}(t));try{await t.profilePromise}finally{t.profilePromise=null}}}async sendVerificationEmail(){await(async(t,e,n)=>{const r=t.config.baseUrl;return await P(t,`${r}${e}`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(h(n))})})(u(this),"/auth/send-verification-email",{})}async user(t){return A(u(this),`/auth/user/${t}`,{})}}class x{constructor(t){this.options={...g,...t}}static createAuthSession(t,e){return new x(e).createAuthSession(t)}createAuthSession(t){return new $(t,this.options)}static async acceptInvite(t,e){return new x(e).acceptInvite(t)}async acceptInvite(t){const e=U(await w(this.options,"/auth/accept-invite",t));return new $(e,this.options)}static async checkEmail(t,e){return new x(e).checkEmail(t)}async checkEmail(t){return m(this.options,"/auth/check-email",t)}static async csrfSession(t){return new x(t).csrfSession()}async csrfSession(){return w(this.options,"/auth/csrf-session")}static async csrfToken(t){return new x(t).csrfToken()}async csrfToken(){return w(this.options,"/auth/csrf-token")}static async signIn(t,e){return new x(e).signIn(t)}async signIn(t){const e=U(await m(this.options,"/auth/sign-in",t));return new $(e,this.options)}static async signInWithToken(t,e){return new x(e).signInWithToken(t)}async signInWithToken(t){const e=this.options,n=U(await w(e,"/auth/sign-in-with-token",{token:t}));return new $(n,e)}static async refresh(t,e){return new x(e).refresh(t)}async refresh(t){return j(await m(this.options,"/auth/refresh",{refreshToken:t}))}static async signUp(t,e){return new x(e).signUp(t)}async signUp(t){const e=U(await m(this.options,"/auth/sign-up",t));return new $(e,this.options)}static async resetPassword(t,e){return new x(e).resetPassword(t)}async resetPassword(t){return m(this.options,"/auth/reset-password",t)}static async sendMagicLink(t,e){return new x(e).sendMagicLink(t)}async sendMagicLink(t){return m(this.options,"/auth/send-magic-link",t)}static async sendPasswordReset(t,e){return new x(e).sendPasswordReset(t)}async sendPasswordReset(t){return m(this.options,"/auth/send-password-reset",t)}}export{x as Am,y as AuthError,$ as AuthSession};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/auth.ts"],"sourcesContent":[null],"names":["camelCaseStr","str","replace","_","letter","toUpperCase","camelCaseObj","input","Array","isArray","map","item","obj","result","key","Object","keys","prototype","hasOwnProperty","call","snakeCaseStr","toLowerCase","snakeCaseObj","AuthError","Error","constructor","problem","super","title","this","name","freeze","type","status","code","detail","invalidParams","defaultConfig","fetchFn","f","globalThis","fetch","async","defaultFetchFn","baseUrl","handleResponse","res","raw","contentType","headers","get","includes","json","readJsonSafe","ok","isProblemJson","statusText","toGenericProblem","undefined","unauthGet","path","query","qs","URLSearchParams","toString","url","method","Accept","unauthPost","body","JSON","stringify","authGet","accessToken","Authorization","AuthSession","tokens","config","lastUpdated","Date","refreshToken","idToken","tokenType","expiresIn","lastUpdatedAt","expiresAt","getTime","isExpired","now","init","refresh","sendVerificationEmail","authPost","me","user","id","Am","options","createAuthSession","acceptInvite","checkEmail","csrfSession","csrfToken","login","tokenLogin","token","register","resetPassword","sendMagicLink","sendPasswordReset"],"mappings":"AAmBA,SAASA,EAAaC,GACpB,OAAOA,EAAIC,QAAQ,YAAa,CAACC,EAAGC,IAAWA,EAAOC,cACxD,CAEA,SAASC,EAAaC,GACpB,GAAc,OAAVA,GAAmC,iBAA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
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/auth.ts"],"sourcesContent":[null],"names":["STATE","Symbol","resolveStorage","storageConfig","window","localStorage","getBrowserLocalStorage","readJson","storage","key","raw","JSON","parse","safeParse","getItem","writeJson","value","setItem","stringify","removeKey","removeItem","writeTokensIfNewer","next","curRaw","cur","isSessionTokens","expiresAt","writeProfileIfNewer","isSessionProfile","lastUpdatedAt","x","accessToken","refreshToken","expiresIn","tokenType","id","accountId","status","identity","getState","session","camelCaseStr","str","replace","_","letter","toUpperCase","camelCaseObj","input","Array","isArray","map","item","obj","result","Object","keys","prototype","hasOwnProperty","call","snakeCaseStr","toLowerCase","snakeCaseObj","AuthError","Error","constructor","problem","super","title","this","name","freeze","type","code","detail","invalidParams","defaultConfig","fetchFn","f","globalThis","fetch","bind","async","defaultFetchFn","baseUrl","earlyRefreshMs","tokensStorageKey","profileStorageKey","handleResponse","res","json","contentType","headers","get","includes","readJsonSafe","ok","isProblemJson","statusText","undefined","toGenericProblem","getProblemJson","unauthGet","path","query","qs","URLSearchParams","toString","url","method","Accept","unauthPost","body","authFetch","state","init","config","Authorization","tokens","isExpired","early","Math","min","max","Date","now","refresh","cleared","refreshPromise","toSessionTokens","onRefresh","doRefresh","isUnauthenticatedAuthError","e","authFetchWithRefresh","e2","onUnauthenticated","authGet","toSessionProfile","profile","handleAuthenticationResponse","AuthSession","initial","merged","profilePromise","setState","restoreSession","tokensRaw","profileRaw","clear","clearAuth","idToken","toJSON","fromJSON","refetchProfile","onProfileRefetch","doRefetchProfile","sendVerificationEmail","authPost","user","Am","options","createAuthSession","acceptInvite","checkEmail","csrfSession","csrfToken","signIn","signInWithToken","token","signUp","resetPassword","sendMagicLink","sendPasswordReset"],"mappings":"AAaA,MACMA,EAAQC,OAAO,SAwCrB,SAASC,EAAeC,GACtB,OAAKA,EACiB,iBAAlBA,EAZN,WACE,IACE,MAAsB,oBAAXC,OAA+B,KACrCA,OAAOC,aACLD,OAAOC,aADmB,IAEnC,CAA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ACfnB,EAAUF,QACRtC,EAAU2D,EAAS,2BAA4B,CACnDQ,WAIJ,OAAO,IAAI5B,EAAYC,EAASmB,EAClC,CAUA,oBAAanC,CACX9F,EACAoF,GAEA,OAAO,IAAI4C,EAAG5C,GAAQU,QAAQ9F,EAChC,CAUA,aAAM8F,CAAQ9F,GACZ,OAAOiG,QACClB,EAAW1C,KAAK4F,QAAS,gBAAiB,CAC9CjI,iBAGN,CASA,mBAAa0I,CACX1D,EAMAI,GAEA,OAAO,IAAI4C,EAAG5C,GAAQsD,OAAO1D,EAC/B,CASA,YAAM0D,CAAO1D,GAMX,MAAM8B,EAAUF,QACR7B,EAAW1C,KAAK4F,QAAS,gBAAiBjD,IAGlD,OAAO,IAAI6B,EAAYC,EAASzE,KAAK4F,QACvC,CASA,0BAAaU,CACX3D,EAIAI,GAEA,OAAO,IAAI4C,EAAG5C,GAAQuD,cAAc3D,EACtC,CASA,mBAAM2D,CAAc3D,GAIlB,OAAOD,EAAW1C,KAAK4F,QAAS,uBAAwBjD,EAC1D,CASA,0BAAa4D,CACX5D,EAKAI,GAEA,OAAO,IAAI4C,EAAG5C,GAAQwD,cAAc5D,EACtC,CASA,mBAAM4D,CAAc5D,GAKlB,OAAOD,EAAW1C,KAAK4F,QAAS,wBAAyBjD,EAC3D,CAQA,8BAAa6D,CACX7D,EAKAI,GAEA,OAAO,IAAI4C,EAAG5C,GAAQyD,kBAAkB7D,EAC1C,CAQA,uBAAM6D,CAAkB7D,GAKtB,OAAOD,EAAW1C,KAAK4F,QAAS,4BAA6BjD,EAC/D"}
|
package/dist/types/auth.d.ts
CHANGED
|
@@ -1,5 +1,61 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Authentication, ClientId, EmailCheckStatus, LoginMethod, ProblemDetails, SessionProfile, SessionTokens, UserId, UserResource, StorageLike } from "./types";
|
|
2
|
+
type StorageConfig = StorageLike | "localStorage" | null | undefined;
|
|
2
3
|
type FetchFn = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
4
|
+
type Config = {
|
|
5
|
+
baseUrl: string;
|
|
6
|
+
earlyRefreshMs: number;
|
|
7
|
+
fetchFn: FetchFn;
|
|
8
|
+
onRefresh?: (tokens: SessionTokens) => void | Promise<void>;
|
|
9
|
+
onProfileRefetch?: (profile: SessionProfile) => void | Promise<void>;
|
|
10
|
+
onUnauthenticated?: (e: AuthError) => void | Promise<void>;
|
|
11
|
+
profileStorageKey: string;
|
|
12
|
+
storage: StorageConfig;
|
|
13
|
+
tokensStorageKey: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Error type for authentication-related failures.
|
|
17
|
+
*
|
|
18
|
+
* Always thrown on non-2xx responses from auth endpoints. Contains structured ProblemDetails
|
|
19
|
+
* from the server when available.
|
|
20
|
+
*
|
|
21
|
+
* Most 400 errors will also contain `invalidParams` for parameters that caused
|
|
22
|
+
* the error, which can be used to display field-level validation messages.
|
|
23
|
+
*
|
|
24
|
+
* Note that network errors, timeouts, etc. will throw other Error types (e.g. TypeError) unrelated
|
|
25
|
+
* to AuthError.
|
|
26
|
+
*
|
|
27
|
+
* Note that HTTP error codes are distinctly:
|
|
28
|
+
* - 400: Client error (bad request, invalid input, etc.)
|
|
29
|
+
* - 401: Unauthenticated (we don't know who you are)
|
|
30
|
+
* - 402: Payment required (e.g. billing issue)
|
|
31
|
+
* - 403: Unauthorized (we know who you are, but you don't have permission)
|
|
32
|
+
* - 404: Not found
|
|
33
|
+
* - 409: Conflict (email already registered, user already invited, etc.)
|
|
34
|
+
* - 429: Too many requests (rate limiting)
|
|
35
|
+
* - 500: Internal server error (server's fault)
|
|
36
|
+
*
|
|
37
|
+
* Also note that the `type` field often contains a URI that points to documentation about the
|
|
38
|
+
* specific error type, including how to resolve it, code samples, and links to the RFCs or other
|
|
39
|
+
* standards that define the error.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* try {
|
|
44
|
+
* const session = await am.signIn({ email: 'test@example.com', password: 'password123' });
|
|
45
|
+
* } catch (e) {
|
|
46
|
+
* if (e instanceof AuthError) {
|
|
47
|
+
* console.error("Authentication failed:", e.title);
|
|
48
|
+
* if (e.invalidParams) {
|
|
49
|
+
* for (const param of e.invalidParams) {
|
|
50
|
+
* console.error(` - Invalid parameter: ${param.path} (${param.type})`);
|
|
51
|
+
* }
|
|
52
|
+
* }
|
|
53
|
+
* } else {
|
|
54
|
+
* console.error("Unexpected error:", e);
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
3
59
|
export declare class AuthError extends Error {
|
|
4
60
|
readonly problem: ProblemDetails;
|
|
5
61
|
constructor(problem: ProblemDetails);
|
|
@@ -10,48 +66,177 @@ export declare class AuthError extends Error {
|
|
|
10
66
|
get detail(): string | undefined;
|
|
11
67
|
get invalidParams(): ProblemDetails["invalidParams"] | undefined;
|
|
12
68
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
69
|
+
/**
|
|
70
|
+
* You receive an AuthSession after successful sign-in/register/etc.
|
|
71
|
+
*
|
|
72
|
+
* It contains the current access token, user profile, and methods to perform authorized
|
|
73
|
+
* requests.
|
|
74
|
+
*
|
|
75
|
+
* Features:
|
|
76
|
+
* - session.fetch() will always use a valid access token (refreshing automatically)
|
|
77
|
+
* - All non-2xx responses throw AuthError
|
|
78
|
+
* - Tokens and profile are automatically persisted to storage (if configured)
|
|
79
|
+
*/
|
|
17
80
|
export declare class AuthSession {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
81
|
+
constructor(initial: Authentication, config: Partial<Config>);
|
|
82
|
+
/**
|
|
83
|
+
* Restores an AuthSession from persisted storage. Returns null if no valid session
|
|
84
|
+
* is found.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const session = AuthSession.restoreSession();
|
|
89
|
+
* if (session) {
|
|
90
|
+
* console.log("Restored session for user:", session.profile);
|
|
91
|
+
* } else {
|
|
92
|
+
* console.log("No valid session found.");
|
|
93
|
+
* }
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
static restoreSession(config?: Partial<Config>): AuthSession | null;
|
|
97
|
+
/**
|
|
98
|
+
* Removes all persisted data (tokens, profile) from storage, and prevents future
|
|
99
|
+
* refreshs of token and profile data. Does NOT clear current token or profile data from the
|
|
100
|
+
* session memory, but effectively deactivates the session for future use.
|
|
101
|
+
*/
|
|
102
|
+
clear(): void;
|
|
103
|
+
accessToken(): string;
|
|
104
|
+
refreshToken(): string;
|
|
105
|
+
idToken(): string | undefined;
|
|
106
|
+
expiresIn(): number;
|
|
107
|
+
expiresAt(): Date;
|
|
108
|
+
profile(): SessionProfile | null;
|
|
109
|
+
toJSON(): Authentication;
|
|
110
|
+
/**
|
|
111
|
+
* Creates an AuthSession from existing authentication data. Useful for restoring
|
|
112
|
+
* a session from custom storage or creating a session from custom server-provided data.
|
|
113
|
+
*/
|
|
114
|
+
static fromJSON(initial: Authentication, config: Partial<Config>): AuthSession;
|
|
115
|
+
/**
|
|
116
|
+
* Returns true if the access token is expired or will expire soon. The
|
|
117
|
+
* "soon" threshold is configured via Config.earlyRefreshMs (default 1 minute).
|
|
118
|
+
*/
|
|
29
119
|
isExpired(): boolean;
|
|
30
120
|
/**
|
|
31
|
-
*
|
|
121
|
+
* Perform an authenticated fetch. Used to call your own APIs with the current
|
|
122
|
+
* session's access token. Any service can validate the token against Am's public
|
|
123
|
+
* keys at https://api.accountmaker.com/.well-known/jwks.json?client_id={clientId}
|
|
124
|
+
*
|
|
125
|
+
* Automatically:
|
|
126
|
+
* - Adds Authorization header
|
|
127
|
+
* - Refreshes token if expired
|
|
128
|
+
* - Retries once on 401 if refresh succeeds
|
|
129
|
+
*
|
|
130
|
+
* Assumes the response is JSON and parses it. Throws AuthError on non-2xx responses.
|
|
131
|
+
*
|
|
132
|
+
* If the error is a RFC 7807 Problem Details response, the AuthError.problem
|
|
133
|
+
* will contain the full details.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```ts
|
|
137
|
+
* const res = await session.fetch('/api/projects');
|
|
138
|
+
* const projects = await res.json();
|
|
139
|
+
* ```
|
|
32
140
|
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
141
|
+
* Throws AuthError on network errors, etc.
|
|
142
|
+
* @throws AuthError
|
|
143
|
+
*/
|
|
144
|
+
fetch(url: string | URL, init?: RequestInit): Promise<any>;
|
|
145
|
+
/**
|
|
146
|
+
* Refreshes the access token using the refresh token. Updates the stored tokens on
|
|
147
|
+
* success. This is called automatically by fetch() if the token is expired or close to
|
|
148
|
+
* expiring.
|
|
35
149
|
*/
|
|
36
|
-
fetch(url: string | URL | Request, init?: RequestInit): Promise<Response>;
|
|
37
150
|
refresh(): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Refetches the user's profile from the server and updates the stored profile.
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* await session.refetchProfile();
|
|
157
|
+
* console.log("Updated profile:", session.profile);
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* Throws AuthError on network errors, etc.
|
|
161
|
+
* @throws AuthError
|
|
162
|
+
*/
|
|
163
|
+
refetchProfile(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Sends a verification email to the user's primary email address. This only succeeds if
|
|
166
|
+
* called by the currently authenticated user or an account admin.
|
|
167
|
+
*
|
|
168
|
+
* Throws AuthError on network errors, etc.
|
|
169
|
+
* @throws AuthError
|
|
170
|
+
*/
|
|
38
171
|
sendVerificationEmail(): Promise<void>;
|
|
39
|
-
|
|
172
|
+
/**
|
|
173
|
+
* Fetches a user by ID.
|
|
174
|
+
*
|
|
175
|
+
* Throws AuthError on invalid user ID, network errors, etc.
|
|
176
|
+
* @throws AuthError
|
|
177
|
+
*/
|
|
40
178
|
user(id: UserId): Promise<UserResource>;
|
|
41
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Use `Am` to perform initial sign-in, registration, password reset flows, magic links,
|
|
182
|
+
* invite acceptance, and other unauthenticated actions.
|
|
183
|
+
*
|
|
184
|
+
* Once authentication succeeds, these methods return an `AuthSession` that you use
|
|
185
|
+
* for all subsequent authenticated requests.
|
|
186
|
+
*
|
|
187
|
+
* Example:
|
|
188
|
+
* ```ts
|
|
189
|
+
* const am = new Am();
|
|
190
|
+
* const session = await am.signIn({ email: 'user@example.com', password: 'secret' });
|
|
191
|
+
* // Now use `session` for protected API calls
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
42
194
|
export declare class Am {
|
|
43
195
|
private options;
|
|
44
196
|
constructor(config?: Partial<Config>);
|
|
45
|
-
|
|
46
|
-
|
|
197
|
+
/**
|
|
198
|
+
* Creates an AuthSession from existing authentication data. Useful for restoring
|
|
199
|
+
* a session from custom storage or creating a session from custom server-provided data.
|
|
200
|
+
*/
|
|
201
|
+
static createAuthSession(initial: Authentication, config?: Partial<Config>): AuthSession;
|
|
202
|
+
/**
|
|
203
|
+
* Creates an AuthSession from existing authentication data. Useful for restoring
|
|
204
|
+
* a session from custom storage or creating a session from custom server-provided data.
|
|
205
|
+
*/
|
|
206
|
+
createAuthSession(initial: Authentication): AuthSession;
|
|
207
|
+
/**
|
|
208
|
+
* Accepts an invitation to join an account. On success, returns an AuthSession
|
|
209
|
+
* containing fresh tokens and profile. Tokens are automatically persisted (if
|
|
210
|
+
* storage is enabled).
|
|
211
|
+
*
|
|
212
|
+
* Throws AuthError on invalid or expired token, etc.
|
|
213
|
+
* @throws AuthError
|
|
214
|
+
*/
|
|
47
215
|
static acceptInvite(query: {
|
|
48
216
|
clientId: ClientId;
|
|
49
217
|
token: string;
|
|
50
|
-
}, config?: Partial<Config>): Promise<
|
|
218
|
+
}, config?: Partial<Config>): Promise<AuthSession>;
|
|
219
|
+
/**
|
|
220
|
+
* Accepts an invitation to join an account. On success, returns an AuthSession
|
|
221
|
+
* containing fresh tokens and profile. Tokens are automatically persisted (if
|
|
222
|
+
* storage is enabled).
|
|
223
|
+
*
|
|
224
|
+
* Throws AuthError on invalid or expired token, etc.
|
|
225
|
+
* @throws AuthError
|
|
226
|
+
*/
|
|
51
227
|
acceptInvite(query: {
|
|
52
228
|
clientId: ClientId;
|
|
53
229
|
token: string;
|
|
54
|
-
}): Promise<
|
|
230
|
+
}): Promise<AuthSession>;
|
|
231
|
+
/**
|
|
232
|
+
* Checks the status of an email address for authentication purposes. Indicates whether the
|
|
233
|
+
* email is associated with an active account, and what login methods are preferred and
|
|
234
|
+
* available for that user. This can be used to enforce login expierences for enterprise SSO or
|
|
235
|
+
* to prefer passwordless login methods.
|
|
236
|
+
*
|
|
237
|
+
* Throws AuthError on invalid client ID, network errors, etc.
|
|
238
|
+
* @throws AuthError
|
|
239
|
+
*/
|
|
55
240
|
static checkEmail(body: {
|
|
56
241
|
clientId: ClientId;
|
|
57
242
|
email: string;
|
|
@@ -61,6 +246,15 @@ export declare class Am {
|
|
|
61
246
|
preferred: LoginMethod[];
|
|
62
247
|
available: LoginMethod[];
|
|
63
248
|
}>;
|
|
249
|
+
/**
|
|
250
|
+
* Checks the status of an email address for authentication purposes. Indicates whether the
|
|
251
|
+
* email is associated with an active account, and what login methods are preferred and
|
|
252
|
+
* available for that user. This can be used to enforce login expierences for enterprise SSO or
|
|
253
|
+
* to prefer passwordless login methods.
|
|
254
|
+
*
|
|
255
|
+
* Throws AuthError on invalid client ID, network errors, etc.
|
|
256
|
+
* @throws AuthError
|
|
257
|
+
*/
|
|
64
258
|
checkEmail(body: {
|
|
65
259
|
clientId: ClientId;
|
|
66
260
|
email: string;
|
|
@@ -70,63 +264,203 @@ export declare class Am {
|
|
|
70
264
|
preferred: LoginMethod[];
|
|
71
265
|
available: LoginMethod[];
|
|
72
266
|
}>;
|
|
267
|
+
/**
|
|
268
|
+
* When called, sets a httpOnly CSRF session cookie. Then when rendering a form, call csrfToken()
|
|
269
|
+
* to get the signed token to include in the form. When the form is submitted, the server
|
|
270
|
+
* will verify the signed token against the session cookie. This prevents a certain class
|
|
271
|
+
* of CSRF attacks that rely on being able to read values from the target site.
|
|
272
|
+
*/
|
|
73
273
|
static csrfSession(config?: Partial<Config>): Promise<{
|
|
74
274
|
csrfToken: string;
|
|
75
275
|
}>;
|
|
276
|
+
/**
|
|
277
|
+
* When called, sets a httpOnly CSRF session cookie. Then when rendering a form, call csrfToken()
|
|
278
|
+
* to get the signed token to include in the form. When the form is submitted, the server
|
|
279
|
+
* will verify the signed token against the session cookie. This prevents a certain class
|
|
280
|
+
* of CSRF attacks that rely on being able to read values from the target site.
|
|
281
|
+
*/
|
|
76
282
|
csrfSession(): Promise<{
|
|
77
283
|
csrfToken: string;
|
|
78
284
|
}>;
|
|
285
|
+
/**
|
|
286
|
+
* Fetches a signed CSRF token for use in forms. Call csrfSession() first to set a httpOnly CSRF
|
|
287
|
+
* session cookie, then call this method to get the signed token, then include the token in your
|
|
288
|
+
* form submissions. When the form is submitted, the server will verify the signed token against
|
|
289
|
+
* the httpOnly session cookie. This prevents a certain class of CSRF attacks that rely on being
|
|
290
|
+
* able to read values from the target site.
|
|
291
|
+
*
|
|
292
|
+
* @throws AuthError
|
|
293
|
+
*/
|
|
79
294
|
static csrfToken(config?: Partial<Config>): Promise<{
|
|
80
295
|
csrfToken: string;
|
|
81
296
|
}>;
|
|
297
|
+
/**
|
|
298
|
+
* Fetches a signed CSRF token for use in forms. Call csrfSession() first to set a httpOnly CSRF
|
|
299
|
+
* session cookie, then call this method to get the signed token, then include the token in your
|
|
300
|
+
* form submissions. When the form is submitted, the server will verify the signed token against
|
|
301
|
+
* the httpOnly session cookie. This prevents a certain class of CSRF attacks that rely on being
|
|
302
|
+
* able to read values from the target site.
|
|
303
|
+
*
|
|
304
|
+
* @throws AuthError
|
|
305
|
+
*/
|
|
82
306
|
csrfToken(): Promise<{
|
|
83
307
|
csrfToken: string;
|
|
84
308
|
}>;
|
|
85
|
-
|
|
309
|
+
/**
|
|
310
|
+
* On success, returns an AuthSession containing fresh tokens and profile.
|
|
311
|
+
* Tokens are automatically persisted (if storage is enabled).
|
|
312
|
+
*
|
|
313
|
+
* Throws AuthError on invalid credentials, unverified email, etc.
|
|
314
|
+
* @throws AuthError
|
|
315
|
+
*/
|
|
316
|
+
static signIn(body: {
|
|
317
|
+
clientId: ClientId;
|
|
86
318
|
email: string;
|
|
87
319
|
password: string;
|
|
88
320
|
csrfToken?: string;
|
|
89
|
-
}, config?: Partial<Config>): Promise<
|
|
90
|
-
|
|
321
|
+
}, config?: Partial<Config>): Promise<AuthSession>;
|
|
322
|
+
/**
|
|
323
|
+
* On success, returns an AuthSession containing fresh tokens and profile.
|
|
324
|
+
* Tokens are automatically persisted (if storage is enabled).
|
|
325
|
+
*
|
|
326
|
+
* Throws AuthError on invalid credentials, unverified email, etc.
|
|
327
|
+
* @throws AuthError
|
|
328
|
+
*/
|
|
329
|
+
signIn(body: {
|
|
330
|
+
clientId: ClientId;
|
|
91
331
|
email: string;
|
|
92
332
|
password: string;
|
|
93
333
|
csrfToken?: string;
|
|
94
|
-
}): Promise<
|
|
95
|
-
|
|
96
|
-
|
|
334
|
+
}): Promise<AuthSession>;
|
|
335
|
+
/**
|
|
336
|
+
* Authenticates using a one-time token (e.g., magic link or invite token).
|
|
337
|
+
*
|
|
338
|
+
* On success, returns an AuthSession containing fresh tokens and profile.
|
|
339
|
+
* Tokens are automatically persisted (if storage is enabled).
|
|
340
|
+
*
|
|
341
|
+
* Throws AuthError on invalid or expired token, etc.
|
|
342
|
+
* @throws AuthError
|
|
343
|
+
*/
|
|
344
|
+
static signInWithToken(token: string, config?: Partial<Config>): Promise<AuthSession>;
|
|
345
|
+
/**
|
|
346
|
+
* Authenticates using a one-time token (e.g., magic link or invite token).
|
|
347
|
+
*
|
|
348
|
+
* On success, returns an AuthSession containing fresh tokens and profile.
|
|
349
|
+
* Tokens are automatically persisted (if storage is enabled).
|
|
350
|
+
*
|
|
351
|
+
* Throws AuthError on invalid or expired token, etc.
|
|
352
|
+
* @throws AuthError
|
|
353
|
+
*/
|
|
354
|
+
signInWithToken(token: string): Promise<AuthSession>;
|
|
355
|
+
/**
|
|
356
|
+
* Manually refreshes session tokens using the provided refresh token. Does NOT
|
|
357
|
+
* persist tokens. Use AuthSession.refresh() to refresh and persist tokens in an
|
|
358
|
+
* existing session.
|
|
359
|
+
*
|
|
360
|
+
* Throws AuthError on invalid or expired refresh token, etc.
|
|
361
|
+
* @throws AuthError
|
|
362
|
+
*/
|
|
97
363
|
static refresh(refreshToken: string, config?: Partial<Config>): Promise<SessionTokens>;
|
|
364
|
+
/**
|
|
365
|
+
* Manually refreshes session tokens using the provided refresh token. Does NOT
|
|
366
|
+
* persist tokens. Use AuthSession.refresh() to refresh and persist tokens in an
|
|
367
|
+
* existing session.
|
|
368
|
+
*
|
|
369
|
+
* Throws AuthError on invalid or expired refresh token, etc.
|
|
370
|
+
* @throws AuthError
|
|
371
|
+
*/
|
|
98
372
|
refresh(refreshToken: string): Promise<SessionTokens>;
|
|
99
|
-
|
|
373
|
+
/**
|
|
374
|
+
* Successful registration immediately authenticates the user and returns an
|
|
375
|
+
* AuthSession. Tokens are automatically persisted (if storage is enabled).
|
|
376
|
+
*
|
|
377
|
+
* Throws AuthError on invalid data, existing email, etc.
|
|
378
|
+
* @throws AuthError
|
|
379
|
+
*/
|
|
380
|
+
static signUp(body: {
|
|
381
|
+
clientId: ClientId;
|
|
100
382
|
email: string;
|
|
101
383
|
password: string;
|
|
102
384
|
csrfToken?: string;
|
|
103
|
-
}, config?: Partial<Config>): Promise<
|
|
104
|
-
|
|
385
|
+
}, config?: Partial<Config>): Promise<AuthSession>;
|
|
386
|
+
/**
|
|
387
|
+
* Successful registration immediately authenticates the user and returns an
|
|
388
|
+
* AuthSession. Tokens are automatically persisted (if storage is enabled).
|
|
389
|
+
*
|
|
390
|
+
* Throws AuthError on invalid data, existing email, etc.
|
|
391
|
+
* @throws AuthError
|
|
392
|
+
*/
|
|
393
|
+
signUp(body: {
|
|
394
|
+
clientId: ClientId;
|
|
105
395
|
email: string;
|
|
106
396
|
password: string;
|
|
107
397
|
csrfToken?: string;
|
|
108
|
-
}): Promise<
|
|
398
|
+
}): Promise<AuthSession>;
|
|
399
|
+
/**
|
|
400
|
+
* Completes a password reset using the token received via email. On success,
|
|
401
|
+
* the user's password is updated.
|
|
402
|
+
*
|
|
403
|
+
* Throws AuthError on invalid or expired token, weak password, etc.
|
|
404
|
+
* @throws AuthError
|
|
405
|
+
*/
|
|
109
406
|
static resetPassword(body: {
|
|
110
407
|
token: string;
|
|
111
408
|
newPassword: string;
|
|
112
409
|
}, config?: Partial<Config>): Promise<void>;
|
|
410
|
+
/**
|
|
411
|
+
* Completes a password reset using the token received via email. On success,
|
|
412
|
+
* the user's password is updated.
|
|
413
|
+
*
|
|
414
|
+
* Throws AuthError on invalid or expired token, weak password, etc.
|
|
415
|
+
* @throws AuthError
|
|
416
|
+
*/
|
|
113
417
|
resetPassword(body: {
|
|
114
418
|
token: string;
|
|
115
419
|
newPassword: string;
|
|
116
420
|
}): Promise<void>;
|
|
421
|
+
/**
|
|
422
|
+
* Sends a magic link email to the specified address. A magic link allows
|
|
423
|
+
* passwordless authentication.
|
|
424
|
+
*
|
|
425
|
+
* Throws AuthError on invalid email format, etc.
|
|
426
|
+
* @throws AuthError
|
|
427
|
+
*/
|
|
117
428
|
static sendMagicLink(body: {
|
|
429
|
+
clientId: ClientId;
|
|
118
430
|
email: string;
|
|
119
431
|
csrfToken?: string;
|
|
120
432
|
}, config?: Partial<Config>): Promise<void>;
|
|
433
|
+
/**
|
|
434
|
+
* Sends a magic link email to the specified address. A magic link allows
|
|
435
|
+
* passwordless authentication.
|
|
436
|
+
*
|
|
437
|
+
* Throws AuthError on invalid email format, etc.
|
|
438
|
+
* @throws AuthError
|
|
439
|
+
*/
|
|
121
440
|
sendMagicLink(body: {
|
|
441
|
+
clientId: ClientId;
|
|
122
442
|
email: string;
|
|
123
443
|
csrfToken?: string;
|
|
124
444
|
}): Promise<void>;
|
|
445
|
+
/**
|
|
446
|
+
* Sends a password reset email to the specified address.
|
|
447
|
+
*
|
|
448
|
+
* Throws AuthError on invalid email format, etc.
|
|
449
|
+
* @throws AuthError
|
|
450
|
+
*/
|
|
125
451
|
static sendPasswordReset(body: {
|
|
452
|
+
clientId: ClientId;
|
|
126
453
|
email: string;
|
|
127
454
|
csrfToken?: string;
|
|
128
455
|
}, config?: Partial<Config>): Promise<void>;
|
|
456
|
+
/**
|
|
457
|
+
* Sends a password reset email to the specified address.
|
|
458
|
+
*
|
|
459
|
+
* Throws AuthError on invalid email format, etc.
|
|
460
|
+
* @throws AuthError
|
|
461
|
+
*/
|
|
129
462
|
sendPasswordReset(body: {
|
|
463
|
+
clientId: ClientId;
|
|
130
464
|
email: string;
|
|
131
465
|
csrfToken?: string;
|
|
132
466
|
}): Promise<void>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from "./auth";
|
|
2
|
+
export * from "./types";
|