@protobase/client 0.66.5 → 0.66.7

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.
@@ -7,12 +7,15 @@ const accountProfile = (client) => ({
7
7
  const { error } = await client.updateUser({ name });
8
8
  if (error) throw authError(error, "Could not change your name");
9
9
  },
10
- /** Changes the password, which the account must have; `signOutOthers` signs out every other device, this one stays signed in. */
11
- changePassword: async (current, next, signOutOthers) => {
10
+ /**
11
+ * Changes the password, which the account must have: every other device is signed out, this one stays signed in,
12
+ * and the account's address is emailed that its password changed.
13
+ */
14
+ changePassword: async (current, next) => {
12
15
  const { error } = await client.changePassword({
13
16
  currentPassword: current,
14
17
  newPassword: next,
15
- revokeOtherSessions: signOutOthers
18
+ revokeOtherSessions: true
16
19
  });
17
20
  if (error) throw authError(error, "Could not change your password");
18
21
  },
package/dist/auth.d.ts CHANGED
@@ -58,7 +58,7 @@ export declare const createAuthSession: (options?: AuthSessionOptions) => {
58
58
  resetPassword: (token: string, newPassword: string) => Promise<void>;
59
59
  account: {
60
60
  updateName: (name: string) => Promise<void>;
61
- changePassword: (current: string, next: string, signOutOthers: boolean) => Promise<void>;
61
+ changePassword: (current: string, next: string) => Promise<void>;
62
62
  setPassword: (next: string) => Promise<void>;
63
63
  requestEmailChange: (newEmail: string) => Promise<void>;
64
64
  changeEmail: (newEmail: string, code: string) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -10,6 +10,7 @@ import { RecordCall, RecordCallsHandlers } from "./record-calls.js";
10
10
  import { UploadProgress } from "./upload-request.js";
11
11
  import { LiveChange, LiveHandlers } from "./live.js";
12
12
  import { Client, InvokeOptions, UploadOptions, UploadResult, createClient } from "./client.js";
13
+ import { LiveSocket, PollThenSocketOptions, pollThenSocket } from "./poll-then-socket.js";
13
14
  import { Availability, PersonStatus, StatusClient, StatusInput } from "./status.js";
14
15
  import { CallRing, RingsClient } from "./rings.js";
15
16
  import { ApiError, PreconditionFailedError, ProblemDetails, ProblemError, isApiError } from "./problem.js";
@@ -31,4 +32,4 @@ import { createStaticSession } from "./static-session.js";
31
32
  import { AssistantClient, AssistantClientOptions, AssistantConnection, createAssistantClient } from "./assistant.js";
32
33
  import { RuntimeClient, RuntimeClientOptions, RuntimeLastUpdate, RuntimePolicy, RuntimeStatus, RuntimeUpdateStage, createRuntimeClient } from "./runtime.js";
33
34
  import { availabilities, heldStatus, maxStatusText, statusTextProblem } from "@protobase/schema/internal";
34
- export { type AccountSecurity, type AccountSignIn, type ActiveRole, type Aggregate, type AggregateGroup, type AggregateParams, type AggregateSplitTotal, ApiError, type AppUser, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type Availability, type BatchOp, type BatchRef, type BatchResult, type CallRing, type Channel, type ChannelError, type ChannelMessage, ChannelRefusal, type ChannelStatus, type ChannelUser, type Client, type ClientOptions, type CommentPage, type CommentPerson, type ConnectClient, type ConnectedApp, type ConnectingClient, type CurrentOrganization, type DeviceSession, type DevicesClient, type Facet, type FilterInput, type FormChallenge, type FormProof, type Histogram, type HistogramBucket, type HistoryChange, type HistoryPage, type InboxNotification, type InboxPage, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type LiveChange, type LiveHandlers, type MapBounds, type MapBucket, type MapLayerModel, type MapParams, type MapResult, type MentionableUser, type Meta, type MetaResult, type NotificationHistoryClient, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationPerson, type OrganizationRole, type OrganizationsClient, type OrganizationsFound, type Passkey, type PersonStatus, type PersonalMailLink, type PlatformSignIn, type PluginRef, PreconditionFailedError, type PresenceChange, type PresenceEntry, type ProblemDetails, type ProblemError, type PublicForm, type RecordCall, type RecordCallsHandlers, type RecordComment, type RecordOf, type RecordPermissions, type RecordPhotos, type RegisteredDevice, type RelatedLabels, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RingsClient, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimeLastUpdate, type RuntimePolicy, type RuntimeStatus, type RuntimeUpdateStage, type SamlSignIn, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SocketLike, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type StatusClient, type StatusInput, type Stored, type StoredFile, type StoredFileVariant, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, type UserInvitation, type UserInvitationSent, type UsersClient, type UsersFound, type WebDeviceRegistration, availabilities, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, heldStatus, isApiError, listWire, maxStatusText, routedClient, sourceMeta, statusTextProblem, tokenExpiry };
35
+ export { type AccountSecurity, type AccountSignIn, type ActiveRole, type Aggregate, type AggregateGroup, type AggregateParams, type AggregateSplitTotal, ApiError, type AppUser, type AssistantClient, type AssistantClientOptions, type AssistantConnection, AuthError, type AuthSession, type AuthSessionOptions, type AuthUser, type AuthenticatorSetup, type Availability, type BatchOp, type BatchRef, type BatchResult, type CallRing, type Channel, type ChannelError, type ChannelMessage, ChannelRefusal, type ChannelStatus, type ChannelUser, type Client, type ClientOptions, type CommentPage, type CommentPerson, type ConnectClient, type ConnectedApp, type ConnectingClient, type CurrentOrganization, type DeviceSession, type DevicesClient, type Facet, type FilterInput, type FormChallenge, type FormProof, type Histogram, type HistogramBucket, type HistoryChange, type HistoryPage, type InboxNotification, type InboxPage, type InvitationPreview, type InvitationSent, type InvokeOptions, type ListPage, type ListParams, type LiveChange, type LiveHandlers, type LiveSocket, type MapBounds, type MapBucket, type MapLayerModel, type MapParams, type MapResult, type MentionableUser, type Meta, type MetaResult, type NotificationHistoryClient, type Organization, type OrganizationInvitation, type OrganizationMember, type OrganizationPerson, type OrganizationRole, type OrganizationsClient, type OrganizationsFound, type Passkey, type PersonStatus, type PersonalMailLink, type PlatformSignIn, type PluginRef, type PollThenSocketOptions, PreconditionFailedError, type PresenceChange, type PresenceEntry, type ProblemDetails, type ProblemError, type PublicForm, type RecordCall, type RecordCallsHandlers, type RecordComment, type RecordOf, type RecordPermissions, type RecordPhotos, type RegisteredDevice, type RelatedLabels, type RequiredSetup, type ResourcePermissions, type ResourceRef, type RingsClient, type RoleLabel, type RoleOption, type RolesClient, type RuntimeClient, type RuntimeClientOptions, type RuntimeLastUpdate, type RuntimePolicy, type RuntimeStatus, type RuntimeUpdateStage, type SamlSignIn, type Series, type SeriesParams, type SeriesPoint, type SetupStatus, type SignInMethod, type SignInPolicy, type SignInPolicyClient, type SignInPolicyState, type SignInResult, type SignInRule, type SocketLike, type SourceMeta, type SourceRef, type StaffAccessRule, type StaffSignIn, type StaffSignInClient, type StatusClient, type StatusInput, type Stored, type StoredFile, type StoredFileVariant, type TwoFactorMethod, type UploadOptions, type UploadProgress, type UploadResult, type UserInvitation, type UserInvitationSent, type UsersClient, type UsersFound, type WebDeviceRegistration, availabilities, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, heldStatus, isApiError, listWire, maxStatusText, pollThenSocket, routedClient, sourceMeta, statusTextProblem, tokenExpiry };
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import { fileUrl } from "./file-urls.js";
3
3
  import { ApiError, PreconditionFailedError, isApiError } from "./problem.js";
4
4
  import { ChannelRefusal } from "./channel-types.js";
5
5
  import { createClient } from "./client.js";
6
+ import { pollThenSocket } from "./poll-then-socket.js";
6
7
  import { routedClient } from "./routed-client.js";
7
8
  import { sourceMeta } from "./source-meta.js";
8
9
  import { AuthError } from "./auth-error.js";
@@ -11,4 +12,4 @@ import { createStaticSession } from "./static-session.js";
11
12
  import { createAssistantClient } from "./assistant.js";
12
13
  import { createRuntimeClient } from "./runtime.js";
13
14
  import { availabilities, heldStatus, maxStatusText, statusTextProblem } from "@protobase/schema/internal";
14
- export { ApiError, AuthError, ChannelRefusal, PreconditionFailedError, availabilities, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, heldStatus, isApiError, listWire, maxStatusText, routedClient, sourceMeta, statusTextProblem, tokenExpiry };
15
+ export { ApiError, AuthError, ChannelRefusal, PreconditionFailedError, availabilities, createAssistantClient, createAuthSession, createClient, createRuntimeClient, createStaticSession, fileUrl, filterText, heldStatus, isApiError, listWire, maxStatusText, pollThenSocket, routedClient, sourceMeta, statusTextProblem, tokenExpiry };
@@ -0,0 +1,32 @@
1
+ import { SocketLike } from "./channel-connection.js";
2
+ //#region src/poll-then-socket.d.ts
3
+ /** The part of a WebSocket `pollThenSocket` uses: the browser's and Node's global `WebSocket` both have it. */
4
+ export type LiveSocket = Pick<SocketLike, 'close' | 'onopen' | 'onmessage' | 'onclose'>;
5
+ export type PollThenSocketOptions = {
6
+ /**
7
+ * Reads what changed. Called at once, then `pollMs` after each read ends for as long as no socket is open, and once
8
+ * more as a socket opens, for what changed before it did. A read that rejects goes to `onError`, and the next read
9
+ * still comes.
10
+ */
11
+ poll: () => Promise<void>;
12
+ /** Each read's rejection: a read that failed, such as on a network error, which the caller reports or shows. */
13
+ onError: (error: unknown) => void;
14
+ /** Opens the WebSocket, such as `() => new WebSocket(url)`. */
15
+ socket: () => LiveSocket;
16
+ /** The data of each message the open socket receives. */
17
+ onMessage: (data: unknown) => void;
18
+ /** How long after a read ends the next one starts while it polls; 5 seconds by default. */
19
+ pollMs?: number;
20
+ /** How long it polls before it opens the socket, and before it tries again after the socket closed or failed to open; 30 seconds by default. */
21
+ switchAfterMs?: number;
22
+ /** Opens the socket at once instead of polling first. */
23
+ socketFirst?: boolean;
24
+ };
25
+ /**
26
+ * Keeps up with something that changes, until the returned function is called: it polls first, and opens a WebSocket
27
+ * after `switchAfterMs`, which takes over once it is open, so a short visit costs no socket. When the socket closes, or
28
+ * never opens, it polls again at once and tries the socket again `switchAfterMs` later. Polling goes on until a socket
29
+ * is open, so nothing waits on a socket still connecting.
30
+ */
31
+ export declare const pollThenSocket: ({ poll, onError, socket: openSocket, onMessage, pollMs, switchAfterMs, socketFirst }: PollThenSocketOptions) => () => void;
32
+ //#endregion
@@ -0,0 +1,72 @@
1
+ //#region src/poll-then-socket.ts
2
+ /**
3
+ * Keeps up with something that changes, until the returned function is called: it polls first, and opens a WebSocket
4
+ * after `switchAfterMs`, which takes over once it is open, so a short visit costs no socket. When the socket closes, or
5
+ * never opens, it polls again at once and tries the socket again `switchAfterMs` later. Polling goes on until a socket
6
+ * is open, so nothing waits on a socket still connecting.
7
+ */
8
+ const pollThenSocket = ({ poll, onError, socket: openSocket, onMessage, pollMs = 5e3, switchAfterMs = 3e4, socketFirst = false }) => {
9
+ let stopped = false;
10
+ let socket;
11
+ let socketOpen = false;
12
+ let reading = false;
13
+ let readAgain = false;
14
+ let pollTimer;
15
+ let switchTimer;
16
+ const read = () => {
17
+ clearTimeout(pollTimer);
18
+ pollTimer = void 0;
19
+ if (stopped) return;
20
+ if (reading) {
21
+ readAgain = true;
22
+ return;
23
+ }
24
+ reading = true;
25
+ poll().catch(onError).finally(() => {
26
+ reading = false;
27
+ if (stopped) return;
28
+ if (readAgain) {
29
+ readAgain = false;
30
+ read();
31
+ return;
32
+ }
33
+ if (!socketOpen) pollTimer = setTimeout(read, pollMs);
34
+ });
35
+ };
36
+ const connect = () => {
37
+ switchTimer = void 0;
38
+ if (stopped) return;
39
+ const current = openSocket();
40
+ socket = current;
41
+ current.onopen = () => {
42
+ if (socket !== current) return;
43
+ socketOpen = true;
44
+ read();
45
+ };
46
+ current.onmessage = (event) => {
47
+ if (socket === current) onMessage(event.data);
48
+ };
49
+ current.onclose = () => {
50
+ if (socket !== current) return;
51
+ socket = void 0;
52
+ socketOpen = false;
53
+ read();
54
+ switchTimer = setTimeout(connect, switchAfterMs);
55
+ };
56
+ };
57
+ if (socketFirst) connect();
58
+ else {
59
+ read();
60
+ switchTimer = setTimeout(connect, switchAfterMs);
61
+ }
62
+ return () => {
63
+ stopped = true;
64
+ clearTimeout(pollTimer);
65
+ clearTimeout(switchTimer);
66
+ const current = socket;
67
+ socket = void 0;
68
+ current?.close();
69
+ };
70
+ };
71
+ //#endregion
72
+ export { pollThenSocket };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@protobase/client",
3
- "version": "0.66.5",
3
+ "version": "0.66.7",
4
4
  "description": "Typed fetch client for the Protobase REST API.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@better-auth/passkey": "^1.7.12",
34
- "@protobase/layout": "0.66.5",
35
- "@protobase/schema": "0.66.5",
34
+ "@protobase/layout": "0.66.7",
35
+ "@protobase/schema": "0.66.7",
36
36
  "@simplewebauthn/browser": "^13.3.0",
37
37
  "better-auth": "^1.7.12"
38
38
  }