theauthapi 1.0.11 → 1.0.13

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.
Files changed (36) hide show
  1. package/README.md +366 -334
  2. package/dist/endpoints/Accounts/Accounts.d.ts +10 -10
  3. package/dist/endpoints/Accounts/AccountsInterface.d.ts +4 -4
  4. package/dist/endpoints/ApiKeys/ApiKeys.d.ts +19 -18
  5. package/dist/endpoints/ApiKeys/ApiKeysInterface.d.ts +12 -11
  6. package/dist/endpoints/Projects/Projects.d.ts +14 -14
  7. package/dist/endpoints/Projects/ProjectsInterface.d.ts +8 -8
  8. package/dist/index.cjs +336 -0
  9. package/dist/index.d.ts +200 -26
  10. package/dist/index.mjs +334 -0
  11. package/dist/libraryMeta.d.ts +1 -1
  12. package/dist/services/ApiRequest/ApiCall.d.ts +5 -5
  13. package/dist/services/ApiRequest/ApiRequest.d.ts +24 -24
  14. package/dist/services/ApiRequest/ApiRequestError.d.ts +10 -10
  15. package/dist/services/ApiRequest/ApiResponseError.d.ts +12 -12
  16. package/dist/services/ApiRequest/HttpMethod.d.ts +7 -7
  17. package/dist/types/index.d.ts +85 -85
  18. package/package.json +14 -7
  19. package/History.md +0 -5
  20. package/dist/endpoints/Accounts/Accounts.js +0 -24
  21. package/dist/endpoints/Accounts/AccountsInterface.js +0 -2
  22. package/dist/endpoints/ApiKeys/ApiKeys.js +0 -80
  23. package/dist/endpoints/ApiKeys/ApiKeysInterface.js +0 -2
  24. package/dist/endpoints/Projects/Projects.js +0 -44
  25. package/dist/endpoints/Projects/ProjectsInterface.js +0 -2
  26. package/dist/index.js +0 -74
  27. package/dist/libraryMeta.js +0 -4
  28. package/dist/services/ApiRequest/ApiCall.js +0 -2
  29. package/dist/services/ApiRequest/ApiRequest.js +0 -115
  30. package/dist/services/ApiRequest/ApiRequestError.js +0 -15
  31. package/dist/services/ApiRequest/ApiResponseError.js +0 -17
  32. package/dist/services/ApiRequest/HttpMethod.js +0 -11
  33. package/dist/types/index.js +0 -13
  34. package/dist/usage.js +0 -20
  35. package/dist/util/index.d.ts +0 -1
  36. package/dist/util/index.js +0 -13
package/dist/index.d.ts CHANGED
@@ -1,26 +1,200 @@
1
- import ApiRequest from "./services/ApiRequest/ApiRequest";
2
- import ApiKeys from "./endpoints/ApiKeys/ApiKeys";
3
- import Projects from "./endpoints/Projects/Projects";
4
- import Accounts from "./endpoints/Accounts/Accounts";
5
- declare type Options = {
6
- host?: string;
7
- retryCount?: number;
8
- };
9
- declare class TheAuthAPI {
10
- accessKey: string;
11
- host: string;
12
- timeout: number | string | undefined;
13
- api: ApiRequest;
14
- apiKeys: ApiKeys;
15
- projects: Projects;
16
- accounts: Accounts;
17
- /**
18
- * @param {String} accessKey
19
- * @param {Object} [options] (optional)
20
- * @property {String} host (default: 'https://api.segment.io')
21
- * @property {number} retryCount (default: 3)
22
- */
23
- constructor(accessKey: string, options?: Options);
24
- authenticateAPIKey(key: string, callback?: (err: any, data: any) => any): Promise<unknown>;
25
- }
26
- export default TheAuthAPI;
1
+ declare enum HttpMethod {
2
+ GET = "GET",
3
+ POST = "POST",
4
+ DELETE = "DELETE",
5
+ PATCH = "PATCH",
6
+ PUT = "PUT"
7
+ }
8
+
9
+ interface ApiCall {
10
+ request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
11
+ }
12
+
13
+ type Config = {
14
+ host: string;
15
+ accessKey: string;
16
+ headers?: object;
17
+ retryCount?: number;
18
+ };
19
+ declare class ApiRequest implements ApiCall {
20
+ host: string;
21
+ headers: object;
22
+ accessKey: string;
23
+ retryCount: number;
24
+ constructor(config: Config);
25
+ _init(): void;
26
+ request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
27
+ _generateDefaultHeaders(): {
28
+ "user-agent": string;
29
+ "x-api-key": string;
30
+ "api-key": string;
31
+ };
32
+ _isErrorRetryable(error: any): boolean;
33
+ }
34
+
35
+ type ApiKey = {
36
+ key: string;
37
+ name: string;
38
+ customMetaData: AnyJson;
39
+ customAccountId: string;
40
+ customUserId: string;
41
+ env: Environment;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ isActive: boolean;
45
+ rateLimitConfigs: RateLimitConfiguration;
46
+ expiry: Date;
47
+ };
48
+ type RateLimitConfiguration = {
49
+ rateLimit: number;
50
+ rateLimitTtl: number;
51
+ };
52
+ type ApiKeyInput = {
53
+ name: string;
54
+ projectId?: string;
55
+ key?: string;
56
+ customMetaData?: AnyJson;
57
+ customAccountId?: string;
58
+ customUserId?: string;
59
+ rateLimitConfigs?: RateLimitConfiguration;
60
+ expiry?: Date;
61
+ };
62
+ type ApiKeyFilter = {
63
+ projectId?: string;
64
+ name?: string;
65
+ customAccountId?: string | null;
66
+ customUserId?: string | null;
67
+ isActive?: boolean;
68
+ };
69
+ type UpdateApiKeyInput = {
70
+ name: string;
71
+ key?: string;
72
+ customMetaData?: AnyJson;
73
+ customAccountId?: string;
74
+ customUserId?: string;
75
+ expiry?: Date | null;
76
+ rateLimitConfigs?: RateLimitConfiguration | null;
77
+ };
78
+ declare enum AuthedEntityType {
79
+ USER = "USER",
80
+ ACCESS_KEY = "ACCESS_KEY"
81
+ }
82
+ type AuthBaseEntity = {
83
+ isActive: boolean;
84
+ createdBy: string;
85
+ createdByType?: AuthedEntityType;
86
+ createdIn: string;
87
+ lastChangedBy: string;
88
+ lastChangedByType?: AuthedEntityType;
89
+ updatedAt: Date;
90
+ createdAt: Date;
91
+ };
92
+ type Project = AuthBaseEntity & {
93
+ id: string;
94
+ name: string;
95
+ accountId: string;
96
+ env: Environment;
97
+ };
98
+ declare enum Environment {
99
+ LIVE = "live",
100
+ TEST = "test"
101
+ }
102
+ type CreateProjectInput = {
103
+ name: string;
104
+ accountId: string;
105
+ env: Environment;
106
+ };
107
+ type UpdateProjectInput = {
108
+ name: string;
109
+ };
110
+ type Account = AuthBaseEntity & {
111
+ id: string;
112
+ name: string;
113
+ };
114
+ type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
115
+ type JsonMap = {
116
+ [key: string]: AnyJson;
117
+ };
118
+ type JsonArray = Array<AnyJson>;
119
+
120
+ interface ApiKeysInterface {
121
+ isValidKey(apiKey: string): Promise<boolean>;
122
+ getKey(apiKey: string): Promise<ApiKey>;
123
+ authenticateKey(apiKey: string): Promise<ApiKey>;
124
+ getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
125
+ createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
126
+ updateKey(apiKey: string, updateTo: UpdateApiKeyInput): Promise<ApiKey>;
127
+ deleteKey(apiKey: string): Promise<boolean>;
128
+ reactivateKey(apiKey: string): Promise<ApiKey>;
129
+ rotateKey(apiKey: string): Promise<ApiKey>;
130
+ }
131
+
132
+ declare class ApiKeys implements ApiKeysInterface {
133
+ api: ApiRequest;
134
+ private readonly endpoint;
135
+ constructor(apiService: ApiRequest);
136
+ isValidKey(apikey: string): Promise<boolean>;
137
+ authenticateKey(apikey: string): Promise<ApiKey>;
138
+ getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
139
+ getKey(apikey: string): Promise<ApiKey>;
140
+ createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
141
+ updateKey(apiKey: string, updatedKey: UpdateApiKeyInput): Promise<ApiKey>;
142
+ deleteKey(apiKey: string): Promise<boolean>;
143
+ reactivateKey(apiKey: string): Promise<ApiKey>;
144
+ rotateKey(apiKey: string): Promise<ApiKey>;
145
+ private getKeysFilterEndpoint;
146
+ }
147
+
148
+ interface ProjectsInterface {
149
+ getProjects(accountId: string): Promise<Project[]>;
150
+ getProject(projectId: string): Promise<Project>;
151
+ deleteProject(projectId: string): Promise<boolean>;
152
+ createProject(project: CreateProjectInput): Promise<Project>;
153
+ updateProject(name: string, updateTo: UpdateProjectInput): Promise<Project>;
154
+ }
155
+
156
+ declare class Projects implements ProjectsInterface {
157
+ api: ApiRequest;
158
+ endpoint: string;
159
+ constructor(apiService: ApiRequest);
160
+ getProjects(accountId: string): Promise<Project[]>;
161
+ getProject(projectId: string): Promise<Project>;
162
+ deleteProject(projectId: string): Promise<boolean>;
163
+ createProject(project: CreateProjectInput): Promise<Project>;
164
+ updateProject(projectId: string, project: UpdateProjectInput): Promise<Project>;
165
+ }
166
+
167
+ interface AccountsInterface {
168
+ getAccount(accountId: string): Promise<Account>;
169
+ }
170
+
171
+ declare class Accounts implements AccountsInterface {
172
+ api: ApiRequest;
173
+ endpoint: string;
174
+ constructor(apiService: ApiRequest);
175
+ getAccount(accountId: string): Promise<Account>;
176
+ }
177
+
178
+ type Options = {
179
+ host?: string;
180
+ retryCount?: number;
181
+ };
182
+ declare class TheAuthAPI {
183
+ accessKey: string;
184
+ host: string;
185
+ timeout: number | string | undefined;
186
+ api: ApiRequest;
187
+ apiKeys: ApiKeys;
188
+ projects: Projects;
189
+ accounts: Accounts;
190
+ /**
191
+ * @param {String} accessKey
192
+ * @param {Object} [options] (optional)
193
+ * @property {String} host (default: 'https://api.segment.io')
194
+ * @property {number} retryCount (default: 3)
195
+ */
196
+ constructor(accessKey: string, options?: Options);
197
+ authenticateAPIKey(key: string, callback?: (err: any, data: any) => any): Promise<unknown>;
198
+ }
199
+
200
+ export { TheAuthAPI as default };
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 };
@@ -1 +1 @@
1
- export declare const version = "1.0.11";
1
+ export declare const version = "1.0.11";
@@ -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,24 +1,24 @@
1
- import { HttpMethod } from "./HttpMethod";
2
- import ApiCall from "./ApiCall";
3
- declare 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;
@@ -1,10 +1,10 @@
1
- /**
2
- *
3
- * Throws when no response was received from the server
4
- * @param message - error message
5
- *
6
- * */
7
- declare class ApiRequestError extends Error {
8
- constructor(message: string);
9
- }
10
- export default ApiRequestError;
1
+ /**
2
+ *
3
+ * Throws when no response was received from the server
4
+ * @param message - error message
5
+ *
6
+ * */
7
+ declare class ApiRequestError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ export default ApiRequestError;
@@ -1,12 +1,12 @@
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
+ /**
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,7 +1,7 @@
1
- export declare enum HttpMethod {
2
- GET = "GET",
3
- POST = "POST",
4
- DELETE = "DELETE",
5
- PATCH = "PATCH",
6
- PUT = "PUT"
7
- }
1
+ export declare enum HttpMethod {
2
+ GET = "GET",
3
+ POST = "POST",
4
+ DELETE = "DELETE",
5
+ PATCH = "PATCH",
6
+ PUT = "PUT"
7
+ }