@yackey-labs/yauth-client 0.1.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/dist/index.js +196 -0
- package/package.json +30 -0
- package/src/bindings/AccountLockoutMessageResponse.ts +3 -0
- package/src/bindings/ApiKeyResponse.ts +3 -0
- package/src/bindings/AuthConfigResponse.ts +14 -0
- package/src/bindings/AuthMethod.ts +3 -0
- package/src/bindings/AuthUser.ts +4 -0
- package/src/bindings/AuthorizeQuery.ts +3 -0
- package/src/bindings/AuthorizeResponse.ts +3 -0
- package/src/bindings/BackupCodeCountResponse.ts +3 -0
- package/src/bindings/BackupCodesResponse.ts +3 -0
- package/src/bindings/BanRequest.ts +3 -0
- package/src/bindings/CallbackBody.ts +3 -0
- package/src/bindings/ChangePasswordRequest.ts +3 -0
- package/src/bindings/ConfirmTotpRequest.ts +3 -0
- package/src/bindings/CreateApiKeyRequest.ts +3 -0
- package/src/bindings/CreateApiKeyResponse.ts +3 -0
- package/src/bindings/CreateWebhookRequest.ts +3 -0
- package/src/bindings/ForgotPasswordRequest.ts +3 -0
- package/src/bindings/ListSessionsQuery.ts +3 -0
- package/src/bindings/ListUsersQuery.ts +3 -0
- package/src/bindings/LoginRequest.ts +3 -0
- package/src/bindings/MagicLinkMessageResponse.ts +3 -0
- package/src/bindings/MagicLinkSendRequest.ts +3 -0
- package/src/bindings/MagicLinkVerifyRequest.ts +3 -0
- package/src/bindings/MessageResponse.ts +3 -0
- package/src/bindings/MfaAuthResponse.ts +3 -0
- package/src/bindings/MfaMessageResponse.ts +3 -0
- package/src/bindings/OAuthAccountResponse.ts +3 -0
- package/src/bindings/OAuthAuthResponse.ts +3 -0
- package/src/bindings/PasskeyInfo.ts +3 -0
- package/src/bindings/PasskeyLoginBeginRequest.ts +3 -0
- package/src/bindings/PasskeyLoginFinishRequest.ts +3 -0
- package/src/bindings/RefreshRequest.ts +3 -0
- package/src/bindings/RegisterFinishRequest.ts +3 -0
- package/src/bindings/RegisterRequest.ts +3 -0
- package/src/bindings/RequestUnlockRequest.ts +3 -0
- package/src/bindings/ResendVerificationRequest.ts +3 -0
- package/src/bindings/ResetPasswordRequest.ts +3 -0
- package/src/bindings/RevokeRequest.ts +3 -0
- package/src/bindings/SetupTotpResponse.ts +3 -0
- package/src/bindings/TokenRequest.ts +7 -0
- package/src/bindings/TokenResponse.ts +3 -0
- package/src/bindings/UnlockAccountRequest.ts +3 -0
- package/src/bindings/UpdateProfileRequest.ts +3 -0
- package/src/bindings/UpdateUserRequest.ts +3 -0
- package/src/bindings/UpdateWebhookRequest.ts +3 -0
- package/src/bindings/VerifyEmailRequest.ts +3 -0
- package/src/bindings/VerifyMfaRequest.ts +3 -0
- package/src/bindings/WebhookDeliveryResponse.ts +3 -0
- package/src/bindings/WebhookDetailResponse.ts +5 -0
- package/src/bindings/WebhookResponse.ts +3 -0
- package/src/generated.test.ts +337 -0
- package/src/generated.ts +385 -0
- package/src/index.ts +419 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function createClient(opts) {
|
|
3
|
+
const { baseUrl, credentials = "include" } = opts;
|
|
4
|
+
const fetchFn = opts.fetch ?? globalThis.fetch;
|
|
5
|
+
async function request(path, options = {}) {
|
|
6
|
+
const { method = "GET", body, headers = {} } = options;
|
|
7
|
+
const response = await fetchFn(`${baseUrl}${path}`, {
|
|
8
|
+
method,
|
|
9
|
+
credentials,
|
|
10
|
+
headers: {
|
|
11
|
+
"Content-Type": "application/json",
|
|
12
|
+
...headers
|
|
13
|
+
},
|
|
14
|
+
body: body ? JSON.stringify(body) : undefined
|
|
15
|
+
});
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
const text2 = await response.text();
|
|
18
|
+
let error;
|
|
19
|
+
try {
|
|
20
|
+
const json = JSON.parse(text2);
|
|
21
|
+
error = json.error ?? json.message ?? text2;
|
|
22
|
+
} catch {
|
|
23
|
+
error = text2;
|
|
24
|
+
}
|
|
25
|
+
throw new YAuthError(error, response.status);
|
|
26
|
+
}
|
|
27
|
+
const text = await response.text();
|
|
28
|
+
return text ? JSON.parse(text) : undefined;
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
getSession: () => request("/session"),
|
|
32
|
+
logout: () => request("/logout", { method: "POST" }),
|
|
33
|
+
updateProfile: (data) => request("/me", { method: "PATCH", body: data }),
|
|
34
|
+
emailPassword: {
|
|
35
|
+
register: (data) => request("/register", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
body: data
|
|
38
|
+
}),
|
|
39
|
+
login: (data) => request("/login", { method: "POST", body: data }),
|
|
40
|
+
verify: (token) => request("/verify-email", {
|
|
41
|
+
method: "POST",
|
|
42
|
+
body: { token }
|
|
43
|
+
}),
|
|
44
|
+
resendVerification: (email) => request("/resend-verification", {
|
|
45
|
+
method: "POST",
|
|
46
|
+
body: { email }
|
|
47
|
+
}),
|
|
48
|
+
forgotPassword: (email) => request("/forgot-password", {
|
|
49
|
+
method: "POST",
|
|
50
|
+
body: { email }
|
|
51
|
+
}),
|
|
52
|
+
resetPassword: (token, password) => request("/reset-password", {
|
|
53
|
+
method: "POST",
|
|
54
|
+
body: { token, password }
|
|
55
|
+
}),
|
|
56
|
+
changePassword: (currentPassword, newPassword) => request("/change-password", {
|
|
57
|
+
method: "POST",
|
|
58
|
+
body: {
|
|
59
|
+
current_password: currentPassword,
|
|
60
|
+
new_password: newPassword
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
passkey: {
|
|
65
|
+
loginBegin: (email) => request("/passkey/login/begin", {
|
|
66
|
+
method: "POST",
|
|
67
|
+
body: email ? { email } : {}
|
|
68
|
+
}),
|
|
69
|
+
loginFinish: (challenge_id, credential) => request("/passkey/login/finish", {
|
|
70
|
+
method: "POST",
|
|
71
|
+
body: { challenge_id, credential }
|
|
72
|
+
}),
|
|
73
|
+
registerBegin: () => request("/passkeys/register/begin", {
|
|
74
|
+
method: "POST"
|
|
75
|
+
}),
|
|
76
|
+
registerFinish: (credential, name) => request("/passkeys/register/finish", {
|
|
77
|
+
method: "POST",
|
|
78
|
+
body: { credential, name }
|
|
79
|
+
}),
|
|
80
|
+
list: () => request("/passkeys"),
|
|
81
|
+
delete: (id) => request(`/passkeys/${id}`, {
|
|
82
|
+
method: "DELETE"
|
|
83
|
+
})
|
|
84
|
+
},
|
|
85
|
+
mfa: {
|
|
86
|
+
setup: () => request("/mfa/totp/setup", { method: "POST" }),
|
|
87
|
+
confirm: (code) => request("/mfa/totp/confirm", {
|
|
88
|
+
method: "POST",
|
|
89
|
+
body: { code }
|
|
90
|
+
}),
|
|
91
|
+
verify: (pending_session_id, code) => request("/mfa/verify", {
|
|
92
|
+
method: "POST",
|
|
93
|
+
body: { pending_session_id, code }
|
|
94
|
+
}),
|
|
95
|
+
disable: () => request("/mfa/totp", { method: "DELETE" }),
|
|
96
|
+
getBackupCodeCount: () => request("/mfa/backup-codes"),
|
|
97
|
+
regenerateBackupCodes: () => request("/mfa/backup-codes/regenerate", {
|
|
98
|
+
method: "POST"
|
|
99
|
+
})
|
|
100
|
+
},
|
|
101
|
+
oauth: {
|
|
102
|
+
authorize: (provider, redirect_url) => {
|
|
103
|
+
const params = redirect_url ? `?redirect_url=${encodeURIComponent(redirect_url)}` : "";
|
|
104
|
+
window.location.href = `${baseUrl}/oauth/${provider}/authorize${params}`;
|
|
105
|
+
},
|
|
106
|
+
callback: (provider, code, state) => request(`/oauth/${provider}/callback`, {
|
|
107
|
+
method: "POST",
|
|
108
|
+
body: { code, state }
|
|
109
|
+
}),
|
|
110
|
+
accounts: () => request("/oauth/accounts"),
|
|
111
|
+
unlink: (provider) => request(`/oauth/${provider}`, {
|
|
112
|
+
method: "DELETE"
|
|
113
|
+
}),
|
|
114
|
+
link: (provider) => request(`/oauth/${provider}/link`, {
|
|
115
|
+
method: "POST"
|
|
116
|
+
})
|
|
117
|
+
},
|
|
118
|
+
magicLink: {
|
|
119
|
+
send: (email) => request("/magic-link/send", {
|
|
120
|
+
method: "POST",
|
|
121
|
+
body: { email }
|
|
122
|
+
}),
|
|
123
|
+
verify: (token) => request("/magic-link/verify", {
|
|
124
|
+
method: "POST",
|
|
125
|
+
body: { token }
|
|
126
|
+
})
|
|
127
|
+
},
|
|
128
|
+
bearer: {
|
|
129
|
+
getToken: (email, password) => request("/token", { method: "POST", body: { email, password } }),
|
|
130
|
+
refresh: (refresh_token) => request("/token/refresh", { method: "POST", body: { refresh_token } }),
|
|
131
|
+
revoke: (refresh_token) => request("/token/revoke", {
|
|
132
|
+
method: "POST",
|
|
133
|
+
body: { refresh_token }
|
|
134
|
+
})
|
|
135
|
+
},
|
|
136
|
+
apiKeys: {
|
|
137
|
+
create: (data) => request("/api-keys", { method: "POST", body: data }),
|
|
138
|
+
list: () => request("/api-keys"),
|
|
139
|
+
delete: (id) => request(`/api-keys/${id}`, { method: "DELETE" })
|
|
140
|
+
},
|
|
141
|
+
admin: {
|
|
142
|
+
listUsers: (params) => {
|
|
143
|
+
const query = new URLSearchParams;
|
|
144
|
+
if (params?.page)
|
|
145
|
+
query.set("page", String(params.page));
|
|
146
|
+
if (params?.per_page)
|
|
147
|
+
query.set("per_page", String(params.per_page));
|
|
148
|
+
if (params?.search)
|
|
149
|
+
query.set("search", params.search);
|
|
150
|
+
const qs = query.toString();
|
|
151
|
+
return request(`/admin/users${qs ? `?${qs}` : ""}`);
|
|
152
|
+
},
|
|
153
|
+
getUser: (id) => request(`/admin/users/${id}`),
|
|
154
|
+
updateUser: (id, data) => request(`/admin/users/${id}`, { method: "PUT", body: data }),
|
|
155
|
+
deleteUser: (id) => request(`/admin/users/${id}`, {
|
|
156
|
+
method: "DELETE"
|
|
157
|
+
}),
|
|
158
|
+
banUser: (id, data) => request(`/admin/users/${id}/ban`, {
|
|
159
|
+
method: "POST",
|
|
160
|
+
body: data ?? {}
|
|
161
|
+
}),
|
|
162
|
+
unbanUser: (id) => request(`/admin/users/${id}/unban`, {
|
|
163
|
+
method: "POST"
|
|
164
|
+
}),
|
|
165
|
+
impersonate: (id) => request(`/admin/users/${id}/impersonate`, { method: "POST" }),
|
|
166
|
+
listSessions: (params) => {
|
|
167
|
+
const query = new URLSearchParams;
|
|
168
|
+
if (params?.page)
|
|
169
|
+
query.set("page", String(params.page));
|
|
170
|
+
if (params?.per_page)
|
|
171
|
+
query.set("per_page", String(params.per_page));
|
|
172
|
+
const qs = query.toString();
|
|
173
|
+
return request(`/admin/sessions${qs ? `?${qs}` : ""}`);
|
|
174
|
+
},
|
|
175
|
+
deleteSession: (id) => request(`/admin/sessions/${id}`, {
|
|
176
|
+
method: "DELETE"
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
class YAuthError extends Error {
|
|
183
|
+
status;
|
|
184
|
+
constructor(message, status) {
|
|
185
|
+
super(message);
|
|
186
|
+
this.status = status;
|
|
187
|
+
this.name = "YAuthError";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
function createYAuthClient(options) {
|
|
191
|
+
return createClient(options);
|
|
192
|
+
}
|
|
193
|
+
export {
|
|
194
|
+
createYAuthClient,
|
|
195
|
+
YAuthError
|
|
196
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@yackey-labs/yauth-client",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./src/index.ts",
|
|
12
|
+
"default": "./src/index.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "bun build src/index.ts --outdir dist --target browser",
|
|
21
|
+
"typecheck": "tsc --noEmit",
|
|
22
|
+
"test": "bun test"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@yackey-labs/yauth-shared": "0.1.0"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.7.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
export type ApiKeyResponse = { id: string, name: string, prefix: string, scopes: Array<string> | null, last_used_at: string | null, expires_at: string | null, created_at: string, };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Server-side auth configuration exposed to frontends via `GET /config`.
|
|
5
|
+
*/
|
|
6
|
+
export type AuthConfigResponse = {
|
|
7
|
+
/**
|
|
8
|
+
* Whether new user registration is allowed.
|
|
9
|
+
*/
|
|
10
|
+
allow_signups: boolean,
|
|
11
|
+
/**
|
|
12
|
+
* Whether newly registered users must verify their email before logging in.
|
|
13
|
+
*/
|
|
14
|
+
require_email_verification: boolean, };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { AuthMethod } from "./AuthMethod";
|
|
3
|
+
|
|
4
|
+
export type AuthUser = { id: string, email: string, display_name: string | null, email_verified: boolean, role: string, banned: boolean, auth_method: AuthMethod, scopes?: Array<string> | null, };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
export type CreateApiKeyResponse = { id: string, key: string, name: string, prefix: string, scopes: Array<string> | null, expires_at: string | null, created_at: string, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
|
|
3
|
+
export type TokenRequest = { email: string, password: string,
|
|
4
|
+
/**
|
|
5
|
+
* Optional space-separated OAuth2 scopes (e.g. "read:runs write:runs").
|
|
6
|
+
*/
|
|
7
|
+
scope: string | null, };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
2
|
+
import type { WebhookDeliveryResponse } from "./WebhookDeliveryResponse";
|
|
3
|
+
import type { WebhookResponse } from "./WebhookResponse";
|
|
4
|
+
|
|
5
|
+
export type WebhookDetailResponse = { webhook: WebhookResponse, recent_deliveries: Array<WebhookDeliveryResponse>, };
|