@fluid-app/portal-sdk 0.1.119 → 0.1.121
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/{MySiteScreen-BvLsBrYD.mjs → MySiteScreen-B5qaPzcW.mjs} +325 -14
- package/dist/MySiteScreen-B5qaPzcW.mjs.map +1 -0
- package/dist/{MySiteScreen-BzO3lthV.cjs → MySiteScreen-BJqtmerU.cjs} +1 -1
- package/dist/{MySiteScreen-DTW2mzIG.cjs → MySiteScreen-DVZ7OKLP.cjs} +325 -14
- package/dist/MySiteScreen-DVZ7OKLP.cjs.map +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +3 -3
- package/package.json +12 -11
- package/dist/MySiteScreen-BvLsBrYD.mjs.map +0 -1
- package/dist/MySiteScreen-DTW2mzIG.cjs.map +0 -1
|
@@ -10,28 +10,337 @@ let _tanstack_react_query = require("@tanstack/react-query");
|
|
|
10
10
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
11
|
let zod = require("zod");
|
|
12
12
|
let lucide_react = require("lucide-react");
|
|
13
|
-
//#region
|
|
13
|
+
//#region ../../api-clients/portal-tenant-mysite/src/namespaces/portal_tenant_mysite.ts
|
|
14
14
|
/**
|
|
15
|
-
*
|
|
15
|
+
* Get MySite profile for the current user
|
|
16
|
+
* Returns the member's MySite profile.
|
|
16
17
|
*
|
|
17
|
-
*
|
|
18
|
-
|
|
18
|
+
* @param client - Fetch client instance
|
|
19
|
+
|
|
20
|
+
*/
|
|
21
|
+
async function mysite_profile_show(client) {
|
|
22
|
+
return client.get(`/api/mysite/profile`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Update MySite profile
|
|
26
|
+
* Updates the member's MySite profile fields.
|
|
27
|
+
*
|
|
28
|
+
* @param client - Fetch client instance
|
|
29
|
+
* @param body - body
|
|
30
|
+
*/
|
|
31
|
+
async function mysite_profile_update(client, body) {
|
|
32
|
+
return client.put(`/api/mysite/profile`, body);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* List available MySite themes
|
|
36
|
+
* Returns available MySite themes.
|
|
37
|
+
*
|
|
38
|
+
* @param client - Fetch client instance
|
|
39
|
+
* @param [params] - params
|
|
40
|
+
*/
|
|
41
|
+
async function mysite_themes_list(client, params) {
|
|
42
|
+
return client.get(`/api/mysite/themes`, params);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Update MySite settings
|
|
46
|
+
* Updates the member's MySite settings.
|
|
47
|
+
*
|
|
48
|
+
* @param client - Fetch client instance
|
|
49
|
+
* @param body - body
|
|
50
|
+
*/
|
|
51
|
+
async function mysite_settings_update(client, body) {
|
|
52
|
+
return client.put(`/api/mysite/settings`, body);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* List MySite links for the current user
|
|
56
|
+
* Returns the member's MySite links, ordered by position.
|
|
57
|
+
*
|
|
58
|
+
* @param client - Fetch client instance
|
|
59
|
+
* @param [params] - params
|
|
60
|
+
*/
|
|
61
|
+
async function mysite_links_list(client, params) {
|
|
62
|
+
return client.get(`/api/mysite/links`, params);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Create a MySite link
|
|
66
|
+
* Adds a new link to the member's MySite.
|
|
67
|
+
*
|
|
68
|
+
* @param client - Fetch client instance
|
|
69
|
+
* @param body - body
|
|
70
|
+
*/
|
|
71
|
+
async function mysite_links_create(client, body) {
|
|
72
|
+
return client.post(`/api/mysite/links`, body);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Update a MySite link
|
|
76
|
+
* Updates an existing MySite link.
|
|
77
|
+
*
|
|
78
|
+
* @param client - Fetch client instance
|
|
79
|
+
* @param id - id
|
|
80
|
+
* @param body - body
|
|
81
|
+
*/
|
|
82
|
+
async function mysite_links_update(client, id, body) {
|
|
83
|
+
return client.put(`/api/mysite/links/${id}`, body);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Delete a MySite link
|
|
87
|
+
* Removes a link from the member's MySite.
|
|
88
|
+
*
|
|
89
|
+
* @param client - Fetch client instance
|
|
90
|
+
* @param id - id
|
|
91
|
+
*/
|
|
92
|
+
async function mysite_links_destroy(client, id) {
|
|
93
|
+
return client.delete(`/api/mysite/links/${id}`);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Reorder MySite links
|
|
97
|
+
* Reorders MySite links by providing an ordered list of IDs.
|
|
98
|
+
*
|
|
99
|
+
* @param client - Fetch client instance
|
|
100
|
+
* @param body - body
|
|
101
|
+
*/
|
|
102
|
+
async function mysite_links_bulk_reorder(client, body) {
|
|
103
|
+
return client.patch(`/api/mysite/links/bulk`, body);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* List MySite favorite products
|
|
107
|
+
* Returns the member's MySite favorite products.
|
|
108
|
+
*
|
|
109
|
+
* @param client - Fetch client instance
|
|
110
|
+
* @param [params] - params
|
|
111
|
+
*/
|
|
112
|
+
async function mysite_favorites_list(client, params) {
|
|
113
|
+
return client.get(`/api/mysite/favorites`, params);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Add a product to MySite favorites
|
|
117
|
+
* Adds a product to the member's MySite favorites.
|
|
118
|
+
*
|
|
119
|
+
* @param client - Fetch client instance
|
|
120
|
+
* @param body - body
|
|
121
|
+
*/
|
|
122
|
+
async function mysite_favorites_create(client, body) {
|
|
123
|
+
return client.post(`/api/mysite/favorites`, body);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Remove a product from MySite favorites
|
|
127
|
+
* Removes a product from the member's MySite favorites.
|
|
128
|
+
*
|
|
129
|
+
* @param client - Fetch client instance
|
|
130
|
+
* @param id - id
|
|
131
|
+
*/
|
|
132
|
+
async function mysite_favorites_destroy(client, id) {
|
|
133
|
+
return client.delete(`/api/mysite/favorites/${id}`);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Reorder MySite favorites
|
|
137
|
+
* Reorders MySite favorites by providing an ordered list of IDs.
|
|
138
|
+
*
|
|
139
|
+
* @param client - Fetch client instance
|
|
140
|
+
* @param body - body
|
|
141
|
+
*/
|
|
142
|
+
async function mysite_favorites_bulk_reorder(client, body) {
|
|
143
|
+
return client.patch(`/api/mysite/favorites/bulk`, body);
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
146
|
+
//#region src/mysite/create-portal-mysite-adapter.ts
|
|
147
|
+
/**
|
|
148
|
+
* BFF MySiteProfile → old /me.json MeProfile shape.
|
|
149
|
+
* Fields not available in the BFF (views, leads, affiliate_id) are zeroed out.
|
|
150
|
+
*/
|
|
151
|
+
function mapProfileToMe(profile) {
|
|
152
|
+
return {
|
|
153
|
+
id: profile.id,
|
|
154
|
+
affiliate_id: null,
|
|
155
|
+
company: null,
|
|
156
|
+
mysite_url: profile.mysite_url ?? null,
|
|
157
|
+
mysite_views: 0,
|
|
158
|
+
mysite_leads: 0,
|
|
159
|
+
mysite_theme_id: profile.theme_id ?? null,
|
|
160
|
+
mysite_theme: null,
|
|
161
|
+
bio: profile.bio ?? null,
|
|
162
|
+
facebook: null,
|
|
163
|
+
instagram: null,
|
|
164
|
+
twitter: null,
|
|
165
|
+
youtube: null,
|
|
166
|
+
pinterest: null,
|
|
167
|
+
tiktok: null,
|
|
168
|
+
linkedin: null,
|
|
169
|
+
whatsapp: null,
|
|
170
|
+
wechat: null
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** BFF Link → old MySiteLink shape (must pass Zod: { id, url, text, order, clicks? }) */
|
|
174
|
+
function mapBffLink(link) {
|
|
175
|
+
return {
|
|
176
|
+
id: link.id,
|
|
177
|
+
url: link.url ?? "",
|
|
178
|
+
text: link.title ?? "",
|
|
179
|
+
order: link.position ?? 0,
|
|
180
|
+
clicks: 0
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/** BFF Favorite → old MySiteFavorite shape (must pass Zod favoriteSchema) */
|
|
184
|
+
function mapBffFavorite(fav) {
|
|
185
|
+
return {
|
|
186
|
+
id: fav.id,
|
|
187
|
+
favoriteable_id: fav.product_id,
|
|
188
|
+
favoriteable_type: "Product",
|
|
189
|
+
order: fav.position ?? 0,
|
|
190
|
+
user_company_id: void 0,
|
|
191
|
+
created_at: fav.created_at,
|
|
192
|
+
favoriteable: {
|
|
193
|
+
id: fav.product_id,
|
|
194
|
+
title: fav.product_name ?? null,
|
|
195
|
+
name: fav.product_name ?? null,
|
|
196
|
+
image_url: fav.product_image_url ?? null,
|
|
197
|
+
type: "Product"
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
/** BFF Theme → old MysiteTheme shape (must pass Zod themeSchema) */
|
|
202
|
+
function mapBffTheme(theme) {
|
|
203
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
204
|
+
return {
|
|
205
|
+
id: theme.id,
|
|
206
|
+
name: theme.name ?? "Untitled",
|
|
207
|
+
description: null,
|
|
208
|
+
public: true,
|
|
209
|
+
company_id: null,
|
|
210
|
+
created_at: now,
|
|
211
|
+
updated_at: now,
|
|
212
|
+
image_url: theme.preview_url ?? null,
|
|
213
|
+
application_theme_template_id: null
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
const LINKS_LIST = /^\/users\/\d+\/links\.json$/;
|
|
217
|
+
const LINK_SINGLE = /^\/users\/\d+\/links\/(\d+)\.json$/;
|
|
218
|
+
const LINKS_REORDER = /^\/users\/\d+\/links\/bulk_reorder\.json$/;
|
|
219
|
+
const FAVORITES_LIST = /^\/user_companies\/\d+\/favorites\.json$/;
|
|
220
|
+
const FAVORITE_SINGLE = /^\/user_companies\/\d+\/favorites\/(\d+)\.json$/;
|
|
221
|
+
const FAVORITES_REORDER = /^\/user_companies\/\d+\/favorites\/bulk_reorder\.json$/;
|
|
222
|
+
/**
|
|
223
|
+
* Creates a FetchClient adapter that translates legacy mysite API calls
|
|
224
|
+
* to portal-tenant MySite BFF endpoints.
|
|
225
|
+
*
|
|
226
|
+
* @param bffClient - A FetchClient pointed at the tenant BFF origin
|
|
227
|
+
* (e.g. https://acme.portal.fluid.app, **without** /api suffix — the
|
|
228
|
+
* generated namespace functions already include /api/mysite/... paths).
|
|
229
|
+
*/
|
|
230
|
+
function createPortalMySiteAdapter(bffClient) {
|
|
231
|
+
async function get(endpoint, params, options) {
|
|
232
|
+
if (endpoint === "/me.json") return mapProfileToMe((await mysite_profile_show(bffClient)).profile ?? {});
|
|
233
|
+
if (endpoint === "/mysite/themes") return ((await mysite_themes_list(bffClient)).themes ?? []).map(mapBffTheme);
|
|
234
|
+
if (LINKS_LIST.test(endpoint)) return ((await mysite_links_list(bffClient)).links ?? []).map(mapBffLink);
|
|
235
|
+
if (FAVORITES_LIST.test(endpoint)) return ((await mysite_favorites_list(bffClient)).favorites ?? []).map(mapBffFavorite);
|
|
236
|
+
return bffClient.get(endpoint, params, options);
|
|
237
|
+
}
|
|
238
|
+
async function post(endpoint, body, options) {
|
|
239
|
+
if (LINKS_LIST.test(endpoint)) {
|
|
240
|
+
const b = body;
|
|
241
|
+
return mapBffLink((await mysite_links_create(bffClient, { link: {
|
|
242
|
+
title: b?.text ?? "",
|
|
243
|
+
url: b?.url ?? ""
|
|
244
|
+
} })).link ?? {});
|
|
245
|
+
}
|
|
246
|
+
if (FAVORITES_LIST.test(endpoint)) return mapBffFavorite((await mysite_favorites_create(bffClient, { favorite: { product_id: body?.favorite?.favoriteable_id ?? 0 } })).favorite ?? {});
|
|
247
|
+
return bffClient.post(endpoint, body, options);
|
|
248
|
+
}
|
|
249
|
+
async function put(endpoint, body, options) {
|
|
250
|
+
if (endpoint === "/me.json") {
|
|
251
|
+
const b = body;
|
|
252
|
+
return mapProfileToMe((await mysite_profile_update(bffClient, { profile: {
|
|
253
|
+
display_name: b?.display_name ?? void 0,
|
|
254
|
+
bio: b?.bio ?? void 0,
|
|
255
|
+
avatar_url: b?.image_url ?? b?.avatar_url ?? void 0
|
|
256
|
+
} })).profile ?? {});
|
|
257
|
+
}
|
|
258
|
+
if (endpoint === "/mysite.json") {
|
|
259
|
+
const uc = body?.user_company;
|
|
260
|
+
if (uc?.theme_id !== void 0) return {
|
|
261
|
+
id: 0,
|
|
262
|
+
...(await mysite_settings_update(bffClient, { settings: { theme_id: uc.theme_id } })).settings ?? {}
|
|
263
|
+
};
|
|
264
|
+
if (uc?.username !== void 0) {
|
|
265
|
+
const profile = (await mysite_profile_update(bffClient, { profile: { slug: uc.username } })).profile ?? {};
|
|
266
|
+
return {
|
|
267
|
+
id: profile.id ?? 0,
|
|
268
|
+
...profile
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
return { id: 0 };
|
|
272
|
+
}
|
|
273
|
+
const linkMatch = endpoint.match(LINK_SINGLE);
|
|
274
|
+
if (linkMatch) {
|
|
275
|
+
const linkId = Number(linkMatch[1]);
|
|
276
|
+
const b = body;
|
|
277
|
+
return mapBffLink((await mysite_links_update(bffClient, linkId, { link: {
|
|
278
|
+
title: b?.text,
|
|
279
|
+
url: b?.url
|
|
280
|
+
} })).link ?? {});
|
|
281
|
+
}
|
|
282
|
+
return bffClient.put(endpoint, body, options);
|
|
283
|
+
}
|
|
284
|
+
async function patch(endpoint, body, options) {
|
|
285
|
+
if (LINKS_REORDER.test(endpoint)) {
|
|
286
|
+
const items = body?.links ?? [];
|
|
287
|
+
if (items.length === 0) return [];
|
|
288
|
+
return ((await mysite_links_bulk_reorder(bffClient, { ordered_ids: [...items].sort((a, b2) => a.order - b2.order).map((l) => l.id) })).links ?? []).map(mapBffLink);
|
|
289
|
+
}
|
|
290
|
+
if (FAVORITES_REORDER.test(endpoint)) {
|
|
291
|
+
const items = body?.favorites ?? [];
|
|
292
|
+
if (items.length === 0) return [];
|
|
293
|
+
return ((await mysite_favorites_bulk_reorder(bffClient, { ordered_ids: [...items].sort((a, b2) => a.order - b2.order).map((f) => f.id) })).favorites ?? []).map(mapBffFavorite);
|
|
294
|
+
}
|
|
295
|
+
return bffClient.patch(endpoint, body, options);
|
|
296
|
+
}
|
|
297
|
+
async function del(endpoint, options) {
|
|
298
|
+
const linkMatch = endpoint.match(LINK_SINGLE);
|
|
299
|
+
if (linkMatch) return mysite_links_destroy(bffClient, Number(linkMatch[1]));
|
|
300
|
+
const favMatch = endpoint.match(FAVORITE_SINGLE);
|
|
301
|
+
if (favMatch) return mysite_favorites_destroy(bffClient, Number(favMatch[1]));
|
|
302
|
+
return bffClient.delete(endpoint, options);
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
request: bffClient.request,
|
|
306
|
+
requestWithFormData: bffClient.requestWithFormData,
|
|
307
|
+
get,
|
|
308
|
+
post,
|
|
309
|
+
put,
|
|
310
|
+
patch,
|
|
311
|
+
delete: del
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
//#endregion
|
|
315
|
+
//#region src/mysite/use-portal-mysite-client.ts
|
|
316
|
+
/**
|
|
317
|
+
* Hook that returns a FetchClient adapter translating legacy mysite API
|
|
318
|
+
* calls to the portal-tenant MySite BFF.
|
|
319
|
+
*
|
|
320
|
+
* The adapter wraps a raw BFF FetchClient so that existing mysite-ui hooks
|
|
321
|
+
* and components (which call `/me.json`, `/users/{id}/links.json`, etc.)
|
|
322
|
+
* work transparently against the BFF endpoints.
|
|
19
323
|
*/
|
|
20
|
-
function
|
|
324
|
+
function usePortalMySiteClient() {
|
|
21
325
|
const { config } = require_FluidProvider.useFluidContext();
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
326
|
+
return (0, react.useMemo)(() => {
|
|
327
|
+
const baseUrl = config.baseUrl.replace(/\/+$/, "").replace(/\/api$/, "");
|
|
328
|
+
const csrfToken = typeof document !== "undefined" ? document.querySelector("meta[name=\"csrf-token\"]")?.getAttribute("content") : null;
|
|
329
|
+
return createPortalMySiteAdapter(require_FluidProvider.createFetchClient({
|
|
330
|
+
baseUrl,
|
|
25
331
|
getAuthToken: config.getAuthToken,
|
|
26
332
|
onAuthError: config.onAuthError,
|
|
27
|
-
defaultHeaders:
|
|
28
|
-
|
|
333
|
+
defaultHeaders: {
|
|
334
|
+
...config.defaultHeaders,
|
|
335
|
+
...csrfToken ? { "X-CSRF-Token": csrfToken } : {}
|
|
336
|
+
}
|
|
337
|
+
}));
|
|
29
338
|
}, [
|
|
30
339
|
config.baseUrl,
|
|
31
340
|
config.getAuthToken,
|
|
32
341
|
config.onAuthError,
|
|
33
342
|
config.defaultHeaders
|
|
34
|
-
])
|
|
343
|
+
]);
|
|
35
344
|
}
|
|
36
345
|
//#endregion
|
|
37
346
|
//#region ../../mysite/ui/src/shared/query-keys.ts
|
|
@@ -1557,6 +1866,7 @@ function MySiteMainView({ client }) {
|
|
|
1557
1866
|
queryKey: ["sdk-mysite", "me"],
|
|
1558
1867
|
queryFn: () => client.get("/me.json")
|
|
1559
1868
|
});
|
|
1869
|
+
const queryClient = (0, _tanstack_react_query.useQueryClient)();
|
|
1560
1870
|
const { data: themes = [] } = useMySiteThemes(client);
|
|
1561
1871
|
const updateMySiteMutation = useUpdateMySite(client);
|
|
1562
1872
|
const [previewKey, setPreviewKey] = (0, react.useState)(0);
|
|
@@ -1595,7 +1905,8 @@ function MySiteMainView({ client }) {
|
|
|
1595
1905
|
onError: () => reject(/* @__PURE__ */ new Error("Failed"))
|
|
1596
1906
|
});
|
|
1597
1907
|
});
|
|
1598
|
-
|
|
1908
|
+
await queryClient.refetchQueries({ queryKey: ["sdk-mysite", "me"] });
|
|
1909
|
+
}, [updateMySiteMutation, queryClient]);
|
|
1599
1910
|
const handleEditSection = (0, react.useCallback)((section) => {
|
|
1600
1911
|
cancelScheduled();
|
|
1601
1912
|
setEditingSection(section);
|
|
@@ -1756,7 +2067,7 @@ function MySiteProfileView({ client }) {
|
|
|
1756
2067
|
//#endregion
|
|
1757
2068
|
//#region src/screens/MySiteScreen/index.tsx
|
|
1758
2069
|
function MySiteScreen({ background, textColor, accentColor, padding, borderRadius, ...divProps }) {
|
|
1759
|
-
const
|
|
2070
|
+
const client = usePortalMySiteClient();
|
|
1760
2071
|
const { currentSlug, navigate } = require_AppNavigationContext.useAppNavigation();
|
|
1761
2072
|
const isProfileView = (currentSlug.split("/")[1] ?? null) === "profile";
|
|
1762
2073
|
require_ScreenHeaderContext.useScreenHeaderBreadcrumbs((0, react.useMemo)(() => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_src.Breadcrumb, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(require_src.BreadcrumbList, {
|
|
@@ -1805,4 +2116,4 @@ Object.defineProperty(exports, "mySiteScreenPropertySchema", {
|
|
|
1805
2116
|
}
|
|
1806
2117
|
});
|
|
1807
2118
|
|
|
1808
|
-
//# sourceMappingURL=MySiteScreen-
|
|
2119
|
+
//# sourceMappingURL=MySiteScreen-DVZ7OKLP.cjs.map
|