@omnibase/core-js 0.1.7 → 0.3.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,132 @@
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/permissions/index.ts
21
+ var permissions_exports = {};
22
+ __export(permissions_exports, {
23
+ PermissionsClient: () => PermissionsClient
24
+ });
25
+ module.exports = __toCommonJS(permissions_exports);
26
+
27
+ // src/permissions/handler.ts
28
+ var import_client = require("@ory/client");
29
+ var PermissionsClient = class {
30
+ /**
31
+ * Ory Keto RelationshipApi for managing subject-object relationships
32
+ *
33
+ * Provides methods for creating, updating, and deleting relationships between
34
+ * subjects (users, groups) and objects (tenants, resources). This API handles
35
+ * write operations and is used to establish permission structures.
36
+ *
37
+ * Key methods:
38
+ * - `createRelationship()` - Creates a new relationship tuple
39
+ * - `deleteRelationships()` - Removes existing relationship tuples
40
+ * - `getRelationships()` - Queries existing relationships
41
+ * - `patchRelationships()` - Updates multiple relationships atomically
42
+ *
43
+ * @example
44
+ * ```typescript
45
+ * // Create a relationship
46
+ * await client.relationships.createRelationship(
47
+ * undefined,
48
+ * {
49
+ * namespace: 'Tenant',
50
+ * object: 'tenant_123',
51
+ * relation: 'members',
52
+ * subjectId: 'user_456'
53
+ * }
54
+ * );
55
+ * ```
56
+ *
57
+ * @since 1.0.0
58
+ * @group Relationships
59
+ */
60
+ relationships;
61
+ /**
62
+ * Ory Keto PermissionApi for checking permissions
63
+ *
64
+ * Provides methods for querying whether a subject has a specific permission
65
+ * on an object. This API handles read operations and is optimized for fast
66
+ * permission checks in your application logic.
67
+ *
68
+ * Key methods:
69
+ * - `checkPermission()` - Checks if a subject has permission on an object
70
+ * - `checkPermissionOrError()` - Same as above but throws error if denied
71
+ * - `expandPermissions()` - Expands relationships to show all granted permissions
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * // Check permission
76
+ * const result = await client.permissions.checkPermission(
77
+ * undefined,
78
+ * {
79
+ * namespace: 'Tenant',
80
+ * object: 'tenant_123',
81
+ * relation: 'view',
82
+ * subjectId: 'user_456'
83
+ * }
84
+ * );
85
+ *
86
+ * console.log('Has permission:', result.data.allowed);
87
+ * ```
88
+ *
89
+ * @since 1.0.0
90
+ * @group Permissions
91
+ */
92
+ permissions;
93
+ /**
94
+ * Creates a new PermissionsClient instance
95
+ *
96
+ * Initializes the client with separate endpoints for read and write operations.
97
+ * The client automatically appends the appropriate Keto API paths to the base URL
98
+ * for optimal performance and security separation.
99
+ *
100
+ * @param apiBaseUrl - The base URL for your Omnibase API instance
101
+ *
102
+ * @throws {Error} When the base URL is invalid or cannot be reached
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const client = new PermissionsClient('https://api.example.com');
107
+ * ```
108
+ *
109
+ * @example
110
+ * Local development:
111
+ * ```typescript
112
+ * const client = new PermissionsClient('http://localhost:8080');
113
+ * ```
114
+ *
115
+ * @since 1.0.0
116
+ * @group Client
117
+ */
118
+ constructor(apiBaseUrl) {
119
+ this.relationships = new import_client.RelationshipApi(
120
+ void 0,
121
+ `${apiBaseUrl}/api/v1/permissions/write`
122
+ );
123
+ this.permissions = new import_client.PermissionApi(
124
+ void 0,
125
+ `${apiBaseUrl}/api/v1/permissions/read`
126
+ );
127
+ }
128
+ };
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ PermissionsClient
132
+ });
@@ -0,0 +1,195 @@
1
+ import { RelationshipApi, PermissionApi } from '@ory/client';
2
+
3
+ /**
4
+ * Client for managing permissions and relationships using Ory Keto
5
+ *
6
+ * This client provides access to Ory Keto's permission system, allowing you to
7
+ * create, manage, and check relationships between subjects and objects. It handles
8
+ * both read operations (permission checks) and write operations (relationship management).
9
+ *
10
+ * The client automatically configures separate endpoints for read and write operations
11
+ * to optimize performance and security by following Ory Keto's recommended architecture.
12
+ *
13
+ * @example
14
+ * Basic permission checking:
15
+ * ```typescript
16
+ * import { PermissionsClient } from '@omnibase/core-js/permissions';
17
+ *
18
+ * const permissionsClient = new PermissionsClient('https://api.example.com');
19
+ *
20
+ * // Check if a user can view a tenant
21
+ * const canView = await permissionsClient.permissions.checkPermission(
22
+ * undefined,
23
+ * {
24
+ * namespace: 'Tenant',
25
+ * object: 'tenant_123',
26
+ * relation: 'view',
27
+ * subjectId: 'user_456'
28
+ * }
29
+ * );
30
+ *
31
+ * if (canView.data.allowed) {
32
+ * console.log('User can view the tenant');
33
+ * }
34
+ * ```
35
+ *
36
+ * @example
37
+ * Creating tenant relationships:
38
+ * ```typescript
39
+ * // Create a relationship making a user an owner of a tenant
40
+ * await permissionsClient.relationships.createRelationship(
41
+ * undefined,
42
+ * {
43
+ * namespace: 'Tenant',
44
+ * object: 'tenant_123',
45
+ * relation: 'owners',
46
+ * subjectId: 'user_456'
47
+ * }
48
+ * );
49
+ *
50
+ * // Now the user has owner permissions on the tenant
51
+ * console.log('User is now an owner of the tenant');
52
+ * ```
53
+ *
54
+ * @example
55
+ * Complex tenant permission management:
56
+ * ```typescript
57
+ * const tenantId = 'tenant_123';
58
+ * const userId = 'user_456';
59
+ *
60
+ * // Grant admin permissions to a user
61
+ * await permissionsClient.relationships.createRelationship(
62
+ * undefined,
63
+ * {
64
+ * namespace: 'Tenant',
65
+ * object: tenantId,
66
+ * relation: 'admins',
67
+ * subjectId: userId
68
+ * }
69
+ * );
70
+ *
71
+ * // Check if user can manage members (admins and owners can)
72
+ * const canManageMembers = await permissionsClient.permissions.checkPermission(
73
+ * undefined,
74
+ * {
75
+ * namespace: 'Tenant',
76
+ * object: tenantId,
77
+ * relation: 'manage_members',
78
+ * subjectId: userId
79
+ * }
80
+ * );
81
+ *
82
+ * if (canManageMembers.data.allowed) {
83
+ * // User can invite/remove members
84
+ * console.log('User can manage tenant members');
85
+ * }
86
+ *
87
+ * // Later, remove admin permissions
88
+ * await permissionsClient.relationships.deleteRelationships(
89
+ * undefined,
90
+ * {
91
+ * namespace: 'Tenant',
92
+ * object: tenantId,
93
+ * relation: 'admins',
94
+ * subjectId: userId
95
+ * }
96
+ * );
97
+ * ```
98
+ *
99
+ * @since 1.0.0
100
+ * @public
101
+ * @group Client
102
+ */
103
+ declare class PermissionsClient {
104
+ /**
105
+ * Ory Keto RelationshipApi for managing subject-object relationships
106
+ *
107
+ * Provides methods for creating, updating, and deleting relationships between
108
+ * subjects (users, groups) and objects (tenants, resources). This API handles
109
+ * write operations and is used to establish permission structures.
110
+ *
111
+ * Key methods:
112
+ * - `createRelationship()` - Creates a new relationship tuple
113
+ * - `deleteRelationships()` - Removes existing relationship tuples
114
+ * - `getRelationships()` - Queries existing relationships
115
+ * - `patchRelationships()` - Updates multiple relationships atomically
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Create a relationship
120
+ * await client.relationships.createRelationship(
121
+ * undefined,
122
+ * {
123
+ * namespace: 'Tenant',
124
+ * object: 'tenant_123',
125
+ * relation: 'members',
126
+ * subjectId: 'user_456'
127
+ * }
128
+ * );
129
+ * ```
130
+ *
131
+ * @since 1.0.0
132
+ * @group Relationships
133
+ */
134
+ relationships: RelationshipApi;
135
+ /**
136
+ * Ory Keto PermissionApi for checking permissions
137
+ *
138
+ * Provides methods for querying whether a subject has a specific permission
139
+ * on an object. This API handles read operations and is optimized for fast
140
+ * permission checks in your application logic.
141
+ *
142
+ * Key methods:
143
+ * - `checkPermission()` - Checks if a subject has permission on an object
144
+ * - `checkPermissionOrError()` - Same as above but throws error if denied
145
+ * - `expandPermissions()` - Expands relationships to show all granted permissions
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * // Check permission
150
+ * const result = await client.permissions.checkPermission(
151
+ * undefined,
152
+ * {
153
+ * namespace: 'Tenant',
154
+ * object: 'tenant_123',
155
+ * relation: 'view',
156
+ * subjectId: 'user_456'
157
+ * }
158
+ * );
159
+ *
160
+ * console.log('Has permission:', result.data.allowed);
161
+ * ```
162
+ *
163
+ * @since 1.0.0
164
+ * @group Permissions
165
+ */
166
+ permissions: PermissionApi;
167
+ /**
168
+ * Creates a new PermissionsClient instance
169
+ *
170
+ * Initializes the client with separate endpoints for read and write operations.
171
+ * The client automatically appends the appropriate Keto API paths to the base URL
172
+ * for optimal performance and security separation.
173
+ *
174
+ * @param apiBaseUrl - The base URL for your Omnibase API instance
175
+ *
176
+ * @throws {Error} When the base URL is invalid or cannot be reached
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const client = new PermissionsClient('https://api.example.com');
181
+ * ```
182
+ *
183
+ * @example
184
+ * Local development:
185
+ * ```typescript
186
+ * const client = new PermissionsClient('http://localhost:8080');
187
+ * ```
188
+ *
189
+ * @since 1.0.0
190
+ * @group Client
191
+ */
192
+ constructor(apiBaseUrl: string);
193
+ }
194
+
195
+ export { PermissionsClient };
@@ -0,0 +1,195 @@
1
+ import { RelationshipApi, PermissionApi } from '@ory/client';
2
+
3
+ /**
4
+ * Client for managing permissions and relationships using Ory Keto
5
+ *
6
+ * This client provides access to Ory Keto's permission system, allowing you to
7
+ * create, manage, and check relationships between subjects and objects. It handles
8
+ * both read operations (permission checks) and write operations (relationship management).
9
+ *
10
+ * The client automatically configures separate endpoints for read and write operations
11
+ * to optimize performance and security by following Ory Keto's recommended architecture.
12
+ *
13
+ * @example
14
+ * Basic permission checking:
15
+ * ```typescript
16
+ * import { PermissionsClient } from '@omnibase/core-js/permissions';
17
+ *
18
+ * const permissionsClient = new PermissionsClient('https://api.example.com');
19
+ *
20
+ * // Check if a user can view a tenant
21
+ * const canView = await permissionsClient.permissions.checkPermission(
22
+ * undefined,
23
+ * {
24
+ * namespace: 'Tenant',
25
+ * object: 'tenant_123',
26
+ * relation: 'view',
27
+ * subjectId: 'user_456'
28
+ * }
29
+ * );
30
+ *
31
+ * if (canView.data.allowed) {
32
+ * console.log('User can view the tenant');
33
+ * }
34
+ * ```
35
+ *
36
+ * @example
37
+ * Creating tenant relationships:
38
+ * ```typescript
39
+ * // Create a relationship making a user an owner of a tenant
40
+ * await permissionsClient.relationships.createRelationship(
41
+ * undefined,
42
+ * {
43
+ * namespace: 'Tenant',
44
+ * object: 'tenant_123',
45
+ * relation: 'owners',
46
+ * subjectId: 'user_456'
47
+ * }
48
+ * );
49
+ *
50
+ * // Now the user has owner permissions on the tenant
51
+ * console.log('User is now an owner of the tenant');
52
+ * ```
53
+ *
54
+ * @example
55
+ * Complex tenant permission management:
56
+ * ```typescript
57
+ * const tenantId = 'tenant_123';
58
+ * const userId = 'user_456';
59
+ *
60
+ * // Grant admin permissions to a user
61
+ * await permissionsClient.relationships.createRelationship(
62
+ * undefined,
63
+ * {
64
+ * namespace: 'Tenant',
65
+ * object: tenantId,
66
+ * relation: 'admins',
67
+ * subjectId: userId
68
+ * }
69
+ * );
70
+ *
71
+ * // Check if user can manage members (admins and owners can)
72
+ * const canManageMembers = await permissionsClient.permissions.checkPermission(
73
+ * undefined,
74
+ * {
75
+ * namespace: 'Tenant',
76
+ * object: tenantId,
77
+ * relation: 'manage_members',
78
+ * subjectId: userId
79
+ * }
80
+ * );
81
+ *
82
+ * if (canManageMembers.data.allowed) {
83
+ * // User can invite/remove members
84
+ * console.log('User can manage tenant members');
85
+ * }
86
+ *
87
+ * // Later, remove admin permissions
88
+ * await permissionsClient.relationships.deleteRelationships(
89
+ * undefined,
90
+ * {
91
+ * namespace: 'Tenant',
92
+ * object: tenantId,
93
+ * relation: 'admins',
94
+ * subjectId: userId
95
+ * }
96
+ * );
97
+ * ```
98
+ *
99
+ * @since 1.0.0
100
+ * @public
101
+ * @group Client
102
+ */
103
+ declare class PermissionsClient {
104
+ /**
105
+ * Ory Keto RelationshipApi for managing subject-object relationships
106
+ *
107
+ * Provides methods for creating, updating, and deleting relationships between
108
+ * subjects (users, groups) and objects (tenants, resources). This API handles
109
+ * write operations and is used to establish permission structures.
110
+ *
111
+ * Key methods:
112
+ * - `createRelationship()` - Creates a new relationship tuple
113
+ * - `deleteRelationships()` - Removes existing relationship tuples
114
+ * - `getRelationships()` - Queries existing relationships
115
+ * - `patchRelationships()` - Updates multiple relationships atomically
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Create a relationship
120
+ * await client.relationships.createRelationship(
121
+ * undefined,
122
+ * {
123
+ * namespace: 'Tenant',
124
+ * object: 'tenant_123',
125
+ * relation: 'members',
126
+ * subjectId: 'user_456'
127
+ * }
128
+ * );
129
+ * ```
130
+ *
131
+ * @since 1.0.0
132
+ * @group Relationships
133
+ */
134
+ relationships: RelationshipApi;
135
+ /**
136
+ * Ory Keto PermissionApi for checking permissions
137
+ *
138
+ * Provides methods for querying whether a subject has a specific permission
139
+ * on an object. This API handles read operations and is optimized for fast
140
+ * permission checks in your application logic.
141
+ *
142
+ * Key methods:
143
+ * - `checkPermission()` - Checks if a subject has permission on an object
144
+ * - `checkPermissionOrError()` - Same as above but throws error if denied
145
+ * - `expandPermissions()` - Expands relationships to show all granted permissions
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * // Check permission
150
+ * const result = await client.permissions.checkPermission(
151
+ * undefined,
152
+ * {
153
+ * namespace: 'Tenant',
154
+ * object: 'tenant_123',
155
+ * relation: 'view',
156
+ * subjectId: 'user_456'
157
+ * }
158
+ * );
159
+ *
160
+ * console.log('Has permission:', result.data.allowed);
161
+ * ```
162
+ *
163
+ * @since 1.0.0
164
+ * @group Permissions
165
+ */
166
+ permissions: PermissionApi;
167
+ /**
168
+ * Creates a new PermissionsClient instance
169
+ *
170
+ * Initializes the client with separate endpoints for read and write operations.
171
+ * The client automatically appends the appropriate Keto API paths to the base URL
172
+ * for optimal performance and security separation.
173
+ *
174
+ * @param apiBaseUrl - The base URL for your Omnibase API instance
175
+ *
176
+ * @throws {Error} When the base URL is invalid or cannot be reached
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const client = new PermissionsClient('https://api.example.com');
181
+ * ```
182
+ *
183
+ * @example
184
+ * Local development:
185
+ * ```typescript
186
+ * const client = new PermissionsClient('http://localhost:8080');
187
+ * ```
188
+ *
189
+ * @since 1.0.0
190
+ * @group Client
191
+ */
192
+ constructor(apiBaseUrl: string);
193
+ }
194
+
195
+ export { PermissionsClient };
@@ -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
+ };