better-supabase 0.29.0 → 0.31.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 (208) hide show
  1. package/dist/{adapter-D4aNBxhm.js → adapter-BTbj5N9C.js} +2 -52
  2. package/dist/ai-sdk/agents/index.d.ts +2 -2
  3. package/dist/{app-tables-DekyKNQ8.d.ts → app-tables-B2mKMNRQ.d.ts} +1 -1
  4. package/dist/astro/index.js +2 -2
  5. package/dist/{authorization-C7nuWMuB.d.ts → authorization-DfEkyFt_.d.ts} +24 -3
  6. package/dist/{bind-DmUGUsBd.d.ts → bind-DAx0bMSi.d.ts} +2 -2
  7. package/dist/{block-env-DWtZsqhH.d.ts → block-env-Dz7Caxk0.d.ts} +3 -3
  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 +7 -3
  17. package/dist/blocks/calendar/index.js +5 -1
  18. package/dist/blocks/comments/index.d.ts +4 -4
  19. package/dist/blocks/employees/index.js +1 -4
  20. package/dist/blocks/entitlements/index.d.ts +2 -2
  21. package/dist/blocks/forms/index.d.ts +1 -1
  22. package/dist/blocks/inbox/index.d.ts +4 -4
  23. package/dist/blocks/index.d.ts +1 -1
  24. package/dist/blocks/messaging/index.d.ts +4 -4
  25. package/dist/blocks/mfa/index.d.ts +1 -1
  26. package/dist/blocks/notifications/index.d.ts +3 -3
  27. package/dist/blocks/notifications/index.js +5 -43
  28. package/dist/blocks/onboarding/index.d.ts +1 -1
  29. package/dist/blocks/organizations/index.d.ts +34 -21
  30. package/dist/blocks/organizations/index.js +5 -1
  31. package/dist/blocks/permissions/index.d.ts +32 -3
  32. package/dist/blocks/permissions/index.js +23 -2
  33. package/dist/blocks/push/index.d.ts +10 -2
  34. package/dist/blocks/push/index.js +23 -7
  35. package/dist/blocks/reactions/index.d.ts +3 -3
  36. package/dist/blocks/saved-views/index.d.ts +1 -1
  37. package/dist/blocks/search/index.d.ts +2 -2
  38. package/dist/blocks/sessions/index.d.ts +1 -1
  39. package/dist/blocks/settings/index.d.ts +1 -1
  40. package/dist/blocks/subjects/index.d.ts +1 -1
  41. package/dist/blocks/tags/index.d.ts +1 -1
  42. package/dist/blocks/tasks/index.js +1 -1
  43. package/dist/blocks/teams/index.d.ts +7 -1
  44. package/dist/blocks/teams/index.js +8 -7
  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/cli/{add-BKkV99g9.js → add-B9wP0YGU.js} +2 -2
  50. package/dist/cli/{add-CrQ3jS7t.js → add-DjZXKd7X.js} +10 -10
  51. package/dist/cli/add-ZcEOEK23.js +1 -0
  52. package/dist/cli/{app-table-files-PnPOpuB4.js → app-table-files-mtvjHa48.js} +2 -2
  53. package/dist/cli/{backfill-DDDLhinm.js → backfill-Coshdvh_.js} +2 -2
  54. package/dist/cli/bin.js +1 -1
  55. package/dist/cli/{blocks-tRfYx_mh.js → blocks-BWCuA0nq.js} +2 -2
  56. package/dist/cli/{blocks-BCVcjvbm.js → blocks-hiSazThw.js} +1 -1
  57. package/dist/cli/{cache-DQZ09YOg.js → cache-x2wWAy0h.js} +1 -1
  58. package/dist/cli/{codemod-HKuwQmi_.js → codemod-BnjV7BpC.js} +210 -11
  59. package/dist/cli/{command-DIPmo0wh.js → command-CCAwhiOh.js} +6 -0
  60. package/dist/cli/{completion-DxPxMtyP.js → completion-BJaB84Pe.js} +2 -2
  61. package/dist/cli/{completion-DyLMSjOD.js → completion-BkUhs1ms.js} +1 -1
  62. package/dist/cli/{completion-FUgqm2-N.js → completion-DmUVsUVQ.js} +2 -2
  63. package/dist/cli/{config-BfapErxs.js → config-zId1jkLx.js} +1 -1
  64. package/dist/cli/{content-mapper-B0ehR7K-.js → content-mapper-DvOSOdTE.js} +2 -2
  65. package/dist/cli/{db-CWvH1_46.js → db-DXKyVEDF.js} +1 -1
  66. package/dist/cli/{doctor-CXJOhwLB.js → doctor-Ywy8oJEU.js} +76 -18
  67. package/dist/cli/env-CNjT_uOV.js +1 -0
  68. package/dist/cli/{env-BM242BCV.js → env-XMiKvhtV.js} +2 -2
  69. package/dist/cli/{gen-B7rw4j19.js → gen-B-FbQmG1.js} +14 -14
  70. package/dist/cli/index.d.ts +1 -1
  71. package/dist/cli/index.js +7 -7
  72. package/dist/cli/{init-C1bXXB_P.js → init-fb9e1BKX.js} +9 -9
  73. package/dist/cli/{keys-V-HcO-21.js → keys-ORiPz1sM.js} +1 -1
  74. package/dist/cli/{live-PpAh9pAc.js → live-DIt7TP-N.js} +2 -2
  75. package/dist/cli/{mcp-BRNAchdH.js → mcp-CVWwraga.js} +3 -3
  76. package/dist/cli/{metadata-dAAKb_kR.js → metadata-CannIjel.js} +3 -3
  77. package/dist/cli/{migrate-BWYXFnaW.js → migrate-Ht2TzIQF.js} +2 -2
  78. package/dist/cli/{migration-safety-DGQswWZy.js → migration-safety-nNyB05I-.js} +1 -1
  79. package/dist/cli/{migrations-Cqk-lJwu.js → migrations-bAd7dpk1.js} +2 -2
  80. package/dist/cli/{module-migration-8-hMiZtW.js → module-migration-CkNux8dr.js} +2 -2
  81. package/dist/cli/{moved-DNOtp9LA.js → moved-C3WyRHkA.js} +1 -1
  82. package/dist/cli/{parse-BPf3kGnc.js → parse-DjHbTaFI.js} +1 -1
  83. package/dist/cli/{powersync-BWQ-8T3G.js → powersync-B2v0tDwp.js} +100 -7
  84. package/dist/cli/powersync-D3mAQ6QE.js +1 -0
  85. package/dist/cli/{print-DSTnq5xz.js → print-CxQ0rBKT.js} +2 -2
  86. package/dist/cli/{providers-Cjf5iOp5.js → providers-DtI90lSw.js} +1 -1
  87. package/dist/cli/{remove-CwG8cPv1.js → remove-DYtE4IZ4.js} +6 -6
  88. package/dist/cli/{render-B18iAdsT.js → render-QGWfEoiB.js} +3 -3
  89. package/dist/cli/{run-CvPl8iQd.js → run-B5aMwErM.js} +3 -3
  90. package/dist/cli/{run-C2Yg5MWt.js → run-BNoJKf5I.js} +40 -39
  91. package/dist/cli/{run-Wx_2Acgv.js → run-DiYX1XEa.js} +8 -8
  92. package/dist/cli/{seed-CDnL4Tnc.js → seed-C-Hu2n_E.js} +1 -1
  93. package/dist/cli/seed-Cm-c0BDd.js +1 -0
  94. package/dist/cli/{shared-BHbtUOvh.js → shared-D_CFi5di.js} +1 -1
  95. package/dist/cli/{skills-DM3oeIxY.js → skills-D98y0bSB.js} +1 -1
  96. package/dist/cli/{snapshot-CXgsUPGj.js → snapshot-BlQ4DDcJ.js} +9 -4
  97. package/dist/cli/{source-B6aMAoEK.js → source-CelMBQMj.js} +1 -1
  98. package/dist/cli/{spec-EO0TP84d.js → spec-BxcoGE0h.js} +1 -1
  99. package/dist/cli/{spec-BcYic005.js → spec-iBx1LcYO.js} +3 -3
  100. package/dist/cli/{sql-layout-CkxDNVEH.js → sql-layout-Dp4Rottt.js} +2 -2
  101. package/dist/cli/{stack-ClESAZYf.js → stack-B2slzrYH.js} +1 -1
  102. package/dist/cli/{stack-env-6hS-WEmh.js → stack-env-3ziggrU3.js} +1 -1
  103. package/dist/cli/{sync-pq6gmlhG.js → sync-BnORI43S.js} +4 -4
  104. package/dist/cli/{table-dyKddjwo.js → table-D6HUECKI.js} +1 -1
  105. package/dist/cli/{upgrade-Dp9p7A69.js → upgrade-CR6-WmIc.js} +5 -5
  106. package/dist/cli/{upgrade-BoHb4h9P.js → upgrade-fz92aCnh.js} +3 -3
  107. package/dist/cli/{version-CQHFm-ak.js → version-Dz8ZlOuh.js} +1 -1
  108. package/dist/client/index.d.ts +5 -5
  109. package/dist/client/native/index.d.ts +4 -4
  110. package/dist/{composite-CBRbvn5j.js → composite-B4qB6k31.js} +2 -2
  111. package/dist/config/index.d.ts +2 -2
  112. package/dist/config/index.js +4 -4
  113. package/dist/{config-r7njjNgh.js → config-B7g-HDis.js} +3 -3
  114. package/dist/{config-bqKaPjst.js → config-R0m0fBiD.js} +1 -1
  115. package/dist/{context-B4TsE2gY.d.ts → context-DWWoP1wK.d.ts} +13 -1
  116. package/dist/{controller-CtwAsnVV.d.ts → controller-Br9dGKGe.d.ts} +1 -1
  117. package/dist/{controller-qG-B1eDn.js → controller-W97g2WGG.js} +1 -1
  118. package/dist/create/index.d.ts +3 -3
  119. package/dist/create/index.js +3 -3
  120. package/dist/create/lite/index.d.ts +3 -3
  121. package/dist/create/lite/index.js +3 -3
  122. package/dist/delivery-events-DbL8IHIY.js +53 -0
  123. package/dist/edge/index.js +3 -3
  124. package/dist/{entitlements-Bw3eYGKJ.d.ts → entitlements-CBjm2lvD.d.ts} +1 -1
  125. package/dist/eve/index.js +1 -1
  126. package/dist/expo/index.js +3 -2
  127. package/dist/{field-errors-DkzFduux.d.ts → field-errors-CEjsMAgd.d.ts} +4 -4
  128. package/dist/{framework-DYEUraqt.js → framework-CqiZk89W.js} +1 -1
  129. package/dist/hono/index.js +2 -2
  130. package/dist/{index-CB66nl14.d.ts → index-Clyd2Goi.d.ts} +1 -1
  131. package/dist/{index-Cw5gGSP8.d.ts → index-D98bQs8a.d.ts} +7 -7
  132. package/dist/{index-BNgpz_BV.d.ts → index-DIdPoQtO.d.ts} +2 -2
  133. package/dist/{index-BxckmAFc.d.ts → index-I8YLxKq8.d.ts} +2 -2
  134. package/dist/{index-CBQT_nXf.d.ts → index-eRBuKtMt.d.ts} +2 -2
  135. package/dist/{index-BM6NmKSc.d.ts → index-uIU65iEn.d.ts} +6 -6
  136. package/dist/{instances-C7qUTjhJ.js → instances-DY_ORk5g.js} +2 -0
  137. package/dist/mapper/bin.js +5 -5
  138. package/dist/mcp/index.d.ts +1 -1
  139. package/dist/mcp/index.js +1 -1
  140. package/dist/mcp/sdk/index.js +1 -1
  141. package/dist/next/index.d.ts +155 -13
  142. package/dist/next/index.js +245 -52
  143. package/dist/{operations-CqmQrTKw.d.ts → operations-hm1Isvvs.d.ts} +1 -1
  144. package/dist/{options-C4LuqmdG.js → options-CF6EVF_G.js} +3 -1
  145. package/dist/{options-COo7_3MX.js → options-DSCW40_5.js} +3 -1
  146. package/dist/orpc/index.js +2 -1
  147. package/dist/otel/index.js +4 -4
  148. package/dist/{ports-6LBgr1Aa.d.ts → ports-DOrPTJzl.d.ts} +1 -1
  149. package/dist/powersync/index.d.ts +204 -4
  150. package/dist/powersync/index.js +361 -4
  151. package/dist/preset/index.d.ts +3 -3
  152. package/dist/preset/index.js +3 -3
  153. package/dist/{preset-DCdEnJj9.js → preset-CXhpPmPV.js} +2 -2
  154. package/dist/{project-C4NA_van.js → project-DJ9Uo0sT.js} +5 -5
  155. package/dist/{push-token-BXsrJ7W9.d.ts → push-token-B4vcIU4s.d.ts} +1 -1
  156. package/dist/query/index.d.ts +1 -1
  157. package/dist/query/index.js +1 -1
  158. package/dist/react/index.d.ts +5 -5
  159. package/dist/react/index.js +1 -1
  160. package/dist/react/native/index.d.ts +1 -1
  161. package/dist/react/server.d.ts +5 -5
  162. package/dist/react/server.js +1 -1
  163. package/dist/{react-CcrQQl0_.js → react-mdVjpewL.js} +2 -2
  164. package/dist/react-router/index.js +2 -2
  165. package/dist/realtime/index.d.ts +3 -3
  166. package/dist/{record-type-DRbnlj5q.js → record-type-BEUyEsFx.js} +2 -2
  167. package/dist/records/index.d.ts +5 -5
  168. package/dist/records/index.js +3 -3
  169. package/dist/{replicas-Dyoh3CEg.js → refresh-DLBgnxjL.js} +51 -1
  170. package/dist/{resolved-names-iLBOUaib.js → resolved-names-kMRjmSIy.js} +1 -1
  171. package/dist/{runtime-CoKxZibd.js → runtime-LRJM7UqY.js} +19 -20
  172. package/dist/server/index.d.ts +3 -3
  173. package/dist/server/index.js +4 -4
  174. package/dist/sign-in-BzihC_8k.d.ts +50 -0
  175. package/dist/{sign-in-NO7LWlw4.js → sign-in-CuZ1Ag7O.js} +136 -26
  176. package/dist/solid/index.d.ts +5 -5
  177. package/dist/solid-start/index.js +2 -2
  178. package/dist/spec/index.js +1 -1
  179. package/dist/sql/index.d.ts +4 -4
  180. package/dist/sql/index.js +3 -3
  181. package/dist/{sql-CoBySj2F.js → sql-DHp0L7zK.js} +680 -333
  182. package/dist/ssr/index.d.ts +1 -1
  183. package/dist/svelte/index.d.ts +5 -5
  184. package/dist/sveltekit/index.js +2 -2
  185. package/dist/tanstack-start/index.js +2 -2
  186. package/dist/{tenant-Ded341Qz.d.ts → tenant-FfgNhd5x.d.ts} +1 -1
  187. package/dist/testing/index.d.ts +13 -4
  188. package/dist/testing/index.js +17 -15
  189. package/dist/{timeline-DvXtXq5q.d.ts → timeline-DqEoD8bb.d.ts} +1 -1
  190. package/dist/{timeline--VU3A1e4.js → timeline-Dz3hO2I6.js} +1 -1
  191. package/dist/{topic-XDdKzlrn.d.ts → topic-BaUElNw2.d.ts} +1 -1
  192. package/dist/{types-BFwB-E1j.d.ts → types-CMN0h_Ix.d.ts} +2 -2
  193. package/dist/vue/index.d.ts +5 -5
  194. package/dist/{watch-topic-DpN_GEoS.d.ts → watch-topic-BabDTZ-L.d.ts} +1 -1
  195. package/dist/workflow-sdk/world/index.js +2 -2
  196. package/dist/{workflow-sdk-CaEw822d.js → workflow-sdk-DJJkP0dT.js} +47 -8
  197. package/dist/yjs/index.d.ts +1 -1
  198. package/package.json +1 -1
  199. package/schemas/config-v1.json +10 -1
  200. package/schemas/doctor-report-v1.json +2 -0
  201. package/skills/better-supabase/references/ui-recipes.md +524 -295
  202. package/skills/better-supabase-api/references/powersync.md +16 -0
  203. package/skills/better-supabase-auth/SKILL.md +11 -1
  204. package/dist/cli/add-CwhrRJz5.js +0 -1
  205. package/dist/cli/env-uqfUbUzk.js +0 -1
  206. package/dist/cli/powersync-CbYxLsjv.js +0 -1
  207. package/dist/cli/seed-BOun22-k.js +0 -1
  208. package/dist/sign-in-CfwJAJJL.d.ts +0 -24
@@ -368,7 +368,7 @@ import {
368
368
  } from "@/components/ui/dialog";
369
369
  import { Input } from "@/components/ui/input";
370
370
  import { useCommandSearch } from "@/hooks/use-search";
371
- import { Link } from "@/i18n/navigation";
371
+ import { Link, toAppHref } from "@/i18n/navigation";
372
372
  import { blockConfig } from "@/lib/supabase/blocks.generated";
373
373
 
374
374
  /** The API schema `gen` wrote for the search block. */
@@ -449,7 +449,7 @@ export function CommandSearch() {
449
449
  {group.items.map((item) => (
450
450
  <li key={`${item.subjectType}:${item.subjectId}`}>
451
451
  <Link
452
- href={item.url ?? "/"}
452
+ href={toAppHref(item.url)}
453
453
  onClick={() => void search.select(item)}
454
454
  className="block rounded-md px-2 py-1.5 outline-none hover:bg-muted focus-visible:bg-muted"
455
455
  >
@@ -616,7 +616,7 @@ import { Progress } from "@/components/ui/progress";
616
616
  import { Skeleton } from "@/components/ui/skeleton";
617
617
  import { gettingStarted } from "@/features/onboarding/checklist";
618
618
  import { useOnboarding } from "@/hooks/use-onboarding";
619
- import { Link } from "@/i18n/navigation";
619
+ import { Link, toAppHref } from "@/i18n/navigation";
620
620
  import { useAuth } from "@/lib/hooks";
621
621
  import { blockConfig } from "@/lib/supabase/blocks.generated";
622
622
 
@@ -684,7 +684,7 @@ export function OnboardingCard() {
684
684
  </span>
685
685
  {step.completed ? null : (
686
686
  <Link
687
- href={step.href ?? "/"}
687
+ href={toAppHref(step.href)}
688
688
  className={buttonVariants({ variant: "outline", size: "sm" })}
689
689
  >
690
690
  {t("Start")}
@@ -1158,18 +1158,31 @@ npx shadcn add @better-supabase/use-organizations
1158
1158
  ```
1159
1159
 
1160
1160
  ```tsx title="apps/examples/expo-powersync/src/components/organization-switcher.tsx"
1161
+ import type { OrganizationMembership } from "better-supabase/blocks/organizations";
1162
+
1161
1163
  import { ActivityIndicator, Pressable, Text, View } from "react-native";
1162
1164
 
1165
+ import type { OrganizationSource } from "../hooks/use-organizations";
1166
+
1163
1167
  import { useOrganizations } from "../hooks/use-organizations";
1164
1168
  import { API_SCHEMA } from "../lib/blocks";
1165
1169
 
1166
1170
  /**
1167
1171
  * The caller's organizations. Pressing one switches to it, refreshes the
1168
- * session so the token carries the new tenant, and loads the list again.
1172
+ * session so the token carries the new tenant, and loads the list again. `load`
1173
+ * reads them elsewhere, such as from the PowerSync database.
1169
1174
  */
1170
- export function OrganizationSwitcher() {
1175
+ export function OrganizationSwitcher({
1176
+ load,
1177
+ }: {
1178
+ readonly load?: OrganizationSource<OrganizationMembership>;
1179
+ }) {
1171
1180
  const { organizations, activeId, switching, error, switchTo } =
1172
- useOrganizations({ schema: API_SCHEMA });
1181
+ useOrganizations(
1182
+ load === undefined
1183
+ ? { schema: API_SCHEMA }
1184
+ : { schema: API_SCHEMA, load },
1185
+ );
1173
1186
 
1174
1187
  if (organizations === undefined) {
1175
1188
  return <ActivityIndicator />;
@@ -2163,24 +2176,47 @@ An organization's members with their roles, where a role change shows at once an
2163
2176
  Web, with shadcn components:
2164
2177
 
2165
2178
  ```bash
2166
- npx shadcn add avatar button select table
2179
+ npx shadcn add avatar badge button empty input select
2167
2180
  ```
2168
2181
 
2169
2182
  ```bash
2170
2183
  npx shadcn add @better-supabase/use-organizations
2171
2184
  ```
2172
2185
 
2173
- ```tsx title="apps/examples/nextjs/src/features/organization/components/member-table.tsx"
2186
+ ```tsx title="apps/examples/nextjs/src/features/members/components/member-table.tsx"
2174
2187
  "use client";
2175
2188
 
2189
+ import type { CellContext, ColumnDef } from "@tanstack/react-table";
2190
+
2191
+ import { useTable } from "@tanstack/react-table";
2176
2192
  import { DbException } from "better-supabase";
2177
2193
  import { UserMinusIcon } from "lucide-react";
2178
2194
  import { useExtracted, useFormatter } from "next-intl";
2195
+ import { createContext, use, useCallback, useMemo, useState } from "react";
2179
2196
  import { toast } from "sonner";
2180
2197
  import * as v from "valibot";
2181
2198
 
2199
+ import type { DataGridFeatures } from "@/components/reui/data-grid/data-grid";
2200
+ import type { Member } from "@/features/organization/organization-queries";
2201
+
2202
+ import {
2203
+ DataGrid,
2204
+ DataGridContainer,
2205
+ dataGridFeatures,
2206
+ } from "@/components/reui/data-grid/data-grid";
2207
+ import { DataGridScrollArea } from "@/components/reui/data-grid/data-grid-scroll-area";
2208
+ import { DataGridTable } from "@/components/reui/data-grid/data-grid-table";
2182
2209
  import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar";
2210
+ import { Badge } from "@/components/ui/badge";
2183
2211
  import { Button } from "@/components/ui/button";
2212
+ import {
2213
+ Empty,
2214
+ EmptyContent,
2215
+ EmptyDescription,
2216
+ EmptyHeader,
2217
+ EmptyTitle,
2218
+ } from "@/components/ui/empty";
2219
+ import { Input } from "@/components/ui/input";
2184
2220
  import {
2185
2221
  Select,
2186
2222
  SelectContent,
@@ -2189,26 +2225,18 @@ import {
2189
2225
  SelectValue,
2190
2226
  } from "@/components/ui/select";
2191
2227
  import {
2192
- Table,
2193
- TableBody,
2194
- TableCell,
2195
- TableHead,
2196
- TableHeader,
2197
- TableRow,
2198
- } from "@/components/ui/table";
2228
+ loadMembers,
2229
+ memberChanged,
2230
+ } from "@/features/organization/organization-actions";
2231
+ import { useRoleLabel } from "@/features/organization/use-role-label";
2199
2232
  import { RoleBadge } from "@/features/user/components/role-badge";
2200
- import { assignableRoles } from "@/features/user/user-permissions";
2201
2233
  import { useMembers } from "@/hooks/use-organizations";
2234
+ import { Link } from "@/i18n/navigation";
2202
2235
  import { Role } from "@/lib/claims";
2203
2236
  import { initials } from "@/lib/initials";
2204
2237
  import { blockConfig } from "@/lib/supabase/blocks.generated";
2205
2238
  import { useErrorMessage } from "@/lib/use-error-message";
2206
2239
 
2207
- import type { Member } from "../organization-queries";
2208
-
2209
- import { loadMembers, memberChanged } from "../organization-actions";
2210
- import { useRoleLabel } from "../use-role-label";
2211
-
2212
2240
  async function loadOrganizationMembers(): Promise<readonly Member[]> {
2213
2241
  const result = await loadMembers({});
2214
2242
 
@@ -2219,29 +2247,203 @@ async function loadOrganizationMembers(): Promise<readonly Member[]> {
2219
2247
  return result.data;
2220
2248
  }
2221
2249
 
2250
+ /** A team as the members table shows it: its name and who is on it. */
2251
+ export interface MemberTeam {
2252
+ readonly id: string;
2253
+ readonly name: string;
2254
+ readonly memberIds: readonly string[];
2255
+ }
2256
+
2257
+ type MemberRow = Member & {
2258
+ readonly teams: readonly MemberTeam[];
2259
+ readonly you: boolean;
2260
+ /** The roles the caller may pick here, empty when the role is fixed. */
2261
+ readonly roleChoices: readonly Role[];
2262
+ readonly removable: boolean;
2263
+ readonly busy: boolean;
2264
+ };
2265
+
2266
+ type MemberCell = CellContext<DataGridFeatures, MemberRow>;
2267
+
2268
+ const ALL_ROLES = "all";
2269
+
2270
+ function MemberCellView({ row }: MemberCell) {
2271
+ const t = useExtracted("members");
2272
+ const member = row.original;
2273
+
2274
+ return (
2275
+ <div className="flex items-center gap-3">
2276
+ <Avatar className="size-8">
2277
+ {member.avatarUrl ? (
2278
+ <AvatarImage src={member.avatarUrl} alt="" />
2279
+ ) : null}
2280
+ <AvatarFallback>{initials(member.name, member.email)}</AvatarFallback>
2281
+ </Avatar>
2282
+ <div className="grid min-w-0 leading-tight">
2283
+ <Link
2284
+ href={`/settings/members/${member.userId}`}
2285
+ className="truncate font-medium hover:underline"
2286
+ >
2287
+ {member.name ?? member.email}
2288
+ {member.you ? (
2289
+ <span className="font-normal text-muted-foreground">
2290
+ {" "}
2291
+ ({t("you")})
2292
+ </span>
2293
+ ) : null}
2294
+ </Link>
2295
+ <span className="truncate text-xs text-muted-foreground">
2296
+ {member.email}
2297
+ </span>
2298
+ </div>
2299
+ </div>
2300
+ );
2301
+ }
2302
+
2303
+ function TeamsCell({ row }: MemberCell) {
2304
+ const { teams } = row.original;
2305
+
2306
+ if (teams.length === 0) {
2307
+ return <span className="text-muted-foreground">–</span>;
2308
+ }
2309
+
2310
+ return (
2311
+ <div className="flex flex-wrap gap-1">
2312
+ {teams.map((team) => (
2313
+ <Badge key={team.id} variant="outline">
2314
+ {team.name}
2315
+ </Badge>
2316
+ ))}
2317
+ </div>
2318
+ );
2319
+ }
2320
+
2321
+ function JoinedCell({ row }: MemberCell) {
2322
+ const format = useFormatter();
2323
+ const { joinedAt } = row.original;
2324
+
2325
+ return (
2326
+ <span className="text-muted-foreground tabular-nums">
2327
+ {joinedAt
2328
+ ? format.dateTime(new Date(joinedAt), { dateStyle: "medium" })
2329
+ : "–"}
2330
+ </span>
2331
+ );
2332
+ }
2333
+
2334
+ interface MemberActions {
2335
+ readonly changeRole: (member: Member, role: Role) => Promise<void>;
2336
+ readonly removeMember: (member: Member) => Promise<void>;
2337
+ }
2338
+
2339
+ const MemberActionsContext = createContext<MemberActions | null>(null);
2340
+
2341
+ function useMemberActions(): MemberActions {
2342
+ const actions = use(MemberActionsContext);
2343
+
2344
+ if (actions === null) {
2345
+ throw new Error("Render member cells inside <MemberTable>.");
2346
+ }
2347
+
2348
+ return actions;
2349
+ }
2350
+
2351
+ function RoleCell({ row }: MemberCell) {
2352
+ const t = useExtracted("members");
2353
+ const roleLabel = useRoleLabel();
2354
+ const { changeRole } = useMemberActions();
2355
+ const member = row.original;
2356
+
2357
+ if (member.roleChoices.length === 0) {
2358
+ return <RoleBadge role={member.role} />;
2359
+ }
2360
+
2361
+ const items = member.roleChoices.map((role) => ({
2362
+ value: role,
2363
+ label: roleLabel(role),
2364
+ }));
2365
+
2366
+ return (
2367
+ <Select
2368
+ value={member.role}
2369
+ items={items}
2370
+ disabled={member.busy}
2371
+ onValueChange={(value) => {
2372
+ if (v.is(Role, value)) {
2373
+ void changeRole(member, value);
2374
+ }
2375
+ }}
2376
+ >
2377
+ <SelectTrigger size="sm" className="w-32" aria-label={t("Role")}>
2378
+ <SelectValue />
2379
+ </SelectTrigger>
2380
+ <SelectContent>
2381
+ {items.map((item) => (
2382
+ <SelectItem key={item.value} value={item.value}>
2383
+ {item.label}
2384
+ </SelectItem>
2385
+ ))}
2386
+ </SelectContent>
2387
+ </Select>
2388
+ );
2389
+ }
2390
+
2391
+ function ActionsCell({ row }: MemberCell) {
2392
+ const t = useExtracted("members");
2393
+ const { removeMember } = useMemberActions();
2394
+ const member = row.original;
2395
+
2396
+ if (!member.removable) {
2397
+ return null;
2398
+ }
2399
+
2400
+ return (
2401
+ <Button
2402
+ variant="ghost"
2403
+ size="icon-sm"
2404
+ disabled={member.busy}
2405
+ aria-label={t("Remove {name}", {
2406
+ name: member.name ?? member.email ?? "",
2407
+ })}
2408
+ onClick={() => {
2409
+ void removeMember(member);
2410
+ }}
2411
+ >
2412
+ <UserMinusIcon />
2413
+ </Button>
2414
+ );
2415
+ }
2416
+
2222
2417
  /**
2223
- * The organization's members. The server renders the rows; a role change shows
2224
- * at once and goes through `update_member_role` in the browser.
2418
+ * The organization's members in a ReUI data grid, with a search and a role
2419
+ * filter. The server renders the rows; a role change shows at once and goes
2420
+ * through `update_member_role` in the browser.
2225
2421
  */
2226
2422
  export function MemberTable({
2227
2423
  organizationId,
2228
2424
  initial,
2425
+ teams,
2229
2426
  currentUserId,
2230
- myRole,
2427
+ assignable,
2231
2428
  canUpdateRole,
2232
2429
  canRemove,
2233
2430
  }: {
2234
2431
  organizationId: string;
2235
2432
  initial: readonly Member[];
2433
+ teams: readonly MemberTeam[];
2236
2434
  currentUserId: string;
2237
- myRole: Role;
2435
+ assignable: readonly Role[];
2238
2436
  canUpdateRole: boolean;
2239
2437
  canRemove: boolean;
2240
2438
  }) {
2241
- const t = useExtracted("organization");
2439
+ const t = useExtracted("members");
2242
2440
  const roleLabel = useRoleLabel();
2243
2441
  const errorMessage = useErrorMessage();
2244
- const format = useFormatter();
2442
+ const [search, setSearch] = useState("");
2443
+
2444
+ const [roleFilter, setRoleFilter] = useState<Role | typeof ALL_ROLES>(
2445
+ ALL_ROLES,
2446
+ );
2245
2447
 
2246
2448
  const { members, pending, setRole, remove } = useMembers({
2247
2449
  organizationId,
@@ -2253,12 +2455,10 @@ export function MemberTable({
2253
2455
  },
2254
2456
  });
2255
2457
 
2256
- const assignable = assignableRoles(myRole);
2257
-
2258
- const roleItems = assignable.map((role) => ({
2259
- value: role,
2260
- label: roleLabel(role),
2261
- }));
2458
+ const filterItems = [
2459
+ { value: ALL_ROLES, label: t("All roles") },
2460
+ ...Role.options.map((role) => ({ value: role, label: roleLabel(role) })),
2461
+ ];
2262
2462
 
2263
2463
  // Nobody changes their own role or an owner's here; ownership moves by transfer.
2264
2464
  const editable = (member: Member) =>
@@ -2266,130 +2466,146 @@ export function MemberTable({
2266
2466
  member.role !== "owner" &&
2267
2467
  assignable.includes(member.role);
2268
2468
 
2269
- const busy = (member: Member) => pending.includes(member.userId);
2469
+ const changeRole = useCallback(
2470
+ async (member: Member, role: Role) => {
2471
+ const result = await setRole(member.userId, role);
2270
2472
 
2271
- const changeRole = async (member: Member, role: Role) => {
2272
- const result = await setRole(member.userId, role);
2473
+ if (result.ok) {
2474
+ toast.success(t("Role updated"));
2475
+ } else {
2476
+ toast.error(errorMessage(result.error));
2477
+ }
2478
+ },
2479
+ [setRole, t, errorMessage],
2480
+ );
2273
2481
 
2274
- if (result.ok) {
2275
- toast.success(t("Role updated"));
2276
- } else {
2277
- toast.error(errorMessage(result.error));
2278
- }
2279
- };
2482
+ const removeMember = useCallback(
2483
+ async (member: Member) => {
2484
+ const result = await remove(member.userId);
2280
2485
 
2281
- const removeMember = async (member: Member) => {
2282
- const result = await remove(member.userId);
2486
+ if (result.ok) {
2487
+ toast.success(t("Member removed"));
2488
+ } else {
2489
+ toast.error(errorMessage(result.error));
2490
+ }
2491
+ },
2492
+ [remove, t, errorMessage],
2493
+ );
2283
2494
 
2284
- if (result.ok) {
2285
- toast.success(t("Member removed"));
2286
- } else {
2287
- toast.error(errorMessage(result.error));
2288
- }
2495
+ const actions = useMemo(
2496
+ () => ({ changeRole, removeMember }),
2497
+ [changeRole, removeMember],
2498
+ );
2499
+
2500
+ const columns: ColumnDef<DataGridFeatures, MemberRow>[] = [
2501
+ { id: "member", header: t("Member"), cell: MemberCellView, size: 280 },
2502
+ { accessorKey: "role", header: t("Role"), cell: RoleCell, size: 150 },
2503
+ { id: "teams", header: t("Teams"), cell: TeamsCell, size: 200 },
2504
+ {
2505
+ accessorKey: "joinedAt",
2506
+ header: t("Joined"),
2507
+ cell: JoinedCell,
2508
+ size: 140,
2509
+ },
2510
+ { id: "actions", header: "", cell: ActionsCell, size: 56 },
2511
+ ];
2512
+
2513
+ const needle = search.trim().toLowerCase();
2514
+ const all = members ?? initial;
2515
+
2516
+ const data: MemberRow[] = all
2517
+ .filter(
2518
+ (member) =>
2519
+ (roleFilter === ALL_ROLES || member.role === roleFilter) &&
2520
+ (needle === "" ||
2521
+ [member.name, member.email].some((text) =>
2522
+ text?.toLowerCase().includes(needle),
2523
+ )),
2524
+ )
2525
+ .map((member) => ({
2526
+ ...member,
2527
+ teams: teams.filter((team) => team.memberIds.includes(member.userId)),
2528
+ you: member.userId === currentUserId,
2529
+ roleChoices: canUpdateRole && editable(member) ? assignable : [],
2530
+ removable: canRemove && editable(member),
2531
+ busy: pending.includes(member.userId),
2532
+ }));
2533
+
2534
+ const table = useTable({
2535
+ features: dataGridFeatures,
2536
+ columns,
2537
+ data,
2538
+ getRowId: (row) => row.userId,
2539
+ });
2540
+
2541
+ const clearFilters = () => {
2542
+ setSearch("");
2543
+ setRoleFilter(ALL_ROLES);
2289
2544
  };
2290
2545
 
2291
2546
  return (
2292
- <Table data-testid="members">
2293
- <TableHeader>
2294
- <TableRow>
2295
- <TableHead>{t("Member")}</TableHead>
2296
- <TableHead>{t("Role")}</TableHead>
2297
- <TableHead className="hidden sm:table-cell">{t("Joined")}</TableHead>
2298
- <TableHead className="w-10" />
2299
- </TableRow>
2300
- </TableHeader>
2301
- <TableBody>
2302
- {(members ?? initial).map((member) => (
2303
- <TableRow
2304
- key={member.userId}
2305
- aria-busy={busy(member) ? true : undefined}
2306
- className={busy(member) ? "opacity-50" : undefined}
2547
+ <MemberActionsContext value={actions}>
2548
+ <div className="flex flex-col gap-3">
2549
+ <div className="flex flex-wrap items-center gap-2">
2550
+ <Input
2551
+ type="search"
2552
+ className="w-56"
2553
+ value={search}
2554
+ placeholder={t("Search members")}
2555
+ aria-label={t("Search members")}
2556
+ onChange={(event) => {
2557
+ setSearch(event.target.value);
2558
+ }}
2559
+ />
2560
+ <Select
2561
+ value={roleFilter}
2562
+ items={filterItems}
2563
+ onValueChange={(value) => {
2564
+ setRoleFilter(v.is(Role, value) ? value : ALL_ROLES);
2565
+ }}
2307
2566
  >
2308
- <TableCell>
2309
- <div className="flex items-center gap-3">
2310
- <Avatar className="size-8">
2311
- {member.avatarUrl ? (
2312
- <AvatarImage src={member.avatarUrl} alt="" />
2313
- ) : null}
2314
- <AvatarFallback>
2315
- {initials(member.name, member.email)}
2316
- </AvatarFallback>
2317
- </Avatar>
2318
- <div className="grid leading-tight">
2319
- <span className="font-medium">
2320
- {member.name ?? member.email}
2321
- {member.userId === currentUserId ? (
2322
- <span className="font-normal text-muted-foreground">
2323
- {" "}
2324
- ({t("you")})
2325
- </span>
2326
- ) : null}
2327
- </span>
2328
- <span className="text-xs text-muted-foreground">
2329
- {member.email}
2330
- </span>
2331
- </div>
2332
- </div>
2333
- </TableCell>
2334
- <TableCell>
2335
- {canUpdateRole && editable(member) ? (
2336
- <Select
2337
- value={member.role}
2338
- items={roleItems}
2339
- disabled={busy(member)}
2340
- onValueChange={(value) => {
2341
- if (v.is(Role, value)) {
2342
- void changeRole(member, value);
2343
- }
2344
- }}
2345
- >
2346
- <SelectTrigger
2347
- size="sm"
2348
- className="w-32"
2349
- aria-label={t("Role")}
2350
- >
2351
- <SelectValue />
2352
- </SelectTrigger>
2353
- <SelectContent>
2354
- {roleItems.map((item) => (
2355
- <SelectItem key={item.value} value={item.value}>
2356
- {item.label}
2357
- </SelectItem>
2358
- ))}
2359
- </SelectContent>
2360
- </Select>
2361
- ) : (
2362
- <RoleBadge role={member.role} />
2363
- )}
2364
- </TableCell>
2365
- <TableCell className="hidden text-muted-foreground sm:table-cell">
2366
- {member.joinedAt
2367
- ? format.dateTime(new Date(member.joinedAt), {
2368
- dateStyle: "medium",
2369
- })
2370
- : "–"}
2371
- </TableCell>
2372
- <TableCell>
2373
- {canRemove && editable(member) ? (
2374
- <Button
2375
- variant="ghost"
2376
- size="icon-sm"
2377
- disabled={busy(member)}
2378
- aria-label={t("Remove {name}", {
2379
- name: member.name ?? member.email ?? "",
2380
- })}
2381
- onClick={() => {
2382
- void removeMember(member);
2383
- }}
2384
- >
2385
- <UserMinusIcon />
2386
- </Button>
2387
- ) : null}
2388
- </TableCell>
2389
- </TableRow>
2390
- ))}
2391
- </TableBody>
2392
- </Table>
2567
+ <SelectTrigger size="sm" className="w-36" aria-label={t("Role")}>
2568
+ <SelectValue />
2569
+ </SelectTrigger>
2570
+ <SelectContent>
2571
+ {filterItems.map((item) => (
2572
+ <SelectItem key={item.value} value={item.value}>
2573
+ {item.label}
2574
+ </SelectItem>
2575
+ ))}
2576
+ </SelectContent>
2577
+ </Select>
2578
+ </div>
2579
+ <div data-testid="members">
2580
+ <DataGrid
2581
+ table={table}
2582
+ recordCount={data.length}
2583
+ tableLayout={{ dense: true }}
2584
+ emptyMessage={
2585
+ <Empty>
2586
+ <EmptyHeader>
2587
+ <EmptyTitle>{t("No members match")}</EmptyTitle>
2588
+ <EmptyDescription>
2589
+ {t("Try another name or role.")}
2590
+ </EmptyDescription>
2591
+ </EmptyHeader>
2592
+ <EmptyContent>
2593
+ <Button size="sm" variant="outline" onClick={clearFilters}>
2594
+ {t("Clear filters")}
2595
+ </Button>
2596
+ </EmptyContent>
2597
+ </Empty>
2598
+ }
2599
+ >
2600
+ <DataGridContainer>
2601
+ <DataGridScrollArea>
2602
+ <DataGridTable />
2603
+ </DataGridScrollArea>
2604
+ </DataGridContainer>
2605
+ </DataGrid>
2606
+ </div>
2607
+ </div>
2608
+ </MemberActionsContext>
2393
2609
  );
2394
2610
  }
2395
2611
  ```
@@ -2492,7 +2708,7 @@ npx shadcn add button dialog field input select
2492
2708
  npx shadcn add @better-supabase/use-organizations
2493
2709
  ```
2494
2710
 
2495
- ```tsx title="apps/examples/nextjs/src/features/organization/components/invite-member-dialog.tsx"
2711
+ ```tsx title="apps/examples/nextjs/src/features/members/components/invite-member-dialog.tsx"
2496
2712
  "use client";
2497
2713
 
2498
2714
  import type { SubmitEvent } from "react";
@@ -2528,26 +2744,24 @@ import {
2528
2744
  SelectTrigger,
2529
2745
  SelectValue,
2530
2746
  } from "@/components/ui/select";
2531
- import { assignableRoles } from "@/features/user/user-permissions";
2747
+ import { invitationSent } from "@/features/organization/organization-actions";
2748
+ import { useInviteLink } from "@/features/organization/use-invite-link";
2749
+ import { useRoleLabel } from "@/features/organization/use-role-label";
2532
2750
  import { useInvitations } from "@/hooks/use-organizations";
2533
2751
  import { Role } from "@/lib/claims";
2534
2752
  import { blockConfig } from "@/lib/supabase/blocks.generated";
2535
2753
  import { useErrorMessage } from "@/lib/use-error-message";
2536
2754
 
2537
- import { invitationSent } from "../organization-actions";
2538
- import { useInviteLink } from "../use-invite-link";
2539
- import { useRoleLabel } from "../use-role-label";
2540
-
2541
2755
  /**
2542
2756
  * Invites a teammate through `invite_member` in the browser, then shows the
2543
2757
  * accept link: the example has no mailer.
2544
2758
  */
2545
2759
  export function InviteMemberDialog({
2546
2760
  organizationId,
2547
- myRole,
2761
+ assignable,
2548
2762
  }: {
2549
2763
  organizationId: string;
2550
- myRole: Role;
2764
+ assignable: readonly Role[];
2551
2765
  }) {
2552
2766
  const t = useExtracted("organization");
2553
2767
  const fieldId = useId();
@@ -2558,7 +2772,7 @@ export function InviteMemberDialog({
2558
2772
  const [email, setEmail] = useState("");
2559
2773
  const [role, setRole] = useState<Role>("member");
2560
2774
 
2561
- const roles = assignableRoles(myRole).map((each) => ({
2775
+ const roles = assignable.map((each) => ({
2562
2776
  value: each,
2563
2777
  label: roleLabel(each),
2564
2778
  }));
@@ -7405,6 +7619,7 @@ import {
7405
7619
  EmptyTitle,
7406
7620
  } from "@/components/ui/empty";
7407
7621
  import { Skeleton } from "@/components/ui/skeleton";
7622
+ import { env } from "@/env";
7408
7623
  import { useSupabase } from "@/lib/hooks";
7409
7624
  import { blockConfig } from "@/lib/supabase/blocks.generated";
7410
7625
 
@@ -7415,7 +7630,7 @@ import { blockConfig } from "@/lib/supabase/blocks.generated";
7415
7630
  const WORKER_URL = "/push-sw.js";
7416
7631
  const PUSH_GUIDE = "https://bettersupabase.com/docs/blocks/push";
7417
7632
 
7418
- const VAPID_PUBLIC_KEY = process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY;
7633
+ const VAPID_PUBLIC_KEY = env.NEXT_PUBLIC_VAPID_PUBLIC_KEY;
7419
7634
 
7420
7635
  type PushState =
7421
7636
  | { readonly kind: "checking" }
@@ -9160,7 +9375,7 @@ import { useExtracted } from "next-intl";
9160
9375
  import { Button } from "@/components/ui/button";
9161
9376
  import { Skeleton } from "@/components/ui/skeleton";
9162
9377
  import { useSubject } from "@/hooks/use-subjects";
9163
- import { Link } from "@/i18n/navigation";
9378
+ import { Link, toAppHref } from "@/i18n/navigation";
9164
9379
 
9165
9380
  /**
9166
9381
  * A link to any subject in `config.subjects`, titled and routed by
@@ -9207,7 +9422,7 @@ export function SubjectLink({ subject }: { subject: RecordRef }) {
9207
9422
  <span className="truncate text-sm font-medium">{title}</span>
9208
9423
  ) : (
9209
9424
  <Link
9210
- href={resolved.url}
9425
+ href={toAppHref(resolved.url)}
9211
9426
  className="truncate text-sm font-medium underline-offset-4 transition-colors hover:underline"
9212
9427
  >
9213
9428
  {title}
@@ -9240,7 +9455,7 @@ import { useExtracted } from "next-intl";
9240
9455
  import { Badge } from "@/components/reui/badge";
9241
9456
  import { Skeleton } from "@/components/ui/skeleton";
9242
9457
  import { useSubject } from "@/hooks/use-subjects";
9243
- import { Link } from "@/i18n/navigation";
9458
+ import { Link, toAppHref } from "@/i18n/navigation";
9244
9459
 
9245
9460
  /**
9246
9461
  * A compact badge for a subject: its type and title, linking to its page. Rows
@@ -9269,7 +9484,7 @@ export function SubjectChip({ subject }: { subject: RecordRef }) {
9269
9484
  <Badge
9270
9485
  variant="outline"
9271
9486
  className="transition-colors hover:bg-accent"
9272
- render={<Link href={resolved.url} />}
9487
+ render={<Link href={toAppHref(resolved.url)} />}
9273
9488
  >
9274
9489
  {content}
9275
9490
  </Badge>
@@ -9556,7 +9771,7 @@ npx shadcn add alert badge button card empty skeleton
9556
9771
  * with and whether they must sign in with SSO.
9557
9772
  */
9558
9773
  export async function SsoSettings() {
9559
- if (!can(await getSession(), "sso.manage")) {
9774
+ if (!can(await getPermissions(), "sso.manage")) {
9560
9775
  forbidden();
9561
9776
  }
9562
9777
 
@@ -9761,7 +9976,7 @@ npx shadcn add alert badge button card empty skeleton table
9761
9976
  * back to the previous one when the duration runs out.
9762
9977
  */
9763
9978
  export async function AccessRequestsInbox() {
9764
- if (!can(await getSession(), "access_requests.create")) {
9979
+ if (!can(await getPermissions(), "access_requests.create")) {
9765
9980
  forbidden();
9766
9981
  }
9767
9982
 
@@ -11339,13 +11554,13 @@ export async function ContactDetail({
11339
11554
  }: {
11340
11555
  params: Promise<{ id: string }>;
11341
11556
  }) {
11342
- const [{ id }, session, t] = await Promise.all([
11557
+ const [{ id }, t, permissions] = await Promise.all([
11343
11558
  params,
11344
- getSession(),
11345
11559
  getExtracted("crm"),
11560
+ getPermissions(),
11346
11561
  ]);
11347
11562
 
11348
- if (!can(session, "parties.read")) {
11563
+ if (!can(permissions, "parties.read")) {
11349
11564
  forbidden();
11350
11565
  }
11351
11566
 
@@ -11476,7 +11691,7 @@ export async function ContactDetail({
11476
11691
  ))}
11477
11692
  </ul>
11478
11693
  )}
11479
- {can(session, "parties.write") ? (
11694
+ {can(permissions, "parties.write") ? (
11480
11695
  <LinkPersonForm
11481
11696
  companyId={contact.id}
11482
11697
  people={contact.candidates.map((person) => ({
@@ -11527,9 +11742,12 @@ npx shadcn add card empty skeleton
11527
11742
  * pipeline. Dragging a deal saves its new stage through `moveDeal`.
11528
11743
  */
11529
11744
  export async function DealBoard() {
11530
- const [session, t] = await Promise.all([getSession(), getExtracted("crm")]);
11745
+ const [t, permissions] = await Promise.all([
11746
+ getExtracted("crm"),
11747
+ getPermissions(),
11748
+ ]);
11531
11749
 
11532
- if (!can(session, "deals.read")) {
11750
+ if (!can(permissions, "deals.read")) {
11533
11751
  forbidden();
11534
11752
  }
11535
11753
 
@@ -11555,7 +11773,7 @@ export async function DealBoard() {
11555
11773
  <CardDescription>
11556
11774
  {t("Drag a deal to another stage to move it.")}
11557
11775
  </CardDescription>
11558
- {pipeline && can(session, "deals.write") ? (
11776
+ {pipeline && can(permissions, "deals.write") ? (
11559
11777
  <CardAction>
11560
11778
  <CreateDealDialog pipelineId={pipeline.id} stages={openStages} />
11561
11779
  </CardAction>
@@ -11572,14 +11790,14 @@ export async function DealBoard() {
11572
11790
  </EmptyMedia>
11573
11791
  <EmptyTitle>{t("No pipeline yet")}</EmptyTitle>
11574
11792
  <EmptyDescription>
11575
- {can(session, "pipelines.manage")
11793
+ {can(permissions, "pipelines.manage")
11576
11794
  ? t(
11577
11795
  "Start with six stages, from qualified to closed won or lost.",
11578
11796
  )
11579
11797
  : t("Ask an admin to create the sales pipeline.")}
11580
11798
  </EmptyDescription>
11581
11799
  </EmptyHeader>
11582
- {can(session, "pipelines.manage") ? (
11800
+ {can(permissions, "pipelines.manage") ? (
11583
11801
  <EmptyContent>
11584
11802
  <CreatePipelineButton />
11585
11803
  </EmptyContent>
@@ -11592,7 +11810,7 @@ export async function DealBoard() {
11592
11810
  .join(",")}
11593
11811
  stages={board.data.stages}
11594
11812
  deals={board.data.deals}
11595
- canMove={can(session, "deals.write")}
11813
+ canMove={can(permissions, "deals.write")}
11596
11814
  />
11597
11815
  )}
11598
11816
  </CardContent>
@@ -11627,10 +11845,10 @@ const stepIcons = {
11627
11845
 
11628
11846
  /** Render inside `<Suspense>`: the organization's sequences and their steps. */
11629
11847
  export async function SequenceBuilder() {
11630
- const [view, session, t] = await Promise.all([
11848
+ const [view, t, permissions] = await Promise.all([
11631
11849
  getSequences(),
11632
- getSession(),
11633
11850
  getExtracted("sequences"),
11851
+ getPermissions(),
11634
11852
  ]);
11635
11853
 
11636
11854
  if (view.kind === "no-organization") {
@@ -11654,7 +11872,7 @@ export async function SequenceBuilder() {
11654
11872
  );
11655
11873
  }
11656
11874
 
11657
- const manage = can(session, "sequences.manage");
11875
+ const manage = can(permissions, "sequences.manage");
11658
11876
 
11659
11877
  if (view.data.length === 0) {
11660
11878
  return (
@@ -11810,13 +12028,13 @@ export async function ActivityTimeline({
11810
12028
  }: {
11811
12029
  subject: { type: ContactKind; id: string };
11812
12030
  }) {
11813
- const [session, t, format] = await Promise.all([
11814
- getSession(),
12031
+ const [t, format, permissions] = await Promise.all([
11815
12032
  getExtracted("crm"),
11816
12033
  getFormatter(),
12034
+ getPermissions(),
11817
12035
  ]);
11818
12036
 
11819
- if (!can(session, "engagements.read")) {
12037
+ if (!can(permissions, "engagements.read")) {
11820
12038
  return null;
11821
12039
  }
11822
12040
 
@@ -11826,7 +12044,7 @@ export async function ActivityTimeline({
11826
12044
  return null;
11827
12045
  }
11828
12046
 
11829
- const canLog = can(session, "engagements.write");
12047
+ const canLog = can(permissions, "engagements.write");
11830
12048
 
11831
12049
  const types = new Map([
11832
12050
  ["call", t("Call")],
@@ -11941,14 +12159,14 @@ export async function QuoteBuilder({
11941
12159
  }: {
11942
12160
  params: Promise<{ id: string }>;
11943
12161
  }) {
11944
- const [{ id }, session, t, locale] = await Promise.all([
12162
+ const [{ id }, t, locale, permissions] = await Promise.all([
11945
12163
  params,
11946
- getSession(),
11947
12164
  getExtracted("crm"),
11948
12165
  getLocale(),
12166
+ getPermissions(),
11949
12167
  ]);
11950
12168
 
11951
- if (!can(session, "quotes.read")) {
12169
+ if (!can(permissions, "quotes.read")) {
11952
12170
  forbidden();
11953
12171
  }
11954
12172
 
@@ -11968,7 +12186,7 @@ export async function QuoteBuilder({
11968
12186
  notFound();
11969
12187
  }
11970
12188
 
11971
- const canWrite = can(session, "quotes.write");
12189
+ const canWrite = can(permissions, "quotes.write");
11972
12190
 
11973
12191
  const editable =
11974
12192
  canWrite &&
@@ -12103,14 +12321,14 @@ npx shadcn add badge card empty progress skeleton
12103
12321
  * are.
12104
12322
  */
12105
12323
  export async function TargetsProgress() {
12106
- const [session, t, format, locale] = await Promise.all([
12107
- getSession(),
12324
+ const [t, format, locale, permissions] = await Promise.all([
12108
12325
  getExtracted("crm"),
12109
12326
  getFormatter(),
12110
12327
  getLocale(),
12328
+ getPermissions(),
12111
12329
  ]);
12112
12330
 
12113
- if (!can(session, "targets.read")) {
12331
+ if (!can(permissions, "targets.read")) {
12114
12332
  return null;
12115
12333
  }
12116
12334
 
@@ -12120,7 +12338,7 @@ export async function TargetsProgress() {
12120
12338
  return null;
12121
12339
  }
12122
12340
 
12123
- const canManage = can(session, "targets.manage");
12341
+ const canManage = can(permissions, "targets.manage");
12124
12342
 
12125
12343
  const amountOf = (target: TargetRow, value: bigint) =>
12126
12344
  target.currency === null
@@ -12711,7 +12929,7 @@ export function WorkItemGrid({
12711
12929
 
12712
12930
  const go = (next: WorkGridQuery) => {
12713
12931
  startTransition(() => {
12714
- router.replace(`${pathname}${workGridSearch(next)}`);
12932
+ router.replace(withSearch(pathname, workGridSearch(next)));
12715
12933
  });
12716
12934
  };
12717
12935
 
@@ -13049,13 +13267,13 @@ npx shadcn add alert badge button card empty skeleton table
13049
13267
  * caller is an approver of the current step.
13050
13268
  */
13051
13269
  export async function ApprovalsQueue() {
13052
- const [session, t, format] = await Promise.all([
13053
- getSession(),
13270
+ const [t, format, permissions] = await Promise.all([
13054
13271
  getExtracted("approvals"),
13055
13272
  getFormatter(),
13273
+ getPermissions(),
13056
13274
  ]);
13057
13275
 
13058
- if (!can(session, "approvals.read")) {
13276
+ if (!can(permissions, "approvals.read")) {
13059
13277
  forbidden();
13060
13278
  }
13061
13279
 
@@ -13065,8 +13283,8 @@ export async function ApprovalsQueue() {
13065
13283
  return null;
13066
13284
  }
13067
13285
 
13068
- const canRequest = can(session, "approvals.request");
13069
- const canDecide = can(session, "approvals.manage");
13286
+ const canRequest = can(permissions, "approvals.request");
13287
+ const canDecide = can(permissions, "approvals.manage");
13070
13288
  const customers = queue.kind === "ok" ? queue.data.customers : [];
13071
13289
 
13072
13290
  const actionLabel = (action: string) =>
@@ -13300,7 +13518,7 @@ export async function MyWorkList() {
13300
13518
  <span className="truncate">{row.title}</span>
13301
13519
  ) : (
13302
13520
  <Link
13303
- href={row.url}
13521
+ href={toAppHref(row.url)}
13304
13522
  className="truncate font-medium underline-offset-4 transition-colors hover:underline"
13305
13523
  >
13306
13524
  {row.title}
@@ -13619,13 +13837,13 @@ export async function CustomFieldsEditor({
13619
13837
  }: {
13620
13838
  searchParams: Promise<Record<string, string | string[] | undefined>>;
13621
13839
  }) {
13622
- const [session, t, params] = await Promise.all([
13623
- getSession(),
13840
+ const [t, params, permissions] = await Promise.all([
13624
13841
  getExtracted("custom-fields"),
13625
13842
  searchParams,
13843
+ getPermissions(),
13626
13844
  ]);
13627
13845
 
13628
- if (!can(session, "custom_fields.read")) {
13846
+ if (!can(permissions, "custom_fields.read")) {
13629
13847
  forbidden();
13630
13848
  }
13631
13849
 
@@ -13637,7 +13855,7 @@ export async function CustomFieldsEditor({
13637
13855
  return null;
13638
13856
  }
13639
13857
 
13640
- const canManage = can(session, "custom_fields.manage");
13858
+ const canManage = can(permissions, "custom_fields.manage");
13641
13859
 
13642
13860
  return (
13643
13861
  <Card data-recipe="custom-fields-editor">
@@ -14285,12 +14503,12 @@ npx shadcn add card empty skeleton
14285
14503
  * with `employees.view_sensitive`.
14286
14504
  */
14287
14505
  export async function EmployeeDirectory() {
14288
- const [session, t] = await Promise.all([
14289
- getSession(),
14506
+ const [t, permissions] = await Promise.all([
14290
14507
  getExtracted("people"),
14508
+ getPermissions(),
14291
14509
  ]);
14292
14510
 
14293
- if (!can(session, "employees.read")) {
14511
+ if (!can(permissions, "employees.read")) {
14294
14512
  forbidden();
14295
14513
  }
14296
14514
 
@@ -14300,8 +14518,8 @@ export async function EmployeeDirectory() {
14300
14518
  return null;
14301
14519
  }
14302
14520
 
14303
- const canWrite = can(session, "employees.write");
14304
- const canViewSensitive = can(session, "employees.view_sensitive");
14521
+ const canWrite = can(permissions, "employees.write");
14522
+ const canViewSensitive = can(permissions, "employees.view_sensitive");
14305
14523
 
14306
14524
  const managers =
14307
14525
  directory.kind === "ok"
@@ -14380,13 +14598,13 @@ export async function HiringBoard({
14380
14598
  }: {
14381
14599
  searchParams: Promise<Record<string, string | string[] | undefined>>;
14382
14600
  }) {
14383
- const [session, t, query] = await Promise.all([
14384
- getSession(),
14601
+ const [t, query, permissions] = await Promise.all([
14385
14602
  getExtracted("people"),
14386
14603
  searchParams,
14604
+ getPermissions(),
14387
14605
  ]);
14388
14606
 
14389
- if (!can(session, "hiring.read")) {
14607
+ if (!can(permissions, "hiring.read")) {
14390
14608
  forbidden();
14391
14609
  }
14392
14610
 
@@ -14396,8 +14614,8 @@ export async function HiringBoard({
14396
14614
  return null;
14397
14615
  }
14398
14616
 
14399
- const canManage = can(session, "hiring.manage");
14400
- const canWrite = can(session, "hiring.write");
14617
+ const canManage = can(permissions, "hiring.manage");
14618
+ const canWrite = can(permissions, "hiring.write");
14401
14619
  const jobs = board.kind === "ok" ? board.data.jobs : [];
14402
14620
  const job = jobs.find((item) => item.id === query["job"]) ?? jobs[0];
14403
14621
 
@@ -14533,15 +14751,15 @@ export async function Timesheet({
14533
14751
  }: {
14534
14752
  searchParams: Promise<Record<string, string | string[] | undefined>>;
14535
14753
  }) {
14536
- const [session, t, format, query] = await Promise.all([
14537
- getSession(),
14754
+ const [t, format, query, permissions] = await Promise.all([
14538
14755
  getExtracted("people"),
14539
14756
  getFormatter(),
14540
14757
  searchParams,
14758
+ getPermissions(),
14541
14759
  connection(),
14542
14760
  ]);
14543
14761
 
14544
- if (!can(session, "time_tracking.track")) {
14762
+ if (!can(permissions, "time_tracking.track")) {
14545
14763
  forbidden();
14546
14764
  }
14547
14765
 
@@ -14746,19 +14964,19 @@ export async function DispatchBoard({
14746
14964
  }: {
14747
14965
  searchParams: Promise<Record<string, string | string[] | undefined>>;
14748
14966
  }) {
14749
- const [session, t, format, query] = await Promise.all([
14750
- getSession(),
14967
+ const [t, format, query, permissions] = await Promise.all([
14751
14968
  getExtracted("field"),
14752
14969
  getFormatter(),
14753
14970
  searchParams,
14971
+ getPermissions(),
14754
14972
  connection(),
14755
14973
  ]);
14756
14974
 
14757
- if (!can(session, "dispatch.read")) {
14975
+ if (!can(permissions, "dispatch.read")) {
14758
14976
  forbidden();
14759
14977
  }
14760
14978
 
14761
- const manage = can(session, "dispatch.manage");
14979
+ const manage = can(permissions, "dispatch.manage");
14762
14980
  const monday = mondayOf(query["week"]);
14763
14981
  const board = await settle(() => loadDispatchWeek(monday.toString()));
14764
14982
 
@@ -14963,15 +15181,15 @@ export async function TechnicianDay({
14963
15181
  }: {
14964
15182
  searchParams: Promise<Record<string, string | string[] | undefined>>;
14965
15183
  }) {
14966
- const [session, t, format, query] = await Promise.all([
14967
- getSession(),
15184
+ const [t, format, query, permissions] = await Promise.all([
14968
15185
  getExtracted("field"),
14969
15186
  getFormatter(),
14970
15187
  searchParams,
15188
+ getPermissions(),
14971
15189
  connection(),
14972
15190
  ]);
14973
15191
 
14974
- if (!can(session, "dispatch.work")) {
15192
+ if (!can(permissions, "dispatch.work")) {
14975
15193
  forbidden();
14976
15194
  }
14977
15195
 
@@ -15103,15 +15321,15 @@ export async function ShipmentTracking({
15103
15321
  }: {
15104
15322
  searchParams: Promise<Record<string, string | string[] | undefined>>;
15105
15323
  }) {
15106
- const [session, t, format, query] = await Promise.all([
15107
- getSession(),
15324
+ const [t, format, query, permissions] = await Promise.all([
15108
15325
  getExtracted("field"),
15109
15326
  getFormatter(),
15110
15327
  searchParams,
15328
+ getPermissions(),
15111
15329
  connection(),
15112
15330
  ]);
15113
15331
 
15114
- if (!can(session, "shipments.read")) {
15332
+ if (!can(permissions, "shipments.read")) {
15115
15333
  forbidden();
15116
15334
  }
15117
15335
 
@@ -15125,7 +15343,7 @@ export async function ShipmentTracking({
15125
15343
  return null;
15126
15344
  }
15127
15345
 
15128
- const newShipment = can(session, "shipments.manage") ? (
15346
+ const newShipment = can(permissions, "shipments.manage") ? (
15129
15347
  <NewShipmentDialog />
15130
15348
  ) : null;
15131
15349
 
@@ -15302,24 +15520,25 @@ async function retry() {
15302
15520
  * billing page still shows the plan.
15303
15521
  */
15304
15522
  export async function InvoicesTable() {
15305
- const session = await getSession();
15306
-
15307
- if (!can(session, "invoices.read")) {
15308
- return null;
15309
- }
15310
-
15311
- const [list, t, format, locale] = await Promise.all([
15523
+ // One round trip: the invoices read starts with the permission read, and RLS
15524
+ // limits it to what the caller may see either way.
15525
+ const [permissions, list, t, format, locale] = await Promise.all([
15526
+ getPermissions(),
15312
15527
  getInvoices(),
15313
15528
  getExtracted("billing"),
15314
15529
  getFormatter(),
15315
15530
  getLocale(),
15316
15531
  ]);
15317
15532
 
15533
+ if (!can(permissions, "invoices.read")) {
15534
+ return null;
15535
+ }
15536
+
15318
15537
  if (list.kind === "no-organization") {
15319
15538
  return null;
15320
15539
  }
15321
15540
 
15322
- const canWrite = can(session, "invoices.write");
15541
+ const canWrite = can(permissions, "invoices.write");
15323
15542
 
15324
15543
  const status = (value: InvoiceStatus, overdue: boolean) => {
15325
15544
  if (overdue) {
@@ -15486,9 +15705,9 @@ async function retry() {
15486
15705
 
15487
15706
  /** Render inside `<Suspense>`: the organization's products as cards. */
15488
15707
  export async function ProductCatalogGrid() {
15489
- const session = await getSession();
15708
+ const permissions = await getPermissions();
15490
15709
 
15491
- if (!can(session, "catalog.read")) {
15710
+ if (!can(permissions, "catalog.read")) {
15492
15711
  forbidden();
15493
15712
  }
15494
15713
 
@@ -15502,7 +15721,7 @@ export async function ProductCatalogGrid() {
15502
15721
  return null;
15503
15722
  }
15504
15723
 
15505
- const canManage = can(session, "catalog.manage");
15724
+ const canManage = can(permissions, "catalog.manage");
15506
15725
 
15507
15726
  const status = (product: Product) => {
15508
15727
  switch (product.status) {
@@ -15567,7 +15786,7 @@ export async function ProductCatalogGrid() {
15567
15786
  })}
15568
15787
  </p>
15569
15788
  <div className="flex items-center gap-2">
15570
- {can(session, "promotions.manage") ? (
15789
+ {can(permissions, "promotions.manage") ? (
15571
15790
  <CreatePromotionCodeDialog />
15572
15791
  ) : null}
15573
15792
  {canManage ? <CreateProductDialog variant="outline" /> : null}
@@ -15628,9 +15847,9 @@ async function retry() {
15628
15847
 
15629
15848
  /** Render inside `<Suspense>`: stock per tracked variant and active location. */
15630
15849
  export async function InventoryTable() {
15631
- const session = await getSession();
15850
+ const permissions = await getPermissions();
15632
15851
 
15633
- if (!can(session, "inventory.read")) {
15852
+ if (!can(permissions, "inventory.read")) {
15634
15853
  forbidden();
15635
15854
  }
15636
15855
 
@@ -15643,7 +15862,7 @@ export async function InventoryTable() {
15643
15862
  return null;
15644
15863
  }
15645
15864
 
15646
- const canManage = can(session, "inventory.manage");
15865
+ const canManage = can(permissions, "inventory.manage");
15647
15866
 
15648
15867
  const locationName = new Map(
15649
15868
  stock.kind === "ok"
@@ -15811,9 +16030,9 @@ export async function OrderDetail({
15811
16030
  }: {
15812
16031
  params: Promise<{ id: string }>;
15813
16032
  }) {
15814
- const [{ id }, session] = await Promise.all([params, getSession()]);
16033
+ const [{ id }, permissions] = await Promise.all([params, getPermissions()]);
15815
16034
 
15816
- if (!can(session, "orders.read")) {
16035
+ if (!can(permissions, "orders.read")) {
15817
16036
  forbidden();
15818
16037
  }
15819
16038
 
@@ -15846,7 +16065,7 @@ export async function OrderDetail({
15846
16065
  }
15847
16066
 
15848
16067
  const view = detail.data;
15849
- const canManage = can(session, "orders.manage");
16068
+ const canManage = can(permissions, "orders.manage");
15850
16069
  const amount = (value: Money) => formatMoney(value, locale);
15851
16070
 
15852
16071
  const problemLabel = (problem: string) => {
@@ -16084,7 +16303,7 @@ export async function OrderDetail({
16084
16303
  ]
16085
16304
  : [],
16086
16305
  )}
16087
- canCreate={can(session, "promotions.manage")}
16306
+ canCreate={can(permissions, "promotions.manage")}
16088
16307
  />
16089
16308
  ) : view.promotions.length === 0 ? (
16090
16309
  <p className="text-sm text-muted-foreground">
@@ -16143,14 +16362,17 @@ export async function KitchenDisplay({
16143
16362
  }: {
16144
16363
  searchParams: Promise<Record<string, string | string[] | undefined>>;
16145
16364
  }) {
16146
- const [session, params] = await Promise.all([getSession(), searchParams]);
16365
+ const [params, permissions] = await Promise.all([
16366
+ searchParams,
16367
+ getPermissions(),
16368
+ ]);
16147
16369
 
16148
- if (!can(session, "orders.read") && !can(session, "orders.prepare")) {
16370
+ if (!can(permissions, "orders.read") && !can(permissions, "orders.prepare")) {
16149
16371
  forbidden();
16150
16372
  }
16151
16373
 
16152
16374
  const canPrepare =
16153
- can(session, "orders.prepare") || can(session, "orders.manage");
16375
+ can(permissions, "orders.prepare") || can(permissions, "orders.manage");
16154
16376
 
16155
16377
  const [kitchen, t] = await Promise.all([
16156
16378
  getKitchen(
@@ -16595,9 +16817,9 @@ export async function CalendarView({
16595
16817
  }: {
16596
16818
  searchParams: Promise<Record<string, string | string[] | undefined>>;
16597
16819
  }) {
16598
- const session = await getSession();
16820
+ const permissions = await getPermissions();
16599
16821
 
16600
- if (!can(session, "calendar.read")) {
16822
+ if (!can(permissions, "calendar.read")) {
16601
16823
  forbidden();
16602
16824
  }
16603
16825
 
@@ -16608,8 +16830,8 @@ export async function CalendarView({
16608
16830
  connection(),
16609
16831
  ]);
16610
16832
 
16611
- const canWrite = can(session, "calendar.write");
16612
- const canManage = can(session, "calendar.manage");
16833
+ const canWrite = can(permissions, "calendar.write");
16834
+ const canManage = can(permissions, "calendar.manage");
16613
16835
  const first = firstOfMonth(query["month"], "UTC");
16614
16836
  const weeks = weeksOf(first);
16615
16837
  const from = weeks[0]?.[0] ?? first;
@@ -16918,9 +17140,9 @@ npx shadcn add badge card empty skeleton
16918
17140
 
16919
17141
  ```tsx title="apps/examples/nextjs/src/features/bookings/components/availability-editor.tsx"
16920
17142
  export async function AvailabilityEditor() {
16921
- const session = await getSession();
17143
+ const permissions = await getPermissions();
16922
17144
 
16923
- if (!can(session, "bookings.manage")) {
17145
+ if (!can(permissions, "bookings.manage")) {
16924
17146
  forbidden();
16925
17147
  }
16926
17148
 
@@ -16951,7 +17173,9 @@ export async function AvailabilityEditor() {
16951
17173
  { count: page.liveLinks },
16952
17174
  )}
16953
17175
  </Badge>
16954
- {can(session, "share_links.create") ? <BookingLinkButton /> : null}
17176
+ {can(permissions, "share_links.create") ? (
17177
+ <BookingLinkButton />
17178
+ ) : null}
16955
17179
  </CardAction>
16956
17180
  ) : null}
16957
17181
  </CardHeader>
@@ -17004,9 +17228,9 @@ npx shadcn add card empty skeleton
17004
17228
  * offset before every occurrence of the event, once per occurrence.
17005
17229
  */
17006
17230
  export async function RemindersList() {
17007
- const session = await getSession();
17231
+ const permissions = await getPermissions();
17008
17232
 
17009
- if (!can(session, "reminders.manage")) {
17233
+ if (!can(permissions, "reminders.manage")) {
17010
17234
  return null;
17011
17235
  }
17012
17236
 
@@ -17049,7 +17273,7 @@ export async function RemindersList() {
17049
17273
  {t("Add an event, then set a reminder for it here.")}
17050
17274
  </EmptyDescription>
17051
17275
  </EmptyHeader>
17052
- {calendars.length > 0 && can(session, "calendar.write") ? (
17276
+ {calendars.length > 0 && can(permissions, "calendar.write") ? (
17053
17277
  <EmptyContent>
17054
17278
  <CreateEventDialog
17055
17279
  calendars={calendars}
@@ -17739,8 +17963,8 @@ import {
17739
17963
  TableHeader,
17740
17964
  TableRow,
17741
17965
  } from "@/components/ui/table";
17966
+ import { getPermissions } from "@/features/user/permission-snapshot";
17742
17967
  import { can } from "@/features/user/user-permissions";
17743
- import { getSession } from "@/features/user/user-queries";
17744
17968
  import { Link } from "@/i18n/navigation";
17745
17969
 
17746
17970
  import { getTrash } from "../trash-queries";
@@ -17757,11 +17981,11 @@ async function retry() {
17757
17981
  * forever.
17758
17982
  */
17759
17983
  export async function TrashBin() {
17760
- const [view, session, t, format] = await Promise.all([
17984
+ const [view, t, format, permissions] = await Promise.all([
17761
17985
  getTrash(),
17762
- getSession(),
17763
17986
  getExtracted("trash"),
17764
17987
  getFormatter(),
17988
+ getPermissions(),
17765
17989
  ]);
17766
17990
 
17767
17991
  if (view.kind === "no-organization") {
@@ -17773,7 +17997,7 @@ export async function TrashBin() {
17773
17997
  ["drive_node", t("Drive item")],
17774
17998
  ]);
17775
17999
 
17776
- const canPurge = can(session, "trash.manage");
18000
+ const canPurge = can(permissions, "trash.manage");
17777
18001
 
17778
18002
  return (
17779
18003
  <Card data-recipe="trash-bin">
@@ -18151,10 +18375,10 @@ const moderationVariants = {
18151
18375
 
18152
18376
  /** Render inside `<Suspense>`: the board's posts, top voted first. */
18153
18377
  export async function PostBoard() {
18154
- const [view, session, t] = await Promise.all([
18378
+ const [view, t, permissions] = await Promise.all([
18155
18379
  getBoard(),
18156
- getSession(),
18157
18380
  getExtracted("community"),
18381
+ getPermissions(),
18158
18382
  ]);
18159
18383
 
18160
18384
  if (view.kind === "no-organization") {
@@ -18181,7 +18405,7 @@ export async function PostBoard() {
18181
18405
  const board = view.data;
18182
18406
 
18183
18407
  if (board === null) {
18184
- const manage = can(session, "posts.manage");
18408
+ const manage = can(permissions, "posts.manage");
18185
18409
 
18186
18410
  return (
18187
18411
  <Empty className="border">
@@ -18209,7 +18433,7 @@ export async function PostBoard() {
18209
18433
  );
18210
18434
  }
18211
18435
 
18212
- const write = can(session, "posts.write");
18436
+ const write = can(permissions, "posts.write");
18213
18437
 
18214
18438
  const statusLabels: Record<PostStatus, string> = {
18215
18439
  open: t("Open"),
@@ -19475,8 +19699,8 @@ import {
19475
19699
  EmptyTitle,
19476
19700
  } from "@/components/ui/empty";
19477
19701
  import { Skeleton } from "@/components/ui/skeleton";
19702
+ import { getPermissions } from "@/features/user/permission-snapshot";
19478
19703
  import { can } from "@/features/user/user-permissions";
19479
- import { getSession } from "@/features/user/user-queries";
19480
19704
 
19481
19705
  import { getTemplates } from "../templates-queries";
19482
19706
  import { CreateTemplateDialog } from "./create-template-dialog";
@@ -19490,18 +19714,18 @@ async function retry() {
19490
19714
 
19491
19715
  /** The New template button, for members who may manage templates. */
19492
19716
  export async function TemplateManagerActions() {
19493
- const session = await getSession();
19717
+ const permissions = await getPermissions();
19494
19718
 
19495
- return can(session, "templates.manage") ? <CreateTemplateDialog /> : null;
19719
+ return can(permissions, "templates.manage") ? <CreateTemplateDialog /> : null;
19496
19720
  }
19497
19721
 
19498
19722
  /** Render inside `<Suspense>`: the customer templates, each with Use template. */
19499
19723
  export async function TemplatesGallery() {
19500
- const [view, session, t, format] = await Promise.all([
19724
+ const [view, t, format, permissions] = await Promise.all([
19501
19725
  getTemplates(),
19502
- getSession(),
19503
19726
  getExtracted("templates"),
19504
19727
  getFormatter(),
19728
+ getPermissions(),
19505
19729
  ]);
19506
19730
 
19507
19731
  if (view.kind === "no-organization") {
@@ -19509,7 +19733,7 @@ export async function TemplatesGallery() {
19509
19733
  }
19510
19734
 
19511
19735
  const canApply =
19512
- can(session, "templates.apply") && can(session, "customers.write");
19736
+ can(permissions, "templates.apply") && can(permissions, "customers.write");
19513
19737
 
19514
19738
  if (view.kind === "error") {
19515
19739
  return (
@@ -19542,7 +19766,7 @@ export async function TemplatesGallery() {
19542
19766
  )}
19543
19767
  </EmptyDescription>
19544
19768
  </EmptyHeader>
19545
- {can(session, "templates.manage") ? (
19769
+ {can(permissions, "templates.manage") ? (
19546
19770
  <EmptyContent>
19547
19771
  <CreateTemplateDialog />
19548
19772
  </EmptyContent>
@@ -20295,14 +20519,14 @@ function EndpointStatusBadge({
20295
20519
  * delete endpoints, and retry finished deliveries.
20296
20520
  */
20297
20521
  export async function WebhookEndpoints() {
20298
- const [session, state, t, format] = await Promise.all([
20299
- getSession(),
20522
+ const [state, t, format, permissions] = await Promise.all([
20300
20523
  loadWebhooksState(),
20301
20524
  getExtracted("webhooks"),
20302
20525
  getFormatter(),
20526
+ getPermissions(),
20303
20527
  ]);
20304
20528
 
20305
- if (!can(session, "webhooks.read")) {
20529
+ if (!can(permissions, "webhooks.read")) {
20306
20530
  forbidden();
20307
20531
  }
20308
20532
 
@@ -20310,7 +20534,7 @@ export async function WebhookEndpoints() {
20310
20534
  return null;
20311
20535
  }
20312
20536
 
20313
- const manage = can(session, "webhooks.manage");
20537
+ const manage = can(permissions, "webhooks.manage");
20314
20538
 
20315
20539
  const firstEnabled =
20316
20540
  state.kind === "ok"
@@ -20578,13 +20802,13 @@ async function retry() {
20578
20802
  * them. Members without `service_principals.read` see nothing.
20579
20803
  */
20580
20804
  export async function ServicePrincipalsTable() {
20581
- const [session, t, format] = await Promise.all([
20582
- getSession(),
20805
+ const [t, format, permissions] = await Promise.all([
20583
20806
  getExtracted("servicePrincipals"),
20584
20807
  getFormatter(),
20808
+ getPermissions(),
20585
20809
  ]);
20586
20810
 
20587
- if (!can(session, "service_principals.read")) {
20811
+ if (!can(permissions, "service_principals.read")) {
20588
20812
  return null;
20589
20813
  }
20590
20814
 
@@ -20594,7 +20818,7 @@ export async function ServicePrincipalsTable() {
20594
20818
  return null;
20595
20819
  }
20596
20820
 
20597
- const manage = can(session, "service_principals.manage");
20821
+ const manage = can(permissions, "service_principals.manage");
20598
20822
 
20599
20823
  const roles = new Map([
20600
20824
  ["owner", t("Owner")],
@@ -20756,12 +20980,12 @@ async function retry() {
20756
20980
  * only, so this checks `organization.update` before it reads.
20757
20981
  */
20758
20982
  export async function SigningKeysRotation() {
20759
- const [session, t] = await Promise.all([
20760
- getSession(),
20983
+ const [t, permissions] = await Promise.all([
20761
20984
  getExtracted("signingKeys"),
20985
+ getPermissions(),
20762
20986
  ]);
20763
20987
 
20764
- if (!can(session, SIGNING_KEYS_PERMISSION)) {
20988
+ if (!can(permissions, SIGNING_KEYS_PERMISSION)) {
20765
20989
  forbidden();
20766
20990
  }
20767
20991
 
@@ -21145,13 +21369,13 @@ function JobStatusBadge({ status, t }: { status: JobRunStatus; t: Translate }) {
21145
21369
  * it reads with the database owner.
21146
21370
  */
21147
21371
  export async function JobRunsTable() {
21148
- const [session, t, format] = await Promise.all([
21149
- getSession(),
21372
+ const [t, format, permissions] = await Promise.all([
21150
21373
  getExtracted("jobs"),
21151
21374
  getFormatter(),
21375
+ getPermissions(),
21152
21376
  ]);
21153
21377
 
21154
- if (!can(session, JOBS_PERMISSION)) {
21378
+ if (!can(permissions, JOBS_PERMISSION)) {
21155
21379
  forbidden();
21156
21380
  }
21157
21381
 
@@ -22145,7 +22369,7 @@ export function TaskToolbar({
22145
22369
 
22146
22370
  const go = (next: TaskQuery) => {
22147
22371
  startTransition(() => {
22148
- router.replace(`${pathname}${taskSearch(next)}`);
22372
+ router.replace(withSearch(pathname, taskSearch(next)));
22149
22373
  });
22150
22374
  };
22151
22375
 
@@ -22891,7 +23115,12 @@ export async function ProjectPage({
22891
23115
  }: {
22892
23116
  params: Promise<{ id: string }>;
22893
23117
  }) {
22894
- const [{ id }, session] = await Promise.all([params, getSession()]);
23118
+ const [{ id }, session, permissions] = await Promise.all([
23119
+ params,
23120
+ getSession(),
23121
+ getPermissions(),
23122
+ ]);
23123
+
22895
23124
  const organizationId = tenantOf(session);
22896
23125
 
22897
23126
  if (!organizationId) {
@@ -23006,7 +23235,7 @@ export async function ProjectPage({
23006
23235
  authors={Object.fromEntries(
23007
23236
  members.data.map((member) => [member.userId, member.name]),
23008
23237
  )}
23009
- canComment={can(session, "messages.send")}
23238
+ canComment={can(permissions, "messages.send")}
23010
23239
  />
23011
23240
  </CardContent>
23012
23241
  </Card>
@@ -23041,8 +23270,8 @@ export async function ProjectPage({
23041
23270
  <ProjectHistory
23042
23271
  projectId={record.id}
23043
23272
  versions={history.data}
23044
- canSave={can(session, "versions.create")}
23045
- canRestore={can(session, "versions.restore")}
23273
+ canSave={can(permissions, "versions.create")}
23274
+ canRestore={can(permissions, "versions.restore")}
23046
23275
  />
23047
23276
  ) : (
23048
23277
  <ProjectLoadError title={t("The history didn't load")} />
@@ -23255,7 +23484,7 @@ export async function TaskCalendar({
23255
23484
  rows: readonly TaskRow[];
23256
23485
  first: Temporal.PlainDate;
23257
23486
  today: Temporal.PlainDate;
23258
- monthHref: (month: string) => string;
23487
+ monthHref: (month: string) => AppHref;
23259
23488
  }) {
23260
23489
  const [t, format] = await Promise.all([
23261
23490
  getExtracted("projects"),
@@ -23427,7 +23656,7 @@ export async function TaskTimeline({
23427
23656
  members: readonly MemberOption[];
23428
23657
  from: Temporal.PlainDate;
23429
23658
  today: Temporal.PlainDate;
23430
- windowHref: (from: string) => string;
23659
+ windowHref: (from: string) => AppHref;
23431
23660
  }) {
23432
23661
  const t = await getExtracted("projects");
23433
23662
  const lanes = new Map<string, TaskRow[]>();
@@ -23549,7 +23778,7 @@ export async function TaskGantt({
23549
23778
  projects: readonly ProjectOption[];
23550
23779
  from: Temporal.PlainDate;
23551
23780
  today: Temporal.PlainDate;
23552
- windowHref: (from: string) => string;
23781
+ windowHref: (from: string) => AppHref;
23553
23782
  }) {
23554
23783
  const t = await getExtracted("projects");
23555
23784