theauthapi 1.0.17 → 1.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/dist/index.cjs +285 -283
- package/dist/index.d.cts +177 -177
- package/dist/index.d.mts +177 -177
- package/dist/index.mjs +285 -283
- package/dist/types.d.cts +83 -83
- package/dist/types.d.ts +83 -83
- package/package.json +4 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
declare enum HttpMethod {
|
|
2
|
-
GET = "GET",
|
|
3
|
-
POST = "POST",
|
|
4
|
-
DELETE = "DELETE",
|
|
5
|
-
PATCH = "PATCH",
|
|
6
|
-
PUT = "PUT"
|
|
1
|
+
declare enum HttpMethod {
|
|
2
|
+
GET = "GET",
|
|
3
|
+
POST = "POST",
|
|
4
|
+
DELETE = "DELETE",
|
|
5
|
+
PATCH = "PATCH",
|
|
6
|
+
PUT = "PUT"
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
interface ApiCall {
|
|
10
|
-
request<T>(method: HttpMethod, endpoint: string, payload?: any): Promise<T>;
|
|
9
|
+
interface ApiCall {
|
|
10
|
+
request<T>(method: HttpMethod, endpoint: string, payload?: any, customHeaders?: object): Promise<T>;
|
|
11
11
|
}
|
|
12
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;
|
|
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, customHeaders?: object): Promise<T>;
|
|
27
|
+
_generateDefaultHeaders(): {
|
|
28
|
+
'user-agent': string;
|
|
29
|
+
'x-api-key': string;
|
|
30
|
+
'api-key': string;
|
|
31
|
+
};
|
|
32
|
+
_isErrorRetryable(error: any): boolean;
|
|
33
33
|
}
|
|
34
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
|
-
};
|
|
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
118
|
type JsonArray = Array<AnyJson>;
|
|
119
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>;
|
|
120
|
+
interface ApiKeysInterface {
|
|
121
|
+
isValidKey(apiKey: string): Promise<boolean>;
|
|
122
|
+
getKey(apiKey: string): Promise<ApiKey>;
|
|
123
|
+
authenticateKey(apiKey: string, origin?: 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
130
|
}
|
|
131
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;
|
|
132
|
+
declare class ApiKeys implements ApiKeysInterface {
|
|
133
|
+
api: ApiRequest;
|
|
134
|
+
private readonly endpoint;
|
|
135
|
+
constructor(apiService: ApiRequest);
|
|
136
|
+
isValidKey(apikey: string, origin?: string): Promise<boolean>;
|
|
137
|
+
authenticateKey(apikey: string, origin?: 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
146
|
}
|
|
147
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>;
|
|
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
154
|
}
|
|
155
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>;
|
|
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
165
|
}
|
|
166
166
|
|
|
167
|
-
interface AccountsInterface {
|
|
168
|
-
getAccount(accountId: string): Promise<Account>;
|
|
167
|
+
interface AccountsInterface {
|
|
168
|
+
getAccount(accountId: string): Promise<Account>;
|
|
169
169
|
}
|
|
170
170
|
|
|
171
|
-
declare class Accounts implements AccountsInterface {
|
|
172
|
-
api: ApiRequest;
|
|
173
|
-
endpoint: string;
|
|
174
|
-
constructor(apiService: ApiRequest);
|
|
175
|
-
getAccount(accountId: string): Promise<Account>;
|
|
171
|
+
declare class Accounts implements AccountsInterface {
|
|
172
|
+
api: ApiRequest;
|
|
173
|
+
endpoint: string;
|
|
174
|
+
constructor(apiService: ApiRequest);
|
|
175
|
+
getAccount(accountId: string): Promise<Account>;
|
|
176
176
|
}
|
|
177
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>;
|
|
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
198
|
}
|
|
199
199
|
|
|
200
200
|
export { TheAuthAPI as default };
|