@coraltravelcenter/b2c-landing-builder 2.6.1 → 2.6.3

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@coraltravelcenter/b2c-landing-builder",
3
- "version": "2.6.1",
3
+ "version": "2.6.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@coraltravelcenter/b2c-landing-builder",
9
- "version": "2.6.1",
9
+ "version": "2.6.3",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@clack/prompts": "1.7.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coraltravelcenter/b2c-landing-builder",
3
- "version": "2.6.1",
3
+ "version": "2.6.3",
4
4
  "description": "CLI and build toolkit for B2C landing projects",
5
5
  "type": "module",
6
6
  "bin": {
@@ -9,19 +9,40 @@ export async function uploadChangedAssets({
9
9
  state,
10
10
  root = process.cwd(),
11
11
  uploadFile,
12
+ listFiles,
12
13
  remoteRoot = "/content",
13
14
  concurrency = 5,
14
15
  }) {
15
16
  const pending = changedAssets(manifest, state);
16
17
  const assets = {...state.assets};
17
18
  const uploaded = [];
19
+ const skipped = [];
20
+ const remoteDirectories = new Map();
18
21
  let cursor = 0;
19
22
 
23
+ const namesInRemoteDirectory = (remoteDirectory) => {
24
+ if (!remoteDirectories.has(remoteDirectory)) {
25
+ remoteDirectories.set(remoteDirectory, Promise.resolve(listFiles(remoteDirectory)).then((listing) => {
26
+ const files = Array.isArray(listing) ? listing : listing?.files || [];
27
+ return new Set(files.map((file) => typeof file === "string" ? path.posix.basename(file) : file.name));
28
+ }));
29
+ }
30
+ return remoteDirectories.get(remoteDirectory);
31
+ };
32
+
20
33
  async function worker() {
21
34
  while (cursor < pending.length) {
22
35
  const asset = pending[cursor++];
23
36
  const localPath = path.join(root, ...(manifest.assetsDirectory || "public").split("/"), ...asset.path.split("/"));
24
37
  const remotePath = path.posix.join("/", remoteRoot, manifest.assetsPrefix, asset.path);
38
+ if (listFiles) {
39
+ const names = await namesInRemoteDirectory(path.posix.dirname(remotePath));
40
+ if (names.has(path.posix.basename(remotePath))) {
41
+ assets[asset.path] = {...asset, immutable: true};
42
+ skipped.push(asset.path);
43
+ continue;
44
+ }
45
+ }
25
46
  const result = await uploadFile(remotePath, localPath);
26
47
  assets[asset.path] = {...asset, url: result?.files?.[0]?.url};
27
48
  uploaded.push(asset.path);
@@ -33,6 +54,7 @@ export async function uploadChangedAssets({
33
54
  return {
34
55
  state: {...state, assets},
35
56
  uploaded: uploaded.sort(),
57
+ skipped: skipped.sort(),
36
58
  unchanged: manifest.assets.length - pending.length,
37
59
  };
38
60
  }
@@ -90,6 +90,9 @@ export class BackofficeClient {
90
90
  }
91
91
 
92
92
  reorderWidget(contentWidgetId, order) {
93
+ if (!Number.isInteger(order) || order < 1) {
94
+ throw new Error(`Widget order must be a positive integer, received: ${order}`);
95
+ }
93
96
  return this.request("PUT", "/Content/Widget/ChangeOrder", {body: {contentWidgetId, order}});
94
97
  }
95
98
 
@@ -97,10 +100,17 @@ export class BackofficeClient {
97
100
  return this.request("PUT", "/Content/UpdateDocumentStatus", {body: {pageContentId, documentStatus}});
98
101
  }
99
102
 
103
+ async listFiles(remoteDirectory) {
104
+ const result = await this.request("GET", "/FileManagement/ListFiles", {
105
+ query: {path: remoteDirectory.replace(/^\/+/, "")},
106
+ });
107
+ return result?.result || result;
108
+ }
109
+
100
110
  async uploadFile(remotePath, localPath) {
101
111
  const parsed = path.posix.parse(remotePath);
102
112
  const form = new FormData();
103
- form.append("Body.OverWrite", "true");
113
+ form.append("Body.OverWrite", "false");
104
114
  form.append("Body.Path", parsed.dir.replace(/^\/+/, ""));
105
115
  form.append("Body.Files", new Blob([fs.readFileSync(localPath)]), parsed.base);
106
116
  const result = await this.request("POST", "/FileManagement/UploadFile", {form});
@@ -30,9 +30,13 @@ export async function deployAssetsOnly({
30
30
  root,
31
31
  remoteRoot: new URL(preset.assetsBase).pathname,
32
32
  uploadFile: api.uploadFile.bind(api),
33
+ listFiles: api.listFiles?.bind(api),
33
34
  });
34
35
  writeDeploymentState(preset.id, manifest.folder, result.state, root);
35
- log(`[deploy] assets: uploaded=${result.uploaded.length}, unchanged=${result.unchanged}`);
36
+ log(`[deploy] assets: uploaded=${result.uploaded.length}, skipped=${result.skipped.length}, unchanged=${result.unchanged}`);
37
+ if (result.skipped.length) {
38
+ log(`[deploy] existing assets were not overwritten: ${result.skipped.join(", ")}. Rename changed files to publish new URLs.`);
39
+ }
36
40
  return {...result, target: String(cdnUrl)};
37
41
  }
38
42
 
@@ -56,6 +60,7 @@ export async function deployProject({
56
60
  root,
57
61
  remoteRoot: new URL(preset.assetsBase).pathname,
58
62
  uploadFile: api.uploadFile.bind(api),
63
+ listFiles: api.listFiles?.bind(api),
59
64
  });
60
65
  const page = previous.placement
61
66
  ? await prepareExistingPage({client: api, placement: previous.placement, update})
@@ -72,7 +77,10 @@ export async function deployProject({
72
77
  const preview = page.pageContent.uniqueId
73
78
  ? `https://${preset.domain}/preview/${page.pageContent.uniqueId}/`
74
79
  : null;
75
- log(`[deploy] assets: uploaded=${assets.uploaded.length}, unchanged=${assets.unchanged}`);
80
+ log(`[deploy] assets: uploaded=${assets.uploaded.length}, skipped=${assets.skipped.length}, unchanged=${assets.unchanged}`);
81
+ if (assets.skipped.length) {
82
+ log(`[deploy] existing assets were not overwritten: ${assets.skipped.join(", ")}. Rename changed files to publish new URLs.`);
83
+ }
76
84
  log(`[deploy] widgets: added=${widgets.added}, updated=${widgets.updated}, removed=${widgets.removed}`);
77
85
  if (preview) log(`[deploy] preview: ${preview}`);
78
86
  return {assets, widgets, placement: page.placement, preview};
@@ -1,11 +1,29 @@
1
1
  import {HTML_WIDGET_ID, STATUS} from "./backoffice-client.mjs";
2
2
 
3
3
  function suitableAreas(scheme) {
4
- return scheme.flatMap((row) => row.children || []).filter((column) =>
5
- column.usableWidgets?.some((widget) => widget.widgetId === HTML_WIDGET_ID)
4
+ return scheme.flatMap((row, rowIndex) => (row.children || []).map((column, columnIndex) => ({
5
+ area: column,
6
+ rowIndex,
7
+ columnIndex,
8
+ }))).filter(({area}) =>
9
+ area.usableWidgets?.some((widget) => widget.widgetId === HTML_WIDGET_ID)
6
10
  );
7
11
  }
8
12
 
13
+ function widgetNames(area) {
14
+ return (area.usedWidgets || []).map((widget, index) =>
15
+ widget.widgetName || widget.cmsTitle || widget.name || `widget ${index + 1}`
16
+ );
17
+ }
18
+
19
+ function areaLabel({area, rowIndex, columnIndex}) {
20
+ const name = area.name || area.title || "HTML area";
21
+ const width = area.breakPoint?.xxl ? `, width ${area.breakPoint.xxl}/12` : "";
22
+ const contents = widgetNames(area);
23
+ const summary = contents.length ? contents.join(" → ") : "empty";
24
+ return `Row ${rowIndex + 1}, column ${columnIndex + 1}${width}: ${name} — ${summary}`;
25
+ }
26
+
9
27
  async function defaultPrompts() {
10
28
  const {isCancel, select, text} = await import("@clack/prompts");
11
29
  const answer = async (promise) => {
@@ -51,19 +69,23 @@ export async function createPagePlacement({client, manifest, prompts}) {
51
69
  });
52
70
  const selected = choices.find(({layout}) => layout.layoutId === layoutId);
53
71
  const layoutAreaId = await prompts.select({
54
- message: "HTML widget area",
55
- options: selected.areas.map((area, index) => ({
56
- label: area.name || area.title || `Area ${index + 1}`,
57
- value: area.layoutAreaId || area.id,
72
+ message: "Where on the layout should the landing blocks go?",
73
+ options: selected.areas.map((descriptor) => ({
74
+ label: areaLabel(descriptor),
75
+ value: descriptor.area.layoutAreaId || descriptor.area.id,
58
76
  })),
59
77
  });
60
- const area = selected.areas.find((candidate) => (candidate.layoutAreaId || candidate.id) === layoutAreaId);
61
- const count = area.usedWidgets?.length || 0;
78
+ const area = selected.areas.find(({area: candidate}) =>
79
+ (candidate.layoutAreaId || candidate.id) === layoutAreaId
80
+ ).area;
81
+ const names = widgetNames(area);
62
82
  const orderIndex = await prompts.select({
63
- message: "Insert blocks after position",
64
- options: Array.from({length: count + 1}, (_, index) => ({
65
- label: index === 0 ? "At the beginning" : `After widget ${index}`,
66
- value: index - 1,
83
+ message: "Exact insertion point",
84
+ options: Array.from({length: names.length + 1}, (_, index) => ({
85
+ label: index === 0
86
+ ? names.length ? `At the beginning, before “${names[0]}”` : "Into the empty area"
87
+ : `After “${names[index - 1]}”`,
88
+ value: index,
67
89
  })),
68
90
  });
69
91
  const created = await client.createPage({applicationId, layoutId, name: pageName.trim()});
@@ -50,7 +50,7 @@ export async function syncWidgets({client, manifest, placement, pageContent, roo
50
50
  added += 1;
51
51
  }
52
52
  activeIds.add(widget.contentWidgetId);
53
- const desiredOrder = placement.orderIndex + 1 + index;
53
+ const desiredOrder = Math.max(0, placement.orderIndex) + 1 + index;
54
54
  if (widget.order !== desiredOrder) {
55
55
  await client.reorderWidget(widget.contentWidgetId, desiredOrder);
56
56
  reordered += 1;