@cerbos/core
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -113,3 +113,4 @@ import type { _RPCs, _Request, _Response } from "./rpcs"; | ||
serverInfo(): Promise<ServerInfo>; | ||
private handleValidationErrors; | ||
} | ||
//# sourceMappingURL=client.d.ts.map |
@@ -70,13 +70,4 @@ "use strict"; | ||
async checkResources(request) { | ||
const { onValidationError } = this.options; | ||
const response = (0, fromProtobuf_1.checkResourcesResponseFromProtobuf)(await this.transport("checkResources", (0, toProtobuf_1.checkResourcesRequestToProtobuf)(request))); | ||
if (onValidationError) { | ||
const validationErrors = response.results.flatMap(({ validationErrors }) => validationErrors); | ||
if (validationErrors.length > 0) { | ||
if (onValidationError === "throw") { | ||
throw new errors_1.ValidationFailed(validationErrors); | ||
} | ||
onValidationError(validationErrors); | ||
} | ||
} | ||
this.handleValidationErrors(response); | ||
return response; | ||
@@ -117,3 +108,5 @@ } | ||
async planResources(request) { | ||
return (0, fromProtobuf_1.planResourcesResponseFromProtobuf)(await this.transport("planResources", (0, toProtobuf_1.planResourcesRequestToProtobuf)(request))); | ||
const response = (0, fromProtobuf_1.planResourcesResponseFromProtobuf)(await this.transport("planResources", (0, toProtobuf_1.planResourcesRequestToProtobuf)(request))); | ||
this.handleValidationErrors(response); | ||
return response; | ||
} | ||
@@ -126,4 +119,15 @@ /** | ||
} | ||
handleValidationErrors({ validationErrors, }) { | ||
const { onValidationError } = this.options; | ||
if (onValidationError) { | ||
if (validationErrors.length > 0) { | ||
if (onValidationError === "throw") { | ||
throw new errors_1.ValidationFailed(validationErrors); | ||
} | ||
onValidationError(validationErrors); | ||
} | ||
} | ||
} | ||
} | ||
exports.Client = Client; | ||
//# sourceMappingURL=client.js.map |
@@ -5,3 +5,3 @@ import type { CheckResourcesResponse as CheckResourcesResponseProtobuf, PlanResourcesResponse as PlanResourcesResponseProtobuf } from "../protobuf/cerbos/response/v1/response"; | ||
export declare const checkResourcesResponseFromProtobuf: ({ requestId, results, }: CheckResourcesResponseProtobuf) => CheckResourcesResponse; | ||
export declare const planResourcesResponseFromProtobuf: ({ requestId, filter, meta, }: PlanResourcesResponseProtobuf) => PlanResourcesResponse; | ||
export declare const planResourcesResponseFromProtobuf: ({ requestId, filter, validationErrors, meta, }: PlanResourcesResponseProtobuf) => PlanResourcesResponse; | ||
//# sourceMappingURL=fromProtobuf.d.ts.map |
@@ -44,3 +44,3 @@ "use strict"; | ||
}; | ||
const planResourcesResponseFromProtobuf = ({ requestId, filter, meta, }) => { | ||
const planResourcesResponseFromProtobuf = ({ requestId, filter, validationErrors, meta, }) => { | ||
if (!filter) { | ||
@@ -59,2 +59,3 @@ throw new Error("Missing filter on PlanResources response"); | ||
condition: planOperandFromProtobuf(filter.condition), | ||
validationErrors: validationErrors.map(validationErrorFromProtobuf), | ||
metadata, | ||
@@ -66,2 +67,3 @@ }; | ||
kind, | ||
validationErrors: validationErrors.map(validationErrorFromProtobuf), | ||
metadata, | ||
@@ -68,0 +70,0 @@ }; |
@@ -81,2 +81,3 @@ import type { Effect } from "../../../cerbos/effect/v1/effect"; | ||
filterDebug: string; | ||
validationErrors: ValidationError[]; | ||
} | ||
@@ -83,0 +84,0 @@ export interface CheckInput { |
@@ -15,2 +15,3 @@ import type { Effect } from "../../../cerbos/effect/v1/effect"; | ||
meta: PlanResourcesResponse_Meta | undefined; | ||
validationErrors: ValidationError[]; | ||
} | ||
@@ -17,0 +18,0 @@ export interface PlanResourcesResponse_Meta { |
@@ -97,2 +97,6 @@ /** | ||
findResult(resource: ResourceSearch): CheckResourcesResult | undefined; | ||
/** | ||
* Unique schema validation errors for the principal or resource attributes. | ||
*/ | ||
get validationErrors(): ValidationError[]; | ||
} | ||
@@ -383,2 +387,6 @@ /** | ||
/** | ||
* Any schema validation errors for the principal or resource attributes. | ||
*/ | ||
validationErrors: ValidationError[]; | ||
/** | ||
* Additional information about the query plan. | ||
@@ -385,0 +393,0 @@ * |
@@ -55,2 +55,15 @@ "use strict"; | ||
} | ||
/** | ||
* Unique schema validation errors for the principal or resource attributes. | ||
*/ | ||
get validationErrors() { | ||
const unique = {}; | ||
this.results.forEach(({ validationErrors }) => { | ||
validationErrors.forEach((validationError) => { | ||
const { path, message, source } = validationError; | ||
unique[`${path}:${message}:${source}`] = validationError; | ||
}); | ||
}); | ||
return Object.values(unique); | ||
} | ||
} | ||
@@ -57,0 +70,0 @@ exports.CheckResourcesResponse = CheckResourcesResponse; |
{ | ||
"name": "@cerbos/core", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Common types used by the @cerbos/grpc and @cerbos/http client libraries", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -20,2 +20,3 @@ import { | ||
ServerInfo, | ||
ValidationError, | ||
ValidationFailedCallback, | ||
@@ -132,4 +133,2 @@ } from "./types"; | ||
): Promise<CheckResourcesResponse> { | ||
const { onValidationError } = this.options; | ||
const response = checkResourcesResponseFromProtobuf( | ||
@@ -142,16 +141,4 @@ await this.transport( | ||
if (onValidationError) { | ||
const validationErrors = response.results.flatMap( | ||
({ validationErrors }) => validationErrors | ||
); | ||
this.handleValidationErrors(response); | ||
if (validationErrors.length > 0) { | ||
if (onValidationError === "throw") { | ||
throw new ValidationFailed(validationErrors); | ||
} | ||
onValidationError(validationErrors); | ||
} | ||
} | ||
return response; | ||
@@ -198,3 +185,3 @@ } | ||
): Promise<PlanResourcesResponse> { | ||
return planResourcesResponseFromProtobuf( | ||
const response = planResourcesResponseFromProtobuf( | ||
await this.transport( | ||
@@ -205,2 +192,6 @@ "planResources", | ||
); | ||
this.handleValidationErrors(response); | ||
return response; | ||
} | ||
@@ -214,2 +205,20 @@ | ||
} | ||
private handleValidationErrors({ | ||
validationErrors, | ||
}: { | ||
validationErrors: ValidationError[]; | ||
}): void { | ||
const { onValidationError } = this.options; | ||
if (onValidationError) { | ||
if (validationErrors.length > 0) { | ||
if (onValidationError === "throw") { | ||
throw new ValidationFailed(validationErrors); | ||
} | ||
onValidationError(validationErrors); | ||
} | ||
} | ||
} | ||
} |
@@ -104,2 +104,3 @@ import { Effect as EffectProtobuf } from "../protobuf/cerbos/effect/v1/effect"; | ||
filter, | ||
validationErrors, | ||
meta, | ||
@@ -123,2 +124,3 @@ }: PlanResourcesResponseProtobuf): PlanResourcesResponse => { | ||
condition: planOperandFromProtobuf(filter.condition), | ||
validationErrors: validationErrors.map(validationErrorFromProtobuf), | ||
metadata, | ||
@@ -131,2 +133,3 @@ }; | ||
kind, | ||
validationErrors: validationErrors.map(validationErrorFromProtobuf), | ||
metadata, | ||
@@ -133,0 +136,0 @@ }; |
@@ -86,2 +86,3 @@ /* eslint-disable */ | ||
filterDebug: string; | ||
validationErrors: ValidationError[]; | ||
} | ||
@@ -88,0 +89,0 @@ |
@@ -21,2 +21,3 @@ /* eslint-disable */ | ||
meta: PlanResourcesResponse_Meta | undefined; | ||
validationErrors: ValidationError[]; | ||
} | ||
@@ -23,0 +24,0 @@ |
@@ -136,2 +136,18 @@ /** | ||
} | ||
/** | ||
* Unique schema validation errors for the principal or resource attributes. | ||
*/ | ||
public get validationErrors(): ValidationError[] { | ||
const unique: Record<string, ValidationError> = {}; | ||
this.results.forEach(({ validationErrors }) => { | ||
validationErrors.forEach((validationError) => { | ||
const { path, message, source } = validationError; | ||
unique[`${path}:${message}:${source}`] = validationError; | ||
}); | ||
}); | ||
return Object.values(unique); | ||
} | ||
} | ||
@@ -486,2 +502,7 @@ | ||
/** | ||
* Any schema validation errors for the principal or resource attributes. | ||
*/ | ||
validationErrors: ValidationError[]; | ||
/** | ||
* Additional information about the query plan. | ||
@@ -488,0 +509,0 @@ * |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
525678
12710