@fluid-app/portal-sdk 0.1.119 → 0.1.120

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