@omnibase/core-js 0.4.2 → 0.5.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.
@@ -1,163 +1,14 @@
1
- // src/payments/config.ts
2
- async function getStripeConfig() {
3
- const baseUrl = process.env.OMNIBASE_API_URL;
4
- if (!baseUrl) {
5
- throw new Error("OMNIBASE_API_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
- };
1
+ import {
2
+ CheckoutManager,
3
+ ConfigManager,
4
+ PaymentHandler,
5
+ PortalManager,
6
+ UsageManager
7
+ } from "../chunk-767PUXYD.js";
156
8
  export {
157
- createCheckout,
158
- createCustomerPortal,
159
- getAvailableProducts,
160
- getProduct,
161
- getStripeConfig,
162
- recordUsage
9
+ CheckoutManager,
10
+ ConfigManager,
11
+ PaymentHandler,
12
+ PortalManager,
13
+ UsageManager
163
14
  };
@@ -1,105 +1,6 @@
1
- // src/permissions/handler.ts
2
- import { RelationshipApi, PermissionApi } from "@ory/client";
3
- var PermissionsClient = class {
4
- /**
5
- * Ory Keto RelationshipApi for managing subject-object relationships
6
- *
7
- * Provides methods for creating, updating, and deleting relationships between
8
- * subjects (users, groups) and objects (tenants, resources). This API handles
9
- * write operations and is used to establish permission structures.
10
- *
11
- * Key methods:
12
- * - `createRelationship()` - Creates a new relationship tuple
13
- * - `deleteRelationships()` - Removes existing relationship tuples
14
- * - `getRelationships()` - Queries existing relationships
15
- * - `patchRelationships()` - Updates multiple relationships atomically
16
- *
17
- * @example
18
- * ```typescript
19
- * // Create a relationship
20
- * await client.relationships.createRelationship(
21
- * undefined,
22
- * {
23
- * namespace: 'Tenant',
24
- * object: 'tenant_123',
25
- * relation: 'members',
26
- * subjectId: 'user_456'
27
- * }
28
- * );
29
- * ```
30
- *
31
- * @since 1.0.0
32
- * @group Relationships
33
- */
34
- relationships;
35
- /**
36
- * Ory Keto PermissionApi for checking permissions
37
- *
38
- * Provides methods for querying whether a subject has a specific permission
39
- * on an object. This API handles read operations and is optimized for fast
40
- * permission checks in your application logic.
41
- *
42
- * Key methods:
43
- * - `checkPermission()` - Checks if a subject has permission on an object
44
- * - `checkPermissionOrError()` - Same as above but throws error if denied
45
- * - `expandPermissions()` - Expands relationships to show all granted permissions
46
- *
47
- * @example
48
- * ```typescript
49
- * // Check permission
50
- * const result = await client.permissions.checkPermission(
51
- * undefined,
52
- * {
53
- * namespace: 'Tenant',
54
- * object: 'tenant_123',
55
- * relation: 'view',
56
- * subjectId: 'user_456'
57
- * }
58
- * );
59
- *
60
- * console.log('Has permission:', result.data.allowed);
61
- * ```
62
- *
63
- * @since 1.0.0
64
- * @group Permissions
65
- */
66
- permissions;
67
- /**
68
- * Creates a new PermissionsClient instance
69
- *
70
- * Initializes the client with separate endpoints for read and write operations.
71
- * The client automatically appends the appropriate Keto API paths to the base URL
72
- * for optimal performance and security separation.
73
- *
74
- * @param apiBaseUrl - The base URL for your Omnibase API instance
75
- *
76
- * @throws {Error} When the base URL is invalid or cannot be reached
77
- *
78
- * @example
79
- * ```typescript
80
- * const client = new PermissionsClient('https://api.example.com');
81
- * ```
82
- *
83
- * @example
84
- * Local development:
85
- * ```typescript
86
- * const client = new PermissionsClient('http://localhost:8080');
87
- * ```
88
- *
89
- * @since 1.0.0
90
- * @group Client
91
- */
92
- constructor(apiBaseUrl) {
93
- this.relationships = new RelationshipApi(
94
- void 0,
95
- `${apiBaseUrl}/api/v1/permissions/write`
96
- );
97
- this.permissions = new PermissionApi(
98
- void 0,
99
- `${apiBaseUrl}/api/v1/permissions/read`
100
- );
101
- }
102
- };
1
+ import {
2
+ PermissionsClient
3
+ } from "../chunk-DDFBRGMG.js";
103
4
  export {
104
5
  PermissionsClient
105
6
  };