@lokalise/node-core 2.0.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/LICENSE +190 -0
- package/README.md +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/src/http/httpClient.d.ts +42 -0
- package/dist/src/http/httpClient.js +162 -0
- package/dist/src/http/httpClient.js.map +1 -0
- package/dist/src/http/httpClient.spec.d.ts +1 -0
- package/dist/src/http/httpClient.spec.js +290 -0
- package/dist/src/http/httpClient.spec.js.map +1 -0
- package/dist/src/http/mock-data/mockProduct1.json +12 -0
- package/dist/src/http/mock-data/mockProductsLimit3.json +38 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2023 Lokalise
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# node-core
|
|
2
|
+
|
|
3
|
+
Core libraries for Node.js backend services
|
|
4
|
+
|
|
5
|
+
See [docs](/docs) for instructions on how to use.
|
|
6
|
+
|
|
7
|
+
## Contributing
|
|
8
|
+
|
|
9
|
+
In order to make a new release, please follow these steps.
|
|
10
|
+
|
|
11
|
+
1. Make changes and open a pull request.
|
|
12
|
+
2. Apply proper labels to pull request;
|
|
13
|
+
|
|
14
|
+
- Add one of `major`, `minor` or `patch` according to [semver](https://semver.org/) to trigger a release.
|
|
15
|
+
- Or add `skip-release` label to avoid release when merging pull request.
|
|
16
|
+
|
|
17
|
+
3. Merge pull request.
|
|
18
|
+
4. Done.
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpClient = exports.sendPost = exports.sendGet = exports.sendPatch = exports.sendDelete = exports.sendPutBinary = exports.sendPut = void 0;
|
|
4
|
+
var httpClient_1 = require("./src/http/httpClient");
|
|
5
|
+
Object.defineProperty(exports, "sendPut", { enumerable: true, get: function () { return httpClient_1.sendPut; } });
|
|
6
|
+
Object.defineProperty(exports, "sendPutBinary", { enumerable: true, get: function () { return httpClient_1.sendPutBinary; } });
|
|
7
|
+
Object.defineProperty(exports, "sendDelete", { enumerable: true, get: function () { return httpClient_1.sendDelete; } });
|
|
8
|
+
Object.defineProperty(exports, "sendPatch", { enumerable: true, get: function () { return httpClient_1.sendPatch; } });
|
|
9
|
+
Object.defineProperty(exports, "sendGet", { enumerable: true, get: function () { return httpClient_1.sendGet; } });
|
|
10
|
+
Object.defineProperty(exports, "sendPost", { enumerable: true, get: function () { return httpClient_1.sendPost; } });
|
|
11
|
+
Object.defineProperty(exports, "httpClient", { enumerable: true, get: function () { return httpClient_1.httpClient; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,oDAQ8B;AAP5B,qGAAA,OAAO,OAAA;AACP,2GAAA,aAAa,OAAA;AACb,wGAAA,UAAU,OAAA;AACV,uGAAA,SAAS,OAAA;AACT,qGAAA,OAAO,OAAA;AACP,sGAAA,QAAQ,OAAA;AACR,wGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import type { Readable } from 'stream';
|
|
4
|
+
import type { FormData } from 'undici';
|
|
5
|
+
type RecordObject = Record<string, any>;
|
|
6
|
+
export type HttpRequestContext = {
|
|
7
|
+
reqId: string;
|
|
8
|
+
};
|
|
9
|
+
export type GetRequestOptions = {
|
|
10
|
+
headers?: RecordObject;
|
|
11
|
+
query?: RecordObject;
|
|
12
|
+
timeout?: number;
|
|
13
|
+
throwOnError?: boolean;
|
|
14
|
+
reqContext?: HttpRequestContext;
|
|
15
|
+
};
|
|
16
|
+
export type DeleteRequestOptions = GetRequestOptions;
|
|
17
|
+
export type RequestOptions = {
|
|
18
|
+
headers?: RecordObject;
|
|
19
|
+
query?: RecordObject;
|
|
20
|
+
timeout?: number;
|
|
21
|
+
throwOnError?: boolean;
|
|
22
|
+
reqContext?: HttpRequestContext;
|
|
23
|
+
};
|
|
24
|
+
export type Response<T> = {
|
|
25
|
+
body: T;
|
|
26
|
+
headers: RecordObject;
|
|
27
|
+
statusCode: number;
|
|
28
|
+
};
|
|
29
|
+
export declare function sendGet<T>(baseUrl: string, path: string, options?: GetRequestOptions): Promise<Response<T>>;
|
|
30
|
+
export declare function sendDelete<T>(baseUrl: string, path: string, options?: DeleteRequestOptions): Promise<Response<T>>;
|
|
31
|
+
export declare function sendPost<T>(baseUrl: string, path: string, body: RecordObject | undefined, options?: RequestOptions): Promise<Response<T>>;
|
|
32
|
+
export declare function sendPut<T>(baseUrl: string, path: string, body: RecordObject | undefined, options?: RequestOptions): Promise<Response<T>>;
|
|
33
|
+
export declare function sendPutBinary<T>(baseUrl: string, path: string, body: Buffer | Uint8Array | Readable | null | FormData, options?: RequestOptions): Promise<Response<T>>;
|
|
34
|
+
export declare function sendPatch<T>(baseUrl: string, path: string, body: RecordObject | undefined, options?: RequestOptions): Promise<Response<T>>;
|
|
35
|
+
export declare const httpClient: {
|
|
36
|
+
get: typeof sendGet;
|
|
37
|
+
post: typeof sendPost;
|
|
38
|
+
put: typeof sendPut;
|
|
39
|
+
patch: typeof sendPatch;
|
|
40
|
+
del: typeof sendDelete;
|
|
41
|
+
};
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.httpClient = exports.sendPatch = exports.sendPutBinary = exports.sendPut = exports.sendPost = exports.sendDelete = exports.sendGet = void 0;
|
|
4
|
+
const undici_1 = require("undici");
|
|
5
|
+
const defaultOptions = {
|
|
6
|
+
throwOnError: true,
|
|
7
|
+
timeout: 30000,
|
|
8
|
+
};
|
|
9
|
+
async function sendGet(baseUrl, path, options = defaultOptions) {
|
|
10
|
+
const url = resolveUrl(baseUrl, path);
|
|
11
|
+
const response = await (0, undici_1.request)(url, {
|
|
12
|
+
method: 'GET',
|
|
13
|
+
query: options.query,
|
|
14
|
+
headers: {
|
|
15
|
+
'x-request-id': options.reqContext?.reqId,
|
|
16
|
+
...options.headers,
|
|
17
|
+
},
|
|
18
|
+
bodyTimeout: options.timeout,
|
|
19
|
+
throwOnError: options.throwOnError,
|
|
20
|
+
});
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
22
|
+
const resolvedBody = await resolveBody(response);
|
|
23
|
+
return {
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
25
|
+
body: resolvedBody,
|
|
26
|
+
headers: response.headers,
|
|
27
|
+
statusCode: response.statusCode,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
exports.sendGet = sendGet;
|
|
31
|
+
async function sendDelete(baseUrl, path, options = defaultOptions) {
|
|
32
|
+
const url = resolveUrl(baseUrl, path);
|
|
33
|
+
const response = await (0, undici_1.request)(url, {
|
|
34
|
+
method: 'DELETE',
|
|
35
|
+
query: options.query,
|
|
36
|
+
headers: {
|
|
37
|
+
'x-request-id': options.reqContext?.reqId,
|
|
38
|
+
...options.headers,
|
|
39
|
+
},
|
|
40
|
+
bodyTimeout: options.timeout,
|
|
41
|
+
throwOnError: options.throwOnError,
|
|
42
|
+
});
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
44
|
+
const resolvedBody = await resolveBody(response);
|
|
45
|
+
return {
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
47
|
+
body: resolvedBody,
|
|
48
|
+
headers: response.headers,
|
|
49
|
+
statusCode: response.statusCode,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.sendDelete = sendDelete;
|
|
53
|
+
async function sendPost(baseUrl, path, body, options = defaultOptions) {
|
|
54
|
+
const url = resolveUrl(baseUrl, path);
|
|
55
|
+
const response = await (0, undici_1.request)(url, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
58
|
+
query: options.query,
|
|
59
|
+
headers: {
|
|
60
|
+
'x-request-id': options.reqContext?.reqId,
|
|
61
|
+
...options.headers,
|
|
62
|
+
},
|
|
63
|
+
bodyTimeout: options.timeout,
|
|
64
|
+
throwOnError: options.throwOnError,
|
|
65
|
+
});
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
67
|
+
const resolvedBody = await resolveBody(response);
|
|
68
|
+
return {
|
|
69
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
70
|
+
body: resolvedBody,
|
|
71
|
+
headers: response.headers,
|
|
72
|
+
statusCode: response.statusCode,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
exports.sendPost = sendPost;
|
|
76
|
+
async function sendPut(baseUrl, path, body, options = defaultOptions) {
|
|
77
|
+
const url = resolveUrl(baseUrl, path);
|
|
78
|
+
const response = await (0, undici_1.request)(url, {
|
|
79
|
+
method: 'PUT',
|
|
80
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
81
|
+
query: options.query,
|
|
82
|
+
headers: {
|
|
83
|
+
'x-request-id': options.reqContext?.reqId,
|
|
84
|
+
...options.headers,
|
|
85
|
+
},
|
|
86
|
+
bodyTimeout: options.timeout,
|
|
87
|
+
throwOnError: options.throwOnError,
|
|
88
|
+
});
|
|
89
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
90
|
+
const resolvedBody = await resolveBody(response);
|
|
91
|
+
return {
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
93
|
+
body: resolvedBody,
|
|
94
|
+
headers: response.headers,
|
|
95
|
+
statusCode: response.statusCode,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
exports.sendPut = sendPut;
|
|
99
|
+
async function sendPutBinary(baseUrl, path, body, options = defaultOptions) {
|
|
100
|
+
const url = resolveUrl(baseUrl, path);
|
|
101
|
+
const response = await (0, undici_1.request)(url, {
|
|
102
|
+
method: 'PUT',
|
|
103
|
+
body,
|
|
104
|
+
query: options.query,
|
|
105
|
+
headers: {
|
|
106
|
+
'x-request-id': options.reqContext?.reqId,
|
|
107
|
+
...options.headers,
|
|
108
|
+
},
|
|
109
|
+
bodyTimeout: options.timeout,
|
|
110
|
+
throwOnError: options.throwOnError,
|
|
111
|
+
});
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
113
|
+
const resolvedBody = await resolveBody(response);
|
|
114
|
+
return {
|
|
115
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
116
|
+
body: resolvedBody,
|
|
117
|
+
headers: response.headers,
|
|
118
|
+
statusCode: response.statusCode,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
exports.sendPutBinary = sendPutBinary;
|
|
122
|
+
async function sendPatch(baseUrl, path, body, options = defaultOptions) {
|
|
123
|
+
const url = resolveUrl(baseUrl, path);
|
|
124
|
+
const response = await (0, undici_1.request)(url, {
|
|
125
|
+
method: 'PATCH',
|
|
126
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
127
|
+
query: options.query,
|
|
128
|
+
headers: {
|
|
129
|
+
'x-request-id': options.reqContext?.reqId,
|
|
130
|
+
...options.headers,
|
|
131
|
+
},
|
|
132
|
+
bodyTimeout: options.timeout,
|
|
133
|
+
throwOnError: options.throwOnError,
|
|
134
|
+
});
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
136
|
+
const resolvedBody = await resolveBody(response);
|
|
137
|
+
return {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
139
|
+
body: resolvedBody,
|
|
140
|
+
headers: response.headers,
|
|
141
|
+
statusCode: response.statusCode,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
exports.sendPatch = sendPatch;
|
|
145
|
+
async function resolveBody(response) {
|
|
146
|
+
const contentType = response.headers['content-type'];
|
|
147
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
148
|
+
return !contentType || contentType?.startsWith('application/json')
|
|
149
|
+
? await response.body.json()
|
|
150
|
+
: await response.body.text();
|
|
151
|
+
}
|
|
152
|
+
function resolveUrl(baseUrl, path) {
|
|
153
|
+
return new URL(path, baseUrl).href;
|
|
154
|
+
}
|
|
155
|
+
exports.httpClient = {
|
|
156
|
+
get: sendGet,
|
|
157
|
+
post: sendPost,
|
|
158
|
+
put: sendPut,
|
|
159
|
+
patch: sendPatch,
|
|
160
|
+
del: sendDelete,
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=httpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.js","sourceRoot":"","sources":["../../../src/http/httpClient.ts"],"names":[],"mappings":";;;AAEA,mCAAgC;AA4BhC,MAAM,cAAc,GAAsB;IACxC,YAAY,EAAE,IAAI;IAClB,OAAO,EAAE,KAAK;CACf,CAAA;AAQM,KAAK,UAAU,OAAO,CAC3B,OAAe,EACf,IAAY,EACZ,UAA6B,cAAc;IAE3C,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IACrC,MAAM,QAAQ,GAAG,MAAM,IAAA,gBAAO,EAAC,GAAG,EAAE;QAClC,MAAM,EAAE,KAAK;QACb,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,OAAO,EAAE;YACP,cAAc,EAAE,OAAO,CAAC,UAAU,EAAE,KAAK;YACzC,GAAG,OAAO,CAAC,OAAO;SACnB;QACD,WAAW,EAAE,OAAO,CAAC,OAAO;QAC5B,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,CAAC,CAAA;IAEF,mEAAmE;IACnE,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAA;IAEhD,OAAO;QACL,mEAAmE;QACnE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C,CAAA;IAEF,mEAAmE;IACnE,MAAM,YAAY,GAAG,MAAM,WAAW,CAAC,QAAQ,CAAC,CAAA;IAEhD,OAAO;QACL,mEAAmE;QACnE,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,QAAQ,CAAC,OAAO;QACzB,UAAU,EAAE,QAAQ,CAAC,UAAU;KAChC,CAAA;AACH,CAAC;AA5BD,8BA4BC;AAED,KAAK,UAAU,WAAW,CAAC,QAAiC;IAC1D,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;IACpD,+DAA+D;IAC/D,OAAO,CAAC,WAAW,IAAI,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC;QAChE,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE;QAC5B,CAAC,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;AAChC,CAAC;AAED,SAAS,UAAU,CAAC,OAAe,EAAE,IAAY;IAC/C,OAAO,IAAI,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAA;AACpC,CAAC;AAEY,QAAA,UAAU,GAAG;IACxB,GAAG,EAAE,OAAO;IACZ,IAAI,EAAE,QAAQ;IACd,GAAG,EAAE,OAAO;IACZ,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,UAAU;CAChB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const undici_1 = require("undici");
|
|
5
|
+
const httpClient_1 = require("./httpClient");
|
|
6
|
+
const mockProduct1_json_1 = tslib_1.__importDefault(require("./mock-data/mockProduct1.json"));
|
|
7
|
+
const mockProductsLimit3_json_1 = tslib_1.__importDefault(require("./mock-data/mockProductsLimit3.json"));
|
|
8
|
+
const JSON_HEADERS = {
|
|
9
|
+
'content-type': 'application/json',
|
|
10
|
+
};
|
|
11
|
+
const TEXT_HEADERS = {
|
|
12
|
+
'content-type': 'text/plain',
|
|
13
|
+
};
|
|
14
|
+
describe('httpClient', () => {
|
|
15
|
+
let mockAgent;
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
mockAgent = new undici_1.MockAgent();
|
|
18
|
+
mockAgent.disableNetConnect();
|
|
19
|
+
(0, undici_1.setGlobalDispatcher)(mockAgent);
|
|
20
|
+
});
|
|
21
|
+
describe('GET', () => {
|
|
22
|
+
it('GET without queryParams', async () => {
|
|
23
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
24
|
+
client
|
|
25
|
+
.intercept({
|
|
26
|
+
path: '/products/1',
|
|
27
|
+
method: 'GET',
|
|
28
|
+
})
|
|
29
|
+
.reply(200, mockProduct1_json_1.default, { headers: JSON_HEADERS });
|
|
30
|
+
const result = await (0, httpClient_1.sendGet)('https://fakestoreapi.com', 'products/1');
|
|
31
|
+
expect(result.body).toEqual(mockProduct1_json_1.default);
|
|
32
|
+
});
|
|
33
|
+
it('GET returning text', async () => {
|
|
34
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
35
|
+
client
|
|
36
|
+
.intercept({
|
|
37
|
+
path: '/products/1',
|
|
38
|
+
method: 'GET',
|
|
39
|
+
})
|
|
40
|
+
.reply(200, 'just text', {
|
|
41
|
+
headers: TEXT_HEADERS,
|
|
42
|
+
});
|
|
43
|
+
const result = await (0, httpClient_1.sendGet)('https://fakestoreapi.com', 'products/1');
|
|
44
|
+
expect(result.body).toBe('just text');
|
|
45
|
+
});
|
|
46
|
+
it('GET with queryParams', async () => {
|
|
47
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
48
|
+
const query = {
|
|
49
|
+
limit: 3,
|
|
50
|
+
};
|
|
51
|
+
client
|
|
52
|
+
.intercept({
|
|
53
|
+
path: '/products',
|
|
54
|
+
method: 'GET',
|
|
55
|
+
query,
|
|
56
|
+
})
|
|
57
|
+
.reply(200, mockProductsLimit3_json_1.default, { headers: JSON_HEADERS });
|
|
58
|
+
const result = await (0, httpClient_1.sendGet)('https://fakestoreapi.com', 'products', {
|
|
59
|
+
query,
|
|
60
|
+
});
|
|
61
|
+
expect(result.body).toEqual(mockProductsLimit3_json_1.default);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe('DELETE', () => {
|
|
65
|
+
it('DELETE without queryParams', async () => {
|
|
66
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
67
|
+
client
|
|
68
|
+
.intercept({
|
|
69
|
+
path: '/products/1',
|
|
70
|
+
method: 'DELETE',
|
|
71
|
+
})
|
|
72
|
+
.reply(204, undefined, { headers: TEXT_HEADERS });
|
|
73
|
+
const result = await (0, httpClient_1.sendDelete)('https://fakestoreapi.com', 'products/1');
|
|
74
|
+
expect(result.statusCode).toBe(204);
|
|
75
|
+
expect(result.body).toBe('');
|
|
76
|
+
});
|
|
77
|
+
it('DELETE with queryParams', async () => {
|
|
78
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
79
|
+
const query = {
|
|
80
|
+
limit: 3,
|
|
81
|
+
};
|
|
82
|
+
client
|
|
83
|
+
.intercept({
|
|
84
|
+
path: '/products',
|
|
85
|
+
method: 'DELETE',
|
|
86
|
+
query,
|
|
87
|
+
})
|
|
88
|
+
.reply(204, undefined, { headers: TEXT_HEADERS });
|
|
89
|
+
const result = await (0, httpClient_1.sendDelete)('https://fakestoreapi.com', 'products', {
|
|
90
|
+
query,
|
|
91
|
+
});
|
|
92
|
+
expect(result.statusCode).toBe(204);
|
|
93
|
+
expect(result.body).toBe('');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
describe('POST', () => {
|
|
97
|
+
it('POST without queryParams', async () => {
|
|
98
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
99
|
+
client
|
|
100
|
+
.intercept({
|
|
101
|
+
path: '/products',
|
|
102
|
+
method: 'POST',
|
|
103
|
+
})
|
|
104
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
105
|
+
const result = await (0, httpClient_1.sendPost)('https://fakestoreapi.com', 'products', mockProduct1_json_1.default);
|
|
106
|
+
expect(result.body).toEqual({ id: 21 });
|
|
107
|
+
});
|
|
108
|
+
it('POST without body', async () => {
|
|
109
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
110
|
+
client
|
|
111
|
+
.intercept({
|
|
112
|
+
path: '/products',
|
|
113
|
+
method: 'POST',
|
|
114
|
+
})
|
|
115
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
116
|
+
const result = await (0, httpClient_1.sendPost)('https://fakestoreapi.com', 'products', undefined);
|
|
117
|
+
expect(result.body).toEqual({ id: 21 });
|
|
118
|
+
});
|
|
119
|
+
it('POST with queryParams', async () => {
|
|
120
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
121
|
+
const query = {
|
|
122
|
+
limit: 3,
|
|
123
|
+
};
|
|
124
|
+
client
|
|
125
|
+
.intercept({
|
|
126
|
+
path: '/products',
|
|
127
|
+
method: 'POST',
|
|
128
|
+
query,
|
|
129
|
+
})
|
|
130
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
131
|
+
const result = await (0, httpClient_1.sendPost)('https://fakestoreapi.com', 'products', mockProduct1_json_1.default, {
|
|
132
|
+
query,
|
|
133
|
+
});
|
|
134
|
+
expect(result.body).toEqual({ id: 21 });
|
|
135
|
+
});
|
|
136
|
+
it('POST that returns 400 throws an error', async () => {
|
|
137
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
138
|
+
client
|
|
139
|
+
.intercept({
|
|
140
|
+
path: '/products',
|
|
141
|
+
method: 'POST',
|
|
142
|
+
})
|
|
143
|
+
.reply(400, { errorCode: 'err' }, { headers: JSON_HEADERS });
|
|
144
|
+
await expect((0, httpClient_1.sendPost)('https://fakestoreapi.com', 'products', mockProduct1_json_1.default)).rejects.toThrow('Response status code 400: Bad Request');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
describe('PUT', () => {
|
|
148
|
+
it('PUT without queryParams', async () => {
|
|
149
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
150
|
+
client
|
|
151
|
+
.intercept({
|
|
152
|
+
path: '/products/1',
|
|
153
|
+
method: 'PUT',
|
|
154
|
+
})
|
|
155
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
156
|
+
const result = await (0, httpClient_1.sendPut)('https://fakestoreapi.com', 'products/1', mockProduct1_json_1.default);
|
|
157
|
+
expect(result.body).toEqual({ id: 21 });
|
|
158
|
+
});
|
|
159
|
+
it('PUT without body', async () => {
|
|
160
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
161
|
+
client
|
|
162
|
+
.intercept({
|
|
163
|
+
path: '/products/1',
|
|
164
|
+
method: 'PUT',
|
|
165
|
+
})
|
|
166
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
167
|
+
const result = await (0, httpClient_1.sendPut)('https://fakestoreapi.com', 'products/1', undefined);
|
|
168
|
+
expect(result.body).toEqual({ id: 21 });
|
|
169
|
+
});
|
|
170
|
+
it('PUT with queryParams', async () => {
|
|
171
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
172
|
+
const query = {
|
|
173
|
+
limit: 3,
|
|
174
|
+
};
|
|
175
|
+
client
|
|
176
|
+
.intercept({
|
|
177
|
+
path: '/products/1',
|
|
178
|
+
method: 'PUT',
|
|
179
|
+
query,
|
|
180
|
+
})
|
|
181
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
182
|
+
const result = await (0, httpClient_1.sendPut)('https://fakestoreapi.com', 'products/1', mockProduct1_json_1.default, {
|
|
183
|
+
query,
|
|
184
|
+
});
|
|
185
|
+
expect(result.body).toEqual({ id: 21 });
|
|
186
|
+
});
|
|
187
|
+
it('PUT that returns 400 throws an error', async () => {
|
|
188
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
189
|
+
client
|
|
190
|
+
.intercept({
|
|
191
|
+
path: '/products/1',
|
|
192
|
+
method: 'PUT',
|
|
193
|
+
})
|
|
194
|
+
.reply(400, { errorCode: 'err' }, { headers: JSON_HEADERS });
|
|
195
|
+
await expect((0, httpClient_1.sendPut)('https://fakestoreapi.com', 'products/1', mockProduct1_json_1.default)).rejects.toThrow('Response status code 400: Bad Request');
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
describe('PUT binary', () => {
|
|
199
|
+
it('PUT without queryParams', async () => {
|
|
200
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
201
|
+
client
|
|
202
|
+
.intercept({
|
|
203
|
+
path: '/products/1',
|
|
204
|
+
method: 'PUT',
|
|
205
|
+
})
|
|
206
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
207
|
+
const result = await (0, httpClient_1.sendPutBinary)('https://fakestoreapi.com', 'products/1', Buffer.from('text'));
|
|
208
|
+
expect(result.body).toEqual({ id: 21 });
|
|
209
|
+
});
|
|
210
|
+
it('PUT with queryParams', async () => {
|
|
211
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
212
|
+
const query = {
|
|
213
|
+
limit: 3,
|
|
214
|
+
};
|
|
215
|
+
client
|
|
216
|
+
.intercept({
|
|
217
|
+
path: '/products/1',
|
|
218
|
+
method: 'PUT',
|
|
219
|
+
query,
|
|
220
|
+
})
|
|
221
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
222
|
+
const result = await (0, httpClient_1.sendPutBinary)('https://fakestoreapi.com', 'products/1', Buffer.from('text'), {
|
|
223
|
+
query,
|
|
224
|
+
});
|
|
225
|
+
expect(result.body).toEqual({ id: 21 });
|
|
226
|
+
});
|
|
227
|
+
it('PUT that returns 400 throws an error', async () => {
|
|
228
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
229
|
+
client
|
|
230
|
+
.intercept({
|
|
231
|
+
path: '/products/1',
|
|
232
|
+
method: 'PUT',
|
|
233
|
+
})
|
|
234
|
+
.reply(400, { errorCode: 'err' }, { headers: JSON_HEADERS });
|
|
235
|
+
await expect((0, httpClient_1.sendPutBinary)('https://fakestoreapi.com', 'products/1', Buffer.from('text'))).rejects.toThrow('Response status code 400: Bad Request');
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
describe('PATCH', () => {
|
|
239
|
+
it('PATCH without queryParams', async () => {
|
|
240
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
241
|
+
client
|
|
242
|
+
.intercept({
|
|
243
|
+
path: '/products/1',
|
|
244
|
+
method: 'PATCH',
|
|
245
|
+
})
|
|
246
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
247
|
+
const result = await (0, httpClient_1.sendPatch)('https://fakestoreapi.com', 'products/1', mockProduct1_json_1.default);
|
|
248
|
+
expect(result.body).toEqual({ id: 21 });
|
|
249
|
+
});
|
|
250
|
+
it('PATCH without body', async () => {
|
|
251
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
252
|
+
client
|
|
253
|
+
.intercept({
|
|
254
|
+
path: '/products/1',
|
|
255
|
+
method: 'PATCH',
|
|
256
|
+
})
|
|
257
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
258
|
+
const result = await (0, httpClient_1.sendPatch)('https://fakestoreapi.com', 'products/1', undefined);
|
|
259
|
+
expect(result.body).toEqual({ id: 21 });
|
|
260
|
+
});
|
|
261
|
+
it('PATCH with queryParams', async () => {
|
|
262
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
263
|
+
const query = {
|
|
264
|
+
limit: 3,
|
|
265
|
+
};
|
|
266
|
+
client
|
|
267
|
+
.intercept({
|
|
268
|
+
path: '/products/1',
|
|
269
|
+
method: 'PATCH',
|
|
270
|
+
query,
|
|
271
|
+
})
|
|
272
|
+
.reply(200, { id: 21 }, { headers: JSON_HEADERS });
|
|
273
|
+
const result = await (0, httpClient_1.sendPatch)('https://fakestoreapi.com', 'products/1', mockProduct1_json_1.default, {
|
|
274
|
+
query,
|
|
275
|
+
});
|
|
276
|
+
expect(result.body).toEqual({ id: 21 });
|
|
277
|
+
});
|
|
278
|
+
it('PATCH that returns 400 throws an error', async () => {
|
|
279
|
+
const client = mockAgent.get('https://fakestoreapi.com');
|
|
280
|
+
client
|
|
281
|
+
.intercept({
|
|
282
|
+
path: '/products/1',
|
|
283
|
+
method: 'PATCH',
|
|
284
|
+
})
|
|
285
|
+
.reply(400, { errorCode: 'err' }, { headers: JSON_HEADERS });
|
|
286
|
+
await expect((0, httpClient_1.sendPatch)('https://fakestoreapi.com', 'products/1', mockProduct1_json_1.default)).rejects.toThrow('Response status code 400: Bad Request');
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
//# sourceMappingURL=httpClient.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpClient.spec.js","sourceRoot":"","sources":["../../../src/http/httpClient.spec.ts"],"names":[],"mappings":";;;AAAA,mCAAuD;AAEvD,6CAA+F;AAC/F,8FAAwD;AACxD,0GAAoE;AAEpE,MAAM,YAAY,GAAG;IACnB,cAAc,EAAE,kBAAkB;CACnC,CAAA;AAED,MAAM,YAAY,GAAG;IACnB,cAAc,EAAE,YAAY;CAC7B,CAAA;AAED,QAAQ,CAAC,YAAY,EAAE,GAAG,EAAE;IAC1B,IAAI,SAAoB,CAAA;IACxB,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG,IAAI,kBAAS,EAAE,CAAA;QAC3B,SAAS,CAAC,iBAAiB,EAAE,CAAA;QAC7B,IAAA,4BAAmB,EAAC,SAAS,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;IAEF,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE;QACnB,EAAE,CAAC,yBAAyB,EAAE,KAAK,IAAI,EAAE;YACvC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,0BA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CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC,CAAA;YAE9D,MAAM,MAAM,CACV,IAAA,sBAAS,EAAC,0BAA0B,EAAE,YAAY,EAAE,2BAAY,CAAC,CAClE,CAAC,OAAO,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAA;QAC5D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"category": "men's clothing",
|
|
3
|
+
"description": "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday",
|
|
4
|
+
"id": 1,
|
|
5
|
+
"image": "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg",
|
|
6
|
+
"price": 109.95,
|
|
7
|
+
"rating": {
|
|
8
|
+
"count": 120,
|
|
9
|
+
"rate": 3.9
|
|
10
|
+
},
|
|
11
|
+
"title": "Fjallraven - Foldsack No. 1 Backpack, Fits 14 Laptops"
|
|
12
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"category": "men's clothing",
|
|
4
|
+
"description": "Your perfect pack for everyday use and walks in the forest. Stash your laptop (up to 15 inches) in the padded sleeve, your everyday",
|
|
5
|
+
"id": 1,
|
|
6
|
+
"image": "https://fakestoreapi.com/img/81fPKd-2AYL._AC_SL1500_.jpg",
|
|
7
|
+
"price": 109.95,
|
|
8
|
+
"rating": {
|
|
9
|
+
"count": 120,
|
|
10
|
+
"rate": 3.9
|
|
11
|
+
},
|
|
12
|
+
"title": "Fjallraven - Foldsack No. 1 Backpack, Fits 15 Laptops"
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"category": "men's clothing",
|
|
16
|
+
"description": "Slim-fitting style, contrast raglan long sleeve, three-button henley placket, light weight & soft fabric for breathable and comfortable wearing. And Solid stitched shirts with round neck made for durability and a great fit for casual fashion wear and diehard baseball fans. The Henley style round neckline includes a three-button placket.",
|
|
17
|
+
"id": 2,
|
|
18
|
+
"image": "https://fakestoreapi.com/img/71-3HjGNDUL._AC_SY879._SX._UX._SY._UY_.jpg",
|
|
19
|
+
"price": 22.3,
|
|
20
|
+
"rating": {
|
|
21
|
+
"count": 259,
|
|
22
|
+
"rate": 4.1
|
|
23
|
+
},
|
|
24
|
+
"title": "Mens Casual Premium Slim Fit T-Shirts "
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"category": "men's clothing",
|
|
28
|
+
"description": "great outerwear jackets for Spring/Autumn/Winter, suitable for many occasions, such as working, hiking, camping, mountain/rock climbing, cycling, traveling or other outdoors. Good gift choice for you or your family member. A warm hearted love to Father, husband or son in this thanksgiving or Christmas Day.",
|
|
29
|
+
"id": 3,
|
|
30
|
+
"image": "https://fakestoreapi.com/img/71li-ujtlUL._AC_UX679_.jpg",
|
|
31
|
+
"price": 55.99,
|
|
32
|
+
"rating": {
|
|
33
|
+
"count": 500,
|
|
34
|
+
"rate": 4.7
|
|
35
|
+
},
|
|
36
|
+
"title": "Mens Cotton Jacket"
|
|
37
|
+
}
|
|
38
|
+
]
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lokalise/node-core",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "Lokalise",
|
|
6
|
+
"url": "https://lokalise.com/"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://github.com/lokalise/node-core",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git://github.com/lokalise/node-core.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist/**",
|
|
16
|
+
"LICENSE",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"test": "jest",
|
|
25
|
+
"test:coverage": "jest --coverage",
|
|
26
|
+
"test:ci": "npm run lint && npm run test:coverage",
|
|
27
|
+
"lint": "eslint . --ext .ts",
|
|
28
|
+
"lint:fix": "eslint . --fix",
|
|
29
|
+
"format": "prettier --write .",
|
|
30
|
+
"version": "auto-changelog -p && git add CHANGELOG.md",
|
|
31
|
+
"prepublishOnly": "npm run build"
|
|
32
|
+
},
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"undici": "^5.14.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@types/jest": "^29.2.5",
|
|
38
|
+
"@types/node": "^18.11.18",
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.47.1",
|
|
40
|
+
"@typescript-eslint/parser": "^5.47.1",
|
|
41
|
+
"auto-changelog": "^2.4.0",
|
|
42
|
+
"eslint": "^8.31.0",
|
|
43
|
+
"eslint-config-prettier": "^8.5.0",
|
|
44
|
+
"eslint-plugin-import": "^2.26.0",
|
|
45
|
+
"eslint-plugin-jest": "^27.2.0",
|
|
46
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
47
|
+
"jest": "^29.3.1",
|
|
48
|
+
"prettier": "^2.8.1",
|
|
49
|
+
"ts-jest": "^29.0.3",
|
|
50
|
+
"typescript": "4.9.4"
|
|
51
|
+
}
|
|
52
|
+
}
|