@cratis/arc 19.7.3 → 19.8.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/commands/Command.ts +31 -9
- package/commands/ICommand.ts +4 -2
- package/commands/for_Command/when_executing/with_allowed_severity_warning.ts +44 -0
- package/dist/cjs/commands/Command.d.ts +3 -1
- package/dist/cjs/commands/Command.d.ts.map +1 -1
- package/dist/cjs/commands/Command.js +26 -9
- package/dist/cjs/commands/Command.js.map +1 -1
- package/dist/cjs/commands/ICommand.d.ts +2 -1
- package/dist/cjs/commands/ICommand.d.ts.map +1 -1
- package/dist/cjs/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts +2 -0
- package/dist/cjs/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts.map +1 -0
- package/dist/cjs/identity/IIdentity.d.ts +2 -0
- package/dist/cjs/identity/IIdentity.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js +4 -0
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/identity/IdentityProviderResult.d.ts +1 -0
- package/dist/cjs/identity/IdentityProviderResult.d.ts.map +1 -1
- package/dist/cjs/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts.map +1 -0
- package/dist/cjs/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts.map +1 -0
- package/dist/esm/commands/Command.d.ts +3 -1
- package/dist/esm/commands/Command.d.ts.map +1 -1
- package/dist/esm/commands/Command.js +26 -9
- package/dist/esm/commands/Command.js.map +1 -1
- package/dist/esm/commands/ICommand.d.ts +2 -1
- package/dist/esm/commands/ICommand.d.ts.map +1 -1
- package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts +2 -0
- package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts.map +1 -0
- package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.js +36 -0
- package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.js.map +1 -0
- package/dist/esm/identity/IIdentity.d.ts +2 -0
- package/dist/esm/identity/IIdentity.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +4 -0
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/identity/IdentityProviderResult.d.ts +1 -0
- package/dist/esm/identity/IdentityProviderResult.d.ts.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.js +36 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.js.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.js +29 -0
- package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/identity/IIdentity.ts +12 -0
- package/identity/IdentityProvider.ts +4 -0
- package/identity/IdentityProviderResult.ts +1 -0
- package/identity/for_IdentityProvider/when_getting_current/with_roles.ts +45 -0
- package/identity/for_IdentityProvider/when_getting_current/without_roles.ts +36 -0
- package/package.json +1 -1
package/identity/IIdentity.ts
CHANGED
|
@@ -16,6 +16,11 @@ export interface IIdentity<TDetails = object> {
|
|
|
16
16
|
*/
|
|
17
17
|
name: string;
|
|
18
18
|
|
|
19
|
+
/**
|
|
20
|
+
* The roles the identity is in.
|
|
21
|
+
*/
|
|
22
|
+
roles: string[];
|
|
23
|
+
|
|
19
24
|
/**
|
|
20
25
|
* The application specific details for the identity.
|
|
21
26
|
*/
|
|
@@ -26,6 +31,13 @@ export interface IIdentity<TDetails = object> {
|
|
|
26
31
|
*/
|
|
27
32
|
isSet: boolean;
|
|
28
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Check if the identity is in a role.
|
|
36
|
+
* @param role The role to check.
|
|
37
|
+
* @returns True if the identity is in the role, false otherwise.
|
|
38
|
+
*/
|
|
39
|
+
isInRole(role: string): boolean;
|
|
40
|
+
|
|
29
41
|
/**
|
|
30
42
|
* Refreshes the identity context.
|
|
31
43
|
*/
|
|
@@ -59,8 +59,10 @@ export class IdentityProvider extends IIdentityProvider {
|
|
|
59
59
|
return {
|
|
60
60
|
id: result.id,
|
|
61
61
|
name: result.name,
|
|
62
|
+
roles: result.roles || [],
|
|
62
63
|
details: details as TDetails,
|
|
63
64
|
isSet: true,
|
|
65
|
+
isInRole: (role: string) => (result.roles || []).includes(role),
|
|
64
66
|
refresh: () => IdentityProvider.refresh(type)
|
|
65
67
|
} as IIdentity<TDetails>;
|
|
66
68
|
} else {
|
|
@@ -92,8 +94,10 @@ export class IdentityProvider extends IIdentityProvider {
|
|
|
92
94
|
return {
|
|
93
95
|
id: result.id,
|
|
94
96
|
name: result.name,
|
|
97
|
+
roles: result.roles || [],
|
|
95
98
|
details: details as TDetails,
|
|
96
99
|
isSet: true,
|
|
100
|
+
isInRole: (role: string) => (result.roles || []).includes(role),
|
|
97
101
|
refresh: () => IdentityProvider.refresh(type)
|
|
98
102
|
};
|
|
99
103
|
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { IdentityProvider } from '../../IdentityProvider';
|
|
5
|
+
import { an_identity_provider } from '../given/an_identity_provider';
|
|
6
|
+
import { given } from '../../../given';
|
|
7
|
+
|
|
8
|
+
describe('when getting current with roles', given(an_identity_provider, () => {
|
|
9
|
+
let identity: { id: string; name: string; roles: string[]; isInRole: (role: string) => boolean };
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
const identityData = {
|
|
13
|
+
id: 'test-user-id',
|
|
14
|
+
name: 'Test User',
|
|
15
|
+
roles: ['Admin', 'User'],
|
|
16
|
+
details: {}
|
|
17
|
+
};
|
|
18
|
+
const encodedData = btoa(JSON.stringify(identityData));
|
|
19
|
+
(global as { document?: { cookie: string } }).document!.cookie = `.cratis-identity=${encodedData}`;
|
|
20
|
+
|
|
21
|
+
const result = await IdentityProvider.getCurrent();
|
|
22
|
+
identity = {
|
|
23
|
+
id: result.id,
|
|
24
|
+
name: result.name,
|
|
25
|
+
roles: result.roles,
|
|
26
|
+
isInRole: result.isInRole
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should have the roles', () => {
|
|
31
|
+
identity.roles.should.deep.equal(['Admin', 'User']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should return true when checking for Admin role', () => {
|
|
35
|
+
identity.isInRole('Admin').should.be.true;
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('should return true when checking for User role', () => {
|
|
39
|
+
identity.isInRole('User').should.be.true;
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should return false when checking for non-existent role', () => {
|
|
43
|
+
identity.isInRole('SuperAdmin').should.be.false;
|
|
44
|
+
});
|
|
45
|
+
}));
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright (c) Cratis. All rights reserved.
|
|
2
|
+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { IdentityProvider } from '../../IdentityProvider';
|
|
5
|
+
import { an_identity_provider } from '../given/an_identity_provider';
|
|
6
|
+
import { given } from '../../../given';
|
|
7
|
+
|
|
8
|
+
describe('when getting current without roles', given(an_identity_provider, () => {
|
|
9
|
+
let identity: { id: string; name: string; roles: string[]; isInRole: (role: string) => boolean };
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
const identityData = {
|
|
13
|
+
id: 'test-user-id',
|
|
14
|
+
name: 'Test User',
|
|
15
|
+
details: {}
|
|
16
|
+
};
|
|
17
|
+
const encodedData = btoa(JSON.stringify(identityData));
|
|
18
|
+
(global as { document?: { cookie: string } }).document!.cookie = `.cratis-identity=${encodedData}`;
|
|
19
|
+
|
|
20
|
+
const result = await IdentityProvider.getCurrent();
|
|
21
|
+
identity = {
|
|
22
|
+
id: result.id,
|
|
23
|
+
name: result.name,
|
|
24
|
+
roles: result.roles,
|
|
25
|
+
isInRole: result.isInRole
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should have empty roles array', () => {
|
|
30
|
+
identity.roles.should.be.empty;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should return false when checking for any role', () => {
|
|
34
|
+
identity.isInRole('Admin').should.be.false;
|
|
35
|
+
});
|
|
36
|
+
}));
|