@cerbos/http
Advanced tools
Comparing version 0.13.0 to 0.14.0
@@ -10,3 +10,2 @@ "use strict"; | ||
const core_1 = require("@cerbos/core"); | ||
const abab_1 = require("abab"); | ||
const qs_1 = require("qs"); | ||
@@ -59,3 +58,3 @@ const request_1 = require("./protobuf/cerbos/request/v1/request"); | ||
constructor(url, options = {}) { | ||
const transport = async (service, rpc, request, adminCredentials) => { | ||
super(async (service, rpc, request, adminCredentials, metadata = {}) => { | ||
const { method, path, requestType, responseType, serializeRequest } = services[service][rpc]; // https://github.com/microsoft/TypeScript/issues/30581 | ||
@@ -69,3 +68,3 @@ const requestProtobuf = requestType.toJSON(request); | ||
body: serializeRequest === "body" ? JSON.stringify(requestProtobuf) : null, | ||
headers: headers(options, adminCredentials), | ||
headers: headers(options, adminCredentials, metadata), | ||
}); | ||
@@ -76,4 +75,3 @@ if (!response.ok) { | ||
return responseType.fromJSON(await response.json()); | ||
}; | ||
super(transport, options); | ||
}, options); | ||
} | ||
@@ -179,3 +177,3 @@ } | ||
}; | ||
const headers = ({ headers: optionalHeaders, playgroundInstance }, adminCredentials) => { | ||
function headers({ headers: optionalHeaders, playgroundInstance }, adminCredentials, metadata) { | ||
const headers = new Headers(typeof optionalHeaders === "function" ? optionalHeaders() : optionalHeaders); | ||
@@ -185,3 +183,3 @@ headers.set("User-Agent", headers.get("User-Agent")?.concat(" ", defaultUserAgent) ?? | ||
if (adminCredentials) { | ||
headers.set("Authorization", `Basic ${(0, abab_1.btoa)(`${adminCredentials.username}:${adminCredentials.password}`) ?? ""}`); | ||
headers.set("Authorization", `Basic ${btoa(`${adminCredentials.username}:${adminCredentials.password}`) ?? ""}`); | ||
} | ||
@@ -191,4 +189,7 @@ if (playgroundInstance) { | ||
} | ||
for (const [key, value] of Object.entries(metadata)) { | ||
headers.set(key, value); | ||
} | ||
return headers; | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@cerbos/http", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "Client library for interacting with the Cerbos policy decision point over HTTP from browser-based applications", | ||
@@ -29,4 +29,3 @@ "repository": { | ||
"dependencies": { | ||
"@cerbos/core": "^0.12.0", | ||
"abab": "^2.0.6", | ||
"@cerbos/core": "^0.13.0", | ||
"qs": "^6.11.2" | ||
@@ -33,0 +32,0 @@ }, |
@@ -14,6 +14,4 @@ /** | ||
_Service, | ||
_Transport, | ||
} from "@cerbos/core"; | ||
import { Client, NotOK } from "@cerbos/core"; | ||
import { btoa } from "abab"; | ||
import { stringify as queryStringify } from "qs"; | ||
@@ -112,8 +110,3 @@ | ||
public constructor(url: string, options: Options = {}) { | ||
const transport: _Transport = async ( | ||
service, | ||
rpc, | ||
request, | ||
adminCredentials, | ||
) => { | ||
super(async (service, rpc, request, adminCredentials, metadata = {}) => { | ||
const { method, path, requestType, responseType, serializeRequest } = | ||
@@ -133,3 +126,3 @@ services[service][rpc] as Endpoint<typeof service, typeof rpc>; // https://github.com/microsoft/TypeScript/issues/30581 | ||
serializeRequest === "body" ? JSON.stringify(requestProtobuf) : null, | ||
headers: headers(options, adminCredentials), | ||
headers: headers(options, adminCredentials, metadata), | ||
}); | ||
@@ -142,5 +135,3 @@ | ||
return responseType.fromJSON(await response.json()); | ||
}; | ||
super(transport, options); | ||
}, options); | ||
} | ||
@@ -261,6 +252,7 @@ } | ||
const headers = ( | ||
function headers( | ||
{ headers: optionalHeaders, playgroundInstance }: Options, | ||
adminCredentials: AdminCredentials | undefined, | ||
): Headers => { | ||
metadata: Record<string, string>, | ||
): Headers { | ||
const headers = new Headers( | ||
@@ -289,3 +281,7 @@ typeof optionalHeaders === "function" ? optionalHeaders() : optionalHeaders, | ||
for (const [key, value] of Object.entries(metadata)) { | ||
headers.set(key, value); | ||
} | ||
return headers; | ||
}; | ||
} |
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
895326
2
18019
+ Added@cerbos/core@0.13.0(transitive)
- Removedabab@^2.0.6
- Removed@cerbos/core@0.12.0(transitive)
- Removedabab@2.0.6(transitive)
Updated@cerbos/core@^0.13.0