@omnibase/core-js 0.5.10 → 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/README.md +64 -198
- package/dist/chunk-4VFICD7B.js +563 -0
- package/dist/chunk-4WXOODCF.js +579 -0
- package/dist/chunk-5MDBFHTF.js +555 -0
- package/dist/chunk-6OGESVXW.js +651 -0
- package/dist/chunk-BZSZVT4V.js +152 -0
- package/dist/chunk-CUBJFCZH.js +579 -0
- package/dist/chunk-I6DMWC32.js +129 -0
- package/dist/chunk-IVPULXIA.js +150 -0
- package/dist/chunk-LCEBQTB7.js +563 -0
- package/dist/chunk-LMDKQ6Z2.js +706 -0
- package/dist/chunk-NBPRDG6O.js +643 -0
- package/dist/chunk-QPW6G4PA.js +490 -0
- package/dist/chunk-QXPPBLH4.js +556 -0
- package/dist/chunk-V56G36FZ.js +558 -0
- package/dist/chunk-ZBRAIBZZ.js +658 -0
- package/dist/chunk-ZYLNNK7H.js +555 -0
- package/dist/database/index.cjs +215 -1
- package/dist/database/index.d.cts +194 -1
- package/dist/database/index.d.ts +194 -1
- package/dist/database/index.js +214 -1
- package/dist/index.cjs +449 -185
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +105 -4
- package/dist/payments/index.cjs +22 -74
- package/dist/payments/index.d.cts +554 -245
- package/dist/payments/index.d.ts +554 -245
- package/dist/payments/index.js +1 -1
- package/dist/storage/index.cjs +153 -0
- package/dist/storage/index.d.cts +3 -0
- package/dist/storage/index.d.ts +3 -0
- package/dist/storage/index.js +6 -0
- package/dist/tenants/index.cjs +200 -109
- package/dist/tenants/index.d.cts +1 -1
- package/dist/tenants/index.d.ts +1 -1
- package/dist/tenants/index.js +1 -1
- package/package.json +17 -12
package/dist/payments/index.js
CHANGED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/storage/index.ts
|
|
21
|
+
var storage_exports = {};
|
|
22
|
+
__export(storage_exports, {
|
|
23
|
+
StorageClient: () => StorageClient
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(storage_exports);
|
|
26
|
+
var StorageClient = class {
|
|
27
|
+
constructor(client) {
|
|
28
|
+
this.client = client;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Upload a file to storage
|
|
32
|
+
*
|
|
33
|
+
* @param path - Full path for the file (e.g., "public/images/avatar.png", "users/123/private/doc.pdf")
|
|
34
|
+
* @param file - File or Blob to upload
|
|
35
|
+
* @param options - Upload options including custom metadata
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* const result = await storage.upload(
|
|
40
|
+
* 'public/avatars/user-123.png',
|
|
41
|
+
* file,
|
|
42
|
+
* {
|
|
43
|
+
* metadata: {
|
|
44
|
+
* userId: '123',
|
|
45
|
+
* uploadedBy: 'john@example.com',
|
|
46
|
+
* tags: ['profile', 'avatar']
|
|
47
|
+
* }
|
|
48
|
+
* }
|
|
49
|
+
* );
|
|
50
|
+
*
|
|
51
|
+
* // File is automatically uploaded to S3 via the presigned URL
|
|
52
|
+
* console.log('File uploaded to:', result.path);
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
async upload(path, file, options) {
|
|
56
|
+
const metadata = {
|
|
57
|
+
// File metadata
|
|
58
|
+
filename: file instanceof File ? file.name : "blob",
|
|
59
|
+
size: file.size,
|
|
60
|
+
mime_type: file.type,
|
|
61
|
+
uploaded_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
62
|
+
// Merge custom metadata
|
|
63
|
+
...options?.metadata || {}
|
|
64
|
+
};
|
|
65
|
+
const response = await this.client.fetch("/api/v1/storage/upload", {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers: {
|
|
68
|
+
"Content-Type": "application/json"
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify({
|
|
71
|
+
path,
|
|
72
|
+
metadata
|
|
73
|
+
})
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const error = await response.json().catch(() => ({ error: "Upload failed" }));
|
|
77
|
+
throw new Error(error.error || "Failed to get upload URL");
|
|
78
|
+
}
|
|
79
|
+
const responseData = await response.json();
|
|
80
|
+
const result = responseData.data;
|
|
81
|
+
const uploadResponse = await fetch(result.upload_url, {
|
|
82
|
+
method: "PUT",
|
|
83
|
+
body: file,
|
|
84
|
+
headers: {
|
|
85
|
+
"Content-Type": file.type
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
if (!uploadResponse.ok) {
|
|
89
|
+
throw new Error("Failed to upload file to storage");
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Download a file from storage
|
|
95
|
+
*
|
|
96
|
+
* @param path - Full path to the file
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const { download_url } = await storage.download('public/images/logo.png');
|
|
101
|
+
*
|
|
102
|
+
* // Download the file
|
|
103
|
+
* const response = await fetch(download_url);
|
|
104
|
+
* const blob = await response.blob();
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
async download(path) {
|
|
108
|
+
const response = await this.client.fetch("/api/v1/storage/download", {
|
|
109
|
+
method: "POST",
|
|
110
|
+
headers: {
|
|
111
|
+
"Content-Type": "application/json"
|
|
112
|
+
},
|
|
113
|
+
body: JSON.stringify({
|
|
114
|
+
path
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
if (!response.ok) {
|
|
118
|
+
const error = await response.json().catch(() => ({ error: "Download failed" }));
|
|
119
|
+
throw new Error(error.error || "Failed to get download URL");
|
|
120
|
+
}
|
|
121
|
+
const responseData = await response.json();
|
|
122
|
+
return responseData.data;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Delete a file from storage
|
|
126
|
+
*
|
|
127
|
+
* @param path - Full path to the file
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* await storage.delete('users/123/documents/old-report.pdf');
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
async delete(path) {
|
|
135
|
+
const response = await this.client.fetch("/api/v1/storage/object", {
|
|
136
|
+
method: "DELETE",
|
|
137
|
+
headers: {
|
|
138
|
+
"Content-Type": "application/json"
|
|
139
|
+
},
|
|
140
|
+
body: JSON.stringify({
|
|
141
|
+
path
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
const error = await response.json().catch(() => ({ error: "Delete failed" }));
|
|
146
|
+
throw new Error(error.error || "Failed to delete file");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
151
|
+
0 && (module.exports = {
|
|
152
|
+
StorageClient
|
|
153
|
+
});
|
package/dist/tenants/index.cjs
CHANGED
|
@@ -68,17 +68,6 @@ var TenantInviteManager = class {
|
|
|
68
68
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
69
69
|
*
|
|
70
70
|
* @example
|
|
71
|
-
* Basic invitation acceptance:
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const result = await acceptTenantInvite('inv_secure_token_abc123');
|
|
74
|
-
*
|
|
75
|
-
* console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
|
|
76
|
-
* // User can now access tenant resources
|
|
77
|
-
* await switchActiveTenant(result.data.tenant_id);
|
|
78
|
-
* ```
|
|
79
|
-
*
|
|
80
|
-
* @example
|
|
81
|
-
* Handling the invitation flow:
|
|
82
71
|
* ```typescript
|
|
83
72
|
* // Typically called from an invitation link like:
|
|
84
73
|
* // https://app.com/accept-invite?token=inv_secure_token_abc123
|
|
@@ -88,21 +77,20 @@ var TenantInviteManager = class {
|
|
|
88
77
|
*
|
|
89
78
|
* if (inviteToken) {
|
|
90
79
|
* try {
|
|
91
|
-
* const result = await
|
|
80
|
+
* const result = await inviteManager.accept(inviteToken);
|
|
92
81
|
*
|
|
93
82
|
* // Success - redirect to tenant dashboard
|
|
83
|
+
* console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
|
|
94
84
|
* window.location.href = `/dashboard?tenant=${result.data.tenant_id}`;
|
|
95
85
|
* } catch (error) {
|
|
96
86
|
* console.error('Failed to accept invitation:', error.message);
|
|
97
|
-
* // Show error to user
|
|
98
87
|
* }
|
|
99
88
|
* }
|
|
100
89
|
* ```
|
|
101
90
|
*
|
|
102
|
-
*
|
|
103
|
-
* @since 1.0.0
|
|
91
|
+
* @since 0.6.0
|
|
104
92
|
* @public
|
|
105
|
-
* @group
|
|
93
|
+
* @group Tenant Invitations
|
|
106
94
|
*/
|
|
107
95
|
async accept(token) {
|
|
108
96
|
if (!token) {
|
|
@@ -137,73 +125,58 @@ var TenantInviteManager = class {
|
|
|
137
125
|
}
|
|
138
126
|
}
|
|
139
127
|
/**
|
|
140
|
-
* Creates a new user invitation for
|
|
128
|
+
* Creates a new user invitation for the active tenant
|
|
141
129
|
*
|
|
142
|
-
* Generates a secure invitation that allows a user to join the
|
|
143
|
-
* tenant with the defined role. The invitation is sent to the provided
|
|
144
|
-
*
|
|
130
|
+
* Generates a secure invitation that allows a user to join the currently active
|
|
131
|
+
* tenant with the defined role. The invitation is sent to the provided email address
|
|
132
|
+
* and includes a time-limited token for security. The invite URL will be automatically
|
|
133
|
+
* appended with ?token=XYZ when sent to the user.
|
|
145
134
|
*
|
|
146
|
-
* The function creates the invitation record in the database and
|
|
147
|
-
*
|
|
148
|
-
* The invitation expires after a predefined time period and can only
|
|
135
|
+
* The function creates the invitation record in the database and triggers an email
|
|
136
|
+
* notification to the invited user. The invitation expires after 7 days and can only
|
|
149
137
|
* be used once.
|
|
150
138
|
*
|
|
151
|
-
* Only existing tenant members with appropriate permissions
|
|
152
|
-
* invitations. The inviter's authentication
|
|
153
|
-
* cookies sent with the request.
|
|
139
|
+
* Only existing tenant members with appropriate permissions (invite_user permission)
|
|
140
|
+
* can create invitations. The inviter's authentication and tenant context are validated
|
|
141
|
+
* via HTTP-only cookies sent with the request.
|
|
154
142
|
*
|
|
155
|
-
* @param tenantId - Unique identifier of the tenant to invite the user to
|
|
156
143
|
* @param inviteData - Configuration object for the invitation
|
|
157
144
|
* @param inviteData.email - Email address of the user to invite
|
|
158
145
|
* @param inviteData.role - Role the user will have after joining (e.g., 'member', 'admin')
|
|
146
|
+
* @param inviteData.invite_url - Base URL for the invitation link (will be appended with ?token=XYZ)
|
|
159
147
|
*
|
|
160
148
|
* @returns Promise resolving to the created invitation with secure token
|
|
161
149
|
*
|
|
162
|
-
* @throws {Error} When
|
|
163
|
-
* @throws {Error} When
|
|
150
|
+
* @throws {Error} When required fields (email, role, invite_url) are missing or empty
|
|
151
|
+
* @throws {Error} When the user doesn't have permission to invite users to the tenant
|
|
164
152
|
* @throws {Error} When the API request fails due to network issues
|
|
165
153
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
166
154
|
*
|
|
167
155
|
* @example
|
|
168
|
-
* Basic invitation creation:
|
|
169
156
|
* ```typescript
|
|
170
|
-
* const invite = await
|
|
157
|
+
* const invite = await inviteManager.create({
|
|
171
158
|
* email: 'colleague@company.com',
|
|
172
|
-
* role: 'member'
|
|
159
|
+
* role: 'member',
|
|
160
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
173
161
|
* });
|
|
174
162
|
*
|
|
175
163
|
* console.log(`Invite sent to: ${invite.data.invite.email}`);
|
|
176
|
-
*
|
|
177
|
-
* const inviteLink = `https://app.com/accept-invite?token=${invite.data.invite.token}`;
|
|
164
|
+
* console.log(`Invite token: ${invite.data.invite.token}`);
|
|
178
165
|
* ```
|
|
179
166
|
*
|
|
180
|
-
* @
|
|
181
|
-
* Creating admin invitation:
|
|
182
|
-
* ```typescript
|
|
183
|
-
* const adminInvite = await createTenantUserInvite('tenant_456', {
|
|
184
|
-
* email: 'admin@company.com',
|
|
185
|
-
* role: 'admin'
|
|
186
|
-
* });
|
|
187
|
-
*
|
|
188
|
-
* // Admin users get elevated permissions
|
|
189
|
-
* console.log(`Admin invite created with ID: ${adminInvite.data.invite.id}`);
|
|
190
|
-
* ```
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* @since 1.0.0
|
|
167
|
+
* @since 0.6.0
|
|
194
168
|
* @public
|
|
195
|
-
* @group
|
|
169
|
+
* @group Tenant Invitations
|
|
196
170
|
*/
|
|
197
|
-
async create(
|
|
198
|
-
if (!
|
|
199
|
-
throw new Error(
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
throw new Error("Email and role are required");
|
|
171
|
+
async create(inviteData) {
|
|
172
|
+
if (!inviteData.email || !inviteData.role || !inviteData.invite_url) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
"Missing data in `create` - email, role, and invite_url are required"
|
|
175
|
+
);
|
|
203
176
|
}
|
|
204
177
|
try {
|
|
205
178
|
const response = await this.omnibaseClient.fetch(
|
|
206
|
-
`/api/v1/tenants
|
|
179
|
+
`/api/v1/tenants/invites`,
|
|
207
180
|
{
|
|
208
181
|
method: "POST",
|
|
209
182
|
headers: {
|
|
@@ -267,21 +240,17 @@ var TenantManger = class {
|
|
|
267
240
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
268
241
|
*
|
|
269
242
|
* @example
|
|
270
|
-
* Basic tenant creation:
|
|
271
243
|
* ```typescript
|
|
272
|
-
* const newTenant = await createTenant({
|
|
244
|
+
* const newTenant = await tenantManager.createTenant({
|
|
273
245
|
* name: 'Acme Corporation',
|
|
274
246
|
* billing_email: 'billing@acme.com',
|
|
275
247
|
* user_id: 'user_123'
|
|
276
248
|
* });
|
|
277
249
|
*
|
|
278
|
-
* console.log(`
|
|
279
|
-
* // Store the token for authenticated requests
|
|
280
|
-
* localStorage.setItem('tenant_token', newTenant.data.token);
|
|
250
|
+
* console.log(`Tenant created: ${newTenant.data.tenant.id}`);
|
|
281
251
|
* ```
|
|
282
252
|
*
|
|
283
|
-
*
|
|
284
|
-
* @since 1.0.0
|
|
253
|
+
* @since 0.6.0
|
|
285
254
|
* @public
|
|
286
255
|
* @group Tenant Management
|
|
287
256
|
*/
|
|
@@ -346,7 +315,6 @@ var TenantManger = class {
|
|
|
346
315
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
347
316
|
*
|
|
348
317
|
* @example
|
|
349
|
-
* Basic tenant deletion with confirmation:
|
|
350
318
|
* ```typescript
|
|
351
319
|
* const tenantToDelete = 'tenant_abc123';
|
|
352
320
|
*
|
|
@@ -357,8 +325,8 @@ var TenantManger = class {
|
|
|
357
325
|
*
|
|
358
326
|
* if (userConfirmed) {
|
|
359
327
|
* try {
|
|
360
|
-
* const result = await deleteTenant(tenantToDelete);
|
|
361
|
-
* console.log(result.data.message);
|
|
328
|
+
* const result = await tenantManager.deleteTenant(tenantToDelete);
|
|
329
|
+
* console.log(result.data.message);
|
|
362
330
|
*
|
|
363
331
|
* // Redirect user away from deleted tenant
|
|
364
332
|
* window.location.href = '/dashboard';
|
|
@@ -368,7 +336,7 @@ var TenantManger = class {
|
|
|
368
336
|
* }
|
|
369
337
|
* ```
|
|
370
338
|
*
|
|
371
|
-
* @since
|
|
339
|
+
* @since 0.6.0
|
|
372
340
|
* @public
|
|
373
341
|
* @group Tenant Management
|
|
374
342
|
*/
|
|
@@ -431,46 +399,17 @@ var TenantManger = class {
|
|
|
431
399
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
432
400
|
*
|
|
433
401
|
* @example
|
|
434
|
-
* Basic tenant switching:
|
|
435
402
|
* ```typescript
|
|
436
|
-
* const result = await switchActiveTenant('tenant_xyz789');
|
|
403
|
+
* const result = await tenantManager.switchActiveTenant('tenant_xyz789');
|
|
404
|
+
*
|
|
405
|
+
* // Store the new token for future requests
|
|
406
|
+
* console.log(`Switched to tenant. New token: ${result.data.token}`);
|
|
437
407
|
*
|
|
438
408
|
* // Now all API calls will be in the context of tenant_xyz789
|
|
439
409
|
* const tenantData = await getCurrentTenantData();
|
|
440
410
|
* ```
|
|
441
411
|
*
|
|
442
|
-
* @
|
|
443
|
-
* Using with tenant-aware data fetching:
|
|
444
|
-
* ```typescript
|
|
445
|
-
* // Switch tenant and immediately fetch tenant-specific data
|
|
446
|
-
* const switchAndLoadTenant = async (tenantId: string) => {
|
|
447
|
-
* try {
|
|
448
|
-
* // Switch to new tenant context
|
|
449
|
-
* const switchResult = await switchActiveTenant(tenantId);
|
|
450
|
-
*
|
|
451
|
-
* // Update authentication token
|
|
452
|
-
* setAuthToken(switchResult.data.token);
|
|
453
|
-
*
|
|
454
|
-
* // Fetch data in new tenant context
|
|
455
|
-
* const [tenantInfo, userPermissions, tenantSettings] = await Promise.all([
|
|
456
|
-
* getTenantInfo(),
|
|
457
|
-
* getUserPermissions(),
|
|
458
|
-
* getTenantSettings()
|
|
459
|
-
* ]);
|
|
460
|
-
*
|
|
461
|
-
* return {
|
|
462
|
-
* tenant: tenantInfo,
|
|
463
|
-
* permissions: userPermissions,
|
|
464
|
-
* settings: tenantSettings
|
|
465
|
-
* };
|
|
466
|
-
* } catch (error) {
|
|
467
|
-
* console.error('Failed to switch tenant and load data:', error);
|
|
468
|
-
* throw error;
|
|
469
|
-
* }
|
|
470
|
-
* };
|
|
471
|
-
* ```
|
|
472
|
-
*
|
|
473
|
-
* @since 1.0.0
|
|
412
|
+
* @since 0.6.0
|
|
474
413
|
* @public
|
|
475
414
|
* @group Tenant Management
|
|
476
415
|
*/
|
|
@@ -508,6 +447,140 @@ var TenantManger = class {
|
|
|
508
447
|
}
|
|
509
448
|
};
|
|
510
449
|
|
|
450
|
+
// src/tenants/user.ts
|
|
451
|
+
var TenantUserManager = class {
|
|
452
|
+
/**
|
|
453
|
+
* Creates a new tenant user manager
|
|
454
|
+
*
|
|
455
|
+
* @param omnibaseClient - Configured OmnibaseClient instance for API communication
|
|
456
|
+
*
|
|
457
|
+
* @group Tenant User Management
|
|
458
|
+
*/
|
|
459
|
+
constructor(omnibaseClient) {
|
|
460
|
+
this.omnibaseClient = omnibaseClient;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Removes a user from the active tenant
|
|
464
|
+
*
|
|
465
|
+
* This method removes a specified user from the current active tenant. The operation
|
|
466
|
+
* requires the requesting user to have appropriate permissions (admin or owner role).
|
|
467
|
+
* The user being removed will lose access to the tenant and all its resources.
|
|
468
|
+
*
|
|
469
|
+
* Note: You cannot remove yourself from a tenant using this method. To leave a tenant,
|
|
470
|
+
* use the appropriate leave or delete tenant operations instead.
|
|
471
|
+
*
|
|
472
|
+
* @param data - Request data containing the user ID to remove
|
|
473
|
+
* @param data.user_id - ID of the user to remove from the tenant
|
|
474
|
+
*
|
|
475
|
+
* @returns Promise resolving to an API response confirming the removal
|
|
476
|
+
*
|
|
477
|
+
* @throws {Error} When user_id is not provided
|
|
478
|
+
* @throws {Error} When the API request fails (includes status code and error details)
|
|
479
|
+
* @throws {Error} When the user doesn't have permission to remove users
|
|
480
|
+
* @throws {Error} When the specified user is not a member of the tenant
|
|
481
|
+
*
|
|
482
|
+
* @example
|
|
483
|
+
* ```typescript
|
|
484
|
+
* // Remove a user from the active tenant
|
|
485
|
+
* try {
|
|
486
|
+
* await userManager.remove({ user_id: 'user_abc123' });
|
|
487
|
+
* console.log('User removed successfully');
|
|
488
|
+
* } catch (error) {
|
|
489
|
+
* if (error.message.includes('403')) {
|
|
490
|
+
* console.error('Insufficient permissions to remove user');
|
|
491
|
+
* } else if (error.message.includes('404')) {
|
|
492
|
+
* console.error('User not found in tenant');
|
|
493
|
+
* } else {
|
|
494
|
+
* console.error('Failed to remove user:', error);
|
|
495
|
+
* }
|
|
496
|
+
* }
|
|
497
|
+
* ```
|
|
498
|
+
*
|
|
499
|
+
* @since 0.6.0
|
|
500
|
+
* @public
|
|
501
|
+
* @group Tenant User Management
|
|
502
|
+
*/
|
|
503
|
+
async remove(data) {
|
|
504
|
+
if (!data.user_id) {
|
|
505
|
+
throw new Error("user_id is required");
|
|
506
|
+
}
|
|
507
|
+
const response = await this.omnibaseClient.fetch("/api/v1/tenants/users", {
|
|
508
|
+
method: "DELETE",
|
|
509
|
+
body: JSON.stringify(data)
|
|
510
|
+
});
|
|
511
|
+
if (!response.ok) {
|
|
512
|
+
const errorData = await response.text();
|
|
513
|
+
throw new Error(
|
|
514
|
+
`Failed to delete user from tenant: ${response.status} - ${errorData}`
|
|
515
|
+
);
|
|
516
|
+
}
|
|
517
|
+
return await response.json();
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* Updates a user's role within the active tenant
|
|
521
|
+
*
|
|
522
|
+
* This method changes the role of a specified user in the current active tenant. The operation
|
|
523
|
+
* requires the requesting user to have appropriate permissions (typically admin or owner role).
|
|
524
|
+
* Role updates take effect immediately and affect the user's permissions and access rights
|
|
525
|
+
* within the tenant.
|
|
526
|
+
*
|
|
527
|
+
* Common roles include 'admin', 'member', and 'viewer', but the exact roles available depend
|
|
528
|
+
* on your tenant's configuration. Changing a user's role will modify their ability to perform
|
|
529
|
+
* various operations within the tenant.
|
|
530
|
+
*
|
|
531
|
+
* @param data - Request data containing the user ID and new role
|
|
532
|
+
* @param data.user_id - ID of the user whose role is being updated
|
|
533
|
+
* @param data.role - New role to assign to the user
|
|
534
|
+
*
|
|
535
|
+
* @returns Promise resolving to an API response confirming the role update
|
|
536
|
+
*
|
|
537
|
+
* @throws {Error} When user_id or role is not provided
|
|
538
|
+
* @throws {Error} When the API request fails (includes status code and error details)
|
|
539
|
+
* @throws {Error} When the user doesn't have permission to update roles
|
|
540
|
+
* @throws {Error} When the specified user is not a member of the tenant
|
|
541
|
+
* @throws {Error} When the specified role is invalid or not allowed
|
|
542
|
+
*
|
|
543
|
+
* @example
|
|
544
|
+
* ```typescript
|
|
545
|
+
* // Update a user's role to admin
|
|
546
|
+
* try {
|
|
547
|
+
* const result = await userManager.updateRole({
|
|
548
|
+
* user_id: 'user_abc123',
|
|
549
|
+
* role: 'admin'
|
|
550
|
+
* });
|
|
551
|
+
* console.log('Role updated successfully:', result.data.message);
|
|
552
|
+
* } catch (error) {
|
|
553
|
+
* if (error.message.includes('403')) {
|
|
554
|
+
* console.error('Insufficient permissions to update roles');
|
|
555
|
+
* } else if (error.message.includes('404')) {
|
|
556
|
+
* console.error('User not found in tenant');
|
|
557
|
+
* } else {
|
|
558
|
+
* console.error('Failed to update role:', error);
|
|
559
|
+
* }
|
|
560
|
+
* }
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @since 0.6.0
|
|
564
|
+
* @public
|
|
565
|
+
* @group Tenant User Management
|
|
566
|
+
*/
|
|
567
|
+
async updateRole(data) {
|
|
568
|
+
if (!data.role || !data.user_id)
|
|
569
|
+
throw new Error("user_id and role is required");
|
|
570
|
+
const response = await this.omnibaseClient.fetch("/api/v1/tenants/users", {
|
|
571
|
+
method: "PUT",
|
|
572
|
+
body: JSON.stringify(data)
|
|
573
|
+
});
|
|
574
|
+
if (!response.ok) {
|
|
575
|
+
const errorData = await response.text();
|
|
576
|
+
throw new Error(
|
|
577
|
+
`Failed to update users role: ${response.status} - ${errorData}`
|
|
578
|
+
);
|
|
579
|
+
}
|
|
580
|
+
return await response.json();
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
|
|
511
584
|
// src/tenants/handler.ts
|
|
512
585
|
var TenantHandler = class {
|
|
513
586
|
/**
|
|
@@ -531,10 +604,27 @@ var TenantHandler = class {
|
|
|
531
604
|
* @group Tenant Management
|
|
532
605
|
*/
|
|
533
606
|
constructor(omnibaseClient) {
|
|
534
|
-
this.
|
|
535
|
-
this.
|
|
536
|
-
this.
|
|
607
|
+
this.invites = new TenantInviteManager(omnibaseClient);
|
|
608
|
+
this.manage = new TenantManger(omnibaseClient);
|
|
609
|
+
this.user = new TenantUserManager(omnibaseClient);
|
|
537
610
|
}
|
|
611
|
+
/**
|
|
612
|
+
* Tenant user management operations
|
|
613
|
+
*
|
|
614
|
+
* Provides access to operations for managing users within tenants, including
|
|
615
|
+
* removing users from the active tenant. All operations respect user permissions
|
|
616
|
+
* and tenant ownership rules.
|
|
617
|
+
*
|
|
618
|
+
* @example
|
|
619
|
+
* ```typescript
|
|
620
|
+
* // Remove a user from the active tenant
|
|
621
|
+
* await tenantHandler.user.remove({ user_id: 'user_123' });
|
|
622
|
+
* ```
|
|
623
|
+
*
|
|
624
|
+
* @since 0.6.0
|
|
625
|
+
* @group Tenant Management
|
|
626
|
+
*/
|
|
627
|
+
user;
|
|
538
628
|
/**
|
|
539
629
|
* Core tenant management operations
|
|
540
630
|
*
|
|
@@ -545,17 +635,17 @@ var TenantHandler = class {
|
|
|
545
635
|
* @example
|
|
546
636
|
* ```typescript
|
|
547
637
|
* // Create a new tenant
|
|
548
|
-
* const tenant = await tenantHandler.
|
|
638
|
+
* const tenant = await tenantHandler.manage.createTenant({
|
|
549
639
|
* name: 'New Company',
|
|
550
640
|
* billing_email: 'billing@newcompany.com',
|
|
551
641
|
* user_id: 'user_456'
|
|
552
642
|
* });
|
|
553
643
|
*
|
|
554
644
|
* // Switch to the tenant
|
|
555
|
-
* await tenantHandler.
|
|
645
|
+
* await tenantHandler.manage.switchActiveTenant(tenant.data.tenant.id);
|
|
556
646
|
*
|
|
557
647
|
* // Delete the tenant (owner only)
|
|
558
|
-
* await tenantHandler.
|
|
648
|
+
* await tenantHandler.manage.deleteTenant(tenant.data.tenant.id);
|
|
559
649
|
* ```
|
|
560
650
|
*/
|
|
561
651
|
manage;
|
|
@@ -569,9 +659,10 @@ var TenantHandler = class {
|
|
|
569
659
|
* @example
|
|
570
660
|
* ```typescript
|
|
571
661
|
* // Create an invitation
|
|
572
|
-
* const invite = await tenantHandler.invites.create(
|
|
662
|
+
* const invite = await tenantHandler.invites.create({
|
|
573
663
|
* email: 'newuser@company.com',
|
|
574
|
-
* role: 'admin'
|
|
664
|
+
* role: 'admin',
|
|
665
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
575
666
|
* });
|
|
576
667
|
*
|
|
577
668
|
* // Accept an invitation (from the invited user's session)
|
package/dist/tenants/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as AcceptTenantInviteRequest,
|
|
1
|
+
export { A as AcceptTenantInviteRequest, b as AcceptTenantInviteResponse, j as CreateTenantRequest, h as CreateTenantResponse, d as CreateTenantUserInviteRequest, C as CreateTenantUserInviteResponse, g as DeleteTenantResponse, f as SwitchActiveTenantResponse, i as Tenant, T as TenantHandler, c as TenantInvite, e as TenantInviteManager, k as TenantManger } from '../payments/index.cjs';
|
|
2
2
|
import '../permissions/index.cjs';
|
|
3
3
|
import '@ory/client';
|
package/dist/tenants/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { A as AcceptTenantInviteRequest,
|
|
1
|
+
export { A as AcceptTenantInviteRequest, b as AcceptTenantInviteResponse, j as CreateTenantRequest, h as CreateTenantResponse, d as CreateTenantUserInviteRequest, C as CreateTenantUserInviteResponse, g as DeleteTenantResponse, f as SwitchActiveTenantResponse, i as Tenant, T as TenantHandler, c as TenantInvite, e as TenantInviteManager, k as TenantManger } from '../payments/index.js';
|
|
2
2
|
import '../permissions/index.js';
|
|
3
3
|
import '@ory/client';
|