theauthapi 1.0.13 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +366 -366
- package/dist/endpoints/Accounts/Accounts.d.ts +3 -3
- package/dist/endpoints/Accounts/Accounts.js +22 -0
- package/dist/endpoints/Accounts/AccountsInterface.d.ts +1 -1
- package/dist/endpoints/Accounts/AccountsInterface.js +1 -0
- package/dist/endpoints/ApiKeys/ApiKeys.d.ts +3 -3
- package/dist/endpoints/ApiKeys/ApiKeys.js +80 -0
- package/dist/endpoints/ApiKeys/ApiKeysInterface.d.ts +1 -1
- package/dist/endpoints/ApiKeys/ApiKeysInterface.js +1 -0
- package/dist/endpoints/Projects/Projects.d.ts +3 -3
- package/dist/endpoints/Projects/Projects.js +42 -0
- package/dist/endpoints/Projects/ProjectsInterface.d.ts +1 -1
- package/dist/endpoints/Projects/ProjectsInterface.js +1 -0
- package/dist/index.cjs +15 -15
- package/dist/index.d.cts +200 -0
- package/dist/index.d.mts +200 -0
- package/dist/index.d.ts +6 -180
- package/dist/index.js +69 -0
- package/dist/index.mjs +15 -15
- package/dist/libraryMeta.js +1 -0
- package/dist/services/ApiRequest/ApiCall.d.ts +1 -1
- package/dist/services/ApiRequest/ApiCall.js +1 -0
- package/dist/services/ApiRequest/ApiRequest.d.ts +5 -5
- package/dist/services/ApiRequest/ApiRequest.js +110 -0
- package/dist/services/ApiRequest/ApiRequestError.js +13 -0
- package/dist/services/ApiRequest/ApiResponseError.js +15 -0
- package/dist/services/ApiRequest/HttpMethod.js +8 -0
- package/dist/types/index.js +10 -0
- package/package.json +26 -5
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,200 @@
|
|
|
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.d.ts
CHANGED
|
@@ -1,180 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
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';
|
|
178
5
|
type Options = {
|
|
179
6
|
host?: string;
|
|
180
7
|
retryCount?: number;
|
|
@@ -195,6 +22,5 @@ declare class TheAuthAPI {
|
|
|
195
22
|
*/
|
|
196
23
|
constructor(accessKey: string, options?: Options);
|
|
197
24
|
authenticateAPIKey(key: string, callback?: (err: any, data: any) => any): Promise<unknown>;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export { TheAuthAPI as default };
|
|
25
|
+
}
|
|
26
|
+
export default TheAuthAPI;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import assert from 'assert';
|
|
11
|
+
import removeSlash from 'remove-trailing-slash';
|
|
12
|
+
import ApiRequest from './services/ApiRequest/ApiRequest';
|
|
13
|
+
import ApiKeys from './endpoints/ApiKeys/ApiKeys';
|
|
14
|
+
import { HttpMethod } from './services/ApiRequest/HttpMethod';
|
|
15
|
+
import Projects from './endpoints/Projects/Projects';
|
|
16
|
+
import Accounts from './endpoints/Accounts/Accounts';
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
18
|
+
const noop = () => { };
|
|
19
|
+
class TheAuthAPI {
|
|
20
|
+
/**
|
|
21
|
+
* @param {String} accessKey
|
|
22
|
+
* @param {Object} [options] (optional)
|
|
23
|
+
* @property {String} host (default: 'https://api.segment.io')
|
|
24
|
+
* @property {number} retryCount (default: 3)
|
|
25
|
+
*/
|
|
26
|
+
constructor(accessKey, options) {
|
|
27
|
+
var _a;
|
|
28
|
+
assert(accessKey, "You must pass your project's write key.");
|
|
29
|
+
this.accessKey = accessKey;
|
|
30
|
+
this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || 'https://api.theauthapi.com');
|
|
31
|
+
this.api = new ApiRequest({
|
|
32
|
+
accessKey: this.accessKey,
|
|
33
|
+
host: this.host,
|
|
34
|
+
retryCount: (_a = options === null || options === void 0 ? void 0 : options.retryCount) !== null && _a !== void 0 ? _a : 3,
|
|
35
|
+
});
|
|
36
|
+
this.apiKeys = new ApiKeys(this.api);
|
|
37
|
+
this.projects = new Projects(this.api);
|
|
38
|
+
this.accounts = new Accounts(this.api);
|
|
39
|
+
}
|
|
40
|
+
/*
|
|
41
|
+
@deprecated
|
|
42
|
+
*/
|
|
43
|
+
authenticateAPIKey(key, callback) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
const cb = callback || noop;
|
|
46
|
+
const done = (err) => {
|
|
47
|
+
cb(err, data);
|
|
48
|
+
};
|
|
49
|
+
const data = {
|
|
50
|
+
credentials: { api_key: key },
|
|
51
|
+
timestamp: new Date().getTime(),
|
|
52
|
+
sentAt: new Date().getTime(),
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
const key = yield this.api.request(HttpMethod.POST, '/auth/authenticate', data);
|
|
56
|
+
done(key);
|
|
57
|
+
return key;
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
if (err.response) {
|
|
61
|
+
const error = new Error(err.response.statusText);
|
|
62
|
+
return done(error);
|
|
63
|
+
}
|
|
64
|
+
done(err);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export default TheAuthAPI;
|
package/dist/index.mjs
CHANGED
|
@@ -30,7 +30,7 @@ function __awaiter(thisArg, _arguments, P, generator) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const version =
|
|
33
|
+
const version = '1.0.11';
|
|
34
34
|
|
|
35
35
|
/**
|
|
36
36
|
*
|
|
@@ -56,7 +56,7 @@ class ApiResponseError extends Error {
|
|
|
56
56
|
constructor(statusCode, message) {
|
|
57
57
|
super(`(${statusCode}): ${message}`);
|
|
58
58
|
this.statusCode = statusCode;
|
|
59
|
-
this.name =
|
|
59
|
+
this.name = 'ApiResponseError';
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -76,10 +76,10 @@ class ApiRequest {
|
|
|
76
76
|
var _a;
|
|
77
77
|
const isoDateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d*)?(?:[-+]\d{2}:?\d{2}|Z)?$/;
|
|
78
78
|
function isIsoDateString(value) {
|
|
79
|
-
return value && typeof value ===
|
|
79
|
+
return value && typeof value === 'string' && isoDateFormat.test(value);
|
|
80
80
|
}
|
|
81
81
|
function handleDates(body) {
|
|
82
|
-
if (body === null || body === undefined || typeof body !==
|
|
82
|
+
if (body === null || body === undefined || typeof body !== 'object') {
|
|
83
83
|
return body;
|
|
84
84
|
}
|
|
85
85
|
for (const key of Object.keys(body)) {
|
|
@@ -87,7 +87,7 @@ class ApiRequest {
|
|
|
87
87
|
if (isIsoDateString(value)) {
|
|
88
88
|
body[key] = new Date(value);
|
|
89
89
|
}
|
|
90
|
-
else if (typeof value ===
|
|
90
|
+
else if (typeof value === 'object') {
|
|
91
91
|
handleDates(value);
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -130,9 +130,9 @@ class ApiRequest {
|
|
|
130
130
|
}
|
|
131
131
|
_generateDefaultHeaders() {
|
|
132
132
|
return {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
'user-agent': `theauthapi-client-node/${version}`,
|
|
134
|
+
'x-api-key': this.accessKey,
|
|
135
|
+
'api-key': this.accessKey,
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
_isErrorRetryable(error) {
|
|
@@ -168,7 +168,7 @@ var HttpMethod;
|
|
|
168
168
|
class ApiKeys {
|
|
169
169
|
constructor(apiService) {
|
|
170
170
|
this.api = apiService;
|
|
171
|
-
this.endpoint =
|
|
171
|
+
this.endpoint = '/api-keys/';
|
|
172
172
|
}
|
|
173
173
|
isValidKey(apikey) {
|
|
174
174
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -202,7 +202,7 @@ class ApiKeys {
|
|
|
202
202
|
}
|
|
203
203
|
createKey(apiKey) {
|
|
204
204
|
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
return yield this.api.request(HttpMethod.POST,
|
|
205
|
+
return yield this.api.request(HttpMethod.POST, '/api-keys', apiKey);
|
|
206
206
|
});
|
|
207
207
|
}
|
|
208
208
|
updateKey(apiKey, updatedKey) {
|
|
@@ -230,14 +230,14 @@ class ApiKeys {
|
|
|
230
230
|
if (filter !== undefined) {
|
|
231
231
|
filters = Object.entries(filter).map(([key, value]) => `${key}=${value}`);
|
|
232
232
|
}
|
|
233
|
-
return `${this.endpoint}${filter !== undefined ?
|
|
233
|
+
return `${this.endpoint}${filter !== undefined ? '?' : ''}${filters.join('&')}`;
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
class Projects {
|
|
238
238
|
constructor(apiService) {
|
|
239
239
|
this.api = apiService;
|
|
240
|
-
this.endpoint =
|
|
240
|
+
this.endpoint = '/projects';
|
|
241
241
|
}
|
|
242
242
|
getProjects(accountId) {
|
|
243
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -269,7 +269,7 @@ class Projects {
|
|
|
269
269
|
class Accounts {
|
|
270
270
|
constructor(apiService) {
|
|
271
271
|
this.api = apiService;
|
|
272
|
-
this.endpoint =
|
|
272
|
+
this.endpoint = '/accounts';
|
|
273
273
|
}
|
|
274
274
|
getAccount(accountId) {
|
|
275
275
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -291,7 +291,7 @@ class TheAuthAPI {
|
|
|
291
291
|
var _a;
|
|
292
292
|
assert(accessKey, "You must pass your project's write key.");
|
|
293
293
|
this.accessKey = accessKey;
|
|
294
|
-
this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) ||
|
|
294
|
+
this.host = removeSlash((options === null || options === void 0 ? void 0 : options.host) || 'https://api.theauthapi.com');
|
|
295
295
|
this.api = new ApiRequest({
|
|
296
296
|
accessKey: this.accessKey,
|
|
297
297
|
host: this.host,
|
|
@@ -316,7 +316,7 @@ class TheAuthAPI {
|
|
|
316
316
|
sentAt: new Date().getTime(),
|
|
317
317
|
};
|
|
318
318
|
try {
|
|
319
|
-
const key = yield this.api.request(HttpMethod.POST,
|
|
319
|
+
const key = yield this.api.request(HttpMethod.POST, '/auth/authenticate', data);
|
|
320
320
|
done(key);
|
|
321
321
|
return key;
|
|
322
322
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const version = '1.0.11';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HttpMethod } from
|
|
2
|
-
import ApiCall from
|
|
1
|
+
import { HttpMethod } from './HttpMethod';
|
|
2
|
+
import ApiCall from './ApiCall';
|
|
3
3
|
type Config = {
|
|
4
4
|
host: string;
|
|
5
5
|
accessKey: string;
|
|
@@ -15,9 +15,9 @@ declare class ApiRequest implements ApiCall {
|
|
|
15
15
|
_init(): void;
|
|
16
16
|
request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
|
|
17
17
|
_generateDefaultHeaders(): {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
'user-agent': string;
|
|
19
|
+
'x-api-key': string;
|
|
20
|
+
'api-key': string;
|
|
21
21
|
};
|
|
22
22
|
_isErrorRetryable(error: any): boolean;
|
|
23
23
|
}
|