@evoke-platform/context 1.3.0-dev.6 → 1.3.0-testing.0
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/README.md
CHANGED
|
@@ -17,7 +17,6 @@ available and no further installation is necessary.
|
|
|
17
17
|
|
|
18
18
|
- [Working With Objects](#working-with-objects)
|
|
19
19
|
- [REST API Calls](#rest-api-calls)
|
|
20
|
-
- [Authentication Context](#authentication-context)
|
|
21
20
|
- [Notifications](#notifications)
|
|
22
21
|
|
|
23
22
|
### Working With Objects
|
|
@@ -223,25 +222,6 @@ absolute URL.
|
|
|
223
222
|
|
|
224
223
|
##### `delete(url, options)`
|
|
225
224
|
|
|
226
|
-
### Authentication Context
|
|
227
|
-
|
|
228
|
-
- [useAuthenticationContext](#useauthenticationcontext)
|
|
229
|
-
|
|
230
|
-
#### `useAuthenticationContext()`
|
|
231
|
-
|
|
232
|
-
Hook to obtain the authentication context based on the current logged-in user.
|
|
233
|
-
|
|
234
|
-
The authentication context includes the following property and functions.
|
|
235
|
-
|
|
236
|
-
- `account` _[object]_
|
|
237
|
-
- The account of the currently logged-in user. This includes both the user's `id` and `name`.
|
|
238
|
-
- `logout()`
|
|
239
|
-
- A function that logs out the currently logged-in user. The user will be redirected to Evoke's logout page upon logout.
|
|
240
|
-
- `getAccessToken()`
|
|
241
|
-
- A function that returns an access token that is associated to the currently logged-in user. This token can be used to make API calls to Evoke's APIs to authenticate the API call.
|
|
242
|
-
- Note: As a general recommendation, the [ApiService](#class-apiservices) class should be used to make API calls as it will take care
|
|
243
|
-
of appending an access token to the call.
|
|
244
|
-
|
|
245
225
|
### Notifications
|
|
246
226
|
|
|
247
227
|
- [useNofitication](#usenotification)
|
|
@@ -9,25 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { createContext, useCallback, useContext, useMemo } from 'react';
|
|
12
|
-
import { useAuth } from 'react-oidc-context';
|
|
13
12
|
const Context = createContext(undefined);
|
|
14
13
|
Context.displayName = 'AuthenticationContext';
|
|
15
14
|
function AuthenticationContextProvider(props) {
|
|
16
|
-
// Auto-detect provider type based on presence of msal prop
|
|
17
|
-
if (props.msal) {
|
|
18
|
-
const { msal, authRequest, children } = props;
|
|
19
|
-
return (_jsx(MsalProvider, { msal: msal, authRequest: authRequest, children: children }));
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
const { authRequest, children } = props;
|
|
23
|
-
return _jsx(OidcProvider, { authRequest: authRequest, children: children });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function MsalProvider({ msal, authRequest, children }) {
|
|
27
15
|
var _a;
|
|
28
|
-
|
|
29
|
-
throw new Error('MSAL instance is required for MsalProvider');
|
|
30
|
-
}
|
|
16
|
+
const { msal, authRequest, children } = props;
|
|
31
17
|
const account = (_a = msal.instance.getActiveAccount()) !== null && _a !== void 0 ? _a : msal.instance.getAllAccounts()[0];
|
|
32
18
|
const getAccessToken = useCallback(function () {
|
|
33
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -40,7 +26,7 @@ function MsalProvider({ msal, authRequest, children }) {
|
|
|
40
26
|
return '';
|
|
41
27
|
}
|
|
42
28
|
});
|
|
43
|
-
}, [msal, authRequest
|
|
29
|
+
}, [msal, authRequest]);
|
|
44
30
|
const context = useMemo(() => account
|
|
45
31
|
? {
|
|
46
32
|
account: { id: account.localAccountId, name: account.name },
|
|
@@ -52,58 +38,7 @@ function MsalProvider({ msal, authRequest, children }) {
|
|
|
52
38
|
},
|
|
53
39
|
getAccessToken,
|
|
54
40
|
}
|
|
55
|
-
: undefined, [account, msal, getAccessToken
|
|
56
|
-
return _jsx(Context.Provider, { value: context, children: children });
|
|
57
|
-
}
|
|
58
|
-
function OidcProvider({ authRequest, children }) {
|
|
59
|
-
var _a, _b;
|
|
60
|
-
// The authRequest for react-oidc is formatted slightly differently than msal.
|
|
61
|
-
const oidcAuthRequest = {
|
|
62
|
-
scope: (_b = (_a = authRequest.scopes) === null || _a === void 0 ? void 0 : _a.join(' ')) !== null && _b !== void 0 ? _b : 'openid profile email',
|
|
63
|
-
extraQueryParams: authRequest.extraQueryParameters,
|
|
64
|
-
state: authRequest.state,
|
|
65
|
-
};
|
|
66
|
-
const auth = useAuth();
|
|
67
|
-
const getAccessToken = useCallback(function () {
|
|
68
|
-
var _a, _b;
|
|
69
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
try {
|
|
71
|
-
// With automaticSilentRenew: true, oidc-client-ts will attempt to renew the token in the background before it expires.
|
|
72
|
-
// However, this is not guaranteed to be perfectly in sync with your API calls. Always check for expiration here and call signinSilent if needed
|
|
73
|
-
// to ensure you get a valid token on demand.
|
|
74
|
-
if (((_a = auth.user) === null || _a === void 0 ? void 0 : _a.access_token) && !auth.user.expired) {
|
|
75
|
-
return auth.user.access_token;
|
|
76
|
-
}
|
|
77
|
-
// Token is either missing or expired - attempt silent refresh.
|
|
78
|
-
const user = yield auth.signinSilent(oidcAuthRequest);
|
|
79
|
-
// If signinSilent returns null, it means silent login failed
|
|
80
|
-
if (!user) {
|
|
81
|
-
console.log('Silent login failed, redirecting to login');
|
|
82
|
-
auth.signinRedirect(oidcAuthRequest);
|
|
83
|
-
return '';
|
|
84
|
-
}
|
|
85
|
-
return ((_b = auth.user) === null || _b === void 0 ? void 0 : _b.access_token) || '';
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
console.error('Failed to get access token:', error);
|
|
89
|
-
// If silent refresh throws an error (e.g., network failure, missing silent_redirect_uri,
|
|
90
|
-
// invalid session, refresh token expired, or provider returned an error), redirect to login
|
|
91
|
-
auth.signinRedirect(oidcAuthRequest);
|
|
92
|
-
return '';
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}, [auth, authRequest]);
|
|
96
|
-
const context = useMemo(() => auth.isAuthenticated && auth.user
|
|
97
|
-
? {
|
|
98
|
-
account: { id: auth.user.profile.sub, name: auth.user.profile.name },
|
|
99
|
-
logout: () => {
|
|
100
|
-
auth.signoutRedirect({
|
|
101
|
-
post_logout_redirect_uri: `/logout?p=${encodeURIComponent(window.location.pathname + window.location.search)}`,
|
|
102
|
-
});
|
|
103
|
-
},
|
|
104
|
-
getAccessToken,
|
|
105
|
-
}
|
|
106
|
-
: undefined, [auth, getAccessToken]);
|
|
41
|
+
: undefined, [account, msal, getAccessToken]);
|
|
107
42
|
return _jsx(Context.Provider, { value: context, children: children });
|
|
108
43
|
}
|
|
109
44
|
export function useAuthenticationContext() {
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { ApiServices, Callback } from '../api/index.js';
|
|
2
2
|
import { Filter } from './filters.js';
|
|
3
|
-
export type EvokeFormDisplayConfiguration = {
|
|
4
|
-
submitLabel?: string;
|
|
5
|
-
};
|
|
6
3
|
export type EvokeForm = {
|
|
7
4
|
id: string;
|
|
8
5
|
name: string;
|
|
@@ -11,7 +8,6 @@ export type EvokeForm = {
|
|
|
11
8
|
formObjectId?: string;
|
|
12
9
|
actionId?: string;
|
|
13
10
|
autosaveActionId?: string;
|
|
14
|
-
display?: EvokeFormDisplayConfiguration;
|
|
15
11
|
};
|
|
16
12
|
export type BaseObjReference = {
|
|
17
13
|
objectId: string;
|
|
@@ -113,7 +109,6 @@ export type InputStringValidation = StringValidation & {
|
|
|
113
109
|
maxLength?: number;
|
|
114
110
|
mask?: string;
|
|
115
111
|
};
|
|
116
|
-
export type BasicInputParameter = Omit<InputParameter, 'name' | 'required'>;
|
|
117
112
|
export type InputParameter = {
|
|
118
113
|
id: string;
|
|
119
114
|
name?: string;
|
|
@@ -135,7 +130,6 @@ export type Action = {
|
|
|
135
130
|
inputProperties?: ActionInput[];
|
|
136
131
|
parameters?: InputParameter[];
|
|
137
132
|
form?: Form;
|
|
138
|
-
defaultFormId?: string;
|
|
139
133
|
customCode?: string;
|
|
140
134
|
preconditions?: object;
|
|
141
135
|
};
|
|
@@ -231,7 +225,7 @@ export type ReadonlyField = {
|
|
|
231
225
|
};
|
|
232
226
|
export type InputField = {
|
|
233
227
|
type: 'inputField';
|
|
234
|
-
input:
|
|
228
|
+
input: InputParameter;
|
|
235
229
|
display?: DisplayConfiguration;
|
|
236
230
|
documentMetadata?: Record<string, string>;
|
|
237
231
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evoke-platform/context",
|
|
3
|
-
"version": "1.3.0-
|
|
3
|
+
"version": "1.3.0-testing.0",
|
|
4
4
|
"description": "Utilities that provide context to Evoke platform widgets",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -56,7 +56,6 @@
|
|
|
56
56
|
"msw": "^1.3.1",
|
|
57
57
|
"react": "^18.2.0",
|
|
58
58
|
"react-dom": "^18.3.1",
|
|
59
|
-
"react-oidc-context": "^2.4.0",
|
|
60
59
|
"react-router-dom": "^6.16.0",
|
|
61
60
|
"sinon": "^18.0.0",
|
|
62
61
|
"typescript": "^5.3.3"
|
|
@@ -65,14 +64,12 @@
|
|
|
65
64
|
"@azure/msal-browser": ">=2",
|
|
66
65
|
"@azure/msal-react": ">=1",
|
|
67
66
|
"react": ">=18",
|
|
68
|
-
"react-oidc-context": ">=2",
|
|
69
67
|
"react-router-dom": ">=6"
|
|
70
68
|
},
|
|
71
69
|
"dependencies": {
|
|
72
70
|
"@isaacs/ttlcache": "^1.4.1",
|
|
73
71
|
"@microsoft/signalr": "^7.0.12",
|
|
74
72
|
"axios": "^1.7.9",
|
|
75
|
-
"oidc-client-ts": "^3.3.0",
|
|
76
73
|
"uuid": "^9.0.1"
|
|
77
74
|
}
|
|
78
75
|
}
|