theauthapi 1.0.12 → 1.0.15
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 -0
- package/README.md +366 -334
- package/dist/endpoints/Accounts/Accounts.d.ts +10 -10
- package/dist/endpoints/Accounts/Accounts.js +22 -24
- package/dist/endpoints/Accounts/AccountsInterface.d.ts +4 -4
- package/dist/endpoints/Accounts/AccountsInterface.js +1 -2
- package/dist/endpoints/ApiKeys/ApiKeys.d.ts +19 -19
- package/dist/endpoints/ApiKeys/ApiKeys.js +80 -85
- package/dist/endpoints/ApiKeys/ApiKeysInterface.d.ts +12 -12
- package/dist/endpoints/ApiKeys/ApiKeysInterface.js +1 -2
- package/dist/endpoints/Projects/Projects.d.ts +14 -14
- package/dist/endpoints/Projects/Projects.js +42 -44
- package/dist/endpoints/Projects/ProjectsInterface.d.ts +8 -8
- package/dist/endpoints/Projects/ProjectsInterface.js +1 -2
- package/dist/index.cjs +336 -0
- package/dist/index.d.ts +200 -26
- package/dist/index.js +69 -74
- package/dist/index.mjs +334 -0
- package/dist/libraryMeta.d.ts +1 -1
- package/dist/libraryMeta.js +1 -4
- package/dist/services/ApiRequest/ApiCall.d.ts +5 -5
- package/dist/services/ApiRequest/ApiCall.js +1 -2
- package/dist/services/ApiRequest/ApiRequest.d.ts +24 -24
- package/dist/services/ApiRequest/ApiRequest.js +110 -115
- package/dist/services/ApiRequest/ApiRequestError.d.ts +10 -10
- package/dist/services/ApiRequest/ApiRequestError.js +13 -15
- package/dist/services/ApiRequest/ApiResponseError.d.ts +12 -12
- package/dist/services/ApiRequest/ApiResponseError.js +15 -17
- package/dist/services/ApiRequest/HttpMethod.d.ts +7 -7
- package/dist/services/ApiRequest/HttpMethod.js +8 -11
- package/dist/types/index.d.ts +85 -85
- package/dist/types/index.js +10 -13
- package/package.json +17 -6
package/dist/index.js
CHANGED
|
@@ -1,74 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
this.
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
exports.default = TheAuthAPI;
|
|
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 assert from "assert";
|
|
11
|
+
import removeSlash from "remove-trailing-slash";
|
|
12
|
+
import ApiRequest from "./services/ApiRequest/ApiRequest";
|
|
13
|
+
import ApiKeys from "./endpoints/ApiKeys/ApiKeys";
|
|
14
|
+
import { HttpMethod } from "./services/ApiRequest/HttpMethod";
|
|
15
|
+
import Projects from "./endpoints/Projects/Projects";
|
|
16
|
+
import Accounts from "./endpoints/Accounts/Accounts";
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
18
|
+
const noop = () => { };
|
|
19
|
+
class TheAuthAPI {
|
|
20
|
+
/**
|
|
21
|
+
* @param {String} accessKey
|
|
22
|
+
* @param {Object} [options] (optional)
|
|
23
|
+
* @property {String} host (default: 'https://api.segment.io')
|
|
24
|
+
* @property {number} retryCount (default: 3)
|
|
25
|
+
*/
|
|
26
|
+
constructor(accessKey, options) {
|
|
27
|
+
var _a;
|
|
28
|
+
assert(accessKey, "You must pass your project's write key.");
|
|
29
|
+
this.accessKey = accessKey;
|
|
30
|
+
this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || "https://api.theauthapi.com");
|
|
31
|
+
this.api = new ApiRequest({
|
|
32
|
+
accessKey: this.accessKey,
|
|
33
|
+
host: this.host,
|
|
34
|
+
retryCount: (_a = options === null || options === void 0 ? void 0 : options.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
35
|
+
});
|
|
36
|
+
this.apiKeys = new ApiKeys(this.api);
|
|
37
|
+
this.projects = new Projects(this.api);
|
|
38
|
+
this.accounts = new Accounts(this.api);
|
|
39
|
+
}
|
|
40
|
+
/*
|
|
41
|
+
@deprecated
|
|
42
|
+
*/
|
|
43
|
+
authenticateAPIKey(key, callback) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const cb = callback || noop;
|
|
46
|
+
const done = (err) => {
|
|
47
|
+
cb(err, data);
|
|
48
|
+
};
|
|
49
|
+
const data = {
|
|
50
|
+
credentials: { api_key: key },
|
|
51
|
+
timestamp: new Date().getTime(),
|
|
52
|
+
sentAt: new Date().getTime(),
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
const key = yield this.api.request(HttpMethod.POST, "/auth/authenticate", data);
|
|
56
|
+
done(key);
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err.response) {
|
|
61
|
+
const error = new Error(err.response.statusText);
|
|
62
|
+
return done(error);
|
|
63
|
+
}
|
|
64
|
+
done(err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export default TheAuthAPI;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import removeSlash from 'remove-trailing-slash';
|
|
3
|
+
import axios from 'axios';
|
|
4
|
+
import axiosRetry from 'axios-retry';
|
|
5
|
+
|
|
6
|
+
/*! *****************************************************************************
|
|
7
|
+
Copyright (c) Microsoft Corporation.
|
|
8
|
+
|
|
9
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
10
|
+
purpose with or without fee is hereby granted.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
13
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
14
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
15
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
16
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
17
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
18
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
19
|
+
***************************************************************************** */
|
|
20
|
+
/* global Reflect, Promise */
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
24
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
25
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
26
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
27
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
28
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
29
|
+
step((generator = generator.apply(thisArg, [])).next());
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const version = "1.0.11";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* Throws when no response was received from the server
|
|
38
|
+
* @param message - error message
|
|
39
|
+
*
|
|
40
|
+
* */
|
|
41
|
+
class ApiRequestError extends Error {
|
|
42
|
+
constructor(message) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.name = 'ApiRequestError';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
51
|
+
* @param statusCode - HTTP status code the server responded with
|
|
52
|
+
* @param message - error message
|
|
53
|
+
*
|
|
54
|
+
* */
|
|
55
|
+
class ApiResponseError extends Error {
|
|
56
|
+
constructor(statusCode, message) {
|
|
57
|
+
super(`(${statusCode}): ${message}`);
|
|
58
|
+
this.statusCode = statusCode;
|
|
59
|
+
this.name = "ApiResponseError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
class ApiRequest {
|
|
64
|
+
constructor(config) {
|
|
65
|
+
const { host, accessKey, headers, retryCount } = config;
|
|
66
|
+
this.host = host;
|
|
67
|
+
this.accessKey = accessKey;
|
|
68
|
+
this.headers = this._generateDefaultHeaders();
|
|
69
|
+
this.retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 3;
|
|
70
|
+
if (headers) {
|
|
71
|
+
this.headers = Object.assign(Object.assign({}, this.headers), { headers });
|
|
72
|
+
}
|
|
73
|
+
this._init();
|
|
74
|
+
}
|
|
75
|
+
_init() {
|
|
76
|
+
var _a;
|
|
77
|
+
const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
78
|
+
function isIsoDateString(value) {
|
|
79
|
+
return value && typeof value === "string" && isoDateFormat.test(value);
|
|
80
|
+
}
|
|
81
|
+
function handleDates(body) {
|
|
82
|
+
if (body === null || body === undefined || typeof body !== "object") {
|
|
83
|
+
return body;
|
|
84
|
+
}
|
|
85
|
+
for (const key of Object.keys(body)) {
|
|
86
|
+
const value = body[key];
|
|
87
|
+
if (isIsoDateString(value)) {
|
|
88
|
+
body[key] = new Date(value);
|
|
89
|
+
}
|
|
90
|
+
else if (typeof value === "object") {
|
|
91
|
+
handleDates(value);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
axios.interceptors.response.use((response) => {
|
|
96
|
+
handleDates(response.data);
|
|
97
|
+
return response;
|
|
98
|
+
});
|
|
99
|
+
axiosRetry(axios, {
|
|
100
|
+
retries: (_a = this.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
101
|
+
retryCondition: this._isErrorRetryable,
|
|
102
|
+
retryDelay: axiosRetry.exponentialDelay,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
request(method, endpoint, payload) {
|
|
106
|
+
var _a;
|
|
107
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
try {
|
|
109
|
+
const response = yield axios.request({
|
|
110
|
+
baseURL: this.host,
|
|
111
|
+
method: method,
|
|
112
|
+
url: endpoint,
|
|
113
|
+
data: payload,
|
|
114
|
+
headers: this.headers,
|
|
115
|
+
});
|
|
116
|
+
return response.data;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
if (axios.isAxiosError(error)) {
|
|
120
|
+
if (error.response) {
|
|
121
|
+
throw new ApiResponseError(error.response.status, (_a = error.response.data.message) !== null && _a !== void 0 ? _a : error.response.statusText);
|
|
122
|
+
}
|
|
123
|
+
else if (error.request) {
|
|
124
|
+
throw new ApiRequestError(error.message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
_generateDefaultHeaders() {
|
|
132
|
+
return {
|
|
133
|
+
"user-agent": `theauthapi-client-node/${version}`,
|
|
134
|
+
"x-api-key": this.accessKey,
|
|
135
|
+
"api-key": this.accessKey,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
_isErrorRetryable(error) {
|
|
139
|
+
// Retry Network Errors.
|
|
140
|
+
if (axiosRetry.isNetworkError(error)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
if (!error.response) {
|
|
144
|
+
// Cannot determine if the request can be retried
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
// Retry Server Errors (5xx).
|
|
148
|
+
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
// Retry if rate limited.
|
|
152
|
+
if (error.response.status === 429) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
var HttpMethod;
|
|
160
|
+
(function (HttpMethod) {
|
|
161
|
+
HttpMethod["GET"] = "GET";
|
|
162
|
+
HttpMethod["POST"] = "POST";
|
|
163
|
+
HttpMethod["DELETE"] = "DELETE";
|
|
164
|
+
HttpMethod["PATCH"] = "PATCH";
|
|
165
|
+
HttpMethod["PUT"] = "PUT";
|
|
166
|
+
})(HttpMethod || (HttpMethod = {}));
|
|
167
|
+
|
|
168
|
+
class ApiKeys {
|
|
169
|
+
constructor(apiService) {
|
|
170
|
+
this.api = apiService;
|
|
171
|
+
this.endpoint = "/api-keys/";
|
|
172
|
+
}
|
|
173
|
+
isValidKey(apikey) {
|
|
174
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
+
try {
|
|
176
|
+
const key = yield this.authenticateKey(apikey);
|
|
177
|
+
return key.key !== undefined;
|
|
178
|
+
}
|
|
179
|
+
catch (error) {
|
|
180
|
+
if (error instanceof ApiResponseError && error.statusCode === 404) {
|
|
181
|
+
return false;
|
|
182
|
+
}
|
|
183
|
+
throw error;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
authenticateKey(apikey) {
|
|
188
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
189
|
+
return yield this.api.request(HttpMethod.POST, `/api-keys/auth/${apikey}`);
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
getKeys(filter) {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
const endpoint = this.getKeysFilterEndpoint(filter);
|
|
195
|
+
return yield this.api.request(HttpMethod.GET, endpoint);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
getKey(apikey) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
200
|
+
return yield this.api.request(HttpMethod.GET, `/api-keys/${apikey}`);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
createKey(apiKey) {
|
|
204
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
+
return yield this.api.request(HttpMethod.POST, "/api-keys", apiKey);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
updateKey(apiKey, updatedKey) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}`, updatedKey);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
deleteKey(apiKey) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
215
|
+
return yield this.api.request(HttpMethod.DELETE, `/api-keys/${apiKey}`);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
reactivateKey(apiKey) {
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}/reactivate`);
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
rotateKey(apiKey) {
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
return yield this.api.request(HttpMethod.POST, `/api-keys/${apiKey}/rotate`);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
getKeysFilterEndpoint(filter) {
|
|
229
|
+
let filters = [];
|
|
230
|
+
if (filter !== undefined) {
|
|
231
|
+
filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
|
|
232
|
+
}
|
|
233
|
+
return `${this.endpoint}${filter !== undefined ? "?" : ""}${filters.join("&")}`;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
class Projects {
|
|
238
|
+
constructor(apiService) {
|
|
239
|
+
this.api = apiService;
|
|
240
|
+
this.endpoint = "/projects";
|
|
241
|
+
}
|
|
242
|
+
getProjects(accountId) {
|
|
243
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
244
|
+
return yield this.api.request(HttpMethod.GET, `${this.endpoint}?accountId=${accountId}`);
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
getProject(projectId) {
|
|
248
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${projectId}`);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
deleteProject(projectId) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
return yield this.api.request(HttpMethod.DELETE, `${this.endpoint}/${projectId}`);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
createProject(project) {
|
|
258
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
259
|
+
return yield this.api.request(HttpMethod.POST, this.endpoint, project);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
updateProject(projectId, project) {
|
|
263
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
264
|
+
return this.api.request(HttpMethod.PATCH, `${this.endpoint}/${projectId}`, project);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
class Accounts {
|
|
270
|
+
constructor(apiService) {
|
|
271
|
+
this.api = apiService;
|
|
272
|
+
this.endpoint = "/accounts";
|
|
273
|
+
}
|
|
274
|
+
getAccount(accountId) {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${accountId}`);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
282
|
+
const noop = () => { };
|
|
283
|
+
class TheAuthAPI {
|
|
284
|
+
/**
|
|
285
|
+
* @param {String} accessKey
|
|
286
|
+
* @param {Object} [options] (optional)
|
|
287
|
+
* @property {String} host (default: 'https://api.segment.io')
|
|
288
|
+
* @property {number} retryCount (default: 3)
|
|
289
|
+
*/
|
|
290
|
+
constructor(accessKey, options) {
|
|
291
|
+
var _a;
|
|
292
|
+
assert(accessKey, "You must pass your project's write key.");
|
|
293
|
+
this.accessKey = accessKey;
|
|
294
|
+
this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || "https://api.theauthapi.com");
|
|
295
|
+
this.api = new ApiRequest({
|
|
296
|
+
accessKey: this.accessKey,
|
|
297
|
+
host: this.host,
|
|
298
|
+
retryCount: (_a = options === null || options === void 0 ? void 0 : options.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
299
|
+
});
|
|
300
|
+
this.apiKeys = new ApiKeys(this.api);
|
|
301
|
+
this.projects = new Projects(this.api);
|
|
302
|
+
this.accounts = new Accounts(this.api);
|
|
303
|
+
}
|
|
304
|
+
/*
|
|
305
|
+
@deprecated
|
|
306
|
+
*/
|
|
307
|
+
authenticateAPIKey(key, callback) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
+
const cb = callback || noop;
|
|
310
|
+
const done = (err) => {
|
|
311
|
+
cb(err, data);
|
|
312
|
+
};
|
|
313
|
+
const data = {
|
|
314
|
+
credentials: { api_key: key },
|
|
315
|
+
timestamp: new Date().getTime(),
|
|
316
|
+
sentAt: new Date().getTime(),
|
|
317
|
+
};
|
|
318
|
+
try {
|
|
319
|
+
const key = yield this.api.request(HttpMethod.POST, "/auth/authenticate", data);
|
|
320
|
+
done(key);
|
|
321
|
+
return key;
|
|
322
|
+
}
|
|
323
|
+
catch (err) {
|
|
324
|
+
if (err.response) {
|
|
325
|
+
const error = new Error(err.response.statusText);
|
|
326
|
+
return done(error);
|
|
327
|
+
}
|
|
328
|
+
done(err);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export { TheAuthAPI as default };
|
package/dist/libraryMeta.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.11";
|
|
1
|
+
export declare const version = "1.0.11";
|
package/dist/libraryMeta.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpMethod } from "./HttpMethod";
|
|
2
|
-
interface ApiCall {
|
|
3
|
-
request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
|
|
4
|
-
}
|
|
5
|
-
export default ApiCall;
|
|
1
|
+
import { HttpMethod } from "./HttpMethod";
|
|
2
|
+
interface ApiCall {
|
|
3
|
+
request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
|
|
4
|
+
}
|
|
5
|
+
export default ApiCall;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { HttpMethod } from "./HttpMethod";
|
|
2
|
-
import ApiCall from "./ApiCall";
|
|
3
|
-
type Config = {
|
|
4
|
-
host: string;
|
|
5
|
-
accessKey: string;
|
|
6
|
-
headers?: object;
|
|
7
|
-
retryCount?: number;
|
|
8
|
-
};
|
|
9
|
-
declare class ApiRequest implements ApiCall {
|
|
10
|
-
host: string;
|
|
11
|
-
headers: object;
|
|
12
|
-
accessKey: string;
|
|
13
|
-
retryCount: number;
|
|
14
|
-
constructor(config: Config);
|
|
15
|
-
_init(): void;
|
|
16
|
-
request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
|
|
17
|
-
_generateDefaultHeaders(): {
|
|
18
|
-
"user-agent": string;
|
|
19
|
-
"x-api-key": string;
|
|
20
|
-
"api-key": string;
|
|
21
|
-
};
|
|
22
|
-
_isErrorRetryable(error: any): boolean;
|
|
23
|
-
}
|
|
24
|
-
export default ApiRequest;
|
|
1
|
+
import { HttpMethod } from "./HttpMethod";
|
|
2
|
+
import ApiCall from "./ApiCall";
|
|
3
|
+
type Config = {
|
|
4
|
+
host: string;
|
|
5
|
+
accessKey: string;
|
|
6
|
+
headers?: object;
|
|
7
|
+
retryCount?: number;
|
|
8
|
+
};
|
|
9
|
+
declare class ApiRequest implements ApiCall {
|
|
10
|
+
host: string;
|
|
11
|
+
headers: object;
|
|
12
|
+
accessKey: string;
|
|
13
|
+
retryCount: number;
|
|
14
|
+
constructor(config: Config);
|
|
15
|
+
_init(): void;
|
|
16
|
+
request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
|
|
17
|
+
_generateDefaultHeaders(): {
|
|
18
|
+
"user-agent": string;
|
|
19
|
+
"x-api-key": string;
|
|
20
|
+
"api-key": string;
|
|
21
|
+
};
|
|
22
|
+
_isErrorRetryable(error: any): boolean;
|
|
23
|
+
}
|
|
24
|
+
export default ApiRequest;
|