@opengeni/db 1.0.1 → 3.2.0-canary.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.
- package/dist/attached-browser-devices.d.ts +7 -0
- package/dist/automations.d.ts +154 -0
- package/dist/canonical-human-identities.js +3 -3
- package/dist/capability-integrations.d.ts +13 -0
- package/dist/child-lifecycle-notices.d.ts +68 -0
- package/dist/{chunk-4SR4HKKA.js → chunk-2EH4WRHL.js} +19 -11
- package/dist/chunk-2EH4WRHL.js.map +1 -0
- package/dist/{chunk-CUPM3FGB.js → chunk-2PRS4J5Q.js} +3 -3
- package/dist/chunk-6HMM2R5T.js +390 -0
- package/dist/chunk-6HMM2R5T.js.map +1 -0
- package/dist/{chunk-ZWREYEWA.js → chunk-AZHW7R5V.js} +56 -11
- package/dist/chunk-AZHW7R5V.js.map +1 -0
- package/dist/{chunk-LTG3S6ZY.js → chunk-E6CLMKEE.js} +2 -2
- package/dist/{chunk-6ZYKCRFO.js → chunk-KRLPEMLH.js} +7591 -4417
- package/dist/chunk-KRLPEMLH.js.map +1 -0
- package/dist/chunk-NAB6FKFN.js +516 -0
- package/dist/chunk-NAB6FKFN.js.map +1 -0
- package/dist/{chunk-SK7YYHBI.js → chunk-SIBYBA2D.js} +46 -1
- package/dist/chunk-SIBYBA2D.js.map +1 -0
- package/dist/chunk-UZNXG44K.js +4508 -0
- package/dist/chunk-UZNXG44K.js.map +1 -0
- package/dist/codemode-operations.d.ts +1 -6
- package/dist/company-brain-context-selection-schema.d.ts +705 -0
- package/dist/company-brain-context-selection.d.ts +94 -0
- package/dist/company-brain-governed-writes.d.ts +24 -0
- package/dist/company-brain.d.ts +55 -0
- package/dist/company-profile-agent-admin.d.ts +15 -0
- package/dist/company-profile-schema.d.ts +619 -2
- package/dist/company-profile.d.ts +9 -4
- package/dist/connection-authority.d.ts +95 -0
- package/dist/connection-scopes.d.ts +8 -0
- package/dist/connection-tenancy-backfill.d.ts +85 -0
- package/dist/connection-token-resolver.d.ts +30 -1
- package/dist/database.d.ts +23 -4
- package/dist/editable-artifact-durable-export.js +2 -2
- package/dist/editable-artifacts.d.ts +2 -2
- package/dist/editable-artifacts.js +3 -3
- package/dist/governed-learning-activation-schema.d.ts +984 -0
- package/dist/governed-learning-activation.d.ts +98 -0
- package/dist/governed-learning-evaluator-schema.d.ts +633 -0
- package/dist/governed-learning-evaluator.d.ts +28 -0
- package/dist/index.d.ts +1606 -81
- package/dist/index.js +21898 -8147
- package/dist/index.js.map +1 -1
- package/dist/insights.d.ts +18 -0
- package/dist/integration-bindings.d.ts +1 -0
- package/dist/integration-facets.d.ts +30 -0
- package/dist/interaction-placement-loss.d.ts +22 -0
- package/dist/managed-human-provisioning.d.ts +25 -0
- package/dist/memory-domain.d.ts +3 -3
- package/dist/migrate.d.ts +11 -1
- package/dist/migrate.js +1 -1
- package/dist/new-session-drafts.d.ts +43 -5
- package/dist/organization-membership-backfill.d.ts +174 -0
- package/dist/organization-membership-lifecycle.d.ts +162 -0
- package/dist/pr-review.d.ts +107 -0
- package/dist/preference-registry-schema.d.ts +2 -0
- package/dist/preference-registry.d.ts +2 -0
- package/dist/provision-roles.js +1 -1
- package/dist/runtime-posture.d.ts +29 -8
- package/dist/schema.d.ts +24914 -13703
- package/dist/schema.js +99 -1
- package/dist/scoped-knowledge-schema.d.ts +52 -1
- package/dist/session-background-commands.d.ts +125 -0
- package/dist/session-background-commands.js +34 -0
- package/dist/session-background-commands.js.map +1 -0
- package/dist/session-control.d.ts +156 -3
- package/dist/session-goal-pacing.d.ts +68 -0
- package/dist/session-queue-commands.d.ts +43 -4
- package/dist/session-realtime-ledger.d.ts +2 -0
- package/dist/session-tenancy.d.ts +71 -1
- package/dist/session-tenancy.js +25 -3
- package/dist/session-tool-call-settlement.d.ts +9 -4
- package/dist/slack-routing-personal-workspace.d.ts +23 -0
- package/dist/slack-routing.d.ts +268 -0
- package/dist/slack-task-policy-schema.d.ts +34 -0
- package/dist/slack-task-policy.d.ts +8 -0
- package/dist/slack-user-link-access.d.ts +28 -0
- package/dist/task-notes-schema.d.ts +594 -0
- package/dist/task-notes.d.ts +39 -0
- package/dist/turn-initiator.d.ts +2 -0
- package/dist/user-resource-authority.d.ts +109 -0
- package/dist/video-generation.js +3 -3
- package/dist/workspace-authority.d.ts +81 -0
- package/dist/workspace-instruction-policies-schema.d.ts +279 -0
- package/dist/workspace-instruction-policies.d.ts +62 -0
- package/dist/workspace-learning-policy.d.ts +1 -0
- package/dist/workspace-membership-permissions.d.ts +2 -0
- package/drizzle/0240_enrollment_connection_authority.sql +39 -0
- package/drizzle/0241_atomic_personal_resource_delegation.sql +1000 -0
- package/drizzle/0241_enrollment_agent_runtime.sql +70 -0
- package/drizzle/0244_slack_app_home_refresh_queue.sql +120 -0
- package/drizzle/0245_model_context_contribution_facts.sql +88 -0
- package/drizzle/0246_integration_personal_instance_authority.sql +70 -0
- package/drizzle/0247_terraform_stacks_provenance_repair.sql +428 -0
- package/drizzle/0248_terraform_stacks_component_resolution_fence.sql +83 -0
- package/drizzle/0249_personal_resource_delegation_authority_correction.sql +662 -0
- package/drizzle/0250_direct_retained_process_owner_liveness.sql +199 -0
- package/drizzle/0251_connected_machine_operation_policy.sql +45 -0
- package/drizzle/0252_scheduled_personal_resource_delegation.sql +1867 -0
- package/drizzle/0253_common_user_resource_authority_lifecycle.sql +1555 -0
- package/drizzle/0254_scoped_variable_set_authority.sql +1255 -0
- package/drizzle/0255_company_brain_governed_write_proposals.sql +524 -0
- package/drizzle/0256_connection_authority_delegation.sql +703 -0
- package/drizzle/0257_goal_revision_decisions_and_root_constraints.sql +436 -0
- package/drizzle/0258_three_scope_document_knowledge_authority.sql +1273 -0
- package/drizzle/0259_company_brain_context_selection_receipts.sql +869 -0
- package/drizzle/0260_task_note_knowledge_promotion.sql +820 -0
- package/drizzle/0261_preference_knowledge_proposal_actor_binding.sql +471 -0
- package/drizzle/0262_scoped_connected_machines_and_rigs.sql +1700 -0
- package/drizzle/0263_organization_membership_lifecycle.sql +3284 -0
- package/drizzle/0264_connection_authority_runtime_activation.sql +1084 -0
- package/drizzle/0266_company_brain_context_receipt_inspection.sql +156 -0
- package/drizzle/0268_governed_learning_decision_receipts.sql +825 -0
- package/drizzle/0269_governed_learning_activation_controller.sql +1874 -0
- package/drizzle/0270_governed_learning_history_inspection.sql +170 -0
- package/drizzle/0271_company_brain_retrieval_only_default.sql +524 -0
- package/drizzle/0272_human_confirmed_learning_activation.sql +591 -0
- package/drizzle/0273_scheduled_variable_set_materialization.sql +268 -0
- package/drizzle/0274_human_confirmed_knowledge_review.sql +310 -0
- package/drizzle/0275_scheduled_connection_authority.sql +5527 -0
- package/drizzle/0276_onboarding_proposal_initiating_human_guc.sql +198 -0
- package/drizzle/0277_workspace_writer_authority_attribution.sql +393 -0
- package/drizzle/0278_workspace_membership_removal_fencing.sql +1174 -0
- package/drizzle/0279_workspace_connection_use_lane.sql +343 -0
- package/drizzle/0280_connection_and_variable_set_audit_attribution.sql +773 -0
- package/drizzle/0281_viewer_holder_authority_claims.sql +52 -0
- package/drizzle/0282_variable_set_session_attach_attribution.sql +178 -0
- package/drizzle/0283_editable_spreadsheet_authored_state.sql +82 -0
- package/drizzle/0284_truthful_human_confirmed_review_reason.sql +930 -0
- package/drizzle/0285_organization_tenancy_inventory.sql +329 -0
- package/drizzle/0286_widen_task_note_expiry_ceiling.sql +391 -0
- package/drizzle/0287_open_suffix_pending_tool_calls.sql +18 -0
- package/drizzle/0288_attached_browser_reenrollment.sql +64 -0
- package/drizzle/0289_session_composer_policy_authority.sql +597 -0
- package/drizzle/0290_organization_membership_backfill.sql +268 -0
- package/drizzle/0291_resource_authority_classification_assertion.sql +371 -0
- package/drizzle/0292_truthful_tenancy_inventory_counters.sql +291 -0
- package/drizzle/0293_confirm_time_rule_rebaseline.sql +615 -0
- package/drizzle/0294_preference_activation_authority.sql +237 -0
- package/drizzle/0295_retire_legacy_standing_memory_mode.sql +476 -0
- package/drizzle/0296_force_rls_backfill_noop_repair.sql +215 -0
- package/drizzle/0297_session_ownership_classification_and_backfill.sql +752 -0
- package/drizzle/0298_organization_tenancy_parity.sql +609 -0
- package/drizzle/0299_organization_membership_lock_order.sql +291 -0
- package/drizzle/0300_tenancy_backfill_ledger.sql +459 -0
- package/drizzle/0301_session_snapshot_and_pin_visibility.sql +181 -0
- package/drizzle/0302_personal_workspace_session_ownership.sql +303 -0
- package/drizzle/0303_session_tenancy_product_activation.sql +919 -0
- package/drizzle/0304_personal_workspace_private_session_reads.sql +97 -0
- package/drizzle/0305_personal_resource_grant_management.sql +584 -0
- package/drizzle/0306_atomic_personal_resource_attachments.sql +1374 -0
- package/drizzle/0307_session_attention_state.sql +51 -0
- package/drizzle/0308_session_archives.sql +35 -0
- package/drizzle/0309_channel_project_pins.sql +6 -0
- package/drizzle/0310_channel_project_order.sql +27 -0
- package/drizzle/0311_company_scope_and_private_session_create.sql +656 -0
- package/drizzle/0312_quiescent_session_tree_deletion.sql +39 -0
- package/drizzle/0313_private_child_session_authority.sql +365 -0
- package/drizzle/0314_unregistered_organization_invitations.sql +606 -0
- package/drizzle/0315_personal_github_repository_selection.sql +624 -0
- package/drizzle/0316_human_confirmed_activation_resumed_generation.sql +869 -0
- package/drizzle/0317_session_goal_continuation_hold.sql +64 -0
- package/drizzle/0318_session_turn_startup_milestones.sql +115 -0
- package/drizzle/0319_event_triggered_automations.sql +254 -0
- package/drizzle/0320_pr_review_pack.sql +113 -0
- package/drizzle/0321_slack_bot_environment_display_name.sql +15 -0
- package/drizzle/0322_session_turns_unclaimed_prompt_trigger_index.sql +5 -0
- package/drizzle/0323_organization_private_session_enablement.sql +489 -0
- package/drizzle/0324_human_confirmed_company_profile_agent_admin.sql +856 -0
- package/drizzle/0325_child_lifecycle_notices.sql +44 -0
- package/drizzle/0326_interaction_operation_error_codes.sql +62 -0
- package/drizzle/0327_slack_first_task_hint.sql +29 -0
- package/drizzle/0328_session_background_commands.sql +590 -0
- package/drizzle/0329_slack_orchestration_delivery_events.sql +91 -0
- package/drizzle/0330_api_key_descriptions.sql +20 -0
- package/drizzle/0331_managed_organization_creation.sql +163 -0
- package/drizzle/0332_organization_shared_workspace_control_plane.sql +539 -0
- package/drizzle/0333_session_turn_prompt_routing.sql +45 -0
- package/drizzle/0334_connected_machine_workspace_root.sql +99 -0
- package/drizzle/0335_slack_workspace_routing.sql +460 -0
- package/drizzle/0336_atomic_session_fork_visibility.sql +667 -0
- package/drizzle/0337_slack_routed_action_handles.sql +189 -0
- package/drizzle/0338_atomic_connected_machine_attachments.sql +410 -0
- package/drizzle/0339_document_authority_reclassification.sql +1153 -0
- package/drizzle/0340_tenancy_backfill_activation_evidence.sql +1347 -0
- package/drizzle/0341_slack_routing_probe_organization_fence.sql +109 -0
- package/drizzle/0342_slack_route_prompt_single_pending.sql +32 -0
- package/drizzle/0343_personal_document_force_rls_lock_repair.sql +146 -0
- package/drizzle/0344_private_session_visibility_transition_gate.sql +85 -0
- package/drizzle/0345_tenant_scoped_session_tenancy_fence.sql +2839 -0
- package/drizzle/0346_document_migration_audit_surface.sql +454 -0
- package/drizzle/0347_connection_authority_convergence_evidence.sql +396 -0
- package/package.json +10 -6
- package/src/attached-browser-devices.ts +233 -5
- package/src/automations.ts +911 -0
- package/src/browser-sessions.ts +10 -0
- package/src/capability-integrations.ts +175 -1
- package/src/child-lifecycle-notices.ts +241 -0
- package/src/codemode-operations.ts +1 -35
- package/src/company-brain-context-selection-schema.ts +100 -0
- package/src/company-brain-context-selection.ts +359 -0
- package/src/company-brain-governed-writes.ts +1170 -0
- package/src/company-brain.ts +309 -0
- package/src/company-profile-agent-admin.ts +225 -0
- package/src/company-profile-schema.ts +121 -1
- package/src/company-profile.ts +21 -0
- package/src/computer-sessions.ts +10 -1
- package/src/connection-authority.ts +290 -0
- package/src/connection-scopes.ts +20 -0
- package/src/connection-tenancy-backfill.ts +167 -0
- package/src/connection-token-resolver.ts +263 -31
- package/src/database.ts +87 -2
- package/src/editable-artifacts-schema.ts +10 -5
- package/src/editable-artifacts.ts +21 -11
- package/src/governed-learning-activation-schema.ts +121 -0
- package/src/governed-learning-activation.ts +588 -0
- package/src/governed-learning-evaluator-schema.ts +72 -0
- package/src/governed-learning-evaluator.ts +217 -0
- package/src/index.ts +11676 -1550
- package/src/insights.ts +107 -0
- package/src/integration-bindings.ts +88 -6
- package/src/integration-facets.ts +287 -84
- package/src/interaction-placement-loss.ts +234 -0
- package/src/managed-human-provisioning.ts +116 -0
- package/src/memory-domain.ts +27 -32
- package/src/migrate.ts +77 -1
- package/src/new-session-drafts.ts +229 -35
- package/src/organization-membership-backfill.ts +735 -0
- package/src/organization-membership-lifecycle.ts +995 -0
- package/src/pr-review.ts +890 -0
- package/src/preference-registry.ts +31 -1
- package/src/provision-roles.ts +905 -6
- package/src/runtime-posture-cli.ts +2 -0
- package/src/runtime-posture.ts +1317 -72
- package/src/schema.ts +3316 -428
- package/src/scoped-knowledge-schema.ts +16 -8
- package/src/scoped-knowledge.ts +1 -1
- package/src/session-background-commands.ts +759 -0
- package/src/session-control.ts +640 -74
- package/src/session-goal-pacing.ts +126 -0
- package/src/session-queue-commands.ts +441 -85
- package/src/session-realtime-context.ts +4 -6
- package/src/session-realtime-ledger.ts +28 -14
- package/src/session-realtime-mirror.ts +1 -1
- package/src/session-tenancy.ts +410 -49
- package/src/session-tool-call-settlement.ts +38 -29
- package/src/slack-routing-personal-workspace.ts +67 -0
- package/src/slack-routing.ts +867 -0
- package/src/slack-task-policy-schema.ts +5 -0
- package/src/slack-task-policy.ts +18 -0
- package/src/slack-user-link-access.ts +138 -11
- package/src/task-notes-schema.ts +74 -0
- package/src/task-notes.ts +124 -2
- package/src/turn-initiator.ts +8 -0
- package/src/user-resource-authority.ts +377 -0
- package/src/workspace-authority.ts +160 -0
- package/src/workspace-instruction-policies-schema.ts +53 -1
- package/src/workspace-instruction-policies.ts +528 -77
- package/src/workspace-learning-policy.ts +21 -5
- package/src/workspace-membership-permissions.ts +9 -0
- package/dist/chunk-4SR4HKKA.js.map +0 -1
- package/dist/chunk-6ZYKCRFO.js.map +0 -1
- package/dist/chunk-NXAFLCQX.js +0 -2468
- package/dist/chunk-NXAFLCQX.js.map +0 -1
- package/dist/chunk-SK7YYHBI.js.map +0 -1
- package/dist/chunk-WD5ROSLL.js +0 -117
- package/dist/chunk-WD5ROSLL.js.map +0 -1
- package/dist/chunk-ZWREYEWA.js.map +0 -1
- /package/dist/{chunk-CUPM3FGB.js.map → chunk-2PRS4J5Q.js.map} +0 -0
- /package/dist/{chunk-LTG3S6ZY.js.map → chunk-E6CLMKEE.js.map} +0 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Bounded, tenant-fenced, actionable evidence for every connection
|
|
3
|
+
-- authority row that has not reached one of migration 0340's terminal shapes.
|
|
4
|
+
|
|
5
|
+
SET LOCAL lock_timeout = '5s';
|
|
6
|
+
SET LOCAL statement_timeout = '10min';
|
|
7
|
+
|
|
8
|
+
-- The inspector needs owner visibility through FORCE RLS, but it must not
|
|
9
|
+
-- reuse 0340's write-capable backfill capability. A target-schema-local token
|
|
10
|
+
-- also prevents one OpenGeni schema from authorizing another schema in the
|
|
11
|
+
-- same database. The token is exact to backend, transaction, organization,
|
|
12
|
+
-- and invocation, and the runtime role has no table privileges.
|
|
13
|
+
CREATE TABLE connection_authority_convergence_audit_capabilities (
|
|
14
|
+
capability_id uuid PRIMARY KEY,
|
|
15
|
+
backend_pid integer NOT NULL,
|
|
16
|
+
transaction_id xid8 NOT NULL,
|
|
17
|
+
account_id uuid NOT NULL,
|
|
18
|
+
created_at timestamptz NOT NULL DEFAULT pg_catalog.clock_timestamp()
|
|
19
|
+
);
|
|
20
|
+
REVOKE ALL ON TABLE connection_authority_convergence_audit_capabilities FROM PUBLIC;
|
|
21
|
+
|
|
22
|
+
CREATE FUNCTION connection_authority_convergence_audit_capability_active(
|
|
23
|
+
p_account_id uuid
|
|
24
|
+
) RETURNS boolean
|
|
25
|
+
LANGUAGE sql STABLE SECURITY DEFINER
|
|
26
|
+
SET search_path FROM CURRENT
|
|
27
|
+
AS $capability$
|
|
28
|
+
SELECT EXISTS (
|
|
29
|
+
SELECT 1
|
|
30
|
+
FROM connection_authority_convergence_audit_capabilities capability
|
|
31
|
+
WHERE capability.capability_id::text = nullif(pg_catalog.current_setting(
|
|
32
|
+
'opengeni.connection_authority_convergence_audit_token', true
|
|
33
|
+
), '')
|
|
34
|
+
AND capability.backend_pid = pg_catalog.pg_backend_pid()
|
|
35
|
+
AND capability.transaction_id = pg_catalog.pg_current_xact_id_if_assigned()
|
|
36
|
+
AND capability.account_id = p_account_id
|
|
37
|
+
)
|
|
38
|
+
$capability$;
|
|
39
|
+
REVOKE ALL ON FUNCTION
|
|
40
|
+
connection_authority_convergence_audit_capability_active(uuid) FROM PUBLIC;
|
|
41
|
+
-- These policies protect shared tables whose owners and SECURITY DEFINER
|
|
42
|
+
-- callers are not all known when this migration runs. The predicate exposes
|
|
43
|
+
-- only a boolean and cannot create or inspect the backend/xid/token-bound
|
|
44
|
+
-- capability, so every policy-evaluating role may execute it safely.
|
|
45
|
+
GRANT EXECUTE ON FUNCTION
|
|
46
|
+
connection_authority_convergence_audit_capability_active(uuid) TO PUBLIC;
|
|
47
|
+
|
|
48
|
+
DO $connection_authority_convergence_audit_policies$
|
|
49
|
+
DECLARE
|
|
50
|
+
data_schema text := pg_catalog.current_schema();
|
|
51
|
+
migration_owner text := current_user;
|
|
52
|
+
table_name text;
|
|
53
|
+
BEGIN
|
|
54
|
+
FOREACH table_name IN ARRAY ARRAY[
|
|
55
|
+
'connections',
|
|
56
|
+
'organization_memberships',
|
|
57
|
+
'organization_user_resource_authorities'
|
|
58
|
+
] LOOP
|
|
59
|
+
EXECUTE pg_catalog.format(
|
|
60
|
+
'CREATE POLICY connection_authority_convergence_audit_read ON %I.%I '
|
|
61
|
+
|| 'FOR SELECT USING (current_user = %L AND '
|
|
62
|
+
|| '%I.connection_authority_convergence_audit_capability_active(account_id))',
|
|
63
|
+
data_schema, table_name, migration_owner, data_schema
|
|
64
|
+
);
|
|
65
|
+
END LOOP;
|
|
66
|
+
END
|
|
67
|
+
$connection_authority_convergence_audit_policies$;
|
|
68
|
+
|
|
69
|
+
CREATE FUNCTION inspect_organization_connection_authority_convergence(
|
|
70
|
+
p_account_id uuid,
|
|
71
|
+
p_limit integer DEFAULT 100,
|
|
72
|
+
p_after_connection_id uuid DEFAULT NULL
|
|
73
|
+
) RETURNS jsonb
|
|
74
|
+
LANGUAGE plpgsql SECURITY DEFINER
|
|
75
|
+
SET search_path FROM CURRENT
|
|
76
|
+
SET statement_timeout = '1min'
|
|
77
|
+
AS $inspection$
|
|
78
|
+
DECLARE
|
|
79
|
+
audit_capability_id uuid := pg_catalog.gen_random_uuid();
|
|
80
|
+
previous_audit_token text := pg_catalog.current_setting(
|
|
81
|
+
'opengeni.connection_authority_convergence_audit_token', true
|
|
82
|
+
);
|
|
83
|
+
report jsonb;
|
|
84
|
+
BEGIN
|
|
85
|
+
IF p_account_id IS NULL THEN
|
|
86
|
+
RAISE EXCEPTION 'connection convergence inspection requires an organization id'
|
|
87
|
+
USING ERRCODE = '22004';
|
|
88
|
+
END IF;
|
|
89
|
+
IF p_account_id IS DISTINCT FROM nullif(
|
|
90
|
+
pg_catalog.current_setting('opengeni.account_id', true), ''
|
|
91
|
+
)::uuid THEN
|
|
92
|
+
RAISE EXCEPTION 'connection convergence inspection scope mismatch'
|
|
93
|
+
USING ERRCODE = '42501';
|
|
94
|
+
END IF;
|
|
95
|
+
IF p_limit IS NULL OR p_limit NOT BETWEEN 1 AND 100 THEN
|
|
96
|
+
RAISE EXCEPTION 'connection convergence inspection limit must be 1..100'
|
|
97
|
+
USING ERRCODE = '22023';
|
|
98
|
+
END IF;
|
|
99
|
+
|
|
100
|
+
INSERT INTO connection_authority_convergence_audit_capabilities (
|
|
101
|
+
capability_id, backend_pid, transaction_id, account_id
|
|
102
|
+
) VALUES (
|
|
103
|
+
audit_capability_id, pg_catalog.pg_backend_pid(),
|
|
104
|
+
pg_catalog.pg_current_xact_id(), p_account_id
|
|
105
|
+
);
|
|
106
|
+
PERFORM pg_catalog.set_config(
|
|
107
|
+
'opengeni.connection_authority_convergence_audit_token',
|
|
108
|
+
audit_capability_id::text,
|
|
109
|
+
true
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
-- A cursor is an organization-scoped persisted identifier, not an arbitrary
|
|
113
|
+
-- UUID that may be used as a cross-tenant ordering oracle.
|
|
114
|
+
IF p_after_connection_id IS NOT NULL AND NOT EXISTS (
|
|
115
|
+
SELECT 1
|
|
116
|
+
FROM connections connection_row
|
|
117
|
+
WHERE connection_row.account_id = p_account_id
|
|
118
|
+
AND connection_row.id = p_after_connection_id
|
|
119
|
+
) THEN
|
|
120
|
+
RAISE EXCEPTION 'connection convergence inspection cursor is invalid'
|
|
121
|
+
USING ERRCODE = '22023';
|
|
122
|
+
END IF;
|
|
123
|
+
|
|
124
|
+
WITH classified AS MATERIALIZED (
|
|
125
|
+
SELECT
|
|
126
|
+
connection_row.id AS connection_id,
|
|
127
|
+
connection_row.subject_id,
|
|
128
|
+
CASE
|
|
129
|
+
-- These are migration 0340's two terminal shapes. Exact terminal rows
|
|
130
|
+
-- never appear in residual evidence.
|
|
131
|
+
WHEN connection_row.authority_scope = 'workspace'
|
|
132
|
+
AND connection_row.subject_id IS NULL
|
|
133
|
+
AND connection_row.authority_id IS NULL
|
|
134
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
135
|
+
AND connection_row.origin_workspace_id = connection_row.workspace_id
|
|
136
|
+
THEN NULL
|
|
137
|
+
WHEN connection_row.authority_scope = 'user'
|
|
138
|
+
AND connection_row.subject_id IS NOT NULL
|
|
139
|
+
AND authority.id = connection_row.authority_id
|
|
140
|
+
AND authority.resource_kind = 'connection'
|
|
141
|
+
AND authority.resource_id = connection_row.id
|
|
142
|
+
AND authority.organization_membership_id
|
|
143
|
+
= connection_row.owner_organization_membership_id
|
|
144
|
+
AND authority.origin_workspace_id = connection_row.origin_workspace_id
|
|
145
|
+
AND authority.status = 'active'
|
|
146
|
+
AND authority.revoked_at IS NULL
|
|
147
|
+
AND owner_membership.id = connection_row.owner_organization_membership_id
|
|
148
|
+
AND owner_membership.subject_id = connection_row.subject_id
|
|
149
|
+
AND owner_membership.status = 'active'
|
|
150
|
+
AND owner_membership.revoked_at IS NULL
|
|
151
|
+
THEN NULL
|
|
152
|
+
|
|
153
|
+
-- Only the exact legacy shape is eligible for an automated 0340
|
|
154
|
+
-- transition. Malformed user or legacy rows need incident repair.
|
|
155
|
+
WHEN connection_row.authority_scope = 'legacy_user'
|
|
156
|
+
AND connection_row.authority_id IS NULL
|
|
157
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
158
|
+
AND live_membership.id IS NOT NULL
|
|
159
|
+
THEN 'connection_backfill_ready'
|
|
160
|
+
WHEN connection_row.authority_scope = 'legacy_user'
|
|
161
|
+
AND connection_row.authority_id IS NULL
|
|
162
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
163
|
+
AND terminal_membership.id IS NOT NULL
|
|
164
|
+
THEN 'membership_lifecycle_review_required'
|
|
165
|
+
WHEN connection_row.authority_scope = 'legacy_user'
|
|
166
|
+
AND connection_row.authority_id IS NULL
|
|
167
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
168
|
+
AND (connection_row.subject_id IS NULL
|
|
169
|
+
OR connection_row.subject_id NOT LIKE 'user:%')
|
|
170
|
+
THEN 'external_subject_requires_classification'
|
|
171
|
+
WHEN connection_row.authority_scope = 'legacy_user'
|
|
172
|
+
AND connection_row.authority_id IS NULL
|
|
173
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
174
|
+
AND login.id IS NULL
|
|
175
|
+
THEN 'missing_login_identity'
|
|
176
|
+
WHEN connection_row.authority_scope = 'legacy_user'
|
|
177
|
+
AND connection_row.authority_id IS NULL
|
|
178
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
179
|
+
AND (
|
|
180
|
+
account.external_source IS DISTINCT FROM 'better-auth:user'
|
|
181
|
+
OR account.external_id IS DISTINCT FROM substring(
|
|
182
|
+
connection_row.subject_id FROM 6
|
|
183
|
+
)
|
|
184
|
+
)
|
|
185
|
+
THEN 'organization_identity_mismatch'
|
|
186
|
+
WHEN connection_row.authority_scope = 'legacy_user'
|
|
187
|
+
AND connection_row.authority_id IS NULL
|
|
188
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
189
|
+
AND owner_access.id IS NULL
|
|
190
|
+
THEN 'missing_owner_workspace_membership'
|
|
191
|
+
WHEN connection_row.authority_scope = 'legacy_user'
|
|
192
|
+
AND connection_row.authority_id IS NULL
|
|
193
|
+
AND connection_row.owner_organization_membership_id IS NULL
|
|
194
|
+
THEN 'membership_backfill_eligible'
|
|
195
|
+
WHEN connection_row.authority_scope = 'user'
|
|
196
|
+
THEN 'conflicting_authority_rows'
|
|
197
|
+
ELSE 'legacy_shape_unrecognized'
|
|
198
|
+
END AS classification
|
|
199
|
+
FROM connections connection_row
|
|
200
|
+
JOIN managed_accounts account ON account.id = connection_row.account_id
|
|
201
|
+
LEFT JOIN organization_memberships live_membership
|
|
202
|
+
ON live_membership.account_id = connection_row.account_id
|
|
203
|
+
AND live_membership.subject_id = connection_row.subject_id
|
|
204
|
+
AND live_membership.status = 'active'
|
|
205
|
+
AND live_membership.revoked_at IS NULL
|
|
206
|
+
LEFT JOIN organization_memberships owner_membership
|
|
207
|
+
ON owner_membership.id = connection_row.owner_organization_membership_id
|
|
208
|
+
AND owner_membership.account_id = connection_row.account_id
|
|
209
|
+
LEFT JOIN LATERAL (
|
|
210
|
+
SELECT membership.id
|
|
211
|
+
FROM organization_memberships membership
|
|
212
|
+
WHERE membership.account_id = connection_row.account_id
|
|
213
|
+
AND membership.subject_id = connection_row.subject_id
|
|
214
|
+
AND (
|
|
215
|
+
membership.status IN ('suspended', 'revoked')
|
|
216
|
+
OR membership.revoked_at IS NOT NULL
|
|
217
|
+
)
|
|
218
|
+
ORDER BY membership.id
|
|
219
|
+
LIMIT 1
|
|
220
|
+
) terminal_membership ON true
|
|
221
|
+
LEFT JOIN organization_user_resource_authorities authority
|
|
222
|
+
ON authority.id = connection_row.authority_id
|
|
223
|
+
AND authority.account_id = connection_row.account_id
|
|
224
|
+
LEFT JOIN auth_users login
|
|
225
|
+
ON connection_row.subject_id LIKE 'user:%'
|
|
226
|
+
AND login.id = substring(connection_row.subject_id FROM 6)
|
|
227
|
+
LEFT JOIN LATERAL (
|
|
228
|
+
SELECT access.id
|
|
229
|
+
FROM workspace_memberships access
|
|
230
|
+
JOIN workspaces workspace
|
|
231
|
+
ON workspace.id = access.workspace_id
|
|
232
|
+
AND workspace.account_id = access.account_id
|
|
233
|
+
WHERE access.account_id = connection_row.account_id
|
|
234
|
+
AND access.subject_id = connection_row.subject_id
|
|
235
|
+
AND access.role = 'owner'
|
|
236
|
+
ORDER BY access.id
|
|
237
|
+
LIMIT 1
|
|
238
|
+
) owner_access ON true
|
|
239
|
+
WHERE connection_row.account_id = p_account_id
|
|
240
|
+
), residual AS MATERIALIZED (
|
|
241
|
+
SELECT
|
|
242
|
+
connection_id,
|
|
243
|
+
subject_id,
|
|
244
|
+
classification,
|
|
245
|
+
CASE classification
|
|
246
|
+
WHEN 'connection_backfill_ready'
|
|
247
|
+
THEN 'run_connection_backfill'
|
|
248
|
+
WHEN 'membership_backfill_eligible'
|
|
249
|
+
THEN 'run_membership_backfill_then_connection_backfill'
|
|
250
|
+
WHEN 'membership_lifecycle_review_required'
|
|
251
|
+
THEN 'review_membership_lifecycle_do_not_reactivate_automatically'
|
|
252
|
+
WHEN 'external_subject_requires_classification'
|
|
253
|
+
THEN 'classify_external_subject_then_migrate_via_authorized_connection_lifecycle'
|
|
254
|
+
WHEN 'missing_login_identity'
|
|
255
|
+
THEN 'restore_login_identity_then_recheck'
|
|
256
|
+
WHEN 'organization_identity_mismatch'
|
|
257
|
+
THEN 'correct_organization_identity_through_supported_account_lifecycle_then_recheck'
|
|
258
|
+
WHEN 'missing_owner_workspace_membership'
|
|
259
|
+
THEN 'establish_owner_workspace_membership_through_supported_membership_lifecycle_then_recheck'
|
|
260
|
+
WHEN 'conflicting_authority_rows'
|
|
261
|
+
THEN 'repair_conflicting_connection_authority_rows_under_incident_procedure'
|
|
262
|
+
ELSE 'repair_unrecognized_connection_authority_shape_under_incident_procedure'
|
|
263
|
+
END AS action
|
|
264
|
+
FROM classified
|
|
265
|
+
WHERE classification IS NOT NULL
|
|
266
|
+
), page_candidates AS MATERIALIZED (
|
|
267
|
+
SELECT *
|
|
268
|
+
FROM residual
|
|
269
|
+
WHERE p_after_connection_id IS NULL
|
|
270
|
+
OR connection_id > p_after_connection_id
|
|
271
|
+
ORDER BY connection_id
|
|
272
|
+
LIMIT p_limit + 1
|
|
273
|
+
), page AS MATERIALIZED (
|
|
274
|
+
SELECT * FROM page_candidates ORDER BY connection_id LIMIT p_limit
|
|
275
|
+
), aggregate AS (
|
|
276
|
+
SELECT
|
|
277
|
+
(SELECT coalesce(pg_catalog.jsonb_agg(pg_catalog.jsonb_build_object(
|
|
278
|
+
'connectionId', page.connection_id,
|
|
279
|
+
'subjectId', page.subject_id,
|
|
280
|
+
'classification', page.classification,
|
|
281
|
+
'action', page.action
|
|
282
|
+
) ORDER BY page.connection_id), '[]'::jsonb) FROM page) AS items,
|
|
283
|
+
(SELECT count(*)::int FROM page) AS returned,
|
|
284
|
+
(SELECT count(*) > p_limit FROM page_candidates) AS has_more,
|
|
285
|
+
(SELECT connection_id FROM page ORDER BY connection_id DESC LIMIT 1) AS next_id,
|
|
286
|
+
count(*)::int AS remaining_total,
|
|
287
|
+
count(*) FILTER (WHERE classification IN (
|
|
288
|
+
'connection_backfill_ready', 'membership_backfill_eligible'
|
|
289
|
+
))::int AS auto_remediable,
|
|
290
|
+
count(*) FILTER (WHERE classification NOT IN (
|
|
291
|
+
'connection_backfill_ready', 'membership_backfill_eligible'
|
|
292
|
+
))::int AS manual_review,
|
|
293
|
+
pg_catalog.jsonb_build_object(
|
|
294
|
+
'connectionBackfillReady', count(*) FILTER (
|
|
295
|
+
WHERE classification = 'connection_backfill_ready'
|
|
296
|
+
)::int,
|
|
297
|
+
'membershipBackfillEligible', count(*) FILTER (
|
|
298
|
+
WHERE classification = 'membership_backfill_eligible'
|
|
299
|
+
)::int,
|
|
300
|
+
'membershipLifecycleReviewRequired', count(*) FILTER (
|
|
301
|
+
WHERE classification = 'membership_lifecycle_review_required'
|
|
302
|
+
)::int,
|
|
303
|
+
'externalSubjectRequiresClassification', count(*) FILTER (
|
|
304
|
+
WHERE classification = 'external_subject_requires_classification'
|
|
305
|
+
)::int,
|
|
306
|
+
'missingLoginIdentity', count(*) FILTER (
|
|
307
|
+
WHERE classification = 'missing_login_identity'
|
|
308
|
+
)::int,
|
|
309
|
+
'organizationIdentityMismatch', count(*) FILTER (
|
|
310
|
+
WHERE classification = 'organization_identity_mismatch'
|
|
311
|
+
)::int,
|
|
312
|
+
'missingOwnerWorkspaceMembership', count(*) FILTER (
|
|
313
|
+
WHERE classification = 'missing_owner_workspace_membership'
|
|
314
|
+
)::int,
|
|
315
|
+
'conflictingAuthorityRows', count(*) FILTER (
|
|
316
|
+
WHERE classification = 'conflicting_authority_rows'
|
|
317
|
+
)::int,
|
|
318
|
+
'legacyShapeUnrecognized', count(*) FILTER (
|
|
319
|
+
WHERE classification = 'legacy_shape_unrecognized'
|
|
320
|
+
)::int
|
|
321
|
+
) AS by_classification
|
|
322
|
+
FROM residual
|
|
323
|
+
)
|
|
324
|
+
SELECT pg_catalog.jsonb_build_object(
|
|
325
|
+
'schemaVersion', 1,
|
|
326
|
+
'organizationId', p_account_id,
|
|
327
|
+
'limit', p_limit,
|
|
328
|
+
'afterConnectionId', p_after_connection_id,
|
|
329
|
+
'items', aggregate.items,
|
|
330
|
+
'returned', aggregate.returned,
|
|
331
|
+
'hasMore', aggregate.has_more,
|
|
332
|
+
'nextCursor', CASE WHEN aggregate.has_more THEN aggregate.next_id ELSE NULL END,
|
|
333
|
+
'remaining', pg_catalog.jsonb_build_object(
|
|
334
|
+
'total', aggregate.remaining_total,
|
|
335
|
+
'autoRemediable', aggregate.auto_remediable,
|
|
336
|
+
'manualReview', aggregate.manual_review,
|
|
337
|
+
'byClassification', aggregate.by_classification
|
|
338
|
+
)
|
|
339
|
+
) INTO report
|
|
340
|
+
FROM aggregate;
|
|
341
|
+
|
|
342
|
+
DELETE FROM connection_authority_convergence_audit_capabilities
|
|
343
|
+
WHERE capability_id = audit_capability_id;
|
|
344
|
+
PERFORM pg_catalog.set_config(
|
|
345
|
+
'opengeni.connection_authority_convergence_audit_token',
|
|
346
|
+
coalesce(previous_audit_token, ''),
|
|
347
|
+
true
|
|
348
|
+
);
|
|
349
|
+
RETURN report;
|
|
350
|
+
EXCEPTION WHEN OTHERS THEN
|
|
351
|
+
DELETE FROM connection_authority_convergence_audit_capabilities
|
|
352
|
+
WHERE capability_id = audit_capability_id;
|
|
353
|
+
PERFORM pg_catalog.set_config(
|
|
354
|
+
'opengeni.connection_authority_convergence_audit_token',
|
|
355
|
+
coalesce(previous_audit_token, ''),
|
|
356
|
+
true
|
|
357
|
+
);
|
|
358
|
+
RAISE;
|
|
359
|
+
END
|
|
360
|
+
$inspection$;
|
|
361
|
+
REVOKE ALL ON FUNCTION inspect_organization_connection_authority_convergence(
|
|
362
|
+
uuid, integer, uuid
|
|
363
|
+
) FROM PUBLIC;
|
|
364
|
+
|
|
365
|
+
DO $connection_authority_convergence_audit_hardening$
|
|
366
|
+
DECLARE
|
|
367
|
+
data_schema text := pg_catalog.current_schema();
|
|
368
|
+
BEGIN
|
|
369
|
+
EXECUTE pg_catalog.format(
|
|
370
|
+
'ALTER FUNCTION %I.connection_authority_convergence_audit_capability_active(uuid) '
|
|
371
|
+
|| 'SET search_path = pg_catalog, %I, pg_temp',
|
|
372
|
+
data_schema, data_schema
|
|
373
|
+
);
|
|
374
|
+
EXECUTE pg_catalog.format(
|
|
375
|
+
'ALTER FUNCTION %I.inspect_organization_connection_authority_convergence(uuid,integer,uuid) '
|
|
376
|
+
|| 'SET search_path = pg_catalog, %I, pg_temp',
|
|
377
|
+
data_schema, data_schema
|
|
378
|
+
);
|
|
379
|
+
|
|
380
|
+
IF EXISTS (SELECT 1 FROM pg_catalog.pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
381
|
+
EXECUTE pg_catalog.format(
|
|
382
|
+
'GRANT EXECUTE ON FUNCTION %I.inspect_organization_connection_authority_convergence(uuid,integer,uuid) TO opengeni_app',
|
|
383
|
+
data_schema
|
|
384
|
+
);
|
|
385
|
+
END IF;
|
|
386
|
+
END
|
|
387
|
+
$connection_authority_convergence_audit_hardening$;
|
|
388
|
+
|
|
389
|
+
COMMENT ON TABLE connection_authority_convergence_audit_capabilities IS
|
|
390
|
+
'Invocation-scoped, target-local read capability for connection convergence evidence.';
|
|
391
|
+
COMMENT ON FUNCTION connection_authority_convergence_audit_capability_active(uuid) IS
|
|
392
|
+
'True only for the exact backend, transaction, organization, and opaque convergence-audit token.';
|
|
393
|
+
COMMENT ON FUNCTION inspect_organization_connection_authority_convergence(
|
|
394
|
+
uuid, integer, uuid
|
|
395
|
+
) IS
|
|
396
|
+
'Bounded tenant-fenced residual connection evidence with global remaining counts and fixed remediation actions. Never writes authority.';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengeni/db",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.2.0-canary.0",
|
|
4
4
|
"description": "OpenGeni persistence: Drizzle schema, RLS-scoped query layer, the SQL migration runner, and role provisioning.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -54,6 +54,10 @@
|
|
|
54
54
|
"./session-tenancy": {
|
|
55
55
|
"types": "./dist/session-tenancy.d.ts",
|
|
56
56
|
"import": "./dist/session-tenancy.js"
|
|
57
|
+
},
|
|
58
|
+
"./session-background-commands": {
|
|
59
|
+
"types": "./dist/session-background-commands.d.ts",
|
|
60
|
+
"import": "./dist/session-background-commands.js"
|
|
57
61
|
}
|
|
58
62
|
},
|
|
59
63
|
"publishConfig": {
|
|
@@ -70,11 +74,11 @@
|
|
|
70
74
|
"prepublishOnly": "bash ../../scripts/prepublish-guard"
|
|
71
75
|
},
|
|
72
76
|
"dependencies": {
|
|
73
|
-
"@opengeni/codemode": "^0.4.
|
|
74
|
-
"@opengeni/codex": "^0.2.
|
|
75
|
-
"@opengeni/config": "^0.
|
|
76
|
-
"@opengeni/contracts": "^
|
|
77
|
-
"@opengeni/network": "^0.2.
|
|
77
|
+
"@opengeni/codemode": "^0.4.13-canary.0",
|
|
78
|
+
"@opengeni/codex": "^0.2.19-canary.0",
|
|
79
|
+
"@opengeni/config": "^0.19.1-canary.0",
|
|
80
|
+
"@opengeni/contracts": "^2.3.0-canary.0",
|
|
81
|
+
"@opengeni/network": "^0.2.3-canary.0",
|
|
78
82
|
"drizzle-orm": "^0.45.2",
|
|
79
83
|
"postgres": "^3.4.7"
|
|
80
84
|
},
|