@rebasepro/client 0.6.1 → 0.7.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
@@ -42,6 +42,19 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
42
42
  deleteUser: (userId: string) => Promise<{
43
43
  success: boolean;
44
44
  }>;
45
+ resetPassword: (userId: string, options?: {
46
+ password?: string;
47
+ }) => Promise<{
48
+ user: AdminUser;
49
+ temporaryPassword?: string;
50
+ invitationSent?: boolean;
51
+ }>;
52
+ listRoles: () => Promise<{
53
+ roles: Array<{
54
+ id: string;
55
+ name: string;
56
+ }>;
57
+ }>;
45
58
  bootstrap: () => Promise<{
46
59
  success: boolean;
47
60
  message: string;
@@ -0,0 +1,65 @@
1
+ import type { Transport } from "./transport";
2
+ /** A single permission entry scoping an API key to a collection and its allowed operations. */
3
+ export interface ApiKeyPermission {
4
+ collection: string;
5
+ operations: ("read" | "write" | "delete")[];
6
+ }
7
+ /** An API key with the secret portion masked (returned by list / get / update). */
8
+ export interface ApiKeyMasked {
9
+ id: string;
10
+ name: string;
11
+ key_prefix: string;
12
+ permissions: ApiKeyPermission[];
13
+ rate_limit: number | null;
14
+ created_by: string;
15
+ created_at: string;
16
+ updated_at: string;
17
+ last_used_at: string | null;
18
+ expires_at: string | null;
19
+ revoked_at: string | null;
20
+ }
21
+ /** An API key including the full secret (returned only on creation). */
22
+ export interface ApiKeyWithSecret extends ApiKeyMasked {
23
+ key: string;
24
+ }
25
+ /** Payload for creating a new API key. */
26
+ export interface CreateApiKeyRequest {
27
+ name: string;
28
+ permissions: ApiKeyPermission[];
29
+ rate_limit?: number | null;
30
+ expires_at?: string | null;
31
+ }
32
+ /** Payload for updating an existing API key. */
33
+ export interface UpdateApiKeyRequest {
34
+ name?: string;
35
+ permissions?: ApiKeyPermission[];
36
+ rate_limit?: number | null;
37
+ expires_at?: string | null;
38
+ }
39
+ /** Options for the `createApiKeys` factory. */
40
+ export interface CreateApiKeysOptions {
41
+ apiKeysPath?: string;
42
+ }
43
+ /**
44
+ * Creates a client for managing API keys via the admin routes.
45
+ *
46
+ * @param transport - The shared HTTP transport created by `createTransport`.
47
+ * @param options - Optional overrides (e.g. a custom base path).
48
+ */
49
+ export declare function createApiKeys(transport: Transport, options?: CreateApiKeysOptions): {
50
+ listKeys: () => Promise<{
51
+ keys: ApiKeyMasked[];
52
+ }>;
53
+ getKey: (id: string) => Promise<{
54
+ key: ApiKeyMasked;
55
+ }>;
56
+ createKey: (data: CreateApiKeyRequest) => Promise<{
57
+ key: ApiKeyWithSecret;
58
+ }>;
59
+ updateKey: (id: string, data: UpdateApiKeyRequest) => Promise<{
60
+ key: ApiKeyMasked;
61
+ }>;
62
+ revokeKey: (id: string) => Promise<{
63
+ success: boolean;
64
+ }>;
65
+ };
package/dist/auth.d.ts CHANGED
@@ -28,6 +28,7 @@ export interface AuthConfig {
28
28
  emailServiceEnabled?: boolean;
29
29
  passwordReset?: boolean;
30
30
  emailVerification?: boolean;
31
+ magicLink?: boolean;
31
32
  enabledProviders: string[];
32
33
  }
33
34
  export interface AuthStorage {
@@ -158,6 +159,15 @@ export declare function createAuth(transport: Transport, options?: CreateAuthOpt
158
159
  success: boolean;
159
160
  message: string;
160
161
  }>;
162
+ sendMagicLink: (email: string) => Promise<{
163
+ success: boolean;
164
+ message: string;
165
+ }>;
166
+ verifyMagicLink: (token: string) => Promise<{
167
+ user: RebaseUser;
168
+ accessToken: string;
169
+ refreshToken: string;
170
+ }>;
161
171
  getSessions: () => Promise<Record<string, unknown>[]>;
162
172
  revokeSession: (sessionId: string) => Promise<{
163
173
  success: boolean;
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import { RebaseClientConfig } from "./transport";
2
2
  import { createAuth, CreateAuthOptions } from "./auth";
3
3
  import { createAdmin, CreateAdminOptions } from "./admin";
4
4
  import { createCron, CreateCronOptions } from "./cron";
5
+ import { createApiKeys, CreateApiKeysOptions } from "./api-keys";
5
6
  import { CollectionClient } from "./collection";
6
7
  import { createFunctionsClient } from "./functions";
7
8
  import { RebaseWebSocketClient } from "./websocket";
@@ -10,6 +11,7 @@ export * from "./transport";
10
11
  export * from "./auth";
11
12
  export * from "./admin";
12
13
  export * from "./cron";
14
+ export * from "./api-keys";
13
15
  export * from "./collection";
14
16
  export * from "./query_builder";
15
17
  export * from "./websocket";
@@ -21,6 +23,7 @@ export interface CreateRebaseClientOptions extends RebaseClientConfig {
21
23
  auth?: CreateAuthOptions;
22
24
  admin?: CreateAdminOptions;
23
25
  cron?: CreateCronOptions;
26
+ apiKeys?: CreateApiKeysOptions;
24
27
  }
25
28
  type KebabToCamelCase<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamelCase<U>>}` : S;
26
29
  type TypedDataLayer<DB> = {
@@ -47,6 +50,7 @@ export type CreateRebaseClientResult<DB = Record<string, unknown>> = Omit<Rebase
47
50
  auth: ReturnType<typeof createAuth>;
48
51
  admin: ReturnType<typeof createAdmin>;
49
52
  cron: ReturnType<typeof createCron>;
53
+ apiKeys: ReturnType<typeof createApiKeys>;
50
54
  functions: ReturnType<typeof createFunctionsClient>;
51
55
  ws?: RebaseWebSocketClient;
52
56
  storage: StorageSource;
package/dist/index.es.js CHANGED
@@ -583,6 +583,31 @@ function createAuth(transport, options) {
583
583
  if (!res.ok) throwApiError(res.status, body, res.statusText);
584
584
  return body;
585
585
  }
586
+ async function sendMagicLink(email) {
587
+ const res = await getFetch()(authUrl("/magic-link"), {
588
+ method: "POST",
589
+ headers: { "Content-Type": "application/json" },
590
+ body: JSON.stringify({ email })
591
+ });
592
+ const body = await res.json().catch(() => ({}));
593
+ if (!res.ok) throwApiError(res.status, body, res.statusText);
594
+ return body;
595
+ }
596
+ async function verifyMagicLink(token) {
597
+ const res = await getFetch()(authUrl("/magic-link/verify"), {
598
+ method: "POST",
599
+ headers: { "Content-Type": "application/json" },
600
+ body: JSON.stringify({ token })
601
+ });
602
+ const body = await res.json().catch(() => ({}));
603
+ if (!res.ok) throwApiError(res.status, body, res.statusText);
604
+ const session = handleAuthResponse(body, "SIGNED_IN");
605
+ return {
606
+ user: session.user,
607
+ accessToken: session.accessToken,
608
+ refreshToken: session.refreshToken
609
+ };
610
+ }
586
611
  async function getSessions() {
587
612
  return (await transport.request(authPath + "/sessions", { method: "GET" })).sessions;
588
613
  }
@@ -659,6 +684,8 @@ function createAuth(transport, options) {
659
684
  changePassword,
660
685
  sendVerificationEmail,
661
686
  verifyEmail,
687
+ sendMagicLink,
688
+ verifyMagicLink,
662
689
  getSessions,
663
690
  revokeSession,
664
691
  revokeAllSessions,
@@ -739,6 +766,15 @@ function createAdmin(transport, options) {
739
766
  async function deleteUser(userId) {
740
767
  return transport.request(adminPath + "/users/" + encodeURIComponent(userId), { method: "DELETE" });
741
768
  }
769
+ async function resetPassword(userId, options) {
770
+ return transport.request(adminPath + "/users/" + encodeURIComponent(userId) + "/reset-password", {
771
+ method: "POST",
772
+ ...options?.password ? { body: JSON.stringify({ password: options.password }) } : {}
773
+ });
774
+ }
775
+ async function listRoles() {
776
+ return transport.request(adminPath + "/roles", { method: "GET" });
777
+ }
742
778
  async function bootstrap() {
743
779
  return transport.request(adminPath + "/bootstrap", { method: "POST" });
744
780
  }
@@ -749,6 +785,8 @@ function createAdmin(transport, options) {
749
785
  createUser,
750
786
  updateUser,
751
787
  deleteUser,
788
+ resetPassword,
789
+ listRoles,
752
790
  bootstrap
753
791
  };
754
792
  }
@@ -786,6 +824,50 @@ function createCron(transport, options) {
786
824
  };
787
825
  }
788
826
  //#endregion
827
+ //#region src/api-keys.ts
828
+ /**
829
+ * Creates a client for managing API keys via the admin routes.
830
+ *
831
+ * @param transport - The shared HTTP transport created by `createTransport`.
832
+ * @param options - Optional overrides (e.g. a custom base path).
833
+ */
834
+ function createApiKeys(transport, options) {
835
+ const apiKeysPath = options?.apiKeysPath || "/admin/api-keys";
836
+ /** List all API keys (masked). */
837
+ async function listKeys() {
838
+ return transport.request(apiKeysPath, { method: "GET" });
839
+ }
840
+ /** Get a single API key by ID (masked). */
841
+ async function getKey(id) {
842
+ return transport.request(apiKeysPath + "/" + encodeURIComponent(id), { method: "GET" });
843
+ }
844
+ /** Create a new API key. The full secret is included in the response. */
845
+ async function createKey(data) {
846
+ return transport.request(apiKeysPath, {
847
+ method: "POST",
848
+ body: JSON.stringify(data)
849
+ });
850
+ }
851
+ /** Update an existing API key. */
852
+ async function updateKey(id, data) {
853
+ return transport.request(apiKeysPath + "/" + encodeURIComponent(id), {
854
+ method: "PUT",
855
+ body: JSON.stringify(data)
856
+ });
857
+ }
858
+ /** Revoke (soft-delete) an API key. */
859
+ async function revokeKey(id) {
860
+ return transport.request(apiKeysPath + "/" + encodeURIComponent(id), { method: "DELETE" });
861
+ }
862
+ return {
863
+ listKeys,
864
+ getKey,
865
+ createKey,
866
+ updateKey,
867
+ revokeKey
868
+ };
869
+ }
870
+ //#endregion
789
871
  //#region src/collection.ts
790
872
  function parseWhereFilter(where) {
791
873
  if (!where) return void 0;
@@ -2037,6 +2119,7 @@ function createRebaseClient(options) {
2037
2119
  const auth = createAuth(transport, options.auth);
2038
2120
  const admin = createAdmin(transport, options.admin);
2039
2121
  const cron = createCron(transport, options.cron);
2122
+ const apiKeys = createApiKeys(transport, options.apiKeys);
2040
2123
  const storage = createStorage(transport);
2041
2124
  const functions = createFunctionsClient(transport);
2042
2125
  const resolvedWsUrl = options.websocketUrl ?? deriveWebSocketUrl(options.baseUrl);
@@ -2090,6 +2173,7 @@ function createRebaseClient(options) {
2090
2173
  auth,
2091
2174
  admin,
2092
2175
  cron,
2176
+ apiKeys,
2093
2177
  functions,
2094
2178
  storage,
2095
2179
  ws,
@@ -2112,6 +2196,6 @@ function createRebaseClient(options) {
2112
2196
  };
2113
2197
  }
2114
2198
  //#endregion
2115
- export { ApiError, QueryBuilder, RebaseApiError, RebaseWebSocketClient, and, buildQueryString, cond, createAdmin, createAuth, createCollectionClient, createCookieStorage, createCron, createFunctionsClient, createMemoryStorage, createRebaseClient, createStorage, createTransport, or, rebaseReviver };
2199
+ export { ApiError, QueryBuilder, RebaseApiError, RebaseWebSocketClient, and, buildQueryString, cond, createAdmin, createApiKeys, createAuth, createCollectionClient, createCookieStorage, createCron, createFunctionsClient, createMemoryStorage, createRebaseClient, createStorage, createTransport, or, rebaseReviver };
2116
2200
 
2117
2201
  //# sourceMappingURL=index.es.js.map