@rebasepro/client 0.0.1-canary.09e5ec5

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/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@rebasepro/client",
3
+ "type": "module",
4
+ "version": "0.0.1-canary.09e5ec5",
5
+ "description": "HTTP SDK client for the Rebase custom backend",
6
+ "funding": {
7
+ "url": "https://github.com/sponsors/rebaseco"
8
+ },
9
+ "author": "Rebase",
10
+ "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/rebasepro/rebase.git",
14
+ "directory": "packages/client"
15
+ },
16
+ "main": "./dist/index.umd.cjs",
17
+ "module": "./dist/index.es.js",
18
+ "types": "./dist/index.d.ts",
19
+ "source": "src/index.ts",
20
+ "engines": {
21
+ "node": ">=14"
22
+ },
23
+ "exports": {
24
+ ".": {
25
+ "types": "./dist/index.d.ts",
26
+ "development": "./src/index.ts",
27
+ "import": "./dist/index.es.js",
28
+ "require": "./dist/index.umd.cjs"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "dependencies": {
33
+ "@rebasepro/utils": "0.0.1-canary.09e5ec5",
34
+ "@rebasepro/types": "0.0.1-canary.09e5ec5"
35
+ },
36
+ "devDependencies": {
37
+ "@jest/globals": "^29.7.0",
38
+ "@types/jest": "^29.5.14",
39
+ "@types/node": "^20.17.14",
40
+ "cross-env": "^7.0.3",
41
+ "jest": "^29.7.0",
42
+ "npm-run-all": "^4.1.5",
43
+ "ts-jest": "^29.3.1",
44
+ "ts-node": "^10.9.2",
45
+ "tsd": "^0.31.2",
46
+ "typescript": "^5.8.3",
47
+ "vite": "^5.4.17"
48
+ },
49
+ "files": [
50
+ "dist",
51
+ "src"
52
+ ],
53
+ "gitHead": "d935eefa5aa8d1009a2398cfac2c1e4ee9aeb6b6",
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "jest": {
58
+ "transform": {
59
+ "^.+\\.tsx?$": "ts-jest"
60
+ },
61
+ "testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$",
62
+ "moduleFileExtensions": [
63
+ "ts",
64
+ "tsx",
65
+ "js",
66
+ "jsx",
67
+ "json",
68
+ "node"
69
+ ],
70
+ "testEnvironment": "node",
71
+ "moduleNameMapper": {
72
+ "^@rebasepro/types$": "<rootDir>/../types/src/index.ts",
73
+ "^@rebasepro/utils$": "<rootDir>/../utils/src/index.ts"
74
+ }
75
+ },
76
+ "scripts": {
77
+ "watch": "vite build --watch",
78
+ "build": "vite build && tsc --emitDeclarationOnly -p tsconfig.prod.json",
79
+ "test:lint": "eslint \"src/**\" --quiet",
80
+ "test": "jest --passWithNoTests --forceExit",
81
+ "clean": "rm -rf dist && find ./src -name '*.js' -type f | xargs rm -f"
82
+ }
83
+ }
package/src/admin.ts ADDED
@@ -0,0 +1,119 @@
1
+ import { Transport } from "./transport";
2
+
3
+ export interface AdminUser {
4
+ uid: string;
5
+ email: string;
6
+ displayName: string | null;
7
+ photoURL: string | null;
8
+ provider: string;
9
+ roles: string[];
10
+ createdAt: string;
11
+ updatedAt: string;
12
+ }
13
+
14
+ export interface RebaseRole {
15
+ id: string;
16
+ name: string;
17
+ isAdmin: boolean;
18
+ defaultPermissions: Record<string, unknown> | null;
19
+ config: Record<string, unknown> | null;
20
+ }
21
+
22
+ export interface CreateAdminOptions {
23
+ adminPath?: string;
24
+ }
25
+
26
+ export function createAdmin(transport: Transport, options?: CreateAdminOptions) {
27
+ const opts = options || {};
28
+ const adminPath = opts.adminPath || "/admin";
29
+
30
+ async function listUsers() {
31
+ return transport.request<{ users: AdminUser[] }>(adminPath + "/users", { method: "GET" });
32
+ }
33
+
34
+ async function listUsersPaginated(options?: { search?: string; limit?: number; offset?: number; orderBy?: string; orderDir?: "asc" | "desc" }) {
35
+ const params = new URLSearchParams();
36
+ if (options?.limit !== undefined) params.set("limit", String(options.limit));
37
+ if (options?.offset !== undefined) params.set("offset", String(options.offset));
38
+ if (options?.search) params.set("search", options.search);
39
+ if (options?.orderBy) params.set("orderBy", options.orderBy);
40
+ if (options?.orderDir) params.set("orderDir", options.orderDir);
41
+ const qs = params.toString();
42
+ return transport.request<{ users: AdminUser[]; total: number; limit: number; offset: number }>(
43
+ adminPath + "/users" + (qs ? "?" + qs : ""), { method: "GET" }
44
+ );
45
+ }
46
+
47
+ async function getUser(userId: string) {
48
+ return transport.request<{ user: AdminUser }>(adminPath + "/users/" + encodeURIComponent(userId), { method: "GET" });
49
+ }
50
+
51
+ async function createUser(data: { email: string, displayName?: string, password?: string, roles?: string[] }) {
52
+ return transport.request<{ user: AdminUser }>(adminPath + "/users", {
53
+ method: "POST",
54
+ body: JSON.stringify(data)
55
+ });
56
+ }
57
+
58
+ async function updateUser(userId: string, data: { email?: string, displayName?: string, password?: string, roles?: string[] }) {
59
+ return transport.request<{ user: AdminUser }>(adminPath + "/users/" + encodeURIComponent(userId), {
60
+ method: "PUT",
61
+ body: JSON.stringify(data)
62
+ });
63
+ }
64
+
65
+ async function deleteUser(userId: string) {
66
+ return transport.request<{ success: boolean }>(adminPath + "/users/" + encodeURIComponent(userId), {
67
+ method: "DELETE"
68
+ });
69
+ }
70
+
71
+ async function listRoles() {
72
+ return transport.request<{ roles: RebaseRole[] }>(adminPath + "/roles", { method: "GET" });
73
+ }
74
+
75
+ async function getRole(roleId: string) {
76
+ return transport.request<{ role: RebaseRole }>(adminPath + "/roles/" + encodeURIComponent(roleId), { method: "GET" });
77
+ }
78
+
79
+ async function createRole(data: { id: string, name: string, isAdmin?: boolean, defaultPermissions?: Record<string, unknown>, config?: Record<string, unknown> }) {
80
+ return transport.request<{ role: RebaseRole }>(adminPath + "/roles", {
81
+ method: "POST",
82
+ body: JSON.stringify(data)
83
+ });
84
+ }
85
+
86
+ async function updateRole(roleId: string, data: { name?: string, isAdmin?: boolean, defaultPermissions?: Record<string, unknown>, config?: Record<string, unknown> }) {
87
+ return transport.request<{ role: RebaseRole }>(adminPath + "/roles/" + encodeURIComponent(roleId), {
88
+ method: "PUT",
89
+ body: JSON.stringify(data)
90
+ });
91
+ }
92
+
93
+ async function deleteRole(roleId: string) {
94
+ return transport.request<{ success: boolean }>(adminPath + "/roles/" + encodeURIComponent(roleId), {
95
+ method: "DELETE"
96
+ });
97
+ }
98
+
99
+ async function bootstrap() {
100
+ return transport.request<{ success: boolean; message: string; user: { uid: string; roles: string[] } }>(adminPath + "/bootstrap", {
101
+ method: "POST"
102
+ });
103
+ }
104
+
105
+ return {
106
+ listUsers,
107
+ listUsersPaginated,
108
+ getUser,
109
+ createUser,
110
+ updateUser,
111
+ deleteUser,
112
+ listRoles,
113
+ getRole,
114
+ createRole,
115
+ updateRole,
116
+ deleteRole,
117
+ bootstrap
118
+ };
119
+ }