@cratis/arc 19.7.3 → 19.9.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.
Files changed (54) hide show
  1. package/commands/Command.ts +31 -9
  2. package/commands/ICommand.ts +4 -2
  3. package/commands/for_Command/when_executing/with_allowed_severity_warning.ts +44 -0
  4. package/dist/cjs/commands/Command.d.ts +3 -1
  5. package/dist/cjs/commands/Command.d.ts.map +1 -1
  6. package/dist/cjs/commands/Command.js +26 -9
  7. package/dist/cjs/commands/Command.js.map +1 -1
  8. package/dist/cjs/commands/ICommand.d.ts +2 -1
  9. package/dist/cjs/commands/ICommand.d.ts.map +1 -1
  10. package/dist/cjs/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts +2 -0
  11. package/dist/cjs/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts.map +1 -0
  12. package/dist/cjs/identity/IIdentity.d.ts +2 -0
  13. package/dist/cjs/identity/IIdentity.d.ts.map +1 -1
  14. package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
  15. package/dist/cjs/identity/IdentityProvider.js +4 -0
  16. package/dist/cjs/identity/IdentityProvider.js.map +1 -1
  17. package/dist/cjs/identity/IdentityProviderResult.d.ts +1 -0
  18. package/dist/cjs/identity/IdentityProviderResult.d.ts.map +1 -1
  19. package/dist/cjs/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts +2 -0
  20. package/dist/cjs/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts.map +1 -0
  21. package/dist/cjs/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts +2 -0
  22. package/dist/cjs/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts.map +1 -0
  23. package/dist/esm/commands/Command.d.ts +3 -1
  24. package/dist/esm/commands/Command.d.ts.map +1 -1
  25. package/dist/esm/commands/Command.js +26 -9
  26. package/dist/esm/commands/Command.js.map +1 -1
  27. package/dist/esm/commands/ICommand.d.ts +2 -1
  28. package/dist/esm/commands/ICommand.d.ts.map +1 -1
  29. package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts +2 -0
  30. package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.d.ts.map +1 -0
  31. package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.js +36 -0
  32. package/dist/esm/commands/for_Command/when_executing/with_allowed_severity_warning.js.map +1 -0
  33. package/dist/esm/identity/IIdentity.d.ts +2 -0
  34. package/dist/esm/identity/IIdentity.d.ts.map +1 -1
  35. package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
  36. package/dist/esm/identity/IdentityProvider.js +4 -0
  37. package/dist/esm/identity/IdentityProvider.js.map +1 -1
  38. package/dist/esm/identity/IdentityProviderResult.d.ts +1 -0
  39. package/dist/esm/identity/IdentityProviderResult.d.ts.map +1 -1
  40. package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts +2 -0
  41. package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.d.ts.map +1 -0
  42. package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.js +36 -0
  43. package/dist/esm/identity/for_IdentityProvider/when_getting_current/with_roles.js.map +1 -0
  44. package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts +2 -0
  45. package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.d.ts.map +1 -0
  46. package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.js +29 -0
  47. package/dist/esm/identity/for_IdentityProvider/when_getting_current/without_roles.js.map +1 -0
  48. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  49. package/identity/IIdentity.ts +12 -0
  50. package/identity/IdentityProvider.ts +4 -0
  51. package/identity/IdentityProviderResult.ts +1 -0
  52. package/identity/for_IdentityProvider/when_getting_current/with_roles.ts +45 -0
  53. package/identity/for_IdentityProvider/when_getting_current/without_roles.ts +36 -0
  54. package/package.json +1 -1
@@ -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
  }
@@ -4,5 +4,6 @@
4
4
  export type IdentityProviderResult = {
5
5
  id: string;
6
6
  name: string;
7
+ roles: string[];
7
8
  details: object;
8
9
  };
@@ -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
+ }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/arc",
3
- "version": "19.7.3",
3
+ "version": "19.9.0",
4
4
  "description": "",
5
5
  "author": "Cratis",
6
6
  "license": "MIT",