api-def 0.12.0 → 0.13.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/README.md +3 -0
- package/bin/index.js +312 -313
- package/cjs/Api.d.ts +6 -6
- package/cjs/Api.js +99 -143
- package/cjs/ApiTypes.d.ts +1 -1
- package/cjs/ApiUtils.d.ts +2 -1
- package/cjs/ApiUtils.js +41 -33
- package/cjs/Endpoint.d.ts +1 -1
- package/cjs/Endpoint.js +112 -175
- package/cjs/EndpointBuilder.js +23 -32
- package/cjs/QueryHandling.js +12 -13
- package/cjs/RequestConfig.js +54 -36
- package/cjs/RequestContext.d.ts +1 -1
- package/cjs/RequestContext.js +125 -180
- package/cjs/RequestError.js +16 -19
- package/cjs/Requester.js +230 -312
- package/cjs/TextDecoding.js +31 -31
- package/cjs/Utils.js +20 -23
- package/cjs/backend/AxiosRequestBackend.d.ts +1 -1
- package/cjs/backend/AxiosRequestBackend.js +65 -172
- package/cjs/backend/FetchRequestBackend.d.ts +1 -1
- package/cjs/backend/FetchRequestBackend.js +108 -154
- package/cjs/backend/MockRequestBackend.d.ts +1 -1
- package/cjs/backend/MockRequestBackend.js +146 -208
- package/cjs/cache/ClientCaching.js +26 -74
- package/cjs/cache/LocalForageClientCacheBackend.js +15 -83
- package/cjs/cache/LocalStorageClientCacheBackend.js +14 -73
- package/cjs/index.d.ts +11 -11
- package/cjs/index.js +24 -21
- package/cjs/middleware/ClientCacheMiddleware.js +80 -103
- package/cjs/middleware/LoggingMiddleware.js +71 -42
- package/cjs/util/retry/index.js +42 -9
- package/cjs/util/retry/lib/retry.js +25 -27
- package/cjs/util/retry/lib/retryOperation.d.ts +1 -26
- package/cjs/util/retry/lib/retryOperation.js +21 -23
- package/esm/Api.d.ts +11 -11
- package/esm/Api.js +12 -23
- package/esm/ApiConstants.d.ts +1 -1
- package/esm/ApiTypes.d.ts +5 -5
- package/esm/ApiUtils.d.ts +4 -3
- package/esm/ApiUtils.js +15 -7
- package/esm/Endpoint.d.ts +6 -6
- package/esm/Endpoint.js +22 -28
- package/esm/EndpointBuilder.d.ts +4 -4
- package/esm/EndpointBuilder.js +2 -2
- package/esm/MockingTypes.d.ts +1 -1
- package/esm/QueryHandling.d.ts +1 -1
- package/esm/QueryHandling.js +2 -3
- package/esm/RequestConfig.d.ts +1 -1
- package/esm/RequestConfig.js +6 -7
- package/esm/RequestContext.d.ts +7 -7
- package/esm/RequestContext.js +15 -27
- package/esm/RequestError.d.ts +3 -3
- package/esm/RequestError.js +2 -3
- package/esm/Requester.d.ts +2 -2
- package/esm/Requester.js +44 -50
- package/esm/UtilTypes.d.ts +1 -1
- package/esm/Utils.js +2 -1
- package/esm/Validation.d.ts +1 -1
- package/esm/backend/AxiosRequestBackend.d.ts +4 -4
- package/esm/backend/AxiosRequestBackend.js +47 -84
- package/esm/backend/FetchRequestBackend.d.ts +5 -5
- package/esm/backend/FetchRequestBackend.js +49 -63
- package/esm/backend/MockRequestBackend.d.ts +4 -4
- package/esm/backend/MockRequestBackend.js +105 -136
- package/esm/backend/RequestBackend.d.ts +2 -2
- package/esm/cache/ClientCaching.d.ts +1 -1
- package/esm/cache/ClientCaching.js +8 -17
- package/esm/cache/LocalForageClientCacheBackend.d.ts +1 -1
- package/esm/cache/LocalForageClientCacheBackend.js +8 -25
- package/esm/cache/LocalStorageClientCacheBackend.d.ts +1 -1
- package/esm/cache/LocalStorageClientCacheBackend.js +9 -26
- package/esm/index.d.ts +16 -16
- package/esm/index.js +15 -15
- package/esm/middleware/ClientCacheMiddleware.d.ts +1 -1
- package/esm/middleware/ClientCacheMiddleware.js +8 -17
- package/esm/middleware/LoggingMiddleware.d.ts +1 -1
- package/esm/middleware/LoggingMiddleware.js +5 -6
- package/esm/util/retry/index.js +1 -1
- package/esm/util/retry/lib/retry.d.ts +1 -1
- package/esm/util/retry/lib/retry.js +13 -7
- package/esm/util/retry/lib/retryOperation.d.ts +1 -26
- package/esm/util/retry/lib/retryOperation.js +1 -1
- package/package.json +66 -28
|
@@ -1,77 +1,18 @@
|
|
|
1
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
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
3
|
+
class LocalStorageClientCacheBackend {
|
|
4
|
+
async getItem(key) {
|
|
5
|
+
const item = localStorage.getItem(key);
|
|
6
|
+
return item ? JSON.parse(item) : null;
|
|
7
|
+
}
|
|
8
|
+
async setItem(key, value) {
|
|
9
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
10
|
+
}
|
|
11
|
+
async removeItem(key) {
|
|
12
|
+
localStorage.removeItem(key);
|
|
13
|
+
}
|
|
14
|
+
async clear() {
|
|
15
|
+
localStorage.clear();
|
|
41
16
|
}
|
|
42
|
-
|
|
43
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
44
|
-
var item;
|
|
45
|
-
return __generator(this, function (_a) {
|
|
46
|
-
item = localStorage.getItem(key);
|
|
47
|
-
return [2 /*return*/, item ? JSON.parse(item) : null];
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
LocalStorageClientCacheBackend.prototype.setItem = function (key, value) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
53
|
-
return __generator(this, function (_a) {
|
|
54
|
-
localStorage.setItem(key, JSON.stringify(value));
|
|
55
|
-
return [2 /*return*/];
|
|
56
|
-
});
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
LocalStorageClientCacheBackend.prototype.removeItem = function (key) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
-
return __generator(this, function (_a) {
|
|
62
|
-
localStorage.removeItem(key);
|
|
63
|
-
return [2 /*return*/];
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
LocalStorageClientCacheBackend.prototype.clear = function () {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
69
|
-
return __generator(this, function (_a) {
|
|
70
|
-
localStorage.clear();
|
|
71
|
-
return [2 /*return*/];
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
return LocalStorageClientCacheBackend;
|
|
76
|
-
}());
|
|
17
|
+
}
|
|
77
18
|
exports.default = LocalStorageClientCacheBackend;
|
package/cjs/index.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
export * from "./Api";
|
|
2
|
-
export * from "./ApiTypes";
|
|
3
|
-
export * from "./UtilTypes";
|
|
4
2
|
export * from "./ApiConstants";
|
|
5
|
-
export
|
|
6
|
-
export type { RetryOptions } from "./util/retry/interfaces";
|
|
7
|
-
export { isRequestError, getErrorResponse, type RequestError } from "./RequestError";
|
|
8
|
-
export { default as Endpoint, type EndpointConfig } from "./Endpoint";
|
|
9
|
-
export { default as EndpointBuilder, type EndpointBuildOptions } from "./EndpointBuilder";
|
|
10
|
-
export { clearClientCache, setClientCacheBackend } from "./cache/ClientCaching";
|
|
11
|
-
export { default as LocalStorageClientCacheBackend } from "./cache/LocalStorageClientCacheBackend";
|
|
12
|
-
export { default as LocalForageClientCacheBackend } from "./cache/LocalForageClientCacheBackend";
|
|
13
|
-
export { default as RequestBackend } from "./backend/RequestBackend";
|
|
3
|
+
export * from "./ApiTypes";
|
|
14
4
|
export { default as AxiosRequestBackend } from "./backend/AxiosRequestBackend";
|
|
15
5
|
export { default as FetchRequestBackend } from "./backend/FetchRequestBackend";
|
|
6
|
+
export { default as RequestBackend } from "./backend/RequestBackend";
|
|
7
|
+
export { clearClientCache, setClientCacheBackend } from "./cache/ClientCaching";
|
|
8
|
+
export { default as LocalForageClientCacheBackend } from "./cache/LocalForageClientCacheBackend";
|
|
9
|
+
export { default as LocalStorageClientCacheBackend } from "./cache/LocalStorageClientCacheBackend";
|
|
10
|
+
export { default as Endpoint, type EndpointConfig } from "./Endpoint";
|
|
11
|
+
export { default as EndpointBuilder, type EndpointBuildOptions } from "./EndpointBuilder";
|
|
16
12
|
export { default as ClientCacheMiddleware } from "./middleware/ClientCacheMiddleware";
|
|
17
13
|
export { default as LoggingMiddleware } from "./middleware/LoggingMiddleware";
|
|
14
|
+
export { getErrorResponse, isRequestError, type RequestError } from "./RequestError";
|
|
15
|
+
export * from "./UtilTypes";
|
|
16
|
+
export { default as retry } from "./util/retry";
|
|
17
|
+
export type { RetryOptions } from "./util/retry/interfaces";
|
package/cjs/index.js
CHANGED
|
@@ -14,33 +14,36 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
14
14
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
|
+
};
|
|
17
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.
|
|
21
|
+
exports.retry = exports.isRequestError = exports.getErrorResponse = exports.LoggingMiddleware = exports.ClientCacheMiddleware = exports.EndpointBuilder = exports.Endpoint = exports.LocalStorageClientCacheBackend = exports.LocalForageClientCacheBackend = exports.setClientCacheBackend = exports.clearClientCache = exports.FetchRequestBackend = exports.AxiosRequestBackend = void 0;
|
|
19
22
|
__exportStar(require("./Api"), exports);
|
|
20
|
-
__exportStar(require("./ApiTypes"), exports);
|
|
21
|
-
__exportStar(require("./UtilTypes"), exports);
|
|
22
23
|
__exportStar(require("./ApiConstants"), exports);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Object.defineProperty(exports, "
|
|
28
|
-
var Endpoint_1 = require("./Endpoint");
|
|
29
|
-
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return Endpoint_1.default; } });
|
|
30
|
-
var EndpointBuilder_1 = require("./EndpointBuilder");
|
|
31
|
-
Object.defineProperty(exports, "EndpointBuilder", { enumerable: true, get: function () { return EndpointBuilder_1.default; } });
|
|
24
|
+
__exportStar(require("./ApiTypes"), exports);
|
|
25
|
+
var AxiosRequestBackend_1 = require("./backend/AxiosRequestBackend");
|
|
26
|
+
Object.defineProperty(exports, "AxiosRequestBackend", { enumerable: true, get: function () { return __importDefault(AxiosRequestBackend_1).default; } });
|
|
27
|
+
var FetchRequestBackend_1 = require("./backend/FetchRequestBackend");
|
|
28
|
+
Object.defineProperty(exports, "FetchRequestBackend", { enumerable: true, get: function () { return __importDefault(FetchRequestBackend_1).default; } });
|
|
32
29
|
var ClientCaching_1 = require("./cache/ClientCaching");
|
|
33
30
|
Object.defineProperty(exports, "clearClientCache", { enumerable: true, get: function () { return ClientCaching_1.clearClientCache; } });
|
|
34
31
|
Object.defineProperty(exports, "setClientCacheBackend", { enumerable: true, get: function () { return ClientCaching_1.setClientCacheBackend; } });
|
|
35
|
-
var LocalStorageClientCacheBackend_1 = require("./cache/LocalStorageClientCacheBackend");
|
|
36
|
-
Object.defineProperty(exports, "LocalStorageClientCacheBackend", { enumerable: true, get: function () { return LocalStorageClientCacheBackend_1.default; } });
|
|
37
32
|
var LocalForageClientCacheBackend_1 = require("./cache/LocalForageClientCacheBackend");
|
|
38
|
-
Object.defineProperty(exports, "LocalForageClientCacheBackend", { enumerable: true, get: function () { return LocalForageClientCacheBackend_1.default; } });
|
|
39
|
-
var
|
|
40
|
-
Object.defineProperty(exports, "
|
|
41
|
-
var
|
|
42
|
-
Object.defineProperty(exports, "
|
|
33
|
+
Object.defineProperty(exports, "LocalForageClientCacheBackend", { enumerable: true, get: function () { return __importDefault(LocalForageClientCacheBackend_1).default; } });
|
|
34
|
+
var LocalStorageClientCacheBackend_1 = require("./cache/LocalStorageClientCacheBackend");
|
|
35
|
+
Object.defineProperty(exports, "LocalStorageClientCacheBackend", { enumerable: true, get: function () { return __importDefault(LocalStorageClientCacheBackend_1).default; } });
|
|
36
|
+
var Endpoint_1 = require("./Endpoint");
|
|
37
|
+
Object.defineProperty(exports, "Endpoint", { enumerable: true, get: function () { return __importDefault(Endpoint_1).default; } });
|
|
38
|
+
var EndpointBuilder_1 = require("./EndpointBuilder");
|
|
39
|
+
Object.defineProperty(exports, "EndpointBuilder", { enumerable: true, get: function () { return __importDefault(EndpointBuilder_1).default; } });
|
|
43
40
|
var ClientCacheMiddleware_1 = require("./middleware/ClientCacheMiddleware");
|
|
44
|
-
Object.defineProperty(exports, "ClientCacheMiddleware", { enumerable: true, get: function () { return ClientCacheMiddleware_1.default; } });
|
|
41
|
+
Object.defineProperty(exports, "ClientCacheMiddleware", { enumerable: true, get: function () { return __importDefault(ClientCacheMiddleware_1).default; } });
|
|
45
42
|
var LoggingMiddleware_1 = require("./middleware/LoggingMiddleware");
|
|
46
|
-
Object.defineProperty(exports, "LoggingMiddleware", { enumerable: true, get: function () { return LoggingMiddleware_1.default; } });
|
|
43
|
+
Object.defineProperty(exports, "LoggingMiddleware", { enumerable: true, get: function () { return __importDefault(LoggingMiddleware_1).default; } });
|
|
44
|
+
var RequestError_1 = require("./RequestError");
|
|
45
|
+
Object.defineProperty(exports, "getErrorResponse", { enumerable: true, get: function () { return RequestError_1.getErrorResponse; } });
|
|
46
|
+
Object.defineProperty(exports, "isRequestError", { enumerable: true, get: function () { return RequestError_1.isRequestError; } });
|
|
47
|
+
__exportStar(require("./UtilTypes"), exports);
|
|
48
|
+
var retry_1 = require("./util/retry");
|
|
49
|
+
Object.defineProperty(exports, "retry", { enumerable: true, get: function () { return __importDefault(retry_1).default; } });
|
|
@@ -1,109 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
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]; } };
|
|
36
7
|
}
|
|
37
|
-
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
38
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!(clientCache && shouldCache)) return [3 /*break*/, 2];
|
|
76
|
-
if (!clientCache) return [3 /*break*/, 2];
|
|
77
|
-
return [4 /*yield*/, ClientCaching.getClientCachedItem(context.key)];
|
|
78
|
-
case 1:
|
|
79
|
-
cachedValue = _a.sent();
|
|
80
|
-
if (cachedValue) {
|
|
81
|
-
context.stats.cached = {
|
|
82
|
-
is: true,
|
|
83
|
-
by: ApiConstants_1.CacheSource.LOCAL,
|
|
84
|
-
};
|
|
85
|
-
context.cacheInfo.source = ApiConstants_1.CacheSource.LOCAL;
|
|
86
|
-
context.cacheInfo.cached = true;
|
|
87
|
-
return [2 /*return*/, {
|
|
88
|
-
type: ApiConstants_1.EventResultType.RESPOND,
|
|
89
|
-
response: cachedValue,
|
|
90
|
-
}];
|
|
91
|
-
}
|
|
92
|
-
_a.label = 2;
|
|
93
|
-
case 2:
|
|
94
|
-
if (clientCache === false) {
|
|
95
|
-
context.updateQuery({
|
|
96
|
-
_bust: Math.floor(Math.random() * 9000) + 1000,
|
|
97
|
-
});
|
|
98
|
-
context.updateHeaders({
|
|
99
|
-
Pragma: "no-cache, no-store, must-revalidate",
|
|
100
|
-
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
return [2 /*return*/];
|
|
36
|
+
const ApiConstants_1 = require("../ApiConstants");
|
|
37
|
+
const ClientCaching = __importStar(require("../cache/ClientCaching"));
|
|
38
|
+
const ClientCacheMiddleware = (options = {}) => {
|
|
39
|
+
return {
|
|
40
|
+
[ApiConstants_1.RequestEvent.SUCCESS]: async (context) => {
|
|
41
|
+
if (context.method !== ApiConstants_1.RequestMethod.GET)
|
|
42
|
+
return;
|
|
43
|
+
const { clientCache } = context.requestConfig || {};
|
|
44
|
+
const shouldCache = !options.predicate || options.predicate();
|
|
45
|
+
if (clientCache && shouldCache) {
|
|
46
|
+
const expiry = typeof clientCache === "number"
|
|
47
|
+
? clientCache
|
|
48
|
+
: options.defaultExpiry || ClientCaching.DEFAULT_CLIENT_CACHE_EXPIRY;
|
|
49
|
+
await ClientCaching.setClientCachedItem(context.key, context.response, expiry);
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
[ApiConstants_1.RequestEvent.BEFORE_SEND]: async (context) => {
|
|
53
|
+
if (context.method !== ApiConstants_1.RequestMethod.GET)
|
|
54
|
+
return;
|
|
55
|
+
const { clientCache } = context.requestConfig || {};
|
|
56
|
+
const shouldCache = !options.predicate || options.predicate();
|
|
57
|
+
if (clientCache && shouldCache) {
|
|
58
|
+
if (clientCache) {
|
|
59
|
+
const cachedValue = await ClientCaching.getClientCachedItem(context.key);
|
|
60
|
+
if (cachedValue) {
|
|
61
|
+
context.stats.cached = {
|
|
62
|
+
is: true,
|
|
63
|
+
by: ApiConstants_1.CacheSource.LOCAL,
|
|
64
|
+
};
|
|
65
|
+
context.cacheInfo.source = ApiConstants_1.CacheSource.LOCAL;
|
|
66
|
+
context.cacheInfo.cached = true;
|
|
67
|
+
return {
|
|
68
|
+
type: ApiConstants_1.EventResultType.RESPOND,
|
|
69
|
+
response: cachedValue,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
104
72
|
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
73
|
+
}
|
|
74
|
+
if (clientCache === false) {
|
|
75
|
+
context.updateQuery({
|
|
76
|
+
_bust: Math.floor(Math.random() * 9000) + 1000,
|
|
77
|
+
});
|
|
78
|
+
context.updateHeaders({
|
|
79
|
+
Pragma: "no-cache, no-store, must-revalidate",
|
|
80
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
108
85
|
};
|
|
109
86
|
exports.default = ClientCacheMiddleware;
|
|
@@ -1,9 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
3
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
36
|
+
const ApiConstants_1 = require("../ApiConstants");
|
|
37
|
+
const ApiUtils = __importStar(require("../ApiUtils"));
|
|
38
|
+
const Utils = __importStar(require("../Utils"));
|
|
7
39
|
var LogType;
|
|
8
40
|
(function (LogType) {
|
|
9
41
|
LogType[LogType["INFO"] = 0] = "INFO";
|
|
@@ -11,77 +43,74 @@ var LogType;
|
|
|
11
43
|
LogType[LogType["ERROR"] = 2] = "ERROR";
|
|
12
44
|
LogType[LogType["WARNING"] = 3] = "WARNING";
|
|
13
45
|
})(LogType || (LogType = {}));
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
46
|
+
const COLOR_MAP = {
|
|
47
|
+
[LogType.ERROR]: "#c8646c",
|
|
48
|
+
[LogType.INFO]: "#85a6c7",
|
|
49
|
+
[LogType.SUCCESS]: "#a9c490",
|
|
50
|
+
[LogType.WARNING]: "#d19a66",
|
|
51
|
+
};
|
|
52
|
+
const diagnoseError = (error) => {
|
|
21
53
|
if (!error.response) {
|
|
22
54
|
if (ApiUtils.isNetworkError(error)) {
|
|
23
|
-
return { message: "network issue", error
|
|
55
|
+
return { message: "network issue", error };
|
|
24
56
|
}
|
|
25
57
|
if (ApiUtils.isCancelledError(error)) {
|
|
26
|
-
return { message: "cancelled", error
|
|
58
|
+
return { message: "cancelled", error };
|
|
27
59
|
}
|
|
28
|
-
return { message: "client-side error", error
|
|
60
|
+
return { message: "client-side error", error };
|
|
29
61
|
}
|
|
30
|
-
|
|
31
|
-
|
|
62
|
+
const { status, data } = error.response;
|
|
63
|
+
const code = data?.code;
|
|
32
64
|
return {
|
|
33
|
-
message:
|
|
65
|
+
message: `responded with ${status}${code ? ` (${code})` : ""}`,
|
|
34
66
|
response: error.response,
|
|
35
67
|
};
|
|
36
68
|
};
|
|
37
|
-
|
|
38
|
-
return
|
|
69
|
+
const formatTime = (time) => {
|
|
70
|
+
return `${Utils.padNumber(time.getHours(), 2)}:${Utils.padNumber(time.getMinutes(), 2)}:${Utils.padNumber(time.getSeconds(), 2)}.${Utils.padNumber(time.getMilliseconds(), 3)}`;
|
|
39
71
|
};
|
|
40
|
-
|
|
72
|
+
const log = (context, type, message, config, objects) => {
|
|
41
73
|
if (typeof config.predicate === "function" && !config.predicate()) {
|
|
42
74
|
return;
|
|
43
75
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
76
|
+
const color = COLOR_MAP[type];
|
|
77
|
+
const timestamp = formatTime(new Date());
|
|
78
|
+
const args = [
|
|
79
|
+
`%cnetwork %c[${context.api.name}] ${context.method.toUpperCase()} ${context.path} %c${message} %c@ ${timestamp}`,
|
|
48
80
|
"color:gray",
|
|
49
81
|
"color:auto",
|
|
50
|
-
|
|
82
|
+
`color:${color}`,
|
|
51
83
|
"color:gray",
|
|
52
84
|
];
|
|
53
|
-
console.groupCollapsed
|
|
85
|
+
console.groupCollapsed(...args);
|
|
54
86
|
console.log(Utils.assign({ context: context }, objects || {}));
|
|
55
87
|
console.groupEnd();
|
|
56
88
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return _a = {},
|
|
61
|
-
_a[ApiConstants_1.RequestEvent.BEFORE_SEND] = function (context) {
|
|
89
|
+
const LoggingMiddleware = (config = {}) => {
|
|
90
|
+
return {
|
|
91
|
+
[ApiConstants_1.RequestEvent.BEFORE_SEND]: (context) => {
|
|
62
92
|
log(context, LogType.INFO, context.stats.attempt > 1 ? "retrying" : "sending", config);
|
|
63
93
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
log(context, LogType.SUCCESS, "responded with ".concat((_a = context.response) === null || _a === void 0 ? void 0 : _a.status).concat(cacheSource ? " (cached by ".concat(cacheSource, ")") : ""), config);
|
|
94
|
+
[ApiConstants_1.RequestEvent.SUCCESS]: (context) => {
|
|
95
|
+
const cacheSource = context.cacheInfo.source;
|
|
96
|
+
log(context, LogType.SUCCESS, `responded with ${context.response?.status}${cacheSource ? ` (cached by ${cacheSource})` : ""}`, config);
|
|
68
97
|
},
|
|
69
|
-
|
|
98
|
+
[ApiConstants_1.RequestEvent.ERROR]: (context) => {
|
|
70
99
|
if (context.error) {
|
|
71
|
-
|
|
72
|
-
log(context, LogType.WARNING,
|
|
100
|
+
const { error, message } = diagnoseError(context.error);
|
|
101
|
+
log(context, LogType.WARNING, `error on attempt ${context.stats.attempt} - ${message}`, config, {
|
|
73
102
|
error: error,
|
|
74
103
|
});
|
|
75
104
|
}
|
|
76
105
|
},
|
|
77
|
-
|
|
106
|
+
[ApiConstants_1.RequestEvent.UNRECOVERABLE_ERROR]: (context) => {
|
|
78
107
|
if (context.error) {
|
|
79
|
-
|
|
80
|
-
log(context, LogType.ERROR,
|
|
108
|
+
const { error, message } = diagnoseError(context.error);
|
|
109
|
+
log(context, LogType.ERROR, `failed - ${message}`, config, {
|
|
81
110
|
error: error,
|
|
82
111
|
});
|
|
83
112
|
}
|
|
84
113
|
},
|
|
85
|
-
|
|
114
|
+
};
|
|
86
115
|
};
|
|
87
116
|
exports.default = LoggingMiddleware;
|
package/cjs/util/retry/index.js
CHANGED
|
@@ -1,25 +1,58 @@
|
|
|
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
36
|
+
const retrier = __importStar(require("./lib/retry"));
|
|
4
37
|
// Retry is just transplanted from here:
|
|
5
38
|
// https://www.npmjs.com/package/retry (lib), and
|
|
6
39
|
// https://www.npmjs.com/package/async-retry (RetryFunction)
|
|
7
40
|
// ---
|
|
8
|
-
|
|
9
|
-
return new Promise(
|
|
10
|
-
|
|
41
|
+
const retry = (fn, opts) => {
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const options = opts || {};
|
|
11
44
|
if (!("randomize" in options)) {
|
|
12
45
|
options.randomize = true;
|
|
13
46
|
}
|
|
14
|
-
|
|
47
|
+
const op = retrier.operation(options);
|
|
15
48
|
// We allow the user to abort retrying
|
|
16
49
|
// this makes sense in the cases where
|
|
17
50
|
// knowledge is obtained that retrying
|
|
18
51
|
// would be futile (e.g.: auth errors)
|
|
19
|
-
|
|
52
|
+
const bail = (err) => {
|
|
20
53
|
reject(err || new Error("Aborted"));
|
|
21
54
|
};
|
|
22
|
-
|
|
55
|
+
const onError = (err, num) => {
|
|
23
56
|
if (err.bail) {
|
|
24
57
|
bail(err);
|
|
25
58
|
return;
|
|
@@ -31,8 +64,8 @@ var retry = function (fn, opts) {
|
|
|
31
64
|
options.onRetry(err, num);
|
|
32
65
|
}
|
|
33
66
|
};
|
|
34
|
-
|
|
35
|
-
|
|
67
|
+
const runAttempt = (num) => {
|
|
68
|
+
let val;
|
|
36
69
|
try {
|
|
37
70
|
val = fn(bail, num);
|
|
38
71
|
}
|