@norskvideo/ctl-product-template-schema 0.1.89 → 0.1.90
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/index.d.ts +0 -3
- package/index.js +8 -11
- package/package.json +1 -1
- package/params.d.ts +6 -5
- package/params.js +13 -9
- package/secret-references.d.ts +4 -4
- package/secret-references.js +5 -5
package/index.d.ts
CHANGED
|
@@ -509,7 +509,6 @@ export declare const ProductTemplateParameterSchema: z.ZodObject<{
|
|
|
509
509
|
boolean: "boolean";
|
|
510
510
|
int: "int";
|
|
511
511
|
enum: "enum";
|
|
512
|
-
json: "json";
|
|
513
512
|
}>>;
|
|
514
513
|
default: z.ZodOptional<z.ZodString>;
|
|
515
514
|
secret: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -536,7 +535,6 @@ export declare const ParametersFileSchema: z.ZodObject<{
|
|
|
536
535
|
boolean: "boolean";
|
|
537
536
|
int: "int";
|
|
538
537
|
enum: "enum";
|
|
539
|
-
json: "json";
|
|
540
538
|
}>>;
|
|
541
539
|
default: z.ZodOptional<z.ZodString>;
|
|
542
540
|
secret: z.ZodOptional<z.ZodBoolean>;
|
|
@@ -824,7 +822,6 @@ export declare const ProductTemplateMaterialsSchema: z.ZodObject<{
|
|
|
824
822
|
boolean: "boolean";
|
|
825
823
|
int: "int";
|
|
826
824
|
enum: "enum";
|
|
827
|
-
json: "json";
|
|
828
825
|
}>>;
|
|
829
826
|
default: z.ZodOptional<z.ZodString>;
|
|
830
827
|
secret: z.ZodOptional<z.ZodBoolean>;
|
package/index.js
CHANGED
|
@@ -603,7 +603,7 @@ export const STANDARD_ADVANCED_OVERRIDES = {
|
|
|
603
603
|
containerUser: {},
|
|
604
604
|
publicHost: {},
|
|
605
605
|
};
|
|
606
|
-
// The shape of a
|
|
606
|
+
// The shape of a structured parameter's value: a small subset of JSON Schema
|
|
607
607
|
// (params.ts `JsonParamSchema`, which every form and the runner validate
|
|
608
608
|
// against). `secret` on a string is ours: the field is masked in reads,
|
|
609
609
|
// rendered as a password input, and may hold a `secretref:`.
|
|
@@ -663,7 +663,7 @@ export const ProductTemplateParameterSchema = z
|
|
|
663
663
|
.object({
|
|
664
664
|
name: z.string().regex(/^[A-Z][A-Z0-9_]*$/, "env var name; uppercase, digits, underscores"),
|
|
665
665
|
purpose: z.string(),
|
|
666
|
-
type: z.enum(["string", "int", "number", "boolean", "enum"
|
|
666
|
+
type: z.enum(["string", "int", "number", "boolean", "enum"]).default("string"),
|
|
667
667
|
default: z.string().optional().meta({ description: "Stringified default (even for numeric/boolean/enum types)" }),
|
|
668
668
|
secret: z.boolean().optional(),
|
|
669
669
|
deliver: z.enum(["value", "reference"]).optional().meta({
|
|
@@ -678,7 +678,7 @@ export const ProductTemplateParameterSchema = z
|
|
|
678
678
|
/** Allowed values for `enum` parameters (rendered as a dropdown). */
|
|
679
679
|
values: z.array(z.string()).optional(),
|
|
680
680
|
schema: JsonParamSchemaSchema.optional().meta({
|
|
681
|
-
description: "
|
|
681
|
+
description: "For a `string` parameter whose value is JSON: its shape (a JSON Schema subset), which a form renders and every surface validates. The value is still one environment variable holding the JSON text. Additive: a runner that predates it ignores the key and takes the text as it is.",
|
|
682
682
|
}),
|
|
683
683
|
// Display metadata for a form built from the template. Declaration order is
|
|
684
684
|
// display order, so there is no `order` field to disagree with it.
|
|
@@ -709,24 +709,21 @@ export const ProductTemplateParameterSchema = z
|
|
|
709
709
|
if ((p.min !== undefined || p.max !== undefined) && p.type !== "int" && p.type !== "number") {
|
|
710
710
|
ctx.addIssue({ code: "custom", path: ["min"], message: "`min`/`max` are only valid for int/number parameters" });
|
|
711
711
|
}
|
|
712
|
-
if (p.
|
|
713
|
-
if (
|
|
714
|
-
ctx.addIssue({ code: "custom", path: ["schema"], message: "
|
|
712
|
+
if (p.schema !== undefined) {
|
|
713
|
+
if (p.type !== "string")
|
|
714
|
+
ctx.addIssue({ code: "custom", path: ["schema"], message: "`schema` is only valid for string parameters" });
|
|
715
715
|
if (p.secret === true)
|
|
716
716
|
ctx.addIssue({
|
|
717
717
|
code: "custom",
|
|
718
718
|
path: ["secret"],
|
|
719
|
-
message: "a
|
|
719
|
+
message: "a parameter with a `schema` is not secret as a whole: mark its secret fields `secret` in the schema",
|
|
720
720
|
});
|
|
721
|
-
if (p.
|
|
721
|
+
if (p.default !== undefined && p.default !== "") {
|
|
722
722
|
const err = validateParamValue(p, p.default);
|
|
723
723
|
if (err)
|
|
724
724
|
ctx.addIssue({ code: "custom", path: ["default"], message: `default: ${err}` });
|
|
725
725
|
}
|
|
726
726
|
}
|
|
727
|
-
else if (p.schema !== undefined) {
|
|
728
|
-
ctx.addIssue({ code: "custom", path: ["schema"], message: "`schema` is only valid for json parameters" });
|
|
729
|
-
}
|
|
730
727
|
})
|
|
731
728
|
.meta({ id: "ProductTemplateParameter", outputId: "ProductTemplateParameter" });
|
|
732
729
|
// Wire shape of the optional parameters.yaml file inside a product-template tar.
|
package/package.json
CHANGED
package/params.d.ts
CHANGED
|
@@ -9,10 +9,11 @@ export type ParamSpec = {
|
|
|
9
9
|
min?: number;
|
|
10
10
|
max?: number;
|
|
11
11
|
values?: string[];
|
|
12
|
-
/**
|
|
12
|
+
/** For a string parameter whose value is JSON: its shape. */
|
|
13
13
|
schema?: JsonParamSchema;
|
|
14
14
|
};
|
|
15
|
-
/** The shape of a
|
|
15
|
+
/** The shape of a structured parameter's value (a `string` parameter with a
|
|
16
|
+
* `schema`, whose text is JSON): a small subset of JSON Schema.
|
|
16
17
|
* `secret` (on a string) is ours: the field is masked in reads, rendered as
|
|
17
18
|
* a password input, and may hold a `secretref:`. Every node may carry a
|
|
18
19
|
* `title` (a form's label) and a `description` (its help text). */
|
|
@@ -48,7 +49,7 @@ export declare function isParamRequired(p: Pick<ProductTemplateParameter, "requi
|
|
|
48
49
|
* empty value for a non-required parameter (the default / runner fills it).
|
|
49
50
|
* Boolean/number/enum values arrive as strings from form inputs. */
|
|
50
51
|
export declare function validateParamValue(p: ParamSpec, raw: string): string | undefined;
|
|
51
|
-
/** A
|
|
52
|
+
/** A structured parameter's text as a value, or why it is not JSON. */
|
|
52
53
|
export declare function parseJsonParam(raw: string): {
|
|
53
54
|
ok: true;
|
|
54
55
|
value: unknown;
|
|
@@ -56,7 +57,7 @@ export declare function parseJsonParam(raw: string): {
|
|
|
56
57
|
ok: false;
|
|
57
58
|
error: string;
|
|
58
59
|
};
|
|
59
|
-
/** Check a value against a
|
|
60
|
+
/** Check a value against a structured parameter's schema. Answers the first
|
|
60
61
|
* problem, naming where it is (`servers[1].url is required`), or undefined.
|
|
61
62
|
* A `secret` string field may hold a `secretref:`; any string does. */
|
|
62
63
|
export declare function validateJsonParamValue(schema: JsonParamSchema, value: unknown, path?: string): string | undefined;
|
|
@@ -67,7 +68,7 @@ export declare function mapSecretFields(schema: JsonParamSchema, value: unknown,
|
|
|
67
68
|
/** Whether the schema marks any field `secret`. */
|
|
68
69
|
export declare function hasSecretFields(schema: JsonParamSchema): boolean;
|
|
69
70
|
/** Every string anywhere in a JSON value, rewritten by `fn` (the runner uses
|
|
70
|
-
* it to resolve the `secretref:`s inside a
|
|
71
|
+
* it to resolve the `secretref:`s inside a structured parameter, which are
|
|
71
72
|
* resolved wherever they sit, as a whole value that is one is). */
|
|
72
73
|
export declare function mapJsonStrings(value: unknown, fn: (v: string) => string): unknown;
|
|
73
74
|
export {};
|
package/params.js
CHANGED
|
@@ -16,6 +16,16 @@ export function validateParamValue(p, raw) {
|
|
|
16
16
|
const v = raw.trim();
|
|
17
17
|
if (v === "")
|
|
18
18
|
return isParamRequired(p) ? "required" : undefined;
|
|
19
|
+
if (p.schema) {
|
|
20
|
+
// A structured parameter (a string whose value is JSON of this shape). A
|
|
21
|
+
// whole-value secretref: is the secret store's JSON, checked at launch.
|
|
22
|
+
if (v.startsWith("secretref:"))
|
|
23
|
+
return undefined;
|
|
24
|
+
const parsed = parseJsonParam(v);
|
|
25
|
+
if (!parsed.ok)
|
|
26
|
+
return parsed.error;
|
|
27
|
+
return validateJsonParamValue(p.schema, parsed.value);
|
|
28
|
+
}
|
|
19
29
|
switch (p.type) {
|
|
20
30
|
case "int":
|
|
21
31
|
if (!/^-?\d+$/.test(v))
|
|
@@ -29,17 +39,11 @@ export function validateParamValue(p, raw) {
|
|
|
29
39
|
return /^(true|false)$/i.test(v) ? undefined : "must be true or false";
|
|
30
40
|
case "enum":
|
|
31
41
|
return p.values && !p.values.includes(v) ? `must be one of: ${p.values.join(", ")}` : undefined;
|
|
32
|
-
case "json": {
|
|
33
|
-
const parsed = parseJsonParam(v);
|
|
34
|
-
if (!parsed.ok)
|
|
35
|
-
return parsed.error;
|
|
36
|
-
return p.schema ? validateJsonParamValue(p.schema, parsed.value) : undefined;
|
|
37
|
-
}
|
|
38
42
|
default:
|
|
39
43
|
return undefined; // string — anything goes
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
|
-
/** A
|
|
46
|
+
/** A structured parameter's text as a value, or why it is not JSON. */
|
|
43
47
|
export function parseJsonParam(raw) {
|
|
44
48
|
try {
|
|
45
49
|
return { ok: true, value: JSON.parse(raw) };
|
|
@@ -52,7 +56,7 @@ export function parseJsonParam(raw) {
|
|
|
52
56
|
function at(path) {
|
|
53
57
|
return path === "" ? "value" : path;
|
|
54
58
|
}
|
|
55
|
-
/** Check a value against a
|
|
59
|
+
/** Check a value against a structured parameter's schema. Answers the first
|
|
56
60
|
* problem, naming where it is (`servers[1].url is required`), or undefined.
|
|
57
61
|
* A `secret` string field may hold a `secretref:`; any string does. */
|
|
58
62
|
export function validateJsonParamValue(schema, value, path = "") {
|
|
@@ -154,7 +158,7 @@ export function hasSecretFields(schema) {
|
|
|
154
158
|
}
|
|
155
159
|
}
|
|
156
160
|
/** Every string anywhere in a JSON value, rewritten by `fn` (the runner uses
|
|
157
|
-
* it to resolve the `secretref:`s inside a
|
|
161
|
+
* it to resolve the `secretref:`s inside a structured parameter, which are
|
|
158
162
|
* resolved wherever they sit, as a whole value that is one is). */
|
|
159
163
|
export function mapJsonStrings(value, fn) {
|
|
160
164
|
if (typeof value === "string")
|
package/secret-references.d.ts
CHANGED
|
@@ -32,17 +32,17 @@ export interface DeclaredSecrecy {
|
|
|
32
32
|
/** Launch parameters as they may be shown: a parameter the template declares
|
|
33
33
|
* `secret` has its literal value masked. A reference is shown as it is — it
|
|
34
34
|
* is the point of a reference that it reveals nothing — and an empty value
|
|
35
|
-
* stays visibly empty. In a
|
|
35
|
+
* stays visibly empty. In a structured parameter, each field its schema marks
|
|
36
36
|
* `secret` is masked by the same rule; one that is not JSON, and has secret
|
|
37
37
|
* fields, is masked whole. */
|
|
38
38
|
export declare function redactSecretParams(params: Record<string, string>, declared: readonly DeclaredSecrecy[]): Record<string, string>;
|
|
39
|
-
/** A
|
|
39
|
+
/** A structured parameter's text with its secret fields masked. */
|
|
40
40
|
export declare function redactJsonSecrets(schema: JsonParamSchema, text: string): string;
|
|
41
|
-
/** A
|
|
41
|
+
/** A structured parameter's text as an editor sent it back, with each secret field
|
|
42
42
|
* that holds the placeholder given the value it stands for in `stored` (the
|
|
43
43
|
* same field of the value held now). Answers the text, or the paths whose
|
|
44
44
|
* placeholder has nothing behind it. */
|
|
45
45
|
export declare function restoreJsonSecrets(schema: JsonParamSchema, incoming: string, stored: string | undefined): Result<string, string[]>;
|
|
46
46
|
/** Every `secretref:` a parameter's value holds: itself, when it is one, or
|
|
47
|
-
* each one inside it, when it is JSON (a
|
|
47
|
+
* each one inside it, when it is JSON (a structured parameter's fields). */
|
|
48
48
|
export declare function secretReferencesIn(value: string): string[];
|
package/secret-references.js
CHANGED
|
@@ -54,7 +54,7 @@ const maskOne = (v) => (v !== "" && !isSecretReference(v) ? SECRET_PLACEHOLDER :
|
|
|
54
54
|
/** Launch parameters as they may be shown: a parameter the template declares
|
|
55
55
|
* `secret` has its literal value masked. A reference is shown as it is — it
|
|
56
56
|
* is the point of a reference that it reveals nothing — and an empty value
|
|
57
|
-
* stays visibly empty. In a
|
|
57
|
+
* stays visibly empty. In a structured parameter, each field its schema marks
|
|
58
58
|
* `secret` is masked by the same rule; one that is not JSON, and has secret
|
|
59
59
|
* fields, is masked whole. */
|
|
60
60
|
export function redactSecretParams(params, declared) {
|
|
@@ -63,12 +63,12 @@ export function redactSecretParams(params, declared) {
|
|
|
63
63
|
const p = byName.get(k);
|
|
64
64
|
if (p?.secret === true)
|
|
65
65
|
return [k, maskOne(v)];
|
|
66
|
-
if (p?.
|
|
66
|
+
if (p?.schema && hasSecretFields(p.schema))
|
|
67
67
|
return [k, redactJsonSecrets(p.schema, v)];
|
|
68
68
|
return [k, v];
|
|
69
69
|
}));
|
|
70
70
|
}
|
|
71
|
-
/** A
|
|
71
|
+
/** A structured parameter's text with its secret fields masked. */
|
|
72
72
|
export function redactJsonSecrets(schema, text) {
|
|
73
73
|
if (text.trim() === "")
|
|
74
74
|
return text;
|
|
@@ -81,7 +81,7 @@ export function redactJsonSecrets(schema, text) {
|
|
|
81
81
|
}
|
|
82
82
|
return JSON.stringify(mapSecretFields(schema, value, maskOne));
|
|
83
83
|
}
|
|
84
|
-
/** A
|
|
84
|
+
/** A structured parameter's text as an editor sent it back, with each secret field
|
|
85
85
|
* that holds the placeholder given the value it stands for in `stored` (the
|
|
86
86
|
* same field of the value held now). Answers the text, or the paths whose
|
|
87
87
|
* placeholder has nothing behind it. */
|
|
@@ -127,7 +127,7 @@ function valueAt(value, path) {
|
|
|
127
127
|
return cur;
|
|
128
128
|
}
|
|
129
129
|
/** Every `secretref:` a parameter's value holds: itself, when it is one, or
|
|
130
|
-
* each one inside it, when it is JSON (a
|
|
130
|
+
* each one inside it, when it is JSON (a structured parameter's fields). */
|
|
131
131
|
export function secretReferencesIn(value) {
|
|
132
132
|
if (isSecretReference(value))
|
|
133
133
|
return [value];
|