@wirecat/cli-core 0.694.0 → 0.696.0
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/CHANGELOG.md +58 -0
- package/dist/cli/bot/api.js +10 -1
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +3 -3
- package/dist/cli/profile-token.d.ts +10 -2
- package/dist/cli/profile-token.js +19 -3
- package/dist/cli/service-api-call.d.ts +2 -0
- package/dist/cli/service-api-call.js +1 -1
- package/dist/cli/service-api-manifest.d.ts +9 -3
- package/dist/cli/service-api-manifest.js +63 -7
- package/dist/cli/service-api.d.ts +5 -0
- package/dist/cli/service-api.js +7 -4
- package/dist/cli/token-session.d.ts +27 -1
- package/dist/cli/token-session.js +52 -13
- package/dist/crm/manifest/paths.d.ts +12 -0
- package/dist/crm/manifest/paths.js +4 -4
- package/dist/crm/testing/index.d.ts +1 -0
- package/dist/crm/testing/index.js +1 -0
- package/dist/crm/testing/manifest-fake.d.ts +47 -0
- package/dist/crm/testing/manifest-fake.js +516 -0
- package/dist/crm/testing/source-contract.d.ts +5 -0
- package/dist/crm/testing/source-contract.js +18 -1
- package/dist/manifest/index.d.ts +15 -1
- package/dist/manifest/index.js +56 -11
- package/package.json +1 -1
package/dist/manifest/index.js
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
|
-
import { isAbsolute } from "node:path";
|
|
2
1
|
import { CliError } from "@wirecat/cli-base";
|
|
3
2
|
import * as v from "valibot";
|
|
4
3
|
export const CLI_CATEGORIES = ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "other"];
|
|
5
4
|
/** Types the config in the editor; it returns what it is given. */
|
|
6
5
|
export const defineCli = (config) => config;
|
|
7
6
|
const word = v.pipe(v.string(), v.regex(/^[a-z][a-z0-9]*(-[a-z0-9]+)*$/, "lower-case letters and digits, words joined by one dash"));
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
// A query parameter with such a word in its name holds a secret, which the URL would put into a committed file. Whole
|
|
8
|
+
// words, so `design` or `keyword` stay allowed.
|
|
9
|
+
const SECRET_WORDS = new Set([
|
|
10
|
+
"key",
|
|
11
|
+
"apikey",
|
|
12
|
+
"token",
|
|
13
|
+
"secret",
|
|
14
|
+
"sig",
|
|
15
|
+
"signature",
|
|
16
|
+
"auth",
|
|
17
|
+
"password",
|
|
18
|
+
"pass",
|
|
19
|
+
"passwd",
|
|
20
|
+
"credential",
|
|
21
|
+
"credentials",
|
|
22
|
+
"session",
|
|
23
|
+
"sessionid",
|
|
24
|
+
"jwt",
|
|
25
|
+
"code",
|
|
26
|
+
]);
|
|
27
|
+
const secretName = (name) => name.split(/[_\-.]+|(?<=[a-z0-9])(?=[A-Z])/).some((part) => SECRET_WORDS.has(part.toLowerCase()));
|
|
28
|
+
const urlOf = (text) => (URL.canParse(text) ? new URL(text) : undefined);
|
|
29
|
+
/** An https URL that can be committed: a host, no spaces, no user name or password, no secret in its query. */
|
|
30
|
+
const httpsUrl = v.pipe(v.string(), v.check((text) => !/\s/.test(text), "an https URL without spaces"), v.check((text) => {
|
|
31
|
+
const url = urlOf(text);
|
|
32
|
+
return url?.protocol === "https:" && url.hostname.length > 0;
|
|
33
|
+
}, "a valid https URL with a host"), v.check((text) => {
|
|
34
|
+
const url = urlOf(text);
|
|
35
|
+
return !url?.username && !url?.password;
|
|
36
|
+
}, "an https URL without a user name or password, which would be committed"), v.check((text) => ![...(urlOf(text)?.searchParams.keys() ?? [])].some(secretName), "an https URL without a key or token in its query, which would be committed"),
|
|
37
|
+
// A token handed back in the fragment (OAuth's implicit flow) would be committed too; a description needs none.
|
|
38
|
+
v.check((text) => !urlOf(text)?.hash, "an https URL without a #fragment"));
|
|
39
|
+
const dotPath = v.pipe(v.string(), v.regex(/^[^.\s]+(\.[^.\s]+)*$/, "a dot path into the answer, such as data.id"));
|
|
40
|
+
const verify = v.optional(v.strictObject({ operation: v.pipe(v.string(), v.minLength(1)), id: dotPath, name: v.optional(dotPath) }));
|
|
10
41
|
const schema = v.strictObject({
|
|
11
42
|
identity: v.strictObject({
|
|
12
43
|
command: word,
|
|
@@ -17,38 +48,52 @@ const schema = v.strictObject({
|
|
|
17
48
|
}),
|
|
18
49
|
spec: v.strictObject({
|
|
19
50
|
kind: v.picklist(["openapi", "swagger"]),
|
|
20
|
-
from:
|
|
51
|
+
from: httpsUrl,
|
|
21
52
|
}),
|
|
22
53
|
auth: v.variant("preset", [
|
|
23
54
|
v.strictObject({ preset: v.literal("none") }),
|
|
24
|
-
v.strictObject({ preset: v.literal("token") }),
|
|
55
|
+
v.strictObject({ preset: v.literal("token"), verify }),
|
|
25
56
|
v.strictObject({
|
|
26
57
|
preset: v.literal("oauth2-pkce"),
|
|
58
|
+
verify,
|
|
27
59
|
scopes: v.array(v.string()),
|
|
28
60
|
scheme: v.optional(v.string()),
|
|
29
|
-
revokeUrl: v.optional(
|
|
61
|
+
revokeUrl: v.optional(httpsUrl),
|
|
30
62
|
authorizeParams: v.optional(v.record(v.string(), v.string())),
|
|
31
63
|
rotating: v.optional(v.boolean()),
|
|
32
64
|
redirect: v.optional(v.variant("kind", [
|
|
33
65
|
v.strictObject({ kind: v.literal("loopback"), host: v.optional(v.literal("localhost")) }),
|
|
34
|
-
v.strictObject({ kind: v.literal("relay"), url:
|
|
66
|
+
v.strictObject({ kind: v.literal("relay"), url: httpsUrl }),
|
|
35
67
|
])),
|
|
36
68
|
}),
|
|
37
69
|
]),
|
|
38
70
|
category: v.picklist(CLI_CATEGORIES),
|
|
39
71
|
source: v.optional(v.looseObject({})),
|
|
40
|
-
hooks: v.optional(v.pipe(v.string(), v.
|
|
72
|
+
hooks: v.optional(v.pipe(v.string(), v.regex(/^\.\/([^\s]*\/)?[^/\s.][^/\s]*\.[cm]?[jt]s$/, "a module in the project, such as ./src/hooks.ts"), v.check((text) => !/\.d\.[cm]?ts$/.test(text), "a module, not a .d.ts declaration file"), v.check((text) => !text.split(/[\\/]/).includes(".."), "a module in the project, without .."))),
|
|
41
73
|
});
|
|
42
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* The config checked against its shape; every error names where it is. A CRM CLI needs its source. `source` comes back
|
|
76
|
+
* unchecked: `parseCrmManifest` checks it against the generated API.
|
|
77
|
+
*/
|
|
43
78
|
export const parseCliConfig = (input) => {
|
|
44
79
|
const parsed = v.safeParse(schema, input);
|
|
45
80
|
if (!parsed.success) {
|
|
46
81
|
const [issue] = parsed.issues;
|
|
47
|
-
|
|
82
|
+
// valibot's own words for a key: "Invalid key: Expected never but received …". By the issue's shape, so a value
|
|
83
|
+
// that is undefined inside a list or record keeps valibot's words.
|
|
84
|
+
const keyed = issue.type === "strict_object" || issue.type === "variant";
|
|
85
|
+
const message = keyed && issue.expected === "never"
|
|
86
|
+
? "not a field of wirecat.config"
|
|
87
|
+
: keyed && issue.input === undefined
|
|
88
|
+
? "missing"
|
|
89
|
+
: issue.message;
|
|
90
|
+
throw new CliError("configuration_error", `wirecat.config: ${v.getDotPath(issue) ?? "(root)"}: ${message}`, {
|
|
48
91
|
reason: "manifest.invalid",
|
|
49
92
|
});
|
|
50
93
|
}
|
|
51
|
-
|
|
94
|
+
// Typed, not cast: a field CliConfig needs that the schema lacks or types otherwise fails to compile (not the reverse).
|
|
95
|
+
const output = parsed.output;
|
|
96
|
+
const config = output;
|
|
52
97
|
if (config.category !== "crm" && config.source)
|
|
53
98
|
throw new CliError("configuration_error", "wirecat.config: source: only a crm CLI reads a source yet", {
|
|
54
99
|
reason: "manifest.invalid",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.696.0",
|
|
4
4
|
"description": "The messenger-neutral half of a messaging CLI: domain model, message locators, rendering, name resolution, the SQLite seam, the command skeleton and shared read commands, the send guard, run records and the message store",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Viacheslav Ptsarev",
|