@norskvideo/ctl-sdk 0.1.49 → 0.1.50

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": "@norskvideo/ctl-sdk",
3
- "version": "0.1.49",
3
+ "version": "0.1.50",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -1,8 +1,12 @@
1
1
  export declare class ProductError extends Error {
2
2
  code: "DEV_URL_INVALID" | "DEV_URL_NOT_LOCALHOST" | "PORT_EXHAUSTED" | "DOCKER_PULL_FAILED" | "DOCKER_RUN_FAILED" | "READINESS_TIMEOUT" | "MANIFEST_FETCH_FAILED" | "MANIFEST_INVALID" | "CONFIG_SCREEN_UNREACHABLE" | "CONFIG_SCREEN_DEV_SERVER" | "LICENSE_INVALID" | "NAME_CONFLICT" | "NOT_FOUND" | "NOT_RESTARTABLE" | "RUNNER_TOO_OLD" | "PRODUCT_TEMPLATE_FETCH_FAILED"
3
3
  /** Two products declare one bare role name with different `defaultFor`. */
4
- | "ROLE_CONFLICT";
4
+ | "ROLE_CONFLICT"
5
+ /** The host's custom role names could not be read to check for a clash. */
6
+ | "ROLE_NAMES_UNREADABLE";
5
7
  constructor(code: "DEV_URL_INVALID" | "DEV_URL_NOT_LOCALHOST" | "PORT_EXHAUSTED" | "DOCKER_PULL_FAILED" | "DOCKER_RUN_FAILED" | "READINESS_TIMEOUT" | "MANIFEST_FETCH_FAILED" | "MANIFEST_INVALID" | "CONFIG_SCREEN_UNREACHABLE" | "CONFIG_SCREEN_DEV_SERVER" | "LICENSE_INVALID" | "NAME_CONFLICT" | "NOT_FOUND" | "NOT_RESTARTABLE" | "RUNNER_TOO_OLD" | "PRODUCT_TEMPLATE_FETCH_FAILED"
6
8
  /** Two products declare one bare role name with different `defaultFor`. */
7
- | "ROLE_CONFLICT", message: string);
9
+ | "ROLE_CONFLICT"
10
+ /** The host's custom role names could not be read to check for a clash. */
11
+ | "ROLE_NAMES_UNREADABLE", message: string);
8
12
  }
@@ -1,3 +1,4 @@
1
+ import { type Result } from "@norskvideo/ctl-foundation";
1
2
  import { type ProductPlacement } from "./docker-runner.js";
2
3
  import { type LicenseStager } from "./license-registration.js";
3
4
  import type { Manifest, ProductRoleDeclaration } from "./manifest-schema.js";
@@ -159,6 +160,14 @@ export interface ProductServiceOptions {
159
160
  onRolesDeclared?: (productName: string, roles: readonly ProductRoleDeclaration[], acceptance: {
160
161
  pending: readonly RoleDefault[];
161
162
  }) => void;
163
+ /**
164
+ * Role names a product may not declare, because the host already uses them
165
+ * for something else: its custom roles (ADR-0014). Names are one name space
166
+ * on a host, so a product role spelt like a custom role would be ambiguous in
167
+ * every assignment naming it. Omitted means none. An error is a host that
168
+ * cannot say which names it uses, and refuses any product declaring roles.
169
+ */
170
+ reservedRoleNames?: () => Result<ReadonlySet<string>, string>;
162
171
  /** Told once a registration is removed, so the host can drop whatever it
163
172
  * holds against the product (role assignments on `product/<name>`). */
164
173
  onRemoved?: (productName: string) => void;
@@ -219,6 +228,7 @@ export declare class ProductService {
219
228
  private reachHostFor;
220
229
  private readonly onRolesDeclared?;
221
230
  private readonly onRemoved?;
231
+ private readonly reservedRoleNames?;
222
232
  /**
223
233
  * Product roles travel bare, so a name means one thing on a host. Two
224
234
  * products may share one — a common vocabulary is the point — but not with
@@ -74,6 +74,7 @@ export class ProductService {
74
74
  this.knownCapabilities = opts.knownCapabilities ?? [];
75
75
  this.identityEnvFor = opts.identityEnvFor;
76
76
  this.onRolesDeclared = opts.onRolesDeclared;
77
+ this.reservedRoleNames = opts.reservedRoleNames;
77
78
  this.onRemoved = opts.onRemoved;
78
79
  this.forgetIdentity = opts.forgetIdentity;
79
80
  this.probeHeadersFor = opts.probeHeadersFor;
@@ -98,6 +99,7 @@ export class ProductService {
98
99
  }
99
100
  onRolesDeclared;
100
101
  onRemoved;
102
+ reservedRoleNames;
101
103
  /**
102
104
  * Product roles travel bare, so a name means one thing on a host. Two
103
105
  * products may share one — a common vocabulary is the point — but not with
@@ -106,7 +108,19 @@ export class ProductService {
106
108
  * know which two products to talk to.
107
109
  */
108
110
  refuseRoleConflicts(manifest, others) {
109
- for (const role of manifest.access?.roles ?? []) {
111
+ const declared = manifest.access?.roles ?? [];
112
+ const read = declared.length === 0 ? undefined : this.reservedRoleNames?.();
113
+ // Fail closed: a clash nobody could see would make one name mean two roles.
114
+ if (read?.status === "error") {
115
+ return new ProductError("ROLE_NAMES_UNREADABLE", `'${manifest.name}' declares product roles, and this host's custom roles cannot be read to check they ` +
116
+ `do not clash: ${read.error}`);
117
+ }
118
+ const reserved = read?.status === "ok" ? read.value : new Set();
119
+ for (const role of declared) {
120
+ if (reserved.has(role.name)) {
121
+ return new ProductError("ROLE_CONFLICT", `product role '${role.name}' is already a custom role on this host; role names are one name space, ` +
122
+ "so rename the custom role (or remove it) before registering this product");
123
+ }
110
124
  for (const other of others) {
111
125
  if (other.name === manifest.name)
112
126
  continue;