@decocms/blocks-cli 7.77.10 → 7.77.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@decocms/blocks-cli",
3
- "version": "7.77.10",
3
+ "version": "7.77.12",
4
4
  "type": "module",
5
5
  "description": "Deco codegen (generate-blocks, generate-schema, generate-invoke) and Fresh-to-TanStack migration tooling",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "lint:unused": "knip"
34
34
  },
35
35
  "dependencies": {
36
- "@decocms/blocks": "7.77.10",
36
+ "@decocms/blocks": "7.77.12",
37
37
  "ts-morph": "^27.0.0",
38
38
  "tsx": "^4.22.5"
39
39
  },
@@ -409,7 +409,7 @@ describe("readDecofileFromDir — CSV redirects", () => {
409
409
  const { blocks } = readDecofileFromDir(blocksDir, { silent: true });
410
410
  const split = splitExactRedirects(blocks);
411
411
 
412
- expect(split.exact).toEqual([{ path: "/old", to: "/new", status: 301 }]);
412
+ expect(split.exact).toEqual([{ path: "/old", from: "/old", to: "/new", status: 301 }]);
413
413
  expect(JSON.stringify(split.blocks)).not.toContain('"/old"');
414
414
  expect(split.blocks["__csv_redirects__r.csv"]).toMatchObject({ redirects: [{ from: "/g/*" }] });
415
415
  });
@@ -467,7 +467,7 @@ describe("syncRedirectsToKv", () => {
467
467
  return { client: client as unknown as KvRestClient, store };
468
468
  }
469
469
 
470
- const rule = (path: string, to: string, status: 301 | 302 = 301) => ({ path, to, status });
470
+ const rule = (path: string, to: string, status: 301 | 307 = 301) => ({ path, to, status });
471
471
 
472
472
  it("adds new rules under redirect:<id>:<path>", async () => {
473
473
  const { client, store } = makeBulkClient();
@@ -549,3 +549,23 @@ describe("generate-schema default output path (.deco/)", () => {
549
549
  expect(stderr).not.toContain("Generator default output moved");
550
550
  }, 30_000);
551
551
  });
552
+
553
+ describe("typeToJsonSchema with RequestURLParam", () => {
554
+ it("points a RequestURLParam prop at the requestToParam picker", () => {
555
+ const project = strictProject();
556
+ const sf = project.createSourceFile(
557
+ "/props.ts",
558
+ `
559
+ type RequestURLParam = string;
560
+ export interface Props {
561
+ slug?: RequestURLParam;
562
+ plain?: string;
563
+ }
564
+ `,
565
+ );
566
+ const schema = typeToJsonSchema(sf.getInterfaceOrThrow("Props").getType());
567
+ const key = `${Buffer.from("website/functions/requestToParam.ts").toString("base64")}@RequestURLParam`;
568
+ expect(schema.properties.slug).toEqual({ $ref: `#/definitions/${key}`, title: "Slug" });
569
+ expect(schema.properties.plain.type).toBe("string");
570
+ });
571
+ });
@@ -305,6 +305,10 @@ export function applyWidgetFormat(schema: any, typeHint: string): void {
305
305
  const SECTION_REF_DEF_KEY = "__SECTION_REF__";
306
306
  // Well-known definition key for Resolvable (saved blocks picker)
307
307
  const RESOLVABLE_KEY = "Resolvable";
308
+ // Well-known definition key for `RequestURLParam` ("Force param" / "Get params
309
+ // from request parameters"), baked by composeMeta. Same base64 of the function
310
+ // key deco-cx/deco used, with the type name as suffix.
311
+ const REQUEST_URL_PARAM_DEF_KEY = `${toBase64("website/functions/requestToParam.ts")}@RequestURLParam`;
308
312
 
309
313
  /**
310
314
  * Whether a prop annotated `Section` / `Section[]` is the framework's opaque
@@ -691,6 +695,24 @@ export function typeToJsonSchema(type: Type, visited = new Set<string>(), ctx?:
691
695
  continue;
692
696
  }
693
697
 
698
+ // `RequestURLParam` (`@decocms/apps-website/functions/requestToParam`) →
699
+ // the requestToParam picker, as deco-cx/deco emitted it. The alias
700
+ // resolves to `string`, so without this the admin only offered a fixed
701
+ // value and lost "Get params from request parameters".
702
+ const nonNullTypes = propType.isUnion()
703
+ ? propType.getUnionTypes().filter((t) => !t.isNull() && !t.isUndefined())
704
+ : [propType];
705
+ if (baseHint === "RequestURLParam" && nonNullTypes.every((t) => t.isString())) {
706
+ const paramSchema: any = {
707
+ $ref: `#/definitions/${REQUEST_URL_PARAM_DEF_KEY}`,
708
+ title: name.charAt(0).toUpperCase() + name.slice(1),
709
+ };
710
+ applyJsDocToSchema(paramSchema, tags);
711
+ properties[name] = paramSchema;
712
+ if (!prop.isOptional()) required.push(name);
713
+ continue;
714
+ }
715
+
694
716
  // Loader output type → block-ref: emit anyOf [Resolvable, ...matchingLoaders]
695
717
  // baseHint strips "| null | undefined" so "ProductListingPage | null" → "ProductListingPage"
696
718
  if (ctx?.outputTypeToLoaderKeys) {
@@ -83,6 +83,30 @@ describe("buildCsvRedirectBlocks", () => {
83
83
  expect(matchRedirect("/dup", map)).toMatchObject({ to: "/from-cms" });
84
84
  });
85
85
 
86
+ it("carries discardQueryParameters and the loader's forcePermanentRedirects", () => {
87
+ writeCsv("f.csv", "from,to\n/a,/b,true\n/c,/d\n/e,/f,temporary\n");
88
+ const blocks = {
89
+ x: {
90
+ __resolveType: "website/loaders/redirectsFromCsv.ts",
91
+ from: "f.csv",
92
+ forcePermanentRedirects: true,
93
+ },
94
+ };
95
+ const csvBlocks = buildCsvRedirectBlocks(blocks, { blocksDir, silent: true });
96
+ expect(csvBlocks["__csv_redirects__f.csv"]).toEqual({
97
+ __resolveType: "website/loaders/redirects.ts",
98
+ redirects: [
99
+ { from: "/a", to: "/b", type: "permanent", discardQueryParameters: true },
100
+ { from: "/c", to: "/d", type: "permanent" },
101
+ { from: "/e", to: "/f", type: "temporary" },
102
+ ],
103
+ });
104
+ const map = loadRedirects(csvBlocks);
105
+ expect(matchRedirect("/a", map)).toMatchObject({ status: 301, discardQueryParameters: true });
106
+ // Temporary under the default (legacy) semantics.
107
+ expect(matchRedirect("/e", map)).toMatchObject({ status: 302 });
108
+ });
109
+
86
110
  it("returns {} when no CSV loader is referenced", () => {
87
111
  const blocks = { a: { __resolveType: "website/loaders/redirect.ts" } };
88
112
  expect(buildCsvRedirectBlocks(blocks, { blocksDir, silent: true })).toEqual({});
@@ -20,8 +20,11 @@ import { parseRedirectsCsv } from "@decocms/blocks/sdk/redirects";
20
20
  const CSV_REDIRECT_RESOLVE_TYPE = "website/loaders/redirectsFromCsv.ts";
21
21
  const REDIRECTS_RESOLVE_TYPE = "website/loaders/redirects.ts";
22
22
 
23
- /** Recursively collect `from` CSV paths referenced by redirectsFromCsv nodes. */
24
- function collectCsvRefs(node: unknown, out: Set<string>): void {
23
+ /**
24
+ * Recursively collect the CSV paths referenced by redirectsFromCsv nodes, with
25
+ * the loader's `forcePermanentRedirects` flag (true if any referrer sets it).
26
+ */
27
+ function collectCsvRefs(node: unknown, out: Map<string, boolean>): void {
25
28
  if (!node || typeof node !== "object") return;
26
29
  if (Array.isArray(node)) {
27
30
  for (const item of node) collectCsvRefs(item, out);
@@ -29,7 +32,7 @@ function collectCsvRefs(node: unknown, out: Set<string>): void {
29
32
  }
30
33
  const obj = node as Record<string, unknown>;
31
34
  if (obj.__resolveType === CSV_REDIRECT_RESOLVE_TYPE && typeof obj.from === "string") {
32
- out.add(obj.from);
35
+ out.set(obj.from, (out.get(obj.from) ?? false) || obj.forcePermanentRedirects === true);
33
36
  }
34
37
  for (const value of Object.values(obj)) collectCsvRefs(value, out);
35
38
  }
@@ -68,12 +71,12 @@ export function buildCsvRedirectBlocks(
68
71
  const silent = options.silent ?? false;
69
72
  const publicDir = path.resolve(options.blocksDir, "../../public");
70
73
 
71
- const refs = new Set<string>();
74
+ const refs = new Map<string, boolean>();
72
75
  for (const value of Object.values(blocks)) collectCsvRefs(value, refs);
73
76
  if (refs.size === 0) return {};
74
77
 
75
78
  const csvBlocks: Record<string, unknown> = {};
76
- for (const from of refs) {
79
+ for (const [from, forcePermanentRedirects] of refs) {
77
80
  const csvPath = resolveCsvPath(from, publicDir);
78
81
  let csv: string;
79
82
  try {
@@ -87,11 +90,12 @@ export function buildCsvRedirectBlocks(
87
90
 
88
91
  // `loadRedirects` reads `entry.type` ("permanent" | "temporary"), while
89
92
  // `parseRedirectsCsv` returns a numeric `status` — map it back so 301s stay
90
- // 301s (a raw status field would be ignored and default to 302).
91
- const entries = parseRedirectsCsv(csv).map((r) => ({
93
+ // 301s (a raw status field would be ignored and default to 307).
94
+ const entries = parseRedirectsCsv(csv, { forcePermanentRedirects }).map((r) => ({
92
95
  from: r.from,
93
96
  to: r.to,
94
97
  type: r.status === 301 ? "permanent" : "temporary",
98
+ ...(r.discardQueryParameters ? { discardQueryParameters: true } : {}),
95
99
  }));
96
100
 
97
101
  const key = `__csv_redirects__${path.basename(csvPath)}`;
@@ -17,7 +17,7 @@ import {
17
17
  revisionKey,
18
18
  snapshotKey,
19
19
  } from "@decocms/blocks/cms";
20
- import type { ExactRedirect } from "@decocms/blocks/sdk/redirects";
20
+ import { type ExactRedirect, storedExactRedirectValue } from "@decocms/blocks/sdk/redirects";
21
21
  import type { KvRestClient } from "./cf-kv-rest";
22
22
 
23
23
  export interface Snapshot {
@@ -94,7 +94,7 @@ export async function syncRedirectsToKv(
94
94
  id: string,
95
95
  ): Promise<{ written: number; deleted: number }> {
96
96
  const desired = new Map(
97
- redirects.map((r) => [redirectKey(id, r.path), JSON.stringify({ to: r.to, status: r.status })]),
97
+ redirects.map((r) => [redirectKey(id, r.path), JSON.stringify(storedExactRedirectValue(r))]),
98
98
  );
99
99
 
100
100
  const existing = await client.list(redirectPrefix(id));