@lu-development/pi-xstate-auth
Advanced tools
Comparing version
@@ -1,5 +0,3 @@ | ||
import { AuthenticationResult, Configuration, PublicClientApplication, SilentRequest } from '@azure/msal-browser'; | ||
import { ContextFrom, EventFrom } from 'xstate'; | ||
import { authEvents } from './enums'; | ||
import { JWTData } from './types'; | ||
import { Configuration, PublicClientApplication } from '@azure/msal-browser'; | ||
import { AuthContext, AuthEvents, JWTData } from './types'; | ||
export declare const tools: { | ||
@@ -9,50 +7,6 @@ createMsalInstance: (config: Configuration) => PublicClientApplication; | ||
}; | ||
export declare const authModel: import("xstate/lib/model.types").Model<{ | ||
refreshIntervalSeconds: number; | ||
authority: string; | ||
clientId: string; | ||
scopes: string[]; | ||
silentRequestConfig: SilentRequest | undefined; | ||
msalInstance: PublicClientApplication | undefined; | ||
authenticationResult: AuthenticationResult | undefined; | ||
}, { | ||
type: authEvents.INITIATEREAUTHORIZATION; | ||
}, import("xstate").BaseActionObject, import("xstate/lib/model.types").FinalModelCreators<{ | ||
events: { | ||
initiateReauthorization: () => {}; | ||
}; | ||
}>>; | ||
export declare type AuthContext = ContextFrom<typeof authModel>; | ||
export declare type AuthEvents = EventFrom<typeof authModel>; | ||
export declare const authMachine: import("xstate").StateMachine<{ | ||
refreshIntervalSeconds: number; | ||
authority: string; | ||
clientId: string; | ||
scopes: string[]; | ||
silentRequestConfig: SilentRequest | undefined; | ||
msalInstance: PublicClientApplication | undefined; | ||
authenticationResult: AuthenticationResult | undefined; | ||
}, any, { | ||
type: authEvents.INITIATEREAUTHORIZATION; | ||
}, { | ||
export declare const authModel: import("xstate/lib/model.types").Model<AuthContext, AuthEvents, import("xstate").BaseActionObject, void>; | ||
export declare const authMachine: import("xstate").StateMachine<AuthContext, any, AuthEvents, { | ||
value: any; | ||
context: { | ||
refreshIntervalSeconds: number; | ||
authority: string; | ||
clientId: string; | ||
scopes: string[]; | ||
silentRequestConfig: SilentRequest | undefined; | ||
msalInstance: PublicClientApplication | undefined; | ||
authenticationResult: AuthenticationResult | undefined; | ||
}; | ||
}, import("xstate").ActionObject<{ | ||
refreshIntervalSeconds: number; | ||
authority: string; | ||
clientId: string; | ||
scopes: string[]; | ||
silentRequestConfig: SilentRequest | undefined; | ||
msalInstance: PublicClientApplication | undefined; | ||
authenticationResult: AuthenticationResult | undefined; | ||
}, { | ||
type: authEvents.INITIATEREAUTHORIZATION; | ||
}>>; | ||
context: AuthContext; | ||
}, import("xstate").ActionObject<AuthContext, AuthEvents>>; |
@@ -25,9 +25,2 @@ "use strict"; | ||
scopes: [], | ||
silentRequestConfig: undefined, | ||
msalInstance: undefined, | ||
authenticationResult: undefined, | ||
}, { | ||
events: { | ||
[enums_1.authEvents.INITIATEREAUTHORIZATION]: () => ({}), | ||
}, | ||
}); | ||
@@ -108,3 +101,12 @@ exports.authMachine = exports.authModel.createMachine({ | ||
invoke: { | ||
id: 'resetAuth', | ||
src: 'resetAuthService', | ||
onError: { | ||
target: enums_1.authStates.FATAL, | ||
actions: (0, xstate_1.assign)({ | ||
error: (_, error) => { | ||
return error.data; | ||
} | ||
}) | ||
} | ||
}, | ||
@@ -129,2 +131,8 @@ }, | ||
}, | ||
[enums_1.authStates.FATAL]: { | ||
entry: (0, xstate_1.sendParent)((context) => ({ | ||
type: enums_1.authEventsForParent.FATAL, | ||
error: context.error ? context.error : new Error("Unknown Error") | ||
})) | ||
} | ||
}, | ||
@@ -131,0 +139,0 @@ }, { |
export declare enum authEventsForParent { | ||
SUCCESS = "authSuccessful" | ||
SUCCESS = "authSuccessful", | ||
FATAL = "authFatal" | ||
} | ||
@@ -9,3 +10,4 @@ export declare enum authStates { | ||
SUCCESS = "success", | ||
FAILED = "failed" | ||
FAILED = "failed", | ||
FATAL = "fatal" | ||
} | ||
@@ -12,0 +14,0 @@ export declare enum authEvents { |
@@ -7,2 +7,3 @@ "use strict"; | ||
authEventsForParent["SUCCESS"] = "authSuccessful"; | ||
authEventsForParent["FATAL"] = "authFatal"; | ||
})(authEventsForParent = exports.authEventsForParent || (exports.authEventsForParent = {})); | ||
@@ -16,2 +17,3 @@ var authStates; | ||
authStates["FAILED"] = "failed"; | ||
authStates["FATAL"] = "fatal"; | ||
})(authStates = exports.authStates || (exports.authStates = {})); | ||
@@ -18,0 +20,0 @@ var authEvents; |
@@ -1,2 +0,2 @@ | ||
import { AuthContext } from '../auth-machine'; | ||
import { AuthContext } from '../types'; | ||
export declare const initialAuthService: (context: AuthContext) => Promise<import("@azure/msal-common").AuthenticationResult | undefined>; |
@@ -1,2 +0,2 @@ | ||
import { AuthContext } from '../auth-machine'; | ||
import { AuthContext } from '../types'; | ||
export declare const reauthorizationService: (context: AuthContext) => Promise<import("@azure/msal-browser").AuthenticationResult | undefined>; |
@@ -1,2 +0,2 @@ | ||
import { AuthContext } from '../auth-machine'; | ||
import { AuthContext } from '../types'; | ||
export declare const resetAuthService: (context: AuthContext) => Promise<void>; |
@@ -1,5 +0,3 @@ | ||
import { EventObject } from 'xstate'; | ||
export declare type ParentSuccess = EventObject & { | ||
data: AuthSuccess; | ||
}; | ||
import { AuthenticationResult, PublicClientApplication, SilentRequest } from '@azure/msal-browser'; | ||
import { authEvents, authEventsForParent } from './enums'; | ||
export interface JWTData { | ||
@@ -15,1 +13,23 @@ email: string; | ||
} | ||
export declare type ParentSuccess = { | ||
type: authEventsForParent.SUCCESS; | ||
data: AuthSuccess; | ||
}; | ||
export declare type ParentFatal = { | ||
type: authEventsForParent.FATAL; | ||
error: Error; | ||
}; | ||
export interface AuthContext { | ||
refreshIntervalSeconds: number; | ||
authority: string; | ||
clientId: string; | ||
scopes: string[]; | ||
silentRequestConfig?: SilentRequest; | ||
msalInstance?: PublicClientApplication; | ||
authenticationResult?: AuthenticationResult; | ||
error?: Error; | ||
} | ||
export declare type AuthEvents = { | ||
type: authEvents.INITIATEREAUTHORIZATION; | ||
data: Error; | ||
}; |
{ | ||
"name": "@lu-development/pi-xstate-auth", | ||
"version": "0.0.12", | ||
"version": "0.0.13", | ||
"description": "Auth Machine", | ||
@@ -14,3 +14,4 @@ "files": [ | ||
"test": "jest", | ||
"pub": "npm run clean & npm run build && npm publish --access public" | ||
"pub": "npm run clean & npm run build && npm publish --access public", | ||
"prepare": "husky install" | ||
}, | ||
@@ -34,4 +35,7 @@ "author": "", | ||
"eslint": "^8.1.0", | ||
"husky": "^7.0.4", | ||
"jest": "^27.2.5", | ||
"lint-staged": "^11.2.6", | ||
"prettier": "^2.4.0", | ||
"prettier-plugin-style-order": "^0.2.2", | ||
"rimraf": "^3.0.2", | ||
@@ -41,3 +45,6 @@ "sinon": "^11.1.2", | ||
"typescript": "^4.4.4" | ||
}, | ||
"lint-staged": { | ||
"**/*": "prettier --write --ignore-unknown" | ||
} | ||
} |
13205
-1.51%18
20%305
-4.39%