@fluid-app/portal-sdk 0.1.142 → 0.1.144
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/{AppDownloadScreen-CO-wctCB.cjs → AppDownloadScreen-CxkoYLT6.cjs} +2 -2
- package/dist/{AppDownloadScreen-CO-wctCB.cjs.map → AppDownloadScreen-CxkoYLT6.cjs.map} +1 -1
- package/dist/{AppDownloadScreen-nz3fgOVF.cjs → AppDownloadScreen-DXZpoE5A.cjs} +2 -2
- package/dist/{AppDownloadScreen-Df1OPjkx.mjs → AppDownloadScreen-ga-5O4jr.mjs} +2 -2
- package/dist/{AppDownloadScreen-Df1OPjkx.mjs.map → AppDownloadScreen-ga-5O4jr.mjs.map} +1 -1
- package/dist/{ContactsScreen-cWDFP8e-.mjs → ContactsScreen-C-xJcR5X.mjs} +6 -6
- package/dist/{ContactsScreen-cWDFP8e-.mjs.map → ContactsScreen-C-xJcR5X.mjs.map} +1 -1
- package/dist/{ContactsScreen-gJB99SIY.cjs → ContactsScreen-DYkGu477.cjs} +7 -7
- package/dist/{ContactsScreen-BPeQemgG.cjs → ContactsScreen-RQ1IENFl.cjs} +6 -6
- package/dist/{ContactsScreen-BPeQemgG.cjs.map → ContactsScreen-RQ1IENFl.cjs.map} +1 -1
- package/dist/{FluidProvider-BIoYteOA.mjs → FluidProvider-Bs9eWShT.mjs} +279 -9
- package/dist/FluidProvider-Bs9eWShT.mjs.map +1 -0
- package/dist/{FluidProvider-DAe8xcAD.cjs → FluidProvider-DzCUwDPA.cjs} +290 -20
- package/dist/FluidProvider-DzCUwDPA.cjs.map +1 -0
- package/dist/{MessagingScreen-BsABB4tn.cjs → MessagingScreen-BmAICPkY.cjs} +4 -4
- package/dist/{MessagingScreen-BgY-m0Pm.cjs → MessagingScreen-D7hAjWaG.cjs} +5 -5
- package/dist/{MessagingScreen-BgY-m0Pm.cjs.map → MessagingScreen-D7hAjWaG.cjs.map} +1 -1
- package/dist/{MessagingScreen-DKXOCrBj.mjs → MessagingScreen-DOcgxDbR.mjs} +4 -4
- package/dist/{MessagingScreen-DKXOCrBj.mjs.map → MessagingScreen-DOcgxDbR.mjs.map} +1 -1
- package/dist/{MySiteScreen-DVjRy-nI.cjs → MySiteScreen-BMFJLAwJ.cjs} +2 -2
- package/dist/{MySiteScreen-DVjRy-nI.cjs.map → MySiteScreen-BMFJLAwJ.cjs.map} +1 -1
- package/dist/{MySiteScreen-D8lFT21T.mjs → MySiteScreen-BwCQLYBT.mjs} +2 -2
- package/dist/{MySiteScreen-D8lFT21T.mjs.map → MySiteScreen-BwCQLYBT.mjs.map} +1 -1
- package/dist/{MySiteScreen-BTF8MZCU.cjs → MySiteScreen-C_-EPLsj.cjs} +2 -2
- package/dist/{OrdersScreen-CbCus7pT.cjs → OrdersScreen-DHoIUinY.cjs} +3 -3
- package/dist/{OrdersScreen-CbCus7pT.cjs.map → OrdersScreen-DHoIUinY.cjs.map} +1 -1
- package/dist/{OrdersScreen-BB_n4hgl.cjs → OrdersScreen-DgBe0kl9.cjs} +3 -3
- package/dist/{OrdersScreen-BHtq-tvn.mjs → OrdersScreen-ihhKswAb.mjs} +3 -3
- package/dist/{OrdersScreen-BHtq-tvn.mjs.map → OrdersScreen-ihhKswAb.mjs.map} +1 -1
- package/dist/{ProductsScreen-CU8nGFN5.mjs → ProductsScreen-BbgYlCfQ.mjs} +6 -6
- package/dist/{ProductsScreen-CU8nGFN5.mjs.map → ProductsScreen-BbgYlCfQ.mjs.map} +1 -1
- package/dist/{ProductsScreen-CP29k8Z3.cjs → ProductsScreen-BulxEN71.cjs} +7 -7
- package/dist/{ProductsScreen-DSgwSnVj.mjs → ProductsScreen-OPY76KpG.mjs} +6 -6
- package/dist/{ProductsScreen-CuMgdka9.cjs → ProductsScreen-snrXLhuy.cjs} +6 -6
- package/dist/{ProductsScreen-CuMgdka9.cjs.map → ProductsScreen-snrXLhuy.cjs.map} +1 -1
- package/dist/{ProfileScreen-CjrhOuY3.cjs → ProfileScreen-CES4uRpE.cjs} +2 -2
- package/dist/{ProfileScreen-CDZ632ue.cjs → ProfileScreen-CPCkXse4.cjs} +5 -6
- package/dist/{ProfileScreen-CDZ632ue.cjs.map → ProfileScreen-CPCkXse4.cjs.map} +1 -1
- package/dist/{ProfileScreen-BajH0_kR.mjs → ProfileScreen-doxUb6Ud.mjs} +3 -4
- package/dist/{ProfileScreen-BajH0_kR.mjs.map → ProfileScreen-doxUb6Ud.mjs.map} +1 -1
- package/dist/{SearchSort-CyeeUmwC.cjs → SearchSort-DOLoubGE.cjs} +1 -1
- package/dist/{SearchSort-CyeeUmwC.cjs.map → SearchSort-DOLoubGE.cjs.map} +1 -1
- package/dist/{SearchSort-BXklP8Pq.mjs → SearchSort-LZm-VfF7.mjs} +1 -1
- package/dist/{SearchSort-BXklP8Pq.mjs.map → SearchSort-LZm-VfF7.mjs.map} +1 -1
- package/dist/{ShareablesScreen-acj-gCLe.cjs → ShareablesScreen-B6-BcjEt.cjs} +7 -7
- package/dist/{ShareablesScreen-F3ockfKE.mjs → ShareablesScreen-CJk0udFG.mjs} +7 -7
- package/dist/{ShareablesScreen-F3ockfKE.mjs.map → ShareablesScreen-CJk0udFG.mjs.map} +1 -1
- package/dist/{ShareablesScreen-ITLkfDHV.cjs → ShareablesScreen-DaQAxGCr.cjs} +7 -7
- package/dist/{ShareablesScreen-ITLkfDHV.cjs.map → ShareablesScreen-DaQAxGCr.cjs.map} +1 -1
- package/dist/{ShareablesScreen-B63fbgRJ.mjs → ShareablesScreen-yC7UrhhU.mjs} +6 -6
- package/dist/{ShopScreen-DdIlnLcB.mjs → ShopScreen-B3kyH-AP.mjs} +5 -5
- package/dist/{ShopScreen-DdIlnLcB.mjs.map → ShopScreen-B3kyH-AP.mjs.map} +1 -1
- package/dist/{ShopScreen-3Z-9TKeI.cjs → ShopScreen-D6JAjTai.cjs} +5 -5
- package/dist/{ShopScreen-3Z-9TKeI.cjs.map → ShopScreen-D6JAjTai.cjs.map} +1 -1
- package/dist/{ShopScreen-Bit0Fdgr.cjs → ShopScreen-DUpCS4va.cjs} +3 -3
- package/dist/{SubscriptionsScreen-DV5RUV66.cjs → SubscriptionsScreen-CEkKX-O9.cjs} +5 -5
- package/dist/{SubscriptionsScreen-DV5RUV66.cjs.map → SubscriptionsScreen-CEkKX-O9.cjs.map} +1 -1
- package/dist/{SubscriptionsScreen-B2-iZojm.mjs → SubscriptionsScreen-DlRbMhFz.mjs} +5 -5
- package/dist/{SubscriptionsScreen-B2-iZojm.mjs.map → SubscriptionsScreen-DlRbMhFz.mjs.map} +1 -1
- package/dist/{SubscriptionsScreen-01RuJl73.cjs → SubscriptionsScreen-jpRkUvPY.cjs} +5 -5
- package/dist/{dist-Cl4FsM3V.mjs → dist-B8padP0r.mjs} +2 -2
- package/dist/{dist-Cl4FsM3V.mjs.map → dist-B8padP0r.mjs.map} +1 -1
- package/dist/{dist-CbeLS2R5.cjs → dist-BoyKnTdv.cjs} +2 -2
- package/dist/{dist-CbeLS2R5.cjs.map → dist-BoyKnTdv.cjs.map} +1 -1
- package/dist/{dist-BbS_7TvS.cjs → dist-DRVtlgQ1.cjs} +1 -1
- package/dist/{dist-BbS_7TvS.cjs.map → dist-DRVtlgQ1.cjs.map} +1 -1
- package/dist/{dist-CMGXkSgZ.mjs → dist-NMbUD0qE.mjs} +1 -1
- package/dist/{dist-CMGXkSgZ.mjs.map → dist-NMbUD0qE.mjs.map} +1 -1
- package/dist/{es-BSkb3AZk.cjs → es-DlWO6buB.cjs} +1 -1
- package/dist/{es-BSkb3AZk.cjs.map → es-DlWO6buB.cjs.map} +1 -1
- package/dist/index.cjs +41 -41
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +40 -40
- package/dist/{order-status-badge-DsbuULAc.cjs → order-status-badge-BqoNJ8XK.cjs} +1 -1
- package/dist/{order-status-badge-DsbuULAc.cjs.map → order-status-badge-BqoNJ8XK.cjs.map} +1 -1
- package/dist/{order-status-badge-B-iGmxDO.mjs → order-status-badge-CkvYyjT7.mjs} +1 -1
- package/dist/{order-status-badge-B-iGmxDO.mjs.map → order-status-badge-CkvYyjT7.mjs.map} +1 -1
- package/dist/{portal-tenant-product-media-adapter-y_yCswfv.mjs → portal-tenant-product-media-adapter-BHtx3DdM.mjs} +4 -4
- package/dist/{portal-tenant-product-media-adapter-y_yCswfv.mjs.map → portal-tenant-product-media-adapter-BHtx3DdM.mjs.map} +1 -1
- package/dist/{portal-tenant-product-media-adapter-DmH2iJvp.cjs → portal-tenant-product-media-adapter-qXW0vGG8.cjs} +5 -5
- package/dist/{portal-tenant-product-media-adapter-DmH2iJvp.cjs.map → portal-tenant-product-media-adapter-qXW0vGG8.cjs.map} +1 -1
- package/dist/use-account-clients-GUakuhX-.cjs +212 -0
- package/dist/use-account-clients-GUakuhX-.cjs.map +1 -0
- package/dist/use-account-clients-d3FMT7rH.mjs +194 -0
- package/dist/use-account-clients-d3FMT7rH.mjs.map +1 -0
- package/dist/{use-current-user-DAxsYRk-.mjs → use-current-user-Cjd0lFyc.mjs} +3 -3
- package/dist/{use-current-user-DAxsYRk-.mjs.map → use-current-user-Cjd0lFyc.mjs.map} +1 -1
- package/dist/{use-current-user-5Kr_1nZZ.cjs → use-current-user-idj1wuKD.cjs} +3 -3
- package/dist/{use-current-user-5Kr_1nZZ.cjs.map → use-current-user-idj1wuKD.cjs.map} +1 -1
- package/dist/{use-fluid-api-BJ-PZ0Zx.mjs → use-fluid-api-DdMmBE5K.mjs} +2 -2
- package/dist/{use-fluid-api-BJ-PZ0Zx.mjs.map → use-fluid-api-DdMmBE5K.mjs.map} +1 -1
- package/dist/{use-fluid-api-uEqwymly.cjs → use-fluid-api-DnDH2bby.cjs} +2 -2
- package/dist/{use-fluid-api-uEqwymly.cjs.map → use-fluid-api-DnDH2bby.cjs.map} +1 -1
- package/dist/{use-fluid-auth-DXDtI7Ep.cjs → use-fluid-auth-CcxpIYkI.cjs} +2 -2
- package/dist/{use-fluid-auth-DXDtI7Ep.cjs.map → use-fluid-auth-CcxpIYkI.cjs.map} +1 -1
- package/dist/{use-fluid-auth-DrtkGGwT.mjs → use-fluid-auth-_LboeZI9.mjs} +2 -2
- package/dist/{use-fluid-auth-DrtkGGwT.mjs.map → use-fluid-auth-_LboeZI9.mjs.map} +1 -1
- package/dist/{use-portal-products-client-zvmWMf8p.mjs → use-portal-products-client-DA7Vop2s.mjs} +2 -2
- package/dist/{use-portal-products-client-zvmWMf8p.mjs.map → use-portal-products-client-DA7Vop2s.mjs.map} +1 -1
- package/dist/{use-portal-products-client-CXZj-fKI.cjs → use-portal-products-client-DAXn2JSf.cjs} +2 -2
- package/dist/{use-portal-products-client-CXZj-fKI.cjs.map → use-portal-products-client-DAXn2JSf.cjs.map} +1 -1
- package/package.json +13 -13
- package/dist/FluidProvider-BIoYteOA.mjs.map +0 -1
- package/dist/FluidProvider-DAe8xcAD.cjs.map +0 -1
- package/dist/use-account-clients-CNDyBxm7.mjs +0 -446
- package/dist/use-account-clients-CNDyBxm7.mjs.map +0 -1
- package/dist/use-account-clients-nmrVvm98.cjs +0 -476
- package/dist/use-account-clients-nmrVvm98.cjs.map +0 -1
- /package/dist/{src-zEMEV1KP.mjs → src-6SxtfYk9.mjs} +0 -0
- /package/dist/{src-CzwiFO_J.cjs → src-ClULVolb.cjs} +0 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
require("./chunk-9hOWP6kD.cjs");
|
|
2
|
+
const require_FluidProvider = require("./FluidProvider-DzCUwDPA.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
//#region ../../subscriptions/api-client/src/portal-tenant-adapter.ts
|
|
5
|
+
/**
|
|
6
|
+
* Maps the BFF meta envelope to the port's expected shape.
|
|
7
|
+
*/
|
|
8
|
+
function mapMeta$1(raw) {
|
|
9
|
+
return {
|
|
10
|
+
request_id: raw.request_id ?? "",
|
|
11
|
+
timestamp: raw.timestamp ?? ""
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Maps a BFF subscription detail response to the port's SubscriptionDetail.
|
|
16
|
+
*
|
|
17
|
+
* The BFF returns a flat Subscription schema while the port expects a richly
|
|
18
|
+
* nested SubscriptionDetailSubscription. Both represent the same underlying
|
|
19
|
+
* data — the consuming portal UI only accesses the subset of fields the BFF
|
|
20
|
+
* provides. The explicit field mapping ensures the envelope structure is
|
|
21
|
+
* correct, while the subscription data passes through at runtime.
|
|
22
|
+
*/
|
|
23
|
+
function mapSubscriptionDetail(response) {
|
|
24
|
+
return {
|
|
25
|
+
subscription: response.subscription ?? {},
|
|
26
|
+
meta: response.meta ? mapMeta$1(response.meta) : void 0
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function mapSubscriptionList(response) {
|
|
30
|
+
return {
|
|
31
|
+
subscriptions: response.subscriptions ?? [],
|
|
32
|
+
meta: mapMeta$1(response.meta ?? {})
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates a SubscriptionsApi-compatible adapter backed by the portal-tenant BFF.
|
|
37
|
+
*
|
|
38
|
+
* Uses async/await with explicit field mapping. The BFF returns simplified
|
|
39
|
+
* subscription types compared to the full admin API; the adapter maps the
|
|
40
|
+
* response envelope and provides runtime defaults for optional fields.
|
|
41
|
+
*/
|
|
42
|
+
function createPortalSubscriptionsAdapter(client) {
|
|
43
|
+
return {
|
|
44
|
+
fetchCustomerSubscriptions: async (params) => {
|
|
45
|
+
return mapSubscriptionList(await require_FluidProvider.subscriptions_list(client, {
|
|
46
|
+
"page[cursor]": params.cursor,
|
|
47
|
+
"page[limit]": params.limit ?? params.perPage
|
|
48
|
+
}));
|
|
49
|
+
},
|
|
50
|
+
fetchSubscription: async (subscriptionToken) => {
|
|
51
|
+
return mapSubscriptionDetail(await require_FluidProvider.subscriptions_show(client, subscriptionToken));
|
|
52
|
+
},
|
|
53
|
+
pauseSubscription: async (subscriptionToken, _params) => {
|
|
54
|
+
return mapSubscriptionDetail(await require_FluidProvider.subscriptions_pause(client, subscriptionToken));
|
|
55
|
+
},
|
|
56
|
+
resumeSubscription: async (subscriptionToken, _params) => {
|
|
57
|
+
return mapSubscriptionDetail(await require_FluidProvider.subscriptions_resume(client, subscriptionToken));
|
|
58
|
+
},
|
|
59
|
+
skipSubscription: async (subscriptionToken, _params) => {
|
|
60
|
+
return mapSubscriptionDetail(await require_FluidProvider.subscriptions_skip(client, subscriptionToken));
|
|
61
|
+
},
|
|
62
|
+
cancelSubscription: async (subscriptionToken, _customerId) => {
|
|
63
|
+
return mapSubscriptionDetail(await require_FluidProvider.subscriptions_cancel(client, subscriptionToken));
|
|
64
|
+
},
|
|
65
|
+
reactivateSubscription: async (subscriptionToken, _params) => {
|
|
66
|
+
return mapSubscriptionDetail(await require_FluidProvider.subscriptions_reactivate(client, subscriptionToken));
|
|
67
|
+
},
|
|
68
|
+
updateSubscriptionInfo: async (subscriptionToken, body) => {
|
|
69
|
+
return mapSubscriptionDetail(await require_FluidProvider.subscriptions_update(client, subscriptionToken, { subscription: { payment_method_id: body.payment_method_id } }));
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region ../../orders/api-client/src/portal-tenant-adapter.ts
|
|
75
|
+
/**
|
|
76
|
+
* Creates an OrdersApi adapter backed by the portal-tenant BFF.
|
|
77
|
+
*
|
|
78
|
+
* Maps the generated portal-tenant namespace functions to the abstract
|
|
79
|
+
* OrdersApi port, closing over the FetchClient so consumers don't need
|
|
80
|
+
* to pass it per-call.
|
|
81
|
+
*/
|
|
82
|
+
function mapOrder(raw) {
|
|
83
|
+
return {
|
|
84
|
+
id: raw.id ?? 0,
|
|
85
|
+
token: raw.token ?? "",
|
|
86
|
+
status: raw.status ?? "pending",
|
|
87
|
+
total: raw.total ?? "0",
|
|
88
|
+
currency: raw.currency ?? "",
|
|
89
|
+
line_items: (raw.line_items ?? []).map((li) => ({
|
|
90
|
+
id: li.id ?? 0,
|
|
91
|
+
product_id: li.product_id ?? 0,
|
|
92
|
+
product_name: li.product_name ?? "",
|
|
93
|
+
quantity: li.quantity ?? 0,
|
|
94
|
+
price: li.price ?? "0",
|
|
95
|
+
total: li.total ?? "0"
|
|
96
|
+
})),
|
|
97
|
+
customer_name: raw.customer_name ?? null,
|
|
98
|
+
customer_email: raw.customer_email ?? null,
|
|
99
|
+
total_points_credited: typeof raw.total_points_credited === "number" ? raw.total_points_credited : void 0,
|
|
100
|
+
customer_points_balance: typeof raw.customer_points_balance === "number" ? raw.customer_points_balance : void 0,
|
|
101
|
+
created_at: raw.created_at ?? "",
|
|
102
|
+
updated_at: raw.updated_at ?? ""
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
function mapMeta(raw) {
|
|
106
|
+
return {
|
|
107
|
+
request_id: raw?.request_id ?? "",
|
|
108
|
+
timestamp: raw?.timestamp ?? "",
|
|
109
|
+
pagination: {
|
|
110
|
+
cursor: raw?.pagination?.cursor ?? null,
|
|
111
|
+
limit: raw?.pagination?.limit ?? 25,
|
|
112
|
+
next_cursor: raw?.pagination?.next_cursor ?? null,
|
|
113
|
+
prev_cursor: raw?.pagination?.prev_cursor ?? null
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function createPortalTenantOrdersAdapter(client) {
|
|
118
|
+
return {
|
|
119
|
+
fetchOrderById: async (id) => {
|
|
120
|
+
const response = await require_FluidProvider.orders_show(client, id);
|
|
121
|
+
return {
|
|
122
|
+
order: mapOrder(response.order ?? {}),
|
|
123
|
+
meta: {
|
|
124
|
+
request_id: response.meta?.request_id ?? "",
|
|
125
|
+
timestamp: response.meta?.timestamp ?? ""
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
fetchOrders: async (params) => {
|
|
130
|
+
const response = await require_FluidProvider.orders_list(client, {
|
|
131
|
+
"page[cursor]": params.cursor,
|
|
132
|
+
"page[limit]": params.limit,
|
|
133
|
+
status: params.status
|
|
134
|
+
});
|
|
135
|
+
return {
|
|
136
|
+
orders: (response.orders ?? []).map(mapOrder),
|
|
137
|
+
meta: mapMeta(response.meta)
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/adapters/orders-api-adapter.ts
|
|
144
|
+
/**
|
|
145
|
+
* Creates an OrdersApi adapter for the portal-tenant BFF.
|
|
146
|
+
*
|
|
147
|
+
* Delegates to the existing clean adapter in orders/api-client which maps
|
|
148
|
+
* BFF responses to PortalTenantOrder types. The legacy methods (fetchOrder,
|
|
149
|
+
* fetchCustomerOrders) are not used by portal UI — portal-specific hooks
|
|
150
|
+
* call fetchOrders/fetchOrderById directly.
|
|
151
|
+
*/
|
|
152
|
+
function createPortalOrdersAdapter(client) {
|
|
153
|
+
const bffAdapter = createPortalTenantOrdersAdapter(client);
|
|
154
|
+
return {
|
|
155
|
+
fetchOrderById: bffAdapter.fetchOrderById,
|
|
156
|
+
fetchOrders: bffAdapter.fetchOrders
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
160
|
+
//#region src/account/use-account-clients.ts
|
|
161
|
+
function useOrdersApi() {
|
|
162
|
+
const client = require_FluidProvider.usePortalTenantClient();
|
|
163
|
+
return (0, react.useMemo)(() => createPortalOrdersAdapter(client), [client]);
|
|
164
|
+
}
|
|
165
|
+
function useSubscriptionsApiClient() {
|
|
166
|
+
const client = require_FluidProvider.usePortalTenantClient();
|
|
167
|
+
return (0, react.useMemo)(() => createPortalSubscriptionsAdapter(client), [client]);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Ensures baseUrl ends with /api.
|
|
171
|
+
* Uncovered endpoints (e.g. /countries, points ledgers) use paths without the
|
|
172
|
+
* /api prefix, so the base URL must include it.
|
|
173
|
+
*/
|
|
174
|
+
function withApiPrefix(baseUrl) {
|
|
175
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
176
|
+
return base.endsWith("/api") ? base : `${base}/api`;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Generic SDK fetch client for endpoints not covered by domain-specific clients
|
|
180
|
+
* (e.g. /countries, /v202506/customers/:id/points_ledgers).
|
|
181
|
+
* Creates a FetchClient with /api-prefixed baseUrl since these endpoints
|
|
182
|
+
* use paths like /countries (not /api/countries).
|
|
183
|
+
*/
|
|
184
|
+
function useSdkClient() {
|
|
185
|
+
const { config } = require_FluidProvider.useFluidContext();
|
|
186
|
+
return (0, react.useMemo)(() => require_FluidProvider.createFetchClient({
|
|
187
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
188
|
+
onAuthError: config.onAuthError,
|
|
189
|
+
credentials: "include"
|
|
190
|
+
}), [config.baseUrl, config.onAuthError]);
|
|
191
|
+
}
|
|
192
|
+
//#endregion
|
|
193
|
+
Object.defineProperty(exports, "useOrdersApi", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
get: function() {
|
|
196
|
+
return useOrdersApi;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
Object.defineProperty(exports, "useSdkClient", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
get: function() {
|
|
202
|
+
return useSdkClient;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(exports, "useSubscriptionsApiClient", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
get: function() {
|
|
208
|
+
return useSubscriptionsApiClient;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
//# sourceMappingURL=use-account-clients-GUakuhX-.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-account-clients-GUakuhX-.cjs","names":["mapMeta","usePortalTenantClient","useFluidContext","createFetchClient"],"sources":["../../../subscriptions/api-client/src/portal-tenant-adapter.ts","../../../orders/api-client/src/portal-tenant-adapter.ts","../src/adapters/orders-api-adapter.ts","../src/account/use-account-clients.ts"],"sourcesContent":["import type { SubscriptionsApi } from \"@fluid-app/subscriptions-core\";\nimport type { FetchClient } from \"./lib/fetch-client\";\nimport type { subscriptions } from \"./custom/subscriptions\";\nimport { portalTenant } from \"@fluid-app/portal-tenant-api-client\";\n\n/**\n * Maps the BFF meta envelope to the port's expected shape.\n */\nfunction mapMeta(raw: { request_id?: string | null; timestamp?: string }): {\n request_id: string;\n timestamp: string;\n} {\n return {\n request_id: raw.request_id ?? \"\",\n timestamp: raw.timestamp ?? \"\",\n };\n}\n\ntype BffSubscriptionResponse = Awaited<\n ReturnType<typeof portalTenant.subscriptions_show>\n>;\n\ntype BffListResponse = Awaited<\n ReturnType<typeof portalTenant.subscriptions_list>\n>;\n\n/**\n * Maps a BFF subscription detail response to the port's SubscriptionDetail.\n *\n * The BFF returns a flat Subscription schema while the port expects a richly\n * nested SubscriptionDetailSubscription. Both represent the same underlying\n * data — the consuming portal UI only accesses the subset of fields the BFF\n * provides. The explicit field mapping ensures the envelope structure is\n * correct, while the subscription data passes through at runtime.\n */\nfunction mapSubscriptionDetail(\n response: BffSubscriptionResponse,\n): subscriptions.SubscriptionDetail {\n return {\n subscription: (response.subscription ??\n {}) as unknown as subscriptions.SubscriptionDetailSubscription,\n meta: response.meta ? mapMeta(response.meta) : undefined,\n };\n}\n\nfunction mapSubscriptionList(\n response: BffListResponse,\n): subscriptions.SubscriptionsResponse {\n return {\n subscriptions: (response.subscriptions ??\n []) as unknown as subscriptions.SubscriptionListItem[],\n meta: mapMeta(response.meta ?? {}),\n };\n}\n\n/**\n * Creates a SubscriptionsApi-compatible adapter backed by the portal-tenant BFF.\n *\n * Uses async/await with explicit field mapping. The BFF returns simplified\n * subscription types compared to the full admin API; the adapter maps the\n * response envelope and provides runtime defaults for optional fields.\n */\nexport function createPortalSubscriptionsAdapter(\n client: FetchClient,\n): SubscriptionsApi {\n return {\n fetchCustomerSubscriptions: async (\n params: subscriptions.FetchSubscriptionsParams,\n ) => {\n const response = await portalTenant.subscriptions_list(client, {\n \"page[cursor]\": params.cursor,\n \"page[limit]\": params.limit ?? params.perPage,\n });\n return mapSubscriptionList(response);\n },\n\n fetchSubscription: async (subscriptionToken: string) => {\n const response = await portalTenant.subscriptions_show(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n pauseSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.PauseSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_pause(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n resumeSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.ResumeSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_resume(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n skipSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.SkipSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_skip(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n cancelSubscription: async (\n subscriptionToken: string,\n _customerId?: number,\n ) => {\n const response = await portalTenant.subscriptions_cancel(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n reactivateSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.ReactivateSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_reactivate(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n updateSubscriptionInfo: async (\n subscriptionToken: string,\n body: Pick<subscriptions.UpdateSubscriptionInfoBody, \"payment_method_id\">,\n ) => {\n const response = await portalTenant.subscriptions_update(\n client,\n subscriptionToken,\n { subscription: { payment_method_id: body.payment_method_id } },\n );\n return mapSubscriptionDetail(response);\n },\n };\n}\n","import type { FetchClient } from \"./lib/fetch-client\";\nimport type { OrdersApi } from \"@fluid-app/orders-core\";\nimport type { orders } from \"@fluid-app/orders-core\";\nimport { portalTenant } from \"@fluid-app/portal-tenant-api-client\";\n\n/**\n * Creates an OrdersApi adapter backed by the portal-tenant BFF.\n *\n * Maps the generated portal-tenant namespace functions to the abstract\n * OrdersApi port, closing over the FetchClient so consumers don't need\n * to pass it per-call.\n */\n\nfunction mapOrder(\n raw: NonNullable<\n Awaited<ReturnType<typeof portalTenant.orders_show>>[\"order\"]\n >,\n): orders.PortalTenantOrder {\n return {\n id: raw.id ?? 0,\n token: raw.token ?? \"\",\n status: (raw.status ?? \"pending\") as orders.PortalTenantOrderStatus,\n total: raw.total ?? \"0\",\n currency: raw.currency ?? \"\",\n line_items: (raw.line_items ?? []).map((li) => ({\n id: li.id ?? 0,\n product_id: li.product_id ?? 0,\n product_name: li.product_name ?? \"\",\n quantity: li.quantity ?? 0,\n price: li.price ?? \"0\",\n total: li.total ?? \"0\",\n })),\n customer_name: raw.customer_name ?? null,\n customer_email: raw.customer_email ?? null,\n total_points_credited:\n typeof (raw as Record<string, unknown>).total_points_credited === \"number\"\n ? ((raw as Record<string, unknown>).total_points_credited as number)\n : undefined,\n customer_points_balance:\n typeof (raw as Record<string, unknown>).customer_points_balance ===\n \"number\"\n ? ((raw as Record<string, unknown>).customer_points_balance as number)\n : undefined,\n created_at: raw.created_at ?? \"\",\n updated_at: raw.updated_at ?? \"\",\n } satisfies orders.PortalTenantOrder;\n}\n\nfunction mapMeta(\n raw: Awaited<ReturnType<typeof portalTenant.orders_list>>[\"meta\"] | undefined,\n): orders.PortalTenantMeta {\n return {\n request_id: raw?.request_id ?? \"\",\n timestamp: raw?.timestamp ?? \"\",\n pagination: {\n cursor: raw?.pagination?.cursor ?? null,\n limit: raw?.pagination?.limit ?? 25,\n next_cursor: raw?.pagination?.next_cursor ?? null,\n prev_cursor: raw?.pagination?.prev_cursor ?? null,\n },\n } satisfies orders.PortalTenantMeta;\n}\n\nexport function createPortalTenantOrdersAdapter(\n client: FetchClient,\n): Required<Pick<OrdersApi, \"fetchOrderById\" | \"fetchOrders\">> {\n return {\n fetchOrderById: async (id: number) => {\n const response = await portalTenant.orders_show(client, id);\n return {\n order: mapOrder(response.order ?? {}),\n meta: {\n request_id: response.meta?.request_id ?? \"\",\n timestamp: response.meta?.timestamp ?? \"\",\n },\n } satisfies orders.PortalTenantOrderResponse;\n },\n\n fetchOrders: async (params: orders.PortalTenantFetchOrdersParams) => {\n const response = await portalTenant.orders_list(client, {\n \"page[cursor]\": params.cursor,\n \"page[limit]\": params.limit,\n status: params.status,\n });\n return {\n orders: (response.orders ?? []).map(mapOrder),\n meta: mapMeta(response.meta),\n } satisfies orders.PortalTenantOrdersResponse;\n },\n };\n}\n","import type { OrdersApi } from \"@fluid-app/orders-core\";\nimport type { FetchClient } from \"@fluid-app/portal-tenant-api-client\";\nimport { createPortalTenantOrdersAdapter } from \"@fluid-app/orders-api-client\";\n\n/**\n * Creates an OrdersApi adapter for the portal-tenant BFF.\n *\n * Delegates to the existing clean adapter in orders/api-client which maps\n * BFF responses to PortalTenantOrder types. The legacy methods (fetchOrder,\n * fetchCustomerOrders) are not used by portal UI — portal-specific hooks\n * call fetchOrders/fetchOrderById directly.\n */\nexport function createPortalOrdersAdapter(client: FetchClient): OrdersApi {\n const bffAdapter = createPortalTenantOrdersAdapter(client);\n return {\n fetchOrderById: bffAdapter.fetchOrderById,\n fetchOrders: bffAdapter.fetchOrders,\n };\n}\n","import { useMemo } from \"react\";\nimport type { OrdersApi } from \"@fluid-app/orders-core\";\nimport type { SubscriptionsApi } from \"@fluid-app/subscriptions-core\";\nimport { createPortalSubscriptionsAdapter } from \"@fluid-app/subscriptions-api-client\";\nimport {\n createFetchClient,\n type FetchClient as CoreFetchClient,\n} from \"@fluid-app/api-client-core\";\nimport { createPortalOrdersAdapter } from \"../adapters/orders-api-adapter\";\nimport { usePortalTenantClient } from \"../providers/PortalTenantClientProvider\";\nimport { useFluidContext } from \"../providers/FluidProvider\";\n\n/** API version prefix for versioned endpoints (e.g. points ledger) */\nexport const API_VERSION = \"/v202506\";\n\nexport function useOrdersApi(): OrdersApi {\n const client = usePortalTenantClient();\n\n return useMemo(() => createPortalOrdersAdapter(client), [client]);\n}\n\nexport function useSubscriptionsApiClient(): SubscriptionsApi {\n const client = usePortalTenantClient();\n\n return useMemo(() => createPortalSubscriptionsAdapter(client), [client]);\n}\n\n/**\n * Ensures baseUrl ends with /api.\n * Uncovered endpoints (e.g. /countries, points ledgers) use paths without the\n * /api prefix, so the base URL must include it.\n */\nfunction withApiPrefix(baseUrl: string): string {\n const base = baseUrl.replace(/\\/+$/, \"\");\n return base.endsWith(\"/api\") ? base : `${base}/api`;\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 * Creates a FetchClient with /api-prefixed baseUrl since these endpoints\n * use paths like /countries (not /api/countries).\n */\nexport function useSdkClient(): CoreFetchClient {\n const { config } = useFluidContext();\n\n return useMemo(\n () =>\n createFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n onAuthError: config.onAuthError,\n credentials: \"include\",\n }),\n [config.baseUrl, config.onAuthError],\n );\n}\n"],"mappings":";;;;;;;AAQA,SAASA,UAAQ,KAGf;AACA,QAAO;EACL,YAAY,IAAI,cAAc;EAC9B,WAAW,IAAI,aAAa;EAC7B;;;;;;;;;;;AAoBH,SAAS,sBACP,UACkC;AAClC,QAAO;EACL,cAAe,SAAS,gBACtB,EAAE;EACJ,MAAM,SAAS,OAAOA,UAAQ,SAAS,KAAK,GAAG,KAAA;EAChD;;AAGH,SAAS,oBACP,UACqC;AACrC,QAAO;EACL,eAAgB,SAAS,iBACvB,EAAE;EACJ,MAAMA,UAAQ,SAAS,QAAQ,EAAE,CAAC;EACnC;;;;;;;;;AAUH,SAAgB,iCACd,QACkB;AAClB,QAAO;EACL,4BAA4B,OAC1B,WACG;AAKH,UAAO,oBAJU,MAAA,sBAAA,mBAAsC,QAAQ;IAC7D,gBAAgB,OAAO;IACvB,eAAe,OAAO,SAAS,OAAO;IACvC,CAAC,CACkC;;EAGtC,mBAAmB,OAAO,sBAA8B;AAKtD,UAAO,sBAJU,MAAA,sBAAA,mBACf,QACA,kBACD,CACqC;;EA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;;;;;;;;AAShD,SAAgB,eAAgC;CAC9C,MAAM,EAAE,WAAWC,sBAAAA,iBAAiB;AAEpC,SAAA,GAAA,MAAA,eAEIC,sBAAAA,kBAAkB;EAChB,SAAS,cAAc,OAAO,QAAQ;EACtC,aAAa,OAAO;EACpB,aAAa;EACd,CAAC,EACJ,CAAC,OAAO,SAAS,OAAO,YAAY,CACrC"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { _t as createFetchClient, ct as subscriptions_cancel, dt as subscriptions_reactivate, ft as subscriptions_resume, ht as subscriptions_update, lt as subscriptions_list, mt as subscriptions_skip, n as useFluidContext, nt as orders_list, pt as subscriptions_show, rt as orders_show, u as usePortalTenantClient, ut as subscriptions_pause } from "./FluidProvider-Bs9eWShT.mjs";
|
|
2
|
+
import { useMemo } from "react";
|
|
3
|
+
//#region ../../subscriptions/api-client/src/portal-tenant-adapter.ts
|
|
4
|
+
/**
|
|
5
|
+
* Maps the BFF meta envelope to the port's expected shape.
|
|
6
|
+
*/
|
|
7
|
+
function mapMeta$1(raw) {
|
|
8
|
+
return {
|
|
9
|
+
request_id: raw.request_id ?? "",
|
|
10
|
+
timestamp: raw.timestamp ?? ""
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Maps a BFF subscription detail response to the port's SubscriptionDetail.
|
|
15
|
+
*
|
|
16
|
+
* The BFF returns a flat Subscription schema while the port expects a richly
|
|
17
|
+
* nested SubscriptionDetailSubscription. Both represent the same underlying
|
|
18
|
+
* data — the consuming portal UI only accesses the subset of fields the BFF
|
|
19
|
+
* provides. The explicit field mapping ensures the envelope structure is
|
|
20
|
+
* correct, while the subscription data passes through at runtime.
|
|
21
|
+
*/
|
|
22
|
+
function mapSubscriptionDetail(response) {
|
|
23
|
+
return {
|
|
24
|
+
subscription: response.subscription ?? {},
|
|
25
|
+
meta: response.meta ? mapMeta$1(response.meta) : void 0
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function mapSubscriptionList(response) {
|
|
29
|
+
return {
|
|
30
|
+
subscriptions: response.subscriptions ?? [],
|
|
31
|
+
meta: mapMeta$1(response.meta ?? {})
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a SubscriptionsApi-compatible adapter backed by the portal-tenant BFF.
|
|
36
|
+
*
|
|
37
|
+
* Uses async/await with explicit field mapping. The BFF returns simplified
|
|
38
|
+
* subscription types compared to the full admin API; the adapter maps the
|
|
39
|
+
* response envelope and provides runtime defaults for optional fields.
|
|
40
|
+
*/
|
|
41
|
+
function createPortalSubscriptionsAdapter(client) {
|
|
42
|
+
return {
|
|
43
|
+
fetchCustomerSubscriptions: async (params) => {
|
|
44
|
+
return mapSubscriptionList(await subscriptions_list(client, {
|
|
45
|
+
"page[cursor]": params.cursor,
|
|
46
|
+
"page[limit]": params.limit ?? params.perPage
|
|
47
|
+
}));
|
|
48
|
+
},
|
|
49
|
+
fetchSubscription: async (subscriptionToken) => {
|
|
50
|
+
return mapSubscriptionDetail(await subscriptions_show(client, subscriptionToken));
|
|
51
|
+
},
|
|
52
|
+
pauseSubscription: async (subscriptionToken, _params) => {
|
|
53
|
+
return mapSubscriptionDetail(await subscriptions_pause(client, subscriptionToken));
|
|
54
|
+
},
|
|
55
|
+
resumeSubscription: async (subscriptionToken, _params) => {
|
|
56
|
+
return mapSubscriptionDetail(await subscriptions_resume(client, subscriptionToken));
|
|
57
|
+
},
|
|
58
|
+
skipSubscription: async (subscriptionToken, _params) => {
|
|
59
|
+
return mapSubscriptionDetail(await subscriptions_skip(client, subscriptionToken));
|
|
60
|
+
},
|
|
61
|
+
cancelSubscription: async (subscriptionToken, _customerId) => {
|
|
62
|
+
return mapSubscriptionDetail(await subscriptions_cancel(client, subscriptionToken));
|
|
63
|
+
},
|
|
64
|
+
reactivateSubscription: async (subscriptionToken, _params) => {
|
|
65
|
+
return mapSubscriptionDetail(await subscriptions_reactivate(client, subscriptionToken));
|
|
66
|
+
},
|
|
67
|
+
updateSubscriptionInfo: async (subscriptionToken, body) => {
|
|
68
|
+
return mapSubscriptionDetail(await subscriptions_update(client, subscriptionToken, { subscription: { payment_method_id: body.payment_method_id } }));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region ../../orders/api-client/src/portal-tenant-adapter.ts
|
|
74
|
+
/**
|
|
75
|
+
* Creates an OrdersApi adapter backed by the portal-tenant BFF.
|
|
76
|
+
*
|
|
77
|
+
* Maps the generated portal-tenant namespace functions to the abstract
|
|
78
|
+
* OrdersApi port, closing over the FetchClient so consumers don't need
|
|
79
|
+
* to pass it per-call.
|
|
80
|
+
*/
|
|
81
|
+
function mapOrder(raw) {
|
|
82
|
+
return {
|
|
83
|
+
id: raw.id ?? 0,
|
|
84
|
+
token: raw.token ?? "",
|
|
85
|
+
status: raw.status ?? "pending",
|
|
86
|
+
total: raw.total ?? "0",
|
|
87
|
+
currency: raw.currency ?? "",
|
|
88
|
+
line_items: (raw.line_items ?? []).map((li) => ({
|
|
89
|
+
id: li.id ?? 0,
|
|
90
|
+
product_id: li.product_id ?? 0,
|
|
91
|
+
product_name: li.product_name ?? "",
|
|
92
|
+
quantity: li.quantity ?? 0,
|
|
93
|
+
price: li.price ?? "0",
|
|
94
|
+
total: li.total ?? "0"
|
|
95
|
+
})),
|
|
96
|
+
customer_name: raw.customer_name ?? null,
|
|
97
|
+
customer_email: raw.customer_email ?? null,
|
|
98
|
+
total_points_credited: typeof raw.total_points_credited === "number" ? raw.total_points_credited : void 0,
|
|
99
|
+
customer_points_balance: typeof raw.customer_points_balance === "number" ? raw.customer_points_balance : void 0,
|
|
100
|
+
created_at: raw.created_at ?? "",
|
|
101
|
+
updated_at: raw.updated_at ?? ""
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function mapMeta(raw) {
|
|
105
|
+
return {
|
|
106
|
+
request_id: raw?.request_id ?? "",
|
|
107
|
+
timestamp: raw?.timestamp ?? "",
|
|
108
|
+
pagination: {
|
|
109
|
+
cursor: raw?.pagination?.cursor ?? null,
|
|
110
|
+
limit: raw?.pagination?.limit ?? 25,
|
|
111
|
+
next_cursor: raw?.pagination?.next_cursor ?? null,
|
|
112
|
+
prev_cursor: raw?.pagination?.prev_cursor ?? null
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function createPortalTenantOrdersAdapter(client) {
|
|
117
|
+
return {
|
|
118
|
+
fetchOrderById: async (id) => {
|
|
119
|
+
const response = await orders_show(client, id);
|
|
120
|
+
return {
|
|
121
|
+
order: mapOrder(response.order ?? {}),
|
|
122
|
+
meta: {
|
|
123
|
+
request_id: response.meta?.request_id ?? "",
|
|
124
|
+
timestamp: response.meta?.timestamp ?? ""
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
fetchOrders: async (params) => {
|
|
129
|
+
const response = await orders_list(client, {
|
|
130
|
+
"page[cursor]": params.cursor,
|
|
131
|
+
"page[limit]": params.limit,
|
|
132
|
+
status: params.status
|
|
133
|
+
});
|
|
134
|
+
return {
|
|
135
|
+
orders: (response.orders ?? []).map(mapOrder),
|
|
136
|
+
meta: mapMeta(response.meta)
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/adapters/orders-api-adapter.ts
|
|
143
|
+
/**
|
|
144
|
+
* Creates an OrdersApi adapter for the portal-tenant BFF.
|
|
145
|
+
*
|
|
146
|
+
* Delegates to the existing clean adapter in orders/api-client which maps
|
|
147
|
+
* BFF responses to PortalTenantOrder types. The legacy methods (fetchOrder,
|
|
148
|
+
* fetchCustomerOrders) are not used by portal UI — portal-specific hooks
|
|
149
|
+
* call fetchOrders/fetchOrderById directly.
|
|
150
|
+
*/
|
|
151
|
+
function createPortalOrdersAdapter(client) {
|
|
152
|
+
const bffAdapter = createPortalTenantOrdersAdapter(client);
|
|
153
|
+
return {
|
|
154
|
+
fetchOrderById: bffAdapter.fetchOrderById,
|
|
155
|
+
fetchOrders: bffAdapter.fetchOrders
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/account/use-account-clients.ts
|
|
160
|
+
function useOrdersApi() {
|
|
161
|
+
const client = usePortalTenantClient();
|
|
162
|
+
return useMemo(() => createPortalOrdersAdapter(client), [client]);
|
|
163
|
+
}
|
|
164
|
+
function useSubscriptionsApiClient() {
|
|
165
|
+
const client = usePortalTenantClient();
|
|
166
|
+
return useMemo(() => createPortalSubscriptionsAdapter(client), [client]);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Ensures baseUrl ends with /api.
|
|
170
|
+
* Uncovered endpoints (e.g. /countries, points ledgers) use paths without the
|
|
171
|
+
* /api prefix, so the base URL must include it.
|
|
172
|
+
*/
|
|
173
|
+
function withApiPrefix(baseUrl) {
|
|
174
|
+
const base = baseUrl.replace(/\/+$/, "");
|
|
175
|
+
return base.endsWith("/api") ? base : `${base}/api`;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Generic SDK fetch client for endpoints not covered by domain-specific clients
|
|
179
|
+
* (e.g. /countries, /v202506/customers/:id/points_ledgers).
|
|
180
|
+
* Creates a FetchClient with /api-prefixed baseUrl since these endpoints
|
|
181
|
+
* use paths like /countries (not /api/countries).
|
|
182
|
+
*/
|
|
183
|
+
function useSdkClient() {
|
|
184
|
+
const { config } = useFluidContext();
|
|
185
|
+
return useMemo(() => createFetchClient({
|
|
186
|
+
baseUrl: withApiPrefix(config.baseUrl),
|
|
187
|
+
onAuthError: config.onAuthError,
|
|
188
|
+
credentials: "include"
|
|
189
|
+
}), [config.baseUrl, config.onAuthError]);
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
export { useSdkClient as n, useSubscriptionsApiClient as r, useOrdersApi as t };
|
|
193
|
+
|
|
194
|
+
//# sourceMappingURL=use-account-clients-d3FMT7rH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-account-clients-d3FMT7rH.mjs","names":["mapMeta","portalTenant.subscriptions_list","portalTenant.subscriptions_show","portalTenant.subscriptions_pause","portalTenant.subscriptions_resume","portalTenant.subscriptions_skip","portalTenant.subscriptions_cancel","portalTenant.subscriptions_reactivate","portalTenant.subscriptions_update","portalTenant.orders_show","portalTenant.orders_list"],"sources":["../../../subscriptions/api-client/src/portal-tenant-adapter.ts","../../../orders/api-client/src/portal-tenant-adapter.ts","../src/adapters/orders-api-adapter.ts","../src/account/use-account-clients.ts"],"sourcesContent":["import type { SubscriptionsApi } from \"@fluid-app/subscriptions-core\";\nimport type { FetchClient } from \"./lib/fetch-client\";\nimport type { subscriptions } from \"./custom/subscriptions\";\nimport { portalTenant } from \"@fluid-app/portal-tenant-api-client\";\n\n/**\n * Maps the BFF meta envelope to the port's expected shape.\n */\nfunction mapMeta(raw: { request_id?: string | null; timestamp?: string }): {\n request_id: string;\n timestamp: string;\n} {\n return {\n request_id: raw.request_id ?? \"\",\n timestamp: raw.timestamp ?? \"\",\n };\n}\n\ntype BffSubscriptionResponse = Awaited<\n ReturnType<typeof portalTenant.subscriptions_show>\n>;\n\ntype BffListResponse = Awaited<\n ReturnType<typeof portalTenant.subscriptions_list>\n>;\n\n/**\n * Maps a BFF subscription detail response to the port's SubscriptionDetail.\n *\n * The BFF returns a flat Subscription schema while the port expects a richly\n * nested SubscriptionDetailSubscription. Both represent the same underlying\n * data — the consuming portal UI only accesses the subset of fields the BFF\n * provides. The explicit field mapping ensures the envelope structure is\n * correct, while the subscription data passes through at runtime.\n */\nfunction mapSubscriptionDetail(\n response: BffSubscriptionResponse,\n): subscriptions.SubscriptionDetail {\n return {\n subscription: (response.subscription ??\n {}) as unknown as subscriptions.SubscriptionDetailSubscription,\n meta: response.meta ? mapMeta(response.meta) : undefined,\n };\n}\n\nfunction mapSubscriptionList(\n response: BffListResponse,\n): subscriptions.SubscriptionsResponse {\n return {\n subscriptions: (response.subscriptions ??\n []) as unknown as subscriptions.SubscriptionListItem[],\n meta: mapMeta(response.meta ?? {}),\n };\n}\n\n/**\n * Creates a SubscriptionsApi-compatible adapter backed by the portal-tenant BFF.\n *\n * Uses async/await with explicit field mapping. The BFF returns simplified\n * subscription types compared to the full admin API; the adapter maps the\n * response envelope and provides runtime defaults for optional fields.\n */\nexport function createPortalSubscriptionsAdapter(\n client: FetchClient,\n): SubscriptionsApi {\n return {\n fetchCustomerSubscriptions: async (\n params: subscriptions.FetchSubscriptionsParams,\n ) => {\n const response = await portalTenant.subscriptions_list(client, {\n \"page[cursor]\": params.cursor,\n \"page[limit]\": params.limit ?? params.perPage,\n });\n return mapSubscriptionList(response);\n },\n\n fetchSubscription: async (subscriptionToken: string) => {\n const response = await portalTenant.subscriptions_show(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n pauseSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.PauseSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_pause(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n resumeSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.ResumeSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_resume(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n skipSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.SkipSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_skip(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n cancelSubscription: async (\n subscriptionToken: string,\n _customerId?: number,\n ) => {\n const response = await portalTenant.subscriptions_cancel(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n reactivateSubscription: async (\n subscriptionToken: string,\n _params: subscriptions.ReactivateSubscriptionParams,\n ) => {\n const response = await portalTenant.subscriptions_reactivate(\n client,\n subscriptionToken,\n );\n return mapSubscriptionDetail(response);\n },\n\n updateSubscriptionInfo: async (\n subscriptionToken: string,\n body: Pick<subscriptions.UpdateSubscriptionInfoBody, \"payment_method_id\">,\n ) => {\n const response = await portalTenant.subscriptions_update(\n client,\n subscriptionToken,\n { subscription: { payment_method_id: body.payment_method_id } },\n );\n return mapSubscriptionDetail(response);\n },\n };\n}\n","import type { FetchClient } from \"./lib/fetch-client\";\nimport type { OrdersApi } from \"@fluid-app/orders-core\";\nimport type { orders } from \"@fluid-app/orders-core\";\nimport { portalTenant } from \"@fluid-app/portal-tenant-api-client\";\n\n/**\n * Creates an OrdersApi adapter backed by the portal-tenant BFF.\n *\n * Maps the generated portal-tenant namespace functions to the abstract\n * OrdersApi port, closing over the FetchClient so consumers don't need\n * to pass it per-call.\n */\n\nfunction mapOrder(\n raw: NonNullable<\n Awaited<ReturnType<typeof portalTenant.orders_show>>[\"order\"]\n >,\n): orders.PortalTenantOrder {\n return {\n id: raw.id ?? 0,\n token: raw.token ?? \"\",\n status: (raw.status ?? \"pending\") as orders.PortalTenantOrderStatus,\n total: raw.total ?? \"0\",\n currency: raw.currency ?? \"\",\n line_items: (raw.line_items ?? []).map((li) => ({\n id: li.id ?? 0,\n product_id: li.product_id ?? 0,\n product_name: li.product_name ?? \"\",\n quantity: li.quantity ?? 0,\n price: li.price ?? \"0\",\n total: li.total ?? \"0\",\n })),\n customer_name: raw.customer_name ?? null,\n customer_email: raw.customer_email ?? null,\n total_points_credited:\n typeof (raw as Record<string, unknown>).total_points_credited === \"number\"\n ? ((raw as Record<string, unknown>).total_points_credited as number)\n : undefined,\n customer_points_balance:\n typeof (raw as Record<string, unknown>).customer_points_balance ===\n \"number\"\n ? ((raw as Record<string, unknown>).customer_points_balance as number)\n : undefined,\n created_at: raw.created_at ?? \"\",\n updated_at: raw.updated_at ?? \"\",\n } satisfies orders.PortalTenantOrder;\n}\n\nfunction mapMeta(\n raw: Awaited<ReturnType<typeof portalTenant.orders_list>>[\"meta\"] | undefined,\n): orders.PortalTenantMeta {\n return {\n request_id: raw?.request_id ?? \"\",\n timestamp: raw?.timestamp ?? \"\",\n pagination: {\n cursor: raw?.pagination?.cursor ?? null,\n limit: raw?.pagination?.limit ?? 25,\n next_cursor: raw?.pagination?.next_cursor ?? null,\n prev_cursor: raw?.pagination?.prev_cursor ?? null,\n },\n } satisfies orders.PortalTenantMeta;\n}\n\nexport function createPortalTenantOrdersAdapter(\n client: FetchClient,\n): Required<Pick<OrdersApi, \"fetchOrderById\" | \"fetchOrders\">> {\n return {\n fetchOrderById: async (id: number) => {\n const response = await portalTenant.orders_show(client, id);\n return {\n order: mapOrder(response.order ?? {}),\n meta: {\n request_id: response.meta?.request_id ?? \"\",\n timestamp: response.meta?.timestamp ?? \"\",\n },\n } satisfies orders.PortalTenantOrderResponse;\n },\n\n fetchOrders: async (params: orders.PortalTenantFetchOrdersParams) => {\n const response = await portalTenant.orders_list(client, {\n \"page[cursor]\": params.cursor,\n \"page[limit]\": params.limit,\n status: params.status,\n });\n return {\n orders: (response.orders ?? []).map(mapOrder),\n meta: mapMeta(response.meta),\n } satisfies orders.PortalTenantOrdersResponse;\n },\n };\n}\n","import type { OrdersApi } from \"@fluid-app/orders-core\";\nimport type { FetchClient } from \"@fluid-app/portal-tenant-api-client\";\nimport { createPortalTenantOrdersAdapter } from \"@fluid-app/orders-api-client\";\n\n/**\n * Creates an OrdersApi adapter for the portal-tenant BFF.\n *\n * Delegates to the existing clean adapter in orders/api-client which maps\n * BFF responses to PortalTenantOrder types. The legacy methods (fetchOrder,\n * fetchCustomerOrders) are not used by portal UI — portal-specific hooks\n * call fetchOrders/fetchOrderById directly.\n */\nexport function createPortalOrdersAdapter(client: FetchClient): OrdersApi {\n const bffAdapter = createPortalTenantOrdersAdapter(client);\n return {\n fetchOrderById: bffAdapter.fetchOrderById,\n fetchOrders: bffAdapter.fetchOrders,\n };\n}\n","import { useMemo } from \"react\";\nimport type { OrdersApi } from \"@fluid-app/orders-core\";\nimport type { SubscriptionsApi } from \"@fluid-app/subscriptions-core\";\nimport { createPortalSubscriptionsAdapter } from \"@fluid-app/subscriptions-api-client\";\nimport {\n createFetchClient,\n type FetchClient as CoreFetchClient,\n} from \"@fluid-app/api-client-core\";\nimport { createPortalOrdersAdapter } from \"../adapters/orders-api-adapter\";\nimport { usePortalTenantClient } from \"../providers/PortalTenantClientProvider\";\nimport { useFluidContext } from \"../providers/FluidProvider\";\n\n/** API version prefix for versioned endpoints (e.g. points ledger) */\nexport const API_VERSION = \"/v202506\";\n\nexport function useOrdersApi(): OrdersApi {\n const client = usePortalTenantClient();\n\n return useMemo(() => createPortalOrdersAdapter(client), [client]);\n}\n\nexport function useSubscriptionsApiClient(): SubscriptionsApi {\n const client = usePortalTenantClient();\n\n return useMemo(() => createPortalSubscriptionsAdapter(client), [client]);\n}\n\n/**\n * Ensures baseUrl ends with /api.\n * Uncovered endpoints (e.g. /countries, points ledgers) use paths without the\n * /api prefix, so the base URL must include it.\n */\nfunction withApiPrefix(baseUrl: string): string {\n const base = baseUrl.replace(/\\/+$/, \"\");\n return base.endsWith(\"/api\") ? base : `${base}/api`;\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 * Creates a FetchClient with /api-prefixed baseUrl since these endpoints\n * use paths like /countries (not /api/countries).\n */\nexport function useSdkClient(): CoreFetchClient {\n const { config } = useFluidContext();\n\n return useMemo(\n () =>\n createFetchClient({\n baseUrl: withApiPrefix(config.baseUrl),\n onAuthError: config.onAuthError,\n credentials: \"include\",\n }),\n [config.baseUrl, config.onAuthError],\n );\n}\n"],"mappings":";;;;;;AAQA,SAASA,UAAQ,KAGf;AACA,QAAO;EACL,YAAY,IAAI,cAAc;EAC9B,WAAW,IAAI,aAAa;EAC7B;;;;;;;;;;;AAoBH,SAAS,sBACP,UACkC;AAClC,QAAO;EACL,cAAe,SAAS,gBACtB,EAAE;EACJ,MAAM,SAAS,OAAOA,UAAQ,SAAS,KAAK,GAAG,KAAA;EAChD;;AAGH,S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tC,QAAO,cAAc,0BAA0B,OAAO,EAAE,CAAC,OAAO,CAAC;;AAGnE,SAAgB,4BAA8C;CAC5D,MAAM,SAAS,uBAAuB;AAEtC,QAAO,cAAc,iCAAiC,OAAO,EAAE,CAAC,OAAO,CAAC;;;;;;;AAQ1E,SAAS,cAAc,SAAyB;CAC9C,MAAM,OAAO,QAAQ,QAAQ,QAAQ,GAAG;AACxC,QAAO,KAAK,SAAS,OAAO,GAAG,OAAO,GAAG,KAAK;;;;;;;;AAShD,SAAgB,eAAgC;CAC9C,MAAM,EAAE,WAAW,iBAAiB;AAEpC,QAAO,cAEH,kBAAkB;EAChB,SAAS,cAAc,OAAO,QAAQ;EACtC,aAAa,OAAO;EACpB,aAAa;EACd,CAAC,EACJ,CAAC,OAAO,SAAS,OAAO,YAAY,CACrC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { l as useFluidAuthContext } from "./FluidProvider-
|
|
2
|
-
import { t as useFluidApi } from "./use-fluid-api-
|
|
1
|
+
import { l as useFluidAuthContext } from "./FluidProvider-Bs9eWShT.mjs";
|
|
2
|
+
import { t as useFluidApi } from "./use-fluid-api-DdMmBE5K.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-
|
|
101
|
+
//# sourceMappingURL=use-current-user-Cjd0lFyc.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-current-user-
|
|
1
|
+
{"version":3,"file":"use-current-user-Cjd0lFyc.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,6 +1,6 @@
|
|
|
1
1
|
require("./chunk-9hOWP6kD.cjs");
|
|
2
|
-
const require_FluidProvider = require("./FluidProvider-
|
|
3
|
-
const require_use_fluid_api = require("./use-fluid-api-
|
|
2
|
+
const require_FluidProvider = require("./FluidProvider-DzCUwDPA.cjs");
|
|
3
|
+
const require_use_fluid_api = require("./use-fluid-api-DnDH2bby.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-
|
|
125
|
+
//# sourceMappingURL=use-current-user-idj1wuKD.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-current-user-
|
|
1
|
+
{"version":3,"file":"use-current-user-idj1wuKD.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,4 +1,4 @@
|
|
|
1
|
-
import { n as useFluidContext } from "./FluidProvider-
|
|
1
|
+
import { n as useFluidContext } from "./FluidProvider-Bs9eWShT.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-
|
|
27
|
+
//# sourceMappingURL=use-fluid-api-DdMmBE5K.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fluid-api-
|
|
1
|
+
{"version":3,"file":"use-fluid-api-DdMmBE5K.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 UserInfo() {\n * const api = useFluidApi();\n *\n * const { data: user } = useQuery({\n * queryKey: [\"me\"],\n * queryFn: () => api.users.me(),\n * });\n *\n * return <p>Hello, {user?.name}</p>;\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-
|
|
1
|
+
const require_FluidProvider = require("./FluidProvider-DzCUwDPA.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-
|
|
32
|
+
//# sourceMappingURL=use-fluid-api-DnDH2bby.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fluid-api-
|
|
1
|
+
{"version":3,"file":"use-fluid-api-DnDH2bby.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 UserInfo() {\n * const api = useFluidApi();\n *\n * const { data: user } = useQuery({\n * queryKey: [\"me\"],\n * queryFn: () => api.users.me(),\n * });\n *\n * return <p>Hello, {user?.name}</p>;\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,4 +1,4 @@
|
|
|
1
|
-
const require_FluidProvider = require("./FluidProvider-
|
|
1
|
+
const require_FluidProvider = require("./FluidProvider-DzCUwDPA.cjs");
|
|
2
2
|
//#region src/hooks/use-fluid-auth.ts
|
|
3
3
|
/**
|
|
4
4
|
* useFluidAuth Hook
|
|
@@ -47,4 +47,4 @@ Object.defineProperty(exports, "useFluidAuth", {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
//# sourceMappingURL=use-fluid-auth-
|
|
50
|
+
//# sourceMappingURL=use-fluid-auth-CcxpIYkI.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fluid-auth-
|
|
1
|
+
{"version":3,"file":"use-fluid-auth-CcxpIYkI.cjs","names":["useFluidAuthContext"],"sources":["../src/hooks/use-fluid-auth.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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,eAAsC;AACpD,QAAOA,sBAAAA,qBAAqB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as useFluidAuthContext } from "./FluidProvider-
|
|
1
|
+
import { l as useFluidAuthContext } from "./FluidProvider-Bs9eWShT.mjs";
|
|
2
2
|
//#region src/hooks/use-fluid-auth.ts
|
|
3
3
|
/**
|
|
4
4
|
* useFluidAuth Hook
|
|
@@ -42,4 +42,4 @@ function useFluidAuth() {
|
|
|
42
42
|
//#endregion
|
|
43
43
|
export { useFluidAuth as t };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=use-fluid-auth-
|
|
45
|
+
//# sourceMappingURL=use-fluid-auth-_LboeZI9.mjs.map
|