@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/dist/index.d.cts CHANGED
@@ -1,3 +1,3 @@
1
- export { j as ApiResponse, i as OmnibaseClient, O as OmnibaseClientConfig } from './payments/index.cjs';
1
+ export { m as ApiResponse, D as DownloadResult, l as OmnibaseClient, O as OmnibaseClientConfig, S as StorageClient, U as UploadOptions, a as UploadResult } from './payments/index.cjs';
2
2
  import './permissions/index.cjs';
3
3
  import '@ory/client';
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { j as ApiResponse, i as OmnibaseClient, O as OmnibaseClientConfig } from './payments/index.js';
1
+ export { m as ApiResponse, D as DownloadResult, l as OmnibaseClient, O as OmnibaseClientConfig, S as StorageClient, U as UploadOptions, a as UploadResult } from './payments/index.js';
2
2
  import './permissions/index.js';
3
3
  import '@ory/client';
package/dist/index.js CHANGED
@@ -1,12 +1,15 @@
1
+ import {
2
+ PaymentHandler
3
+ } from "./chunk-QPW6G4PA.js";
1
4
  import {
2
5
  PermissionsClient
3
6
  } from "./chunk-DDFBRGMG.js";
4
7
  import {
5
- PaymentHandler
6
- } from "./chunk-PNP3T7XU.js";
8
+ StorageClient
9
+ } from "./chunk-I6DMWC32.js";
7
10
  import {
8
11
  TenantHandler
9
- } from "./chunk-L7EZC6WP.js";
12
+ } from "./chunk-6OGESVXW.js";
10
13
 
11
14
  // src/client.ts
12
15
  var OmnibaseClient = class {
@@ -39,8 +42,105 @@ var OmnibaseClient = class {
39
42
  * ```
40
43
  */
41
44
  payments = new PaymentHandler(this);
45
+ /**
46
+ * Main tenant management handler
47
+ *
48
+ * This is the primary entry point for all tenant-related operations in the
49
+ * Omnibase SDK. It provides a unified interface to tenant management,
50
+ * user management, and invitation functionality through dedicated manager instances.
51
+ *
52
+ * The handler follows the composition pattern, combining specialized managers
53
+ * for different aspects of tenant functionality:
54
+ * - `manage`: Core tenant operations (create, delete, switch)
55
+ * - `invites`: User invitation management (create, accept)
56
+ * - `user`: Tenant user operations (remove, update role)
57
+ *
58
+ * All operations are performed within the context of the authenticated user
59
+ * and respect tenant-level permissions and row-level security policies.
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * // Create a new tenant
64
+ * const tenant = await omnibase.tenants.manage.createTenant({
65
+ * name: 'My Company',
66
+ * billing_email: 'billing@company.com',
67
+ * user_id: 'user_123'
68
+ * });
69
+ *
70
+ * // Invite users to the tenant
71
+ * const invite = await omnibase.tenants.invites.create({
72
+ * email: 'colleague@company.com',
73
+ * role: 'member',
74
+ * invite_url: 'https://yourapp.com/accept-invite'
75
+ * });
76
+ *
77
+ * // Switch to the new tenant
78
+ * await omnibase.tenants.manage.switchActiveTenant(tenant.data.tenant.id);
79
+ * ```
80
+ *
81
+ * @since 0.6.0
82
+ * @public
83
+ * @group Tenant Management
84
+ */
42
85
  tenants = new TenantHandler(this);
86
+ /**
87
+ * Client for managing permissions and relationships using Ory Keto
88
+ *
89
+ * This client provides access to Ory Keto's permission system, allowing you to
90
+ * create, manage, and check relationships between subjects and objects. It handles
91
+ * both read operations (permission checks) and write operations (relationship management).
92
+ *
93
+ * The client automatically configures separate endpoints for read and write operations
94
+ * to optimize performance and security by following Ory Keto's recommended architecture.
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Check if a user can view a tenant
99
+ * const canView = await omnibase.permissions.permissions.checkPermission(
100
+ * undefined,
101
+ * {
102
+ * namespace: 'Tenant',
103
+ * object: 'tenant_123',
104
+ * relation: 'view',
105
+ * subjectId: 'user_456'
106
+ * }
107
+ * );
108
+ *
109
+ * if (canView.data.allowed) {
110
+ * console.log('User can view the tenant');
111
+ * }
112
+ *
113
+ * // Create a relationship making a user an owner of a tenant
114
+ * await omnibase.permissions.relationships.createRelationship(
115
+ * undefined,
116
+ * {
117
+ * namespace: 'Tenant',
118
+ * object: 'tenant_123',
119
+ * relation: 'owners',
120
+ * subjectId: 'user_456'
121
+ * }
122
+ * );
123
+ * ```
124
+ *
125
+ * @since 0.6.0
126
+ * @public
127
+ * @group Permissions
128
+ */
43
129
  permissions;
130
+ /**
131
+ * Storage client for file upload/download operations
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // Upload with metadata
136
+ * await omnibase.storage.bucket('documents').upload(
137
+ * 'report.pdf',
138
+ * file,
139
+ * { metadata: { department: 'engineering' } }
140
+ * );
141
+ * ```
142
+ */
143
+ storage = new StorageClient(this);
44
144
  async fetch(endpoint, options = {}) {
45
145
  if (this.config.fetch)
46
146
  return this.config.fetch(this.config.api_url + endpoint, options);
@@ -51,5 +151,6 @@ var OmnibaseClient = class {
51
151
  }
52
152
  };
53
153
  export {
54
- OmnibaseClient
154
+ OmnibaseClient,
155
+ StorageClient
55
156
  };
@@ -60,31 +60,20 @@ var CheckoutManager = class {
60
60
  * @throws {ValidationError} When required parameters are missing or invalid
61
61
  *
62
62
  * @example
63
- * Creating a checkout session (mode is auto-detected):
64
63
  * ```typescript
65
64
  * const session = await checkoutManager.createSession({
66
- * price_id: 'price_one_time_product',
65
+ * price_id: 'price_monthly_pro',
67
66
  * success_url: 'https://app.com/success',
68
67
  * cancel_url: 'https://app.com/cancel'
69
68
  * });
70
69
  *
71
70
  * // Redirect to Stripe checkout
72
- * window.location.href = session.data.url;
73
- * ```
74
- *
75
- * @example
76
- * Checkout with session tracking:
77
- * ```typescript
78
- * const session = await checkoutManager.createSession({
79
- * price_id: 'price_monthly_plan',
80
- * success_url: 'https://app.com/dashboard?session_id={CHECKOUT_SESSION_ID}',
81
- * cancel_url: 'https://app.com/pricing',
82
- * });
83
- *
84
- * console.log(`Session created: ${session.data.sessionId}`);
71
+ * if (session.data?.url) {
72
+ * window.location.href = session.data.url;
73
+ * }
85
74
  * ```
86
75
  *
87
- * @since 1.0.0
76
+ * @since 0.6.0
88
77
  * @group Checkout
89
78
  */
90
79
  async createSession(options) {
@@ -305,7 +294,7 @@ var PortalManager = class {
305
294
  /**
306
295
  * Initialize the portal manager
307
296
  *
308
- * @param paymentHandler - Payment handler instance for API communication
297
+ * @param omnibaseClient - OmnibaseClient instance for API communication
309
298
  *
310
299
  * @group Portal
311
300
  */
@@ -332,32 +321,18 @@ var PortalManager = class {
332
321
  * @throws {ValidationError} When required parameters are missing or invalid
333
322
  *
334
323
  * @example
335
- * Basic portal creation:
336
324
  * ```typescript
337
325
  * const portal = await portalManager.create({
338
326
  * return_url: 'https://myapp.com/account/billing'
339
327
  * });
340
328
  *
341
329
  * // Redirect user to portal
342
- * window.location.href = portal.data.url;
343
- * ```
344
- *
345
- * @example
346
- * With error handling:
347
- * ```typescript
348
- * try {
349
- * const portal = await portalManager.create({
350
- * return_url: window.location.origin + '/billing'
351
- * });
352
- *
330
+ * if (portal.data?.url) {
353
331
  * window.location.href = portal.data.url;
354
- * } catch (error) {
355
- * console.error('Failed to create portal session:', error);
356
- * showErrorMessage('Unable to access billing portal. Please try again.');
357
332
  * }
358
333
  * ```
359
334
  *
360
- * @since 1.0.0
335
+ * @since 0.6.0
361
336
  * @group Portal
362
337
  */
363
338
  async create(options) {
@@ -387,7 +362,7 @@ var UsageManager = class {
387
362
  /**
388
363
  * Initialize the usage manager
389
364
  *
390
- * @param paymentHandler - Payment handler instance for API communication
365
+ * @param omnibaseClient - OmnibaseClient instance for API communication
391
366
  *
392
367
  * @group Usage
393
368
  */
@@ -416,7 +391,6 @@ var UsageManager = class {
416
391
  * @throws {ValidationError} When required parameters are missing or invalid
417
392
  *
418
393
  * @example
419
- * API call tracking:
420
394
  * ```typescript
421
395
  * // Record each API call
422
396
  * await usageManager.recordUsage({
@@ -425,37 +399,7 @@ var UsageManager = class {
425
399
  * });
426
400
  * ```
427
401
  *
428
- * @example
429
- * Batch usage recording:
430
- * ```typescript
431
- * // Record multiple operations at once
432
- * const usageEvents = [
433
- * { meter_event_name: 'compute_hours', value: '0.5' },
434
- * { meter_event_name: 'storage_gb', value: '10' },
435
- * { meter_event_name: 'api_calls', value: '50' }
436
- * ];
437
- *
438
- * for (const event of usageEvents) {
439
- * await usageManager.recordUsage(event);
440
- * }
441
- * ```
442
- *
443
- * @example
444
- * With error handling:
445
- * ```typescript
446
- * try {
447
- * await usageManager.recordUsage({
448
- * meter_event_name: 'file_uploads',
449
- * value: String(uploadedFiles.length)
450
- * });
451
- * } catch (error) {
452
- * console.error('Failed to record usage:', error);
453
- * // Usage recording failure shouldn't block user operations
454
- * // but should be logged for billing accuracy
455
- * }
456
- * ```
457
- *
458
- * @since 1.0.0
402
+ * @since 0.6.0
459
403
  * @group Usage
460
404
  */
461
405
  async recordUsage(options) {
@@ -480,20 +424,20 @@ var UsageManager = class {
480
424
  // src/payments/handler.ts
481
425
  var PaymentHandler = class {
482
426
  /**
483
- * Initialize the payment handler with API configuration
427
+ * Initialize the payment handler with OmnibaseClient
484
428
  *
485
- * Creates a new payment handler instance that will communicate with
486
- * the specified API endpoint. The handler automatically handles
487
- * request formatting and authentication headers.
429
+ * Creates a new payment handler instance with access to all payment
430
+ * operations including checkout, configuration, portal, and usage tracking.
431
+ * The handler uses the provided OmnibaseClient for API communication.
488
432
  *
489
- * @param apiUrl - Base URL for the payment API endpoint
433
+ * @param omnibaseClient - OmnibaseClient instance for API communication
490
434
  *
491
435
  * @example
492
436
  * ```typescript
493
- * const paymentHandler = new PaymentHandler('https://api.myapp.com');
437
+ * const paymentHandler = new PaymentHandler(omnibaseClient);
494
438
  * ```
495
439
  *
496
- * @since 1.0.0
440
+ * @since 0.6.0
497
441
  * @group Client
498
442
  */
499
443
  constructor(omnibaseClient) {
@@ -512,10 +456,14 @@ var PaymentHandler = class {
512
456
  * @example
513
457
  * ```typescript
514
458
  * const session = await paymentHandler.checkout.createSession({
515
- * price_id: 'price_monthly',
459
+ * price_id: 'price_monthly_pro',
516
460
  * success_url: window.location.origin + '/success',
517
461
  * cancel_url: window.location.origin + '/pricing'
518
462
  * });
463
+ *
464
+ * if (session.data?.url) {
465
+ * window.location.href = session.data.url;
466
+ * }
519
467
  * ```
520
468
  */
521
469
  checkout;