better-supabase 0.38.0 → 0.40.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.
Files changed (156) hide show
  1. package/dist/ai-sdk/agents/index.d.ts +2 -2
  2. package/dist/{app-tables-D2c0i05-.d.ts → app-tables-jaQmdgAM.d.ts} +1 -1
  3. package/dist/{authorization-D8CaAdqU.d.ts → authorization-Ul_ApMYW.d.ts} +41 -2
  4. package/dist/{bind-5vOwNouG.d.ts → bind-B2GlypM6.d.ts} +1 -1
  5. package/dist/{block-env-hco8BLjC.d.ts → block-env-Bcr-jEA1.d.ts} +3 -3
  6. package/dist/{block-subjects-CINiJW1R.js → block-subjects-BumEsEYb.js} +17 -6
  7. package/dist/{block-tables-BsgdB6VG.d.ts → block-tables-nkIjJ1ly.d.ts} +1 -1
  8. package/dist/blocks/ai-chat/index.d.ts +3 -3
  9. package/dist/blocks/announcements/index.d.ts +3 -3
  10. package/dist/blocks/api-keys/index.d.ts +1 -1
  11. package/dist/blocks/attachments/index.d.ts +1 -1
  12. package/dist/blocks/audit/index.d.ts +2 -2
  13. package/dist/blocks/automations/index.d.ts +1 -1
  14. package/dist/blocks/billing/index.d.ts +1 -1
  15. package/dist/blocks/bookings/index.d.ts +1 -1
  16. package/dist/blocks/calendar/index.d.ts +1 -1
  17. package/dist/blocks/catalog/index.d.ts +25 -5
  18. package/dist/blocks/catalog/index.js +32 -9
  19. package/dist/blocks/comments/index.d.ts +4 -4
  20. package/dist/blocks/entitlements/index.d.ts +2 -2
  21. package/dist/blocks/expenses/index.js +1 -1
  22. package/dist/blocks/forms/index.d.ts +1 -1
  23. package/dist/blocks/inbox/index.d.ts +4 -4
  24. package/dist/blocks/index.d.ts +1 -1
  25. package/dist/blocks/invoices/index.d.ts +1 -0
  26. package/dist/blocks/invoices/index.js +18 -10
  27. package/dist/blocks/leave/index.d.ts +35 -1
  28. package/dist/blocks/leave/index.js +17 -2
  29. package/dist/blocks/ledger/index.d.ts +1 -0
  30. package/dist/blocks/ledger/index.js +2 -1
  31. package/dist/blocks/messaging/index.d.ts +4 -4
  32. package/dist/blocks/mfa/index.d.ts +1 -1
  33. package/dist/blocks/notifications/index.d.ts +3 -3
  34. package/dist/blocks/onboarding/index.d.ts +1 -1
  35. package/dist/blocks/organizations/index.d.ts +2 -2
  36. package/dist/blocks/permissions/index.d.ts +1 -1
  37. package/dist/blocks/push/index.d.ts +1 -1
  38. package/dist/blocks/reactions/index.d.ts +3 -3
  39. package/dist/blocks/saved-views/index.d.ts +1 -1
  40. package/dist/blocks/search/index.d.ts +2 -2
  41. package/dist/blocks/sessions/index.d.ts +1 -1
  42. package/dist/blocks/settings/index.d.ts +1 -1
  43. package/dist/blocks/subjects/index.d.ts +1 -1
  44. package/dist/blocks/tags/index.d.ts +1 -1
  45. package/dist/blocks/undo/index.d.ts +1 -1
  46. package/dist/blocks/usage/index.d.ts +1 -1
  47. package/dist/blocks/workflow-editor/index.d.ts +3 -3
  48. package/dist/blocks/workflows/index.d.ts +3 -3
  49. package/dist/claims/index.d.ts +3 -3
  50. package/dist/cli/{add-7nCSDmpt.js → add-BVs8Ym-K.js} +10 -10
  51. package/dist/cli/{add-B4tQpnXP.js → add-DP1ct-7e.js} +2 -2
  52. package/dist/cli/add-DrwQvDYD.js +1 -0
  53. package/dist/cli/{app-table-files-CtO-zxpO.js → app-table-files-gjMyFqH4.js} +2 -2
  54. package/dist/cli/{app-tables-B7UzcJ_g.js → app-tables-B26PHK75.js} +2 -2
  55. package/dist/cli/{backfill-B2nFDXaS.js → backfill-CP_LpTK2.js} +1 -1
  56. package/dist/cli/bin.js +1 -1
  57. package/dist/cli/{blocks-DU4iDrYS.js → blocks-CpBLp57s.js} +1 -1
  58. package/dist/cli/{blocks-BX_6HUQT.js → blocks-Ewp49Kbm.js} +1 -1
  59. package/dist/cli/{cache-bS5bAoF-.js → cache-BxxtUXVN.js} +1 -1
  60. package/dist/cli/{codemod-B1sSIE2p.js → codemod-CGCxMEyD.js} +1 -1
  61. package/dist/cli/{content-mapper-CW6V6VRq.js → content-mapper-DngBJv4r.js} +2 -2
  62. package/dist/cli/{doctor-Dw2pAf1b.js → doctor-3dcMraMn.js} +17 -17
  63. package/dist/cli/{gen-BtoSx3go.js → gen-DrXxFwUU.js} +11 -11
  64. package/dist/cli/index.d.ts +1 -1
  65. package/dist/cli/index.js +6 -6
  66. package/dist/cli/{init-DZXbrKuJ.js → init-bVKQ4Onb.js} +8 -8
  67. package/dist/cli/{live-CDFfJcdR.js → live-CHTbAqdS.js} +2 -2
  68. package/dist/cli/{mcp-BukxvITV.js → mcp-BbmhntrR.js} +2 -2
  69. package/dist/cli/{metadata-iZizGVuY.js → metadata-BS56R_eb.js} +3 -3
  70. package/dist/cli/{migrate-DPnnGLzw.js → migrate-DV6a9-jI.js} +1 -1
  71. package/dist/cli/{migration-safety-COcnZbMO.js → migration-safety-Ce9IQwmJ.js} +1 -1
  72. package/dist/cli/{migrations-BBt9fmiV.js → migrations-CCCnMhmM.js} +2 -2
  73. package/dist/cli/{module-migration-tCmPLhQp.js → module-migration-C0cAzpNa.js} +2 -2
  74. package/dist/cli/powersync-Cxd3a_v_.js +1 -0
  75. package/dist/cli/{powersync-BRmUJ-uR.js → powersync-OIIpG-y_.js} +3 -3
  76. package/dist/cli/{print-DdwQNG_e.js → print-BGF3d6O2.js} +2 -2
  77. package/dist/cli/{providers-CaNg6Ayz.js → providers-fEzlYSLs.js} +1 -1
  78. package/dist/cli/{prune-workflows-BQQrI3tU.js → prune-workflows-Bx7J5T3a.js} +1 -1
  79. package/dist/cli/{remove-BEj9YEON.js → remove-Ds4N6WvD.js} +5 -5
  80. package/dist/cli/{render-UBqU9r44.js → render-BeZToAp-.js} +3 -3
  81. package/dist/cli/{run-3E_IuJzS.js → run-DR0sTyNQ.js} +9 -9
  82. package/dist/cli/{run-BXlX9YdD.js → run-iUmtksq5.js} +27 -27
  83. package/dist/cli/{shared-agrqD28l.js → shared-BCWYvKeR.js} +1 -1
  84. package/dist/cli/{snapshot-DOXmozSq.js → snapshot-CfgRxTQq.js} +2 -2
  85. package/dist/cli/{source-BfJprU-6.js → source-Ct3ZCy6p.js} +1 -1
  86. package/dist/cli/{spec-CgtIHFsl.js → spec-1eEq2P4T.js} +1 -1
  87. package/dist/cli/{spec-DRpSQGOW.js → spec-9vb-or-k.js} +2 -2
  88. package/dist/cli/{sql-layout-Cs3FMWcY.js → sql-layout-cYsnyjRf.js} +2 -2
  89. package/dist/cli/{sync-C_YGIDjk.js → sync-XpcpINnx.js} +4 -4
  90. package/dist/cli/{upgrade-OG9vaBeX.js → upgrade-A18FY5Iy.js} +2 -2
  91. package/dist/cli/{upgrade-ByQeJRGU.js → upgrade-DXhyb2jV.js} +5 -5
  92. package/dist/cli/{version-CF6Yzah0.js → version-PcwPOm4G.js} +1 -1
  93. package/dist/client/index.d.ts +5 -5
  94. package/dist/client/native/index.d.ts +4 -4
  95. package/dist/config/index.d.ts +2 -2
  96. package/dist/config/index.js +4 -4
  97. package/dist/{config-1-UmQczM.js → config-BRGMUEE2.js} +1 -1
  98. package/dist/{config-AEB5iNEO.js → config-qqAfS_1_.js} +4 -4
  99. package/dist/{context-CH5FYnVk.d.ts → context-dHluCmud.d.ts} +1 -1
  100. package/dist/contract/index.d.ts +3 -3
  101. package/dist/{controller-CJ6rLnpS.d.ts → controller-BQXgMwWN.d.ts} +1 -1
  102. package/dist/create/index.d.ts +3 -3
  103. package/dist/create/index.js +3 -3
  104. package/dist/create/lite/index.d.ts +3 -3
  105. package/dist/create/lite/index.js +2 -2
  106. package/dist/{entitlements-6gODwBSz.d.ts → entitlements-Jh_w-PgX.d.ts} +1 -1
  107. package/dist/{field-errors-CdSjV9Zo.d.ts → field-errors-DIDkgzFA.d.ts} +4 -4
  108. package/dist/{index-DnEJVKQ2.d.ts → index-BKz-E3Mv.d.ts} +6 -6
  109. package/dist/{index-DzLLMmUB.d.ts → index-CpZ4WDDJ.d.ts} +1 -1
  110. package/dist/{index-vkd2LTt2.d.ts → index-DhcLJAtX.d.ts} +1 -1
  111. package/dist/{index-BgRl484n.d.ts → index-IrJQqPeQ.d.ts} +1 -1
  112. package/dist/{index-CrOeAgSh.d.ts → index-g_eFnFqo.d.ts} +2 -2
  113. package/dist/{index-CgKieWlO.d.ts → index-xmb6YGTg.d.ts} +2 -2
  114. package/dist/{index-B5awu2SP.d.ts → index-y70eTezB.d.ts} +2 -2
  115. package/dist/{instances-Bycf_aus.js → instances-DqEZrffE.js} +5 -1
  116. package/dist/mapper/bin.js +5 -5
  117. package/dist/mcp/index.d.ts +1 -1
  118. package/dist/next/index.d.ts +4 -4
  119. package/dist/{operations-knMnfzgm.d.ts → operations-Sza7UQKP.d.ts} +1 -1
  120. package/dist/{options-X61tvckX.js → options-C5cLEJEa.js} +4 -1
  121. package/dist/{options-CS1DA8q9.js → options-CYZH9uxU.js} +2 -1
  122. package/dist/{options-CEwoGUk_.js → options-DiEoDCtf.js} +4 -1
  123. package/dist/otel/index.js +4 -4
  124. package/dist/{permissions-Ed8WvLgQ.d.ts → permissions-COamTJYz.d.ts} +1 -1
  125. package/dist/{ports-Bnwy2mlR.d.ts → ports-1M1E_r2n.d.ts} +1 -1
  126. package/dist/powersync/index.d.ts +2 -2
  127. package/dist/preset/index.d.ts +3 -3
  128. package/dist/preset/index.js +3 -3
  129. package/dist/{preset-DkeXFh7e.js → preset-Byz43PrL.js} +2 -2
  130. package/dist/{project-By0R8ioI.js → project-Y2wW_nr_.js} +5 -5
  131. package/dist/{push-token-CJbEvwjI.d.ts → push-token-DKImhAca.d.ts} +1 -1
  132. package/dist/react/index.d.ts +5 -5
  133. package/dist/react/native/index.d.ts +1 -1
  134. package/dist/react/server.d.ts +5 -5
  135. package/dist/realtime/index.d.ts +3 -3
  136. package/dist/records/index.d.ts +3 -3
  137. package/dist/server/index.d.ts +3 -3
  138. package/dist/solid/index.d.ts +5 -5
  139. package/dist/sql/index.d.ts +5 -5
  140. package/dist/sql/index.js +2 -2
  141. package/dist/{sql-B2cMvGnZ.js → sql-B1FA8jTx.js} +265 -84
  142. package/dist/ssr/index.d.ts +1 -1
  143. package/dist/svelte/index.d.ts +5 -5
  144. package/dist/{tenant-eZNRWTRJ.d.ts → tenant-DflHpV32.d.ts} +1 -1
  145. package/dist/testing/index.d.ts +3 -3
  146. package/dist/testing/index.js +1 -1
  147. package/dist/{topic-D7F2FBNp.d.ts → topic-CekU96q7.d.ts} +1 -1
  148. package/dist/{types-bqvFoBhf.d.ts → types-B42S7qfO.d.ts} +2 -2
  149. package/dist/vue/index.d.ts +5 -5
  150. package/dist/{watch-topic-BIEaSN0Y.d.ts → watch-topic-DBw411Mq.d.ts} +1 -1
  151. package/dist/yjs/index.d.ts +1 -1
  152. package/package.json +1 -1
  153. package/schemas/config-v1.json +13 -0
  154. package/skills/better-supabase/SKILL.md +26 -8
  155. package/dist/cli/add-CdDneXMN.js +0 -1
  156. package/dist/cli/powersync-CYLPcJ9G.js +0 -1
@@ -2,8 +2,8 @@ import { a as SessionActor, c as agentClaims, r as AgentActOptions } from "../..
2
2
  import { d as KnowledgeSearchOptions, o as KnowledgeHit, r as Knowledge } from "../../knowledge-DWXAxvkN.js";
3
3
  import { t as Agent } from "../../agents-BwUHtvD6.js";
4
4
  import { R as AiToolPolicy, t as AiChat, w as AiModerationStage, x as AiModerationAction } from "../../ai-chat-BZhfCHHr.js";
5
- import { r as AuthorizationOperation } from "../../authorization-D8CaAdqU.js";
6
- import { t as OperationTable } from "../../operations-knMnfzgm.js";
5
+ import { r as AuthorizationOperation } from "../../authorization-Ul_ApMYW.js";
6
+ import { t as OperationTable } from "../../operations-Sza7UQKP.js";
7
7
  import { i as SearchToolOptions, r as ResultsFilter } from "../../embeddings-CI6P_mtD.js";
8
8
  import { n as GatewayOptions } from "../../gateway-options-Mut8jih_.js";
9
9
  import { LanguageModel, LanguageModelMiddleware, StopCondition, ToolLoopAgent, ToolLoopAgentSettings, ToolSet } from "ai";
@@ -1,4 +1,4 @@
1
- import { Tr as AppTableConfig } from "./context-CH5FYnVk.js";
1
+ import { Tr as AppTableConfig } from "./context-dHluCmud.js";
2
2
  /**
3
3
  * The columns every app table gets, which `columns` may not name: `id`,
4
4
  * `created_at`, `updated_at`, `user_id` and the tenant column
@@ -703,7 +703,7 @@ interface BlockNameRegistry {
703
703
  readonly "expenses": "id" | "tenant" | "user" | "employee" | "category" | "spentOn" | "description" | "merchant" | "amount" | "currency" | "status" | "submittedAt" | "approvedAt" | "rejectedAt" | "decidedBy" | "decidedAt" | "decisionNote" | "reimbursedAt" | "reimbursedBy" | "reimbursement" | "createdBy" | "createdAt" | "updatedAt";
704
704
  };
705
705
  readonly functions: "add_expense_line" | "approve_expense_report" | "archive_expense_category" | "cancel_expense_report" | "check_expense_report" | "create_expense_report" | "expense_report_violations" | "get_expense_report" | "list_expense_categories" | "list_expense_reports" | "reimburse_expense_report" | "remove_expense_line" | "save_expense_category" | "submit_expense_report" | "update_expense_line";
706
- readonly actions: "read" | "submit" | "approve" | "manage" | "create" | "update" | "delete" | "reimburse" | "categories";
706
+ readonly actions: "read" | "submit" | "approve" | "manage" | "create" | "update" | "delete" | "reimburse" | "categories" | "withdraw" | "deleteSubmitted";
707
707
  readonly hooks: never;
708
708
  readonly entities: {
709
709
  readonly "expense_report": "id" | "tenant_id" | "user_id" | "title" | "currency" | "note" | "approval_id" | "submitted_at" | "approved_at" | "approval_transaction_id" | "reimbursed_at" | "reimbursement_transaction_id" | "cancelled_at" | "created_at" | "updated_at" | "rejected_at" | "decided_by" | "decision_note";
@@ -957,7 +957,7 @@ interface BlockNameRegistry {
957
957
  readonly "lines": "id" | "tenant" | "parent" | "productType" | "productId" | "description" | "quantity" | "unitAmount" | "discountBps" | "taxRateBps" | "taxCode" | "position" | "createdAt";
958
958
  readonly "charges": "id" | "tenant" | "invoice" | "amount" | "currency" | "description" | "createdBy" | "createdAt";
959
959
  };
960
- readonly functions: "add_invoice_charge" | "create_invoice" | "credit_invoice" | "delete_invoice" | "invoice_aging" | "issue_invoice" | "record_invoice_payment" | "remove_invoice_charge" | "reverse_invoice_payment" | "set_invoice_lines" | "set_invoice_lines_recount" | "update_invoice" | "void_invoice" | "write_off_invoice";
960
+ readonly functions: "add_invoice_charge" | "create_invoice" | "credit_invoice" | "delete_invoice" | "invoice_aging" | "issue_invoice" | "list_invoice_payments" | "record_invoice_payment" | "remove_invoice_charge" | "reverse_invoice_payment" | "set_invoice_lines" | "set_invoice_lines_recount" | "update_invoice" | "void_invoice" | "write_off_invoice";
961
961
  readonly actions: "read" | "write" | "manage" | "create" | "update" | "issue" | "payment" | "credit" | "charge" | "void" | "writeOff" | "reverse" | "delete";
962
962
  readonly hooks: "before_invoice_issue" | "after_invoice_issue" | "before_invoice_payment" | "after_invoice_payment";
963
963
  readonly entities: {
@@ -2417,6 +2417,12 @@ type ExpensesSqlOptions = {
2417
2417
  * must allow null.
2418
2418
  */
2419
2419
  readonly companyExpenses?: boolean;
2420
+ /**
2421
+ * Without reports: `withdrawExpense` also takes an approved expense that
2422
+ * isn't reimbursed back to draft and clears its decision. The owner may, and
2423
+ * so may a holder of `permissions.withdraw` (default the `update` key).
2424
+ */
2425
+ readonly withdrawApproved?: boolean;
2420
2426
  };
2421
2427
  /**
2422
2428
  * A custom context's source: the table and column that hold a tenant's value,
@@ -2532,6 +2538,19 @@ type InvoicesSqlOptions = {
2532
2538
  */
2533
2539
  readonly totals?: "block" | "app";
2534
2540
  readonly providerPaymentMethods?: readonly string[];
2541
+ /**
2542
+ * The column an invoice's number is unique on, per tenant and kind:
2543
+ * `"number"` (default), `"identifier"` for numbering that restarts each
2544
+ * period with the period in the identifier, or `false` when the app keeps
2545
+ * numbers unique itself.
2546
+ */
2547
+ readonly uniqueNumber?: "number" | "identifier" | false;
2548
+ /**
2549
+ * `false` leaves out the unique `(invoice, position)` index on your own line
2550
+ * table, so the app can renumber lines in one update. Default `true`.
2551
+ */
2552
+ readonly linePositionKey?: boolean;
2553
+ readonly paymentsAfterWriteOff?: boolean;
2535
2554
  };
2536
2555
  /** `blocks.knowledge.options`. */
2537
2556
  type KnowledgeSqlOptions = {
@@ -2558,6 +2577,26 @@ type LeaveFeedOptions = ShareLinkFeedOptions & {
2558
2577
  readonly teams?: boolean;
2559
2578
  /** Each entry carries the request's extra columns. */
2560
2579
  readonly fields?: boolean;
2580
+ /**
2581
+ * A column of the employees table that names an employee's team, such as
2582
+ * `department_team_id`. A team feed then shares the leave of the employees
2583
+ * whose column holds the team's id, instead of the team's members. Needs
2584
+ * `teams` and the employees block.
2585
+ */
2586
+ readonly teamColumn?: string;
2587
+ /** A team feed carries the team's name. Needs `teams`. */
2588
+ readonly teamName?: boolean;
2589
+ /**
2590
+ * `"schema.table.column"` of the organization's name, matched on the table's
2591
+ * `id`; the feed carries it as `organizationName`.
2592
+ */
2593
+ readonly organizationName?: string;
2594
+ /**
2595
+ * `"busy"` lists the confidential leave the link's creator can't see under
2596
+ * `busy`, with who and when but without the type, amount or fields. Default
2597
+ * `"hide"` leaves it out. Needs `columns.types.confidential`.
2598
+ */
2599
+ readonly confidential?: "hide" | "busy";
2561
2600
  };
2562
2601
  /** `blocks.leave.options`. */
2563
2602
  type LeaveSqlOptions = {
@@ -4,7 +4,7 @@ import { t as BetterSupabase, y as Db } from "./define-C_He1bQO.js";
4
4
  import { n as DataEngine } from "./data-engine-CX1oYDZl.js";
5
5
  import { Dn as GeneratedBlocks } from "./define-block-CDw9YGVh.js";
6
6
  import { rt as BetterQueries } from "./index-DAS_5OfK.js";
7
- import { t as ClientPorts } from "./ports-Bnwy2mlR.js";
7
+ import { t as ClientPorts } from "./ports-1M1E_r2n.js";
8
8
  import { SupabaseClient } from "@supabase/supabase-js";
9
9
  interface AuthUser {
10
10
  readonly id: string;
@@ -1,7 +1,7 @@
1
1
  import { Dn as GeneratedBlocks } from "./define-block-CDw9YGVh.js";
2
- import { n as TopicPort } from "./watch-topic-BIEaSN0Y.js";
3
- import { t as ClientPorts } from "./ports-Bnwy2mlR.js";
4
- import { t as AuthPort } from "./controller-CJ6rLnpS.js";
2
+ import { n as TopicPort } from "./watch-topic-DBw411Mq.js";
3
+ import { t as ClientPorts } from "./ports-1M1E_r2n.js";
4
+ import { t as AuthPort } from "./controller-BQXgMwWN.js";
5
5
  import { SupabaseClient } from "@supabase/supabase-js";
6
6
  /**
7
7
  * What the block bindings hand their controllers: the provider's client,
@@ -1,5 +1,5 @@
1
1
  import { a as entityNoun, i as entityNames, n as checkEntityName, s as tenantRename, t as DEFAULT_TENANT } from "./entity-naming-BES3pkQI.js";
2
- import { I as resolveBlock, L as tenantNameOf, M as PRESET_CATALOG } from "./instances-Bycf_aus.js";
2
+ import { I as resolveBlock, L as tenantNameOf, M as PRESET_CATALOG } from "./instances-DqEZrffE.js";
3
3
  // src/config/defaults.ts
4
4
  /**
5
5
  * Every default `resolveConfig` fills in. Other modules (the SQL module
@@ -127,6 +127,14 @@ function resolveNames(module, names, blocks = {}) {
127
127
  entityNaming: entityNames(renames)
128
128
  };
129
129
  }
130
+ // src/sql/tenant-column.ts
131
+ const DEFAULT_TENANT_COLUMN = "tenant_id";
132
+ function blockColumnName(where, columns, name, tenantColumn, rename) {
133
+ if (name !== DEFAULT_TENANT_COLUMN || tenantColumn === void 0) return rename(name);
134
+ const clash = Object.entries(columns).find(([, other]) => rename(other) === tenantColumn);
135
+ if (clash !== void 0) throw new TypeError(`sql.tenantColumn: "${tenantColumn}" is the name of ${where.table}.${clash[0]} in the ${where.module} module. Choose another name, or map blocks.${where.module}.columns.${where.table}.tenant.`);
136
+ return tenantColumn;
137
+ }
130
138
  // src/config/block-subjects.ts
131
139
  const CATALOG = new Map(PRESET_CATALOG.blocks.map((block) => [block.name, block]));
132
140
  /** `names` and every block they require, from the catalog, in order. */
@@ -184,7 +192,7 @@ function blockEntities(module, blocks) {
184
192
  });
185
193
  }
186
194
  /** The subjects one installed block registers, keyed by renamed entity. */
187
- function subjectsOf(module, blocks) {
195
+ function subjectsOf(module, blocks, tenantColumn) {
188
196
  const entities = CATALOG.get(module)?.entities;
189
197
  const names = catalogNames(module);
190
198
  const config = resolveBlock(blocks[module]);
@@ -197,7 +205,10 @@ function subjectsOf(module, blocks) {
197
205
  const mapped = entity.table === void 0 ? void 0 : config.tables[entity.table];
198
206
  if (subject === void 0 || entity.table === void 0 || table === void 0 || mapped === null) return [];
199
207
  const logical = entity.table;
200
- const column = (name) => config.columns[logical]?.[name] ?? resolved.naming.rename(table.columns[name] ?? name);
208
+ const column = (name) => config.columns[logical]?.[name] ?? blockColumnName({
209
+ module,
210
+ table: logical
211
+ }, table.columns, table.columns[name] ?? name, tenantColumn, (each) => resolved.naming.rename(each));
201
212
  const titled = (key) => config.columns[logical]?.[key] === null && subject.fallbackTitle !== void 0 ? column(subject.fallbackTitle) : column(key);
202
213
  const name = mapped ?? resolved.naming.rename(table.name);
203
214
  const url = entity.url ?? subject.url;
@@ -235,9 +246,9 @@ function subjectsOf(module, blocks) {
235
246
  function blockSubjectTypes(module, blocks) {
236
247
  return Object.keys(subjectsOf(module, blocks));
237
248
  }
238
- function withBlockSubjects(subjects, blockNames, blocks) {
249
+ function withBlockSubjects(subjects, blockNames, blocks, tenantColumn) {
239
250
  const merged = {};
240
- for (const module of withRequired(blockNames)) for (const [type, entry] of Object.entries(subjectsOf(module, blocks))) {
251
+ for (const module of withRequired(blockNames)) for (const [type, entry] of Object.entries(subjectsOf(module, blocks, tenantColumn))) {
241
252
  if (Object.hasOwn(subjects, type)) throw new TypeError(`records.${type}: the ${module} block registers "${type}" itself; remove records.${type}, or set blocks.${module}.names.<entity>.subject to false to keep your own`);
242
253
  merged[type] = entry;
243
254
  }
@@ -250,4 +261,4 @@ function installedBlockSubjects(subjects, installed, blocks) {
250
261
  const dropped = new Set(withRequired(installed).filter((module) => !installed.includes(module)).flatMap((module) => blockSubjectTypes(module, blocks)));
251
262
  return dropped.size === 0 ? subjects : Object.fromEntries(Object.entries(subjects).filter(([type]) => !dropped.has(type)));
252
263
  }
253
- export { withBlockSubjects as a, CONFIG_DEFAULTS as c, installedBlockSubjects as i, blockEntityRenames as n, resolveNames as o, blockSubjectTypes as r, resolveJsonSchema as s, blockEntities as t };
264
+ export { withBlockSubjects as a, resolveJsonSchema as c, installedBlockSubjects as i, CONFIG_DEFAULTS as l, blockEntityRenames as n, blockColumnName as o, blockSubjectTypes as r, resolveNames as s, blockEntities as t };
@@ -1,4 +1,4 @@
1
- import { cn as ResolvedConfig } from "./context-CH5FYnVk.js";
1
+ import { cn as ResolvedConfig } from "./context-dHluCmud.js";
2
2
  /**
3
3
  * One block table as the config names it: unquoted schema and table, and each
4
4
  * logical column's written name, or `null` when an adopted table lacks it.
@@ -5,9 +5,9 @@ import { a as AiMessagePart, c as AiReasoningPart, d as AiTextPart, f as AiToolA
5
5
  import { $ as createHarnessSessions, A as AiRunStatus, B as SharedAiChat, C as AiModerationInput, D as AiProject, E as AiPendingInputRequest, F as AiStreamClaim, G as AiPendingApproval, H as AiHarnessSessionPatch, I as AiToolApproval, J as AiRunState, K as AiRun, L as AiToolApprovalRequest, M as AiShareLink, N as AiStoredMessage, O as AiProjectInput, P as AiStoredMessageStatus, Q as AiRuns, R as AiToolPolicy, S as AiModerationEvent, T as AiPendingInput, U as AiHarnessSessions, V as AiHarnessSession, W as AiHarnessStatus, X as AiRunStepInput, Y as AiRunStep, Z as AiRunStepStatus, _ as AiFeedback, a as createAiChat, b as AiModelInput, c as AiAssistantMessageOptions, d as AiChatPage, f as AiChatPatch, g as AiChatVisibility, h as AiChatShare, i as aiChatTopic, j as AiSaveResult, k as AiRunRelease, l as AiChatInput, m as AiChatRecord, n as AiChatOptions, o as AiAppendResult, p as AiChatQuery, q as AiRunQuery, r as aiChatListTopic, s as AiApprovalDecision, t as AiChat, v as AiMessageSibling, w as AiModerationStage, x as AiModerationAction, y as AiModel, z as AiUserMessageTrigger } from "../../ai-chat-BZhfCHHr.js";
6
6
  import { a as NewAiSandbox, i as AiSandboxes, n as AiSandboxStatus, r as AiSandboxStopper, t as AiSandbox } from "../../sandboxes-BF9RxxCU.js";
7
7
  import { c as BlockOf } from "../../define-block-CDw9YGVh.js";
8
- import { p as SubscriptionStatus } from "../../topic-D7F2FBNp.js";
9
- import { n as TopicPort } from "../../watch-topic-BIEaSN0Y.js";
10
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
8
+ import { p as SubscriptionStatus } from "../../topic-CekU96q7.js";
9
+ import { n as TopicPort } from "../../watch-topic-DBw411Mq.js";
10
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
11
11
  import { StandardSchemaV1 } from "@standard-schema/spec";
12
12
  /**
13
13
  * The `type` of each part in the canonical AI message (version 1); the SQL
@@ -8,9 +8,9 @@ import { r as BlockTemporalOptions } from "../../block-helpers-BNtM1tqy.js";
8
8
  import { a as dbTransport, o as rpcTransport, s as sqlTransport, t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
9
9
  import { n as BlockHooks } from "../../block-hooks-CtMsgLQr.js";
10
10
  import { c as BlockOf } from "../../define-block-CDw9YGVh.js";
11
- import { p as SubscriptionStatus } from "../../topic-D7F2FBNp.js";
12
- import { n as TopicPort } from "../../watch-topic-BIEaSN0Y.js";
13
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
11
+ import { p as SubscriptionStatus } from "../../topic-CekU96q7.js";
12
+ import { n as TopicPort } from "../../watch-topic-DBw411Mq.js";
13
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
14
14
  type AnnouncementSeverity = "info" | "success" | "warning" | "critical";
15
15
  /**
16
16
  * Who sees it: everyone, members of some tenants, members with some roles, or
@@ -1,4 +1,4 @@
1
1
  import { a as dbTransport, o as rpcTransport, s as sqlTransport, t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
2
2
  import { _ as createApiKeys, a as ApiKeyExtraClaims, c as ApiKeyState, d as CreateApiKeyInput, f as CreatedApiKey, g as apiKeyResolver, h as apiKeyClaims, i as ApiKeyExtraClaim, l as ApiKeys, m as apiKeyChecksum, n as ApiKeyCheck, o as ApiKeyReservedClaim, p as ParsedApiKey, r as ApiKeyClaimsOptions, s as ApiKeyResolverOptions, t as ApiKey, u as ApiKeysOptions, v as parseApiKey } from "../../api-keys-BncNDlWG.js";
3
- import { a as ApiKeyDraft, c as ApiKeysControllerOptions, d as ApiKeyAuth, f as ApiKeyContributions, i as ApiKeyChange, l as ApiKeysSnapshot, m as withApiKey, n as ApiKeysEvents, o as ApiKeysActions, p as WithApiKeyOptions, r as apiKeysEvents, s as ApiKeysController, t as apiKeysBlock, u as createApiKeysController } from "../../index-BgRl484n.js";
3
+ import { a as ApiKeyDraft, c as ApiKeysControllerOptions, d as ApiKeyAuth, f as ApiKeyContributions, i as ApiKeyChange, l as ApiKeysSnapshot, m as withApiKey, n as ApiKeysEvents, o as ApiKeysActions, p as WithApiKeyOptions, r as apiKeysEvents, s as ApiKeysController, t as apiKeysBlock, u as createApiKeysController } from "../../index-IrJQqPeQ.js";
4
4
  export { type ApiKey, type ApiKeyAuth, type ApiKeyChange, type ApiKeyCheck, type ApiKeyClaimsOptions, type ApiKeyContributions, type ApiKeyDraft, type ApiKeyExtraClaim, type ApiKeyExtraClaims, type ApiKeyReservedClaim, type ApiKeyResolverOptions, type ApiKeyState, type ApiKeys, type ApiKeysActions, type ApiKeysController, type ApiKeysControllerOptions, type ApiKeysEvents, type ApiKeysOptions, type ApiKeysSnapshot, type BlockTransport, type CreateApiKeyInput, type CreatedApiKey, type ParsedApiKey, type WithApiKeyOptions, apiKeyChecksum, apiKeyClaims, apiKeyResolver, apiKeysBlock, apiKeysEvents, createApiKeys, createApiKeysController, dbTransport, parseApiKey, rpcTransport, sqlTransport, withApiKey };
@@ -3,7 +3,7 @@ import { Ct as Events, ot as StorageObjectEventData, y as AttachmentEventData }
3
3
  import { a as dbTransport, o as rpcTransport, s as sqlTransport, t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
4
4
  import { t as Author } from "../../block-authors-C5z3tGVu.js";
5
5
  import { At as NewAttachment, Ct as AttachmentScannerOptions, Dt as AttachmentVersion, Et as AttachmentUpload, Ft as ScannedObject, It as attachmentVersionOf, Lt as createAttachmentScanner, Mt as ObjectScanner, Nt as ObjectScannerOptions, Ot as Attachments, Pt as ScanVerdict, Rt as createAttachments, Sn as EntitySchema, St as AttachmentScanner, Tt as AttachmentStorage, _t as AttachmentDownload, bt as AttachmentReplacement, c as BlockOf, gt as AttachmentBucket, ht as Attachment, jt as ObjectScanJob, kt as AttachmentsOptions, ln as RecordBindingWrite, mn as RecordRowInput, rn as RecordBinding, vt as AttachmentImageUrlOptions, wt as AttachmentStatus, xt as AttachmentScanJob, yt as AttachmentImages, zt as createObjectScanner } from "../../define-block-CDw9YGVh.js";
6
- import { n as Controller } from "../../controller-CJ6rLnpS.js";
6
+ import { n as Controller } from "../../controller-BQXgMwWN.js";
7
7
  /** A pending write to a record's files, for `useOptimistic`. */
8
8
  type AttachmentsOptimisticAction = {
9
9
  readonly type: "add";
@@ -11,9 +11,9 @@ import { Yt as WhereInput, t as BetterSupabase } from "../../define-C_He1bQO.js"
11
11
  import { c as BlockOf } from "../../define-block-CDw9YGVh.js";
12
12
  import { i as EventSink, t as CloudEvent } from "../../cloud-event-BjgxkfJJ.js";
13
13
  import { i as ListDefinition } from "../../list-query-BkbLV-Yc.js";
14
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
14
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
15
15
  import { a as UndoToken } from "../../undo-CdKp5_2X.js";
16
- import { n as AuditCategory } from "../../context-CH5FYnVk.js";
16
+ import { n as AuditCategory } from "../../context-dHluCmud.js";
17
17
  interface PurgeAuditLogOptions extends BlockTemporalOptions {
18
18
  /**
19
19
  * How long entries are kept when `retention` has no answer. Defaults to `1
@@ -8,7 +8,7 @@ import { a as dbTransport, i as RpcClient, o as rpcTransport, s as sqlTransport,
8
8
  import { a as BlockTransportMiddleware, d as extendBlock, f as withBlockHooks, n as BlockHooks, p as wrapTransport } from "../../block-hooks-CtMsgLQr.js";
9
9
  import { _ as FilterRule, d as FilterLimits, f as FilterNode, h as FilterQuery, i as FilterCombinator, m as FilterOperatorSpec, r as FilterClock } from "../../filter-query-Xj40B5KT.js";
10
10
  import { $t as createActionRegistry, Bt as Action, Gt as ActionInfo, Ht as ActionContext, Jt as ActionRegistry, Kt as ActionOrigin, L as NotifierInput, Qt as actionKey, Ut as ActionDescriptor, Vt as ActionCall, Wt as ActionHandler, Yt as ActionSpec, Zt as DefaultAutomation, c as BlockOf, en as defineAction, qt as ActionRef } from "../../define-block-CDw9YGVh.js";
11
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
11
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
12
12
  import { c as ApprovalRequestInput } from "../../approvals-CXW3yFWZ.js";
13
13
  import { n as FilterRecordField, t as FilterEvaluation } from "../../filter-evaluate-Bkbb0nuQ.js";
14
14
  import { a as checkRuleConditions, c as ruleFilterFields, i as RuleFieldDefinition, n as RuleField, o as defineRuleFields, r as RuleFieldCatalog, s as ruleFilterFieldInfo, t as RULE_LIMITS } from "../../fields-CP46SPNE.js";
@@ -9,7 +9,7 @@ import { n as BlockHooks } from "../../block-hooks-CtMsgLQr.js";
9
9
  import { n as StripeSource, r as StripeTaxId, t as StripeClient } from "../../stripe-Bl-sjnl6.js";
10
10
  import { c as BlockOf } from "../../define-block-CDw9YGVh.js";
11
11
  import { i as EventSink } from "../../cloud-event-BjgxkfJJ.js";
12
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
12
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
13
13
  import { d as stripeInboxVerify, f as verifyStripeWebhook, u as signStripeWebhook } from "../../verify-Cpc1upDA.js";
14
14
  /** The events of the `billing` block: type to data. */
15
15
  type BillingEvents = {
@@ -1,7 +1,7 @@
1
1
  import { b as DbError } from "../../result-DTOQRyGY.js";
2
2
  import { Ct as Events, tt as SchedulingEventData } from "../../events-DddDlibJ.js";
3
3
  import { c as BlockOf } from "../../define-block-CDw9YGVh.js";
4
- import { n as Controller } from "../../controller-CJ6rLnpS.js";
4
+ import { n as Controller } from "../../controller-BQXgMwWN.js";
5
5
  import { o as WeeklyHours } from "../../availability-CZlcrkqD.js";
6
6
  import { C as bookingSeriesOf, S as BookingWeekday, T as parseRecurrence, _ as BookedSeries, a as BookingExceptionInput, b as BookingSeriesScope, c as BookingResourceInput, d as BookingStatus, f as Bookings, g as createBookings, h as PublicBookingService, i as BookingDuration, l as BookingServiceInput, m as PlacedBooking, n as Booking, o as BookingExpirePayload, p as BookingsOptions, r as BookingCustomer, s as BookingRange, t as BOOKING_EXPIRE_QUEUE, u as BookingSlot, v as BookingRecurrence, w as formatRecurrence, x as BookingSeriesStatus, y as BookingSeries } from "../../bookings-Dj5cvXKv.js";
7
7
  import { t as EventCalendarEvent } from "../../event-calendar-DPMcqy7Q.js";
@@ -7,7 +7,7 @@ import { n as Logger } from "../../logger-0LfhvwE4.js";
7
7
  import { t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
8
8
  import { n as BlockHooks } from "../../block-hooks-CtMsgLQr.js";
9
9
  import { Sn as EntitySchema, c as BlockOf } from "../../define-block-CDw9YGVh.js";
10
- import { n as Controller } from "../../controller-CJ6rLnpS.js";
10
+ import { n as Controller } from "../../controller-BQXgMwWN.js";
11
11
  import { A as CalendarAlarmAction, C as IcsEvent, D as parseIcs, E as ToIcsOptions, O as toIcs, S as CalendarEventStatus, T as ParsedIcs, _ as expandOccurrences, a as FreeBusy, b as AttendeeRole, c as WorkingHoursInput, d as workingHoursOf, f as CalendarEvent, g as SplitRules, h as OccurrenceRange, i as CommonFreeTimeOptions, j as CalendarReminder, k as CalendarAlarm, l as commonFreeTime, m as OccurrenceOptions, n as CalendarEventKind, o as WeeklyHours, p as CalendarOccurrence, r as CalendarTransparency, s as WorkingHours, t as BusyRange, u as freeBusyOf, v as splitRule, w as IcsSource, x as CalendarAttendee, y as AttendeeResponse } from "../../availability-CZlcrkqD.js";
12
12
  import { a as fromEventCalendarUpdate, c as toEventCalendarResources, i as OccurrenceMove, n as EventCalendarOptions, o as seriesOf, r as EventCalendarResource, s as toEventCalendarEvents, t as EventCalendarEvent } from "../../event-calendar-DPMcqy7Q.js";
13
13
  import { t as VisibleRange } from "../../range-BN3kpJAE.js";
@@ -11,6 +11,18 @@ import { h as FilterQuery } from "../../filter-query-Xj40B5KT.js";
11
11
  import { Sn as EntitySchema, c as BlockOf } from "../../define-block-CDw9YGVh.js";
12
12
  import { n as Money } from "../../money-BgpAd7d3.js";
13
13
  import { t as RankNeighbors } from "../../rank-result-B_xLQCBV.js";
14
+ /**
15
+ * A whole-number position for a rank method when `options.rankType` is
16
+ * `"integer"`.
17
+ */
18
+ interface RankPosition {
19
+ readonly position: number;
20
+ }
21
+ /**
22
+ * Where a rank method moves a row: between two neighbors' rank keys, or, with
23
+ * integer ranks, at a position.
24
+ */
25
+ type CatalogRank = RankNeighbors | RankPosition;
14
26
  export declare const PRODUCT_KINDS: readonly ["physical", "digital", "service"];
15
27
  type ProductKind = (typeof PRODUCT_KINDS)[number];
16
28
  export declare const PRODUCT_STATUSES: readonly ["draft", "active", "archived"];
@@ -28,6 +40,11 @@ interface CatalogOptions<S extends StandardSchemaV1 | undefined = undefined> ext
28
40
  readonly hooks?: NoInfer<BlockHooks<Catalog<FieldsOf<S>>>>;
29
41
  /** Receives the errors `after` hooks throw. Default: `console`. */
30
42
  readonly logger?: Logger;
43
+ /**
44
+ * `blocks.catalog.options.rankType`, which `blockConfig` passes. With
45
+ * `"integer"`, the rank methods write whole-number positions.
46
+ */
47
+ readonly rankType?: "text" | "integer";
31
48
  }
32
49
  interface ProductInput {
33
50
  readonly title: string;
@@ -294,8 +311,11 @@ interface Catalog<F extends object = Record<never, never>> {
294
311
  setOptions(productId: string, options: readonly OptionMatrixInput[], settings?: OptionMatrixOptions): AsyncResult<OptionMatrix>;
295
312
  createVariant(productId: string, input: VariantInput): AsyncResult<SavedVariant>;
296
313
  updateVariant(productId: string, variantId: string, input: VariantInput): AsyncResult<SavedVariant>;
297
- /** Moves a variant between the variants with rank keys `previous` and `next`. */
298
- reorderVariant(variantId: string, neighbors: RankNeighbors): AsyncResult<string>;
314
+ /**
315
+ * Moves a variant between the variants with rank keys `previous` and `next`,
316
+ * or to a whole-number position with integer ranks.
317
+ */
318
+ reorderVariant(variantId: string, rank: CatalogRank): AsyncResult<string>;
299
319
  setVariantStatus(variantId: string, status: "active" | "archived" | (string & {})): AsyncResult<{
300
320
  readonly status: string;
301
321
  readonly from: string;
@@ -318,7 +338,7 @@ interface Catalog<F extends object = Record<never, never>> {
318
338
  * Moves a category under `parentId` (null for the top level) between two
319
339
  * siblings.
320
340
  */
321
- moveCategory(categoryId: string, parentId: string | null, neighbors: RankNeighbors): AsyncResult<string>;
341
+ moveCategory(categoryId: string, parentId: string | null, rank: CatalogRank): AsyncResult<string>;
322
342
  deleteCategory(categoryId: string): AsyncResult<boolean>;
323
343
  setProductCategories(productId: string, categoryIds: readonly string[]): AsyncResult<boolean>;
324
344
  saveCollection(organizationId: string, input: CollectionInput): AsyncResult<SavedCollection>;
@@ -327,7 +347,7 @@ interface Catalog<F extends object = Record<never, never>> {
327
347
  * Adds a product to a manual collection, last or between two neighbors.
328
348
  * Resolves to its rank key.
329
349
  */
330
- addToCollection(collectionId: string, productId: string, neighbors?: RankNeighbors): AsyncResult<string>;
350
+ addToCollection(collectionId: string, productId: string, rank?: CatalogRank): AsyncResult<string>;
331
351
  removeFromCollection(collectionId: string, productId: string): AsyncResult<boolean>;
332
352
  /**
333
353
  * With `options.storefront: "public"`, anyone can read a published
@@ -400,4 +420,4 @@ export declare const catalogBlock: BlockOf<"catalog", typeof createCatalog, Cata
400
420
  * checks.
401
421
  */
402
422
  export declare const productInputSchema: EntitySchema<ProductInput>;
403
- export { type BlockHooks, type BlockTransport, type BlockTransportMiddleware, type Catalog, type CatalogEvents, type CatalogOptions, type CategoryInput, type ChannelInput, type ChannelProduct, type ChannelProductsOptions, type CollectionInput, type LocaleOptions, type LocalizedProduct, type LocalizedVariant, type MatrixVariant, type OptionInput, type OptionMatrix, type OptionMatrixInput, type OptionMatrixOptions, type OptionValue, type Price, type PriceInput, type PriceListInput, type ProductInput, type ProductKind, type ProductMedia, type ProductMediaInput, type ProductPatch, type ProductStatus, type ProductTranslation, type RpcClient, type SavedCategory, type SavedChannel, type SavedCollection, type SavedOption, type SavedPrice, type SavedProduct, type SavedProductMedia, type SavedVariant, type StatusChange, type VariantInput, type VariantPriceOptions, dbTransport, extendBlock, rpcTransport, sqlTransport, withBlockHooks, wrapTransport };
423
+ export { type BlockHooks, type BlockTransport, type BlockTransportMiddleware, type Catalog, type CatalogEvents, type CatalogOptions, type CatalogRank, type CategoryInput, type ChannelInput, type ChannelProduct, type ChannelProductsOptions, type CollectionInput, type LocaleOptions, type LocalizedProduct, type LocalizedVariant, type MatrixVariant, type OptionInput, type OptionMatrix, type OptionMatrixInput, type OptionMatrixOptions, type OptionValue, type Price, type PriceInput, type PriceListInput, type ProductInput, type ProductKind, type ProductMedia, type ProductMediaInput, type ProductPatch, type ProductStatus, type ProductTranslation, type RankPosition, type RpcClient, type SavedCategory, type SavedChannel, type SavedCollection, type SavedOption, type SavedPrice, type SavedProduct, type SavedProductMedia, type SavedVariant, type StatusChange, type VariantInput, type VariantPriceOptions, dbTransport, extendBlock, rpcTransport, sqlTransport, withBlockHooks, wrapTransport };
@@ -1,7 +1,7 @@
1
1
  import { n as dbError } from "../../errors-B7tCfCvX.js";
2
2
  import { n as isRecord } from "../../guards-CsRa6v57.js";
3
- import { t as AsyncResult } from "../../result-8xza7w5W.js";
4
- import { t as catalogSqlOptions } from "../../options-CEwoGUk_.js";
3
+ import { a as ok, r as err, t as AsyncResult } from "../../result-8xza7w5W.js";
4
+ import { t as catalogSqlOptions } from "../../options-DiEoDCtf.js";
5
5
  import { n as event, t as defineEvents } from "../../event-map-DxfsFgQT.js";
6
6
  import { A as recordsOf, I as stringsOf, L as textOf, O as recordOf, T as pageOf, U as rpcTransport, V as dbTransport, W as sqlTransport, d as enumOrThrow, h as instantOf, m as instantArg, n as applyTemporal, o as blockCall, w as optionalText } from "../../block-helpers-I7UzjNEf.js";
7
7
  import { i as wrapTransport, n as extendBlock, r as withBlockHooks } from "../../block-hooks-CadxQ9-_.js";
@@ -11,6 +11,28 @@ import { n as defineBlock } from "../../define-block-22Jv4U_-.js";
11
11
  import { t as rankBetweenResult } from "../../rank-result-DzaTKKhH.js";
12
12
  import { d as money } from "../../money-DH--bbYr.js";
13
13
  import { a as optionalAmountText, o as optionalMoneyOf, t as amountText } from "../../money-codec-SKPm8FPw.js";
14
+ // src/blocks/catalog/rank.ts
15
+ const WHOLE_RANK = /^-?[0-9]{1,9}$/u;
16
+ const MAX_POSITION = 999999999;
17
+ const rankInvalid = (message) => err(dbError("invalid_request", message, { hint: "RANK_KEY_INVALID" }));
18
+ const isPosition = (value) => Number.isSafeInteger(value) && Math.abs(value) <= MAX_POSITION;
19
+ /**
20
+ * The rank key a rank method writes: a base-62 key between the neighbors, or
21
+ * with integer ranks the position, or a whole number between the neighbors.
22
+ */
23
+ function catalogRankKey(rank, type) {
24
+ if ("position" in rank) {
25
+ if (type !== "integer") return rankInvalid("a position needs blocks.catalog.options.rankType: \"integer\"; pass previous and next rank keys");
26
+ return isPosition(rank.position) ? ok(String(rank.position)) : rankInvalid("a position is a whole number of up to nine digits");
27
+ }
28
+ if (type === "text") return rankBetweenResult(rank);
29
+ const bound = (value) => value === null || value === void 0 ? null : WHOLE_RANK.test(value) ? Number(value) : void 0;
30
+ const previous = bound(rank.previous);
31
+ const next = bound(rank.next);
32
+ if (previous === void 0 || next === void 0) return rankInvalid("integer rank keys are whole numbers of up to nine digits");
33
+ const key = previous === null ? next === null ? 1 : next - 1 : next === null ? previous + 1 : next - previous >= 2 ? Math.floor((previous + next) / 2) : void 0;
34
+ return key === void 0 ? rankInvalid(`no whole number lies between ${String(previous)} and ${String(next)}; pass a position`) : isPosition(key) ? ok(String(key)) : rankInvalid("a position is a whole number of up to nine digits");
35
+ }
14
36
  // src/blocks/catalog/catalog.ts
15
37
  const PRODUCT_KINDS = [
16
38
  "physical",
@@ -157,6 +179,7 @@ function createCatalog(options) {
157
179
  applyTemporal(options);
158
180
  const call = blockCall(options.transport, options.schema, options.mappers);
159
181
  const fields = blockFields(options.fields, "product fields");
182
+ const rankOf = (rank) => catalogRankKey(rank, options.rankType ?? "text");
160
183
  const saveProduct = (organizationId, productId, { title, slug, description, kind, price, trackInventory, ...extra }) => {
161
184
  const clear = [
162
185
  ["price", price],
@@ -231,8 +254,8 @@ function createCatalog(options) {
231
254
  }, matrixOf),
232
255
  createVariant: (productId, input) => call("save_variant", variantArgs(productId, null, input), variantOf),
233
256
  updateVariant: (productId, variantId, input) => call("save_variant", variantArgs(productId, variantId, input), variantOf),
234
- reorderVariant: (variantId, neighbors) => {
235
- const key = rankBetweenResult(neighbors);
257
+ reorderVariant: (variantId, rank) => {
258
+ const key = rankOf(rank);
236
259
  if (!key.ok) return AsyncResult.err(key.error);
237
260
  return call("rank_variant", {
238
261
  variant: variantId,
@@ -292,8 +315,8 @@ function createCatalog(options) {
292
315
  ...isRecord(row["fields"]) ? { fields: row["fields"] } : {}
293
316
  };
294
317
  }),
295
- moveCategory: (categoryId, parentId, neighbors) => {
296
- const key = rankBetweenResult(neighbors);
318
+ moveCategory: (categoryId, parentId, rank) => {
319
+ const key = rankOf(rank);
297
320
  if (!key.ok) return AsyncResult.err(key.error);
298
321
  return call("move_category", {
299
322
  category: categoryId,
@@ -322,14 +345,14 @@ function createCatalog(options) {
322
345
  };
323
346
  }),
324
347
  deleteCollection: (collectionId) => call("delete_collection", { collection: collectionId }, (value) => value === true),
325
- addToCollection: (collectionId, productId, neighbors) => {
348
+ addToCollection: (collectionId, productId, rank) => {
326
349
  const add = (rank) => call("add_to_collection", {
327
350
  collection: collectionId,
328
351
  product: productId,
329
352
  rank
330
353
  }, textOf);
331
- if (neighbors === void 0) return add(null);
332
- const key = rankBetweenResult(neighbors);
354
+ if (rank === void 0) return add(null);
355
+ const key = rankOf(rank);
333
356
  return key.ok ? add(key.data) : AsyncResult.err(key.error);
334
357
  },
335
358
  removeFromCollection: (collectionId, productId) => call("remove_from_collection", {
@@ -7,14 +7,14 @@ import { n as Logger } from "../../logger-0LfhvwE4.js";
7
7
  import { a as BlockTenantOptions, i as CursorPageOptions, r as BlockTemporalOptions } from "../../block-helpers-BNtM1tqy.js";
8
8
  import { a as dbTransport, o as rpcTransport, s as sqlTransport, t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
9
9
  import { n as BlockHooks } from "../../block-hooks-CtMsgLQr.js";
10
- import { F as CommentsSqlOptions } from "../../authorization-D8CaAdqU.js";
10
+ import { F as CommentsSqlOptions } from "../../authorization-Ul_ApMYW.js";
11
11
  import { t as Author } from "../../block-authors-C5z3tGVu.js";
12
12
  import { a as isFileAnchor, i as fileAnchor, n as FileAnchor, o as conversationTopic, r as FileAnchorAt, t as AnchorRegion } from "../../anchors-sCLvYj-8.js";
13
13
  import { c as MessageEdit, l as MessageEdition, o as Message } from "../../messaging-Bfe4p9Pm.js";
14
14
  import { Sn as EntitySchema, c as BlockOf, ln as RecordBindingWrite, mn as RecordRowInput, rn as RecordBinding } from "../../define-block-CDw9YGVh.js";
15
- import { p as SubscriptionStatus } from "../../topic-D7F2FBNp.js";
16
- import { n as TopicPort } from "../../watch-topic-BIEaSN0Y.js";
17
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
15
+ import { p as SubscriptionStatus } from "../../topic-CekU96q7.js";
16
+ import { n as TopicPort } from "../../watch-topic-DBw411Mq.js";
17
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
18
18
  interface CommentsOptions<S extends StandardSchemaV1 | undefined = undefined> extends BlockTemporalOptions, BlockTenantOptions {
19
19
  /**
20
20
  * A Standard Schema for the message extra columns
@@ -4,8 +4,8 @@ import { n as SqlClient } from "../../executor-DoSNec_H.js";
4
4
  import { a as dbTransport, o as rpcTransport, s as sqlTransport, t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
5
5
  import { n as BlockHooks } from "../../block-hooks-CtMsgLQr.js";
6
6
  import { c as BlockOf } from "../../define-block-CDw9YGVh.js";
7
- import { a as hasEntitlement, n as EntitlementKey, t as EntitlementClaimOptions } from "../../entitlements-6gODwBSz.js";
8
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
7
+ import { a as hasEntitlement, n as EntitlementKey, t as EntitlementClaimOptions } from "../../entitlements-Jh_w-PgX.js";
8
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
9
9
  /** The Stripe event sent when a customer's active entitlements change. */
10
10
  export declare const ENTITLEMENTS_UPDATED = "entitlements.active_entitlement_summary.updated";
11
11
  /**
@@ -2,7 +2,7 @@ import { n as dbError } from "../../errors-B7tCfCvX.js";
2
2
  import { n as isRecord } from "../../guards-CsRa6v57.js";
3
3
  import { t as temporal } from "../../temporal-required-w_2u4EDp.js";
4
4
  import { t as AsyncResult } from "../../result-8xza7w5W.js";
5
- import { t as expensesSqlOptions } from "../../options-CS1DA8q9.js";
5
+ import { t as expensesSqlOptions } from "../../options-CYZH9uxU.js";
6
6
  import { n as event, t as defineEvents } from "../../event-map-DxfsFgQT.js";
7
7
  import { A as recordsOf, L as textOf, O as recordOf, U as rpcTransport, V as dbTransport, W as sqlTransport, d as enumOrThrow, j as requiredInstant, m as instantArg, n as applyTemporal, o as blockCall, w as optionalText } from "../../block-helpers-I7UzjNEf.js";
8
8
  import { i as wrapTransport, n as extendBlock, r as withBlockHooks } from "../../block-hooks-CadxQ9-_.js";
@@ -8,7 +8,7 @@ import { r as BlockTemporalOptions } from "../../block-helpers-BNtM1tqy.js";
8
8
  import { a as dbTransport, o as rpcTransport, s as sqlTransport, t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
9
9
  import { n as BlockHooks } from "../../block-hooks-CtMsgLQr.js";
10
10
  import { c as BlockOf } from "../../define-block-CDw9YGVh.js";
11
- import { n as Controller } from "../../controller-CJ6rLnpS.js";
11
+ import { n as Controller } from "../../controller-BQXgMwWN.js";
12
12
  import { _ as isFormDefinition, a as FormDefinition, c as FormJson, d as FormScoring, f as FormStep, g as formSchema, h as formDefinitionProblems, i as FormCondition, l as FormJsonSchema, m as UNSCORED_FIELD_TYPES, n as FORM_FIELD_TYPES, o as FormField, p as NPS_MAX, r as FORM_SCHEMA_DIALECT, s as FormFieldType, t as FORM_DEFINITION_SCHEMA, u as FormOption } from "../../form-definition-BN8shngm.js";
13
13
  import { StandardSchemaV1 } from "@standard-schema/spec";
14
14
  /** A submission's answers, by field key. */
@@ -2,10 +2,10 @@ import { Ct as Events, H as InboxEventData } from "../../events-DddDlibJ.js";
2
2
  import { a as dbTransport, i as RpcClient, o as rpcTransport, s as sqlTransport, t as BlockTransport } from "../../block-transport-CDmOUuLZ.js";
3
3
  import { d as MessageKind, p as MessageReaction, u as MessageFile } from "../../messaging-Bfe4p9Pm.js";
4
4
  import { Zt as DefaultAutomation, c as BlockOf } from "../../define-block-CDw9YGVh.js";
5
- import { p as SubscriptionStatus } from "../../topic-D7F2FBNp.js";
6
- import { n as TopicPort } from "../../watch-topic-BIEaSN0Y.js";
7
- import { l as StoragePort } from "../../ports-Bnwy2mlR.js";
8
- import { n as Controller, t as AuthPort } from "../../controller-CJ6rLnpS.js";
5
+ import { p as SubscriptionStatus } from "../../topic-CekU96q7.js";
6
+ import { n as TopicPort } from "../../watch-topic-DBw411Mq.js";
7
+ import { l as StoragePort } from "../../ports-1M1E_r2n.js";
8
+ import { n as Controller, t as AuthPort } from "../../controller-BQXgMwWN.js";
9
9
  import { S as StoredInboundEvent, _ as MessageDirection, a as ConversationEvent, b as PurgedContact, c as DeliveryStatus, d as InboxCounts, f as InboxFileSource, g as MessageDelivery, h as InboxUpload, i as Conversation, l as InboundResult, m as InboxRow, n as BotMode, o as ConversationPriority, p as InboxMessage, r as Contact, s as ConversationStatus, t as AuthorType, u as InboxChannel, v as MessageTemplate, x as ScheduledInboxMessage, y as PendingInboxFile } from "../../types-D5uf0l4_.js";
10
10
  import { _ as InboxDraftSource, a as Inbox, c as InboxPatch, d as ScheduledMessageInput, f as StartConversationInput, g as InboxDraftInput, h as InboxDraft, i as InboundInput, l as MessageInput, m as createInbox, n as ConversationFilter, o as InboxHooks, p as TemplateInput, r as CreateInboxInput, s as InboxOptions, t as ContactInput, u as MessagePageOptions, v as InboxDraftStatus, y as InboxDrafts } from "../../inbox-yGfUVQr2.js";
11
11
  export declare const INBOX_CHANNELS: readonly InboxChannel[];
@@ -12,7 +12,7 @@ import { a as OptionInput, c as OptionSpecs, d as optionsJsonSchema, i as Option
12
12
  import { A as CreateBlocksOptions, An as BlockNaming, C as BlockContext, Cn as EntitySchemaSpec, D as Blocks, Dn as GeneratedBlocks, E as BlockSinks, En as GeneratedBlock, F as BlockPorts, Fn as entityNames, I as Notifier, L as NotifierInput, M as createBlockClient, Mn as EntityNames, N as createBlocks, Nn as EntityNoun, O as BlocksEventMap, On as fillTopic, P as defineBlocks, Pn as EntityRename, R as PortName, S as BlockClientSource, Sn as EntitySchema, T as BlockSet, Tn as entitySchema, _ as BlockProvider, a as BlockConsumes, b as BLOCK_EVENT_SOURCE, bn as BlockSchemas, c as BlockOf, d as ClientOf, f as ConsumedPorts, g as BlockEnvKey, h as defineBlock, i as BlockCategory, j as UniquePort, jn as blockNames, k as BlocksHooks, kn as generatedOptions, l as BlockOptionSchemas, m as UsingOptions, n as BLOCK_CATEGORIES, o as BlockDefinition, p as ProvidedPorts, r as Block, s as BlockInvalidates, t as AnyBlock, tn as AnyRecordBinding, u as BlockProvides, v as BlockWiring, w as BlockMap, wn as EntitySchemas, x as BlockClientOptions, xn as EntityFieldSpecs, y as BlockWorker } from "../define-block-CDw9YGVh.js";
13
13
  import { t as VisibleRange } from "../range-BN3kpJAE.js";
14
14
  import { t as subjectKey } from "../block-subjects-Bkieh2Xk.js";
15
- import { t as BlockEnv } from "../block-env-hco8BLjC.js";
15
+ import { t as BlockEnv } from "../block-env-Bcr-jEA1.js";
16
16
  /** What a hook passes a block creator from the env. */
17
17
  interface EnvBlockOptions {
18
18
  readonly transport: BlockTransport;
@@ -152,6 +152,7 @@ interface Invoices<F extends object = Record<never, never>> {
152
152
  readonly fields?: Readonly<Record<string, unknown>>;
153
153
  }): AsyncResult<Invoice<F>>;
154
154
  aging(organizationId: string, currency: string, asOf?: Temporal.PlainDate): AsyncResult<InvoiceAging>;
155
+ payments(invoiceId: string): AsyncResult<readonly InvoicePayment[]>;
155
156
  /**
156
157
  * An invoice from an accepted quote: the full invoice once, minus the
157
158
  * deposits already issued, or a deposit invoice for `depositBps` of it.
@@ -1,6 +1,6 @@
1
1
  import { n as isRecord } from "../../guards-CsRa6v57.js";
2
2
  import { t as AsyncResult } from "../../result-8xza7w5W.js";
3
- import { t as invoicesSqlOptions } from "../../options-X61tvckX.js";
3
+ import { t as invoicesSqlOptions } from "../../options-C5cLEJEa.js";
4
4
  import { n as event, t as defineEvents } from "../../event-map-DxfsFgQT.js";
5
5
  import { A as recordsOf, C as optionalInstant, L as textOf, O as recordOf, U as rpcTransport, V as dbTransport, W as sqlTransport, a as bigintOf, d as enumOrThrow, j as requiredInstant, m as instantArg, n as applyTemporal, o as blockCall, w as optionalText } from "../../block-helpers-I7UzjNEf.js";
6
6
  import { i as wrapTransport, n as extendBlock, r as withBlockHooks } from "../../block-hooks-CadxQ9-_.js";
@@ -60,6 +60,17 @@ const KNOWN = /* @__PURE__ */ new Set([
60
60
  "charges",
61
61
  "charged_total"
62
62
  ]);
63
+ function paymentOf(payment, currency) {
64
+ return compact({
65
+ id: textOf(payment["id"]),
66
+ amount: moneyOf(payment["amount"], currency, "invoice payment amount"),
67
+ paidAt: requiredInstant(payment["paidAt"], "paidAt"),
68
+ method: optionalText(payment["method"]),
69
+ reference: optionalText(payment["reference"]),
70
+ note: optionalText(payment["note"]),
71
+ recordedBy: optionalText(payment["recordedBy"])
72
+ });
73
+ }
63
74
  function invoiceOf(value) {
64
75
  const row = recordOf(value, "invoice");
65
76
  const currency = textOf(row["currency"]);
@@ -98,15 +109,7 @@ function invoiceOf(value) {
98
109
  depositBps: typeof row["deposit_bps"] === "number" ? row["deposit_bps"] : void 0,
99
110
  pricesIncludeTax: row["prices_include_tax"] === true,
100
111
  lines: recordsOf(row["lines"], "invoice lines").map((line) => lineOf(line, currency)),
101
- payments: recordsOf(row["payments"], "invoice payments").map((payment) => compact({
102
- id: textOf(payment["id"]),
103
- amount: moneyOf(payment["amount"], currency, "invoice payment amount"),
104
- paidAt: requiredInstant(payment["paidAt"], "paidAt"),
105
- method: optionalText(payment["method"]),
106
- reference: optionalText(payment["reference"]),
107
- note: optionalText(payment["note"]),
108
- recordedBy: optionalText(payment["recordedBy"])
109
- })),
112
+ payments: recordsOf(row["payments"], "invoice payments").map((payment) => paymentOf(payment, currency)),
110
113
  totals: totalsOf(row, false),
111
114
  fields: Object.fromEntries(Object.entries(row).filter(([key]) => !KNOWN.has(key))),
112
115
  createdAt: requiredInstant(row["created_at"], "createdAt")
@@ -221,6 +224,11 @@ function createInvoices(options) {
221
224
  overdueCount: Number(row["overdueCount"] ?? 0)
222
225
  };
223
226
  }) : AsyncResult.err(unknownCurrency(currency)),
227
+ payments: (invoiceId) => call("list_invoice_payments", { invoice: invoiceId }, (value) => {
228
+ const row = recordOf(value, "list_invoice_payments");
229
+ const currency = textOf(row["currency"]);
230
+ return recordsOf(row["payments"], "invoice payments").map((payment) => paymentOf(payment, currency));
231
+ }),
224
232
  fromQuote: (quoteId, fromQuote = {}) => invoice("invoice_from_quote", {
225
233
  quote: quoteId,
226
234
  deposit_bps: fromQuote.depositBps ?? null