Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
},
"homepage": "https://github.com/AsyncLegs/wayforpay-typescript#readme",
"dependencies": {
"lodash": "^4.17.11",
"node-fetch": "^2.6.0"
"lodash": "^4.17.11"
},
"devDependencies": {
"@types/jest": "^24.0.13",
Expand Down
10 changes: 0 additions & 10 deletions src/fields.ts

This file was deleted.

9 changes: 9 additions & 0 deletions src/transport/enums/http.methods.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export enum HttpMethod {
'POST' = 'POST',
'PUT' = 'PUT',
'PATCH' = 'PATCH',
'DELETE' = 'DELETE',
'HEAD' = 'HEAD',
'OPTIONS' = 'OPTIONS',
'GET' = 'GET'
}
1 change: 1 addition & 0 deletions src/transport/enums/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './http.methods.enum';
43 changes: 43 additions & 0 deletions src/transport/http.request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as https from 'https';
import { parse } from 'url';
import { HttpMethod } from './enums';

export const request = (url: string, requestData: any) => {
const { port, hostname, path } = parse(url);
return new Promise((resolve, reject) => {
const httpRequest = https.request(
{
headers: requestData.headers,
hostname,
method: requestData.method as HttpMethod,
path,
port
},
response => {
if (
response &&
response.statusCode &&
(response.statusCode < 200 || response.statusCode > 299)
) {
reject(
new Error(
`Request failed, status code: ${
response.statusCode
}, message is : ${response.statusMessage}`
)
);
}

const body: any[] = [];
response.on('data', chunk => body.push(chunk));
response.on('end', () => resolve(body.join('')));
response.on('error', err => reject(err));
}
);
httpRequest.on('error', err => reject(err));
if (requestData.body) {
httpRequest.write(requestData.body);
}
httpRequest.end();
});
};
1 change: 1 addition & 0 deletions src/transport/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './http.request';
7 changes: 2 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@ export const serialize = (obj: any) => {
const str = [];
for (const p in obj) {
if (obj.hasOwnProperty(p)) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
str.push(`${encodeURIComponent(p)}=${encodeURIComponent(obj[p])}`);
}
}
return str.join("&");
};
export const propertyExists = (key: string, search: any) => {
if (
!search ||
(search.constructor !== Array && search.constructor !== Object)
) {
if (!Array.isArray(search) && search.constructor !== Object) {
return false;
}

Expand Down
Loading