@wirecat/cli-core 0.692.0 → 0.693.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 +54 -0
- package/README.md +1 -1
- package/dist/background/daily-archive-timer.d.ts +1 -1
- package/dist/calendar/prepare.d.ts +11 -0
- package/dist/cli/bot/api-http.d.ts +4 -1
- package/dist/cli/bot/api-http.js +17 -4
- package/dist/cli/bot/api-input.d.ts +4 -0
- package/dist/cli/bot/api-input.js +9 -0
- package/dist/cli/bot/api.d.ts +4 -0
- package/dist/cli/bot/api.js +16 -2
- package/dist/cli/documents/words.d.ts +1 -1
- package/dist/cli/envelope.d.ts +22 -0
- package/dist/cli/index.d.ts +6 -4
- package/dist/cli/index.js +6 -4
- package/dist/cli/oauth-session.d.ts +60 -0
- package/dist/cli/oauth-session.js +224 -0
- package/dist/cli/service-api-call.d.ts +2 -1
- package/dist/cli/service-api-call.js +4 -6
- package/dist/cli/service-api-manifest.d.ts +10 -10
- package/dist/cli/service-api-manifest.js +37 -33
- package/dist/cli/service-api.d.ts +17 -2
- package/dist/cli/service-api.js +42 -24
- package/dist/cli/token-session.d.ts +33 -0
- package/dist/cli/token-session.js +121 -0
- package/dist/crm/index.d.ts +2 -1
- package/dist/crm/index.js +1 -0
- package/dist/crm/manifest/manifest.d.ts +19 -0
- package/dist/crm/manifest/manifest.js +6 -1
- package/dist/crm/manifest/map.d.ts +5 -0
- package/dist/crm/manifest/map.js +21 -15
- package/dist/crm/manifest/paths.d.ts +11 -0
- package/dist/crm/manifest/paths.js +161 -0
- package/dist/crm/manifest/source.js +105 -34
- package/dist/manifest/index.d.ts +53 -0
- package/dist/manifest/index.js +61 -0
- package/dist/services/metadata.d.ts +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { CrmManifest } from "../crm/manifest/manifest.js";
|
|
2
|
+
import type { OAuthProvider } from "../oauth/provider.js";
|
|
3
|
+
export type CliAuth = {
|
|
4
|
+
preset: "none";
|
|
5
|
+
}
|
|
6
|
+
/** A token or key, sent where the spec's `securitySchemes` say: a bearer header, an API key header or query. */
|
|
7
|
+
| {
|
|
8
|
+
preset: "token";
|
|
9
|
+
}
|
|
10
|
+
/** The browser sign-in the spec's authorization code flow declares; the redirect is what the app registered. */
|
|
11
|
+
| {
|
|
12
|
+
preset: "oauth2-pkce";
|
|
13
|
+
scopes: readonly string[];
|
|
14
|
+
scheme?: string;
|
|
15
|
+
redirect?: OAuthProvider["redirect"];
|
|
16
|
+
revokeUrl?: string;
|
|
17
|
+
authorizeParams?: Record<string, string>;
|
|
18
|
+
/** The provider sends a new refresh token on each refresh; the spec cannot say so. */
|
|
19
|
+
rotating?: boolean;
|
|
20
|
+
};
|
|
21
|
+
export declare const CLI_CATEGORIES: readonly ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "other"];
|
|
22
|
+
export type CliCategory = (typeof CLI_CATEGORIES)[number];
|
|
23
|
+
/** One file, `wirecat.config.ts`, that `new --from-config` builds a CLI from. */
|
|
24
|
+
export interface CliConfig {
|
|
25
|
+
identity: {
|
|
26
|
+
/** The word people type: `attio`. */
|
|
27
|
+
command: string;
|
|
28
|
+
/** `@wirecat/attio-cli`. */
|
|
29
|
+
package: string;
|
|
30
|
+
/** The environment variables' prefix: `WCATTIO`. */
|
|
31
|
+
prefix: string;
|
|
32
|
+
/** The name people know: `Attio`. */
|
|
33
|
+
service: string;
|
|
34
|
+
/** The GitHub owner of the repository. */
|
|
35
|
+
owner: string;
|
|
36
|
+
};
|
|
37
|
+
/** `from`: the https URL the description is published at. */
|
|
38
|
+
spec: {
|
|
39
|
+
kind: "openapi" | "swagger";
|
|
40
|
+
from: string;
|
|
41
|
+
};
|
|
42
|
+
auth: CliAuth;
|
|
43
|
+
/** cli-template's `--category`; `other` is any API outside them. */
|
|
44
|
+
category: CliCategory;
|
|
45
|
+
/** The CRM source; checked against the generated API by `parseCrmManifest` once the api group exists. */
|
|
46
|
+
source?: CrmManifest;
|
|
47
|
+
/** The module of named hooks, relative to the config: `./src/hooks.ts`. */
|
|
48
|
+
hooks?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Types the config in the editor; it returns what it is given. */
|
|
51
|
+
export declare const defineCli: (config: CliConfig) => CliConfig;
|
|
52
|
+
/** The config checked against its shape; every error names where it is. A CRM CLI needs its source. */
|
|
53
|
+
export declare const parseCliConfig: (input: unknown) => CliConfig;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { isAbsolute } from "node:path";
|
|
2
|
+
import { CliError } from "@wirecat/cli-base";
|
|
3
|
+
import * as v from "valibot";
|
|
4
|
+
export const CLI_CATEGORIES = ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "other"];
|
|
5
|
+
/** Types the config in the editor; it returns what it is given. */
|
|
6
|
+
export const defineCli = (config) => config;
|
|
7
|
+
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
|
+
/** In the project: no absolute path, no `..`, no scheme. */
|
|
9
|
+
const projectPath = (text) => !isAbsolute(text) && !text.split(/[\\/]/).includes("..") && !/^[a-z][a-z0-9+.-]*:/i.test(text);
|
|
10
|
+
const schema = v.strictObject({
|
|
11
|
+
identity: v.strictObject({
|
|
12
|
+
command: word,
|
|
13
|
+
package: v.pipe(v.string(), v.regex(/^(@[a-z0-9][a-z0-9._-]*\/)?[a-z0-9][a-z0-9._-]*$/, "an npm package name")),
|
|
14
|
+
prefix: v.pipe(v.string(), v.regex(/^[A-Z][A-Z0-9_]*$/, "upper-case letters, digits and underscores")),
|
|
15
|
+
service: v.pipe(v.string(), v.minLength(1)),
|
|
16
|
+
owner: v.pipe(v.string(), v.regex(/^[A-Za-z0-9](?:-?[A-Za-z0-9]){0,38}$/, "a GitHub owner")),
|
|
17
|
+
}),
|
|
18
|
+
spec: v.strictObject({
|
|
19
|
+
kind: v.picklist(["openapi", "swagger"]),
|
|
20
|
+
from: v.pipe(v.string(), v.check((text) => /^https:\/\/[^/\s]+/.test(text), "the https URL the description is published at")),
|
|
21
|
+
}),
|
|
22
|
+
auth: v.variant("preset", [
|
|
23
|
+
v.strictObject({ preset: v.literal("none") }),
|
|
24
|
+
v.strictObject({ preset: v.literal("token") }),
|
|
25
|
+
v.strictObject({
|
|
26
|
+
preset: v.literal("oauth2-pkce"),
|
|
27
|
+
scopes: v.array(v.string()),
|
|
28
|
+
scheme: v.optional(v.string()),
|
|
29
|
+
revokeUrl: v.optional(v.pipe(v.string(), v.startsWith("https://"))),
|
|
30
|
+
authorizeParams: v.optional(v.record(v.string(), v.string())),
|
|
31
|
+
rotating: v.optional(v.boolean()),
|
|
32
|
+
redirect: v.optional(v.variant("kind", [
|
|
33
|
+
v.strictObject({ kind: v.literal("loopback"), host: v.optional(v.literal("localhost")) }),
|
|
34
|
+
v.strictObject({ kind: v.literal("relay"), url: v.pipe(v.string(), v.startsWith("https://")) }),
|
|
35
|
+
])),
|
|
36
|
+
}),
|
|
37
|
+
]),
|
|
38
|
+
category: v.picklist(CLI_CATEGORIES),
|
|
39
|
+
source: v.optional(v.looseObject({})),
|
|
40
|
+
hooks: v.optional(v.pipe(v.string(), v.startsWith("./"), v.check(projectPath, "a module in the project"))),
|
|
41
|
+
});
|
|
42
|
+
/** The config checked against its shape; every error names where it is. A CRM CLI needs its source. */
|
|
43
|
+
export const parseCliConfig = (input) => {
|
|
44
|
+
const parsed = v.safeParse(schema, input);
|
|
45
|
+
if (!parsed.success) {
|
|
46
|
+
const [issue] = parsed.issues;
|
|
47
|
+
throw new CliError("configuration_error", `wirecat.config: ${v.getDotPath(issue) ?? "(root)"}: ${issue.message}`, {
|
|
48
|
+
reason: "manifest.invalid",
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const config = parsed.output;
|
|
52
|
+
if (config.category !== "crm" && config.source)
|
|
53
|
+
throw new CliError("configuration_error", "wirecat.config: source: only a crm CLI reads a source yet", {
|
|
54
|
+
reason: "manifest.invalid",
|
|
55
|
+
});
|
|
56
|
+
if (config.category === "crm" && !config.source)
|
|
57
|
+
throw new CliError("configuration_error", "wirecat.config: source: a crm CLI needs its source", {
|
|
58
|
+
reason: "manifest.invalid",
|
|
59
|
+
});
|
|
60
|
+
return config;
|
|
61
|
+
};
|
|
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
|
|
|
14
14
|
dryRun?: boolean;
|
|
15
15
|
}) => Promise<{
|
|
16
16
|
items: ({
|
|
17
|
+
error?: undefined;
|
|
17
18
|
chatId: string;
|
|
18
19
|
tags: import("../domain/channel-tags.js").ChannelTagMatch[];
|
|
19
20
|
algorithm: string;
|
|
20
21
|
fetchedAt: string | null;
|
|
21
22
|
source: string;
|
|
22
|
-
error?: undefined;
|
|
23
23
|
} | {
|
|
24
24
|
tags?: undefined;
|
|
25
25
|
algorithm?: undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wirecat/cli-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.693.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",
|
|
@@ -143,6 +143,10 @@
|
|
|
143
143
|
"types": "./dist/calendar/testing/index.d.ts",
|
|
144
144
|
"default": "./dist/calendar/testing/index.js"
|
|
145
145
|
},
|
|
146
|
+
"./manifest": {
|
|
147
|
+
"types": "./dist/manifest/index.d.ts",
|
|
148
|
+
"default": "./dist/manifest/index.js"
|
|
149
|
+
},
|
|
146
150
|
"./crm": {
|
|
147
151
|
"types": "./dist/crm/index.d.ts",
|
|
148
152
|
"default": "./dist/crm/index.js"
|
|
@@ -301,7 +305,7 @@
|
|
|
301
305
|
"@types/pngjs": "6.0.5",
|
|
302
306
|
"@types/ssh2": "1.15.5",
|
|
303
307
|
"@vitest/coverage-v8": "^5.0.5",
|
|
304
|
-
"@wirecat/cli-base": "0.
|
|
308
|
+
"@wirecat/cli-base": "0.112.0",
|
|
305
309
|
"@wirecat/cli-core-legacy-tags": "npm:@wirecat/cli-core@0.414.0",
|
|
306
310
|
"ajv": "8.17.1",
|
|
307
311
|
"commander": "15.0.0",
|
|
@@ -325,7 +329,7 @@
|
|
|
325
329
|
},
|
|
326
330
|
"peerDependencies": {
|
|
327
331
|
"@napi-rs/canvas": ">=0.1.69 <2",
|
|
328
|
-
"@wirecat/cli-base": ">=0.
|
|
332
|
+
"@wirecat/cli-base": ">=0.112.0 <1.0.0",
|
|
329
333
|
"commander": ">=15",
|
|
330
334
|
"mysql2": "^3.24.6",
|
|
331
335
|
"pg": "^8.23.1",
|