@protobase/client 0.46.3 → 0.46.5

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.
@@ -1,7 +1,7 @@
1
1
  import { authError } from "./auth-error.js";
2
2
  //#region src/account-profile.ts
3
3
  const isoDate = (value) => new Date(value).toISOString();
4
- /** The signed-in person's name, password and signed-in devices. Each call rejects with `AuthError`. */
4
+ /** The signed-in person's name, address, password and signed-in devices. Each call rejects with `AuthError`. */
5
5
  const accountProfile = (client) => ({
6
6
  updateName: async (name) => {
7
7
  const { error } = await client.updateUser({ name });
@@ -16,6 +16,39 @@ const accountProfile = (client) => ({
16
16
  });
17
17
  if (error) throw authError(error, "Could not change your password");
18
18
  },
19
+ /**
20
+ * Gives an account without a password, such as one that signs in with emailed codes or GitHub, its first one; every
21
+ * device stays signed in. One that has a password already is refused (`PASSWORD_ALREADY_SET`).
22
+ */
23
+ setPassword: async (next) => {
24
+ const { error } = await client.$fetch("/account/set-password", {
25
+ method: "POST",
26
+ body: { newPassword: next }
27
+ });
28
+ if (error) throw authError(error, "Could not set your password");
29
+ },
30
+ /**
31
+ * Mails a code to `newEmail` that moves the account to it, when the server has mail (`status().changeEmail`). The answer
32
+ * is the same when another account has the address, which then gets no code.
33
+ */
34
+ requestEmailChange: async (newEmail) => {
35
+ const { error } = await client.$fetch("/email-otp/request-email-change", {
36
+ method: "POST",
37
+ body: { newEmail }
38
+ });
39
+ if (error) throw authError(error, "Could not send the code");
40
+ },
41
+ /** Moves the account to `newEmail` with the code mailed there; this device stays signed in, with the new address. */
42
+ changeEmail: async (newEmail, code) => {
43
+ const { error } = await client.$fetch("/email-otp/change-email", {
44
+ method: "POST",
45
+ body: {
46
+ newEmail,
47
+ otp: code
48
+ }
49
+ });
50
+ if (error) throw authError(error, "Could not change your address");
51
+ },
19
52
  /** The devices signed in now, with this one marked `current`. */
20
53
  sessions: async () => {
21
54
  const [list, own] = await Promise.all([client.listSessions(), client.getSession()]);
@@ -31,7 +31,8 @@ export type SamlSignIn = {
31
31
  };
32
32
  /**
33
33
  * `needsAdmin` while no user exists yet; `signInMethods` the ways to sign in the server's policy leaves on;
34
- * `passwordReset` when the server can email reset links; `signUp` when anyone can make their own account (see
34
+ * `passwordReset` when the server can email reset links; `changeEmail` when it can email the code that confirms a new
35
+ * address (see `account.requestEmailChange`); `signUp` when anyone can make their own account (see
35
36
  * `sendSignUpCode`); `socialProviders` the ids of the sign-in providers, for example
36
37
  * `github`; `platformSignIn` the one of them the platform adds; `samlProviders` the app's SAML identity providers; `staffSignIn` the operator provider's name when its staff
37
38
  * can sign in as people; `organizations` when the app has them; `anonymous` when visitors may browse what the project's
@@ -43,6 +44,7 @@ export type SetupStatus = {
43
44
  needsAdmin: boolean;
44
45
  signInMethods: SignInMethod[];
45
46
  passwordReset: boolean;
47
+ changeEmail?: boolean;
46
48
  signUp?: boolean;
47
49
  socialProviders: string[];
48
50
  platformSignIn?: PlatformSignIn;
package/dist/auth.d.ts CHANGED
@@ -53,6 +53,9 @@ export declare const createAuthSession: (options?: AuthSessionOptions) => {
53
53
  account: {
54
54
  updateName: (name: string) => Promise<void>;
55
55
  changePassword: (current: string, next: string, signOutOthers: boolean) => Promise<void>;
56
+ setPassword: (next: string) => Promise<void>;
57
+ requestEmailChange: (newEmail: string) => Promise<void>;
58
+ changeEmail: (newEmail: string, code: string) => Promise<void>;
56
59
  sessions: () => Promise<DeviceSession[]>;
57
60
  revokeSession: (token: string) => Promise<void>;
58
61
  revokeOtherSessions: () => Promise<void>;
package/dist/auth.js CHANGED
@@ -77,6 +77,7 @@ const createAuthSession = (options = {}) => {
77
77
  needsAdmin: Boolean(body.needsAdmin),
78
78
  signInMethods: body.signInMethods ?? ["password"],
79
79
  passwordReset: Boolean(body.passwordReset),
80
+ ...body.changeEmail && { changeEmail: true },
80
81
  ...body.signUp && { signUp: true },
81
82
  socialProviders: body.socialProviders ?? [],
82
83
  ...body.platformSignIn && { platformSignIn: body.platformSignIn },
@@ -78,6 +78,9 @@ const createStaticSession = (token, user = {
78
78
  disconnectApp: unsupported("disconnect an app"),
79
79
  updateName: unsupported("change its name"),
80
80
  changePassword: unsupported("change its password"),
81
+ setPassword: unsupported("set its password"),
82
+ requestEmailChange: unsupported("change its address"),
83
+ changeEmail: unsupported("change its address"),
81
84
  sessions: async () => [],
82
85
  revokeSession: unsupported("sign out a device"),
83
86
  revokeOtherSessions: unsupported("sign out other devices")
package/dist/types.d.ts CHANGED
@@ -261,6 +261,7 @@ export type Meta = {
261
261
  resources: ResourceModel[];
262
262
  views: ViewModel[];
263
263
  pages?: PageModel[];
264
+ account?: PageModel;
264
265
  permissions?: Record<string, ResourcePermissions>;
265
266
  userMenu?: UserMenuModel;
266
267
  signIn?: SignInViewModel[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/client",
3
- "version": "0.46.3",
3
+ "version": "0.46.5",
4
4
  "description": "Typed fetch client for the Protobase REST API.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@better-auth/passkey": "^1.7.12",
33
- "@protobase/layout": "0.46.3",
34
- "@protobase/schema": "0.46.3",
33
+ "@protobase/layout": "0.46.5",
34
+ "@protobase/schema": "0.46.5",
35
35
  "@simplewebauthn/browser": "^13.3.0",
36
36
  "better-auth": "^1.7.12"
37
37
  }