@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,454 @@
|
|
|
1
|
+
-- deployment-mode: rolling
|
|
2
|
+
-- Organization-admin read surfaces for the immutable Document authority and
|
|
3
|
+
-- Default-collection migration evidence introduced by 0339. Audit reads use a
|
|
4
|
+
-- target-schema-local, exact-token capability that cannot grant write access or
|
|
5
|
+
-- collide with a second OpenGeni schema in the same database.
|
|
6
|
+
|
|
7
|
+
SET LOCAL lock_timeout = '5s';
|
|
8
|
+
SET LOCAL statement_timeout = '10min';
|
|
9
|
+
|
|
10
|
+
CREATE TABLE document_migration_audit_capabilities (
|
|
11
|
+
capability_id uuid PRIMARY KEY,
|
|
12
|
+
backend_pid integer NOT NULL,
|
|
13
|
+
transaction_id xid8 NOT NULL,
|
|
14
|
+
capability_kind text NOT NULL,
|
|
15
|
+
created_at timestamptz NOT NULL DEFAULT clock_timestamp(),
|
|
16
|
+
CONSTRAINT document_migration_audit_capabilities_kind_chk CHECK (
|
|
17
|
+
capability_kind IN ('default_backfill_audit', 'reclassification_audit')
|
|
18
|
+
)
|
|
19
|
+
);
|
|
20
|
+
REVOKE ALL ON TABLE document_migration_audit_capabilities FROM PUBLIC;
|
|
21
|
+
|
|
22
|
+
CREATE FUNCTION document_migration_audit_capability_active(p_capability_kind text)
|
|
23
|
+
RETURNS boolean
|
|
24
|
+
LANGUAGE sql
|
|
25
|
+
STABLE
|
|
26
|
+
SECURITY DEFINER
|
|
27
|
+
SET search_path FROM CURRENT
|
|
28
|
+
AS $body$
|
|
29
|
+
SELECT EXISTS (
|
|
30
|
+
SELECT 1
|
|
31
|
+
FROM document_migration_audit_capabilities capability
|
|
32
|
+
WHERE capability.capability_id::text =
|
|
33
|
+
nullif(current_setting('opengeni.document_migration_audit_token', true), '')
|
|
34
|
+
AND capability.backend_pid = pg_backend_pid()
|
|
35
|
+
AND capability.transaction_id = pg_current_xact_id_if_assigned()
|
|
36
|
+
AND capability.capability_kind = p_capability_kind
|
|
37
|
+
)
|
|
38
|
+
$body$;
|
|
39
|
+
REVOKE ALL ON FUNCTION document_migration_audit_capability_active(text) FROM PUBLIC;
|
|
40
|
+
|
|
41
|
+
CREATE FUNCTION assert_document_migration_audit_authority(p_command jsonb)
|
|
42
|
+
RETURNS void
|
|
43
|
+
LANGUAGE plpgsql
|
|
44
|
+
SECURITY DEFINER
|
|
45
|
+
SET search_path FROM CURRENT
|
|
46
|
+
AS $body$
|
|
47
|
+
DECLARE
|
|
48
|
+
account_id_value uuid := nullif(p_command ->> 'accountId', '')::uuid;
|
|
49
|
+
workspace_id_value uuid := nullif(p_command ->> 'workspaceId', '')::uuid;
|
|
50
|
+
actor_subject text := nullif(p_command ->> 'actorSubjectId', '');
|
|
51
|
+
authorization_value jsonb := p_command -> 'accountAdminAuthorization';
|
|
52
|
+
BEGIN
|
|
53
|
+
IF p_command IS NULL OR account_id_value IS NULL OR workspace_id_value IS NULL
|
|
54
|
+
OR actor_subject IS NULL
|
|
55
|
+
THEN
|
|
56
|
+
RAISE EXCEPTION 'document migration audit authority is incomplete'
|
|
57
|
+
USING ERRCODE = '22023';
|
|
58
|
+
END IF;
|
|
59
|
+
IF account_id_value IS DISTINCT FROM nullif(
|
|
60
|
+
current_setting('opengeni.account_id', true), ''
|
|
61
|
+
)::uuid
|
|
62
|
+
OR workspace_id_value IS DISTINCT FROM nullif(
|
|
63
|
+
current_setting('opengeni.workspace_id', true), ''
|
|
64
|
+
)::uuid
|
|
65
|
+
OR actor_subject IS DISTINCT FROM nullif(
|
|
66
|
+
current_setting('opengeni.subject_id', true), ''
|
|
67
|
+
)
|
|
68
|
+
THEN
|
|
69
|
+
RAISE EXCEPTION 'document migration audit scope is invalid'
|
|
70
|
+
USING ERRCODE = '42501';
|
|
71
|
+
END IF;
|
|
72
|
+
IF jsonb_typeof(authorization_value) IS DISTINCT FROM 'object'
|
|
73
|
+
OR authorization_value ->> 'permission' IS DISTINCT FROM 'account:admin'
|
|
74
|
+
OR coalesce(authorization_value ->> 'accountId', '')
|
|
75
|
+
!~* '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
|
|
76
|
+
OR (authorization_value ->> 'accountId')::uuid IS DISTINCT FROM account_id_value
|
|
77
|
+
OR nullif(authorization_value ->> 'actorSubjectId', '') IS DISTINCT FROM actor_subject
|
|
78
|
+
OR coalesce(authorization_value ->> 'authorizationId', '')
|
|
79
|
+
!~* '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
|
|
80
|
+
THEN
|
|
81
|
+
RAISE EXCEPTION 'document migration audit requires organization administration'
|
|
82
|
+
USING ERRCODE = '42501';
|
|
83
|
+
END IF;
|
|
84
|
+
END;
|
|
85
|
+
$body$;
|
|
86
|
+
REVOKE ALL ON FUNCTION assert_document_migration_audit_authority(jsonb) FROM PUBLIC;
|
|
87
|
+
|
|
88
|
+
DO $document_migration_audit_policies$
|
|
89
|
+
DECLARE
|
|
90
|
+
data_schema text := current_schema();
|
|
91
|
+
migration_owner text := current_user;
|
|
92
|
+
table_name text;
|
|
93
|
+
capability_kind text;
|
|
94
|
+
BEGIN
|
|
95
|
+
FOREACH table_name IN ARRAY ARRAY[
|
|
96
|
+
'document_default_collection_backfill_runs',
|
|
97
|
+
'document_default_collection_backfill_operations',
|
|
98
|
+
'document_default_collection_backfill_receipts',
|
|
99
|
+
'document_authority_reclassifications'
|
|
100
|
+
] LOOP
|
|
101
|
+
capability_kind := CASE
|
|
102
|
+
WHEN table_name = 'document_authority_reclassifications'
|
|
103
|
+
THEN 'reclassification_audit'
|
|
104
|
+
ELSE 'default_backfill_audit'
|
|
105
|
+
END;
|
|
106
|
+
EXECUTE format(
|
|
107
|
+
'CREATE POLICY document_migration_audit_read ON %I.%I '
|
|
108
|
+
|| 'FOR SELECT USING (current_user = %L AND '
|
|
109
|
+
|| '%I.document_migration_audit_capability_active(%L))',
|
|
110
|
+
data_schema, table_name, migration_owner, data_schema, capability_kind
|
|
111
|
+
);
|
|
112
|
+
END LOOP;
|
|
113
|
+
END;
|
|
114
|
+
$document_migration_audit_policies$;
|
|
115
|
+
|
|
116
|
+
CREATE FUNCTION list_document_default_collection_backfill_runs(p_command jsonb)
|
|
117
|
+
RETURNS SETOF jsonb
|
|
118
|
+
LANGUAGE plpgsql
|
|
119
|
+
SECURITY DEFINER
|
|
120
|
+
SET search_path FROM CURRENT
|
|
121
|
+
AS $body$
|
|
122
|
+
DECLARE
|
|
123
|
+
account_id_value uuid := nullif(p_command ->> 'accountId', '')::uuid;
|
|
124
|
+
limit_value integer := coalesce((p_command ->> 'limit')::integer, 50);
|
|
125
|
+
before_started_at timestamptz := nullif(p_command ->> 'beforeStartedAt', '')::timestamptz;
|
|
126
|
+
before_run_id uuid := nullif(p_command ->> 'beforeRunId', '')::uuid;
|
|
127
|
+
audit_capability_id uuid := gen_random_uuid();
|
|
128
|
+
previous_audit_token text := current_setting(
|
|
129
|
+
'opengeni.document_migration_audit_token', true
|
|
130
|
+
);
|
|
131
|
+
row_value jsonb;
|
|
132
|
+
BEGIN
|
|
133
|
+
PERFORM assert_document_migration_audit_authority(p_command);
|
|
134
|
+
IF limit_value NOT BETWEEN 1 AND 101 THEN
|
|
135
|
+
RAISE EXCEPTION 'document migration audit limit is invalid'
|
|
136
|
+
USING ERRCODE = '22023';
|
|
137
|
+
END IF;
|
|
138
|
+
IF (before_started_at IS NULL) IS DISTINCT FROM (before_run_id IS NULL) THEN
|
|
139
|
+
RAISE EXCEPTION 'document migration audit cursor is invalid'
|
|
140
|
+
USING ERRCODE = '22023';
|
|
141
|
+
END IF;
|
|
142
|
+
|
|
143
|
+
INSERT INTO document_migration_audit_capabilities (
|
|
144
|
+
capability_id, backend_pid, transaction_id, capability_kind
|
|
145
|
+
) VALUES (
|
|
146
|
+
audit_capability_id, pg_backend_pid(), pg_current_xact_id(),
|
|
147
|
+
'default_backfill_audit'
|
|
148
|
+
);
|
|
149
|
+
PERFORM set_config(
|
|
150
|
+
'opengeni.document_migration_audit_token', audit_capability_id::text, true
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
FOR row_value IN
|
|
154
|
+
SELECT jsonb_build_object(
|
|
155
|
+
'runId', run.run_id,
|
|
156
|
+
'actorSubjectId', run.actor_subject_id,
|
|
157
|
+
'status', run.status,
|
|
158
|
+
'lastWorkspaceId', run.last_workspace_id,
|
|
159
|
+
'processedCount', run.processed_count,
|
|
160
|
+
'createdCount', run.created_count,
|
|
161
|
+
'adoptedCount', run.adopted_count,
|
|
162
|
+
'startedAt', run.started_at,
|
|
163
|
+
'updatedAt', run.updated_at,
|
|
164
|
+
'completedAt', run.completed_at
|
|
165
|
+
)
|
|
166
|
+
FROM document_default_collection_backfill_runs run
|
|
167
|
+
WHERE run.account_id = account_id_value
|
|
168
|
+
AND (
|
|
169
|
+
before_started_at IS NULL
|
|
170
|
+
OR (run.started_at, run.run_id) < (before_started_at, before_run_id)
|
|
171
|
+
)
|
|
172
|
+
ORDER BY run.started_at DESC, run.run_id DESC
|
|
173
|
+
LIMIT limit_value
|
|
174
|
+
LOOP
|
|
175
|
+
RETURN NEXT row_value;
|
|
176
|
+
END LOOP;
|
|
177
|
+
|
|
178
|
+
DELETE FROM document_migration_audit_capabilities
|
|
179
|
+
WHERE capability_id = audit_capability_id;
|
|
180
|
+
PERFORM set_config(
|
|
181
|
+
'opengeni.document_migration_audit_token', coalesce(previous_audit_token, ''), true
|
|
182
|
+
);
|
|
183
|
+
RETURN;
|
|
184
|
+
EXCEPTION WHEN OTHERS THEN
|
|
185
|
+
DELETE FROM document_migration_audit_capabilities
|
|
186
|
+
WHERE capability_id = audit_capability_id;
|
|
187
|
+
PERFORM set_config(
|
|
188
|
+
'opengeni.document_migration_audit_token', coalesce(previous_audit_token, ''), true
|
|
189
|
+
);
|
|
190
|
+
RAISE;
|
|
191
|
+
END;
|
|
192
|
+
$body$;
|
|
193
|
+
REVOKE ALL ON FUNCTION list_document_default_collection_backfill_runs(jsonb) FROM PUBLIC;
|
|
194
|
+
|
|
195
|
+
CREATE FUNCTION get_document_default_collection_backfill_audit(p_command jsonb)
|
|
196
|
+
RETURNS jsonb
|
|
197
|
+
LANGUAGE plpgsql
|
|
198
|
+
SECURITY DEFINER
|
|
199
|
+
SET search_path FROM CURRENT
|
|
200
|
+
AS $body$
|
|
201
|
+
DECLARE
|
|
202
|
+
account_id_value uuid := nullif(p_command ->> 'accountId', '')::uuid;
|
|
203
|
+
run_id_value uuid := nullif(p_command ->> 'runId', '')::uuid;
|
|
204
|
+
requested_limit integer := coalesce((p_command ->> 'limit')::integer, 50);
|
|
205
|
+
page_limit integer;
|
|
206
|
+
operation_before_created_at timestamptz := nullif(
|
|
207
|
+
p_command ->> 'operationBeforeCreatedAt', ''
|
|
208
|
+
)::timestamptz;
|
|
209
|
+
operation_before_id uuid := nullif(p_command ->> 'operationBeforeId', '')::uuid;
|
|
210
|
+
receipt_after_workspace_id uuid := nullif(
|
|
211
|
+
p_command ->> 'receiptAfterWorkspaceId', ''
|
|
212
|
+
)::uuid;
|
|
213
|
+
audit_capability_id uuid := gen_random_uuid();
|
|
214
|
+
previous_audit_token text := current_setting(
|
|
215
|
+
'opengeni.document_migration_audit_token', true
|
|
216
|
+
);
|
|
217
|
+
result_value jsonb;
|
|
218
|
+
BEGIN
|
|
219
|
+
PERFORM assert_document_migration_audit_authority(p_command);
|
|
220
|
+
IF run_id_value IS NULL THEN
|
|
221
|
+
RAISE EXCEPTION 'document Default collection backfill audit run id is required'
|
|
222
|
+
USING ERRCODE = '22023';
|
|
223
|
+
END IF;
|
|
224
|
+
IF requested_limit NOT BETWEEN 1 AND 100 THEN
|
|
225
|
+
RAISE EXCEPTION 'document migration audit limit is invalid'
|
|
226
|
+
USING ERRCODE = '22023';
|
|
227
|
+
END IF;
|
|
228
|
+
IF (operation_before_created_at IS NULL)
|
|
229
|
+
IS DISTINCT FROM (operation_before_id IS NULL)
|
|
230
|
+
THEN
|
|
231
|
+
RAISE EXCEPTION 'document migration audit cursor is invalid'
|
|
232
|
+
USING ERRCODE = '22023';
|
|
233
|
+
END IF;
|
|
234
|
+
page_limit := requested_limit + 1;
|
|
235
|
+
|
|
236
|
+
INSERT INTO document_migration_audit_capabilities (
|
|
237
|
+
capability_id, backend_pid, transaction_id, capability_kind
|
|
238
|
+
) VALUES (
|
|
239
|
+
audit_capability_id, pg_backend_pid(), pg_current_xact_id(),
|
|
240
|
+
'default_backfill_audit'
|
|
241
|
+
);
|
|
242
|
+
PERFORM set_config(
|
|
243
|
+
'opengeni.document_migration_audit_token', audit_capability_id::text, true
|
|
244
|
+
);
|
|
245
|
+
|
|
246
|
+
SELECT jsonb_build_object(
|
|
247
|
+
'run', jsonb_build_object(
|
|
248
|
+
'runId', run.run_id,
|
|
249
|
+
'actorSubjectId', run.actor_subject_id,
|
|
250
|
+
'status', run.status,
|
|
251
|
+
'lastWorkspaceId', run.last_workspace_id,
|
|
252
|
+
'processedCount', run.processed_count,
|
|
253
|
+
'createdCount', run.created_count,
|
|
254
|
+
'adoptedCount', run.adopted_count,
|
|
255
|
+
'startedAt', run.started_at,
|
|
256
|
+
'updatedAt', run.updated_at,
|
|
257
|
+
'completedAt', run.completed_at
|
|
258
|
+
),
|
|
259
|
+
'operations', coalesce((
|
|
260
|
+
SELECT jsonb_agg(item.value ORDER BY item.created_at DESC, item.operation_id DESC)
|
|
261
|
+
FROM (
|
|
262
|
+
SELECT
|
|
263
|
+
operation.created_at,
|
|
264
|
+
operation.operation_id,
|
|
265
|
+
jsonb_build_object(
|
|
266
|
+
'operationId', operation.operation_id,
|
|
267
|
+
'result', operation.result,
|
|
268
|
+
'createdAt', operation.created_at
|
|
269
|
+
) AS value
|
|
270
|
+
FROM document_default_collection_backfill_operations operation
|
|
271
|
+
WHERE operation.account_id = account_id_value
|
|
272
|
+
AND operation.run_id = run_id_value
|
|
273
|
+
AND (
|
|
274
|
+
operation_before_created_at IS NULL
|
|
275
|
+
OR (operation.created_at, operation.operation_id)
|
|
276
|
+
< (operation_before_created_at, operation_before_id)
|
|
277
|
+
)
|
|
278
|
+
ORDER BY operation.created_at DESC, operation.operation_id DESC
|
|
279
|
+
LIMIT page_limit
|
|
280
|
+
) item
|
|
281
|
+
), '[]'::jsonb),
|
|
282
|
+
'receipts', coalesce((
|
|
283
|
+
SELECT jsonb_agg(item.value ORDER BY item.workspace_id)
|
|
284
|
+
FROM (
|
|
285
|
+
SELECT
|
|
286
|
+
receipt.workspace_id,
|
|
287
|
+
jsonb_build_object(
|
|
288
|
+
'workspaceId', receipt.workspace_id,
|
|
289
|
+
'baseId', receipt.base_id,
|
|
290
|
+
'outcome', receipt.outcome,
|
|
291
|
+
'createdAt', receipt.created_at
|
|
292
|
+
) AS value
|
|
293
|
+
FROM document_default_collection_backfill_receipts receipt
|
|
294
|
+
WHERE receipt.account_id = account_id_value
|
|
295
|
+
AND receipt.run_id = run_id_value
|
|
296
|
+
AND (
|
|
297
|
+
receipt_after_workspace_id IS NULL
|
|
298
|
+
OR receipt.workspace_id > receipt_after_workspace_id
|
|
299
|
+
)
|
|
300
|
+
ORDER BY receipt.workspace_id
|
|
301
|
+
LIMIT page_limit
|
|
302
|
+
) item
|
|
303
|
+
), '[]'::jsonb)
|
|
304
|
+
) INTO result_value
|
|
305
|
+
FROM document_default_collection_backfill_runs run
|
|
306
|
+
WHERE run.account_id = account_id_value
|
|
307
|
+
AND run.run_id = run_id_value;
|
|
308
|
+
|
|
309
|
+
DELETE FROM document_migration_audit_capabilities
|
|
310
|
+
WHERE capability_id = audit_capability_id;
|
|
311
|
+
PERFORM set_config(
|
|
312
|
+
'opengeni.document_migration_audit_token', coalesce(previous_audit_token, ''), true
|
|
313
|
+
);
|
|
314
|
+
IF result_value IS NULL THEN
|
|
315
|
+
RAISE EXCEPTION 'document Default collection backfill audit run is unavailable'
|
|
316
|
+
USING ERRCODE = 'P0002';
|
|
317
|
+
END IF;
|
|
318
|
+
RETURN result_value;
|
|
319
|
+
EXCEPTION WHEN OTHERS THEN
|
|
320
|
+
DELETE FROM document_migration_audit_capabilities
|
|
321
|
+
WHERE capability_id = audit_capability_id;
|
|
322
|
+
PERFORM set_config(
|
|
323
|
+
'opengeni.document_migration_audit_token', coalesce(previous_audit_token, ''), true
|
|
324
|
+
);
|
|
325
|
+
RAISE;
|
|
326
|
+
END;
|
|
327
|
+
$body$;
|
|
328
|
+
REVOKE ALL ON FUNCTION get_document_default_collection_backfill_audit(jsonb) FROM PUBLIC;
|
|
329
|
+
|
|
330
|
+
CREATE FUNCTION list_organization_document_authority_reclassifications(p_command jsonb)
|
|
331
|
+
RETURNS SETOF jsonb
|
|
332
|
+
LANGUAGE plpgsql
|
|
333
|
+
SECURITY DEFINER
|
|
334
|
+
SET search_path FROM CURRENT
|
|
335
|
+
AS $body$
|
|
336
|
+
DECLARE
|
|
337
|
+
account_id_value uuid := nullif(p_command ->> 'accountId', '')::uuid;
|
|
338
|
+
limit_value integer := coalesce((p_command ->> 'limit')::integer, 50);
|
|
339
|
+
before_created_at timestamptz := nullif(p_command ->> 'beforeCreatedAt', '')::timestamptz;
|
|
340
|
+
before_operation_id uuid := nullif(p_command ->> 'beforeOperationId', '')::uuid;
|
|
341
|
+
audit_capability_id uuid := gen_random_uuid();
|
|
342
|
+
previous_audit_token text := current_setting(
|
|
343
|
+
'opengeni.document_migration_audit_token', true
|
|
344
|
+
);
|
|
345
|
+
row_value jsonb;
|
|
346
|
+
BEGIN
|
|
347
|
+
PERFORM assert_document_migration_audit_authority(p_command);
|
|
348
|
+
IF limit_value NOT BETWEEN 1 AND 101 THEN
|
|
349
|
+
RAISE EXCEPTION 'document migration audit limit is invalid'
|
|
350
|
+
USING ERRCODE = '22023';
|
|
351
|
+
END IF;
|
|
352
|
+
IF (before_created_at IS NULL) IS DISTINCT FROM (before_operation_id IS NULL) THEN
|
|
353
|
+
RAISE EXCEPTION 'document migration audit cursor is invalid'
|
|
354
|
+
USING ERRCODE = '22023';
|
|
355
|
+
END IF;
|
|
356
|
+
|
|
357
|
+
INSERT INTO document_migration_audit_capabilities (
|
|
358
|
+
capability_id, backend_pid, transaction_id, capability_kind
|
|
359
|
+
) VALUES (
|
|
360
|
+
audit_capability_id, pg_backend_pid(), pg_current_xact_id(),
|
|
361
|
+
'reclassification_audit'
|
|
362
|
+
);
|
|
363
|
+
PERFORM set_config(
|
|
364
|
+
'opengeni.document_migration_audit_token', audit_capability_id::text, true
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
FOR row_value IN
|
|
368
|
+
SELECT receipt.result || jsonb_build_object(
|
|
369
|
+
'actorSubjectId', receipt.actor_subject_id,
|
|
370
|
+
'requestWorkspaceId', receipt.request_workspace_id
|
|
371
|
+
)
|
|
372
|
+
FROM document_authority_reclassifications receipt
|
|
373
|
+
WHERE receipt.account_id = account_id_value
|
|
374
|
+
AND (
|
|
375
|
+
before_created_at IS NULL
|
|
376
|
+
OR (receipt.created_at, receipt.operation_id)
|
|
377
|
+
< (before_created_at, before_operation_id)
|
|
378
|
+
)
|
|
379
|
+
ORDER BY receipt.created_at DESC, receipt.operation_id DESC
|
|
380
|
+
LIMIT limit_value
|
|
381
|
+
LOOP
|
|
382
|
+
RETURN NEXT row_value;
|
|
383
|
+
END LOOP;
|
|
384
|
+
|
|
385
|
+
DELETE FROM document_migration_audit_capabilities
|
|
386
|
+
WHERE capability_id = audit_capability_id;
|
|
387
|
+
PERFORM set_config(
|
|
388
|
+
'opengeni.document_migration_audit_token', coalesce(previous_audit_token, ''), true
|
|
389
|
+
);
|
|
390
|
+
RETURN;
|
|
391
|
+
EXCEPTION WHEN OTHERS THEN
|
|
392
|
+
DELETE FROM document_migration_audit_capabilities
|
|
393
|
+
WHERE capability_id = audit_capability_id;
|
|
394
|
+
PERFORM set_config(
|
|
395
|
+
'opengeni.document_migration_audit_token', coalesce(previous_audit_token, ''), true
|
|
396
|
+
);
|
|
397
|
+
RAISE;
|
|
398
|
+
END;
|
|
399
|
+
$body$;
|
|
400
|
+
REVOKE ALL ON FUNCTION
|
|
401
|
+
list_organization_document_authority_reclassifications(jsonb) FROM PUBLIC;
|
|
402
|
+
|
|
403
|
+
DO $document_migration_audit_search_paths$
|
|
404
|
+
DECLARE
|
|
405
|
+
data_schema text := current_schema();
|
|
406
|
+
BEGIN
|
|
407
|
+
EXECUTE format(
|
|
408
|
+
'ALTER FUNCTION %I.document_migration_audit_capability_active(text) '
|
|
409
|
+
|| 'SET search_path = pg_catalog, %I, pg_temp',
|
|
410
|
+
data_schema, data_schema
|
|
411
|
+
);
|
|
412
|
+
EXECUTE format(
|
|
413
|
+
'ALTER FUNCTION %I.assert_document_migration_audit_authority(jsonb) '
|
|
414
|
+
|| 'SET search_path = pg_catalog, %I, pg_temp',
|
|
415
|
+
data_schema, data_schema
|
|
416
|
+
);
|
|
417
|
+
EXECUTE format(
|
|
418
|
+
'ALTER FUNCTION %I.list_document_default_collection_backfill_runs(jsonb) '
|
|
419
|
+
|| 'SET search_path = pg_catalog, %I, pg_temp',
|
|
420
|
+
data_schema, data_schema
|
|
421
|
+
);
|
|
422
|
+
EXECUTE format(
|
|
423
|
+
'ALTER FUNCTION %I.get_document_default_collection_backfill_audit(jsonb) '
|
|
424
|
+
|| 'SET search_path = pg_catalog, %I, pg_temp',
|
|
425
|
+
data_schema, data_schema
|
|
426
|
+
);
|
|
427
|
+
EXECUTE format(
|
|
428
|
+
'ALTER FUNCTION %I.list_organization_document_authority_reclassifications(jsonb) '
|
|
429
|
+
|| 'SET search_path = pg_catalog, %I, pg_temp',
|
|
430
|
+
data_schema, data_schema
|
|
431
|
+
);
|
|
432
|
+
END;
|
|
433
|
+
$document_migration_audit_search_paths$;
|
|
434
|
+
|
|
435
|
+
DO $document_migration_audit_runtime_grants$
|
|
436
|
+
BEGIN
|
|
437
|
+
IF EXISTS (SELECT 1 FROM pg_roles WHERE rolname = 'opengeni_app') THEN
|
|
438
|
+
GRANT EXECUTE ON FUNCTION
|
|
439
|
+
list_document_default_collection_backfill_runs(jsonb) TO opengeni_app;
|
|
440
|
+
GRANT EXECUTE ON FUNCTION
|
|
441
|
+
get_document_default_collection_backfill_audit(jsonb) TO opengeni_app;
|
|
442
|
+
GRANT EXECUTE ON FUNCTION
|
|
443
|
+
list_organization_document_authority_reclassifications(jsonb) TO opengeni_app;
|
|
444
|
+
REVOKE ALL ON FUNCTION
|
|
445
|
+
document_migration_audit_capability_active(text) FROM opengeni_app;
|
|
446
|
+
REVOKE ALL ON FUNCTION
|
|
447
|
+
assert_document_migration_audit_authority(jsonb) FROM opengeni_app;
|
|
448
|
+
REVOKE ALL ON TABLE document_migration_audit_capabilities FROM opengeni_app;
|
|
449
|
+
END IF;
|
|
450
|
+
END;
|
|
451
|
+
$document_migration_audit_runtime_grants$;
|
|
452
|
+
|
|
453
|
+
COMMENT ON TABLE document_migration_audit_capabilities IS
|
|
454
|
+
'Target-local exact-token capabilities for read-only Document migration audit projections.';
|