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
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 That API Company
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 That API Company
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -357,6 +357,8 @@ async function getProjectsIds(accountId: string): Promise<string[]> {
|
|
|
357
357
|
}
|
|
358
358
|
```
|
|
359
359
|
|
|
360
|
+
⚠️ Works in Node.js 16+ and all modern bundlers. Not supported in Node.js 10–14.
|
|
361
|
+
|
|
360
362
|
### 📙 Further Reading
|
|
361
363
|
|
|
362
364
|
- Create your account [https://theauthapi.com](https://theauthapi.com)
|
package/dist/index.cjs
CHANGED
|
@@ -34,303 +34,305 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
34
34
|
|
|
35
35
|
const version = '1.0.11';
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
*
|
|
39
|
-
* Throws when no response was received from the server
|
|
40
|
-
* @param message - error message
|
|
41
|
-
*
|
|
42
|
-
* */
|
|
43
|
-
class ApiRequestError extends Error {
|
|
44
|
-
constructor(message) {
|
|
45
|
-
super(message);
|
|
46
|
-
this.name = 'ApiRequestError';
|
|
47
|
-
}
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* Throws when no response was received from the server
|
|
40
|
+
* @param message - error message
|
|
41
|
+
*
|
|
42
|
+
* */
|
|
43
|
+
class ApiRequestError extends Error {
|
|
44
|
+
constructor(message) {
|
|
45
|
+
super(message);
|
|
46
|
+
this.name = 'ApiRequestError';
|
|
47
|
+
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
51
|
-
*
|
|
52
|
-
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
53
|
-
* @param statusCode - HTTP status code the server responded with
|
|
54
|
-
* @param message - error message
|
|
55
|
-
*
|
|
56
|
-
* */
|
|
57
|
-
class ApiResponseError extends Error {
|
|
58
|
-
constructor(statusCode, message) {
|
|
59
|
-
super(`(${statusCode}): ${message}`);
|
|
60
|
-
this.statusCode = statusCode;
|
|
61
|
-
this.name = 'ApiResponseError';
|
|
62
|
-
}
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
53
|
+
* @param statusCode - HTTP status code the server responded with
|
|
54
|
+
* @param message - error message
|
|
55
|
+
*
|
|
56
|
+
* */
|
|
57
|
+
class ApiResponseError extends Error {
|
|
58
|
+
constructor(statusCode, message) {
|
|
59
|
+
super(`(${statusCode}): ${message}`);
|
|
60
|
+
this.statusCode = statusCode;
|
|
61
|
+
this.name = 'ApiResponseError';
|
|
62
|
+
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
class ApiRequest {
|
|
66
|
-
constructor(config) {
|
|
67
|
-
const { host, accessKey, headers, retryCount } = config;
|
|
68
|
-
this.host = host;
|
|
69
|
-
this.accessKey = accessKey;
|
|
70
|
-
this.headers = this._generateDefaultHeaders();
|
|
71
|
-
this.retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 3;
|
|
72
|
-
if (headers) {
|
|
73
|
-
this.headers = Object.assign(Object.assign({}, this.headers), { headers });
|
|
74
|
-
}
|
|
75
|
-
this._init();
|
|
76
|
-
}
|
|
77
|
-
_init() {
|
|
78
|
-
var _a;
|
|
79
|
-
const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
80
|
-
function isIsoDateString(value) {
|
|
81
|
-
return value && typeof value === 'string' && isoDateFormat.test(value);
|
|
82
|
-
}
|
|
83
|
-
function handleDates(body) {
|
|
84
|
-
if (body === null || body === undefined || typeof body !== 'object') {
|
|
85
|
-
return body;
|
|
86
|
-
}
|
|
87
|
-
for (const key of Object.keys(body)) {
|
|
88
|
-
const value = body[key];
|
|
89
|
-
if (isIsoDateString(value)) {
|
|
90
|
-
body[key] = new Date(value);
|
|
91
|
-
}
|
|
92
|
-
else if (typeof value === 'object') {
|
|
93
|
-
handleDates(value);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
axios.interceptors.response.use((response) => {
|
|
98
|
-
handleDates(response.data);
|
|
99
|
-
return response;
|
|
100
|
-
});
|
|
101
|
-
axiosRetry(axios, {
|
|
102
|
-
retries: (_a = this.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
103
|
-
retryCondition: this._isErrorRetryable,
|
|
104
|
-
retryDelay: axiosRetry.exponentialDelay,
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
request(method, endpoint, payload) {
|
|
108
|
-
var _a;
|
|
109
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
-
try {
|
|
111
|
-
const response = yield axios.request({
|
|
112
|
-
baseURL: this.host,
|
|
113
|
-
method: method,
|
|
114
|
-
url: endpoint,
|
|
115
|
-
data: payload,
|
|
116
|
-
headers:
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
'
|
|
137
|
-
'api-key': this.accessKey,
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
65
|
+
class ApiRequest {
|
|
66
|
+
constructor(config) {
|
|
67
|
+
const { host, accessKey, headers, retryCount } = config;
|
|
68
|
+
this.host = host;
|
|
69
|
+
this.accessKey = accessKey;
|
|
70
|
+
this.headers = this._generateDefaultHeaders();
|
|
71
|
+
this.retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 3;
|
|
72
|
+
if (headers) {
|
|
73
|
+
this.headers = Object.assign(Object.assign({}, this.headers), { headers });
|
|
74
|
+
}
|
|
75
|
+
this._init();
|
|
76
|
+
}
|
|
77
|
+
_init() {
|
|
78
|
+
var _a;
|
|
79
|
+
const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
80
|
+
function isIsoDateString(value) {
|
|
81
|
+
return value && typeof value === 'string' && isoDateFormat.test(value);
|
|
82
|
+
}
|
|
83
|
+
function handleDates(body) {
|
|
84
|
+
if (body === null || body === undefined || typeof body !== 'object') {
|
|
85
|
+
return body;
|
|
86
|
+
}
|
|
87
|
+
for (const key of Object.keys(body)) {
|
|
88
|
+
const value = body[key];
|
|
89
|
+
if (isIsoDateString(value)) {
|
|
90
|
+
body[key] = new Date(value);
|
|
91
|
+
}
|
|
92
|
+
else if (typeof value === 'object') {
|
|
93
|
+
handleDates(value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
axios.interceptors.response.use((response) => {
|
|
98
|
+
handleDates(response.data);
|
|
99
|
+
return response;
|
|
100
|
+
});
|
|
101
|
+
axiosRetry(axios, {
|
|
102
|
+
retries: (_a = this.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
103
|
+
retryCondition: this._isErrorRetryable,
|
|
104
|
+
retryDelay: axiosRetry.exponentialDelay,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
request(method, endpoint, payload, customHeaders) {
|
|
108
|
+
var _a;
|
|
109
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
110
|
+
try {
|
|
111
|
+
const response = yield axios.request({
|
|
112
|
+
baseURL: this.host,
|
|
113
|
+
method: method,
|
|
114
|
+
url: endpoint,
|
|
115
|
+
data: payload,
|
|
116
|
+
headers: customHeaders
|
|
117
|
+
? Object.assign(Object.assign({}, this.headers), customHeaders) : this.headers,
|
|
118
|
+
});
|
|
119
|
+
return response.data;
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (axios.isAxiosError(error)) {
|
|
123
|
+
if (error.response) {
|
|
124
|
+
throw new ApiResponseError(error.response.status, (_a = error.response.data.message) !== null && _a !== void 0 ? _a : error.response.statusText);
|
|
125
|
+
}
|
|
126
|
+
else if (error.request) {
|
|
127
|
+
throw new ApiRequestError(error.message);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
_generateDefaultHeaders() {
|
|
135
|
+
return {
|
|
136
|
+
'user-agent': `theauthapi-client-node/${version}`,
|
|
137
|
+
'x-api-key': this.accessKey,
|
|
138
|
+
'api-key': this.accessKey,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
_isErrorRetryable(error) {
|
|
142
|
+
// Retry Network Errors.
|
|
143
|
+
if (axiosRetry.isNetworkError(error)) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
if (!error.response) {
|
|
147
|
+
// Cannot determine if the request can be retried
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
// Retry Server Errors (5xx).
|
|
151
|
+
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
// Retry if rate limited.
|
|
155
|
+
if (error.response.status === 429) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
159
160
|
}
|
|
160
161
|
|
|
161
|
-
var HttpMethod;
|
|
162
|
-
(function (HttpMethod) {
|
|
163
|
-
HttpMethod["GET"] = "GET";
|
|
164
|
-
HttpMethod["POST"] = "POST";
|
|
165
|
-
HttpMethod["DELETE"] = "DELETE";
|
|
166
|
-
HttpMethod["PATCH"] = "PATCH";
|
|
167
|
-
HttpMethod["PUT"] = "PUT";
|
|
162
|
+
var HttpMethod;
|
|
163
|
+
(function (HttpMethod) {
|
|
164
|
+
HttpMethod["GET"] = "GET";
|
|
165
|
+
HttpMethod["POST"] = "POST";
|
|
166
|
+
HttpMethod["DELETE"] = "DELETE";
|
|
167
|
+
HttpMethod["PATCH"] = "PATCH";
|
|
168
|
+
HttpMethod["PUT"] = "PUT";
|
|
168
169
|
})(HttpMethod || (HttpMethod = {}));
|
|
169
170
|
|
|
170
|
-
class ApiKeys {
|
|
171
|
-
constructor(apiService) {
|
|
172
|
-
this.api = apiService;
|
|
173
|
-
this.endpoint = '/api-keys/';
|
|
174
|
-
}
|
|
175
|
-
isValidKey(apikey) {
|
|
176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
try {
|
|
178
|
-
const key = yield this.authenticateKey(apikey);
|
|
179
|
-
return key.key !== undefined;
|
|
180
|
-
}
|
|
181
|
-
catch (error) {
|
|
182
|
-
if (error instanceof ApiResponseError && error.statusCode === 404) {
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
authenticateKey(apikey) {
|
|
190
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
171
|
+
class ApiKeys {
|
|
172
|
+
constructor(apiService) {
|
|
173
|
+
this.api = apiService;
|
|
174
|
+
this.endpoint = '/api-keys/';
|
|
175
|
+
}
|
|
176
|
+
isValidKey(apikey, origin) {
|
|
177
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
178
|
+
try {
|
|
179
|
+
const key = yield this.authenticateKey(apikey, origin);
|
|
180
|
+
return key.key !== undefined;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
if (error instanceof ApiResponseError && error.statusCode === 404) {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
authenticateKey(apikey, origin) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
const headers = origin ? { 'x-origin-domain': origin } : undefined;
|
|
193
|
+
return yield this.api.request(HttpMethod.POST, `/api-keys/auth/${apikey}`, undefined, headers);
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
getKeys(filter) {
|
|
197
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
198
|
+
const endpoint = this.getKeysFilterEndpoint(filter);
|
|
199
|
+
return yield this.api.request(HttpMethod.GET, endpoint);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
getKey(apikey) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
return yield this.api.request(HttpMethod.GET, `/api-keys/${apikey}`);
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
createKey(apiKey) {
|
|
208
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
209
|
+
return yield this.api.request(HttpMethod.POST, '/api-keys', apiKey);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
updateKey(apiKey, updatedKey) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}`, updatedKey);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
deleteKey(apiKey) {
|
|
218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
+
return yield this.api.request(HttpMethod.DELETE, `/api-keys/${apiKey}`);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
reactivateKey(apiKey) {
|
|
223
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
224
|
+
return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}/reactivate`);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
rotateKey(apiKey) {
|
|
228
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
return yield this.api.request(HttpMethod.POST, `/api-keys/${apiKey}/rotate`);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
getKeysFilterEndpoint(filter) {
|
|
233
|
+
let filters = [];
|
|
234
|
+
if (filter !== undefined) {
|
|
235
|
+
filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
|
|
236
|
+
}
|
|
237
|
+
return `${this.endpoint}${filter !== undefined ? '?' : ''}${filters.join('&')}`;
|
|
238
|
+
}
|
|
237
239
|
}
|
|
238
240
|
|
|
239
|
-
class Projects {
|
|
240
|
-
constructor(apiService) {
|
|
241
|
-
this.api = apiService;
|
|
242
|
-
this.endpoint = '/projects';
|
|
243
|
-
}
|
|
244
|
-
getProjects(accountId) {
|
|
245
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
-
return yield this.api.request(HttpMethod.GET, `${this.endpoint}?accountId=${accountId}`);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
getProject(projectId) {
|
|
250
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
251
|
-
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${projectId}`);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
deleteProject(projectId) {
|
|
255
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
256
|
-
return yield this.api.request(HttpMethod.DELETE, `${this.endpoint}/${projectId}`);
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
createProject(project) {
|
|
260
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
261
|
-
return yield this.api.request(HttpMethod.POST, this.endpoint, project);
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
updateProject(projectId, project) {
|
|
265
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
-
return this.api.request(HttpMethod.PATCH, `${this.endpoint}/${projectId}`, project);
|
|
267
|
-
});
|
|
268
|
-
}
|
|
241
|
+
class Projects {
|
|
242
|
+
constructor(apiService) {
|
|
243
|
+
this.api = apiService;
|
|
244
|
+
this.endpoint = '/projects';
|
|
245
|
+
}
|
|
246
|
+
getProjects(accountId) {
|
|
247
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
248
|
+
return yield this.api.request(HttpMethod.GET, `${this.endpoint}?accountId=${accountId}`);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
getProject(projectId) {
|
|
252
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
253
|
+
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${projectId}`);
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
deleteProject(projectId) {
|
|
257
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
258
|
+
return yield this.api.request(HttpMethod.DELETE, `${this.endpoint}/${projectId}`);
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
createProject(project) {
|
|
262
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
263
|
+
return yield this.api.request(HttpMethod.POST, this.endpoint, project);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
updateProject(projectId, project) {
|
|
267
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
268
|
+
return this.api.request(HttpMethod.PATCH, `${this.endpoint}/${projectId}`, project);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
269
271
|
}
|
|
270
272
|
|
|
271
|
-
class Accounts {
|
|
272
|
-
constructor(apiService) {
|
|
273
|
-
this.api = apiService;
|
|
274
|
-
this.endpoint = '/accounts';
|
|
275
|
-
}
|
|
276
|
-
getAccount(accountId) {
|
|
277
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${accountId}`);
|
|
279
|
-
});
|
|
280
|
-
}
|
|
273
|
+
class Accounts {
|
|
274
|
+
constructor(apiService) {
|
|
275
|
+
this.api = apiService;
|
|
276
|
+
this.endpoint = '/accounts';
|
|
277
|
+
}
|
|
278
|
+
getAccount(accountId) {
|
|
279
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
280
|
+
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${accountId}`);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
281
283
|
}
|
|
282
284
|
|
|
283
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
284
|
-
const noop = () => { };
|
|
285
|
-
class TheAuthAPI {
|
|
286
|
-
/**
|
|
287
|
-
* @param {String} accessKey
|
|
288
|
-
* @param {Object} [options] (optional)
|
|
289
|
-
* @property {String} host (default: 'https://api.segment.io')
|
|
290
|
-
* @property {number} retryCount (default: 3)
|
|
291
|
-
*/
|
|
292
|
-
constructor(accessKey, options) {
|
|
293
|
-
var _a;
|
|
294
|
-
assert(accessKey, "You must pass your project's write key.");
|
|
295
|
-
this.accessKey = accessKey;
|
|
296
|
-
this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || 'https://api.theauthapi.com');
|
|
297
|
-
this.api = new ApiRequest({
|
|
298
|
-
accessKey: this.accessKey,
|
|
299
|
-
host: this.host,
|
|
300
|
-
retryCount: (_a = options === null || options === void 0 ? void 0 : options.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
301
|
-
});
|
|
302
|
-
this.apiKeys = new ApiKeys(this.api);
|
|
303
|
-
this.projects = new Projects(this.api);
|
|
304
|
-
this.accounts = new Accounts(this.api);
|
|
305
|
-
}
|
|
306
|
-
/*
|
|
307
|
-
@deprecated
|
|
308
|
-
*/
|
|
309
|
-
authenticateAPIKey(key, callback) {
|
|
310
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
311
|
-
const cb = callback || noop;
|
|
312
|
-
const done = (err) => {
|
|
313
|
-
cb(err, data);
|
|
314
|
-
};
|
|
315
|
-
const data = {
|
|
316
|
-
credentials: { api_key: key },
|
|
317
|
-
timestamp: new Date().getTime(),
|
|
318
|
-
sentAt: new Date().getTime(),
|
|
319
|
-
};
|
|
320
|
-
try {
|
|
321
|
-
const key = yield this.api.request(HttpMethod.POST, '/auth/authenticate', data);
|
|
322
|
-
done(key);
|
|
323
|
-
return key;
|
|
324
|
-
}
|
|
325
|
-
catch (err) {
|
|
326
|
-
if (err.response) {
|
|
327
|
-
const error = new Error(err.response.statusText);
|
|
328
|
-
return done(error);
|
|
329
|
-
}
|
|
330
|
-
done(err);
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
}
|
|
285
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
286
|
+
const noop = () => { };
|
|
287
|
+
class TheAuthAPI {
|
|
288
|
+
/**
|
|
289
|
+
* @param {String} accessKey
|
|
290
|
+
* @param {Object} [options] (optional)
|
|
291
|
+
* @property {String} host (default: 'https://api.segment.io')
|
|
292
|
+
* @property {number} retryCount (default: 3)
|
|
293
|
+
*/
|
|
294
|
+
constructor(accessKey, options) {
|
|
295
|
+
var _a;
|
|
296
|
+
assert(accessKey, "You must pass your project's write key.");
|
|
297
|
+
this.accessKey = accessKey;
|
|
298
|
+
this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || 'https://api.theauthapi.com');
|
|
299
|
+
this.api = new ApiRequest({
|
|
300
|
+
accessKey: this.accessKey,
|
|
301
|
+
host: this.host,
|
|
302
|
+
retryCount: (_a = options === null || options === void 0 ? void 0 : options.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
303
|
+
});
|
|
304
|
+
this.apiKeys = new ApiKeys(this.api);
|
|
305
|
+
this.projects = new Projects(this.api);
|
|
306
|
+
this.accounts = new Accounts(this.api);
|
|
307
|
+
}
|
|
308
|
+
/*
|
|
309
|
+
@deprecated
|
|
310
|
+
*/
|
|
311
|
+
authenticateAPIKey(key, callback) {
|
|
312
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
313
|
+
const cb = callback || noop;
|
|
314
|
+
const done = (err) => {
|
|
315
|
+
cb(err, data);
|
|
316
|
+
};
|
|
317
|
+
const data = {
|
|
318
|
+
credentials: { api_key: key },
|
|
319
|
+
timestamp: new Date().getTime(),
|
|
320
|
+
sentAt: new Date().getTime(),
|
|
321
|
+
};
|
|
322
|
+
try {
|
|
323
|
+
const key = yield this.api.request(HttpMethod.POST, '/auth/authenticate', data);
|
|
324
|
+
done(key);
|
|
325
|
+
return key;
|
|
326
|
+
}
|
|
327
|
+
catch (err) {
|
|
328
|
+
if (err.response) {
|
|
329
|
+
const error = new Error(err.response.statusText);
|
|
330
|
+
return done(error);
|
|
331
|
+
}
|
|
332
|
+
done(err);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
334
336
|
}
|
|
335
337
|
|
|
336
338
|
module.exports = TheAuthAPI;
|