theauthapi 1.0.0 → 1.0.1-2.1

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 (33) hide show
  1. package/README.md +366 -2
  2. package/dist/endpoints/Accounts/Accounts.d.ts +10 -0
  3. package/dist/endpoints/Accounts/Accounts.js +24 -0
  4. package/dist/endpoints/Accounts/AccountsInterface.d.ts +4 -0
  5. package/dist/endpoints/Accounts/AccountsInterface.js +2 -0
  6. package/dist/endpoints/ApiKeys/ApiKeys.d.ts +19 -0
  7. package/dist/endpoints/ApiKeys/ApiKeys.js +85 -0
  8. package/dist/endpoints/ApiKeys/ApiKeysInterface.d.ts +12 -0
  9. package/dist/endpoints/ApiKeys/ApiKeysInterface.js +2 -0
  10. package/dist/endpoints/Projects/Projects.d.ts +14 -0
  11. package/dist/endpoints/Projects/Projects.js +44 -0
  12. package/dist/endpoints/Projects/ProjectsInterface.d.ts +8 -0
  13. package/dist/endpoints/Projects/ProjectsInterface.js +2 -0
  14. package/dist/index.d.ts +26 -0
  15. package/dist/index.js +74 -0
  16. package/dist/libraryMeta.d.ts +1 -0
  17. package/dist/libraryMeta.js +4 -0
  18. package/dist/services/ApiRequest/ApiCall.d.ts +5 -0
  19. package/dist/services/ApiRequest/ApiCall.js +2 -0
  20. package/dist/services/ApiRequest/ApiRequest.d.ts +24 -0
  21. package/dist/services/ApiRequest/ApiRequest.js +115 -0
  22. package/dist/services/ApiRequest/ApiRequestError.d.ts +10 -0
  23. package/dist/services/ApiRequest/ApiRequestError.js +15 -0
  24. package/dist/services/ApiRequest/ApiResponseError.d.ts +12 -0
  25. package/dist/services/ApiRequest/ApiResponseError.js +17 -0
  26. package/dist/services/ApiRequest/HttpMethod.d.ts +7 -0
  27. package/dist/services/ApiRequest/HttpMethod.js +11 -0
  28. package/dist/types/index.d.ts +85 -0
  29. package/dist/types/index.js +13 -0
  30. package/package.json +30 -34
  31. package/History.md +0 -5
  32. package/index.js +0 -182
  33. package/test.js +0 -113
package/README.md CHANGED
@@ -1,2 +1,366 @@
1
- # theauthapi
2
- Client library for TheAuthAPI.com
1
+ # Client library for [TheAuthAPI](https://theauthapi.com/)
2
+
3
+ **Contents**
4
+
5
+ - [Client library for TheAuthAPI](#client-library-for-theauthapi)
6
+ - [Installation](#installation)
7
+ - [Configuration](#configuration)
8
+ - [Imports](#imports)
9
+ - [CommonJS](#commonjs)
10
+ - [ES Modules](#es-modules)
11
+ - [Usage](#usage)
12
+ - [Example: Validating an API-Key](#example-validating-an-api-key)
13
+ - [Example: Listing API-keys](#example-listing-api-keys)
14
+ - [Example: Listing the projects of an account](#example-listing-the-projects-of-an-account)
15
+ - [Example: Listing projects and associated API-Keys](#example-listing-projects-and-associated-api-keys)
16
+ - [Example: Creating an API-Key](#example-creating-an-api-key)
17
+ - [Example: Rotating an API-Key](#example-rotating-an-api-key)
18
+ - [Handling Errors](#handling-errors)
19
+ - [ApiRequestError](#apirequesterror)
20
+ - [ApiResponseError](#apiresponseerror)
21
+ - [Example: Getting a key throws an ApiResponseError if the key is invalid](#example-getting-a-key-throws-an-apiresponseerror-if-the-key-is-invalid)
22
+ - [Error](#error)
23
+ - [Handling Errors the Right Way](#handling-errors-the-right-way)
24
+ - [Typescript](#typescript)
25
+ - [📙 Further Reading](#-further-reading)
26
+
27
+ **Scalable API Key Management and Auth Control**
28
+ Secure your API with best in class API Key management, user access, all with great analytics.
29
+
30
+ ## Installation
31
+
32
+ This library is published on [npm](https://www.npmjs.com/package/theauthapi), you can add it as a dependency using the following
33
+ command
34
+
35
+ ```bash
36
+ npm install theauthapi
37
+ # or
38
+ yarn add theauthapi
39
+ ```
40
+
41
+ ## Configuration
42
+
43
+ You'll need to configure the library with your `access key` and `account id`, you can grab these from [TheAuthAPI](https://app.theauthapi.com) dashboard.
44
+
45
+ For further instructions on creating an account, check out our [how to guides](https://support.theauthapi.com/).
46
+
47
+ ### Imports
48
+
49
+ #### CommonJS
50
+
51
+ ```javascript
52
+ const TheAuthAPI = require("theauthapi").default;
53
+ ```
54
+
55
+ #### ES Modules
56
+
57
+ ```typescript
58
+ import TheAuthAPI from "theauthapi";
59
+ ```
60
+
61
+ initialize the client using your access key:
62
+
63
+ ```javascript
64
+ const theAuthAPI = new TheAuthAPI("YOUR_ACCESS_KEY");
65
+ ```
66
+
67
+ You can also provide custom options:
68
+
69
+ ```javascript
70
+ const theAuthAPI = new TheAuthAPI("YOUR_ACCESS_KEY", {
71
+ retryCount: 2,
72
+ });
73
+ ```
74
+
75
+ **Full option types:**
76
+
77
+ ```typescript
78
+ type Options = {
79
+ // server url
80
+ host?: string;
81
+ // number of retries before failing
82
+ retryCount?: number;
83
+ };
84
+ ```
85
+
86
+ ## Usage
87
+
88
+ After initiating the client, you can access endpoint methods using the following pattern:
89
+ `[object instance].[endpoint].[method]`
90
+
91
+ For example, getting the projects for an account would be: `theAuthApiClient.projects.getProjects("ACCOUNT_ID")`,
92
+
93
+ Similarly, getting the api keys would be:
94
+ `theAuthApiClient.apiKeys.getKeys("PROJECT_ID")`
95
+
96
+ | endpoint | attribute | example |
97
+ | --------- | --------- | --------------------------------------------- |
98
+ | /api-keys | apiKeys | `client.apiKeys.createKey("MY_KEY")` |
99
+ | /projects | projects | `client.projects.createProject("MY_PROJECT")` |
100
+ | /accounts | accounts | `client.accounts.createAccount("MY_ACCOUNT")` |
101
+
102
+ For details on each endpoint accepted values, please reference these docs: [docs.theauthapi.com](https://docs.theauthapi.com/)
103
+
104
+ All methods return a promise containing the returned JSON as a javascript object. Each method of an endpoint maps HTTP methods to
105
+
106
+ | HTTP Method | method name | example |
107
+ | ----------- | ----------- | ------------------------------------------------------------------------- |
108
+ | POST | create\* | `client.apiKeys.createKey({ name: "KEY_NAME", projectId: "PROJECT_ID" })` |
109
+ | GET | get\* | `client.apiKeys.getKeys()` |
110
+ | DELETE | delete\* | `client.apiKeys.deleteKey("MY_KEY")` |
111
+ | PATCH | update\* | `client.apiKeys.updateKey("MY_KEY", { name: "UPDATED_KEY_NAME" })` |
112
+
113
+ #### Example: Validating an API-Key
114
+
115
+ You can easily validate an API key using `apiKeys.isValidKey` which returns `true` if the key is valid, `false` otherwise.
116
+ `isValidKey` throws an `ApiRequestError` if there's a network issue, it's advised to wrap it in a `try/catch` to handle the potential error
117
+
118
+ ```javascript
119
+ theAuthAPI.apiKeys
120
+ .isValidKey("API_KEY")
121
+ .then((isValidKey) => {
122
+ if (isValidKey) {
123
+ console.log("The API is valid!");
124
+ } else {
125
+ console.log("Invalid API key!");
126
+ }
127
+ })
128
+ .catch((error) => {
129
+ // handle network error
130
+ });
131
+ ```
132
+
133
+ **Using async/await**
134
+
135
+ ```javascript
136
+ try {
137
+ const isValidKey = await theAuthAPI.apiKeys.isValidKey("API_KEY");
138
+ if (isValidKey) {
139
+ console.log("The API is valid!");
140
+ } else {
141
+ console.log("Invalid API key!");
142
+ }
143
+ } catch (error) {
144
+ // handle network error
145
+ }
146
+ ```
147
+
148
+ **Note:** If you want to consume the API key and get the API key entity in return, you can use `apiKeys.authenticateKey` which returns an ApiKey.
149
+
150
+ #### Example: Listing API-keys
151
+
152
+ ```javascript
153
+ theAuthAPI.apiKeys
154
+ .getKeys()
155
+ .then((keys) => console.log(keys))
156
+ .catch((error) => console.log(error));
157
+ ```
158
+
159
+ **Using async/await**
160
+
161
+ ```javascript
162
+ try {
163
+ const keys = await theAuthAPI.apiKeys.getKeys();
164
+ } catch (error) {
165
+ console.log(error);
166
+ }
167
+ ```
168
+
169
+ **Filtering API Keys**: You can filter the listed API keys by passing an object of type filter as an argument to `getKeys`
170
+
171
+ ```typescript
172
+ type ApiKeyFilter = {
173
+ projectId?: string;
174
+ name?: string;
175
+ customAccountId?: string | null;
176
+ customUserId?: string | null;
177
+ isActive?: boolean;
178
+ };
179
+ ```
180
+
181
+ **Example**: filtering api-keys with a specific `projectId` where the keys are not active
182
+
183
+ ```javascript
184
+ try {
185
+ const keys = await theAuthAPI.apiKeys.getKeys({
186
+ projectId: "PROJECT_ID",
187
+ isActive: false,
188
+ });
189
+ } catch (error) {
190
+ console.log(error);
191
+ }
192
+ ```
193
+
194
+ **NOTE** that if your access key is at account level, you need to specify `projectId` when listing the API keys:
195
+ `getKeys({ projectId: "PROJECT_ID" })`, otherwise if your access key is created at project level, you don't have to specify `projectId`,
196
+ the access key's `projectId` will be used to get the API-keys (i.e. you'll see only the keys of the project your access key is created against)
197
+
198
+ #### Example: Listing the projects of an account
199
+
200
+ ```javascript
201
+ theAuthAPI.projects
202
+ .getProjects("ACCOUNT_ID")
203
+ .then((projects) => console.log(projects))
204
+ .catch((error) => console.log(error));
205
+ ```
206
+
207
+ **Using async/await**
208
+
209
+ ```javascript
210
+ try {
211
+ const projects = await client.projects.getProjects("ACCOUNT_ID");
212
+ } catch (error) {
213
+ console.log(error);
214
+ }
215
+ ```
216
+
217
+ #### Example: Listing projects and associated API-Keys
218
+
219
+ ```javascript
220
+ async function getProjectsWithKeys(accountId: string) {
221
+ try {
222
+ const projects = await theAuthAPI.projects.getProjects(accountId);
223
+ const projectsKeys = projects.map(async (project) => {
224
+ const keys = await theAuthAPI.apiKeys.getKeys(project.id);
225
+ return { project, keys };
226
+ });
227
+ return await Promise.all(projectsKeys);
228
+ } catch (error) {
229
+ // handle error
230
+ }
231
+ }
232
+ ```
233
+
234
+ #### Example: Creating an API-Key
235
+
236
+ ```javascript
237
+ theAuthAPI.apiKeys
238
+ .createKey({
239
+ projectId: "PROJECT_ID",
240
+ customMetaData: { metadata_val: "value to store" },
241
+ customAccountId: "[any info you want]",
242
+ name: "[any info you want e.g. name of customer or the key]",
243
+ })
244
+ .then((key) => console.log("Key created > ", key))
245
+ .catch((error) => console.log("Couldn't make the key", error));
246
+ ```
247
+
248
+ **Using async/await**
249
+
250
+ ```javascript
251
+ try {
252
+ const key = await theAuthAPI.apiKeys.createKey({
253
+ projectId: "PROJECT_ID",
254
+ customMetaData: { metadata_val: "value to store" },
255
+ customAccountId: "[any info you want]",
256
+ name: "[any info you want e.g. name of customer or the key]",
257
+ });
258
+ console.log("Key created > ", key);
259
+ } catch (error) {
260
+ console.log("Couldn't make the key ", error);
261
+ }
262
+ ```
263
+
264
+ #### Example: Rotating an API-Key
265
+
266
+ When you need to quickly and securely rotate a compromised key, while preserving the key's metadata, use the `rotateKey` method. This method while clone your key and return you with a new one.
267
+
268
+ ```javascript
269
+ theAuthAPI.apiKeys
270
+ .rotateKey("API_KEY")
271
+ .then((key) => console.log("Rotated Key > ", key))
272
+ .catch((error) => console.log("Couldn't rotate the key", error));
273
+ ```
274
+
275
+ **Using async/await**
276
+
277
+ ```javascript
278
+ try {
279
+ const key = await theAuthAPI.apiKeys.createKey("API_KEY");
280
+ console.log("Rotated Key > ", key);
281
+ } catch (error) {
282
+ console.log("Couldn't rotate the key", error);
283
+ }
284
+ ```
285
+
286
+ **NOTE** In the background, this marks the old key as inactive and issues you with a new key. Any requests to the old key will be instantly blocked.
287
+
288
+ ### Handling Errors
289
+
290
+ [comment]: <> (All methods that return a promise throw 3 types of errors)
291
+
292
+ ##### ApiRequestError
293
+
294
+ Thrown when there's a network or a connectivity issue, for example, if the client didn't establish any network connection with the host
295
+
296
+ ```
297
+ ApiRequestError: getaddrinfo EAI_AGAIN api.theauthapi.com
298
+ ```
299
+
300
+ ##### ApiResponseError
301
+
302
+ Thrown when the server responds with an HTTP status code not in the `2xx` range. `ApiRequestError` provides two properties to distinguish the type of the error
303
+
304
+ - `statusCode` HTTP status code
305
+ - `message` the message the server responded with in the body
306
+
307
+ This is the most common thrown error, you should expect and handle it each time you use any of the library methods
308
+
309
+ ##### Example: Getting a key throws an ApiResponseError if the key is invalid
310
+
311
+ If you try to GET an invalid key using `apiKeys.getKey("invalid-key")`, the server responds with a 404 error and an `ApiResponseError` is thrown
312
+
313
+ ```
314
+ ApiResponseError: (404): Invalid client key
315
+ ```
316
+
317
+ "404" is the `statusCode`, "Invalid client Key" is the `message`, you can access these properties using `error.statusCode` and `error.message` respectively
318
+
319
+ ##### Error
320
+
321
+ Unknown error, just a normal javascript error
322
+
323
+ #### Handling Errors the Right Way
324
+
325
+ Since all the possible thrown errors are instances of classes, we can check the type of the thrown error and handle it accordingly
326
+
327
+ ```javascript
328
+ try {
329
+ const key = await theAuthAPI.apiKeys.getKey("KEY");
330
+ } catch (error) {
331
+ if (error instanceof ApiResponseError) {
332
+ // handle response error
333
+ }
334
+ if (error instanceof ApiRequestError) {
335
+ // handle network error
336
+ }
337
+ // unknown error
338
+ throw error;
339
+ }
340
+ ```
341
+
342
+ ### Typescript
343
+
344
+ This library is written in [Typescript](https://www.typescriptlang.org/), types are provided out of the box.
345
+
346
+ Example of usage with Typescript:
347
+
348
+ ```typescript
349
+ import TheAuthAPI from "theauthapi";
350
+ import { Project } from "theauthapi/types";
351
+
352
+ const client = new TheAuthAPI("ACCESS_KEY");
353
+
354
+ async function getProjectsIds(accountId: string): Promise<string[]> {
355
+ const projects: Project[] = await client.projects.getProjects(accountId);
356
+ return projects.map((project) => project.name);
357
+ }
358
+ ```
359
+
360
+ ### 📙 Further Reading
361
+
362
+ - Create your account [https://theauthapi.com](https://theauthapi.com)
363
+ - View our [Knowledge Base](https://thatapicompany.notion.site/The-Auth-API-Knowledge-Base-21660cee84e640729714fad43d9ce546) help centre
364
+ - Read our [API docs](https://docs.theauthapi.com)
365
+ - Articles on best Auth practice - [https://theauthapi.com/articles](https://theauthapi.com/articles)
366
+ - Meet the team behind The Auth API - [That API Company](https://thatapicompany.com/)
@@ -0,0 +1,10 @@
1
+ import { AccountsInterface } from "./AccountsInterface";
2
+ import ApiRequest from "../../services/ApiRequest/ApiRequest";
3
+ import { Account } from "../../types";
4
+ declare class Accounts implements AccountsInterface {
5
+ api: ApiRequest;
6
+ endpoint: string;
7
+ constructor(apiService: ApiRequest);
8
+ getAccount(accountId: string): Promise<Account>;
9
+ }
10
+ export default Accounts;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const HttpMethod_1 = require("../../services/ApiRequest/HttpMethod");
13
+ class Accounts {
14
+ constructor(apiService) {
15
+ this.api = apiService;
16
+ this.endpoint = "/accounts";
17
+ }
18
+ getAccount(accountId) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return yield this.api.request(HttpMethod_1.HttpMethod.GET, `${this.endpoint}/${accountId}`);
21
+ });
22
+ }
23
+ }
24
+ exports.default = Accounts;
@@ -0,0 +1,4 @@
1
+ import { Account } from "../../types";
2
+ export interface AccountsInterface {
3
+ getAccount(accountId: string): Promise<Account>;
4
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ import ApiRequest from "../../services/ApiRequest/ApiRequest";
2
+ import { ApiKey, ApiKeyFilter, ApiKeyInput, UpdateApiKeyInput } from "../../types";
3
+ import { ApiKeysInterface } from "./ApiKeysInterface";
4
+ declare class ApiKeys implements ApiKeysInterface {
5
+ api: ApiRequest;
6
+ private readonly endpoint;
7
+ constructor(apiService: ApiRequest);
8
+ isValidKey(apikey: string): Promise<boolean>;
9
+ authenticateKey(apikey: string): Promise<ApiKey>;
10
+ getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
11
+ getKey(apikey: string): Promise<ApiKey>;
12
+ createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
13
+ updateKey(apiKey: string, updatedKey: UpdateApiKeyInput): Promise<ApiKey>;
14
+ deleteKey(apiKey: string): Promise<boolean>;
15
+ reactivateKey(apiKey: string): Promise<ApiKey>;
16
+ rotateKey(apiKey: string): Promise<ApiKey>;
17
+ private getKeysFilterEndpoint;
18
+ }
19
+ export default ApiKeys;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const HttpMethod_1 = require("../../services/ApiRequest/HttpMethod");
16
+ const ApiResponseError_1 = __importDefault(require("../../services/ApiRequest/ApiResponseError"));
17
+ class ApiKeys {
18
+ constructor(apiService) {
19
+ this.api = apiService;
20
+ this.endpoint = "/api-keys/";
21
+ }
22
+ isValidKey(apikey) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ try {
25
+ const key = yield this.authenticateKey(apikey);
26
+ return key.key !== undefined;
27
+ }
28
+ catch (error) {
29
+ if (error instanceof ApiResponseError_1.default && error.statusCode === 404) {
30
+ return false;
31
+ }
32
+ throw error;
33
+ }
34
+ });
35
+ }
36
+ authenticateKey(apikey) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ return yield this.api.request(HttpMethod_1.HttpMethod.POST, `/api-keys/auth/${apikey}`);
39
+ });
40
+ }
41
+ getKeys(filter) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const endpoint = this.getKeysFilterEndpoint(filter);
44
+ return yield this.api.request(HttpMethod_1.HttpMethod.GET, endpoint);
45
+ });
46
+ }
47
+ getKey(apikey) {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ return yield this.api.request(HttpMethod_1.HttpMethod.GET, `/api-keys/${apikey}`);
50
+ });
51
+ }
52
+ createKey(apiKey) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ return yield this.api.request(HttpMethod_1.HttpMethod.POST, "/api-keys", apiKey);
55
+ });
56
+ }
57
+ updateKey(apiKey, updatedKey) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ return yield this.api.request(HttpMethod_1.HttpMethod.PATCH, `/api-keys/${apiKey}`, updatedKey);
60
+ });
61
+ }
62
+ deleteKey(apiKey) {
63
+ return __awaiter(this, void 0, void 0, function* () {
64
+ return yield this.api.request(HttpMethod_1.HttpMethod.DELETE, `/api-keys/${apiKey}`);
65
+ });
66
+ }
67
+ reactivateKey(apiKey) {
68
+ return __awaiter(this, void 0, void 0, function* () {
69
+ return yield this.api.request(HttpMethod_1.HttpMethod.PATCH, `/api-keys/${apiKey}/reactivate`);
70
+ });
71
+ }
72
+ rotateKey(apiKey) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ return yield this.api.request(HttpMethod_1.HttpMethod.POST, `/api-keys/${apiKey}/rotate`);
75
+ });
76
+ }
77
+ getKeysFilterEndpoint(filter) {
78
+ let filters = [];
79
+ if (filter !== undefined) {
80
+ filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
81
+ }
82
+ return `${this.endpoint}${filter !== undefined ? "?" : ""}${filters.join("&")}`;
83
+ }
84
+ }
85
+ exports.default = ApiKeys;
@@ -0,0 +1,12 @@
1
+ import { ApiKey, ApiKeyFilter, ApiKeyInput, UpdateApiKeyInput } from "../../types";
2
+ export interface ApiKeysInterface {
3
+ isValidKey(apiKey: string): Promise<boolean>;
4
+ getKey(apiKey: string): Promise<ApiKey>;
5
+ authenticateKey(apiKey: string): Promise<ApiKey>;
6
+ getKeys(filter?: ApiKeyFilter): Promise<ApiKey[]>;
7
+ createKey(apiKey: ApiKeyInput): Promise<ApiKey>;
8
+ updateKey(apiKey: string, updateTo: UpdateApiKeyInput): Promise<ApiKey>;
9
+ deleteKey(apiKey: string): Promise<boolean>;
10
+ reactivateKey(apiKey: string): Promise<ApiKey>;
11
+ rotateKey(apiKey: string): Promise<ApiKey>;
12
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ import ApiRequest from "../../services/ApiRequest/ApiRequest";
2
+ import { CreateProjectInput, Project, UpdateProjectInput } from "../../types";
3
+ import { ProjectsInterface } from "./ProjectsInterface";
4
+ declare class Projects implements ProjectsInterface {
5
+ api: ApiRequest;
6
+ endpoint: string;
7
+ constructor(apiService: ApiRequest);
8
+ getProjects(accountId: string): Promise<Project[]>;
9
+ getProject(projectId: string): Promise<Project>;
10
+ deleteProject(projectId: string): Promise<boolean>;
11
+ createProject(project: CreateProjectInput): Promise<Project>;
12
+ updateProject(projectId: string, project: UpdateProjectInput): Promise<Project>;
13
+ }
14
+ export default Projects;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const HttpMethod_1 = require("../../services/ApiRequest/HttpMethod");
13
+ class Projects {
14
+ constructor(apiService) {
15
+ this.api = apiService;
16
+ this.endpoint = "/projects";
17
+ }
18
+ getProjects(accountId) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return yield this.api.request(HttpMethod_1.HttpMethod.GET, `${this.endpoint}?accountId=${accountId}`);
21
+ });
22
+ }
23
+ getProject(projectId) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ return yield this.api.request(HttpMethod_1.HttpMethod.GET, `${this.endpoint}/${projectId}`);
26
+ });
27
+ }
28
+ deleteProject(projectId) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ return yield this.api.request(HttpMethod_1.HttpMethod.DELETE, `${this.endpoint}/${projectId}`);
31
+ });
32
+ }
33
+ createProject(project) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return yield this.api.request(HttpMethod_1.HttpMethod.POST, this.endpoint, project);
36
+ });
37
+ }
38
+ updateProject(projectId, project) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ return this.api.request(HttpMethod_1.HttpMethod.PATCH, `${this.endpoint}/${projectId}`, project);
41
+ });
42
+ }
43
+ }
44
+ exports.default = Projects;
@@ -0,0 +1,8 @@
1
+ import { CreateProjectInput, Project, UpdateProjectInput } from "../../types";
2
+ export interface ProjectsInterface {
3
+ getProjects(accountId: string): Promise<Project[]>;
4
+ getProject(projectId: string): Promise<Project>;
5
+ deleteProject(projectId: string): Promise<boolean>;
6
+ createProject(project: CreateProjectInput): Promise<Project>;
7
+ updateProject(name: string, updateTo: UpdateProjectInput): Promise<Project>;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,26 @@
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
+ 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;