narai-primitives 2.0.0-rc.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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/config/bootstrap.d.ts +28 -0
- package/dist/config/bootstrap.d.ts.map +1 -0
- package/dist/config/bootstrap.js +80 -0
- package/dist/config/bootstrap.js.map +1 -0
- package/dist/config/index.d.ts +13 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +12 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/load.d.ts +37 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +99 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/resolve.d.ts +23 -0
- package/dist/config/resolve.d.ts.map +1 -0
- package/dist/config/resolve.js +198 -0
- package/dist/config/resolve.js.map +1 -0
- package/dist/config/secrets.d.ts +20 -0
- package/dist/config/secrets.d.ts.map +1 -0
- package/dist/config/secrets.js +43 -0
- package/dist/config/secrets.js.map +1 -0
- package/dist/config/types.d.ts +104 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +11 -0
- package/dist/config/types.js.map +1 -0
- package/dist/connectors/aws/cli.d.ts +3 -0
- package/dist/connectors/aws/cli.d.ts.map +1 -0
- package/dist/connectors/aws/cli.js +27 -0
- package/dist/connectors/aws/cli.js.map +1 -0
- package/dist/connectors/aws/index.d.ts +27 -0
- package/dist/connectors/aws/index.d.ts.map +1 -0
- package/dist/connectors/aws/index.js +281 -0
- package/dist/connectors/aws/index.js.map +1 -0
- package/dist/connectors/aws/lib/aws_client.d.ts +140 -0
- package/dist/connectors/aws/lib/aws_client.d.ts.map +1 -0
- package/dist/connectors/aws/lib/aws_client.js +196 -0
- package/dist/connectors/aws/lib/aws_client.js.map +1 -0
- package/dist/connectors/aws/lib/aws_error.d.ts +10 -0
- package/dist/connectors/aws/lib/aws_error.d.ts.map +1 -0
- package/dist/connectors/aws/lib/aws_error.js +15 -0
- package/dist/connectors/aws/lib/aws_error.js.map +1 -0
- package/dist/connectors/confluence/cli.d.ts +3 -0
- package/dist/connectors/confluence/cli.d.ts.map +1 -0
- package/dist/connectors/confluence/cli.js +24 -0
- package/dist/connectors/confluence/cli.js.map +1 -0
- package/dist/connectors/confluence/index.d.ts +15 -0
- package/dist/connectors/confluence/index.d.ts.map +1 -0
- package/dist/connectors/confluence/index.js +295 -0
- package/dist/connectors/confluence/index.js.map +1 -0
- package/dist/connectors/confluence/lib/confluence_client.d.ts +135 -0
- package/dist/connectors/confluence/lib/confluence_client.d.ts.map +1 -0
- package/dist/connectors/confluence/lib/confluence_client.js +329 -0
- package/dist/connectors/confluence/lib/confluence_client.js.map +1 -0
- package/dist/connectors/confluence/lib/confluence_error.d.ts +13 -0
- package/dist/connectors/confluence/lib/confluence_error.d.ts.map +1 -0
- package/dist/connectors/confluence/lib/confluence_error.js +19 -0
- package/dist/connectors/confluence/lib/confluence_error.js.map +1 -0
- package/dist/connectors/db/cli.d.ts +5 -0
- package/dist/connectors/db/cli.d.ts.map +1 -0
- package/dist/connectors/db/cli.js +34 -0
- package/dist/connectors/db/cli.js.map +1 -0
- package/dist/connectors/db/config.d.ts +18 -0
- package/dist/connectors/db/config.d.ts.map +1 -0
- package/dist/connectors/db/config.js +142 -0
- package/dist/connectors/db/config.js.map +1 -0
- package/dist/connectors/db/connector.d.ts +31 -0
- package/dist/connectors/db/connector.d.ts.map +1 -0
- package/dist/connectors/db/connector.js +175 -0
- package/dist/connectors/db/connector.js.map +1 -0
- package/dist/connectors/db/dispatcher.d.ts +36 -0
- package/dist/connectors/db/dispatcher.d.ts.map +1 -0
- package/dist/connectors/db/dispatcher.js +597 -0
- package/dist/connectors/db/dispatcher.js.map +1 -0
- package/dist/connectors/db/index.d.ts +22 -0
- package/dist/connectors/db/index.d.ts.map +1 -0
- package/dist/connectors/db/index.js +26 -0
- package/dist/connectors/db/index.js.map +1 -0
- package/dist/connectors/db/lib/audit.d.ts +32 -0
- package/dist/connectors/db/lib/audit.d.ts.map +1 -0
- package/dist/connectors/db/lib/audit.js +130 -0
- package/dist/connectors/db/lib/audit.js.map +1 -0
- package/dist/connectors/db/lib/connection.d.ts +61 -0
- package/dist/connectors/db/lib/connection.d.ts.map +1 -0
- package/dist/connectors/db/lib/connection.js +326 -0
- package/dist/connectors/db/lib/connection.js.map +1 -0
- package/dist/connectors/db/lib/credentials.d.ts +60 -0
- package/dist/connectors/db/lib/credentials.d.ts.map +1 -0
- package/dist/connectors/db/lib/credentials.js +117 -0
- package/dist/connectors/db/lib/credentials.js.map +1 -0
- package/dist/connectors/db/lib/drivers/base.d.ts +83 -0
- package/dist/connectors/db/lib/drivers/base.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/base.js +46 -0
- package/dist/connectors/db/lib/drivers/base.js.map +1 -0
- package/dist/connectors/db/lib/drivers/dynamodb.d.ts +108 -0
- package/dist/connectors/db/lib/drivers/dynamodb.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/dynamodb.js +468 -0
- package/dist/connectors/db/lib/drivers/dynamodb.js.map +1 -0
- package/dist/connectors/db/lib/drivers/mongodb.d.ts +60 -0
- package/dist/connectors/db/lib/drivers/mongodb.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/mongodb.js +371 -0
- package/dist/connectors/db/lib/drivers/mongodb.js.map +1 -0
- package/dist/connectors/db/lib/drivers/mysql.d.ts +45 -0
- package/dist/connectors/db/lib/drivers/mysql.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/mysql.js +265 -0
- package/dist/connectors/db/lib/drivers/mysql.js.map +1 -0
- package/dist/connectors/db/lib/drivers/oracle.d.ts +53 -0
- package/dist/connectors/db/lib/drivers/oracle.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/oracle.js +350 -0
- package/dist/connectors/db/lib/drivers/oracle.js.map +1 -0
- package/dist/connectors/db/lib/drivers/postgresql.d.ts +65 -0
- package/dist/connectors/db/lib/drivers/postgresql.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/postgresql.js +294 -0
- package/dist/connectors/db/lib/drivers/postgresql.js.map +1 -0
- package/dist/connectors/db/lib/drivers/register.d.ts +16 -0
- package/dist/connectors/db/lib/drivers/register.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/register.js +111 -0
- package/dist/connectors/db/lib/drivers/register.js.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlite.d.ts +11 -0
- package/dist/connectors/db/lib/drivers/sqlite.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlite.js +147 -0
- package/dist/connectors/db/lib/drivers/sqlite.js.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlserver.d.ts +58 -0
- package/dist/connectors/db/lib/drivers/sqlserver.d.ts.map +1 -0
- package/dist/connectors/db/lib/drivers/sqlserver.js +274 -0
- package/dist/connectors/db/lib/drivers/sqlserver.js.map +1 -0
- package/dist/connectors/db/lib/environments.d.ts +68 -0
- package/dist/connectors/db/lib/environments.d.ts.map +1 -0
- package/dist/connectors/db/lib/environments.js +53 -0
- package/dist/connectors/db/lib/environments.js.map +1 -0
- package/dist/connectors/db/lib/index.d.ts +28 -0
- package/dist/connectors/db/lib/index.d.ts.map +1 -0
- package/dist/connectors/db/lib/index.js +30 -0
- package/dist/connectors/db/lib/index.js.map +1 -0
- package/dist/connectors/db/lib/plugin_config.d.ts +64 -0
- package/dist/connectors/db/lib/plugin_config.d.ts.map +1 -0
- package/dist/connectors/db/lib/plugin_config.js +287 -0
- package/dist/connectors/db/lib/plugin_config.js.map +1 -0
- package/dist/connectors/db/lib/policy.d.ts +162 -0
- package/dist/connectors/db/lib/policy.d.ts.map +1 -0
- package/dist/connectors/db/lib/policy.js +581 -0
- package/dist/connectors/db/lib/policy.js.map +1 -0
- package/dist/connectors/db/lib/query.d.ts +22 -0
- package/dist/connectors/db/lib/query.d.ts.map +1 -0
- package/dist/connectors/db/lib/query.js +93 -0
- package/dist/connectors/db/lib/query.js.map +1 -0
- package/dist/connectors/db/lib/schema.d.ts +13 -0
- package/dist/connectors/db/lib/schema.d.ts.map +1 -0
- package/dist/connectors/db/lib/schema.js +80 -0
- package/dist/connectors/db/lib/schema.js.map +1 -0
- package/dist/connectors/gcp/cli.d.ts +3 -0
- package/dist/connectors/gcp/cli.d.ts.map +1 -0
- package/dist/connectors/gcp/cli.js +24 -0
- package/dist/connectors/gcp/cli.js.map +1 -0
- package/dist/connectors/gcp/index.d.ts +24 -0
- package/dist/connectors/gcp/index.d.ts.map +1 -0
- package/dist/connectors/gcp/index.js +205 -0
- package/dist/connectors/gcp/index.js.map +1 -0
- package/dist/connectors/gcp/lib/gcp_client.d.ts +88 -0
- package/dist/connectors/gcp/lib/gcp_client.d.ts.map +1 -0
- package/dist/connectors/gcp/lib/gcp_client.js +434 -0
- package/dist/connectors/gcp/lib/gcp_client.js.map +1 -0
- package/dist/connectors/gcp/lib/gcp_error.d.ts +10 -0
- package/dist/connectors/gcp/lib/gcp_error.d.ts.map +1 -0
- package/dist/connectors/gcp/lib/gcp_error.js +15 -0
- package/dist/connectors/gcp/lib/gcp_error.js.map +1 -0
- package/dist/connectors/github/cli.d.ts +3 -0
- package/dist/connectors/github/cli.d.ts.map +1 -0
- package/dist/connectors/github/cli.js +23 -0
- package/dist/connectors/github/cli.js.map +1 -0
- package/dist/connectors/github/index.d.ts +23 -0
- package/dist/connectors/github/index.d.ts.map +1 -0
- package/dist/connectors/github/index.js +462 -0
- package/dist/connectors/github/index.js.map +1 -0
- package/dist/connectors/github/lib/github_client.d.ts +181 -0
- package/dist/connectors/github/lib/github_client.d.ts.map +1 -0
- package/dist/connectors/github/lib/github_client.js +383 -0
- package/dist/connectors/github/lib/github_client.js.map +1 -0
- package/dist/connectors/github/lib/github_error.d.ts +11 -0
- package/dist/connectors/github/lib/github_error.d.ts.map +1 -0
- package/dist/connectors/github/lib/github_error.js +17 -0
- package/dist/connectors/github/lib/github_error.js.map +1 -0
- package/dist/connectors/jira/cli.d.ts +3 -0
- package/dist/connectors/jira/cli.d.ts.map +1 -0
- package/dist/connectors/jira/cli.js +24 -0
- package/dist/connectors/jira/cli.js.map +1 -0
- package/dist/connectors/jira/index.d.ts +13 -0
- package/dist/connectors/jira/index.d.ts.map +1 -0
- package/dist/connectors/jira/index.js +287 -0
- package/dist/connectors/jira/index.js.map +1 -0
- package/dist/connectors/jira/lib/adf.d.ts +25 -0
- package/dist/connectors/jira/lib/adf.d.ts.map +1 -0
- package/dist/connectors/jira/lib/adf.js +105 -0
- package/dist/connectors/jira/lib/adf.js.map +1 -0
- package/dist/connectors/jira/lib/jira_client.d.ts +143 -0
- package/dist/connectors/jira/lib/jira_client.d.ts.map +1 -0
- package/dist/connectors/jira/lib/jira_client.js +355 -0
- package/dist/connectors/jira/lib/jira_client.js.map +1 -0
- package/dist/connectors/jira/lib/jira_error.d.ts +11 -0
- package/dist/connectors/jira/lib/jira_error.d.ts.map +1 -0
- package/dist/connectors/jira/lib/jira_error.js +17 -0
- package/dist/connectors/jira/lib/jira_error.js.map +1 -0
- package/dist/connectors/notion/cli.d.ts +3 -0
- package/dist/connectors/notion/cli.d.ts.map +1 -0
- package/dist/connectors/notion/cli.js +22 -0
- package/dist/connectors/notion/cli.js.map +1 -0
- package/dist/connectors/notion/index.d.ts +20 -0
- package/dist/connectors/notion/index.d.ts.map +1 -0
- package/dist/connectors/notion/index.js +317 -0
- package/dist/connectors/notion/index.js.map +1 -0
- package/dist/connectors/notion/lib/notion_client.d.ts +117 -0
- package/dist/connectors/notion/lib/notion_client.d.ts.map +1 -0
- package/dist/connectors/notion/lib/notion_client.js +377 -0
- package/dist/connectors/notion/lib/notion_client.js.map +1 -0
- package/dist/connectors/notion/lib/notion_error.d.ts +12 -0
- package/dist/connectors/notion/lib/notion_error.d.ts.map +1 -0
- package/dist/connectors/notion/lib/notion_error.js +18 -0
- package/dist/connectors/notion/lib/notion_error.js.map +1 -0
- package/dist/hub/cli.d.ts +4 -0
- package/dist/hub/cli.d.ts.map +1 -0
- package/dist/hub/cli.js +93 -0
- package/dist/hub/cli.js.map +1 -0
- package/dist/hub/dispatch.d.ts +33 -0
- package/dist/hub/dispatch.d.ts.map +1 -0
- package/dist/hub/dispatch.js +297 -0
- package/dist/hub/dispatch.js.map +1 -0
- package/dist/hub/index.d.ts +9 -0
- package/dist/hub/index.d.ts.map +1 -0
- package/dist/hub/index.js +215 -0
- package/dist/hub/index.js.map +1 -0
- package/dist/hub/plan.d.ts +24 -0
- package/dist/hub/plan.d.ts.map +1 -0
- package/dist/hub/plan.js +103 -0
- package/dist/hub/plan.js.map +1 -0
- package/dist/hub/types.d.ts +65 -0
- package/dist/hub/types.d.ts.map +1 -0
- package/dist/hub/types.js +3 -0
- package/dist/hub/types.js.map +1 -0
- package/dist/toolkit/_optional.d.ts +14 -0
- package/dist/toolkit/_optional.d.ts.map +1 -0
- package/dist/toolkit/_optional.js +96 -0
- package/dist/toolkit/_optional.js.map +1 -0
- package/dist/toolkit/agent_cli.d.ts +33 -0
- package/dist/toolkit/agent_cli.d.ts.map +1 -0
- package/dist/toolkit/agent_cli.js +62 -0
- package/dist/toolkit/agent_cli.js.map +1 -0
- package/dist/toolkit/agent_resolver.d.ts +46 -0
- package/dist/toolkit/agent_resolver.d.ts.map +1 -0
- package/dist/toolkit/agent_resolver.js +78 -0
- package/dist/toolkit/agent_resolver.js.map +1 -0
- package/dist/toolkit/audit/events.d.ts +45 -0
- package/dist/toolkit/audit/events.d.ts.map +1 -0
- package/dist/toolkit/audit/events.js +8 -0
- package/dist/toolkit/audit/events.js.map +1 -0
- package/dist/toolkit/audit/writer.d.ts +16 -0
- package/dist/toolkit/audit/writer.d.ts.map +1 -0
- package/dist/toolkit/audit/writer.js +73 -0
- package/dist/toolkit/audit/writer.js.map +1 -0
- package/dist/toolkit/cli/usage-report.d.ts +3 -0
- package/dist/toolkit/cli/usage-report.d.ts.map +1 -0
- package/dist/toolkit/cli/usage-report.js +76 -0
- package/dist/toolkit/cli/usage-report.js.map +1 -0
- package/dist/toolkit/connector.d.ts +142 -0
- package/dist/toolkit/connector.d.ts.map +1 -0
- package/dist/toolkit/connector.js +593 -0
- package/dist/toolkit/connector.js.map +1 -0
- package/dist/toolkit/extract_binary.d.ts +45 -0
- package/dist/toolkit/extract_binary.d.ts.map +1 -0
- package/dist/toolkit/extract_binary.js +342 -0
- package/dist/toolkit/extract_binary.js.map +1 -0
- package/dist/toolkit/extract_multimodal.d.ts +22 -0
- package/dist/toolkit/extract_multimodal.d.ts.map +1 -0
- package/dist/toolkit/extract_multimodal.js +209 -0
- package/dist/toolkit/extract_multimodal.js.map +1 -0
- package/dist/toolkit/fetch_attachment.d.ts +21 -0
- package/dist/toolkit/fetch_attachment.d.ts.map +1 -0
- package/dist/toolkit/fetch_attachment.js +169 -0
- package/dist/toolkit/fetch_attachment.js.map +1 -0
- package/dist/toolkit/fetch_helper.d.ts +47 -0
- package/dist/toolkit/fetch_helper.d.ts.map +1 -0
- package/dist/toolkit/fetch_helper.js +124 -0
- package/dist/toolkit/fetch_helper.js.map +1 -0
- package/dist/toolkit/guardrail.d.ts +63 -0
- package/dist/toolkit/guardrail.d.ts.map +1 -0
- package/dist/toolkit/guardrail.js +166 -0
- package/dist/toolkit/guardrail.js.map +1 -0
- package/dist/toolkit/hardship/curate.d.ts +47 -0
- package/dist/toolkit/hardship/curate.d.ts.map +1 -0
- package/dist/toolkit/hardship/curate.js +113 -0
- package/dist/toolkit/hardship/curate.js.map +1 -0
- package/dist/toolkit/hardship/patterns.d.ts +32 -0
- package/dist/toolkit/hardship/patterns.d.ts.map +1 -0
- package/dist/toolkit/hardship/patterns.js +98 -0
- package/dist/toolkit/hardship/patterns.js.map +1 -0
- package/dist/toolkit/hardship/preamble.d.ts +13 -0
- package/dist/toolkit/hardship/preamble.d.ts.map +1 -0
- package/dist/toolkit/hardship/preamble.js +47 -0
- package/dist/toolkit/hardship/preamble.js.map +1 -0
- package/dist/toolkit/hardship/read.d.ts +34 -0
- package/dist/toolkit/hardship/read.d.ts.map +1 -0
- package/dist/toolkit/hardship/read.js +116 -0
- package/dist/toolkit/hardship/read.js.map +1 -0
- package/dist/toolkit/hardship/record.d.ts +43 -0
- package/dist/toolkit/hardship/record.d.ts.map +1 -0
- package/dist/toolkit/hardship/record.js +74 -0
- package/dist/toolkit/hardship/record.js.map +1 -0
- package/dist/toolkit/hardship/scope.d.ts +20 -0
- package/dist/toolkit/hardship/scope.d.ts.map +1 -0
- package/dist/toolkit/hardship/scope.js +56 -0
- package/dist/toolkit/hardship/scope.js.map +1 -0
- package/dist/toolkit/index.d.ts +42 -0
- package/dist/toolkit/index.d.ts.map +1 -0
- package/dist/toolkit/index.js +51 -0
- package/dist/toolkit/index.js.map +1 -0
- package/dist/toolkit/plugin/curate-cmd.d.ts +22 -0
- package/dist/toolkit/plugin/curate-cmd.d.ts.map +1 -0
- package/dist/toolkit/plugin/curate-cmd.js +72 -0
- package/dist/toolkit/plugin/curate-cmd.js.map +1 -0
- package/dist/toolkit/plugin/prefs.d.ts +15 -0
- package/dist/toolkit/plugin/prefs.d.ts.map +1 -0
- package/dist/toolkit/plugin/prefs.js +78 -0
- package/dist/toolkit/plugin/prefs.js.map +1 -0
- package/dist/toolkit/plugin/reminder.d.ts +28 -0
- package/dist/toolkit/plugin/reminder.d.ts.map +1 -0
- package/dist/toolkit/plugin/reminder.js +103 -0
- package/dist/toolkit/plugin/reminder.js.map +1 -0
- package/dist/toolkit/policy/approval.d.ts +24 -0
- package/dist/toolkit/policy/approval.d.ts.map +1 -0
- package/dist/toolkit/policy/approval.js +56 -0
- package/dist/toolkit/policy/approval.js.map +1 -0
- package/dist/toolkit/policy/config.d.ts +38 -0
- package/dist/toolkit/policy/config.d.ts.map +1 -0
- package/dist/toolkit/policy/config.js +172 -0
- package/dist/toolkit/policy/config.js.map +1 -0
- package/dist/toolkit/policy/gate.d.ts +28 -0
- package/dist/toolkit/policy/gate.d.ts.map +1 -0
- package/dist/toolkit/policy/gate.js +126 -0
- package/dist/toolkit/policy/gate.js.map +1 -0
- package/dist/toolkit/policy/types.d.ts +106 -0
- package/dist/toolkit/policy/types.d.ts.map +1 -0
- package/dist/toolkit/policy/types.js +22 -0
- package/dist/toolkit/policy/types.js.map +1 -0
- package/dist/toolkit/security_check.d.ts +15 -0
- package/dist/toolkit/security_check.d.ts.map +1 -0
- package/dist/toolkit/security_check.js +109 -0
- package/dist/toolkit/security_check.js.map +1 -0
- package/dist/toolkit/usage/aggregate-cross-session.d.ts +36 -0
- package/dist/toolkit/usage/aggregate-cross-session.d.ts.map +1 -0
- package/dist/toolkit/usage/aggregate-cross-session.js +142 -0
- package/dist/toolkit/usage/aggregate-cross-session.js.map +1 -0
- package/dist/toolkit/usage/aggregate.d.ts +4 -0
- package/dist/toolkit/usage/aggregate.d.ts.map +1 -0
- package/dist/toolkit/usage/aggregate.js +105 -0
- package/dist/toolkit/usage/aggregate.js.map +1 -0
- package/dist/toolkit/usage/index.d.ts +11 -0
- package/dist/toolkit/usage/index.d.ts.map +1 -0
- package/dist/toolkit/usage/index.js +7 -0
- package/dist/toolkit/usage/index.js.map +1 -0
- package/dist/toolkit/usage/parse.d.ts +5 -0
- package/dist/toolkit/usage/parse.d.ts.map +1 -0
- package/dist/toolkit/usage/parse.js +19 -0
- package/dist/toolkit/usage/parse.js.map +1 -0
- package/dist/toolkit/usage/record.d.ts +8 -0
- package/dist/toolkit/usage/record.d.ts.map +1 -0
- package/dist/toolkit/usage/record.js +18 -0
- package/dist/toolkit/usage/record.js.map +1 -0
- package/dist/toolkit/usage/retention.d.ts +6 -0
- package/dist/toolkit/usage/retention.d.ts.map +1 -0
- package/dist/toolkit/usage/retention.js +71 -0
- package/dist/toolkit/usage/retention.js.map +1 -0
- package/dist/toolkit/usage/tokenize.d.ts +11 -0
- package/dist/toolkit/usage/tokenize.d.ts.map +1 -0
- package/dist/toolkit/usage/tokenize.js +24 -0
- package/dist/toolkit/usage/tokenize.js.map +1 -0
- package/dist/toolkit/usage/types.d.ts +34 -0
- package/dist/toolkit/usage/types.d.ts.map +1 -0
- package/dist/toolkit/usage/types.js +2 -0
- package/dist/toolkit/usage/types.js.map +1 -0
- package/package.json +124 -0
- package/plugin-hooks/session-summary.mjs +138 -0
- package/plugin-hooks/stale-summarize.mjs +70 -0
- package/plugin-hooks/usage-record.mjs +112 -0
- package/plugins/aws-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/aws-agent/README.md +46 -0
- package/plugins/aws-agent/bin/aws-agent +22 -0
- package/plugins/aws-agent/commands/aws-agent.md +6 -0
- package/plugins/aws-agent/hooks/hooks.json +49 -0
- package/plugins/aws-agent/hooks/reminder.mjs +16 -0
- package/plugins/aws-agent/package.json +9 -0
- package/plugins/aws-agent/skills/aws-agent/SKILL.md +70 -0
- package/plugins/confluence-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/confluence-agent/README.md +15 -0
- package/plugins/confluence-agent/bin/confluence-agent +17 -0
- package/plugins/confluence-agent/commands/confluence-agent.md +6 -0
- package/plugins/confluence-agent/hooks/hooks.json +49 -0
- package/plugins/confluence-agent/hooks/reminder.mjs +25 -0
- package/plugins/confluence-agent/package.json +8 -0
- package/plugins/confluence-agent/skills/confluence-agent/SKILL.md +40 -0
- package/plugins/db-agent/.claude-plugin/plugin.json +20 -0
- package/plugins/db-agent/README.md +13 -0
- package/plugins/db-agent/bin/db-agent +17 -0
- package/plugins/db-agent/commands/db-agent.md +6 -0
- package/plugins/db-agent/hooks/db-guard.mjs +110 -0
- package/plugins/db-agent/hooks/guardrails.json +26 -0
- package/plugins/db-agent/hooks/hooks.json +61 -0
- package/plugins/db-agent/hooks/reminder.mjs +16 -0
- package/plugins/db-agent/package.json +8 -0
- package/plugins/db-agent/skills/db-agent/SKILL.md +50 -0
- package/plugins/gcp-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/gcp-agent/README.md +31 -0
- package/plugins/gcp-agent/bin/gcp-agent +18 -0
- package/plugins/gcp-agent/commands/gcp-agent.md +6 -0
- package/plugins/gcp-agent/hooks/hooks.json +49 -0
- package/plugins/gcp-agent/hooks/reminder.mjs +16 -0
- package/plugins/gcp-agent/package.json +9 -0
- package/plugins/gcp-agent/skills/gcp-agent/SKILL.md +54 -0
- package/plugins/github-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/github-agent/README.md +13 -0
- package/plugins/github-agent/bin/github-agent +17 -0
- package/plugins/github-agent/commands/github-agent.md +6 -0
- package/plugins/github-agent/hooks/hooks.json +49 -0
- package/plugins/github-agent/hooks/reminder.mjs +16 -0
- package/plugins/github-agent/package.json +8 -0
- package/plugins/github-agent/skills/github-agent/SKILL.md +41 -0
- package/plugins/jira-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/jira-agent/README.md +15 -0
- package/plugins/jira-agent/bin/jira-agent +17 -0
- package/plugins/jira-agent/commands/jira-agent.md +6 -0
- package/plugins/jira-agent/hooks/hooks.json +49 -0
- package/plugins/jira-agent/hooks/reminder.mjs +16 -0
- package/plugins/jira-agent/package.json +8 -0
- package/plugins/jira-agent/skills/jira-agent/SKILL.md +37 -0
- package/plugins/notion-agent/.claude-plugin/plugin.json +6 -0
- package/plugins/notion-agent/README.md +23 -0
- package/plugins/notion-agent/bin/notion-agent +17 -0
- package/plugins/notion-agent/commands/notion-agent.md +6 -0
- package/plugins/notion-agent/hooks/hooks.json +49 -0
- package/plugins/notion-agent/hooks/reminder.mjs +17 -0
- package/plugins/notion-agent/package.json +8 -0
- package/plugins/notion-agent/skills/notion-agent/SKILL.md +48 -0
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* policy.ts — Guard-rail mechanism for SQL query authorization.
|
|
3
|
+
*
|
|
4
|
+
* Classifies SQL statements and enforces approval policies before execution.
|
|
5
|
+
*
|
|
6
|
+
* Parity notes vs. the Python reference (`policy.py`):
|
|
7
|
+
* - `Decision` is a string-literal union (not an enum) so JSON output is the
|
|
8
|
+
* lowercase wire value directly: `"allow" | "deny" | "escalate" |
|
|
9
|
+
* "present_only"`. Python's `Enum` values serialize the same.
|
|
10
|
+
* - `PolicyResult` is a discriminated union on `decision`; `formatted_sql`
|
|
11
|
+
* exists ONLY on the `present_only` branch, matching Python's behaviour
|
|
12
|
+
* where the field is populated just for write/delete/admin (was DML).
|
|
13
|
+
* - Default-deny on unknown first-words: the classifier falls through to
|
|
14
|
+
* `"admin"` (the most restrictive category) for anything not in the known
|
|
15
|
+
* keyword sets. Python's reference fell through to `"ddl"`; the V2.0
|
|
16
|
+
* rename moves DDL→ADMIN but the safety floor is unchanged.
|
|
17
|
+
*
|
|
18
|
+
* G-DB-1: the SQL keyword classifier is exported as a top-level
|
|
19
|
+
* `classifySqlKeywords` so non-relational drivers (MongoDB, DynamoDB) can
|
|
20
|
+
* provide their own override via the `DatabaseDriver.classifyOperation`
|
|
21
|
+
* method without going through the SQL keyword path. Policy.checkQuery
|
|
22
|
+
* accepts an optional driver and dispatches accordingly.
|
|
23
|
+
*/
|
|
24
|
+
import { performance } from "node:perf_hooks";
|
|
25
|
+
import { logEvent, scrubSqlSecrets } from "./audit.js";
|
|
26
|
+
import { DEFAULT_POLICY } from "./plugin_config.js";
|
|
27
|
+
/** Namespace providing Python-style attribute access (`Decision.ALLOW`). */
|
|
28
|
+
export const Decision = {
|
|
29
|
+
ALLOW: "allow",
|
|
30
|
+
DENY: "deny",
|
|
31
|
+
ESCALATE: "escalate",
|
|
32
|
+
PRESENT_ONLY: "present_only",
|
|
33
|
+
};
|
|
34
|
+
/** Namespace mirroring Python's `OperationType.READ` etc. */
|
|
35
|
+
export const OperationType = {
|
|
36
|
+
READ: "read",
|
|
37
|
+
WRITE: "write",
|
|
38
|
+
DELETE: "delete",
|
|
39
|
+
ADMIN: "admin",
|
|
40
|
+
PRIVILEGE: "privilege",
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Decision strictness rank. When a compound statement has multiple per-statement
|
|
44
|
+
* decisions, the combined result is the one with the highest rank (deny beats
|
|
45
|
+
* escalate beats present_only beats allow). Ties break by first occurrence so
|
|
46
|
+
* the reported reason points at the earliest offending statement.
|
|
47
|
+
*/
|
|
48
|
+
const _DECISION_RANK = {
|
|
49
|
+
allow: 0,
|
|
50
|
+
present_only: 1,
|
|
51
|
+
escalate: 2,
|
|
52
|
+
deny: 3,
|
|
53
|
+
};
|
|
54
|
+
// -----------------------------------------------------------------------
|
|
55
|
+
// Keyword -> OperationType mapping (V2.0 vocab)
|
|
56
|
+
// -----------------------------------------------------------------------
|
|
57
|
+
const _READ_KEYWORDS = new Set([
|
|
58
|
+
"SELECT", "EXPLAIN", "SHOW", "DESCRIBE", "DESC", "WITH",
|
|
59
|
+
]);
|
|
60
|
+
const _WRITE_KEYWORDS = new Set([
|
|
61
|
+
"INSERT", "UPDATE", "REPLACE", "MERGE", "UPSERT",
|
|
62
|
+
]);
|
|
63
|
+
const _DELETE_KEYWORDS = new Set([
|
|
64
|
+
"DELETE", "TRUNCATE",
|
|
65
|
+
]);
|
|
66
|
+
const _ADMIN_KEYWORDS = new Set([
|
|
67
|
+
"CREATE", "DROP", "ALTER", "RENAME",
|
|
68
|
+
]);
|
|
69
|
+
const _PRIVILEGE_KEYWORDS = new Set([
|
|
70
|
+
"GRANT", "REVOKE",
|
|
71
|
+
]);
|
|
72
|
+
/**
|
|
73
|
+
* Classify a SQL string by its leading keyword.
|
|
74
|
+
*
|
|
75
|
+
* Exported so SQL drivers (sqlite, postgres, mysql, mssql) can implement
|
|
76
|
+
* `DatabaseDriver.classifyOperation` without instantiating a Policy. Throws
|
|
77
|
+
* `Error("Empty SQL statement")` for empty/whitespace-only input.
|
|
78
|
+
*
|
|
79
|
+
* Default-deny: any unknown first-word falls through to `ADMIN` (most
|
|
80
|
+
* restrictive), matching `policy.py`'s safety-floor intent.
|
|
81
|
+
*/
|
|
82
|
+
export function classifySqlKeywords(sql) {
|
|
83
|
+
const cleaned = Policy._stripComments(sql).trim();
|
|
84
|
+
if (!cleaned) {
|
|
85
|
+
throw new Error("Empty SQL statement");
|
|
86
|
+
}
|
|
87
|
+
const firstToken = cleaned.split(/\s+/)[0] ?? "";
|
|
88
|
+
const firstWord = firstToken.toUpperCase();
|
|
89
|
+
if (_PRIVILEGE_KEYWORDS.has(firstWord))
|
|
90
|
+
return OperationType.PRIVILEGE;
|
|
91
|
+
if (_ADMIN_KEYWORDS.has(firstWord))
|
|
92
|
+
return OperationType.ADMIN;
|
|
93
|
+
if (_DELETE_KEYWORDS.has(firstWord))
|
|
94
|
+
return OperationType.DELETE;
|
|
95
|
+
if (_WRITE_KEYWORDS.has(firstWord))
|
|
96
|
+
return OperationType.WRITE;
|
|
97
|
+
if (_READ_KEYWORDS.has(firstWord))
|
|
98
|
+
return OperationType.READ;
|
|
99
|
+
return OperationType.ADMIN;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Split SQL on statement-terminating semicolons, respecting single- and double-
|
|
103
|
+
* quoted string literals. Comments are stripped first, so line and block
|
|
104
|
+
* comments cannot hide a semicolon.
|
|
105
|
+
*
|
|
106
|
+
* Returns trimmed, non-empty statements. An input with a single trailing
|
|
107
|
+
* semicolon returns one statement. Edge cases: `''` escaped quotes inside a
|
|
108
|
+
* single-quoted literal work by accident of toggle semantics (exit + re-enter
|
|
109
|
+
* with nothing in between). NOT handled: PostgreSQL dollar-quoted strings
|
|
110
|
+
* (`$tag$...$tag$`) and backtick-quoted identifiers — tolerably over-split
|
|
111
|
+
* rather than under-split, which is the right bias for a safety gate.
|
|
112
|
+
*/
|
|
113
|
+
function _splitStatements(sql) {
|
|
114
|
+
const cleaned = Policy._stripComments(sql);
|
|
115
|
+
const out = [];
|
|
116
|
+
let start = 0;
|
|
117
|
+
let inSingle = false;
|
|
118
|
+
let inDouble = false;
|
|
119
|
+
for (let i = 0; i < cleaned.length; i++) {
|
|
120
|
+
const c = cleaned[i];
|
|
121
|
+
if (c === "'" && !inDouble)
|
|
122
|
+
inSingle = !inSingle;
|
|
123
|
+
else if (c === '"' && !inSingle)
|
|
124
|
+
inDouble = !inDouble;
|
|
125
|
+
else if (c === ";" && !inSingle && !inDouble) {
|
|
126
|
+
const s = cleaned.slice(start, i).trim();
|
|
127
|
+
if (s)
|
|
128
|
+
out.push(s);
|
|
129
|
+
start = i + 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const tail = cleaned.slice(start).trim();
|
|
133
|
+
if (tail)
|
|
134
|
+
out.push(tail);
|
|
135
|
+
return out;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Classify every statement in a compound SQL string. Comments are stripped,
|
|
139
|
+
* then the input is split on semicolons (outside quoted literals). Each
|
|
140
|
+
* non-empty statement is classified via `classifySqlKeywords`. Throws
|
|
141
|
+
* `"Empty SQL statement"` when the result would be zero statements — same
|
|
142
|
+
* contract as `classifySqlKeywords` on empty input.
|
|
143
|
+
*
|
|
144
|
+
* The CLI pre-check and `Policy.checkQuery` both use this so that a compound
|
|
145
|
+
* like `SELECT 1; DROP TABLE users;` is classified as [READ, ADMIN] and the
|
|
146
|
+
* strictest rule (under V2.0 default `admin: present` → present_only) wins.
|
|
147
|
+
* A compound of all reads classifies as [READ, READ, ...] and the aggregate
|
|
148
|
+
* decision is allow.
|
|
149
|
+
*/
|
|
150
|
+
export function classifyStatements(sql) {
|
|
151
|
+
const stmts = _splitStatements(sql);
|
|
152
|
+
if (stmts.length === 0) {
|
|
153
|
+
throw new Error("Empty SQL statement");
|
|
154
|
+
}
|
|
155
|
+
return stmts.map((s) => classifySqlKeywords(s));
|
|
156
|
+
}
|
|
157
|
+
// Regex to strip SQL line comments (-- ...) and block comments (/* ... */)
|
|
158
|
+
const _LINE_COMMENT_RE = /--[^\n]*/g;
|
|
159
|
+
// Python uses re.DOTALL so `.` matches newlines; in JS use the `s` flag.
|
|
160
|
+
const _BLOCK_COMMENT_RE = /\/\*.*?\*\//gs;
|
|
161
|
+
/**
|
|
162
|
+
* Heuristic: a SELECT is "unbounded" if it reads from a table but has
|
|
163
|
+
* no WHERE, LIMIT, JOIN, or specific id filter.
|
|
164
|
+
*
|
|
165
|
+
* Python uses `re.IGNORECASE | re.DOTALL`; in JS we emulate with `is` flags.
|
|
166
|
+
*/
|
|
167
|
+
const _UNBOUNDED_RE = /^\s*SELECT\s+.*\bFROM\s+\w+/is;
|
|
168
|
+
// G-POLICY-CROSSJOIN: require JOIN ... ON so CROSS JOIN (which has no
|
|
169
|
+
// join predicate and explodes rows) does not count as bounded. Bare
|
|
170
|
+
// JOIN USING (…) also falls through to escalate — safe direction.
|
|
171
|
+
const _BOUNDED_KEYWORDS_RE = /\b(WHERE|LIMIT|OFFSET|HAVING|GROUP\s+BY|JOIN\s+\S+\s+ON)\b/i;
|
|
172
|
+
const _VALID_APPROVAL_MODES = new Set([
|
|
173
|
+
"auto", "confirm_once", "confirm_each", "grant_required",
|
|
174
|
+
]);
|
|
175
|
+
/**
|
|
176
|
+
* Stateful policy engine that gates SQL execution.
|
|
177
|
+
*
|
|
178
|
+
* Parameters
|
|
179
|
+
* ----------
|
|
180
|
+
* approvalMode : string
|
|
181
|
+
* One of: auto, confirm_once, confirm_each, grant_required.
|
|
182
|
+
*/
|
|
183
|
+
export class Policy {
|
|
184
|
+
_approval_mode;
|
|
185
|
+
_rules;
|
|
186
|
+
_session_approved;
|
|
187
|
+
_grants; // grant_type -> expiry (ms, performance.now())
|
|
188
|
+
// G-DB-AUDIT: grant_types that have already had a `grant_expired` event
|
|
189
|
+
// emitted (de-dupes spam from repeated isGrantActive polling).
|
|
190
|
+
_expired_logged;
|
|
191
|
+
constructor(approvalMode = "auto", rules = DEFAULT_POLICY) {
|
|
192
|
+
if (!_VALID_APPROVAL_MODES.has(approvalMode)) {
|
|
193
|
+
// Match Python repr(): single-quoted string.
|
|
194
|
+
throw new Error(`Unknown approval_mode: '${approvalMode}'`);
|
|
195
|
+
}
|
|
196
|
+
this._approval_mode = approvalMode;
|
|
197
|
+
this._rules = rules;
|
|
198
|
+
this._session_approved = false;
|
|
199
|
+
this._grants = new Map();
|
|
200
|
+
this._expired_logged = new Set();
|
|
201
|
+
}
|
|
202
|
+
// ------------------------------------------------------------------
|
|
203
|
+
// SQL classification
|
|
204
|
+
// ------------------------------------------------------------------
|
|
205
|
+
/** Remove SQL comments from the statement. */
|
|
206
|
+
static _stripComments(sql) {
|
|
207
|
+
let s = sql.replace(_BLOCK_COMMENT_RE, "");
|
|
208
|
+
s = s.replace(_LINE_COMMENT_RE, "");
|
|
209
|
+
return s.trim();
|
|
210
|
+
}
|
|
211
|
+
/** Determine the OperationType of a raw SQL string. */
|
|
212
|
+
classifySql(sql) {
|
|
213
|
+
return classifySqlKeywords(sql);
|
|
214
|
+
}
|
|
215
|
+
// ------------------------------------------------------------------
|
|
216
|
+
// Unbounded query heuristic
|
|
217
|
+
// ------------------------------------------------------------------
|
|
218
|
+
/** Return true if the SELECT appears to lack a bounding clause. */
|
|
219
|
+
static _isUnboundedSelect(sql) {
|
|
220
|
+
if (!_UNBOUNDED_RE.test(sql))
|
|
221
|
+
return false;
|
|
222
|
+
return !_BOUNDED_KEYWORDS_RE.test(sql);
|
|
223
|
+
}
|
|
224
|
+
// ------------------------------------------------------------------
|
|
225
|
+
// Decision logic
|
|
226
|
+
// ------------------------------------------------------------------
|
|
227
|
+
/**
|
|
228
|
+
* Evaluate whether `sql` should be executed under current policy.
|
|
229
|
+
*
|
|
230
|
+
* G-DB-1: when `driver` is supplied, classification is delegated to
|
|
231
|
+
* `driver.classifyOperation()`. This lets non-relational drivers
|
|
232
|
+
* (MongoDB, DynamoDB) classify their JSON envelope queries instead of
|
|
233
|
+
* falling through SQL keyword matching (which would default to ADMIN).
|
|
234
|
+
*
|
|
235
|
+
* G-DB-AUDIT: every `deny` decision is emitted as a `policy_deny` event
|
|
236
|
+
* via `audit.logEvent`. The audit module no-ops when audit is disabled.
|
|
237
|
+
*/
|
|
238
|
+
checkQuery(sql, driver) {
|
|
239
|
+
const stripped = sql.trim();
|
|
240
|
+
if (!stripped) {
|
|
241
|
+
const result = { decision: "deny", reason: "Empty SQL statement" };
|
|
242
|
+
_emitDeny(result.reason, null);
|
|
243
|
+
return result;
|
|
244
|
+
}
|
|
245
|
+
// Non-SQL drivers (MongoDB, DynamoDB) receive JSON envelopes — semicolon
|
|
246
|
+
// splitting would corrupt them. Stay on the single-statement path and
|
|
247
|
+
// trust the driver's own classifier for those.
|
|
248
|
+
if (driver !== undefined) {
|
|
249
|
+
return this._checkSingleStatement(stripped, driver);
|
|
250
|
+
}
|
|
251
|
+
// SQL path: split on statement terminators, classify each, combine via
|
|
252
|
+
// strictest-wins (deny > escalate > present_only > allow). A compound of
|
|
253
|
+
// all-allowed statements stays allowed.
|
|
254
|
+
let classifications;
|
|
255
|
+
try {
|
|
256
|
+
classifications = classifyStatements(stripped);
|
|
257
|
+
}
|
|
258
|
+
catch (exc) {
|
|
259
|
+
const reason = exc.message;
|
|
260
|
+
_emitDeny(reason, null);
|
|
261
|
+
return { decision: "deny", reason };
|
|
262
|
+
}
|
|
263
|
+
const statements = _splitStatements(stripped);
|
|
264
|
+
const perStmt = [];
|
|
265
|
+
for (let i = 0; i < statements.length; i++) {
|
|
266
|
+
const stmt = statements[i];
|
|
267
|
+
const op = classifications[i];
|
|
268
|
+
perStmt.push({ stmt, op, result: this._decideOne(stmt, op) });
|
|
269
|
+
}
|
|
270
|
+
// Pick the strictest decision; break ties by first occurrence so the
|
|
271
|
+
// reason and op reflect the earliest culprit (predictable messaging).
|
|
272
|
+
let winner = perStmt[0];
|
|
273
|
+
for (const entry of perStmt.slice(1)) {
|
|
274
|
+
if (_DECISION_RANK[entry.result.decision] > _DECISION_RANK[winner.result.decision]) {
|
|
275
|
+
winner = entry;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// For a present_only compound, substitute the formatted whole-compound so
|
|
279
|
+
// the human who runs it manually gets every statement, not just the
|
|
280
|
+
// write/delete/admin half.
|
|
281
|
+
let final = winner.result;
|
|
282
|
+
if (statements.length > 1 && final.decision === "present_only") {
|
|
283
|
+
const combined = perStmt.map((e) => _formatStatement(e.stmt)).join("; ") + ";";
|
|
284
|
+
final = { ...final, formatted_sql: combined };
|
|
285
|
+
}
|
|
286
|
+
// Emit one audit event for the combined decision. Tagging with the
|
|
287
|
+
// winner's op makes the event legible ("policy_deny op=admin because an
|
|
288
|
+
// ADMIN statement was present") without flooding the log with per-stmt
|
|
289
|
+
// entries for every compound query.
|
|
290
|
+
if (final.decision === "deny") {
|
|
291
|
+
_emitDeny(final.reason, winner.op);
|
|
292
|
+
}
|
|
293
|
+
else if (final.decision === "escalate") {
|
|
294
|
+
_emitEscalate(final.reason, winner.op);
|
|
295
|
+
}
|
|
296
|
+
else if (final.decision === "present_only") {
|
|
297
|
+
_emitPresentOnly(final.reason, winner.op, final.formatted_sql);
|
|
298
|
+
}
|
|
299
|
+
else if (winner.op !== OperationType.READ) {
|
|
300
|
+
// READ allow is deliberately not audited (matches prior behavior);
|
|
301
|
+
// write/delete allow is, so symmetry with present_only/deny holds.
|
|
302
|
+
_emitAllow(winner.op);
|
|
303
|
+
}
|
|
304
|
+
return final;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Single-statement decision path. Factored out so compound handling can
|
|
308
|
+
* call it per sub-statement without emitting audit events (those are
|
|
309
|
+
* consolidated into one emission after combining). Compatible with the
|
|
310
|
+
* driver-provided path: when a non-SQL driver supplies its own
|
|
311
|
+
* `classifyOperation`, the whole query string flows through here.
|
|
312
|
+
*/
|
|
313
|
+
_decideOne(stmt, op) {
|
|
314
|
+
const rule = this._rules[op];
|
|
315
|
+
if (rule === "deny") {
|
|
316
|
+
return { decision: "deny", reason: _denyReason(op) };
|
|
317
|
+
}
|
|
318
|
+
if (rule === "escalate") {
|
|
319
|
+
return { decision: "escalate", reason: _escalateReason(op) };
|
|
320
|
+
}
|
|
321
|
+
if (rule === "present") {
|
|
322
|
+
const formatted = _formatStatement(stmt);
|
|
323
|
+
return { decision: "present_only", reason: _presentReason(op), formatted_sql: formatted };
|
|
324
|
+
}
|
|
325
|
+
// rule === "allow"
|
|
326
|
+
if (op === OperationType.READ) {
|
|
327
|
+
return this._checkRead(stmt);
|
|
328
|
+
}
|
|
329
|
+
// Config validation prevents "allow" from reaching ADMIN/PRIVILEGE; only
|
|
330
|
+
// WRITE/DELETE remain.
|
|
331
|
+
return { decision: "allow", reason: `${op.toUpperCase()} allowed by policy` };
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Driver-provided path: the caller owns classification (possibly via a
|
|
335
|
+
* JSON envelope for MongoDB/DynamoDB). Emits the audit event itself since
|
|
336
|
+
* we're not aggregating across multiple sub-statements here.
|
|
337
|
+
*/
|
|
338
|
+
_checkSingleStatement(stmt, driver) {
|
|
339
|
+
let op;
|
|
340
|
+
try {
|
|
341
|
+
op = driver.classifyOperation(stmt);
|
|
342
|
+
}
|
|
343
|
+
catch (exc) {
|
|
344
|
+
const reason = exc.message;
|
|
345
|
+
_emitDeny(reason, null);
|
|
346
|
+
return { decision: "deny", reason };
|
|
347
|
+
}
|
|
348
|
+
const result = this._decideOne(stmt, op);
|
|
349
|
+
if (result.decision === "deny")
|
|
350
|
+
_emitDeny(result.reason, op);
|
|
351
|
+
else if (result.decision === "escalate")
|
|
352
|
+
_emitEscalate(result.reason, op);
|
|
353
|
+
else if (result.decision === "present_only")
|
|
354
|
+
_emitPresentOnly(result.reason, op, result.formatted_sql);
|
|
355
|
+
else if (op !== OperationType.READ)
|
|
356
|
+
_emitAllow(op);
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
/** Apply approval-mode logic for READ operations. */
|
|
360
|
+
_checkRead(sql) {
|
|
361
|
+
// Unbounded safety check — operator can opt out via
|
|
362
|
+
// policy.unbounded_select: 'allow' (default 'escalate').
|
|
363
|
+
if (this._rules.unbounded_select !== "allow" &&
|
|
364
|
+
Policy._isUnboundedSelect(sql)) {
|
|
365
|
+
return {
|
|
366
|
+
decision: "escalate",
|
|
367
|
+
reason: "Unbounded SELECT detected -- add WHERE or LIMIT",
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
const mode = this._approval_mode;
|
|
371
|
+
if (mode === "auto") {
|
|
372
|
+
return { decision: "allow", reason: "auto-approved" };
|
|
373
|
+
}
|
|
374
|
+
if (mode === "confirm_once") {
|
|
375
|
+
if (this._session_approved) {
|
|
376
|
+
return { decision: "allow", reason: "session approved" };
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
decision: "escalate",
|
|
380
|
+
reason: "First read requires confirmation (confirm_once)",
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
if (mode === "confirm_each") {
|
|
384
|
+
return {
|
|
385
|
+
decision: "escalate",
|
|
386
|
+
reason: "Each read requires confirmation (confirm_each)",
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
if (mode === "grant_required") {
|
|
390
|
+
if (this.isGrantActive("read")) {
|
|
391
|
+
return { decision: "allow", reason: "active read grant" };
|
|
392
|
+
}
|
|
393
|
+
return { decision: "deny", reason: "No active read grant" };
|
|
394
|
+
}
|
|
395
|
+
// Unreachable given the constructor guard, but defensive:
|
|
396
|
+
return { decision: "deny", reason: `Unknown mode: ${mode}` };
|
|
397
|
+
}
|
|
398
|
+
// ------------------------------------------------------------------
|
|
399
|
+
// Session & grant management
|
|
400
|
+
// ------------------------------------------------------------------
|
|
401
|
+
/** Mark the current session as approved (for confirm_once mode). */
|
|
402
|
+
approveSession() {
|
|
403
|
+
this._session_approved = true;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Add a time-limited grant.
|
|
407
|
+
*
|
|
408
|
+
* G-DB-AUDIT: emits a `grant_added` event with the grant type and TTL.
|
|
409
|
+
*
|
|
410
|
+
* Lifetime scope: grants are in-process only. Expiry is measured with
|
|
411
|
+
* `performance.now()`, which is reset on every Node process start, so
|
|
412
|
+
* a new CLI invocation always begins with no active grants — even if
|
|
413
|
+
* a previous run added one seconds ago. Suitable for the CLI's
|
|
414
|
+
* single-invocation model; not suitable as a cross-process gate.
|
|
415
|
+
*/
|
|
416
|
+
addGrant(grantType, ttlSeconds = 300) {
|
|
417
|
+
// performance.now() is process-relative; see JSDoc for lifetime scope.
|
|
418
|
+
this._grants.set(grantType, performance.now() + ttlSeconds * 1000);
|
|
419
|
+
logEvent({
|
|
420
|
+
event_type: "grant_added",
|
|
421
|
+
details: { grant_type: grantType, ttl_seconds: ttlSeconds },
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Check whether a grant is currently active (not expired).
|
|
426
|
+
*
|
|
427
|
+
* G-DB-AUDIT: emits a single `grant_expired` event the first time an
|
|
428
|
+
* expired grant is observed (subsequent checks are silent so the audit
|
|
429
|
+
* log isn't spammed by repeated polling).
|
|
430
|
+
*/
|
|
431
|
+
isGrantActive(grantType) {
|
|
432
|
+
const expiry = this._grants.get(grantType);
|
|
433
|
+
if (expiry === undefined)
|
|
434
|
+
return false;
|
|
435
|
+
if (performance.now() < expiry)
|
|
436
|
+
return true;
|
|
437
|
+
if (!this._expired_logged.has(grantType)) {
|
|
438
|
+
this._expired_logged.add(grantType);
|
|
439
|
+
logEvent({
|
|
440
|
+
event_type: "grant_expired",
|
|
441
|
+
details: { grant_type: grantType },
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
return false;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* Issue a time-limited grant whose TTL derives from an environment's
|
|
449
|
+
* `grant_duration_hours` field (v2 design §4 default: 8 hours).
|
|
450
|
+
*
|
|
451
|
+
* This is the recommended API for prod callers — `addGrant` remains the
|
|
452
|
+
* low-level primitive (5-minute default, used for short-lived operations
|
|
453
|
+
* like test scaffolding and administrative confirmations).
|
|
454
|
+
*
|
|
455
|
+
* Lifetime scope: grants live in memory only. Because `addGrant` uses
|
|
456
|
+
* `performance.now()` — a process-relative monotonic clock — a grant
|
|
457
|
+
* written in one CLI invocation does NOT carry into the next one, even
|
|
458
|
+
* if `grant_duration_hours=8`. The "8 hour" default means "up to 8
|
|
459
|
+
* wall-clock hours within a single long-running session," not "8
|
|
460
|
+
* wall-clock hours across reboots." Persisting grants to disk is out
|
|
461
|
+
* of scope for v2.
|
|
462
|
+
*/
|
|
463
|
+
export function grantFromEnv(policy, env, grantType) {
|
|
464
|
+
const hours = env.grant_duration_hours ?? 8;
|
|
465
|
+
policy.addGrant(grantType, hours * 3600);
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* G-DB-AUDIT: emit a `policy_deny` event with the deny reason and the
|
|
469
|
+
* SQL operation type (when known). The audit module no-ops when audit
|
|
470
|
+
* has not been enabled, so this is safe to call unconditionally.
|
|
471
|
+
*/
|
|
472
|
+
function _emitDeny(reason, op) {
|
|
473
|
+
const details = { reason };
|
|
474
|
+
if (op !== null)
|
|
475
|
+
details["op"] = op;
|
|
476
|
+
logEvent({ event_type: "policy_deny", details });
|
|
477
|
+
}
|
|
478
|
+
/** Emit a `policy_allow` audit event tagged with the operation type. */
|
|
479
|
+
function _emitAllow(op) {
|
|
480
|
+
logEvent({ event_type: "policy_allow", details: { op } });
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Symmetric to `_emitDeny` / `_emitPresentOnly`: record a `policy_escalate`
|
|
484
|
+
* event when the policy returns `escalate`. Without this, a blocked-pending-
|
|
485
|
+
* approval path leaves an empty audit trail, making "no write happened" hard
|
|
486
|
+
* to prove positively — the viewer's absence-of-write check sees nothing to
|
|
487
|
+
* distinguish from "CLI never ran". The `op` tag lets consumers filter
|
|
488
|
+
* read-escalation (grant_required / unbounded SELECT) from write-escalation.
|
|
489
|
+
*/
|
|
490
|
+
function _emitEscalate(reason, op) {
|
|
491
|
+
const details = { reason };
|
|
492
|
+
if (op !== null)
|
|
493
|
+
details["op"] = op;
|
|
494
|
+
logEvent({ event_type: "policy_escalate", details });
|
|
495
|
+
}
|
|
496
|
+
/** Default deny reason per operation type (stable strings used by evals). */
|
|
497
|
+
function _denyReason(op) {
|
|
498
|
+
if (op === OperationType.ADMIN)
|
|
499
|
+
return "ADMIN statements are never allowed";
|
|
500
|
+
if (op === OperationType.PRIVILEGE)
|
|
501
|
+
return "PRIVILEGE statements are never allowed";
|
|
502
|
+
if (op === OperationType.WRITE)
|
|
503
|
+
return "WRITE statements are not allowed";
|
|
504
|
+
if (op === OperationType.DELETE)
|
|
505
|
+
return "DELETE statements are not allowed";
|
|
506
|
+
return "READ statements are not allowed";
|
|
507
|
+
}
|
|
508
|
+
function _escalateReason(op) {
|
|
509
|
+
return `${op.toUpperCase()} statements require approval`;
|
|
510
|
+
}
|
|
511
|
+
function _presentReason(op) {
|
|
512
|
+
return `${op.toUpperCase()} statements are displayed but not executed`;
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* Strip comments and uppercase the leading keyword for readability when
|
|
516
|
+
* echoing a statement back to the caller in a `present_only` response.
|
|
517
|
+
*/
|
|
518
|
+
function _formatStatement(sql) {
|
|
519
|
+
let formatted = Policy._stripComments(sql.trim());
|
|
520
|
+
const parts = formatted.split(/\s+/);
|
|
521
|
+
const first = parts[0];
|
|
522
|
+
if (first !== undefined) {
|
|
523
|
+
if (parts.length > 1) {
|
|
524
|
+
const rest = parts.slice(1).join(" ");
|
|
525
|
+
formatted = first.toUpperCase() + " " + rest;
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
formatted = first.toUpperCase();
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return formatted;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* Symmetric to `_emitDeny`: emit a `policy_present_only` event when a
|
|
535
|
+
* write/delete/admin statement is intercepted and returned as formatted
|
|
536
|
+
* SQL rather than executed. Without this, the "no write event occurred"
|
|
537
|
+
* audit assertion on PRESENT_ONLY paths passes vacuously — an empty
|
|
538
|
+
* audit log also has no writes. Recording the policy decision gives
|
|
539
|
+
* downstream consumers (and eval graders) a positive signal that the
|
|
540
|
+
* decision actually fired.
|
|
541
|
+
*
|
|
542
|
+
* The `formatted_sql` is truncated to a reasonable length so the audit
|
|
543
|
+
* file doesn't bloat on long INSERTs; the full SQL is already in the
|
|
544
|
+
* API response.
|
|
545
|
+
*/
|
|
546
|
+
function _emitPresentOnly(reason, op, formattedSql) {
|
|
547
|
+
// Scrub credentials before truncation so a literal split by truncation
|
|
548
|
+
// can't leak. Same helper used by audit.logQuery.
|
|
549
|
+
const scrubbed = scrubSqlSecrets(formattedSql);
|
|
550
|
+
const truncated = scrubbed.length > 500
|
|
551
|
+
? scrubbed.slice(0, 500) + "\u2026"
|
|
552
|
+
: scrubbed;
|
|
553
|
+
const details = {
|
|
554
|
+
reason,
|
|
555
|
+
formatted_sql: truncated,
|
|
556
|
+
};
|
|
557
|
+
if (op !== null)
|
|
558
|
+
details["op"] = op;
|
|
559
|
+
logEvent({ event_type: "policy_present_only", details });
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Serialize a PolicyResult to JSON.
|
|
563
|
+
*
|
|
564
|
+
* Key order: decision, reason, (formatted_sql only when decision ===
|
|
565
|
+
* "present_only"). V8 preserves string-key insertion order so explicit
|
|
566
|
+
* construction is sufficient.
|
|
567
|
+
*/
|
|
568
|
+
export function policyResultJson(result) {
|
|
569
|
+
if (result.decision === "present_only") {
|
|
570
|
+
return JSON.stringify({
|
|
571
|
+
decision: result.decision,
|
|
572
|
+
reason: result.reason,
|
|
573
|
+
formatted_sql: result.formatted_sql,
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
return JSON.stringify({
|
|
577
|
+
decision: result.decision,
|
|
578
|
+
reason: result.reason,
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sourceRoot":"","sources":["../../../../src/connectors/db/lib/policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,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;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB;IACnD,IAAI,MAAM,CAAC,QAAQ,KAAK,cAAc,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;YACzB,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,aAAa,EAAE,MAAM,CAAC,aAAa;SACpC,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,MAAM,EAAE,MAAM,CAAC,MAAM;KACtB,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Policy } from "./policy.js";
|
|
2
|
+
import type { ExecuteReadResult } from "./drivers/base.js";
|
|
3
|
+
/**
|
|
4
|
+
* Minimal driver shape `executeQuery` needs. The test suite constructs
|
|
5
|
+
* one of these directly (sync drivers wrap via `Promise.resolve(...)`).
|
|
6
|
+
*/
|
|
7
|
+
export interface QueryableDriver {
|
|
8
|
+
executeReadAsync(conn: unknown, query: string, params?: unknown[] | null, maxRows?: number, timeoutMs?: number): Promise<ExecuteReadResult>;
|
|
9
|
+
}
|
|
10
|
+
export interface ExecuteQueryOptions {
|
|
11
|
+
/** Connection passed straight through to `executeReadAsync`. */
|
|
12
|
+
conn?: unknown;
|
|
13
|
+
params?: unknown[] | null;
|
|
14
|
+
max_rows?: number;
|
|
15
|
+
timeout_ms?: number;
|
|
16
|
+
}
|
|
17
|
+
/** Execute a SQL query through policy checks and the database driver.
|
|
18
|
+
*
|
|
19
|
+
* Returns a structured dict — never raises.
|
|
20
|
+
*/
|
|
21
|
+
export declare function executeQuery(driver: QueryableDriver, sql: string, policy: Policy, options?: ExecuteQueryOptions): Promise<Record<string, unknown>>;
|
|
22
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../../src/connectors/db/lib/query.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAY,KAAK,MAAM,EAAqB,MAAM,aAAa,CAAC;AACvE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,gBAAgB,CACd,IAAI,EAAE,OAAO,EACb,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,EACzB,OAAO,CAAC,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,iBAAiB,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,eAAe,EACvB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA8ElC"}
|