@omnibase/core-js 0.6.0 → 0.7.1
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-6OGESVXW.js +651 -0
- package/dist/chunk-QPW6G4PA.js +490 -0
- package/dist/database/index.cjs +187 -0
- package/dist/database/index.d.cts +194 -1
- package/dist/database/index.d.ts +194 -1
- package/dist/database/index.js +186 -0
- package/dist/index.cjs +150 -174
- package/dist/index.js +87 -4
- package/dist/payments/index.cjs +22 -74
- package/dist/payments/index.d.cts +230 -249
- package/dist/payments/index.d.ts +230 -249
- package/dist/payments/index.js +1 -1
- package/dist/tenants/index.cjs +45 -100
- package/dist/tenants/index.js +1 -1
- package/package.json +1 -1
|
@@ -28,7 +28,7 @@ import '@ory/client';
|
|
|
28
28
|
* };
|
|
29
29
|
* ```
|
|
30
30
|
*
|
|
31
|
-
* @since
|
|
31
|
+
* @since 0.6.0
|
|
32
32
|
* @public
|
|
33
33
|
*/
|
|
34
34
|
type ApiResponse<T> = {
|
|
@@ -53,20 +53,20 @@ type ApiResponse<T> = {
|
|
|
53
53
|
* Configuration options for creating a Stripe checkout session
|
|
54
54
|
*
|
|
55
55
|
* Defines all parameters needed to create a checkout session for either
|
|
56
|
-
* one-time payments or subscription billing. The
|
|
57
|
-
*
|
|
56
|
+
* one-time payments or subscription billing. The checkout mode (payment vs
|
|
57
|
+
* subscription) is automatically determined by examining the price configuration
|
|
58
|
+
* - no need to specify it manually.
|
|
58
59
|
*
|
|
59
60
|
* @example
|
|
60
61
|
* ```typescript
|
|
61
62
|
* const options: CheckoutOptions = {
|
|
62
|
-
* price_id: '
|
|
63
|
-
* mode: 'subscription',
|
|
63
|
+
* price_id: 'price_monthly_pro',
|
|
64
64
|
* success_url: 'https://app.com/success?session_id={CHECKOUT_SESSION_ID}',
|
|
65
65
|
* cancel_url: 'https://app.com/pricing',
|
|
66
66
|
* };
|
|
67
67
|
* ```
|
|
68
68
|
*
|
|
69
|
-
* @since
|
|
69
|
+
* @since 0.6.0
|
|
70
70
|
* @public
|
|
71
71
|
* @group Checkout
|
|
72
72
|
*/
|
|
@@ -87,7 +87,7 @@ type CheckoutOptions = {
|
|
|
87
87
|
* Contains the checkout session URL and ID for redirecting users
|
|
88
88
|
* to Stripe's hosted checkout page and tracking the session.
|
|
89
89
|
*
|
|
90
|
-
* @since
|
|
90
|
+
* @since 0.6.0
|
|
91
91
|
* @public
|
|
92
92
|
* @group Checkout
|
|
93
93
|
*/
|
|
@@ -101,17 +101,18 @@ type CreateCheckoutResponse = ApiResponse<{
|
|
|
101
101
|
* Manager for Stripe checkout session operations
|
|
102
102
|
*
|
|
103
103
|
* Handles creation and management of Stripe checkout sessions for both
|
|
104
|
-
* one-time payments and subscription billing.
|
|
105
|
-
*
|
|
104
|
+
* one-time payments and subscription billing. The checkout mode is automatically
|
|
105
|
+
* determined by examining whether the price has a recurring interval - recurring
|
|
106
|
+
* prices create subscription checkouts, while non-recurring prices create one-time
|
|
107
|
+
* payment checkouts.
|
|
106
108
|
*
|
|
107
|
-
* Checkout sessions
|
|
108
|
-
*
|
|
109
|
-
*
|
|
109
|
+
* Checkout sessions provide a secure, PCI-compliant payment flow without requiring
|
|
110
|
+
* sensitive payment data to touch your servers. The API automatically fetches the
|
|
111
|
+
* price details from Stripe to determine the appropriate checkout mode.
|
|
110
112
|
*
|
|
111
113
|
* @example
|
|
112
|
-
* Creating a checkout session (mode auto-detected from price):
|
|
113
114
|
* ```typescript
|
|
114
|
-
* const checkoutManager = new CheckoutManager(
|
|
115
|
+
* const checkoutManager = new CheckoutManager(omnibaseClient);
|
|
115
116
|
*
|
|
116
117
|
* const session = await checkoutManager.createSession({
|
|
117
118
|
* price_id: 'price_monthly_pro',
|
|
@@ -123,7 +124,7 @@ type CreateCheckoutResponse = ApiResponse<{
|
|
|
123
124
|
* window.location.href = session.data.url;
|
|
124
125
|
* ```
|
|
125
126
|
*
|
|
126
|
-
* @since
|
|
127
|
+
* @since 0.6.0
|
|
127
128
|
* @public
|
|
128
129
|
* @group Checkout
|
|
129
130
|
*/
|
|
@@ -157,31 +158,20 @@ declare class CheckoutManager {
|
|
|
157
158
|
* @throws {ValidationError} When required parameters are missing or invalid
|
|
158
159
|
*
|
|
159
160
|
* @example
|
|
160
|
-
* Creating a checkout session (mode is auto-detected):
|
|
161
161
|
* ```typescript
|
|
162
162
|
* const session = await checkoutManager.createSession({
|
|
163
|
-
* price_id: '
|
|
163
|
+
* price_id: 'price_monthly_pro',
|
|
164
164
|
* success_url: 'https://app.com/success',
|
|
165
165
|
* cancel_url: 'https://app.com/cancel'
|
|
166
166
|
* });
|
|
167
167
|
*
|
|
168
168
|
* // Redirect to Stripe checkout
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* Checkout with session tracking:
|
|
174
|
-
* ```typescript
|
|
175
|
-
* const session = await checkoutManager.createSession({
|
|
176
|
-
* price_id: 'price_monthly_plan',
|
|
177
|
-
* success_url: 'https://app.com/dashboard?session_id={CHECKOUT_SESSION_ID}',
|
|
178
|
-
* cancel_url: 'https://app.com/pricing',
|
|
179
|
-
* });
|
|
180
|
-
*
|
|
181
|
-
* console.log(`Session created: ${session.data.sessionId}`);
|
|
169
|
+
* if (session.data?.url) {
|
|
170
|
+
* window.location.href = session.data.url;
|
|
171
|
+
* }
|
|
182
172
|
* ```
|
|
183
173
|
*
|
|
184
|
-
* @since
|
|
174
|
+
* @since 0.6.0
|
|
185
175
|
* @group Checkout
|
|
186
176
|
*/
|
|
187
177
|
createSession(options: CheckoutOptions): Promise<CreateCheckoutResponse>;
|
|
@@ -194,7 +184,7 @@ declare class CheckoutManager {
|
|
|
194
184
|
* and UI customization settings. This represents the complete billing
|
|
195
185
|
* configuration loaded from the database.
|
|
196
186
|
*
|
|
197
|
-
* @since
|
|
187
|
+
* @since 0.6.0
|
|
198
188
|
* @public
|
|
199
189
|
* @group Configuration
|
|
200
190
|
*/
|
|
@@ -227,7 +217,7 @@ type StripeConfigResponse = ApiResponse<{
|
|
|
227
217
|
* };
|
|
228
218
|
* ```
|
|
229
219
|
*
|
|
230
|
-
* @since
|
|
220
|
+
* @since 0.6.0
|
|
231
221
|
* @public
|
|
232
222
|
* @group Configuration
|
|
233
223
|
*/
|
|
@@ -264,7 +254,7 @@ interface StripeConfiguration {
|
|
|
264
254
|
* };
|
|
265
255
|
* ```
|
|
266
256
|
*
|
|
267
|
-
* @since
|
|
257
|
+
* @since 0.6.0
|
|
268
258
|
* @public
|
|
269
259
|
* @group Configuration
|
|
270
260
|
*/
|
|
@@ -322,7 +312,7 @@ interface Product {
|
|
|
322
312
|
* };
|
|
323
313
|
* ```
|
|
324
314
|
*
|
|
325
|
-
* @since
|
|
315
|
+
* @since 0.6.0
|
|
326
316
|
* @public
|
|
327
317
|
* @group Configuration
|
|
328
318
|
*/
|
|
@@ -387,7 +377,7 @@ interface Price {
|
|
|
387
377
|
* ];
|
|
388
378
|
* ```
|
|
389
379
|
*
|
|
390
|
-
* @since
|
|
380
|
+
* @since 0.6.0
|
|
391
381
|
* @public
|
|
392
382
|
* @group Configuration
|
|
393
383
|
*/
|
|
@@ -427,7 +417,7 @@ interface Tier {
|
|
|
427
417
|
* };
|
|
428
418
|
* ```
|
|
429
419
|
*
|
|
430
|
-
* @since
|
|
420
|
+
* @since 0.6.0
|
|
431
421
|
* @public
|
|
432
422
|
* @group UI Configuration
|
|
433
423
|
*/
|
|
@@ -470,7 +460,7 @@ interface ProductUI {
|
|
|
470
460
|
* };
|
|
471
461
|
* ```
|
|
472
462
|
*
|
|
473
|
-
* @since
|
|
463
|
+
* @since 0.6.0
|
|
474
464
|
* @public
|
|
475
465
|
* @group UI Configuration
|
|
476
466
|
*/
|
|
@@ -501,7 +491,7 @@ interface PriceUI {
|
|
|
501
491
|
* };
|
|
502
492
|
* ```
|
|
503
493
|
*
|
|
504
|
-
* @since
|
|
494
|
+
* @since 0.6.0
|
|
505
495
|
* @public
|
|
506
496
|
* @group UI Configuration
|
|
507
497
|
*/
|
|
@@ -534,7 +524,7 @@ interface PriceDisplay {
|
|
|
534
524
|
* ];
|
|
535
525
|
* ```
|
|
536
526
|
*
|
|
537
|
-
* @since
|
|
527
|
+
* @since 0.6.0
|
|
538
528
|
* @public
|
|
539
529
|
* @group UI Configuration
|
|
540
530
|
*/
|
|
@@ -571,7 +561,7 @@ interface PriceLimit {
|
|
|
571
561
|
* });
|
|
572
562
|
* ```
|
|
573
563
|
*
|
|
574
|
-
* @since
|
|
564
|
+
* @since 0.6.0
|
|
575
565
|
* @public
|
|
576
566
|
* @group UI Configuration
|
|
577
567
|
*/
|
|
@@ -706,7 +696,7 @@ declare class ConfigManager {
|
|
|
706
696
|
* };
|
|
707
697
|
* ```
|
|
708
698
|
*
|
|
709
|
-
* @since
|
|
699
|
+
* @since 0.6.0
|
|
710
700
|
* @public
|
|
711
701
|
* @group Portal
|
|
712
702
|
*/
|
|
@@ -721,7 +711,7 @@ type PortalOptions = {
|
|
|
721
711
|
* Stripe's hosted customer portal where they can manage their
|
|
722
712
|
* billing and subscription settings.
|
|
723
713
|
*
|
|
724
|
-
* @since
|
|
714
|
+
* @since 0.6.0
|
|
725
715
|
* @public
|
|
726
716
|
* @group Portal
|
|
727
717
|
*/
|
|
@@ -741,9 +731,8 @@ type CreateCustomerPortalResponse = ApiResponse<{
|
|
|
741
731
|
* billing tasks independently.
|
|
742
732
|
*
|
|
743
733
|
* @example
|
|
744
|
-
* Creating a customer portal session:
|
|
745
734
|
* ```typescript
|
|
746
|
-
* const portalManager = new PortalManager(
|
|
735
|
+
* const portalManager = new PortalManager(omnibaseClient);
|
|
747
736
|
*
|
|
748
737
|
* const portal = await portalManager.create({
|
|
749
738
|
* return_url: 'https://app.com/billing'
|
|
@@ -753,7 +742,7 @@ type CreateCustomerPortalResponse = ApiResponse<{
|
|
|
753
742
|
* window.location.href = portal.data.url;
|
|
754
743
|
* ```
|
|
755
744
|
*
|
|
756
|
-
* @since
|
|
745
|
+
* @since 0.6.0
|
|
757
746
|
* @public
|
|
758
747
|
* @group Portal
|
|
759
748
|
*/
|
|
@@ -762,7 +751,7 @@ declare class PortalManager {
|
|
|
762
751
|
/**
|
|
763
752
|
* Initialize the portal manager
|
|
764
753
|
*
|
|
765
|
-
* @param
|
|
754
|
+
* @param omnibaseClient - OmnibaseClient instance for API communication
|
|
766
755
|
*
|
|
767
756
|
* @group Portal
|
|
768
757
|
*/
|
|
@@ -787,32 +776,18 @@ declare class PortalManager {
|
|
|
787
776
|
* @throws {ValidationError} When required parameters are missing or invalid
|
|
788
777
|
*
|
|
789
778
|
* @example
|
|
790
|
-
* Basic portal creation:
|
|
791
779
|
* ```typescript
|
|
792
780
|
* const portal = await portalManager.create({
|
|
793
781
|
* return_url: 'https://myapp.com/account/billing'
|
|
794
782
|
* });
|
|
795
783
|
*
|
|
796
784
|
* // Redirect user to portal
|
|
797
|
-
*
|
|
798
|
-
* ```
|
|
799
|
-
*
|
|
800
|
-
* @example
|
|
801
|
-
* With error handling:
|
|
802
|
-
* ```typescript
|
|
803
|
-
* try {
|
|
804
|
-
* const portal = await portalManager.create({
|
|
805
|
-
* return_url: window.location.origin + '/billing'
|
|
806
|
-
* });
|
|
807
|
-
*
|
|
785
|
+
* if (portal.data?.url) {
|
|
808
786
|
* window.location.href = portal.data.url;
|
|
809
|
-
* } catch (error) {
|
|
810
|
-
* console.error('Failed to create portal session:', error);
|
|
811
|
-
* showErrorMessage('Unable to access billing portal. Please try again.');
|
|
812
787
|
* }
|
|
813
788
|
* ```
|
|
814
789
|
*
|
|
815
|
-
* @since
|
|
790
|
+
* @since 0.6.0
|
|
816
791
|
* @group Portal
|
|
817
792
|
*/
|
|
818
793
|
create(options: PortalOptions): Promise<CreateCustomerPortalResponse>;
|
|
@@ -833,7 +808,7 @@ declare class PortalManager {
|
|
|
833
808
|
* };
|
|
834
809
|
* ```
|
|
835
810
|
*
|
|
836
|
-
* @since
|
|
811
|
+
* @since 0.6.0
|
|
837
812
|
* @public
|
|
838
813
|
* @group Usage
|
|
839
814
|
*/
|
|
@@ -860,9 +835,8 @@ type UsageOptions = {
|
|
|
860
835
|
* transparency to customers about their consumption patterns.
|
|
861
836
|
*
|
|
862
837
|
* @example
|
|
863
|
-
* Recording API usage:
|
|
864
838
|
* ```typescript
|
|
865
|
-
* const usageManager = new UsageManager(
|
|
839
|
+
* const usageManager = new UsageManager(omnibaseClient);
|
|
866
840
|
*
|
|
867
841
|
* // Record a single API call
|
|
868
842
|
* await usageManager.recordUsage({
|
|
@@ -877,7 +851,7 @@ type UsageOptions = {
|
|
|
877
851
|
* });
|
|
878
852
|
* ```
|
|
879
853
|
*
|
|
880
|
-
* @since
|
|
854
|
+
* @since 0.6.0
|
|
881
855
|
* @public
|
|
882
856
|
* @group Usage
|
|
883
857
|
*/
|
|
@@ -886,7 +860,7 @@ declare class UsageManager {
|
|
|
886
860
|
/**
|
|
887
861
|
* Initialize the usage manager
|
|
888
862
|
*
|
|
889
|
-
* @param
|
|
863
|
+
* @param omnibaseClient - OmnibaseClient instance for API communication
|
|
890
864
|
*
|
|
891
865
|
* @group Usage
|
|
892
866
|
*/
|
|
@@ -913,7 +887,6 @@ declare class UsageManager {
|
|
|
913
887
|
* @throws {ValidationError} When required parameters are missing or invalid
|
|
914
888
|
*
|
|
915
889
|
* @example
|
|
916
|
-
* API call tracking:
|
|
917
890
|
* ```typescript
|
|
918
891
|
* // Record each API call
|
|
919
892
|
* await usageManager.recordUsage({
|
|
@@ -922,37 +895,7 @@ declare class UsageManager {
|
|
|
922
895
|
* });
|
|
923
896
|
* ```
|
|
924
897
|
*
|
|
925
|
-
* @
|
|
926
|
-
* Batch usage recording:
|
|
927
|
-
* ```typescript
|
|
928
|
-
* // Record multiple operations at once
|
|
929
|
-
* const usageEvents = [
|
|
930
|
-
* { meter_event_name: 'compute_hours', value: '0.5' },
|
|
931
|
-
* { meter_event_name: 'storage_gb', value: '10' },
|
|
932
|
-
* { meter_event_name: 'api_calls', value: '50' }
|
|
933
|
-
* ];
|
|
934
|
-
*
|
|
935
|
-
* for (const event of usageEvents) {
|
|
936
|
-
* await usageManager.recordUsage(event);
|
|
937
|
-
* }
|
|
938
|
-
* ```
|
|
939
|
-
*
|
|
940
|
-
* @example
|
|
941
|
-
* With error handling:
|
|
942
|
-
* ```typescript
|
|
943
|
-
* try {
|
|
944
|
-
* await usageManager.recordUsage({
|
|
945
|
-
* meter_event_name: 'file_uploads',
|
|
946
|
-
* value: String(uploadedFiles.length)
|
|
947
|
-
* });
|
|
948
|
-
* } catch (error) {
|
|
949
|
-
* console.error('Failed to record usage:', error);
|
|
950
|
-
* // Usage recording failure shouldn't block user operations
|
|
951
|
-
* // but should be logged for billing accuracy
|
|
952
|
-
* }
|
|
953
|
-
* ```
|
|
954
|
-
*
|
|
955
|
-
* @since 1.0.0
|
|
898
|
+
* @since 0.6.0
|
|
956
899
|
* @group Usage
|
|
957
900
|
*/
|
|
958
901
|
recordUsage(options: UsageOptions): Promise<ApiResponse<"">>;
|
|
@@ -963,19 +906,20 @@ declare class UsageManager {
|
|
|
963
906
|
*
|
|
964
907
|
* This class serves as the central coordinator for all payment functionality,
|
|
965
908
|
* providing access to checkout sessions, billing configuration, customer portals,
|
|
966
|
-
* and usage tracking. It
|
|
967
|
-
*
|
|
909
|
+
* and usage tracking. It delegates specific operations to specialized managers
|
|
910
|
+
* that handle checkout, configuration, portal, and usage operations.
|
|
968
911
|
*
|
|
969
|
-
* The handler
|
|
970
|
-
*
|
|
912
|
+
* The handler provides a consistent interface across all payment operations,
|
|
913
|
+
* with automatic checkout mode detection (subscription vs one-time payment)
|
|
914
|
+
* based on the price configuration retrieved from Stripe.
|
|
971
915
|
*
|
|
972
916
|
* @example
|
|
973
917
|
* ```typescript
|
|
974
|
-
* const paymentHandler = new PaymentHandler(
|
|
918
|
+
* const paymentHandler = new PaymentHandler(omnibaseClient);
|
|
975
919
|
*
|
|
976
920
|
* // Create a checkout session (mode auto-detected from price)
|
|
977
921
|
* const checkout = await paymentHandler.checkout.createSession({
|
|
978
|
-
* price_id: '
|
|
922
|
+
* price_id: 'price_monthly_pro',
|
|
979
923
|
* success_url: 'https://app.com/success',
|
|
980
924
|
* cancel_url: 'https://app.com/cancel'
|
|
981
925
|
* });
|
|
@@ -984,27 +928,27 @@ declare class UsageManager {
|
|
|
984
928
|
* const products = await paymentHandler.config.getAvailableProducts();
|
|
985
929
|
* ```
|
|
986
930
|
*
|
|
987
|
-
* @since
|
|
931
|
+
* @since 0.6.0
|
|
988
932
|
* @public
|
|
989
933
|
* @group Client
|
|
990
934
|
*/
|
|
991
935
|
declare class PaymentHandler {
|
|
992
936
|
private omnibaseClient;
|
|
993
937
|
/**
|
|
994
|
-
* Initialize the payment handler with
|
|
938
|
+
* Initialize the payment handler with OmnibaseClient
|
|
995
939
|
*
|
|
996
|
-
* Creates a new payment handler instance
|
|
997
|
-
*
|
|
998
|
-
*
|
|
940
|
+
* Creates a new payment handler instance with access to all payment
|
|
941
|
+
* operations including checkout, configuration, portal, and usage tracking.
|
|
942
|
+
* The handler uses the provided OmnibaseClient for API communication.
|
|
999
943
|
*
|
|
1000
|
-
* @param
|
|
944
|
+
* @param omnibaseClient - OmnibaseClient instance for API communication
|
|
1001
945
|
*
|
|
1002
946
|
* @example
|
|
1003
947
|
* ```typescript
|
|
1004
|
-
* const paymentHandler = new PaymentHandler(
|
|
948
|
+
* const paymentHandler = new PaymentHandler(omnibaseClient);
|
|
1005
949
|
* ```
|
|
1006
950
|
*
|
|
1007
|
-
* @since
|
|
951
|
+
* @since 0.6.0
|
|
1008
952
|
* @group Client
|
|
1009
953
|
*/
|
|
1010
954
|
constructor(omnibaseClient: OmnibaseClient);
|
|
@@ -1017,10 +961,14 @@ declare class PaymentHandler {
|
|
|
1017
961
|
* @example
|
|
1018
962
|
* ```typescript
|
|
1019
963
|
* const session = await paymentHandler.checkout.createSession({
|
|
1020
|
-
* price_id: '
|
|
964
|
+
* price_id: 'price_monthly_pro',
|
|
1021
965
|
* success_url: window.location.origin + '/success',
|
|
1022
966
|
* cancel_url: window.location.origin + '/pricing'
|
|
1023
967
|
* });
|
|
968
|
+
*
|
|
969
|
+
* if (session.data?.url) {
|
|
970
|
+
* window.location.href = session.data.url;
|
|
971
|
+
* }
|
|
1024
972
|
* ```
|
|
1025
973
|
*/
|
|
1026
974
|
readonly checkout: CheckoutManager;
|
|
@@ -1193,9 +1141,9 @@ declare class StorageClient {
|
|
|
1193
1141
|
* };
|
|
1194
1142
|
* ```
|
|
1195
1143
|
*
|
|
1196
|
-
* @since
|
|
1144
|
+
* @since 0.6.0
|
|
1197
1145
|
* @public
|
|
1198
|
-
* @group
|
|
1146
|
+
* @group Tenant Invitations
|
|
1199
1147
|
*/
|
|
1200
1148
|
type AcceptTenantInviteRequest = {
|
|
1201
1149
|
/** Secure invitation token from the email invitation */
|
|
@@ -1220,9 +1168,9 @@ type AcceptTenantInviteRequest = {
|
|
|
1220
1168
|
* };
|
|
1221
1169
|
* ```
|
|
1222
1170
|
*
|
|
1223
|
-
* @since
|
|
1171
|
+
* @since 0.6.0
|
|
1224
1172
|
* @public
|
|
1225
|
-
* @group
|
|
1173
|
+
* @group Tenant Invitations
|
|
1226
1174
|
*/
|
|
1227
1175
|
type AcceptTenantInviteResponse = ApiResponse<{
|
|
1228
1176
|
/** ID of the tenant the user has joined */
|
|
@@ -1257,9 +1205,9 @@ type AcceptTenantInviteResponse = ApiResponse<{
|
|
|
1257
1205
|
* };
|
|
1258
1206
|
* ```
|
|
1259
1207
|
*
|
|
1260
|
-
* @since
|
|
1208
|
+
* @since 0.6.0
|
|
1261
1209
|
* @public
|
|
1262
|
-
* @group
|
|
1210
|
+
* @group Tenant Invitations
|
|
1263
1211
|
*/
|
|
1264
1212
|
type CreateTenantUserInviteResponse = ApiResponse<{
|
|
1265
1213
|
/** The newly created tenant invite */
|
|
@@ -1289,9 +1237,9 @@ type CreateTenantUserInviteResponse = ApiResponse<{
|
|
|
1289
1237
|
* };
|
|
1290
1238
|
* ```
|
|
1291
1239
|
*
|
|
1292
|
-
* @since
|
|
1240
|
+
* @since 0.6.0
|
|
1293
1241
|
* @public
|
|
1294
|
-
* @group
|
|
1242
|
+
* @group Tenant Invitations
|
|
1295
1243
|
*/
|
|
1296
1244
|
type TenantInvite = {
|
|
1297
1245
|
/** Unique identifier for the invitation */
|
|
@@ -1316,28 +1264,30 @@ type TenantInvite = {
|
|
|
1316
1264
|
/**
|
|
1317
1265
|
* Required data for creating a tenant user invitation
|
|
1318
1266
|
*
|
|
1319
|
-
* Specifies the email address of the user to invite
|
|
1320
|
-
* role within the tenant
|
|
1321
|
-
* will have once they accept the invitation.
|
|
1267
|
+
* Specifies the email address of the user to invite, their intended
|
|
1268
|
+
* role within the tenant, and the invitation URL that will be sent in the email.
|
|
1269
|
+
* The role determines what permissions the user will have once they accept the invitation.
|
|
1270
|
+
* The invite_url will be automatically appended with ?token=XYZ when sent to the user.
|
|
1322
1271
|
*
|
|
1323
1272
|
* @example
|
|
1324
1273
|
* ```typescript
|
|
1325
1274
|
* const inviteData: CreateTenantUserInviteRequest = {
|
|
1326
1275
|
* email: 'developer@company.com',
|
|
1327
|
-
* role: 'admin'
|
|
1276
|
+
* role: 'admin',
|
|
1277
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
1328
1278
|
* };
|
|
1329
1279
|
* ```
|
|
1330
1280
|
*
|
|
1331
|
-
* @since
|
|
1281
|
+
* @since 0.6.0
|
|
1332
1282
|
* @public
|
|
1333
|
-
* @group
|
|
1283
|
+
* @group Tenant Invitations
|
|
1334
1284
|
*/
|
|
1335
1285
|
type CreateTenantUserInviteRequest = {
|
|
1336
1286
|
/** Email address of the user to invite */
|
|
1337
1287
|
email: string;
|
|
1338
1288
|
/** Role the invited user will have in the tenant */
|
|
1339
1289
|
role: string;
|
|
1340
|
-
/** Invite URL - the link that will be sent to the
|
|
1290
|
+
/** Invite URL - the link that will be sent to the user's email, automatically suffixed with ?token=XYZ */
|
|
1341
1291
|
invite_url: string;
|
|
1342
1292
|
};
|
|
1343
1293
|
/**
|
|
@@ -1363,9 +1313,10 @@ type CreateTenantUserInviteRequest = {
|
|
|
1363
1313
|
* const inviteManager = new TenantInviteManager(omnibaseClient);
|
|
1364
1314
|
*
|
|
1365
1315
|
* // Create an invitation
|
|
1366
|
-
* const invite = await inviteManager.create(
|
|
1316
|
+
* const invite = await inviteManager.create({
|
|
1367
1317
|
* email: 'colleague@company.com',
|
|
1368
|
-
* role: 'member'
|
|
1318
|
+
* role: 'member',
|
|
1319
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
1369
1320
|
* });
|
|
1370
1321
|
*
|
|
1371
1322
|
* // Accept an invitation (from the invited user's session)
|
|
@@ -1373,7 +1324,7 @@ type CreateTenantUserInviteRequest = {
|
|
|
1373
1324
|
* console.log(`Joined tenant: ${result.data.tenant_id}`);
|
|
1374
1325
|
* ```
|
|
1375
1326
|
*
|
|
1376
|
-
* @since
|
|
1327
|
+
* @since 0.6.0
|
|
1377
1328
|
* @public
|
|
1378
1329
|
* @group Tenant Invitations
|
|
1379
1330
|
*/
|
|
@@ -1419,17 +1370,6 @@ declare class TenantInviteManager {
|
|
|
1419
1370
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1420
1371
|
*
|
|
1421
1372
|
* @example
|
|
1422
|
-
* Basic invitation acceptance:
|
|
1423
|
-
* ```typescript
|
|
1424
|
-
* const result = await acceptTenantInvite('inv_secure_token_abc123');
|
|
1425
|
-
*
|
|
1426
|
-
* console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
|
|
1427
|
-
* // User can now access tenant resources
|
|
1428
|
-
* await switchActiveTenant(result.data.tenant_id);
|
|
1429
|
-
* ```
|
|
1430
|
-
*
|
|
1431
|
-
* @example
|
|
1432
|
-
* Handling the invitation flow:
|
|
1433
1373
|
* ```typescript
|
|
1434
1374
|
* // Typically called from an invitation link like:
|
|
1435
1375
|
* // https://app.com/accept-invite?token=inv_secure_token_abc123
|
|
@@ -1439,80 +1379,65 @@ declare class TenantInviteManager {
|
|
|
1439
1379
|
*
|
|
1440
1380
|
* if (inviteToken) {
|
|
1441
1381
|
* try {
|
|
1442
|
-
* const result = await
|
|
1382
|
+
* const result = await inviteManager.accept(inviteToken);
|
|
1443
1383
|
*
|
|
1444
1384
|
* // Success - redirect to tenant dashboard
|
|
1385
|
+
* console.log(`Successfully joined tenant: ${result.data.tenant_id}`);
|
|
1445
1386
|
* window.location.href = `/dashboard?tenant=${result.data.tenant_id}`;
|
|
1446
1387
|
* } catch (error) {
|
|
1447
1388
|
* console.error('Failed to accept invitation:', error.message);
|
|
1448
|
-
* // Show error to user
|
|
1449
1389
|
* }
|
|
1450
1390
|
* }
|
|
1451
1391
|
* ```
|
|
1452
1392
|
*
|
|
1453
|
-
*
|
|
1454
|
-
* @since 1.0.0
|
|
1393
|
+
* @since 0.6.0
|
|
1455
1394
|
* @public
|
|
1456
|
-
* @group
|
|
1395
|
+
* @group Tenant Invitations
|
|
1457
1396
|
*/
|
|
1458
1397
|
accept(token: string): Promise<AcceptTenantInviteResponse>;
|
|
1459
1398
|
/**
|
|
1460
|
-
* Creates a new user invitation for
|
|
1399
|
+
* Creates a new user invitation for the active tenant
|
|
1461
1400
|
*
|
|
1462
|
-
* Generates a secure invitation that allows a user to join the
|
|
1463
|
-
* tenant with the defined role. The invitation is sent to the provided
|
|
1464
|
-
*
|
|
1401
|
+
* Generates a secure invitation that allows a user to join the currently active
|
|
1402
|
+
* tenant with the defined role. The invitation is sent to the provided email address
|
|
1403
|
+
* and includes a time-limited token for security. The invite URL will be automatically
|
|
1404
|
+
* appended with ?token=XYZ when sent to the user.
|
|
1465
1405
|
*
|
|
1466
|
-
* The function creates the invitation record in the database and
|
|
1467
|
-
*
|
|
1468
|
-
* The invitation expires after a predefined time period and can only
|
|
1406
|
+
* The function creates the invitation record in the database and triggers an email
|
|
1407
|
+
* notification to the invited user. The invitation expires after 7 days and can only
|
|
1469
1408
|
* be used once.
|
|
1470
1409
|
*
|
|
1471
|
-
* Only existing tenant members with appropriate permissions
|
|
1472
|
-
* invitations. The inviter's authentication
|
|
1473
|
-
* cookies sent with the request.
|
|
1410
|
+
* Only existing tenant members with appropriate permissions (invite_user permission)
|
|
1411
|
+
* can create invitations. The inviter's authentication and tenant context are validated
|
|
1412
|
+
* via HTTP-only cookies sent with the request.
|
|
1474
1413
|
*
|
|
1475
|
-
* @param tenantId - Unique identifier of the tenant to invite the user to
|
|
1476
1414
|
* @param inviteData - Configuration object for the invitation
|
|
1477
1415
|
* @param inviteData.email - Email address of the user to invite
|
|
1478
1416
|
* @param inviteData.role - Role the user will have after joining (e.g., 'member', 'admin')
|
|
1417
|
+
* @param inviteData.invite_url - Base URL for the invitation link (will be appended with ?token=XYZ)
|
|
1479
1418
|
*
|
|
1480
1419
|
* @returns Promise resolving to the created invitation with secure token
|
|
1481
1420
|
*
|
|
1482
|
-
* @throws {Error} When
|
|
1483
|
-
* @throws {Error} When
|
|
1421
|
+
* @throws {Error} When required fields (email, role, invite_url) are missing or empty
|
|
1422
|
+
* @throws {Error} When the user doesn't have permission to invite users to the tenant
|
|
1484
1423
|
* @throws {Error} When the API request fails due to network issues
|
|
1485
1424
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1486
1425
|
*
|
|
1487
1426
|
* @example
|
|
1488
|
-
* Basic invitation creation:
|
|
1489
1427
|
* ```typescript
|
|
1490
|
-
* const invite = await
|
|
1428
|
+
* const invite = await inviteManager.create({
|
|
1491
1429
|
* email: 'colleague@company.com',
|
|
1492
|
-
* role: 'member'
|
|
1430
|
+
* role: 'member',
|
|
1431
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
1493
1432
|
* });
|
|
1494
1433
|
*
|
|
1495
1434
|
* console.log(`Invite sent to: ${invite.data.invite.email}`);
|
|
1496
|
-
*
|
|
1497
|
-
* const inviteLink = `https://app.com/accept-invite?token=${invite.data.invite.token}`;
|
|
1498
|
-
* ```
|
|
1499
|
-
*
|
|
1500
|
-
* @example
|
|
1501
|
-
* Creating admin invitation:
|
|
1502
|
-
* ```typescript
|
|
1503
|
-
* const adminInvite = await createTenantUserInvite('tenant_456', {
|
|
1504
|
-
* email: 'admin@company.com',
|
|
1505
|
-
* role: 'admin'
|
|
1506
|
-
* });
|
|
1507
|
-
*
|
|
1508
|
-
* // Admin users get elevated permissions
|
|
1509
|
-
* console.log(`Admin invite created with ID: ${adminInvite.data.invite.id}`);
|
|
1435
|
+
* console.log(`Invite token: ${invite.data.invite.token}`);
|
|
1510
1436
|
* ```
|
|
1511
1437
|
*
|
|
1512
|
-
*
|
|
1513
|
-
* @since 1.0.0
|
|
1438
|
+
* @since 0.6.0
|
|
1514
1439
|
* @public
|
|
1515
|
-
* @group
|
|
1440
|
+
* @group Tenant Invitations
|
|
1516
1441
|
*/
|
|
1517
1442
|
create(inviteData: CreateTenantUserInviteRequest): Promise<CreateTenantUserInviteResponse>;
|
|
1518
1443
|
}
|
|
@@ -1540,7 +1465,7 @@ declare class TenantInviteManager {
|
|
|
1540
1465
|
* };
|
|
1541
1466
|
* ```
|
|
1542
1467
|
*
|
|
1543
|
-
* @since
|
|
1468
|
+
* @since 0.6.0
|
|
1544
1469
|
* @public
|
|
1545
1470
|
* @group Tenant Management
|
|
1546
1471
|
*/
|
|
@@ -1567,7 +1492,7 @@ type SwitchActiveTenantResponse = ApiResponse<{
|
|
|
1567
1492
|
* };
|
|
1568
1493
|
* ```
|
|
1569
1494
|
*
|
|
1570
|
-
* @since
|
|
1495
|
+
* @since 0.6.0
|
|
1571
1496
|
* @public
|
|
1572
1497
|
* @group Tenant Management
|
|
1573
1498
|
*/
|
|
@@ -1599,7 +1524,7 @@ type DeleteTenantResponse = ApiResponse<{
|
|
|
1599
1524
|
* };
|
|
1600
1525
|
* ```
|
|
1601
1526
|
*
|
|
1602
|
-
* @since
|
|
1527
|
+
* @since 0.6.0
|
|
1603
1528
|
* @public
|
|
1604
1529
|
* @group Tenant Management
|
|
1605
1530
|
*/
|
|
@@ -1630,7 +1555,7 @@ type CreateTenantResponse = ApiResponse<{
|
|
|
1630
1555
|
* };
|
|
1631
1556
|
* ```
|
|
1632
1557
|
*
|
|
1633
|
-
* @since
|
|
1558
|
+
* @since 0.6.0
|
|
1634
1559
|
* @public
|
|
1635
1560
|
* @group Tenant Management
|
|
1636
1561
|
*/
|
|
@@ -1663,7 +1588,7 @@ type Tenant = {
|
|
|
1663
1588
|
* };
|
|
1664
1589
|
* ```
|
|
1665
1590
|
*
|
|
1666
|
-
* @since
|
|
1591
|
+
* @since 0.6.0
|
|
1667
1592
|
* @public
|
|
1668
1593
|
* @group Tenant Management
|
|
1669
1594
|
*/
|
|
@@ -1710,7 +1635,7 @@ type CreateTenantRequest = {
|
|
|
1710
1635
|
* await tenantManager.deleteTenant(tenant.data.tenant.id);
|
|
1711
1636
|
* ```
|
|
1712
1637
|
*
|
|
1713
|
-
* @since
|
|
1638
|
+
* @since 0.6.0
|
|
1714
1639
|
* @public
|
|
1715
1640
|
* @group Tenant Management
|
|
1716
1641
|
*/
|
|
@@ -1751,17 +1676,17 @@ declare class TenantManger {
|
|
|
1751
1676
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1752
1677
|
*
|
|
1753
1678
|
* @example
|
|
1754
|
-
* Basic tenant creation:
|
|
1755
1679
|
* ```typescript
|
|
1756
|
-
* const newTenant = await createTenant({
|
|
1680
|
+
* const newTenant = await tenantManager.createTenant({
|
|
1757
1681
|
* name: 'Acme Corporation',
|
|
1758
1682
|
* billing_email: 'billing@acme.com',
|
|
1759
1683
|
* user_id: 'user_123'
|
|
1760
1684
|
* });
|
|
1761
|
-
* ```
|
|
1762
1685
|
*
|
|
1686
|
+
* console.log(`Tenant created: ${newTenant.data.tenant.id}`);
|
|
1687
|
+
* ```
|
|
1763
1688
|
*
|
|
1764
|
-
* @since
|
|
1689
|
+
* @since 0.6.0
|
|
1765
1690
|
* @public
|
|
1766
1691
|
* @group Tenant Management
|
|
1767
1692
|
*/
|
|
@@ -1801,7 +1726,6 @@ declare class TenantManger {
|
|
|
1801
1726
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1802
1727
|
*
|
|
1803
1728
|
* @example
|
|
1804
|
-
* Basic tenant deletion with confirmation:
|
|
1805
1729
|
* ```typescript
|
|
1806
1730
|
* const tenantToDelete = 'tenant_abc123';
|
|
1807
1731
|
*
|
|
@@ -1812,8 +1736,8 @@ declare class TenantManger {
|
|
|
1812
1736
|
*
|
|
1813
1737
|
* if (userConfirmed) {
|
|
1814
1738
|
* try {
|
|
1815
|
-
* const result = await deleteTenant(tenantToDelete);
|
|
1816
|
-
* console.log(result.data.message);
|
|
1739
|
+
* const result = await tenantManager.deleteTenant(tenantToDelete);
|
|
1740
|
+
* console.log(result.data.message);
|
|
1817
1741
|
*
|
|
1818
1742
|
* // Redirect user away from deleted tenant
|
|
1819
1743
|
* window.location.href = '/dashboard';
|
|
@@ -1823,7 +1747,7 @@ declare class TenantManger {
|
|
|
1823
1747
|
* }
|
|
1824
1748
|
* ```
|
|
1825
1749
|
*
|
|
1826
|
-
* @since
|
|
1750
|
+
* @since 0.6.0
|
|
1827
1751
|
* @public
|
|
1828
1752
|
* @group Tenant Management
|
|
1829
1753
|
*/
|
|
@@ -1859,46 +1783,17 @@ declare class TenantManger {
|
|
|
1859
1783
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
1860
1784
|
*
|
|
1861
1785
|
* @example
|
|
1862
|
-
* Basic tenant switching:
|
|
1863
1786
|
* ```typescript
|
|
1864
|
-
* const result = await switchActiveTenant('tenant_xyz789');
|
|
1787
|
+
* const result = await tenantManager.switchActiveTenant('tenant_xyz789');
|
|
1788
|
+
*
|
|
1789
|
+
* // Store the new token for future requests
|
|
1790
|
+
* console.log(`Switched to tenant. New token: ${result.data.token}`);
|
|
1865
1791
|
*
|
|
1866
1792
|
* // Now all API calls will be in the context of tenant_xyz789
|
|
1867
1793
|
* const tenantData = await getCurrentTenantData();
|
|
1868
1794
|
* ```
|
|
1869
1795
|
*
|
|
1870
|
-
* @
|
|
1871
|
-
* Using with tenant-aware data fetching:
|
|
1872
|
-
* ```typescript
|
|
1873
|
-
* // Switch tenant and immediately fetch tenant-specific data
|
|
1874
|
-
* const switchAndLoadTenant = async (tenantId: string) => {
|
|
1875
|
-
* try {
|
|
1876
|
-
* // Switch to new tenant context
|
|
1877
|
-
* const switchResult = await switchActiveTenant(tenantId);
|
|
1878
|
-
*
|
|
1879
|
-
* // Update authentication token
|
|
1880
|
-
* setAuthToken(switchResult.data.token);
|
|
1881
|
-
*
|
|
1882
|
-
* // Fetch data in new tenant context
|
|
1883
|
-
* const [tenantInfo, userPermissions, tenantSettings] = await Promise.all([
|
|
1884
|
-
* getTenantInfo(),
|
|
1885
|
-
* getUserPermissions(),
|
|
1886
|
-
* getTenantSettings()
|
|
1887
|
-
* ]);
|
|
1888
|
-
*
|
|
1889
|
-
* return {
|
|
1890
|
-
* tenant: tenantInfo,
|
|
1891
|
-
* permissions: userPermissions,
|
|
1892
|
-
* settings: tenantSettings
|
|
1893
|
-
* };
|
|
1894
|
-
* } catch (error) {
|
|
1895
|
-
* console.error('Failed to switch tenant and load data:', error);
|
|
1896
|
-
* throw error;
|
|
1897
|
-
* }
|
|
1898
|
-
* };
|
|
1899
|
-
* ```
|
|
1900
|
-
*
|
|
1901
|
-
* @since 1.0.0
|
|
1796
|
+
* @since 0.6.0
|
|
1902
1797
|
* @public
|
|
1903
1798
|
* @group Tenant Management
|
|
1904
1799
|
*/
|
|
@@ -1920,7 +1815,7 @@ declare class TenantManger {
|
|
|
1920
1815
|
* };
|
|
1921
1816
|
* ```
|
|
1922
1817
|
*
|
|
1923
|
-
* @since
|
|
1818
|
+
* @since 0.6.0
|
|
1924
1819
|
* @public
|
|
1925
1820
|
* @group Tenant User Management
|
|
1926
1821
|
*/
|
|
@@ -1958,7 +1853,7 @@ type UpdateTenantUserRoleResponse = ApiResponse<{
|
|
|
1958
1853
|
* };
|
|
1959
1854
|
* ```
|
|
1960
1855
|
*
|
|
1961
|
-
* @since
|
|
1856
|
+
* @since 0.6.0
|
|
1962
1857
|
* @public
|
|
1963
1858
|
* @group Tenant User Management
|
|
1964
1859
|
*/
|
|
@@ -1987,7 +1882,7 @@ type RemoveUserRequest = {
|
|
|
1987
1882
|
* await userManager.remove({ user_id: 'user_123' });
|
|
1988
1883
|
* ```
|
|
1989
1884
|
*
|
|
1990
|
-
* @since
|
|
1885
|
+
* @since 0.6.0
|
|
1991
1886
|
* @public
|
|
1992
1887
|
* @group Tenant User Management
|
|
1993
1888
|
*/
|
|
@@ -2038,7 +1933,7 @@ declare class TenantUserManager {
|
|
|
2038
1933
|
* }
|
|
2039
1934
|
* ```
|
|
2040
1935
|
*
|
|
2041
|
-
* @since
|
|
1936
|
+
* @since 0.6.0
|
|
2042
1937
|
* @public
|
|
2043
1938
|
* @group Tenant User Management
|
|
2044
1939
|
*/
|
|
@@ -2087,7 +1982,7 @@ declare class TenantUserManager {
|
|
|
2087
1982
|
* }
|
|
2088
1983
|
* ```
|
|
2089
1984
|
*
|
|
2090
|
-
* @since
|
|
1985
|
+
* @since 0.6.0
|
|
2091
1986
|
* @public
|
|
2092
1987
|
* @group Tenant User Management
|
|
2093
1988
|
*/
|
|
@@ -2098,13 +1993,14 @@ declare class TenantUserManager {
|
|
|
2098
1993
|
* Main tenant management handler
|
|
2099
1994
|
*
|
|
2100
1995
|
* This is the primary entry point for all tenant-related operations in the
|
|
2101
|
-
* Omnibase SDK. It provides a unified interface to
|
|
2102
|
-
* and invitation functionality through dedicated manager instances.
|
|
1996
|
+
* Omnibase SDK. It provides a unified interface to tenant management,
|
|
1997
|
+
* user management, and invitation functionality through dedicated manager instances.
|
|
2103
1998
|
*
|
|
2104
1999
|
* The handler follows the composition pattern, combining specialized managers
|
|
2105
2000
|
* for different aspects of tenant functionality:
|
|
2106
|
-
* - `
|
|
2001
|
+
* - `manage`: Core tenant operations (create, delete, switch)
|
|
2107
2002
|
* - `invites`: User invitation management (create, accept)
|
|
2003
|
+
* - `user`: Tenant user operations (remove, update role)
|
|
2108
2004
|
*
|
|
2109
2005
|
* All operations are performed within the context of the authenticated user
|
|
2110
2006
|
* and respect tenant-level permissions and row-level security policies.
|
|
@@ -2118,23 +2014,24 @@ declare class TenantUserManager {
|
|
|
2118
2014
|
* const tenantHandler = new TenantHandler(client);
|
|
2119
2015
|
*
|
|
2120
2016
|
* // Create a new tenant
|
|
2121
|
-
* const tenant = await tenantHandler.
|
|
2017
|
+
* const tenant = await tenantHandler.manage.createTenant({
|
|
2122
2018
|
* name: 'My Company',
|
|
2123
2019
|
* billing_email: 'billing@company.com',
|
|
2124
2020
|
* user_id: 'user_123'
|
|
2125
2021
|
* });
|
|
2126
2022
|
*
|
|
2127
2023
|
* // Invite users to the tenant
|
|
2128
|
-
* const invite = await tenantHandler.invites.create(
|
|
2024
|
+
* const invite = await tenantHandler.invites.create({
|
|
2129
2025
|
* email: 'colleague@company.com',
|
|
2130
|
-
* role: 'member'
|
|
2026
|
+
* role: 'member',
|
|
2027
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
2131
2028
|
* });
|
|
2132
2029
|
*
|
|
2133
2030
|
* // Switch to the new tenant
|
|
2134
|
-
* await tenantHandler.
|
|
2031
|
+
* await tenantHandler.manage.switchActiveTenant(tenant.data.tenant.id);
|
|
2135
2032
|
* ```
|
|
2136
2033
|
*
|
|
2137
|
-
* @since
|
|
2034
|
+
* @since 0.6.0
|
|
2138
2035
|
* @public
|
|
2139
2036
|
* @group Tenant Management
|
|
2140
2037
|
*/
|
|
@@ -2173,7 +2070,7 @@ declare class TenantHandler {
|
|
|
2173
2070
|
* await tenantHandler.user.remove({ user_id: 'user_123' });
|
|
2174
2071
|
* ```
|
|
2175
2072
|
*
|
|
2176
|
-
* @since
|
|
2073
|
+
* @since 0.6.0
|
|
2177
2074
|
* @group Tenant Management
|
|
2178
2075
|
*/
|
|
2179
2076
|
readonly user: TenantUserManager;
|
|
@@ -2187,17 +2084,17 @@ declare class TenantHandler {
|
|
|
2187
2084
|
* @example
|
|
2188
2085
|
* ```typescript
|
|
2189
2086
|
* // Create a new tenant
|
|
2190
|
-
* const tenant = await tenantHandler.
|
|
2087
|
+
* const tenant = await tenantHandler.manage.createTenant({
|
|
2191
2088
|
* name: 'New Company',
|
|
2192
2089
|
* billing_email: 'billing@newcompany.com',
|
|
2193
2090
|
* user_id: 'user_456'
|
|
2194
2091
|
* });
|
|
2195
2092
|
*
|
|
2196
2093
|
* // Switch to the tenant
|
|
2197
|
-
* await tenantHandler.
|
|
2094
|
+
* await tenantHandler.manage.switchActiveTenant(tenant.data.tenant.id);
|
|
2198
2095
|
*
|
|
2199
2096
|
* // Delete the tenant (owner only)
|
|
2200
|
-
* await tenantHandler.
|
|
2097
|
+
* await tenantHandler.manage.deleteTenant(tenant.data.tenant.id);
|
|
2201
2098
|
* ```
|
|
2202
2099
|
*/
|
|
2203
2100
|
readonly manage: TenantManger;
|
|
@@ -2211,9 +2108,10 @@ declare class TenantHandler {
|
|
|
2211
2108
|
* @example
|
|
2212
2109
|
* ```typescript
|
|
2213
2110
|
* // Create an invitation
|
|
2214
|
-
* const invite = await tenantHandler.invites.create(
|
|
2111
|
+
* const invite = await tenantHandler.invites.create({
|
|
2215
2112
|
* email: 'newuser@company.com',
|
|
2216
|
-
* role: 'admin'
|
|
2113
|
+
* role: 'admin',
|
|
2114
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
2217
2115
|
* });
|
|
2218
2116
|
*
|
|
2219
2117
|
* // Accept an invitation (from the invited user's session)
|
|
@@ -2255,7 +2153,90 @@ declare class OmnibaseClient {
|
|
|
2255
2153
|
* ```
|
|
2256
2154
|
*/
|
|
2257
2155
|
readonly payments: PaymentHandler;
|
|
2156
|
+
/**
|
|
2157
|
+
* Main tenant management handler
|
|
2158
|
+
*
|
|
2159
|
+
* This is the primary entry point for all tenant-related operations in the
|
|
2160
|
+
* Omnibase SDK. It provides a unified interface to tenant management,
|
|
2161
|
+
* user management, and invitation functionality through dedicated manager instances.
|
|
2162
|
+
*
|
|
2163
|
+
* The handler follows the composition pattern, combining specialized managers
|
|
2164
|
+
* for different aspects of tenant functionality:
|
|
2165
|
+
* - `manage`: Core tenant operations (create, delete, switch)
|
|
2166
|
+
* - `invites`: User invitation management (create, accept)
|
|
2167
|
+
* - `user`: Tenant user operations (remove, update role)
|
|
2168
|
+
*
|
|
2169
|
+
* All operations are performed within the context of the authenticated user
|
|
2170
|
+
* and respect tenant-level permissions and row-level security policies.
|
|
2171
|
+
*
|
|
2172
|
+
* @example
|
|
2173
|
+
* ```typescript
|
|
2174
|
+
* // Create a new tenant
|
|
2175
|
+
* const tenant = await omnibase.tenants.manage.createTenant({
|
|
2176
|
+
* name: 'My Company',
|
|
2177
|
+
* billing_email: 'billing@company.com',
|
|
2178
|
+
* user_id: 'user_123'
|
|
2179
|
+
* });
|
|
2180
|
+
*
|
|
2181
|
+
* // Invite users to the tenant
|
|
2182
|
+
* const invite = await omnibase.tenants.invites.create({
|
|
2183
|
+
* email: 'colleague@company.com',
|
|
2184
|
+
* role: 'member',
|
|
2185
|
+
* invite_url: 'https://yourapp.com/accept-invite'
|
|
2186
|
+
* });
|
|
2187
|
+
*
|
|
2188
|
+
* // Switch to the new tenant
|
|
2189
|
+
* await omnibase.tenants.manage.switchActiveTenant(tenant.data.tenant.id);
|
|
2190
|
+
* ```
|
|
2191
|
+
*
|
|
2192
|
+
* @since 0.6.0
|
|
2193
|
+
* @public
|
|
2194
|
+
* @group Tenant Management
|
|
2195
|
+
*/
|
|
2258
2196
|
readonly tenants: TenantHandler;
|
|
2197
|
+
/**
|
|
2198
|
+
* Client for managing permissions and relationships using Ory Keto
|
|
2199
|
+
*
|
|
2200
|
+
* This client provides access to Ory Keto's permission system, allowing you to
|
|
2201
|
+
* create, manage, and check relationships between subjects and objects. It handles
|
|
2202
|
+
* both read operations (permission checks) and write operations (relationship management).
|
|
2203
|
+
*
|
|
2204
|
+
* The client automatically configures separate endpoints for read and write operations
|
|
2205
|
+
* to optimize performance and security by following Ory Keto's recommended architecture.
|
|
2206
|
+
*
|
|
2207
|
+
* @example
|
|
2208
|
+
* ```typescript
|
|
2209
|
+
* // Check if a user can view a tenant
|
|
2210
|
+
* const canView = await omnibase.permissions.permissions.checkPermission(
|
|
2211
|
+
* undefined,
|
|
2212
|
+
* {
|
|
2213
|
+
* namespace: 'Tenant',
|
|
2214
|
+
* object: 'tenant_123',
|
|
2215
|
+
* relation: 'view',
|
|
2216
|
+
* subjectId: 'user_456'
|
|
2217
|
+
* }
|
|
2218
|
+
* );
|
|
2219
|
+
*
|
|
2220
|
+
* if (canView.data.allowed) {
|
|
2221
|
+
* console.log('User can view the tenant');
|
|
2222
|
+
* }
|
|
2223
|
+
*
|
|
2224
|
+
* // Create a relationship making a user an owner of a tenant
|
|
2225
|
+
* await omnibase.permissions.relationships.createRelationship(
|
|
2226
|
+
* undefined,
|
|
2227
|
+
* {
|
|
2228
|
+
* namespace: 'Tenant',
|
|
2229
|
+
* object: 'tenant_123',
|
|
2230
|
+
* relation: 'owners',
|
|
2231
|
+
* subjectId: 'user_456'
|
|
2232
|
+
* }
|
|
2233
|
+
* );
|
|
2234
|
+
* ```
|
|
2235
|
+
*
|
|
2236
|
+
* @since 0.6.0
|
|
2237
|
+
* @public
|
|
2238
|
+
* @group Permissions
|
|
2239
|
+
*/
|
|
2259
2240
|
readonly permissions: PermissionsClient;
|
|
2260
2241
|
/**
|
|
2261
2242
|
* Storage client for file upload/download operations
|