@rebasepro/client 0.0.1-canary.4d4fb3e
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/LICENSE +6 -0
- package/dist/admin.d.ts +94 -0
- package/dist/auth.d.ts +95 -0
- package/dist/collection.d.ts +19 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.es.js +1882 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +1886 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/query_builder.d.ts +53 -0
- package/dist/storage.d.ts +3 -0
- package/dist/transport.d.ts +33 -0
- package/dist/websocket.d.ts +93 -0
- package/package.json +79 -0
- package/src/admin.ts +119 -0
- package/src/auth.ts +400 -0
- package/src/collection.ts +198 -0
- package/src/index.ts +154 -0
- package/src/query_builder.ts +126 -0
- package/src/storage.ts +181 -0
- package/src/transport.ts +173 -0
- package/src/websocket.ts +1114 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Source code in this repository is variously licensed under the Business Source
|
|
2
|
+
License 1.1 (BSL), Apache version 2.0 and the MIT license. A copy of each
|
|
3
|
+
license can be found in each one of the packages under the folder packages
|
|
4
|
+
under a file called License. Source code in a given file is licensed under the
|
|
5
|
+
BSL and the copyright belongs to Rebase Authors unless otherwise noted at the
|
|
6
|
+
beginning of the file.
|
package/dist/admin.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Transport } from "./transport";
|
|
2
|
+
export interface AdminUser {
|
|
3
|
+
uid: string;
|
|
4
|
+
email: string;
|
|
5
|
+
displayName: string | null;
|
|
6
|
+
photoURL: string | null;
|
|
7
|
+
provider: string;
|
|
8
|
+
roles: string[];
|
|
9
|
+
createdAt: string;
|
|
10
|
+
updatedAt: string;
|
|
11
|
+
}
|
|
12
|
+
export interface RebaseRole {
|
|
13
|
+
id: string;
|
|
14
|
+
name: string;
|
|
15
|
+
isAdmin: boolean;
|
|
16
|
+
defaultPermissions: Record<string, any> | null;
|
|
17
|
+
config: Record<string, any> | null;
|
|
18
|
+
}
|
|
19
|
+
export interface CreateAdminOptions {
|
|
20
|
+
adminPath?: string;
|
|
21
|
+
}
|
|
22
|
+
export declare function createAdmin(transport: Transport, options?: CreateAdminOptions): {
|
|
23
|
+
listUsers: () => Promise<{
|
|
24
|
+
users: AdminUser[];
|
|
25
|
+
}>;
|
|
26
|
+
listUsersPaginated: (options?: {
|
|
27
|
+
search?: string;
|
|
28
|
+
limit?: number;
|
|
29
|
+
offset?: number;
|
|
30
|
+
orderBy?: string;
|
|
31
|
+
orderDir?: "asc" | "desc";
|
|
32
|
+
}) => Promise<{
|
|
33
|
+
users: AdminUser[];
|
|
34
|
+
total: number;
|
|
35
|
+
limit: number;
|
|
36
|
+
offset: number;
|
|
37
|
+
}>;
|
|
38
|
+
getUser: (userId: string) => Promise<{
|
|
39
|
+
user: AdminUser;
|
|
40
|
+
}>;
|
|
41
|
+
createUser: (data: {
|
|
42
|
+
email: string;
|
|
43
|
+
displayName?: string;
|
|
44
|
+
password?: string;
|
|
45
|
+
roles?: string[];
|
|
46
|
+
}) => Promise<{
|
|
47
|
+
user: AdminUser;
|
|
48
|
+
}>;
|
|
49
|
+
updateUser: (userId: string, data: {
|
|
50
|
+
email?: string;
|
|
51
|
+
displayName?: string;
|
|
52
|
+
password?: string;
|
|
53
|
+
roles?: string[];
|
|
54
|
+
}) => Promise<{
|
|
55
|
+
user: AdminUser;
|
|
56
|
+
}>;
|
|
57
|
+
deleteUser: (userId: string) => Promise<{
|
|
58
|
+
success: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
listRoles: () => Promise<{
|
|
61
|
+
roles: RebaseRole[];
|
|
62
|
+
}>;
|
|
63
|
+
getRole: (roleId: string) => Promise<{
|
|
64
|
+
role: RebaseRole;
|
|
65
|
+
}>;
|
|
66
|
+
createRole: (data: {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
isAdmin?: boolean;
|
|
70
|
+
defaultPermissions?: any;
|
|
71
|
+
config?: any;
|
|
72
|
+
}) => Promise<{
|
|
73
|
+
role: RebaseRole;
|
|
74
|
+
}>;
|
|
75
|
+
updateRole: (roleId: string, data: {
|
|
76
|
+
name?: string;
|
|
77
|
+
isAdmin?: boolean;
|
|
78
|
+
defaultPermissions?: any;
|
|
79
|
+
config?: any;
|
|
80
|
+
}) => Promise<{
|
|
81
|
+
role: RebaseRole;
|
|
82
|
+
}>;
|
|
83
|
+
deleteRole: (roleId: string) => Promise<{
|
|
84
|
+
success: boolean;
|
|
85
|
+
}>;
|
|
86
|
+
bootstrap: () => Promise<{
|
|
87
|
+
success: boolean;
|
|
88
|
+
message: string;
|
|
89
|
+
user: {
|
|
90
|
+
uid: string;
|
|
91
|
+
roles: string[];
|
|
92
|
+
};
|
|
93
|
+
}>;
|
|
94
|
+
};
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { Transport } from "./transport";
|
|
2
|
+
export interface RebaseUser {
|
|
3
|
+
uid: string;
|
|
4
|
+
email: string | null;
|
|
5
|
+
displayName: string | null;
|
|
6
|
+
photoURL: string | null;
|
|
7
|
+
emailVerified?: boolean;
|
|
8
|
+
roles?: string[];
|
|
9
|
+
providerId: string;
|
|
10
|
+
isAnonymous: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface RebaseTokens {
|
|
13
|
+
accessToken: string;
|
|
14
|
+
refreshToken: string;
|
|
15
|
+
accessTokenExpiresAt: number;
|
|
16
|
+
}
|
|
17
|
+
export interface RebaseSession {
|
|
18
|
+
accessToken: string;
|
|
19
|
+
refreshToken: string;
|
|
20
|
+
expiresAt: number;
|
|
21
|
+
user: RebaseUser;
|
|
22
|
+
}
|
|
23
|
+
export type AuthChangeEvent = 'SIGNED_IN' | 'SIGNED_OUT' | 'TOKEN_REFRESHED' | 'USER_UPDATED';
|
|
24
|
+
export interface AuthConfig {
|
|
25
|
+
needsSetup: boolean;
|
|
26
|
+
registrationEnabled: boolean;
|
|
27
|
+
googleEnabled: boolean;
|
|
28
|
+
emailServiceEnabled: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface AuthStorage {
|
|
31
|
+
getItem: (key: string) => string | null;
|
|
32
|
+
setItem: (key: string, value: string) => void;
|
|
33
|
+
removeItem: (key: string) => void;
|
|
34
|
+
}
|
|
35
|
+
export declare function createMemoryStorage(): AuthStorage;
|
|
36
|
+
export interface CreateAuthOptions {
|
|
37
|
+
storage?: AuthStorage;
|
|
38
|
+
authPath?: string;
|
|
39
|
+
autoRefresh?: boolean;
|
|
40
|
+
persistSession?: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare function createAuth(transport: Transport, options?: CreateAuthOptions): {
|
|
43
|
+
signInWithEmail: (email: string, password: string) => Promise<{
|
|
44
|
+
user: RebaseUser;
|
|
45
|
+
accessToken: string;
|
|
46
|
+
refreshToken: string;
|
|
47
|
+
}>;
|
|
48
|
+
signUp: (email: string, password: string, displayName?: string) => Promise<{
|
|
49
|
+
user: RebaseUser;
|
|
50
|
+
accessToken: string;
|
|
51
|
+
refreshToken: string;
|
|
52
|
+
}>;
|
|
53
|
+
signInWithGoogle: (idToken: string) => Promise<{
|
|
54
|
+
user: RebaseUser;
|
|
55
|
+
accessToken: string;
|
|
56
|
+
refreshToken: string;
|
|
57
|
+
}>;
|
|
58
|
+
signOut: () => Promise<void>;
|
|
59
|
+
refreshSession: () => Promise<RebaseSession>;
|
|
60
|
+
getUser: () => Promise<RebaseUser>;
|
|
61
|
+
updateUser: (updates: {
|
|
62
|
+
displayName?: string;
|
|
63
|
+
photoURL?: string;
|
|
64
|
+
}) => Promise<RebaseUser>;
|
|
65
|
+
resetPasswordForEmail: (email: string) => Promise<{
|
|
66
|
+
success: boolean;
|
|
67
|
+
message: string;
|
|
68
|
+
}>;
|
|
69
|
+
resetPassword: (token: string, password: string) => Promise<{
|
|
70
|
+
success: boolean;
|
|
71
|
+
message: string;
|
|
72
|
+
}>;
|
|
73
|
+
changePassword: (oldPassword: string, newPassword: string) => Promise<{
|
|
74
|
+
success: boolean;
|
|
75
|
+
message: string;
|
|
76
|
+
}>;
|
|
77
|
+
sendVerificationEmail: () => Promise<{
|
|
78
|
+
success: boolean;
|
|
79
|
+
message: string;
|
|
80
|
+
}>;
|
|
81
|
+
verifyEmail: (token: string) => Promise<{
|
|
82
|
+
success: boolean;
|
|
83
|
+
message: string;
|
|
84
|
+
}>;
|
|
85
|
+
getSessions: () => Promise<Record<string, unknown>[]>;
|
|
86
|
+
revokeSession: (sessionId: string) => Promise<{
|
|
87
|
+
success: boolean;
|
|
88
|
+
}>;
|
|
89
|
+
revokeAllSessions: () => Promise<{
|
|
90
|
+
success: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
getAuthConfig: () => Promise<AuthConfig>;
|
|
93
|
+
getSession: () => RebaseSession | null;
|
|
94
|
+
onAuthStateChange: (callback: (event: AuthChangeEvent, session: RebaseSession | null) => void) => () => boolean;
|
|
95
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Transport } from "./transport";
|
|
2
|
+
import { RebaseWebSocketClient } from "./websocket";
|
|
3
|
+
import { CollectionAccessor } from "@rebasepro/types";
|
|
4
|
+
import { FilterOperator, QueryBuilder } from "./query_builder";
|
|
5
|
+
/**
|
|
6
|
+
* CollectionClient extends `CollectionAccessor` from `@rebasepro/types` so that
|
|
7
|
+
* `client.data` can be passed directly to the core Rebase component.
|
|
8
|
+
*
|
|
9
|
+
* Additionally it exposes fluent query builder methods like `.where()`, `.orderBy()`.
|
|
10
|
+
*/
|
|
11
|
+
export interface CollectionClient<M extends Record<string, any> = any> extends CollectionAccessor<M> {
|
|
12
|
+
where(column: keyof M & string, operator: FilterOperator, value: any): QueryBuilder<M>;
|
|
13
|
+
orderBy(column: keyof M & string, ascending?: "asc" | "desc"): QueryBuilder<M>;
|
|
14
|
+
limit(count: number): QueryBuilder<M>;
|
|
15
|
+
offset(count: number): QueryBuilder<M>;
|
|
16
|
+
search(searchString: string): QueryBuilder<M>;
|
|
17
|
+
include(...relations: string[]): QueryBuilder<M>;
|
|
18
|
+
}
|
|
19
|
+
export declare function createCollectionClient<M extends Record<string, any> = any>(transport: Transport, slug: string, ws?: RebaseWebSocketClient): CollectionClient<M>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { RebaseClientConfig } from "./transport";
|
|
2
|
+
import { createAuth, CreateAuthOptions } from "./auth";
|
|
3
|
+
import { createAdmin, CreateAdminOptions } from "./admin";
|
|
4
|
+
import { CollectionClient } from "./collection";
|
|
5
|
+
export * from "./transport";
|
|
6
|
+
export * from "./auth";
|
|
7
|
+
export * from "./admin";
|
|
8
|
+
export * from "./collection";
|
|
9
|
+
export * from "./websocket";
|
|
10
|
+
export * from "./storage";
|
|
11
|
+
export interface CreateRebaseClientOptions extends RebaseClientConfig {
|
|
12
|
+
auth?: CreateAuthOptions;
|
|
13
|
+
admin?: CreateAdminOptions;
|
|
14
|
+
}
|
|
15
|
+
import { RebaseWebSocketClient } from "./websocket";
|
|
16
|
+
import { RebaseClient as BaseRebaseClient, RebaseData, StorageSource } from "@rebasepro/types";
|
|
17
|
+
export type RebaseClient<DB = any> = BaseRebaseClient<DB> & {
|
|
18
|
+
setToken: (token: string | null) => void;
|
|
19
|
+
setAuthTokenGetter: (getter: () => Promise<string | null>) => void;
|
|
20
|
+
setOnUnauthorized: (handler: () => Promise<boolean>) => void;
|
|
21
|
+
resolveToken: () => Promise<string | null>;
|
|
22
|
+
auth: ReturnType<typeof createAuth>;
|
|
23
|
+
admin: ReturnType<typeof createAdmin>;
|
|
24
|
+
ws?: RebaseWebSocketClient;
|
|
25
|
+
storage?: StorageSource;
|
|
26
|
+
call: <T = any>(endpoint: string, payload?: any) => Promise<T>;
|
|
27
|
+
data: RebaseData & {
|
|
28
|
+
collection<K extends keyof DB>(slug: Extract<K, string>): CollectionClient<DB[K] extends {
|
|
29
|
+
Row: infer R extends Record<string, any>;
|
|
30
|
+
} ? R : any>;
|
|
31
|
+
} & {
|
|
32
|
+
[K in keyof DB]: CollectionClient<DB[K] extends {
|
|
33
|
+
Row: infer R extends Record<string, any>;
|
|
34
|
+
} ? R : any>;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export declare function createRebaseClient<DB = any>(options: CreateRebaseClientOptions): RebaseClient<DB>;
|