@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.
@@ -0,0 +1,105 @@
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
+ };
103
+ export {
104
+ PermissionsClient
105
+ };
@@ -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.OMNIBASE_API_URL;
33
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
34
34
  if (!baseUrl) {
35
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
68
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
69
69
  if (!baseUrl) {
70
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
106
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
107
107
  if (!baseUrl) {
108
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
138
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
139
139
  if (!baseUrl) {
140
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
173
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
174
174
  if (!baseUrl) {
175
- throw new Error("OMNIBASE_API_URL is not configured");
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");
@@ -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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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
@@ -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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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 OMNIBASE_API_URL environment variable is not configured
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
@@ -1,8 +1,8 @@
1
1
  // src/tenants/switch-tenant.ts
2
2
  async function switchActiveTenant(tenantId) {
3
- const baseUrl = process.env.OMNIBASE_API_URL;
3
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
4
4
  if (!baseUrl) {
5
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
38
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
39
39
  if (!baseUrl) {
40
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
76
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
77
77
  if (!baseUrl) {
78
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
108
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
109
109
  if (!baseUrl) {
110
- throw new Error("OMNIBASE_API_URL is not configured");
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.OMNIBASE_API_URL;
143
+ const baseUrl = process.env.OMNIBASE_AUTH_URL;
144
144
  if (!baseUrl) {
145
- throw new Error("OMNIBASE_API_URL is not configured");
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,20 +1,24 @@
1
1
  {
2
2
  "name": "@omnibase/core-js",
3
- "version": "0.2.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/database/index.ts src/tenants/index.ts src/auth/index.ts src/stripe/index.ts --format cjs,esm --dts",
11
- "prepublishOnly": "npm run build",
12
- "build:docs": "bunx typedoc"
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
+ "prepublishOnly": "npm run build"
13
12
  },
14
13
  "exports": {
15
14
  "./auth": {
16
15
  "types": "./dist/auth/index.d.ts"
17
16
  },
17
+ "./permissions": {
18
+ "import": "./dist/permissions/index.d.ts",
19
+ "require": "./dist/permissions/index.cjs",
20
+ "types": "./dist/permissions/index.d.ts"
21
+ },
18
22
  "./database": {
19
23
  "import": "./dist/database/index.js",
20
24
  "require": "./dist/database/index.cjs",
@@ -25,10 +29,10 @@
25
29
  "require": "./dist/tenants/index.cjs",
26
30
  "types": "./dist/tenants/index.d.ts"
27
31
  },
28
- "./stripe": {
29
- "import": "./dist/stripe/index.js",
30
- "require": "./dist/stripe/index.cjs",
31
- "types": "./dist/stripe/index.d.ts"
32
+ "./payments": {
33
+ "import": "./dist/payments/index.js",
34
+ "require": "./dist/payments/index.cjs",
35
+ "types": "./dist/payments/index.d.ts"
32
36
  }
33
37
  },
34
38
  "keywords": [
@@ -51,6 +55,7 @@
51
55
  "typescript": "^5.9.2"
52
56
  },
53
57
  "dependencies": {
58
+ "@ory/client": "^1.22.3",
54
59
  "@ory/client-fetch": "^1.22.2",
55
60
  "@supabase/postgrest-js": "^1.21.4"
56
61
  }