@omnibase/core-js 0.3.0 → 0.4.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 +1 -1
- package/dist/payments/index.cjs +195 -0
- package/dist/payments/index.d.cts +191 -0
- package/dist/payments/index.d.ts +191 -0
- package/dist/payments/index.js +163 -0
- package/dist/tenants/index.cjs +10 -10
- package/dist/tenants/index.d.cts +5 -5
- package/dist/tenants/index.d.ts +5 -5
- package/dist/tenants/index.js +10 -10
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -257,7 +257,7 @@ The SDK requires environment configuration for proper operation:
|
|
|
257
257
|
|
|
258
258
|
```bash
|
|
259
259
|
# Required environment variables
|
|
260
|
-
|
|
260
|
+
OMNIBASE_AUTH_URL=https://your-auth-endpoint.com
|
|
261
261
|
|
|
262
262
|
# Optional database configuration
|
|
263
263
|
DATABASE_URL=postgresql://user:pass@host:5432/dbname
|
|
@@ -0,0 +1,195 @@
|
|
|
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/payments/index.ts
|
|
21
|
+
var payments_exports = {};
|
|
22
|
+
__export(payments_exports, {
|
|
23
|
+
createCheckout: () => createCheckout,
|
|
24
|
+
createCustomerPortal: () => createCustomerPortal,
|
|
25
|
+
getAvailableProducts: () => getAvailableProducts,
|
|
26
|
+
getProduct: () => getProduct,
|
|
27
|
+
getStripeConfig: () => getStripeConfig,
|
|
28
|
+
recordUsage: () => recordUsage
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(payments_exports);
|
|
31
|
+
|
|
32
|
+
// src/payments/config.ts
|
|
33
|
+
async function getStripeConfig() {
|
|
34
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
35
|
+
if (!baseUrl) {
|
|
36
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const response = await fetch(`${baseUrl}/api/v1/stripe/config`, {
|
|
40
|
+
method: "GET",
|
|
41
|
+
headers: {
|
|
42
|
+
"Content-Type": "application/json"
|
|
43
|
+
},
|
|
44
|
+
credentials: "include"
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const errorData = await response.text();
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Failed to get Stripe config: ${response.status} - ${errorData}`
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
return data;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error("Error getting Stripe config:", error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function getAvailableProducts() {
|
|
60
|
+
const configResponse = await getStripeConfig();
|
|
61
|
+
if (!configResponse.data?.config) {
|
|
62
|
+
throw new Error("No Stripe configuration found");
|
|
63
|
+
}
|
|
64
|
+
const products = configResponse.data.config.products;
|
|
65
|
+
return products.map(transformProductToUIReady).sort(
|
|
66
|
+
(a, b) => a.pricing_display.sort_order - b.pricing_display.sort_order
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
async function getProduct(productId) {
|
|
70
|
+
const configResponse = await getStripeConfig();
|
|
71
|
+
if (!configResponse.data?.config) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const product = configResponse.data.config.products.find(
|
|
75
|
+
(p) => p.id === productId
|
|
76
|
+
);
|
|
77
|
+
return product || null;
|
|
78
|
+
}
|
|
79
|
+
function transformProductToUIReady(product) {
|
|
80
|
+
const ui = product.ui || {};
|
|
81
|
+
return {
|
|
82
|
+
...product,
|
|
83
|
+
pricing_display: {
|
|
84
|
+
name: ui.display_name || product.name,
|
|
85
|
+
tagline: ui.tagline,
|
|
86
|
+
features: ui.features || [],
|
|
87
|
+
badge: ui.badge,
|
|
88
|
+
cta_text: ui.cta_text || "Choose Plan",
|
|
89
|
+
highlighted: ui.highlighted || false,
|
|
90
|
+
sort_order: ui.sort_order || 0,
|
|
91
|
+
prices: product.prices.map((price) => {
|
|
92
|
+
const priceUI = price.ui || {};
|
|
93
|
+
return {
|
|
94
|
+
id: price.id,
|
|
95
|
+
display_name: priceUI.display_name || formatDefaultPriceName(price),
|
|
96
|
+
formatted_price: formatPrice(price, priceUI),
|
|
97
|
+
billing_period: priceUI.billing_period || formatDefaultBillingPeriod(price),
|
|
98
|
+
features: priceUI.features || [],
|
|
99
|
+
limits: priceUI.limits || []
|
|
100
|
+
};
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function formatPrice(price, priceUI) {
|
|
106
|
+
if (priceUI.price_display?.custom_text) {
|
|
107
|
+
return priceUI.price_display.custom_text;
|
|
108
|
+
}
|
|
109
|
+
if (!price.amount || price.amount === 0) {
|
|
110
|
+
return "Free";
|
|
111
|
+
}
|
|
112
|
+
const amount = price.amount / 100;
|
|
113
|
+
const currency = price.currency.toUpperCase();
|
|
114
|
+
let formattedPrice = "";
|
|
115
|
+
if (priceUI.price_display?.show_currency !== false) {
|
|
116
|
+
const currencySymbol = getCurrencySymbol(currency);
|
|
117
|
+
formattedPrice = `${currencySymbol}${amount.toFixed(2)}`;
|
|
118
|
+
} else {
|
|
119
|
+
formattedPrice = amount.toFixed(2);
|
|
120
|
+
}
|
|
121
|
+
if (priceUI.price_display?.suffix) {
|
|
122
|
+
formattedPrice += ` ${priceUI.price_display.suffix}`;
|
|
123
|
+
}
|
|
124
|
+
return formattedPrice;
|
|
125
|
+
}
|
|
126
|
+
function getCurrencySymbol(currency) {
|
|
127
|
+
const symbols = {
|
|
128
|
+
USD: "$",
|
|
129
|
+
EUR: "\u20AC",
|
|
130
|
+
GBP: "\xA3",
|
|
131
|
+
JPY: "\xA5",
|
|
132
|
+
CAD: "C$",
|
|
133
|
+
AUD: "A$"
|
|
134
|
+
};
|
|
135
|
+
return symbols[currency] || currency;
|
|
136
|
+
}
|
|
137
|
+
function formatDefaultPriceName(price) {
|
|
138
|
+
if (price.interval) {
|
|
139
|
+
return price.interval.charAt(0).toUpperCase() + price.interval.slice(1);
|
|
140
|
+
}
|
|
141
|
+
return "One-time";
|
|
142
|
+
}
|
|
143
|
+
function formatDefaultBillingPeriod(price) {
|
|
144
|
+
if (price.interval) {
|
|
145
|
+
const count = price.interval_count || 1;
|
|
146
|
+
const period = count === 1 ? price.interval : `${count} ${price.interval}s`;
|
|
147
|
+
return `per ${period}`;
|
|
148
|
+
}
|
|
149
|
+
return "one-time";
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// src/payments/checkout.ts
|
|
153
|
+
var API_URL = process.env.OMNIBASE_API_URL;
|
|
154
|
+
if (!API_URL) throw new Error("must set OMNIBASE_API_URL in env variables");
|
|
155
|
+
var createCheckout = async (options) => {
|
|
156
|
+
const response = await fetch(API_URL + "/api/v1/payments/checkout", {
|
|
157
|
+
method: "POST",
|
|
158
|
+
body: JSON.stringify(options)
|
|
159
|
+
});
|
|
160
|
+
const result = await response.json();
|
|
161
|
+
return result;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// src/payments/portal.ts
|
|
165
|
+
var API_URL2 = process.env.OMNIBASE_API_URL;
|
|
166
|
+
if (!API_URL2) throw new Error("must set OMNIBASE_API_URL in env variables");
|
|
167
|
+
var createCustomerPortal = async (options) => {
|
|
168
|
+
const response = await fetch(API_URL2 + "/api/v1/payments/portal", {
|
|
169
|
+
method: "POST",
|
|
170
|
+
body: JSON.stringify(options)
|
|
171
|
+
});
|
|
172
|
+
const result = await response.json();
|
|
173
|
+
return result;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/payments/usage.ts
|
|
177
|
+
var API_URL3 = process.env.OMNIBASE_API_URL;
|
|
178
|
+
if (!API_URL3) throw new Error("must set OMNIBASE_API_URL in env variables");
|
|
179
|
+
var recordUsage = async (options) => {
|
|
180
|
+
const response = await fetch(API_URL3 + "/api/v1/payments/usage", {
|
|
181
|
+
method: "POST",
|
|
182
|
+
body: JSON.stringify(options)
|
|
183
|
+
});
|
|
184
|
+
const result = await response.json();
|
|
185
|
+
return result;
|
|
186
|
+
};
|
|
187
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
188
|
+
0 && (module.exports = {
|
|
189
|
+
createCheckout,
|
|
190
|
+
createCustomerPortal,
|
|
191
|
+
getAvailableProducts,
|
|
192
|
+
getProduct,
|
|
193
|
+
getStripeConfig,
|
|
194
|
+
recordUsage
|
|
195
|
+
});
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { A as ApiResponse } from '../types-DgsX5kVK.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stripe configuration types mirroring the Go structs and JSON schema
|
|
5
|
+
*/
|
|
6
|
+
type StripeConfigResponse = ApiResponse<{
|
|
7
|
+
config: StripeConfiguration;
|
|
8
|
+
message?: string;
|
|
9
|
+
}>;
|
|
10
|
+
interface StripeConfiguration {
|
|
11
|
+
version: string;
|
|
12
|
+
products: Product[];
|
|
13
|
+
}
|
|
14
|
+
interface Product {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
type?: "service" | "good" | "metered";
|
|
19
|
+
prices: Price[];
|
|
20
|
+
ui?: ProductUI;
|
|
21
|
+
}
|
|
22
|
+
interface Price {
|
|
23
|
+
id: string;
|
|
24
|
+
amount?: number;
|
|
25
|
+
currency: string;
|
|
26
|
+
interval?: "month" | "year" | "week" | "day";
|
|
27
|
+
interval_count?: number;
|
|
28
|
+
usage_type?: "licensed" | "metered";
|
|
29
|
+
billing_scheme?: "per_unit" | "tiered";
|
|
30
|
+
tiers_mode?: "graduated" | "volume";
|
|
31
|
+
tiers?: Tier[];
|
|
32
|
+
ui?: PriceUI;
|
|
33
|
+
}
|
|
34
|
+
interface Tier {
|
|
35
|
+
up_to: number | "inf";
|
|
36
|
+
flat_amount?: number;
|
|
37
|
+
unit_amount?: number;
|
|
38
|
+
}
|
|
39
|
+
interface ProductUI {
|
|
40
|
+
display_name?: string;
|
|
41
|
+
tagline?: string;
|
|
42
|
+
features?: string[];
|
|
43
|
+
badge?: string;
|
|
44
|
+
cta_text?: string;
|
|
45
|
+
highlighted?: boolean;
|
|
46
|
+
sort_order?: number;
|
|
47
|
+
}
|
|
48
|
+
interface PriceUI {
|
|
49
|
+
display_name?: string;
|
|
50
|
+
price_display?: PriceDisplay;
|
|
51
|
+
billing_period?: string;
|
|
52
|
+
features?: string[];
|
|
53
|
+
limits?: PriceLimit[];
|
|
54
|
+
}
|
|
55
|
+
interface PriceDisplay {
|
|
56
|
+
custom_text?: string;
|
|
57
|
+
show_currency?: boolean;
|
|
58
|
+
suffix?: string;
|
|
59
|
+
}
|
|
60
|
+
interface PriceLimit {
|
|
61
|
+
text: string;
|
|
62
|
+
value?: number;
|
|
63
|
+
unit?: string;
|
|
64
|
+
}
|
|
65
|
+
interface ProductWithPricingUI extends Product {
|
|
66
|
+
pricing_display: {
|
|
67
|
+
name: string;
|
|
68
|
+
tagline?: string;
|
|
69
|
+
features: string[];
|
|
70
|
+
badge?: string;
|
|
71
|
+
cta_text: string;
|
|
72
|
+
highlighted: boolean;
|
|
73
|
+
sort_order: number;
|
|
74
|
+
prices: Array<{
|
|
75
|
+
id: string;
|
|
76
|
+
display_name: string;
|
|
77
|
+
formatted_price: string;
|
|
78
|
+
billing_period: string;
|
|
79
|
+
features: string[];
|
|
80
|
+
limits: Array<{
|
|
81
|
+
text: string;
|
|
82
|
+
value?: number;
|
|
83
|
+
unit?: string;
|
|
84
|
+
}>;
|
|
85
|
+
}>;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get the current Stripe configuration from the database
|
|
91
|
+
*
|
|
92
|
+
* Retrieves the latest Stripe configuration including products, prices,
|
|
93
|
+
* and UI customization data. This configuration represents the current
|
|
94
|
+
* active pricing structure with all UI elements for pricing table rendering.
|
|
95
|
+
*
|
|
96
|
+
* @returns Promise resolving to the current Stripe configuration
|
|
97
|
+
*
|
|
98
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
99
|
+
* @throws {Error} When the API request fails due to network issues
|
|
100
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* Basic usage:
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const config = await getStripeConfig();
|
|
106
|
+
* console.log(`Found ${config.data.config.products.length} products`);
|
|
107
|
+
*
|
|
108
|
+
* // Access product UI configuration
|
|
109
|
+
* config.data.config.products.forEach(product => {
|
|
110
|
+
* console.log(`${product.name}: ${product.ui?.tagline || 'No tagline'}`);
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function getStripeConfig(): Promise<StripeConfigResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* Get available products with UI-ready pricing data
|
|
117
|
+
*
|
|
118
|
+
* Transforms the raw Stripe configuration into UI-ready format for pricing
|
|
119
|
+
* table rendering. Includes formatted pricing, features, limits, and all
|
|
120
|
+
* display customizations needed for marketing pages.
|
|
121
|
+
*
|
|
122
|
+
* @returns Promise resolving to products ready for UI consumption
|
|
123
|
+
*
|
|
124
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
125
|
+
* @throws {Error} When the API request fails or configuration is invalid
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* Pricing table rendering:
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const products = await getAvailableProducts();
|
|
131
|
+
*
|
|
132
|
+
* products.forEach(product => {
|
|
133
|
+
* const display = product.pricing_display;
|
|
134
|
+
* console.log(`${display.name} - ${display.tagline}`);
|
|
135
|
+
*
|
|
136
|
+
* display.prices.forEach(price => {
|
|
137
|
+
* console.log(` ${price.display_name}: ${price.formatted_price}`);
|
|
138
|
+
* });
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function getAvailableProducts(): Promise<ProductWithPricingUI[]>;
|
|
143
|
+
/**
|
|
144
|
+
* Get a specific product by ID
|
|
145
|
+
*
|
|
146
|
+
* Retrieves a single product configuration by its ID from the current
|
|
147
|
+
* Stripe configuration. Useful for product-specific operations.
|
|
148
|
+
*
|
|
149
|
+
* @param productId - The configuration product ID to retrieve
|
|
150
|
+
* @returns Promise resolving to the product or null if not found
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const product = await getProduct('starter_plan');
|
|
155
|
+
* if (product) {
|
|
156
|
+
* console.log(`Found product: ${product.name}`);
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function getProduct(productId: string): Promise<Product | null>;
|
|
161
|
+
|
|
162
|
+
type CheckoutOptions = {
|
|
163
|
+
priceId: string;
|
|
164
|
+
mode: "payment" | "subscription";
|
|
165
|
+
successUrl: string;
|
|
166
|
+
cancelUrl: string;
|
|
167
|
+
customerId?: string;
|
|
168
|
+
};
|
|
169
|
+
type CreateCheckoutResponse = ApiResponse<{
|
|
170
|
+
url: string;
|
|
171
|
+
sessionId: string;
|
|
172
|
+
}>;
|
|
173
|
+
declare const createCheckout: (options: CheckoutOptions) => Promise<CreateCheckoutResponse>;
|
|
174
|
+
|
|
175
|
+
type PortalOptions = {
|
|
176
|
+
customer_id: string;
|
|
177
|
+
return_url: string;
|
|
178
|
+
};
|
|
179
|
+
type CreateCustomerPortalResponse = ApiResponse<{
|
|
180
|
+
url: string;
|
|
181
|
+
}>;
|
|
182
|
+
declare const createCustomerPortal: (options: PortalOptions) => Promise<CreateCustomerPortalResponse>;
|
|
183
|
+
|
|
184
|
+
type UsageOptions = {
|
|
185
|
+
meter_event_name: string;
|
|
186
|
+
customer_id: string;
|
|
187
|
+
value: string;
|
|
188
|
+
};
|
|
189
|
+
declare const recordUsage: (options: UsageOptions) => Promise<ApiResponse<"">>;
|
|
190
|
+
|
|
191
|
+
export { type CheckoutOptions, type CreateCheckoutResponse, type CreateCustomerPortalResponse, type PortalOptions, type Price, type PriceDisplay, type PriceLimit, type PriceUI, type Product, type ProductUI, type ProductWithPricingUI, type StripeConfigResponse, type StripeConfiguration, type Tier, type UsageOptions, createCheckout, createCustomerPortal, getAvailableProducts, getProduct, getStripeConfig, recordUsage };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { A as ApiResponse } from '../types-DgsX5kVK.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stripe configuration types mirroring the Go structs and JSON schema
|
|
5
|
+
*/
|
|
6
|
+
type StripeConfigResponse = ApiResponse<{
|
|
7
|
+
config: StripeConfiguration;
|
|
8
|
+
message?: string;
|
|
9
|
+
}>;
|
|
10
|
+
interface StripeConfiguration {
|
|
11
|
+
version: string;
|
|
12
|
+
products: Product[];
|
|
13
|
+
}
|
|
14
|
+
interface Product {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
description?: string;
|
|
18
|
+
type?: "service" | "good" | "metered";
|
|
19
|
+
prices: Price[];
|
|
20
|
+
ui?: ProductUI;
|
|
21
|
+
}
|
|
22
|
+
interface Price {
|
|
23
|
+
id: string;
|
|
24
|
+
amount?: number;
|
|
25
|
+
currency: string;
|
|
26
|
+
interval?: "month" | "year" | "week" | "day";
|
|
27
|
+
interval_count?: number;
|
|
28
|
+
usage_type?: "licensed" | "metered";
|
|
29
|
+
billing_scheme?: "per_unit" | "tiered";
|
|
30
|
+
tiers_mode?: "graduated" | "volume";
|
|
31
|
+
tiers?: Tier[];
|
|
32
|
+
ui?: PriceUI;
|
|
33
|
+
}
|
|
34
|
+
interface Tier {
|
|
35
|
+
up_to: number | "inf";
|
|
36
|
+
flat_amount?: number;
|
|
37
|
+
unit_amount?: number;
|
|
38
|
+
}
|
|
39
|
+
interface ProductUI {
|
|
40
|
+
display_name?: string;
|
|
41
|
+
tagline?: string;
|
|
42
|
+
features?: string[];
|
|
43
|
+
badge?: string;
|
|
44
|
+
cta_text?: string;
|
|
45
|
+
highlighted?: boolean;
|
|
46
|
+
sort_order?: number;
|
|
47
|
+
}
|
|
48
|
+
interface PriceUI {
|
|
49
|
+
display_name?: string;
|
|
50
|
+
price_display?: PriceDisplay;
|
|
51
|
+
billing_period?: string;
|
|
52
|
+
features?: string[];
|
|
53
|
+
limits?: PriceLimit[];
|
|
54
|
+
}
|
|
55
|
+
interface PriceDisplay {
|
|
56
|
+
custom_text?: string;
|
|
57
|
+
show_currency?: boolean;
|
|
58
|
+
suffix?: string;
|
|
59
|
+
}
|
|
60
|
+
interface PriceLimit {
|
|
61
|
+
text: string;
|
|
62
|
+
value?: number;
|
|
63
|
+
unit?: string;
|
|
64
|
+
}
|
|
65
|
+
interface ProductWithPricingUI extends Product {
|
|
66
|
+
pricing_display: {
|
|
67
|
+
name: string;
|
|
68
|
+
tagline?: string;
|
|
69
|
+
features: string[];
|
|
70
|
+
badge?: string;
|
|
71
|
+
cta_text: string;
|
|
72
|
+
highlighted: boolean;
|
|
73
|
+
sort_order: number;
|
|
74
|
+
prices: Array<{
|
|
75
|
+
id: string;
|
|
76
|
+
display_name: string;
|
|
77
|
+
formatted_price: string;
|
|
78
|
+
billing_period: string;
|
|
79
|
+
features: string[];
|
|
80
|
+
limits: Array<{
|
|
81
|
+
text: string;
|
|
82
|
+
value?: number;
|
|
83
|
+
unit?: string;
|
|
84
|
+
}>;
|
|
85
|
+
}>;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Get the current Stripe configuration from the database
|
|
91
|
+
*
|
|
92
|
+
* Retrieves the latest Stripe configuration including products, prices,
|
|
93
|
+
* and UI customization data. This configuration represents the current
|
|
94
|
+
* active pricing structure with all UI elements for pricing table rendering.
|
|
95
|
+
*
|
|
96
|
+
* @returns Promise resolving to the current Stripe configuration
|
|
97
|
+
*
|
|
98
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
99
|
+
* @throws {Error} When the API request fails due to network issues
|
|
100
|
+
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* Basic usage:
|
|
104
|
+
* ```typescript
|
|
105
|
+
* const config = await getStripeConfig();
|
|
106
|
+
* console.log(`Found ${config.data.config.products.length} products`);
|
|
107
|
+
*
|
|
108
|
+
* // Access product UI configuration
|
|
109
|
+
* config.data.config.products.forEach(product => {
|
|
110
|
+
* console.log(`${product.name}: ${product.ui?.tagline || 'No tagline'}`);
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
declare function getStripeConfig(): Promise<StripeConfigResponse>;
|
|
115
|
+
/**
|
|
116
|
+
* Get available products with UI-ready pricing data
|
|
117
|
+
*
|
|
118
|
+
* Transforms the raw Stripe configuration into UI-ready format for pricing
|
|
119
|
+
* table rendering. Includes formatted pricing, features, limits, and all
|
|
120
|
+
* display customizations needed for marketing pages.
|
|
121
|
+
*
|
|
122
|
+
* @returns Promise resolving to products ready for UI consumption
|
|
123
|
+
*
|
|
124
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
125
|
+
* @throws {Error} When the API request fails or configuration is invalid
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* Pricing table rendering:
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const products = await getAvailableProducts();
|
|
131
|
+
*
|
|
132
|
+
* products.forEach(product => {
|
|
133
|
+
* const display = product.pricing_display;
|
|
134
|
+
* console.log(`${display.name} - ${display.tagline}`);
|
|
135
|
+
*
|
|
136
|
+
* display.prices.forEach(price => {
|
|
137
|
+
* console.log(` ${price.display_name}: ${price.formatted_price}`);
|
|
138
|
+
* });
|
|
139
|
+
* });
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function getAvailableProducts(): Promise<ProductWithPricingUI[]>;
|
|
143
|
+
/**
|
|
144
|
+
* Get a specific product by ID
|
|
145
|
+
*
|
|
146
|
+
* Retrieves a single product configuration by its ID from the current
|
|
147
|
+
* Stripe configuration. Useful for product-specific operations.
|
|
148
|
+
*
|
|
149
|
+
* @param productId - The configuration product ID to retrieve
|
|
150
|
+
* @returns Promise resolving to the product or null if not found
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* const product = await getProduct('starter_plan');
|
|
155
|
+
* if (product) {
|
|
156
|
+
* console.log(`Found product: ${product.name}`);
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
declare function getProduct(productId: string): Promise<Product | null>;
|
|
161
|
+
|
|
162
|
+
type CheckoutOptions = {
|
|
163
|
+
priceId: string;
|
|
164
|
+
mode: "payment" | "subscription";
|
|
165
|
+
successUrl: string;
|
|
166
|
+
cancelUrl: string;
|
|
167
|
+
customerId?: string;
|
|
168
|
+
};
|
|
169
|
+
type CreateCheckoutResponse = ApiResponse<{
|
|
170
|
+
url: string;
|
|
171
|
+
sessionId: string;
|
|
172
|
+
}>;
|
|
173
|
+
declare const createCheckout: (options: CheckoutOptions) => Promise<CreateCheckoutResponse>;
|
|
174
|
+
|
|
175
|
+
type PortalOptions = {
|
|
176
|
+
customer_id: string;
|
|
177
|
+
return_url: string;
|
|
178
|
+
};
|
|
179
|
+
type CreateCustomerPortalResponse = ApiResponse<{
|
|
180
|
+
url: string;
|
|
181
|
+
}>;
|
|
182
|
+
declare const createCustomerPortal: (options: PortalOptions) => Promise<CreateCustomerPortalResponse>;
|
|
183
|
+
|
|
184
|
+
type UsageOptions = {
|
|
185
|
+
meter_event_name: string;
|
|
186
|
+
customer_id: string;
|
|
187
|
+
value: string;
|
|
188
|
+
};
|
|
189
|
+
declare const recordUsage: (options: UsageOptions) => Promise<ApiResponse<"">>;
|
|
190
|
+
|
|
191
|
+
export { type CheckoutOptions, type CreateCheckoutResponse, type CreateCustomerPortalResponse, type PortalOptions, type Price, type PriceDisplay, type PriceLimit, type PriceUI, type Product, type ProductUI, type ProductWithPricingUI, type StripeConfigResponse, type StripeConfiguration, type Tier, type UsageOptions, createCheckout, createCustomerPortal, getAvailableProducts, getProduct, getStripeConfig, recordUsage };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
// src/payments/config.ts
|
|
2
|
+
async function getStripeConfig() {
|
|
3
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
4
|
+
if (!baseUrl) {
|
|
5
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
const response = await fetch(`${baseUrl}/api/v1/stripe/config`, {
|
|
9
|
+
method: "GET",
|
|
10
|
+
headers: {
|
|
11
|
+
"Content-Type": "application/json"
|
|
12
|
+
},
|
|
13
|
+
credentials: "include"
|
|
14
|
+
});
|
|
15
|
+
if (!response.ok) {
|
|
16
|
+
const errorData = await response.text();
|
|
17
|
+
throw new Error(
|
|
18
|
+
`Failed to get Stripe config: ${response.status} - ${errorData}`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
const data = await response.json();
|
|
22
|
+
return data;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error("Error getting Stripe config:", error);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
async function getAvailableProducts() {
|
|
29
|
+
const configResponse = await getStripeConfig();
|
|
30
|
+
if (!configResponse.data?.config) {
|
|
31
|
+
throw new Error("No Stripe configuration found");
|
|
32
|
+
}
|
|
33
|
+
const products = configResponse.data.config.products;
|
|
34
|
+
return products.map(transformProductToUIReady).sort(
|
|
35
|
+
(a, b) => a.pricing_display.sort_order - b.pricing_display.sort_order
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
async function getProduct(productId) {
|
|
39
|
+
const configResponse = await getStripeConfig();
|
|
40
|
+
if (!configResponse.data?.config) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const product = configResponse.data.config.products.find(
|
|
44
|
+
(p) => p.id === productId
|
|
45
|
+
);
|
|
46
|
+
return product || null;
|
|
47
|
+
}
|
|
48
|
+
function transformProductToUIReady(product) {
|
|
49
|
+
const ui = product.ui || {};
|
|
50
|
+
return {
|
|
51
|
+
...product,
|
|
52
|
+
pricing_display: {
|
|
53
|
+
name: ui.display_name || product.name,
|
|
54
|
+
tagline: ui.tagline,
|
|
55
|
+
features: ui.features || [],
|
|
56
|
+
badge: ui.badge,
|
|
57
|
+
cta_text: ui.cta_text || "Choose Plan",
|
|
58
|
+
highlighted: ui.highlighted || false,
|
|
59
|
+
sort_order: ui.sort_order || 0,
|
|
60
|
+
prices: product.prices.map((price) => {
|
|
61
|
+
const priceUI = price.ui || {};
|
|
62
|
+
return {
|
|
63
|
+
id: price.id,
|
|
64
|
+
display_name: priceUI.display_name || formatDefaultPriceName(price),
|
|
65
|
+
formatted_price: formatPrice(price, priceUI),
|
|
66
|
+
billing_period: priceUI.billing_period || formatDefaultBillingPeriod(price),
|
|
67
|
+
features: priceUI.features || [],
|
|
68
|
+
limits: priceUI.limits || []
|
|
69
|
+
};
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function formatPrice(price, priceUI) {
|
|
75
|
+
if (priceUI.price_display?.custom_text) {
|
|
76
|
+
return priceUI.price_display.custom_text;
|
|
77
|
+
}
|
|
78
|
+
if (!price.amount || price.amount === 0) {
|
|
79
|
+
return "Free";
|
|
80
|
+
}
|
|
81
|
+
const amount = price.amount / 100;
|
|
82
|
+
const currency = price.currency.toUpperCase();
|
|
83
|
+
let formattedPrice = "";
|
|
84
|
+
if (priceUI.price_display?.show_currency !== false) {
|
|
85
|
+
const currencySymbol = getCurrencySymbol(currency);
|
|
86
|
+
formattedPrice = `${currencySymbol}${amount.toFixed(2)}`;
|
|
87
|
+
} else {
|
|
88
|
+
formattedPrice = amount.toFixed(2);
|
|
89
|
+
}
|
|
90
|
+
if (priceUI.price_display?.suffix) {
|
|
91
|
+
formattedPrice += ` ${priceUI.price_display.suffix}`;
|
|
92
|
+
}
|
|
93
|
+
return formattedPrice;
|
|
94
|
+
}
|
|
95
|
+
function getCurrencySymbol(currency) {
|
|
96
|
+
const symbols = {
|
|
97
|
+
USD: "$",
|
|
98
|
+
EUR: "\u20AC",
|
|
99
|
+
GBP: "\xA3",
|
|
100
|
+
JPY: "\xA5",
|
|
101
|
+
CAD: "C$",
|
|
102
|
+
AUD: "A$"
|
|
103
|
+
};
|
|
104
|
+
return symbols[currency] || currency;
|
|
105
|
+
}
|
|
106
|
+
function formatDefaultPriceName(price) {
|
|
107
|
+
if (price.interval) {
|
|
108
|
+
return price.interval.charAt(0).toUpperCase() + price.interval.slice(1);
|
|
109
|
+
}
|
|
110
|
+
return "One-time";
|
|
111
|
+
}
|
|
112
|
+
function formatDefaultBillingPeriod(price) {
|
|
113
|
+
if (price.interval) {
|
|
114
|
+
const count = price.interval_count || 1;
|
|
115
|
+
const period = count === 1 ? price.interval : `${count} ${price.interval}s`;
|
|
116
|
+
return `per ${period}`;
|
|
117
|
+
}
|
|
118
|
+
return "one-time";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// src/payments/checkout.ts
|
|
122
|
+
var API_URL = process.env.OMNIBASE_API_URL;
|
|
123
|
+
if (!API_URL) throw new Error("must set OMNIBASE_API_URL in env variables");
|
|
124
|
+
var createCheckout = async (options) => {
|
|
125
|
+
const response = await fetch(API_URL + "/api/v1/payments/checkout", {
|
|
126
|
+
method: "POST",
|
|
127
|
+
body: JSON.stringify(options)
|
|
128
|
+
});
|
|
129
|
+
const result = await response.json();
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/payments/portal.ts
|
|
134
|
+
var API_URL2 = process.env.OMNIBASE_API_URL;
|
|
135
|
+
if (!API_URL2) throw new Error("must set OMNIBASE_API_URL in env variables");
|
|
136
|
+
var createCustomerPortal = async (options) => {
|
|
137
|
+
const response = await fetch(API_URL2 + "/api/v1/payments/portal", {
|
|
138
|
+
method: "POST",
|
|
139
|
+
body: JSON.stringify(options)
|
|
140
|
+
});
|
|
141
|
+
const result = await response.json();
|
|
142
|
+
return result;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// src/payments/usage.ts
|
|
146
|
+
var API_URL3 = process.env.OMNIBASE_API_URL;
|
|
147
|
+
if (!API_URL3) throw new Error("must set OMNIBASE_API_URL in env variables");
|
|
148
|
+
var recordUsage = async (options) => {
|
|
149
|
+
const response = await fetch(API_URL3 + "/api/v1/payments/usage", {
|
|
150
|
+
method: "POST",
|
|
151
|
+
body: JSON.stringify(options)
|
|
152
|
+
});
|
|
153
|
+
const result = await response.json();
|
|
154
|
+
return result;
|
|
155
|
+
};
|
|
156
|
+
export {
|
|
157
|
+
createCheckout,
|
|
158
|
+
createCustomerPortal,
|
|
159
|
+
getAvailableProducts,
|
|
160
|
+
getProduct,
|
|
161
|
+
getStripeConfig,
|
|
162
|
+
recordUsage
|
|
163
|
+
};
|
package/dist/tenants/index.cjs
CHANGED
|
@@ -30,9 +30,9 @@ module.exports = __toCommonJS(tenants_exports);
|
|
|
30
30
|
|
|
31
31
|
// src/tenants/switch-tenant.ts
|
|
32
32
|
async function switchActiveTenant(tenantId) {
|
|
33
|
-
const baseUrl = process.env.
|
|
33
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
34
34
|
if (!baseUrl) {
|
|
35
|
-
throw new Error("
|
|
35
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
36
36
|
}
|
|
37
37
|
if (!tenantId) {
|
|
38
38
|
throw new Error("Tenant ID is required");
|
|
@@ -65,9 +65,9 @@ async function switchActiveTenant(tenantId) {
|
|
|
65
65
|
|
|
66
66
|
// src/tenants/create-invite.ts
|
|
67
67
|
async function createTenantUserInvite(tenantId, inviteData) {
|
|
68
|
-
const baseUrl = process.env.
|
|
68
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
69
69
|
if (!baseUrl) {
|
|
70
|
-
throw new Error("
|
|
70
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
71
71
|
}
|
|
72
72
|
if (!tenantId) {
|
|
73
73
|
throw new Error("Tenant ID is required");
|
|
@@ -103,9 +103,9 @@ async function createTenantUserInvite(tenantId, inviteData) {
|
|
|
103
103
|
|
|
104
104
|
// src/tenants/create-tenant.ts
|
|
105
105
|
async function createTenant(tenantData) {
|
|
106
|
-
const baseUrl = process.env.
|
|
106
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
107
107
|
if (!baseUrl) {
|
|
108
|
-
throw new Error("
|
|
108
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
109
109
|
}
|
|
110
110
|
if (!tenantData.name || !tenantData.user_id) {
|
|
111
111
|
throw new Error("Name and user_id are required");
|
|
@@ -135,9 +135,9 @@ async function createTenant(tenantData) {
|
|
|
135
135
|
|
|
136
136
|
// src/tenants/accept-invite.ts
|
|
137
137
|
async function acceptTenantInvite(token) {
|
|
138
|
-
const baseUrl = process.env.
|
|
138
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
139
139
|
if (!baseUrl) {
|
|
140
|
-
throw new Error("
|
|
140
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
141
141
|
}
|
|
142
142
|
if (!token) {
|
|
143
143
|
throw new Error("Invite token is required");
|
|
@@ -170,9 +170,9 @@ async function acceptTenantInvite(token) {
|
|
|
170
170
|
|
|
171
171
|
// src/tenants/delete-tenant.ts
|
|
172
172
|
async function deleteTenant(tenantId) {
|
|
173
|
-
const baseUrl = process.env.
|
|
173
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
174
174
|
if (!baseUrl) {
|
|
175
|
-
throw new Error("
|
|
175
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
176
176
|
}
|
|
177
177
|
if (!tenantId) {
|
|
178
178
|
throw new Error("Tenant ID is required");
|
package/dist/tenants/index.d.cts
CHANGED
|
@@ -74,7 +74,7 @@ type AcceptTenantInviteResponse = ApiResponse<{
|
|
|
74
74
|
*
|
|
75
75
|
* @returns Promise resolving to the tenant ID and success confirmation
|
|
76
76
|
*
|
|
77
|
-
* @throws {Error} When
|
|
77
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
78
78
|
* @throws {Error} When the token parameter is missing or empty
|
|
79
79
|
* @throws {Error} When the invitation token is invalid or expired
|
|
80
80
|
* @throws {Error} When the invitation has already been accepted
|
|
@@ -250,7 +250,7 @@ type CreateTenantUserInviteRequest = {
|
|
|
250
250
|
*
|
|
251
251
|
* @returns Promise resolving to the created invitation with secure token
|
|
252
252
|
*
|
|
253
|
-
* @throws {Error} When
|
|
253
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
254
254
|
* @throws {Error} When tenantId parameter is missing or empty
|
|
255
255
|
* @throws {Error} When required fields (email, role) are missing or empty
|
|
256
256
|
* @throws {Error} When the API request fails due to network issues
|
|
@@ -407,7 +407,7 @@ type CreateTenantRequest = {
|
|
|
407
407
|
*
|
|
408
408
|
* @returns Promise resolving to the created tenant with authentication token
|
|
409
409
|
*
|
|
410
|
-
* @throws {Error} When
|
|
410
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
411
411
|
* @throws {Error} When required fields (name, user_id) are missing or empty
|
|
412
412
|
* @throws {Error} When the API request fails due to network issues
|
|
413
413
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
@@ -485,7 +485,7 @@ type DeleteTenantResponse = ApiResponse<{
|
|
|
485
485
|
*
|
|
486
486
|
* @returns Promise resolving to a confirmation message
|
|
487
487
|
*
|
|
488
|
-
* @throws {Error} When
|
|
488
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
489
489
|
* @throws {Error} When the tenantId parameter is missing or empty
|
|
490
490
|
* @throws {Error} When the user is not authenticated
|
|
491
491
|
* @throws {Error} When the user is not an owner of the specified tenant
|
|
@@ -578,7 +578,7 @@ type SwitchActiveTenantResponse = ApiResponse<{
|
|
|
578
578
|
*
|
|
579
579
|
* @returns Promise resolving to a new JWT token and success confirmation
|
|
580
580
|
*
|
|
581
|
-
* @throws {Error} When
|
|
581
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
582
582
|
* @throws {Error} When the tenantId parameter is missing or empty
|
|
583
583
|
* @throws {Error} When the user doesn't have access to the specified tenant
|
|
584
584
|
* @throws {Error} When the user is not authenticated
|
package/dist/tenants/index.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ type AcceptTenantInviteResponse = ApiResponse<{
|
|
|
74
74
|
*
|
|
75
75
|
* @returns Promise resolving to the tenant ID and success confirmation
|
|
76
76
|
*
|
|
77
|
-
* @throws {Error} When
|
|
77
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
78
78
|
* @throws {Error} When the token parameter is missing or empty
|
|
79
79
|
* @throws {Error} When the invitation token is invalid or expired
|
|
80
80
|
* @throws {Error} When the invitation has already been accepted
|
|
@@ -250,7 +250,7 @@ type CreateTenantUserInviteRequest = {
|
|
|
250
250
|
*
|
|
251
251
|
* @returns Promise resolving to the created invitation with secure token
|
|
252
252
|
*
|
|
253
|
-
* @throws {Error} When
|
|
253
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
254
254
|
* @throws {Error} When tenantId parameter is missing or empty
|
|
255
255
|
* @throws {Error} When required fields (email, role) are missing or empty
|
|
256
256
|
* @throws {Error} When the API request fails due to network issues
|
|
@@ -407,7 +407,7 @@ type CreateTenantRequest = {
|
|
|
407
407
|
*
|
|
408
408
|
* @returns Promise resolving to the created tenant with authentication token
|
|
409
409
|
*
|
|
410
|
-
* @throws {Error} When
|
|
410
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
411
411
|
* @throws {Error} When required fields (name, user_id) are missing or empty
|
|
412
412
|
* @throws {Error} When the API request fails due to network issues
|
|
413
413
|
* @throws {Error} When the server returns an error response (4xx, 5xx status codes)
|
|
@@ -485,7 +485,7 @@ type DeleteTenantResponse = ApiResponse<{
|
|
|
485
485
|
*
|
|
486
486
|
* @returns Promise resolving to a confirmation message
|
|
487
487
|
*
|
|
488
|
-
* @throws {Error} When
|
|
488
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
489
489
|
* @throws {Error} When the tenantId parameter is missing or empty
|
|
490
490
|
* @throws {Error} When the user is not authenticated
|
|
491
491
|
* @throws {Error} When the user is not an owner of the specified tenant
|
|
@@ -578,7 +578,7 @@ type SwitchActiveTenantResponse = ApiResponse<{
|
|
|
578
578
|
*
|
|
579
579
|
* @returns Promise resolving to a new JWT token and success confirmation
|
|
580
580
|
*
|
|
581
|
-
* @throws {Error} When
|
|
581
|
+
* @throws {Error} When OMNIBASE_AUTH_URL environment variable is not configured
|
|
582
582
|
* @throws {Error} When the tenantId parameter is missing or empty
|
|
583
583
|
* @throws {Error} When the user doesn't have access to the specified tenant
|
|
584
584
|
* @throws {Error} When the user is not authenticated
|
package/dist/tenants/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/tenants/switch-tenant.ts
|
|
2
2
|
async function switchActiveTenant(tenantId) {
|
|
3
|
-
const baseUrl = process.env.
|
|
3
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
4
4
|
if (!baseUrl) {
|
|
5
|
-
throw new Error("
|
|
5
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
6
6
|
}
|
|
7
7
|
if (!tenantId) {
|
|
8
8
|
throw new Error("Tenant ID is required");
|
|
@@ -35,9 +35,9 @@ async function switchActiveTenant(tenantId) {
|
|
|
35
35
|
|
|
36
36
|
// src/tenants/create-invite.ts
|
|
37
37
|
async function createTenantUserInvite(tenantId, inviteData) {
|
|
38
|
-
const baseUrl = process.env.
|
|
38
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
39
39
|
if (!baseUrl) {
|
|
40
|
-
throw new Error("
|
|
40
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
41
41
|
}
|
|
42
42
|
if (!tenantId) {
|
|
43
43
|
throw new Error("Tenant ID is required");
|
|
@@ -73,9 +73,9 @@ async function createTenantUserInvite(tenantId, inviteData) {
|
|
|
73
73
|
|
|
74
74
|
// src/tenants/create-tenant.ts
|
|
75
75
|
async function createTenant(tenantData) {
|
|
76
|
-
const baseUrl = process.env.
|
|
76
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
77
77
|
if (!baseUrl) {
|
|
78
|
-
throw new Error("
|
|
78
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
79
79
|
}
|
|
80
80
|
if (!tenantData.name || !tenantData.user_id) {
|
|
81
81
|
throw new Error("Name and user_id are required");
|
|
@@ -105,9 +105,9 @@ async function createTenant(tenantData) {
|
|
|
105
105
|
|
|
106
106
|
// src/tenants/accept-invite.ts
|
|
107
107
|
async function acceptTenantInvite(token) {
|
|
108
|
-
const baseUrl = process.env.
|
|
108
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
109
109
|
if (!baseUrl) {
|
|
110
|
-
throw new Error("
|
|
110
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
111
111
|
}
|
|
112
112
|
if (!token) {
|
|
113
113
|
throw new Error("Invite token is required");
|
|
@@ -140,9 +140,9 @@ async function acceptTenantInvite(token) {
|
|
|
140
140
|
|
|
141
141
|
// src/tenants/delete-tenant.ts
|
|
142
142
|
async function deleteTenant(tenantId) {
|
|
143
|
-
const baseUrl = process.env.
|
|
143
|
+
const baseUrl = process.env.OMNIBASE_AUTH_URL;
|
|
144
144
|
if (!baseUrl) {
|
|
145
|
-
throw new Error("
|
|
145
|
+
throw new Error("OMNIBASE_AUTH_URL is not configured");
|
|
146
146
|
}
|
|
147
147
|
if (!tenantId) {
|
|
148
148
|
throw new Error("Tenant ID is required");
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnibase/core-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "OmniBase core Javascript SDK - framework agnostic",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/**/*"
|
|
7
7
|
],
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "tsup src/permissions/index.ts src/database/index.ts src/tenants/index.ts src/auth/index.ts src/
|
|
10
|
+
"build": "tsup src/permissions/index.ts src/database/index.ts src/tenants/index.ts src/auth/index.ts src/payments/index.ts --format cjs,esm --dts",
|
|
11
11
|
"prepublishOnly": "npm run build"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"require": "./dist/tenants/index.cjs",
|
|
30
30
|
"types": "./dist/tenants/index.d.ts"
|
|
31
31
|
},
|
|
32
|
-
"./
|
|
33
|
-
"import": "./dist/
|
|
34
|
-
"require": "./dist/
|
|
35
|
-
"types": "./dist/
|
|
32
|
+
"./payments": {
|
|
33
|
+
"import": "./dist/payments/index.js",
|
|
34
|
+
"require": "./dist/payments/index.cjs",
|
|
35
|
+
"types": "./dist/payments/index.d.ts"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"keywords": [
|