theauthapi 1.0.16 → 1.0.18
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/LICENSE +21 -21
- package/README.md +2 -0
- package/dist/index.cjs +285 -283
- package/dist/index.d.cts +178 -178
- package/dist/index.d.mts +177 -177
- package/dist/index.mjs +285 -283
- package/dist/{types/index.d.ts → types.d.cts} +87 -85
- package/dist/types.d.ts +87 -0
- package/package.json +11 -2
- package/dist/endpoints/Accounts/Accounts.d.ts +0 -10
- package/dist/endpoints/Accounts/Accounts.js +0 -22
- package/dist/endpoints/Accounts/AccountsInterface.d.ts +0 -4
- package/dist/endpoints/Accounts/AccountsInterface.js +0 -1
- package/dist/endpoints/ApiKeys/ApiKeys.d.ts +0 -19
- package/dist/endpoints/ApiKeys/ApiKeys.js +0 -80
- package/dist/endpoints/ApiKeys/ApiKeysInterface.d.ts +0 -12
- package/dist/endpoints/ApiKeys/ApiKeysInterface.js +0 -1
- package/dist/endpoints/Projects/Projects.d.ts +0 -14
- package/dist/endpoints/Projects/Projects.js +0 -42
- package/dist/endpoints/Projects/ProjectsInterface.d.ts +0 -8
- package/dist/endpoints/Projects/ProjectsInterface.js +0 -1
- package/dist/index.d.ts +0 -26
- package/dist/index.js +0 -69
- package/dist/libraryMeta.d.ts +0 -1
- package/dist/libraryMeta.js +0 -1
- package/dist/services/ApiRequest/ApiCall.d.ts +0 -5
- package/dist/services/ApiRequest/ApiCall.js +0 -1
- package/dist/services/ApiRequest/ApiRequest.d.ts +0 -24
- package/dist/services/ApiRequest/ApiRequest.js +0 -110
- package/dist/services/ApiRequest/ApiRequestError.d.ts +0 -10
- package/dist/services/ApiRequest/ApiRequestError.js +0 -13
- package/dist/services/ApiRequest/ApiResponseError.d.ts +0 -12
- package/dist/services/ApiRequest/ApiResponseError.js +0 -15
- package/dist/services/ApiRequest/HttpMethod.d.ts +0 -7
- package/dist/services/ApiRequest/HttpMethod.js +0 -8
- package/dist/types/index.js +0 -10
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from 'axios';
|
|
11
|
-
import { version } from '../../libraryMeta';
|
|
12
|
-
import ApiRequestError from './ApiRequestError';
|
|
13
|
-
import axiosRetry from 'axios-retry';
|
|
14
|
-
import ApiResponseError from './ApiResponseError';
|
|
15
|
-
class ApiRequest {
|
|
16
|
-
constructor(config) {
|
|
17
|
-
const { host, accessKey, headers, retryCount } = config;
|
|
18
|
-
this.host = host;
|
|
19
|
-
this.accessKey = accessKey;
|
|
20
|
-
this.headers = this._generateDefaultHeaders();
|
|
21
|
-
this.retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 3;
|
|
22
|
-
if (headers) {
|
|
23
|
-
this.headers = Object.assign(Object.assign({}, this.headers), { headers });
|
|
24
|
-
}
|
|
25
|
-
this._init();
|
|
26
|
-
}
|
|
27
|
-
_init() {
|
|
28
|
-
var _a;
|
|
29
|
-
const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
30
|
-
function isIsoDateString(value) {
|
|
31
|
-
return value && typeof value === 'string' && isoDateFormat.test(value);
|
|
32
|
-
}
|
|
33
|
-
function handleDates(body) {
|
|
34
|
-
if (body === null || body === undefined || typeof body !== 'object') {
|
|
35
|
-
return body;
|
|
36
|
-
}
|
|
37
|
-
for (const key of Object.keys(body)) {
|
|
38
|
-
const value = body[key];
|
|
39
|
-
if (isIsoDateString(value)) {
|
|
40
|
-
body[key] = new Date(value);
|
|
41
|
-
}
|
|
42
|
-
else if (typeof value === 'object') {
|
|
43
|
-
handleDates(value);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
axios.interceptors.response.use((response) => {
|
|
48
|
-
handleDates(response.data);
|
|
49
|
-
return response;
|
|
50
|
-
});
|
|
51
|
-
axiosRetry(axios, {
|
|
52
|
-
retries: (_a = this.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
53
|
-
retryCondition: this._isErrorRetryable,
|
|
54
|
-
retryDelay: axiosRetry.exponentialDelay,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
request(method, endpoint, payload) {
|
|
58
|
-
var _a;
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
try {
|
|
61
|
-
const response = yield axios.request({
|
|
62
|
-
baseURL: this.host,
|
|
63
|
-
method: method,
|
|
64
|
-
url: endpoint,
|
|
65
|
-
data: payload,
|
|
66
|
-
headers: this.headers,
|
|
67
|
-
});
|
|
68
|
-
return response.data;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
if (axios.isAxiosError(error)) {
|
|
72
|
-
if (error.response) {
|
|
73
|
-
throw new ApiResponseError(error.response.status, (_a = error.response.data.message) !== null && _a !== void 0 ? _a : error.response.statusText);
|
|
74
|
-
}
|
|
75
|
-
else if (error.request) {
|
|
76
|
-
throw new ApiRequestError(error.message);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
_generateDefaultHeaders() {
|
|
84
|
-
return {
|
|
85
|
-
'user-agent': `theauthapi-client-node/${version}`,
|
|
86
|
-
'x-api-key': this.accessKey,
|
|
87
|
-
'api-key': this.accessKey,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
_isErrorRetryable(error) {
|
|
91
|
-
// Retry Network Errors.
|
|
92
|
-
if (axiosRetry.isNetworkError(error)) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
if (!error.response) {
|
|
96
|
-
// Cannot determine if the request can be retried
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
// Retry Server Errors (5xx).
|
|
100
|
-
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
// Retry if rate limited.
|
|
104
|
-
if (error.response.status === 429) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
export default ApiRequest;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Throws when no response was received from the server
|
|
4
|
-
* @param message - error message
|
|
5
|
-
*
|
|
6
|
-
* */
|
|
7
|
-
class ApiRequestError extends Error {
|
|
8
|
-
constructor(message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = 'ApiRequestError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export default ApiRequestError;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
4
|
-
* @param statusCode - HTTP status code the server responded with
|
|
5
|
-
* @param message - error message
|
|
6
|
-
*
|
|
7
|
-
* */
|
|
8
|
-
declare class ApiResponseError extends Error {
|
|
9
|
-
statusCode: number;
|
|
10
|
-
constructor(statusCode: number, message: string);
|
|
11
|
-
}
|
|
12
|
-
export default ApiResponseError;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
4
|
-
* @param statusCode - HTTP status code the server responded with
|
|
5
|
-
* @param message - error message
|
|
6
|
-
*
|
|
7
|
-
* */
|
|
8
|
-
class ApiResponseError extends Error {
|
|
9
|
-
constructor(statusCode, message) {
|
|
10
|
-
super(`(${statusCode}): ${message}`);
|
|
11
|
-
this.statusCode = statusCode;
|
|
12
|
-
this.name = 'ApiResponseError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export default ApiResponseError;
|
package/dist/types/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export var AuthedEntityType;
|
|
2
|
-
(function (AuthedEntityType) {
|
|
3
|
-
AuthedEntityType["USER"] = "USER";
|
|
4
|
-
AuthedEntityType["ACCESS_KEY"] = "ACCESS_KEY";
|
|
5
|
-
})(AuthedEntityType || (AuthedEntityType = {}));
|
|
6
|
-
export var Environment;
|
|
7
|
-
(function (Environment) {
|
|
8
|
-
Environment["LIVE"] = "live";
|
|
9
|
-
Environment["TEST"] = "test";
|
|
10
|
-
})(Environment || (Environment = {}));
|