@driveflux/fetch 2.0.0-next.7 → 2.0.0-next.8
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/CHANGELOG.md +8 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/cjs/index.js
CHANGED
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["import isomorphicFetch from 'isomorphic-unfetch'\nimport { Ok, Err, Result } from '@driveflux/result'\nimport { makeProblem, PROBLEM_INVALID_DATA } from '@driveflux/problem'\n\n/**\n * Parses the JSON returned by a network request\n *\n * @param response A response from a network request\n *\n * @throws if json is wrong\n * @return The parsed JSON from the request\n */\nconst parseJSON = async <T>(response: isomorphicFetch.IsomorphicResponse): Promise<T> => {\n return await response.json() as T\n}\n\n\n/**\n * Checks if a network request came back fine, and throws an error if not\n *\n * @param response A response from a network request\n *\n * @return Returns either the response, or throws an error\n */\nconst isSuccessful = (response: isomorphicFetch.IsomorphicResponse) => {\n return response.status >= 200 && response.status < 300\n}\n\n/**\n * Requests a URL, returning a promise\n *\n * @param url The URL we want to request\n * @param [options] The options we want to pass to \"fetch\"\n *\n * @return The response data\n */\nexport const enhancedFetch = async <S = object, E = import('@driveflux/problem').Problem>(url: string, providedOptions?: isomorphicFetch.IsomorphicRequestInit): Promise<Result<S, E | import('@driveflux/problem').Problem>> => {\n // @ts-ignore\n const options: isomorphicFetch.IsomorphicRequestInit = {\n ...providedOptions,\n headers: {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Accept': 'application/json',\n ...providedOptions?.headers,\n },\n }\n\n if(options.body && typeof options.body !== 'string') {\n options.body = JSON.stringify(options.body)\n }\n\n const response = await isomorphicFetch(url, options as any)\n\n // Will parse JSON body regardless of the response status\n let body\n try {\n body = await parseJSON<S | E>(response)\n } catch (e: any) {\n return new Err(makeProblem(PROBLEM_INVALID_DATA, `Unable to parse json`, {\n response,\n }))\n }\n\n // We return the body as E if the fetch is not successful\n if(!isSuccessful(response)) {\n return new Err(body as E)\n }\n \n // We return the body as S if the fetch is successful\n return new Ok(body as S)\n}\n\nexport default enhancedFetch\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,gCAA4B;AAC5B,oBAAgC;AAChC,qBAAkD;AAUlD,IAAM,YAAY,OAAU,aAA6D;AACvF,SAAO,MAAM,SAAS,KAAK;AAC7B;AAUA,IAAM,eAAe,CAAC,aAAiD;AACrE,SAAO,SAAS,UAAU,OAAO,SAAS,SAAS;AACrD;AAUO,IAAM,gBAAgB,OAA6D,KAAa,oBAA0H;AAE/N,QAAM,UAAiD;AAAA,IACrD,GAAG;AAAA,IACH,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,GAAG,iBAAiB;AAAA,IACtB;AAAA,EACF;AAEA,MAAG,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAAU;AACnD,YAAQ,OAAO,KAAK,UAAU,QAAQ,IAAI;AAAA,EAC5C;AAEA,QAAM,WAAW,MAAM,uCAAgB,KAAK,OAAc;AAG1D,MAAI;AACJ,MAAI;AACF,WAAO,MAAM,UAAiB,QAAQ;AAAA,EACxC,SAAS,GAAP;AACA,WAAO,IAAI,kBAAI,gCAAY,qCAAsB,wBAAwB;AAAA,MACvE;AAAA,IACF,CAAC,CAAC;AAAA,EACJ;AAGA,MAAG,CAAC,aAAa,QAAQ,GAAG;AAC1B,WAAO,IAAI,kBAAI,IAAS;AAAA,EAC1B;AAGA,SAAO,IAAI,iBAAG,IAAS;AACzB;AAEA,IAAO,cAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["import isomorphicFetch from 'isomorphic-unfetch'\nimport { Ok, Err, Result } from '@driveflux/result'\nimport { makeProblem, PROBLEM_INVALID_DATA } from '@driveflux/problem'\n\n/**\n * Parses the JSON returned by a network request\n *\n * @param response A response from a network request\n *\n * @throws if json is wrong\n * @return The parsed JSON from the request\n */\nconst parseJSON = async <T>(response: isomorphicFetch.IsomorphicResponse): Promise<T> => {\n return await response.json() as T\n}\n\n\n/**\n * Checks if a network request came back fine, and throws an error if not\n *\n * @param response A response from a network request\n *\n * @return Returns either the response, or throws an error\n */\nconst isSuccessful = (response: isomorphicFetch.IsomorphicResponse) => {\n return response.status >= 200 && response.status < 300\n}\n\n/**\n * Requests a URL, returning a promise\n *\n * @param url The URL we want to request\n * @param [options] The options we want to pass to \"fetch\"\n *\n * @return The response data\n */\nexport const enhancedFetch = async <S = object, E = import('@driveflux/problem').Problem>(url: string, providedOptions?: isomorphicFetch.IsomorphicRequestInit): Promise<Result<S, E | import('@driveflux/problem').Problem>> => {\n // @ts-ignore\n const options: isomorphicFetch.IsomorphicRequestInit = {\n ...providedOptions,\n headers: {\n 'Content-Type': 'application/json; charset=utf-8',\n 'Accept': 'application/json',\n ...providedOptions?.headers,\n },\n }\n\n if(options.body && typeof options.body !== 'string') {\n options.body = JSON.stringify(options.body)\n }\n\n const response = await isomorphicFetch(url, options as any)\n\n // Will parse JSON body regardless of the response status\n let body\n try {\n body = await parseJSON<S | E>(response)\n } catch (e: any) {\n return new Err(makeProblem(PROBLEM_INVALID_DATA, `Unable to parse json`, {\n response,\n }))\n }\n\n // We return the body as E if the fetch is not successful\n if(!isSuccessful(response)) {\n return new Err(body as E)\n }\n \n // We return the body as S if the fetch is successful\n return new Ok(body as S)\n}\n\nexport default enhancedFetch\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;AAAA;AACA;AACA;AAUA,IAAM,YAAY,OAAU,aAA6D;AACvF,SAAO,MAAM,SAAS,KAAK;AAC7B;AAUA,IAAM,eAAe,CAAC,aAAiD;AACrE,SAAO,SAAS,UAAU,OAAO,SAAS,SAAS;AACrD;AAUO,IAAM,gBAAgB,OAA6D,KAAa,oBAA0H;AAE/N,QAAM,UAAiD;AAAA,IACrD,GAAG;AAAA,IACH,SAAS;AAAA,MACP,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,GAAG,iBAAiB;AAAA,IACtB;AAAA,EACF;AAEA,MAAG,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAAU;AACnD,YAAQ,OAAO,KAAK,UAAU,QAAQ,IAAI;AAAA,EAC5C;AAEA,QAAM,WAAW,MAAM,gBAAgB,KAAK,OAAc;AAG1D,MAAI;AACJ,MAAI;AACF,WAAO,MAAM,UAAiB,QAAQ;AAAA,EACxC,SAAS,GAAP;AACA,WAAO,IAAI,IAAI,YAAY,sBAAsB,wBAAwB;AAAA,MACvE;AAAA,IACF,CAAC,CAAC;AAAA,EACJ;AAGA,MAAG,CAAC,aAAa,QAAQ,GAAG;AAC1B,WAAO,IAAI,IAAI,IAAS;AAAA,EAC1B;AAGA,SAAO,IAAI,GAAG,IAAS;AACzB;AAEA,IAAO,cAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@driveflux/fetch",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.8",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@driveflux/problem": "2.0.0-next.
|
|
17
|
-
"@driveflux/result": "2.0.0-next.
|
|
16
|
+
"@driveflux/problem": "2.0.0-next.8",
|
|
17
|
+
"@driveflux/result": "2.0.0-next.8",
|
|
18
18
|
"encoding": "^0.1.13",
|
|
19
19
|
"isomorphic-unfetch": "^3.1.0"
|
|
20
20
|
},
|