@rebasepro/client 0.34.2 → 0.35.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/admin.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Transport } from "./transport.js";
2
- import type { AdminGuest, AdminUser, DeleteGuestsResult, RoleSummary } from "@rebasepro/types";
2
+ import type { AdminGuest, AdminUser, DeleteGuestsResult, ImportUserInput, ImportUsersResult, RoleSummary } from "@rebasepro/types";
3
3
  export type { AdminUser };
4
4
  export interface CreateAdminOptions {
5
5
  adminPath?: string;
@@ -55,6 +55,9 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
55
55
  invitationSent?: boolean;
56
56
  emailDeliveryFailed?: boolean;
57
57
  }>;
58
+ importUsers: (users: ImportUserInput[], options?: {
59
+ dryRun?: boolean;
60
+ }) => Promise<ImportUsersResult>;
58
61
  updateUser: (userId: string, data: {
59
62
  email?: string;
60
63
  displayName?: string;
package/dist/index.d.ts CHANGED
@@ -7,6 +7,7 @@ import { createSchema } from "./schema.js";
7
7
  import { createApiKeys, CreateApiKeysOptions, createPersonalKeys, CreatePersonalKeysOptions } from "./api-keys.js";
8
8
  import { TableClient } from "./table.js";
9
9
  import { createFunctionsClient } from "./functions.js";
10
+ import { type RpcCall } from "./rpc.js";
10
11
  import { type PushClient } from "./push.js";
11
12
  import { RebaseWebSocketClient } from "./websocket.js";
12
13
  import { RebaseRealtimeChannel, type ChannelOptions } from "./realtime-channel.js";
@@ -37,6 +38,7 @@ export { SCHEMA_UNAVAILABLE, isSchemaUnavailable } from "./schema.js";
37
38
  export type { SchemaAPI, SchemaTablesOptions, TableDescriptor } from "@rebasepro/types";
38
39
  export type { ApiKeyKind, ApiKeyMasked, ApiKeyWithSecret, CreateApiKeyRequest, CreateApiKeysOptions, CreatePersonalKeyRequest, CreatePersonalKeysOptions, UpdateApiKeyRequest } from "./api-keys.js";
39
40
  export type { FunctionInvokeOptions, FunctionsClient } from "./functions.js";
41
+ export type { RpcCall } from "./rpc.js";
40
42
  export type { PushClient, PushSubscribeOptions, PushRegistrationOptions } from "./push.js";
41
43
  export { RebaseWebSocketClient } from "./websocket.js";
42
44
  export type { RealtimeDisconnectInfo, RealtimeDisconnectCause } from "./websocket.js";
@@ -179,6 +181,17 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
179
181
  apiKeys: ReturnType<typeof createApiKeys>;
180
182
  personalKeys: ReturnType<typeof createPersonalKeys>;
181
183
  functions: ReturnType<typeof createFunctionsClient>;
184
+ /**
185
+ * Call a SQL function the backend declares with `defineRpc` — `POST
186
+ * /rpc/<name>` with the named arguments — as the signed-in user, or
187
+ * anonymously. Resolves to the function's result: an array for a
188
+ * set-returning function, the row or the value for any other.
189
+ *
190
+ * ```ts
191
+ * const proposal = await client.rpc<Proposal | null>("get_public_proposal", { token });
192
+ * ```
193
+ */
194
+ rpc: RpcCall;
182
195
  /** Web Push from the browser: subscribe and unsubscribe through a service worker. Needs `push: true` on the backend. */
183
196
  push: PushClient;
184
197
  ws?: RebaseWebSocketClient;
package/dist/index.es.js CHANGED
@@ -155,7 +155,7 @@ function createMemoryStorage() {
155
155
  }
156
156
  function detectStorage() {
157
157
  try {
158
- if (typeof localStorage !== "undefined") {
158
+ if (typeof window !== "undefined" && typeof localStorage !== "undefined") {
159
159
  localStorage.setItem("__rebase_test__", "1");
160
160
  localStorage.removeItem("__rebase_test__");
161
161
  return localStorage;
@@ -1800,6 +1800,24 @@ function createAdmin(transport, options) {
1800
1800
  });
1801
1801
  }
1802
1802
  /**
1803
+ * Import accounts from another system, keeping their ids (`id`, often a
1804
+ * uuid) so the rows that point at them still do. No password, no email:
1805
+ * an imported account signs in by magic link, an email code, a provider or
1806
+ * a password reset. An account whose id or email is already taken is
1807
+ * `skipped`, never updated. At most `MAX_USERS_PER_IMPORT` (100) accounts
1808
+ * per call; `dryRun: true` checks them and writes nothing.
1809
+ */
1810
+ async function importUsers(users, options) {
1811
+ const body = {
1812
+ users,
1813
+ ...options?.dryRun ? { dryRun: true } : {}
1814
+ };
1815
+ return transport.request(adminPath + "/users/import", {
1816
+ method: "POST",
1817
+ body: JSON.stringify(body)
1818
+ });
1819
+ }
1820
+ /**
1803
1821
  * Change an account. `disabled: true` switches it off — no sign-in, no
1804
1822
  * refresh, and every token it holds refused at once — without deleting it.
1805
1823
  */
@@ -1860,6 +1878,7 @@ function createAdmin(transport, options) {
1860
1878
  listUsersPaginated,
1861
1879
  getUser,
1862
1880
  createUser,
1881
+ importUsers,
1863
1882
  updateUser,
1864
1883
  deleteUser,
1865
1884
  resetMfa,
@@ -2231,6 +2250,23 @@ function createFunctionsClient(transport) {
2231
2250
  } };
2232
2251
  }
2233
2252
  //#endregion
2253
+ //#region src/rpc.ts
2254
+ /** The SQL identifier an RPC name is. */
2255
+ var RPC_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
2256
+ /** @internal */
2257
+ function createRpcCall(transport) {
2258
+ return (name, args) => {
2259
+ if (!RPC_NAME.test(name)) throw new RebaseClientError$1(`Invalid RPC name "${name}": an RPC is named after its SQL function — letters, digits and _, not starting with a digit.`, {
2260
+ code: "INVALID_RPC_NAME",
2261
+ details: { name }
2262
+ });
2263
+ return transport.request(`/rpc/${name}`, {
2264
+ method: "POST",
2265
+ body: JSON.stringify(args ?? {})
2266
+ });
2267
+ };
2268
+ }
2269
+ //#endregion
2234
2270
  //#region src/push.ts
2235
2271
  /** A VAPID key, as base64url, in the form `PushManager.subscribe` takes. */
2236
2272
  function keyBytes(base64url) {
@@ -5335,7 +5371,7 @@ var LazyOfflineManager = class {
5335
5371
  keepsLastUser;
5336
5372
  constructor(config, createInner) {
5337
5373
  this.keepsLastUser = config.keepLastUser === true;
5338
- import("./offline-ET6xI1ZO.js").then(({ OfflineManager: Engine }) => {
5374
+ import("./offline-DSkf2JrL.js").then(({ OfflineManager: Engine }) => {
5339
5375
  const engine = new Engine(config, createInner);
5340
5376
  this.engine = engine;
5341
5377
  const queued = this.queued;
@@ -5533,6 +5569,7 @@ function createRebaseClient(options) {
5533
5569
  const personalKeys = createPersonalKeys(transport, options.personalKeys);
5534
5570
  const storage = createStorage(transport);
5535
5571
  const functions = createFunctionsClient(transport);
5572
+ const rpc = createRpcCall(transport);
5536
5573
  const push = createPushClient(transport);
5537
5574
  const createStorageSource = (storageId) => storageId === DEFAULT_STORAGE_SOURCE_KEY ? storage : createStorage(transport, storageId);
5538
5575
  const storageRegistry = new ClientStorageSourceRegistry();
@@ -5784,6 +5821,7 @@ function createRebaseClient(options) {
5784
5821
  apiKeys,
5785
5822
  personalKeys,
5786
5823
  functions,
5824
+ rpc,
5787
5825
  push,
5788
5826
  storage,
5789
5827
  storageRegistry,