@guestlinelabs/react-auth
Advanced tools
Comparing version 2.4.0 to 3.0.0
import React from 'react'; | ||
import { LoginFunction, HandleRedirectCallbackFunction, LogoutFunction, AuthData, GetAccessTokenFunction } from './types'; | ||
declare type State = AuthData & { | ||
type State = AuthData & { | ||
error: Error | null; | ||
}; | ||
declare type Auth = State & { | ||
type Auth = State & { | ||
loginWithRedirect: LoginFunction; | ||
@@ -8,0 +8,0 @@ handleRedirectCallback: HandleRedirectCallbackFunction; |
@@ -20,3 +20,3 @@ "use strict"; | ||
function assertNever(x) { | ||
throw new Error("Unexpected object: " + x); | ||
throw new Error("Unexpected object: ".concat(x)); | ||
} | ||
@@ -50,3 +50,3 @@ function reducer(state, action) { | ||
} })); | ||
exports.AuthProvider = function (_a) { | ||
var AuthProvider = function (_a) { | ||
var children = _a.children; | ||
@@ -80,7 +80,5 @@ var _b = react_1.default.useReducer(reducer, initialState), state = _b[0], dispatch = _b[1]; | ||
}, []); | ||
return (react_1.default.createElement(AuthContext.Provider, { value: __assign(__assign({}, state), { loginWithRedirect: loginWithRedirect, | ||
handleRedirectCallback: handleRedirectCallback, | ||
logout: logout, | ||
getAccessToken: getAccessToken }) }, children)); | ||
return (react_1.default.createElement(AuthContext.Provider, { value: __assign(__assign({}, state), { loginWithRedirect: loginWithRedirect, handleRedirectCallback: handleRedirectCallback, logout: logout, getAccessToken: getAccessToken }) }, children)); | ||
}; | ||
exports.AuthProvider = AuthProvider; | ||
function useAuth() { | ||
@@ -87,0 +85,0 @@ var authContext = react_1.default.useContext(AuthContext); |
import { AuthProvider, useAuth } from './auth'; | ||
import { AuthData, UserInfo, HandleRedirectCallbackFunction, LoginFunction, LogoutFunction, SubscriptionHandler, GetAccessTokenFunction } from './types'; | ||
declare type Authentication = { | ||
type Authentication = { | ||
subscriptions: SubscriptionHandler[]; | ||
@@ -5,0 +5,0 @@ loginWithRedirect: LoginFunction; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -1,41 +0,48 @@ | ||
import * as t from 'io-ts'; | ||
declare const TenantMetadata: t.ExactC<t.TypeC<{ | ||
authentication: t.TypeC<{ | ||
rezlynx: t.ArrayC<t.ExactC<t.TypeC<{ | ||
id: t.StringC; | ||
username: t.StringC; | ||
roles: t.ArrayC<t.StringC>; | ||
}>>>; | ||
roomlynx: t.ArrayC<t.ExactC<t.TypeC<{ | ||
id: t.StringC; | ||
username: t.StringC; | ||
}>>>; | ||
roomlynxGroupSettings: t.ExactC<t.TypeC<{ | ||
role: t.StringC; | ||
}>>; | ||
rezlynxGroupSettings: t.ExactC<t.TypeC<{ | ||
username: t.StringC; | ||
roles: t.ArrayC<t.StringC>; | ||
ssoManagedRoles: t.BooleanC; | ||
ssoManagedUser: t.BooleanC; | ||
}>>; | ||
}>; | ||
authorization: t.ExactC<t.TypeC<{ | ||
users: t.ExactC<t.TypeC<{ | ||
read: t.BooleanC; | ||
create: t.BooleanC; | ||
update_permissions: t.BooleanC; | ||
delete: t.BooleanC; | ||
}>>; | ||
insights: t.ExactC<t.TypeC<{ | ||
read: t.BooleanC; | ||
allowExport: t.BooleanC; | ||
manageBudget: t.BooleanC; | ||
}>>; | ||
epos: t.ExactC<t.TypeC<{ | ||
allowAccess: t.BooleanC; | ||
}>>; | ||
}>>; | ||
}>>; | ||
declare type TenantMetadata = t.TypeOf<typeof TenantMetadata>; | ||
type LegacyRezlynxSiteAccess = { | ||
id: string; | ||
username: string; | ||
roles: string[]; | ||
}; | ||
type LegacyRezlynxGroupAccess = { | ||
username: string; | ||
roles: string[]; | ||
ssoManagedRoles: boolean; | ||
ssoManagedUser: boolean; | ||
}; | ||
type LegacyRoomlynxSiteAccess = { | ||
id: string; | ||
username: string; | ||
}; | ||
type LegacyRoomlynxGroupAccess = { | ||
role: string; | ||
}; | ||
type UserAuthentication = { | ||
rezlynx: LegacyRezlynxSiteAccess[]; | ||
roomlynx: LegacyRoomlynxSiteAccess[]; | ||
roomlynxGroupSettings: LegacyRoomlynxGroupAccess; | ||
rezlynxGroupSettings: LegacyRezlynxGroupAccess; | ||
}; | ||
type UsersPermissions = { | ||
read: boolean; | ||
create: boolean; | ||
update_permissions: boolean; | ||
delete: boolean; | ||
}; | ||
type InsightsPermissions = { | ||
read: boolean; | ||
allowExport: boolean; | ||
manageBudget: boolean; | ||
}; | ||
type EposPermissions = { | ||
allowAccess: boolean; | ||
}; | ||
type UserAuthorization = { | ||
users: UsersPermissions; | ||
insights: InsightsPermissions; | ||
epos: EposPermissions; | ||
}; | ||
type TenantMetadata = { | ||
authentication: UserAuthentication; | ||
authorization: UserAuthorization; | ||
}; | ||
interface LoginOptions { | ||
@@ -47,3 +54,3 @@ appState?: {}; | ||
} | ||
export declare type LoginFunction = (options?: LoginOptions) => Promise<void>; | ||
export type LoginFunction = (options?: LoginOptions) => Promise<void>; | ||
interface AccessTokenOptions { | ||
@@ -57,7 +64,7 @@ audience?: string; | ||
} | ||
export declare type GetAccessTokenFunction = (options?: AccessTokenOptions) => Promise<string>; | ||
export type GetAccessTokenFunction = (options?: AccessTokenOptions) => Promise<string>; | ||
interface HandleRedirectCallbackOptions { | ||
url?: string; | ||
} | ||
export declare type HandleRedirectCallbackFunction = (options?: HandleRedirectCallbackOptions) => Promise<{ | ||
export type HandleRedirectCallbackFunction = (options?: HandleRedirectCallbackOptions) => Promise<{ | ||
appState?: any; | ||
@@ -68,7 +75,6 @@ }>; | ||
} | ||
export declare type LogoutFunction = (options?: LogoutOptions) => void; | ||
export declare type UserInfo = { | ||
export type LogoutFunction = (options?: LogoutOptions) => void; | ||
export type UserInfo = { | ||
id: string; | ||
email: string; | ||
email_verified: boolean; | ||
name: string; | ||
@@ -85,3 +91,3 @@ nickname: string; | ||
}; | ||
export declare type AuthData = { | ||
export type AuthData = { | ||
isLoading: true; | ||
@@ -105,3 +111,3 @@ isAuthenticated: false; | ||
}; | ||
export declare type SubscriptionHandler = (error: Error | null, data?: AuthData) => void; | ||
export type SubscriptionHandler = (error: Error | null, data?: AuthData) => void; | ||
export {}; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var t = __importStar(require("io-ts")); | ||
var fromNullable_1 = require("io-ts-types/lib/fromNullable"); | ||
var LegacyRezlynxSiteAccess = t.strict({ | ||
id: t.string, | ||
username: t.string, | ||
roles: fromNullable_1.fromNullable(t.array(t.string), []), | ||
}); | ||
var LegacyRezlynxGroupAccess = t.strict({ | ||
username: t.string, | ||
roles: fromNullable_1.fromNullable(t.array(t.string), []), | ||
ssoManagedRoles: fromNullable_1.fromNullable(t.boolean, false), | ||
ssoManagedUser: fromNullable_1.fromNullable(t.boolean, false), | ||
}); | ||
var defaultLegacyRezlynxGroupAccess = { | ||
roles: [], | ||
username: '', | ||
ssoManagedUser: false, | ||
ssoManagedRoles: false, | ||
}; | ||
var LegacyRoomlynxSiteAccess = t.strict({ | ||
id: t.string, | ||
username: t.string, | ||
}); | ||
var LegacyRoomlynxGroupAccess = t.strict({ | ||
role: t.string, | ||
}); | ||
var defaultLegacyRoomlynxGroupAccess = { | ||
role: '', | ||
}; | ||
var UserAuthentication = t.type({ | ||
rezlynx: fromNullable_1.fromNullable(t.array(LegacyRezlynxSiteAccess), []), | ||
roomlynx: fromNullable_1.fromNullable(t.array(LegacyRoomlynxSiteAccess), []), | ||
roomlynxGroupSettings: fromNullable_1.fromNullable(LegacyRoomlynxGroupAccess, defaultLegacyRoomlynxGroupAccess), | ||
rezlynxGroupSettings: fromNullable_1.fromNullable(LegacyRezlynxGroupAccess, defaultLegacyRezlynxGroupAccess), | ||
}); | ||
var defaultUserAuthentication = { | ||
rezlynxGroupSettings: defaultLegacyRezlynxGroupAccess, | ||
roomlynxGroupSettings: defaultLegacyRoomlynxGroupAccess, | ||
rezlynx: [], | ||
roomlynx: [], | ||
}; | ||
var UsersPermissions = t.strict({ | ||
read: fromNullable_1.fromNullable(t.boolean, false), | ||
create: fromNullable_1.fromNullable(t.boolean, false), | ||
update_permissions: fromNullable_1.fromNullable(t.boolean, false), | ||
delete: fromNullable_1.fromNullable(t.boolean, false), | ||
}); | ||
var defaultUsersPermissions = { | ||
read: false, | ||
create: false, | ||
update_permissions: false, | ||
delete: false, | ||
}; | ||
var InsightsPermissions = t.strict({ | ||
read: fromNullable_1.fromNullable(t.boolean, false), | ||
allowExport: fromNullable_1.fromNullable(t.boolean, false), | ||
manageBudget: fromNullable_1.fromNullable(t.boolean, false), | ||
}); | ||
var defaultInsightsPermissions = { | ||
read: false, | ||
allowExport: false, | ||
manageBudget: false, | ||
}; | ||
var EposPermissions = t.strict({ | ||
allowAccess: fromNullable_1.fromNullable(t.boolean, false), | ||
}); | ||
var defaultEposPermissions = { | ||
allowAccess: false, | ||
}; | ||
var UserAuthorization = t.strict({ | ||
users: fromNullable_1.fromNullable(UsersPermissions, defaultUsersPermissions), | ||
insights: fromNullable_1.fromNullable(InsightsPermissions, defaultInsightsPermissions), | ||
epos: fromNullable_1.fromNullable(EposPermissions, defaultEposPermissions), | ||
}); | ||
var defaultUserAuthorization = { | ||
users: defaultUsersPermissions, | ||
insights: defaultInsightsPermissions, | ||
epos: defaultEposPermissions, | ||
}; | ||
var TenantMetadata = t.strict({ | ||
authentication: fromNullable_1.fromNullable(UserAuthentication, defaultUserAuthentication), | ||
authorization: fromNullable_1.fromNullable(UserAuthorization, defaultUserAuthorization), | ||
}); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@guestlinelabs/react-auth", | ||
"version": "2.4.0", | ||
"version": "3.0.0", | ||
"description": "TODO: Give a short introduction of your project. Let this section explain the objectives or the motivation behind this project.", | ||
@@ -49,12 +49,7 @@ "main": "dist/index.js", | ||
"react-dom": "16.14.0", | ||
"typescript": "3.9.7" | ||
"typescript": "5.0.3" | ||
}, | ||
"dependencies": { | ||
"fp-ts": "2.12.1", | ||
"io-ts": "2.0.1", | ||
"io-ts-types": "0.5.16" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.9.0 || ^17 || ^18" | ||
} | ||
} | ||
} |
134
src/types.ts
@@ -1,111 +0,58 @@ | ||
import * as t from 'io-ts'; | ||
import { fromNullable } from 'io-ts-types/lib/fromNullable'; | ||
type LegacyRezlynxSiteAccess = { | ||
id: string; | ||
username: string; | ||
roles: string[]; | ||
}; | ||
const LegacyRezlynxSiteAccess = t.strict({ | ||
id: t.string, | ||
username: t.string, | ||
roles: fromNullable(t.array(t.string), []), | ||
}); | ||
type LegacyRezlynxSiteAccess = t.TypeOf<typeof LegacyRezlynxSiteAccess>; | ||
type LegacyRezlynxGroupAccess = { | ||
username: string; | ||
roles: string[]; | ||
ssoManagedRoles: boolean; | ||
ssoManagedUser: boolean; | ||
}; | ||
const LegacyRezlynxGroupAccess = t.strict({ | ||
username: t.string, | ||
roles: fromNullable(t.array(t.string), []), | ||
ssoManagedRoles: fromNullable(t.boolean, false), | ||
ssoManagedUser: fromNullable(t.boolean, false), | ||
}); | ||
type LegacyRezlynxGroupAccess = t.TypeOf<typeof LegacyRezlynxGroupAccess>; | ||
const defaultLegacyRezlynxGroupAccess: LegacyRezlynxGroupAccess = { | ||
roles: [], | ||
username: '', | ||
ssoManagedUser: false, | ||
ssoManagedRoles: false, | ||
type LegacyRoomlynxSiteAccess = { | ||
id: string; | ||
username: string; | ||
}; | ||
const LegacyRoomlynxSiteAccess = t.strict({ | ||
id: t.string, | ||
username: t.string, | ||
}); | ||
type LegacyRoomlynxSiteAccess = t.TypeOf<typeof LegacyRoomlynxSiteAccess>; | ||
type LegacyRoomlynxGroupAccess = { | ||
role: string; | ||
}; | ||
const LegacyRoomlynxGroupAccess = t.strict({ | ||
role: t.string, | ||
}); | ||
type LegacyRoomlynxGroupAccess = t.TypeOf<typeof LegacyRoomlynxGroupAccess>; | ||
const defaultLegacyRoomlynxGroupAccess: LegacyRoomlynxGroupAccess = { | ||
role: '', | ||
type UserAuthentication = { | ||
rezlynx: LegacyRezlynxSiteAccess[]; | ||
roomlynx: LegacyRoomlynxSiteAccess[]; | ||
roomlynxGroupSettings: LegacyRoomlynxGroupAccess; | ||
rezlynxGroupSettings: LegacyRezlynxGroupAccess; | ||
}; | ||
const UserAuthentication = t.type({ | ||
rezlynx: fromNullable(t.array(LegacyRezlynxSiteAccess), []), | ||
roomlynx: fromNullable(t.array(LegacyRoomlynxSiteAccess), []), | ||
roomlynxGroupSettings: fromNullable( | ||
LegacyRoomlynxGroupAccess, | ||
defaultLegacyRoomlynxGroupAccess | ||
), | ||
rezlynxGroupSettings: fromNullable( | ||
LegacyRezlynxGroupAccess, | ||
defaultLegacyRezlynxGroupAccess | ||
), | ||
}); | ||
type UserAuthentication = t.TypeOf<typeof UserAuthentication>; | ||
const defaultUserAuthentication: UserAuthentication = { | ||
rezlynxGroupSettings: defaultLegacyRezlynxGroupAccess, | ||
roomlynxGroupSettings: defaultLegacyRoomlynxGroupAccess, | ||
rezlynx: [], | ||
roomlynx: [], | ||
type UsersPermissions = { | ||
read: boolean; | ||
create: boolean; | ||
update_permissions: boolean; | ||
delete: boolean; | ||
}; | ||
const UsersPermissions = t.strict({ | ||
read: fromNullable(t.boolean, false), | ||
create: fromNullable(t.boolean, false), | ||
update_permissions: fromNullable(t.boolean, false), | ||
delete: fromNullable(t.boolean, false), | ||
}); | ||
type UsersPermissions = t.TypeOf<typeof UsersPermissions>; | ||
const defaultUsersPermissions: UsersPermissions = { | ||
read: false, | ||
create: false, | ||
update_permissions: false, | ||
delete: false, | ||
type InsightsPermissions = { | ||
read: boolean; | ||
allowExport: boolean; | ||
manageBudget: boolean; | ||
}; | ||
const InsightsPermissions = t.strict({ | ||
read: fromNullable(t.boolean, false), | ||
allowExport: fromNullable(t.boolean, false), | ||
manageBudget: fromNullable(t.boolean, false), | ||
}); | ||
type InsightsPermissions = t.TypeOf<typeof InsightsPermissions>; | ||
const defaultInsightsPermissions: InsightsPermissions = { | ||
read: false, | ||
allowExport: false, | ||
manageBudget: false, | ||
type EposPermissions = { | ||
allowAccess: boolean; | ||
}; | ||
const EposPermissions = t.strict({ | ||
allowAccess: fromNullable(t.boolean, false), | ||
}); | ||
type EposPermissions = t.TypeOf<typeof EposPermissions>; | ||
const defaultEposPermissions: EposPermissions = { | ||
allowAccess: false, | ||
type UserAuthorization = { | ||
users: UsersPermissions; | ||
insights: InsightsPermissions; | ||
epos: EposPermissions; | ||
}; | ||
const UserAuthorization = t.strict({ | ||
users: fromNullable(UsersPermissions, defaultUsersPermissions), | ||
insights: fromNullable(InsightsPermissions, defaultInsightsPermissions), | ||
epos: fromNullable(EposPermissions, defaultEposPermissions), | ||
}); | ||
type UserAuthorization = t.TypeOf<typeof UserAuthorization>; | ||
const defaultUserAuthorization: UserAuthorization = { | ||
users: defaultUsersPermissions, | ||
insights: defaultInsightsPermissions, | ||
epos: defaultEposPermissions, | ||
type TenantMetadata = { | ||
authentication: UserAuthentication; | ||
authorization: UserAuthorization; | ||
}; | ||
const TenantMetadata = t.strict({ | ||
authentication: fromNullable(UserAuthentication, defaultUserAuthentication), | ||
authorization: fromNullable(UserAuthorization, defaultUserAuthorization), | ||
}); | ||
type TenantMetadata = t.TypeOf<typeof TenantMetadata>; | ||
interface LoginOptions { | ||
@@ -146,3 +93,2 @@ appState?: {}; // State to get back on the login-callback (e.g. to store the page to redirect to after login) | ||
email: string; | ||
email_verified: boolean; | ||
@@ -149,0 +95,0 @@ name: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1
32111
800
- Removedfp-ts@2.12.1
- Removedio-ts@2.0.1
- Removedio-ts-types@0.5.16
- Removedfp-ts@2.12.1(transitive)
- Removedio-ts@2.0.1(transitive)
- Removedio-ts-types@0.5.16(transitive)
- Removedmonocle-ts@2.3.13(transitive)
- Removednewtype-ts@0.3.5(transitive)