Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

conjure-client

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conjure-client - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

9

lib/fetchBridge/__tests__/fetchBridgeServerTests.js

@@ -44,4 +44,3 @@ "use strict";

app.all("/*", function (_req, res) {
res
.status(200)
res.status(200)
.set("Content-Type", "application/json")

@@ -60,4 +59,3 @@ .send("Hello, world!");

app.all("/*", function (_req, res) {
res
.status(200)
res.status(200)
.set("Content-Type", "application/json")

@@ -77,4 +75,3 @@ .send('"Hello, world!"');

app.all("/*", function (_req, res) {
res
.status(200)
res.status(200)
.set("Content-Type", "application/json")

@@ -81,0 +78,0 @@ .send(JSON.stringify(payload));

@@ -386,2 +386,30 @@ "use strict";

}); });
it("passes dynamic tokens", function () { return __awaiter(_this, void 0, void 0, function () {
var tokenProvider, request, expectedUrl, expectedFetchRequest, expectedFetchResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
tokenProvider = jest.fn().mockReturnValueOnce(token);
bridge = new fetchBridge_1.FetchBridge({ baseUrl: baseUrl, token: tokenProvider, fetch: undefined, userAgent: userAgent });
request = {
endpointName: "a",
endpointPath: "a/",
method: "GET",
pathArguments: [],
queryArguments: {},
};
expectedUrl = baseUrl + "/a/";
expectedFetchRequest = createFetchRequest({
method: "GET",
responseMediaType: request.responseMediaType,
});
expectedFetchResponse = createFetchResponse(undefined, 204);
mockFetch(expectedUrl, expectedFetchRequest, expectedFetchResponse);
return [4 /*yield*/, expect(bridge.callEndpoint(request)).resolves.toBeUndefined()];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); });
it("passes headers", function () { return __awaiter(_this, void 0, void 0, function () {

@@ -388,0 +416,0 @@ var request, expectedUrl, expectedFetchRequest, expectedFetchResponse;

@@ -41,3 +41,3 @@ /**

userAgent: IUserAgent;
token?: string;
token?: string | Supplier<string>;
fetch?: FetchFunction;

@@ -48,3 +48,3 @@ }

private readonly getBaseUrl;
private readonly token;
private readonly getToken;
private readonly fetch;

@@ -51,0 +51,0 @@ private readonly userAgent;

@@ -70,4 +70,4 @@ "use strict";

function FetchBridge(params) {
this.getBaseUrl = typeof params.baseUrl === "string" ? function () { return params.baseUrl; } : params.baseUrl;
this.token = params.token;
this.getBaseUrl = typeof params.baseUrl === "function" ? params.baseUrl : function () { return params.baseUrl; };
this.getToken = typeof params.token === "function" ? params.token : function () { return params.token; };
this.fetch = params.fetch;

@@ -78,3 +78,3 @@ this.userAgent = params.userAgent;

return __awaiter(this, void 0, void 0, function () {
var url, data, _a, headers, method, requestMediaType, responseMediaType, stringifiedHeaders, fetchRequestInit, fetchFunction, response, contentType, bodyPromise, body, error_1, error_2;
var url, data, _a, headers, method, requestMediaType, responseMediaType, stringifiedHeaders, fetchRequestInit, token, fetchFunction, response, contentType, bodyPromise, body, error_1, error_2;
return __generator(this, function (_b) {

@@ -99,4 +99,5 @@ switch (_b.label) {

};
if (this.token !== undefined) {
fetchRequestInit.headers = __assign({}, fetchRequestInit.headers, { Authorization: "Bearer " + this.token });
token = this.getToken();
if (token !== undefined) {
fetchRequestInit.headers = __assign({}, fetchRequestInit.headers, { Authorization: "Bearer " + token });
}

@@ -103,0 +104,0 @@ if (requestMediaType != null && requestMediaType !== httpApiBridge_1.MediaType.MULTIPART_FORM_DATA) {

{
"name": "conjure-client",
"version": "1.4.0",
"version": "1.5.0",
"description": "An HTTP bridge library for use in front end applications and generated conjure code",

@@ -24,9 +24,9 @@ "sideEffects": false,

"devDependencies": {
"@blueprintjs/tslint-config": "^1.6.0",
"@types/chai": "^4.1.6",
"@types/express": "^4.16.0",
"@blueprintjs/tslint-config": "^1.8.0",
"@types/chai": "^4.1.7",
"@types/express": "^4.16.1",
"@types/fetch-mock": "^5.12.2",
"@types/jest": "^21.1.10",
"chai": "^4.2.0",
"es6-shim": "^0.35.3",
"es6-shim": "^0.35.5",
"express": "^4.16.4",

@@ -43,5 +43,5 @@ "fetch-mock": "^5.13.1",

"node-fetch-polyfill": "^2.0.6",
"npm-run-all": "^4.1.3",
"npm-run-all": "^4.1.5",
"ts-jest": "^21.2.4",
"tslint": "^5.11.0",
"tslint": "^5.15.0",
"tslint-react": "^3.6.0",

@@ -48,0 +48,0 @@ "typescript": "~2.9.2",

@@ -50,4 +50,3 @@ /**

app.all("/*", (_req, res) => {
res
.status(200)
res.status(200)
.set("Content-Type", "application/json")

@@ -68,4 +67,3 @@ .send("Hello, world!");

app.all("/*", (_req, res) => {
res
.status(200)
res.status(200)
.set("Content-Type", "application/json")

@@ -88,4 +86,3 @@ .send('"Hello, world!"');

app.all("/*", (_req, res) => {
res
.status(200)
res.status(200)
.set("Content-Type", "application/json")

@@ -92,0 +89,0 @@ .send(JSON.stringify(payload));

@@ -277,2 +277,23 @@ /**

it("passes dynamic tokens", async () => {
const tokenProvider: () => string = jest.fn().mockReturnValueOnce(token);
bridge = new FetchBridge({ baseUrl, token: tokenProvider, fetch: undefined, userAgent });
const request: IHttpEndpointOptions = {
endpointName: "a",
endpointPath: "a/",
method: "GET",
pathArguments: [],
queryArguments: {},
};
const expectedUrl = `${baseUrl}/a/`;
const expectedFetchRequest = createFetchRequest({
method: "GET",
responseMediaType: request.responseMediaType,
});
const expectedFetchResponse = createFetchResponse(undefined, 204);
mockFetch(expectedUrl, expectedFetchRequest, expectedFetchResponse);
await expect(bridge.callEndpoint(request)).resolves.toBeUndefined();
});
it("passes headers", async () => {

@@ -279,0 +300,0 @@ const request: IHttpEndpointOptions = {

@@ -54,3 +54,3 @@ /**

userAgent: IUserAgent;
token?: string;
token?: string | Supplier<string>;
fetch?: FetchFunction;

@@ -63,3 +63,3 @@ }

private readonly getBaseUrl: Supplier<string>;
private readonly token: string | undefined;
private readonly getToken: Supplier<string | undefined>;
private readonly fetch: FetchFunction | undefined;

@@ -69,4 +69,4 @@ private readonly userAgent: IUserAgent;

constructor(params: IFetchBridgeParams) {
this.getBaseUrl = typeof params.baseUrl === "string" ? () => params.baseUrl as string : params.baseUrl;
this.token = params.token;
this.getBaseUrl = typeof params.baseUrl === "function" ? params.baseUrl : () => params.baseUrl as string;
this.getToken = typeof params.token === "function" ? params.token : () => params.token as string | undefined;
this.fetch = params.fetch;

@@ -96,4 +96,5 @@ this.userAgent = params.userAgent;

if (this.token !== undefined) {
fetchRequestInit.headers = { ...fetchRequestInit.headers, Authorization: `Bearer ${this.token}` };
const token = this.getToken();
if (token !== undefined) {
fetchRequestInit.headers = { ...fetchRequestInit.headers, Authorization: `Bearer ${token}` };
}

@@ -100,0 +101,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc