@vertesia/api-fetch-client 0.52.0 → 0.54.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/package.json +1 -1
- package/src/base.ts +3 -3
- package/src/client.ts +3 -3
- package/src/sse/EventSourceParserStream.ts +1 -1
- package/src/sse/TextDecoderStream.ts +1 -1
- package/lib/cjs/base.js +0 -190
- package/lib/cjs/base.js.map +0 -1
- package/lib/cjs/client.js +0 -107
- package/lib/cjs/client.js.map +0 -1
- package/lib/cjs/errors.js +0 -57
- package/lib/cjs/errors.js.map +0 -1
- package/lib/cjs/index.js +0 -21
- package/lib/cjs/index.js.map +0 -1
- package/lib/cjs/package.json +0 -3
- package/lib/cjs/sse/EventSourceParserStream.js +0 -41
- package/lib/cjs/sse/EventSourceParserStream.js.map +0 -1
- package/lib/cjs/sse/TextDecoderStream.js +0 -51
- package/lib/cjs/sse/TextDecoderStream.js.map +0 -1
- package/lib/cjs/sse/index.js +0 -27
- package/lib/cjs/sse/index.js.map +0 -1
- package/lib/cjs/utils.js +0 -38
- package/lib/cjs/utils.js.map +0 -1
- package/lib/esm/base.js +0 -185
- package/lib/esm/base.js.map +0 -1
- package/lib/esm/client.js +0 -101
- package/lib/esm/client.js.map +0 -1
- package/lib/esm/errors.js +0 -51
- package/lib/esm/errors.js.map +0 -1
- package/lib/esm/index.js +0 -5
- package/lib/esm/index.js.map +0 -1
- package/lib/esm/sse/EventSourceParserStream.js +0 -37
- package/lib/esm/sse/EventSourceParserStream.js.map +0 -1
- package/lib/esm/sse/TextDecoderStream.js +0 -49
- package/lib/esm/sse/TextDecoderStream.js.map +0 -1
- package/lib/esm/sse/index.js +0 -24
- package/lib/esm/sse/index.js.map +0 -1
- package/lib/esm/utils.js +0 -33
- package/lib/esm/utils.js.map +0 -1
- package/lib/tsconfig.tsbuildinfo +0 -1
- package/lib/types/base.d.ts +0 -67
- package/lib/types/base.d.ts.map +0 -1
- package/lib/types/client.d.ts +0 -36
- package/lib/types/client.d.ts.map +0 -1
- package/lib/types/errors.d.ts +0 -18
- package/lib/types/errors.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -5
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/sse/EventSourceParserStream.d.ts +0 -23
- package/lib/types/sse/EventSourceParserStream.d.ts.map +0 -1
- package/lib/types/sse/TextDecoderStream.d.ts +0 -8
- package/lib/types/sse/TextDecoderStream.d.ts.map +0 -1
- package/lib/types/sse/index.d.ts +0 -13
- package/lib/types/sse/index.d.ts.map +0 -1
- package/lib/types/utils.d.ts +0 -4
- package/lib/types/utils.d.ts.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vertesia/api-fetch-client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "HTTP client which wraps a fetch implementation and simplify the creation of REST API clients. Works both in browser and in node.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "./lib/types/index.d.ts",
|
package/src/base.ts
CHANGED
|
@@ -9,13 +9,13 @@ export interface IRequestParams {
|
|
|
9
9
|
query?: Record<string, IPrimitives> | null;
|
|
10
10
|
headers?: Record<string, string> | null;
|
|
11
11
|
/*
|
|
12
|
-
* custom response reader. The default is to read a JSON
|
|
12
|
+
* custom response reader. The default is to read a JSON object using the jsonParse method
|
|
13
13
|
* The reader function is called with the client as the `this` context
|
|
14
14
|
* This can be an async function (i.e. return a promise). If a promise is returned
|
|
15
15
|
* it will wait for the promise to resolve before returning the result
|
|
16
16
|
*
|
|
17
17
|
* If set to 'sse' the response will be treated as a server-sent event stream
|
|
18
|
-
* and the
|
|
18
|
+
* and the request will return a Promise<ReadableStream<ServerSentEvent>> object
|
|
19
19
|
*/
|
|
20
20
|
reader?: 'sse' | ((response: Response) => any);
|
|
21
21
|
/**
|
|
@@ -145,7 +145,7 @@ export abstract class ClientBase {
|
|
|
145
145
|
}).catch((err) => {
|
|
146
146
|
return {
|
|
147
147
|
status: res.status,
|
|
148
|
-
error: "Unable to load
|
|
148
|
+
error: "Unable to load response content",
|
|
149
149
|
message: err.message,
|
|
150
150
|
};
|
|
151
151
|
});
|
package/src/client.ts
CHANGED
|
@@ -10,7 +10,7 @@ export class AbstractFetchClient<T extends AbstractFetchClient<T>> extends Clien
|
|
|
10
10
|
|
|
11
11
|
headers: Record<string, string>;
|
|
12
12
|
_auth?: () => Promise<string>;
|
|
13
|
-
// callbacks
|
|
13
|
+
// callbacks useful to log requests and responses
|
|
14
14
|
onRequest?: (req: Request) => void;
|
|
15
15
|
onResponse?: (res: Response, req: Request) => void;
|
|
16
16
|
// the last response. Can be used to inspect the response headers
|
|
@@ -28,7 +28,7 @@ export class AbstractFetchClient<T extends AbstractFetchClient<T>> extends Clien
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Install an auth callback. If the callback is undefined or null then remove the auth callback.
|
|
31
|
-
* @param authCb a
|
|
31
|
+
* @param authCb a function returning a promise that resolves to the value to use for the authorization header
|
|
32
32
|
* @returns the client instance
|
|
33
33
|
*/
|
|
34
34
|
withAuthCallback(authCb?: (() => Promise<string>) | null) {
|
|
@@ -85,7 +85,7 @@ export class AbstractFetchClient<T extends AbstractFetchClient<T>> extends Clien
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
async handleResponse(req: Request, res: Response, params: IRequestParamsWithPayload | undefined): Promise<any> {
|
|
88
|
-
this.response = res; // store last
|
|
88
|
+
this.response = res; // store last response
|
|
89
89
|
this.onResponse && this.onResponse(res, req);
|
|
90
90
|
return super.handleResponse(req, res, params);
|
|
91
91
|
}
|
|
@@ -2,7 +2,7 @@ import { createParser, ReconnectInterval, type EventSourceParser, type ParsedEve
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* We copied this file from the eventsource-parser/stream package and made it a part of our project.
|
|
5
|
-
* because importing the eventsource-parser/stream breaks tsc build when
|
|
5
|
+
* because importing the eventsource-parser/stream breaks tsc build when building the commonjs version
|
|
6
6
|
* see for a similar error:
|
|
7
7
|
* https://stackoverflow.com/questions/77280140/why-typescript-dont-see-exports-of-package-with-module-commonjs-and-moduleres
|
|
8
8
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Decode a stream of bytes into a stream of characters.
|
|
3
3
|
* Some javascript env like Bun.js doesn't supports the TextDecoderStream (as for jan 2024)
|
|
4
|
-
* This is a polyfill for
|
|
4
|
+
* This is a polyfill for bunJS
|
|
5
5
|
*/
|
|
6
6
|
let _TextDecoderStream: typeof TextDecoderStream;
|
|
7
7
|
if (globalThis.TextDecoderStream && typeof globalThis.TextDecoderStream === 'function') {
|
package/lib/cjs/base.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ClientBase = void 0;
|
|
4
|
-
exports.fetchPromise = fetchPromise;
|
|
5
|
-
const errors_js_1 = require("./errors.js");
|
|
6
|
-
const index_js_1 = require("./index.js");
|
|
7
|
-
const utils_js_1 = require("./utils.js");
|
|
8
|
-
function fetchPromise(fetchImpl) {
|
|
9
|
-
if (fetchImpl) {
|
|
10
|
-
return Promise.resolve(fetchImpl);
|
|
11
|
-
}
|
|
12
|
-
else if (typeof globalThis.fetch === 'function') {
|
|
13
|
-
return Promise.resolve(globalThis.fetch);
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
// install an error impl
|
|
17
|
-
return Promise.resolve(() => {
|
|
18
|
-
throw new Error('No Fetch implementation found');
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
class ClientBase {
|
|
23
|
-
constructor(baseUrl, fetchImpl) {
|
|
24
|
-
this.errorFactory = (err) => err;
|
|
25
|
-
this.verboseErrors = true;
|
|
26
|
-
this.baseUrl = (0, utils_js_1.removeTrailingSlash)(baseUrl);
|
|
27
|
-
this._fetch = fetchPromise(fetchImpl);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Can be subclassed to map to custom errors
|
|
31
|
-
* @param err
|
|
32
|
-
*/
|
|
33
|
-
throwError(err) {
|
|
34
|
-
throw this.errorFactory(err);
|
|
35
|
-
}
|
|
36
|
-
getUrl(path) {
|
|
37
|
-
return (0, utils_js_1.removeTrailingSlash)((0, utils_js_1.join)(this.baseUrl, path));
|
|
38
|
-
}
|
|
39
|
-
get(path, params) {
|
|
40
|
-
return this.request('GET', path, params);
|
|
41
|
-
}
|
|
42
|
-
del(path, params) {
|
|
43
|
-
return this.request('DELETE', path, params);
|
|
44
|
-
}
|
|
45
|
-
delete(path, params) {
|
|
46
|
-
return this.request('DELETE', path, params);
|
|
47
|
-
}
|
|
48
|
-
post(path, params) {
|
|
49
|
-
return this.request('POST', path, params);
|
|
50
|
-
}
|
|
51
|
-
put(path, params) {
|
|
52
|
-
return this.request('PUT', path, params);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* You can customize the json parser by overriding this method
|
|
56
|
-
* @param text
|
|
57
|
-
* @returns
|
|
58
|
-
*/
|
|
59
|
-
jsonParse(text) {
|
|
60
|
-
return JSON.parse(text);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Can be overridden to create the request
|
|
64
|
-
* @param fetch
|
|
65
|
-
* @param url
|
|
66
|
-
* @param init
|
|
67
|
-
* @returns
|
|
68
|
-
*/
|
|
69
|
-
createRequest(url, init) {
|
|
70
|
-
return Promise.resolve(new Request(url, init));
|
|
71
|
-
}
|
|
72
|
-
createServerError(req, res, payload) {
|
|
73
|
-
const status = res.status;
|
|
74
|
-
let message = 'Server Error: ' + status;
|
|
75
|
-
if (payload) {
|
|
76
|
-
if (payload.message) {
|
|
77
|
-
message = String(payload.message);
|
|
78
|
-
}
|
|
79
|
-
else if (payload.error) {
|
|
80
|
-
if (typeof payload.error === 'string') {
|
|
81
|
-
message = String(payload.error);
|
|
82
|
-
}
|
|
83
|
-
else if (typeof payload.error.message === 'string') {
|
|
84
|
-
message = String(payload.error.message);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return new errors_js_1.ServerError(message, req, res.status, payload, this.verboseErrors);
|
|
89
|
-
}
|
|
90
|
-
async readJSONPayload(res) {
|
|
91
|
-
return res.text().then(text => {
|
|
92
|
-
if (!text) {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
try {
|
|
97
|
-
return this.jsonParse(text);
|
|
98
|
-
}
|
|
99
|
-
catch (err) {
|
|
100
|
-
return {
|
|
101
|
-
status: res.status,
|
|
102
|
-
error: "Not a valid JSON payload",
|
|
103
|
-
message: err.message,
|
|
104
|
-
text: text,
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}).catch((err) => {
|
|
109
|
-
return {
|
|
110
|
-
status: res.status,
|
|
111
|
-
error: "Unable to load repsonse content",
|
|
112
|
-
message: err.message,
|
|
113
|
-
};
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Subclasses You can override this to do something with the response
|
|
118
|
-
* @param res
|
|
119
|
-
*/
|
|
120
|
-
handleResponse(req, res, params) {
|
|
121
|
-
res.url;
|
|
122
|
-
if (params && params.reader) {
|
|
123
|
-
if (params.reader === 'sse') {
|
|
124
|
-
return (0, index_js_1.sse)(res);
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
return params.reader.call(this, res);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
return this.readJSONPayload(res).then((payload) => {
|
|
132
|
-
if (res.ok) {
|
|
133
|
-
return payload;
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
this.throwError(this.createServerError(req, res, payload));
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
async request(method, path, params) {
|
|
142
|
-
let url = this.getUrl(path);
|
|
143
|
-
if (params?.query) {
|
|
144
|
-
url += '?' + (0, utils_js_1.buildQueryString)(params.query);
|
|
145
|
-
}
|
|
146
|
-
const headers = this.headers ? Object.assign({}, this.headers) : {};
|
|
147
|
-
const paramsHeaders = params?.headers;
|
|
148
|
-
if (paramsHeaders) {
|
|
149
|
-
for (const key in paramsHeaders) {
|
|
150
|
-
headers[key.toLowerCase()] = paramsHeaders[key];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
let body;
|
|
154
|
-
const payload = params?.payload;
|
|
155
|
-
if (payload) {
|
|
156
|
-
if (params && params.jsonPayload === false) {
|
|
157
|
-
body = payload;
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
body = (typeof payload !== 'string') ? JSON.stringify(payload) : payload;
|
|
161
|
-
if (!('content-type' in headers)) {
|
|
162
|
-
headers['content-type'] = 'application/json';
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
const init = {
|
|
167
|
-
method: method,
|
|
168
|
-
headers: headers,
|
|
169
|
-
body: body,
|
|
170
|
-
};
|
|
171
|
-
const req = await this.createRequest(url, init);
|
|
172
|
-
return this._fetch.then(fetch => fetch(req).catch(err => {
|
|
173
|
-
console.error(`Failed to connect to ${url}`, err);
|
|
174
|
-
this.throwError(new errors_js_1.ConnectionError(req, err));
|
|
175
|
-
}).then(res => {
|
|
176
|
-
return this.handleResponse(req, res, params);
|
|
177
|
-
}));
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Expose the fetch method
|
|
181
|
-
* @param input
|
|
182
|
-
* @param init
|
|
183
|
-
* @returns
|
|
184
|
-
*/
|
|
185
|
-
fetch(input, init) {
|
|
186
|
-
return this._fetch.then(fetch => fetch(input, init));
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.ClientBase = ClientBase;
|
|
190
|
-
//# sourceMappingURL=base.js.map
|
package/lib/cjs/base.js.map
DELETED
|
@@ -1 +0,0 @@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,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IACzD,CAAC;CAEJ;AApLD,gCAoLC"}
|
package/lib/cjs/client.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiTopic = exports.FetchClient = exports.AbstractFetchClient = void 0;
|
|
4
|
-
const base_js_1 = require("./base.js");
|
|
5
|
-
function isAuthorizationHeaderSet(headers) {
|
|
6
|
-
if (!headers)
|
|
7
|
-
return false;
|
|
8
|
-
return "authorization" in headers;
|
|
9
|
-
}
|
|
10
|
-
class AbstractFetchClient extends base_js_1.ClientBase {
|
|
11
|
-
constructor(baseUrl, fetchImpl) {
|
|
12
|
-
super(baseUrl, fetchImpl);
|
|
13
|
-
this.baseUrl = baseUrl[baseUrl.length - 1] === '/' ? baseUrl.substring(0, baseUrl.length - 1) : baseUrl;
|
|
14
|
-
this.headers = this.initialHeaders;
|
|
15
|
-
}
|
|
16
|
-
get initialHeaders() {
|
|
17
|
-
return { accept: 'application/json' };
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Install an auth callback. If the callback is undefined or null then remove the auth callback.
|
|
21
|
-
* @param authCb a fucntion returning a promise that resolves to the value to use for the authorization header
|
|
22
|
-
* @returns the client instance
|
|
23
|
-
*/
|
|
24
|
-
withAuthCallback(authCb) {
|
|
25
|
-
this._auth = authCb || undefined;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
withErrorFactory(factory) {
|
|
29
|
-
this.errorFactory = factory;
|
|
30
|
-
return this;
|
|
31
|
-
}
|
|
32
|
-
withLang(locale) {
|
|
33
|
-
if (locale) {
|
|
34
|
-
this.headers['accept-language'] = locale;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
delete this.headers['accept-language'];
|
|
38
|
-
}
|
|
39
|
-
return this;
|
|
40
|
-
}
|
|
41
|
-
withHeaders(headers) {
|
|
42
|
-
const thisHeaders = this.headers;
|
|
43
|
-
for (const key in headers) {
|
|
44
|
-
const value = headers[key];
|
|
45
|
-
if (value != null) {
|
|
46
|
-
thisHeaders[key.toLowerCase()] = value;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return this;
|
|
50
|
-
}
|
|
51
|
-
setHeader(key, value) {
|
|
52
|
-
if (!value) {
|
|
53
|
-
delete this.headers[key.toLowerCase()];
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
this.headers[key.toLowerCase()] = value;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
async createRequest(url, init) {
|
|
60
|
-
if (this._auth && !isAuthorizationHeaderSet(init.headers)) {
|
|
61
|
-
const headers = (init.headers ? init.headers : {});
|
|
62
|
-
init.headers = headers;
|
|
63
|
-
const auth = await this._auth();
|
|
64
|
-
if (auth) {
|
|
65
|
-
init.headers["authorization"] = auth;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
this.response = undefined;
|
|
69
|
-
const request = await super.createRequest(url, init);
|
|
70
|
-
this.onRequest && this.onRequest(request);
|
|
71
|
-
return request;
|
|
72
|
-
}
|
|
73
|
-
async handleResponse(req, res, params) {
|
|
74
|
-
this.response = res; // store last repsonse
|
|
75
|
-
this.onResponse && this.onResponse(res, req);
|
|
76
|
-
return super.handleResponse(req, res, params);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
exports.AbstractFetchClient = AbstractFetchClient;
|
|
80
|
-
class FetchClient extends AbstractFetchClient {
|
|
81
|
-
constructor(baseUrl, fetchImpl) {
|
|
82
|
-
super(baseUrl, fetchImpl);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
exports.FetchClient = FetchClient;
|
|
86
|
-
class ApiTopic extends base_js_1.ClientBase {
|
|
87
|
-
constructor(client, basePath) {
|
|
88
|
-
//TODO we should refactor the way ClientBase and ApiTopic is created
|
|
89
|
-
// to avoid cloning all customizations
|
|
90
|
-
super(client.getUrl(basePath), client._fetch);
|
|
91
|
-
this.client = client;
|
|
92
|
-
this.createServerError = client.createServerError;
|
|
93
|
-
this.errorFactory = client.errorFactory;
|
|
94
|
-
this.verboseErrors = client.verboseErrors;
|
|
95
|
-
}
|
|
96
|
-
createRequest(url, init) {
|
|
97
|
-
return this.client.createRequest(url, init);
|
|
98
|
-
}
|
|
99
|
-
handleResponse(req, res, params) {
|
|
100
|
-
return this.client.handleResponse(req, res, params);
|
|
101
|
-
}
|
|
102
|
-
get headers() {
|
|
103
|
-
return this.client.headers;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
exports.ApiTopic = ApiTopic;
|
|
107
|
-
//# sourceMappingURL=client.js.map
|
package/lib/cjs/client.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,uCAA4E;AAG5E,SAAS,wBAAwB,CAAC,OAAgC;IAC9D,IAAI,CAAC,OAAO;QAAE,OAAO,KAAK,CAAC;IAC3B,OAAO,eAAe,IAAI,OAAO,CAAC;AACtC,CAAC;AAED,MAAa,mBAAsD,SAAQ,oBAAU;IAUjF,YAAY,OAAe,EAAE,SAAwC;QACjE,KAAK,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;QACxG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC;IACvC,CAAC;IAED,IAAI,cAAc;QACd,OAAO,EAAE,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,gBAAgB,CAAC,MAAuC;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IjC,IAAI,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAA;QACjD,IAAI,CAAC,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC;QACxC,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC;IAC9C,CAAC;IAED,aAAa,CAAC,GAAW,EAAE,IAAiB;QACxC,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC;IAED,cAAc,CAAC,GAAY,EAAE,GAAa,EAAE,MAA6C;QACrF,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC;IAC/B,CAAC;CAEJ;AAvBD,4BAuBC"}
|
package/lib/cjs/errors.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ConnectionError = exports.ServerError = exports.RequestError = void 0;
|
|
4
|
-
function createMessage(message, request, status, payload, displayDetails) {
|
|
5
|
-
let msg = message;
|
|
6
|
-
if (displayDetails) {
|
|
7
|
-
msg += '\nRequest: ' + request.method + ' ' + request.url + ' => ' + status;
|
|
8
|
-
const details = payload?.details || payload?.error?.details;
|
|
9
|
-
if (details) {
|
|
10
|
-
const detailsType = typeof details;
|
|
11
|
-
if (detailsType === 'string') {
|
|
12
|
-
msg += '\nDetails: ' + details;
|
|
13
|
-
}
|
|
14
|
-
else if (detailsType === "object") {
|
|
15
|
-
msg += '\nDetails: ' + JSON.stringify(details, undefined, 2);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
msg += '\nStack Trace: ';
|
|
19
|
-
}
|
|
20
|
-
return msg;
|
|
21
|
-
}
|
|
22
|
-
class RequestError extends Error {
|
|
23
|
-
constructor(message, request, status, payload, displayDetails = true) {
|
|
24
|
-
super(createMessage(message, request, status, payload, displayDetails));
|
|
25
|
-
this.original_message = message;
|
|
26
|
-
this.request = request;
|
|
27
|
-
this.status = status;
|
|
28
|
-
this.payload = payload;
|
|
29
|
-
this.request_info = request.method + ' ' + request.url + ' => ' + status;
|
|
30
|
-
this.displayDetails = displayDetails;
|
|
31
|
-
}
|
|
32
|
-
get details() {
|
|
33
|
-
return this.payload?.details || this.payload?.error?.details;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.RequestError = RequestError;
|
|
37
|
-
class ServerError extends RequestError {
|
|
38
|
-
constructor(message, req, status, payload, displayDetails = true) {
|
|
39
|
-
super(message, req, status, payload, displayDetails);
|
|
40
|
-
}
|
|
41
|
-
updateDetails(details) {
|
|
42
|
-
if (details !== this.details) {
|
|
43
|
-
return new ServerError(this.original_message, this.request, this.status, { ...this.payload, details }, this.displayDetails);
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.ServerError = ServerError;
|
|
51
|
-
class ConnectionError extends RequestError {
|
|
52
|
-
constructor(req, err) {
|
|
53
|
-
super("Failed to connect to server: " + err.message, req, 0, err);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
exports.ConnectionError = ConnectionError;
|
|
57
|
-
//# sourceMappingURL=errors.js.map
|
package/lib/cjs/errors.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":";;;AACA,SAAS,aAAa,CAAC,OAAe,EAAE,OAAgB,EAAE,MAAc,EAAE,OAAY,EAAE,cAAuB;IAC3G,IAAI,GAAG,GAAG,OAAO,CAAC;IAClB,IAAI,cAAc,EAAE,CAAC;QACjB,GAAG,IAAI,aAAa,GAAG,OAAO,CAAC,MAAM,GAAG,GAAG,GAAG,OA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ArBD,oCAqBC;AAED,MAAa,WAAY,SAAQ,YAAY;IACzC,YAAY,OAAe,EAAE,GAAY,EAAE,MAAc,EAAE,OAAY,EAAE,cAAc,GAAG,IAAI;QAC1F,KAAK,CAAC,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;IACzD,CAAC;IAED,aAAa,CAAC,OAAY;QACtB,IAAI,OAAO,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;YAC3B,OAAO,IAAI,WAAW,CAAC,IAAI,CAAC,gBAAgB,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,CAAC,cAAc,CAAC,CAAA;QAC/H,CAAC;aAAM,CAAC;YACJ,OAAO,IAAI,CAAC;QAChB,CAAC;IACL,CAAC;CACJ;AAZD,kCAYC;AAED,MAAa,eAAgB,SAAQ,YAAY;IAC7C,YAAY,GAAY,EAAE,GAAU;QAChC,KAAK,CAAC,+BAA+B,GAAG,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;IACtE,CAAC;CACJ;AAJD,0CAIC"}
|
package/lib/cjs/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./base.js"), exports);
|
|
18
|
-
__exportStar(require("./client.js"), exports);
|
|
19
|
-
__exportStar(require("./errors.js"), exports);
|
|
20
|
-
__exportStar(require("./sse/index.js"), exports);
|
|
21
|
-
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,8CAA4B;AAC5B,8CAA4B;AAC5B,iDAA+B"}
|
package/lib/cjs/package.json
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EventSourceParserStream = void 0;
|
|
4
|
-
const eventsource_parser_1 = require("eventsource-parser");
|
|
5
|
-
/**
|
|
6
|
-
* We copied this file from the eventsource-parser/stream package and made it a part of our project.
|
|
7
|
-
* because importing the eventsource-parser/stream breaks tsc build when buuilding the commonjs version
|
|
8
|
-
* see for a similar error:
|
|
9
|
-
* https://stackoverflow.com/questions/77280140/why-typescript-dont-see-exports-of-package-with-module-commonjs-and-moduleres
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* A TransformStream that ingests a stream of strings and produces a stream of ParsedEvents.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```
|
|
16
|
-
* const eventStream =
|
|
17
|
-
* response.body
|
|
18
|
-
* .pipeThrough(new TextDecoderStream())
|
|
19
|
-
* .pipeThrough(new EventSourceParserStream())
|
|
20
|
-
* ```
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
|
-
class EventSourceParserStream extends TransformStream {
|
|
24
|
-
constructor() {
|
|
25
|
-
let parser;
|
|
26
|
-
super({
|
|
27
|
-
start(controller) {
|
|
28
|
-
parser = (0, eventsource_parser_1.createParser)((event) => {
|
|
29
|
-
if (event.type === 'event') {
|
|
30
|
-
controller.enqueue(event);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
},
|
|
34
|
-
transform(chunk) {
|
|
35
|
-
parser.feed(chunk);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.EventSourceParserStream = EventSourceParserStream;
|
|
41
|
-
//# sourceMappingURL=EventSourceParserStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"EventSourceParserStream.js","sourceRoot":"","sources":["../../../src/sse/EventSourceParserStream.ts"],"names":[],"mappings":";;;AAAA,2DAA8G;AAE9G;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AACH,MAAa,uBAAwB,SAAQ,eAAoC;IAC7E;QACI,IAAI,MAA0B,CAAA;QAE9B,KAAK,CAAC;YACF,KAAK,CAAC,UAAU;gBACZ,MAAM,GAAG,IAAA,iCAAY,EAAC,CAAC,KAAsC,EAAE,EAAE;oBAC7D,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;wBACzB,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;oBAC7B,CAAC;gBACL,CAAC,CAAC,CAAA;YACN,CAAC;YACD,SAAS,CAAC,KAAK;gBACX,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;YACtB,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;CACJ;AAjBD,0DAiBC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextDecoderStream = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Decode a stream of bytes into a stream of characters.
|
|
6
|
-
* Some javascript env like Bun.js doesn't supports the TextDecoderStream (as for jan 2024)
|
|
7
|
-
* This is a polyfill for bunjs
|
|
8
|
-
*/
|
|
9
|
-
let _TextDecoderStream;
|
|
10
|
-
if (globalThis.TextDecoderStream && typeof globalThis.TextDecoderStream === 'function') {
|
|
11
|
-
exports.TextDecoderStream = _TextDecoderStream = globalThis.TextDecoderStream;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
class MyTextDecoderStream extends TransformStream {
|
|
15
|
-
constructor(encoding = "utf-8", { fatal = false, ignoreBOM = false } = {}) {
|
|
16
|
-
super(new TextDecodeTransformer(new TextDecoder(encoding, { fatal, ignoreBOM })));
|
|
17
|
-
this._options = { fatal, ignoreBOM, encoding };
|
|
18
|
-
}
|
|
19
|
-
get encoding() {
|
|
20
|
-
return this._options.encoding;
|
|
21
|
-
}
|
|
22
|
-
get fatal() {
|
|
23
|
-
return this._options.fatal;
|
|
24
|
-
}
|
|
25
|
-
get ignoreBOM() {
|
|
26
|
-
return this._options.ignoreBOM;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
class TextDecodeTransformer {
|
|
30
|
-
constructor(decoder) {
|
|
31
|
-
this.decoder = decoder;
|
|
32
|
-
}
|
|
33
|
-
transform(chunk, controller) {
|
|
34
|
-
if (!(chunk instanceof ArrayBuffer || ArrayBuffer.isView(chunk))) {
|
|
35
|
-
throw new TypeError("Input must be a compatible with: ArrayBuffer | Uint8Array");
|
|
36
|
-
}
|
|
37
|
-
const text = this.decoder.decode(chunk, { stream: true });
|
|
38
|
-
if (text.length !== 0) {
|
|
39
|
-
controller.enqueue(text);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
flush(controller) {
|
|
43
|
-
const text = this.decoder.decode();
|
|
44
|
-
if (text.length !== 0) {
|
|
45
|
-
controller.enqueue(text);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.TextDecoderStream = _TextDecoderStream = MyTextDecoderStream;
|
|
50
|
-
}
|
|
51
|
-
//# sourceMappingURL=TextDecoderStream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TextDecoderStream.js","sourceRoot":"","sources":["../../../src/sse/TextDecoderStream.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,IAAI,kBAA4C,CAAC;AACjD,IAAI,UAAU,CAAC,iBAAiB,IAAI,OAAO,UAAU,CAAC,iBAAiB,KAAK,UAAU,EAAE,CAAC;IACrF,4BAAA,kBAAkB,GAAG,UAAU,CAAC,iBAAiB,CAAC;AACtD,CAAC;KAAM,CAAC;IACJ,MAAM,mBAAoB,SAAQ,eAAiD;QAM/E,YAAY,QAAQ,GAAG,OAAO,EAAE,EAAE,KAAK,GAAG,KAAK,EAAE,SAAS,GAAG,KAAK,KAG9D,EAAE;YACF,KAAK,CAAC,IAAI,qBAAqB,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC;YAClF,IAAI,CAAC,QAAQ,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC;QACnD,CAAC;QAED,IAAI,QAAQ;YACR,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAClC,CAAC;QACD,IAAI,KAAK;YACL,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC/B,CAAC;QACD,IAAI,SAAS;YACT,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC;QACnC,CAAC;KACJ;IACD,MAAM,qBAAqB;QAGvB,YAAY,OAAoB;YAC5B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAC3B,CAAC;QAED,SAAS,CAAC,KAA+B,EAAE,UAAoD;YAC3F,IAAI,CAAC,CAAC,KAAK,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBAC/D,MAAM,IAAI,SAAS,CAAC,2DAA2D,CAAC,CAAC;YACrF,CAAC;YACD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1D,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7B,CAAC;QACL,CAAC;QAED,KAAK,CAAC,UAAoD;YACtD,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACnC,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpB,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC7B,CAAC;QACL,CAAC;KACJ;IACD,4BAAA,kBAAkB,GAAG,mBAA0B,CAAC;AACpD,CAAC"}
|
package/lib/cjs/sse/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TextDecoderStream = void 0;
|
|
4
|
-
exports.sse = sse;
|
|
5
|
-
const TextDecoderStream_js_1 = require("./TextDecoderStream.js");
|
|
6
|
-
Object.defineProperty(exports, "TextDecoderStream", { enumerable: true, get: function () { return TextDecoderStream_js_1.TextDecoderStream; } });
|
|
7
|
-
const EventSourceParserStream_js_1 = require("./EventSourceParserStream.js");
|
|
8
|
-
/**
|
|
9
|
-
* A SSE response reader.
|
|
10
|
-
* Usage client.get('/path', {reader: sse}) or client.post('/path', {reader: sse})
|
|
11
|
-
* where sse is this function
|
|
12
|
-
* @param response
|
|
13
|
-
* @returns
|
|
14
|
-
*/
|
|
15
|
-
async function sse(response) {
|
|
16
|
-
if (!response.ok) {
|
|
17
|
-
const text = await response.text();
|
|
18
|
-
const error = new Error("SSE error: " + response.status + ". Content:\n" + text);
|
|
19
|
-
error.status = response.status;
|
|
20
|
-
throw error;
|
|
21
|
-
}
|
|
22
|
-
if (!response.body) {
|
|
23
|
-
throw new Error('No body in response');
|
|
24
|
-
}
|
|
25
|
-
return response.body.pipeThrough(new TextDecoderStream_js_1.TextDecoderStream()).pipeThrough(new EventSourceParserStream_js_1.EventSourceParserStream());
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=index.js.map
|
package/lib/cjs/sse/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sse/index.ts"],"names":[],"mappings":";;;AAYA,kBAWC;AAvBD,iEAA2D;AA0BlD,kGA1BA,wCAAiB,OA0BA;AAzB1B,6EAAuE;AAIvE;;;;;;GAMG;AACI,KAAK,UAAU,GAAG,CAAC,QAAkB;IACxC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACf,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,aAAa,GAAG,QAAQ,CAAC,MAAM,GAAG,cAAc,GAAG,IAAI,CAAC,CAAC;QAChF,KAAa,CAAC,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;QACxC,MAAM,KAAK,CAAC;IAChB,CAAC;IACD,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,wCAAiB,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI,oDAAuB,EAAE,CAAC,CAAC;AACzG,CAAC"}
|