@norskvideo/ctl-sdk 0.1.55 → 0.1.57

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.
@@ -0,0 +1,7 @@
1
+ import type { ReactNode } from "react";
2
+ import { type VariableRow } from "./VariableRowsEditor.js";
3
+ export declare function LabelsEditor({ rows, onChange, addLabel, }: {
4
+ rows: VariableRow[];
5
+ onChange: (rows: VariableRow[]) => void;
6
+ addLabel?: string;
7
+ }): ReactNode;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { labelNameError } from "./label-rows.js";
3
+ import { VariableRowsEditor } from "./VariableRowsEditor.js";
4
+ export function LabelsEditor({ rows, onChange, addLabel = "Add label", }) {
5
+ const seen = new Set();
6
+ return (_jsx(VariableRowsEditor, { rows: rows, onChange: onChange, nameCase: "as-typed", noun: "label", addLabel: addLabel, namePlaceholder: "env", valuePlaceholder: "qa", nameError: (name) => {
7
+ const error = labelNameError(name.trim(), seen);
8
+ if (name.trim() !== "")
9
+ seen.add(name.trim());
10
+ return error;
11
+ } }));
12
+ }
@@ -22,6 +22,9 @@ export type ProductTemplateBuildRequest = {
22
22
  * dev-kit-generated product splits off before its strict config parse
23
23
  * and bakes into the manifest's `advanced` block. */
24
24
  formValues: Record<string, unknown>;
25
+ /** The template's labels (ADR-0015, norsk-ctl task 124), when the form was
26
+ * asked for them (`withLabels`): the caller records them on the template. */
27
+ labels?: Record<string, string>;
25
28
  };
26
29
  export type ProductTemplateBuildOutcome<TProductTemplate> = {
27
30
  ok: true;
@@ -30,8 +33,10 @@ export type ProductTemplateBuildOutcome<TProductTemplate> = {
30
33
  ok: false;
31
34
  error: string;
32
35
  };
33
- export declare function ProductTemplateBuildForm<TProductTemplate>({ productName, configScreenUrl, onClose, sections, onSubmit, onSaved, onSavedAndLaunch, onRequirements, }: {
36
+ export declare function ProductTemplateBuildForm<TProductTemplate>({ productName, configScreenUrl, onClose, sections, onSubmit, onSaved, onSavedAndLaunch, onRequirements, withLabels, }: {
34
37
  productName: string;
38
+ /** Ask for the template's labels too; the save carries them as `labels`. */
39
+ withLabels?: boolean;
35
40
  configScreenUrl: string | null;
36
41
  onClose: () => void;
37
42
  /** Forwarded from the config-screen iframe: the product's suggested placement
@@ -3,6 +3,8 @@ import { ChevronDown, ChevronRight, X } from "lucide-react";
3
3
  import { useRef, useState } from "react";
4
4
  import toast from "react-hot-toast";
5
5
  import { validateInstanceId } from "../validate.js";
6
+ import { LabelsEditor } from "./LabelsEditor.js";
7
+ import { readLabelRows } from "./label-rows.js";
6
8
  import { ProductIframe } from "./ProductIframe.js";
7
9
  import { useUIPrimitives } from "./ui-primitives.js";
8
10
  const emptyAdvancedDefaults = {
@@ -34,9 +36,11 @@ function assembleAdvancedDefaults(d) {
34
36
  out.openFileLimit = { default: limit };
35
37
  return Object.keys(out).length > 0 ? out : undefined;
36
38
  }
37
- export function ProductTemplateBuildForm({ productName, configScreenUrl, onClose, sections, onSubmit, onSaved, onSavedAndLaunch, onRequirements, }) {
39
+ export function ProductTemplateBuildForm({ productName, configScreenUrl, onClose, sections, onSubmit, onSaved, onSavedAndLaunch, onRequirements, withLabels = false, }) {
38
40
  const { Button, Input, Label } = useUIPrimitives();
39
41
  const [productTemplateName, setProductTemplateName] = useState("");
42
+ const [labelRowsDraft, setLabelRowsDraft] = useState([]);
43
+ const labels = readLabelRows(labelRowsDraft);
40
44
  // The iframe can suggest a name derived from its current choices (#317).
41
45
  // We prefill the field with it while the operator hasn't typed anything,
42
46
  // so changing template/release keeps the suggestion live; once they edit
@@ -58,7 +62,7 @@ export function ProductTemplateBuildForm({ productName, configScreenUrl, onClose
58
62
  };
59
63
  const nameValidation = productTemplateName ? validateInstanceId(productTemplateName) : null;
60
64
  const productTemplateNameError = nameValidation?.status === "error" ? nameValidation.message : null;
61
- const canSubmit = !!productTemplateName && !productTemplateNameError && !submitting && iframeValid;
65
+ const canSubmit = !!productTemplateName && !productTemplateNameError && !submitting && iframeValid && (!withLabels || labels.ok);
62
66
  // Internal helper. Returns the saved product template on success (so the
63
67
  // caller can hand it off to its launch flow without waiting for a refetch),
64
68
  // null on failure.
@@ -81,7 +85,16 @@ export function ProductTemplateBuildForm({ productName, configScreenUrl, onClose
81
85
  const advanced = assembleAdvancedDefaults(advancedDraft);
82
86
  if (advanced)
83
87
  formValues = { ...formValues, $advancedDefaults: advanced };
84
- const outcome = await onSubmit({ productName, productTemplateName, formValues });
88
+ if (withLabels && !labels.ok) {
89
+ toast.error(labels.error);
90
+ return null;
91
+ }
92
+ const outcome = await onSubmit({
93
+ productName,
94
+ productTemplateName,
95
+ formValues,
96
+ ...(withLabels && labels.ok && Object.keys(labels.labels).length > 0 ? { labels: labels.labels } : {}),
97
+ });
85
98
  if (!outcome.ok) {
86
99
  toast.error(`Save product template failed: ${outcome.error}`);
87
100
  return null;
@@ -118,5 +131,5 @@ export function ProductTemplateBuildForm({ productName, configScreenUrl, onClose
118
131
  return (_jsxs("div", { className: "mb-6 rounded-lg border border-zinc-700 bg-zinc-900 p-4", children: [_jsxs("div", { className: "flex items-center justify-between mb-4", children: [_jsxs("div", { children: [_jsxs("h4", { className: "text-sm font-semibold text-zinc-100", children: ["Create ", productName, " product template"] }), _jsx("p", { className: "text-xs text-zinc-500 mt-0.5", children: "Saves a reusable product template. Launch instances from it later." })] }), _jsx("button", { type: "button", onClick: onClose, className: "text-zinc-500 hover:text-zinc-300", children: _jsx(X, { size: 14 }) })] }), _jsxs("form", { onSubmit: handleSave, className: "space-y-4", children: [_jsxs("div", { children: [_jsx(Label, { children: "Product template name *" }), _jsx(Input, { value: productTemplateName, onChange: (e) => {
119
132
  setNameTouched(true);
120
133
  setProductTemplateName(e.target.value);
121
- }, placeholder: suggestedName || `e.g. ${productName}-prod`, required: true }), productTemplateNameError ? (_jsx("p", { className: "text-xs text-red-400 mt-1", children: productTemplateNameError })) : (_jsx("p", { className: "text-xs text-zinc-500 mt-1", children: "Lowercase letters, numbers, and hyphens only. Used to launch instances later." }))] }), configScreenUrl ? (_jsx(ProductIframe, { ref: iframeRef, productName: productName, configScreenUrl: configScreenUrl, onValidityChange: (v) => setIframeValid(v), onSuggestName: handleSuggestName, ...(onRequirements ? { onRequirements } : {}) })) : (_jsxs("p", { className: "text-xs text-zinc-500", children: ["Product manifest does not declare ", _jsx("code", { children: "ui.configScreenUrl" }), " \u2014 nothing to configure."] })), sections, _jsxs("div", { children: [_jsxs("button", { type: "button", onClick: () => setDefaultsOpen((v) => !v), className: "flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-widest text-zinc-500 hover:text-zinc-300", children: [defaultsOpen ? _jsx(ChevronDown, { size: 12 }) : _jsx(ChevronRight, { size: 12 }), "Custom defaults"] }), defaultsOpen && (_jsxs("div", { className: "mt-2", children: [_jsx("p", { className: "text-xs text-zinc-500 mb-2", children: "Launch-form defaults baked into this template's manifest. Operators can still override them per instance." }), _jsxs("div", { className: "flex flex-wrap gap-3", children: [_jsxs("div", { children: [_jsx(Label, { children: "Network mode" }), _jsxs("select", { "aria-label": "Network mode", value: advancedDraft.networkMode, onChange: (e) => patchDraft({ networkMode: e.target.value }), className: "block rounded border border-zinc-700 bg-zinc-900 px-3 py-1.5 text-sm text-zinc-100", children: [_jsx("option", { value: "", children: "product default" }), _jsx("option", { value: "docker", children: "docker" }), _jsx("option", { value: "hybrid", children: "hybrid" })] })] }), _jsxs("div", { className: "min-w-[14rem] flex-1", children: [_jsx(Label, { children: "Host ports" }), _jsx(Input, { "aria-label": "Host ports", placeholder: "e.g. 1935, 5001/udp, 9000:80@svc", value: advancedDraft.hostPorts, onChange: (e) => patchDraft({ hostPorts: e.target.value }) })] }), _jsxs("div", { children: [_jsx(Label, { children: "Container user" }), _jsx(Input, { "aria-label": "Container user", placeholder: "uid:gid", value: advancedDraft.containerUser, onChange: (e) => patchDraft({ containerUser: e.target.value }), className: "w-28" })] }), _jsxs("div", { children: [_jsx(Label, { children: "Shared memory size" }), _jsx(Input, { "aria-label": "Shared memory size", placeholder: "e.g. 8gb", value: advancedDraft.shmSize, onChange: (e) => patchDraft({ shmSize: e.target.value }), className: "w-24" })] }), _jsxs("div", { children: [_jsx(Label, { children: "Open file limit" }), _jsx(Input, { "aria-label": "Open file limit", type: "number", min: 1024, max: 1048576, placeholder: "runner default", value: advancedDraft.openFileLimit, onChange: (e) => patchDraft({ openFileLimit: e.target.value }), className: "w-32" })] })] })] }))] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", variant: "primary", disabled: !canSubmit, onClick: handleSaveAndLaunch, children: submitting ? "Working…" : "Save & Launch…" }), _jsx(Button, { type: "submit", variant: "default", disabled: !canSubmit, children: "Save" }), _jsx(Button, { type: "button", variant: "ghost", onClick: onClose, children: "Cancel" })] })] })] }));
134
+ }, placeholder: suggestedName || `e.g. ${productName}-prod`, required: true }), productTemplateNameError ? (_jsx("p", { className: "text-xs text-red-400 mt-1", children: productTemplateNameError })) : (_jsx("p", { className: "text-xs text-zinc-500 mt-1", children: "Lowercase letters, numbers, and hyphens only. Used to launch instances later." }))] }), withLabels && (_jsxs("div", { children: [_jsx(Label, { children: "Labels" }), _jsx(LabelsEditor, { rows: labelRowsDraft, onChange: setLabelRowsDraft }), labels.ok ? (_jsx("p", { className: "text-xs text-zinc-500 mt-1", children: "name=value pairs joined by commas. Instances launched from it start with them; they decide who may see it, and what walls show it." })) : (_jsx("p", { className: "text-xs text-red-400 mt-1", children: labels.error }))] })), configScreenUrl ? (_jsx(ProductIframe, { ref: iframeRef, productName: productName, configScreenUrl: configScreenUrl, onValidityChange: (v) => setIframeValid(v), onSuggestName: handleSuggestName, ...(onRequirements ? { onRequirements } : {}) })) : (_jsxs("p", { className: "text-xs text-zinc-500", children: ["Product manifest does not declare ", _jsx("code", { children: "ui.configScreenUrl" }), " \u2014 nothing to configure."] })), sections, _jsxs("div", { children: [_jsxs("button", { type: "button", onClick: () => setDefaultsOpen((v) => !v), className: "flex items-center gap-1.5 text-[10px] font-semibold uppercase tracking-widest text-zinc-500 hover:text-zinc-300", children: [defaultsOpen ? _jsx(ChevronDown, { size: 12 }) : _jsx(ChevronRight, { size: 12 }), "Custom defaults"] }), defaultsOpen && (_jsxs("div", { className: "mt-2", children: [_jsx("p", { className: "text-xs text-zinc-500 mb-2", children: "Launch-form defaults baked into this template's manifest. Operators can still override them per instance." }), _jsxs("div", { className: "flex flex-wrap gap-3", children: [_jsxs("div", { children: [_jsx(Label, { children: "Network mode" }), _jsxs("select", { "aria-label": "Network mode", value: advancedDraft.networkMode, onChange: (e) => patchDraft({ networkMode: e.target.value }), className: "block rounded border border-zinc-700 bg-zinc-900 px-3 py-1.5 text-sm text-zinc-100", children: [_jsx("option", { value: "", children: "product default" }), _jsx("option", { value: "docker", children: "docker" }), _jsx("option", { value: "hybrid", children: "hybrid" })] })] }), _jsxs("div", { className: "min-w-[14rem] flex-1", children: [_jsx(Label, { children: "Host ports" }), _jsx(Input, { "aria-label": "Host ports", placeholder: "e.g. 1935, 5001/udp, 9000:80@svc", value: advancedDraft.hostPorts, onChange: (e) => patchDraft({ hostPorts: e.target.value }) })] }), _jsxs("div", { children: [_jsx(Label, { children: "Container user" }), _jsx(Input, { "aria-label": "Container user", placeholder: "uid:gid", value: advancedDraft.containerUser, onChange: (e) => patchDraft({ containerUser: e.target.value }), className: "w-28" })] }), _jsxs("div", { children: [_jsx(Label, { children: "Shared memory size" }), _jsx(Input, { "aria-label": "Shared memory size", placeholder: "e.g. 8gb", value: advancedDraft.shmSize, onChange: (e) => patchDraft({ shmSize: e.target.value }), className: "w-24" })] }), _jsxs("div", { children: [_jsx(Label, { children: "Open file limit" }), _jsx(Input, { "aria-label": "Open file limit", type: "number", min: 1024, max: 1048576, placeholder: "runner default", value: advancedDraft.openFileLimit, onChange: (e) => patchDraft({ openFileLimit: e.target.value }), className: "w-32" })] })] })] }))] }), _jsxs("div", { className: "flex gap-2", children: [_jsx(Button, { type: "button", variant: "primary", disabled: !canSubmit, onClick: handleSaveAndLaunch, children: submitting ? "Working…" : "Save & Launch…" }), _jsx(Button, { type: "submit", variant: "default", disabled: !canSubmit, children: "Save" }), _jsx(Button, { type: "button", variant: "ghost", onClick: onClose, children: "Cancel" })] })] })] }));
122
135
  }
@@ -20,5 +20,10 @@ export interface VariableRowsEditorProps {
20
20
  showBackup?: boolean;
21
21
  addLabel?: string;
22
22
  namePlaceholder?: string;
23
+ valuePlaceholder?: string;
24
+ /** Env-var names are upper-cased as typed; a label's are kept as typed. */
25
+ nameCase?: "upper" | "as-typed";
26
+ /** What a row is, for the controls' accessible names. */
27
+ noun?: string;
23
28
  }
24
- export declare function VariableRowsEditor({ rows, onChange, nameError, showBackup, addLabel, namePlaceholder, }: VariableRowsEditorProps): ReactNode;
29
+ export declare function VariableRowsEditor({ rows, onChange, nameError, showBackup, addLabel, namePlaceholder, valuePlaceholder, nameCase, noun, }: VariableRowsEditorProps): ReactNode;
@@ -2,13 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  // Free-form environment-variable rows: NAME, a value, and (optionally) the
3
3
  // value the backup replica should use instead.
4
4
  //
5
- // Shared because this is the same editor in two places that otherwise cannot
6
- // share a form. The production composer uses it for variables the operator adds
7
- // beyond what the product template declares; the product-template create panel
8
- // uses it for the whole template tier, because at CREATION TIME there is no
9
- // declared parameter list to tabulate — the tar has not been built yet. That
10
- // asymmetry is why the composer's parameter TABLE cannot be reused here, and
11
- // why this row editor is the part that can.
5
+ // The one name/value editor (RFC 0008 §2): variables here, and labels through
6
+ // LabelsEditor, which keeps names as typed and checks them as labels. The
7
+ // product-template create panel uses it for the whole template tier, because
8
+ // at CREATION TIME there is no declared parameter list to tabulate. The
9
+ // production composer's added variables are rows of its parameter table
10
+ // instead (they share its columns with the declared parameters, and carry the
11
+ // ask-at-launch box), so they are not this editor.
12
12
  //
13
13
  // Controlled, and name validation is injected: the reserved-prefix and
14
14
  // uniqueness rules are the manager's vocabulary, not the SDK's.
@@ -19,12 +19,12 @@ export function newVariableRow() {
19
19
  seq += 1;
20
20
  return { id: `var-${seq}`, name: "", value: "" };
21
21
  }
22
- export function VariableRowsEditor({ rows, onChange, nameError, showBackup = false, addLabel = "Add variable", namePlaceholder = "MY_VAR", }) {
22
+ export function VariableRowsEditor({ rows, onChange, nameError, showBackup = false, addLabel = "Add variable", namePlaceholder = "MY_VAR", valuePlaceholder = "value", nameCase = "upper", noun = "variable", }) {
23
23
  const { Button, Input } = useUIPrimitives();
24
24
  const errors = rows.map((r, i) => nameError?.(r.name, i));
25
25
  const update = (id, patch) => onChange(rows.map((r) => (r.id === id ? { ...r, ...patch } : r)));
26
- return (_jsxs("div", { className: "space-y-1.5", children: [rows.map((row, i) => (_jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "w-48 shrink-0", children: _jsx(Input, { "aria-label": "variable name", className: "font-mono", placeholder: namePlaceholder, value: row.name,
26
+ return (_jsxs("div", { className: "space-y-1.5", children: [rows.map((row, i) => (_jsxs("div", { children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsx("div", { className: "w-48 shrink-0", children: _jsx(Input, { "aria-label": `${noun} name`, className: "font-mono", placeholder: namePlaceholder, value: row.name,
27
27
  // Env-var names are conventionally upper-case; doing it here
28
28
  // saves the operator shouting and keeps the two hosts identical.
29
- onChange: (e) => update(row.id, { name: e.target.value.toUpperCase() }) }) }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(Input, { "aria-label": `value for ${row.name || "new variable"}`, placeholder: "value", value: row.value, onChange: (e) => update(row.id, { value: e.target.value }) }) }), showBackup && (_jsx("div", { className: "min-w-0 flex-1", children: _jsx(Input, { "aria-label": `backup value for ${row.name || "new variable"}`, placeholder: "same as primary", value: row.backupValue ?? "", onChange: (e) => update(row.id, { backupValue: e.target.value }) }) })), _jsx(Button, { type: "button", variant: "ghost", size: "sm", "aria-label": `remove variable ${row.name || "row"}`, onClick: () => onChange(rows.filter((r) => r.id !== row.id)), children: _jsx(Trash2, { size: 13 }) })] }), errors[i] && _jsx("p", { className: "mt-0.5 text-xs text-amber-400", children: errors[i] })] }, row.id))), _jsxs(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => onChange([...rows, newVariableRow()]), children: [_jsx(Plus, { size: 12 }), " ", addLabel] })] }));
29
+ onChange: (e) => update(row.id, { name: nameCase === "upper" ? e.target.value.toUpperCase() : e.target.value }) }) }), _jsx("div", { className: "min-w-0 flex-1", children: _jsx(Input, { "aria-label": `value for ${row.name || `new ${noun}`}`, placeholder: valuePlaceholder, value: row.value, onChange: (e) => update(row.id, { value: e.target.value }) }) }), showBackup && (_jsx("div", { className: "min-w-0 flex-1", children: _jsx(Input, { "aria-label": `backup value for ${row.name || `new ${noun}`}`, placeholder: "same as primary", value: row.backupValue ?? "", onChange: (e) => update(row.id, { backupValue: e.target.value }) }) })), _jsx(Button, { type: "button", variant: "ghost", size: "sm", "aria-label": `remove ${noun} ${row.name || "row"}`, onClick: () => onChange(rows.filter((r) => r.id !== row.id)), children: _jsx(Trash2, { size: 13 }) })] }), errors[i] && _jsx("p", { className: "mt-0.5 text-xs text-amber-400", children: errors[i] })] }, row.id))), _jsxs(Button, { type: "button", variant: "ghost", size: "sm", onClick: () => onChange([...rows, newVariableRow()]), children: [_jsx(Plus, { size: 12 }), " ", addLabel] })] }));
30
30
  }
@@ -1,4 +1,7 @@
1
1
  export { type ComposeLayer, ComposeLayerPreview, type ComposeLayerPreviewProps } from "./ComposeLayerPreview.js";
2
+ export { LabelsEditor } from "./LabelsEditor.js";
3
+ export { labelNameError, labelRows, readLabelRows } from "./label-rows.js";
4
+ export { type LabelsTextResult, labelsText, parseLabelsText } from "./labels-text.js";
2
5
  export { ProductIframe, type ProductIframeHandle, type SubmitResult } from "./ProductIframe.js";
3
6
  export { ProductTemplateBuildForm, type ProductTemplateBuildOutcome, type ProductTemplateBuildRequest, } from "./ProductTemplateBuildForm.js";
4
7
  export { SectionFold, type SectionFoldProps } from "./SectionFold.js";
@@ -1,4 +1,7 @@
1
1
  export { ComposeLayerPreview } from "./ComposeLayerPreview.js";
2
+ export { LabelsEditor } from "./LabelsEditor.js";
3
+ export { labelNameError, labelRows, readLabelRows } from "./label-rows.js";
4
+ export { labelsText, parseLabelsText } from "./labels-text.js";
2
5
  export { ProductIframe } from "./ProductIframe.js";
3
6
  export { ProductTemplateBuildForm, } from "./ProductTemplateBuildForm.js";
4
7
  export { SectionFold } from "./SectionFold.js";
@@ -0,0 +1,7 @@
1
+ import type { LabelsTextResult } from "./labels-text.js";
2
+ import { type VariableRow } from "./VariableRowsEditor.js";
3
+ /** Why `name` cannot be a label here, or undefined. `seen` holds the names
4
+ * of the rows above it. An empty name is a row not yet filled in. */
5
+ export declare function labelNameError(name: string, seen: ReadonlySet<string>): string | undefined;
6
+ export declare function labelRows(labels: Readonly<Record<string, string>>): VariableRow[];
7
+ export declare function readLabelRows(rows: readonly VariableRow[]): LabelsTextResult;
@@ -0,0 +1,47 @@
1
+ // Labels as rows of the name/value editor (RFC 0008 §2: one editor for
2
+ // labels and variables alike). ADR-0015's rules, mirrored so the editor can
3
+ // say what is wrong as it is typed; the platform still checks every set.
4
+ import { newVariableRow } from "./VariableRowsEditor.js";
5
+ const NAME = /^[A-Za-z0-9][A-Za-z0-9._/-]*$/;
6
+ const MAX = 64;
7
+ const VALUE_FORBIDDEN = /[,=[\]]/;
8
+ /** Why `name` cannot be a label here, or undefined. `seen` holds the names
9
+ * of the rows above it. An empty name is a row not yet filled in. */
10
+ export function labelNameError(name, seen) {
11
+ if (name === "")
12
+ return undefined;
13
+ if (name.startsWith("norsk."))
14
+ return "names under norsk. are the platform's";
15
+ if (!NAME.test(name) || name.length > MAX)
16
+ return "letters, digits and . _ / -, at most 64";
17
+ if (seen.has(name))
18
+ return `'${name}' is named twice`;
19
+ return undefined;
20
+ }
21
+ export function labelRows(labels) {
22
+ return Object.entries(labels)
23
+ .sort(([a], [b]) => a.localeCompare(b))
24
+ .map(([name, value]) => ({ ...newVariableRow(), name, value }));
25
+ }
26
+ export function readLabelRows(rows) {
27
+ const labels = {};
28
+ const seen = new Set();
29
+ for (const { name, value } of rows) {
30
+ const n = name.trim();
31
+ const v = value.trim();
32
+ if (n === "" && v === "")
33
+ continue;
34
+ if (n === "")
35
+ return { ok: false, error: `the value '${v}' has no name` };
36
+ const problem = labelNameError(n, seen);
37
+ if (problem)
38
+ return { ok: false, error: `${n}: ${problem}` };
39
+ if (v === "")
40
+ return { ok: false, error: `${n} has no value` };
41
+ if (VALUE_FORBIDDEN.test(v) || v.length > MAX)
42
+ return { ok: false, error: `${n}: a value has no , = [ or ]` };
43
+ seen.add(n);
44
+ labels[n] = v;
45
+ }
46
+ return { ok: true, labels };
47
+ }
@@ -0,0 +1,9 @@
1
+ export type LabelsTextResult = {
2
+ ok: true;
3
+ labels: Record<string, string>;
4
+ } | {
5
+ ok: false;
6
+ error: string;
7
+ };
8
+ export declare function parseLabelsText(text: string): LabelsTextResult;
9
+ export declare function labelsText(labels: Readonly<Record<string, string>>): string;
@@ -0,0 +1,26 @@
1
+ // Labels as an operator types them (norsk-ctl task 124): `name=value` pairs
2
+ // joined by commas, the same form a runtime receives as NORSK_LABELS. The
3
+ // platform still checks each set (ADR-0015's limits); this only reads the box.
4
+ export function parseLabelsText(text) {
5
+ const labels = {};
6
+ for (const raw of text.split(",")) {
7
+ const pair = raw.trim();
8
+ if (pair === "")
9
+ continue;
10
+ const at = pair.indexOf("=");
11
+ const name = pair.slice(0, at).trim();
12
+ const value = pair.slice(at + 1).trim();
13
+ if (at <= 0 || name === "" || value === "")
14
+ return { ok: false, error: `'${pair}' is not name=value` };
15
+ if (name.startsWith("norsk."))
16
+ return { ok: false, error: `'${name}': names under norsk. are the platform's` };
17
+ labels[name] = value;
18
+ }
19
+ return { ok: true, labels };
20
+ }
21
+ export function labelsText(labels) {
22
+ return Object.entries(labels)
23
+ .sort(([a], [b]) => a.localeCompare(b))
24
+ .map(([k, v]) => `${k}=${v}`)
25
+ .join(",");
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@norskvideo/ctl-sdk",
3
- "version": "0.1.55",
3
+ "version": "0.1.57",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {