@trayio/commons 4.49.0 → 4.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts +12 -0
- package/dist/codec/SnakeCasePropertyNameCodec.d.ts.map +1 -0
- package/dist/codec/SnakeCasePropertyNameCodec.js +74 -0
- package/dist/codec/SnakeCasePropertyNameCodec.unit.test.d.ts +2 -0
- package/dist/codec/SnakeCasePropertyNameCodec.unit.test.d.ts.map +1 -0
- package/dist/codec/SnakeCasePropertyNameCodec.unit.test.js +70 -0
- package/dist/http/Http.d.ts +12 -0
- package/dist/http/Http.d.ts.map +1 -1
- package/dist/http/Http.js +12 -1
- package/dist/http/HttpClient.abstract.test.d.ts.map +1 -1
- package/dist/http/HttpClient.abstract.test.js +62 -12
- package/dist/string/StringExtensions.d.ts +1 -0
- package/dist/string/StringExtensions.d.ts.map +1 -1
- package/dist/string/StringExtensions.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as E from 'fp-ts/lib/Either';
|
|
2
|
+
import { Codec } from './Codec';
|
|
3
|
+
export declare class SnakeCasePropertyNameCodec implements Codec<unknown> {
|
|
4
|
+
static instance: Codec<unknown>;
|
|
5
|
+
encode(value: unknown): unknown;
|
|
6
|
+
decode(value: unknown): E.Either<Error, unknown>;
|
|
7
|
+
private isObject;
|
|
8
|
+
private snakeCasePropertyNameIfPresent;
|
|
9
|
+
private snakeCasePropertyNameFromArrayIfPresent;
|
|
10
|
+
private snakeCasePropertyNameFromObjectIfPresent;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=SnakeCasePropertyNameCodec.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnakeCasePropertyNameCodec.d.ts","sourceRoot":"","sources":["../../src/codec/SnakeCasePropertyNameCodec.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,qBAAa,0BAA2B,YAAW,KAAK,CAAC,OAAO,CAAC;IAChE,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,CAAoC;IAEnE,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO;IAI/B,MAAM,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC;IAIhD,OAAO,CAAC,QAAQ;IAIhB,OAAO,CAAC,8BAA8B;IAatC,OAAO,CAAC,uCAAuC;IAW/C,OAAO,CAAC,wCAAwC;CAehD"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.SnakeCasePropertyNameCodec = void 0;
|
|
27
|
+
const E = __importStar(require("fp-ts/lib/Either"));
|
|
28
|
+
const StringExtensions_1 = require("../string/StringExtensions");
|
|
29
|
+
class SnakeCasePropertyNameCodec {
|
|
30
|
+
static instance = new SnakeCasePropertyNameCodec();
|
|
31
|
+
encode(value) {
|
|
32
|
+
return this.snakeCasePropertyNameIfPresent(value);
|
|
33
|
+
}
|
|
34
|
+
decode(value) {
|
|
35
|
+
return E.right(this.snakeCasePropertyNameIfPresent(value));
|
|
36
|
+
}
|
|
37
|
+
isObject(value) {
|
|
38
|
+
return typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
39
|
+
}
|
|
40
|
+
snakeCasePropertyNameIfPresent(value) {
|
|
41
|
+
if (value === null) {
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
if (this.isObject(value)) {
|
|
45
|
+
return this.snakeCasePropertyNameFromObjectIfPresent(value);
|
|
46
|
+
}
|
|
47
|
+
if (Array.isArray(value)) {
|
|
48
|
+
return this.snakeCasePropertyNameFromArrayIfPresent(value);
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
snakeCasePropertyNameFromArrayIfPresent(value) {
|
|
53
|
+
return value.reduce((acc, propertyValue) => {
|
|
54
|
+
if (propertyValue == null) {
|
|
55
|
+
return acc;
|
|
56
|
+
}
|
|
57
|
+
return [...acc, this.snakeCasePropertyNameIfPresent(propertyValue)];
|
|
58
|
+
}, []);
|
|
59
|
+
}
|
|
60
|
+
snakeCasePropertyNameFromObjectIfPresent(value) {
|
|
61
|
+
return Object.entries(value).reduce((acc, [key, propertyValue]) => {
|
|
62
|
+
if (this.isObject(propertyValue)) {
|
|
63
|
+
const nestedObject = this.snakeCasePropertyNameFromObjectIfPresent(propertyValue);
|
|
64
|
+
return { ...acc, [key]: nestedObject };
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(propertyValue)) {
|
|
67
|
+
const nestedArray = this.snakeCasePropertyNameFromArrayIfPresent(propertyValue);
|
|
68
|
+
return { ...acc, [key]: nestedArray };
|
|
69
|
+
}
|
|
70
|
+
return { ...acc, [StringExtensions_1.StringExtensions.snakeCase(key)]: propertyValue };
|
|
71
|
+
}, {});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.SnakeCasePropertyNameCodec = SnakeCasePropertyNameCodec;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnakeCasePropertyNameCodec.unit.test.d.ts","sourceRoot":"","sources":["../../src/codec/SnakeCasePropertyNameCodec.unit.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const SnakeCasePropertyNameCodec_1 = require("./SnakeCasePropertyNameCodec");
|
|
4
|
+
const testSnakeCasePropertyNameCodec = SnakeCasePropertyNameCodec_1.SnakeCasePropertyNameCodec.instance;
|
|
5
|
+
describe('SnakeCasePropertyNameCodec', () => {
|
|
6
|
+
test('should snake case all properties names', () => {
|
|
7
|
+
const value = {
|
|
8
|
+
firstName: 'blah',
|
|
9
|
+
LastName: null,
|
|
10
|
+
addresses: [
|
|
11
|
+
{
|
|
12
|
+
street: 'blah street',
|
|
13
|
+
number: 123,
|
|
14
|
+
city: {
|
|
15
|
+
name: 'London',
|
|
16
|
+
province: null,
|
|
17
|
+
state: null,
|
|
18
|
+
},
|
|
19
|
+
notes_id: 'blah blah blah',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
street: 'blah blah street',
|
|
23
|
+
number: 321,
|
|
24
|
+
city: {
|
|
25
|
+
name: 'New York',
|
|
26
|
+
province: null,
|
|
27
|
+
state: 'NY',
|
|
28
|
+
},
|
|
29
|
+
notesId: null,
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
phone: {
|
|
33
|
+
Area_Code: null,
|
|
34
|
+
TelephoneNumber: 1234567,
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const actualValue = testSnakeCasePropertyNameCodec.encode(value);
|
|
38
|
+
const expectedValue = {
|
|
39
|
+
first_name: 'blah',
|
|
40
|
+
last_name: null,
|
|
41
|
+
addresses: [
|
|
42
|
+
{
|
|
43
|
+
street: 'blah street',
|
|
44
|
+
number: 123,
|
|
45
|
+
city: {
|
|
46
|
+
name: 'London',
|
|
47
|
+
province: null,
|
|
48
|
+
state: null,
|
|
49
|
+
},
|
|
50
|
+
notes_id: 'blah blah blah',
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
street: 'blah blah street',
|
|
54
|
+
number: 321,
|
|
55
|
+
city: {
|
|
56
|
+
name: 'New York',
|
|
57
|
+
province: null,
|
|
58
|
+
state: 'NY',
|
|
59
|
+
},
|
|
60
|
+
notes_id: null,
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
phone: {
|
|
64
|
+
area_code: null,
|
|
65
|
+
telephone_number: 1234567,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
expect(actualValue).toEqual(expectedValue);
|
|
69
|
+
});
|
|
70
|
+
});
|
package/dist/http/Http.d.ts
CHANGED
|
@@ -22,11 +22,19 @@ export declare const MultipartHttpRequestBody: {
|
|
|
22
22
|
create: (value: unknown, fileStorage: FileStorage) => TE.TaskEither<Error, MultipartHttpRequestBody>;
|
|
23
23
|
};
|
|
24
24
|
export type HttpRequestBody = RegularHttpRequestBody | MultipartHttpRequestBody;
|
|
25
|
+
export type HttpCertificate = {
|
|
26
|
+
cert: string;
|
|
27
|
+
key: string;
|
|
28
|
+
};
|
|
29
|
+
export type HttpAgent = {
|
|
30
|
+
certificate: O.Option<HttpCertificate>;
|
|
31
|
+
};
|
|
25
32
|
export type HttpRequest = {
|
|
26
33
|
headers: HttpHeaders;
|
|
27
34
|
pathParams: Record<string, string>;
|
|
28
35
|
queryString: HttpQueryString;
|
|
29
36
|
body: HttpRequestBody;
|
|
37
|
+
agent: O.Option<HttpAgent>;
|
|
30
38
|
};
|
|
31
39
|
export type HttpResponse = {
|
|
32
40
|
statusCode: number;
|
|
@@ -57,6 +65,10 @@ export declare enum HttpHeader {
|
|
|
57
65
|
ContentLength = "Content-Length",
|
|
58
66
|
ContentDisposition = "Content-Disposition"
|
|
59
67
|
}
|
|
68
|
+
export interface HttpRequestInterface {
|
|
69
|
+
create: (httpRequest: Partial<HttpRequest>) => HttpRequest;
|
|
70
|
+
}
|
|
71
|
+
export declare const HttpRequest: HttpRequestInterface;
|
|
60
72
|
export interface HttpHeadersInterface {
|
|
61
73
|
get: (headers: HttpHeaders, name: string) => O.Option<HttpHeaderValue>;
|
|
62
74
|
extractBearerToken: (headers: HttpHeaders) => O.Option<string>;
|
package/dist/http/Http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Http.d.ts","sourceRoot":"","sources":["../../src/http/Http.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,CAAC,MAAM,kBAAkB,CAAC;AACtC,OAAO,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAG3C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,OAAO,EAAE,IAAI,EAAkB,WAAW,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,gCAAgC,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAgB3D,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;AAEhD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,eAAe,CAAC,CAAC;AAE5E,MAAM,MAAM,0BAA0B,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEnE,MAAM,MAAM,oBAAo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eAAO,MAAM,WAAW,EAAE,oBAyIzB,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,MAAM,CACxD,mBAAmB,EACnB,eAAe,CAIf,CAAC;AAEF,eAAO,MAAM,eAAe,SACrB,eAAe,qCAEkC,CAAC"}
|
package/dist/http/Http.js
CHANGED
|
@@ -23,10 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.isMultiPartBody = exports.serializationFormatToHttpContentType = exports.HttpHeaders = exports.HttpHeader = exports.HttpContentType = exports.HttpMethod = exports.MultipartHttpRequestBody = void 0;
|
|
26
|
+
exports.isMultiPartBody = exports.serializationFormatToHttpContentType = exports.HttpHeaders = exports.HttpRequest = exports.HttpHeader = exports.HttpContentType = exports.HttpMethod = exports.MultipartHttpRequestBody = void 0;
|
|
27
27
|
const O = __importStar(require("fp-ts/lib/Option"));
|
|
28
28
|
const TE = __importStar(require("fp-ts/lib/TaskEither"));
|
|
29
29
|
const function_1 = require("fp-ts/lib/function");
|
|
30
|
+
const stream_1 = require("stream");
|
|
30
31
|
const _ = __importStar(require("lodash"));
|
|
31
32
|
const File_1 = require("../file/File");
|
|
32
33
|
const Serialization_1 = require("../serialization/Serialization");
|
|
@@ -91,6 +92,16 @@ var HttpHeader;
|
|
|
91
92
|
HttpHeader["ContentLength"] = "Content-Length";
|
|
92
93
|
HttpHeader["ContentDisposition"] = "Content-Disposition";
|
|
93
94
|
})(HttpHeader || (exports.HttpHeader = HttpHeader = {}));
|
|
95
|
+
exports.HttpRequest = {
|
|
96
|
+
create: (httpRequest) => ({
|
|
97
|
+
headers: {},
|
|
98
|
+
pathParams: {},
|
|
99
|
+
queryString: {},
|
|
100
|
+
body: stream_1.Readable.from(''),
|
|
101
|
+
agent: O.none,
|
|
102
|
+
...httpRequest,
|
|
103
|
+
}),
|
|
104
|
+
};
|
|
94
105
|
exports.HttpHeaders = {
|
|
95
106
|
get: (headers, name) => getHeader(headers, name),
|
|
96
107
|
extractBearerToken: (headers) => (0, function_1.pipe)(getHeader(headers, HttpHeader.Authorization), O.chain((header) => header.toLowerCase().startsWith('bearer ')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HttpClient.abstract.test.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.abstract.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"HttpClient.abstract.test.d.ts","sourceRoot":"","sources":["../../src/http/HttpClient.abstract.test.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAO1C,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,QA2sBpD"}
|
|
@@ -28,11 +28,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.httpClientTest = void 0;
|
|
30
30
|
const E = __importStar(require("fp-ts/Either"));
|
|
31
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
31
32
|
const stream_1 = require("stream");
|
|
33
|
+
const selfsigned_1 = __importDefault(require("selfsigned"));
|
|
32
34
|
const function_1 = require("fp-ts/function");
|
|
33
35
|
const t = __importStar(require("io-ts"));
|
|
34
36
|
const td = __importStar(require("io-ts-types"));
|
|
35
37
|
const http_1 = require("http");
|
|
38
|
+
const https_1 = require("https");
|
|
36
39
|
const util_1 = require("util");
|
|
37
40
|
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
38
41
|
const formidable_1 = __importDefault(require("formidable"));
|
|
@@ -201,12 +204,28 @@ function httpClientTest(httpClient) {
|
|
|
201
204
|
};
|
|
202
205
|
const host = 'localhost';
|
|
203
206
|
const port = 8000; // TODO: Get random port
|
|
207
|
+
const httpsPort = 9001;
|
|
204
208
|
const baseUrl = `http://${host}:${port}`;
|
|
209
|
+
const httpsServerUrl = `https://${host}:${httpsPort}`;
|
|
210
|
+
// Generate self-signed certificates for Https server, override type as it didn't include client certs
|
|
211
|
+
const certs = selfsigned_1.default.generate([], {
|
|
212
|
+
clientCertificate: true,
|
|
213
|
+
clientCertificateCN: 'client',
|
|
214
|
+
extensions: [{ name: 'basicConstraints', cA: true }],
|
|
215
|
+
});
|
|
205
216
|
const server = (0, http_1.createServer)(requestListener);
|
|
217
|
+
const httpsServer = (0, https_1.createServer)({
|
|
218
|
+
key: certs.private,
|
|
219
|
+
cert: certs.cert,
|
|
220
|
+
requestCert: true,
|
|
221
|
+
rejectUnauthorized: true,
|
|
222
|
+
ca: [certs.clientcert],
|
|
223
|
+
}, requestListener);
|
|
206
224
|
describe('HttpClient Test', () => {
|
|
207
225
|
beforeAll(async () => {
|
|
208
226
|
await new Promise((resolve) => {
|
|
209
227
|
server.listen(port, host, resolve);
|
|
228
|
+
httpsServer.listen(httpsPort, host);
|
|
210
229
|
});
|
|
211
230
|
});
|
|
212
231
|
afterAll(async () => {
|
|
@@ -220,14 +239,45 @@ function httpClientTest(httpClient) {
|
|
|
220
239
|
}
|
|
221
240
|
});
|
|
222
241
|
});
|
|
242
|
+
await new Promise((resolve, reject) => {
|
|
243
|
+
httpsServer.close((error) => {
|
|
244
|
+
if (error) {
|
|
245
|
+
reject(error);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
resolve();
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
});
|
|
223
252
|
});
|
|
224
253
|
test('should send a GET request', async () => {
|
|
225
|
-
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
254
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
226
255
|
headers: { 'x-custom-header': 'customVal' },
|
|
227
256
|
pathParams: {},
|
|
228
257
|
queryString: {},
|
|
229
258
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
230
|
-
})();
|
|
259
|
+
}))();
|
|
260
|
+
const testValue = {
|
|
261
|
+
strField: 'customVal',
|
|
262
|
+
intField: 123,
|
|
263
|
+
};
|
|
264
|
+
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testResponseCodec.decode(encoded)))));
|
|
265
|
+
const resultE = await result();
|
|
266
|
+
expect(resultE).toStrictEqual(E.right(testValue));
|
|
267
|
+
});
|
|
268
|
+
test('should send a GET request with a certificate', async () => {
|
|
269
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, httpsServerUrl, Http_1.HttpRequest.create({
|
|
270
|
+
headers: { 'x-custom-header': 'customVal' },
|
|
271
|
+
pathParams: {},
|
|
272
|
+
queryString: {},
|
|
273
|
+
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
274
|
+
agent: O.some({
|
|
275
|
+
certificate: O.some({
|
|
276
|
+
key: certs.clientprivate,
|
|
277
|
+
cert: certs.clientcert,
|
|
278
|
+
}),
|
|
279
|
+
}),
|
|
280
|
+
}))();
|
|
231
281
|
const testValue = {
|
|
232
282
|
strField: 'customVal',
|
|
233
283
|
intField: 123,
|
|
@@ -240,7 +290,7 @@ function httpClientTest(httpClient) {
|
|
|
240
290
|
const testInput = {
|
|
241
291
|
inputField: 321,
|
|
242
292
|
};
|
|
243
|
-
const response = await (0, function_1.pipe)((0, Task_1.createTaskEitherFromEither)(E.right(testInputCodec.encode(testInput))), TE.map((encoded) => serialization.serialize(encoded)), TE.chain((serializedInput) => httpClient.execute(Http_1.HttpMethod.Post, baseUrl, {
|
|
293
|
+
const response = await (0, function_1.pipe)((0, Task_1.createTaskEitherFromEither)(E.right(testInputCodec.encode(testInput))), TE.map((encoded) => serialization.serialize(encoded)), TE.chain((serializedInput) => httpClient.execute(Http_1.HttpMethod.Post, baseUrl, Http_1.HttpRequest.create({
|
|
244
294
|
headers: {
|
|
245
295
|
'x-custom-header': 'customVal',
|
|
246
296
|
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.Json,
|
|
@@ -248,7 +298,7 @@ function httpClientTest(httpClient) {
|
|
|
248
298
|
pathParams: {},
|
|
249
299
|
queryString: {},
|
|
250
300
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedInput),
|
|
251
|
-
})))();
|
|
301
|
+
}))))();
|
|
252
302
|
const testValue = {
|
|
253
303
|
strField: 'customVal',
|
|
254
304
|
intField: 321,
|
|
@@ -298,7 +348,7 @@ function httpClientTest(httpClient) {
|
|
|
298
348
|
},
|
|
299
349
|
},
|
|
300
350
|
};
|
|
301
|
-
const response = await httpClient.execute(Http_1.HttpMethod.Post, baseUrl, {
|
|
351
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Post, baseUrl, Http_1.HttpRequest.create({
|
|
302
352
|
headers: {
|
|
303
353
|
'x-custom-header': 'customVal',
|
|
304
354
|
'content-type': Http_1.HttpContentType.MultipartRequestBody,
|
|
@@ -306,7 +356,7 @@ function httpClientTest(httpClient) {
|
|
|
306
356
|
pathParams: {},
|
|
307
357
|
queryString: {},
|
|
308
358
|
body: testInput,
|
|
309
|
-
})();
|
|
359
|
+
}))();
|
|
310
360
|
const result = (0, function_1.pipe)(response, TE.fromEither, TE.chain((httpResponse) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(httpResponse.body)), TE.match((error) => E.left(error), (buffer) => (0, function_1.pipe)(serialization.deserialize(buffer), E.chain((encoded) => testMultiPartBodyTypeCodec.decode(encoded)))));
|
|
311
361
|
const resultE = await result();
|
|
312
362
|
expect(resultE).toEqual(E.right(expect.objectContaining({
|
|
@@ -330,14 +380,14 @@ function httpClientTest(httpClient) {
|
|
|
330
380
|
})));
|
|
331
381
|
});
|
|
332
382
|
test('should send a POST request with a formUrlEncoded body', async () => {
|
|
333
|
-
const response = await (0, function_1.pipe)((0, Task_1.createTaskEitherFromEither)(E.right(testInputFormUrlEncodedCodec.encode(testInputFormUrlEncoded))), TE.map((encoded) => formUrlEncodedSerialization.serialize(encoded)), TE.chain((serializedInput) => httpClient.execute(Http_1.HttpMethod.Post, baseUrl, {
|
|
383
|
+
const response = await (0, function_1.pipe)((0, Task_1.createTaskEitherFromEither)(E.right(testInputFormUrlEncodedCodec.encode(testInputFormUrlEncoded))), TE.map((encoded) => formUrlEncodedSerialization.serialize(encoded)), TE.chain((serializedInput) => httpClient.execute(Http_1.HttpMethod.Post, baseUrl, Http_1.HttpRequest.create({
|
|
334
384
|
headers: {
|
|
335
385
|
[Http_1.HttpHeader.ContentType]: Http_1.HttpContentType.FormUrlEncoded,
|
|
336
386
|
},
|
|
337
387
|
pathParams: {},
|
|
338
388
|
queryString: {},
|
|
339
389
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(serializedInput),
|
|
340
|
-
})))();
|
|
390
|
+
}))))();
|
|
341
391
|
const testValue = {
|
|
342
392
|
strField: 'customVal',
|
|
343
393
|
intField: 1,
|
|
@@ -347,12 +397,12 @@ function httpClientTest(httpClient) {
|
|
|
347
397
|
expect(resultE).toStrictEqual(E.right(testValue));
|
|
348
398
|
});
|
|
349
399
|
test('should parse an internal error response', async () => {
|
|
350
|
-
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
400
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
351
401
|
headers: { error: '500' },
|
|
352
402
|
pathParams: {},
|
|
353
403
|
queryString: {},
|
|
354
404
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
355
|
-
})();
|
|
405
|
+
}))();
|
|
356
406
|
const testErrorResponse = {
|
|
357
407
|
message: 'some error message 500',
|
|
358
408
|
};
|
|
@@ -364,12 +414,12 @@ function httpClientTest(httpClient) {
|
|
|
364
414
|
expect(responseBodyE).toStrictEqual(E.right(serialization.serialize(testErrorResponseCodec.encode(testErrorResponse))));
|
|
365
415
|
});
|
|
366
416
|
test('should parse a not found error response', async () => {
|
|
367
|
-
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, {
|
|
417
|
+
const response = await httpClient.execute(Http_1.HttpMethod.Get, baseUrl, Http_1.HttpRequest.create({
|
|
368
418
|
headers: { error: '404' },
|
|
369
419
|
pathParams: {},
|
|
370
420
|
queryString: {},
|
|
371
421
|
body: BufferExtensions_1.BufferExtensions.arrayBufferToReadable(new ArrayBuffer(0)),
|
|
372
|
-
})();
|
|
422
|
+
}))();
|
|
373
423
|
const testErrorResponse = {
|
|
374
424
|
message: 'some error message 404',
|
|
375
425
|
};
|
|
@@ -2,6 +2,7 @@ export interface StringExtensionsInterface {
|
|
|
2
2
|
pascalCase: (str: string) => string;
|
|
3
3
|
titleCase: (str: string) => string;
|
|
4
4
|
camelCase: (str: string) => string;
|
|
5
|
+
snakeCase: (str: string) => string;
|
|
5
6
|
}
|
|
6
7
|
export declare const StringExtensions: StringExtensionsInterface;
|
|
7
8
|
//# sourceMappingURL=StringExtensions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StringExtensions.d.ts","sourceRoot":"","sources":["../../src/string/StringExtensions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StringExtensions.d.ts","sourceRoot":"","sources":["../../src/string/StringExtensions.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,yBAAyB;IACzC,UAAU,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACnC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IACnC,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC;AAED,eAAO,MAAM,gBAAgB,EAAE,yBAM9B,CAAC"}
|
|
@@ -6,4 +6,5 @@ exports.StringExtensions = {
|
|
|
6
6
|
pascalCase: (str) => (0, lodash_1.upperFirst)((0, lodash_1.camelCase)(str)),
|
|
7
7
|
titleCase: (value) => (0, lodash_1.capitalize)((0, lodash_1.startCase)(value).replace(/_|-/g, ' ')),
|
|
8
8
|
camelCase: (str) => (0, lodash_1.camelCase)(str),
|
|
9
|
+
snakeCase: (str) => (0, lodash_1.snakeCase)(str),
|
|
9
10
|
};
|