ag-common 0.0.439 → 0.0.441
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/dist/common/helpers/stream.d.ts +1 -0
- package/dist/common/helpers/stream.js +40 -0
- package/dist/ui/helpers/callOpenApi/direct.js +13 -12
- package/dist/ui/helpers/callOpenApi/helpers.d.ts +1 -1
- package/dist/ui/helpers/callOpenApi/helpers.js +15 -4
- package/dist/ui/helpers/callOpenApi/types.d.ts +1 -1
- package/dist/ui/helpers/jwt.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getStringFromStream(stream: ReadableStream<Uint8Array | Uint32Array>): Promise<string>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.getStringFromStream = void 0;
|
|
13
|
+
const log_1 = require("./log");
|
|
14
|
+
function getStringFromStream(stream) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
const decoder = new TextDecoder();
|
|
17
|
+
const reader = stream.getReader();
|
|
18
|
+
let result = '';
|
|
19
|
+
try {
|
|
20
|
+
// eslint-disable-next-line no-constant-condition
|
|
21
|
+
while (true) {
|
|
22
|
+
const { done, value } = yield reader.read();
|
|
23
|
+
if (done)
|
|
24
|
+
break;
|
|
25
|
+
// Convert the Uint8Array chunk to a string
|
|
26
|
+
const chunkString = decoder.decode(value);
|
|
27
|
+
// Append the chunk to the final result
|
|
28
|
+
result += chunkString;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
(0, log_1.error)('error converting stream');
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
reader.releaseLock();
|
|
36
|
+
}
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
exports.getStringFromStream = getStringFromStream;
|
|
@@ -10,7 +10,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.callOpenApi = exports.getIdTokenAuthHeaderRaw = void 0;
|
|
13
|
-
const axios_1 = require("axios");
|
|
14
13
|
const const_1 = require("../../../common/const");
|
|
15
14
|
const array_1 = require("../../../common/helpers/array");
|
|
16
15
|
const sleep_1 = require("../../../common/helpers/sleep");
|
|
@@ -59,7 +58,7 @@ function getIdTokenAuthHeader({ overrideAuth, refreshToken, }) {
|
|
|
59
58
|
});
|
|
60
59
|
}
|
|
61
60
|
const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q
|
|
61
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
|
|
63
62
|
const { func, apiUrl, logout, newDefaultApi, headers } = p;
|
|
64
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
64
|
let error;
|
|
@@ -94,28 +93,29 @@ const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
94
93
|
errorCount += 1;
|
|
95
94
|
try {
|
|
96
95
|
// eslint-disable-next-line no-await-in-loop
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
99
|
-
data =
|
|
96
|
+
const response = yield func(cl);
|
|
97
|
+
if (response.status < 400) {
|
|
98
|
+
data = response.data;
|
|
100
99
|
break;
|
|
101
100
|
}
|
|
102
|
-
throw
|
|
101
|
+
throw { response };
|
|
103
102
|
}
|
|
104
103
|
catch (e) {
|
|
105
104
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
106
105
|
const ae = e;
|
|
107
|
-
const status = Number((
|
|
106
|
+
const status = Number((_c = (_a = ae.code) !== null && _a !== void 0 ? _a : (_b = ae.response) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : 500);
|
|
108
107
|
const errorMessage = [
|
|
109
|
-
(
|
|
108
|
+
(_d = ae.status) !== null && _d !== void 0 ? _d : '',
|
|
110
109
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
111
|
-
(
|
|
112
|
-
(
|
|
113
|
-
(
|
|
114
|
-
(
|
|
110
|
+
(_g = (_f = (_e = ae.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : '',
|
|
111
|
+
(_k = (_j = (_h = ae.response) === null || _h === void 0 ? void 0 : _h.statusText) === null || _j === void 0 ? void 0 : _j.toString()) !== null && _k !== void 0 ? _k : '',
|
|
112
|
+
(_o = (_m = (_l = ae.response) === null || _l === void 0 ? void 0 : _l.status) === null || _m === void 0 ? void 0 : _m.toString()) !== null && _o !== void 0 ? _o : '',
|
|
113
|
+
(_q = (_p = ae.message) === null || _p === void 0 ? void 0 : _p.toString()) !== null && _q !== void 0 ? _q : '',
|
|
115
114
|
]
|
|
116
115
|
.filter(array_1.notEmpty)
|
|
117
116
|
.sort((a, b) => (a.length < b.length ? -1 : 1))
|
|
118
117
|
.join('\n');
|
|
118
|
+
//if auth fail, then quick exit
|
|
119
119
|
if (status === 403 || status === 401) {
|
|
120
120
|
logout();
|
|
121
121
|
return {
|
|
@@ -123,6 +123,7 @@ const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
123
123
|
data: undefined,
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
|
+
//if not a potential retriable error, or have retried enough, then exit
|
|
126
127
|
if (!const_1.retryHttpCodes.includes(status) || errorCount === errorMax) {
|
|
127
128
|
error = Object.assign(Object.assign({}, ae), { message: errorMessage });
|
|
128
129
|
break;
|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.apiResponseToAxiosResponse = void 0;
|
|
13
13
|
const array_1 = require("../../../common/helpers/array");
|
|
14
|
+
const stream_1 = require("../../../common/helpers/stream");
|
|
14
15
|
/**
|
|
15
16
|
* shim to convert raw response to an axios style response.
|
|
16
17
|
* must convert all DefaultClass requests to the Raw equivalent
|
|
@@ -30,18 +31,28 @@ const apiResponseToAxiosResponse = (p) => __awaiter(void 0, void 0, void 0, func
|
|
|
30
31
|
};
|
|
31
32
|
return r1;
|
|
32
33
|
}))
|
|
33
|
-
.catch((e) => {
|
|
34
|
+
.catch((e) => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
35
|
const er = e;
|
|
36
|
+
//try and get body
|
|
37
|
+
let statusText = er.statusText;
|
|
38
|
+
if (er.body) {
|
|
39
|
+
try {
|
|
40
|
+
const st = yield (0, stream_1.getStringFromStream)(er.body);
|
|
41
|
+
statusText = st;
|
|
42
|
+
}
|
|
43
|
+
catch (e) {
|
|
44
|
+
//
|
|
45
|
+
}
|
|
46
|
+
}
|
|
35
47
|
const ret = {
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
48
|
data: undefined,
|
|
38
49
|
status: er.status,
|
|
39
|
-
statusText
|
|
50
|
+
statusText,
|
|
40
51
|
headers: (0, array_1.arrayToObject)(Object.entries(er.headers), (s) => s[0], (s) => s[1]),
|
|
41
52
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
53
|
config: {},
|
|
43
54
|
};
|
|
44
55
|
return ret;
|
|
45
|
-
});
|
|
56
|
+
}));
|
|
46
57
|
});
|
|
47
58
|
exports.apiResponseToAxiosResponse = apiResponseToAxiosResponse;
|
package/dist/ui/helpers/jwt.d.ts
CHANGED
package/package.json
CHANGED