@emilgroup/billing-v2-sdk 0.0.0-stage → 1.0.1-beta.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/.openapi-generator/FILES +93 -0
- package/.openapi-generator/VERSION +1 -0
- package/.openapi-generator-ignore +23 -0
- package/README.md +50 -2
- package/api/bill-runs-api.ts +468 -0
- package/api/bills-api.ts +145 -0
- package/api/invoices-api.ts +1530 -0
- package/api/jobs-api.ts +756 -0
- package/api/policy-billings-api.ts +591 -0
- package/api.ts +35 -0
- package/base.ts +588 -0
- package/common.ts +199 -0
- package/configuration.ts +130 -0
- package/dist/api/bill-runs-api.d.ts +266 -0
- package/dist/api/bill-runs-api.js +466 -0
- package/dist/api/bills-api.d.ts +87 -0
- package/dist/api/bills-api.js +207 -0
- package/dist/api/invoices-api.d.ts +847 -0
- package/dist/api/invoices-api.js +1353 -0
- package/dist/api/jobs-api.d.ts +426 -0
- package/dist/api/jobs-api.js +708 -0
- package/dist/api/policy-billings-api.d.ts +332 -0
- package/dist/api/policy-billings-api.js +561 -0
- package/dist/api.d.ts +16 -0
- package/dist/api.js +34 -0
- package/dist/base.d.ts +120 -0
- package/dist/base.js +604 -0
- package/dist/common.d.ts +91 -0
- package/dist/common.js +277 -0
- package/dist/configuration.d.ts +106 -0
- package/dist/configuration.js +54 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +36 -0
- package/dist/models/any.d.ts +25 -0
- package/dist/models/any.js +15 -0
- package/dist/models/bill-item.d.ts +132 -0
- package/dist/models/bill-item.js +15 -0
- package/dist/models/bill-run.d.ts +145 -0
- package/dist/models/bill-run.js +15 -0
- package/dist/models/bill.d.ts +194 -0
- package/dist/models/bill.js +15 -0
- package/dist/models/cancel-job-response.d.ts +25 -0
- package/dist/models/cancel-job-response.js +15 -0
- package/dist/models/create-correction-invoices-request.d.ts +72 -0
- package/dist/models/create-correction-invoices-request.js +15 -0
- package/dist/models/create-correction-invoices-response.d.ts +31 -0
- package/dist/models/create-correction-invoices-response.js +15 -0
- package/dist/models/create-detail-export-job-request.d.ts +56 -0
- package/dist/models/create-detail-export-job-request.js +15 -0
- package/dist/models/create-detail-export-job-response.d.ts +25 -0
- package/dist/models/create-detail-export-job-response.js +15 -0
- package/dist/models/create-estimated-invoice-for-interval-request.d.ts +42 -0
- package/dist/models/create-estimated-invoice-for-interval-request.js +15 -0
- package/dist/models/create-estimated-invoice-for-interval-response.d.ts +25 -0
- package/dist/models/create-estimated-invoice-for-interval-response.js +15 -0
- package/dist/models/create-estimated-invoice-request.d.ts +36 -0
- package/dist/models/create-estimated-invoice-request.js +15 -0
- package/dist/models/create-estimated-invoice-response.d.ts +25 -0
- package/dist/models/create-estimated-invoice-response.js +15 -0
- package/dist/models/create-export-job-request.d.ts +68 -0
- package/dist/models/create-export-job-request.js +15 -0
- package/dist/models/create-export-job-response.d.ts +25 -0
- package/dist/models/create-export-job-response.js +15 -0
- package/dist/models/create-initial-invoice-request.d.ts +72 -0
- package/dist/models/create-initial-invoice-request.js +15 -0
- package/dist/models/create-initial-invoice-response.d.ts +25 -0
- package/dist/models/create-initial-invoice-response.js +15 -0
- package/dist/models/create-invoice-request.d.ts +67 -0
- package/dist/models/create-invoice-request.js +15 -0
- package/dist/models/create-invoice-response.d.ts +25 -0
- package/dist/models/create-invoice-response.js +15 -0
- package/dist/models/create-invoice-status-body.d.ts +24 -0
- package/dist/models/create-invoice-status-body.js +15 -0
- package/dist/models/create-invoice-status-response.d.ts +25 -0
- package/dist/models/create-invoice-status-response.js +15 -0
- package/dist/models/create-item-request.d.ts +36 -0
- package/dist/models/create-item-request.js +15 -0
- package/dist/models/create-policy-billing-request.d.ts +42 -0
- package/dist/models/create-policy-billing-request.js +15 -0
- package/dist/models/create-policy-billing-response.d.ts +25 -0
- package/dist/models/create-policy-billing-response.js +15 -0
- package/dist/models/create-recurring-invoice-request.d.ts +72 -0
- package/dist/models/create-recurring-invoice-request.js +15 -0
- package/dist/models/create-recurring-invoice-response.d.ts +31 -0
- package/dist/models/create-recurring-invoice-response.js +15 -0
- package/dist/models/create-termination-invoice-request.d.ts +60 -0
- package/dist/models/create-termination-invoice-request.js +15 -0
- package/dist/models/create-termination-invoice-response.d.ts +25 -0
- package/dist/models/create-termination-invoice-response.js +15 -0
- package/dist/models/create-withdraw-invoice-request.d.ts +48 -0
- package/dist/models/create-withdraw-invoice-request.js +15 -0
- package/dist/models/create-withdraw-invoice-response.d.ts +25 -0
- package/dist/models/create-withdraw-invoice-response.js +15 -0
- package/dist/models/estimate-history-entry.d.ts +36 -0
- package/dist/models/estimate-history-entry.js +15 -0
- package/dist/models/export-column.d.ts +36 -0
- package/dist/models/export-column.js +15 -0
- package/dist/models/filter-field.d.ts +110 -0
- package/dist/models/filter-field.js +15 -0
- package/dist/models/filter-value.d.ts +37 -0
- package/dist/models/filter-value.js +15 -0
- package/dist/models/get-bill-response.d.ts +25 -0
- package/dist/models/get-bill-response.js +15 -0
- package/dist/models/get-bill-run-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-bill-run-filter-catalog-response.js +15 -0
- package/dist/models/get-bill-run-response.d.ts +25 -0
- package/dist/models/get-bill-run-response.js +15 -0
- package/dist/models/get-invoice-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-invoice-filter-catalog-response.js +15 -0
- package/dist/models/get-invoice-response.d.ts +25 -0
- package/dist/models/get-invoice-response.js +15 -0
- package/dist/models/get-job-download-response.d.ts +25 -0
- package/dist/models/get-job-download-response.js +15 -0
- package/dist/models/get-job-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-job-filter-catalog-response.js +15 -0
- package/dist/models/get-job-response.d.ts +25 -0
- package/dist/models/get-job-response.js +15 -0
- package/dist/models/get-policies-billing-date-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-policies-billing-date-filter-catalog-response.js +15 -0
- package/dist/models/get-policies-billing-filter-catalog-response.d.ts +31 -0
- package/dist/models/get-policies-billing-filter-catalog-response.js +15 -0
- package/dist/models/get-policy-billing-response.d.ts +25 -0
- package/dist/models/get-policy-billing-response.js +15 -0
- package/dist/models/highlight.d.ts +30 -0
- package/dist/models/highlight.js +15 -0
- package/dist/models/index.d.ts +75 -0
- package/dist/models/index.js +91 -0
- package/dist/models/invoice-item.d.ts +204 -0
- package/dist/models/invoice-item.js +15 -0
- package/dist/models/invoice-payment.d.ts +108 -0
- package/dist/models/invoice-payment.js +15 -0
- package/dist/models/invoice-payments.d.ts +25 -0
- package/dist/models/invoice-payments.js +15 -0
- package/dist/models/invoice-status.d.ts +54 -0
- package/dist/models/invoice-status.js +15 -0
- package/dist/models/invoice.d.ts +275 -0
- package/dist/models/invoice.js +15 -0
- package/dist/models/job-download.d.ts +36 -0
- package/dist/models/job-download.js +15 -0
- package/dist/models/job-error.d.ts +30 -0
- package/dist/models/job-error.js +15 -0
- package/dist/models/job-progress.d.ts +36 -0
- package/dist/models/job-progress.js +15 -0
- package/dist/models/job.d.ts +134 -0
- package/dist/models/job.js +15 -0
- package/dist/models/list-bill-runs-response.d.ts +37 -0
- package/dist/models/list-bill-runs-response.js +15 -0
- package/dist/models/list-invoices-response.d.ts +37 -0
- package/dist/models/list-invoices-response.js +15 -0
- package/dist/models/list-jobs-response.d.ts +37 -0
- package/dist/models/list-jobs-response.js +15 -0
- package/dist/models/list-policies-billing-dates-response.d.ts +37 -0
- package/dist/models/list-policies-billing-dates-response.js +15 -0
- package/dist/models/list-policies-billings-response.d.ts +37 -0
- package/dist/models/list-policies-billings-response.js +15 -0
- package/dist/models/list-request.d.ts +60 -0
- package/dist/models/list-request.js +15 -0
- package/dist/models/localized-text.d.ts +30 -0
- package/dist/models/localized-text.js +15 -0
- package/dist/models/match.d.ts +69 -0
- package/dist/models/match.js +15 -0
- package/dist/models/payment-term.d.ts +42 -0
- package/dist/models/payment-term.js +15 -0
- package/dist/models/policy-billing.d.ts +139 -0
- package/dist/models/policy-billing.js +15 -0
- package/dist/models/request-bill-run-request.d.ts +30 -0
- package/dist/models/request-bill-run-request.js +15 -0
- package/dist/models/request-bill-run-response.d.ts +25 -0
- package/dist/models/request-bill-run-response.js +15 -0
- package/dist/models/resolved-billing-config.d.ts +130 -0
- package/dist/models/resolved-billing-config.js +15 -0
- package/dist/models/revert-invoice-request.d.ts +24 -0
- package/dist/models/revert-invoice-request.js +15 -0
- package/dist/models/revert-invoice-response.d.ts +25 -0
- package/dist/models/revert-invoice-response.js +15 -0
- package/dist/models/slice.d.ts +30 -0
- package/dist/models/slice.js +15 -0
- package/dist/models/status.d.ts +37 -0
- package/dist/models/status.js +15 -0
- package/dist/models/tax.d.ts +30 -0
- package/dist/models/tax.js +15 -0
- package/dist/models/update-policy-billing-body.d.ts +24 -0
- package/dist/models/update-policy-billing-body.js +15 -0
- package/dist/models/update-policy-billing-response.d.ts +25 -0
- package/dist/models/update-policy-billing-response.js +15 -0
- package/git_push.sh +57 -0
- package/index.ts +19 -0
- package/models/any.ts +32 -0
- package/models/bill-item.ts +138 -0
- package/models/bill-run.ts +151 -0
- package/models/bill.ts +200 -0
- package/models/cancel-job-response.ts +31 -0
- package/models/create-correction-invoices-request.ts +78 -0
- package/models/create-correction-invoices-response.ts +37 -0
- package/models/create-detail-export-job-request.ts +60 -0
- package/models/create-detail-export-job-response.ts +31 -0
- package/models/create-estimated-invoice-for-interval-request.ts +48 -0
- package/models/create-estimated-invoice-for-interval-response.ts +31 -0
- package/models/create-estimated-invoice-request.ts +42 -0
- package/models/create-estimated-invoice-response.ts +31 -0
- package/models/create-export-job-request.ts +74 -0
- package/models/create-export-job-response.ts +31 -0
- package/models/create-initial-invoice-request.ts +78 -0
- package/models/create-initial-invoice-response.ts +31 -0
- package/models/create-invoice-request.ts +73 -0
- package/models/create-invoice-response.ts +31 -0
- package/models/create-invoice-status-body.ts +30 -0
- package/models/create-invoice-status-response.ts +31 -0
- package/models/create-item-request.ts +42 -0
- package/models/create-policy-billing-request.ts +48 -0
- package/models/create-policy-billing-response.ts +31 -0
- package/models/create-recurring-invoice-request.ts +78 -0
- package/models/create-recurring-invoice-response.ts +37 -0
- package/models/create-termination-invoice-request.ts +66 -0
- package/models/create-termination-invoice-response.ts +31 -0
- package/models/create-withdraw-invoice-request.ts +54 -0
- package/models/create-withdraw-invoice-response.ts +31 -0
- package/models/estimate-history-entry.ts +42 -0
- package/models/export-column.ts +42 -0
- package/models/filter-field.ts +116 -0
- package/models/filter-value.ts +43 -0
- package/models/get-bill-response.ts +31 -0
- package/models/get-bill-run-filter-catalog-response.ts +37 -0
- package/models/get-bill-run-response.ts +31 -0
- package/models/get-invoice-filter-catalog-response.ts +37 -0
- package/models/get-invoice-response.ts +31 -0
- package/models/get-job-download-response.ts +31 -0
- package/models/get-job-filter-catalog-response.ts +37 -0
- package/models/get-job-response.ts +31 -0
- package/models/get-policies-billing-date-filter-catalog-response.ts +37 -0
- package/models/get-policies-billing-filter-catalog-response.ts +37 -0
- package/models/get-policy-billing-response.ts +31 -0
- package/models/highlight.ts +36 -0
- package/models/index.ts +75 -0
- package/models/invoice-item.ts +210 -0
- package/models/invoice-payment.ts +114 -0
- package/models/invoice-payments.ts +31 -0
- package/models/invoice-status.ts +60 -0
- package/models/invoice.ts +281 -0
- package/models/job-download.ts +42 -0
- package/models/job-error.ts +36 -0
- package/models/job-progress.ts +42 -0
- package/models/job.ts +140 -0
- package/models/list-bill-runs-response.ts +43 -0
- package/models/list-invoices-response.ts +43 -0
- package/models/list-jobs-response.ts +43 -0
- package/models/list-policies-billing-dates-response.ts +43 -0
- package/models/list-policies-billings-response.ts +43 -0
- package/models/list-request.ts +66 -0
- package/models/localized-text.ts +36 -0
- package/models/match.ts +75 -0
- package/models/payment-term.ts +48 -0
- package/models/policy-billing.ts +145 -0
- package/models/request-bill-run-request.ts +36 -0
- package/models/request-bill-run-response.ts +31 -0
- package/models/resolved-billing-config.ts +134 -0
- package/models/revert-invoice-request.ts +30 -0
- package/models/revert-invoice-response.ts +31 -0
- package/models/slice.ts +36 -0
- package/models/status.ts +43 -0
- package/models/tax.ts +36 -0
- package/models/update-policy-billing-body.ts +30 -0
- package/models/update-policy-billing-response.ts +31 -0
- package/package.json +25 -4
- package/tsconfig.json +23 -0
package/dist/base.js
ADDED
|
@@ -0,0 +1,604 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* tslint:disable */
|
|
3
|
+
/* eslint-disable */
|
|
4
|
+
/**
|
|
5
|
+
* EMIL Billing Service
|
|
6
|
+
* The billing service: bills, bill runs, invoices and policy billings.
|
|
7
|
+
*
|
|
8
|
+
* The version of the OpenAPI document: 2.0
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
12
|
+
* https://openapi-generator.tech
|
|
13
|
+
* Do not edit the class manually.
|
|
14
|
+
*/
|
|
15
|
+
var __extends = (this && this.__extends) || (function () {
|
|
16
|
+
var extendStatics = function (d, b) {
|
|
17
|
+
extendStatics = Object.setPrototypeOf ||
|
|
18
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
19
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
20
|
+
return extendStatics(d, b);
|
|
21
|
+
};
|
|
22
|
+
return function (d, b) {
|
|
23
|
+
if (typeof b !== "function" && b !== null)
|
|
24
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
25
|
+
extendStatics(d, b);
|
|
26
|
+
function __() { this.constructor = d; }
|
|
27
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
28
|
+
};
|
|
29
|
+
})();
|
|
30
|
+
var __assign = (this && this.__assign) || function () {
|
|
31
|
+
__assign = Object.assign || function(t) {
|
|
32
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
33
|
+
s = arguments[i];
|
|
34
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
35
|
+
t[p] = s[p];
|
|
36
|
+
}
|
|
37
|
+
return t;
|
|
38
|
+
};
|
|
39
|
+
return __assign.apply(this, arguments);
|
|
40
|
+
};
|
|
41
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
42
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
43
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
44
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
45
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
46
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
47
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
51
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
52
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
53
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
54
|
+
function step(op) {
|
|
55
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
56
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
57
|
+
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;
|
|
58
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
59
|
+
switch (op[0]) {
|
|
60
|
+
case 0: case 1: t = op; break;
|
|
61
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
62
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
63
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
64
|
+
default:
|
|
65
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
66
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
67
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
68
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
69
|
+
if (t[2]) _.ops.pop();
|
|
70
|
+
_.trys.pop(); continue;
|
|
71
|
+
}
|
|
72
|
+
op = body.call(thisArg, _);
|
|
73
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
74
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
78
|
+
var t = {};
|
|
79
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
80
|
+
t[p] = s[p];
|
|
81
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
82
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
83
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
84
|
+
t[p[i]] = s[p[i]];
|
|
85
|
+
}
|
|
86
|
+
return t;
|
|
87
|
+
};
|
|
88
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
89
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
90
|
+
};
|
|
91
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
92
|
+
exports.RequiredError = exports.BaseAPI = exports.resetRetry = exports.Environment = exports.COLLECTION_FORMATS = exports.BASE_PATH = void 0;
|
|
93
|
+
var configuration_1 = require("./configuration");
|
|
94
|
+
var common_1 = require("./common");
|
|
95
|
+
// Some imports not used depending on template conditions
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
var axios_1 = __importDefault(require("axios"));
|
|
98
|
+
exports.BASE_PATH = "https://apiv2.emil.de".replace(/\/+$/, "");
|
|
99
|
+
/**
|
|
100
|
+
*
|
|
101
|
+
* @export
|
|
102
|
+
*/
|
|
103
|
+
exports.COLLECTION_FORMATS = {
|
|
104
|
+
csv: ",",
|
|
105
|
+
ssv: " ",
|
|
106
|
+
tsv: "\t",
|
|
107
|
+
pipes: "|",
|
|
108
|
+
};
|
|
109
|
+
var Environment;
|
|
110
|
+
(function (Environment) {
|
|
111
|
+
Environment["Production"] = "https://apiv2.emil.de";
|
|
112
|
+
Environment["Test"] = "https://apiv2-test.emil.de";
|
|
113
|
+
Environment["Staging"] = "https://apiv2-staging.emil.de";
|
|
114
|
+
Environment["Development"] = "https://apiv2-dev.emil.de";
|
|
115
|
+
Environment["ProductionZurich"] = "https://eu-central-2.apiv2.emil.de";
|
|
116
|
+
Environment["StagingZurich"] = "https://eu-central-2.apiv2-staging.emil.de";
|
|
117
|
+
})(Environment = exports.Environment || (exports.Environment = {}));
|
|
118
|
+
var _retry_count = 0;
|
|
119
|
+
var _retry = null;
|
|
120
|
+
// Refreshes in flight per account (BaseAPI.shareRefresh).
|
|
121
|
+
var refreshesInFlight = new Map();
|
|
122
|
+
function resetRetry() {
|
|
123
|
+
_retry_count = 0;
|
|
124
|
+
}
|
|
125
|
+
exports.resetRetry = resetRetry;
|
|
126
|
+
var NETWORK_ERROR_MESSAGE = "Network Error";
|
|
127
|
+
var TOKEN_DATA = 'APP_TOKEN';
|
|
128
|
+
// Sent only to authservice, to ask for a server session.
|
|
129
|
+
var AUTH_MODE_HEADER = 'X-Emil-Auth-Mode';
|
|
130
|
+
// Names the account on every call; one browser session can hold several.
|
|
131
|
+
var ACCOUNT_HEADER = 'X-Emil-Account';
|
|
132
|
+
var SESSION_MODES = ['both', 'session'];
|
|
133
|
+
var RESEND_SAFE_METHODS = ['get', 'head', 'options'];
|
|
134
|
+
/**
|
|
135
|
+
*
|
|
136
|
+
* @export
|
|
137
|
+
* @class BaseAPI
|
|
138
|
+
*/
|
|
139
|
+
var BaseAPI = /** @class */ (function () {
|
|
140
|
+
function BaseAPI(configuration, basePath, axios) {
|
|
141
|
+
if (basePath === void 0) { basePath = exports.BASE_PATH; }
|
|
142
|
+
if (axios === void 0) { axios = axios_1.default; }
|
|
143
|
+
this.basePath = basePath;
|
|
144
|
+
this.axios = axios;
|
|
145
|
+
this.loadTokenData();
|
|
146
|
+
if (configuration) {
|
|
147
|
+
// Two accounts in one browser share APP_TOKEN: never take the token or session account saved for
|
|
148
|
+
// another account. The mode stays (an app naming its account keeps its session). Saved with the next refresh.
|
|
149
|
+
var ownUser = configuration.username;
|
|
150
|
+
var storedUser = this.tokenData.username;
|
|
151
|
+
if (ownUser && storedUser && ownUser.toLowerCase() !== storedUser.toLowerCase()) {
|
|
152
|
+
delete this.tokenData.accessToken;
|
|
153
|
+
delete this.tokenData.sub;
|
|
154
|
+
this.tokenData.username = ownUser;
|
|
155
|
+
}
|
|
156
|
+
var accessToken = this.tokenData.accessToken;
|
|
157
|
+
this.configuration = configuration;
|
|
158
|
+
this.basePath = configuration.basePath || this.basePath;
|
|
159
|
+
if (configuration.cookieAuth) {
|
|
160
|
+
this.configuration.username = this.configuration.username || this.tokenData.username;
|
|
161
|
+
}
|
|
162
|
+
if (this.usesSession()) {
|
|
163
|
+
this.useSessionAuth();
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// Use config token if provided, otherwise use tokenData token
|
|
167
|
+
var configToken = this.configuration.accessToken;
|
|
168
|
+
var storedToken = accessToken ? "Bearer ".concat(accessToken) : '';
|
|
169
|
+
this.configuration.accessToken = configToken || storedToken;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
var _a = this.tokenData, accessToken = _a.accessToken, username = _a.username;
|
|
174
|
+
this.configuration = new configuration_1.Configuration({
|
|
175
|
+
basePath: this.basePath,
|
|
176
|
+
accessToken: accessToken ? "Bearer ".concat(accessToken) : '',
|
|
177
|
+
username: username,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
this.attachInterceptor(axios);
|
|
181
|
+
}
|
|
182
|
+
// The app's own account wins over APP_TOKEN, which holds whichever tab wrote last.
|
|
183
|
+
BaseAPI.prototype.sessionAccount = function () {
|
|
184
|
+
return this.configuration.account || this.tokenData.sub;
|
|
185
|
+
};
|
|
186
|
+
// Apps may pass the address as the second argument only; authservice is on the same host.
|
|
187
|
+
BaseAPI.prototype.authBasePath = function () {
|
|
188
|
+
return this.configuration.basePath || this.basePath;
|
|
189
|
+
};
|
|
190
|
+
BaseAPI.prototype.usesSession = function () {
|
|
191
|
+
return !!this.configuration.cookieAuth && SESSION_MODES.indexOf(this.tokenData.authMode) !== -1 && !!this.sessionAccount();
|
|
192
|
+
};
|
|
193
|
+
BaseAPI.prototype.useSessionAuth = function () {
|
|
194
|
+
var _a;
|
|
195
|
+
var _b = this.configuration.baseOptions || {}, headers = _b.headers, baseOptions = __rest(_b, ["headers"]);
|
|
196
|
+
this.configuration.accessToken = '';
|
|
197
|
+
this.configuration.baseOptions = __assign(__assign({}, baseOptions), { withCredentials: true, headers: __assign(__assign({}, headers), (_a = {}, _a[ACCOUNT_HEADER] = this.sessionAccount(), _a)) });
|
|
198
|
+
};
|
|
199
|
+
BaseAPI.prototype.useHeaderAuth = function (accessToken, keepSessionData) {
|
|
200
|
+
if (keepSessionData === void 0) { keepSessionData = false; }
|
|
201
|
+
this.configuration.accessToken = accessToken ? "Bearer ".concat(accessToken) : '';
|
|
202
|
+
this.tokenData.accessToken = accessToken;
|
|
203
|
+
// An app without cookieAuth does not own the session fields: its refresh leaves them for the session apps.
|
|
204
|
+
if (!keepSessionData || this.configuration.cookieAuth) {
|
|
205
|
+
delete this.tokenData.authMode;
|
|
206
|
+
delete this.tokenData.sub;
|
|
207
|
+
}
|
|
208
|
+
if (this.configuration.cookieAuth) {
|
|
209
|
+
var _a = this.configuration.baseOptions || {}, withCredentials = _a.withCredentials, headers = _a.headers, baseOptions = __rest(_a, ["withCredentials", "headers"]);
|
|
210
|
+
var _b = headers || {}, _c = ACCOUNT_HEADER, account = _b[_c], otherHeaders = __rest(_b, [typeof _c === "symbol" ? _c : _c + ""]);
|
|
211
|
+
this.configuration.baseOptions = __assign(__assign({}, baseOptions), { headers: otherHeaders });
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
BaseAPI.prototype.applyTokenReply = function (_a, fromRefresh) {
|
|
215
|
+
var accessToken = _a.accessToken, authMode = _a.authMode, session = _a.session;
|
|
216
|
+
if (fromRefresh === void 0) { fromRefresh = false; }
|
|
217
|
+
if (this.configuration.cookieAuth && SESSION_MODES.indexOf(authMode) !== -1 && (session === null || session === void 0 ? void 0 : session.sub)) {
|
|
218
|
+
this.tokenData.authMode = authMode;
|
|
219
|
+
this.tokenData.sub = session.sub;
|
|
220
|
+
if (this.configuration.account) {
|
|
221
|
+
// A workspace switch moves the app to another account.
|
|
222
|
+
this.configuration.account = session.sub;
|
|
223
|
+
}
|
|
224
|
+
// Both keeps the token for apps not moved yet; session mode keeps no token at all.
|
|
225
|
+
if (authMode === 'both' && accessToken) {
|
|
226
|
+
this.tokenData.accessToken = accessToken;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
delete this.tokenData.accessToken;
|
|
230
|
+
}
|
|
231
|
+
this.useSessionAuth();
|
|
232
|
+
}
|
|
233
|
+
else {
|
|
234
|
+
this.useHeaderAuth(accessToken, fromRefresh);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
BaseAPI.prototype.sessionHeaders = function () {
|
|
238
|
+
var _a, _b;
|
|
239
|
+
if (!this.configuration.cookieAuth) {
|
|
240
|
+
return {};
|
|
241
|
+
}
|
|
242
|
+
return __assign((_a = {}, _a[AUTH_MODE_HEADER] = 'session', _a), (this.usesSession() && (_b = {}, _b[ACCOUNT_HEADER] = this.sessionAccount(), _b)));
|
|
243
|
+
};
|
|
244
|
+
BaseAPI.prototype.withCurrentAuth = function (config) {
|
|
245
|
+
delete config.headers['Authorization'];
|
|
246
|
+
delete config.headers[ACCOUNT_HEADER];
|
|
247
|
+
if (this.usesSession()) {
|
|
248
|
+
config.headers[ACCOUNT_HEADER] = this.sessionAccount();
|
|
249
|
+
config.withCredentials = true;
|
|
250
|
+
}
|
|
251
|
+
else if (this.configuration.accessToken) {
|
|
252
|
+
config.headers['Authorization'] = this.configuration.accessToken;
|
|
253
|
+
}
|
|
254
|
+
return config;
|
|
255
|
+
};
|
|
256
|
+
// Both keeps the token, so a session call the browser could not complete can be sent again with it.
|
|
257
|
+
BaseAPI.prototype.canRetryWithToken = function (config) {
|
|
258
|
+
var _a;
|
|
259
|
+
return !!config.withCredentials && !!((_a = config.headers) === null || _a === void 0 ? void 0 : _a[ACCOUNT_HEADER])
|
|
260
|
+
&& !!this.tokenData.accessToken && this.tokenData.authMode !== 'session';
|
|
261
|
+
};
|
|
262
|
+
// A network error can come after the server ran the call, so only a call that is safe to repeat is sent again.
|
|
263
|
+
BaseAPI.prototype.canResend = function (config) {
|
|
264
|
+
return RESEND_SAFE_METHODS.indexOf((config.method || 'get').toLowerCase()) !== -1
|
|
265
|
+
|| Object.keys(config.headers || {}).some(function (name) { return name.toLowerCase() === 'idempotency-key'; });
|
|
266
|
+
};
|
|
267
|
+
BaseAPI.prototype.switchToToken = function () {
|
|
268
|
+
this.useHeaderAuth(this.tokenData.accessToken);
|
|
269
|
+
this.storeTokenData(this.tokenData);
|
|
270
|
+
};
|
|
271
|
+
BaseAPI.prototype.retryWithToken = function (axios, config) {
|
|
272
|
+
this.switchToToken();
|
|
273
|
+
config.withCredentials = false;
|
|
274
|
+
return axios(this.withCurrentAuth(config));
|
|
275
|
+
};
|
|
276
|
+
BaseAPI.prototype.selectEnvironment = function (env) {
|
|
277
|
+
this.selectBasePath(env);
|
|
278
|
+
};
|
|
279
|
+
BaseAPI.prototype.selectBasePath = function (path) {
|
|
280
|
+
this.configuration.basePath = path;
|
|
281
|
+
};
|
|
282
|
+
BaseAPI.prototype.getPermissions = function () {
|
|
283
|
+
var _a;
|
|
284
|
+
if (!((_a = this.tokenData) === null || _a === void 0 ? void 0 : _a.permissions)) {
|
|
285
|
+
return [];
|
|
286
|
+
}
|
|
287
|
+
return this.tokenData.permissions.split(',');
|
|
288
|
+
};
|
|
289
|
+
BaseAPI.prototype.authorize = function (username, password, targetWorkspace) {
|
|
290
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
291
|
+
var options, response;
|
|
292
|
+
var _a;
|
|
293
|
+
return __generator(this, function (_b) {
|
|
294
|
+
switch (_b.label) {
|
|
295
|
+
case 0:
|
|
296
|
+
options = {
|
|
297
|
+
method: 'POST',
|
|
298
|
+
url: "".concat(this.authBasePath(), "/authservice/v1/login"),
|
|
299
|
+
headers: __assign({ 'Content-Type': 'application/json' }, (this.configuration.cookieAuth && (_a = {}, _a[AUTH_MODE_HEADER] = 'session', _a))),
|
|
300
|
+
data: {
|
|
301
|
+
username: username,
|
|
302
|
+
password: password,
|
|
303
|
+
},
|
|
304
|
+
withCredentials: true,
|
|
305
|
+
};
|
|
306
|
+
return [4 /*yield*/, axios_1.default.request(options)];
|
|
307
|
+
case 1:
|
|
308
|
+
response = _b.sent();
|
|
309
|
+
this.configuration.username = username;
|
|
310
|
+
this.tokenData.username = username;
|
|
311
|
+
this.tokenData.permissions = response.data.permissions;
|
|
312
|
+
this.applyTokenReply(response.data);
|
|
313
|
+
if (!targetWorkspace) return [3 /*break*/, 3];
|
|
314
|
+
return [4 /*yield*/, this.switchWorkspace(targetWorkspace)];
|
|
315
|
+
case 2:
|
|
316
|
+
_b.sent();
|
|
317
|
+
return [3 /*break*/, 4];
|
|
318
|
+
case 3:
|
|
319
|
+
// Only store if no workspace switch (since switchWorkspace will store after switching)
|
|
320
|
+
this.storeTokenData(__assign({}, this.tokenData));
|
|
321
|
+
_b.label = 4;
|
|
322
|
+
case 4:
|
|
323
|
+
this.storeTokenData(__assign({}, this.tokenData));
|
|
324
|
+
return [2 /*return*/];
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
BaseAPI.prototype.switchWorkspace = function (targetWorkspace) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
331
|
+
var options, response;
|
|
332
|
+
return __generator(this, function (_a) {
|
|
333
|
+
switch (_a.label) {
|
|
334
|
+
case 0:
|
|
335
|
+
options = {
|
|
336
|
+
method: 'POST',
|
|
337
|
+
url: "".concat(this.authBasePath(), "/authservice/v1/workspaces/switch"),
|
|
338
|
+
headers: __assign(__assign({ 'Content-Type': 'application/json' }, this.sessionHeaders()), (!this.usesSession() && !!this.configuration.accessToken && { 'Authorization': this.configuration.accessToken })),
|
|
339
|
+
data: {
|
|
340
|
+
username: this.configuration.username,
|
|
341
|
+
targetWorkspace: targetWorkspace,
|
|
342
|
+
},
|
|
343
|
+
withCredentials: true,
|
|
344
|
+
};
|
|
345
|
+
return [4 /*yield*/, axios_1.default.request(options)];
|
|
346
|
+
case 1:
|
|
347
|
+
response = _a.sent();
|
|
348
|
+
this.tokenData.permissions = response.data.permissions;
|
|
349
|
+
this.applyTokenReply(response.data);
|
|
350
|
+
this.storeTokenData(__assign({}, this.tokenData));
|
|
351
|
+
return [2 /*return*/];
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
});
|
|
355
|
+
};
|
|
356
|
+
BaseAPI.prototype.refreshTokenInternal = function () {
|
|
357
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
358
|
+
var username, cannotRefresh, refreshTokenAxios, options, response;
|
|
359
|
+
var _this = this;
|
|
360
|
+
return __generator(this, function (_a) {
|
|
361
|
+
switch (_a.label) {
|
|
362
|
+
case 0:
|
|
363
|
+
username = this.configuration.username;
|
|
364
|
+
if (!username) {
|
|
365
|
+
cannotRefresh = new Error('Failed to refresh token.');
|
|
366
|
+
cannotRefresh.sessionExpired = true;
|
|
367
|
+
throw cannotRefresh;
|
|
368
|
+
}
|
|
369
|
+
refreshTokenAxios = axios_1.default.create();
|
|
370
|
+
refreshTokenAxios.interceptors.response.use(function (response) {
|
|
371
|
+
var _a, _b;
|
|
372
|
+
var _c = response.data, permissions = _c.permissions, accessToken = _c.accessToken, authMode = _c.authMode;
|
|
373
|
+
// Decided before the merge below: newer session data must not keep the new token from this object.
|
|
374
|
+
var onSession = _this.usesSession();
|
|
375
|
+
// Newer data saved for this account (e.g. the session mode the shell saved later) wins over the copy
|
|
376
|
+
// read when the object was made; data of another account or another workspace (sub) is never taken.
|
|
377
|
+
var latest = ((typeof window !== 'undefined' && (0, common_1.defaultStorage)().get(TOKEN_DATA)) || {});
|
|
378
|
+
var ownSub = _this.sessionAccount();
|
|
379
|
+
if (((_a = latest.username) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === username.toLowerCase()
|
|
380
|
+
&& (!ownSub || !latest.sub || latest.sub === ownSub)) {
|
|
381
|
+
// A bare reset ({username}, an app's account check) keeps this copy's other fields; any fuller record
|
|
382
|
+
// is the truth, so fields it lacks were removed on purpose (e.g. a rollback) and stay removed.
|
|
383
|
+
var bareReset = Object.keys(latest).every(function (key) { return key === 'username'; });
|
|
384
|
+
_this.tokenData = bareReset ? __assign(__assign({}, _this.tokenData), latest) : __assign({}, latest);
|
|
385
|
+
}
|
|
386
|
+
// The reply is for this account: label it, or an SDK object of another account would take the token.
|
|
387
|
+
if (((_b = _this.tokenData.username) === null || _b === void 0 ? void 0 : _b.toLowerCase()) !== username.toLowerCase()) {
|
|
388
|
+
_this.tokenData.username = username;
|
|
389
|
+
}
|
|
390
|
+
_this.tokenData.permissions = permissions;
|
|
391
|
+
// Keep the new token for the page's next SDK objects; session data is left as it is.
|
|
392
|
+
if (accessToken && !onSession) {
|
|
393
|
+
_this.tokenData.accessToken = accessToken;
|
|
394
|
+
_this.configuration.accessToken = "Bearer ".concat(accessToken);
|
|
395
|
+
}
|
|
396
|
+
else if (accessToken && authMode === 'both') {
|
|
397
|
+
// Both: this app stays on the session; the token is kept for apps not moved yet.
|
|
398
|
+
_this.tokenData.accessToken = accessToken;
|
|
399
|
+
}
|
|
400
|
+
_this.storeTokenData(_this.tokenData);
|
|
401
|
+
return response;
|
|
402
|
+
});
|
|
403
|
+
options = {
|
|
404
|
+
method: 'POST',
|
|
405
|
+
url: "".concat(this.authBasePath(), "/authservice/v1/refresh-token"),
|
|
406
|
+
headers: __assign({ 'Content-Type': 'application/json' }, this.sessionHeaders()),
|
|
407
|
+
data: { username: username },
|
|
408
|
+
withCredentials: true,
|
|
409
|
+
};
|
|
410
|
+
return [4 /*yield*/, refreshTokenAxios.request(options)];
|
|
411
|
+
case 1:
|
|
412
|
+
response = _a.sent();
|
|
413
|
+
return [2 /*return*/, response.data];
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
BaseAPI.prototype.storeTokenData = function (tokenData) {
|
|
419
|
+
if (typeof window !== 'undefined') {
|
|
420
|
+
(0, common_1.defaultStorage)().set(TOKEN_DATA, tokenData);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
BaseAPI.prototype.loadTokenData = function () {
|
|
424
|
+
if (typeof window !== 'undefined') {
|
|
425
|
+
this.tokenData = (0, common_1.defaultStorage)().get(TOKEN_DATA) || {};
|
|
426
|
+
}
|
|
427
|
+
else {
|
|
428
|
+
this.tokenData = {};
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
BaseAPI.prototype.cleanTokenData = function () {
|
|
432
|
+
this.storeTokenData(null);
|
|
433
|
+
};
|
|
434
|
+
BaseAPI.prototype.ownAccount = function () {
|
|
435
|
+
return (this.configuration.username || '').toLowerCase();
|
|
436
|
+
};
|
|
437
|
+
BaseAPI.prototype.withOwner = function (options) {
|
|
438
|
+
var _a;
|
|
439
|
+
// An object without a username cannot refresh itself: its requests stay unmarked, as before.
|
|
440
|
+
if (!this.ownAccount()) {
|
|
441
|
+
return __assign({}, options);
|
|
442
|
+
}
|
|
443
|
+
return __assign(__assign({}, options), (_a = {}, _a[BaseAPI.REQUEST_OWNER] = this.ownAccount(), _a));
|
|
444
|
+
};
|
|
445
|
+
// Sent for another account: only that account's SDK objects handle it. Unmarked requests as before.
|
|
446
|
+
BaseAPI.prototype.sentByOtherAccount = function (config) {
|
|
447
|
+
var owner = config === null || config === void 0 ? void 0 : config[BaseAPI.REQUEST_OWNER];
|
|
448
|
+
return owner !== undefined && owner !== this.ownAccount();
|
|
449
|
+
};
|
|
450
|
+
// One refresh per account; an object without a username keeps its own, which fails as before.
|
|
451
|
+
BaseAPI.prototype.sharedRefresh = function () {
|
|
452
|
+
var _this = this;
|
|
453
|
+
var account = this.ownAccount();
|
|
454
|
+
if (!account) {
|
|
455
|
+
return this.refreshTokenInternal();
|
|
456
|
+
}
|
|
457
|
+
return BaseAPI.shareRefresh(refreshesInFlight, account, function () { return _this.refreshTokenInternal(); });
|
|
458
|
+
};
|
|
459
|
+
BaseAPI.prototype.refreshRunning = function () {
|
|
460
|
+
var account = this.ownAccount();
|
|
461
|
+
return !!account && refreshesInFlight.has(account);
|
|
462
|
+
};
|
|
463
|
+
// Joins the refresh already in flight for this key, or starts one: calls refused at the same time wait for
|
|
464
|
+
// one refresh instead of each starting their own (a refresh token may be single-use). The entry is removed
|
|
465
|
+
// when the refresh settles.
|
|
466
|
+
BaseAPI.shareRefresh = function (inFlight, key, start) {
|
|
467
|
+
var running = inFlight.get(key);
|
|
468
|
+
if (running) {
|
|
469
|
+
return running;
|
|
470
|
+
}
|
|
471
|
+
var refresh = start();
|
|
472
|
+
inFlight.set(key, refresh);
|
|
473
|
+
var settled = function () { inFlight.delete(key); };
|
|
474
|
+
refresh.then(settled, settled);
|
|
475
|
+
return refresh;
|
|
476
|
+
};
|
|
477
|
+
// A refused call that joins a refresh already running is not a new try: only started refreshes count toward
|
|
478
|
+
// the limit, so every call refused at the same time is retried.
|
|
479
|
+
BaseAPI.prototype.mayRefreshAfterNetworkError = function () {
|
|
480
|
+
if (this.refreshRunning()) {
|
|
481
|
+
return true;
|
|
482
|
+
}
|
|
483
|
+
if (_retry_count >= 4) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
_retry_count++;
|
|
487
|
+
return true;
|
|
488
|
+
};
|
|
489
|
+
// Rejects as before (the refresh's response body, or its error). Marks it as an ended session only when the
|
|
490
|
+
// refresh was refused (401 or 403) or could not run (no username, marked where it is thrown); a server error
|
|
491
|
+
// or a network error says nothing about the session, so an app must not log the user out for it. A body that
|
|
492
|
+
// is not an object cannot carry the mark and is kept as it is.
|
|
493
|
+
BaseAPI.prototype.rejectEndedSession = function (error) {
|
|
494
|
+
var _a, _b;
|
|
495
|
+
var rejection = ((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error;
|
|
496
|
+
var status = (_b = error.response) === null || _b === void 0 ? void 0 : _b.status;
|
|
497
|
+
if (typeof rejection === 'object' && (status === 401 || status === 403)) {
|
|
498
|
+
rejection.sessionExpired = true;
|
|
499
|
+
}
|
|
500
|
+
return Promise.reject(rejection);
|
|
501
|
+
};
|
|
502
|
+
BaseAPI.prototype.attachInterceptor = function (axios) {
|
|
503
|
+
var _this = this;
|
|
504
|
+
axios.interceptors.response.use(function (res) {
|
|
505
|
+
return res;
|
|
506
|
+
}, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
507
|
+
var originalConfig, reply, _error_1, reply, _error_2;
|
|
508
|
+
var _this = this;
|
|
509
|
+
return __generator(this, function (_a) {
|
|
510
|
+
switch (_a.label) {
|
|
511
|
+
case 0:
|
|
512
|
+
originalConfig = err.config;
|
|
513
|
+
if (this.sentByOtherAccount(originalConfig)) {
|
|
514
|
+
return [2 /*return*/, Promise.reject(err)];
|
|
515
|
+
}
|
|
516
|
+
if (!(err.response && !(err.response instanceof XMLHttpRequest))) return [3 /*break*/, 5];
|
|
517
|
+
if (!((err.response.status === 401 || err.response.status === 403)
|
|
518
|
+
&& !originalConfig._retry)) return [3 /*break*/, 4];
|
|
519
|
+
originalConfig._retry = true;
|
|
520
|
+
_a.label = 1;
|
|
521
|
+
case 1:
|
|
522
|
+
_a.trys.push([1, 3, , 4]);
|
|
523
|
+
return [4 /*yield*/, this.sharedRefresh()];
|
|
524
|
+
case 2:
|
|
525
|
+
reply = _a.sent();
|
|
526
|
+
this.tokenData.permissions = reply.permissions;
|
|
527
|
+
this.applyTokenReply(reply, true);
|
|
528
|
+
this.storeTokenData(this.tokenData);
|
|
529
|
+
if (!this.usesSession()) {
|
|
530
|
+
return [2 /*return*/, axios(this.withCurrentAuth(originalConfig))];
|
|
531
|
+
}
|
|
532
|
+
// Both mode: if the browser does not send the session cookie (another site), use the token.
|
|
533
|
+
return [2 /*return*/, axios(this.withCurrentAuth(originalConfig)).catch(function (retryError) {
|
|
534
|
+
var _a;
|
|
535
|
+
if (((_a = retryError === null || retryError === void 0 ? void 0 : retryError.response) === null || _a === void 0 ? void 0 : _a.status) !== 401 || !_this.tokenData.accessToken) {
|
|
536
|
+
return Promise.reject(retryError);
|
|
537
|
+
}
|
|
538
|
+
return _this.retryWithToken(axios, originalConfig);
|
|
539
|
+
})];
|
|
540
|
+
case 3:
|
|
541
|
+
_error_1 = _a.sent();
|
|
542
|
+
return [2 /*return*/, this.rejectEndedSession(_error_1)];
|
|
543
|
+
case 4: return [3 /*break*/, 10];
|
|
544
|
+
case 5:
|
|
545
|
+
if (!(err.message === NETWORK_ERROR_MESSAGE && this.canRetryWithToken(originalConfig))) return [3 /*break*/, 6];
|
|
546
|
+
// Both mode: the browser blocked the session call or hid its reply; later calls use the token.
|
|
547
|
+
if (!this.canResend(originalConfig)) {
|
|
548
|
+
this.switchToToken();
|
|
549
|
+
return [2 /*return*/, Promise.reject(err)];
|
|
550
|
+
}
|
|
551
|
+
return [2 /*return*/, this.retryWithToken(axios, originalConfig)];
|
|
552
|
+
case 6:
|
|
553
|
+
if (!(err.message === NETWORK_ERROR_MESSAGE
|
|
554
|
+
&& (originalConfig.headers.hasOwnProperty('Authorization')
|
|
555
|
+
|| (this.configuration.cookieAuth && originalConfig.withCredentials && this.canResend(originalConfig)))
|
|
556
|
+
&& this.mayRefreshAfterNetworkError())) return [3 /*break*/, 10];
|
|
557
|
+
_a.label = 7;
|
|
558
|
+
case 7:
|
|
559
|
+
_a.trys.push([7, 9, , 10]);
|
|
560
|
+
return [4 /*yield*/, this.sharedRefresh()];
|
|
561
|
+
case 8:
|
|
562
|
+
reply = _a.sent();
|
|
563
|
+
this.tokenData.permissions = reply.permissions;
|
|
564
|
+
_retry = true;
|
|
565
|
+
this.applyTokenReply(reply, true);
|
|
566
|
+
this.storeTokenData(this.tokenData);
|
|
567
|
+
// The limit is for refreshes that do not help; one that worked starts the count again.
|
|
568
|
+
// Not awaited, so a failed retry reaches the app as the same axios error as before.
|
|
569
|
+
return [2 /*return*/, axios.request(__assign({}, this.withCurrentAuth(originalConfig))).then(function (retried) {
|
|
570
|
+
_retry_count = 0;
|
|
571
|
+
return retried;
|
|
572
|
+
})];
|
|
573
|
+
case 9:
|
|
574
|
+
_error_2 = _a.sent();
|
|
575
|
+
return [2 /*return*/, this.rejectEndedSession(_error_2)];
|
|
576
|
+
case 10: return [2 /*return*/, Promise.reject(err)];
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
}); });
|
|
580
|
+
};
|
|
581
|
+
// Marks each request with the account (username) of the SDK object that sent it: only SDK objects of that
|
|
582
|
+
// account refresh and resend it, never an object of another account in the same app.
|
|
583
|
+
BaseAPI.REQUEST_OWNER = '_emilSdkOwner';
|
|
584
|
+
return BaseAPI;
|
|
585
|
+
}());
|
|
586
|
+
exports.BaseAPI = BaseAPI;
|
|
587
|
+
;
|
|
588
|
+
/**
|
|
589
|
+
*
|
|
590
|
+
* @export
|
|
591
|
+
* @class RequiredError
|
|
592
|
+
* @extends {Error}
|
|
593
|
+
*/
|
|
594
|
+
var RequiredError = /** @class */ (function (_super) {
|
|
595
|
+
__extends(RequiredError, _super);
|
|
596
|
+
function RequiredError(field, msg) {
|
|
597
|
+
var _this = _super.call(this, msg) || this;
|
|
598
|
+
_this.field = field;
|
|
599
|
+
_this.name = "RequiredError";
|
|
600
|
+
return _this;
|
|
601
|
+
}
|
|
602
|
+
return RequiredError;
|
|
603
|
+
}(Error));
|
|
604
|
+
exports.RequiredError = RequiredError;
|