@ai-matrx/records 0.16.0 → 0.20.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.
@@ -47,7 +47,7 @@ var err = (error) => ({ ok: false, error });
47
47
  var ACTOR_VOCABULARY = ["user", "agent", "system"];
48
48
  var RETIRED_ACTOR_WORDS = { "ai": "agent", "code": "system", "human": "user" };
49
49
  var ABSENCE_REASONS = ["never asked", "none", "refused", "conflicting"];
50
- var VALUE_ENVELOPE_KEYS = ["ver", "src", "actor", "on_behalf_of", "at", "absent", "alternates", "dated"];
50
+ var VALUE_ENVELOPE_KEYS = ["ver", "src", "actor", "on_behalf_of", "at", "absent", "alternates", "dated", "pinned"];
51
51
  var VALUE_ALTERNATE_KEYS = ["value", "src", "rank"];
52
52
  var STORAGE_MODES = ["light", "heavy"];
53
53
  var RULE_USES = ["validate", "compute", "membership", "applicability"];
@@ -143,8 +143,19 @@ var STORE_DOORS = [
143
143
  { name: "bump_epoch", args: "p_entity_type text, p_entity_id uuid, p_organization_id uuid DEFAULT NULL::uuid", returns: "bigint", security: "definer" },
144
144
  { name: "cache_lookup", args: "p_container_type text, p_container_id uuid, p_item_type text, p_item_id uuid", returns: "permission_level", security: "definer" },
145
145
  { name: "caller_role", args: "", returns: "name", security: "invoker" },
146
+ { name: "carry_unchanged_value_stamps", args: "p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
146
147
  { name: "carrying_edges_in", args: "p_organization_id uuid", returns: "TABLE(container_type text, container_id uuid, item_type text, item_id uuid, conveys_max permission_level)", security: "definer" },
147
148
  { name: "carrying_edges_of", args: "p_item_type text, p_item_id uuid", returns: "TABLE(container_type text, container_id uuid, conveys_max permission_level)", security: "definer" },
149
+ { name: "checklist_declare", args: "p_organization_id uuid, p_spec jsonb, p_template_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
150
+ { name: "checklist_refusal", args: "p_spec jsonb", returns: "text", security: "invoker" },
151
+ { name: "checklist_run", args: "p_organization_id uuid, p_run_id uuid", returns: "TABLE(step_id uuid, step_order integer, ref text, title text, role text, assignee_name text, assignee_user_id uuid, due_on timestamp with time zone, due_state text, status text, finished boolean, requires text, requires_key text, requires_label text, requires_id uuid, evidence jsonb, blocked_by text[], may_complete boolean, refusal text)", security: "definer" },
152
+ { name: "checklist_runs", args: "p_organization_id uuid, p_about_table_id uuid DEFAULT NULL::uuid, p_about_record_id uuid DEFAULT NULL::uuid, p_include_closed boolean DEFAULT true, p_limit integer DEFAULT 100", returns: "TABLE(run_id uuid, name text, template_id uuid, template text, about_record_id uuid, about text, about_table_id uuid, started_at timestamp with time zone, started_by uuid, origin text, step_count integer, done integer, overdue integer, next_step text, next_due timestamp with time zone, closed_at timestamp with time zone)", security: "definer" },
153
+ { name: "checklist_start", args: "p_organization_id uuid, p_template_id uuid, p_about_record_id uuid DEFAULT NULL::uuid, p_roles jsonb DEFAULT '{}'::jsonb, p_starting_at timestamp with time zone DEFAULT NULL::timestamp with time zone", returns: "jsonb", security: "definer" },
154
+ { name: "checklist_step_complete", args: "p_organization_id uuid, p_step_id uuid, p_evidence jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
155
+ { name: "checklist_step_refusal", args: "p_organization_id uuid, p_step_id uuid", returns: "text", security: "definer" },
156
+ { name: "checklist_steps_table", args: "p_organization_id uuid", returns: "uuid", security: "definer" },
157
+ { name: "checklist_template_shape", args: "p_organization_id uuid, p_template_id uuid", returns: "jsonb", security: "definer" },
158
+ { name: "checklist_templates", args: "p_organization_id uuid, p_about_table_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 100", returns: "TABLE(template_id uuid, name text, about_table_id uuid, about_table text, steps integer, roles integer, trigger_kind text, trigger_status text, open_runs integer, total_runs integer, updated_at timestamp with time zone)", security: "definer" },
148
159
  { name: "choice_census", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
149
160
  { name: "choice_field_map", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "invoker" },
150
161
  { name: "choice_filter_normalize", args: "p_map jsonb, p_filter jsonb", returns: "jsonb", security: "invoker" },
@@ -160,11 +171,19 @@ var STORE_DOORS = [
160
171
  { name: "choice_synonyms_in", args: "p_map jsonb, p_token text", returns: "text[]", security: "invoker" },
161
172
  { name: "choice_words", args: "p_field jsonb", returns: "text", security: "invoker" },
162
173
  { name: "client_write_grants", args: "", returns: "TABLE(role_name text, object_name text, privilege text)", security: "invoker" },
174
+ { name: "comment_mention_deliver", args: "p_organization_id uuid, p_record_id uuid, p_table_id uuid, p_comment_id uuid, p_recipient uuid, p_author_name text, p_record_title text, p_body text", returns: "uuid", security: "definer" },
175
+ { name: "comment_thread", args: "p_organization_id uuid, p_record_id uuid, p_include_resolved boolean DEFAULT false", returns: "jsonb", security: "definer" },
176
+ { name: "comment_write", args: "p_organization_id uuid, p_record_id uuid, p_body text, p_anchor jsonb DEFAULT '{}'::jsonb, p_parent_comment_id uuid DEFAULT NULL::uuid, p_mentions uuid[] DEFAULT NULL::uuid[]", returns: "jsonb", security: "definer" },
163
177
  { name: "computed_provenance", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, value jsonb, rule_id uuid, rule_version integer, computed_at timestamp with time zone)", security: "invoker" },
164
178
  { name: "containment_chain", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(ancestor_id uuid, depth integer)", security: "invoker" },
165
179
  { name: "containment_depth_ceiling", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "integer", security: "invoker" },
166
180
  { name: "containment_edges", args: "p_organization_id uuid", returns: "TABLE(parent_id uuid, child_id uuid, via text)", security: "invoker" },
167
181
  { name: "containment_parent", args: "p_data jsonb", returns: "uuid", security: "invoker" },
182
+ { name: "context_resolve", args: "p_organization_id uuid, p_bindings jsonb, p_scope_slug text DEFAULT 'scopes'::text", returns: "jsonb", security: "definer" },
183
+ { name: "conversation_scope", args: "p_organization_id uuid, p_conversation_id uuid", returns: "jsonb", security: "definer" },
184
+ { name: "conversation_scope_bind", args: "p_organization_id uuid, p_conversation_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
185
+ { name: "conversation_scope_context", args: "p_organization_id uuid, p_conversation_id uuid, p_relations integer DEFAULT 12, p_history integer DEFAULT 15, p_siblings integer DEFAULT 8", returns: "jsonb", security: "definer" },
186
+ { name: "conversation_scope_unbind", args: "p_organization_id uuid, p_conversation_id uuid", returns: "jsonb", security: "definer" },
168
187
  { name: "cross_organization_links_open", args: "p_source_organization_id uuid, p_target_organization_id uuid", returns: "boolean", security: "invoker" },
169
188
  { name: "custom_fields_tables", args: "", returns: "TABLE(token text, schema_name text, table_name text)", security: "invoker" },
170
189
  { name: "dashboard_block_normalize", args: "p_organization_id uuid, p_subject_table_id uuid, p_block jsonb", returns: "jsonb", security: "definer" },
@@ -188,24 +207,43 @@ var STORE_DOORS = [
188
207
  { name: "derived_values", args: "p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "invoker" },
189
208
  { name: "doc_content_hash", args: "p_body text", returns: "text", security: "invoker" },
190
209
  { name: "doc_format_value", args: "p_field_data jsonb, p_value jsonb", returns: "text", security: "invoker" },
210
+ { name: "doc_letterhead", args: "p_organization_id uuid", returns: "jsonb", security: "definer" },
211
+ { name: "doc_name_token_pattern", args: "", returns: "text", security: "invoker" },
212
+ { name: "doc_name_tokens", args: "p_body text", returns: "TABLE(ordinal integer, raw text)", security: "invoker" },
191
213
  { name: "doc_render_body", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid", returns: "text", security: "invoker" },
192
214
  { name: "doc_render_document", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
193
215
  { name: "doc_render_read", args: "p_organization_id uuid, p_render_id uuid", returns: "jsonb", security: "definer" },
194
216
  { name: "doc_render_write", args: "p_organization_id uuid, p_template_id uuid, p_record_id uuid, p_table_id uuid, p_template_version integer, p_body text, p_content_hash text", returns: "uuid", security: "definer" },
217
+ { name: "doc_renders", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(render_id uuid, template_id uuid, record_id uuid, table_id uuid, template_version integer, body text, content_hash text, rendered_at timestamp with time zone)", security: "definer" },
195
218
  { name: "doc_sign", args: "p_organization_id uuid, p_render_id uuid, p_field_key text, p_signer_name text, p_signer_user_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
196
219
  { name: "doc_signature_field_ok", args: "p_field_data jsonb", returns: "boolean", security: "invoker" },
197
220
  { name: "doc_signature_intact", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "invoker" },
198
221
  { name: "doc_signature_read", args: "p_organization_id uuid, p_signature_id uuid", returns: "jsonb", security: "definer" },
199
222
  { name: "doc_signature_write", args: "p_organization_id uuid, p_render_id uuid, p_record_id uuid, p_field_key text, p_signer_name text, p_signer_user_id uuid, p_document_hash text, p_document_version integer", returns: "uuid", security: "definer" },
223
+ { name: "doc_signatures", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(signature_id uuid, render_id uuid, record_id uuid, field_key text, signer_name text, signer_user_id uuid, signed_at timestamp with time zone, document_hash text, document_version integer)", security: "definer" },
224
+ { name: "doc_template_delete", args: "p_organization_id uuid, p_template_id uuid", returns: "boolean", security: "definer" },
200
225
  { name: "doc_template_read", args: "p_organization_id uuid, p_template_id uuid", returns: "jsonb", security: "definer" },
201
226
  { name: "doc_template_save", args: "p_organization_id uuid, p_table_id uuid, p_name text, p_body text, p_template_id uuid DEFAULT NULL::uuid", returns: "uuid", security: "definer" },
227
+ { name: "doc_templates", args: "p_organization_id uuid, p_table_id uuid", returns: "TABLE(template_id uuid, renders_table_id uuid, name text, body text, template_version integer, token_count bigint, updated_at timestamp with time zone)", security: "definer" },
202
228
  { name: "doc_token_pattern", args: "", returns: "text", security: "invoker" },
203
229
  { name: "doc_tokens", args: "p_body text", returns: "TABLE(ordinal integer, raw text, field_id uuid)", security: "invoker" },
204
230
  { name: "doc_unresolved_tokens", args: "p_organization_id uuid, p_table_id uuid, p_body text", returns: "TABLE(raw text, field_id uuid, why text)", security: "invoker" },
205
231
  { name: "doors_not_deciding_the_caller", args: "", returns: "TABLE(function_name text, identity_args text)", security: "invoker" },
206
232
  { name: "doors_not_deciding_the_record", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
233
+ { name: "doors_not_masking_fields", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
207
234
  { name: "doors_not_on_one_ladder", args: "", returns: "TABLE(function_name text, identity_args text, why text)", security: "invoker" },
208
235
  { name: "effective_level", args: "p_user_id uuid, p_organization_id uuid, p_id uuid, p_type text DEFAULT 'record'::text", returns: "permission_level", security: "definer" },
236
+ { name: "enrich_cells", args: "p_organization_id uuid, p_table_id uuid, p_field_keys text[] DEFAULT NULL::text[], p_record_ids uuid[] DEFAULT NULL::uuid[]", returns: "TABLE(record_id uuid, field_key text, agent_owned boolean, value jsonb, value_version integer, actor text, on_behalf_of text, written_at timestamp with time zone, source jsonb, absent_reason text, alternates jsonb, pinned boolean, stale boolean, due_at timestamp with time zone)", security: "definer" },
237
+ { name: "enrich_declare", args: "p_organization_id uuid, p_field_id uuid, p_spec jsonb", returns: "jsonb", security: "definer" },
238
+ { name: "enrich_due", args: "p_organization_id uuid, p_field_id uuid, p_limit integer DEFAULT 50, p_include_fresh boolean DEFAULT false", returns: "TABLE(record_id uuid, title text, inputs jsonb, current_value jsonb, written_at timestamp with time zone, reason text, trimmed_to integer)", security: "definer" },
239
+ { name: "enrich_land", args: "p_organization_id uuid, p_field_id uuid, p_results jsonb, p_run jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
240
+ { name: "enrich_normalize", args: "p_organization_id uuid, p_table_id uuid, p_field_key text, p_spec jsonb", returns: "jsonb", security: "definer" },
241
+ { name: "enrich_pin", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_pinned boolean DEFAULT true", returns: "jsonb", security: "definer" },
242
+ { name: "enrich_run_class", args: "", returns: "text", security: "invoker" },
243
+ { name: "enrich_runs", args: "p_organization_id uuid, p_field_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 50", returns: "TABLE(run_id uuid, field_id uuid, field_key text, model text, trigger_word text, rows_seen integer, rows_written integer, rows_absent integer, rows_below_floor integer, rows_pinned integer, rows_refused integer, cost_cents numeric, cost_per_row_cents numeric, ran_at timestamp with time zone)", security: "definer" },
244
+ { name: "enrich_sensitivity_rank", args: "p_word text", returns: "integer", security: "invoker" },
245
+ { name: "enrich_triggers", args: "", returns: "text[]", security: "invoker" },
246
+ { name: "enrichments", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(field_id uuid, table_id uuid, field_key text, label text, enrichment jsonb, enabled boolean, review_interval_days integer, rows_total integer, rows_filled integer, rows_stale integer, rows_pinned integer, rows_absent integer, runs integer, cost_cents numeric, cost_per_row_cents numeric, last_run_at timestamp with time zone, last_run jsonb)", security: "definer" },
209
247
  { name: "entity_field_declare", args: "p_organization_id uuid, p_token text, p_spec jsonb", returns: "uuid", security: "definer" },
210
248
  { name: "entity_field_retire", args: "p_organization_id uuid, p_field_id uuid", returns: "uuid", security: "definer" },
211
249
  { name: "entity_field_rights", args: "p_organization_id uuid, p_token text", returns: "jsonb", security: "definer" },
@@ -227,6 +265,7 @@ var STORE_DOORS = [
227
265
  { name: "field_behaviour", args: "p_field_data jsonb", returns: "text", security: "invoker" },
228
266
  { name: "field_declare", args: "p_organization_id uuid, p_table_id uuid, p_spec jsonb", returns: "uuid", security: "definer" },
229
267
  { name: "field_dependants", args: "p_organization_id uuid, p_field_id uuid", returns: "TABLE(kind text, dependant_id uuid, label text, how text)", security: "definer" },
268
+ { name: "field_history", args: "p_organization_id uuid, p_table_id uuid, p_field_key text, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0, p_record_id uuid DEFAULT NULL::uuid", returns: "TABLE(record_id uuid, record_title text, version integer, occurred_at timestamp with time zone, operation_label text, actor jsonb, before jsonb, after jsonb)", security: "definer" },
230
269
  { name: "field_kernel_id", args: "", returns: "uuid", security: "invoker" },
231
270
  { name: "field_options", args: "p_organization_id uuid, p_field_id uuid", returns: "SETOF custom.record", security: "definer" },
232
271
  { name: "field_retire", args: "p_organization_id uuid, p_field_id uuid", returns: "boolean", security: "definer" },
@@ -245,14 +284,26 @@ var STORE_DOORS = [
245
284
  { name: "has_visibility", args: "p_user_id uuid, p_type text, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "boolean", security: "definer" },
246
285
  { name: "has_visibility_at", args: "p_user_id uuid, p_type text, p_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level, p_organization_id uuid DEFAULT NULL::uuid, p_min_version bigint DEFAULT NULL::bigint", returns: "boolean", security: "definer" },
247
286
  { name: "hidden_field_notice", args: "p_field custom.record, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "invoker" },
287
+ { name: "history_actor", args: "p_tier text, p_document jsonb, p_actor_id uuid, p_people jsonb", returns: "jsonb", security: "invoker" },
288
+ { name: "history_changes", args: "p_organization_id uuid, p_table_id uuid, p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
289
+ { name: "history_people", args: "p_organization_id uuid, p_ids uuid[]", returns: "jsonb", security: "definer" },
248
290
  { name: "history_prune", args: "p_organization_id uuid, p_scope text DEFAULT 'values'::text, p_table_id uuid DEFAULT NULL::uuid, p_dry_run boolean DEFAULT true", returns: "jsonb", security: "definer" },
291
+ { name: "history_restore_body", args: "p_current jsonb, p_target jsonb, p_field_key text DEFAULT NULL::text", returns: "jsonb", security: "invoker" },
292
+ { name: "history_restore_body", args: "p_current jsonb, p_target jsonb, p_field_key text, p_author jsonb", returns: "jsonb", security: "invoker" },
249
293
  { name: "history_retention", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
250
294
  { name: "history_retention_floor_raise", args: "p_organization_id uuid, p_days integer", returns: "integer", security: "definer" },
251
295
  { name: "history_retention_set", args: "p_organization_id uuid, p_table_id uuid, p_days integer", returns: "integer", security: "definer" },
252
296
  { name: "home_add", args: "p_organization_id uuid, p_table_id uuid, p_home_record_id uuid", returns: "uuid", security: "definer" },
253
297
  { name: "home_relations", args: "", returns: "TABLE(table_id uuid, home_record_id uuid, organization_id uuid, relation_id uuid)", security: "invoker" },
298
+ { name: "inbound_addresses", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "jsonb", security: "definer" },
299
+ { name: "inbound_declare", args: "p_organization_id uuid, p_table_id uuid, p_label text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
300
+ { name: "inbound_domain", args: "p_organization_id uuid", returns: "text", security: "invoker" },
301
+ { name: "inbound_mail_land", args: "p_address text, p_mail jsonb, p_secret text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
302
+ { name: "inbound_mail_map", args: "p_organization_id uuid, p_table_id uuid, p_mail jsonb", returns: "jsonb", security: "invoker" },
303
+ { name: "inbound_set", args: "p_organization_id uuid, p_inbound_id uuid, p_enabled boolean", returns: "jsonb", security: "definer" },
254
304
  { name: "index_payload", args: "p_organization_id uuid, p_table_id uuid, p_limit integer DEFAULT 1000", returns: "TABLE(id uuid, searchable text)", security: "invoker" },
255
305
  { name: "intern_provenance", args: "p_data jsonb", returns: "jsonb", security: "invoker" },
306
+ { name: "io_cell", args: "p_organization_id uuid, p_field jsonb, p_word text, p_date_order text DEFAULT 'mdy'::text", returns: "jsonb", security: "invoker" },
256
307
  { name: "io_changed_field_ids", args: "p_organization_id uuid, p_table_id uuid, p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
257
308
  { name: "io_changed_keys", args: "p_old jsonb, p_new jsonb", returns: "text[]", security: "invoker" },
258
309
  { name: "io_comment_resolve", args: "p_organization_id uuid, p_comment_id uuid, p_resolved boolean DEFAULT true", returns: "boolean", security: "definer" },
@@ -262,23 +313,38 @@ var STORE_DOORS = [
262
313
  { name: "io_csv_parse", args: "p_text text, p_delimiter text DEFAULT NULL::text", returns: "TABLE(row_number integer, cells text[])", security: "invoker" },
263
314
  { name: "io_export", args: "p_organization_id uuid, p_table_id uuid, p_columns text[] DEFAULT NULL::text[], p_limit integer DEFAULT 10000, p_required text DEFAULT 'viewer'::text", returns: "jsonb", security: "definer" },
264
315
  { name: "io_export_csv", args: "p_organization_id uuid, p_table_id uuid, p_columns text[] DEFAULT NULL::text[], p_limit integer DEFAULT 10000, p_delimiter text DEFAULT chr(44), p_required text DEFAULT 'viewer'::text", returns: "text", security: "definer" },
316
+ { name: "io_import_begin", args: "p_organization_id uuid, p_table_id uuid, p_format text DEFAULT 'csv'::text, p_source_name text DEFAULT NULL::text, p_source_columns jsonb DEFAULT '[]'::jsonb, p_file_hash text DEFAULT NULL::text, p_policy jsonb DEFAULT '{}'::jsonb, p_dedupe_key text DEFAULT NULL::text, p_file_bytes bigint DEFAULT NULL::bigint, p_force boolean DEFAULT false", returns: "jsonb", security: "definer" },
317
+ { name: "io_import_finish", args: "p_organization_id uuid, p_import_id uuid, p_unmapped text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
318
+ { name: "io_import_forget", args: "p_organization_id uuid, p_import_id uuid", returns: "boolean", security: "definer" },
265
319
  { name: "io_import_open", args: "p_organization_id uuid, p_table_id uuid, p_format text DEFAULT 'csv'::text, p_source_name text DEFAULT NULL::text, p_source_columns jsonb DEFAULT '[]'::jsonb", returns: "uuid", security: "definer" },
320
+ { name: "io_import_plan", args: "p_organization_id uuid, p_table_id uuid, p_columns jsonb DEFAULT '[]'::jsonb", returns: "jsonb", security: "definer" },
321
+ { name: "io_import_report", args: "p_organization_id uuid, p_import_id uuid, p_state text DEFAULT NULL::text, p_limit integer DEFAULT 100, p_offset integer DEFAULT 0", returns: "jsonb", security: "definer" },
266
322
  { name: "io_import_rows", args: "p_organization_id uuid, p_import_id uuid, p_rows jsonb, p_mapping jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "definer" },
323
+ { name: "io_imports", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 25", returns: "jsonb", security: "definer" },
324
+ { name: "io_infer_column", args: "p_organization_id uuid, p_table_id uuid, p_header text, p_samples jsonb DEFAULT '[]'::jsonb", returns: "jsonb", security: "definer" },
267
325
  { name: "io_infer_type", args: "p_samples jsonb", returns: "text", security: "invoker" },
326
+ { name: "io_money_unit", args: "p_word text", returns: "text", security: "invoker" },
268
327
  { name: "io_outbox_announce", args: "", returns: "trigger", security: "definer" },
269
328
  { name: "io_outbox_drain", args: "p_organization_id uuid, p_consumer text, p_limit integer DEFAULT 100, p_event_key text DEFAULT 'records.changed'::text", returns: "TABLE(outbox_id uuid, record_id uuid, table_id uuid, operation text, changed_field_ids jsonb, actor jsonb, occurred_at timestamp with time zone)", security: "definer" },
270
329
  { name: "io_outbox_release", args: "p_organization_id uuid, p_consumer text, p_older_than interval DEFAULT '00:15:00'::interval", returns: "integer", security: "definer" },
271
330
  { name: "io_proposal_accept", args: "p_organization_id uuid, p_import_id uuid, p_column text, p_type text DEFAULT NULL::text, p_label text DEFAULT NULL::text", returns: "uuid", security: "definer" },
272
331
  { name: "io_proposal_reject", args: "p_organization_id uuid, p_import_id uuid, p_column text", returns: "boolean", security: "definer" },
332
+ { name: "io_proposal_spec", args: "p_proposal jsonb", returns: "jsonb", security: "invoker" },
273
333
  { name: "io_record_changed", args: "", returns: "trigger", security: "definer" },
334
+ { name: "io_relation_candidate", args: "p_organization_id uuid, p_table_id uuid, p_words text[]", returns: "uuid", security: "invoker" },
274
335
  { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "integer", security: "definer" },
336
+ { name: "io_restore", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_author jsonb", returns: "integer", security: "definer" },
275
337
  { name: "io_revisions", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(version integer, changed_at timestamp with time zone, changed_by uuid, summary text, operation text, changed_fields jsonb)", security: "definer" },
338
+ { name: "io_sample_words", args: "p_samples jsonb", returns: "TABLE(word text)", security: "invoker" },
339
+ { name: "io_value_shape", args: "p_envelope jsonb", returns: "jsonb", security: "invoker" },
276
340
  { name: "is_a_retirement", args: "p_old_deleted timestamp with time zone, p_new_deleted timestamp with time zone, p_old_data jsonb, p_new_data jsonb, p_old_table uuid, p_new_table uuid, p_old_org uuid, p_new_org uuid, p_old_class text, p_new_class text", returns: "boolean", security: "invoker" },
341
+ { name: "ladder_replanners", args: "p_roots text[] DEFAULT ARRAY['custom.has_visibility'::text, 'custom.effective_level'::text, 'custom.reaches_directly'::text, 'custom.visible_set'::text]", returns: "TABLE(fn text, lang text, why text, remedy text)", security: "definer" },
277
342
  { name: "list_door_disagreements", args: "p_pretend text DEFAULT NULL::text, p_only_organization uuid DEFAULT NULL::uuid, p_sample integer DEFAULT 200", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, table_id uuid, record_id uuid, door text, why text)", security: "invoker" },
278
343
  { name: "list_door_disagreements", args: "p_pretend text, p_only_organization uuid, p_sample integer, p_exhaustive boolean", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, table_id uuid, record_id uuid, door text, why text)", security: "invoker" },
279
344
  { name: "lookup_value", args: "p_organization_id uuid, p_record_id uuid, p_field_data jsonb", returns: "jsonb", security: "invoker" },
280
345
  { name: "mask_document", args: "p_document jsonb, p_visible_keys text[], p_notices jsonb, p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb", returns: "jsonb", security: "invoker" },
281
346
  { name: "mask_document", args: "p_document jsonb, p_visible_keys text[], p_notices jsonb, p_by_id boolean DEFAULT false, p_key_ids jsonb DEFAULT '{}'::jsonb, p_declared_keys text[] DEFAULT NULL::text[]", returns: "jsonb", security: "invoker" },
347
+ { name: "mask_says_withheld", args: "p_mask jsonb, p_key text", returns: "boolean", security: "invoker" },
282
348
  { name: "merge_field_kernel_id", args: "", returns: "uuid", security: "invoker" },
283
349
  { name: "migrate_choice_keys", args: "p_organization_id uuid, p_table_id uuid, p_dry_run boolean DEFAULT false", returns: "jsonb", security: "definer" },
284
350
  { name: "migrate_delete", args: "p_organization_id uuid, p_record_id uuid, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
@@ -294,6 +360,7 @@ var STORE_DOORS = [
294
360
  { name: "migrate_split", args: "p_organization_id uuid, p_record_id uuid, p_moved_keys text[], p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
295
361
  { name: "migrate_undo", args: "p_organization_id uuid, p_log_id uuid", returns: "jsonb", security: "definer" },
296
362
  { name: "migrations", args: "p_organization_id uuid, p_target_id uuid DEFAULT NULL::uuid, p_limit integer DEFAULT 100", returns: "TABLE(id uuid, verb text, target_kind text, target_id uuid, note text, applied_at timestamp with time zone, applied_by uuid, undone_at timestamp with time zone)", security: "definer" },
363
+ { name: "mirror_asks_the_whole_database", args: "", returns: "TABLE(schema_name text, table_name text, policy_name text, why text)", security: "invoker" },
297
364
  { name: "my_level", args: "p_organization_id uuid, p_id uuid, p_type text DEFAULT 'record'::text", returns: "permission_level", security: "definer" },
298
365
  { name: "my_levels", args: "p_organization_id uuid, p_ids jsonb, p_type text DEFAULT 'record'::text", returns: "TABLE(id uuid, level permission_level)", security: "definer" },
299
366
  { name: "organization_clear", args: "p_organization_id uuid, p_confirm text, p_and_destroy boolean DEFAULT false", returns: "jsonb", security: "definer" },
@@ -307,6 +374,7 @@ var STORE_DOORS = [
307
374
  { name: "parity_values", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(field_key text, field_id uuid, parity_type text, behavior text, unit text, format text, value jsonb, value_version integer, actor text, written_at timestamp with time zone)", security: "invoker" },
308
375
  { name: "per_value_access_words", args: "", returns: "text[]", security: "invoker" },
309
376
  { name: "person_kernel_id", args: "", returns: "uuid", security: "invoker" },
377
+ { name: "pin_agent_cells", args: "p_new jsonb, p_old jsonb, p_agent_keys text[]", returns: "jsonb", security: "invoker" },
310
378
  { name: "portal_admits", args: "p_organization_id uuid, p_user_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "definer" },
311
379
  { name: "portal_card", args: "p_organization_id uuid, p_portal_id uuid", returns: "jsonb", security: "definer" },
312
380
  { name: "portal_declare", args: "p_organization_id uuid, p_title text, p_client_table_id uuid, p_tables jsonb, p_portal_id uuid DEFAULT NULL::uuid, p_slug text DEFAULT NULL::text, p_sign_in_method text DEFAULT 'magic_link'::text", returns: "uuid", security: "definer" },
@@ -357,6 +425,7 @@ var STORE_DOORS = [
357
425
  { name: "read_door_granted_ids", args: "p_organization_id uuid, p_table_id uuid", returns: "uuid[]", security: "definer" },
358
426
  { name: "read_door_ladder_ceiling", args: "", returns: "integer", security: "invoker" },
359
427
  { name: "read_door_parity", args: "p_organization_id uuid, p_table_id uuid, p_user uuid, p_required permission_level, p_sample integer", returns: "TABLE(record_id uuid, set_based boolean, per_row boolean, verdict text)", security: "definer" },
428
+ { name: "read_mask", args: "p_organization_id uuid, p_record_id uuid, p_action text DEFAULT 'read'::text", returns: "jsonb", security: "definer" },
360
429
  { name: "read_paths_outside_the_door", args: "", returns: "TABLE(object_name text, why text)", security: "invoker" },
361
430
  { name: "read_record", args: "p_organization_id uuid, p_record_id uuid, p_by_id boolean DEFAULT false", returns: "jsonb", security: "definer" },
362
431
  { name: "read_records", args: "p_organization_id uuid, p_table_id uuid, p_by_id boolean DEFAULT false, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(id uuid, document jsonb, level permission_level)", security: "definer" },
@@ -366,10 +435,15 @@ var STORE_DOORS = [
366
435
  { name: "record_card", args: "p_viewer uuid, p_organization_id uuid, p_record_id uuid", returns: "jsonb", security: "definer" },
367
436
  { name: "record_carrying_edges", args: "p_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(container_id uuid, item_id uuid, edge_role text)", security: "invoker" },
368
437
  { name: "record_delete", args: "p_organization_id uuid, p_record_id uuid", returns: "timestamp with time zone", security: "definer" },
438
+ { name: "record_history", args: "p_organization_id uuid, p_record_id uuid, p_limit integer DEFAULT 200, p_offset integer DEFAULT 0", returns: "TABLE(version integer, occurred_at timestamp with time zone, operation text, operation_label text, actor jsonb, changes jsonb, migration_id uuid, undoable boolean)", security: "definer" },
369
439
  { name: "record_relation_edges", args: "p_organization_id uuid, p_id uuid, p_table_id uuid, p_data_class text, p_data jsonb, p_deleted_at timestamp with time zone", returns: "TABLE(target_id uuid, edge_role text, field_id uuid, ord integer)", security: "invoker" },
370
440
  { name: "record_reparent", args: "p_organization_id uuid, p_record_id uuid, p_parent_id uuid", returns: "void", security: "definer" },
371
441
  { name: "record_resolve", args: "p_organization_id uuid, p_id uuid", returns: "jsonb", security: "definer" },
372
442
  { name: "record_restore", args: "p_organization_id uuid, p_record_id uuid", returns: "void", security: "definer" },
443
+ { name: "record_restore_preview", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_field_key text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
444
+ { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer", returns: "jsonb", security: "definer" },
445
+ { name: "record_restore_version", args: "p_organization_id uuid, p_record_id uuid, p_version integer, p_author jsonb", returns: "jsonb", security: "definer" },
446
+ { name: "record_scope_context", args: "p_organization_id uuid, p_record_id uuid, p_relations integer DEFAULT 12, p_history integer DEFAULT 15, p_siblings integer DEFAULT 8", returns: "jsonb", security: "definer" },
373
447
  { name: "record_state_as_of", args: "p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(state jsonb, replayed boolean)", security: "definer" },
374
448
  { name: "record_table", args: "p_organization_id uuid, p_record_id uuid", returns: "uuid", security: "definer" },
375
449
  { name: "record_update", args: "p_organization_id uuid, p_record_id uuid, p_patch jsonb, p_expected_version integer DEFAULT NULL::integer", returns: "integer", security: "definer" },
@@ -416,12 +490,25 @@ var STORE_DOORS = [
416
490
  { name: "share_revoke", args: "p_organization_id uuid, p_subject_id uuid, p_principal_kind text, p_principal_id uuid", returns: "jsonb", security: "definer" },
417
491
  { name: "share_subject_name", args: "p_organization_id uuid, p_type text, p_id uuid", returns: "text", security: "definer" },
418
492
  { name: "shared_only_disagreements", args: "p_pretend text DEFAULT NULL::text", returns: "TABLE(organization_id uuid, organization_name text, member_id uuid, record_id uuid, table_id uuid, ladder boolean, read_door boolean, rls_mirror boolean, why text)", security: "invoker" },
493
+ { name: "sign_request_cancel", args: "p_organization_id uuid, p_request_id uuid, p_reason text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
494
+ { name: "sign_request_create", args: "p_organization_id uuid, p_render_id uuid, p_field_key text, p_signer_email text, p_signer_name text, p_expires_in interval DEFAULT '14 days'::interval", returns: "jsonb", security: "definer" },
495
+ { name: "sign_request_decline", args: "p_token text, p_reason text DEFAULT NULL::text, p_ip text DEFAULT NULL::text, p_user_agent text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
496
+ { name: "sign_request_public", args: "p_token text, p_origin text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
497
+ { name: "sign_request_remind", args: "p_organization_id uuid, p_request_id uuid", returns: "jsonb", security: "definer" },
498
+ { name: "sign_request_sentence", args: "p_data jsonb", returns: "text", security: "invoker" },
499
+ { name: "sign_request_sign", args: "p_token text, p_signed_name text, p_mark text, p_image text DEFAULT NULL::text, p_ip text DEFAULT NULL::text, p_user_agent text DEFAULT NULL::text, p_origin text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
500
+ { name: "sign_request_state", args: "p_data jsonb", returns: "text", security: "invoker" },
501
+ { name: "sign_request_unchanged", args: "p_organization_id uuid, p_request_id uuid", returns: "boolean", security: "definer" },
502
+ { name: "sign_requests", args: "p_organization_id uuid, p_record_id uuid", returns: "TABLE(request_id uuid, render_id uuid, record_id uuid, field_key text, document_title text, signer_name text, signer_email text, signer_has_account boolean, state text, sentence text, document_version integer, document_hash text, sent_at timestamp with time zone, expires_at timestamp with time zone, viewed_at timestamp with time zone, signed_at timestamp with time zone, declined_at timestamp with time zone, invalidated_at timestamp with time zone, signature_id uuid, signature_mark text, reminder_count integer)", security: "definer" },
503
+ { name: "sign_token_decode", args: "p_token text", returns: "bytea", security: "invoker" },
504
+ { name: "sign_token_encode", args: "p_bytes bytea", returns: "text", security: "invoker" },
419
505
  { name: "size_refusal", args: "p_organization_id uuid, p_data jsonb", returns: "text", security: "invoker" },
420
506
  { name: "source_next_pointer", args: "p_sources jsonb", returns: "text", security: "invoker" },
421
507
  { name: "source_pointer", args: "p_sources jsonb, p_source jsonb", returns: "text", security: "invoker" },
422
508
  { name: "stamp_value_envelopes", args: "p_data jsonb, p_actor text, p_on_behalf_of text, p_at timestamp with time zone", returns: "jsonb", security: "invoker" },
423
509
  { name: "storage_modes", args: "", returns: "text[]", security: "invoker" },
424
510
  { name: "store_is_open", args: "p_organization_id uuid DEFAULT NULL::uuid", returns: "boolean", security: "invoker" },
511
+ { name: "subscription_cadences", args: "p_organization_id uuid", returns: "text[]", security: "definer" },
425
512
  { name: "subscription_mute", args: "p_organization_id uuid, p_rule_id uuid, p_muted boolean DEFAULT true", returns: "boolean", security: "definer" },
426
513
  { name: "subscriptions", args: "p_organization_id uuid, p_table_id uuid DEFAULT NULL::uuid", returns: "TABLE(rule_id uuid, name text, table_id uuid, saved_view_id uuid, cadence text, schedule text, channel text, recipient_user_id uuid, event_key text, muted boolean, mine boolean, i_may_mute boolean)", security: "definer" },
427
514
  { name: "table_capacity", args: "p_organization_id uuid, p_table_id uuid", returns: "jsonb", security: "definer" },
@@ -447,6 +534,8 @@ var STORE_DOORS = [
447
534
  { name: "value_envelope_ok", args: "p_data jsonb", returns: "boolean", security: "invoker" },
448
535
  { name: "value_envelope_refusal", args: "p_data jsonb", returns: "text", security: "invoker" },
449
536
  { name: "value_read", args: "p_organization_id uuid, p_record_id uuid, p_key text", returns: "TABLE(field_key text, field_id uuid, value jsonb, value_version integer, source jsonb, absent_reason text, actor text, on_behalf_of text, written_at timestamp with time zone, alternates jsonb)", security: "definer" },
537
+ { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer", returns: "jsonb", security: "definer" },
538
+ { name: "value_restore", args: "p_organization_id uuid, p_record_id uuid, p_field_key text, p_version integer, p_author jsonb", returns: "jsonb", security: "definer" },
450
539
  { name: "value_versions", args: "p_old jsonb, p_new jsonb", returns: "jsonb", security: "invoker" },
451
540
  { name: "visibility_ancestors", args: "p_item_type text, p_item_id uuid", returns: "TABLE(container_type text, container_id uuid, depth integer, max_level permission_level)", security: "definer" },
452
541
  { name: "visibility_as_of", args: "p_organization_id uuid, p_record_id uuid, p_at timestamp with time zone", returns: "TABLE(principal_kind text, principal_id uuid, level permission_level, through_kind text, through_id uuid, reason text, replayed boolean, held_from timestamp with time zone, held_to timestamp with time zone)", security: "definer" },
@@ -457,6 +546,8 @@ var STORE_DOORS = [
457
546
  { name: "visible_record_ids", args: "p_user_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level", returns: "TABLE(id uuid)", security: "definer" },
458
547
  { name: "visible_set", args: "p_user uuid, p_organization_id uuid, p_table_id uuid, p_required permission_level DEFAULT 'viewer'::permission_level, OUT o_all_visible boolean, OUT o_true_visibility platform.visibility[], OUT o_granted_all uuid[], OUT o_granted_visible uuid[], OUT o_carried_visible uuid[], OUT o_ladder_calls integer, OUT o_fallback boolean, OUT o_note text", returns: "record", security: "definer" },
459
548
  { name: "widget_kernel_id", args: "", returns: "uuid", security: "invoker" },
549
+ { name: "withheld_marker", args: "p_mask jsonb, p_key text", returns: "jsonb", security: "invoker" },
550
+ { name: "withheld_sentence", args: "p_mask jsonb, p_key text", returns: "text", security: "invoker" },
460
551
  { name: "work_approval_approvers", args: "p_organization_id uuid, p_subject_id uuid, p_approver_id uuid DEFAULT NULL::uuid", returns: "TABLE(user_id uuid, name text, why text)", security: "definer" },
461
552
  { name: "work_approval_decide", args: "p_organization_id uuid, p_approval_id uuid, p_approve boolean, p_note text DEFAULT NULL::text", returns: "jsonb", security: "definer" },
462
553
  { name: "work_approval_kinds", args: "", returns: "text[]", security: "invoker" },
@@ -497,6 +588,7 @@ var STORE_KNOBS = [
497
588
  { key: "code_paths_enabled", value: "false", type: "boolean" },
498
589
  { key: "consumer_chat_seeding_enabled", value: "false", type: "boolean" },
499
590
  { key: "consumer_checkout_enabled", value: "false", type: "boolean" },
591
+ { key: "consumer_context_enabled", value: "false", type: "boolean" },
500
592
  { key: "consumer_education_enabled", value: "false", type: "boolean" },
501
593
  { key: "consumer_extension_enabled", value: "false", type: "boolean" },
502
594
  { key: "consumer_grid_enabled", value: "false", type: "boolean" },
@@ -505,14 +597,21 @@ var STORE_KNOBS = [
505
597
  { key: "consumer_scopes_enabled", value: "false", type: "boolean" },
506
598
  { key: "containment_depth_ceiling", value: "16", type: "integer" },
507
599
  { key: "cross_organization_links", value: "false", type: "boolean" },
600
+ { key: "document_letterhead", value: "{}", type: "json" },
508
601
  { key: "document_max_bytes", value: "1048576", type: "integer" },
509
602
  { key: "emergency_door_guard", value: "false", type: "boolean" },
510
603
  { key: "emergency_door_sweep_enabled", value: "false", type: "boolean" },
604
+ { key: "enrichment_batch_ceiling", value: "200", type: "integer" },
605
+ { key: "enrichment_confidence_floor", value: "0.6", type: "number" },
606
+ { key: "enrichment_cost_cap_cents", value: "2000", type: "integer" },
607
+ { key: "enrichment_model", value: '"claude-fable-5-latest"', type: "string" },
608
+ { key: "enrichment_sensitivity_ceiling", value: '"internal"', type: "string" },
511
609
  { key: "entity_custom_fields_guard", value: "false", type: "boolean" },
512
610
  { key: "entity_types_guard", value: "false", type: "boolean" },
513
611
  { key: "external_principal_enabled", value: "false", type: "boolean" },
514
612
  { key: "field_index_guard", value: "false", type: "boolean" },
515
613
  { key: "field_sensitivity_levels", value: '{"edit": {"public": "editor", "internal": "editor", "restricted": "admin", "confidential": "admin"}, "read": {"public": "viewer", "internal": "viewer", "restricted": "admin", "confidential": "editor"}}', type: "json" },
614
+ { key: "inbound_domain", value: '"inbound.matrxserver.com"', type: "string" },
516
615
  { key: "member_default_level", value: '"viewer"', type: "enum" },
517
616
  { key: "member_default_visibility", value: '"all_records"', type: "enum" },
518
617
  { key: "records_tool_default", value: "true", type: "boolean" },
@@ -528,19 +627,20 @@ var STORE_KNOBS = [
528
627
  { key: "world_publish_enabled", value: "false", type: "boolean" }
529
628
  ];
530
629
  var STORE_REFUSAL_CODES = [
531
- { code: "02000", raised_by: "dashboard_delete,dashboard_run,doc_render_body,doc_render_document,doc_render_read,doc_sign,doc_signature_intact,doc_signature_read,doc_template_read,doc_template_save,entity_field_retire,entity_field_update,entity_record_read,entity_value_write,external_history_event,external_rows,external_stub_upsert,external_writes_set,migrate_delete,migrate_extract_parent,migrate_merge,migrate_reclass,migrate_rename,migrate_reparent,migrate_retype,migrate_split,migrate_undo,organization_clear,portal_card,portal_declare,portal_invite,portal_preview,portal_principal_bind,portal_revoke,read_record,record_delete,record_restore,record_table,record_update,relation_uncarry,share_access,share_grant,share_lane_set,share_people,share_revoke,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_assign,work_record_states,work_set_state" },
532
- { code: "0A000", raised_by: "external_rows,external_source_declare,external_write_through,promote_field,promoted_index_expr,promoted_query_sql,promoted_read,rule_eval,work_assign" },
533
- { code: "22004", raised_by: "_entity_custom_fields_guard,_value_envelope,actor_word,agg_assert_key,agg_sql,anon_capture,anon_token_issue,anon_write,assert_client_may_reach,dashboard_block_normalize,dashboard_declare,dashboard_window_sql,doc_render_write,doc_sign,doc_signature_write,doc_template_save,external_history_event,external_rows,external_source_declare,external_stub_upsert,external_write_through,external_writes_set,form_declare,form_submit,home_add,io_comment_write,io_import_open,io_outbox_drain,io_restore,migrate_choice_keys,migrate_purge,migrate_reclass,migrate_split,migrate_undo,organization_clear,organization_contents,portal_declare,portal_invite,portal_principal_bind,query_across_homes,query_by_coordinates,query_rollup,record_delete,record_reparent,record_resolve,record_restore,record_update,record_write,relation_carry,relation_own,rule_declare,share_grant,table_declare,work_approval_decide,work_approval_request,work_template_declare" },
630
+ { code: "02000", raised_by: "_checklist_instantiate,checklist_declare,checklist_run,checklist_step_complete,checklist_step_refusal,checklist_template_shape,conversation_scope_bind,dashboard_delete,dashboard_run,doc_letterhead,doc_render_body,doc_render_document,doc_render_read,doc_sign,doc_signature_intact,doc_signature_read,doc_template_delete,doc_template_read,doc_template_save,enrich_pin,entity_field_retire,entity_field_update,entity_record_read,entity_value_write,external_history_event,external_rows,external_stub_upsert,external_writes_set,io_restore,migrate_delete,migrate_extract_parent,migrate_merge,migrate_reclass,migrate_rename,migrate_reparent,migrate_retype,migrate_split,migrate_undo,organization_clear,portal_card,portal_declare,portal_invite,portal_preview,portal_principal_bind,portal_revoke,read_record,record_delete,record_restore,record_restore_preview,record_table,record_update,relation_uncarry,share_access,share_grant,share_lane_set,share_people,share_revoke,sign_request_cancel,sign_request_create,sign_request_remind,sign_request_unchanged,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_assign,work_record_states,work_set_state" },
631
+ { code: "0A000", raised_by: "checklist_step_complete,external_rows,external_source_declare,external_write_through,promote_field,promoted_index_expr,promoted_query_sql,promoted_read,rule_eval,work_assign" },
632
+ { code: "22003", raised_by: "context_resolve" },
633
+ { code: "22004", raised_by: "_entity_custom_fields_guard,_value_envelope,actor_word,agg_assert_key,agg_sql,anon_capture,anon_token_issue,anon_write,assert_client_may_reach,checklist_declare,context_resolve,dashboard_block_normalize,dashboard_declare,dashboard_window_sql,doc_render_write,doc_sign,doc_signature_write,doc_template_save,enrich_land,enrich_normalize,external_history_event,external_rows,external_source_declare,external_stub_upsert,external_write_through,external_writes_set,field_history,form_declare,form_submit,home_add,io_comment_write,io_import_begin,io_infer_column,io_outbox_drain,io_restore,migrate_choice_keys,migrate_purge,migrate_reclass,migrate_split,migrate_undo,organization_clear,organization_contents,portal_declare,portal_invite,portal_principal_bind,query_across_homes,query_by_coordinates,query_rollup,record_delete,record_reparent,record_resolve,record_restore,record_update,record_write,relation_carry,relation_own,rule_declare,share_grant,sign_request_create,sign_request_sign,table_declare,value_restore,work_approval_decide,work_approval_request,work_template_declare" },
534
634
  { code: "22007", raised_by: "dashboard_window_sql" },
535
635
  { code: "22012", raised_by: "rule_eval" },
536
- { code: "22023", raised_by: "_entity_custom_fields_guard,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,io_import_open,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,portal_declare,query_by_coordinates,query_rollup,record_update,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
537
- { code: "23503", raised_by: "_containment_guard,_field_document_for,_record_rule_uses,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,dashboard_declare,delete_rule,doc_sign,doc_template_save,form_declare,form_submit,home_add,io_comment_write,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,promote_field,promote_table,record_applicability,record_reparent,relation_carry,relation_own,resolve_first_match,rule_applies,rule_declare,rule_eval,rule_members,rule_run,subscription_mute,work_set_state,work_take_assignment,work_template_instantiate" },
538
- { code: "23505", raised_by: "_unique_rule_holds,doc_sign,doc_signature_write,entity_field_declare,field_declare,home_add,io_proposal_accept,relation_carry,relation_own,share_grant,work_approval_decide,work_slot_hold" },
539
- { code: "23514", raised_by: "_containment_guard,_dated_values_guard,_derived_fields,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_shape_guard,_value_envelope,_work_shape_guard,_workdoors_approval_guard,assert_entity_is_organization_scoped,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,migrate_merge,relation_carry,relation_own,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
636
+ { code: "22023", raised_by: "_entity_custom_fields_guard,_value_envelope,_work_shape_guard,actor_word,agg_assert_key,agg_sql,anon_token_issue,containment_parent,dashboard_block_normalize,dashboard_window_sql,doc_render_body,doc_render_write,doc_signature_write,enrich_declare,enrich_land,enrich_normalize,enrich_pin,entity_value_write,external_history_event,external_source_declare,external_stub_upsert,external_write_through,field_history,io_import_begin,io_import_finish,io_import_plan,io_import_report,io_proposal_accept,migrate_merge,migrate_reclass,my_levels,organization_clear,pin_agent_cells,portal_declare,query_by_coordinates,query_rollup,record_update,relation_carry,rule_eval,rule_members,share_grant,share_lane_set,sign_request_create,sign_request_sign,table_rules,visibility_as_of,work_approval_request,work_list,work_slot_hold" },
637
+ { code: "23503", raised_by: "_checklist_instantiate,_containment_guard,_field_document_for,_record_rule_uses,anon_publish,anon_rate_take,anon_token_issue,anon_write,assert_organization_wall,checklist_declare,checklist_steps_table,comment_write,dashboard_declare,delete_rule,doc_sign,doc_template_save,enrich_declare,enrich_due,enrich_land,form_declare,form_submit,home_add,inbound_declare,inbound_mail_land,inbound_set,io_comment_write,io_import_begin,io_import_finish,io_import_report,io_import_rows,io_proposal_accept,migrate_demote,migrate_promote,promote_field,promote_table,record_applicability,record_reparent,relation_carry,relation_own,resolve_first_match,rule_applies,rule_declare,rule_eval,rule_members,rule_run,sign_request_create,subscription_mute,work_set_state,work_take_assignment,work_template_instantiate" },
638
+ { code: "23505", raised_by: "_unique_rule_holds,doc_sign,doc_signature_write,entity_field_declare,field_declare,home_add,inbound_declare,io_proposal_accept,relation_carry,relation_own,share_grant,sign_request_cancel,sign_request_create,work_approval_decide,work_slot_hold" },
639
+ { code: "23514", raised_by: "_checklist_instantiate,_checklist_step_guard,_containment_guard,_dated_values_guard,_derived_fields,_entity_custom_fields_guard,_field_class_guard,_field_document_for,_field_shape_guard,_field_type_parity_guard,_merge_field_shape_guard,_merge_field_temporal_guard,_promoted_field_cap_guard,_record_rule_uses,_resolve_choice_words,_rule_shape_guard,_rule_topology_guard,_store_relation_edge_names_its_field,_table_shape_guard,_value_envelope,_work_shape_guard,_workdoors_approval_guard,assert_entity_is_organization_scoped,checklist_declare,checklist_step_complete,doc_sign,doc_signature_write,doc_template_save,entity_field_declare,entity_field_retire,entity_field_update,entity_records_find,entity_table,field_declare,field_retire,field_update,home_add,io_import_rows,migrate_merge,relation_carry,relation_own,sign_request_create,sign_request_sign,validate_value_envelope,validate_values,work_set_state,work_slots_declare,work_take_assignment,work_template_instantiate" },
540
640
  { code: "40001", raised_by: "has_visibility_at" },
541
- { code: "42501", raised_by: "_doc_render_immutable,_doc_signature_immutable,_field_definition_write,_field_write_door,_rule_definition_write,_store_door,anon_capture,anon_inbound_land,anon_publish,anon_token_issue,anon_token_verify,anon_write,assert_client_may_change,assert_client_may_open,assert_client_may_reach,assert_may_know_table,assert_organization_admin,assert_store_door,entity_field_declare,entity_field_retire,entity_field_update,entity_value_write,external_write_through,form_declare,form_submit,io_comment_resolve,io_comment_write,io_restore,migrate_purge,migrate_reclass,my_levels,organization_clear,portal_declare,portal_invitation,portal_invite,portal_principal_bind,promote_table,query_visibility_parity,read_record,read_records,share_grant,subscription_mute,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
641
+ { code: "42501", raised_by: "_doc_render_immutable,_doc_signature_immutable,_field_definition_write,_field_write_door,_rule_definition_write,_store_door,anon_capture,anon_inbound_land,anon_publish,anon_token_issue,anon_token_verify,anon_write,assert_client_may_change,assert_client_may_open,assert_client_may_reach,assert_may_know_table,assert_organization_admin,assert_store_door,checklist_run,comment_write,conversation_scope_bind,conversation_scope_unbind,enrich_declare,enrich_due,enrich_land,enrich_normalize,entity_field_declare,entity_field_retire,entity_field_update,entity_value_write,external_write_through,form_declare,form_submit,inbound_mail_land,io_comment_resolve,io_comment_write,io_import_begin,io_import_finish,io_restore,migrate_purge,migrate_reclass,my_levels,organization_clear,portal_declare,portal_invitation,portal_invite,portal_principal_bind,promote_table,query_visibility_parity,read_record,read_records,record_table,share_grant,subscription_mute,visibility_as_of,work_approval_decide,work_approval_read,work_approval_request,work_person" },
542
642
  { code: "42703", raised_by: "entity_table,portal_declare" },
543
- { code: "53400", raised_by: "anon_rate_take,delete_cascade_closure,promote_field" },
643
+ { code: "53400", raised_by: "anon_rate_take,delete_cascade_closure,enrich_due,enrich_land,promote_field" },
544
644
  { code: "54001", raised_by: "record_delete" },
545
645
  { code: "PT409", raised_by: "record_update" }
546
646
  ];
@@ -1715,6 +1815,30 @@ var DOORS = {
1715
1815
  // are server-lane doors and a browser never calls them.
1716
1816
  forms: "forms",
1717
1817
  formDeclare: "form_declare",
1818
+ // PRODUCTS row 9 — "pull my spreadsheet in". W4-IO built `io_import_open` and
1819
+ // `io_import_rows`; lane IMPORT gave a run an IDENTITY (the file's sha-256, so
1820
+ // a re-import doubles nothing), a duplicate key, a policy, per-row outcomes
1821
+ // with the source row on them, and the type inference that reads THIS
1822
+ // organization — an address that belongs to a member is a person, a few
1823
+ // repeating words are a dropdown, a column of names that are all records of
1824
+ // another Table points at it. `importOpen` (the older, narrower way in) is
1825
+ // deliberately absent from this catalogue: `importBegin` is a superset and two
1826
+ // ways to start an import from one client is how they drift.
1827
+ importPlan: "io_import_plan",
1828
+ importBegin: "io_import_begin",
1829
+ importRows: "io_import_rows",
1830
+ importFinish: "io_import_finish",
1831
+ importReport: "io_import_report",
1832
+ imports: "io_imports",
1833
+ importForget: "io_import_forget",
1834
+ inferColumn: "io_infer_column",
1835
+ // DOOR-19 (P8) — the address a Table owns. `inboundMailLand` is deliberately
1836
+ // absent: it is the mail gateway's door, granted to `service_role` alone and
1837
+ // declared `non_client_lane`, and a browser that could land mail at an
1838
+ // arbitrary address would be writing into any table of any organization.
1839
+ inboundDeclare: "inbound_declare",
1840
+ inboundAddresses: "inbound_addresses",
1841
+ inboundSet: "inbound_set",
1718
1842
  // THE CLIENT PORTAL, OWNER'S SIDE (VIS-31 / PORTAL). A portal is how somebody
1719
1843
  // with NO membership is let in to see the records that name them. `portals`
1720
1844
  // lists them, `portalCard` opens one, `portalDeclare` states what it exposes,
@@ -1741,6 +1865,41 @@ var DOORS = {
1741
1865
  dashboardRun: "dashboard_run",
1742
1866
  dashboardStuck: "dashboard_stuck",
1743
1867
  dashboardDelete: "dashboard_delete",
1868
+ // PRODUCTS row 4 — "Who changed this price, and can I put it back?" The
1869
+ // history has been in the store since W3-HIST; until 2026-09-20 the only way
1870
+ // to ask for it was `io_revisions`, which answers a raw uuid for the author
1871
+ // and a list of KEYS for what moved. `recordHistory` answers the person (or
1872
+ // the agent AND the person it acted for), the operation in the word somebody
1873
+ // used, and every field with its before, its after, the Rule version that
1874
+ // produced it and its source. `fieldHistory` is the other half nobody ships:
1875
+ // one column's history across the whole Table.
1876
+ recordHistory: "record_history",
1877
+ fieldHistory: "field_history",
1878
+ // THE PUT-IT-BACK THREE. `restorePreview` names what will change BEFORE it
1879
+ // does; `restoreVersion` puts the whole record back and `valueRestore` puts
1880
+ // one column back (HIS-N-2). All three write a NEW version through the
1881
+ // record's own write path — no stored version is ever altered.
1882
+ restorePreview: "record_restore_preview",
1883
+ restoreVersion: "record_restore_version",
1884
+ valueRestore: "value_restore",
1885
+ // SCR-18. The store has had comment doors at the `commenter` rung all along;
1886
+ // these two add the people's NAMES and a mention that reaches somebody.
1887
+ // AGT-N-9 / PRODUCTS row 11 — "What's the history with this customer?" A
1888
+ // conversation can be ABOUT one record, and `recordScopeContext` is the ONE
1889
+ // door that answers everything such a chat is allowed to know in a single
1890
+ // round trip: the Fields with their (record, field, value version) triples,
1891
+ // the relations one hop out, the history, the comments and the Table's other
1892
+ // records — every piece assembled INSIDE the database through the read door
1893
+ // under this person's own field-level security. A Field the store masks is
1894
+ // named as withheld with the store's reason and never valued.
1895
+ recordScopeContext: "record_scope_context",
1896
+ conversationScope: "conversation_scope",
1897
+ conversationScopeBind: "conversation_scope_bind",
1898
+ conversationScopeUnbind: "conversation_scope_unbind",
1899
+ conversationScopeContext: "conversation_scope_context",
1900
+ commentThread: "comment_thread",
1901
+ commentWrite: "comment_write",
1902
+ commentResolve: "io_comment_resolve",
1744
1903
  // The eighth verb (AGT-N-8): a grouped, bucketed, filtered count/sum/avg/
1745
1904
  // min/max computed INSIDE the read door's own query, so a chart shows exactly
1746
1905
  // the rows this person may see and never fetches the ones they may not.
@@ -1757,6 +1916,10 @@ var DOORS = {
1757
1916
  // these rows, so "tell me when a patient arrives" can also be un-told.
1758
1917
  subscriptions: "subscriptions",
1759
1918
  subscriptionMute: "subscription_mute",
1919
+ // The cadence CATALOGUE a person's screen may ask for. `agg_subscription_cadences`
1920
+ // above is the notifier's own and holds no client grant; this door delegates to
1921
+ // it, so a picker and the digest runner can never offer different words.
1922
+ subscriptionCadences: "subscription_cadences",
1760
1923
  // The doc doors: a template is saved, a render is written once and frozen,
1761
1924
  // and a signature is checked against the exact bytes that were signed.
1762
1925
  docTemplateSave: "doc_template_save",
@@ -1766,6 +1929,15 @@ var DOORS = {
1766
1929
  docUnresolvedTokens: "doc_unresolved_tokens",
1767
1930
  docSign: "doc_sign",
1768
1931
  docSignatureIntact: "doc_signature_intact",
1932
+ // THE PLURAL ACTS. Until 2026-09-20 this package read `custom.doc_template`,
1933
+ // `custom.doc_render` and `custom.doc_signature` with a direct PostgREST
1934
+ // `.from()`, and all three hold NO client SELECT — so every list in product #5
1935
+ // opened on "permission denied for view doc_template". A list is a DOOR, never
1936
+ // a grant on the thing behind it (DOORS-TWO).
1937
+ docTemplates: "doc_templates",
1938
+ docTemplateDelete: "doc_template_delete",
1939
+ docRenders: "doc_renders",
1940
+ docSignatures: "doc_signatures",
1769
1941
  // THE ANONYMOUS LANE (W4-ANON). It landed, and it landed as SEVEN doors
1770
1942
  // rather than the one this package had guessed at: a token is issued and
1771
1943
  // verified separately from the write it authorises, a form is published
@@ -1861,6 +2033,15 @@ var BY_SQLSTATE = {
1861
2033
  // live-door census caught it — the same way 42703 arrived, which is the
1862
2034
  // census working rather than a guess.
1863
2035
  "22007": "invalid_argument",
2036
+ // 22003 — a number the store could not hold at the size it was handed. It is
2037
+ // raised by `custom.context_resolve`, which is given a window or a depth a
2038
+ // caller wrote, so the class is the same one 22P02, 42703 and 22007 already
2039
+ // are: the CALL named a value the shape does not accept, and the store's own
2040
+ // sentence names the number and the range. Added 2026-09-20 (lane GRID-TWO)
2041
+ // when the live-door census caught the release gate red on it — which is the
2042
+ // census working, and the fourth time it has been the thing that found a new
2043
+ // refusal class rather than a person guessing one.
2044
+ "22003": "invalid_argument",
1864
2045
  "02000": "not_found",
1865
2046
  "23503": "missing_reference",
1866
2047
  "23505": "already_exists",
@@ -2408,6 +2589,98 @@ function createRecordsClient(config) {
2408
2589
  "formDeclare"
2409
2590
  );
2410
2591
  },
2592
+ async importPlan(args) {
2593
+ return callDoor(
2594
+ DOORS.importPlan,
2595
+ { p_organization_id: org, p_table_id: args.table_id, p_columns: args.columns },
2596
+ "importPlan"
2597
+ );
2598
+ },
2599
+ async importBegin(args) {
2600
+ return callDoor(
2601
+ DOORS.importBegin,
2602
+ {
2603
+ p_organization_id: org,
2604
+ p_table_id: args.table_id,
2605
+ p_format: args.format ?? "csv",
2606
+ p_source_name: args.source_name ?? null,
2607
+ p_source_columns: args.source_columns ?? [],
2608
+ p_file_hash: args.file_hash ?? null,
2609
+ p_policy: args.policy ?? {},
2610
+ p_dedupe_key: args.dedupe_key ?? null,
2611
+ p_file_bytes: args.file_bytes ?? null,
2612
+ p_force: args.force ?? false
2613
+ },
2614
+ "importBegin"
2615
+ );
2616
+ },
2617
+ async importRows(args) {
2618
+ return callDoor(
2619
+ DOORS.importRows,
2620
+ {
2621
+ p_organization_id: org,
2622
+ p_import_id: args.import_id,
2623
+ p_rows: args.rows,
2624
+ p_mapping: args.mapping ?? {}
2625
+ },
2626
+ "importRows"
2627
+ );
2628
+ },
2629
+ async importFinish(args) {
2630
+ return callDoor(
2631
+ DOORS.importFinish,
2632
+ { p_organization_id: org, p_import_id: args.import_id, p_unmapped: args.unmapped ?? null },
2633
+ "importFinish"
2634
+ );
2635
+ },
2636
+ async importReport(args) {
2637
+ return callDoor(
2638
+ DOORS.importReport,
2639
+ {
2640
+ p_organization_id: org,
2641
+ p_import_id: args.import_id,
2642
+ p_state: args.state ?? "refused",
2643
+ p_limit: args.limit ?? 100,
2644
+ p_offset: args.offset ?? 0
2645
+ },
2646
+ "importReport"
2647
+ );
2648
+ },
2649
+ async imports(args) {
2650
+ return callDoor(
2651
+ DOORS.imports,
2652
+ { p_organization_id: org, p_table_id: args?.table_id ?? null, p_limit: args?.limit ?? 25 },
2653
+ "imports"
2654
+ );
2655
+ },
2656
+ async importForget(args) {
2657
+ return callDoor(
2658
+ DOORS.importForget,
2659
+ { p_organization_id: org, p_import_id: args.import_id },
2660
+ "importForget"
2661
+ );
2662
+ },
2663
+ async inboundDeclare(args) {
2664
+ return callDoor(
2665
+ DOORS.inboundDeclare,
2666
+ { p_organization_id: org, p_table_id: args.table_id, p_label: args.label ?? null },
2667
+ "inboundDeclare"
2668
+ );
2669
+ },
2670
+ async inboundAddresses(args) {
2671
+ return callDoor(
2672
+ DOORS.inboundAddresses,
2673
+ { p_organization_id: org, p_table_id: args?.table_id ?? null },
2674
+ "inboundAddresses"
2675
+ );
2676
+ },
2677
+ async inboundSet(args) {
2678
+ return callDoor(
2679
+ DOORS.inboundSet,
2680
+ { p_organization_id: org, p_inbound_id: args.inbound_id, p_enabled: args.enabled },
2681
+ "inboundSet"
2682
+ );
2683
+ },
2411
2684
  async portals() {
2412
2685
  return callDoor(DOORS.portals, { p_organization_id: org }, "portals");
2413
2686
  },
@@ -2575,6 +2848,13 @@ function createRecordsClient(config) {
2575
2848
  async aggSubscriptionCadences() {
2576
2849
  return callDoor(DOORS.aggSubscriptionCadences, {}, "aggSubscriptionCadences");
2577
2850
  },
2851
+ async subscriptionCadences() {
2852
+ return callDoor(
2853
+ DOORS.subscriptionCadences,
2854
+ { p_organization_id: org },
2855
+ "subscriptionCadences"
2856
+ );
2857
+ },
2578
2858
  async subscriptions(args) {
2579
2859
  return callDoor(
2580
2860
  DOORS.subscriptions,
@@ -2639,32 +2919,52 @@ function createRecordsClient(config) {
2639
2919
  "docSign"
2640
2920
  );
2641
2921
  },
2922
+ // A LIST IS A DOOR, NEVER A GRANT ON THE THING BEHIND IT. These three used to
2923
+ // read `custom.doc_template`, `custom.doc_render` and `custom.doc_signature`
2924
+ // with a direct PostgREST `.from()`, and none of the three holds a client
2925
+ // SELECT — so a person could save a template they could never list and
2926
+ // render a document they could never find again, and every document screen
2927
+ // opened on "permission denied for view doc_template". The doors below
2928
+ // narrow inside the definer, after the ladder has spoken (DOORS-TWO).
2642
2929
  async docTemplates({ table_id }) {
2643
- const response = await config.dataSource.schema(schema).from("doc_template").select("*").eq("organization_id", org).eq("renders_table_id", table_id).order("name");
2644
- if (response.error) {
2645
- const refusal = mapPgError(response.error, "docTemplates");
2646
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where: "docTemplates" });
2647
- return err(refusal);
2648
- }
2649
- return ok(response.data ?? []);
2930
+ const answered = await callDoor(
2931
+ DOORS.docTemplates,
2932
+ { p_organization_id: org, p_table_id: table_id },
2933
+ "docTemplates"
2934
+ );
2935
+ if (!answered.ok) return answered;
2936
+ return ok(
2937
+ answered.data.map((row) => ({ ...row, id: row["template_id"] }))
2938
+ );
2939
+ },
2940
+ async docTemplateDelete({ template_id }) {
2941
+ return callDoor(
2942
+ DOORS.docTemplateDelete,
2943
+ { p_organization_id: org, p_template_id: template_id },
2944
+ "docTemplateDelete"
2945
+ );
2650
2946
  },
2651
2947
  async docRenders({ record_id }) {
2652
- const response = await config.dataSource.schema(schema).from("doc_render").select("*").eq("organization_id", org).eq("record_id", record_id).is("deleted_at", null).order("rendered_at", { ascending: false });
2653
- if (response.error) {
2654
- const refusal = mapPgError(response.error, "docRenders");
2655
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where: "docRenders" });
2656
- return err(refusal);
2657
- }
2658
- return ok(response.data ?? []);
2948
+ const answered = await callDoor(
2949
+ DOORS.docRenders,
2950
+ { p_organization_id: org, p_record_id: record_id },
2951
+ "docRenders"
2952
+ );
2953
+ if (!answered.ok) return answered;
2954
+ return ok(
2955
+ answered.data.map((row) => ({ ...row, id: row["render_id"] }))
2956
+ );
2659
2957
  },
2660
2958
  async docSignatures({ record_id }) {
2661
- const response = await config.dataSource.schema(schema).from("doc_signature").select("*").eq("organization_id", org).eq("record_id", record_id).is("deleted_at", null).order("signed_at", { ascending: false });
2662
- if (response.error) {
2663
- const refusal = mapPgError(response.error, "docSignatures");
2664
- scream({ code: refusal.code, message: refusal.message, ...refusal.hint ? { hint: refusal.hint } : {}, where: "docSignatures" });
2665
- return err(refusal);
2666
- }
2667
- return ok(response.data ?? []);
2959
+ const answered = await callDoor(
2960
+ DOORS.docSignatures,
2961
+ { p_organization_id: org, p_record_id: record_id },
2962
+ "docSignatures"
2963
+ );
2964
+ if (!answered.ok) return answered;
2965
+ return ok(
2966
+ answered.data.map((row) => ({ ...row, id: row["signature_id"] }))
2967
+ );
2668
2968
  },
2669
2969
  async recordValuesVersioned({ record_id }) {
2670
2970
  return readValues(record_id);
@@ -2676,6 +2976,152 @@ function createRecordsClient(config) {
2676
2976
  "revisions"
2677
2977
  );
2678
2978
  },
2979
+ async recordScopeContext({ record_id, relations, history, siblings }) {
2980
+ return callDoor(
2981
+ DOORS.recordScopeContext,
2982
+ {
2983
+ p_organization_id: org,
2984
+ p_record_id: record_id,
2985
+ p_relations: relations ?? 12,
2986
+ p_history: history ?? 15,
2987
+ p_siblings: siblings ?? 8
2988
+ },
2989
+ "recordScopeContext"
2990
+ );
2991
+ },
2992
+ async conversationScope({ conversation_id }) {
2993
+ return callDoor(
2994
+ DOORS.conversationScope,
2995
+ { p_organization_id: org, p_conversation_id: conversation_id },
2996
+ "conversationScope"
2997
+ );
2998
+ },
2999
+ async conversationScopeBind({ conversation_id, record_id }) {
3000
+ return callDoor(
3001
+ DOORS.conversationScopeBind,
3002
+ {
3003
+ p_organization_id: org,
3004
+ p_conversation_id: conversation_id,
3005
+ p_record_id: record_id
3006
+ },
3007
+ "conversationScopeBind"
3008
+ );
3009
+ },
3010
+ async conversationScopeUnbind({ conversation_id }) {
3011
+ return callDoor(
3012
+ DOORS.conversationScopeUnbind,
3013
+ { p_organization_id: org, p_conversation_id: conversation_id },
3014
+ "conversationScopeUnbind"
3015
+ );
3016
+ },
3017
+ async conversationScopeContext({ conversation_id, relations, history, siblings }) {
3018
+ return callDoor(
3019
+ DOORS.conversationScopeContext,
3020
+ {
3021
+ p_organization_id: org,
3022
+ p_conversation_id: conversation_id,
3023
+ p_relations: relations ?? 12,
3024
+ p_history: history ?? 15,
3025
+ p_siblings: siblings ?? 8
3026
+ },
3027
+ "conversationScopeContext"
3028
+ );
3029
+ },
3030
+ async recordHistory({ record_id, limit, offset }) {
3031
+ return callDoor(
3032
+ DOORS.recordHistory,
3033
+ {
3034
+ p_organization_id: org,
3035
+ p_record_id: record_id,
3036
+ p_limit: limit ?? 200,
3037
+ p_offset: offset ?? 0
3038
+ },
3039
+ "recordHistory"
3040
+ );
3041
+ },
3042
+ async fieldHistory({ table_id, field_key, limit, offset, record_id }) {
3043
+ return callDoor(
3044
+ DOORS.fieldHistory,
3045
+ {
3046
+ p_organization_id: org,
3047
+ p_table_id: table_id,
3048
+ p_field_key: field_key,
3049
+ p_limit: limit ?? 100,
3050
+ p_offset: offset ?? 0,
3051
+ p_record_id: record_id ?? null
3052
+ },
3053
+ "fieldHistory"
3054
+ );
3055
+ },
3056
+ async restorePreview({ record_id, version, field_key }) {
3057
+ return callDoor(
3058
+ DOORS.restorePreview,
3059
+ {
3060
+ p_organization_id: org,
3061
+ p_record_id: record_id,
3062
+ p_version: version,
3063
+ p_field_key: field_key ?? null
3064
+ },
3065
+ "restorePreview"
3066
+ );
3067
+ },
3068
+ async restoreVersion({ record_id, version }) {
3069
+ return callDoor(
3070
+ DOORS.restoreVersion,
3071
+ { p_organization_id: org, p_record_id: record_id, p_version: version },
3072
+ "restoreVersion"
3073
+ );
3074
+ },
3075
+ async valueRestore({ record_id, field_key, version }) {
3076
+ return callDoor(
3077
+ DOORS.valueRestore,
3078
+ {
3079
+ p_organization_id: org,
3080
+ p_record_id: record_id,
3081
+ p_field_key: field_key,
3082
+ p_version: version
3083
+ },
3084
+ "valueRestore"
3085
+ );
3086
+ },
3087
+ async commentThread({ record_id, include_resolved }) {
3088
+ return callDoor(
3089
+ DOORS.commentThread,
3090
+ {
3091
+ p_organization_id: org,
3092
+ p_record_id: record_id,
3093
+ p_include_resolved: include_resolved ?? false
3094
+ },
3095
+ "commentThread"
3096
+ );
3097
+ },
3098
+ async commentWrite({ record_id, body, field_key, parent_comment_id, mentions }) {
3099
+ return callDoor(
3100
+ DOORS.commentWrite,
3101
+ {
3102
+ p_organization_id: org,
3103
+ p_record_id: record_id,
3104
+ p_body: body,
3105
+ // THE ANCHOR IS WHERE A FIELD COMMENT LIVES. `custom.io_comment` has
3106
+ // always carried it; nothing was ever putting a Field in it.
3107
+ p_anchor: field_key ? { field_key } : {},
3108
+ p_parent_comment_id: parent_comment_id ?? null,
3109
+ p_mentions: mentions && mentions.length > 0 ? mentions : null
3110
+ },
3111
+ "commentWrite"
3112
+ );
3113
+ },
3114
+ async commentResolve({ comment_id, resolved }) {
3115
+ return callDoor(
3116
+ DOORS.commentResolve,
3117
+ {
3118
+ p_organization_id: org,
3119
+ p_comment_id: comment_id,
3120
+ p_resolved: resolved ?? true
3121
+ },
3122
+ "commentResolve"
3123
+ );
3124
+ },
2679
3125
  async docSignatureIntact({ signature_id }) {
2680
3126
  return callDoor(
2681
3127
  DOORS.docSignatureIntact,
@@ -3577,6 +4023,11 @@ function portalPath(slug) {
3577
4023
  function measureKey(measure) {
3578
4024
  return measure.op === "count" ? "count" : `${measure.op}_${measure.key ?? ""}`;
3579
4025
  }
4026
+
4027
+ // src/record-scope.ts
4028
+ function scopeChip(scope) {
4029
+ return scope.title ? `About: ${scope.title}` : "About: this record";
4030
+ }
3580
4031
  export {
3581
4032
  ABSENCE_REASONS,
3582
4033
  ACTOR_VOCABULARY,
@@ -3629,6 +4080,7 @@ export {
3629
4080
  optionLabel,
3630
4081
  portalPath,
3631
4082
  publicFormPath,
4083
+ scopeChip,
3632
4084
  useEntityFieldMutation,
3633
4085
  useEntityFieldRights,
3634
4086
  useEntityFields,