theauthapi 1.0.16 → 1.0.17
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/README.md +2 -0
- package/dist/index.d.cts +1 -1
- package/dist/{types/index.d.ts → types.d.cts} +16 -14
- package/dist/types.d.ts +87 -0
- package/package.json +8 -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/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.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
type ApiKey = {
|
|
2
2
|
key: string;
|
|
3
3
|
name: string;
|
|
4
4
|
customMetaData: AnyJson;
|
|
@@ -11,11 +11,11 @@ export type ApiKey = {
|
|
|
11
11
|
rateLimitConfigs: RateLimitConfiguration;
|
|
12
12
|
expiry: Date;
|
|
13
13
|
};
|
|
14
|
-
|
|
14
|
+
type RateLimitConfiguration = {
|
|
15
15
|
rateLimit: number;
|
|
16
16
|
rateLimitTtl: number;
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
type ApiKeyInput = {
|
|
19
19
|
name: string;
|
|
20
20
|
projectId?: string;
|
|
21
21
|
key?: string;
|
|
@@ -25,14 +25,14 @@ export type ApiKeyInput = {
|
|
|
25
25
|
rateLimitConfigs?: RateLimitConfiguration;
|
|
26
26
|
expiry?: Date;
|
|
27
27
|
};
|
|
28
|
-
|
|
28
|
+
type ApiKeyFilter = {
|
|
29
29
|
projectId?: string;
|
|
30
30
|
name?: string;
|
|
31
31
|
customAccountId?: string | null;
|
|
32
32
|
customUserId?: string | null;
|
|
33
33
|
isActive?: boolean;
|
|
34
34
|
};
|
|
35
|
-
|
|
35
|
+
type UpdateApiKeyInput = {
|
|
36
36
|
name: string;
|
|
37
37
|
key?: string;
|
|
38
38
|
customMetaData?: AnyJson;
|
|
@@ -41,11 +41,11 @@ export type UpdateApiKeyInput = {
|
|
|
41
41
|
expiry?: Date | null;
|
|
42
42
|
rateLimitConfigs?: RateLimitConfiguration | null;
|
|
43
43
|
};
|
|
44
|
-
|
|
44
|
+
declare enum AuthedEntityType {
|
|
45
45
|
USER = "USER",
|
|
46
46
|
ACCESS_KEY = "ACCESS_KEY"
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
type AuthBaseEntity = {
|
|
49
49
|
isActive: boolean;
|
|
50
50
|
createdBy: string;
|
|
51
51
|
createdByType?: AuthedEntityType;
|
|
@@ -55,25 +55,25 @@ export type AuthBaseEntity = {
|
|
|
55
55
|
updatedAt: Date;
|
|
56
56
|
createdAt: Date;
|
|
57
57
|
};
|
|
58
|
-
|
|
58
|
+
type Project = AuthBaseEntity & {
|
|
59
59
|
id: string;
|
|
60
60
|
name: string;
|
|
61
61
|
accountId: string;
|
|
62
62
|
env: Environment;
|
|
63
63
|
};
|
|
64
|
-
|
|
64
|
+
declare enum Environment {
|
|
65
65
|
LIVE = "live",
|
|
66
66
|
TEST = "test"
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
type CreateProjectInput = {
|
|
69
69
|
name: string;
|
|
70
70
|
accountId: string;
|
|
71
71
|
env: Environment;
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
type UpdateProjectInput = {
|
|
74
74
|
name: string;
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
type Account = AuthBaseEntity & {
|
|
77
77
|
id: string;
|
|
78
78
|
name: string;
|
|
79
79
|
};
|
|
@@ -81,5 +81,7 @@ type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
|
|
|
81
81
|
type JsonMap = {
|
|
82
82
|
[key: string]: AnyJson;
|
|
83
83
|
};
|
|
84
|
-
type JsonArray = Array<AnyJson>;
|
|
85
|
-
|
|
84
|
+
type JsonArray = Array<AnyJson>;
|
|
85
|
+
|
|
86
|
+
export { AuthedEntityType, Environment };
|
|
87
|
+
export type { Account, ApiKey, ApiKeyFilter, ApiKeyInput, AuthBaseEntity, CreateProjectInput, Project, RateLimitConfiguration, UpdateApiKeyInput, UpdateProjectInput };
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
type ApiKey = {
|
|
2
|
+
key: string;
|
|
3
|
+
name: string;
|
|
4
|
+
customMetaData: AnyJson;
|
|
5
|
+
customAccountId: string;
|
|
6
|
+
customUserId: string;
|
|
7
|
+
env: Environment;
|
|
8
|
+
createdAt: Date;
|
|
9
|
+
updatedAt: Date;
|
|
10
|
+
isActive: boolean;
|
|
11
|
+
rateLimitConfigs: RateLimitConfiguration;
|
|
12
|
+
expiry: Date;
|
|
13
|
+
};
|
|
14
|
+
type RateLimitConfiguration = {
|
|
15
|
+
rateLimit: number;
|
|
16
|
+
rateLimitTtl: number;
|
|
17
|
+
};
|
|
18
|
+
type ApiKeyInput = {
|
|
19
|
+
name: string;
|
|
20
|
+
projectId?: string;
|
|
21
|
+
key?: string;
|
|
22
|
+
customMetaData?: AnyJson;
|
|
23
|
+
customAccountId?: string;
|
|
24
|
+
customUserId?: string;
|
|
25
|
+
rateLimitConfigs?: RateLimitConfiguration;
|
|
26
|
+
expiry?: Date;
|
|
27
|
+
};
|
|
28
|
+
type ApiKeyFilter = {
|
|
29
|
+
projectId?: string;
|
|
30
|
+
name?: string;
|
|
31
|
+
customAccountId?: string | null;
|
|
32
|
+
customUserId?: string | null;
|
|
33
|
+
isActive?: boolean;
|
|
34
|
+
};
|
|
35
|
+
type UpdateApiKeyInput = {
|
|
36
|
+
name: string;
|
|
37
|
+
key?: string;
|
|
38
|
+
customMetaData?: AnyJson;
|
|
39
|
+
customAccountId?: string;
|
|
40
|
+
customUserId?: string;
|
|
41
|
+
expiry?: Date | null;
|
|
42
|
+
rateLimitConfigs?: RateLimitConfiguration | null;
|
|
43
|
+
};
|
|
44
|
+
declare enum AuthedEntityType {
|
|
45
|
+
USER = "USER",
|
|
46
|
+
ACCESS_KEY = "ACCESS_KEY"
|
|
47
|
+
}
|
|
48
|
+
type AuthBaseEntity = {
|
|
49
|
+
isActive: boolean;
|
|
50
|
+
createdBy: string;
|
|
51
|
+
createdByType?: AuthedEntityType;
|
|
52
|
+
createdIn: string;
|
|
53
|
+
lastChangedBy: string;
|
|
54
|
+
lastChangedByType?: AuthedEntityType;
|
|
55
|
+
updatedAt: Date;
|
|
56
|
+
createdAt: Date;
|
|
57
|
+
};
|
|
58
|
+
type Project = AuthBaseEntity & {
|
|
59
|
+
id: string;
|
|
60
|
+
name: string;
|
|
61
|
+
accountId: string;
|
|
62
|
+
env: Environment;
|
|
63
|
+
};
|
|
64
|
+
declare enum Environment {
|
|
65
|
+
LIVE = "live",
|
|
66
|
+
TEST = "test"
|
|
67
|
+
}
|
|
68
|
+
type CreateProjectInput = {
|
|
69
|
+
name: string;
|
|
70
|
+
accountId: string;
|
|
71
|
+
env: Environment;
|
|
72
|
+
};
|
|
73
|
+
type UpdateProjectInput = {
|
|
74
|
+
name: string;
|
|
75
|
+
};
|
|
76
|
+
type Account = AuthBaseEntity & {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
};
|
|
80
|
+
type AnyJson = boolean | number | string | null | JsonArray | JsonMap;
|
|
81
|
+
type JsonMap = {
|
|
82
|
+
[key: string]: AnyJson;
|
|
83
|
+
};
|
|
84
|
+
type JsonArray = Array<AnyJson>;
|
|
85
|
+
|
|
86
|
+
export { AuthedEntityType, Environment };
|
|
87
|
+
export type { Account, ApiKey, ApiKeyFilter, ApiKeyInput, AuthBaseEntity, CreateProjectInput, Project, RateLimitConfiguration, UpdateApiKeyInput, UpdateProjectInput };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "theauthapi",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"description": "Client library for TheAuthAPI.com",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"types": "dist/index.d.cts",
|
|
@@ -14,6 +14,10 @@
|
|
|
14
14
|
"types": "./dist/index.d.cts",
|
|
15
15
|
"default": "./dist/index.cjs"
|
|
16
16
|
}
|
|
17
|
+
},
|
|
18
|
+
"./types": {
|
|
19
|
+
"require": "./dist/types.d.cts",
|
|
20
|
+
"types": "./dist/types.d.ts"
|
|
17
21
|
}
|
|
18
22
|
},
|
|
19
23
|
"type": "module",
|
|
@@ -36,7 +40,9 @@
|
|
|
36
40
|
"local-release": "npm run ci && changeset version && changeset publish",
|
|
37
41
|
"format": "prettier --write .",
|
|
38
42
|
"check-format": "prettier --check .",
|
|
39
|
-
"check-exports": "
|
|
43
|
+
"check-exports": "npm run check-exports:all && npm run check-exports:types",
|
|
44
|
+
"check-exports:all": "npx attw --pack . --exclude-entrypoints ./types",
|
|
45
|
+
"check-exports:types": "npx attw --pack . --entrypoints ./types --profile node16"
|
|
40
46
|
},
|
|
41
47
|
"repository": {
|
|
42
48
|
"type": "git",
|
|
@@ -1,10 +0,0 @@
|
|
|
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;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { HttpMethod } from '../../services/ApiRequest/HttpMethod';
|
|
11
|
-
class Accounts {
|
|
12
|
-
constructor(apiService) {
|
|
13
|
-
this.api = apiService;
|
|
14
|
-
this.endpoint = '/accounts';
|
|
15
|
-
}
|
|
16
|
-
getAccount(accountId) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${accountId}`);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export default Accounts;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
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;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { HttpMethod } from '../../services/ApiRequest/HttpMethod';
|
|
11
|
-
import ApiResponseError from '../../services/ApiRequest/ApiResponseError';
|
|
12
|
-
class ApiKeys {
|
|
13
|
-
constructor(apiService) {
|
|
14
|
-
this.api = apiService;
|
|
15
|
-
this.endpoint = '/api-keys/';
|
|
16
|
-
}
|
|
17
|
-
isValidKey(apikey) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
try {
|
|
20
|
-
const key = yield this.authenticateKey(apikey);
|
|
21
|
-
return key.key !== undefined;
|
|
22
|
-
}
|
|
23
|
-
catch (error) {
|
|
24
|
-
if (error instanceof ApiResponseError && error.statusCode === 404) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
throw error;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
authenticateKey(apikey) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return yield this.api.request(HttpMethod.POST, `/api-keys/auth/${apikey}`);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
getKeys(filter) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const endpoint = this.getKeysFilterEndpoint(filter);
|
|
39
|
-
return yield this.api.request(HttpMethod.GET, endpoint);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
getKey(apikey) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
return yield this.api.request(HttpMethod.GET, `/api-keys/${apikey}`);
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
createKey(apiKey) {
|
|
48
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
-
return yield this.api.request(HttpMethod.POST, '/api-keys', apiKey);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
updateKey(apiKey, updatedKey) {
|
|
53
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}`, updatedKey);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
deleteKey(apiKey) {
|
|
58
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
return yield this.api.request(HttpMethod.DELETE, `/api-keys/${apiKey}`);
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
reactivateKey(apiKey) {
|
|
63
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
64
|
-
return yield this.api.request(HttpMethod.PATCH, `/api-keys/${apiKey}/reactivate`);
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
rotateKey(apiKey) {
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
return yield this.api.request(HttpMethod.POST, `/api-keys/${apiKey}/rotate`);
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
getKeysFilterEndpoint(filter) {
|
|
73
|
-
let filters = [];
|
|
74
|
-
if (filter !== undefined) {
|
|
75
|
-
filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
|
|
76
|
-
}
|
|
77
|
-
return `${this.endpoint}${filter !== undefined ? '?' : ''}${filters.join('&')}`;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
export default ApiKeys;
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
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;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { HttpMethod } from '../../services/ApiRequest/HttpMethod';
|
|
11
|
-
class Projects {
|
|
12
|
-
constructor(apiService) {
|
|
13
|
-
this.api = apiService;
|
|
14
|
-
this.endpoint = '/projects';
|
|
15
|
-
}
|
|
16
|
-
getProjects(accountId) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
return yield this.api.request(HttpMethod.GET, `${this.endpoint}?accountId=${accountId}`);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
getProject(projectId) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
return yield this.api.request(HttpMethod.GET, `${this.endpoint}/${projectId}`);
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
deleteProject(projectId) {
|
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
-
return yield this.api.request(HttpMethod.DELETE, `${this.endpoint}/${projectId}`);
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
createProject(project) {
|
|
32
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
-
return yield this.api.request(HttpMethod.POST, this.endpoint, project);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
updateProject(projectId, project) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
return this.api.request(HttpMethod.PATCH, `${this.endpoint}/${projectId}`, project);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
export default Projects;
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
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;
|
package/dist/index.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import 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/libraryMeta.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const version = "1.0.11";
|
package/dist/libraryMeta.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const version = '1.0.11';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,24 +0,0 @@
|
|
|
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,110 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from 'axios';
|
|
11
|
-
import { version } from '../../libraryMeta';
|
|
12
|
-
import ApiRequestError from './ApiRequestError';
|
|
13
|
-
import axiosRetry from 'axios-retry';
|
|
14
|
-
import ApiResponseError from './ApiResponseError';
|
|
15
|
-
class ApiRequest {
|
|
16
|
-
constructor(config) {
|
|
17
|
-
const { host, accessKey, headers, retryCount } = config;
|
|
18
|
-
this.host = host;
|
|
19
|
-
this.accessKey = accessKey;
|
|
20
|
-
this.headers = this._generateDefaultHeaders();
|
|
21
|
-
this.retryCount = retryCount !== null && retryCount !== void 0 ? retryCount : 3;
|
|
22
|
-
if (headers) {
|
|
23
|
-
this.headers = Object.assign(Object.assign({}, this.headers), { headers });
|
|
24
|
-
}
|
|
25
|
-
this._init();
|
|
26
|
-
}
|
|
27
|
-
_init() {
|
|
28
|
-
var _a;
|
|
29
|
-
const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
30
|
-
function isIsoDateString(value) {
|
|
31
|
-
return value && typeof value === 'string' && isoDateFormat.test(value);
|
|
32
|
-
}
|
|
33
|
-
function handleDates(body) {
|
|
34
|
-
if (body === null || body === undefined || typeof body !== 'object') {
|
|
35
|
-
return body;
|
|
36
|
-
}
|
|
37
|
-
for (const key of Object.keys(body)) {
|
|
38
|
-
const value = body[key];
|
|
39
|
-
if (isIsoDateString(value)) {
|
|
40
|
-
body[key] = new Date(value);
|
|
41
|
-
}
|
|
42
|
-
else if (typeof value === 'object') {
|
|
43
|
-
handleDates(value);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
axios.interceptors.response.use((response) => {
|
|
48
|
-
handleDates(response.data);
|
|
49
|
-
return response;
|
|
50
|
-
});
|
|
51
|
-
axiosRetry(axios, {
|
|
52
|
-
retries: (_a = this.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
53
|
-
retryCondition: this._isErrorRetryable,
|
|
54
|
-
retryDelay: axiosRetry.exponentialDelay,
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
request(method, endpoint, payload) {
|
|
58
|
-
var _a;
|
|
59
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
try {
|
|
61
|
-
const response = yield axios.request({
|
|
62
|
-
baseURL: this.host,
|
|
63
|
-
method: method,
|
|
64
|
-
url: endpoint,
|
|
65
|
-
data: payload,
|
|
66
|
-
headers: this.headers,
|
|
67
|
-
});
|
|
68
|
-
return response.data;
|
|
69
|
-
}
|
|
70
|
-
catch (error) {
|
|
71
|
-
if (axios.isAxiosError(error)) {
|
|
72
|
-
if (error.response) {
|
|
73
|
-
throw new ApiResponseError(error.response.status, (_a = error.response.data.message) !== null && _a !== void 0 ? _a : error.response.statusText);
|
|
74
|
-
}
|
|
75
|
-
else if (error.request) {
|
|
76
|
-
throw new ApiRequestError(error.message);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
throw error;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
_generateDefaultHeaders() {
|
|
84
|
-
return {
|
|
85
|
-
'user-agent': `theauthapi-client-node/${version}`,
|
|
86
|
-
'x-api-key': this.accessKey,
|
|
87
|
-
'api-key': this.accessKey,
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
_isErrorRetryable(error) {
|
|
91
|
-
// Retry Network Errors.
|
|
92
|
-
if (axiosRetry.isNetworkError(error)) {
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
if (!error.response) {
|
|
96
|
-
// Cannot determine if the request can be retried
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
// Retry Server Errors (5xx).
|
|
100
|
-
if (error.response.status >= 500 && error.response.status <= 599) {
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
// Retry if rate limited.
|
|
104
|
-
if (error.response.status === 429) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
export default ApiRequest;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Throws when no response was received from the server
|
|
4
|
-
* @param message - error message
|
|
5
|
-
*
|
|
6
|
-
* */
|
|
7
|
-
class ApiRequestError extends Error {
|
|
8
|
-
constructor(message) {
|
|
9
|
-
super(message);
|
|
10
|
-
this.name = 'ApiRequestError';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export default ApiRequestError;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
4
|
-
* @param statusCode - HTTP status code the server responded with
|
|
5
|
-
* @param message - error message
|
|
6
|
-
*
|
|
7
|
-
* */
|
|
8
|
-
declare class ApiResponseError extends Error {
|
|
9
|
-
statusCode: number;
|
|
10
|
-
constructor(statusCode: number, message: string);
|
|
11
|
-
}
|
|
12
|
-
export default ApiResponseError;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Throws when the server responds with a status code that falls out of the range 2xx
|
|
4
|
-
* @param statusCode - HTTP status code the server responded with
|
|
5
|
-
* @param message - error message
|
|
6
|
-
*
|
|
7
|
-
* */
|
|
8
|
-
class ApiResponseError extends Error {
|
|
9
|
-
constructor(statusCode, message) {
|
|
10
|
-
super(`(${statusCode}): ${message}`);
|
|
11
|
-
this.statusCode = statusCode;
|
|
12
|
-
this.name = 'ApiResponseError';
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export default ApiResponseError;
|
package/dist/types/index.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export var AuthedEntityType;
|
|
2
|
-
(function (AuthedEntityType) {
|
|
3
|
-
AuthedEntityType["USER"] = "USER";
|
|
4
|
-
AuthedEntityType["ACCESS_KEY"] = "ACCESS_KEY";
|
|
5
|
-
})(AuthedEntityType || (AuthedEntityType = {}));
|
|
6
|
-
export var Environment;
|
|
7
|
-
(function (Environment) {
|
|
8
|
-
Environment["LIVE"] = "live";
|
|
9
|
-
Environment["TEST"] = "test";
|
|
10
|
-
})(Environment || (Environment = {}));
|