@agentic-kit/db-tools 0.12.47 → 0.13.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.
- package/README.md +18 -4
- package/access/findings.d.ts +93 -0
- package/access/findings.js +434 -0
- package/access/index.d.ts +5 -0
- package/access/index.js +27 -0
- package/access/policies.d.ts +142 -0
- package/access/policies.js +338 -0
- package/access/provisioning.d.ts +121 -0
- package/access/provisioning.js +381 -0
- package/access/rule-check.d.ts +52 -0
- package/access/rule-check.js +307 -0
- package/access/words.d.ts +38 -0
- package/access/words.js +530 -0
- package/app-workspace.d.ts +1 -0
- package/app-workspace.js +7 -9
- package/blueprint/blueprint-defaults.d.ts +9 -0
- package/blueprint/blueprint-defaults.js +77 -0
- package/blueprint/blueprint-schema.d.ts +68 -0
- package/blueprint/blueprint-schema.js +139 -0
- package/blueprint/field-type.d.ts +4 -0
- package/blueprint/field-type.js +100 -0
- package/blueprint/internal-policies.d.ts +1 -0
- package/blueprint/internal-policies.js +10 -0
- package/blueprint-construction.d.ts +10 -6
- package/blueprint-construction.js +34 -25
- package/context.d.ts +15 -0
- package/context.js +132 -69
- package/db-probe.d.ts +1 -1
- package/db-probe.js +19 -4
- package/esm/access/findings.d.ts +93 -0
- package/esm/access/findings.js +428 -0
- package/esm/access/index.d.ts +5 -0
- package/esm/access/index.js +5 -0
- package/esm/access/policies.d.ts +142 -0
- package/esm/access/policies.js +315 -0
- package/esm/access/provisioning.d.ts +121 -0
- package/esm/access/provisioning.js +375 -0
- package/esm/access/rule-check.d.ts +52 -0
- package/esm/access/rule-check.js +297 -0
- package/esm/access/words.d.ts +38 -0
- package/esm/access/words.js +524 -0
- package/esm/app-workspace.d.ts +1 -0
- package/esm/app-workspace.js +7 -10
- package/esm/blueprint/blueprint-defaults.d.ts +9 -0
- package/esm/blueprint/blueprint-defaults.js +74 -0
- package/esm/blueprint/blueprint-schema.d.ts +68 -0
- package/esm/blueprint/blueprint-schema.js +134 -0
- package/esm/blueprint/field-type.d.ts +4 -0
- package/esm/blueprint/field-type.js +95 -0
- package/esm/blueprint/internal-policies.d.ts +1 -0
- package/esm/blueprint/internal-policies.js +7 -0
- package/esm/blueprint-construction.d.ts +10 -6
- package/esm/blueprint-construction.js +32 -24
- package/esm/context.d.ts +15 -0
- package/esm/context.js +133 -70
- package/esm/db-probe.d.ts +1 -1
- package/esm/db-probe.js +21 -6
- package/esm/failure.d.ts +89 -0
- package/esm/failure.js +362 -0
- package/esm/gate.d.ts +6 -4
- package/esm/gate.js +42 -14
- package/esm/graphql-http.d.ts +27 -6
- package/esm/graphql-http.js +96 -24
- package/esm/host.d.ts +33 -8
- package/esm/host.js +42 -2
- package/esm/index.d.ts +22 -12
- package/esm/index.js +21 -39
- package/esm/provision-database/env-file.d.ts +7 -0
- package/esm/provision-database/env-file.js +30 -0
- package/esm/provision-database/preset-match.js +1 -2
- package/esm/provision-database/provision.d.ts +21 -4
- package/esm/provision-database/provision.js +330 -85
- package/esm/provision-database/request-database.d.ts +22 -3
- package/esm/provision-database/request-database.js +46 -13
- package/esm/ready.d.ts +20 -0
- package/esm/ready.js +45 -0
- package/esm/run-codegen/barrels.js +1 -1
- package/esm/run-codegen/endpoints.js +5 -6
- package/esm/schema-model/normalize.js +1 -1
- package/esm/schema-model.js +4 -5
- package/esm/schema-resolve.d.ts +50 -0
- package/esm/schema-resolve.js +200 -14
- package/esm/table-access.d.ts +116 -0
- package/esm/table-access.js +418 -0
- package/esm/tools/access.d.ts +218 -0
- package/esm/tools/access.js +651 -0
- package/esm/tools/add-policies.d.ts +44 -12
- package/esm/tools/add-policies.js +84 -84
- package/esm/tools/add-records.d.ts +23 -2
- package/esm/tools/add-records.js +113 -75
- package/esm/tools/add-relation-schema.d.ts +5 -5
- package/esm/tools/add-relation-schema.js +13 -14
- package/esm/tools/add-relation.d.ts +11 -2
- package/esm/tools/add-relation.js +68 -31
- package/esm/tools/create-api-key.d.ts +18 -4
- package/esm/tools/create-api-key.js +105 -54
- package/esm/tools/describe-schema.d.ts +5 -7
- package/esm/tools/describe-schema.js +41 -118
- package/esm/tools/entity-types.d.ts +54 -0
- package/esm/tools/entity-types.js +233 -0
- package/esm/tools/index.d.ts +26 -0
- package/esm/tools/index.js +151 -0
- package/esm/tools/mutations.d.ts +36 -7
- package/esm/tools/mutations.js +245 -99
- package/esm/tools/provision-blueprint.d.ts +25 -1
- package/esm/tools/provision-blueprint.js +184 -42
- package/esm/tools/provision-database.d.ts +7 -5
- package/esm/tools/provision-database.js +31 -17
- package/esm/tools/run-codegen.d.ts +27 -4
- package/esm/tools/run-codegen.js +143 -76
- package/esm/tools/templates.d.ts +30 -7
- package/esm/tools/templates.js +166 -95
- package/failure.d.ts +89 -0
- package/failure.js +375 -0
- package/gate.d.ts +6 -4
- package/gate.js +41 -13
- package/graphql-http.d.ts +27 -6
- package/graphql-http.js +105 -25
- package/host.d.ts +33 -8
- package/host.js +45 -2
- package/index.d.ts +22 -12
- package/index.js +86 -43
- package/package.json +6 -5
- package/provision-database/env-file.d.ts +7 -0
- package/provision-database/env-file.js +32 -1
- package/provision-database/preset-match.js +1 -2
- package/provision-database/provision.d.ts +21 -4
- package/provision-database/provision.js +327 -81
- package/provision-database/request-database.d.ts +22 -3
- package/provision-database/request-database.js +49 -14
- package/ready.d.ts +20 -0
- package/ready.js +52 -0
- package/run-codegen/barrels.js +1 -1
- package/run-codegen/endpoints.js +5 -6
- package/schema-model/normalize.js +4 -4
- package/schema-model.js +4 -5
- package/schema-resolve.d.ts +50 -0
- package/schema-resolve.js +209 -14
- package/table-access.d.ts +116 -0
- package/table-access.js +437 -0
- package/tools/access.d.ts +218 -0
- package/tools/access.js +669 -0
- package/tools/add-policies.d.ts +44 -12
- package/tools/add-policies.js +86 -84
- package/tools/add-records.d.ts +23 -2
- package/tools/add-records.js +113 -74
- package/tools/add-relation-schema.d.ts +5 -5
- package/tools/add-relation-schema.js +13 -14
- package/tools/add-relation.d.ts +11 -2
- package/tools/add-relation.js +69 -31
- package/tools/create-api-key.d.ts +18 -4
- package/tools/create-api-key.js +104 -53
- package/tools/describe-schema.d.ts +5 -7
- package/tools/describe-schema.js +40 -117
- package/tools/entity-types.d.ts +54 -0
- package/tools/entity-types.js +240 -0
- package/tools/index.d.ts +26 -0
- package/tools/index.js +154 -0
- package/tools/mutations.d.ts +36 -7
- package/tools/mutations.js +252 -101
- package/tools/provision-blueprint.d.ts +25 -1
- package/tools/provision-blueprint.js +186 -43
- package/tools/provision-database.d.ts +7 -5
- package/tools/provision-database.js +33 -18
- package/tools/run-codegen.d.ts +27 -4
- package/tools/run-codegen.js +141 -73
- package/tools/templates.d.ts +30 -7
- package/tools/templates.js +167 -94
- package/esm/policy/add-policies-to-table.d.ts +0 -26
- package/esm/policy/add-policies-to-table.js +0 -66
- package/esm/policy/provision-helpers.d.ts +0 -38
- package/esm/policy/provision-helpers.js +0 -50
- package/esm/tools/manage-entity-types.d.ts +0 -40
- package/esm/tools/manage-entity-types.js +0 -201
- package/policy/add-policies-to-table.d.ts +0 -26
- package/policy/add-policies-to-table.js +0 -71
- package/policy/provision-helpers.d.ts +0 -38
- package/policy/provision-helpers.js +0 -58
- package/tools/manage-entity-types.d.ts +0 -40
- package/tools/manage-entity-types.js +0 -206
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { resolveProjectContext } from '../context';
|
|
3
|
-
const ManageEntityTypesZod = z.object({
|
|
4
|
-
action: z
|
|
5
|
-
.enum(['list', 'create', 'delete'])
|
|
6
|
-
.describe('list: show the entity types provisioned in this database. create: provision a new entity type (creates its entity table + membership wiring). delete: remove the provision registration. Registrations are immutable once provisioned — there is no update; to change one, delete it and create a new one.'),
|
|
7
|
-
name: z.string().describe('Entity type name. Required for create.').optional(),
|
|
8
|
-
entity_type_id: z
|
|
9
|
-
.string()
|
|
10
|
-
.describe('Entity type provision id. Required for delete — get it from action "list".')
|
|
11
|
-
.optional(),
|
|
12
|
-
description: z
|
|
13
|
-
.string()
|
|
14
|
-
.describe('Human-readable description of the entity type. Create only.')
|
|
15
|
-
.optional(),
|
|
16
|
-
prefix: z
|
|
17
|
-
.string()
|
|
18
|
-
.describe('Table-name prefix for the provisioned tables (e.g. "org" → org table, org_memberships). Create only; defaults to the snake_case of name.')
|
|
19
|
-
.optional(),
|
|
20
|
-
parent_entity: z
|
|
21
|
-
.string()
|
|
22
|
-
.describe('Parent entity table name, for hierarchical types (e.g. a "team" under an "org"). Create only; the backend defaults it to the root entity (org).')
|
|
23
|
-
.optional(),
|
|
24
|
-
is_visible: z
|
|
25
|
-
.boolean()
|
|
26
|
-
.describe('Whether the type shows up in end-user entity listings. Create only.')
|
|
27
|
-
.optional(),
|
|
28
|
-
has_invites: z
|
|
29
|
-
.boolean()
|
|
30
|
-
.describe('Provision an invites module ({prefix}_invites + claimed invites). Create only.')
|
|
31
|
-
.optional(),
|
|
32
|
-
has_profiles: z
|
|
33
|
-
.boolean()
|
|
34
|
-
.describe('Provision a profiles table for members of this type. Create only.')
|
|
35
|
-
.optional(),
|
|
36
|
-
has_limits: z
|
|
37
|
-
.boolean()
|
|
38
|
-
.describe('Provision usage-limits tracking for this type. Create only.')
|
|
39
|
-
.optional(),
|
|
40
|
-
has_levels: z
|
|
41
|
-
.boolean()
|
|
42
|
-
.describe('Provision levels/achievements support for this type. Create only.')
|
|
43
|
-
.optional(),
|
|
44
|
-
has_storage: z
|
|
45
|
-
.boolean()
|
|
46
|
-
.describe('Provision a storage module (files + buckets tables) for this type. Create only.')
|
|
47
|
-
.optional(),
|
|
48
|
-
});
|
|
49
|
-
const SUMMARY_SELECT = {
|
|
50
|
-
id: true,
|
|
51
|
-
name: true,
|
|
52
|
-
description: true,
|
|
53
|
-
prefix: true,
|
|
54
|
-
parentEntity: true,
|
|
55
|
-
isVisible: true,
|
|
56
|
-
outEntityTableName: true,
|
|
57
|
-
outInstalledModules: true,
|
|
58
|
-
};
|
|
59
|
-
function toSummary(row) {
|
|
60
|
-
return {
|
|
61
|
-
id: row.id,
|
|
62
|
-
name: row.name,
|
|
63
|
-
description: row.description,
|
|
64
|
-
prefix: row.prefix,
|
|
65
|
-
parentEntity: row.parentEntity,
|
|
66
|
-
isVisible: row.isVisible,
|
|
67
|
-
entityTableName: row.outEntityTableName,
|
|
68
|
-
installedModules: row.outInstalledModules,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function formatSummary(s) {
|
|
72
|
-
const parts = [
|
|
73
|
-
`- ${s.name ?? '?'} (id: ${s.id})`,
|
|
74
|
-
` table: ${s.entityTableName ?? '?'}, prefix: ${s.prefix ?? '?'}`,
|
|
75
|
-
];
|
|
76
|
-
if (s.parentEntity)
|
|
77
|
-
parts.push(` parent: ${s.parentEntity}`);
|
|
78
|
-
if (s.description)
|
|
79
|
-
parts.push(` description: ${s.description}`);
|
|
80
|
-
if (s.installedModules?.length)
|
|
81
|
-
parts.push(` modules: ${s.installedModules.join(', ')}`);
|
|
82
|
-
return parts.join('\n');
|
|
83
|
-
}
|
|
84
|
-
export function defaultPrefix(name) {
|
|
85
|
-
return name
|
|
86
|
-
.trim()
|
|
87
|
-
.toLowerCase()
|
|
88
|
-
.replace(/[^a-z0-9]+/g, '_')
|
|
89
|
-
.replace(/^_+|_+$/g, '');
|
|
90
|
-
}
|
|
91
|
-
export function validateManageEntityTypes(params) {
|
|
92
|
-
switch (params.action) {
|
|
93
|
-
case 'create':
|
|
94
|
-
if (!params.name?.trim())
|
|
95
|
-
return 'create requires "name".';
|
|
96
|
-
if (params.entity_type_id)
|
|
97
|
-
return 'create does not take "entity_type_id" — it mints a new one.';
|
|
98
|
-
return null;
|
|
99
|
-
case 'delete':
|
|
100
|
-
if (!params.entity_type_id)
|
|
101
|
-
return 'delete requires "entity_type_id" (use action "list" to find it).';
|
|
102
|
-
return null;
|
|
103
|
-
default:
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
export const manageEntityTypesTool = {
|
|
108
|
-
name: 'manage_entity_types',
|
|
109
|
-
label: 'Manage entity types',
|
|
110
|
-
description: 'List, create, or delete entity types in the project database. An entity type (e.g. organization, team, project) provisions its own entity table plus membership wiring, and is the unit that API keys can be scoped to. Registrations are immutable once provisioned — to change one, delete it and create a new one. Deleting removes the registration; the already-provisioned entity table stays in the API schema.',
|
|
111
|
-
promptSnippet: 'manage_entity_types: list/create/delete entity types (orgs, teams, …) in the project database. list is free; create/delete are gated.',
|
|
112
|
-
parameters: ManageEntityTypesZod,
|
|
113
|
-
async execute(params, ctx) {
|
|
114
|
-
const resolved = await resolveProjectContext(ctx.cwd);
|
|
115
|
-
if (!resolved.context) {
|
|
116
|
-
return {
|
|
117
|
-
content: [{ type: 'text', text: resolved.reason }],
|
|
118
|
-
details: { success: false, message: resolved.reason },
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
const invalid = validateManageEntityTypes(params);
|
|
122
|
-
if (invalid) {
|
|
123
|
-
return {
|
|
124
|
-
content: [{ type: 'text', text: invalid }],
|
|
125
|
-
details: { success: false, message: invalid },
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
const { modules, databaseId } = resolved.context;
|
|
129
|
-
try {
|
|
130
|
-
switch (params.action) {
|
|
131
|
-
case 'list': {
|
|
132
|
-
const result = await modules.entityTypeProvision
|
|
133
|
-
.findMany({
|
|
134
|
-
where: { databaseId: { equalTo: databaseId } },
|
|
135
|
-
select: SUMMARY_SELECT,
|
|
136
|
-
})
|
|
137
|
-
.unwrap();
|
|
138
|
-
const entityTypes = result.entityTypeProvisions.nodes.map((row) => toSummary(row));
|
|
139
|
-
const message = entityTypes.length === 0
|
|
140
|
-
? 'No entity types are provisioned in this database yet.'
|
|
141
|
-
: `${entityTypes.length} entity type${entityTypes.length === 1 ? '' : 's'}:\n${entityTypes.map(formatSummary).join('\n')}`;
|
|
142
|
-
return {
|
|
143
|
-
content: [{ type: 'text', text: message }],
|
|
144
|
-
details: { success: true, message, entityTypes },
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
case 'create': {
|
|
148
|
-
const name = params.name.trim();
|
|
149
|
-
const result = await modules.entityTypeProvision
|
|
150
|
-
.create({
|
|
151
|
-
data: {
|
|
152
|
-
databaseId,
|
|
153
|
-
name,
|
|
154
|
-
prefix: params.prefix?.trim() || defaultPrefix(name),
|
|
155
|
-
...(params.description !== undefined && { description: params.description }),
|
|
156
|
-
...(params.parent_entity !== undefined && { parentEntity: params.parent_entity }),
|
|
157
|
-
...(params.is_visible !== undefined && { isVisible: params.is_visible }),
|
|
158
|
-
...(params.has_invites !== undefined && { hasInvites: params.has_invites }),
|
|
159
|
-
...(params.has_profiles !== undefined && { hasProfiles: params.has_profiles }),
|
|
160
|
-
...(params.has_limits !== undefined && { hasLimits: params.has_limits }),
|
|
161
|
-
...(params.has_levels !== undefined && { hasLevels: params.has_levels }),
|
|
162
|
-
...(params.has_storage && {
|
|
163
|
-
storage: [{}],
|
|
164
|
-
}),
|
|
165
|
-
},
|
|
166
|
-
select: SUMMARY_SELECT,
|
|
167
|
-
})
|
|
168
|
-
.unwrap();
|
|
169
|
-
const row = result.createEntityTypeProvision?.entityTypeProvision;
|
|
170
|
-
if (!row)
|
|
171
|
-
throw new Error('createEntityTypeProvision returned no row.');
|
|
172
|
-
const summary = toSummary(row);
|
|
173
|
-
const message = `Created entity type "${summary.name}" (id: ${summary.id}) — entity table "${summary.entityTableName}"${summary.installedModules?.length ? `, modules: ${summary.installedModules.join(', ')}` : ''}. Run run_codegen to pull it into the typed SDK.`;
|
|
174
|
-
return {
|
|
175
|
-
content: [{ type: 'text', text: message }],
|
|
176
|
-
details: { success: true, message, entityTypes: [summary] },
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
case 'delete': {
|
|
180
|
-
const result = await modules.entityTypeProvision
|
|
181
|
-
.delete({
|
|
182
|
-
where: { id: params.entity_type_id },
|
|
183
|
-
select: { id: true, name: true, outEntityTableName: true },
|
|
184
|
-
})
|
|
185
|
-
.unwrap();
|
|
186
|
-
const row = result.deleteEntityTypeProvision?.entityTypeProvision;
|
|
187
|
-
const name = row?.name ?? params.entity_type_id;
|
|
188
|
-
const message = `Deleted entity type registration "${name}". Note: the provisioned entity table${row?.outEntityTableName ? ` "${row.outEntityTableName}"` : ''} remains in the API schema with its data.`;
|
|
189
|
-
return {
|
|
190
|
-
content: [{ type: 'text', text: message }],
|
|
191
|
-
details: { success: true, message },
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
catch (err) {
|
|
197
|
-
const message = err instanceof Error ? err.message : 'Failed to manage entity types';
|
|
198
|
-
return { content: [{ type: 'text', text: message }], details: { success: false, message } };
|
|
199
|
-
}
|
|
200
|
-
},
|
|
201
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type PolicyProvisioningCategory } from '@agentic-kit/harness';
|
|
2
|
-
import type { ModulesClient } from '../context';
|
|
3
|
-
import { type CrudOperation, type CrudPolicyConfigs } from './provision-helpers';
|
|
4
|
-
export interface AddPoliciesToTablePolicyEntry {
|
|
5
|
-
policyType: string;
|
|
6
|
-
dataNodeType?: string;
|
|
7
|
-
nodeData?: Record<string, unknown>;
|
|
8
|
-
sharedPolicyData: Record<string, unknown>;
|
|
9
|
-
operations: CrudPolicyConfigs;
|
|
10
|
-
enabledOperations?: CrudOperation[];
|
|
11
|
-
}
|
|
12
|
-
export interface AddPoliciesToTableInput {
|
|
13
|
-
client: ModulesClient;
|
|
14
|
-
databaseId: string;
|
|
15
|
-
schemaId: string;
|
|
16
|
-
tableId: string;
|
|
17
|
-
policies: AddPoliciesToTablePolicyEntry[];
|
|
18
|
-
}
|
|
19
|
-
export declare class UnsupportedPolicyCategoryError extends Error {
|
|
20
|
-
readonly policyType: string;
|
|
21
|
-
readonly category: PolicyProvisioningCategory;
|
|
22
|
-
constructor(policyType: string, category: PolicyProvisioningCategory);
|
|
23
|
-
}
|
|
24
|
-
export declare function addPoliciesToExistingTable(input: AddPoliciesToTableInput): Promise<{
|
|
25
|
-
success: true;
|
|
26
|
-
}>;
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.UnsupportedPolicyCategoryError = void 0;
|
|
4
|
-
exports.addPoliciesToExistingTable = addPoliciesToExistingTable;
|
|
5
|
-
const harness_1 = require("@agentic-kit/harness");
|
|
6
|
-
const provision_helpers_1 = require("./provision-helpers");
|
|
7
|
-
const SUPPORTED_CATEGORIES = new Set([
|
|
8
|
-
'has-module',
|
|
9
|
-
'no-fields',
|
|
10
|
-
'needs-table',
|
|
11
|
-
]);
|
|
12
|
-
class UnsupportedPolicyCategoryError extends Error {
|
|
13
|
-
policyType;
|
|
14
|
-
category;
|
|
15
|
-
constructor(policyType, category) {
|
|
16
|
-
super(`Policy type "${policyType}" has category "${category}" which requires column creation or composite handling — use the policies UI instead.`);
|
|
17
|
-
this.policyType = policyType;
|
|
18
|
-
this.category = category;
|
|
19
|
-
this.name = 'UnsupportedPolicyCategoryError';
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
exports.UnsupportedPolicyCategoryError = UnsupportedPolicyCategoryError;
|
|
23
|
-
async function addPoliciesToExistingTable(input) {
|
|
24
|
-
const { client } = input;
|
|
25
|
-
for (const entry of input.policies) {
|
|
26
|
-
const category = (0, harness_1.getPolicyCategory)(entry.policyType);
|
|
27
|
-
if (!SUPPORTED_CATEGORIES.has(category)) {
|
|
28
|
-
throw new UnsupportedPolicyCategoryError(entry.policyType, category);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
const policiesArray = [];
|
|
32
|
-
const nodesByType = new Map();
|
|
33
|
-
for (const entry of input.policies) {
|
|
34
|
-
const groups = (0, provision_helpers_1.groupOperationsByConfig)(entry.enabledOperations ?? provision_helpers_1.CRUD_OPERATIONS, entry.operations);
|
|
35
|
-
for (const group of groups) {
|
|
36
|
-
const ops = group.privileges.join('_');
|
|
37
|
-
const rand = Math.random().toString(36).slice(2, 8);
|
|
38
|
-
policiesArray.push((0, provision_helpers_1.buildPolicyEntry)(entry.policyType, {
|
|
39
|
-
privileges: group.privileges,
|
|
40
|
-
policy_role: group.roleName,
|
|
41
|
-
permissive: group.isPermissive,
|
|
42
|
-
data: entry.sharedPolicyData,
|
|
43
|
-
policy_name: `${ops}_${rand}`,
|
|
44
|
-
}));
|
|
45
|
-
}
|
|
46
|
-
if (entry.dataNodeType && !nodesByType.has(entry.dataNodeType)) {
|
|
47
|
-
const nodeData = entry.nodeData ?? {};
|
|
48
|
-
nodesByType.set(entry.dataNodeType, {
|
|
49
|
-
$type: entry.dataNodeType,
|
|
50
|
-
...(Object.keys(nodeData).length > 0 ? { data: nodeData } : {}),
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const provisionInput = {
|
|
55
|
-
databaseId: input.databaseId,
|
|
56
|
-
schemaId: input.schemaId,
|
|
57
|
-
tableId: input.tableId,
|
|
58
|
-
grants: (0, provision_helpers_1.buildGrants)(),
|
|
59
|
-
policies: policiesArray,
|
|
60
|
-
};
|
|
61
|
-
if (nodesByType.size > 0) {
|
|
62
|
-
provisionInput.nodes = [...nodesByType.values()];
|
|
63
|
-
}
|
|
64
|
-
await client.secureTableProvision
|
|
65
|
-
.create({
|
|
66
|
-
data: provisionInput,
|
|
67
|
-
select: { id: true, tableId: true, tableName: true },
|
|
68
|
-
})
|
|
69
|
-
.unwrap();
|
|
70
|
-
return { success: true };
|
|
71
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export type CrudOperation = 'create' | 'read' | 'update' | 'delete';
|
|
2
|
-
export interface OperationPolicyConfig {
|
|
3
|
-
roleName: string;
|
|
4
|
-
isPermissive: boolean;
|
|
5
|
-
policyData: Record<string, unknown>;
|
|
6
|
-
isCustomized: boolean;
|
|
7
|
-
}
|
|
8
|
-
export interface CrudPolicyConfigs {
|
|
9
|
-
create: OperationPolicyConfig;
|
|
10
|
-
read: OperationPolicyConfig;
|
|
11
|
-
update: OperationPolicyConfig;
|
|
12
|
-
delete: OperationPolicyConfig;
|
|
13
|
-
}
|
|
14
|
-
export declare const CRUD_OPERATIONS: CrudOperation[];
|
|
15
|
-
export type GrantPrivilege = [string, string | string[]];
|
|
16
|
-
export interface GrantEntry {
|
|
17
|
-
roles: string[];
|
|
18
|
-
privileges: GrantPrivilege[];
|
|
19
|
-
}
|
|
20
|
-
export interface PolicyEntry {
|
|
21
|
-
$type: string;
|
|
22
|
-
data?: Record<string, unknown>;
|
|
23
|
-
privileges?: string[];
|
|
24
|
-
policy_role?: string;
|
|
25
|
-
permissive?: boolean;
|
|
26
|
-
policy_name?: string;
|
|
27
|
-
}
|
|
28
|
-
export declare const ALL_CRUD_PRIVILEGES: GrantPrivilege[];
|
|
29
|
-
export declare function crudOpToPrivilege(op: CrudOperation): string;
|
|
30
|
-
export declare function crudOpsToPrivileges(ops: readonly CrudOperation[]): string[];
|
|
31
|
-
export declare function buildGrants(roles?: string[], privileges?: GrantPrivilege[]): GrantEntry[];
|
|
32
|
-
export declare function buildPolicyEntry(type: string, opts?: Partial<Omit<PolicyEntry, '$type'>>): PolicyEntry;
|
|
33
|
-
export interface OperationGroup {
|
|
34
|
-
roleName: string;
|
|
35
|
-
isPermissive: boolean;
|
|
36
|
-
privileges: string[];
|
|
37
|
-
}
|
|
38
|
-
export declare function groupOperationsByConfig(enabledOperations: readonly CrudOperation[], operations: CrudPolicyConfigs): OperationGroup[];
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ALL_CRUD_PRIVILEGES = exports.CRUD_OPERATIONS = void 0;
|
|
4
|
-
exports.crudOpToPrivilege = crudOpToPrivilege;
|
|
5
|
-
exports.crudOpsToPrivileges = crudOpsToPrivileges;
|
|
6
|
-
exports.buildGrants = buildGrants;
|
|
7
|
-
exports.buildPolicyEntry = buildPolicyEntry;
|
|
8
|
-
exports.groupOperationsByConfig = groupOperationsByConfig;
|
|
9
|
-
exports.CRUD_OPERATIONS = ['create', 'read', 'update', 'delete'];
|
|
10
|
-
exports.ALL_CRUD_PRIVILEGES = [
|
|
11
|
-
['select', '*'],
|
|
12
|
-
['insert', '*'],
|
|
13
|
-
['update', '*'],
|
|
14
|
-
['delete', '*'],
|
|
15
|
-
];
|
|
16
|
-
const CRUD_OP_TO_LOWER_PRIVILEGE = {
|
|
17
|
-
create: 'insert',
|
|
18
|
-
read: 'select',
|
|
19
|
-
update: 'update',
|
|
20
|
-
delete: 'delete',
|
|
21
|
-
};
|
|
22
|
-
function crudOpToPrivilege(op) {
|
|
23
|
-
return CRUD_OP_TO_LOWER_PRIVILEGE[op];
|
|
24
|
-
}
|
|
25
|
-
function crudOpsToPrivileges(ops) {
|
|
26
|
-
return ops.map(crudOpToPrivilege);
|
|
27
|
-
}
|
|
28
|
-
function buildGrants(roles = ['authenticated'], privileges = exports.ALL_CRUD_PRIVILEGES) {
|
|
29
|
-
return [{ roles, privileges }];
|
|
30
|
-
}
|
|
31
|
-
function buildPolicyEntry(type, opts = {}) {
|
|
32
|
-
const entry = { $type: type };
|
|
33
|
-
if (opts.data && Object.keys(opts.data).length > 0)
|
|
34
|
-
entry.data = opts.data;
|
|
35
|
-
if (opts.privileges && opts.privileges.length > 0)
|
|
36
|
-
entry.privileges = opts.privileges;
|
|
37
|
-
if (opts.policy_role)
|
|
38
|
-
entry.policy_role = opts.policy_role;
|
|
39
|
-
if (opts.permissive !== undefined)
|
|
40
|
-
entry.permissive = opts.permissive;
|
|
41
|
-
if (opts.policy_name)
|
|
42
|
-
entry.policy_name = opts.policy_name;
|
|
43
|
-
return entry;
|
|
44
|
-
}
|
|
45
|
-
function groupOperationsByConfig(enabledOperations, operations) {
|
|
46
|
-
const groupMap = new Map();
|
|
47
|
-
for (const op of enabledOperations) {
|
|
48
|
-
const config = operations[op];
|
|
49
|
-
const key = `${config.roleName}:${config.isPermissive}`;
|
|
50
|
-
let group = groupMap.get(key);
|
|
51
|
-
if (!group) {
|
|
52
|
-
group = { roleName: config.roleName, isPermissive: config.isPermissive, privileges: [] };
|
|
53
|
-
groupMap.set(key, group);
|
|
54
|
-
}
|
|
55
|
-
group.privileges.push(...crudOpsToPrivileges([op]));
|
|
56
|
-
}
|
|
57
|
-
return [...groupMap.values()];
|
|
58
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import type { HarnessTool } from '@agentic-kit/harness';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
declare const ManageEntityTypesZod: z.ZodObject<{
|
|
4
|
-
action: z.ZodEnum<{
|
|
5
|
-
delete: "delete";
|
|
6
|
-
create: "create";
|
|
7
|
-
list: "list";
|
|
8
|
-
}>;
|
|
9
|
-
name: z.ZodOptional<z.ZodString>;
|
|
10
|
-
entity_type_id: z.ZodOptional<z.ZodString>;
|
|
11
|
-
description: z.ZodOptional<z.ZodString>;
|
|
12
|
-
prefix: z.ZodOptional<z.ZodString>;
|
|
13
|
-
parent_entity: z.ZodOptional<z.ZodString>;
|
|
14
|
-
is_visible: z.ZodOptional<z.ZodBoolean>;
|
|
15
|
-
has_invites: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
-
has_profiles: z.ZodOptional<z.ZodBoolean>;
|
|
17
|
-
has_limits: z.ZodOptional<z.ZodBoolean>;
|
|
18
|
-
has_levels: z.ZodOptional<z.ZodBoolean>;
|
|
19
|
-
has_storage: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
-
}, z.core.$strip>;
|
|
21
|
-
export type EntityTypeSummary = {
|
|
22
|
-
id: string;
|
|
23
|
-
name: string | null;
|
|
24
|
-
description: string | null;
|
|
25
|
-
prefix: string | null;
|
|
26
|
-
parentEntity: string | null;
|
|
27
|
-
isVisible: boolean | null;
|
|
28
|
-
entityTableName: string | null;
|
|
29
|
-
installedModules: string[] | null;
|
|
30
|
-
};
|
|
31
|
-
export type ManageEntityTypesDetails = {
|
|
32
|
-
success: boolean;
|
|
33
|
-
message: string;
|
|
34
|
-
entityTypes?: EntityTypeSummary[];
|
|
35
|
-
};
|
|
36
|
-
export declare function defaultPrefix(name: string): string;
|
|
37
|
-
type Params = z.infer<typeof ManageEntityTypesZod>;
|
|
38
|
-
export declare function validateManageEntityTypes(params: Params): string | null;
|
|
39
|
-
export declare const manageEntityTypesTool: HarnessTool<typeof ManageEntityTypesZod, ManageEntityTypesDetails>;
|
|
40
|
-
export {};
|
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.manageEntityTypesTool = void 0;
|
|
4
|
-
exports.defaultPrefix = defaultPrefix;
|
|
5
|
-
exports.validateManageEntityTypes = validateManageEntityTypes;
|
|
6
|
-
const zod_1 = require("zod");
|
|
7
|
-
const context_1 = require("../context");
|
|
8
|
-
const ManageEntityTypesZod = zod_1.z.object({
|
|
9
|
-
action: zod_1.z
|
|
10
|
-
.enum(['list', 'create', 'delete'])
|
|
11
|
-
.describe('list: show the entity types provisioned in this database. create: provision a new entity type (creates its entity table + membership wiring). delete: remove the provision registration. Registrations are immutable once provisioned — there is no update; to change one, delete it and create a new one.'),
|
|
12
|
-
name: zod_1.z.string().describe('Entity type name. Required for create.').optional(),
|
|
13
|
-
entity_type_id: zod_1.z
|
|
14
|
-
.string()
|
|
15
|
-
.describe('Entity type provision id. Required for delete — get it from action "list".')
|
|
16
|
-
.optional(),
|
|
17
|
-
description: zod_1.z
|
|
18
|
-
.string()
|
|
19
|
-
.describe('Human-readable description of the entity type. Create only.')
|
|
20
|
-
.optional(),
|
|
21
|
-
prefix: zod_1.z
|
|
22
|
-
.string()
|
|
23
|
-
.describe('Table-name prefix for the provisioned tables (e.g. "org" → org table, org_memberships). Create only; defaults to the snake_case of name.')
|
|
24
|
-
.optional(),
|
|
25
|
-
parent_entity: zod_1.z
|
|
26
|
-
.string()
|
|
27
|
-
.describe('Parent entity table name, for hierarchical types (e.g. a "team" under an "org"). Create only; the backend defaults it to the root entity (org).')
|
|
28
|
-
.optional(),
|
|
29
|
-
is_visible: zod_1.z
|
|
30
|
-
.boolean()
|
|
31
|
-
.describe('Whether the type shows up in end-user entity listings. Create only.')
|
|
32
|
-
.optional(),
|
|
33
|
-
has_invites: zod_1.z
|
|
34
|
-
.boolean()
|
|
35
|
-
.describe('Provision an invites module ({prefix}_invites + claimed invites). Create only.')
|
|
36
|
-
.optional(),
|
|
37
|
-
has_profiles: zod_1.z
|
|
38
|
-
.boolean()
|
|
39
|
-
.describe('Provision a profiles table for members of this type. Create only.')
|
|
40
|
-
.optional(),
|
|
41
|
-
has_limits: zod_1.z
|
|
42
|
-
.boolean()
|
|
43
|
-
.describe('Provision usage-limits tracking for this type. Create only.')
|
|
44
|
-
.optional(),
|
|
45
|
-
has_levels: zod_1.z
|
|
46
|
-
.boolean()
|
|
47
|
-
.describe('Provision levels/achievements support for this type. Create only.')
|
|
48
|
-
.optional(),
|
|
49
|
-
has_storage: zod_1.z
|
|
50
|
-
.boolean()
|
|
51
|
-
.describe('Provision a storage module (files + buckets tables) for this type. Create only.')
|
|
52
|
-
.optional(),
|
|
53
|
-
});
|
|
54
|
-
const SUMMARY_SELECT = {
|
|
55
|
-
id: true,
|
|
56
|
-
name: true,
|
|
57
|
-
description: true,
|
|
58
|
-
prefix: true,
|
|
59
|
-
parentEntity: true,
|
|
60
|
-
isVisible: true,
|
|
61
|
-
outEntityTableName: true,
|
|
62
|
-
outInstalledModules: true,
|
|
63
|
-
};
|
|
64
|
-
function toSummary(row) {
|
|
65
|
-
return {
|
|
66
|
-
id: row.id,
|
|
67
|
-
name: row.name,
|
|
68
|
-
description: row.description,
|
|
69
|
-
prefix: row.prefix,
|
|
70
|
-
parentEntity: row.parentEntity,
|
|
71
|
-
isVisible: row.isVisible,
|
|
72
|
-
entityTableName: row.outEntityTableName,
|
|
73
|
-
installedModules: row.outInstalledModules,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
function formatSummary(s) {
|
|
77
|
-
const parts = [
|
|
78
|
-
`- ${s.name ?? '?'} (id: ${s.id})`,
|
|
79
|
-
` table: ${s.entityTableName ?? '?'}, prefix: ${s.prefix ?? '?'}`,
|
|
80
|
-
];
|
|
81
|
-
if (s.parentEntity)
|
|
82
|
-
parts.push(` parent: ${s.parentEntity}`);
|
|
83
|
-
if (s.description)
|
|
84
|
-
parts.push(` description: ${s.description}`);
|
|
85
|
-
if (s.installedModules?.length)
|
|
86
|
-
parts.push(` modules: ${s.installedModules.join(', ')}`);
|
|
87
|
-
return parts.join('\n');
|
|
88
|
-
}
|
|
89
|
-
function defaultPrefix(name) {
|
|
90
|
-
return name
|
|
91
|
-
.trim()
|
|
92
|
-
.toLowerCase()
|
|
93
|
-
.replace(/[^a-z0-9]+/g, '_')
|
|
94
|
-
.replace(/^_+|_+$/g, '');
|
|
95
|
-
}
|
|
96
|
-
function validateManageEntityTypes(params) {
|
|
97
|
-
switch (params.action) {
|
|
98
|
-
case 'create':
|
|
99
|
-
if (!params.name?.trim())
|
|
100
|
-
return 'create requires "name".';
|
|
101
|
-
if (params.entity_type_id)
|
|
102
|
-
return 'create does not take "entity_type_id" — it mints a new one.';
|
|
103
|
-
return null;
|
|
104
|
-
case 'delete':
|
|
105
|
-
if (!params.entity_type_id)
|
|
106
|
-
return 'delete requires "entity_type_id" (use action "list" to find it).';
|
|
107
|
-
return null;
|
|
108
|
-
default:
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
exports.manageEntityTypesTool = {
|
|
113
|
-
name: 'manage_entity_types',
|
|
114
|
-
label: 'Manage entity types',
|
|
115
|
-
description: 'List, create, or delete entity types in the project database. An entity type (e.g. organization, team, project) provisions its own entity table plus membership wiring, and is the unit that API keys can be scoped to. Registrations are immutable once provisioned — to change one, delete it and create a new one. Deleting removes the registration; the already-provisioned entity table stays in the API schema.',
|
|
116
|
-
promptSnippet: 'manage_entity_types: list/create/delete entity types (orgs, teams, …) in the project database. list is free; create/delete are gated.',
|
|
117
|
-
parameters: ManageEntityTypesZod,
|
|
118
|
-
async execute(params, ctx) {
|
|
119
|
-
const resolved = await (0, context_1.resolveProjectContext)(ctx.cwd);
|
|
120
|
-
if (!resolved.context) {
|
|
121
|
-
return {
|
|
122
|
-
content: [{ type: 'text', text: resolved.reason }],
|
|
123
|
-
details: { success: false, message: resolved.reason },
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
const invalid = validateManageEntityTypes(params);
|
|
127
|
-
if (invalid) {
|
|
128
|
-
return {
|
|
129
|
-
content: [{ type: 'text', text: invalid }],
|
|
130
|
-
details: { success: false, message: invalid },
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
const { modules, databaseId } = resolved.context;
|
|
134
|
-
try {
|
|
135
|
-
switch (params.action) {
|
|
136
|
-
case 'list': {
|
|
137
|
-
const result = await modules.entityTypeProvision
|
|
138
|
-
.findMany({
|
|
139
|
-
where: { databaseId: { equalTo: databaseId } },
|
|
140
|
-
select: SUMMARY_SELECT,
|
|
141
|
-
})
|
|
142
|
-
.unwrap();
|
|
143
|
-
const entityTypes = result.entityTypeProvisions.nodes.map((row) => toSummary(row));
|
|
144
|
-
const message = entityTypes.length === 0
|
|
145
|
-
? 'No entity types are provisioned in this database yet.'
|
|
146
|
-
: `${entityTypes.length} entity type${entityTypes.length === 1 ? '' : 's'}:\n${entityTypes.map(formatSummary).join('\n')}`;
|
|
147
|
-
return {
|
|
148
|
-
content: [{ type: 'text', text: message }],
|
|
149
|
-
details: { success: true, message, entityTypes },
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
case 'create': {
|
|
153
|
-
const name = params.name.trim();
|
|
154
|
-
const result = await modules.entityTypeProvision
|
|
155
|
-
.create({
|
|
156
|
-
data: {
|
|
157
|
-
databaseId,
|
|
158
|
-
name,
|
|
159
|
-
prefix: params.prefix?.trim() || defaultPrefix(name),
|
|
160
|
-
...(params.description !== undefined && { description: params.description }),
|
|
161
|
-
...(params.parent_entity !== undefined && { parentEntity: params.parent_entity }),
|
|
162
|
-
...(params.is_visible !== undefined && { isVisible: params.is_visible }),
|
|
163
|
-
...(params.has_invites !== undefined && { hasInvites: params.has_invites }),
|
|
164
|
-
...(params.has_profiles !== undefined && { hasProfiles: params.has_profiles }),
|
|
165
|
-
...(params.has_limits !== undefined && { hasLimits: params.has_limits }),
|
|
166
|
-
...(params.has_levels !== undefined && { hasLevels: params.has_levels }),
|
|
167
|
-
...(params.has_storage && {
|
|
168
|
-
storage: [{}],
|
|
169
|
-
}),
|
|
170
|
-
},
|
|
171
|
-
select: SUMMARY_SELECT,
|
|
172
|
-
})
|
|
173
|
-
.unwrap();
|
|
174
|
-
const row = result.createEntityTypeProvision?.entityTypeProvision;
|
|
175
|
-
if (!row)
|
|
176
|
-
throw new Error('createEntityTypeProvision returned no row.');
|
|
177
|
-
const summary = toSummary(row);
|
|
178
|
-
const message = `Created entity type "${summary.name}" (id: ${summary.id}) — entity table "${summary.entityTableName}"${summary.installedModules?.length ? `, modules: ${summary.installedModules.join(', ')}` : ''}. Run run_codegen to pull it into the typed SDK.`;
|
|
179
|
-
return {
|
|
180
|
-
content: [{ type: 'text', text: message }],
|
|
181
|
-
details: { success: true, message, entityTypes: [summary] },
|
|
182
|
-
};
|
|
183
|
-
}
|
|
184
|
-
case 'delete': {
|
|
185
|
-
const result = await modules.entityTypeProvision
|
|
186
|
-
.delete({
|
|
187
|
-
where: { id: params.entity_type_id },
|
|
188
|
-
select: { id: true, name: true, outEntityTableName: true },
|
|
189
|
-
})
|
|
190
|
-
.unwrap();
|
|
191
|
-
const row = result.deleteEntityTypeProvision?.entityTypeProvision;
|
|
192
|
-
const name = row?.name ?? params.entity_type_id;
|
|
193
|
-
const message = `Deleted entity type registration "${name}". Note: the provisioned entity table${row?.outEntityTableName ? ` "${row.outEntityTableName}"` : ''} remains in the API schema with its data.`;
|
|
194
|
-
return {
|
|
195
|
-
content: [{ type: 'text', text: message }],
|
|
196
|
-
details: { success: true, message },
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
catch (err) {
|
|
202
|
-
const message = err instanceof Error ? err.message : 'Failed to manage entity types';
|
|
203
|
-
return { content: [{ type: 'text', text: message }], details: { success: false, message } };
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
};
|