@fayz-ai/saas 0.1.6

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 (645) hide show
  1. package/dist/app/AdminShell.d.ts +31 -0
  2. package/dist/app/AdminShell.d.ts.map +1 -0
  3. package/dist/app/LoginPage.d.ts +17 -0
  4. package/dist/app/LoginPage.d.ts.map +1 -0
  5. package/dist/app/config.d.ts +83 -0
  6. package/dist/app/config.d.ts.map +1 -0
  7. package/dist/app/createFayzApp.d.ts +11 -0
  8. package/dist/app/createFayzApp.d.ts.map +1 -0
  9. package/dist/app/routing.d.ts +10 -0
  10. package/dist/app/routing.d.ts.map +1 -0
  11. package/dist/app/scaffold.d.ts +17 -0
  12. package/dist/app/scaffold.d.ts.map +1 -0
  13. package/dist/archetype-lookup.d.ts +30 -0
  14. package/dist/archetype-lookup.d.ts.map +1 -0
  15. package/dist/billing/index.cjs +12 -0
  16. package/dist/billing/index.cjs.map +1 -0
  17. package/dist/billing/index.d.ts +3 -0
  18. package/dist/billing/index.d.ts.map +1 -0
  19. package/dist/billing/index.js +3 -0
  20. package/dist/billing/index.js.map +1 -0
  21. package/dist/billing/store.d.ts +35 -0
  22. package/dist/billing/store.d.ts.map +1 -0
  23. package/dist/chunk-4XTQ4V5L.cjs +124 -0
  24. package/dist/chunk-4XTQ4V5L.cjs.map +1 -0
  25. package/dist/chunk-5GYQK5IW.js +21 -0
  26. package/dist/chunk-5GYQK5IW.js.map +1 -0
  27. package/dist/chunk-DJW67TCY.js +781 -0
  28. package/dist/chunk-DJW67TCY.js.map +1 -0
  29. package/dist/chunk-KYID2MR6.cjs +23 -0
  30. package/dist/chunk-KYID2MR6.cjs.map +1 -0
  31. package/dist/chunk-QGMDVLLW.cjs +816 -0
  32. package/dist/chunk-QGMDVLLW.cjs.map +1 -0
  33. package/dist/chunk-XNWCGJYH.js +97 -0
  34. package/dist/chunk-XNWCGJYH.js.map +1 -0
  35. package/dist/components/shared/PersonLink.d.ts +18 -0
  36. package/dist/components/shared/PersonLink.d.ts.map +1 -0
  37. package/dist/crud/CrudCardGrid.d.ts +13 -0
  38. package/dist/crud/CrudCardGrid.d.ts.map +1 -0
  39. package/dist/crud/CrudDetailPage.d.ts +18 -0
  40. package/dist/crud/CrudDetailPage.d.ts.map +1 -0
  41. package/dist/crud/CrudFormPage.d.ts +18 -0
  42. package/dist/crud/CrudFormPage.d.ts.map +1 -0
  43. package/dist/crud/CrudListView.d.ts +51 -0
  44. package/dist/crud/CrudListView.d.ts.map +1 -0
  45. package/dist/crud/CrudPage.d.ts +20 -0
  46. package/dist/crud/CrudPage.d.ts.map +1 -0
  47. package/dist/crud/DeleteConfirmDialog.d.ts +11 -0
  48. package/dist/crud/DeleteConfirmDialog.d.ts.map +1 -0
  49. package/dist/crud/EntityOverview.d.ts +14 -0
  50. package/dist/crud/EntityOverview.d.ts.map +1 -0
  51. package/dist/crud/ImportWizard.d.ts +18 -0
  52. package/dist/crud/ImportWizard.d.ts.map +1 -0
  53. package/dist/crud/archetypes/ActiveToggle.d.ts +8 -0
  54. package/dist/crud/archetypes/ActiveToggle.d.ts.map +1 -0
  55. package/dist/crud/archetypes/ArchetypeStatusBar.d.ts +11 -0
  56. package/dist/crud/archetypes/ArchetypeStatusBar.d.ts.map +1 -0
  57. package/dist/crud/archetypes/BlockSettingsPopover.d.ts +15 -0
  58. package/dist/crud/archetypes/BlockSettingsPopover.d.ts.map +1 -0
  59. package/dist/crud/archetypes/EntityLink.d.ts +32 -0
  60. package/dist/crud/archetypes/EntityLink.d.ts.map +1 -0
  61. package/dist/crud/archetypes/LocationDetailTabs.d.ts +11 -0
  62. package/dist/crud/archetypes/LocationDetailTabs.d.ts.map +1 -0
  63. package/dist/crud/archetypes/LocationFormLayout.d.ts +12 -0
  64. package/dist/crud/archetypes/LocationFormLayout.d.ts.map +1 -0
  65. package/dist/crud/archetypes/PersonDetailTabs.d.ts +22 -0
  66. package/dist/crud/archetypes/PersonDetailTabs.d.ts.map +1 -0
  67. package/dist/crud/archetypes/PersonFormLayout.d.ts +13 -0
  68. package/dist/crud/archetypes/PersonFormLayout.d.ts.map +1 -0
  69. package/dist/crud/archetypes/PersonPicker.d.ts +23 -0
  70. package/dist/crud/archetypes/PersonPicker.d.ts.map +1 -0
  71. package/dist/crud/archetypes/ProductDetailTabs.d.ts +11 -0
  72. package/dist/crud/archetypes/ProductDetailTabs.d.ts.map +1 -0
  73. package/dist/crud/archetypes/ProductFormLayout.d.ts +12 -0
  74. package/dist/crud/archetypes/ProductFormLayout.d.ts.map +1 -0
  75. package/dist/crud/archetypes/ScheduleEditor.d.ts +7 -0
  76. package/dist/crud/archetypes/ScheduleEditor.d.ts.map +1 -0
  77. package/dist/crud/archetypes/ServiceDetailTabs.d.ts +10 -0
  78. package/dist/crud/archetypes/ServiceDetailTabs.d.ts.map +1 -0
  79. package/dist/crud/archetypes/ServiceFormLayout.d.ts +12 -0
  80. package/dist/crud/archetypes/ServiceFormLayout.d.ts.map +1 -0
  81. package/dist/crud/archetypes/SubjectDetailTabs.d.ts +12 -0
  82. package/dist/crud/archetypes/SubjectDetailTabs.d.ts.map +1 -0
  83. package/dist/crud/archetypes/SubjectFormLayout.d.ts +14 -0
  84. package/dist/crud/archetypes/SubjectFormLayout.d.ts.map +1 -0
  85. package/dist/crud/createCrudPage.d.ts +20 -0
  86. package/dist/crud/createCrudPage.d.ts.map +1 -0
  87. package/dist/crud/csv-export.d.ts +3 -0
  88. package/dist/crud/csv-export.d.ts.map +1 -0
  89. package/dist/crud/fieldToColumn.d.ts +14 -0
  90. package/dist/crud/fieldToColumn.d.ts.map +1 -0
  91. package/dist/crud/index.d.ts +12 -0
  92. package/dist/crud/index.d.ts.map +1 -0
  93. package/dist/hooks/useFieldRules.d.ts +5 -0
  94. package/dist/hooks/useFieldRules.d.ts.map +1 -0
  95. package/dist/hooks/useModuleNavigation.d.ts +25 -0
  96. package/dist/hooks/useModuleNavigation.d.ts.map +1 -0
  97. package/dist/hooks/usePluginPrefs.d.ts +23 -0
  98. package/dist/hooks/usePluginPrefs.d.ts.map +1 -0
  99. package/dist/index.cjs +13880 -0
  100. package/dist/index.cjs.map +1 -0
  101. package/dist/index.d.ts +46 -0
  102. package/dist/index.d.ts.map +1 -0
  103. package/dist/index.js +13730 -0
  104. package/dist/index.js.map +1 -0
  105. package/dist/lib/currency.d.ts +13 -0
  106. package/dist/lib/currency.d.ts.map +1 -0
  107. package/dist/lib/entity-routes.d.ts +24 -0
  108. package/dist/lib/entity-routes.d.ts.map +1 -0
  109. package/dist/lib/schedule-config.d.ts +32 -0
  110. package/dist/lib/schedule-config.d.ts.map +1 -0
  111. package/dist/lib/schedule-service.d.ts +76 -0
  112. package/dist/lib/schedule-service.d.ts.map +1 -0
  113. package/dist/org/adapters/mock.d.ts +4 -0
  114. package/dist/org/adapters/mock.d.ts.map +1 -0
  115. package/dist/org/adapters/supabase.d.ts +7 -0
  116. package/dist/org/adapters/supabase.d.ts.map +1 -0
  117. package/dist/org/context.d.ts +29 -0
  118. package/dist/org/context.d.ts.map +1 -0
  119. package/dist/org/index.cjs +44 -0
  120. package/dist/org/index.cjs.map +1 -0
  121. package/dist/org/index.d.ts +8 -0
  122. package/dist/org/index.d.ts.map +1 -0
  123. package/dist/org/index.js +3 -0
  124. package/dist/org/index.js.map +1 -0
  125. package/dist/org/store.d.ts +16 -0
  126. package/dist/org/store.d.ts.map +1 -0
  127. package/dist/permissions/PermissionGate.d.ts +12 -0
  128. package/dist/permissions/PermissionGate.d.ts.map +1 -0
  129. package/dist/permissions/context.d.ts +37 -0
  130. package/dist/permissions/context.d.ts.map +1 -0
  131. package/dist/permissions/index.cjs +32 -0
  132. package/dist/permissions/index.cjs.map +1 -0
  133. package/dist/permissions/index.d.ts +5 -0
  134. package/dist/permissions/index.d.ts.map +1 -0
  135. package/dist/permissions/index.js +3 -0
  136. package/dist/permissions/index.js.map +1 -0
  137. package/dist/permissions/store.d.ts +21 -0
  138. package/dist/permissions/store.d.ts.map +1 -0
  139. package/dist/placeholder.d.ts +7 -0
  140. package/dist/placeholder.d.ts.map +1 -0
  141. package/dist/plugins/ModuleActionBar.d.ts +27 -0
  142. package/dist/plugins/ModuleActionBar.d.ts.map +1 -0
  143. package/dist/plugins/PluginRegistryManager.d.ts +13 -0
  144. package/dist/plugins/PluginRegistryManager.d.ts.map +1 -0
  145. package/dist/plugins/QuickActionsButton.d.ts +12 -0
  146. package/dist/plugins/QuickActionsButton.d.ts.map +1 -0
  147. package/dist/plugins/SettingsGroup.d.ts +25 -0
  148. package/dist/plugins/SettingsGroup.d.ts.map +1 -0
  149. package/dist/plugins/WidgetSlot.d.ts +8 -0
  150. package/dist/plugins/WidgetSlot.d.ts.map +1 -0
  151. package/dist/plugins/createPluginContext.d.ts +28 -0
  152. package/dist/plugins/createPluginContext.d.ts.map +1 -0
  153. package/dist/plugins/createViewRouter.d.ts +38 -0
  154. package/dist/plugins/createViewRouter.d.ts.map +1 -0
  155. package/dist/shell/components/auth/CenteredLogin.d.ts +13 -0
  156. package/dist/shell/components/auth/CenteredLogin.d.ts.map +1 -0
  157. package/dist/shell/components/auth/LoginForm.d.ts +12 -0
  158. package/dist/shell/components/auth/LoginForm.d.ts.map +1 -0
  159. package/dist/shell/components/auth/LoginPage.d.ts +15 -0
  160. package/dist/shell/components/auth/LoginPage.d.ts.map +1 -0
  161. package/dist/shell/components/auth/OAuthButtons.d.ts +10 -0
  162. package/dist/shell/components/auth/OAuthButtons.d.ts.map +1 -0
  163. package/dist/shell/components/auth/ProtectedRoute.d.ts +11 -0
  164. package/dist/shell/components/auth/ProtectedRoute.d.ts.map +1 -0
  165. package/dist/shell/components/auth/RecoveryForm.d.ts +9 -0
  166. package/dist/shell/components/auth/RecoveryForm.d.ts.map +1 -0
  167. package/dist/shell/components/auth/SignupForm.d.ts +10 -0
  168. package/dist/shell/components/auth/SignupForm.d.ts.map +1 -0
  169. package/dist/shell/components/auth/SplitLogin.d.ts +14 -0
  170. package/dist/shell/components/auth/SplitLogin.d.ts.map +1 -0
  171. package/dist/shell/components/auth/index.d.ts +7 -0
  172. package/dist/shell/components/auth/index.d.ts.map +1 -0
  173. package/dist/shell/components/billing/BillingPage.d.ts +7 -0
  174. package/dist/shell/components/billing/BillingPage.d.ts.map +1 -0
  175. package/dist/shell/components/billing/InvoiceList.d.ts +9 -0
  176. package/dist/shell/components/billing/InvoiceList.d.ts.map +1 -0
  177. package/dist/shell/components/billing/PaywallGate.d.ts +11 -0
  178. package/dist/shell/components/billing/PaywallGate.d.ts.map +1 -0
  179. package/dist/shell/components/billing/PlanSelector.d.ts +13 -0
  180. package/dist/shell/components/billing/PlanSelector.d.ts.map +1 -0
  181. package/dist/shell/components/billing/SubscriptionCard.d.ts +12 -0
  182. package/dist/shell/components/billing/SubscriptionCard.d.ts.map +1 -0
  183. package/dist/shell/components/billing/index.d.ts +6 -0
  184. package/dist/shell/components/billing/index.d.ts.map +1 -0
  185. package/dist/shell/components/chat/ChatFab.d.ts +9 -0
  186. package/dist/shell/components/chat/ChatFab.d.ts.map +1 -0
  187. package/dist/shell/components/chat/ChatPanel.d.ts +10 -0
  188. package/dist/shell/components/chat/ChatPanel.d.ts.map +1 -0
  189. package/dist/shell/components/chat/ChatSuggestions.d.ts +14 -0
  190. package/dist/shell/components/chat/ChatSuggestions.d.ts.map +1 -0
  191. package/dist/shell/components/chat/index.d.ts +3 -0
  192. package/dist/shell/components/chat/index.d.ts.map +1 -0
  193. package/dist/shell/components/crud/archetypes/ClientOrdersTab.d.ts +16 -0
  194. package/dist/shell/components/crud/archetypes/ClientOrdersTab.d.ts.map +1 -0
  195. package/dist/shell/components/layout/BottomNav.d.ts +24 -0
  196. package/dist/shell/components/layout/BottomNav.d.ts.map +1 -0
  197. package/dist/shell/components/layout/CommandPalette.d.ts +29 -0
  198. package/dist/shell/components/layout/CommandPalette.d.ts.map +1 -0
  199. package/dist/shell/components/layout/LocationSwitchOverlay.d.ts +3 -0
  200. package/dist/shell/components/layout/LocationSwitchOverlay.d.ts.map +1 -0
  201. package/dist/shell/components/layout/MockModeBanner.d.ts +3 -0
  202. package/dist/shell/components/layout/MockModeBanner.d.ts.map +1 -0
  203. package/dist/shell/components/layout/PrintChrome.d.ts +10 -0
  204. package/dist/shell/components/layout/PrintChrome.d.ts.map +1 -0
  205. package/dist/shell/components/layout/index.d.ts +6 -0
  206. package/dist/shell/components/layout/index.d.ts.map +1 -0
  207. package/dist/shell/components/notifications/ChangelogFeed.d.ts +8 -0
  208. package/dist/shell/components/notifications/ChangelogFeed.d.ts.map +1 -0
  209. package/dist/shell/components/notifications/NotificationBell.d.ts +9 -0
  210. package/dist/shell/components/notifications/NotificationBell.d.ts.map +1 -0
  211. package/dist/shell/components/notifications/NotificationInbox.d.ts +13 -0
  212. package/dist/shell/components/notifications/NotificationInbox.d.ts.map +1 -0
  213. package/dist/shell/components/notifications/ToastProvider.d.ts +2 -0
  214. package/dist/shell/components/notifications/ToastProvider.d.ts.map +1 -0
  215. package/dist/shell/components/notifications/index.d.ts +5 -0
  216. package/dist/shell/components/notifications/index.d.ts.map +1 -0
  217. package/dist/shell/components/organization/ImpersonationBanner.d.ts +3 -0
  218. package/dist/shell/components/organization/ImpersonationBanner.d.ts.map +1 -0
  219. package/dist/shell/components/organization/InviteMemberDialog.d.ts +10 -0
  220. package/dist/shell/components/organization/InviteMemberDialog.d.ts.map +1 -0
  221. package/dist/shell/components/organization/OrgInitializer.d.ts +7 -0
  222. package/dist/shell/components/organization/OrgInitializer.d.ts.map +1 -0
  223. package/dist/shell/components/organization/OrgSwitcher.d.ts +7 -0
  224. package/dist/shell/components/organization/OrgSwitcher.d.ts.map +1 -0
  225. package/dist/shell/components/organization/PermissionGate.d.ts +11 -0
  226. package/dist/shell/components/organization/PermissionGate.d.ts.map +1 -0
  227. package/dist/shell/components/organization/PermissionMatrixEditor.d.ts +17 -0
  228. package/dist/shell/components/organization/PermissionMatrixEditor.d.ts.map +1 -0
  229. package/dist/shell/components/organization/PermissionProfilesTab.d.ts +3 -0
  230. package/dist/shell/components/organization/PermissionProfilesTab.d.ts.map +1 -0
  231. package/dist/shell/components/organization/TeamTab.d.ts +3 -0
  232. package/dist/shell/components/organization/TeamTab.d.ts.map +1 -0
  233. package/dist/shell/components/organization/TenantOnboarding.d.ts +9 -0
  234. package/dist/shell/components/organization/TenantOnboarding.d.ts.map +1 -0
  235. package/dist/shell/components/organization/index.d.ts +8 -0
  236. package/dist/shell/components/organization/index.d.ts.map +1 -0
  237. package/dist/shell/components/plugins/PluginSettingsPanel.d.ts +23 -0
  238. package/dist/shell/components/plugins/PluginSettingsPanel.d.ts.map +1 -0
  239. package/dist/shell/components/settings/BrandingSettings.d.ts +12 -0
  240. package/dist/shell/components/settings/BrandingSettings.d.ts.map +1 -0
  241. package/dist/shell/components/settings/CompanySettings.d.ts +13 -0
  242. package/dist/shell/components/settings/CompanySettings.d.ts.map +1 -0
  243. package/dist/shell/components/settings/ConnectedBrandingSettings.d.ts +2 -0
  244. package/dist/shell/components/settings/ConnectedBrandingSettings.d.ts.map +1 -0
  245. package/dist/shell/components/settings/ConnectedCompanySettings.d.ts +2 -0
  246. package/dist/shell/components/settings/ConnectedCompanySettings.d.ts.map +1 -0
  247. package/dist/shell/components/settings/ConnectedFieldRulesSettings.d.ts +2 -0
  248. package/dist/shell/components/settings/ConnectedFieldRulesSettings.d.ts.map +1 -0
  249. package/dist/shell/components/settings/ConnectedHolidaysSettings.d.ts +3 -0
  250. package/dist/shell/components/settings/ConnectedHolidaysSettings.d.ts.map +1 -0
  251. package/dist/shell/components/settings/ConnectedLocationsOverview.d.ts +3 -0
  252. package/dist/shell/components/settings/ConnectedLocationsOverview.d.ts.map +1 -0
  253. package/dist/shell/components/settings/ConnectedSecuritySettings.d.ts +2 -0
  254. package/dist/shell/components/settings/ConnectedSecuritySettings.d.ts.map +1 -0
  255. package/dist/shell/components/settings/ConnectedUserProfile.d.ts +2 -0
  256. package/dist/shell/components/settings/ConnectedUserProfile.d.ts.map +1 -0
  257. package/dist/shell/components/settings/FieldRulesSettings.d.ts +11 -0
  258. package/dist/shell/components/settings/FieldRulesSettings.d.ts.map +1 -0
  259. package/dist/shell/components/settings/HolidaysSettings.d.ts +21 -0
  260. package/dist/shell/components/settings/HolidaysSettings.d.ts.map +1 -0
  261. package/dist/shell/components/settings/LocationsCrudPage.d.ts +6 -0
  262. package/dist/shell/components/settings/LocationsCrudPage.d.ts.map +1 -0
  263. package/dist/shell/components/settings/LocationsOverview.d.ts +19 -0
  264. package/dist/shell/components/settings/LocationsOverview.d.ts.map +1 -0
  265. package/dist/shell/components/settings/SecuritySettings.d.ts +17 -0
  266. package/dist/shell/components/settings/SecuritySettings.d.ts.map +1 -0
  267. package/dist/shell/components/settings/SettingsPage.d.ts +18 -0
  268. package/dist/shell/components/settings/SettingsPage.d.ts.map +1 -0
  269. package/dist/shell/components/settings/UserProfile.d.ts +12 -0
  270. package/dist/shell/components/settings/UserProfile.d.ts.map +1 -0
  271. package/dist/shell/components/settings/index.d.ts +11 -0
  272. package/dist/shell/components/settings/index.d.ts.map +1 -0
  273. package/dist/shell/config/index.d.ts +7 -0
  274. package/dist/shell/config/index.d.ts.map +1 -0
  275. package/dist/shell/config/permissions.d.ts +7 -0
  276. package/dist/shell/config/permissions.d.ts.map +1 -0
  277. package/dist/shell/config/tailwind-preset.d.ts +4 -0
  278. package/dist/shell/config/tailwind-preset.d.ts.map +1 -0
  279. package/dist/shell/config/theme/dark.d.ts +3 -0
  280. package/dist/shell/config/theme/dark.d.ts.map +1 -0
  281. package/dist/shell/config/theme/index.d.ts +6 -0
  282. package/dist/shell/config/theme/index.d.ts.map +1 -0
  283. package/dist/shell/config/theme/light.d.ts +3 -0
  284. package/dist/shell/config/theme/light.d.ts.map +1 -0
  285. package/dist/shell/config/theme/tokens.d.ts +97 -0
  286. package/dist/shell/config/theme/tokens.d.ts.map +1 -0
  287. package/dist/shell/config/theme/utils.d.ts +23 -0
  288. package/dist/shell/config/theme/utils.d.ts.map +1 -0
  289. package/dist/shell/createSaasApp.d.ts +145 -0
  290. package/dist/shell/createSaasApp.d.ts.map +1 -0
  291. package/dist/shell/hooks/index.d.ts +19 -0
  292. package/dist/shell/hooks/index.d.ts.map +1 -0
  293. package/dist/shell/hooks/useAITools.d.ts +21 -0
  294. package/dist/shell/hooks/useAITools.d.ts.map +1 -0
  295. package/dist/shell/hooks/useAuth.d.ts +16 -0
  296. package/dist/shell/hooks/useAuth.d.ts.map +1 -0
  297. package/dist/shell/hooks/useBilling.d.ts +14 -0
  298. package/dist/shell/hooks/useBilling.d.ts.map +1 -0
  299. package/dist/shell/hooks/useChat.d.ts +16 -0
  300. package/dist/shell/hooks/useChat.d.ts.map +1 -0
  301. package/dist/shell/hooks/useFieldRules.d.ts +6 -0
  302. package/dist/shell/hooks/useFieldRules.d.ts.map +1 -0
  303. package/dist/shell/hooks/useFormatters.d.ts +7 -0
  304. package/dist/shell/hooks/useFormatters.d.ts.map +1 -0
  305. package/dist/shell/hooks/useLayout.d.ts +16 -0
  306. package/dist/shell/hooks/useLayout.d.ts.map +1 -0
  307. package/dist/shell/hooks/useModuleNavigation.d.ts +25 -0
  308. package/dist/shell/hooks/useModuleNavigation.d.ts.map +1 -0
  309. package/dist/shell/hooks/useNotifications.d.ts +11 -0
  310. package/dist/shell/hooks/useNotifications.d.ts.map +1 -0
  311. package/dist/shell/hooks/usePermission.d.ts +16 -0
  312. package/dist/shell/hooks/usePermission.d.ts.map +1 -0
  313. package/dist/shell/hooks/usePluginPrefs.d.ts +23 -0
  314. package/dist/shell/hooks/usePluginPrefs.d.ts.map +1 -0
  315. package/dist/shell/hooks/usePlugins.d.ts +5 -0
  316. package/dist/shell/hooks/usePlugins.d.ts.map +1 -0
  317. package/dist/shell/hooks/useTenant.d.ts +23 -0
  318. package/dist/shell/hooks/useTenant.d.ts.map +1 -0
  319. package/dist/shell/hooks/useTenantPlugins.d.ts +10 -0
  320. package/dist/shell/hooks/useTenantPlugins.d.ts.map +1 -0
  321. package/dist/shell/hooks/useTranslation.d.ts +5 -0
  322. package/dist/shell/hooks/useTranslation.d.ts.map +1 -0
  323. package/dist/shell/lib/api.d.ts +28 -0
  324. package/dist/shell/lib/api.d.ts.map +1 -0
  325. package/dist/shell/lib/apply-field-rules.d.ts +4 -0
  326. package/dist/shell/lib/apply-field-rules.d.ts.map +1 -0
  327. package/dist/shell/lib/auth-adapters/mock.d.ts +3 -0
  328. package/dist/shell/lib/auth-adapters/mock.d.ts.map +1 -0
  329. package/dist/shell/lib/auth-adapters/supabase.d.ts +3 -0
  330. package/dist/shell/lib/auth-adapters/supabase.d.ts.map +1 -0
  331. package/dist/shell/lib/auth-context.d.ts +5 -0
  332. package/dist/shell/lib/auth-context.d.ts.map +1 -0
  333. package/dist/shell/lib/cache.d.ts +18 -0
  334. package/dist/shell/lib/cache.d.ts.map +1 -0
  335. package/dist/shell/lib/cn.d.ts +2 -0
  336. package/dist/shell/lib/cn.d.ts.map +1 -0
  337. package/dist/shell/lib/core-ai-tools.d.ts +15 -0
  338. package/dist/shell/lib/core-ai-tools.d.ts.map +1 -0
  339. package/dist/shell/lib/create-client-orders-provider.d.ts +3 -0
  340. package/dist/shell/lib/create-client-orders-provider.d.ts.map +1 -0
  341. package/dist/shell/lib/csv.d.ts +14 -0
  342. package/dist/shell/lib/csv.d.ts.map +1 -0
  343. package/dist/shell/lib/dedup.d.ts +2 -0
  344. package/dist/shell/lib/dedup.d.ts.map +1 -0
  345. package/dist/shell/lib/entity-registry.d.ts +19 -0
  346. package/dist/shell/lib/entity-registry.d.ts.map +1 -0
  347. package/dist/shell/lib/entity-routes.d.ts +24 -0
  348. package/dist/shell/lib/entity-routes.d.ts.map +1 -0
  349. package/dist/shell/lib/format.d.ts +7 -0
  350. package/dist/shell/lib/format.d.ts.map +1 -0
  351. package/dist/shell/lib/i18n.d.ts +4 -0
  352. package/dist/shell/lib/i18n.d.ts.map +1 -0
  353. package/dist/shell/lib/locale-config.d.ts +8 -0
  354. package/dist/shell/lib/locale-config.d.ts.map +1 -0
  355. package/dist/shell/lib/org-adapters/mock.d.ts +4 -0
  356. package/dist/shell/lib/org-adapters/mock.d.ts.map +1 -0
  357. package/dist/shell/lib/org-adapters/supabase.d.ts +3 -0
  358. package/dist/shell/lib/org-adapters/supabase.d.ts.map +1 -0
  359. package/dist/shell/lib/org-context.d.ts +5 -0
  360. package/dist/shell/lib/org-context.d.ts.map +1 -0
  361. package/dist/shell/lib/plugins.d.ts +2 -0
  362. package/dist/shell/lib/plugins.d.ts.map +1 -0
  363. package/dist/shell/lib/router.d.ts +15 -0
  364. package/dist/shell/lib/router.d.ts.map +1 -0
  365. package/dist/shell/lib/schedule-config.d.ts +32 -0
  366. package/dist/shell/lib/schedule-config.d.ts.map +1 -0
  367. package/dist/shell/lib/schedule-service.d.ts +76 -0
  368. package/dist/shell/lib/schedule-service.d.ts.map +1 -0
  369. package/dist/shell/lib/supabase.d.ts +9 -0
  370. package/dist/shell/lib/supabase.d.ts.map +1 -0
  371. package/dist/shell/stores/auth.store.d.ts +12 -0
  372. package/dist/shell/stores/auth.store.d.ts.map +1 -0
  373. package/dist/shell/stores/billing.store.d.ts +2 -0
  374. package/dist/shell/stores/billing.store.d.ts.map +1 -0
  375. package/dist/shell/stores/chat.store.d.ts +20 -0
  376. package/dist/shell/stores/chat.store.d.ts.map +1 -0
  377. package/dist/shell/stores/index.d.ts +13 -0
  378. package/dist/shell/stores/index.d.ts.map +1 -0
  379. package/dist/shell/stores/invite.store.d.ts +11 -0
  380. package/dist/shell/stores/invite.store.d.ts.map +1 -0
  381. package/dist/shell/stores/layout.store.d.ts +2 -0
  382. package/dist/shell/stores/layout.store.d.ts.map +1 -0
  383. package/dist/shell/stores/locale.store.d.ts +7 -0
  384. package/dist/shell/stores/locale.store.d.ts.map +1 -0
  385. package/dist/shell/stores/location.store.d.ts +20 -0
  386. package/dist/shell/stores/location.store.d.ts.map +1 -0
  387. package/dist/shell/stores/notifications.store.d.ts +12 -0
  388. package/dist/shell/stores/notifications.store.d.ts.map +1 -0
  389. package/dist/shell/stores/organization.store.d.ts +2 -0
  390. package/dist/shell/stores/organization.store.d.ts.map +1 -0
  391. package/dist/shell/stores/permissions.store.d.ts +2 -0
  392. package/dist/shell/stores/permissions.store.d.ts.map +1 -0
  393. package/dist/shell/stores/plugin.store.d.ts +24 -0
  394. package/dist/shell/stores/plugin.store.d.ts.map +1 -0
  395. package/dist/shell/stores/tenant.store.d.ts +11 -0
  396. package/dist/shell/stores/tenant.store.d.ts.map +1 -0
  397. package/dist/shell/stores/theme.store.d.ts +17 -0
  398. package/dist/shell/stores/theme.store.d.ts.map +1 -0
  399. package/dist/shell/test-setup.d.ts +2 -0
  400. package/dist/shell/test-setup.d.ts.map +1 -0
  401. package/dist/shell/types/auth-adapter.d.ts +14 -0
  402. package/dist/shell/types/auth-adapter.d.ts.map +1 -0
  403. package/dist/shell/types/auth.d.ts +34 -0
  404. package/dist/shell/types/auth.d.ts.map +1 -0
  405. package/dist/shell/types/billing.d.ts +74 -0
  406. package/dist/shell/types/billing.d.ts.map +1 -0
  407. package/dist/shell/types/client-orders.d.ts +43 -0
  408. package/dist/shell/types/client-orders.d.ts.map +1 -0
  409. package/dist/shell/types/crud.d.ts +122 -0
  410. package/dist/shell/types/crud.d.ts.map +1 -0
  411. package/dist/shell/types/entities.d.ts +150 -0
  412. package/dist/shell/types/entities.d.ts.map +1 -0
  413. package/dist/shell/types/entity-lookup.d.ts +18 -0
  414. package/dist/shell/types/entity-lookup.d.ts.map +1 -0
  415. package/dist/shell/types/index.d.ts +17 -0
  416. package/dist/shell/types/index.d.ts.map +1 -0
  417. package/dist/shell/types/integrations.d.ts +48 -0
  418. package/dist/shell/types/integrations.d.ts.map +1 -0
  419. package/dist/shell/types/invite.d.ts +23 -0
  420. package/dist/shell/types/invite.d.ts.map +1 -0
  421. package/dist/shell/types/layout.d.ts +26 -0
  422. package/dist/shell/types/layout.d.ts.map +1 -0
  423. package/dist/shell/types/notifications.d.ts +31 -0
  424. package/dist/shell/types/notifications.d.ts.map +1 -0
  425. package/dist/shell/types/org-adapter.d.ts +72 -0
  426. package/dist/shell/types/org-adapter.d.ts.map +1 -0
  427. package/dist/shell/types/permissions.d.ts +39 -0
  428. package/dist/shell/types/permissions.d.ts.map +1 -0
  429. package/dist/shell/types/platform.d.ts +25 -0
  430. package/dist/shell/types/platform.d.ts.map +1 -0
  431. package/dist/shell/types/plugins.d.ts +308 -0
  432. package/dist/shell/types/plugins.d.ts.map +1 -0
  433. package/dist/shell/types/tenant.d.ts +74 -0
  434. package/dist/shell/types/tenant.d.ts.map +1 -0
  435. package/dist/stores/createCrudStore.d.ts +32 -0
  436. package/dist/stores/createCrudStore.d.ts.map +1 -0
  437. package/dist/supabase/client.d.ts +18 -0
  438. package/dist/supabase/client.d.ts.map +1 -0
  439. package/package.json +72 -0
  440. package/src/app/AdminShell.tsx +449 -0
  441. package/src/app/LoginPage.tsx +264 -0
  442. package/src/app/config.ts +146 -0
  443. package/src/app/createFayzApp.tsx +254 -0
  444. package/src/app/routing.tsx +65 -0
  445. package/src/app/scaffold.tsx +175 -0
  446. package/src/archetype-lookup.ts +160 -0
  447. package/src/billing/index.ts +7 -0
  448. package/src/billing/store.ts +62 -0
  449. package/src/components/shared/PersonLink.tsx +199 -0
  450. package/src/crud/CrudCardGrid.tsx +92 -0
  451. package/src/crud/CrudDetailPage.tsx +366 -0
  452. package/src/crud/CrudFormPage.tsx +467 -0
  453. package/src/crud/CrudListView.tsx +223 -0
  454. package/src/crud/CrudPage.tsx +491 -0
  455. package/src/crud/DeleteConfirmDialog.tsx +41 -0
  456. package/src/crud/EntityOverview.tsx +230 -0
  457. package/src/crud/ImportWizard.tsx +690 -0
  458. package/src/crud/archetypes/ActiveToggle.tsx +23 -0
  459. package/src/crud/archetypes/ArchetypeStatusBar.tsx +58 -0
  460. package/src/crud/archetypes/BlockSettingsPopover.tsx +322 -0
  461. package/src/crud/archetypes/EntityLink.tsx +74 -0
  462. package/src/crud/archetypes/LocationDetailTabs.tsx +72 -0
  463. package/src/crud/archetypes/LocationFormLayout.tsx +173 -0
  464. package/src/crud/archetypes/PersonDetailTabs.tsx +87 -0
  465. package/src/crud/archetypes/PersonFormLayout.tsx +184 -0
  466. package/src/crud/archetypes/PersonPicker.tsx +299 -0
  467. package/src/crud/archetypes/ProductDetailTabs.tsx +72 -0
  468. package/src/crud/archetypes/ProductFormLayout.tsx +197 -0
  469. package/src/crud/archetypes/ScheduleEditor.tsx +796 -0
  470. package/src/crud/archetypes/ServiceDetailTabs.tsx +60 -0
  471. package/src/crud/archetypes/ServiceFormLayout.tsx +155 -0
  472. package/src/crud/archetypes/SubjectDetailTabs.tsx +142 -0
  473. package/src/crud/archetypes/SubjectFormLayout.tsx +164 -0
  474. package/src/crud/createCrudPage.tsx +65 -0
  475. package/src/crud/csv-export.ts +17 -0
  476. package/src/crud/fieldToColumn.tsx +109 -0
  477. package/src/crud/index.ts +11 -0
  478. package/src/hooks/useFieldRules.ts +10 -0
  479. package/src/hooks/useModuleNavigation.ts +124 -0
  480. package/src/hooks/usePluginPrefs.ts +113 -0
  481. package/src/index.ts +168 -0
  482. package/src/lib/currency.ts +19 -0
  483. package/src/lib/entity-routes.ts +53 -0
  484. package/src/lib/schedule-config.ts +42 -0
  485. package/src/lib/schedule-service.ts +307 -0
  486. package/src/org/adapters/mock.ts +353 -0
  487. package/src/org/adapters/supabase.ts +509 -0
  488. package/src/org/context.tsx +174 -0
  489. package/src/org/index.ts +19 -0
  490. package/src/org/store.ts +70 -0
  491. package/src/permissions/PermissionGate.tsx +17 -0
  492. package/src/permissions/context.tsx +126 -0
  493. package/src/permissions/index.ts +13 -0
  494. package/src/permissions/store.ts +68 -0
  495. package/src/placeholder.ts +32 -0
  496. package/src/plugins/ModuleActionBar.tsx +57 -0
  497. package/src/plugins/PluginRegistryManager.tsx +110 -0
  498. package/src/plugins/QuickActionsButton.tsx +73 -0
  499. package/src/plugins/SettingsGroup.tsx +100 -0
  500. package/src/plugins/WidgetSlot.tsx +38 -0
  501. package/src/plugins/createPluginContext.tsx +68 -0
  502. package/src/plugins/createViewRouter.tsx +45 -0
  503. package/src/shell/components/auth/CenteredLogin.tsx +86 -0
  504. package/src/shell/components/auth/LoginForm.tsx +129 -0
  505. package/src/shell/components/auth/LoginPage.tsx +22 -0
  506. package/src/shell/components/auth/OAuthButtons.tsx +66 -0
  507. package/src/shell/components/auth/ProtectedRoute.tsx +52 -0
  508. package/src/shell/components/auth/RecoveryForm.tsx +110 -0
  509. package/src/shell/components/auth/SignupForm.tsx +170 -0
  510. package/src/shell/components/auth/SplitLogin.tsx +124 -0
  511. package/src/shell/components/auth/index.ts +6 -0
  512. package/src/shell/components/billing/BillingPage.tsx +56 -0
  513. package/src/shell/components/billing/InvoiceList.tsx +123 -0
  514. package/src/shell/components/billing/PaywallGate.tsx +80 -0
  515. package/src/shell/components/billing/PlanSelector.tsx +125 -0
  516. package/src/shell/components/billing/SubscriptionCard.tsx +108 -0
  517. package/src/shell/components/billing/index.ts +5 -0
  518. package/src/shell/components/chat/ChatFab.tsx +195 -0
  519. package/src/shell/components/chat/ChatPanel.tsx +170 -0
  520. package/src/shell/components/chat/ChatSuggestions.tsx +102 -0
  521. package/src/shell/components/chat/index.ts +2 -0
  522. package/src/shell/components/crud/archetypes/ClientOrdersTab.tsx +212 -0
  523. package/src/shell/components/layout/BottomNav.tsx +131 -0
  524. package/src/shell/components/layout/CommandPalette.tsx +257 -0
  525. package/src/shell/components/layout/LocationSwitchOverlay.tsx +64 -0
  526. package/src/shell/components/layout/MockModeBanner.tsx +17 -0
  527. package/src/shell/components/layout/PrintChrome.tsx +200 -0
  528. package/src/shell/components/layout/index.ts +5 -0
  529. package/src/shell/components/notifications/ChangelogFeed.tsx +85 -0
  530. package/src/shell/components/notifications/NotificationBell.tsx +44 -0
  531. package/src/shell/components/notifications/NotificationInbox.tsx +175 -0
  532. package/src/shell/components/notifications/ToastProvider.tsx +2 -0
  533. package/src/shell/components/notifications/index.ts +4 -0
  534. package/src/shell/components/organization/ImpersonationBanner.tsx +29 -0
  535. package/src/shell/components/organization/InviteMemberDialog.tsx +161 -0
  536. package/src/shell/components/organization/OrgInitializer.tsx +179 -0
  537. package/src/shell/components/organization/OrgSwitcher.tsx +177 -0
  538. package/src/shell/components/organization/PermissionGate.tsx +16 -0
  539. package/src/shell/components/organization/PermissionMatrixEditor.tsx +206 -0
  540. package/src/shell/components/organization/PermissionProfilesTab.tsx +148 -0
  541. package/src/shell/components/organization/TeamTab.tsx +243 -0
  542. package/src/shell/components/organization/TenantOnboarding.tsx +179 -0
  543. package/src/shell/components/organization/index.ts +7 -0
  544. package/src/shell/components/plugins/PluginSettingsPanel.tsx +189 -0
  545. package/src/shell/components/settings/BrandingSettings.tsx +255 -0
  546. package/src/shell/components/settings/CompanySettings.tsx +188 -0
  547. package/src/shell/components/settings/ConnectedBrandingSettings.tsx +82 -0
  548. package/src/shell/components/settings/ConnectedCompanySettings.tsx +63 -0
  549. package/src/shell/components/settings/ConnectedFieldRulesSettings.tsx +47 -0
  550. package/src/shell/components/settings/ConnectedHolidaysSettings.tsx +99 -0
  551. package/src/shell/components/settings/ConnectedLocationsOverview.tsx +57 -0
  552. package/src/shell/components/settings/ConnectedSecuritySettings.tsx +59 -0
  553. package/src/shell/components/settings/ConnectedUserProfile.tsx +59 -0
  554. package/src/shell/components/settings/FieldRulesSettings.tsx +511 -0
  555. package/src/shell/components/settings/HolidaysSettings.tsx +141 -0
  556. package/src/shell/components/settings/LocationsCrudPage.ts +36 -0
  557. package/src/shell/components/settings/LocationsOverview.tsx +171 -0
  558. package/src/shell/components/settings/SecuritySettings.tsx +208 -0
  559. package/src/shell/components/settings/SettingsPage.tsx +162 -0
  560. package/src/shell/components/settings/UserProfile.tsx +151 -0
  561. package/src/shell/components/settings/index.ts +10 -0
  562. package/src/shell/config/index.ts +6 -0
  563. package/src/shell/config/permissions.ts +31 -0
  564. package/src/shell/config/tailwind-preset.ts +164 -0
  565. package/src/shell/config/theme/dark.ts +63 -0
  566. package/src/shell/config/theme/index.ts +5 -0
  567. package/src/shell/config/theme/light.ts +63 -0
  568. package/src/shell/config/theme/tokens.ts +105 -0
  569. package/src/shell/config/theme/utils.ts +249 -0
  570. package/src/shell/createSaasApp.tsx +922 -0
  571. package/src/shell/hooks/index.ts +18 -0
  572. package/src/shell/hooks/useAITools.ts +139 -0
  573. package/src/shell/hooks/useAuth.ts +109 -0
  574. package/src/shell/hooks/useBilling.ts +151 -0
  575. package/src/shell/hooks/useChat.ts +84 -0
  576. package/src/shell/hooks/useFieldRules.ts +19 -0
  577. package/src/shell/hooks/useFormatters.ts +56 -0
  578. package/src/shell/hooks/useLayout.ts +76 -0
  579. package/src/shell/hooks/useModuleNavigation.ts +124 -0
  580. package/src/shell/hooks/useNotifications.ts +114 -0
  581. package/src/shell/hooks/usePermission.ts +101 -0
  582. package/src/shell/hooks/usePluginPrefs.ts +113 -0
  583. package/src/shell/hooks/usePlugins.ts +18 -0
  584. package/src/shell/hooks/useTenant.ts +106 -0
  585. package/src/shell/hooks/useTenantPlugins.ts +103 -0
  586. package/src/shell/hooks/useTranslation.ts +10 -0
  587. package/src/shell/lib/api.ts +67 -0
  588. package/src/shell/lib/apply-field-rules.ts +14 -0
  589. package/src/shell/lib/auth-adapters/mock.ts +97 -0
  590. package/src/shell/lib/auth-adapters/supabase.ts +96 -0
  591. package/src/shell/lib/auth-context.ts +18 -0
  592. package/src/shell/lib/cache.ts +124 -0
  593. package/src/shell/lib/cn.ts +1 -0
  594. package/src/shell/lib/core-ai-tools.ts +90 -0
  595. package/src/shell/lib/create-client-orders-provider.ts +105 -0
  596. package/src/shell/lib/csv.ts +54 -0
  597. package/src/shell/lib/dedup.ts +17 -0
  598. package/src/shell/lib/entity-registry.ts +39 -0
  599. package/src/shell/lib/entity-routes.ts +53 -0
  600. package/src/shell/lib/format.ts +58 -0
  601. package/src/shell/lib/i18n.ts +3723 -0
  602. package/src/shell/lib/locale-config.ts +14 -0
  603. package/src/shell/lib/org-adapters/mock.ts +318 -0
  604. package/src/shell/lib/org-adapters/supabase.ts +533 -0
  605. package/src/shell/lib/org-context.ts +18 -0
  606. package/src/shell/lib/plugins.ts +11 -0
  607. package/src/shell/lib/router.ts +86 -0
  608. package/src/shell/lib/schedule-config.ts +42 -0
  609. package/src/shell/lib/schedule-service.ts +307 -0
  610. package/src/shell/lib/supabase.ts +19 -0
  611. package/src/shell/stores/auth.store.ts +29 -0
  612. package/src/shell/stores/billing.store.ts +1 -0
  613. package/src/shell/stores/chat.store.ts +45 -0
  614. package/src/shell/stores/index.ts +12 -0
  615. package/src/shell/stores/invite.store.ts +18 -0
  616. package/src/shell/stores/layout.store.ts +1 -0
  617. package/src/shell/stores/locale.store.ts +24 -0
  618. package/src/shell/stores/location.store.ts +89 -0
  619. package/src/shell/stores/notifications.store.ts +48 -0
  620. package/src/shell/stores/organization.store.ts +3 -0
  621. package/src/shell/stores/permissions.store.ts +1 -0
  622. package/src/shell/stores/plugin.store.ts +50 -0
  623. package/src/shell/stores/tenant.store.ts +26 -0
  624. package/src/shell/stores/theme.store.ts +162 -0
  625. package/src/shell/styles.css +433 -0
  626. package/src/shell/test-setup.ts +1 -0
  627. package/src/shell/types/auth-adapter.ts +11 -0
  628. package/src/shell/types/auth.ts +38 -0
  629. package/src/shell/types/billing.ts +90 -0
  630. package/src/shell/types/client-orders.ts +58 -0
  631. package/src/shell/types/crud.ts +134 -0
  632. package/src/shell/types/entities.ts +169 -0
  633. package/src/shell/types/entity-lookup.ts +25 -0
  634. package/src/shell/types/index.ts +16 -0
  635. package/src/shell/types/integrations.ts +51 -0
  636. package/src/shell/types/invite.ts +23 -0
  637. package/src/shell/types/layout.ts +29 -0
  638. package/src/shell/types/notifications.ts +33 -0
  639. package/src/shell/types/org-adapter.ts +72 -0
  640. package/src/shell/types/permissions.ts +64 -0
  641. package/src/shell/types/platform.ts +25 -0
  642. package/src/shell/types/plugins.ts +359 -0
  643. package/src/shell/types/tenant.ts +79 -0
  644. package/src/stores/createCrudStore.ts +138 -0
  645. package/src/supabase/client.ts +54 -0
@@ -0,0 +1,509 @@
1
+ import type {
2
+ OrgAdapter,
3
+ Organization,
4
+ OrgMember,
5
+ OrgMembership,
6
+ CreateOrgOptions,
7
+ Location,
8
+ Invite,
9
+ } from '@fayz-ai/core'
10
+ import type { PermissionProfile } from '@fayz-ai/core'
11
+ import { getFayzSupabaseClient, CORE_SCHEMA } from '../../supabase/client'
12
+
13
+ // ---------------------------------------------------------------------------
14
+ // Request dedup — prevents duplicate in-flight requests (React StrictMode etc.)
15
+ // ---------------------------------------------------------------------------
16
+
17
+ const inflightRequests = new Map<string, Promise<unknown>>()
18
+
19
+ function dedup<T>(key: string, fn: () => Promise<T>): Promise<T> {
20
+ const existing = inflightRequests.get(key)
21
+ if (existing) return existing as Promise<T>
22
+
23
+ const promise = fn().finally(() => {
24
+ inflightRequests.delete(key)
25
+ })
26
+ inflightRequests.set(key, promise)
27
+ return promise
28
+ }
29
+
30
+ // ---------------------------------------------------------------------------
31
+ // Helpers
32
+ // ---------------------------------------------------------------------------
33
+
34
+ function slugify(name: string): string {
35
+ return name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-|-$/g, '')
36
+ }
37
+
38
+ function capitalize(s: string): string {
39
+ return s.charAt(0).toUpperCase() + s.slice(1)
40
+ }
41
+
42
+ function mapTenantToOrg(row: Record<string, unknown>): Organization {
43
+ return {
44
+ id: row['id'] as string,
45
+ name: row['name'] as string,
46
+ slug: row['slug'] as string,
47
+ logoUrl: (row['logo_url'] as string | null) ?? undefined,
48
+ verticalId: (row['vertical_id'] as string | null) ?? undefined,
49
+ plan: (row['plan'] as string | null) ?? undefined,
50
+ settings: (row['settings'] as Record<string, unknown> | null) ?? undefined,
51
+ createdAt: row['created_at'] as string,
52
+ updatedAt: row['updated_at'] as string,
53
+ }
54
+ }
55
+
56
+ function mapMemberRow(row: Record<string, unknown>): OrgMember {
57
+ const profile = (row['profile'] as Record<string, unknown>) ?? {}
58
+ return {
59
+ id: row['id'] as string,
60
+ userId: row['user_id'] as string,
61
+ orgId: row['tenant_id'] as string,
62
+ profileId: row['role'] as string,
63
+ profileName: capitalize(row['role'] as string),
64
+ user: {
65
+ id: row['user_id'] as string,
66
+ email: (profile['email'] as string) ?? '',
67
+ fullName: (profile['full_name'] as string) ?? '',
68
+ avatarUrl: (profile['avatar_url'] as string | null) ?? undefined,
69
+ },
70
+ joinedAt: row['joined_at'] as string,
71
+ }
72
+ }
73
+
74
+ function mapLocationRow(row: Record<string, unknown>): Location {
75
+ return {
76
+ id: row['id'] as string,
77
+ tenantId: row['tenant_id'] as string,
78
+ name: row['name'] as string,
79
+ address: (row['address'] as string | null) ?? undefined,
80
+ city: (row['city'] as string | null) ?? undefined,
81
+ state: (row['state'] as string | null) ?? undefined,
82
+ country: (row['country'] as string | null) ?? undefined,
83
+ phone: (row['phone'] as string | null) ?? undefined,
84
+ isHeadquarters: (row['is_headquarters'] as boolean) ?? false,
85
+ isActive: (row['is_active'] as boolean) ?? true,
86
+ createdAt: row['created_at'] as string,
87
+ updatedAt: row['updated_at'] as string,
88
+ }
89
+ }
90
+
91
+ function mapInviteRow(row: Record<string, unknown>): Invite {
92
+ return {
93
+ id: row['id'] as string,
94
+ orgId: row['tenant_id'] as string,
95
+ email: row['email'] as string,
96
+ profileId: row['role'] as string,
97
+ profileName: capitalize(row['role'] as string),
98
+ invitedBy: row['invited_by'] as string,
99
+ token: row['token'] as string,
100
+ status: (row['status'] as Invite['status']) ?? 'pending',
101
+ createdAt: row['created_at'] as string,
102
+ expiresAt: row['expires_at'] as string,
103
+ }
104
+ }
105
+
106
+ const SYSTEM_ROLES = ['owner', 'admin', 'manager', 'staff', 'viewer'] as const
107
+
108
+ type SystemRole = (typeof SYSTEM_ROLES)[number]
109
+
110
+ // Map DB permission ids to feature action grants
111
+ function buildPermissionProfiles(
112
+ permissions: Array<{ id: string; category: string }>,
113
+ rolePerms: Array<{ role: string; permission_id: string }>,
114
+ overrides: Array<{ role: string; permission_id: string; granted: boolean }>,
115
+ ): PermissionProfile[] {
116
+ const overrideMap = new Map<string, boolean>()
117
+ for (const o of overrides) {
118
+ overrideMap.set(`${o.role}:${o.permission_id}`, o.granted)
119
+ }
120
+
121
+ const rolePermMap = new Map<SystemRole, Set<string>>()
122
+ for (const role of SYSTEM_ROLES) {
123
+ rolePermMap.set(role, new Set())
124
+ }
125
+ // Owner gets all permissions by default
126
+ for (const p of permissions) {
127
+ rolePermMap.get('owner')!.add(p.id)
128
+ }
129
+ for (const rp of rolePerms) {
130
+ rolePermMap.get(rp.role as SystemRole)?.add(rp.permission_id)
131
+ }
132
+
133
+ // Apply overrides
134
+ for (const [key, granted] of overrideMap) {
135
+ const colonIdx = key.indexOf(':')
136
+ const role = key.slice(0, colonIdx) as SystemRole
137
+ const permId = key.slice(colonIdx + 1)
138
+ const perms = rolePermMap.get(role)
139
+ if (!perms) continue
140
+ if (granted) {
141
+ perms.add(permId)
142
+ } else {
143
+ perms.delete(permId)
144
+ }
145
+ }
146
+
147
+ const actionMap: Record<string, string> = {
148
+ read: 'read',
149
+ create: 'write',
150
+ update: 'write',
151
+ manage: 'manage',
152
+ delete: 'delete',
153
+ configure: 'manage',
154
+ invite: 'write',
155
+ }
156
+
157
+ return SYSTEM_ROLES.map((role) => {
158
+ const permIds = rolePermMap.get(role)!
159
+ const features: Record<string, string[]> = {}
160
+
161
+ for (const permId of permIds) {
162
+ const dotIdx = permId.indexOf('.')
163
+ if (dotIdx === -1) continue
164
+ const category = permId.slice(0, dotIdx)
165
+ const action = permId.slice(dotIdx + 1)
166
+ const mappedAction = actionMap[action]
167
+ if (!mappedAction) continue
168
+
169
+ if (!features[category]) features[category] = []
170
+ if (!features[category].includes(mappedAction)) {
171
+ features[category].push(mappedAction)
172
+ }
173
+ }
174
+
175
+ return {
176
+ id: role,
177
+ name: capitalize(role),
178
+ isSystem: true,
179
+ grants: features,
180
+ }
181
+ })
182
+ }
183
+
184
+ // ---------------------------------------------------------------------------
185
+ // Adapter factory
186
+ // ---------------------------------------------------------------------------
187
+
188
+ export interface SupabaseOrgAdapterConfig {
189
+ /** Override the core schema name (default: 'saas_core') */
190
+ coreSchema?: string
191
+ }
192
+
193
+ export function createSupabaseOrgAdapter(config?: SupabaseOrgAdapterConfig): OrgAdapter {
194
+ const schema = config?.coreSchema ?? CORE_SCHEMA
195
+
196
+ function supabase() {
197
+ return getFayzSupabaseClient()
198
+ }
199
+
200
+ function core() {
201
+ return supabase().schema(schema)
202
+ }
203
+
204
+ return {
205
+ async listUserOrgs(userId: string): Promise<OrgMembership[]> {
206
+ return dedup(`listUserOrgs:${userId}`, async () => {
207
+ const { data, error } = await core()
208
+ .from('tenant_members')
209
+ .select('tenant_id, role, tenant:tenants(id, name, slug, logo_url)')
210
+ .eq('user_id', userId)
211
+
212
+ if (error) throw error
213
+
214
+ return ((data ?? []) as Array<Record<string, unknown>>).map((row) => ({
215
+ orgId: row['tenant_id'] as string,
216
+ orgName: ((row['tenant'] as Record<string, unknown>)?.['name'] as string) ?? '',
217
+ orgSlug: ((row['tenant'] as Record<string, unknown>)?.['slug'] as string) ?? '',
218
+ orgLogoUrl: ((row['tenant'] as Record<string, unknown>)?.['logo_url'] as string | null) ?? undefined,
219
+ profileId: row['role'] as string,
220
+ profileName: capitalize(row['role'] as string),
221
+ }))
222
+ })
223
+ },
224
+
225
+ async getOrg(orgId: string): Promise<Organization> {
226
+ const { data, error } = await core()
227
+ .from('tenants')
228
+ .select('*')
229
+ .eq('id', orgId)
230
+ .single()
231
+
232
+ if (error) throw error
233
+ return mapTenantToOrg(data as Record<string, unknown>)
234
+ },
235
+
236
+ async createOrg(name: string, userId: string, options?: CreateOrgOptions): Promise<Organization> {
237
+ const { data: tenant, error } = await supabase()
238
+ .rpc('create_tenant_with_owner', {
239
+ p_name: name,
240
+ p_slug: slugify(name),
241
+ p_user_id: userId,
242
+ p_vertical_id: options?.verticalId ?? null,
243
+ p_plan: 'free',
244
+ p_settings: {
245
+ timezone: options?.timezone ?? 'America/Sao_Paulo',
246
+ currency: options?.currency ?? 'BRL',
247
+ locale: options?.locale ?? 'pt-BR',
248
+ teamSize: options?.teamSize ?? undefined,
249
+ branding: {},
250
+ },
251
+ })
252
+
253
+ if (error) throw error
254
+ return mapTenantToOrg(tenant as Record<string, unknown>)
255
+ },
256
+
257
+ async updateOrg(orgId: string, updates: Partial<Organization>): Promise<Organization> {
258
+ const row: Record<string, unknown> = {}
259
+ if (updates.name !== undefined) row['name'] = updates.name
260
+ if (updates.slug !== undefined) row['slug'] = updates.slug
261
+ if (updates.logoUrl !== undefined) row['logo_url'] = updates.logoUrl
262
+ if (updates.verticalId !== undefined) row['vertical_id'] = updates.verticalId
263
+ if (updates.plan !== undefined) row['plan'] = updates.plan
264
+ if (updates.settings !== undefined) row['settings'] = updates.settings
265
+
266
+ const { data, error } = await core()
267
+ .from('tenants')
268
+ .update(row)
269
+ .eq('id', orgId)
270
+ .select()
271
+ .single()
272
+
273
+ if (error) throw error
274
+ return mapTenantToOrg(data as Record<string, unknown>)
275
+ },
276
+
277
+ async listMembers(orgId: string): Promise<OrgMember[]> {
278
+ const { data, error } = await core()
279
+ .from('tenant_members')
280
+ .select('*')
281
+ .eq('tenant_id', orgId)
282
+
283
+ if (error) throw error
284
+
285
+ const userIds = ((data ?? []) as Array<Record<string, unknown>>).map((m) => m['user_id'] as string)
286
+ const { data: profiles } = userIds.length > 0
287
+ ? await core().from('profiles').select('id, full_name, avatar_url, email').in('id', userIds)
288
+ : { data: [] }
289
+
290
+ const profileMap = new Map(
291
+ ((profiles ?? []) as Array<Record<string, unknown>>).map((p) => [p['id'], p]),
292
+ )
293
+
294
+ return ((data ?? []) as Array<Record<string, unknown>>).map((row) => {
295
+ const profile = profileMap.get(row['user_id'] as string) ?? {}
296
+ return mapMemberRow({ ...row, profile })
297
+ })
298
+ },
299
+
300
+ async updateMemberProfile(orgId: string, memberId: string, profileId: string): Promise<void> {
301
+ const { error } = await core()
302
+ .from('tenant_members')
303
+ .update({ role: profileId })
304
+ .eq('id', memberId)
305
+ .eq('tenant_id', orgId)
306
+
307
+ if (error) throw error
308
+ },
309
+
310
+ async removeMember(orgId: string, memberId: string): Promise<void> {
311
+ const { error } = await core()
312
+ .from('tenant_members')
313
+ .delete()
314
+ .eq('id', memberId)
315
+ .eq('tenant_id', orgId)
316
+
317
+ if (error) throw error
318
+ },
319
+
320
+ async listProfiles(orgId: string): Promise<PermissionProfile[]> {
321
+ const [permsResult, rolePermsResult, overridesResult] = await Promise.all([
322
+ core().from('permissions').select('id, category'),
323
+ core().from('role_permissions').select('role, permission_id'),
324
+ core().from('tenant_role_overrides').select('role, permission_id, granted').eq('tenant_id', orgId),
325
+ ])
326
+
327
+ if (permsResult.error) throw permsResult.error
328
+ if (rolePermsResult.error) throw rolePermsResult.error
329
+ if (overridesResult.error) throw overridesResult.error
330
+
331
+ return buildPermissionProfiles(
332
+ (permsResult.data ?? []) as Array<{ id: string; category: string }>,
333
+ (rolePermsResult.data ?? []) as Array<{ role: string; permission_id: string }>,
334
+ (overridesResult.data ?? []) as Array<{ role: string; permission_id: string; granted: boolean }>,
335
+ )
336
+ },
337
+
338
+ async createProfile(
339
+ _orgId: string,
340
+ _profile: Omit<PermissionProfile, 'id' | 'isSystem'>,
341
+ ): Promise<PermissionProfile> {
342
+ throw new Error(
343
+ 'Custom roles are not supported. Roles are system-defined (owner, admin, manager, staff, viewer).',
344
+ )
345
+ },
346
+
347
+ async updateProfile(
348
+ orgId: string,
349
+ profileId: string,
350
+ data: Partial<PermissionProfile>,
351
+ ): Promise<PermissionProfile> {
352
+ if (data.grants) {
353
+ await core()
354
+ .from('tenant_role_overrides')
355
+ .delete()
356
+ .eq('tenant_id', orgId)
357
+ .eq('role', profileId)
358
+
359
+ const overrides: Array<{
360
+ tenant_id: string
361
+ role: string
362
+ permission_id: string
363
+ granted: boolean
364
+ }> = []
365
+
366
+ for (const [category, actions] of Object.entries(data.grants)) {
367
+ for (const action of actions) {
368
+ const dbActionMap: Record<string, string> = {
369
+ read: 'read',
370
+ write: 'create',
371
+ manage: 'manage',
372
+ delete: 'delete',
373
+ }
374
+ const dbAction = dbActionMap[action] ?? action
375
+ overrides.push({
376
+ tenant_id: orgId,
377
+ role: profileId,
378
+ permission_id: `${category}.${dbAction}`,
379
+ granted: true,
380
+ })
381
+ }
382
+ }
383
+
384
+ if (overrides.length > 0) {
385
+ const { error } = await core().from('tenant_role_overrides').insert(overrides)
386
+ if (error) throw error
387
+ }
388
+ }
389
+
390
+ const profiles = await this.listProfiles(orgId)
391
+ const updated = profiles.find((p) => p.id === profileId)
392
+ if (!updated) throw new Error(`Profile not found: ${profileId}`)
393
+ return updated
394
+ },
395
+
396
+ async deleteProfile(_orgId: string, _profileId: string): Promise<void> {
397
+ throw new Error('System roles cannot be deleted.')
398
+ },
399
+
400
+ async listInvites(orgId: string): Promise<Invite[]> {
401
+ const { data, error } = await core()
402
+ .from('invitations')
403
+ .select('*')
404
+ .eq('tenant_id', orgId)
405
+ .order('created_at', { ascending: false })
406
+
407
+ if (error) throw error
408
+ return ((data ?? []) as Array<Record<string, unknown>>).map(mapInviteRow)
409
+ },
410
+
411
+ async createInvite(orgId: string, email: string, profileId: string, invitedBy: string): Promise<Invite> {
412
+ const { data, error } = await core()
413
+ .from('invitations')
414
+ .insert({
415
+ tenant_id: orgId,
416
+ email,
417
+ role: profileId,
418
+ invited_by: invitedBy,
419
+ })
420
+ .select()
421
+ .single()
422
+
423
+ if (error) throw error
424
+ return mapInviteRow(data as Record<string, unknown>)
425
+ },
426
+
427
+ async bulkInvite(orgId: string, emails: string[], profileId: string, invitedBy: string): Promise<Invite[]> {
428
+ const rows = emails.map((email) => ({
429
+ tenant_id: orgId,
430
+ email,
431
+ role: profileId,
432
+ invited_by: invitedBy,
433
+ }))
434
+
435
+ const { data, error } = await core().from('invitations').insert(rows).select()
436
+ if (error) throw error
437
+ return ((data ?? []) as Array<Record<string, unknown>>).map(mapInviteRow)
438
+ },
439
+
440
+ async revokeInvite(orgId: string, inviteId: string): Promise<void> {
441
+ const { error } = await core()
442
+ .from('invitations')
443
+ .update({ status: 'revoked' })
444
+ .eq('id', inviteId)
445
+ .eq('tenant_id', orgId)
446
+
447
+ if (error) throw error
448
+ },
449
+
450
+ async resendInvite(orgId: string, inviteId: string): Promise<Invite> {
451
+ const { data, error } = await core()
452
+ .from('invitations')
453
+ .update({
454
+ status: 'pending',
455
+ expires_at: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString(),
456
+ })
457
+ .eq('id', inviteId)
458
+ .eq('tenant_id', orgId)
459
+ .select()
460
+ .single()
461
+
462
+ if (error) throw error
463
+ return mapInviteRow(data as Record<string, unknown>)
464
+ },
465
+
466
+ async listLocations(orgId: string): Promise<Location[]> {
467
+ const { data, error } = await core()
468
+ .from('locations')
469
+ .select('*')
470
+ .eq('tenant_id', orgId)
471
+ .order('is_headquarters', { ascending: false })
472
+ .order('name')
473
+
474
+ if (error) throw error
475
+ return ((data ?? []) as Array<Record<string, unknown>>).map(mapLocationRow)
476
+ },
477
+
478
+ async createLocation(
479
+ orgId: string,
480
+ input: {
481
+ name: string
482
+ address?: string
483
+ city?: string
484
+ state?: string
485
+ country?: string
486
+ phone?: string
487
+ isHeadquarters?: boolean
488
+ },
489
+ ): Promise<Location> {
490
+ const { data, error } = await core()
491
+ .from('locations')
492
+ .insert({
493
+ tenant_id: orgId,
494
+ name: input.name,
495
+ address: input.address ?? null,
496
+ city: input.city ?? null,
497
+ state: input.state ?? null,
498
+ country: input.country ?? 'BR',
499
+ phone: input.phone ?? null,
500
+ is_headquarters: input.isHeadquarters ?? false,
501
+ })
502
+ .select()
503
+ .single()
504
+
505
+ if (error) throw error
506
+ return mapLocationRow(data as Record<string, unknown>)
507
+ },
508
+ }
509
+ }
@@ -0,0 +1,174 @@
1
+ import * as React from 'react'
2
+ import type { OrgAdapter, Organization, OrgMembership } from '@fayz-ai/core'
3
+ import { useAuthStore } from '@fayz-ai/auth'
4
+ import { useOrganizationStore, getPersistedOrgId } from './store'
5
+
6
+ // ---------------------------------------------------------------------------
7
+ // Adapter context
8
+ // ---------------------------------------------------------------------------
9
+
10
+ const OrgAdapterContext = React.createContext<OrgAdapter | null>(null)
11
+
12
+ export function useOrgAdapter(): OrgAdapter {
13
+ const adapter = React.useContext(OrgAdapterContext)
14
+ if (!adapter) {
15
+ throw new Error('useOrgAdapter must be used within an <OrgProvider>')
16
+ }
17
+ return adapter
18
+ }
19
+
20
+ export function useOrgAdapterOptional(): OrgAdapter | null {
21
+ return React.useContext(OrgAdapterContext)
22
+ }
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Tenant / org hook
26
+ // ---------------------------------------------------------------------------
27
+
28
+ export interface TenantContext {
29
+ /** The currently active organization */
30
+ org: Organization | null
31
+ /** All orgs the current user belongs to */
32
+ userOrgs: OrgMembership[]
33
+ loading: boolean
34
+ /** Switch the active org */
35
+ switchOrg: (orgId: string) => Promise<void>
36
+ /** Refresh the current org from the adapter */
37
+ refreshOrg: () => Promise<void>
38
+ }
39
+
40
+ const TenantContext = React.createContext<TenantContext | null>(null)
41
+
42
+ /**
43
+ * Access the current tenant / organization.
44
+ * Must be used inside <OrgProvider>.
45
+ */
46
+ export function useTenant(): TenantContext {
47
+ const ctx = React.useContext(TenantContext)
48
+ if (!ctx) {
49
+ throw new Error('useTenant must be used inside <OrgProvider>')
50
+ }
51
+ return ctx
52
+ }
53
+
54
+ export function useTenantOptional(): TenantContext | null {
55
+ return React.useContext(TenantContext)
56
+ }
57
+
58
+ // ---------------------------------------------------------------------------
59
+ // Provider
60
+ // ---------------------------------------------------------------------------
61
+
62
+ export interface OrgProviderProps {
63
+ adapter: OrgAdapter
64
+ /** When true, automatically creates an org if the user has none */
65
+ autoCreate?: boolean
66
+ children: React.ReactNode
67
+ }
68
+
69
+ export function OrgProvider({ adapter, autoCreate = false, children }: OrgProviderProps) {
70
+ const { user } = useAuthStore()
71
+ const { currentOrg, userOrgs, loading, setCurrentOrg, setUserOrgs, setLoading, reset } =
72
+ useOrganizationStore()
73
+
74
+ const adapterRef = React.useRef(adapter)
75
+ adapterRef.current = adapter
76
+
77
+ // Load orgs when user is authenticated
78
+ React.useEffect(() => {
79
+ if (!user) {
80
+ reset()
81
+ return
82
+ }
83
+
84
+ let cancelled = false
85
+
86
+ async function loadOrgs() {
87
+ setLoading(true)
88
+ try {
89
+ const memberships = await adapterRef.current.listUserOrgs(user!.id)
90
+
91
+ if (cancelled) return
92
+
93
+ setUserOrgs(memberships)
94
+
95
+ // Auto-create org if user has none
96
+ if (memberships.length === 0 && autoCreate) {
97
+ const newOrg = await adapterRef.current.createOrg(
98
+ user!.fullName ? `${user!.fullName}'s Organization` : 'My Organization',
99
+ user!.id,
100
+ )
101
+ if (!cancelled) {
102
+ setUserOrgs([
103
+ {
104
+ orgId: newOrg.id,
105
+ orgName: newOrg.name,
106
+ orgSlug: newOrg.slug,
107
+ profileId: 'owner',
108
+ profileName: 'Owner',
109
+ },
110
+ ])
111
+ setCurrentOrg(newOrg)
112
+ }
113
+ return
114
+ }
115
+
116
+ // Restore previously selected org or default to first
117
+ const persistedId = getPersistedOrgId()
118
+ const target =
119
+ memberships.find((m) => m.orgId === persistedId) ?? memberships[0]
120
+
121
+ if (target && !cancelled) {
122
+ const org = await adapterRef.current.getOrg(target.orgId)
123
+ if (!cancelled) setCurrentOrg(org)
124
+ }
125
+ } finally {
126
+ if (!cancelled) setLoading(false)
127
+ }
128
+ }
129
+
130
+ void loadOrgs()
131
+
132
+ return () => {
133
+ cancelled = true
134
+ }
135
+ // eslint-disable-next-line react-hooks/exhaustive-deps
136
+ }, [user?.id])
137
+
138
+ async function switchOrg(orgId: string): Promise<void> {
139
+ setLoading(true)
140
+ try {
141
+ const org = await adapterRef.current.getOrg(orgId)
142
+ setCurrentOrg(org)
143
+ } finally {
144
+ setLoading(false)
145
+ }
146
+ }
147
+
148
+ async function refreshOrg(): Promise<void> {
149
+ if (!currentOrg) return
150
+ setLoading(true)
151
+ try {
152
+ const org = await adapterRef.current.getOrg(currentOrg.id)
153
+ setCurrentOrg(org)
154
+ } finally {
155
+ setLoading(false)
156
+ }
157
+ }
158
+
159
+ const tenantValue: TenantContext = {
160
+ org: currentOrg,
161
+ userOrgs,
162
+ loading,
163
+ switchOrg,
164
+ refreshOrg,
165
+ }
166
+
167
+ return (
168
+ <OrgAdapterContext.Provider value={adapter}>
169
+ <TenantContext.Provider value={tenantValue}>
170
+ {children}
171
+ </TenantContext.Provider>
172
+ </OrgAdapterContext.Provider>
173
+ )
174
+ }
@@ -0,0 +1,19 @@
1
+ // Adapters
2
+ export { createSupabaseOrgAdapter } from './adapters/supabase'
3
+ export type { SupabaseOrgAdapterConfig } from './adapters/supabase'
4
+
5
+ export { createMockOrgAdapter } from './adapters/mock'
6
+
7
+ // Store
8
+ export { useOrganizationStore, getPersistedOrgId } from './store'
9
+ export type { OrgStore } from './store'
10
+
11
+ // Context & hooks
12
+ export {
13
+ OrgProvider,
14
+ useTenant,
15
+ useTenantOptional,
16
+ useOrgAdapter,
17
+ useOrgAdapterOptional,
18
+ } from './context'
19
+ export type { OrgProviderProps, TenantContext } from './context'