@slyxup/core 0.2.4 → 1.0.0
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/.turbo/turbo-build.log +4 -0
- package/LICENSE +21 -0
- package/README.md +35 -8
- package/dist/client.d.ts +35 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +125 -10
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +48 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/client.ts +195 -19
- package/src/types.ts +56 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SlyxUp
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -20,15 +20,20 @@ const client = new SlyxupClient({
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
// ── Auth ──
|
|
23
|
-
await client.auth.signUp({ email: 'ada@example.com', password: 'password123', firstName: 'Ada' });
|
|
23
|
+
await client.auth.signUp({ email: 'ada@example.com', password: 'password123', firstName: 'Ada', username: 'ada' });
|
|
24
|
+
// Returns { user, sessionToken, expiresAt } on success, or
|
|
25
|
+
// { code: '2FA_REQUIRED', challengeToken } when the account has 2FA enabled.
|
|
24
26
|
await client.auth.signIn({ email: 'ada@example.com', password: 'password123' });
|
|
27
|
+
// Complete a 2FA challenge:
|
|
28
|
+
await client.auth.completeSignIn({ challengeToken, code: '123456' }); // or { challengeToken, recoveryCode }
|
|
25
29
|
await client.auth.signOut();
|
|
26
30
|
await client.auth.resendVerification('ada@example.com'); // resend email verification
|
|
31
|
+
await client.auth.forgotPassword('ada@example.com'); // send reset email
|
|
32
|
+
await client.auth.resetPassword(token, 'newPassword'); // reset with emailed token
|
|
33
|
+
await client.auth.verifyEmail(token); // confirm email with emailed token
|
|
27
34
|
|
|
28
|
-
// ── Sessions ──
|
|
29
|
-
const {
|
|
30
|
-
// session.expiresAt — ISO date; throws UnauthorizedError (401) when signed out
|
|
31
|
-
const { sessions } = await client.sessions.list();
|
|
35
|
+
// ── Sessions ── (list supports pagination)
|
|
36
|
+
const { sessions, total } = await client.sessions.list({ limit: 10, offset: 0 });
|
|
32
37
|
// SlyxupSessionInfo[]: { id, ipAddress, userAgent, expiresAt, createdAt, isCurrent }
|
|
33
38
|
await client.sessions.revoke('session-id'); // revoke one device
|
|
34
39
|
const { revoked } = await client.sessions.revokeOthers(); // sign out everywhere else
|
|
@@ -36,9 +41,20 @@ const { revoked } = await client.sessions.revokeOthers(); // sign out everywher
|
|
|
36
41
|
// ── Password ──
|
|
37
42
|
await client.password.change({ currentPassword, newPassword });
|
|
38
43
|
|
|
44
|
+
// ── Two-factor (TOTP) ──
|
|
45
|
+
const { secret, provisioningUri, accountName } = await client.twoFactor.setup();
|
|
46
|
+
await client.twoFactor.enable(secret, '123456'); // returns { recoveryCodes: string[] } — save them
|
|
47
|
+
await client.twoFactor.verify('123456'); // { valid: true }
|
|
48
|
+
await client.twoFactor.disable('123456');
|
|
49
|
+
const { enabled } = await client.twoFactor.status();
|
|
50
|
+
|
|
51
|
+
// ── Connected accounts (OAuth) ──
|
|
52
|
+
const { accounts } = await client.accounts.list(); // [{ id, provider, ... }]
|
|
53
|
+
await client.accounts.unlink(accountId, 'google');
|
|
54
|
+
|
|
39
55
|
// ── Users ──
|
|
40
|
-
const me = await client.users.me(); // full profile
|
|
41
|
-
await client.users.update({ firstName: 'Ada',
|
|
56
|
+
const me = await client.users.me(); // full profile (includes username, twoFactorEnabled)
|
|
57
|
+
await client.users.update({ firstName: 'Ada', username: 'ada' });
|
|
42
58
|
await client.users.delete(); // GDPR delete
|
|
43
59
|
```
|
|
44
60
|
|
|
@@ -72,13 +88,24 @@ try {
|
|
|
72
88
|
|---|---|---|
|
|
73
89
|
| `auth.signUp(input)` | POST | `/v1/auth/sign-up` |
|
|
74
90
|
| `auth.signIn(input)` | POST | `/v1/auth/sign-in` |
|
|
91
|
+
| `auth.completeSignIn(input)` | POST | `/v1/auth/sign-in/2fa` |
|
|
75
92
|
| `auth.signOut()` | POST | `/v1/auth/sign-out` |
|
|
76
93
|
| `auth.resendVerification(email)` | POST | `/v1/verification/resend` |
|
|
94
|
+
| `auth.forgotPassword(email)` | POST | `/v1/verification/password/forgot` |
|
|
95
|
+
| `auth.resetPassword(token, password)` | POST | `/v1/verification/password/reset` |
|
|
96
|
+
| `auth.verifyEmail(token)` | POST | `/v1/verification/verify` |
|
|
77
97
|
| `sessions.get()` | GET | `/v1/session` |
|
|
78
|
-
| `sessions.list()` | GET | `/v1/sessions` |
|
|
98
|
+
| `sessions.list({ limit, offset })` | GET | `/v1/sessions` |
|
|
79
99
|
| `sessions.revoke(id)` | DELETE | `/v1/sessions/:id` |
|
|
80
100
|
| `sessions.revokeOthers()` | DELETE | `/v1/sessions` |
|
|
81
101
|
| `password.change(input)` | POST | `/v1/user/password` |
|
|
102
|
+
| `twoFactor.setup()` | GET | `/v1/user/2fa/setup` |
|
|
103
|
+
| `twoFactor.status()` | GET | `/v1/user/2fa/status` |
|
|
104
|
+
| `twoFactor.enable(secret, code)` | POST | `/v1/user/2fa/enable` |
|
|
105
|
+
| `twoFactor.verify(code)` | POST | `/v1/user/2fa/verify` |
|
|
106
|
+
| `twoFactor.disable(code)` | POST | `/v1/user/2fa/disable` |
|
|
107
|
+
| `accounts.list()` | GET | `/v1/user/accounts` |
|
|
108
|
+
| `accounts.unlink(id, provider)` | DELETE | `/v1/user/accounts/:id` |
|
|
82
109
|
| `users.me()` | GET | `/v1/user` |
|
|
83
110
|
| `users.update(patch)` | PATCH | `/v1/user` |
|
|
84
111
|
| `users.delete()` | DELETE | `/v1/user` |
|
package/dist/client.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthResponse, ChangePasswordInput, RevokeSessionsResponse, SessionResponse, SessionsResponse, SignInInput, SignUpInput, SlyxupClientOptions, UpdateUserInput, UserResponse } from './types.js';
|
|
1
|
+
import type { AuthResponse, ChangePasswordInput, CompleteSignInInput, ConnectedAccountsResponse, EnableTOTPResponse, RevokeSessionsResponse, SessionResponse, SessionsResponse, SignInInput, SignInResponse, SignUpInput, SlyxupClientOptions, TOTPSetupResponse, TwoFactorStatusResponse, UpdateUserInput, UserResponse } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* SlyxUp Core Client.
|
|
4
4
|
*
|
|
@@ -15,17 +15,31 @@ export declare class SlyxupClient {
|
|
|
15
15
|
private _request?;
|
|
16
16
|
readonly auth: {
|
|
17
17
|
signUp: (input: SignUpInput) => Promise<AuthResponse>;
|
|
18
|
-
signIn: (input: SignInInput) => Promise<
|
|
18
|
+
signIn: (input: SignInInput) => Promise<SignInResponse>;
|
|
19
19
|
signOut: () => Promise<{
|
|
20
20
|
ok: true;
|
|
21
21
|
}>;
|
|
22
22
|
resendVerification: (email: string) => Promise<{
|
|
23
23
|
ok: true;
|
|
24
24
|
}>;
|
|
25
|
+
forgotPassword: (email: string, projectId?: string) => Promise<{
|
|
26
|
+
ok: true;
|
|
27
|
+
}>;
|
|
28
|
+
resetPassword: (token: string, password: string) => Promise<{
|
|
29
|
+
ok: true;
|
|
30
|
+
}>;
|
|
31
|
+
verifyEmail: (token: string) => Promise<{
|
|
32
|
+
ok: true;
|
|
33
|
+
}>;
|
|
34
|
+
/** Complete a 2FA challenge returned by signIn. */
|
|
35
|
+
completeSignIn: (input: CompleteSignInInput) => Promise<AuthResponse>;
|
|
25
36
|
};
|
|
26
37
|
readonly sessions: {
|
|
27
38
|
get: () => Promise<SessionResponse>;
|
|
28
|
-
list: (
|
|
39
|
+
list: (opts?: {
|
|
40
|
+
limit?: number;
|
|
41
|
+
offset?: number;
|
|
42
|
+
}) => Promise<SessionsResponse>;
|
|
29
43
|
revoke: (sessionId: string) => Promise<{
|
|
30
44
|
ok: true;
|
|
31
45
|
}>;
|
|
@@ -36,6 +50,24 @@ export declare class SlyxupClient {
|
|
|
36
50
|
ok: true;
|
|
37
51
|
}>;
|
|
38
52
|
};
|
|
53
|
+
readonly twoFactor: {
|
|
54
|
+
setup: () => Promise<TOTPSetupResponse>;
|
|
55
|
+
status: () => Promise<TwoFactorStatusResponse>;
|
|
56
|
+
enable: (secret: string, code: string) => Promise<EnableTOTPResponse>;
|
|
57
|
+
verify: (code: string) => Promise<{
|
|
58
|
+
ok: boolean;
|
|
59
|
+
valid: boolean;
|
|
60
|
+
}>;
|
|
61
|
+
disable: (code: string) => Promise<{
|
|
62
|
+
ok: true;
|
|
63
|
+
}>;
|
|
64
|
+
};
|
|
65
|
+
readonly accounts: {
|
|
66
|
+
list: () => Promise<ConnectedAccountsResponse>;
|
|
67
|
+
unlink: (accountId: string, provider: 'google' | 'github') => Promise<{
|
|
68
|
+
ok: true;
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
39
71
|
readonly users: {
|
|
40
72
|
me: () => Promise<UserResponse>;
|
|
41
73
|
update: (input: UpdateUserInput) => Promise<UserResponse>;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,yBAAyB,EACzB,kBAAkB,EAGlB,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EAEjB,uBAAuB,EACvB,eAAe,EACf,YAAY,EACb,MAAM,YAAY,CAAC;AAqBpB;;;;;;;;GAQG;AACH,qBAAa,YAAY;IACvB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,OAAO,CAAC,SAAS,CAAC,CAA2B;IAC7C,OAAO,CAAC,QAAQ,CAAC,CAAsD;IAEvE,QAAQ,CAAC,IAAI,EAAE;QACb,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;QACtD,MAAM,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;QACxD,OAAO,EAAE,MAAM,OAAO,CAAC;YAAE,EAAE,EAAE,IAAI,CAAA;SAAE,CAAC,CAAC;QACrC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;YAAE,EAAE,EAAE,IAAI,CAAA;SAAE,CAAC,CAAC;QAC7D,c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twoFactor;
|
|
38
|
+
accounts;
|
|
37
39
|
users;
|
|
38
40
|
/** Get current session token (for custom project APIs that need Bearer) */
|
|
39
41
|
getToken() {
|
|
@@ -47,12 +49,32 @@ export class SlyxupClient {
|
|
|
47
49
|
}
|
|
48
50
|
constructor(options = {}) {
|
|
49
51
|
const jar = createCookieJar();
|
|
52
|
+
// Persist token in localStorage so refresh keeps session for cross-origin (auth -> billing) and for dashboard project APIs
|
|
53
|
+
const STORAGE_KEY = 'slyxup_session_token';
|
|
50
54
|
let storedToken;
|
|
55
|
+
try {
|
|
56
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
57
|
+
storedToken = window.localStorage.getItem(STORAGE_KEY) ?? undefined;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
catch { }
|
|
61
|
+
const persistToken = (t) => {
|
|
62
|
+
storedToken = t;
|
|
63
|
+
try {
|
|
64
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
65
|
+
if (t)
|
|
66
|
+
window.localStorage.setItem(STORAGE_KEY, t);
|
|
67
|
+
else
|
|
68
|
+
window.localStorage.removeItem(STORAGE_KEY);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch { }
|
|
72
|
+
};
|
|
51
73
|
this.publishableKey = options.publishableKey;
|
|
52
74
|
this.apiUrl = (options.apiUrl ?? DEFAULT_API_URL).replace(/\/$/, '');
|
|
53
75
|
this._getToken = () => storedToken;
|
|
54
76
|
// _request will be assigned after `request` is defined below
|
|
55
|
-
const requestInner = async (path, init = {}) => {
|
|
77
|
+
const requestInner = async (path, init = {}, opts) => {
|
|
56
78
|
let res;
|
|
57
79
|
try {
|
|
58
80
|
// Build headers: prefer cookie jar (SSR), fall back to stored Bearer token (browser cross-origin)
|
|
@@ -87,6 +109,8 @@ export class SlyxupClient {
|
|
|
87
109
|
.json()
|
|
88
110
|
.catch(() => ({ ok: false, error: 'Invalid response' })));
|
|
89
111
|
if (!res.ok) {
|
|
112
|
+
if (opts?.captureError)
|
|
113
|
+
return data;
|
|
90
114
|
if (res.status === 401)
|
|
91
115
|
throw new UnauthorizedError('error' in data ? String(data.error) : undefined);
|
|
92
116
|
if (res.status === 429)
|
|
@@ -97,30 +121,45 @@ export class SlyxupClient {
|
|
|
97
121
|
}
|
|
98
122
|
return data;
|
|
99
123
|
};
|
|
100
|
-
const post = (path, body) => requestInner(path, {
|
|
124
|
+
const post = (path, body, opts) => requestInner(path, {
|
|
101
125
|
method: 'POST',
|
|
102
126
|
body: body === undefined ? undefined : JSON.stringify(body),
|
|
103
|
-
});
|
|
127
|
+
}, opts);
|
|
104
128
|
this.auth = {
|
|
105
129
|
signUp: async (input) => {
|
|
106
130
|
const res = await post('/v1/auth/sign-up', input);
|
|
107
131
|
if (!('user' in res))
|
|
108
132
|
throw new SlyxupError(res.error, 400, 'api_error');
|
|
109
133
|
if (res.sessionToken)
|
|
110
|
-
|
|
134
|
+
persistToken(res.sessionToken);
|
|
111
135
|
return res;
|
|
112
136
|
},
|
|
113
137
|
signIn: async (input) => {
|
|
114
|
-
|
|
138
|
+
// The server may answer 403 with code 2FA_REQUIRED — we must surface
|
|
139
|
+
// the challenge back to the caller instead of throwing a generic error.
|
|
140
|
+
const res = await post('/v1/auth/sign-in', input, {
|
|
141
|
+
captureError: true,
|
|
142
|
+
});
|
|
143
|
+
if ('challengeToken' in res) {
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
115
146
|
if (!('user' in res))
|
|
116
|
-
throw new
|
|
147
|
+
throw new UnauthorizedError(res.error ?? 'Sign in failed');
|
|
117
148
|
if (res.sessionToken)
|
|
118
|
-
|
|
149
|
+
persistToken(res.sessionToken);
|
|
150
|
+
return res;
|
|
151
|
+
},
|
|
152
|
+
completeSignIn: async (input) => {
|
|
153
|
+
const res = await post('/v1/auth/sign-in/2fa', input);
|
|
154
|
+
if (!('user' in res))
|
|
155
|
+
throw new UnauthorizedError(res.error);
|
|
156
|
+
if (res.sessionToken)
|
|
157
|
+
persistToken(res.sessionToken);
|
|
119
158
|
return res;
|
|
120
159
|
},
|
|
121
160
|
signOut: async () => {
|
|
122
161
|
const res = await post('/v1/auth/sign-out');
|
|
123
|
-
|
|
162
|
+
persistToken(undefined);
|
|
124
163
|
jar.clear();
|
|
125
164
|
return res;
|
|
126
165
|
},
|
|
@@ -132,6 +171,32 @@ export class SlyxupClient {
|
|
|
132
171
|
throw new SlyxupError(res.error, 400, 'api_error');
|
|
133
172
|
return res;
|
|
134
173
|
},
|
|
174
|
+
forgotPassword: async (email, projectId) => {
|
|
175
|
+
const res = await post('/v1/verification/password/forgot', {
|
|
176
|
+
email,
|
|
177
|
+
projectId,
|
|
178
|
+
});
|
|
179
|
+
if (!res.ok)
|
|
180
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
181
|
+
return res;
|
|
182
|
+
},
|
|
183
|
+
resetPassword: async (token, password) => {
|
|
184
|
+
const res = await post('/v1/verification/password/reset', {
|
|
185
|
+
token,
|
|
186
|
+
password,
|
|
187
|
+
});
|
|
188
|
+
if (!res.ok)
|
|
189
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
190
|
+
return res;
|
|
191
|
+
},
|
|
192
|
+
verifyEmail: async (token) => {
|
|
193
|
+
const res = await post('/v1/verification/verify', {
|
|
194
|
+
token,
|
|
195
|
+
});
|
|
196
|
+
if (!res.ok)
|
|
197
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
198
|
+
return res;
|
|
199
|
+
},
|
|
135
200
|
};
|
|
136
201
|
this.sessions = {
|
|
137
202
|
get: async () => {
|
|
@@ -140,8 +205,14 @@ export class SlyxupClient {
|
|
|
140
205
|
throw new UnauthorizedError(res.error);
|
|
141
206
|
return res;
|
|
142
207
|
},
|
|
143
|
-
list: async () => {
|
|
144
|
-
const
|
|
208
|
+
list: async (opts) => {
|
|
209
|
+
const params = new URLSearchParams();
|
|
210
|
+
if (opts?.limit !== undefined)
|
|
211
|
+
params.set('limit', String(opts.limit));
|
|
212
|
+
if (opts?.offset !== undefined)
|
|
213
|
+
params.set('offset', String(opts.offset));
|
|
214
|
+
const qs = params.toString();
|
|
215
|
+
const res = await requestInner(`/v1/sessions${qs ? `?${qs}` : ''}`);
|
|
145
216
|
if (!('sessions' in res))
|
|
146
217
|
throw new SlyxupError(res.error, 400, 'api_error');
|
|
147
218
|
return res;
|
|
@@ -169,6 +240,50 @@ export class SlyxupClient {
|
|
|
169
240
|
return res;
|
|
170
241
|
},
|
|
171
242
|
};
|
|
243
|
+
this.twoFactor = {
|
|
244
|
+
setup: async () => {
|
|
245
|
+
const res = await requestInner('/v1/user/2fa/setup');
|
|
246
|
+
if (!('secret' in res))
|
|
247
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
248
|
+
return res;
|
|
249
|
+
},
|
|
250
|
+
status: async () => {
|
|
251
|
+
const res = await requestInner('/v1/user/2fa/status');
|
|
252
|
+
return res;
|
|
253
|
+
},
|
|
254
|
+
enable: async (secret, code) => {
|
|
255
|
+
const res = await post('/v1/user/2fa/enable', { secret, code }, { captureError: true });
|
|
256
|
+
if (!('recoveryCodes' in res))
|
|
257
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
258
|
+
return res;
|
|
259
|
+
},
|
|
260
|
+
verify: async (code) => {
|
|
261
|
+
const res = await post('/v1/user/2fa/verify', { code }, { captureError: true });
|
|
262
|
+
if (!('valid' in res))
|
|
263
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
264
|
+
return res;
|
|
265
|
+
},
|
|
266
|
+
disable: async (code) => {
|
|
267
|
+
const res = await post('/v1/user/2fa/disable', { code });
|
|
268
|
+
if (!res.ok)
|
|
269
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
270
|
+
return res;
|
|
271
|
+
},
|
|
272
|
+
};
|
|
273
|
+
this.accounts = {
|
|
274
|
+
list: async () => {
|
|
275
|
+
const res = await requestInner('/v1/user/accounts');
|
|
276
|
+
if (!('accounts' in res))
|
|
277
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
278
|
+
return res;
|
|
279
|
+
},
|
|
280
|
+
unlink: async (accountId, provider) => {
|
|
281
|
+
const res = await requestInner(`/v1/user/accounts/${accountId}?provider=${encodeURIComponent(provider)}`, {
|
|
282
|
+
method: 'DELETE',
|
|
283
|
+
});
|
|
284
|
+
return res;
|
|
285
|
+
},
|
|
286
|
+
};
|
|
172
287
|
this.users = {
|
|
173
288
|
me: async () => {
|
|
174
289
|
const res = await requestInner('/v1/user');
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,cAAc,EACd,WAAW,EACX,iBAAiB,GAClB,MAAM,aAAa,CAAC;AAgBrB,MAAM,eAAe,GAAG,4BAA4B,CAAC;AAErD,0FAA0F;AAC1F,SAAS,eAAe;IACtB,IAAI,GAAuB,CAAC;IAC5B,OAAO;QACL,OAAO,CAAC,GAAa;YACnB,MAAM,SAAS,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;YAChD,IAAI,SAAS;gBAAE,GAAG,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QACvD,CAAC;QACD,MAAM;YACJ,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACpC,CAAC;QACD,KAAK;YACH,GAAG,GAAG,SAAS,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,YAAY;IACd,cAAc,CAAU;IACxB,MAAM,CAAS;IAChB,SAAS,CAA4B;IACrC,QAAQ,CAAuD;IAE9D,IAAI,CAKX;IAEO,QAAQ,CAKf;IAEO,QAAQ,CAEf;IAEO,KAAK,CAIZ;IAEF,2EAA2E;IA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Verified: boolean;
|
|
6
|
+
username: string | null;
|
|
6
7
|
firstName: string | null;
|
|
7
8
|
lastName: string | null;
|
|
8
9
|
avatarUrl: string | null;
|
|
10
|
+
twoFactorEnabled: boolean;
|
|
9
11
|
preferences: Record<string, unknown> | null;
|
|
10
12
|
createdAt: string;
|
|
11
13
|
updatedAt: string;
|
|
@@ -16,18 +18,21 @@ export interface SlyxupSession {
|
|
|
16
18
|
expiresAt: string;
|
|
17
19
|
}
|
|
18
20
|
export interface SignInInput {
|
|
19
|
-
email
|
|
21
|
+
email?: string;
|
|
22
|
+
username?: string;
|
|
20
23
|
password: string;
|
|
21
24
|
projectId?: string;
|
|
22
25
|
}
|
|
23
|
-
export interface SignUpInput extends SignInInput {
|
|
26
|
+
export interface SignUpInput extends Omit<SignInInput, 'username'> {
|
|
24
27
|
firstName?: string;
|
|
25
28
|
lastName?: string;
|
|
29
|
+
username?: string;
|
|
26
30
|
}
|
|
27
31
|
export interface UpdateUserInput {
|
|
28
32
|
firstName?: string;
|
|
29
33
|
lastName?: string;
|
|
30
34
|
avatarUrl?: string;
|
|
35
|
+
username?: string | null;
|
|
31
36
|
preferences?: Record<string, unknown>;
|
|
32
37
|
}
|
|
33
38
|
export interface SessionResponse {
|
|
@@ -51,6 +56,9 @@ export interface SlyxupSessionInfo {
|
|
|
51
56
|
export interface SessionsResponse {
|
|
52
57
|
ok: true;
|
|
53
58
|
sessions: SlyxupSessionInfo[];
|
|
59
|
+
total: number;
|
|
60
|
+
limit: number;
|
|
61
|
+
offset: number;
|
|
54
62
|
}
|
|
55
63
|
export interface RevokeSessionsResponse {
|
|
56
64
|
ok: true;
|
|
@@ -66,6 +74,44 @@ export interface AuthResponse {
|
|
|
66
74
|
sessionToken?: string;
|
|
67
75
|
expiresAt?: string;
|
|
68
76
|
}
|
|
77
|
+
/** Returned by signIn when the account has 2FA enabled. */
|
|
78
|
+
export interface TwoFactorRequiredResponse {
|
|
79
|
+
ok: false;
|
|
80
|
+
code: '2FA_REQUIRED';
|
|
81
|
+
challengeToken: string;
|
|
82
|
+
}
|
|
83
|
+
/** Union returned by client.auth.signIn. */
|
|
84
|
+
export type SignInResponse = AuthResponse | TwoFactorRequiredResponse;
|
|
85
|
+
export interface TOTPSetupResponse {
|
|
86
|
+
ok: true;
|
|
87
|
+
secret: string;
|
|
88
|
+
provisioningUri: string;
|
|
89
|
+
accountName: string;
|
|
90
|
+
}
|
|
91
|
+
export interface EnableTOTPResponse {
|
|
92
|
+
ok: true;
|
|
93
|
+
recoveryCodes: string[];
|
|
94
|
+
}
|
|
95
|
+
export interface TwoFactorStatusResponse {
|
|
96
|
+
ok: boolean;
|
|
97
|
+
enabled: boolean;
|
|
98
|
+
}
|
|
99
|
+
export interface ConnectedAccount {
|
|
100
|
+
id: string;
|
|
101
|
+
provider: 'google' | 'github';
|
|
102
|
+
providerAccountId: string;
|
|
103
|
+
createdAt: string;
|
|
104
|
+
}
|
|
105
|
+
export interface ConnectedAccountsResponse {
|
|
106
|
+
ok: true;
|
|
107
|
+
accounts: ConnectedAccount[];
|
|
108
|
+
}
|
|
109
|
+
/** Input for completing a 2FA sign-in challenge. */
|
|
110
|
+
export interface CompleteSignInInput {
|
|
111
|
+
challengeToken: string;
|
|
112
|
+
code?: string;
|
|
113
|
+
recoveryCode?: string;
|
|
114
|
+
}
|
|
69
115
|
export interface ErrorResponse {
|
|
70
116
|
ok: false;
|
|
71
117
|
error: string;
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,aAAa,EAAE,OAAO,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAA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ACd,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,KAAK,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;AAE1C,MAAM,WAAW,mBAAmB;IAClC,kDAAkD;IAClD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uDAAuD;IACvD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
|
package/package.json
CHANGED
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@slyxup/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "@slyxup/core — SlyxUp SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsc -p tsconfig.json",
|
|
10
|
-
"typecheck": "tsc --noEmit",
|
|
11
|
-
"test": "vitest run --passWithNoTests"
|
|
12
|
-
},
|
|
13
8
|
"repository": {
|
|
14
9
|
"type": "git",
|
|
15
10
|
"url": "git+https://github.com/slyxup/stack.git",
|
|
@@ -26,5 +21,10 @@
|
|
|
26
21
|
},
|
|
27
22
|
"devDependencies": {
|
|
28
23
|
"vitest": "^4.1.11"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsc -p tsconfig.json",
|
|
27
|
+
"typecheck": "tsc --noEmit",
|
|
28
|
+
"test": "vitest run --passWithNoTests"
|
|
29
29
|
}
|
|
30
|
-
}
|
|
30
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -7,14 +7,21 @@ import {
|
|
|
7
7
|
import type {
|
|
8
8
|
AuthResponse,
|
|
9
9
|
ChangePasswordInput,
|
|
10
|
+
CompleteSignInInput,
|
|
11
|
+
ConnectedAccountsResponse,
|
|
12
|
+
EnableTOTPResponse,
|
|
10
13
|
ErrorResponse,
|
|
11
14
|
Result,
|
|
12
15
|
RevokeSessionsResponse,
|
|
13
16
|
SessionResponse,
|
|
14
17
|
SessionsResponse,
|
|
15
18
|
SignInInput,
|
|
19
|
+
SignInResponse,
|
|
16
20
|
SignUpInput,
|
|
17
21
|
SlyxupClientOptions,
|
|
22
|
+
TOTPSetupResponse,
|
|
23
|
+
TwoFactorRequiredResponse,
|
|
24
|
+
TwoFactorStatusResponse,
|
|
18
25
|
UpdateUserInput,
|
|
19
26
|
UserResponse,
|
|
20
27
|
} from './types.js';
|
|
@@ -55,14 +62,25 @@ export class SlyxupClient {
|
|
|
55
62
|
|
|
56
63
|
readonly auth: {
|
|
57
64
|
signUp: (input: SignUpInput) => Promise<AuthResponse>;
|
|
58
|
-
signIn: (input: SignInInput) => Promise<
|
|
65
|
+
signIn: (input: SignInInput) => Promise<SignInResponse>;
|
|
59
66
|
signOut: () => Promise<{ ok: true }>;
|
|
60
67
|
resendVerification: (email: string) => Promise<{ ok: true }>;
|
|
68
|
+
forgotPassword: (
|
|
69
|
+
email: string,
|
|
70
|
+
projectId?: string
|
|
71
|
+
) => Promise<{ ok: true }>;
|
|
72
|
+
resetPassword: (token: string, password: string) => Promise<{ ok: true }>;
|
|
73
|
+
verifyEmail: (token: string) => Promise<{ ok: true }>;
|
|
74
|
+
/** Complete a 2FA challenge returned by signIn. */
|
|
75
|
+
completeSignIn: (input: CompleteSignInInput) => Promise<AuthResponse>;
|
|
61
76
|
};
|
|
62
77
|
|
|
63
78
|
readonly sessions: {
|
|
64
79
|
get: () => Promise<SessionResponse>;
|
|
65
|
-
list: (
|
|
80
|
+
list: (opts?: {
|
|
81
|
+
limit?: number;
|
|
82
|
+
offset?: number;
|
|
83
|
+
}) => Promise<SessionsResponse>;
|
|
66
84
|
revoke: (sessionId: string) => Promise<{ ok: true }>;
|
|
67
85
|
revokeOthers: () => Promise<RevokeSessionsResponse>;
|
|
68
86
|
};
|
|
@@ -71,6 +89,22 @@ export class SlyxupClient {
|
|
|
71
89
|
change: (input: ChangePasswordInput) => Promise<{ ok: true }>;
|
|
72
90
|
};
|
|
73
91
|
|
|
92
|
+
readonly twoFactor: {
|
|
93
|
+
setup: () => Promise<TOTPSetupResponse>;
|
|
94
|
+
status: () => Promise<TwoFactorStatusResponse>;
|
|
95
|
+
enable: (secret: string, code: string) => Promise<EnableTOTPResponse>;
|
|
96
|
+
verify: (code: string) => Promise<{ ok: boolean; valid: boolean }>;
|
|
97
|
+
disable: (code: string) => Promise<{ ok: true }>;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
readonly accounts: {
|
|
101
|
+
list: () => Promise<ConnectedAccountsResponse>;
|
|
102
|
+
unlink: (
|
|
103
|
+
accountId: string,
|
|
104
|
+
provider: 'google' | 'github'
|
|
105
|
+
) => Promise<{ ok: true }>;
|
|
106
|
+
};
|
|
107
|
+
|
|
74
108
|
readonly users: {
|
|
75
109
|
me: () => Promise<UserResponse>;
|
|
76
110
|
update: (input: UpdateUserInput) => Promise<UserResponse>;
|
|
@@ -89,7 +123,23 @@ export class SlyxupClient {
|
|
|
89
123
|
|
|
90
124
|
constructor(options: SlyxupClientOptions = {}) {
|
|
91
125
|
const jar = createCookieJar();
|
|
126
|
+
// Persist token in localStorage so refresh keeps session for cross-origin (auth -> billing) and for dashboard project APIs
|
|
127
|
+
const STORAGE_KEY = 'slyxup_session_token';
|
|
92
128
|
let storedToken: string | undefined;
|
|
129
|
+
try {
|
|
130
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
131
|
+
storedToken = window.localStorage.getItem(STORAGE_KEY) ?? undefined;
|
|
132
|
+
}
|
|
133
|
+
} catch {}
|
|
134
|
+
const persistToken = (t: string | undefined) => {
|
|
135
|
+
storedToken = t;
|
|
136
|
+
try {
|
|
137
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
138
|
+
if (t) window.localStorage.setItem(STORAGE_KEY, t);
|
|
139
|
+
else window.localStorage.removeItem(STORAGE_KEY);
|
|
140
|
+
}
|
|
141
|
+
} catch {}
|
|
142
|
+
};
|
|
93
143
|
this.publishableKey = options.publishableKey;
|
|
94
144
|
this.apiUrl = (options.apiUrl ?? DEFAULT_API_URL).replace(/\/$/, '');
|
|
95
145
|
this._getToken = () => storedToken;
|
|
@@ -97,7 +147,8 @@ export class SlyxupClient {
|
|
|
97
147
|
|
|
98
148
|
const requestInner = async <T>(
|
|
99
149
|
path: string,
|
|
100
|
-
init: RequestInit & { body?: string } = {}
|
|
150
|
+
init: RequestInit & { body?: string } = {},
|
|
151
|
+
opts?: { captureError?: boolean }
|
|
101
152
|
): Promise<Result<T>> => {
|
|
102
153
|
let res: Response;
|
|
103
154
|
try {
|
|
@@ -134,6 +185,7 @@ export class SlyxupClient {
|
|
|
134
185
|
.catch(() => ({ ok: false, error: 'Invalid response' }))) as object;
|
|
135
186
|
|
|
136
187
|
if (!res.ok) {
|
|
188
|
+
if (opts?.captureError) return data as Result<T>;
|
|
137
189
|
if (res.status === 401)
|
|
138
190
|
throw new UnauthorizedError(
|
|
139
191
|
'error' in data ? String(data.error) : undefined
|
|
@@ -151,30 +203,53 @@ export class SlyxupClient {
|
|
|
151
203
|
return data as Result<T>;
|
|
152
204
|
};
|
|
153
205
|
|
|
154
|
-
const post = <T>(
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
206
|
+
const post = <T>(
|
|
207
|
+
path: string,
|
|
208
|
+
body?: unknown,
|
|
209
|
+
opts?: { captureError?: boolean }
|
|
210
|
+
) =>
|
|
211
|
+
requestInner<T>(
|
|
212
|
+
path,
|
|
213
|
+
{
|
|
214
|
+
method: 'POST',
|
|
215
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
216
|
+
},
|
|
217
|
+
opts
|
|
218
|
+
);
|
|
159
219
|
|
|
160
220
|
this.auth = {
|
|
161
221
|
signUp: async (input) => {
|
|
162
222
|
const res = await post<AuthResponse>('/v1/auth/sign-up', input);
|
|
163
223
|
if (!('user' in res))
|
|
164
224
|
throw new SlyxupError(res.error, 400, 'api_error');
|
|
165
|
-
if (res.sessionToken)
|
|
225
|
+
if (res.sessionToken) persistToken(res.sessionToken);
|
|
166
226
|
return res;
|
|
167
227
|
},
|
|
168
228
|
signIn: async (input) => {
|
|
169
|
-
|
|
229
|
+
// The server may answer 403 with code 2FA_REQUIRED — we must surface
|
|
230
|
+
// the challenge back to the caller instead of throwing a generic error.
|
|
231
|
+
const res = await post<SignInResponse>('/v1/auth/sign-in', input, {
|
|
232
|
+
captureError: true,
|
|
233
|
+
});
|
|
234
|
+
if ('challengeToken' in res) {
|
|
235
|
+
return res as TwoFactorRequiredResponse;
|
|
236
|
+
}
|
|
170
237
|
if (!('user' in res))
|
|
171
|
-
throw new
|
|
172
|
-
|
|
238
|
+
throw new UnauthorizedError(
|
|
239
|
+
(res as { error?: string }).error ?? 'Sign in failed'
|
|
240
|
+
);
|
|
241
|
+
if (res.sessionToken) persistToken(res.sessionToken);
|
|
242
|
+
return res;
|
|
243
|
+
},
|
|
244
|
+
completeSignIn: async (input) => {
|
|
245
|
+
const res = await post<AuthResponse>('/v1/auth/sign-in/2fa', input);
|
|
246
|
+
if (!('user' in res)) throw new UnauthorizedError(res.error);
|
|
247
|
+
if (res.sessionToken) persistToken(res.sessionToken);
|
|
173
248
|
return res;
|
|
174
249
|
},
|
|
175
250
|
signOut: async () => {
|
|
176
251
|
const res = await post<{ ok: true }>('/v1/auth/sign-out');
|
|
177
|
-
|
|
252
|
+
persistToken(undefined);
|
|
178
253
|
jar.clear();
|
|
179
254
|
return res as { ok: true };
|
|
180
255
|
},
|
|
@@ -185,6 +260,35 @@ export class SlyxupClient {
|
|
|
185
260
|
if (!res.ok) throw new SlyxupError(res.error, 400, 'api_error');
|
|
186
261
|
return res as { ok: true };
|
|
187
262
|
},
|
|
263
|
+
forgotPassword: async (email: string, projectId?: string) => {
|
|
264
|
+
const res = await post<{ ok: true }>(
|
|
265
|
+
'/v1/verification/password/forgot',
|
|
266
|
+
{
|
|
267
|
+
email,
|
|
268
|
+
projectId,
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
if (!res.ok) throw new SlyxupError(res.error, 400, 'api_error');
|
|
272
|
+
return res as { ok: true };
|
|
273
|
+
},
|
|
274
|
+
resetPassword: async (token: string, password: string) => {
|
|
275
|
+
const res = await post<{ ok: true }>(
|
|
276
|
+
'/v1/verification/password/reset',
|
|
277
|
+
{
|
|
278
|
+
token,
|
|
279
|
+
password,
|
|
280
|
+
}
|
|
281
|
+
);
|
|
282
|
+
if (!res.ok) throw new SlyxupError(res.error, 400, 'api_error');
|
|
283
|
+
return res as { ok: true };
|
|
284
|
+
},
|
|
285
|
+
verifyEmail: async (token: string) => {
|
|
286
|
+
const res = await post<{ ok: true }>('/v1/verification/verify', {
|
|
287
|
+
token,
|
|
288
|
+
});
|
|
289
|
+
if (!res.ok) throw new SlyxupError(res.error, 400, 'api_error');
|
|
290
|
+
return res as { ok: true };
|
|
291
|
+
},
|
|
188
292
|
};
|
|
189
293
|
|
|
190
294
|
this.sessions = {
|
|
@@ -193,16 +297,26 @@ export class SlyxupClient {
|
|
|
193
297
|
if (!('session' in res)) throw new UnauthorizedError(res.error);
|
|
194
298
|
return res;
|
|
195
299
|
},
|
|
196
|
-
list: async () => {
|
|
197
|
-
const
|
|
300
|
+
list: async (opts?: { limit?: number; offset?: number }) => {
|
|
301
|
+
const params = new URLSearchParams();
|
|
302
|
+
if (opts?.limit !== undefined) params.set('limit', String(opts.limit));
|
|
303
|
+
if (opts?.offset !== undefined)
|
|
304
|
+
params.set('offset', String(opts.offset));
|
|
305
|
+
const qs = params.toString();
|
|
306
|
+
const res = await requestInner<SessionsResponse>(
|
|
307
|
+
`/v1/sessions${qs ? `?${qs}` : ''}`
|
|
308
|
+
);
|
|
198
309
|
if (!('sessions' in res))
|
|
199
310
|
throw new SlyxupError(res.error, 400, 'api_error');
|
|
200
311
|
return res;
|
|
201
312
|
},
|
|
202
313
|
revoke: async (sessionId: string) => {
|
|
203
|
-
const res = await requestInner<{ ok: true }>(
|
|
204
|
-
|
|
205
|
-
|
|
314
|
+
const res = await requestInner<{ ok: true }>(
|
|
315
|
+
`/v1/sessions/${sessionId}`,
|
|
316
|
+
{
|
|
317
|
+
method: 'DELETE',
|
|
318
|
+
}
|
|
319
|
+
);
|
|
206
320
|
return res as { ok: true };
|
|
207
321
|
},
|
|
208
322
|
revokeOthers: async () => {
|
|
@@ -223,6 +337,65 @@ export class SlyxupClient {
|
|
|
223
337
|
},
|
|
224
338
|
};
|
|
225
339
|
|
|
340
|
+
this.twoFactor = {
|
|
341
|
+
setup: async () => {
|
|
342
|
+
const res = await requestInner<TOTPSetupResponse>('/v1/user/2fa/setup');
|
|
343
|
+
if (!('secret' in res))
|
|
344
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
345
|
+
return res;
|
|
346
|
+
},
|
|
347
|
+
status: async () => {
|
|
348
|
+
const res = await requestInner<TwoFactorStatusResponse>(
|
|
349
|
+
'/v1/user/2fa/status'
|
|
350
|
+
);
|
|
351
|
+
return res as TwoFactorStatusResponse;
|
|
352
|
+
},
|
|
353
|
+
enable: async (secret, code) => {
|
|
354
|
+
const res = await post<EnableTOTPResponse>(
|
|
355
|
+
'/v1/user/2fa/enable',
|
|
356
|
+
{ secret, code },
|
|
357
|
+
{ captureError: true }
|
|
358
|
+
);
|
|
359
|
+
if (!('recoveryCodes' in res))
|
|
360
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
361
|
+
return res;
|
|
362
|
+
},
|
|
363
|
+
verify: async (code) => {
|
|
364
|
+
const res = await post<{ ok: boolean; valid: boolean }>(
|
|
365
|
+
'/v1/user/2fa/verify',
|
|
366
|
+
{ code },
|
|
367
|
+
{ captureError: true }
|
|
368
|
+
);
|
|
369
|
+
if (!('valid' in res))
|
|
370
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
371
|
+
return res as { ok: boolean; valid: boolean };
|
|
372
|
+
},
|
|
373
|
+
disable: async (code) => {
|
|
374
|
+
const res = await post<{ ok: true }>('/v1/user/2fa/disable', { code });
|
|
375
|
+
if (!res.ok) throw new SlyxupError(res.error, 400, 'api_error');
|
|
376
|
+
return res as { ok: true };
|
|
377
|
+
},
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
this.accounts = {
|
|
381
|
+
list: async () => {
|
|
382
|
+
const res =
|
|
383
|
+
await requestInner<ConnectedAccountsResponse>('/v1/user/accounts');
|
|
384
|
+
if (!('accounts' in res))
|
|
385
|
+
throw new SlyxupError(res.error, 400, 'api_error');
|
|
386
|
+
return res;
|
|
387
|
+
},
|
|
388
|
+
unlink: async (accountId, provider) => {
|
|
389
|
+
const res = await requestInner<{ ok: true }>(
|
|
390
|
+
`/v1/user/accounts/${accountId}?provider=${encodeURIComponent(provider)}`,
|
|
391
|
+
{
|
|
392
|
+
method: 'DELETE',
|
|
393
|
+
}
|
|
394
|
+
);
|
|
395
|
+
return res as { ok: true };
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
|
|
226
399
|
this.users = {
|
|
227
400
|
me: async () => {
|
|
228
401
|
const res = await requestInner<UserResponse>('/v1/user');
|
|
@@ -246,7 +419,10 @@ export class SlyxupClient {
|
|
|
246
419
|
},
|
|
247
420
|
};
|
|
248
421
|
|
|
249
|
-
this._request = requestInner as unknown as <T>(
|
|
422
|
+
this._request = requestInner as unknown as <T>(
|
|
423
|
+
path: string,
|
|
424
|
+
init?: RequestInit
|
|
425
|
+
) => Promise<T>;
|
|
250
426
|
}
|
|
251
427
|
}
|
|
252
428
|
|
package/src/types.ts
CHANGED
|
@@ -5,9 +5,11 @@ export interface SlyxupUser {
|
|
|
5
5
|
projectId: string | null;
|
|
6
6
|
email: string;
|
|
7
7
|
emailVerified: boolean;
|
|
8
|
+
username: string | null;
|
|
8
9
|
firstName: string | null;
|
|
9
10
|
lastName: string | null;
|
|
10
11
|
avatarUrl: string | null;
|
|
12
|
+
twoFactorEnabled: boolean;
|
|
11
13
|
preferences: Record<string, unknown> | null;
|
|
12
14
|
createdAt: string;
|
|
13
15
|
updatedAt: string;
|
|
@@ -20,20 +22,23 @@ export interface SlyxupSession {
|
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
export interface SignInInput {
|
|
23
|
-
email
|
|
25
|
+
email?: string;
|
|
26
|
+
username?: string;
|
|
24
27
|
password: string;
|
|
25
28
|
projectId?: string;
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
export interface SignUpInput extends SignInInput {
|
|
31
|
+
export interface SignUpInput extends Omit<SignInInput, 'username'> {
|
|
29
32
|
firstName?: string;
|
|
30
33
|
lastName?: string;
|
|
34
|
+
username?: string;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
export interface UpdateUserInput {
|
|
34
38
|
firstName?: string;
|
|
35
39
|
lastName?: string;
|
|
36
40
|
avatarUrl?: string;
|
|
41
|
+
username?: string | null;
|
|
37
42
|
preferences?: Record<string, unknown>;
|
|
38
43
|
}
|
|
39
44
|
|
|
@@ -61,6 +66,9 @@ export interface SlyxupSessionInfo {
|
|
|
61
66
|
export interface SessionsResponse {
|
|
62
67
|
ok: true;
|
|
63
68
|
sessions: SlyxupSessionInfo[];
|
|
69
|
+
total: number;
|
|
70
|
+
limit: number;
|
|
71
|
+
offset: number;
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
export interface RevokeSessionsResponse {
|
|
@@ -80,6 +88,52 @@ export interface AuthResponse {
|
|
|
80
88
|
expiresAt?: string;
|
|
81
89
|
}
|
|
82
90
|
|
|
91
|
+
/** Returned by signIn when the account has 2FA enabled. */
|
|
92
|
+
export interface TwoFactorRequiredResponse {
|
|
93
|
+
ok: false;
|
|
94
|
+
code: '2FA_REQUIRED';
|
|
95
|
+
challengeToken: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Union returned by client.auth.signIn. */
|
|
99
|
+
export type SignInResponse = AuthResponse | TwoFactorRequiredResponse;
|
|
100
|
+
|
|
101
|
+
export interface TOTPSetupResponse {
|
|
102
|
+
ok: true;
|
|
103
|
+
secret: string;
|
|
104
|
+
provisioningUri: string;
|
|
105
|
+
accountName: string;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface EnableTOTPResponse {
|
|
109
|
+
ok: true;
|
|
110
|
+
recoveryCodes: string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface TwoFactorStatusResponse {
|
|
114
|
+
ok: boolean;
|
|
115
|
+
enabled: boolean;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface ConnectedAccount {
|
|
119
|
+
id: string;
|
|
120
|
+
provider: 'google' | 'github';
|
|
121
|
+
providerAccountId: string;
|
|
122
|
+
createdAt: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export interface ConnectedAccountsResponse {
|
|
126
|
+
ok: true;
|
|
127
|
+
accounts: ConnectedAccount[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** Input for completing a 2FA sign-in challenge. */
|
|
131
|
+
export interface CompleteSignInInput {
|
|
132
|
+
challengeToken: string;
|
|
133
|
+
code?: string;
|
|
134
|
+
recoveryCode?: string;
|
|
135
|
+
}
|
|
136
|
+
|
|
83
137
|
export interface ErrorResponse {
|
|
84
138
|
ok: false;
|
|
85
139
|
error: string;
|