@norskvideo/ctl-sdk 0.1.6 → 0.1.7
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 +1 -0
- package/index.js +1 -0
- package/license-staged.d.ts +20 -0
- package/license-staged.js +55 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./dev-url.js";
|
|
|
5
5
|
export * from "./docker-runner.js";
|
|
6
6
|
export * from "./http-proxy.js";
|
|
7
7
|
export * from "./license-registration.js";
|
|
8
|
+
export * from "./license-staged.js";
|
|
8
9
|
export * from "./license-stager.js";
|
|
9
10
|
export * from "./license-v2.js";
|
|
10
11
|
export * from "./manifest-fetch.js";
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export * from "./dev-url.js";
|
|
|
7
7
|
export * from "./docker-runner.js";
|
|
8
8
|
export * from "./http-proxy.js";
|
|
9
9
|
export * from "./license-registration.js";
|
|
10
|
+
export * from "./license-staged.js";
|
|
10
11
|
export * from "./license-stager.js";
|
|
11
12
|
export * from "./license-v2.js";
|
|
12
13
|
export * from "./manifest-fetch.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The staged copy corresponding to an operator-supplied licence path, if one
|
|
3
|
+
* exists under `licensesDir`. `exists` is injected so this stays unit-testable.
|
|
4
|
+
*/
|
|
5
|
+
export declare function stagedLicenseCandidate(operatorPath: string, licensesDir: string | undefined, exists?: (path: string) => boolean): string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* Explain an unreadable licence in terms of the thing that's actually wrong.
|
|
8
|
+
*
|
|
9
|
+
* A permissions failure and a missing file are different mistakes: the first is
|
|
10
|
+
* "right file, wrong path for this process", the second is a typo. Naming the
|
|
11
|
+
* daemon user on an ENOENT would send the operator hunting a permissions
|
|
12
|
+
* problem that isn't there.
|
|
13
|
+
*/
|
|
14
|
+
export declare function unreadableLicenseMessage(opts: {
|
|
15
|
+
operatorPath: string;
|
|
16
|
+
cause: string;
|
|
17
|
+
daemonUser: string;
|
|
18
|
+
licensesDir?: string;
|
|
19
|
+
stagedCandidate?: string;
|
|
20
|
+
}): string;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostics for a licence file the daemon cannot read.
|
|
3
|
+
*
|
|
4
|
+
* The licence-driven routes (`preview-license`, `from-license`) read the file
|
|
5
|
+
* daemon-side, and the daemon runs unprivileged as its service user — so an
|
|
6
|
+
* operator who passes the path they used at install time (`~/licence.json`, in
|
|
7
|
+
* *their* home) gets an EACCES that reads like a broken licence rather than a
|
|
8
|
+
* wrong path.
|
|
9
|
+
*
|
|
10
|
+
* The remedy is almost always sitting in `licensesDir`: the installers stage a
|
|
11
|
+
* copy there, deliberately keeping the operator's basename, so the file they
|
|
12
|
+
* meant can be found by name and named back to them. Shared by the hosts (ctl
|
|
13
|
+
* and mgr) so the two daemons explain the same mistake the same way.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync } from "node:fs";
|
|
16
|
+
import { basename, dirname, join, resolve } from "node:path";
|
|
17
|
+
/**
|
|
18
|
+
* The staged copy corresponding to an operator-supplied licence path, if one
|
|
19
|
+
* exists under `licensesDir`. `exists` is injected so this stays unit-testable.
|
|
20
|
+
*/
|
|
21
|
+
export function stagedLicenseCandidate(operatorPath, licensesDir, exists = existsSync) {
|
|
22
|
+
if (!licensesDir)
|
|
23
|
+
return undefined;
|
|
24
|
+
// Already the staged copy — suggesting it back would be circular.
|
|
25
|
+
if (resolve(dirname(operatorPath)) === resolve(licensesDir))
|
|
26
|
+
return undefined;
|
|
27
|
+
const candidate = join(licensesDir, basename(operatorPath));
|
|
28
|
+
return exists(candidate) ? candidate : undefined;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Explain an unreadable licence in terms of the thing that's actually wrong.
|
|
32
|
+
*
|
|
33
|
+
* A permissions failure and a missing file are different mistakes: the first is
|
|
34
|
+
* "right file, wrong path for this process", the second is a typo. Naming the
|
|
35
|
+
* daemon user on an ENOENT would send the operator hunting a permissions
|
|
36
|
+
* problem that isn't there.
|
|
37
|
+
*/
|
|
38
|
+
export function unreadableLicenseMessage(opts) {
|
|
39
|
+
const { operatorPath, cause, daemonUser, licensesDir, stagedCandidate } = opts;
|
|
40
|
+
const missing = /ENOENT/.test(cause);
|
|
41
|
+
const parts = [`cannot read license file '${operatorPath}': ${cause}`];
|
|
42
|
+
if (missing) {
|
|
43
|
+
parts.push("Check the path — nothing exists there.");
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
parts.push(`The daemon runs as '${daemonUser}', which cannot read it.`);
|
|
47
|
+
}
|
|
48
|
+
if (stagedCandidate) {
|
|
49
|
+
parts.push(`A staged licence of the same name exists at '${stagedCandidate}' — pass that instead.`);
|
|
50
|
+
}
|
|
51
|
+
else if (!missing) {
|
|
52
|
+
parts.push(`Licences are staged under ${licensesDir ?? "the daemon's licenses directory"} at install time; pass the staged path, or copy the file there readable by '${daemonUser}'.`);
|
|
53
|
+
}
|
|
54
|
+
return parts.join(" ");
|
|
55
|
+
}
|