@cratis/arc 19.7.2 → 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.
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
@@ -70,15 +70,17 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
70
70
  }
71
71
 
72
72
  /** @inheritdoc */
73
- async execute(): Promise<CommandResult<TCommandResponse>> {
73
+ async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {
74
74
  const clientValidationErrors = this.validation?.validate(this) || [];
75
- if (clientValidationErrors.length > 0) {
76
- return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;
75
+ const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);
76
+ if (filteredClientErrors.length > 0) {
77
+ return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;
77
78
  }
78
79
 
79
80
  const validationErrors = this.validateRequiredProperties();
80
- if (validationErrors.length > 0) {
81
- return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;
81
+ const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);
82
+ if (filteredRequiredErrors.length > 0) {
83
+ return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;
82
84
  }
83
85
 
84
86
  let actualRoute = this.route;
@@ -89,7 +91,7 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
89
91
  actualRoute = route;
90
92
  }
91
93
 
92
- const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');
94
+ const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);
93
95
  this.setInitialValuesFromCurrentValues();
94
96
  return result;
95
97
  }
@@ -145,7 +147,17 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
145
147
  return validationErrors;
146
148
  }
147
149
 
148
- private buildHeaders(): HeadersInit {
150
+ private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {
151
+ if (ignoreWarnings === true) {
152
+ return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);
153
+ }
154
+ if (allowedSeverity === undefined) {
155
+ return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);
156
+ }
157
+ return validationResults.filter(result => result.severity > allowedSeverity);
158
+ }
159
+
160
+ private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {
149
161
  const customHeaders = this._httpHeadersCallback?.() ?? {};
150
162
  const headers = {
151
163
  ...customHeaders,
@@ -157,16 +169,26 @@ export abstract class Command<TCommandContent = object, TCommandResponse = objec
157
169
  headers[Globals.microserviceHttpHeader] = this._microservice;
158
170
  }
159
171
 
172
+ if (allowedSeverity !== undefined) {
173
+ headers['X-Allowed-Severity'] = allowedSeverity.toString();
174
+ }
175
+
176
+ if (ignoreWarnings === true) {
177
+ headers['X-Ignore-Warnings'] = 'true';
178
+ }
179
+
160
180
  return headers;
161
181
  }
162
182
 
163
183
  private async performRequest(
164
184
  route: string,
165
185
  notFoundMessage: string,
166
- errorMessage: string
186
+ errorMessage: string,
187
+ allowedSeverity?: ValidationResultSeverity,
188
+ ignoreWarnings?: boolean
167
189
  ): Promise<CommandResult<TCommandResponse>> {
168
190
  const payload = this.buildPayload();
169
- const headers = this.buildHeaders();
191
+ const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);
170
192
  const actualRoute = joinPaths(this._apiBasePath, route);
171
193
  const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
172
194
 
@@ -4,6 +4,7 @@
4
4
  import { ICanBeConfigured } from '../ICanBeConfigured';
5
5
  import { CommandResult } from './CommandResult';
6
6
  import { PropertyDescriptor } from '../reflection/PropertyDescriptor';
7
+ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity';
7
8
 
8
9
  /**
9
10
  * Callback for when a property changes.
@@ -26,10 +27,11 @@ export interface ICommand<TCommandContent = object, TCommandResponse = object> e
26
27
 
27
28
  /**
28
29
  * Execute the {@link ICommand}.
29
- * @param [args] Optional arguments for the command route - depends on whether or not the command needs arguments.
30
+ * @param [allowedSeverity] Optional maximum severity level to allow. Validation results with severity higher than this will cause the command to fail.
31
+ * @param [ignoreWarnings] Optional flag to ignore warnings. When true, only errors will cause the command to fail.
30
32
  * @returns {CommandResult} for the execution.
31
33
  */
32
- execute(): Promise<CommandResult<TCommandResponse>>;
34
+ execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
33
35
 
34
36
  /**
35
37
  * Validate the {@link ICommand} without executing it.
@@ -0,0 +1,44 @@
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 { given } from '../../../given';
5
+ import { a_command } from '../given/a_command';
6
+ import { ValidationResultSeverity } from '../../../validation/ValidationResultSeverity';
7
+ import { CommandResult } from '../../CommandResult';
8
+
9
+ describe("when executing with allowed severity warning", given(class extends a_command {
10
+ constructor() {
11
+ super();
12
+
13
+ // Setup fetch to respond normally - we're just testing that the header gets sent
14
+ this.fetchStub.resolves({
15
+ status: 200,
16
+ json: async () => ({
17
+ correlationId: '00000000-0000-0000-0000-000000000000',
18
+ isSuccess: true,
19
+ isAuthorized: true,
20
+ isValid: true,
21
+ hasExceptions: false,
22
+ validationResults: [],
23
+ exceptionMessages: [],
24
+ exceptionStackTrace: '',
25
+ authorizationFailureReason: '',
26
+ response: null
27
+ })
28
+ });
29
+ }
30
+ }, context => {
31
+ beforeEach(async () => {
32
+ await context.command.execute(ValidationResultSeverity.Warning);
33
+ });
34
+
35
+ afterEach(() => {
36
+ context.fetchHelper.restore();
37
+ });
38
+
39
+ it("should call fetch", () => context.fetchStub.called.should.be.true);
40
+ it("should have sent X-Allowed-Severity header with value 2", () => {
41
+ const headers = context.fetchStub.firstCall.args[1].headers;
42
+ headers['X-Allowed-Severity'].should.equal('2'); // Warning = 2
43
+ });
44
+ }));
@@ -4,6 +4,7 @@ import { CommandValidator } from './CommandValidator';
4
4
  import { Constructor } from '@cratis/fundamentals';
5
5
  import { GetHttpHeaders } from '../GetHttpHeaders';
6
6
  import { PropertyDescriptor } from '../reflection/PropertyDescriptor';
7
+ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity';
7
8
  export declare abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {
8
9
  readonly _responseType: Constructor;
9
10
  readonly _isResponseTypeEnumerable: boolean;
@@ -23,10 +24,11 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
23
24
  setApiBasePath(apiBasePath: string): void;
24
25
  setOrigin(origin: string): void;
25
26
  setHttpHeadersCallback(callback: GetHttpHeaders): void;
26
- execute(): Promise<CommandResult<TCommandResponse>>;
27
+ execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
27
28
  validate(): Promise<CommandResult<TCommandResponse>>;
28
29
  private buildPayload;
29
30
  private validateRequiredProperties;
31
+ private filterValidationResultsBySeverity;
30
32
  private buildHeaders;
31
33
  private performRequest;
32
34
  clear(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../commands/Command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAYtE,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAqBzH,QAAQ,CAAC,aAAa,EAAE,WAAW;IAAW,QAAQ,CAAC,yBAAyB,EAAE,OAAO;IApBrG,OAAO,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zC,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAK/B,sBAAsB,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAKhD,OAAO,CAAC,eAAe,CAAC,EAAE,wBAAwB,EAAE,cAAc,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IA2BvH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAuB1D,OAAO,CAAC,YAAY;IASpB,OAAO,CAAC,0BAA0B;IAkBlC,OAAO,CAAC,iCAAiC;IAUzC,OAAO,CAAC,YAAY;YAuBN,cAAc;IA+B5B,KAAK,IAAI,IAAI;IAUb,gBAAgB,CAAC,MAAM,EAAE,eAAe;IAYxC,iCAAiC;IAWjC,aAAa,IAAI,IAAI;IAQrB,IAAI,UAAU,YAEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAM3B"}
@@ -39,14 +39,16 @@ class Command {
39
39
  setHttpHeadersCallback(callback) {
40
40
  this._httpHeadersCallback = callback;
41
41
  }
42
- async execute() {
42
+ async execute(allowedSeverity, ignoreWarnings) {
43
43
  const clientValidationErrors = this.validation?.validate(this) || [];
44
- if (clientValidationErrors.length > 0) {
45
- return CommandResult.CommandResult.validationFailed(clientValidationErrors);
44
+ const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);
45
+ if (filteredClientErrors.length > 0) {
46
+ return CommandResult.CommandResult.validationFailed(filteredClientErrors);
46
47
  }
47
48
  const validationErrors = this.validateRequiredProperties();
48
- if (validationErrors.length > 0) {
49
- return CommandResult.CommandResult.validationFailed(validationErrors);
49
+ const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);
50
+ if (filteredRequiredErrors.length > 0) {
51
+ return CommandResult.CommandResult.validationFailed(filteredRequiredErrors);
50
52
  }
51
53
  let actualRoute = this.route;
52
54
  if (this.requestParameters && this.requestParameters.length > 0) {
@@ -54,7 +56,7 @@ class Command {
54
56
  const { route } = UrlHelpers.UrlHelpers.replaceRouteParameters(this.route, payload);
55
57
  actualRoute = route;
56
58
  }
57
- const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');
59
+ const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);
58
60
  this.setInitialValuesFromCurrentValues();
59
61
  return result;
60
62
  }
@@ -96,7 +98,16 @@ class Command {
96
98
  });
97
99
  return validationErrors;
98
100
  }
99
- buildHeaders() {
101
+ filterValidationResultsBySeverity(validationResults, allowedSeverity, ignoreWarnings) {
102
+ if (ignoreWarnings === true) {
103
+ return validationResults.filter(result => result.severity === ValidationResultSeverity.ValidationResultSeverity.Error);
104
+ }
105
+ if (allowedSeverity === undefined) {
106
+ return validationResults.filter(result => result.severity === ValidationResultSeverity.ValidationResultSeverity.Error);
107
+ }
108
+ return validationResults.filter(result => result.severity > allowedSeverity);
109
+ }
110
+ buildHeaders(allowedSeverity, ignoreWarnings) {
100
111
  const customHeaders = this._httpHeadersCallback?.() ?? {};
101
112
  const headers = {
102
113
  ...customHeaders,
@@ -106,11 +117,17 @@ class Command {
106
117
  if (this._microservice?.length > 0) {
107
118
  headers[Globals.Globals.microserviceHttpHeader] = this._microservice;
108
119
  }
120
+ if (allowedSeverity !== undefined) {
121
+ headers['X-Allowed-Severity'] = allowedSeverity.toString();
122
+ }
123
+ if (ignoreWarnings === true) {
124
+ headers['X-Ignore-Warnings'] = 'true';
125
+ }
109
126
  return headers;
110
127
  }
111
- async performRequest(route, notFoundMessage, errorMessage) {
128
+ async performRequest(route, notFoundMessage, errorMessage, allowedSeverity, ignoreWarnings) {
112
129
  const payload = this.buildPayload();
113
- const headers = this.buildHeaders();
130
+ const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);
114
131
  const actualRoute = joinPaths.joinPaths(this._apiBasePath, route);
115
132
  const url = UrlHelpers.UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
116
133
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"Command.js","sources":["../../../commands/Command.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private buildHeaders(): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders();\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer"],"mappings":";;;;;;;;;;MAuBsB,OAAO,CAAA;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EA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file":"Command.js","sources":["../../../commands/Command.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { ICommand, PropertyChanged } from './ICommand';\nimport { CommandResult } from \"./CommandResult\";\nimport { CommandValidator } from './CommandValidator';\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { Globals } from '../Globals';\nimport { joinPaths } from '../joinPaths';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { GetHttpHeaders } from '../GetHttpHeaders';\nimport { PropertyDescriptor } from '../reflection/PropertyDescriptor';\nimport { ValidationResult } from '../validation/ValidationResult';\nimport { ValidationResultSeverity } from '../validation/ValidationResultSeverity';\n\ntype Callback = {\n callback: WeakRef<PropertyChanged>;\n thisArg: WeakRef<object>;\n}\n\n/**\n * Represents an implementation of {@link ICommand} that works with HTTP fetch.\n */\nexport abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {\n private _microservice: string;\n private _apiBasePath: string;\n private _origin: string;\n private _httpHeadersCallback: GetHttpHeaders;\n abstract readonly route: string;\n /* eslint-disable @typescript-eslint/no-explicit-any */\n readonly validation?: CommandValidator<any>;\n /* eslint-enable @typescript-eslint/no-explicit-any */\n abstract readonly propertyDescriptors: PropertyDescriptor[];\n abstract get requestParameters(): string[];\n\n private _initialValues: object = {};\n private _hasChanges = false;\n private _callbacks: Callback[] = [];\n\n /**\n * Initializes a new instance of the {@link Command<,>} class.\n * @param _responseType Type of response.\n * @param _isResponseTypeEnumerable Whether or not the response type is enumerable.\n */\n constructor(readonly _responseType: Constructor = Object, readonly _isResponseTypeEnumerable: boolean) {\n this._microservice = Globals.microservice ?? '';\n this._apiBasePath = Globals.apiBasePath ?? '';\n this._origin = Globals.origin ?? '';\n this._httpHeadersCallback = () => ({});\n }\n\n /** @inheritdoc */\n setMicroservice(microservice: string) {\n this._microservice = microservice;\n }\n\n /** @inheritdoc */\n setApiBasePath(apiBasePath: string): void {\n this._apiBasePath = apiBasePath;\n }\n\n /** @inheritdoc */\n setOrigin(origin: string): void {\n this._origin = origin;\n }\n\n /** @inheritdoc */\n setHttpHeadersCallback(callback: GetHttpHeaders): void {\n this._httpHeadersCallback = callback;\n }\n\n /** @inheritdoc */\n async execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);\n if (filteredClientErrors.length > 0) {\n return CommandResult.validationFailed(filteredClientErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);\n if (filteredRequiredErrors.length > 0) {\n return CommandResult.validationFailed(filteredRequiredErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);\n this.setInitialValuesFromCurrentValues();\n return result;\n }\n\n /** @inheritdoc */\n async validate(): Promise<CommandResult<TCommandResponse>> {\n const clientValidationErrors = this.validation?.validate(this) || [];\n if (clientValidationErrors.length > 0) {\n return CommandResult.validationFailed(clientValidationErrors) as CommandResult<TCommandResponse>;\n }\n\n const validationErrors = this.validateRequiredProperties();\n if (validationErrors.length > 0) {\n return CommandResult.validationFailed(validationErrors) as CommandResult<TCommandResponse>;\n }\n\n let actualRoute = this.route;\n\n if (this.requestParameters && this.requestParameters.length > 0) {\n const payload = this.buildPayload();\n const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);\n actualRoute = route;\n }\n\n actualRoute = `${actualRoute}/validate`;\n return this.performRequest(actualRoute, 'Command validation endpoint not found at route', 'Error during validation call');\n }\n\n private buildPayload(): object {\n const payload = {};\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n payload[property] = this[property];\n });\n return payload;\n }\n\n private validateRequiredProperties(): ValidationResult[] {\n const validationErrors: ValidationResult[] = [];\n this.propertyDescriptors.forEach(propertyDescriptor => {\n if (!propertyDescriptor.isOptional && !this.requestParameters.includes(propertyDescriptor.name)) {\n const value = this[propertyDescriptor.name];\n if (value === undefined || value === null || value === '') {\n validationErrors.push(new ValidationResult(\n ValidationResultSeverity.Error,\n `${propertyDescriptor.name} is required`,\n [propertyDescriptor.name],\n null\n ));\n }\n }\n });\n return validationErrors;\n }\n\n private filterValidationResultsBySeverity(validationResults: ValidationResult[], allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): ValidationResult[] {\n if (ignoreWarnings === true) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n if (allowedSeverity === undefined) {\n return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);\n }\n return validationResults.filter(result => result.severity > allowedSeverity);\n }\n\n private buildHeaders(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): HeadersInit {\n const customHeaders = this._httpHeadersCallback?.() ?? {};\n const headers = {\n ...customHeaders,\n 'Accept': 'application/json',\n 'Content-Type': 'application/json'\n };\n\n if (this._microservice?.length > 0) {\n headers[Globals.microserviceHttpHeader] = this._microservice;\n }\n\n if (allowedSeverity !== undefined) {\n headers['X-Allowed-Severity'] = allowedSeverity.toString();\n }\n\n if (ignoreWarnings === true) {\n headers['X-Ignore-Warnings'] = 'true';\n }\n\n return headers;\n }\n\n private async performRequest(\n route: string,\n notFoundMessage: string,\n errorMessage: string,\n allowedSeverity?: ValidationResultSeverity,\n ignoreWarnings?: boolean\n ): Promise<CommandResult<TCommandResponse>> {\n const payload = this.buildPayload();\n const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);\n const actualRoute = joinPaths(this._apiBasePath, route);\n const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);\n\n try {\n const response = await fetch(url, {\n method: 'POST',\n headers,\n body: JsonSerializer.serialize(payload)\n });\n\n if (response.status === 404) {\n return CommandResult.failed([`${notFoundMessage} '${actualRoute}'`]) as CommandResult<TCommandResponse>;\n }\n\n const result = await response.json();\n return new CommandResult(result, this._responseType, this._isResponseTypeEnumerable);\n } catch (ex) {\n return CommandResult.failed([`${errorMessage}: ${ex}`]) as CommandResult<TCommandResponse>;\n }\n }\n\n /** @inheritdoc */\n clear(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = undefined;\n });\n this._initialValues = {};\n this._hasChanges = false;\n }\n\n /** @inheritdoc */\n setInitialValues(values: TCommandContent) {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (Object.prototype.hasOwnProperty.call(values, property)) {\n this._initialValues[property] = values[property];\n this[property] = values[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n setInitialValuesFromCurrentValues() {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n if (this[property]) {\n this._initialValues[property] = this[property];\n }\n });\n this.updateHasChanges();\n }\n\n /** @inheritdoc */\n revertChanges(): void {\n this.propertyDescriptors.forEach(propertyDescriptor => {\n const property = propertyDescriptor.name;\n this[property] = this._initialValues[property];\n });\n }\n\n /** @inheritdoc */\n get hasChanges() {\n return this._hasChanges;\n }\n\n /** @inheritdoc */\n propertyChanged(property: string) {\n this.updateHasChanges();\n\n this._callbacks.forEach(callbackContainer => {\n const callback = callbackContainer.callback.deref();\n const thisArg = callbackContainer.thisArg.deref();\n if (callback && thisArg) {\n callback.call(thisArg, property);\n } else {\n this._callbacks = this._callbacks.filter(_ => _.callback !== callbackContainer.callback);\n }\n });\n }\n\n /** @inheritdoc */\n onPropertyChanged(callback: PropertyChanged, thisArg: object) {\n this._callbacks.push({\n callback: new WeakRef(callback),\n thisArg: new WeakRef(thisArg)\n });\n }\n\n private updateHasChanges() {\n this._hasChanges = this.propertyDescriptors.some(propertyDescriptor => {\n const property = propertyDescriptor.name;\n return this[property] !== this._initialValues[property];\n });\n }\n}\n"],"names":["Globals","CommandResult","UrlHelpers","ValidationResult","ValidationResultSeverity","joinPaths","JsonSerializer"],"mappings":";;;;;;;;;;MAuBsB,OAAO,CAAA;AAqBJ,IAAA,aAAA;AAA8C,IAAA,yBAAA;AApB3D,IAAA,aAAa;AACb,IAAA,YAAY;AACZ,IAAA,OAAO;AACP,IAAA,oBAAoB;AAGnB,IAAA,UAAU;IAKX,cAAc,GAAW,EAAE;IAC3B,WAAW,GAAG,KAAK;IACnB,UAAU,GAAe,EAAE;IAOnC,WAAA,CAAqB,aAAA,GAA6B,MAAM,EAAW,yBAAkC,EAAA;QAAhF,IAAA,CAAA,aAAa,GAAb,aAAa;QAAiC,IAAA,CAAA,yBAAyB,GAAzB,yBAAyB;QACxF,IAAI,CAAC,aAAa,GAAGA,eAAO,CAAC,YAAY,IAAI,EAAE;QAC/C,IAAI,CAAC,YAAY,GAAGA,eAAO,CAAC,WAAW,IAAI,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAGA,eAAO,CAAC,MAAM,IAAI,EAAE;QACnC,IAAI,CAAC,oBAAoB,GAAG,OAAO,EAAE,CAAC;IAC1C;AAGA,IAAA,eAAe,CAAC,YAAoB,EAAA;AAChC,QAAA,IAAI,CAAC,aAAa,GAAG,YAAY;IACrC;AAGA,IAAA,cAAc,CAAC,WAAmB,EAAA;AAC9B,QAAA,IAAI,CAAC,YAAY,GAAG,WAAW;IACnC;AAGA,IAAA,SAAS,CAAC,MAAc,EAAA;AACpB,QAAA,IAAI,CAAC,OAAO,GAAG,MAAM;IACzB;AAGA,IAAA,sBAAsB,CAAC,QAAwB,EAAA;AAC3C,QAAA,IAAI,CAAC,oBAAoB,GAAG,QAAQ;IACxC;AAGA,IAAA,MAAM,OAAO,CAAC,eAA0C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N;IAEQ,gBAAgB,GAAA;QACpB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,kBAAkB,IAAG;AAClE,YAAA,MAAM,QAAQ,GAAG,kBAAkB,CAAC,IAAI;YACxC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC;AAC3D,QAAA,CAAC,CAAC;IACN;AACH;;;;"}
@@ -1,11 +1,12 @@
1
1
  import { ICanBeConfigured } from '../ICanBeConfigured';
2
2
  import { CommandResult } from './CommandResult';
3
3
  import { PropertyDescriptor } from '../reflection/PropertyDescriptor';
4
+ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity';
4
5
  export type PropertyChanged = (property: string) => void;
5
6
  export interface ICommand<TCommandContent = object, TCommandResponse = object> extends ICanBeConfigured {
6
7
  readonly route: string;
7
8
  readonly propertyDescriptors: PropertyDescriptor[];
8
- execute(): Promise<CommandResult<TCommandResponse>>;
9
+ execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
9
10
  validate(): Promise<CommandResult<TCommandResponse>>;
10
11
  clear(): void;
11
12
  setInitialValues(values: TCommandContent): void;
@@ -1 +1 @@
1
- {"version":3,"file":"ICommand.d.ts","sourceRoot":"","sources":["../../../commands/ICommand.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAKtE,MAAM,MAAM,eAAe,GAAG,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAC;AAKzD,MAAM,WAAW,QAAQ,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,SAAQ,gBAAgB;IAInG,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;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xH,QAAQ,IAAI,OAAO,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAMrD,KAAK,IAAI,IAAI,CAAC;IAMd,gBAAgB,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAKhD,iCAAiC,IAAI,IAAI,CAAC;IAK1C,aAAa,IAAI,IAAI,CAAC;IAKtB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAM7B,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAOxC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACvE"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=with_allowed_severity_warning.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with_allowed_severity_warning.d.ts","sourceRoot":"","sources":["../../../../../commands/for_Command/when_executing/with_allowed_severity_warning.ts"],"names":[],"mappings":""}
@@ -1,8 +1,10 @@
1
1
  export interface IIdentity<TDetails = object> {
2
2
  id: string;
3
3
  name: string;
4
+ roles: string[];
4
5
  details: TDetails;
5
6
  isSet: boolean;
7
+ isInRole(role: string): boolean;
6
8
  refresh(): Promise<IIdentity<TDetails>>;
7
9
  }
8
10
  //# sourceMappingURL=IIdentity.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IIdentity.d.ts","sourceRoot":"","sources":["../../../identity/IIdentity.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,SAAS,CAAC,QAAQ,GAAG,MAAM;IAKxC,EAAE,EAAE,MAAM,CAAC;IAKX,IAAI,EAAE,MAAM,CAAC;IAKb,OAAO,EAAE,QAAQ,CAAC;IAKlB,KAAK,EAAE,OAAO,CAAC;IAKf,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;CAC3C"}
1
+ {"version":3,"file":"IIdentity.d.ts","sourceRoot":"","sources":["../../../identity/IIdentity.ts"],"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UAAU,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;WAIjG,OAAO,CAAC,QAAQ,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;IA0BlH,OAAO,CAAC,MAAM,CAAC,SAAS;IAYxB,OAAO,CAAC,MAAM,CAAC,WAAW;CAI7B"}
@@ -29,8 +29,10 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
29
29
  return {
30
30
  id: result.id,
31
31
  name: result.name,
32
+ roles: result.roles || [],
32
33
  details: details,
33
34
  isSet: true,
35
+ isInRole: (role) => (result.roles || []).includes(role),
34
36
  refresh: () => IdentityProvider.refresh(type)
35
37
  };
36
38
  }
@@ -57,8 +59,10 @@ class IdentityProvider extends IIdentityProvider.IIdentityProvider {
57
59
  return {
58
60
  id: result.id,
59
61
  name: result.name,
62
+ roles: result.roles || [],
60
63
  details: details,
61
64
  isSet: true,
65
+ isInRole: (role) => (result.roles || []).includes(role),
62
66
  refresh: () => IdentityProvider.refresh(type)
63
67
  };
64
68
  }
@@ -1 +1 @@
1
- {"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from 'GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n return {\n id: result.id,\n name: result.name,\n details: details as TDetails,\n isSet: true,\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearCookie();\n const origin = IdentityProvider.origin || Globals.origin || '';\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const route = joinPaths(apiBasePath, '/.cratis/me');\n const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n const result = await response.json() as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n\n return {\n id: result.id,\n name: result.name,\n details: details as TDetails,\n isSet: true,\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n if (typeof document === 'undefined') return [];\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n private static clearCookie() {\n if (typeof document === 'undefined') return;\n document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;\n }\n}\n"],"names":["IIdentityProvider","JsonSerializer","Globals","joinPaths","UrlHelpers"],"mappings":";;;;;;;;AAeM,MAAO,gBAAiB,SAAQA,mCAAiB,CAAA;AAEnD,IAAA,OAAgB,UAAU,GAAG,kBAAkB;IAC/C,OAAO,mBAAmB;AAC1B,IAAA,OAAO,WAAW,GAAW,EAAE;AAC/B,IAAA,OAAO,MAAM,GAAW,EAAE;IAM1B,OAAO,sBAAsB,CAAC,QAAwB,EAAA;AAClD,QAAA,gBAAgB,CAAC,mBAAmB,GAAG,QAAQ;IACnD;IAMA,OAAO,cAAc,CAAC,WAAmB,EAAA;AACrC,QAAA,gBAAgB,CAAC,WAAW,GAAG,WAAW;IAC9C;IAMA,OAAO,SAAS,CAAC,MAAc,EAAA;AAC3B,QAAA,gBAAgB,CAAC,MAAM,GAAG,MAAM;IACpC;AAQA,IAAA,aAAa,UAAU,CAAmC,IAA4B,EAAA;AAClF,QAAA,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE;AAC/B,QAAA,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,EAAE;YACpB,MAAM,IAAI,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
+ {"version":3,"file":"IdentityProvider.js","sources":["../../../identity/IdentityProvider.ts"],"sourcesContent":["// Copyright (c) Cratis. All rights reserved.\n// Licensed under the MIT license. See LICENSE file in the project root for full license information.\n\nimport { Constructor, JsonSerializer } from '@cratis/fundamentals';\nimport { IIdentityProvider } from './IIdentityProvider';\nimport { IIdentity } from './IIdentity';\nimport { IdentityProviderResult } from './IdentityProviderResult';\nimport { GetHttpHeaders } from 'GetHttpHeaders';\nimport { Globals } from '../Globals';\nimport { UrlHelpers } from '../UrlHelpers';\nimport { joinPaths } from '../joinPaths';\n\n/**\n * Represents an implementation of {@link IIdentityProvider}.\n*/\nexport class IdentityProvider extends IIdentityProvider {\n\n static readonly CookieName = '.cratis-identity';\n static httpHeadersCallback: GetHttpHeaders | undefined;\n static apiBasePath: string = '';\n static origin: string = '';\n\n /**\n * Sets the HTTP headers callback.\n * @param callback Callback to set.\n */\n static setHttpHeadersCallback(callback: GetHttpHeaders): void {\n IdentityProvider.httpHeadersCallback = callback;\n }\n\n /**\n * Sets the API base path.\n * @param apiBasePath API base path to set.\n */\n static setApiBasePath(apiBasePath: string): void {\n IdentityProvider.apiBasePath = apiBasePath;\n }\n\n /**\n * Sets the origin.\n * @param origin Origin to set.\n */\n static setOrigin(origin: string): void {\n IdentityProvider.origin = origin;\n }\n\n /**\n * Gets the current identity by optionally specifying the details type.\n * @param type Optional constructor for the details type to enable type-safe deserialization.\n * @returns The current identity as {@link IIdentity}.\n * @remarks The `extends object` constraint is required for compatibility with JsonSerializer.deserializeFromInstance().\n */\n static async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n const cookie = this.getCookie();\n if (cookie.length == 2) {\n const json = atob(cookie[1]);\n const result = JSON.parse(json) as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n } as IIdentity<TDetails>;\n } else {\n const identity = await this.refresh<TDetails>(type);\n return identity;\n }\n }\n\n /** @inheritdoc */\n async getCurrent<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n return IdentityProvider.getCurrent<TDetails>(type);\n }\n\n static async refresh<TDetails extends object = object>(type?: Constructor<TDetails>): Promise<IIdentity<TDetails>> {\n IdentityProvider.clearCookie();\n const origin = IdentityProvider.origin || Globals.origin || '';\n const apiBasePath = IdentityProvider.apiBasePath || Globals.apiBasePath || '';\n const route = joinPaths(apiBasePath, '/.cratis/me');\n const url = UrlHelpers.createUrlFrom(origin, apiBasePath, route);\n const response = await fetch(\n url, {\n method: 'GET',\n headers: IdentityProvider.httpHeadersCallback?.() ?? {}\n });\n\n const result = await response.json() as IdentityProviderResult;\n const details = type ? JsonSerializer.deserializeFromInstance(type, result.details) : result.details;\n\n return {\n id: result.id,\n name: result.name,\n roles: result.roles || [],\n details: details as TDetails,\n isSet: true,\n isInRole: (role: string) => (result.roles || []).includes(role),\n refresh: () => IdentityProvider.refresh(type)\n };\n }\n\n private static getCookie() {\n if (typeof document === 'undefined') return [];\n const decoded = decodeURIComponent(document.cookie);\n const cookies = decoded.split(';').map(_ => _.trim());\n const cookie = cookies.find(_ => _.indexOf(`${IdentityProvider.CookieName}=`) == 0);\n if (cookie) {\n const keyValue = cookie.split('=');\n return [keyValue[0].trim(), keyValue[1].trim()];\n }\n return [];\n }\n\n private static clearCookie() {\n if (typeof document === 'undefined') return;\n document.cookie = `${IdentityProvider.CookieName}=;expires=Thu, 01 Jan 1970 00:00:00 GMT`;\n }\n}\n"],"names":["IIdentityProvider","JsonSerializer","Globals","joinPaths","UrlHelpers"],"mappings":";;;;;;;;AAeM,MAAO,gBAAiB,SAAQA,mCAAiB,CAAA;AAEnD,IAAA,OAAgB,UAAU,GAAG,kBAAkB;IAC/C,OAAO,mBAAmB;AAC1B,IAAA,OAAO,WA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L;AAEQ,IAAA,OAAO,SAAS,GAAA;QACpB,IAAI,OAAO,QAAQ,KAAK,WAAW;AAAE,YAAA,OAAO,EAAE;QAC9C,MAAM,OAAO,GAAG,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC;QACnD,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC;QACrD,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAA,EAAG,gBAAgB,CAAC,UAAU,GAAG,CAAC,IAAI,CAAC,CAAC;QACnF,IAAI,MAAM,EAAE;YACR,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC;AAClC,YAAA,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACnD;AACA,QAAA,OAAO,EAAE;IACb;AAEQ,IAAA,OAAO,WAAW,GAAA;QACtB,IAAI,OAAO,QAAQ,KAAK,WAAW;YAAE;QACrC,QAAQ,CAAC,MAAM,GAAG,CAAA,EAAG,gBAAgB,CAAC,UAAU,yCAAyC;IAC7F;;;;;"}
@@ -1,6 +1,7 @@
1
1
  export type IdentityProviderResult = {
2
2
  id: string;
3
3
  name: string;
4
+ roles: string[];
4
5
  details: object;
5
6
  };
6
7
  //# sourceMappingURL=IdentityProviderResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"IdentityProviderResult.d.ts","sourceRoot":"","sources":["../../../identity/IdentityProviderResult.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,sBAAsB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC"}
1
+ {"version":3,"file":"IdentityProviderResult.d.ts","sourceRoot":"","sources":["../../../identity/IdentityProviderResult.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,sBAAsB,GAAG;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=with_roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"with_roles.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_getting_current/with_roles.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=without_roles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"without_roles.d.ts","sourceRoot":"","sources":["../../../../../identity/for_IdentityProvider/when_getting_current/without_roles.ts"],"names":[],"mappings":""}
@@ -4,6 +4,7 @@ import { CommandValidator } from './CommandValidator';
4
4
  import { Constructor } from '@cratis/fundamentals';
5
5
  import { GetHttpHeaders } from '../GetHttpHeaders';
6
6
  import { PropertyDescriptor } from '../reflection/PropertyDescriptor';
7
+ import { ValidationResultSeverity } from '../validation/ValidationResultSeverity';
7
8
  export declare abstract class Command<TCommandContent = object, TCommandResponse = object> implements ICommand<TCommandContent, TCommandResponse> {
8
9
  readonly _responseType: Constructor;
9
10
  readonly _isResponseTypeEnumerable: boolean;
@@ -23,10 +24,11 @@ export declare abstract class Command<TCommandContent = object, TCommandResponse
23
24
  setApiBasePath(apiBasePath: string): void;
24
25
  setOrigin(origin: string): void;
25
26
  setHttpHeadersCallback(callback: GetHttpHeaders): void;
26
- execute(): Promise<CommandResult<TCommandResponse>>;
27
+ execute(allowedSeverity?: ValidationResultSeverity, ignoreWarnings?: boolean): Promise<CommandResult<TCommandResponse>>;
27
28
  validate(): Promise<CommandResult<TCommandResponse>>;
28
29
  private buildPayload;
29
30
  private validateRequiredProperties;
31
+ private filterValidationResultsBySeverity;
30
32
  private buildHeaders;
31
33
  private performRequest;
32
34
  clear(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"Command.d.ts","sourceRoot":"","sources":["../../../commands/Command.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAInE,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAYtE,8BAAsB,OAAO,CAAC,eAAe,GAAG,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAAE,YAAW,QAAQ,CAAC,eAAe,EAAE,gBAAgB,CAAC;IAqBzH,QAAQ,CAAC,aAAa,EAAE,WAAW;IAAW,QAAQ,CAAC,yBAAyB,EAAE,OAAO;IApBrG,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,oBAAoB,CAAiB;IAC7C,QAAQ,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAEhC,QAAQ,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAE5C,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC5D,QAAQ,KAAK,iBAAiB,IAAI,MAAM,EAAE,CAAC;IAE3C,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,UAAU,CAAkB;gBAOf,aAAa,EAAE,WAAW,YAAS,EAAW,yBAAyB,EAAE,OAAO;IAQrG,eAAe,CAAC,YA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AEb;IAGD,eAAe,CAAC,QAAQ,EAAE,MAAM;IAehC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM;IAO5D,OAAO,CAAC,gBAAgB;CAM3B"}
@@ -37,14 +37,16 @@ class Command {
37
37
  setHttpHeadersCallback(callback) {
38
38
  this._httpHeadersCallback = callback;
39
39
  }
40
- async execute() {
40
+ async execute(allowedSeverity, ignoreWarnings) {
41
41
  const clientValidationErrors = this.validation?.validate(this) || [];
42
- if (clientValidationErrors.length > 0) {
43
- return CommandResult.validationFailed(clientValidationErrors);
42
+ const filteredClientErrors = this.filterValidationResultsBySeverity(clientValidationErrors, allowedSeverity, ignoreWarnings);
43
+ if (filteredClientErrors.length > 0) {
44
+ return CommandResult.validationFailed(filteredClientErrors);
44
45
  }
45
46
  const validationErrors = this.validateRequiredProperties();
46
- if (validationErrors.length > 0) {
47
- return CommandResult.validationFailed(validationErrors);
47
+ const filteredRequiredErrors = this.filterValidationResultsBySeverity(validationErrors, allowedSeverity, ignoreWarnings);
48
+ if (filteredRequiredErrors.length > 0) {
49
+ return CommandResult.validationFailed(filteredRequiredErrors);
48
50
  }
49
51
  let actualRoute = this.route;
50
52
  if (this.requestParameters && this.requestParameters.length > 0) {
@@ -52,7 +54,7 @@ class Command {
52
54
  const { route } = UrlHelpers.replaceRouteParameters(this.route, payload);
53
55
  actualRoute = route;
54
56
  }
55
- const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call');
57
+ const result = await this.performRequest(actualRoute, 'Command not found at route', 'Error during server call', allowedSeverity, ignoreWarnings);
56
58
  this.setInitialValuesFromCurrentValues();
57
59
  return result;
58
60
  }
@@ -94,7 +96,16 @@ class Command {
94
96
  });
95
97
  return validationErrors;
96
98
  }
97
- buildHeaders() {
99
+ filterValidationResultsBySeverity(validationResults, allowedSeverity, ignoreWarnings) {
100
+ if (ignoreWarnings === true) {
101
+ return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);
102
+ }
103
+ if (allowedSeverity === undefined) {
104
+ return validationResults.filter(result => result.severity === ValidationResultSeverity.Error);
105
+ }
106
+ return validationResults.filter(result => result.severity > allowedSeverity);
107
+ }
108
+ buildHeaders(allowedSeverity, ignoreWarnings) {
98
109
  const customHeaders = this._httpHeadersCallback?.() ?? {};
99
110
  const headers = {
100
111
  ...customHeaders,
@@ -104,11 +115,17 @@ class Command {
104
115
  if (this._microservice?.length > 0) {
105
116
  headers[Globals.microserviceHttpHeader] = this._microservice;
106
117
  }
118
+ if (allowedSeverity !== undefined) {
119
+ headers['X-Allowed-Severity'] = allowedSeverity.toString();
120
+ }
121
+ if (ignoreWarnings === true) {
122
+ headers['X-Ignore-Warnings'] = 'true';
123
+ }
107
124
  return headers;
108
125
  }
109
- async performRequest(route, notFoundMessage, errorMessage) {
126
+ async performRequest(route, notFoundMessage, errorMessage, allowedSeverity, ignoreWarnings) {
110
127
  const payload = this.buildPayload();
111
- const headers = this.buildHeaders();
128
+ const headers = this.buildHeaders(allowedSeverity, ignoreWarnings);
112
129
  const actualRoute = joinPaths(this._apiBasePath, route);
113
130
  const url = UrlHelpers.createUrlFrom(this._origin, this._apiBasePath, actualRoute);
114
131
  try {