@pentops/jsonapi-request
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -11,2 +11,3 @@ import { APIError } from './error'; | ||
export declare function makeRequest<TRes, TReqBody extends unknown = undefined>(method: HTTPMethod, path: string, request?: TypedRequestInit<TReqBody>): Promise<TRes | undefined>; | ||
export declare function makeCancellableRequest<TRes, TReqBody extends unknown = undefined>(method: HTTPMethod, path: string, request?: TypedRequestInit<TReqBody>): [Promise<TRes | undefined>, AbortController]; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -17,3 +17,3 @@ import { stringify } from 'qs'; | ||
***************************************************************************** */ | ||
/* global Reflect, Promise, SuppressedError, Symbol */ | ||
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */ | ||
@@ -52,3 +52,3 @@ | ||
super(message); | ||
this.name = this.constructor.name; | ||
this.name = 'APIError'; | ||
this.status = status; | ||
@@ -61,6 +61,20 @@ this.requestIdentifier = requestIdentifier; | ||
let uuid; | ||
try { | ||
uuid = require('uuid').v4; | ||
function loadUUID() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (uuid) { | ||
return uuid; | ||
} | ||
const uuidModule = yield import('uuid'); | ||
uuid = uuidModule.v4; | ||
return uuid; | ||
} | ||
catch (_a) { } | ||
}); | ||
} | ||
catch (_a) { } | ||
(function () { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
yield loadUUID(); | ||
}); | ||
}()); | ||
function processResponse(rawResponse) { | ||
@@ -73,2 +87,5 @@ return __awaiter(this, void 0, void 0, function* () { | ||
return (yield rawResponse.blob()); | ||
case 'multipart/form-data': | ||
case 'application/x-www-form-urlencoded': | ||
return (yield rawResponse.formData()); | ||
default: | ||
@@ -178,3 +195,7 @@ return (yield rawResponse.text()); | ||
} | ||
function makeCancellableRequest(method, path, request) { | ||
const controller = new AbortController(); | ||
return [makeRequest(method, path, Object.assign(Object.assign({}, request), { signal: controller.signal })), controller]; | ||
} | ||
export { APIError, buildMergedRequestInit, buildSearchString, buildSplitRequestInit, makeRequest }; | ||
export { APIError, buildMergedRequestInit, buildSearchString, buildSplitRequestInit, makeCancellableRequest, makeRequest }; |
{ | ||
"name": "@pentops/jsonapi-request", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "", | ||
@@ -22,9 +22,9 @@ "main": "dist/index.js", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@types/node": "^22.3.0", | ||
"@types/node": "^22.5.4", | ||
"@types/qs": "^6.9.15", | ||
"@types/uuid": "^10.0.0", | ||
"rollup": "^4.20.0", | ||
"rollup": "^4.21.3", | ||
"rollup-plugin-peer-deps-external": "^2.2.4", | ||
"tslib": "^2.6.3", | ||
"typescript": "^5.5.4" | ||
"tslib": "^2.7.0", | ||
"typescript": "^5.6.2" | ||
}, | ||
@@ -36,3 +36,4 @@ "dependencies": { | ||
"peerDependencies": { | ||
"uuid": "^10.0.0" | ||
"uuid": "^10.0.0", | ||
"qs": ">=6.0.0 < 7.0.0" | ||
}, | ||
@@ -39,0 +40,0 @@ "peerDependenciesMeta": { |
Sorry, the diff of this file is not supported yet
15221
204
4