@fluid-app/portal-sdk 0.1.28 → 0.1.30
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.
- package/dist/{AppNavigationContext-DrayF_RG.cjs → AppNavigationContext-DAcrNgXZ.cjs} +1 -1
- package/dist/{AppNavigationContext-DrayF_RG.cjs.map → AppNavigationContext-DAcrNgXZ.cjs.map} +1 -1
- package/dist/{AppNavigationContext-2nkMoO8F.mjs → AppNavigationContext-v_y8OYHo.mjs} +1 -1
- package/dist/{AppNavigationContext-2nkMoO8F.mjs.map → AppNavigationContext-v_y8OYHo.mjs.map} +1 -1
- package/dist/{ContactsScreen-GPOgZ-Wi.cjs → ContactsScreen-BL5Jlaz5.cjs} +2 -2
- package/dist/{ContactsScreen-GPOgZ-Wi.cjs.map → ContactsScreen-BL5Jlaz5.cjs.map} +1 -1
- package/dist/{ContactsScreen-BicHZ37M.mjs → ContactsScreen-CcNUC8xu.mjs} +2 -2
- package/dist/{ContactsScreen-BicHZ37M.mjs.map → ContactsScreen-CcNUC8xu.mjs.map} +1 -1
- package/dist/{CoreScreenPlaceholder-Cl_zuOBC.cjs → CoreScreenPlaceholder-B64M78iR.cjs} +1 -1
- package/dist/{CoreScreenPlaceholder-Cl_zuOBC.cjs.map → CoreScreenPlaceholder-B64M78iR.cjs.map} +1 -1
- package/dist/{CoreScreenPlaceholder-Cdyl97Wo.mjs → CoreScreenPlaceholder-DVVLc-OM.mjs} +1 -1
- package/dist/{CoreScreenPlaceholder-Cdyl97Wo.mjs.map → CoreScreenPlaceholder-DVVLc-OM.mjs.map} +1 -1
- package/dist/{CustomersScreen-Brz5zLkq.mjs → CustomersScreen-SuHGSUdb.mjs} +2 -2
- package/dist/{CustomersScreen-Brz5zLkq.mjs.map → CustomersScreen-SuHGSUdb.mjs.map} +1 -1
- package/dist/{CustomersScreen-CK1jJhvM.cjs → CustomersScreen-zl_vRzcJ.cjs} +2 -2
- package/dist/{CustomersScreen-CK1jJhvM.cjs.map → CustomersScreen-zl_vRzcJ.cjs.map} +1 -1
- package/dist/{MessagingScreen-DVU3c8fX.mjs → MessagingScreen-BGzfLD8k.mjs} +2 -2
- package/dist/{MessagingScreen-sAWF7pjl.cjs → MessagingScreen-CRLd91tP.cjs} +2 -2
- package/dist/{MessagingScreen-sAWF7pjl.cjs.map → MessagingScreen-CRLd91tP.cjs.map} +1 -1
- package/dist/{MessagingScreen-C33eDdna.cjs → MessagingScreen-DIZ72Tg0.cjs} +2 -2
- package/dist/{MessagingScreen-II_iNqLk.mjs → MessagingScreen-We1B2pka.mjs} +2 -2
- package/dist/{MessagingScreen-II_iNqLk.mjs.map → MessagingScreen-We1B2pka.mjs.map} +1 -1
- package/dist/OrdersScreen-Bu-ENmH6.cjs +133 -0
- package/dist/OrdersScreen-Bu-ENmH6.cjs.map +1 -0
- package/dist/OrdersScreen-TSXDDHZe.cjs +33 -0
- package/dist/OrdersScreen-afRAHf07.mjs +126 -0
- package/dist/OrdersScreen-afRAHf07.mjs.map +1 -0
- package/dist/{ProductsScreen-DrrBYFl0.mjs → ProductsScreen-B-oWUzvD.mjs} +3 -3
- package/dist/{ProductsScreen-BOngRxSO.mjs → ProductsScreen-ChvK61hX.mjs} +3 -3
- package/dist/{ProductsScreen-BOngRxSO.mjs.map → ProductsScreen-ChvK61hX.mjs.map} +1 -1
- package/dist/{ProductsScreen-DzD-TPh5.cjs → ProductsScreen-CkE2nyuw.cjs} +3 -3
- package/dist/{ProductsScreen-DzD-TPh5.cjs.map → ProductsScreen-CkE2nyuw.cjs.map} +1 -1
- package/dist/{ProductsScreen-CdP_m_Ok.cjs → ProductsScreen-PCg91SbX.cjs} +3 -3
- package/dist/ProfileScreen-B6Dp7RLa.cjs +2856 -0
- package/dist/ProfileScreen-B6Dp7RLa.cjs.map +1 -0
- package/dist/ProfileScreen-B83tzedh.mjs +2849 -0
- package/dist/ProfileScreen-B83tzedh.mjs.map +1 -0
- package/dist/{AccountScreen-Vzz8W4Iq.cjs → ProfileScreen-CH3B-IQz.cjs} +3 -3
- package/dist/{ShareablesScreen-DYPJgZ3z.cjs → ShareablesScreen-Bqj6dtOM.cjs} +3 -3
- package/dist/{ShareablesScreen-DYPJgZ3z.cjs.map → ShareablesScreen-Bqj6dtOM.cjs.map} +1 -1
- package/dist/{ShareablesScreen-jHqLmOC6.cjs → ShareablesScreen-BvJIBZvI.cjs} +3 -3
- package/dist/{ShareablesScreen-CQy39TAK.mjs → ShareablesScreen-ChS517hq.mjs} +3 -3
- package/dist/{ShareablesScreen-CQy39TAK.mjs.map → ShareablesScreen-ChS517hq.mjs.map} +1 -1
- package/dist/{ShareablesScreen-BsqZvRSK.mjs → ShareablesScreen-CqVj81Ol.mjs} +3 -3
- package/dist/{ShopScreen-BPCwix1m.cjs → ShopScreen-CjoTGnCJ.cjs} +2 -2
- package/dist/{ShopScreen-BPCwix1m.cjs.map → ShopScreen-CjoTGnCJ.cjs.map} +1 -1
- package/dist/{ShopScreen--pUsiUNt.cjs → ShopScreen-DS4p47Ry.cjs} +1 -1
- package/dist/{ShopScreen-BKBzgkr7.mjs → ShopScreen-KeU6x3PT.mjs} +2 -2
- package/dist/{ShopScreen-BKBzgkr7.mjs.map → ShopScreen-KeU6x3PT.mjs.map} +1 -1
- package/dist/SubscriptionsScreen-CHn_Q0zf.cjs +1288 -0
- package/dist/SubscriptionsScreen-CHn_Q0zf.cjs.map +1 -0
- package/dist/SubscriptionsScreen-D5_eJwBP.mjs +1281 -0
- package/dist/SubscriptionsScreen-D5_eJwBP.mjs.map +1 -0
- package/dist/SubscriptionsScreen-DGJ_YeX3.cjs +33 -0
- package/dist/{es-kNOrmozy.cjs → es-BtechuHV.cjs} +1 -1
- package/dist/{es-kNOrmozy.cjs.map → es-BtechuHV.cjs.map} +1 -1
- package/dist/{es-BL8VBBDa.mjs → es-DxWiENwN.mjs} +1 -1
- package/dist/{es-BL8VBBDa.mjs.map → es-DxWiENwN.mjs.map} +1 -1
- package/dist/index.cjs +166 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +38 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +162 -92
- package/dist/index.mjs.map +1 -1
- package/dist/src-BZEkCfd4.mjs +973 -0
- package/dist/src-BZEkCfd4.mjs.map +1 -0
- package/dist/src-DXC-Jw6i.cjs +1009 -0
- package/dist/src-DXC-Jw6i.cjs.map +1 -0
- package/dist/{src-DMjlIMO9.cjs → src-vxm9rMYT.cjs} +2 -2
- package/dist/{src-DMjlIMO9.cjs.map → src-vxm9rMYT.cjs.map} +1 -1
- package/dist/{src-9pW9wS5O.mjs → src-wpQFW94i.mjs} +2 -2
- package/dist/{src-9pW9wS5O.mjs.map → src-wpQFW94i.mjs.map} +1 -1
- package/dist/use-account-clients-DYTyFvdN.mjs +134 -0
- package/dist/use-account-clients-DYTyFvdN.mjs.map +1 -0
- package/dist/use-account-clients-n2a8bdSP.cjs +182 -0
- package/dist/use-account-clients-n2a8bdSP.cjs.map +1 -0
- package/package.json +10 -10
- package/dist/AccountScreen-Dp6QFyEr.cjs +0 -5322
- package/dist/AccountScreen-Dp6QFyEr.cjs.map +0 -1
- package/dist/AccountScreen-E4ZBgOUS.mjs +0 -5309
- package/dist/AccountScreen-E4ZBgOUS.mjs.map +0 -1
- package/dist/OrdersScreen-DGt-CTBS.mjs +0 -24
- package/dist/OrdersScreen-DGt-CTBS.mjs.map +0 -1
- package/dist/OrdersScreen-Dy-JChVQ.cjs +0 -41
- package/dist/OrdersScreen-Dy-JChVQ.cjs.map +0 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { _t as createFetchClient, n as useFluidContext, u as useFluidAuthContext } from "./FluidProvider-x96kqsgN.mjs";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
//#region src/hooks/use-fluid-auth.ts
|
|
4
|
+
/**
|
|
5
|
+
* useFluidAuth Hook
|
|
6
|
+
*
|
|
7
|
+
* Provides access to authentication state and utilities.
|
|
8
|
+
* This is the primary hook for interacting with auth in components.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Hook to access authentication state and utilities.
|
|
12
|
+
*
|
|
13
|
+
* Must be used within a `FluidAuthProvider`.
|
|
14
|
+
*
|
|
15
|
+
* @returns Authentication context with user info, loading state, and utilities
|
|
16
|
+
* @throws Error if used outside FluidAuthProvider
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* function UserProfile() {
|
|
21
|
+
* const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();
|
|
22
|
+
*
|
|
23
|
+
* if (isLoading) {
|
|
24
|
+
* return <Spinner />;
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* if (!isAuthenticated) {
|
|
28
|
+
* return <p>Please log in</p>;
|
|
29
|
+
* }
|
|
30
|
+
*
|
|
31
|
+
* return (
|
|
32
|
+
* <div>
|
|
33
|
+
* <p>Welcome, {user.full_name}!</p>
|
|
34
|
+
* <button onClick={clearAuth}>Log out</button>
|
|
35
|
+
* </div>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
function useFluidAuth() {
|
|
41
|
+
return useFluidAuthContext();
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region ../../fluid-pay/api-client/src/namespaces/customers.ts
|
|
45
|
+
/**
|
|
46
|
+
* Fetch the current customer's account info.
|
|
47
|
+
* Endpoint: GET /fluid_pay/me?jwt={jwt}
|
|
48
|
+
*/
|
|
49
|
+
async function fetchCustomerAccount(client, jwt) {
|
|
50
|
+
return client.get(`/fluid_pay/me`, { jwt });
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Update customer profile (name, phone, language).
|
|
54
|
+
* Endpoint: PATCH /fluid_pay/update_me?jwt={jwt}
|
|
55
|
+
*/
|
|
56
|
+
async function updateCustomer(client, jwt, body) {
|
|
57
|
+
return client.patch(`/fluid_pay/update_me?jwt=${jwt}`, { fluid_pay_account: body });
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/account/use-account-clients.ts
|
|
61
|
+
/** API version prefix for versioned endpoints (e.g. points ledger) */
|
|
62
|
+
const API_VERSION = "/v202506";
|
|
63
|
+
/**
|
|
64
|
+
* Ensures baseUrl ends with /api.
|
|
65
|
+
* Domain-specific API clients (orders, subscriptions, fluid-pay) use endpoint
|
|
66
|
+
* paths without /api (e.g. /fluid_pay/me, /subscriptions), matching fluid-admin's
|
|
67
|
+
* NEXT_PUBLIC_API_URL convention. The portal SDK's config.baseUrl is the domain
|
|
68
|
+
* root (e.g. https://api.fluid.app), so we append /api here.
|
|
69
|
+
*/
|
|
70
|
+
function withApiPrefix(baseUrl) {
|
|
71
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
72
|
+
return base.endsWith("/api") ? base : `${base}/api`;
|
|
73
|
+
}
|
|
74
|
+
function useOrdersClient() {
|
|
75
|
+
const { config } = useFluidContext();
|
|
76
|
+
const { token } = useFluidAuth();
|
|
77
|
+
return useMemo(() => createFetchClient({
|
|
78
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
79
|
+
getAuthToken: () => token,
|
|
80
|
+
onAuthError: config.onAuthError
|
|
81
|
+
}), [
|
|
82
|
+
config.baseUrl,
|
|
83
|
+
config.onAuthError,
|
|
84
|
+
token
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
function useSubscriptionsClient() {
|
|
88
|
+
const { config } = useFluidContext();
|
|
89
|
+
const { token } = useFluidAuth();
|
|
90
|
+
return useMemo(() => createFetchClient({
|
|
91
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
92
|
+
getAuthToken: () => token,
|
|
93
|
+
onAuthError: config.onAuthError
|
|
94
|
+
}), [
|
|
95
|
+
config.baseUrl,
|
|
96
|
+
config.onAuthError,
|
|
97
|
+
token
|
|
98
|
+
]);
|
|
99
|
+
}
|
|
100
|
+
function useFluidPayClient() {
|
|
101
|
+
const { config } = useFluidContext();
|
|
102
|
+
const { token } = useFluidAuth();
|
|
103
|
+
return useMemo(() => createFetchClient({
|
|
104
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
105
|
+
getAuthToken: () => token,
|
|
106
|
+
onAuthError: config.onAuthError
|
|
107
|
+
}), [
|
|
108
|
+
config.baseUrl,
|
|
109
|
+
config.onAuthError,
|
|
110
|
+
token
|
|
111
|
+
]);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Generic SDK fetch client for endpoints not covered by domain-specific clients
|
|
115
|
+
* (e.g. /countries, /v202506/customers/:id/points_ledgers).
|
|
116
|
+
* Uses the same auth/baseUrl/error handling as the domain clients.
|
|
117
|
+
*/
|
|
118
|
+
function useSdkClient() {
|
|
119
|
+
const { config } = useFluidContext();
|
|
120
|
+
const { token } = useFluidAuth();
|
|
121
|
+
return useMemo(() => createFetchClient({
|
|
122
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
123
|
+
getAuthToken: () => token,
|
|
124
|
+
onAuthError: config.onAuthError
|
|
125
|
+
}), [
|
|
126
|
+
config.baseUrl,
|
|
127
|
+
config.onAuthError,
|
|
128
|
+
token
|
|
129
|
+
]);
|
|
130
|
+
}
|
|
131
|
+
//#endregion
|
|
132
|
+
export { useSubscriptionsClient as a, useFluidAuth as c, useSdkClient as i, useFluidPayClient as n, fetchCustomerAccount as o, useOrdersClient as r, updateCustomer as s, API_VERSION as t };
|
|
133
|
+
|
|
134
|
+
//# sourceMappingURL=use-account-clients-DYTyFvdN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-account-clients-DYTyFvdN.mjs","names":["createOrdersFetchClient","createSubscriptionsFetchClient","createFluidPayFetchClient","createCoreFetchClient"],"sources":["../src/hooks/use-fluid-auth.ts","../../../fluid-pay/api-client/src/namespaces/customers.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 type { FetchClient } from \"../lib/fetch-client\";\nimport type { fluidPay } from \"../custom/fluid-pay\";\n\n/**\n * Fetch the current customer's account info.\n * Endpoint: GET /fluid_pay/me?jwt={jwt}\n */\nexport async function fetchCustomerAccount(\n client: FetchClient,\n jwt: string,\n): Promise<fluidPay.CustomerAccount> {\n return client.get(`/fluid_pay/me`, { jwt });\n}\n\n/**\n * Update customer profile (name, phone, language).\n * Endpoint: PATCH /fluid_pay/update_me?jwt={jwt}\n */\nexport async function updateCustomer(\n client: FetchClient,\n jwt: string,\n body: fluidPay.UpdateCustomerBody,\n): Promise<fluidPay.FluidPayAccountResponse> {\n return client.patch(`/fluid_pay/update_me?jwt=${jwt}`, {\n fluid_pay_account: body,\n });\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;;;;;;;;AClC9B,eAAsB,qBACpB,QACA,KACmC;AACnC,QAAO,OAAO,IAAI,iBAAiB,EAAE,KAAK,CAAC;;;;;;AAO7C,eAAsB,eACpB,QACA,KACA,MAC2C;AAC3C,QAAO,OAAO,MAAM,4BAA4B,OAAO,EACrD,mBAAmB,MACpB,CAAC;;;;;ACJJ,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"}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
require("./chunk-9hOWP6kD.cjs");
|
|
2
|
+
const require_FluidProvider = require("./FluidProvider-BmkSwcgV.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
//#region src/hooks/use-fluid-auth.ts
|
|
5
|
+
/**
|
|
6
|
+
* useFluidAuth Hook
|
|
7
|
+
*
|
|
8
|
+
* Provides access to authentication state and utilities.
|
|
9
|
+
* This is the primary hook for interacting with auth in components.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Hook to access authentication state and utilities.
|
|
13
|
+
*
|
|
14
|
+
* Must be used within a `FluidAuthProvider`.
|
|
15
|
+
*
|
|
16
|
+
* @returns Authentication context with user info, loading state, and utilities
|
|
17
|
+
* @throws Error if used outside FluidAuthProvider
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* function UserProfile() {
|
|
22
|
+
* const { isAuthenticated, isLoading, user, clearAuth } = useFluidAuth();
|
|
23
|
+
*
|
|
24
|
+
* if (isLoading) {
|
|
25
|
+
* return <Spinner />;
|
|
26
|
+
* }
|
|
27
|
+
*
|
|
28
|
+
* if (!isAuthenticated) {
|
|
29
|
+
* return <p>Please log in</p>;
|
|
30
|
+
* }
|
|
31
|
+
*
|
|
32
|
+
* return (
|
|
33
|
+
* <div>
|
|
34
|
+
* <p>Welcome, {user.full_name}!</p>
|
|
35
|
+
* <button onClick={clearAuth}>Log out</button>
|
|
36
|
+
* </div>
|
|
37
|
+
* );
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
function useFluidAuth() {
|
|
42
|
+
return require_FluidProvider.useFluidAuthContext();
|
|
43
|
+
}
|
|
44
|
+
//#endregion
|
|
45
|
+
//#region ../../fluid-pay/api-client/src/namespaces/customers.ts
|
|
46
|
+
/**
|
|
47
|
+
* Fetch the current customer's account info.
|
|
48
|
+
* Endpoint: GET /fluid_pay/me?jwt={jwt}
|
|
49
|
+
*/
|
|
50
|
+
async function fetchCustomerAccount(client, jwt) {
|
|
51
|
+
return client.get(`/fluid_pay/me`, { jwt });
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Update customer profile (name, phone, language).
|
|
55
|
+
* Endpoint: PATCH /fluid_pay/update_me?jwt={jwt}
|
|
56
|
+
*/
|
|
57
|
+
async function updateCustomer(client, jwt, body) {
|
|
58
|
+
return client.patch(`/fluid_pay/update_me?jwt=${jwt}`, { fluid_pay_account: body });
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/account/use-account-clients.ts
|
|
62
|
+
/** API version prefix for versioned endpoints (e.g. points ledger) */
|
|
63
|
+
const API_VERSION = "/v202506";
|
|
64
|
+
/**
|
|
65
|
+
* Ensures baseUrl ends with /api.
|
|
66
|
+
* Domain-specific API clients (orders, subscriptions, fluid-pay) use endpoint
|
|
67
|
+
* paths without /api (e.g. /fluid_pay/me, /subscriptions), matching fluid-admin's
|
|
68
|
+
* NEXT_PUBLIC_API_URL convention. The portal SDK's config.baseUrl is the domain
|
|
69
|
+
* root (e.g. https://api.fluid.app), so we append /api here.
|
|
70
|
+
*/
|
|
71
|
+
function withApiPrefix(baseUrl) {
|
|
72
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
73
|
+
return base.endsWith("/api") ? base : `${base}/api`;
|
|
74
|
+
}
|
|
75
|
+
function useOrdersClient() {
|
|
76
|
+
const { config } = require_FluidProvider.useFluidContext();
|
|
77
|
+
const { token } = useFluidAuth();
|
|
78
|
+
return (0, react.useMemo)(() => require_FluidProvider.createFetchClient({
|
|
79
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
80
|
+
getAuthToken: () => token,
|
|
81
|
+
onAuthError: config.onAuthError
|
|
82
|
+
}), [
|
|
83
|
+
config.baseUrl,
|
|
84
|
+
config.onAuthError,
|
|
85
|
+
token
|
|
86
|
+
]);
|
|
87
|
+
}
|
|
88
|
+
function useSubscriptionsClient() {
|
|
89
|
+
const { config } = require_FluidProvider.useFluidContext();
|
|
90
|
+
const { token } = useFluidAuth();
|
|
91
|
+
return (0, react.useMemo)(() => require_FluidProvider.createFetchClient({
|
|
92
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
93
|
+
getAuthToken: () => token,
|
|
94
|
+
onAuthError: config.onAuthError
|
|
95
|
+
}), [
|
|
96
|
+
config.baseUrl,
|
|
97
|
+
config.onAuthError,
|
|
98
|
+
token
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
function useFluidPayClient() {
|
|
102
|
+
const { config } = require_FluidProvider.useFluidContext();
|
|
103
|
+
const { token } = useFluidAuth();
|
|
104
|
+
return (0, react.useMemo)(() => require_FluidProvider.createFetchClient({
|
|
105
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
106
|
+
getAuthToken: () => token,
|
|
107
|
+
onAuthError: config.onAuthError
|
|
108
|
+
}), [
|
|
109
|
+
config.baseUrl,
|
|
110
|
+
config.onAuthError,
|
|
111
|
+
token
|
|
112
|
+
]);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Generic SDK fetch client for endpoints not covered by domain-specific clients
|
|
116
|
+
* (e.g. /countries, /v202506/customers/:id/points_ledgers).
|
|
117
|
+
* Uses the same auth/baseUrl/error handling as the domain clients.
|
|
118
|
+
*/
|
|
119
|
+
function useSdkClient() {
|
|
120
|
+
const { config } = require_FluidProvider.useFluidContext();
|
|
121
|
+
const { token } = useFluidAuth();
|
|
122
|
+
return (0, react.useMemo)(() => require_FluidProvider.createFetchClient({
|
|
123
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
124
|
+
getAuthToken: () => token,
|
|
125
|
+
onAuthError: config.onAuthError
|
|
126
|
+
}), [
|
|
127
|
+
config.baseUrl,
|
|
128
|
+
config.onAuthError,
|
|
129
|
+
token
|
|
130
|
+
]);
|
|
131
|
+
}
|
|
132
|
+
//#endregion
|
|
133
|
+
Object.defineProperty(exports, "API_VERSION", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function() {
|
|
136
|
+
return API_VERSION;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(exports, "fetchCustomerAccount", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function() {
|
|
142
|
+
return fetchCustomerAccount;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
Object.defineProperty(exports, "updateCustomer", {
|
|
146
|
+
enumerable: true,
|
|
147
|
+
get: function() {
|
|
148
|
+
return updateCustomer;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
Object.defineProperty(exports, "useFluidAuth", {
|
|
152
|
+
enumerable: true,
|
|
153
|
+
get: function() {
|
|
154
|
+
return useFluidAuth;
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
Object.defineProperty(exports, "useFluidPayClient", {
|
|
158
|
+
enumerable: true,
|
|
159
|
+
get: function() {
|
|
160
|
+
return useFluidPayClient;
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
Object.defineProperty(exports, "useOrdersClient", {
|
|
164
|
+
enumerable: true,
|
|
165
|
+
get: function() {
|
|
166
|
+
return useOrdersClient;
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
Object.defineProperty(exports, "useSdkClient", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: function() {
|
|
172
|
+
return useSdkClient;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
Object.defineProperty(exports, "useSubscriptionsClient", {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: function() {
|
|
178
|
+
return useSubscriptionsClient;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
//# sourceMappingURL=use-account-clients-n2a8bdSP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-account-clients-n2a8bdSP.cjs","names":["useFluidAuthContext","useFluidContext","createOrdersFetchClient","createSubscriptionsFetchClient","createFluidPayFetchClient","createCoreFetchClient"],"sources":["../src/hooks/use-fluid-auth.ts","../../../fluid-pay/api-client/src/namespaces/customers.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 type { FetchClient } from \"../lib/fetch-client\";\nimport type { fluidPay } from \"../custom/fluid-pay\";\n\n/**\n * Fetch the current customer's account info.\n * Endpoint: GET /fluid_pay/me?jwt={jwt}\n */\nexport async function fetchCustomerAccount(\n client: FetchClient,\n jwt: string,\n): Promise<fluidPay.CustomerAccount> {\n return client.get(`/fluid_pay/me`, { jwt });\n}\n\n/**\n * Update customer profile (name, phone, language).\n * Endpoint: PATCH /fluid_pay/update_me?jwt={jwt}\n */\nexport async function updateCustomer(\n client: FetchClient,\n jwt: string,\n body: fluidPay.UpdateCustomerBody,\n): Promise<fluidPay.FluidPayAccountResponse> {\n return client.patch(`/fluid_pay/update_me?jwt=${jwt}`, {\n fluid_pay_account: body,\n });\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;;;;;;;;AClC9B,eAAsB,qBACpB,QACA,KACmC;AACnC,QAAO,OAAO,IAAI,iBAAiB,EAAE,KAAK,CAAC;;;;;;AAO7C,eAAsB,eACpB,QACA,KACA,MAC2C;AAC3C,QAAO,OAAO,MAAM,4BAA4B,OAAO,EACrD,mBAAmB,MACpB,CAAC;;;;;ACJJ,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-app/portal-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.30",
|
|
4
4
|
"description": "SDK for building custom Fluid portals",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -55,30 +55,30 @@
|
|
|
55
55
|
"zod": "4.3.5",
|
|
56
56
|
"@fluid-app/api-client-core": "0.1.0",
|
|
57
57
|
"@fluid-app/auth": "0.1.0",
|
|
58
|
+
"@fluid-app/file-picker-api-client": "0.1.0",
|
|
58
59
|
"@fluid-app/fluidos-api-client": "0.1.0",
|
|
59
60
|
"@fluid-app/fluid-pay-api-client": "0.1.0",
|
|
60
|
-
"@fluid-app/file-picker-api-client": "0.1.0",
|
|
61
|
-
"@fluid-app/messaging-core": "0.1.0",
|
|
62
61
|
"@fluid-app/messaging-api-client": "0.1.0",
|
|
63
62
|
"@fluid-app/messaging-ui": "0.1.0",
|
|
64
63
|
"@fluid-app/orders-api-client": "0.1.0",
|
|
64
|
+
"@fluid-app/messaging-core": "0.1.0",
|
|
65
65
|
"@fluid-app/orders-core": "0.1.0",
|
|
66
66
|
"@fluid-app/orders-ui": "0.1.0",
|
|
67
|
+
"@fluid-app/portal-widgets": "0.1.22",
|
|
67
68
|
"@fluid-app/portal-core": "0.1.23",
|
|
68
69
|
"@fluid-app/products-api-client": "0.1.0",
|
|
69
|
-
"@fluid-app/profile-core": "0.1.0",
|
|
70
|
-
"@fluid-app/portal-widgets": "0.1.22",
|
|
71
70
|
"@fluid-app/profile-ui": "0.1.0",
|
|
72
71
|
"@fluid-app/products-core": "0.1.0",
|
|
72
|
+
"@fluid-app/profile-core": "0.1.0",
|
|
73
73
|
"@fluid-app/query-persister": "0.1.0",
|
|
74
74
|
"@fluid-app/shareables-api-client": "0.1.0",
|
|
75
|
-
"@fluid-app/
|
|
76
|
-
"@fluid-app/shareables-ui": "0.1.0",
|
|
75
|
+
"@fluid-app/shop-ui": "0.1.0",
|
|
77
76
|
"@fluid-app/subscriptions-api-client": "0.1.0",
|
|
78
77
|
"@fluid-app/subscriptions-core": "0.1.0",
|
|
79
|
-
"@fluid-app/
|
|
80
|
-
"@fluid-app/
|
|
81
|
-
"@fluid-app/typescript-config": "0.0.0"
|
|
78
|
+
"@fluid-app/shareables-core": "0.1.0",
|
|
79
|
+
"@fluid-app/shareables-ui": "0.1.0",
|
|
80
|
+
"@fluid-app/typescript-config": "0.0.0",
|
|
81
|
+
"@fluid-app/subscriptions-ui": "0.1.0"
|
|
82
82
|
},
|
|
83
83
|
"peerDependencies": {
|
|
84
84
|
"@hookform/resolvers": "^5.2.2",
|