@fluid-app/fluid-cli-theme-dev 0.1.501 → 0.1.502

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/index.mjs CHANGED
@@ -495,12 +495,13 @@ function parseMemberMetadata(value) {
495
495
  const sites = value.members_sites.map((site) => {
496
496
  if (!isRecord$5(site) || !isId(site.id) || typeof site.name !== "string" || !Array.isArray(site.pages)) throw new MemberPreviewError("Invalid member site metadata.");
497
497
  const pages = site.pages.map((page) => {
498
- if (!isRecord$5(page) || !isId(page.id) || typeof page.title !== "string" || !isProductionPath(page.path) || typeof page.published !== "boolean") throw new MemberPreviewError("Invalid member page metadata.");
498
+ if (!isRecord$5(page) || !isId(page.id) || typeof page.title !== "string" || !isProductionPath(page.path) || typeof page.published !== "boolean" || !(page.template_id === void 0 || page.template_id === null || isId(page.template_id))) throw new MemberPreviewError("Invalid member page metadata.");
499
499
  return {
500
500
  id: page.id,
501
501
  title: page.title,
502
502
  path: accountPath(page.path),
503
- published: page.published
503
+ published: page.published,
504
+ ...page.template_id === void 0 ? {} : { template_id: page.template_id }
504
505
  };
505
506
  });
506
507
  if (new Set(pages.map((p) => p.path)).size !== pages.length) throw new MemberPreviewError("Ambiguous member page paths.");
@@ -2000,7 +2001,41 @@ var MemberPreview = class {
2000
2001
  this.metadata = await this.loadMetadata();
2001
2002
  }
2002
2003
  async loadMetadata() {
2003
- return parseMemberMetadata(await this.api.get("/api/company/members_sites", { application_theme_id: this.theme.id }));
2004
+ const metadata = parseMemberMetadata(await this.api.get("/api/company/members_sites", { application_theme_id: this.theme.id }));
2005
+ const templateNames = metadata.members_sites.some((site) => site.pages.some((page) => isId(page.template_id))) ? await this.memberTemplateNames() : /* @__PURE__ */ new Map();
2006
+ return {
2007
+ ...metadata,
2008
+ members_sites: metadata.members_sites.map((site) => ({
2009
+ ...site,
2010
+ pages: site.pages.map(({ template_id: templateId, ...page }) => {
2011
+ if (templateId === null) return {
2012
+ ...page,
2013
+ template_path: null
2014
+ };
2015
+ const name = templateId === void 0 ? void 0 : templateNames.get(templateId);
2016
+ return name === void 0 ? page : {
2017
+ ...page,
2018
+ template_path: `members_page/${name}/index.liquid`
2019
+ };
2020
+ })
2021
+ }))
2022
+ };
2023
+ }
2024
+ /** Template id → folder name for this theme's member pages. Empty when the lookup fails, so tools fall back to members_sites.json. */
2025
+ async memberTemplateNames() {
2026
+ const names = /* @__PURE__ */ new Map();
2027
+ try {
2028
+ const body = await this.api.get("/api/application_theme_templates", {
2029
+ application_theme_id: this.theme.id,
2030
+ themeable_type: "members_page"
2031
+ });
2032
+ const templates = isRecord$5(body) && Array.isArray(body.templates) ? body.templates : [];
2033
+ for (const template of templates) if (isRecord$5(template) && isId(template.id) && template.application_theme_id === this.theme.id && template.themeable_type === "members_page" && typeof template.name === "string" && /^[^/\\]+$/.test(template.name) && template.name !== "." && template.name !== "..") names.set(template.id, template.name);
2034
+ } catch (error) {
2035
+ const message = error instanceof Error ? error.message : String(error);
2036
+ console.warn(`[Members] Could not read member page templates (${message}); page template paths are left out.`);
2037
+ }
2038
+ return names;
2004
2039
  }
2005
2040
  async getMetadata() {
2006
2041
  if (this.metadata) return this.metadata;