@fluid-app/portal-sdk 0.1.59 → 0.1.61

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 (93) hide show
  1. package/dist/{AppDownloadScreen-B_SwkDDi.cjs → AppDownloadScreen-BH7GQ-qi.cjs} +2 -2
  2. package/dist/{AppDownloadScreen-B_SwkDDi.cjs.map → AppDownloadScreen-BH7GQ-qi.cjs.map} +1 -1
  3. package/dist/{AppDownloadScreen-NJI_UTLu.cjs → AppDownloadScreen-CH96k5cA.cjs} +2 -2
  4. package/dist/{AppDownloadScreen-Dw7DyU92.mjs → AppDownloadScreen-CLWxnFsd.mjs} +2 -2
  5. package/dist/{AppDownloadScreen-B-4Om2j8.mjs → AppDownloadScreen-DcVl4492.mjs} +2 -2
  6. package/dist/{AppDownloadScreen-B-4Om2j8.mjs.map → AppDownloadScreen-DcVl4492.mjs.map} +1 -1
  7. package/dist/{ContactsScreen-C8510XHQ.cjs → ContactsScreen-B8iWQTbP.cjs} +2 -2
  8. package/dist/{ContactsScreen-BSaedR34.mjs → ContactsScreen-C8Bp62F4.mjs} +2 -2
  9. package/dist/{ContactsScreen-Dcx-CUNk.mjs → ContactsScreen-Dk9bp3Jj.mjs} +2 -2
  10. package/dist/{ContactsScreen-Dcx-CUNk.mjs.map → ContactsScreen-Dk9bp3Jj.mjs.map} +1 -1
  11. package/dist/{ContactsScreen-BHnAPB1v.cjs → ContactsScreen-IAGjo08W.cjs} +2 -2
  12. package/dist/{ContactsScreen-BHnAPB1v.cjs.map → ContactsScreen-IAGjo08W.cjs.map} +1 -1
  13. package/dist/{FluidProvider-BcMVqXGW.cjs → FluidProvider-9JuTycML.cjs} +4 -2
  14. package/dist/{FluidProvider-BcMVqXGW.cjs.map → FluidProvider-9JuTycML.cjs.map} +1 -1
  15. package/dist/{FluidProvider-NsdWcsos.mjs → FluidProvider-9ZC28GXK.mjs} +4 -2
  16. package/dist/{FluidProvider-NsdWcsos.mjs.map → FluidProvider-9ZC28GXK.mjs.map} +1 -1
  17. package/dist/{MessagingScreen-BUC6-xNT.cjs → MessagingScreen-BuZTTy-l.cjs} +2 -2
  18. package/dist/{MessagingScreen-CGvz_4UM.mjs → MessagingScreen-DdQPLrmd.mjs} +3 -3
  19. package/dist/{MessagingScreen-CGvz_4UM.mjs.map → MessagingScreen-DdQPLrmd.mjs.map} +1 -1
  20. package/dist/{MessagingScreen-XSXGBuM5.cjs → MessagingScreen-DpVYlTyB.cjs} +3 -3
  21. package/dist/{MessagingScreen-XSXGBuM5.cjs.map → MessagingScreen-DpVYlTyB.cjs.map} +1 -1
  22. package/dist/{MessagingScreen-CMx7NBXH.mjs → MessagingScreen-RhCqymLN.mjs} +2 -2
  23. package/dist/{MySiteScreen-armH7ZmU.cjs → MySiteScreen-DNn3aWn0.cjs} +2 -2
  24. package/dist/{MySiteScreen-armH7ZmU.cjs.map → MySiteScreen-DNn3aWn0.cjs.map} +1 -1
  25. package/dist/{MySiteScreen-6qkt1-AM.cjs → MySiteScreen-DadI19bJ.cjs} +2 -2
  26. package/dist/{MySiteScreen-CJaXSfvP.mjs → MySiteScreen-Dbvaw1nu.mjs} +2 -2
  27. package/dist/{MySiteScreen-BYhZIZth.mjs → MySiteScreen-Ddxdk1Pe.mjs} +2 -2
  28. package/dist/{MySiteScreen-BYhZIZth.mjs.map → MySiteScreen-Ddxdk1Pe.mjs.map} +1 -1
  29. package/dist/{OrdersScreen-CKfSGMRB.cjs → OrdersScreen-CZdh8mbE.cjs} +2 -2
  30. package/dist/{OrdersScreen-36U1k66t.mjs → OrdersScreen-CwTIkQNI.mjs} +3 -3
  31. package/dist/{OrdersScreen-36U1k66t.mjs.map → OrdersScreen-CwTIkQNI.mjs.map} +1 -1
  32. package/dist/{OrdersScreen-D5qbccVE.cjs → OrdersScreen-DpyL3mIg.cjs} +3 -3
  33. package/dist/{OrdersScreen-D5qbccVE.cjs.map → OrdersScreen-DpyL3mIg.cjs.map} +1 -1
  34. package/dist/{OrdersScreen-cBlQv9h0.mjs → OrdersScreen-QFndb0Oi.mjs} +2 -2
  35. package/dist/{ProductsScreen-D1TMPOpi.cjs → ProductsScreen-CGjMUHds.cjs} +3 -3
  36. package/dist/{ProductsScreen-D1TMPOpi.cjs.map → ProductsScreen-CGjMUHds.cjs.map} +1 -1
  37. package/dist/{ProductsScreen-i6JTXwNY.mjs → ProductsScreen-CmZw1rWf.mjs} +3 -3
  38. package/dist/{ProductsScreen-i6JTXwNY.mjs.map → ProductsScreen-CmZw1rWf.mjs.map} +1 -1
  39. package/dist/{ProductsScreen-DLysCJ9C.mjs → ProductsScreen-HaYLhqt1.mjs} +2 -2
  40. package/dist/{ProductsScreen-Y3MJJSeK.cjs → ProductsScreen-dN4s469R.cjs} +2 -2
  41. package/dist/{ProfileScreen-BGOd1zyN.cjs → ProfileScreen-1hqd2fN7.cjs} +3 -3
  42. package/dist/{ProfileScreen-BGOd1zyN.cjs.map → ProfileScreen-1hqd2fN7.cjs.map} +1 -1
  43. package/dist/{ProfileScreen-CFSEMg7L.mjs → ProfileScreen-DSr0OwIA.mjs} +2 -2
  44. package/dist/{ProfileScreen-DARnojGI.cjs → ProfileScreen-_4yPoIgh.cjs} +2 -2
  45. package/dist/{ProfileScreen-DOGhmpk-.mjs → ProfileScreen-pCW_VAPN.mjs} +3 -3
  46. package/dist/{ProfileScreen-DOGhmpk-.mjs.map → ProfileScreen-pCW_VAPN.mjs.map} +1 -1
  47. package/dist/{ShareablesScreen-C0OVGZ07.cjs → ShareablesScreen-CdXtyZma.cjs} +3 -3
  48. package/dist/{ShareablesScreen-C0OVGZ07.cjs.map → ShareablesScreen-CdXtyZma.cjs.map} +1 -1
  49. package/dist/{ShareablesScreen-i1KpJcwV.mjs → ShareablesScreen-Cm8zbATC.mjs} +3 -3
  50. package/dist/{ShareablesScreen-i1KpJcwV.mjs.map → ShareablesScreen-Cm8zbATC.mjs.map} +1 -1
  51. package/dist/{ShareablesScreen-CbcwPnLx.cjs → ShareablesScreen-DNzrgsmZ.cjs} +2 -2
  52. package/dist/{ShareablesScreen-Clf0Z7vk.mjs → ShareablesScreen-xqMDNJ6m.mjs} +2 -2
  53. package/dist/{ShopScreen-DE1qzYW6.cjs → ShopScreen-BnVS75fU.cjs} +2 -2
  54. package/dist/{ShopScreen-Kq0LKtBN.mjs → ShopScreen-D2cMeKSk.mjs} +2 -2
  55. package/dist/{ShopScreen-1HiWn8Hg.mjs → ShopScreen-Dc3lQLGI.mjs} +4 -4
  56. package/dist/{ShopScreen-1HiWn8Hg.mjs.map → ShopScreen-Dc3lQLGI.mjs.map} +1 -1
  57. package/dist/{ShopScreen-ClGySVDF.cjs → ShopScreen-qZa0cEwy.cjs} +4 -4
  58. package/dist/{ShopScreen-ClGySVDF.cjs.map → ShopScreen-qZa0cEwy.cjs.map} +1 -1
  59. package/dist/{SubscriptionsScreen-D-pb9t7Z.mjs → SubscriptionsScreen-749p5heX.mjs} +3 -3
  60. package/dist/{SubscriptionsScreen-D-pb9t7Z.mjs.map → SubscriptionsScreen-749p5heX.mjs.map} +1 -1
  61. package/dist/{SubscriptionsScreen-CPicMEVG.cjs → SubscriptionsScreen-7VBEggJ_.cjs} +3 -3
  62. package/dist/{SubscriptionsScreen-CPicMEVG.cjs.map → SubscriptionsScreen-7VBEggJ_.cjs.map} +1 -1
  63. package/dist/{SubscriptionsScreen-CluHNO3J.cjs → SubscriptionsScreen-DRgSTuJv.cjs} +2 -2
  64. package/dist/{SubscriptionsScreen-4DRQtr5m.mjs → SubscriptionsScreen-DxVV0sZx.mjs} +2 -2
  65. package/dist/index.cjs +49 -37
  66. package/dist/index.cjs.map +1 -1
  67. package/dist/index.d.cts +10 -1
  68. package/dist/index.d.cts.map +1 -1
  69. package/dist/index.d.mts +10 -1
  70. package/dist/index.d.mts.map +1 -1
  71. package/dist/index.mjs +49 -37
  72. package/dist/index.mjs.map +1 -1
  73. package/dist/{use-account-clients-BNdnotPF.mjs → use-account-clients-CqC0etbc.mjs} +2 -2
  74. package/dist/{use-account-clients-BNdnotPF.mjs.map → use-account-clients-CqC0etbc.mjs.map} +1 -1
  75. package/dist/{use-account-clients-BcfCVnN1.cjs → use-account-clients-cHyQEhPp.cjs} +2 -2
  76. package/dist/{use-account-clients-BcfCVnN1.cjs.map → use-account-clients-cHyQEhPp.cjs.map} +1 -1
  77. package/dist/{use-current-user-C5ye4E_t.cjs → use-current-user-Ccn1lGeB.cjs} +3 -3
  78. package/dist/{use-current-user-C5ye4E_t.cjs.map → use-current-user-Ccn1lGeB.cjs.map} +1 -1
  79. package/dist/{use-current-user-BR36V_-x.mjs → use-current-user-CyodELl8.mjs} +3 -3
  80. package/dist/{use-current-user-BR36V_-x.mjs.map → use-current-user-CyodELl8.mjs.map} +1 -1
  81. package/dist/{use-customer-account-CBRukk1K.mjs → use-customer-account-DODRyBye.mjs} +3 -3
  82. package/dist/{use-customer-account-CBRukk1K.mjs.map → use-customer-account-DODRyBye.mjs.map} +1 -1
  83. package/dist/{use-customer-account-BUcZbQG8.cjs → use-customer-account-DOmzp1sM.cjs} +3 -3
  84. package/dist/{use-customer-account-BUcZbQG8.cjs.map → use-customer-account-DOmzp1sM.cjs.map} +1 -1
  85. package/dist/{use-fluid-api-ByXKmAb3.mjs → use-fluid-api-BvakcAkY.mjs} +2 -2
  86. package/dist/{use-fluid-api-ByXKmAb3.mjs.map → use-fluid-api-BvakcAkY.mjs.map} +1 -1
  87. package/dist/{use-fluid-api-Cp5NpYvl.cjs → use-fluid-api-CBm9h3s3.cjs} +2 -2
  88. package/dist/{use-fluid-api-Cp5NpYvl.cjs.map → use-fluid-api-CBm9h3s3.cjs.map} +1 -1
  89. package/dist/vite/index.cjs +90 -2
  90. package/dist/vite/index.cjs.map +1 -1
  91. package/dist/vite/index.mjs +89 -1
  92. package/dist/vite/index.mjs.map +1 -1
  93. package/package.json +12 -12
@@ -1,4 +1,4 @@
1
- import { n as useFluidContext, o as useFluidAuthContext, q as createFetchClient } from "./FluidProvider-NsdWcsos.mjs";
1
+ import { n as useFluidContext, o as useFluidAuthContext, q as createFetchClient } from "./FluidProvider-9ZC28GXK.mjs";
2
2
  import { useMemo } from "react";
3
3
  //#region src/hooks/use-fluid-auth.ts
4
4
  /**
@@ -115,4 +115,4 @@ function useSdkClient() {
115
115
  //#endregion
116
116
  export { useSubscriptionsClient as a, useSdkClient as i, useFluidPayClient as n, useFluidAuth as o, useOrdersClient as r, API_VERSION as t };
117
117
 
118
- //# sourceMappingURL=use-account-clients-BNdnotPF.mjs.map
118
+ //# sourceMappingURL=use-account-clients-CqC0etbc.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-account-clients-BNdnotPF.mjs","names":["createOrdersFetchClient","createSubscriptionsFetchClient","createFluidPayFetchClient","createCoreFetchClient"],"sources":["../src/hooks/use-fluid-auth.ts","../src/account/use-account-clients.ts"],"sourcesContent":["/**\n * useFluidAuth Hook\n *\n * Provides access to authentication state and utilities.\n * This is the primary hook for interacting with auth in components.\n */\n\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\nimport type { FluidAuthContextValue } from \"../auth/types\";\n\n/**\n * Hook to access authentication state and utilities.\n *\n * Must be used within a `FluidAuthProvider`.\n *\n * @returns Authentication context with user info, loading state, and utilities\n * @throws Error if used outside FluidAuthProvider\n *\n * @example\n * ```tsx\n * function UserProfile() {\n * const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();\n *\n * if (isLoading) {\n * return <Spinner />;\n * }\n *\n * if (!isAuthenticated) {\n * return <p>Please log in</p>;\n * }\n *\n * return (\n * <div>\n * <p>Welcome, {user.full_name}!</p>\n * <button onClick={clearAuth}>Log out</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useFluidAuth(): FluidAuthContextValue {\n return useFluidAuthContext();\n}\n","import { useMemo } from \"react\";\nimport {\n createFetchClient as createOrdersFetchClient,\n type FetchClient as OrdersFetchClient,\n} from \"@fluid-app/orders-api-client\";\nimport {\n createFetchClient as createSubscriptionsFetchClient,\n type FetchClient as SubscriptionsFetchClient,\n} from \"@fluid-app/subscriptions-api-client\";\nimport {\n createFetchClient as createFluidPayFetchClient,\n type FetchClient as FluidPayFetchClient,\n} from \"@fluid-app/fluid-pay-api-client\";\nimport {\n createFetchClient as createCoreFetchClient,\n type FetchClient as CoreFetchClient,\n} from \"@fluid-app/api-client-core\";\nimport { useFluidContext } from \"../providers/FluidProvider\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\n\n/** API version prefix for versioned endpoints (e.g. points ledger) */\nexport const API_VERSION = \"/v202506\";\n\n/**\n * Ensures baseUrl ends with /api.\n * Domain-specific API clients (orders, subscriptions, fluid-pay) use endpoint\n * paths without /api (e.g. /fluid_pay/me, /subscriptions), matching fluid-admin's\n * NEXT_PUBLIC_API_URL convention. The portal SDK's config.baseUrl is the domain\n * root (e.g. https://api.fluid.app), so we append /api here.\n */\nfunction withApiPrefix(baseUrl: string): string {\n const base = baseUrl.replace(/\\/+$/, \"\");\n return base.endsWith(\"/api\") ? base : `${base}/api`;\n}\n\nexport function useOrdersClient(): OrdersFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createOrdersFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useSubscriptionsClient(): SubscriptionsFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createSubscriptionsFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useFluidPayClient(): FluidPayFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createFluidPayFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\n/**\n * Generic SDK fetch client for endpoints not covered by domain-specific clients\n * (e.g. /countries, /v202506/customers/:id/points_ledgers).\n * Uses the same auth/baseUrl/error handling as the domain clients.\n */\nexport function useSdkClient(): CoreFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createCoreFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,eAAsC;AACpD,QAAO,qBAAqB;;;;;ACpB9B,MAAa,cAAc;;;;;;;;AAS3B,SAAS,cAAc,SAAyB;CAC9C,MAAM,OAAO,QAAQ,QAAQ,QAAQ,GAAG;AACxC,QAAO,KAAK,SAAS,OAAO,GAAG,OAAO,GAAG,KAAK;;AAGhD,SAAgB,kBAAqC;CACnD,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHA,kBAAwB;EACtB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,yBAAmD;CACjE,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHC,kBAA+B;EAC7B,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,oBAAyC;CACvD,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHC,kBAA0B;EACxB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;;;;;;AAQH,SAAgB,eAAgC;CAC9C,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHC,kBAAsB;EACpB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C"}
1
+ {"version":3,"file":"use-account-clients-CqC0etbc.mjs","names":["createOrdersFetchClient","createSubscriptionsFetchClient","createFluidPayFetchClient","createCoreFetchClient"],"sources":["../src/hooks/use-fluid-auth.ts","../src/account/use-account-clients.ts"],"sourcesContent":["/**\n * useFluidAuth Hook\n *\n * Provides access to authentication state and utilities.\n * This is the primary hook for interacting with auth in components.\n */\n\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\nimport type { FluidAuthContextValue } from \"../auth/types\";\n\n/**\n * Hook to access authentication state and utilities.\n *\n * Must be used within a `FluidAuthProvider`.\n *\n * @returns Authentication context with user info, loading state, and utilities\n * @throws Error if used outside FluidAuthProvider\n *\n * @example\n * ```tsx\n * function UserProfile() {\n * const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();\n *\n * if (isLoading) {\n * return <Spinner />;\n * }\n *\n * if (!isAuthenticated) {\n * return <p>Please log in</p>;\n * }\n *\n * return (\n * <div>\n * <p>Welcome, {user.full_name}!</p>\n * <button onClick={clearAuth}>Log out</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useFluidAuth(): FluidAuthContextValue {\n return useFluidAuthContext();\n}\n","import { useMemo } from \"react\";\nimport {\n createFetchClient as createOrdersFetchClient,\n type FetchClient as OrdersFetchClient,\n} from \"@fluid-app/orders-api-client\";\nimport {\n createFetchClient as createSubscriptionsFetchClient,\n type FetchClient as SubscriptionsFetchClient,\n} from \"@fluid-app/subscriptions-api-client\";\nimport {\n createFetchClient as createFluidPayFetchClient,\n type FetchClient as FluidPayFetchClient,\n} from \"@fluid-app/fluid-pay-api-client\";\nimport {\n createFetchClient as createCoreFetchClient,\n type FetchClient as CoreFetchClient,\n} from \"@fluid-app/api-client-core\";\nimport { useFluidContext } from \"../providers/FluidProvider\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\n\n/** API version prefix for versioned endpoints (e.g. points ledger) */\nexport const API_VERSION = \"/v202506\";\n\n/**\n * Ensures baseUrl ends with /api.\n * Domain-specific API clients (orders, subscriptions, fluid-pay) use endpoint\n * paths without /api (e.g. /fluid_pay/me, /subscriptions), matching fluid-admin's\n * NEXT_PUBLIC_API_URL convention. The portal SDK's config.baseUrl is the domain\n * root (e.g. https://api.fluid.app), so we append /api here.\n */\nfunction withApiPrefix(baseUrl: string): string {\n const base = baseUrl.replace(/\\/+$/, \"\");\n return base.endsWith(\"/api\") ? base : `${base}/api`;\n}\n\nexport function useOrdersClient(): OrdersFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createOrdersFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useSubscriptionsClient(): SubscriptionsFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createSubscriptionsFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useFluidPayClient(): FluidPayFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createFluidPayFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\n/**\n * Generic SDK fetch client for endpoints not covered by domain-specific clients\n * (e.g. /countries, /v202506/customers/:id/points_ledgers).\n * Uses the same auth/baseUrl/error handling as the domain clients.\n */\nexport function useSdkClient(): CoreFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createCoreFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,eAAsC;AACpD,QAAO,qBAAqB;;;;;ACpB9B,MAAa,cAAc;;;;;;;;AAS3B,SAAS,cAAc,SAAyB;CAC9C,MAAM,OAAO,QAAQ,QAAQ,QAAQ,GAAG;AACxC,QAAO,KAAK,SAAS,OAAO,GAAG,OAAO,GAAG,KAAK;;AAGhD,SAAgB,kBAAqC;CACnD,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHA,kBAAwB;EACtB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,yBAAmD;CACjE,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHC,kBAA+B;EAC7B,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,oBAAyC;CACvD,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHC,kBAA0B;EACxB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;;;;;;AAQH,SAAgB,eAAgC;CAC9C,MAAM,EAAE,WAAW,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,QAAO,cAEHC,kBAAsB;EACpB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C"}
@@ -1,5 +1,5 @@
1
1
  require("./chunk-DAgNkxik.cjs");
2
- const require_FluidProvider = require("./FluidProvider-BcMVqXGW.cjs");
2
+ const require_FluidProvider = require("./FluidProvider-9JuTycML.cjs");
3
3
  let react = require("react");
4
4
  //#region src/hooks/use-fluid-auth.ts
5
5
  /**
@@ -151,4 +151,4 @@ Object.defineProperty(exports, "useSubscriptionsClient", {
151
151
  }
152
152
  });
153
153
 
154
- //# sourceMappingURL=use-account-clients-BcfCVnN1.cjs.map
154
+ //# sourceMappingURL=use-account-clients-cHyQEhPp.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-account-clients-BcfCVnN1.cjs","names":["useFluidAuthContext","useFluidContext","createOrdersFetchClient","createSubscriptionsFetchClient","createFluidPayFetchClient","createCoreFetchClient"],"sources":["../src/hooks/use-fluid-auth.ts","../src/account/use-account-clients.ts"],"sourcesContent":["/**\n * useFluidAuth Hook\n *\n * Provides access to authentication state and utilities.\n * This is the primary hook for interacting with auth in components.\n */\n\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\nimport type { FluidAuthContextValue } from \"../auth/types\";\n\n/**\n * Hook to access authentication state and utilities.\n *\n * Must be used within a `FluidAuthProvider`.\n *\n * @returns Authentication context with user info, loading state, and utilities\n * @throws Error if used outside FluidAuthProvider\n *\n * @example\n * ```tsx\n * function UserProfile() {\n * const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();\n *\n * if (isLoading) {\n * return <Spinner />;\n * }\n *\n * if (!isAuthenticated) {\n * return <p>Please log in</p>;\n * }\n *\n * return (\n * <div>\n * <p>Welcome, {user.full_name}!</p>\n * <button onClick={clearAuth}>Log out</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useFluidAuth(): FluidAuthContextValue {\n return useFluidAuthContext();\n}\n","import { useMemo } from \"react\";\nimport {\n createFetchClient as createOrdersFetchClient,\n type FetchClient as OrdersFetchClient,\n} from \"@fluid-app/orders-api-client\";\nimport {\n createFetchClient as createSubscriptionsFetchClient,\n type FetchClient as SubscriptionsFetchClient,\n} from \"@fluid-app/subscriptions-api-client\";\nimport {\n createFetchClient as createFluidPayFetchClient,\n type FetchClient as FluidPayFetchClient,\n} from \"@fluid-app/fluid-pay-api-client\";\nimport {\n createFetchClient as createCoreFetchClient,\n type FetchClient as CoreFetchClient,\n} from \"@fluid-app/api-client-core\";\nimport { useFluidContext } from \"../providers/FluidProvider\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\n\n/** API version prefix for versioned endpoints (e.g. points ledger) */\nexport const API_VERSION = \"/v202506\";\n\n/**\n * Ensures baseUrl ends with /api.\n * Domain-specific API clients (orders, subscriptions, fluid-pay) use endpoint\n * paths without /api (e.g. /fluid_pay/me, /subscriptions), matching fluid-admin's\n * NEXT_PUBLIC_API_URL convention. The portal SDK's config.baseUrl is the domain\n * root (e.g. https://api.fluid.app), so we append /api here.\n */\nfunction withApiPrefix(baseUrl: string): string {\n const base = baseUrl.replace(/\\/+$/, \"\");\n return base.endsWith(\"/api\") ? base : `${base}/api`;\n}\n\nexport function useOrdersClient(): OrdersFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createOrdersFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useSubscriptionsClient(): SubscriptionsFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createSubscriptionsFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useFluidPayClient(): FluidPayFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createFluidPayFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\n/**\n * Generic SDK fetch client for endpoints not covered by domain-specific clients\n * (e.g. /countries, /v202506/customers/:id/points_ledgers).\n * Uses the same auth/baseUrl/error handling as the domain clients.\n */\nexport function useSdkClient(): CoreFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createCoreFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,eAAsC;AACpD,QAAOA,sBAAAA,qBAAqB;;;;;ACpB9B,MAAa,cAAc;;;;;;;;AAS3B,SAAS,cAAc,SAAyB;CAC9C,MAAM,OAAO,QAAQ,QAAQ,QAAQ,GAAG;AACxC,QAAO,KAAK,SAAS,OAAO,GAAG,OAAO,GAAG,KAAK;;AAGhD,SAAgB,kBAAqC;CACnD,MAAM,EAAE,WAAWC,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEIC,sBAAAA,kBAAwB;EACtB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,yBAAmD;CACjE,MAAM,EAAE,WAAWD,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEIE,sBAAAA,kBAA+B;EAC7B,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,oBAAyC;CACvD,MAAM,EAAE,WAAWF,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEIG,sBAAAA,kBAA0B;EACxB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;;;;;;AAQH,SAAgB,eAAgC;CAC9C,MAAM,EAAE,WAAWH,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEII,sBAAAA,kBAAsB;EACpB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C"}
1
+ {"version":3,"file":"use-account-clients-cHyQEhPp.cjs","names":["useFluidAuthContext","useFluidContext","createOrdersFetchClient","createSubscriptionsFetchClient","createFluidPayFetchClient","createCoreFetchClient"],"sources":["../src/hooks/use-fluid-auth.ts","../src/account/use-account-clients.ts"],"sourcesContent":["/**\n * useFluidAuth Hook\n *\n * Provides access to authentication state and utilities.\n * This is the primary hook for interacting with auth in components.\n */\n\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\nimport type { FluidAuthContextValue } from \"../auth/types\";\n\n/**\n * Hook to access authentication state and utilities.\n *\n * Must be used within a `FluidAuthProvider`.\n *\n * @returns Authentication context with user info, loading state, and utilities\n * @throws Error if used outside FluidAuthProvider\n *\n * @example\n * ```tsx\n * function UserProfile() {\n * const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();\n *\n * if (isLoading) {\n * return <Spinner />;\n * }\n *\n * if (!isAuthenticated) {\n * return <p>Please log in</p>;\n * }\n *\n * return (\n * <div>\n * <p>Welcome, {user.full_name}!</p>\n * <button onClick={clearAuth}>Log out</button>\n * </div>\n * );\n * }\n * ```\n */\nexport function useFluidAuth(): FluidAuthContextValue {\n return useFluidAuthContext();\n}\n","import { useMemo } from \"react\";\nimport {\n createFetchClient as createOrdersFetchClient,\n type FetchClient as OrdersFetchClient,\n} from \"@fluid-app/orders-api-client\";\nimport {\n createFetchClient as createSubscriptionsFetchClient,\n type FetchClient as SubscriptionsFetchClient,\n} from \"@fluid-app/subscriptions-api-client\";\nimport {\n createFetchClient as createFluidPayFetchClient,\n type FetchClient as FluidPayFetchClient,\n} from \"@fluid-app/fluid-pay-api-client\";\nimport {\n createFetchClient as createCoreFetchClient,\n type FetchClient as CoreFetchClient,\n} from \"@fluid-app/api-client-core\";\nimport { useFluidContext } from \"../providers/FluidProvider\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\n\n/** API version prefix for versioned endpoints (e.g. points ledger) */\nexport const API_VERSION = \"/v202506\";\n\n/**\n * Ensures baseUrl ends with /api.\n * Domain-specific API clients (orders, subscriptions, fluid-pay) use endpoint\n * paths without /api (e.g. /fluid_pay/me, /subscriptions), matching fluid-admin's\n * NEXT_PUBLIC_API_URL convention. The portal SDK's config.baseUrl is the domain\n * root (e.g. https://api.fluid.app), so we append /api here.\n */\nfunction withApiPrefix(baseUrl: string): string {\n const base = baseUrl.replace(/\\/+$/, \"\");\n return base.endsWith(\"/api\") ? base : `${base}/api`;\n}\n\nexport function useOrdersClient(): OrdersFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createOrdersFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useSubscriptionsClient(): SubscriptionsFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createSubscriptionsFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\nexport function useFluidPayClient(): FluidPayFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createFluidPayFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n\n/**\n * Generic SDK fetch client for endpoints not covered by domain-specific clients\n * (e.g. /countries, /v202506/customers/:id/points_ledgers).\n * Uses the same auth/baseUrl/error handling as the domain clients.\n */\nexport function useSdkClient(): CoreFetchClient {\n const { config } = useFluidContext();\n const { token } = useFluidAuth();\n\n return useMemo(\n () =>\n createCoreFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n getAuthToken: () => token,\n onAuthError: config.onAuthError,\n }),\n [config.baseUrl, config.onAuthError, token],\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,eAAsC;AACpD,QAAOA,sBAAAA,qBAAqB;;;;;ACpB9B,MAAa,cAAc;;;;;;;;AAS3B,SAAS,cAAc,SAAyB;CAC9C,MAAM,OAAO,QAAQ,QAAQ,QAAQ,GAAG;AACxC,QAAO,KAAK,SAAS,OAAO,GAAG,OAAO,GAAG,KAAK;;AAGhD,SAAgB,kBAAqC;CACnD,MAAM,EAAE,WAAWC,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEIC,sBAAAA,kBAAwB;EACtB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,yBAAmD;CACjE,MAAM,EAAE,WAAWD,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEIE,sBAAAA,kBAA+B;EAC7B,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;AAGH,SAAgB,oBAAyC;CACvD,MAAM,EAAE,WAAWF,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEIG,sBAAAA,kBAA0B;EACxB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C;;;;;;;AAQH,SAAgB,eAAgC;CAC9C,MAAM,EAAE,WAAWH,sBAAAA,iBAAiB;CACpC,MAAM,EAAE,UAAU,cAAc;AAEhC,SAAA,GAAA,MAAA,eAEII,sBAAAA,kBAAsB;EACpB,SAAS,cAAc,OAAO,QAAQ;EACtC,oBAAoB;EACpB,aAAa,OAAO;EACrB,CAAC,EACJ;EAAC,OAAO;EAAS,OAAO;EAAa;EAAM,CAC5C"}
@@ -1,6 +1,6 @@
1
1
  require("./chunk-DAgNkxik.cjs");
2
- const require_FluidProvider = require("./FluidProvider-BcMVqXGW.cjs");
3
- const require_use_fluid_api = require("./use-fluid-api-Cp5NpYvl.cjs");
2
+ const require_FluidProvider = require("./FluidProvider-9JuTycML.cjs");
3
+ const require_use_fluid_api = require("./use-fluid-api-CBm9h3s3.cjs");
4
4
  let react = require("react");
5
5
  let _tanstack_react_query = require("@tanstack/react-query");
6
6
  //#region src/hooks/query-keys.ts
@@ -122,4 +122,4 @@ Object.defineProperty(exports, "useCurrentUser", {
122
122
  }
123
123
  });
124
124
 
125
- //# sourceMappingURL=use-current-user-C5ye4E_t.cjs.map
125
+ //# sourceMappingURL=use-current-user-Ccn1lGeB.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-user-C5ye4E_t.cjs","names":["useFluidAuthContext","useFluidApi"],"sources":["../src/hooks/query-keys.ts","../src/hooks/use-current-user.ts"],"sourcesContent":["/**\n * Company-scoped query key factory for TanStack Query.\n *\n * All portal SDK query keys are prefixed with [\"company\", companyId, ...]\n * so that switching companies naturally invalidates the entire cache scope.\n *\n * The exported `*_QUERY_KEY` constants (e.g. PROFILE_QUERY_KEY) remain as\n * backwards-compatible base keys. The runtime keys used by hooks include the\n * company prefix via {@link createCompanyQueryKey}.\n */\n\nimport { useCallback, useRef } from \"react\";\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\n\n/**\n * Create a company-scoped query key by prepending [\"company\", companyId].\n *\n * @param companyId - The company ID from the JWT payload\n * @param baseKey - The base query key segments (e.g. [\"fluid\", \"profile\"])\n * @returns A tuple like [\"company\", 42, \"fluid\", \"profile\"]\n *\n * @example\n * ```ts\n * const key = createCompanyQueryKey(42, \"fluid\", \"profile\");\n * // => [\"company\", 42, \"fluid\", \"profile\"]\n * ```\n */\nexport function createCompanyQueryKey(\n companyId: number,\n ...baseKey: readonly string[]\n): readonly [\"company\", number, ...string[]] {\n return [\"company\", companyId, ...baseKey] as const;\n}\n\n/**\n * Hook that returns a `scopeKey` function bound to the current company ID\n * from the auth context. If the user is not authenticated or has no\n * company_id, the base key is returned unscoped (graceful degradation).\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { scopeKey } = useCompanyScopedQueryKey();\n * const queryKey = scopeKey(PROFILE_QUERY_KEY);\n * // => [\"company\", 42, \"fluid\", \"profile\"] (when authenticated)\n * // => [\"fluid\", \"profile\"] (fallback)\n * }\n * ```\n */\nexport function useCompanyScopedQueryKey(): {\n readonly companyId: number | undefined;\n readonly scopeKey: <T extends readonly string[]>(\n baseKey: T,\n ) => readonly (string | number)[];\n} {\n const auth = useFluidAuthContext();\n const companyId = auth.user?.company_id;\n\n // Warn (once per component instance) when an authenticated user has no\n // company_id. This is a security-relevant condition: unscoped keys allow\n // cross-company cache collisions. The warning fires in all environments\n // so that it's visible in production logs if a misconfigured JWT is issued.\n const hasWarnedRef = useRef(false);\n if (auth.isAuthenticated && companyId == null && !hasWarnedRef.current) {\n hasWarnedRef.current = true;\n console.warn(\n \"[portal-sdk] Authenticated user has no company_id in JWT. \" +\n \"Query keys will fall back to unscoped keys, which may cause \" +\n \"cross-company cache collisions. Ensure the JWT includes company_id.\",\n );\n }\n\n const scopeKey = useCallback(\n <T extends readonly string[]>(baseKey: T): readonly (string | number)[] => {\n if (companyId != null) {\n return createCompanyQueryKey(companyId, ...baseKey);\n }\n return baseKey;\n },\n [companyId],\n );\n\n return { companyId, scopeKey } as const;\n}\n","import { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useFluidApi } from \"./use-fluid-api\";\nimport { useCompanyScopedQueryKey } from \"./query-keys\";\nimport type { UserMe } from \"../types/rep\";\n\n/**\n * Base query key for current user data.\n * Kept for backwards compatibility — the runtime key used by the hook\n * includes a company prefix via {@link useCompanyScopedQueryKey}.\n */\nexport const CURRENT_USER_QUERY_KEY = [\"fluid\", \"currentUser\"] as const;\n\n/**\n * Hook to fetch the currently authenticated user's full profile.\n * Returns company, country, and other fields from GET /api/me.\n *\n * @example\n * ```tsx\n * function ShopPage() {\n * const { data: user, isLoading } = useCurrentUser();\n * const subdomain = user?.company?.subdomain;\n * const countryIso = user?.country?.iso ?? \"US\";\n * // ...\n * }\n * ```\n */\nexport function useCurrentUser(): UseQueryResult<UserMe> {\n const api = useFluidApi();\n const { scopeKey } = useCompanyScopedQueryKey();\n\n return useQuery({\n queryKey: scopeKey(CURRENT_USER_QUERY_KEY),\n queryFn: () => api.users.me(),\n staleTime: 5 * 60 * 1000,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,sBACd,WACA,GAAG,SACwC;AAC3C,QAAO;EAAC;EAAW;EAAW,GAAG;EAAQ;;;;;;;;;;;;;;;;;AAkB3C,SAAgB,2BAKd;CACA,MAAM,OAAOA,sBAAAA,qBAAqB;CAClC,MAAM,YAAY,KAAK,MAAM;CAM7B,MAAM,gBAAA,GAAA,MAAA,QAAsB,MAAM;AAClC,KAAI,KAAK,mBAAmB,aAAa,QAAQ,CAAC,aAAa,SAAS;AACtE,eAAa,UAAU;AACvB,UAAQ,KACN,4LAGD;;AAaH,QAAO;EAAE;EAAW,WAAA,GAAA,MAAA,cATY,YAA6C;AACzE,OAAI,aAAa,KACf,QAAO,sBAAsB,WAAW,GAAG,QAAQ;AAErD,UAAO;KAET,CAAC,UAAU,CACZ;EAE6B;;;;;;;;;ACxEhC,MAAa,yBAAyB,CAAC,SAAS,cAAc;;;;;;;;;;;;;;;AAgB9D,SAAgB,iBAAyC;CACvD,MAAM,MAAMC,sBAAAA,aAAa;CACzB,MAAM,EAAE,aAAa,0BAA0B;AAE/C,SAAA,GAAA,sBAAA,UAAgB;EACd,UAAU,SAAS,uBAAuB;EAC1C,eAAe,IAAI,MAAM,IAAI;EAC7B,WAAW,MAAS;EACrB,CAAC"}
1
+ {"version":3,"file":"use-current-user-Ccn1lGeB.cjs","names":["useFluidAuthContext","useFluidApi"],"sources":["../src/hooks/query-keys.ts","../src/hooks/use-current-user.ts"],"sourcesContent":["/**\n * Company-scoped query key factory for TanStack Query.\n *\n * All portal SDK query keys are prefixed with [\"company\", companyId, ...]\n * so that switching companies naturally invalidates the entire cache scope.\n *\n * The exported `*_QUERY_KEY` constants (e.g. PROFILE_QUERY_KEY) remain as\n * backwards-compatible base keys. The runtime keys used by hooks include the\n * company prefix via {@link createCompanyQueryKey}.\n */\n\nimport { useCallback, useRef } from \"react\";\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\n\n/**\n * Create a company-scoped query key by prepending [\"company\", companyId].\n *\n * @param companyId - The company ID from the JWT payload\n * @param baseKey - The base query key segments (e.g. [\"fluid\", \"profile\"])\n * @returns A tuple like [\"company\", 42, \"fluid\", \"profile\"]\n *\n * @example\n * ```ts\n * const key = createCompanyQueryKey(42, \"fluid\", \"profile\");\n * // => [\"company\", 42, \"fluid\", \"profile\"]\n * ```\n */\nexport function createCompanyQueryKey(\n companyId: number,\n ...baseKey: readonly string[]\n): readonly [\"company\", number, ...string[]] {\n return [\"company\", companyId, ...baseKey] as const;\n}\n\n/**\n * Hook that returns a `scopeKey` function bound to the current company ID\n * from the auth context. If the user is not authenticated or has no\n * company_id, the base key is returned unscoped (graceful degradation).\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { scopeKey } = useCompanyScopedQueryKey();\n * const queryKey = scopeKey(PROFILE_QUERY_KEY);\n * // => [\"company\", 42, \"fluid\", \"profile\"] (when authenticated)\n * // => [\"fluid\", \"profile\"] (fallback)\n * }\n * ```\n */\nexport function useCompanyScopedQueryKey(): {\n readonly companyId: number | undefined;\n readonly scopeKey: <T extends readonly string[]>(\n baseKey: T,\n ) => readonly (string | number)[];\n} {\n const auth = useFluidAuthContext();\n const companyId = auth.user?.company_id;\n\n // Warn (once per component instance) when an authenticated user has no\n // company_id. This is a security-relevant condition: unscoped keys allow\n // cross-company cache collisions. The warning fires in all environments\n // so that it's visible in production logs if a misconfigured JWT is issued.\n const hasWarnedRef = useRef(false);\n if (auth.isAuthenticated && companyId == null && !hasWarnedRef.current) {\n hasWarnedRef.current = true;\n console.warn(\n \"[portal-sdk] Authenticated user has no company_id in JWT. \" +\n \"Query keys will fall back to unscoped keys, which may cause \" +\n \"cross-company cache collisions. Ensure the JWT includes company_id.\",\n );\n }\n\n const scopeKey = useCallback(\n <T extends readonly string[]>(baseKey: T): readonly (string | number)[] => {\n if (companyId != null) {\n return createCompanyQueryKey(companyId, ...baseKey);\n }\n return baseKey;\n },\n [companyId],\n );\n\n return { companyId, scopeKey } as const;\n}\n","import { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useFluidApi } from \"./use-fluid-api\";\nimport { useCompanyScopedQueryKey } from \"./query-keys\";\nimport type { UserMe } from \"../types/rep\";\n\n/**\n * Base query key for current user data.\n * Kept for backwards compatibility — the runtime key used by the hook\n * includes a company prefix via {@link useCompanyScopedQueryKey}.\n */\nexport const CURRENT_USER_QUERY_KEY = [\"fluid\", \"currentUser\"] as const;\n\n/**\n * Hook to fetch the currently authenticated user's full profile.\n * Returns company, country, and other fields from GET /api/me.\n *\n * @example\n * ```tsx\n * function ShopPage() {\n * const { data: user, isLoading } = useCurrentUser();\n * const subdomain = user?.company?.subdomain;\n * const countryIso = user?.country?.iso ?? \"US\";\n * // ...\n * }\n * ```\n */\nexport function useCurrentUser(): UseQueryResult<UserMe> {\n const api = useFluidApi();\n const { scopeKey } = useCompanyScopedQueryKey();\n\n return useQuery({\n queryKey: scopeKey(CURRENT_USER_QUERY_KEY),\n queryFn: () => api.users.me(),\n staleTime: 5 * 60 * 1000,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,sBACd,WACA,GAAG,SACwC;AAC3C,QAAO;EAAC;EAAW;EAAW,GAAG;EAAQ;;;;;;;;;;;;;;;;;AAkB3C,SAAgB,2BAKd;CACA,MAAM,OAAOA,sBAAAA,qBAAqB;CAClC,MAAM,YAAY,KAAK,MAAM;CAM7B,MAAM,gBAAA,GAAA,MAAA,QAAsB,MAAM;AAClC,KAAI,KAAK,mBAAmB,aAAa,QAAQ,CAAC,aAAa,SAAS;AACtE,eAAa,UAAU;AACvB,UAAQ,KACN,4LAGD;;AAaH,QAAO;EAAE;EAAW,WAAA,GAAA,MAAA,cATY,YAA6C;AACzE,OAAI,aAAa,KACf,QAAO,sBAAsB,WAAW,GAAG,QAAQ;AAErD,UAAO;KAET,CAAC,UAAU,CACZ;EAE6B;;;;;;;;;ACxEhC,MAAa,yBAAyB,CAAC,SAAS,cAAc;;;;;;;;;;;;;;;AAgB9D,SAAgB,iBAAyC;CACvD,MAAM,MAAMC,sBAAAA,aAAa;CACzB,MAAM,EAAE,aAAa,0BAA0B;AAE/C,SAAA,GAAA,sBAAA,UAAgB;EACd,UAAU,SAAS,uBAAuB;EAC1C,eAAe,IAAI,MAAM,IAAI;EAC7B,WAAW,MAAS;EACrB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { o as useFluidAuthContext } from "./FluidProvider-NsdWcsos.mjs";
2
- import { t as useFluidApi } from "./use-fluid-api-ByXKmAb3.mjs";
1
+ import { o as useFluidAuthContext } from "./FluidProvider-9ZC28GXK.mjs";
2
+ import { t as useFluidApi } from "./use-fluid-api-BvakcAkY.mjs";
3
3
  import { useCallback, useRef } from "react";
4
4
  import { useQuery } from "@tanstack/react-query";
5
5
  //#region src/hooks/query-keys.ts
@@ -98,4 +98,4 @@ function useCurrentUser() {
98
98
  //#endregion
99
99
  export { useCompanyScopedQueryKey as i, useCurrentUser as n, createCompanyQueryKey as r, CURRENT_USER_QUERY_KEY as t };
100
100
 
101
- //# sourceMappingURL=use-current-user-BR36V_-x.mjs.map
101
+ //# sourceMappingURL=use-current-user-CyodELl8.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-current-user-BR36V_-x.mjs","names":[],"sources":["../src/hooks/query-keys.ts","../src/hooks/use-current-user.ts"],"sourcesContent":["/**\n * Company-scoped query key factory for TanStack Query.\n *\n * All portal SDK query keys are prefixed with [\"company\", companyId, ...]\n * so that switching companies naturally invalidates the entire cache scope.\n *\n * The exported `*_QUERY_KEY` constants (e.g. PROFILE_QUERY_KEY) remain as\n * backwards-compatible base keys. The runtime keys used by hooks include the\n * company prefix via {@link createCompanyQueryKey}.\n */\n\nimport { useCallback, useRef } from \"react\";\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\n\n/**\n * Create a company-scoped query key by prepending [\"company\", companyId].\n *\n * @param companyId - The company ID from the JWT payload\n * @param baseKey - The base query key segments (e.g. [\"fluid\", \"profile\"])\n * @returns A tuple like [\"company\", 42, \"fluid\", \"profile\"]\n *\n * @example\n * ```ts\n * const key = createCompanyQueryKey(42, \"fluid\", \"profile\");\n * // => [\"company\", 42, \"fluid\", \"profile\"]\n * ```\n */\nexport function createCompanyQueryKey(\n companyId: number,\n ...baseKey: readonly string[]\n): readonly [\"company\", number, ...string[]] {\n return [\"company\", companyId, ...baseKey] as const;\n}\n\n/**\n * Hook that returns a `scopeKey` function bound to the current company ID\n * from the auth context. If the user is not authenticated or has no\n * company_id, the base key is returned unscoped (graceful degradation).\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { scopeKey } = useCompanyScopedQueryKey();\n * const queryKey = scopeKey(PROFILE_QUERY_KEY);\n * // => [\"company\", 42, \"fluid\", \"profile\"] (when authenticated)\n * // => [\"fluid\", \"profile\"] (fallback)\n * }\n * ```\n */\nexport function useCompanyScopedQueryKey(): {\n readonly companyId: number | undefined;\n readonly scopeKey: <T extends readonly string[]>(\n baseKey: T,\n ) => readonly (string | number)[];\n} {\n const auth = useFluidAuthContext();\n const companyId = auth.user?.company_id;\n\n // Warn (once per component instance) when an authenticated user has no\n // company_id. This is a security-relevant condition: unscoped keys allow\n // cross-company cache collisions. The warning fires in all environments\n // so that it's visible in production logs if a misconfigured JWT is issued.\n const hasWarnedRef = useRef(false);\n if (auth.isAuthenticated && companyId == null && !hasWarnedRef.current) {\n hasWarnedRef.current = true;\n console.warn(\n \"[portal-sdk] Authenticated user has no company_id in JWT. \" +\n \"Query keys will fall back to unscoped keys, which may cause \" +\n \"cross-company cache collisions. Ensure the JWT includes company_id.\",\n );\n }\n\n const scopeKey = useCallback(\n <T extends readonly string[]>(baseKey: T): readonly (string | number)[] => {\n if (companyId != null) {\n return createCompanyQueryKey(companyId, ...baseKey);\n }\n return baseKey;\n },\n [companyId],\n );\n\n return { companyId, scopeKey } as const;\n}\n","import { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useFluidApi } from \"./use-fluid-api\";\nimport { useCompanyScopedQueryKey } from \"./query-keys\";\nimport type { UserMe } from \"../types/rep\";\n\n/**\n * Base query key for current user data.\n * Kept for backwards compatibility — the runtime key used by the hook\n * includes a company prefix via {@link useCompanyScopedQueryKey}.\n */\nexport const CURRENT_USER_QUERY_KEY = [\"fluid\", \"currentUser\"] as const;\n\n/**\n * Hook to fetch the currently authenticated user's full profile.\n * Returns company, country, and other fields from GET /api/me.\n *\n * @example\n * ```tsx\n * function ShopPage() {\n * const { data: user, isLoading } = useCurrentUser();\n * const subdomain = user?.company?.subdomain;\n * const countryIso = user?.country?.iso ?? \"US\";\n * // ...\n * }\n * ```\n */\nexport function useCurrentUser(): UseQueryResult<UserMe> {\n const api = useFluidApi();\n const { scopeKey } = useCompanyScopedQueryKey();\n\n return useQuery({\n queryKey: scopeKey(CURRENT_USER_QUERY_KEY),\n queryFn: () => api.users.me(),\n staleTime: 5 * 60 * 1000,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,sBACd,WACA,GAAG,SACwC;AAC3C,QAAO;EAAC;EAAW;EAAW,GAAG;EAAQ;;;;;;;;;;;;;;;;;AAkB3C,SAAgB,2BAKd;CACA,MAAM,OAAO,qBAAqB;CAClC,MAAM,YAAY,KAAK,MAAM;CAM7B,MAAM,eAAe,OAAO,MAAM;AAClC,KAAI,KAAK,mBAAmB,aAAa,QAAQ,CAAC,aAAa,SAAS;AACtE,eAAa,UAAU;AACvB,UAAQ,KACN,4LAGD;;AAaH,QAAO;EAAE;EAAW,UAVH,aACe,YAA6C;AACzE,OAAI,aAAa,KACf,QAAO,sBAAsB,WAAW,GAAG,QAAQ;AAErD,UAAO;KAET,CAAC,UAAU,CACZ;EAE6B;;;;;;;;;ACxEhC,MAAa,yBAAyB,CAAC,SAAS,cAAc;;;;;;;;;;;;;;;AAgB9D,SAAgB,iBAAyC;CACvD,MAAM,MAAM,aAAa;CACzB,MAAM,EAAE,aAAa,0BAA0B;AAE/C,QAAO,SAAS;EACd,UAAU,SAAS,uBAAuB;EAC1C,eAAe,IAAI,MAAM,IAAI;EAC7B,WAAW,MAAS;EACrB,CAAC"}
1
+ {"version":3,"file":"use-current-user-CyodELl8.mjs","names":[],"sources":["../src/hooks/query-keys.ts","../src/hooks/use-current-user.ts"],"sourcesContent":["/**\n * Company-scoped query key factory for TanStack Query.\n *\n * All portal SDK query keys are prefixed with [\"company\", companyId, ...]\n * so that switching companies naturally invalidates the entire cache scope.\n *\n * The exported `*_QUERY_KEY` constants (e.g. PROFILE_QUERY_KEY) remain as\n * backwards-compatible base keys. The runtime keys used by hooks include the\n * company prefix via {@link createCompanyQueryKey}.\n */\n\nimport { useCallback, useRef } from \"react\";\nimport { useFluidAuthContext } from \"../providers/FluidAuthProvider\";\n\n/**\n * Create a company-scoped query key by prepending [\"company\", companyId].\n *\n * @param companyId - The company ID from the JWT payload\n * @param baseKey - The base query key segments (e.g. [\"fluid\", \"profile\"])\n * @returns A tuple like [\"company\", 42, \"fluid\", \"profile\"]\n *\n * @example\n * ```ts\n * const key = createCompanyQueryKey(42, \"fluid\", \"profile\");\n * // => [\"company\", 42, \"fluid\", \"profile\"]\n * ```\n */\nexport function createCompanyQueryKey(\n companyId: number,\n ...baseKey: readonly string[]\n): readonly [\"company\", number, ...string[]] {\n return [\"company\", companyId, ...baseKey] as const;\n}\n\n/**\n * Hook that returns a `scopeKey` function bound to the current company ID\n * from the auth context. If the user is not authenticated or has no\n * company_id, the base key is returned unscoped (graceful degradation).\n *\n * @example\n * ```tsx\n * function MyComponent() {\n * const { scopeKey } = useCompanyScopedQueryKey();\n * const queryKey = scopeKey(PROFILE_QUERY_KEY);\n * // => [\"company\", 42, \"fluid\", \"profile\"] (when authenticated)\n * // => [\"fluid\", \"profile\"] (fallback)\n * }\n * ```\n */\nexport function useCompanyScopedQueryKey(): {\n readonly companyId: number | undefined;\n readonly scopeKey: <T extends readonly string[]>(\n baseKey: T,\n ) => readonly (string | number)[];\n} {\n const auth = useFluidAuthContext();\n const companyId = auth.user?.company_id;\n\n // Warn (once per component instance) when an authenticated user has no\n // company_id. This is a security-relevant condition: unscoped keys allow\n // cross-company cache collisions. The warning fires in all environments\n // so that it's visible in production logs if a misconfigured JWT is issued.\n const hasWarnedRef = useRef(false);\n if (auth.isAuthenticated && companyId == null && !hasWarnedRef.current) {\n hasWarnedRef.current = true;\n console.warn(\n \"[portal-sdk] Authenticated user has no company_id in JWT. \" +\n \"Query keys will fall back to unscoped keys, which may cause \" +\n \"cross-company cache collisions. Ensure the JWT includes company_id.\",\n );\n }\n\n const scopeKey = useCallback(\n <T extends readonly string[]>(baseKey: T): readonly (string | number)[] => {\n if (companyId != null) {\n return createCompanyQueryKey(companyId, ...baseKey);\n }\n return baseKey;\n },\n [companyId],\n );\n\n return { companyId, scopeKey } as const;\n}\n","import { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useFluidApi } from \"./use-fluid-api\";\nimport { useCompanyScopedQueryKey } from \"./query-keys\";\nimport type { UserMe } from \"../types/rep\";\n\n/**\n * Base query key for current user data.\n * Kept for backwards compatibility — the runtime key used by the hook\n * includes a company prefix via {@link useCompanyScopedQueryKey}.\n */\nexport const CURRENT_USER_QUERY_KEY = [\"fluid\", \"currentUser\"] as const;\n\n/**\n * Hook to fetch the currently authenticated user's full profile.\n * Returns company, country, and other fields from GET /api/me.\n *\n * @example\n * ```tsx\n * function ShopPage() {\n * const { data: user, isLoading } = useCurrentUser();\n * const subdomain = user?.company?.subdomain;\n * const countryIso = user?.country?.iso ?? \"US\";\n * // ...\n * }\n * ```\n */\nexport function useCurrentUser(): UseQueryResult<UserMe> {\n const api = useFluidApi();\n const { scopeKey } = useCompanyScopedQueryKey();\n\n return useQuery({\n queryKey: scopeKey(CURRENT_USER_QUERY_KEY),\n queryFn: () => api.users.me(),\n staleTime: 5 * 60 * 1000,\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,sBACd,WACA,GAAG,SACwC;AAC3C,QAAO;EAAC;EAAW;EAAW,GAAG;EAAQ;;;;;;;;;;;;;;;;;AAkB3C,SAAgB,2BAKd;CACA,MAAM,OAAO,qBAAqB;CAClC,MAAM,YAAY,KAAK,MAAM;CAM7B,MAAM,eAAe,OAAO,MAAM;AAClC,KAAI,KAAK,mBAAmB,aAAa,QAAQ,CAAC,aAAa,SAAS;AACtE,eAAa,UAAU;AACvB,UAAQ,KACN,4LAGD;;AAaH,QAAO;EAAE;EAAW,UAVH,aACe,YAA6C;AACzE,OAAI,aAAa,KACf,QAAO,sBAAsB,WAAW,GAAG,QAAQ;AAErD,UAAO;KAET,CAAC,UAAU,CACZ;EAE6B;;;;;;;;;ACxEhC,MAAa,yBAAyB,CAAC,SAAS,cAAc;;;;;;;;;;;;;;;AAgB9D,SAAgB,iBAAyC;CACvD,MAAM,MAAM,aAAa;CACzB,MAAM,EAAE,aAAa,0BAA0B;AAE/C,QAAO,SAAS;EACd,UAAU,SAAS,uBAAuB;EAC1C,eAAe,IAAI,MAAM,IAAI;EAC7B,WAAW,MAAS;EACrB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { W as fetchCustomerAccount } from "./FluidProvider-NsdWcsos.mjs";
2
- import { n as useFluidPayClient, o as useFluidAuth } from "./use-account-clients-BNdnotPF.mjs";
1
+ import { W as fetchCustomerAccount } from "./FluidProvider-9ZC28GXK.mjs";
2
+ import { n as useFluidPayClient, o as useFluidAuth } from "./use-account-clients-CqC0etbc.mjs";
3
3
  import { useQuery } from "@tanstack/react-query";
4
4
  //#region src/account/use-customer-account.ts
5
5
  function useCustomerAccount({ enabled = true } = {}) {
@@ -20,4 +20,4 @@ function useCustomerAccount({ enabled = true } = {}) {
20
20
  //#endregion
21
21
  export { useCustomerAccount as t };
22
22
 
23
- //# sourceMappingURL=use-customer-account-CBRukk1K.mjs.map
23
+ //# sourceMappingURL=use-customer-account-DODRyBye.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-customer-account-CBRukk1K.mjs","names":["customersApi.fetchCustomerAccount"],"sources":["../src/account/use-customer-account.ts"],"sourcesContent":["import { useQuery } from \"@tanstack/react-query\";\nimport { customersApi } from \"@fluid-app/fluid-pay-api-client\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\nimport { useFluidPayClient } from \"./use-account-clients\";\n\nexport function useCustomerAccount({\n enabled = true,\n}: { enabled?: boolean } = {}) {\n const { token, user } = useFluidAuth();\n const fluidPayClient = useFluidPayClient();\n const jwt = token ?? \"\";\n\n const query = useQuery({\n queryKey: [\"fluidPayAccount\", user?.id],\n queryFn: () => customersApi.fetchCustomerAccount(fluidPayClient, jwt),\n enabled: !!jwt && enabled,\n });\n\n return {\n customerId: query.data?.customer?.id,\n isLoadingCustomer: query.isLoading,\n isCustomerError: query.isError,\n };\n}\n"],"mappings":";;;;AAKA,SAAgB,mBAAmB,EACjC,UAAU,SACe,EAAE,EAAE;CAC7B,MAAM,EAAE,OAAO,SAAS,cAAc;CACtC,MAAM,iBAAiB,mBAAmB;CAC1C,MAAM,MAAM,SAAS;CAErB,MAAM,QAAQ,SAAS;EACrB,UAAU,CAAC,mBAAmB,MAAM,GAAG;EACvC,eAAeA,qBAAkC,gBAAgB,IAAI;EACrE,SAAS,CAAC,CAAC,OAAO;EACnB,CAAC;AAEF,QAAO;EACL,YAAY,MAAM,MAAM,UAAU;EAClC,mBAAmB,MAAM;EACzB,iBAAiB,MAAM;EACxB"}
1
+ {"version":3,"file":"use-customer-account-DODRyBye.mjs","names":["customersApi.fetchCustomerAccount"],"sources":["../src/account/use-customer-account.ts"],"sourcesContent":["import { useQuery } from \"@tanstack/react-query\";\nimport { customersApi } from \"@fluid-app/fluid-pay-api-client\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\nimport { useFluidPayClient } from \"./use-account-clients\";\n\nexport function useCustomerAccount({\n enabled = true,\n}: { enabled?: boolean } = {}) {\n const { token, user } = useFluidAuth();\n const fluidPayClient = useFluidPayClient();\n const jwt = token ?? \"\";\n\n const query = useQuery({\n queryKey: [\"fluidPayAccount\", user?.id],\n queryFn: () => customersApi.fetchCustomerAccount(fluidPayClient, jwt),\n enabled: !!jwt && enabled,\n });\n\n return {\n customerId: query.data?.customer?.id,\n isLoadingCustomer: query.isLoading,\n isCustomerError: query.isError,\n };\n}\n"],"mappings":";;;;AAKA,SAAgB,mBAAmB,EACjC,UAAU,SACe,EAAE,EAAE;CAC7B,MAAM,EAAE,OAAO,SAAS,cAAc;CACtC,MAAM,iBAAiB,mBAAmB;CAC1C,MAAM,MAAM,SAAS;CAErB,MAAM,QAAQ,SAAS;EACrB,UAAU,CAAC,mBAAmB,MAAM,GAAG;EACvC,eAAeA,qBAAkC,gBAAgB,IAAI;EACrE,SAAS,CAAC,CAAC,OAAO;EACnB,CAAC;AAEF,QAAO;EACL,YAAY,MAAM,MAAM,UAAU;EAClC,mBAAmB,MAAM;EACzB,iBAAiB,MAAM;EACxB"}
@@ -1,6 +1,6 @@
1
1
  require("./chunk-DAgNkxik.cjs");
2
- const require_FluidProvider = require("./FluidProvider-BcMVqXGW.cjs");
3
- const require_use_account_clients = require("./use-account-clients-BcfCVnN1.cjs");
2
+ const require_FluidProvider = require("./FluidProvider-9JuTycML.cjs");
3
+ const require_use_account_clients = require("./use-account-clients-cHyQEhPp.cjs");
4
4
  let _tanstack_react_query = require("@tanstack/react-query");
5
5
  //#region src/account/use-customer-account.ts
6
6
  function useCustomerAccount({ enabled = true } = {}) {
@@ -26,4 +26,4 @@ Object.defineProperty(exports, "useCustomerAccount", {
26
26
  }
27
27
  });
28
28
 
29
- //# sourceMappingURL=use-customer-account-BUcZbQG8.cjs.map
29
+ //# sourceMappingURL=use-customer-account-DOmzp1sM.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-customer-account-BUcZbQG8.cjs","names":["useFluidAuth","useFluidPayClient"],"sources":["../src/account/use-customer-account.ts"],"sourcesContent":["import { useQuery } from \"@tanstack/react-query\";\nimport { customersApi } from \"@fluid-app/fluid-pay-api-client\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\nimport { useFluidPayClient } from \"./use-account-clients\";\n\nexport function useCustomerAccount({\n enabled = true,\n}: { enabled?: boolean } = {}) {\n const { token, user } = useFluidAuth();\n const fluidPayClient = useFluidPayClient();\n const jwt = token ?? \"\";\n\n const query = useQuery({\n queryKey: [\"fluidPayAccount\", user?.id],\n queryFn: () => customersApi.fetchCustomerAccount(fluidPayClient, jwt),\n enabled: !!jwt && enabled,\n });\n\n return {\n customerId: query.data?.customer?.id,\n isLoadingCustomer: query.isLoading,\n isCustomerError: query.isError,\n };\n}\n"],"mappings":";;;;;AAKA,SAAgB,mBAAmB,EACjC,UAAU,SACe,EAAE,EAAE;CAC7B,MAAM,EAAE,OAAO,SAASA,4BAAAA,cAAc;CACtC,MAAM,iBAAiBC,4BAAAA,mBAAmB;CAC1C,MAAM,MAAM,SAAS;CAErB,MAAM,SAAA,GAAA,sBAAA,UAAiB;EACrB,UAAU,CAAC,mBAAmB,MAAM,GAAG;EACvC,eAAA,sBAAA,qBAAiD,gBAAgB,IAAI;EACrE,SAAS,CAAC,CAAC,OAAO;EACnB,CAAC;AAEF,QAAO;EACL,YAAY,MAAM,MAAM,UAAU;EAClC,mBAAmB,MAAM;EACzB,iBAAiB,MAAM;EACxB"}
1
+ {"version":3,"file":"use-customer-account-DOmzp1sM.cjs","names":["useFluidAuth","useFluidPayClient"],"sources":["../src/account/use-customer-account.ts"],"sourcesContent":["import { useQuery } from \"@tanstack/react-query\";\nimport { customersApi } from \"@fluid-app/fluid-pay-api-client\";\nimport { useFluidAuth } from \"../hooks/use-fluid-auth\";\nimport { useFluidPayClient } from \"./use-account-clients\";\n\nexport function useCustomerAccount({\n enabled = true,\n}: { enabled?: boolean } = {}) {\n const { token, user } = useFluidAuth();\n const fluidPayClient = useFluidPayClient();\n const jwt = token ?? \"\";\n\n const query = useQuery({\n queryKey: [\"fluidPayAccount\", user?.id],\n queryFn: () => customersApi.fetchCustomerAccount(fluidPayClient, jwt),\n enabled: !!jwt && enabled,\n });\n\n return {\n customerId: query.data?.customer?.id,\n isLoadingCustomer: query.isLoading,\n isCustomerError: query.isError,\n };\n}\n"],"mappings":";;;;;AAKA,SAAgB,mBAAmB,EACjC,UAAU,SACe,EAAE,EAAE;CAC7B,MAAM,EAAE,OAAO,SAASA,4BAAAA,cAAc;CACtC,MAAM,iBAAiBC,4BAAAA,mBAAmB;CAC1C,MAAM,MAAM,SAAS;CAErB,MAAM,SAAA,GAAA,sBAAA,UAAiB;EACrB,UAAU,CAAC,mBAAmB,MAAM,GAAG;EACvC,eAAA,sBAAA,qBAAiD,gBAAgB,IAAI;EACrE,SAAS,CAAC,CAAC,OAAO;EACnB,CAAC;AAEF,QAAO;EACL,YAAY,MAAM,MAAM,UAAU;EAClC,mBAAmB,MAAM;EACzB,iBAAiB,MAAM;EACxB"}
@@ -1,4 +1,4 @@
1
- import { n as useFluidContext } from "./FluidProvider-NsdWcsos.mjs";
1
+ import { n as useFluidContext } from "./FluidProvider-9ZC28GXK.mjs";
2
2
  //#region src/hooks/use-fluid-api.ts
3
3
  /**
4
4
  * Hook to access the Fluid API client
@@ -24,4 +24,4 @@ function useFluidApi() {
24
24
  //#endregion
25
25
  export { useFluidApi as t };
26
26
 
27
- //# sourceMappingURL=use-fluid-api-ByXKmAb3.mjs.map
27
+ //# sourceMappingURL=use-fluid-api-BvakcAkY.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-fluid-api-ByXKmAb3.mjs","names":[],"sources":["../src/hooks/use-fluid-api.ts"],"sourcesContent":["import { useFluidContext } from \"../providers/FluidProvider\";\nimport type { FluidClient } from \"../client/fluid-client\";\n\n/**\n * Hook to access the Fluid API client\n *\n * @example\n * ```tsx\n * function ProductList() {\n * const api = useFluidApi();\n *\n * const { data: products } = useQuery({\n * queryKey: [\"products\"],\n * queryFn: () => api.products.list(),\n * });\n *\n * return <ul>{products?.map(p => <li key={p.id}>{p.name}</li>)}</ul>;\n * }\n * ```\n */\nexport function useFluidApi(): FluidClient {\n const { client } = useFluidContext();\n return client;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,cAA2B;CACzC,MAAM,EAAE,WAAW,iBAAiB;AACpC,QAAO"}
1
+ {"version":3,"file":"use-fluid-api-BvakcAkY.mjs","names":[],"sources":["../src/hooks/use-fluid-api.ts"],"sourcesContent":["import { useFluidContext } from \"../providers/FluidProvider\";\nimport type { FluidClient } from \"../client/fluid-client\";\n\n/**\n * Hook to access the Fluid API client\n *\n * @example\n * ```tsx\n * function ProductList() {\n * const api = useFluidApi();\n *\n * const { data: products } = useQuery({\n * queryKey: [\"products\"],\n * queryFn: () => api.products.list(),\n * });\n *\n * return <ul>{products?.map(p => <li key={p.id}>{p.name}</li>)}</ul>;\n * }\n * ```\n */\nexport function useFluidApi(): FluidClient {\n const { client } = useFluidContext();\n return client;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,cAA2B;CACzC,MAAM,EAAE,WAAW,iBAAiB;AACpC,QAAO"}
@@ -1,4 +1,4 @@
1
- const require_FluidProvider = require("./FluidProvider-BcMVqXGW.cjs");
1
+ const require_FluidProvider = require("./FluidProvider-9JuTycML.cjs");
2
2
  //#region src/hooks/use-fluid-api.ts
3
3
  /**
4
4
  * Hook to access the Fluid API client
@@ -29,4 +29,4 @@ Object.defineProperty(exports, "useFluidApi", {
29
29
  }
30
30
  });
31
31
 
32
- //# sourceMappingURL=use-fluid-api-Cp5NpYvl.cjs.map
32
+ //# sourceMappingURL=use-fluid-api-CBm9h3s3.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-fluid-api-Cp5NpYvl.cjs","names":["useFluidContext"],"sources":["../src/hooks/use-fluid-api.ts"],"sourcesContent":["import { useFluidContext } from \"../providers/FluidProvider\";\nimport type { FluidClient } from \"../client/fluid-client\";\n\n/**\n * Hook to access the Fluid API client\n *\n * @example\n * ```tsx\n * function ProductList() {\n * const api = useFluidApi();\n *\n * const { data: products } = useQuery({\n * queryKey: [\"products\"],\n * queryFn: () => api.products.list(),\n * });\n *\n * return <ul>{products?.map(p => <li key={p.id}>{p.name}</li>)}</ul>;\n * }\n * ```\n */\nexport function useFluidApi(): FluidClient {\n const { client } = useFluidContext();\n return client;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,cAA2B;CACzC,MAAM,EAAE,WAAWA,sBAAAA,iBAAiB;AACpC,QAAO"}
1
+ {"version":3,"file":"use-fluid-api-CBm9h3s3.cjs","names":["useFluidContext"],"sources":["../src/hooks/use-fluid-api.ts"],"sourcesContent":["import { useFluidContext } from \"../providers/FluidProvider\";\nimport type { FluidClient } from \"../client/fluid-client\";\n\n/**\n * Hook to access the Fluid API client\n *\n * @example\n * ```tsx\n * function ProductList() {\n * const api = useFluidApi();\n *\n * const { data: products } = useQuery({\n * queryKey: [\"products\"],\n * queryFn: () => api.products.list(),\n * });\n *\n * return <ul>{products?.map(p => <li key={p.id}>{p.name}</li>)}</ul>;\n * }\n * ```\n */\nexport function useFluidApi(): FluidClient {\n const { client } = useFluidContext();\n return client;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,SAAgB,cAA2B;CACzC,MAAM,EAAE,WAAWA,sBAAAA,iBAAiB;AACpC,QAAO"}
@@ -1,6 +1,94 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../chunk-DAgNkxik.cjs");
3
- let _fluid_app_portal_core_validation = require("@fluid-app/portal-core/validation");
3
+ //#region src/vite/validate-manifest.ts
4
+ /**
5
+ * Lightweight manifest validation for the SDK vite plugin.
6
+ *
7
+ * Inlined here (rather than imported from @fluid-app/portal-core) because
8
+ * portal-core is private and not published to npm. This avoids a runtime
9
+ * ERR_MODULE_NOT_FOUND for portals installed from npm.
10
+ */
11
+ const VALID_FIELD_TYPES = [
12
+ "text",
13
+ "textarea",
14
+ "number",
15
+ "boolean",
16
+ "select",
17
+ "color",
18
+ "range",
19
+ "dataSource",
20
+ "resource",
21
+ "image",
22
+ "alignment",
23
+ "slider",
24
+ "colorPicker",
25
+ "sectionHeader",
26
+ "separator",
27
+ "buttonGroup",
28
+ "colorSelect",
29
+ "sectionLayoutSelect",
30
+ "background",
31
+ "contentPosition",
32
+ "textSizeSelect",
33
+ "cssUnit",
34
+ "fontPicker",
35
+ "stringArray",
36
+ "borderRadius",
37
+ "screenPicker"
38
+ ];
39
+ function validateManifest(input) {
40
+ const errors = [];
41
+ const m = input;
42
+ if (!m || typeof m !== "object") return {
43
+ success: false,
44
+ errors: [{
45
+ path: "",
46
+ message: "Manifest must be an object"
47
+ }]
48
+ };
49
+ for (const key of [
50
+ "type",
51
+ "displayName",
52
+ "description",
53
+ "icon",
54
+ "category"
55
+ ]) if (typeof m[key] !== "string" || m[key].length === 0) errors.push({
56
+ path: key,
57
+ message: `${key} is required and must be a non-empty string`
58
+ });
59
+ if (typeof m.manifestVersion !== "number" || m.manifestVersion < 1) errors.push({
60
+ path: "manifestVersion",
61
+ message: "manifestVersion must be a positive integer"
62
+ });
63
+ if (typeof m.component !== "function") errors.push({
64
+ path: "component",
65
+ message: "component must be a React component (function)"
66
+ });
67
+ const schema = m.propertySchema;
68
+ if (schema && typeof schema === "object") {
69
+ if (typeof schema.widgetType !== "string" || !schema.widgetType) errors.push({
70
+ path: "propertySchema.widgetType",
71
+ message: "widgetType is required"
72
+ });
73
+ if (typeof m.type === "string" && schema.widgetType !== m.type) errors.push({
74
+ path: "propertySchema.widgetType",
75
+ message: "manifest.type must match manifest.propertySchema.widgetType"
76
+ });
77
+ if (Array.isArray(schema.fields)) for (let i = 0; i < schema.fields.length; i++) {
78
+ const field = schema.fields[i];
79
+ if (!field || typeof field.type !== "string") continue;
80
+ if (!VALID_FIELD_TYPES.includes(field.type)) errors.push({
81
+ path: `propertySchema.fields.${i}.type`,
82
+ message: `Invalid field type "${field.type}". Valid types: ${VALID_FIELD_TYPES.join(", ")}`
83
+ });
84
+ }
85
+ }
86
+ return errors.length === 0 ? { success: true } : {
87
+ success: false,
88
+ errors
89
+ };
90
+ }
91
+ //#endregion
4
92
  //#region src/vite/manifest-plugin.ts
5
93
  /**
6
94
  * Vite plugin that serves widget manifest metadata.
@@ -62,7 +150,7 @@ async function loadManifests(server, logger) {
62
150
  }
63
151
  const manifests = rawWidgets;
64
152
  if (logger) for (const manifest of manifests) {
65
- const result = (0, _fluid_app_portal_core_validation.validateManifest)(manifest);
153
+ const result = validateManifest(manifest);
66
154
  if (!result.success) {
67
155
  const type = manifest.type ?? "unknown";
68
156
  logger.warn(`[fluid] Invalid manifest for "${type}":\n` + result.errors.map((e) => ` - ${e.path}: ${e.message}`).join("\n"));
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../../src/vite/manifest-plugin.ts","../../src/vite/builder-preview-plugin.ts"],"sourcesContent":["import type { Plugin, ViteDevServer, Logger } from \"vite\";\nimport { validateManifest } from \"@fluid-app/portal-core/validation\";\n\n/**\n * Vite plugin that serves widget manifest metadata.\n *\n * Dev mode: middleware serves /__manifests__ dynamically via ssrLoadModule.\n * Re-reads portal.config.ts on every request (HMR-aware).\n *\n * Build mode: emits an empty __manifests__.json as a static asset in dist/.\n * The CLI extraction utility (extract-manifests.ts) handles build-time\n * extraction via tsx subprocess for `fluid build` and `fluid deploy`.\n *\n * The builder fetches this endpoint/file to discover custom widgets.\n */\nexport function fluidManifestPlugin(): Plugin {\n return {\n name: \"fluid-manifest-plugin\",\n\n configureServer(server) {\n server.middlewares.use(\"/__manifests__\", async (_req, res) => {\n try {\n const serializable = await loadManifests(\n server,\n server.config.logger,\n );\n\n res.setHeader(\"Content-Type\", \"application/json\");\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.end(JSON.stringify(serializable));\n } catch (err) {\n server.config.logger.error(\n `[fluid] Failed to load manifests: ${err}`,\n );\n res.statusCode = 500;\n res.end(JSON.stringify({ error: String(err) }));\n }\n });\n },\n\n generateBundle() {\n // Build mode: emit placeholder. The CLI extraction utility handles\n // actual build-time manifest extraction via tsx subprocess.\n this.warn(\n \"[fluid] fluidManifestPlugin: emitting empty __manifests__.json. \" +\n \"Run `fluid build` instead of `vite build` to include widget manifests.\",\n );\n this.emitFile({\n type: \"asset\",\n fileName: \"__manifests__.json\",\n source: JSON.stringify([]),\n });\n },\n };\n}\n\n/**\n * Load and serialize manifests from portal.config.ts via Vite's ssrLoadModule.\n * Validates each manifest before stripping the `component` field.\n * Returns an empty array if the config module or export is missing/invalid.\n */\nasync function loadManifests(\n server: ViteDevServer,\n logger?: Logger,\n): Promise<unknown[]> {\n let mod: Record<string, unknown>;\n try {\n mod = await server.ssrLoadModule(\"/src/portal.config.ts\");\n } catch (err) {\n logger?.warn(\n `[fluid] Could not load portal.config.ts: ${err instanceof Error ? err.message : err}`,\n );\n return [];\n }\n\n const rawWidgets = mod.customWidgets;\n if (!rawWidgets) return [];\n\n if (!Array.isArray(rawWidgets)) {\n logger?.warn(\n `[fluid] customWidgets export is not an array (got ${typeof rawWidgets}). Skipping manifest serving.`,\n );\n return [];\n }\n\n const manifests = rawWidgets as Record<string, unknown>[];\n\n // Validate full manifests (with component) before stripping\n if (logger) {\n for (const manifest of manifests) {\n const result = validateManifest(manifest);\n if (!result.success) {\n const type = (manifest as { type?: string }).type ?? \"unknown\";\n logger.warn(\n `[fluid] Invalid manifest for \"${type}\":\\n` +\n result.errors.map((e) => ` - ${e.path}: ${e.message}`).join(\"\\n\"),\n );\n }\n }\n }\n\n return manifests.map(\n ({ component: _component, ...rest }: Record<string, unknown>) => rest,\n );\n}\n","import type { Plugin } from \"vite\";\n\nconst VIRTUAL_ENTRY_ID = \"virtual:builder-preview-entry\";\nconst RESOLVED_VIRTUAL_ID = \"\\0\" + VIRTUAL_ENTRY_ID;\nconst VIRTUAL_MODULE_URL = \"/@id/__x00__virtual:builder-preview-entry\";\n\nconst RAW_HTML = `<!doctype html>\n<html lang=\"en\" data-theme-mode=\"dark\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Custom Widget Preview</title>\n <style>\n body { margin: 0; font-family: system-ui, -apple-system, sans-serif; }\n </style>\n </head>\n <body>\n <div id=\"builder-preview-root\"></div>\n <script type=\"module\" src=\"${VIRTUAL_MODULE_URL}\"></script>\n <script type=\"module\">import \"/src/index.css\";</script>\n </body>\n</html>`;\n\n/**\n * Vite plugin that serves a standalone widget preview page at /builder-preview.\n *\n * Dev mode only. Renders all customWidgets from portal.config.ts with\n * a live preview and property editor — no auth, no iframe, no fluid-admin needed.\n *\n * Uses a virtual module to bridge the user's portal.config.ts into the preview app.\n */\nexport function fluidBuilderPreviewPlugin(): Plugin {\n return {\n name: \"fluid-builder-preview-plugin\",\n apply: \"serve\",\n\n resolveId(id) {\n if (id === VIRTUAL_ENTRY_ID) return RESOLVED_VIRTUAL_ID;\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return `\nimport * as portalConfig from \"/src/portal.config.ts\";\nimport { createRoot } from \"react-dom/client\";\nimport { createElement } from \"react\";\nimport { BuilderPreviewApp } from \"@fluid-app/portal-preview\";\n\nconst widgets = portalConfig.customWidgets || [];\nconst root = document.getElementById(\"builder-preview-root\");\nif (root) {\n createRoot(root).render(\n createElement(BuilderPreviewApp, { widgets })\n );\n}\n`;\n }\n },\n\n configureServer(server) {\n server.middlewares.use(async (req, res, next) => {\n const pathname = (req.url ?? \"\").split(\"?\")[0];\n if (pathname !== \"/builder-preview\" && pathname !== \"/builder-preview/\")\n return next();\n try {\n const transformed = await server.transformIndexHtml(\n \"/builder-preview\",\n RAW_HTML,\n );\n res.setHeader(\"Content-Type\", \"text/html\");\n res.end(transformed);\n } catch (e) {\n server.config.logger.error(\n `[fluid] Failed to serve builder preview: ${e}`,\n );\n res.statusCode = 500;\n res.end(\"Builder preview failed to load\");\n }\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAeA,SAAgB,sBAA8B;AAC5C,QAAO;EACL,MAAM;EAEN,gBAAgB,QAAQ;AACtB,UAAO,YAAY,IAAI,kBAAkB,OAAO,MAAM,QAAQ;AAC5D,QAAI;KACF,MAAM,eAAe,MAAM,cACzB,QACA,OAAO,OAAO,OACf;AAED,SAAI,UAAU,gBAAgB,mBAAmB;AACjD,SAAI,UAAU,+BAA+B,IAAI;AACjD,SAAI,IAAI,KAAK,UAAU,aAAa,CAAC;aAC9B,KAAK;AACZ,YAAO,OAAO,OAAO,MACnB,qCAAqC,MACtC;AACD,SAAI,aAAa;AACjB,SAAI,IAAI,KAAK,UAAU,EAAE,OAAO,OAAO,IAAI,EAAE,CAAC,CAAC;;KAEjD;;EAGJ,iBAAiB;AAGf,QAAK,KACH,yIAED;AACD,QAAK,SAAS;IACZ,MAAM;IACN,UAAU;IACV,QAAQ,KAAK,UAAU,EAAE,CAAC;IAC3B,CAAC;;EAEL;;;;;;;AAQH,eAAe,cACb,QACA,QACoB;CACpB,IAAI;AACJ,KAAI;AACF,QAAM,MAAM,OAAO,cAAc,wBAAwB;UAClD,KAAK;AACZ,UAAQ,KACN,4CAA4C,eAAe,QAAQ,IAAI,UAAU,MAClF;AACD,SAAO,EAAE;;CAGX,MAAM,aAAa,IAAI;AACvB,KAAI,CAAC,WAAY,QAAO,EAAE;AAE1B,KAAI,CAAC,MAAM,QAAQ,WAAW,EAAE;AAC9B,UAAQ,KACN,qDAAqD,OAAO,WAAW,+BACxE;AACD,SAAO,EAAE;;CAGX,MAAM,YAAY;AAGlB,KAAI,OACF,MAAK,MAAM,YAAY,WAAW;EAChC,MAAM,UAAA,GAAA,kCAAA,kBAA0B,SAAS;AACzC,MAAI,CAAC,OAAO,SAAS;GACnB,MAAM,OAAQ,SAA+B,QAAQ;AACrD,UAAO,KACL,iCAAiC,KAAK,QACpC,OAAO,OAAO,KAAK,MAAM,OAAO,EAAE,KAAK,IAAI,EAAE,UAAU,CAAC,KAAK,KAAK,CACrE;;;AAKP,QAAO,UAAU,KACd,EAAE,WAAW,YAAY,GAAG,WAAoC,KAClE;;;;ACrGH,MAAM,mBAAmB;AACzB,MAAM,sBAAsB,OAAO;AAGnC,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;AAyBjB,SAAgB,4BAAoC;AAClD,QAAO;EACL,MAAM;EACN,OAAO;EAEP,UAAU,IAAI;AACZ,OAAI,OAAO,iBAAkB,QAAO;;EAGtC,KAAK,IAAI;AACP,OAAI,OAAO,oBACT,QAAO;;;;;;;;;;;;;;;EAiBX,gBAAgB,QAAQ;AACtB,UAAO,YAAY,IAAI,OAAO,KAAK,KAAK,SAAS;IAC/C,MAAM,YAAY,IAAI,OAAO,IAAI,MAAM,IAAI,CAAC;AAC5C,QAAI,aAAa,sBAAsB,aAAa,oBAClD,QAAO,MAAM;AACf,QAAI;KACF,MAAM,cAAc,MAAM,OAAO,mBAC/B,oBACA,SACD;AACD,SAAI,UAAU,gBAAgB,YAAY;AAC1C,SAAI,IAAI,YAAY;aACb,GAAG;AACV,YAAO,OAAO,OAAO,MACnB,4CAA4C,IAC7C;AACD,SAAI,aAAa;AACjB,SAAI,IAAI,iCAAiC;;KAE3C;;EAEL"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../../src/vite/validate-manifest.ts","../../src/vite/manifest-plugin.ts","../../src/vite/builder-preview-plugin.ts"],"sourcesContent":["/**\n * Lightweight manifest validation for the SDK vite plugin.\n *\n * Inlined here (rather than imported from @fluid-app/portal-core) because\n * portal-core is private and not published to npm. This avoids a runtime\n * ERR_MODULE_NOT_FOUND for portals installed from npm.\n */\n\nconst VALID_FIELD_TYPES = [\n \"text\",\n \"textarea\",\n \"number\",\n \"boolean\",\n \"select\",\n \"color\",\n \"range\",\n \"dataSource\",\n \"resource\",\n \"image\",\n \"alignment\",\n \"slider\",\n \"colorPicker\",\n \"sectionHeader\",\n \"separator\",\n \"buttonGroup\",\n \"colorSelect\",\n \"sectionLayoutSelect\",\n \"background\",\n \"contentPosition\",\n \"textSizeSelect\",\n \"cssUnit\",\n \"fontPicker\",\n \"stringArray\",\n \"borderRadius\",\n \"screenPicker\",\n] as const;\n\ninterface ValidationError {\n path: string;\n message: string;\n}\n\ntype ValidationResult =\n | { success: true }\n | { success: false; errors: ValidationError[] };\n\nexport function validateManifest(input: unknown): ValidationResult {\n const errors: ValidationError[] = [];\n const m = input as Record<string, unknown>;\n\n if (!m || typeof m !== \"object\") {\n return {\n success: false,\n errors: [{ path: \"\", message: \"Manifest must be an object\" }],\n };\n }\n\n // Required string fields\n for (const key of [\n \"type\",\n \"displayName\",\n \"description\",\n \"icon\",\n \"category\",\n ]) {\n if (typeof m[key] !== \"string\" || (m[key] as string).length === 0) {\n errors.push({\n path: key,\n message: `${key} is required and must be a non-empty string`,\n });\n }\n }\n\n if (typeof m.manifestVersion !== \"number\" || m.manifestVersion < 1) {\n errors.push({\n path: \"manifestVersion\",\n message: \"manifestVersion must be a positive integer\",\n });\n }\n\n if (typeof m.component !== \"function\") {\n errors.push({\n path: \"component\",\n message: \"component must be a React component (function)\",\n });\n }\n\n // Property schema validation\n const schema = m.propertySchema as Record<string, unknown> | undefined;\n if (schema && typeof schema === \"object\") {\n if (typeof schema.widgetType !== \"string\" || !schema.widgetType) {\n errors.push({\n path: \"propertySchema.widgetType\",\n message: \"widgetType is required\",\n });\n }\n if (typeof m.type === \"string\" && schema.widgetType !== m.type) {\n errors.push({\n path: \"propertySchema.widgetType\",\n message: \"manifest.type must match manifest.propertySchema.widgetType\",\n });\n }\n if (Array.isArray(schema.fields)) {\n for (let i = 0; i < schema.fields.length; i++) {\n const field = schema.fields[i] as Record<string, unknown>;\n if (!field || typeof field.type !== \"string\") continue;\n if (\n !VALID_FIELD_TYPES.includes(\n field.type as (typeof VALID_FIELD_TYPES)[number],\n )\n ) {\n errors.push({\n path: `propertySchema.fields.${i}.type`,\n message: `Invalid field type \"${field.type}\". Valid types: ${VALID_FIELD_TYPES.join(\", \")}`,\n });\n }\n }\n }\n }\n\n return errors.length === 0 ? { success: true } : { success: false, errors };\n}\n","import type { Plugin, ViteDevServer, Logger } from \"vite\";\nimport { validateManifest } from \"./validate-manifest\";\n\n/**\n * Vite plugin that serves widget manifest metadata.\n *\n * Dev mode: middleware serves /__manifests__ dynamically via ssrLoadModule.\n * Re-reads portal.config.ts on every request (HMR-aware).\n *\n * Build mode: emits an empty __manifests__.json as a static asset in dist/.\n * The CLI extraction utility (extract-manifests.ts) handles build-time\n * extraction via tsx subprocess for `fluid build` and `fluid deploy`.\n *\n * The builder fetches this endpoint/file to discover custom widgets.\n */\nexport function fluidManifestPlugin(): Plugin {\n return {\n name: \"fluid-manifest-plugin\",\n\n configureServer(server) {\n server.middlewares.use(\"/__manifests__\", async (_req, res) => {\n try {\n const serializable = await loadManifests(\n server,\n server.config.logger,\n );\n\n res.setHeader(\"Content-Type\", \"application/json\");\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.end(JSON.stringify(serializable));\n } catch (err) {\n server.config.logger.error(\n `[fluid] Failed to load manifests: ${err}`,\n );\n res.statusCode = 500;\n res.end(JSON.stringify({ error: String(err) }));\n }\n });\n },\n\n generateBundle() {\n // Build mode: emit placeholder. The CLI extraction utility handles\n // actual build-time manifest extraction via tsx subprocess.\n this.warn(\n \"[fluid] fluidManifestPlugin: emitting empty __manifests__.json. \" +\n \"Run `fluid build` instead of `vite build` to include widget manifests.\",\n );\n this.emitFile({\n type: \"asset\",\n fileName: \"__manifests__.json\",\n source: JSON.stringify([]),\n });\n },\n };\n}\n\n/**\n * Load and serialize manifests from portal.config.ts via Vite's ssrLoadModule.\n * Validates each manifest before stripping the `component` field.\n * Returns an empty array if the config module or export is missing/invalid.\n */\nasync function loadManifests(\n server: ViteDevServer,\n logger?: Logger,\n): Promise<unknown[]> {\n let mod: Record<string, unknown>;\n try {\n mod = await server.ssrLoadModule(\"/src/portal.config.ts\");\n } catch (err) {\n logger?.warn(\n `[fluid] Could not load portal.config.ts: ${err instanceof Error ? err.message : err}`,\n );\n return [];\n }\n\n const rawWidgets = mod.customWidgets;\n if (!rawWidgets) return [];\n\n if (!Array.isArray(rawWidgets)) {\n logger?.warn(\n `[fluid] customWidgets export is not an array (got ${typeof rawWidgets}). Skipping manifest serving.`,\n );\n return [];\n }\n\n const manifests = rawWidgets as Record<string, unknown>[];\n\n // Validate full manifests (with component) before stripping\n if (logger) {\n for (const manifest of manifests) {\n const result = validateManifest(manifest);\n if (!result.success) {\n const type = (manifest as { type?: string }).type ?? \"unknown\";\n logger.warn(\n `[fluid] Invalid manifest for \"${type}\":\\n` +\n result.errors.map((e) => ` - ${e.path}: ${e.message}`).join(\"\\n\"),\n );\n }\n }\n }\n\n return manifests.map(\n ({ component: _component, ...rest }: Record<string, unknown>) => rest,\n );\n}\n","import type { Plugin } from \"vite\";\n\nconst VIRTUAL_ENTRY_ID = \"virtual:builder-preview-entry\";\nconst RESOLVED_VIRTUAL_ID = \"\\0\" + VIRTUAL_ENTRY_ID;\nconst VIRTUAL_MODULE_URL = \"/@id/__x00__virtual:builder-preview-entry\";\n\nconst RAW_HTML = `<!doctype html>\n<html lang=\"en\" data-theme-mode=\"dark\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Custom Widget Preview</title>\n <style>\n body { margin: 0; font-family: system-ui, -apple-system, sans-serif; }\n </style>\n </head>\n <body>\n <div id=\"builder-preview-root\"></div>\n <script type=\"module\" src=\"${VIRTUAL_MODULE_URL}\"></script>\n <script type=\"module\">import \"/src/index.css\";</script>\n </body>\n</html>`;\n\n/**\n * Vite plugin that serves a standalone widget preview page at /builder-preview.\n *\n * Dev mode only. Renders all customWidgets from portal.config.ts with\n * a live preview and property editor — no auth, no iframe, no fluid-admin needed.\n *\n * Uses a virtual module to bridge the user's portal.config.ts into the preview app.\n */\nexport function fluidBuilderPreviewPlugin(): Plugin {\n return {\n name: \"fluid-builder-preview-plugin\",\n apply: \"serve\",\n\n resolveId(id) {\n if (id === VIRTUAL_ENTRY_ID) return RESOLVED_VIRTUAL_ID;\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return `\nimport * as portalConfig from \"/src/portal.config.ts\";\nimport { createRoot } from \"react-dom/client\";\nimport { createElement } from \"react\";\nimport { BuilderPreviewApp } from \"@fluid-app/portal-preview\";\n\nconst widgets = portalConfig.customWidgets || [];\nconst root = document.getElementById(\"builder-preview-root\");\nif (root) {\n createRoot(root).render(\n createElement(BuilderPreviewApp, { widgets })\n );\n}\n`;\n }\n },\n\n configureServer(server) {\n server.middlewares.use(async (req, res, next) => {\n const pathname = (req.url ?? \"\").split(\"?\")[0];\n if (pathname !== \"/builder-preview\" && pathname !== \"/builder-preview/\")\n return next();\n try {\n const transformed = await server.transformIndexHtml(\n \"/builder-preview\",\n RAW_HTML,\n );\n res.setHeader(\"Content-Type\", \"text/html\");\n res.end(transformed);\n } catch (e) {\n server.config.logger.error(\n `[fluid] Failed to serve builder preview: ${e}`,\n );\n res.statusCode = 500;\n res.end(\"Builder preview failed to load\");\n }\n });\n },\n };\n}\n"],"mappings":"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"}
@@ -1,4 +1,92 @@
1
- import { validateManifest } from "@fluid-app/portal-core/validation";
1
+ //#region src/vite/validate-manifest.ts
2
+ /**
3
+ * Lightweight manifest validation for the SDK vite plugin.
4
+ *
5
+ * Inlined here (rather than imported from @fluid-app/portal-core) because
6
+ * portal-core is private and not published to npm. This avoids a runtime
7
+ * ERR_MODULE_NOT_FOUND for portals installed from npm.
8
+ */
9
+ const VALID_FIELD_TYPES = [
10
+ "text",
11
+ "textarea",
12
+ "number",
13
+ "boolean",
14
+ "select",
15
+ "color",
16
+ "range",
17
+ "dataSource",
18
+ "resource",
19
+ "image",
20
+ "alignment",
21
+ "slider",
22
+ "colorPicker",
23
+ "sectionHeader",
24
+ "separator",
25
+ "buttonGroup",
26
+ "colorSelect",
27
+ "sectionLayoutSelect",
28
+ "background",
29
+ "contentPosition",
30
+ "textSizeSelect",
31
+ "cssUnit",
32
+ "fontPicker",
33
+ "stringArray",
34
+ "borderRadius",
35
+ "screenPicker"
36
+ ];
37
+ function validateManifest(input) {
38
+ const errors = [];
39
+ const m = input;
40
+ if (!m || typeof m !== "object") return {
41
+ success: false,
42
+ errors: [{
43
+ path: "",
44
+ message: "Manifest must be an object"
45
+ }]
46
+ };
47
+ for (const key of [
48
+ "type",
49
+ "displayName",
50
+ "description",
51
+ "icon",
52
+ "category"
53
+ ]) if (typeof m[key] !== "string" || m[key].length === 0) errors.push({
54
+ path: key,
55
+ message: `${key} is required and must be a non-empty string`
56
+ });
57
+ if (typeof m.manifestVersion !== "number" || m.manifestVersion < 1) errors.push({
58
+ path: "manifestVersion",
59
+ message: "manifestVersion must be a positive integer"
60
+ });
61
+ if (typeof m.component !== "function") errors.push({
62
+ path: "component",
63
+ message: "component must be a React component (function)"
64
+ });
65
+ const schema = m.propertySchema;
66
+ if (schema && typeof schema === "object") {
67
+ if (typeof schema.widgetType !== "string" || !schema.widgetType) errors.push({
68
+ path: "propertySchema.widgetType",
69
+ message: "widgetType is required"
70
+ });
71
+ if (typeof m.type === "string" && schema.widgetType !== m.type) errors.push({
72
+ path: "propertySchema.widgetType",
73
+ message: "manifest.type must match manifest.propertySchema.widgetType"
74
+ });
75
+ if (Array.isArray(schema.fields)) for (let i = 0; i < schema.fields.length; i++) {
76
+ const field = schema.fields[i];
77
+ if (!field || typeof field.type !== "string") continue;
78
+ if (!VALID_FIELD_TYPES.includes(field.type)) errors.push({
79
+ path: `propertySchema.fields.${i}.type`,
80
+ message: `Invalid field type "${field.type}". Valid types: ${VALID_FIELD_TYPES.join(", ")}`
81
+ });
82
+ }
83
+ }
84
+ return errors.length === 0 ? { success: true } : {
85
+ success: false,
86
+ errors
87
+ };
88
+ }
89
+ //#endregion
2
90
  //#region src/vite/manifest-plugin.ts
3
91
  /**
4
92
  * Vite plugin that serves widget manifest metadata.
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/vite/manifest-plugin.ts","../../src/vite/builder-preview-plugin.ts"],"sourcesContent":["import type { Plugin, ViteDevServer, Logger } from \"vite\";\nimport { validateManifest } from \"@fluid-app/portal-core/validation\";\n\n/**\n * Vite plugin that serves widget manifest metadata.\n *\n * Dev mode: middleware serves /__manifests__ dynamically via ssrLoadModule.\n * Re-reads portal.config.ts on every request (HMR-aware).\n *\n * Build mode: emits an empty __manifests__.json as a static asset in dist/.\n * The CLI extraction utility (extract-manifests.ts) handles build-time\n * extraction via tsx subprocess for `fluid build` and `fluid deploy`.\n *\n * The builder fetches this endpoint/file to discover custom widgets.\n */\nexport function fluidManifestPlugin(): Plugin {\n return {\n name: \"fluid-manifest-plugin\",\n\n configureServer(server) {\n server.middlewares.use(\"/__manifests__\", async (_req, res) => {\n try {\n const serializable = await loadManifests(\n server,\n server.config.logger,\n );\n\n res.setHeader(\"Content-Type\", \"application/json\");\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.end(JSON.stringify(serializable));\n } catch (err) {\n server.config.logger.error(\n `[fluid] Failed to load manifests: ${err}`,\n );\n res.statusCode = 500;\n res.end(JSON.stringify({ error: String(err) }));\n }\n });\n },\n\n generateBundle() {\n // Build mode: emit placeholder. The CLI extraction utility handles\n // actual build-time manifest extraction via tsx subprocess.\n this.warn(\n \"[fluid] fluidManifestPlugin: emitting empty __manifests__.json. \" +\n \"Run `fluid build` instead of `vite build` to include widget manifests.\",\n );\n this.emitFile({\n type: \"asset\",\n fileName: \"__manifests__.json\",\n source: JSON.stringify([]),\n });\n },\n };\n}\n\n/**\n * Load and serialize manifests from portal.config.ts via Vite's ssrLoadModule.\n * Validates each manifest before stripping the `component` field.\n * Returns an empty array if the config module or export is missing/invalid.\n */\nasync function loadManifests(\n server: ViteDevServer,\n logger?: Logger,\n): Promise<unknown[]> {\n let mod: Record<string, unknown>;\n try {\n mod = await server.ssrLoadModule(\"/src/portal.config.ts\");\n } catch (err) {\n logger?.warn(\n `[fluid] Could not load portal.config.ts: ${err instanceof Error ? err.message : err}`,\n );\n return [];\n }\n\n const rawWidgets = mod.customWidgets;\n if (!rawWidgets) return [];\n\n if (!Array.isArray(rawWidgets)) {\n logger?.warn(\n `[fluid] customWidgets export is not an array (got ${typeof rawWidgets}). Skipping manifest serving.`,\n );\n return [];\n }\n\n const manifests = rawWidgets as Record<string, unknown>[];\n\n // Validate full manifests (with component) before stripping\n if (logger) {\n for (const manifest of manifests) {\n const result = validateManifest(manifest);\n if (!result.success) {\n const type = (manifest as { type?: string }).type ?? \"unknown\";\n logger.warn(\n `[fluid] Invalid manifest for \"${type}\":\\n` +\n result.errors.map((e) => ` - ${e.path}: ${e.message}`).join(\"\\n\"),\n );\n }\n }\n }\n\n return manifests.map(\n ({ component: _component, ...rest }: Record<string, unknown>) => rest,\n );\n}\n","import type { Plugin } from \"vite\";\n\nconst VIRTUAL_ENTRY_ID = \"virtual:builder-preview-entry\";\nconst RESOLVED_VIRTUAL_ID = \"\\0\" + VIRTUAL_ENTRY_ID;\nconst VIRTUAL_MODULE_URL = \"/@id/__x00__virtual:builder-preview-entry\";\n\nconst RAW_HTML = `<!doctype html>\n<html lang=\"en\" data-theme-mode=\"dark\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Custom Widget Preview</title>\n <style>\n body { margin: 0; font-family: system-ui, -apple-system, sans-serif; }\n </style>\n </head>\n <body>\n <div id=\"builder-preview-root\"></div>\n <script type=\"module\" src=\"${VIRTUAL_MODULE_URL}\"></script>\n <script type=\"module\">import \"/src/index.css\";</script>\n </body>\n</html>`;\n\n/**\n * Vite plugin that serves a standalone widget preview page at /builder-preview.\n *\n * Dev mode only. Renders all customWidgets from portal.config.ts with\n * a live preview and property editor — no auth, no iframe, no fluid-admin needed.\n *\n * Uses a virtual module to bridge the user's portal.config.ts into the preview app.\n */\nexport function fluidBuilderPreviewPlugin(): Plugin {\n return {\n name: \"fluid-builder-preview-plugin\",\n apply: \"serve\",\n\n resolveId(id) {\n if (id === VIRTUAL_ENTRY_ID) return RESOLVED_VIRTUAL_ID;\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return `\nimport * as portalConfig from \"/src/portal.config.ts\";\nimport { createRoot } from \"react-dom/client\";\nimport { createElement } from \"react\";\nimport { BuilderPreviewApp } from \"@fluid-app/portal-preview\";\n\nconst widgets = portalConfig.customWidgets || [];\nconst root = document.getElementById(\"builder-preview-root\");\nif (root) {\n createRoot(root).render(\n createElement(BuilderPreviewApp, { widgets })\n );\n}\n`;\n }\n },\n\n configureServer(server) {\n server.middlewares.use(async (req, res, next) => {\n const pathname = (req.url ?? \"\").split(\"?\")[0];\n if (pathname !== \"/builder-preview\" && pathname !== \"/builder-preview/\")\n return next();\n try {\n const transformed = await server.transformIndexHtml(\n \"/builder-preview\",\n RAW_HTML,\n );\n res.setHeader(\"Content-Type\", \"text/html\");\n res.end(transformed);\n } catch (e) {\n server.config.logger.error(\n `[fluid] Failed to serve builder preview: ${e}`,\n );\n res.statusCode = 500;\n res.end(\"Builder preview failed to load\");\n }\n });\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,sBAA8B;AAC5C,QAAO;EACL,MAAM;EAEN,gBAAgB,QAAQ;AACtB,UAAO,YAAY,IAAI,kBAAkB,OAAO,MAAM,QAAQ;AAC5D,QAAI;KACF,MAAM,eAAe,MAAM,cACzB,QACA,OAAO,OAAO,OACf;AAED,SAAI,UAAU,gBAAgB,mBAAmB;AACjD,SAAI,UAAU,+BAA+B,IAAI;AACjD,SAAI,IAAI,KAAK,UAAU,aAAa,CAAC;aAC9B,KAAK;AACZ,YAAO,OAAO,OAAO,MACnB,qCAAqC,MACtC;AACD,SAAI,aAAa;AACjB,SAAI,IAAI,KAAK,UAAU,EAAE,OAAO,OAAO,IAAI,EAAE,CAAC,CAAC;;KAEjD;;EAGJ,iBAAiB;AAGf,QAAK,KACH,yIAED;AACD,QAAK,SAAS;IACZ,MAAM;IACN,UAAU;IACV,QAAQ,KAAK,UAAU,EAAE,CAAC;IAC3B,CAAC;;EAEL;;;;;;;AAQH,eAAe,cACb,QACA,QACoB;CACpB,IAAI;AACJ,KAAI;AACF,QAAM,MAAM,OAAO,cAAc,wBAAwB;UAClD,KAAK;AACZ,UAAQ,KACN,4CAA4C,eAAe,QAAQ,IAAI,UAAU,MAClF;AACD,SAAO,EAAE;;CAGX,MAAM,aAAa,IAAI;AACvB,KAAI,CAAC,WAAY,QAAO,EAAE;AAE1B,KAAI,CAAC,MAAM,QAAQ,WAAW,EAAE;AAC9B,UAAQ,KACN,qDAAqD,OAAO,WAAW,+BACxE;AACD,SAAO,EAAE;;CAGX,MAAM,YAAY;AAGlB,KAAI,OACF,MAAK,MAAM,YAAY,WAAW;EAChC,MAAM,SAAS,iBAAiB,SAAS;AACzC,MAAI,CAAC,OAAO,SAAS;GACnB,MAAM,OAAQ,SAA+B,QAAQ;AACrD,UAAO,KACL,iCAAiC,KAAK,QACpC,OAAO,OAAO,KAAK,MAAM,OAAO,EAAE,KAAK,IAAI,EAAE,UAAU,CAAC,KAAK,KAAK,CACrE;;;AAKP,QAAO,UAAU,KACd,EAAE,WAAW,YAAY,GAAG,WAAoC,KAClE;;;;ACrGH,MAAM,mBAAmB;AACzB,MAAM,sBAAsB,OAAO;AAGnC,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;AAyBjB,SAAgB,4BAAoC;AAClD,QAAO;EACL,MAAM;EACN,OAAO;EAEP,UAAU,IAAI;AACZ,OAAI,OAAO,iBAAkB,QAAO;;EAGtC,KAAK,IAAI;AACP,OAAI,OAAO,oBACT,QAAO;;;;;;;;;;;;;;;EAiBX,gBAAgB,QAAQ;AACtB,UAAO,YAAY,IAAI,OAAO,KAAK,KAAK,SAAS;IAC/C,MAAM,YAAY,IAAI,OAAO,IAAI,MAAM,IAAI,CAAC;AAC5C,QAAI,aAAa,sBAAsB,aAAa,oBAClD,QAAO,MAAM;AACf,QAAI;KACF,MAAM,cAAc,MAAM,OAAO,mBAC/B,oBACA,SACD;AACD,SAAI,UAAU,gBAAgB,YAAY;AAC1C,SAAI,IAAI,YAAY;aACb,GAAG;AACV,YAAO,OAAO,OAAO,MACnB,4CAA4C,IAC7C;AACD,SAAI,aAAa;AACjB,SAAI,IAAI,iCAAiC;;KAE3C;;EAEL"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/vite/validate-manifest.ts","../../src/vite/manifest-plugin.ts","../../src/vite/builder-preview-plugin.ts"],"sourcesContent":["/**\n * Lightweight manifest validation for the SDK vite plugin.\n *\n * Inlined here (rather than imported from @fluid-app/portal-core) because\n * portal-core is private and not published to npm. This avoids a runtime\n * ERR_MODULE_NOT_FOUND for portals installed from npm.\n */\n\nconst VALID_FIELD_TYPES = [\n \"text\",\n \"textarea\",\n \"number\",\n \"boolean\",\n \"select\",\n \"color\",\n \"range\",\n \"dataSource\",\n \"resource\",\n \"image\",\n \"alignment\",\n \"slider\",\n \"colorPicker\",\n \"sectionHeader\",\n \"separator\",\n \"buttonGroup\",\n \"colorSelect\",\n \"sectionLayoutSelect\",\n \"background\",\n \"contentPosition\",\n \"textSizeSelect\",\n \"cssUnit\",\n \"fontPicker\",\n \"stringArray\",\n \"borderRadius\",\n \"screenPicker\",\n] as const;\n\ninterface ValidationError {\n path: string;\n message: string;\n}\n\ntype ValidationResult =\n | { success: true }\n | { success: false; errors: ValidationError[] };\n\nexport function validateManifest(input: unknown): ValidationResult {\n const errors: ValidationError[] = [];\n const m = input as Record<string, unknown>;\n\n if (!m || typeof m !== \"object\") {\n return {\n success: false,\n errors: [{ path: \"\", message: \"Manifest must be an object\" }],\n };\n }\n\n // Required string fields\n for (const key of [\n \"type\",\n \"displayName\",\n \"description\",\n \"icon\",\n \"category\",\n ]) {\n if (typeof m[key] !== \"string\" || (m[key] as string).length === 0) {\n errors.push({\n path: key,\n message: `${key} is required and must be a non-empty string`,\n });\n }\n }\n\n if (typeof m.manifestVersion !== \"number\" || m.manifestVersion < 1) {\n errors.push({\n path: \"manifestVersion\",\n message: \"manifestVersion must be a positive integer\",\n });\n }\n\n if (typeof m.component !== \"function\") {\n errors.push({\n path: \"component\",\n message: \"component must be a React component (function)\",\n });\n }\n\n // Property schema validation\n const schema = m.propertySchema as Record<string, unknown> | undefined;\n if (schema && typeof schema === \"object\") {\n if (typeof schema.widgetType !== \"string\" || !schema.widgetType) {\n errors.push({\n path: \"propertySchema.widgetType\",\n message: \"widgetType is required\",\n });\n }\n if (typeof m.type === \"string\" && schema.widgetType !== m.type) {\n errors.push({\n path: \"propertySchema.widgetType\",\n message: \"manifest.type must match manifest.propertySchema.widgetType\",\n });\n }\n if (Array.isArray(schema.fields)) {\n for (let i = 0; i < schema.fields.length; i++) {\n const field = schema.fields[i] as Record<string, unknown>;\n if (!field || typeof field.type !== \"string\") continue;\n if (\n !VALID_FIELD_TYPES.includes(\n field.type as (typeof VALID_FIELD_TYPES)[number],\n )\n ) {\n errors.push({\n path: `propertySchema.fields.${i}.type`,\n message: `Invalid field type \"${field.type}\". Valid types: ${VALID_FIELD_TYPES.join(\", \")}`,\n });\n }\n }\n }\n }\n\n return errors.length === 0 ? { success: true } : { success: false, errors };\n}\n","import type { Plugin, ViteDevServer, Logger } from \"vite\";\nimport { validateManifest } from \"./validate-manifest\";\n\n/**\n * Vite plugin that serves widget manifest metadata.\n *\n * Dev mode: middleware serves /__manifests__ dynamically via ssrLoadModule.\n * Re-reads portal.config.ts on every request (HMR-aware).\n *\n * Build mode: emits an empty __manifests__.json as a static asset in dist/.\n * The CLI extraction utility (extract-manifests.ts) handles build-time\n * extraction via tsx subprocess for `fluid build` and `fluid deploy`.\n *\n * The builder fetches this endpoint/file to discover custom widgets.\n */\nexport function fluidManifestPlugin(): Plugin {\n return {\n name: \"fluid-manifest-plugin\",\n\n configureServer(server) {\n server.middlewares.use(\"/__manifests__\", async (_req, res) => {\n try {\n const serializable = await loadManifests(\n server,\n server.config.logger,\n );\n\n res.setHeader(\"Content-Type\", \"application/json\");\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.end(JSON.stringify(serializable));\n } catch (err) {\n server.config.logger.error(\n `[fluid] Failed to load manifests: ${err}`,\n );\n res.statusCode = 500;\n res.end(JSON.stringify({ error: String(err) }));\n }\n });\n },\n\n generateBundle() {\n // Build mode: emit placeholder. The CLI extraction utility handles\n // actual build-time manifest extraction via tsx subprocess.\n this.warn(\n \"[fluid] fluidManifestPlugin: emitting empty __manifests__.json. \" +\n \"Run `fluid build` instead of `vite build` to include widget manifests.\",\n );\n this.emitFile({\n type: \"asset\",\n fileName: \"__manifests__.json\",\n source: JSON.stringify([]),\n });\n },\n };\n}\n\n/**\n * Load and serialize manifests from portal.config.ts via Vite's ssrLoadModule.\n * Validates each manifest before stripping the `component` field.\n * Returns an empty array if the config module or export is missing/invalid.\n */\nasync function loadManifests(\n server: ViteDevServer,\n logger?: Logger,\n): Promise<unknown[]> {\n let mod: Record<string, unknown>;\n try {\n mod = await server.ssrLoadModule(\"/src/portal.config.ts\");\n } catch (err) {\n logger?.warn(\n `[fluid] Could not load portal.config.ts: ${err instanceof Error ? err.message : err}`,\n );\n return [];\n }\n\n const rawWidgets = mod.customWidgets;\n if (!rawWidgets) return [];\n\n if (!Array.isArray(rawWidgets)) {\n logger?.warn(\n `[fluid] customWidgets export is not an array (got ${typeof rawWidgets}). Skipping manifest serving.`,\n );\n return [];\n }\n\n const manifests = rawWidgets as Record<string, unknown>[];\n\n // Validate full manifests (with component) before stripping\n if (logger) {\n for (const manifest of manifests) {\n const result = validateManifest(manifest);\n if (!result.success) {\n const type = (manifest as { type?: string }).type ?? \"unknown\";\n logger.warn(\n `[fluid] Invalid manifest for \"${type}\":\\n` +\n result.errors.map((e) => ` - ${e.path}: ${e.message}`).join(\"\\n\"),\n );\n }\n }\n }\n\n return manifests.map(\n ({ component: _component, ...rest }: Record<string, unknown>) => rest,\n );\n}\n","import type { Plugin } from \"vite\";\n\nconst VIRTUAL_ENTRY_ID = \"virtual:builder-preview-entry\";\nconst RESOLVED_VIRTUAL_ID = \"\\0\" + VIRTUAL_ENTRY_ID;\nconst VIRTUAL_MODULE_URL = \"/@id/__x00__virtual:builder-preview-entry\";\n\nconst RAW_HTML = `<!doctype html>\n<html lang=\"en\" data-theme-mode=\"dark\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>Custom Widget Preview</title>\n <style>\n body { margin: 0; font-family: system-ui, -apple-system, sans-serif; }\n </style>\n </head>\n <body>\n <div id=\"builder-preview-root\"></div>\n <script type=\"module\" src=\"${VIRTUAL_MODULE_URL}\"></script>\n <script type=\"module\">import \"/src/index.css\";</script>\n </body>\n</html>`;\n\n/**\n * Vite plugin that serves a standalone widget preview page at /builder-preview.\n *\n * Dev mode only. Renders all customWidgets from portal.config.ts with\n * a live preview and property editor — no auth, no iframe, no fluid-admin needed.\n *\n * Uses a virtual module to bridge the user's portal.config.ts into the preview app.\n */\nexport function fluidBuilderPreviewPlugin(): Plugin {\n return {\n name: \"fluid-builder-preview-plugin\",\n apply: \"serve\",\n\n resolveId(id) {\n if (id === VIRTUAL_ENTRY_ID) return RESOLVED_VIRTUAL_ID;\n },\n\n load(id) {\n if (id === RESOLVED_VIRTUAL_ID) {\n return `\nimport * as portalConfig from \"/src/portal.config.ts\";\nimport { createRoot } from \"react-dom/client\";\nimport { createElement } from \"react\";\nimport { BuilderPreviewApp } from \"@fluid-app/portal-preview\";\n\nconst widgets = portalConfig.customWidgets || [];\nconst root = document.getElementById(\"builder-preview-root\");\nif (root) {\n createRoot(root).render(\n createElement(BuilderPreviewApp, { widgets })\n );\n}\n`;\n }\n },\n\n configureServer(server) {\n server.middlewares.use(async (req, res, next) => {\n const pathname = (req.url ?? \"\").split(\"?\")[0];\n if (pathname !== \"/builder-preview\" && pathname !== \"/builder-preview/\")\n return next();\n try {\n const transformed = await server.transformIndexHtml(\n \"/builder-preview\",\n RAW_HTML,\n );\n res.setHeader(\"Content-Type\", \"text/html\");\n res.end(transformed);\n } catch (e) {\n server.config.logger.error(\n `[fluid] Failed to serve builder preview: ${e}`,\n );\n res.statusCode = 500;\n res.end(\"Builder preview failed to load\");\n }\n });\n },\n };\n}\n"],"mappings":"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"}