@rebasepro/client 0.2.3 → 0.2.4
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 +0 -3
- package/dist/auth.d.ts +3 -1
- package/dist/index.d.ts +7 -5
- package/dist/index.es.js +13 -6
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +13 -6
- package/dist/index.umd.js.map +1 -1
- package/package.json +4 -4
- package/src/admin.ts +2 -3
- package/src/auth.ts +3 -1
- package/src/index.ts +13 -5
- package/src/transport.ts +17 -9
package/dist/admin.d.ts
CHANGED
|
@@ -14,7 +14,6 @@ export interface RebaseRole {
|
|
|
14
14
|
name: string;
|
|
15
15
|
isAdmin: boolean;
|
|
16
16
|
defaultPermissions: Record<string, unknown> | null;
|
|
17
|
-
config: Record<string, unknown> | null;
|
|
18
17
|
}
|
|
19
18
|
export interface CreateAdminOptions {
|
|
20
19
|
adminPath?: string;
|
|
@@ -68,7 +67,6 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
|
|
|
68
67
|
name: string;
|
|
69
68
|
isAdmin?: boolean;
|
|
70
69
|
defaultPermissions?: Record<string, unknown>;
|
|
71
|
-
config?: Record<string, unknown>;
|
|
72
70
|
}) => Promise<{
|
|
73
71
|
role: RebaseRole;
|
|
74
72
|
}>;
|
|
@@ -76,7 +74,6 @@ export declare function createAdmin(transport: Transport, options?: CreateAdminO
|
|
|
76
74
|
name?: string;
|
|
77
75
|
isAdmin?: boolean;
|
|
78
76
|
defaultPermissions?: Record<string, unknown>;
|
|
79
|
-
config?: Record<string, unknown>;
|
|
80
77
|
}) => Promise<{
|
|
81
78
|
role: RebaseRole;
|
|
82
79
|
}>;
|
package/dist/auth.d.ts
CHANGED
|
@@ -24,7 +24,9 @@ export type AuthChangeEvent = "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "
|
|
|
24
24
|
export interface AuthConfig {
|
|
25
25
|
needsSetup: boolean;
|
|
26
26
|
registrationEnabled: boolean;
|
|
27
|
-
emailServiceEnabled
|
|
27
|
+
emailServiceEnabled?: boolean;
|
|
28
|
+
passwordReset?: boolean;
|
|
29
|
+
emailVerification?: boolean;
|
|
28
30
|
enabledProviders: string[];
|
|
29
31
|
}
|
|
30
32
|
export interface AuthStorage {
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
|
21
21
|
}
|
|
22
22
|
import { RebaseWebSocketClient } from "./websocket";
|
|
23
23
|
import { RebaseClient as BaseRebaseClient, RebaseData, StorageSource } from "@rebasepro/types";
|
|
24
|
-
export type
|
|
24
|
+
export type { Entity, FindResponse } from "@rebasepro/types";
|
|
25
|
+
type KebabToCamelCase<S extends string> = S extends `${infer T}-${infer U}` ? `${T}${Capitalize<KebabToCamelCase<U>>}` : S;
|
|
26
|
+
export type RebaseClient<DB = Record<string, unknown>> = Omit<BaseRebaseClient<DB>, "data"> & {
|
|
25
27
|
setToken: (token: string | null) => void;
|
|
26
28
|
setAuthTokenGetter: (getter: () => Promise<string | null>) => void;
|
|
27
29
|
setOnUnauthorized: (handler: () => Promise<boolean>) => void;
|
|
@@ -33,14 +35,14 @@ export type RebaseClient<DB = Record<string, unknown>> = BaseRebaseClient<DB> &
|
|
|
33
35
|
ws?: RebaseWebSocketClient;
|
|
34
36
|
storage?: StorageSource;
|
|
35
37
|
call: <T = unknown>(endpoint: string, payload?: unknown) => Promise<T>;
|
|
36
|
-
data:
|
|
37
|
-
collection<
|
|
38
|
+
data: {
|
|
39
|
+
collection<S extends string>(slug: S): CollectionClient<KebabToCamelCase<S> extends keyof DB ? (DB[KebabToCamelCase<S>] extends {
|
|
38
40
|
Row: infer R extends Record<string, unknown>;
|
|
39
|
-
} ? R : Record<string, unknown>>;
|
|
41
|
+
} ? R : Record<string, unknown>) : Record<string, unknown>>;
|
|
40
42
|
} & {
|
|
41
43
|
[K in keyof DB]: CollectionClient<DB[K] extends {
|
|
42
44
|
Row: infer R extends Record<string, unknown>;
|
|
43
45
|
} ? R : Record<string, unknown>>;
|
|
44
|
-
};
|
|
46
|
+
} & RebaseData;
|
|
45
47
|
};
|
|
46
48
|
export declare function createRebaseClient<DB = Record<string, unknown>>(options: CreateRebaseClientOptions): RebaseClient<DB>;
|
package/dist/index.es.js
CHANGED
|
@@ -141,6 +141,13 @@ function createTransport(config) {
|
|
|
141
141
|
} catch (e) {
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
const getErrorField = (obj, field) => {
|
|
145
|
+
const err = obj?.error;
|
|
146
|
+
if (err && typeof err === "object" && err !== null && field in err) {
|
|
147
|
+
return err[field];
|
|
148
|
+
}
|
|
149
|
+
return obj?.[field];
|
|
150
|
+
};
|
|
144
151
|
if (res.status === 401 && onUnauthorizedHandler) {
|
|
145
152
|
const retried = await onUnauthorizedHandler();
|
|
146
153
|
if (retried) {
|
|
@@ -176,9 +183,9 @@ function createTransport(config) {
|
|
|
176
183
|
}
|
|
177
184
|
throw new RebaseApiError(
|
|
178
185
|
retryRes.status,
|
|
179
|
-
retryBody
|
|
180
|
-
retryBody
|
|
181
|
-
retryBody
|
|
186
|
+
String(getErrorField(retryBody, "message") || fallbackMessage || `Request failed with status ${retryRes.status}`),
|
|
187
|
+
getErrorField(retryBody, "code"),
|
|
188
|
+
getErrorField(retryBody, "details")
|
|
182
189
|
);
|
|
183
190
|
}
|
|
184
191
|
return retryBody;
|
|
@@ -192,9 +199,9 @@ function createTransport(config) {
|
|
|
192
199
|
}
|
|
193
200
|
throw new RebaseApiError(
|
|
194
201
|
res.status,
|
|
195
|
-
body
|
|
196
|
-
body
|
|
197
|
-
body
|
|
202
|
+
String(getErrorField(body, "message") || fallbackMessage || `Request failed with status ${res.status}`),
|
|
203
|
+
getErrorField(body, "code"),
|
|
204
|
+
getErrorField(body, "details")
|
|
198
205
|
);
|
|
199
206
|
}
|
|
200
207
|
return body;
|