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.5.0 to 1.6.0

35

lib/fetchBridge/__tests__/fetchBridgeTests.js

@@ -302,2 +302,37 @@ "use strict";

}); });
it("makes POST request with url encoded form data", function () { return __awaiter(_this, void 0, void 0, function () {
var request, expectedUrl, expectedFetchRequest, expectedFetchResponse;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
request = {
data: {
param1: "a",
param2: ["b", "c"],
"param=3": "ürl-êñçódèd",
},
endpointName: "a",
endpointPath: "a/{var}/b",
method: "POST",
pathArguments: ["val"],
queryArguments: {},
requestMediaType: httpApiBridge_1.MediaType.APPLICATION_X_WWW_FORM_URLENCODED,
responseMediaType: httpApiBridge_1.MediaType.APPLICATION_JSON,
};
expectedUrl = baseUrl + "/a/val/b";
expectedFetchRequest = createFetchRequest({
contentType: "application/x-www-form-urlencoded",
data: "param1=a&param2=b&param2=c&param%3D3=%C3%BCrl-%C3%AA%C3%B1%C3%A7%C3%B3d%C3%A8d",
method: "POST",
responseMediaType: request.responseMediaType,
});
expectedFetchResponse = createFetchResponse(mockedResponseData, 200);
mockFetch(expectedUrl, expectedFetchRequest, expectedFetchResponse);
return [4 /*yield*/, expect(bridge.callEndpoint(request)).resolves.toEqual(mockedResponseData)];
case 1:
_a.sent();
return [2 /*return*/];
}
});
}); });
it("makes PUT request", function () { return __awaiter(_this, void 0, void 0, function () {

@@ -304,0 +339,0 @@ var request, expectedUrl, expectedFetchRequest, expectedFetchResponse;

15

lib/fetchBridge/fetchBridge.js

@@ -77,7 +77,8 @@ "use strict";

return __awaiter(this, void 0, void 0, function () {
var url, data, _a, headers, method, requestMediaType, responseMediaType, stringifiedHeaders, fetchRequestInit, token, fetchFunction, response, contentType, bodyPromise, body, error_1, error_2;
var query, url, data, _a, headers, method, requestMediaType, responseMediaType, stringifiedHeaders, fetchRequestInit, token, fetchFunction, response, contentType, bodyPromise, body, error_1, error_2;
return __generator(this, function (_b) {
switch (_b.label) {
case 0:
url = this.getBaseUrl() + "/" + this.buildPath(params) + this.buildQueryString(params);
query = this.buildQueryString(params.queryArguments);
url = this.getBaseUrl() + "/" + this.buildPath(params) + (query.length > 0 ? "?" + query : "");
data = params.data, _a = params.headers, headers = _a === void 0 ? {} : _a, method = params.method, requestMediaType = params.requestMediaType, responseMediaType = params.responseMediaType;

@@ -190,7 +191,7 @@ headers["Fetch-User-Agent"] = formatUserAgent(this.userAgent);

};
FetchBridge.prototype.buildQueryString = function (parameters) {
FetchBridge.prototype.buildQueryString = function (data) {
var _this = this;
var query = [];
var _loop_1 = function (key) {
var value = parameters.queryArguments[key];
var value = data[key];
if (value == null) {

@@ -207,7 +208,7 @@ return "continue";

var this_1 = this;
for (var _i = 0, _a = Object.keys(parameters.queryArguments); _i < _a.length; _i++) {
for (var _i = 0, _a = Object.keys(data); _i < _a.length; _i++) {
var key = _a[_i];
_loop_1(key);
}
return query.length > 0 ? "?" + query.join("&") : "";
return query.join("&");
};

@@ -221,2 +222,4 @@ FetchBridge.prototype.handleBody = function (parameters) {

return parameters.data;
case httpApiBridge_1.MediaType.APPLICATION_X_WWW_FORM_URLENCODED:
return this.buildQueryString(parameters.data);
case httpApiBridge_1.MediaType.TEXT_PLAIN:

@@ -223,0 +226,0 @@ if (typeof parameters.data === "object") {

1

lib/httpApiBridge.d.ts

@@ -44,2 +44,3 @@ /**

APPLICATION_OCTET_STREAM = "application/octet-stream",
APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded",
MULTIPART_FORM_DATA = "multipart/form-data",

@@ -46,0 +47,0 @@ TEXT_PLAIN = "text/plain"

@@ -23,2 +23,3 @@ "use strict";

MediaType["APPLICATION_OCTET_STREAM"] = "application/octet-stream";
MediaType["APPLICATION_X_WWW_FORM_URLENCODED"] = "application/x-www-form-urlencoded";
MediaType["MULTIPART_FORM_DATA"] = "multipart/form-data";

@@ -25,0 +26,0 @@ MediaType["TEXT_PLAIN"] = "text/plain";

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

@@ -5,0 +5,0 @@ "sideEffects": false,

@@ -217,2 +217,29 @@ /**

it("makes POST request with url encoded form data", async () => {
const request: IHttpEndpointOptions = {
data: {
param1: "a",
param2: ["b", "c"],
"param=3": "ürl-êñçódèd",
},
endpointName: "a",
endpointPath: "a/{var}/b",
method: "POST",
pathArguments: ["val"],
queryArguments: {},
requestMediaType: MediaType.APPLICATION_X_WWW_FORM_URLENCODED,
responseMediaType: MediaType.APPLICATION_JSON,
};
const expectedUrl = `${baseUrl}/a/val/b`;
const expectedFetchRequest = createFetchRequest({
contentType: "application/x-www-form-urlencoded",
data: "param1=a&param2=b&param2=c&param%3D3=%C3%BCrl-%C3%AA%C3%B1%C3%A7%C3%B3d%C3%A8d",
method: "POST",
responseMediaType: request.responseMediaType,
});
const expectedFetchResponse = createFetchResponse(mockedResponseData, 200);
mockFetch(expectedUrl, expectedFetchRequest, expectedFetchResponse);
await expect(bridge.callEndpoint(request)).resolves.toEqual(mockedResponseData);
});
it("makes PUT request", async () => {

@@ -219,0 +246,0 @@ const request: IHttpEndpointOptions = {

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

public async callEndpoint<T>(params: IHttpEndpointOptions): Promise<T> {
const url = `${this.getBaseUrl()}/${this.buildPath(params)}${this.buildQueryString(params)}`;
const query = this.buildQueryString(params.queryArguments);
const url = `${this.getBaseUrl()}/${this.buildPath(params)}${query.length > 0 ? `?${query}` : ""}`;
const { data, headers = {}, method, requestMediaType, responseMediaType } = params;

@@ -176,6 +177,6 @@ headers["Fetch-User-Agent"] = formatUserAgent(this.userAgent);

private buildQueryString(parameters: IHttpEndpointOptions) {
private buildQueryString(data: { [key: string]: any }) {
const query: string[] = [];
for (const key of Object.keys(parameters.queryArguments)) {
const value = parameters.queryArguments[key];
for (const key of Object.keys(data)) {
const value = data[key];
if (value == null) {

@@ -190,3 +191,3 @@ continue;

}
return query.length > 0 ? `?${query.join("&")}` : "";
return query.join("&");
}

@@ -201,2 +202,4 @@

return parameters.data;
case MediaType.APPLICATION_X_WWW_FORM_URLENCODED:
return this.buildQueryString(parameters.data);
case MediaType.TEXT_PLAIN:

@@ -203,0 +206,0 @@ if (typeof parameters.data === "object") {

@@ -53,2 +53,3 @@ /**

APPLICATION_OCTET_STREAM = "application/octet-stream",
APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded",
MULTIPART_FORM_DATA = "multipart/form-data",

@@ -55,0 +56,0 @@ TEXT_PLAIN = "text/plain",

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