@equinor/roma-framework 0.0.7-BETA.6 → 0.0.8
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/dev-portal/index.d.ts +2 -0
- package/dev-portal/lib/hooks/use-get-api-roles.d.ts +14 -0
- package/dev-portal/lib/hooks/use-has-api-role.d.ts +7 -0
- package/dev-portal/package.json +1 -1
- package/index.d.ts +2 -0
- package/lib/hooks/use-get-api-roles.d.ts +14 -0
- package/lib/hooks/use-has-api-role.d.ts +7 -0
- package/package.json +1 -1
- package/roma-framework.mjs +50 -0
package/dev-portal/index.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a JWT token and returns an object with the roles contained in the token.
|
|
3
|
+
* @param token The JWT token to parse.
|
|
4
|
+
* @returns An object with the roles contained in the token.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseJwt(token: string): {
|
|
7
|
+
roles: Array<string>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the roles associated with a specified API from fusion's service discovery module.
|
|
11
|
+
* @param api The name of the API to retrieve roles for.
|
|
12
|
+
* @returns An array of roles associated with the specified API.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useGetApiRoles: (api: string) => string[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the current user has a specified role associated with a specified API using the `useGetApiRoles` hook.
|
|
3
|
+
* @param api The name of the API to check for the specified role.
|
|
4
|
+
* @param role The name of the role to check for.
|
|
5
|
+
* @returns True if the current user has the specified role associated with the specified API, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useHasApiRole: (api: string, role: string) => boolean;
|
package/dev-portal/package.json
CHANGED
package/index.d.ts
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parses a JWT token and returns an object with the roles contained in the token.
|
|
3
|
+
* @param token The JWT token to parse.
|
|
4
|
+
* @returns An object with the roles contained in the token.
|
|
5
|
+
*/
|
|
6
|
+
export declare function parseJwt(token: string): {
|
|
7
|
+
roles: Array<string>;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Retrieves the roles associated with a specified API from fusion's service discovery module.
|
|
11
|
+
* @param api The name of the API to retrieve roles for.
|
|
12
|
+
* @returns An array of roles associated with the specified API.
|
|
13
|
+
*/
|
|
14
|
+
export declare const useGetApiRoles: (api: string) => string[];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the current user has a specified role associated with a specified API using the `useGetApiRoles` hook.
|
|
3
|
+
* @param api The name of the API to check for the specified role.
|
|
4
|
+
* @param role The name of the role to check for.
|
|
5
|
+
* @returns True if the current user has the specified role associated with the specified API, false otherwise.
|
|
6
|
+
*/
|
|
7
|
+
export declare const useHasApiRole: (api: string, role: string) => boolean;
|
package/package.json
CHANGED
package/roma-framework.mjs
CHANGED
|
@@ -15,6 +15,10 @@ const createExtraScopePlugin = (scope) => {
|
|
|
15
15
|
const plugin = (element, index, childEls) => {
|
|
16
16
|
if (element.type === "rule") {
|
|
17
17
|
element.props = element.props.map((value) => {
|
|
18
|
+
var _a2;
|
|
19
|
+
if (((_a2 = element.parent) == null ? void 0 : _a2.type) === "@keyframes") {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
18
22
|
const containerMatch = `div[id^='eds-']`;
|
|
19
23
|
const snackbarMatch = `body > ${value}`;
|
|
20
24
|
return `${scope} ${value}, ${containerMatch} ${value}, ${snackbarMatch}`;
|
|
@@ -6216,6 +6220,49 @@ const useGetAllRomaConfigurationByType = (type, options) => {
|
|
|
6216
6220
|
query.queryKey = queryOptions.queryKey;
|
|
6217
6221
|
return query;
|
|
6218
6222
|
};
|
|
6223
|
+
function parseJwt(token) {
|
|
6224
|
+
const parts = token.split(".");
|
|
6225
|
+
if (parts.length !== 3) {
|
|
6226
|
+
throw new Error("Invalid JWT token format");
|
|
6227
|
+
}
|
|
6228
|
+
const base64Url = parts[1];
|
|
6229
|
+
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
6230
|
+
let jsonPayload;
|
|
6231
|
+
try {
|
|
6232
|
+
jsonPayload = decodeURIComponent(
|
|
6233
|
+
window.atob(base64).split("").map(function(c) {
|
|
6234
|
+
return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
|
|
6235
|
+
}).join("")
|
|
6236
|
+
);
|
|
6237
|
+
} catch (error) {
|
|
6238
|
+
throw new Error("Error decoding JWT token");
|
|
6239
|
+
}
|
|
6240
|
+
try {
|
|
6241
|
+
return JSON.parse(jsonPayload);
|
|
6242
|
+
} catch (error) {
|
|
6243
|
+
throw new Error("Invalid JSON payload in JWT token");
|
|
6244
|
+
}
|
|
6245
|
+
}
|
|
6246
|
+
const useGetApiRoles = (api) => {
|
|
6247
|
+
const { modules } = useFramework();
|
|
6248
|
+
const [roles, setRoles] = useState([]);
|
|
6249
|
+
modules.serviceDiscovery.resolveService(api).then(async (s) => {
|
|
6250
|
+
const jwt = await modules.auth.acquireAccessToken({
|
|
6251
|
+
scopes: s.defaultScopes
|
|
6252
|
+
});
|
|
6253
|
+
if (!jwt) {
|
|
6254
|
+
throw new Error(`No jwt found for ${api}`);
|
|
6255
|
+
}
|
|
6256
|
+
const token = parseJwt(jwt);
|
|
6257
|
+
if (roles.length === 0)
|
|
6258
|
+
setRoles(token.roles);
|
|
6259
|
+
});
|
|
6260
|
+
return roles;
|
|
6261
|
+
};
|
|
6262
|
+
const useHasApiRole = (api, role) => {
|
|
6263
|
+
const roles = useGetApiRoles(api);
|
|
6264
|
+
return roles.includes(role);
|
|
6265
|
+
};
|
|
6219
6266
|
export {
|
|
6220
6267
|
AppContext,
|
|
6221
6268
|
AppLoader,
|
|
@@ -6243,6 +6290,7 @@ export {
|
|
|
6243
6290
|
getGetSettingsByUserIdQueryKey,
|
|
6244
6291
|
getStreamEventsQueryKey,
|
|
6245
6292
|
makeComponent,
|
|
6293
|
+
parseJwt,
|
|
6246
6294
|
useAddRomaConfiguration,
|
|
6247
6295
|
useAddRomaConfigurationHook,
|
|
6248
6296
|
useAddRomaConfigurationMutationOptions,
|
|
@@ -6299,6 +6347,7 @@ export {
|
|
|
6299
6347
|
useGetAllServices,
|
|
6300
6348
|
useGetAllServicesHook,
|
|
6301
6349
|
useGetAllServicesQueryOptions,
|
|
6350
|
+
useGetApiRoles,
|
|
6302
6351
|
useGetAppByKey,
|
|
6303
6352
|
useGetAppByKeyHook,
|
|
6304
6353
|
useGetAppByKeyQueryOptions,
|
|
@@ -6328,6 +6377,7 @@ export {
|
|
|
6328
6377
|
useGetSettingsByUserId,
|
|
6329
6378
|
useGetSettingsByUserIdHook,
|
|
6330
6379
|
useGetSettingsByUserIdQueryOptions,
|
|
6380
|
+
useHasApiRole,
|
|
6331
6381
|
useStreamEvents,
|
|
6332
6382
|
useStreamEventsHook,
|
|
6333
6383
|
useStreamEventsQueryOptions,
|