@omnibase/core-js 0.2.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/permissions/index.cjs +132 -0
- package/dist/permissions/index.d.cts +195 -0
- package/dist/permissions/index.d.ts +195 -0
- package/dist/permissions/index.js +105 -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 +13 -8
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 };
|