@authsome/client 0.0.1 → 0.0.3
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/CHANGELOG.md +38 -0
- package/README.md +392 -0
- package/RELEASE_CHECKLIST.md +162 -0
- package/RELEASE_v0.0.2.md +126 -0
- package/authsome-client-0.0.2.tgz +0 -0
- package/dist/client.d.ts +65 -3
- package/dist/client.js +52 -8
- package/dist/index.d.ts +25 -25
- package/dist/index.js +78 -26
- package/dist/plugins/oidcprovider.d.ts +1 -1
- package/dist/plugins/webhook.d.ts +1 -1
- package/dist/plugins/webhook.js +4 -4
- package/dist/types.d.ts +2465 -2500
- package/package.json +3 -24
- package/src/client.ts +270 -0
- package/src/errors.ts +92 -0
- package/src/index.ts +33 -0
- package/src/plugin.ts +13 -0
- package/src/plugins/admin.ts +84 -0
- package/src/plugins/anonymous.ts +31 -0
- package/src/plugins/apikey.ts +56 -0
- package/src/plugins/backupauth.ts +208 -0
- package/src/plugins/compliance.ts +204 -0
- package/src/plugins/consent.ts +125 -0
- package/src/plugins/emailotp.ts +33 -0
- package/src/plugins/idverification.ts +80 -0
- package/src/plugins/impersonation.ts +53 -0
- package/src/plugins/jwt.ts +44 -0
- package/src/plugins/magiclink.ts +31 -0
- package/src/plugins/mfa.ts +111 -0
- package/src/plugins/multiapp.ts +116 -0
- package/src/plugins/multisession.ts +36 -0
- package/src/plugins/notification.ts +98 -0
- package/src/plugins/oidcprovider.ts +90 -0
- package/src/plugins/organization.ts +99 -0
- package/src/plugins/passkey.ts +54 -0
- package/src/plugins/phone.ts +40 -0
- package/src/plugins/social.ts +48 -0
- package/src/plugins/sso.ts +55 -0
- package/src/plugins/stepup.ts +97 -0
- package/src/plugins/twofa.ts +61 -0
- package/src/plugins/username.ts +29 -0
- package/src/plugins/webhook.ts +50 -0
- package/src/types.ts +3702 -0
- package/tsconfig.json +16 -0
package/package.json
CHANGED
|
@@ -1,37 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@authsome/client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "TypeScript client for AuthSome authentication",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
7
|
"scripts": {
|
|
11
8
|
"build": "tsc",
|
|
12
9
|
"prepublishOnly": "npm run build"
|
|
13
10
|
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
|
|
16
|
-
"authentication",
|
|
17
|
-
"auth",
|
|
18
|
-
"client",
|
|
19
|
-
"sdk",
|
|
20
|
-
"typescript",
|
|
21
|
-
"multi-tenant",
|
|
22
|
-
"rbac"
|
|
23
|
-
],
|
|
24
|
-
"author": "Rex Raphael <rex.raphael@outlook.com>",
|
|
11
|
+
"keywords": ["authsome", "authentication", "client"],
|
|
12
|
+
"author": "",
|
|
25
13
|
"license": "MIT",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "https://github.com/xraph/authsome.git",
|
|
29
|
-
"directory": "clients/typescript"
|
|
30
|
-
},
|
|
31
|
-
"bugs": {
|
|
32
|
-
"url": "https://github.com/xraph/authsome/issues"
|
|
33
|
-
},
|
|
34
|
-
"homepage": "https://github.com/xraph/authsome#readme",
|
|
35
14
|
"devDependencies": {
|
|
36
15
|
"typescript": "^5.0.0"
|
|
37
16
|
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
// Auto-generated AuthSome client
|
|
2
|
+
|
|
3
|
+
import { ClientPlugin } from './plugin';
|
|
4
|
+
import { createErrorFromResponse } from './errors';
|
|
5
|
+
import * as types from './types';
|
|
6
|
+
import { MagiclinkPlugin } from './plugins/magiclink';
|
|
7
|
+
import { NotificationPlugin } from './plugins/notification';
|
|
8
|
+
import { PasskeyPlugin } from './plugins/passkey';
|
|
9
|
+
import { UsernamePlugin } from './plugins/username';
|
|
10
|
+
import { ApikeyPlugin } from './plugins/apikey';
|
|
11
|
+
import { BackupauthPlugin } from './plugins/backupauth';
|
|
12
|
+
import { ConsentPlugin } from './plugins/consent';
|
|
13
|
+
import { IdverificationPlugin } from './plugins/idverification';
|
|
14
|
+
import { MultiappPlugin } from './plugins/multiapp';
|
|
15
|
+
import { OidcproviderPlugin } from './plugins/oidcprovider';
|
|
16
|
+
import { PhonePlugin } from './plugins/phone';
|
|
17
|
+
import { AdminPlugin } from './plugins/admin';
|
|
18
|
+
import { EmailotpPlugin } from './plugins/emailotp';
|
|
19
|
+
import { MfaPlugin } from './plugins/mfa';
|
|
20
|
+
import { OrganizationPlugin } from './plugins/organization';
|
|
21
|
+
import { SocialPlugin } from './plugins/social';
|
|
22
|
+
import { SsoPlugin } from './plugins/sso';
|
|
23
|
+
import { AnonymousPlugin } from './plugins/anonymous';
|
|
24
|
+
import { StepupPlugin } from './plugins/stepup';
|
|
25
|
+
import { JwtPlugin } from './plugins/jwt';
|
|
26
|
+
import { MultisessionPlugin } from './plugins/multisession';
|
|
27
|
+
import { TwofaPlugin } from './plugins/twofa';
|
|
28
|
+
import { WebhookPlugin } from './plugins/webhook';
|
|
29
|
+
import { CompliancePlugin } from './plugins/compliance';
|
|
30
|
+
import { ImpersonationPlugin } from './plugins/impersonation';
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* AuthSome client configuration
|
|
34
|
+
* Supports multiple authentication methods that can be used simultaneously:
|
|
35
|
+
* - Cookies: Automatically sent with every request (session-based auth)
|
|
36
|
+
* - Bearer Token: JWT tokens sent in Authorization header when auth: true
|
|
37
|
+
* - API Key: Sent with every request for server-to-server auth
|
|
38
|
+
* - Publishable Key (pk_*): Safe for frontend, limited permissions
|
|
39
|
+
* - Secret Key (sk_*): Backend only, full admin access
|
|
40
|
+
*/
|
|
41
|
+
export interface AuthsomeClientConfig {
|
|
42
|
+
/** Base URL of the AuthSome API */
|
|
43
|
+
baseURL: string;
|
|
44
|
+
|
|
45
|
+
/** Plugin instances to initialize */
|
|
46
|
+
plugins?: ClientPlugin[];
|
|
47
|
+
|
|
48
|
+
/** JWT/Bearer token for user authentication (sent only when auth: true) */
|
|
49
|
+
token?: string;
|
|
50
|
+
|
|
51
|
+
/** API key for server-to-server auth (pk_* or sk_*, sent with all requests) */
|
|
52
|
+
apiKey?: string;
|
|
53
|
+
|
|
54
|
+
/** Custom header name for API key (default: 'X-API-Key') */
|
|
55
|
+
apiKeyHeader?: string;
|
|
56
|
+
|
|
57
|
+
/** Custom headers to include with all requests */
|
|
58
|
+
headers?: Record<string, string>;
|
|
59
|
+
|
|
60
|
+
/** Base path prefix for all API routes (default: '') */
|
|
61
|
+
basePath?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class AuthsomeClient {
|
|
65
|
+
private baseURL: string;
|
|
66
|
+
private basePath: string;
|
|
67
|
+
private token?: string;
|
|
68
|
+
private apiKey?: string;
|
|
69
|
+
private apiKeyHeader: string;
|
|
70
|
+
private headers: Record<string, string>;
|
|
71
|
+
private plugins: Map<string, ClientPlugin>;
|
|
72
|
+
|
|
73
|
+
constructor(config: AuthsomeClientConfig) {
|
|
74
|
+
this.baseURL = config.baseURL;
|
|
75
|
+
this.basePath = config.basePath || '';
|
|
76
|
+
this.token = config.token;
|
|
77
|
+
this.apiKey = config.apiKey;
|
|
78
|
+
this.apiKeyHeader = config.apiKeyHeader || 'X-API-Key';
|
|
79
|
+
this.headers = config.headers || {};
|
|
80
|
+
this.plugins = new Map();
|
|
81
|
+
|
|
82
|
+
if (config.plugins) {
|
|
83
|
+
for (const plugin of config.plugins) {
|
|
84
|
+
this.plugins.set(plugin.id, plugin);
|
|
85
|
+
plugin.init(this);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
setToken(token: string): void {
|
|
91
|
+
this.token = token;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
setApiKey(apiKey: string, header?: string): void {
|
|
95
|
+
this.apiKey = apiKey;
|
|
96
|
+
if (header) {
|
|
97
|
+
this.apiKeyHeader = header;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Set a publishable key (pk_*) - safe for frontend use
|
|
103
|
+
* Publishable keys have limited permissions and can be exposed in client-side code
|
|
104
|
+
* Typically used for: session creation, user verification, public data reads
|
|
105
|
+
*/
|
|
106
|
+
setPublishableKey(publishableKey: string): void {
|
|
107
|
+
if (!publishableKey.startsWith('pk_')) {
|
|
108
|
+
console.warn('Warning: Publishable keys should start with pk_');
|
|
109
|
+
}
|
|
110
|
+
this.setApiKey(publishableKey);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Set a secret key (sk_*) - MUST be kept secret on server-side only!
|
|
115
|
+
* Secret keys have full administrative access to all operations
|
|
116
|
+
* WARNING: Never expose secret keys in client-side code (browser, mobile apps)
|
|
117
|
+
*/
|
|
118
|
+
setSecretKey(secretKey: string): void {
|
|
119
|
+
if (!secretKey.startsWith('sk_')) {
|
|
120
|
+
console.warn('Warning: Secret keys should start with sk_');
|
|
121
|
+
}
|
|
122
|
+
this.setApiKey(secretKey);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
setBasePath(basePath: string): void {
|
|
126
|
+
this.basePath = basePath;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Set global headers for all requests
|
|
131
|
+
* @param headers - Headers to set
|
|
132
|
+
* @param replace - If true, replaces all existing headers. If false (default), merges with existing headers
|
|
133
|
+
*/
|
|
134
|
+
setGlobalHeaders(headers: Record<string, string>, replace: boolean = false): void {
|
|
135
|
+
if (replace) {
|
|
136
|
+
this.headers = { ...headers };
|
|
137
|
+
} else {
|
|
138
|
+
this.headers = { ...this.headers, ...headers };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
getPlugin<T extends ClientPlugin>(id: string): T | undefined {
|
|
143
|
+
return this.plugins.get(id) as T | undefined;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public readonly $plugins = {
|
|
147
|
+
magiclink: (): MagiclinkPlugin | undefined => this.getPlugin<MagiclinkPlugin>('magiclink'),
|
|
148
|
+
notification: (): NotificationPlugin | undefined => this.getPlugin<NotificationPlugin>('notification'),
|
|
149
|
+
passkey: (): PasskeyPlugin | undefined => this.getPlugin<PasskeyPlugin>('passkey'),
|
|
150
|
+
username: (): UsernamePlugin | undefined => this.getPlugin<UsernamePlugin>('username'),
|
|
151
|
+
apikey: (): ApikeyPlugin | undefined => this.getPlugin<ApikeyPlugin>('apikey'),
|
|
152
|
+
backupauth: (): BackupauthPlugin | undefined => this.getPlugin<BackupauthPlugin>('backupauth'),
|
|
153
|
+
consent: (): ConsentPlugin | undefined => this.getPlugin<ConsentPlugin>('consent'),
|
|
154
|
+
idverification: (): IdverificationPlugin | undefined => this.getPlugin<IdverificationPlugin>('idverification'),
|
|
155
|
+
multiapp: (): MultiappPlugin | undefined => this.getPlugin<MultiappPlugin>('multiapp'),
|
|
156
|
+
oidcprovider: (): OidcproviderPlugin | undefined => this.getPlugin<OidcproviderPlugin>('oidcprovider'),
|
|
157
|
+
phone: (): PhonePlugin | undefined => this.getPlugin<PhonePlugin>('phone'),
|
|
158
|
+
admin: (): AdminPlugin | undefined => this.getPlugin<AdminPlugin>('admin'),
|
|
159
|
+
emailotp: (): EmailotpPlugin | undefined => this.getPlugin<EmailotpPlugin>('emailotp'),
|
|
160
|
+
mfa: (): MfaPlugin | undefined => this.getPlugin<MfaPlugin>('mfa'),
|
|
161
|
+
organization: (): OrganizationPlugin | undefined => this.getPlugin<OrganizationPlugin>('organization'),
|
|
162
|
+
social: (): SocialPlugin | undefined => this.getPlugin<SocialPlugin>('social'),
|
|
163
|
+
sso: (): SsoPlugin | undefined => this.getPlugin<SsoPlugin>('sso'),
|
|
164
|
+
anonymous: (): AnonymousPlugin | undefined => this.getPlugin<AnonymousPlugin>('anonymous'),
|
|
165
|
+
stepup: (): StepupPlugin | undefined => this.getPlugin<StepupPlugin>('stepup'),
|
|
166
|
+
jwt: (): JwtPlugin | undefined => this.getPlugin<JwtPlugin>('jwt'),
|
|
167
|
+
multisession: (): MultisessionPlugin | undefined => this.getPlugin<MultisessionPlugin>('multisession'),
|
|
168
|
+
twofa: (): TwofaPlugin | undefined => this.getPlugin<TwofaPlugin>('twofa'),
|
|
169
|
+
webhook: (): WebhookPlugin | undefined => this.getPlugin<WebhookPlugin>('webhook'),
|
|
170
|
+
compliance: (): CompliancePlugin | undefined => this.getPlugin<CompliancePlugin>('compliance'),
|
|
171
|
+
impersonation: (): ImpersonationPlugin | undefined => this.getPlugin<ImpersonationPlugin>('impersonation'),
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
public async request<T>(
|
|
175
|
+
method: string,
|
|
176
|
+
path: string,
|
|
177
|
+
options?: {
|
|
178
|
+
body?: any;
|
|
179
|
+
query?: Record<string, string>;
|
|
180
|
+
auth?: boolean;
|
|
181
|
+
}
|
|
182
|
+
): Promise<T> {
|
|
183
|
+
const url = new URL(this.basePath + path, this.baseURL);
|
|
184
|
+
|
|
185
|
+
if (options?.query) {
|
|
186
|
+
for (const [key, value] of Object.entries(options.query)) {
|
|
187
|
+
url.searchParams.append(key, value);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const headers: Record<string, string> = {
|
|
192
|
+
'Content-Type': 'application/json',
|
|
193
|
+
...this.headers,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
if (options?.auth && this.token) {
|
|
197
|
+
headers['Authorization'] = `Bearer ${this.token}`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (this.apiKey) {
|
|
201
|
+
headers[this.apiKeyHeader] = this.apiKey;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const response = await fetch(url.toString(), {
|
|
205
|
+
method,
|
|
206
|
+
headers,
|
|
207
|
+
body: options?.body ? JSON.stringify(options.body) : undefined,
|
|
208
|
+
credentials: 'include',
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
if (!response.ok) {
|
|
212
|
+
const error = await response.json().catch(() => ({ error: response.statusText }));
|
|
213
|
+
throw createErrorFromResponse(response.status, error.error || error.message || 'Request failed');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return response.json();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
async signUp(request: { email: string; password: string; name?: string }): Promise<{ user: types.User; session: types.Session }> {
|
|
220
|
+
const path = '/signup';
|
|
221
|
+
return this.request<{ user: types.User; session: types.Session }>('POST', path, {
|
|
222
|
+
body: request,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async signIn(request: { email: string; password: string }): Promise<{ user: types.User; session: types.Session; requiresTwoFactor: boolean }> {
|
|
227
|
+
const path = '/signin';
|
|
228
|
+
return this.request<{ user: types.User; session: types.Session; requiresTwoFactor: boolean }>('POST', path, {
|
|
229
|
+
body: request,
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
async signOut(): Promise<{ success: boolean }> {
|
|
234
|
+
const path = '/signout';
|
|
235
|
+
return this.request<{ success: boolean }>('POST', path, {
|
|
236
|
+
auth: true,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async getSession(): Promise<{ user: types.User; session: types.Session }> {
|
|
241
|
+
const path = '/session';
|
|
242
|
+
return this.request<{ user: types.User; session: types.Session }>('GET', path, {
|
|
243
|
+
auth: true,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async updateUser(request: { email?: string; name?: string }): Promise<{ user: types.User }> {
|
|
248
|
+
const path = '/user/update';
|
|
249
|
+
return this.request<{ user: types.User }>('POST', path, {
|
|
250
|
+
body: request,
|
|
251
|
+
auth: true,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
async listDevices(): Promise<{ devices: types.Device[] }> {
|
|
256
|
+
const path = '/devices';
|
|
257
|
+
return this.request<{ devices: types.Device[] }>('GET', path, {
|
|
258
|
+
auth: true,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
async revokeDevice(request: { deviceId: string }): Promise<{ success: boolean }> {
|
|
263
|
+
const path = '/devices/revoke';
|
|
264
|
+
return this.request<{ success: boolean }>('POST', path, {
|
|
265
|
+
body: request,
|
|
266
|
+
auth: true,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
}
|
package/src/errors.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Auto-generated error classes
|
|
2
|
+
|
|
3
|
+
export class AuthsomeError extends Error {
|
|
4
|
+
constructor(
|
|
5
|
+
message: string,
|
|
6
|
+
public statusCode: number,
|
|
7
|
+
public code?: string
|
|
8
|
+
) {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = 'AuthsomeError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class NetworkError extends AuthsomeError {
|
|
15
|
+
constructor(message: string) {
|
|
16
|
+
super(message, 0, 'NETWORK_ERROR');
|
|
17
|
+
this.name = 'NetworkError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ValidationError extends AuthsomeError {
|
|
22
|
+
constructor(message: string, public fields?: Record<string, string>) {
|
|
23
|
+
super(message, 400, 'VALIDATION_ERROR');
|
|
24
|
+
this.name = 'ValidationError';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class UnauthorizedError extends AuthsomeError {
|
|
29
|
+
constructor(message: string = 'Unauthorized') {
|
|
30
|
+
super(message, 401, 'UNAUTHORIZED');
|
|
31
|
+
this.name = 'UnauthorizedError';
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class ForbiddenError extends AuthsomeError {
|
|
36
|
+
constructor(message: string = 'Forbidden') {
|
|
37
|
+
super(message, 403, 'FORBIDDEN');
|
|
38
|
+
this.name = 'ForbiddenError';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export class NotFoundError extends AuthsomeError {
|
|
43
|
+
constructor(message: string = 'Not found') {
|
|
44
|
+
super(message, 404, 'NOT_FOUND');
|
|
45
|
+
this.name = 'NotFoundError';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class ConflictError extends AuthsomeError {
|
|
50
|
+
constructor(message: string) {
|
|
51
|
+
super(message, 409, 'CONFLICT');
|
|
52
|
+
this.name = 'ConflictError';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export class RateLimitError extends AuthsomeError {
|
|
57
|
+
constructor(message: string = 'Rate limit exceeded') {
|
|
58
|
+
super(message, 429, 'RATE_LIMIT_EXCEEDED');
|
|
59
|
+
this.name = 'RateLimitError';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export class ServerError extends AuthsomeError {
|
|
64
|
+
constructor(message: string = 'Internal server error') {
|
|
65
|
+
super(message, 500, 'SERVER_ERROR');
|
|
66
|
+
this.name = 'ServerError';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function createErrorFromResponse(statusCode: number, message: string): AuthsomeError {
|
|
71
|
+
switch (statusCode) {
|
|
72
|
+
case 400:
|
|
73
|
+
return new ValidationError(message);
|
|
74
|
+
case 401:
|
|
75
|
+
return new UnauthorizedError(message);
|
|
76
|
+
case 403:
|
|
77
|
+
return new ForbiddenError(message);
|
|
78
|
+
case 404:
|
|
79
|
+
return new NotFoundError(message);
|
|
80
|
+
case 409:
|
|
81
|
+
return new ConflictError(message);
|
|
82
|
+
case 429:
|
|
83
|
+
return new RateLimitError(message);
|
|
84
|
+
case 500:
|
|
85
|
+
case 502:
|
|
86
|
+
case 503:
|
|
87
|
+
case 504:
|
|
88
|
+
return new ServerError(message);
|
|
89
|
+
default:
|
|
90
|
+
return new AuthsomeError(message, statusCode);
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Auto-generated exports
|
|
2
|
+
|
|
3
|
+
export { AuthsomeClient, AuthsomeClientConfig } from './client';
|
|
4
|
+
export { ClientPlugin } from './plugin';
|
|
5
|
+
export * from './types';
|
|
6
|
+
export * from './errors';
|
|
7
|
+
|
|
8
|
+
// Plugin exports
|
|
9
|
+
export { MagiclinkPlugin, magiclinkClient } from './plugins/magiclink';
|
|
10
|
+
export { NotificationPlugin, notificationClient } from './plugins/notification';
|
|
11
|
+
export { PasskeyPlugin, passkeyClient } from './plugins/passkey';
|
|
12
|
+
export { UsernamePlugin, usernameClient } from './plugins/username';
|
|
13
|
+
export { ApikeyPlugin, apikeyClient } from './plugins/apikey';
|
|
14
|
+
export { BackupauthPlugin, backupauthClient } from './plugins/backupauth';
|
|
15
|
+
export { ConsentPlugin, consentClient } from './plugins/consent';
|
|
16
|
+
export { IdverificationPlugin, idverificationClient } from './plugins/idverification';
|
|
17
|
+
export { MultiappPlugin, multiappClient } from './plugins/multiapp';
|
|
18
|
+
export { OidcproviderPlugin, oidcproviderClient } from './plugins/oidcprovider';
|
|
19
|
+
export { PhonePlugin, phoneClient } from './plugins/phone';
|
|
20
|
+
export { AdminPlugin, adminClient } from './plugins/admin';
|
|
21
|
+
export { EmailotpPlugin, emailotpClient } from './plugins/emailotp';
|
|
22
|
+
export { MfaPlugin, mfaClient } from './plugins/mfa';
|
|
23
|
+
export { OrganizationPlugin, organizationClient } from './plugins/organization';
|
|
24
|
+
export { SocialPlugin, socialClient } from './plugins/social';
|
|
25
|
+
export { SsoPlugin, ssoClient } from './plugins/sso';
|
|
26
|
+
export { AnonymousPlugin, anonymousClient } from './plugins/anonymous';
|
|
27
|
+
export { StepupPlugin, stepupClient } from './plugins/stepup';
|
|
28
|
+
export { JwtPlugin, jwtClient } from './plugins/jwt';
|
|
29
|
+
export { MultisessionPlugin, multisessionClient } from './plugins/multisession';
|
|
30
|
+
export { TwofaPlugin, twofaClient } from './plugins/twofa';
|
|
31
|
+
export { WebhookPlugin, webhookClient } from './plugins/webhook';
|
|
32
|
+
export { CompliancePlugin, complianceClient } from './plugins/compliance';
|
|
33
|
+
export { ImpersonationPlugin, impersonationClient } from './plugins/impersonation';
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Auto-generated plugin interface
|
|
2
|
+
|
|
3
|
+
import { AuthsomeClient } from './client';
|
|
4
|
+
|
|
5
|
+
export interface ClientPlugin {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
|
|
8
|
+
// Initialize plugin with base client
|
|
9
|
+
init(client: AuthsomeClient): void;
|
|
10
|
+
|
|
11
|
+
// Optional: validate configuration
|
|
12
|
+
validate?(): Promise<boolean>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Auto-generated admin plugin
|
|
2
|
+
|
|
3
|
+
import { ClientPlugin } from '../plugin';
|
|
4
|
+
import { AuthsomeClient } from '../client';
|
|
5
|
+
import * as types from '../types';
|
|
6
|
+
|
|
7
|
+
export class AdminPlugin implements ClientPlugin {
|
|
8
|
+
readonly id = 'admin';
|
|
9
|
+
private client!: AuthsomeClient;
|
|
10
|
+
|
|
11
|
+
init(client: AuthsomeClient): void {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async createUser(request: types.CreateUser_reqBody): Promise<void> {
|
|
16
|
+
const path = '/users';
|
|
17
|
+
return this.client.request<void>('POST', path, {
|
|
18
|
+
body: request,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async listUsers(): Promise<void> {
|
|
23
|
+
const path = '/users';
|
|
24
|
+
return this.client.request<void>('GET', path);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async deleteUser(): Promise<types.MessageResponse> {
|
|
28
|
+
const path = '/users/:id';
|
|
29
|
+
return this.client.request<types.MessageResponse>('DELETE', path);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async banUser(request: types.BanUser_reqBody): Promise<types.MessageResponse> {
|
|
33
|
+
const path = '/users/:id/ban';
|
|
34
|
+
return this.client.request<types.MessageResponse>('POST', path, {
|
|
35
|
+
body: request,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async unbanUser(request: types.UnbanUser_reqBody): Promise<types.MessageResponse> {
|
|
40
|
+
const path = '/users/:id/unban';
|
|
41
|
+
return this.client.request<types.MessageResponse>('POST', path, {
|
|
42
|
+
body: request,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async impersonateUser(request: types.ImpersonateUser_reqBody): Promise<void> {
|
|
47
|
+
const path = '/users/:id/impersonate';
|
|
48
|
+
return this.client.request<void>('POST', path, {
|
|
49
|
+
body: request,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async setUserRole(request: types.SetUserRole_reqBody): Promise<types.MessageResponse> {
|
|
54
|
+
const path = '/users/:id/role';
|
|
55
|
+
return this.client.request<types.MessageResponse>('POST', path, {
|
|
56
|
+
body: request,
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async listSessions(): Promise<void> {
|
|
61
|
+
const path = '/sessions';
|
|
62
|
+
return this.client.request<void>('GET', path);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async revokeSession(): Promise<types.MessageResponse> {
|
|
66
|
+
const path = '/sessions/:id';
|
|
67
|
+
return this.client.request<types.MessageResponse>('DELETE', path);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async getStats(): Promise<void> {
|
|
71
|
+
const path = '/stats';
|
|
72
|
+
return this.client.request<void>('GET', path);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async getAuditLogs(): Promise<void> {
|
|
76
|
+
const path = '/audit-logs';
|
|
77
|
+
return this.client.request<void>('GET', path);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function adminClient(): AdminPlugin {
|
|
83
|
+
return new AdminPlugin();
|
|
84
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Auto-generated anonymous plugin
|
|
2
|
+
|
|
3
|
+
import { ClientPlugin } from '../plugin';
|
|
4
|
+
import { AuthsomeClient } from '../client';
|
|
5
|
+
import * as types from '../types';
|
|
6
|
+
|
|
7
|
+
export class AnonymousPlugin implements ClientPlugin {
|
|
8
|
+
readonly id = 'anonymous';
|
|
9
|
+
private client!: AuthsomeClient;
|
|
10
|
+
|
|
11
|
+
init(client: AuthsomeClient): void {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async signIn(): Promise<types.SignInResponse> {
|
|
16
|
+
const path = '/anonymous/signin';
|
|
17
|
+
return this.client.request<types.SignInResponse>('POST', path);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async link(request: types.LinkRequest): Promise<types.LinkResponse> {
|
|
21
|
+
const path = '/anonymous/link';
|
|
22
|
+
return this.client.request<types.LinkResponse>('POST', path, {
|
|
23
|
+
body: request,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function anonymousClient(): AnonymousPlugin {
|
|
30
|
+
return new AnonymousPlugin();
|
|
31
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Auto-generated apikey plugin
|
|
2
|
+
|
|
3
|
+
import { ClientPlugin } from '../plugin';
|
|
4
|
+
import { AuthsomeClient } from '../client';
|
|
5
|
+
import * as types from '../types';
|
|
6
|
+
|
|
7
|
+
export class ApikeyPlugin implements ClientPlugin {
|
|
8
|
+
readonly id = 'apikey';
|
|
9
|
+
private client!: AuthsomeClient;
|
|
10
|
+
|
|
11
|
+
init(client: AuthsomeClient): void {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async createAPIKey(request: types.CreateAPIKey_reqBody): Promise<types.CreateAPIKeyResponse> {
|
|
16
|
+
const path = '/createapikey';
|
|
17
|
+
return this.client.request<types.CreateAPIKeyResponse>('POST', path, {
|
|
18
|
+
body: request,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async listAPIKeys(): Promise<void> {
|
|
23
|
+
const path = '/listapikeys';
|
|
24
|
+
return this.client.request<void>('GET', path);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async getAPIKey(): Promise<void> {
|
|
28
|
+
const path = '/:id';
|
|
29
|
+
return this.client.request<void>('GET', path);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async updateAPIKey(): Promise<void> {
|
|
33
|
+
const path = '/:id';
|
|
34
|
+
return this.client.request<void>('PUT', path);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async deleteAPIKey(): Promise<types.MessageResponse> {
|
|
38
|
+
const path = '/:id';
|
|
39
|
+
return this.client.request<types.MessageResponse>('DELETE', path);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async rotateAPIKey(): Promise<types.RotateAPIKeyResponse> {
|
|
43
|
+
const path = '/:id/rotate';
|
|
44
|
+
return this.client.request<types.RotateAPIKeyResponse>('POST', path);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async verifyAPIKey(): Promise<void> {
|
|
48
|
+
const path = '/verify';
|
|
49
|
+
return this.client.request<void>('POST', path);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function apikeyClient(): ApikeyPlugin {
|
|
55
|
+
return new ApikeyPlugin();
|
|
56
|
+
}
|