@jpmorganchase/mosaic-from-http-request 0.1.0-beta.15

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.
@@ -0,0 +1,6 @@
1
+ import * as nodeFetch from 'node-fetch';
2
+ import { fromFetch } from 'rxjs/fetch';
3
+ declare global {
4
+ var fetch: typeof nodeFetch.default;
5
+ }
6
+ export { fromFetch };
@@ -0,0 +1,9 @@
1
+ /* eslint-disable eslint-comments/no-unlimited-disable */
2
+ import * as nodeFetch from 'node-fetch';
3
+ import { fromFetch } from 'rxjs/fetch';
4
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
5
+ // @ts-ignore
6
+ global.fetch = nodeFetch.default;
7
+ export { fromFetch };
8
+ /* eslint-enable eslint-comments/no-unlimited-disable */
9
+ //# sourceMappingURL=fromFetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromFetch.js","sourceRoot":"","sources":["../src/fromFetch.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,KAAK,SAAS,MAAM,YAAY,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAQvC,6DAA6D;AAC7D,aAAa;AACb,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC;AAEjC,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,wDAAwD"}
@@ -0,0 +1,9 @@
1
+ import 'event-target-polyfill';
2
+ import 'yet-another-abortcontroller-polyfill';
3
+ import { Observable } from 'rxjs';
4
+ export declare type ErrorResponse = {
5
+ error: boolean;
6
+ message: string;
7
+ };
8
+ export declare function isErrorResponse<TData>(response: TData | ErrorResponse): response is ErrorResponse;
9
+ export declare function fromHttpRequest<TData>(url: string): Observable<TData | ErrorResponse>;
@@ -0,0 +1,20 @@
1
+ import 'event-target-polyfill';
2
+ import 'yet-another-abortcontroller-polyfill';
3
+ import { of } from 'rxjs';
4
+ import { catchError, switchMap } from 'rxjs/operators';
5
+ import { fromFetch } from './fromFetch.js';
6
+ export function isErrorResponse(response) {
7
+ return response.error !== undefined;
8
+ }
9
+ export function fromHttpRequest(url) {
10
+ return fromFetch(url).pipe(switchMap(response => {
11
+ if (response.ok) {
12
+ return response.json();
13
+ }
14
+ return of({ error: true, message: `Error ${response.status}` });
15
+ }), catchError(err => {
16
+ console.error(err);
17
+ return of({ error: true, message: err.message });
18
+ }));
19
+ }
20
+ //# sourceMappingURL=fromHttpRequest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fromHttpRequest.js","sourceRoot":"","sources":["../src/fromHttpRequest.ts"],"names":[],"mappings":"AAAA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,sCAAsC,CAAC;AAC9C,OAAO,EAAc,EAAE,EAAE,MAAM,MAAM,CAAC;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAI3C,MAAM,UAAU,eAAe,CAAQ,QAA+B;IACpE,OAAQ,QAA0B,CAAC,KAAK,KAAK,SAAS,CAAC;AACzD,CAAC;AAED,MAAM,UAAU,eAAe,CAAQ,GAAW;IAChD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CACxB,SAAS,CAAC,QAAQ,CAAC,EAAE;QACnB,IAAI,QAAQ,CAAC,EAAE,EAAE;YACf,OAAO,QAAQ,CAAC,IAAI,EAAoB,CAAC;SAC1C;QACD,OAAO,EAAE,CAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,QAAQ,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACjF,CAAC,CAAC,EACF,UAAU,CAAC,GAAG,CAAC,EAAE;QACf,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,EAAE,CAAgB,EAAE,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,CAAC,OAAiB,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1 @@
1
+ export * from './fromHttpRequest.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './fromHttpRequest.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@jpmorganchase/mosaic-from-http-request",
3
+ "version": "0.1.0-beta.15",
4
+ "author": "",
5
+ "description": "Utility package to turn HTTP fetch requests to observables. This package can be deleted when node 18 is used.",
6
+ "license": "Apache-2.0",
7
+ "main": "./dist/index.js",
8
+ "type": "module",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "node": "./dist/index.js"
15
+ }
16
+ },
17
+ "engines": {
18
+ "node": ">= 16.0.0"
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsc",
25
+ "clean": "rm -fr dist",
26
+ "lint": "eslint --ignore-pattern \"**/__tests__/**\""
27
+ },
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "git@github.com:jpmorganchase/mosaic.git"
31
+ },
32
+ "dependencies": {
33
+ "event-target-polyfill": "^0.0.3",
34
+ "rxjs": "^7.5.5",
35
+ "node-fetch": "^2.6.1",
36
+ "yet-another-abortcontroller-polyfill": "0.0.4"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node-fetch": "^2.5.8",
40
+ "msw": "^0.47.4"
41
+ }
42
+ }