@wirecat/cli-core 0.696.0 → 0.697.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 +30 -0
- package/dist/cli/bot/api-http.d.ts +1 -1
- package/dist/cli/bot/api-http.js +77 -5
- package/dist/cli/bot/api-input.d.ts +5 -0
- package/dist/cli/bot/api-input.js +55 -0
- package/dist/cli/bot/api.d.ts +2 -0
- package/dist/cli/bot/api.js +12 -3
- package/dist/cli/messenger/store-maintenance-command.js +3 -2
- package/dist/cli/service-api-manifest.js +7 -4
- package/dist/cli/service-api.js +6 -2
- package/dist/crm/manifest/manifest.d.ts +2 -0
- package/dist/crm/manifest/manifest.js +2 -1
- package/dist/crm/manifest/map.d.ts +2 -1
- package/dist/crm/manifest/map.js +2 -1
- package/dist/domain/tracker.d.ts +100 -0
- package/dist/domain/tracker.js +28 -0
- package/dist/errors/reasons.js +1 -0
- package/dist/manifest/index.d.ts +9 -5
- package/dist/manifest/index.js +18 -7
- package/dist/store/exports.d.ts +1 -0
- package/dist/store/exports.js +1 -0
- package/dist/store/recover.js +2 -0
- package/dist/store/sqlite/account-purge.js +1 -0
- package/dist/store/sqlite/crm-files.d.ts +3 -0
- package/dist/store/sqlite/crm-files.js +2 -2
- package/dist/store/sqlite/manifest.js +2 -0
- package/dist/store/sqlite/migrations.generated.js +17 -0
- package/dist/store/sqlite/schema.d.ts +252 -0
- package/dist/store/sqlite/schema.js +28 -0
- package/dist/store/sqlite/tracker.d.ts +82 -0
- package/dist/store/sqlite/tracker.js +210 -0
- package/dist/store/store.d.ts +3 -0
- package/dist/store/store.js +5 -0
- package/dist/tracker/cli/index.d.ts +24 -0
- package/dist/tracker/cli/index.js +279 -0
- package/dist/tracker/index.d.ts +8 -0
- package/dist/tracker/index.js +7 -0
- package/dist/tracker/manifest/manifest.d.ts +76 -0
- package/dist/tracker/manifest/manifest.js +139 -0
- package/dist/tracker/manifest/map.d.ts +10 -0
- package/dist/tracker/manifest/map.js +86 -0
- package/dist/tracker/manifest/source.d.ts +18 -0
- package/dist/tracker/manifest/source.js +174 -0
- package/dist/tracker/source.d.ts +55 -0
- package/dist/tracker/source.js +1 -0
- package/dist/tracker/sync.d.ts +60 -0
- package/dist/tracker/sync.js +254 -0
- package/dist/tracker/tasks.d.ts +18 -0
- package/dist/tracker/tasks.js +29 -0
- package/dist/tracker/testing/index.d.ts +2 -0
- package/dist/tracker/testing/index.js +2 -0
- package/dist/tracker/testing/source-contract.d.ts +46 -0
- package/dist/tracker/testing/source-contract.js +246 -0
- package/dist/tracker/testing/source.d.ts +31 -0
- package/dist/tracker/testing/source.js +141 -0
- package/package.json +12 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,36 @@ Notable changes to `@wirecat/cli-core` (`@wirecat/cli-messaging` up to 0.261.0,
|
|
|
5
5
|
minor version may break callers, and says how under "Changed — may break callers". `pnpm docs:check` checks the
|
|
6
6
|
shape of this file.
|
|
7
7
|
|
|
8
|
+
## 0.697.0 — 17.11.2026
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- **The `api` group and `serviceApiCall` send a GraphQL operation** of a manifest that cli-base 0.115.0 generates
|
|
13
|
+
from a schema. Each call is one POST of the document `graphqlDocument` builds, never sent again on a redirect.
|
|
14
|
+
The variables are `--body` as one object with each flag over it, read by its schema: digits as written, `true` or
|
|
15
|
+
`false`, JSON for an input object. A variable the operation does not declare, or a required one left out, is
|
|
16
|
+
refused before anything is sent. The flags of a GraphQL operation are its body and stay out of the run's files.
|
|
17
|
+
- **`errors[]` is a failure even at HTTP 200.** A CLI's own `failure` names it first; else its `extensions.code`
|
|
18
|
+
does, repeated only when it is a plain constant, never the service's message. A write is `outcome_unknown` unless
|
|
19
|
+
the code says nothing ran and no data came back. The answer is `data.<field>`; `--all` pages by `pageInfo`.
|
|
20
|
+
- **`ApiCommandInput.selection`** gives a source a deeper selection than the generated one. `api list` and the run
|
|
21
|
+
record name a GraphQL operation as `POST` `query/issues`.
|
|
22
|
+
- **A tracker CLI can be described as data: `trackerSourceFromManifest`.** A `TrackerManifest` names, for each kind,
|
|
23
|
+
the list, changes and ids operations of the generated API and maps our fields to paths in a row, in the CRM
|
|
24
|
+
manifest's rule language. Over GraphQL each call may send its own selection, and `parseTrackerManifest` refuses a
|
|
25
|
+
map path the selection leaves out. `wirecat.config` takes `category: "tracker"` with its `source`, and
|
|
26
|
+
`spec.kind: "graphql"`. See [Trackers](docs/dev/TRACKER.md#a-tracker-described-as-data).
|
|
27
|
+
- **Issue trackers get their own category: `@wirecat/cli-core/tracker`.** A tracker CLI writes one `TrackerSource`
|
|
28
|
+
and gets the copy in the shared store (store version 70: `tracker_items` and the word index `tracker_item_words`),
|
|
29
|
+
`syncTracker` (changes by cursor, deletions by a daily id pass, a run budget that resumes where it stopped),
|
|
30
|
+
`addTrackerCommands` (`sync`, `issues list|show|search|task`, and `projects`, `teams`, `users`, `states`, `labels`
|
|
31
|
+
lists), and `/tracker/testing` with `trackerSourceContract` and `fakeTrackerSource`. `issues task` makes an issue
|
|
32
|
+
the owner's task by a link, copying only its key. See [Trackers](docs/dev/TRACKER.md).
|
|
33
|
+
|
|
34
|
+
### Changed — may break callers
|
|
35
|
+
|
|
36
|
+
- **cli-core needs `@wirecat/cli-base` 0.115.0 or later**, whose manifest has the `graphql` binding.
|
|
37
|
+
|
|
8
38
|
## 0.696.0 — 17.11.2026
|
|
9
39
|
|
|
10
40
|
### Added
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CliError } from "@wirecat/cli-base";
|
|
2
|
-
import type
|
|
2
|
+
import { type ManifestOperation } from "@wirecat/cli-base/codegen";
|
|
3
3
|
import { type FetchLike } from "@wirecat/cli-base/http";
|
|
4
4
|
import type { Command } from "commander";
|
|
5
5
|
import type { ApiCommandInput } from "./api.js";
|
package/dist/cli/bot/api-http.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CliError, wallClock } from "@wirecat/cli-base";
|
|
2
|
+
import { graphqlDocument } from "@wirecat/cli-base/codegen";
|
|
2
3
|
import { providerWaitMs, readJsonResponse, statusToCode } from "@wirecat/cli-base/http";
|
|
3
4
|
import { providerRequest } from "../command-runs.js";
|
|
4
5
|
import { outputFor } from "../context.js";
|
|
5
6
|
import { itemOf, renderAnswer } from "../envelope.js";
|
|
6
|
-
import { parseApiJson, sendsBytes } from "./api-input.js";
|
|
7
|
+
import { apiJson, graphqlVariables, parseApiJson, sendsBytes } from "./api-input.js";
|
|
7
8
|
const LARGEST_ANSWER = 16 * 1024 * 1024;
|
|
8
9
|
/** `new URL` folds a `.` or `..` segment into its parent, so such an id would reach another endpoint. */
|
|
9
10
|
const segment = (name, value) => {
|
|
@@ -21,12 +22,14 @@ export const unsendableBody = (operation) => {
|
|
|
21
22
|
/** One generated HTTP operation and its flags as the request they stand for; nothing is sent. */
|
|
22
23
|
export const httpApiRequest = (operation, input, baseUrl) => {
|
|
23
24
|
const { binding } = operation;
|
|
24
|
-
if (binding.kind !== "http")
|
|
25
|
+
if (binding.kind !== "http" && binding.kind !== "graphql")
|
|
25
26
|
throw new CliError("configuration_error", `${operation.command} is not an HTTP operation`);
|
|
26
27
|
if (unsendableBody(operation))
|
|
27
28
|
throw new CliError("validation_error", `${operation.command} sends ${operation.request?.contentType}, which the generated command cannot send; nothing was sent`, { sent: false });
|
|
28
29
|
if (operation.response?.sensitive)
|
|
29
30
|
throw new CliError("validation_error", `${operation.command} answers with a credential, which the generated command never prints; nothing was sent`, { sent: false });
|
|
31
|
+
if (binding.kind === "graphql")
|
|
32
|
+
return graphqlRequest(operation, binding, input, baseUrl);
|
|
30
33
|
if (Object.keys(input.fields).length > 0)
|
|
31
34
|
throw new CliError("configuration_error", `${operation.command} has body fields as flags, which HTTP cannot send`);
|
|
32
35
|
if (!/^\/(?!\/)/.test(binding.path))
|
|
@@ -58,8 +61,70 @@ export const httpApiRequest = (operation, input, baseUrl) => {
|
|
|
58
61
|
headers.set("content-type", "application/json");
|
|
59
62
|
return { method: binding.method, url, headers, ...(body === undefined ? {} : { body }) };
|
|
60
63
|
};
|
|
64
|
+
/** One GraphQL operation as a POST of its one document to the endpoint, with its variables. */
|
|
65
|
+
const graphqlRequest = (operation, binding, input, baseUrl) => {
|
|
66
|
+
const variables = graphqlVariables(operation, input.body, input.fields);
|
|
67
|
+
const headers = new Headers(input.headers);
|
|
68
|
+
headers.set("accept", "application/json");
|
|
69
|
+
headers.set("content-type", "application/json");
|
|
70
|
+
const query = graphqlDocument(binding, input.selection);
|
|
71
|
+
// A 307 or 308 would send the variables again, to wherever it points.
|
|
72
|
+
return { method: "POST", url: new URL(baseUrl), headers, body: apiJson({ query, variables }), redirect: "error" };
|
|
73
|
+
};
|
|
61
74
|
/** `/v1/pages/{page_id}` → `/v1/pages/:page_id`: the run record keeps the template, never an id. */
|
|
62
75
|
const templateOf = (path) => path.replace(/\{([^}]+)\}/g, ":$1");
|
|
76
|
+
/** What the run record names a request by: the path template, or a GraphQL operation's root field. */
|
|
77
|
+
const endpointOf = (operation) => operation.binding.kind === "http"
|
|
78
|
+
? templateOf(operation.binding.path)
|
|
79
|
+
: operation.binding.kind === "graphql"
|
|
80
|
+
? `${operation.binding.operation}/${operation.binding.field}`
|
|
81
|
+
: "";
|
|
82
|
+
// Common GraphQL server codes (Apollo's names) as the CLI's; any other is the provider's.
|
|
83
|
+
const GRAPHQL_CODES = {
|
|
84
|
+
UNAUTHENTICATED: "authentication_error",
|
|
85
|
+
AUTHENTICATION_ERROR: "authentication_error",
|
|
86
|
+
FORBIDDEN: "permission_error",
|
|
87
|
+
RATELIMITED: "rate_limited",
|
|
88
|
+
BAD_USER_INPUT: "validation_error",
|
|
89
|
+
GRAPHQL_VALIDATION_FAILED: "validation_error",
|
|
90
|
+
INVALID_INPUT: "validation_error",
|
|
91
|
+
};
|
|
92
|
+
// A refusal of these kinds means the service did nothing, so a write that got one is not in doubt.
|
|
93
|
+
const NOTHING_RAN = new Set(["authentication_error", "permission_error", "rate_limited", "validation_error"]);
|
|
94
|
+
/**
|
|
95
|
+
* A GraphQL answer comes with HTTP 200 even when it failed: `errors[]` is the failure, named by the CLI's own
|
|
96
|
+
* `failure`, else by its first `extensions.code`, never by the service's message (WC-SECR-6). A write that failed in
|
|
97
|
+
* any other way, or answered data too, may have landed (WC-LIFE-9). Otherwise the answer is `data.<field>`.
|
|
98
|
+
*/
|
|
99
|
+
const graphqlAnswer = (options, operation, answer) => {
|
|
100
|
+
const { binding } = operation;
|
|
101
|
+
if (binding.kind !== "graphql")
|
|
102
|
+
return answer;
|
|
103
|
+
const { data, errors } = (answer ?? {});
|
|
104
|
+
if (Array.isArray(errors) && errors.length > 0) {
|
|
105
|
+
const own = options.failure?.(200, answer, operation);
|
|
106
|
+
if (own)
|
|
107
|
+
throw own;
|
|
108
|
+
const raw = errors[0]?.extensions?.code;
|
|
109
|
+
// The code is the service's text too: only a plain constant is repeated.
|
|
110
|
+
const code = typeof raw === "string" && /^[A-Z][A-Z0-9_]{0,40}$/.test(raw) ? raw : undefined;
|
|
111
|
+
const known = (code && GRAPHQL_CODES[code]) || "provider_error";
|
|
112
|
+
const writes = operation.effect !== "read";
|
|
113
|
+
if (writes && (!NOTHING_RAN.has(known) || data?.[binding.field] != null))
|
|
114
|
+
return outcomeUnknown(options.service);
|
|
115
|
+
throw new CliError(known, `${options.service} refused ${operation.command}${code ? ` (${code})` : ""}`, {
|
|
116
|
+
retryable: known === "rate_limited",
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
if (!data || !(binding.field in data))
|
|
120
|
+
throw new CliError("invalid_response", `${options.service} answered ${operation.command} without data.${binding.field}`);
|
|
121
|
+
return data[binding.field];
|
|
122
|
+
};
|
|
123
|
+
const outcomeUnknown = (service) => {
|
|
124
|
+
throw new CliError("outcome_unknown", `${service} did not confirm a write; check it before repeating the write`, {
|
|
125
|
+
retryable: false,
|
|
126
|
+
});
|
|
127
|
+
};
|
|
63
128
|
const answerOf = async (response, maxBytes) => {
|
|
64
129
|
if (response.status === 204 || !response.body || response.headers.get("content-length") === "0")
|
|
65
130
|
return {};
|
|
@@ -71,7 +136,7 @@ const answerOf = async (response, maxBytes) => {
|
|
|
71
136
|
*/
|
|
72
137
|
export const httpApiSend = (options) => async (command, operation, request) => {
|
|
73
138
|
const writes = operation.effect !== "read";
|
|
74
|
-
const template =
|
|
139
|
+
const template = endpointOf(operation);
|
|
75
140
|
const end = providerRequest(`${request.method} ${template}`, undefined, {
|
|
76
141
|
method: request.method,
|
|
77
142
|
endpointTemplate: template,
|
|
@@ -109,8 +174,15 @@ export const httpApiSend = (options) => async (command, operation, request) => {
|
|
|
109
174
|
end({ status, error: failed });
|
|
110
175
|
throw failed;
|
|
111
176
|
}
|
|
112
|
-
|
|
113
|
-
|
|
177
|
+
try {
|
|
178
|
+
const result = graphqlAnswer(options, operation, answer);
|
|
179
|
+
end({ status });
|
|
180
|
+
return result;
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
end({ status, error });
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
114
186
|
};
|
|
115
187
|
/**
|
|
116
188
|
* The `execute` of `generatedApiCommand` for any OpenAPI CLI: fills the path, adds the query, sends the JSON body
|
|
@@ -15,3 +15,8 @@ export declare const checkApiBody: (operation: ManifestOperation, text: string |
|
|
|
15
15
|
export declare const parseApiJson: (text: string) => unknown;
|
|
16
16
|
export declare const apiJson: (value: unknown) => string;
|
|
17
17
|
export declare const apiPlainJson: (value: unknown) => unknown;
|
|
18
|
+
/**
|
|
19
|
+
* A GraphQL operation's variables: the body's (`--body`, all of them as one object) with each flag over it, read by
|
|
20
|
+
* the variable's schema. A name the operation does not declare, or a required one left out, is refused unsent.
|
|
21
|
+
*/
|
|
22
|
+
export declare const graphqlVariables: (operation: ManifestOperation, body: string | undefined, fields: Readonly<Record<string, string>>) => Record<string, unknown>;
|
|
@@ -118,3 +118,58 @@ const finite = (key, value) => {
|
|
|
118
118
|
};
|
|
119
119
|
export const apiJson = (value) => stringify(value, finite) ?? "null";
|
|
120
120
|
export const apiPlainJson = (value) => JSON.parse(stringify(value, (key, inner) => isLosslessNumber(inner) && !isSafeNumber(inner.value) ? inner.toString() : finite(key, inner)) ?? "null");
|
|
121
|
+
/** A JSON object with no lossless number at its top: what a GraphQL body of variables must be. */
|
|
122
|
+
const isVariables = (value) => value !== null && typeof value === "object" && !Array.isArray(value) && !isLosslessNumber(value);
|
|
123
|
+
/**
|
|
124
|
+
* A GraphQL operation's variables: the body's (`--body`, all of them as one object) with each flag over it, read by
|
|
125
|
+
* the variable's schema. A name the operation does not declare, or a required one left out, is refused unsent.
|
|
126
|
+
*/
|
|
127
|
+
export const graphqlVariables = (operation, body, fields) => {
|
|
128
|
+
const { binding } = operation;
|
|
129
|
+
if (binding.kind !== "graphql")
|
|
130
|
+
throw new CliError("configuration_error", `${operation.command} is not a GraphQL operation`);
|
|
131
|
+
const given = body?.trim() ? parseApiJson(body) : {};
|
|
132
|
+
if (!isVariables(given))
|
|
133
|
+
throw new CliError("validation_error", `${operation.command} takes its variables as one JSON object`, {
|
|
134
|
+
sent: false,
|
|
135
|
+
});
|
|
136
|
+
const variables = { ...given };
|
|
137
|
+
for (const [name, raw] of Object.entries(fields)) {
|
|
138
|
+
const schema = operation.parameters.find((one) => one.in === "body" && one.name === name)?.schema;
|
|
139
|
+
variables[name] = flagValue(operation, name, raw, schema?.type);
|
|
140
|
+
}
|
|
141
|
+
const unknown = Object.keys(variables).filter((name) => !(name in binding.variables));
|
|
142
|
+
if (unknown.length > 0)
|
|
143
|
+
throw new CliError("validation_error", `${operation.command} has no variable ${unknown.join(", ")}`, {
|
|
144
|
+
sent: false,
|
|
145
|
+
});
|
|
146
|
+
const missing = Object.entries(binding.variables)
|
|
147
|
+
.filter(([name, type]) => type.endsWith("!") && variables[name] == null)
|
|
148
|
+
.map(([name]) => `--${apiFlagOf(name)}`);
|
|
149
|
+
if (missing.length > 0)
|
|
150
|
+
throw new CliError("validation_error", `${operation.command} needs ${missing.join(", ")}`, { sent: false });
|
|
151
|
+
return variables;
|
|
152
|
+
};
|
|
153
|
+
const DECIMAL = /^-?\d+(\.\d+)?$/;
|
|
154
|
+
const flagValue = (operation, name, raw, type) => {
|
|
155
|
+
const flag = `--${apiFlagOf(name)} of ${operation.command}`;
|
|
156
|
+
if (type === "integer" || type === "number") {
|
|
157
|
+
// Number() would take 0x10 and 1e1, and round a long id; the digits go as written.
|
|
158
|
+
if (!(type === "integer" ? DIGITS : DECIMAL).test(raw.trim()))
|
|
159
|
+
throw new CliError("validation_error", `${flag} takes ${type === "integer" ? "a whole number" : "a number"}`, {
|
|
160
|
+
sent: false,
|
|
161
|
+
});
|
|
162
|
+
return new LosslessNumber(raw.trim());
|
|
163
|
+
}
|
|
164
|
+
if (type === "boolean") {
|
|
165
|
+
if (raw !== "true" && raw !== "false")
|
|
166
|
+
throw new CliError("validation_error", `${flag} takes true or false`, { sent: false });
|
|
167
|
+
return raw === "true";
|
|
168
|
+
}
|
|
169
|
+
if (type === "object" || type === "array" || type === "unknown")
|
|
170
|
+
return parseApiJson(raw);
|
|
171
|
+
// An input object or a list given as JSON; an enum's value, behind a ref too, is a bare word.
|
|
172
|
+
if (type === "ref" && /^\s*[{["]/.test(raw))
|
|
173
|
+
return parseApiJson(raw);
|
|
174
|
+
return raw;
|
|
175
|
+
};
|
package/dist/cli/bot/api.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ export interface ApiCommandInput {
|
|
|
10
10
|
bytes?: Uint8Array<ArrayBuffer>;
|
|
11
11
|
bodySource?: "argument" | "stdin" | "file";
|
|
12
12
|
tokenProfile?: string;
|
|
13
|
+
/** A GraphQL operation's selection in place of its default, for a source that needs more than one level. */
|
|
14
|
+
selection?: string;
|
|
13
15
|
}
|
|
14
16
|
export interface ApiCommands {
|
|
15
17
|
operations: readonly ManifestOperation[];
|
package/dist/cli/bot/api.js
CHANGED
|
@@ -3,7 +3,7 @@ import { annotate } from "@wirecat/cli-base/commands";
|
|
|
3
3
|
import { Command, Option } from "commander";
|
|
4
4
|
import { secretInput } from "../../runs/run-context.js";
|
|
5
5
|
import { REMOTE_READ, REMOTE_WRITE } from "../effects.js";
|
|
6
|
-
import { apiFlagOf, apiOptionKey, readApiBody, readApiBytes, sendsBytes } from "./api-input.js";
|
|
6
|
+
import { apiFlagOf, apiJson, apiOptionKey, graphqlVariables, readApiBody, readApiBytes, sendsBytes, } from "./api-input.js";
|
|
7
7
|
const scalarOf = (value) => typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value) : undefined;
|
|
8
8
|
export const generatedApiCommand = (api) => {
|
|
9
9
|
const group = new Command("api").description(api.description ?? "every operation of the official Bot API, generated from its schema");
|
|
@@ -11,7 +11,9 @@ export const generatedApiCommand = (api) => {
|
|
|
11
11
|
for (const operation of api.operations) {
|
|
12
12
|
const binding = operation.binding.kind === "http"
|
|
13
13
|
? `${operation.binding.method} ${operation.binding.path}`
|
|
14
|
-
: operation.binding.
|
|
14
|
+
: operation.binding.kind === "graphql"
|
|
15
|
+
? `${operation.binding.operation} ${operation.binding.field}`
|
|
16
|
+
: operation.binding.name;
|
|
15
17
|
const command = annotate(new Command(operation.command), {
|
|
16
18
|
effects: operation.effect === "read" ? REMOTE_READ : REMOTE_WRITE,
|
|
17
19
|
}).description(`${operation.summary ?? operation.id} — ${operation.effect} (${binding})`);
|
|
@@ -19,6 +21,9 @@ export const generatedApiCommand = (api) => {
|
|
|
19
21
|
if (parameter.sensitive)
|
|
20
22
|
continue;
|
|
21
23
|
const option = new Option(`--${apiFlagOf(parameter.name)} <value>`, parameter.description?.split("\n")[0] ?? parameter.name);
|
|
24
|
+
// A GraphQL flag is the request body, which never reaches the run's files (SEC-196).
|
|
25
|
+
if (operation.binding.kind === "graphql" && parameter.in === "body")
|
|
26
|
+
secretInput(option);
|
|
22
27
|
if (parameter.required && parameter.in !== "body") {
|
|
23
28
|
// A required parameter the spec gives a default (Notion's `Notion-Version`) is sent with it, never asked for.
|
|
24
29
|
const fallback = scalarOf(parameter.schema.default);
|
|
@@ -85,7 +90,11 @@ export const generatedApiCommand = (api) => {
|
|
|
85
90
|
input.bodySource = options.body === "-" ? "stdin" : "argument";
|
|
86
91
|
else if (options.bodyFile !== undefined)
|
|
87
92
|
input.bodySource = options.bodyFile === "-" ? "stdin" : "file";
|
|
88
|
-
|
|
93
|
+
// A GraphQL body is all the variables: the flags join it here, so the schema check sees what is sent.
|
|
94
|
+
const given = operation.binding.kind === "graphql" ? apiJson(graphqlVariables(operation, text, input.fields)) : text;
|
|
95
|
+
if (operation.binding.kind === "graphql")
|
|
96
|
+
input.fields = {};
|
|
97
|
+
const body = operation.binding.kind === "rpc" ? text : api.checkBody ? api.checkBody(operation, given) : given;
|
|
89
98
|
if (body !== undefined)
|
|
90
99
|
input.body = body;
|
|
91
100
|
await api.execute(this, operation, input);
|
|
@@ -16,7 +16,7 @@ import { migrate } from "../../store/migrations.js";
|
|
|
16
16
|
import { openCache } from "../../store/open.js";
|
|
17
17
|
import { storePath } from "../../store/path.js";
|
|
18
18
|
import { deleteCopy, repairStore } from "../../store/repair.js";
|
|
19
|
-
import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetCrmFileWords, resetNoteIndex, resetSearchIndex, resetStems, rollBack, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
|
|
19
|
+
import { drainNoteIndex, dropAllUnusedVectors, fillSearchIndex, fillStems, involvementStoreOver, noteIndexState, openSqlite, openStore, orphanPointers, pendingNormalization, resetAttachmentWords, resetCrmFileWords, resetNoteIndex, resetSearchIndex, resetStems, resetTrackerItemWords, rollBack, searchIndexState, stemmerCache, stemsState, vectorIndexCounts, } from "../../store/store.js";
|
|
20
20
|
import { environmentOf, outputFor } from "../context.js";
|
|
21
21
|
import { destroysNothing, grantsAuthority, LOCAL_READ, LOCAL_WRITE } from "../effects.js";
|
|
22
22
|
import { itemOf, renderAnswer, snakeKeys } from "../envelope.js";
|
|
@@ -327,6 +327,7 @@ const inspect = (path) => reading(path, (database) => {
|
|
|
327
327
|
...(stems ? [["message_stems", indexIntegrity(database, "message_stems", 0)]] : []),
|
|
328
328
|
...(schema.version > 0 ? [["attachment_words", indexIntegrity(database, "attachment_words", 0)]] : []),
|
|
329
329
|
...(schema.version >= 68 ? [["crm_file_words", indexIntegrity(database, "crm_file_words", 0)]] : []),
|
|
330
|
+
...(schema.version >= 70 ? [["tracker_item_words", indexIntegrity(database, "tracker_item_words", 0)]] : []),
|
|
330
331
|
]);
|
|
331
332
|
const size = bytesOf(path) + bytesOf(`${path}-wal`);
|
|
332
333
|
const { bavail, bsize } = statfsSync(dirname(path));
|
|
@@ -531,7 +532,7 @@ const reindexCommand = (owner) => destroysNothing(annotate(new Command("rebuild"
|
|
|
531
532
|
throw new CliError("validation_error", `the store is behind this build — \`${lineOf(this, "store migrate")}\` first`);
|
|
532
533
|
}
|
|
533
534
|
resetSearchIndex(database);
|
|
534
|
-
const fileTexts = resetAttachmentWords(database) + resetCrmFileWords(database);
|
|
535
|
+
const fileTexts = resetAttachmentWords(database) + resetCrmFileWords(database) + resetTrackerItemWords(database);
|
|
535
536
|
const words = buildWordIndex(database, (note) => renderer.note(note));
|
|
536
537
|
return {
|
|
537
538
|
path,
|
|
@@ -126,14 +126,17 @@ const numberOf = (value) => {
|
|
|
126
126
|
};
|
|
127
127
|
export const parameterValue = (input, parameter) => parameter.in === "query"
|
|
128
128
|
? input.query[parameter.name]
|
|
129
|
-
: input.
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
: (input.fields[parameter.name] ??
|
|
130
|
+
(input.body === undefined
|
|
131
|
+
? undefined
|
|
132
|
+
: parseApiJson(input.body)?.[parameter.name]));
|
|
132
133
|
export const withValue = (input, parameter, value) => {
|
|
133
134
|
if (parameter.in === "query")
|
|
134
135
|
return { ...input, query: { ...input.query, [parameter.name]: String(value) } };
|
|
135
136
|
const body = input.body === undefined ? {} : parseApiJson(input.body);
|
|
136
|
-
|
|
137
|
+
// A flag of the same name would stand over the body, and every page would ask for the first.
|
|
138
|
+
const { [parameter.name]: _, ...fields } = input.fields;
|
|
139
|
+
return { ...input, fields, body: apiJson({ ...body, [parameter.name]: value }) };
|
|
137
140
|
};
|
|
138
141
|
/** Reads one answer by the manifest's pagination: where its items are and what the next request is. */
|
|
139
142
|
export const nextPage = (pagination, input, answer) => {
|
package/dist/cli/service-api.js
CHANGED
|
@@ -83,8 +83,12 @@ export const serviceApiPermissions = (input) => {
|
|
|
83
83
|
};
|
|
84
84
|
const rowOf = (operation) => ({
|
|
85
85
|
command: operation.command,
|
|
86
|
-
method: operation.binding.kind === "http" ? operation.binding.method : "",
|
|
87
|
-
path: operation.binding.kind === "http"
|
|
86
|
+
method: operation.binding.kind === "http" ? operation.binding.method : operation.binding.kind === "graphql" ? "POST" : "",
|
|
87
|
+
path: operation.binding.kind === "http"
|
|
88
|
+
? operation.binding.path
|
|
89
|
+
: operation.binding.kind === "graphql"
|
|
90
|
+
? `${operation.binding.operation} ${operation.binding.field}`
|
|
91
|
+
: "",
|
|
88
92
|
effect: operation.effect,
|
|
89
93
|
summary: operation.summary ?? "",
|
|
90
94
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as v from "valibot";
|
|
1
2
|
import type { ServiceApiCall } from "../../cli/service-api-call.js";
|
|
2
3
|
import type { ServiceApiManifest } from "../../cli/service-api-manifest.js";
|
|
3
4
|
import { type CrmKind, type CrmRecords } from "../../domain/crm.js";
|
|
@@ -188,6 +189,7 @@ export interface CrmManifestHooks {
|
|
|
188
189
|
/** Adds or replaces source methods (`self`, `activities`, a live `list`); `base` is what the manifest built. */
|
|
189
190
|
extend?: (base: CrmSource) => Partial<CrmSource>;
|
|
190
191
|
}
|
|
192
|
+
export declare const crmRuleSchema: v.GenericSchema<CrmRule>;
|
|
191
193
|
/**
|
|
192
194
|
* The manifest checked against its shape and the generated API: each operation exists, a list pages or says where its
|
|
193
195
|
* rows are, a change call places `{since}`, a deal or lead kind has pipelines. Every error names where it is.
|
|
@@ -6,7 +6,7 @@ import { editDistance } from "../../search/correct.js";
|
|
|
6
6
|
import { FIELDS } from "./map.js";
|
|
7
7
|
const path = v.pipe(v.string(), v.regex(/^[^.\s]+(\.[^.\s]+)*$/, "a dotted path such as properties.name"));
|
|
8
8
|
const paths = v.pipe(v.array(path), v.minLength(1));
|
|
9
|
-
const
|
|
9
|
+
export const crmRuleSchema = v.union([
|
|
10
10
|
path,
|
|
11
11
|
v.strictObject({ first: paths }),
|
|
12
12
|
v.strictObject({ join: paths }),
|
|
@@ -18,6 +18,7 @@ const rule = v.union([
|
|
|
18
18
|
v.strictObject({ value: v.unknown() }),
|
|
19
19
|
v.function(),
|
|
20
20
|
], "a path, one of first, join, all, path, each, value, or a function");
|
|
21
|
+
const rule = crmRuleSchema;
|
|
21
22
|
const call = v.strictObject({
|
|
22
23
|
operation: v.pipe(v.string(), v.minLength(1)),
|
|
23
24
|
path: v.optional(v.record(v.string(), v.string())),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CrmField, CrmKind, CrmRecords } from "../../domain/crm.js";
|
|
2
|
-
import { type CrmRaw, id, text } from "../values.js";
|
|
2
|
+
import { type CrmRaw, id, number, text } from "../values.js";
|
|
3
3
|
import type { CrmRule } from "./manifest.js";
|
|
4
4
|
/** The service sent nothing at this path: the field is left out, so the stored copy keeps what it held. */
|
|
5
5
|
export declare const MISSING: unique symbol;
|
|
@@ -18,6 +18,7 @@ declare const CONVERT: {
|
|
|
18
18
|
epoch: typeof epochOf;
|
|
19
19
|
day: typeof dayOf;
|
|
20
20
|
bool: typeof yes;
|
|
21
|
+
number: typeof number;
|
|
21
22
|
texts: (value: unknown) => string[];
|
|
22
23
|
ids: (value: unknown) => string[];
|
|
23
24
|
status: (value: unknown) => string | null;
|
package/dist/crm/manifest/map.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DEAL_STATUSES } from "../../domain/deals.js";
|
|
2
|
-
import { amountOf, crmValuesOf, epoch, fullName, id, isRaw, text } from "../values.js";
|
|
2
|
+
import { amountOf, crmValuesOf, epoch, fullName, id, isRaw, number, text } from "../values.js";
|
|
3
3
|
/** The service sent nothing at this path: the field is left out, so the stored copy keeps what it held. */
|
|
4
4
|
export const MISSING = Symbol("missing");
|
|
5
5
|
/** A dotted path; a number steps into a list (`results.0.id`), and `.` is the value itself. */
|
|
@@ -86,6 +86,7 @@ const CONVERT = {
|
|
|
86
86
|
epoch: epochOf,
|
|
87
87
|
day: dayOf,
|
|
88
88
|
bool: yes,
|
|
89
|
+
number,
|
|
89
90
|
texts: (value) => unique(listOf(value).map(text)),
|
|
90
91
|
ids: (value) => linksOf(value).map(({ externalId }) => externalId),
|
|
91
92
|
status: (value) => {
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an issue tracker holds that the store copies (Linear, and any tracker after it): its teams, users, workflow
|
|
3
|
+
* states, labels, projects, issues and the comments on them. Teams, users, states and labels come before the
|
|
4
|
+
* projects and issues that name them.
|
|
5
|
+
*/
|
|
6
|
+
export declare const TRACKER_KINDS: readonly ["team", "user", "state", "label", "project", "issue", "comment"];
|
|
7
|
+
export type TrackerKind = (typeof TRACKER_KINDS)[number];
|
|
8
|
+
/** Where an issue in a state stands in its work, whatever the team named the state. */
|
|
9
|
+
export declare const STATE_TYPES: readonly ["triage", "backlog", "unstarted", "started", "completed", "canceled"];
|
|
10
|
+
export type StateType = (typeof STATE_TYPES)[number];
|
|
11
|
+
/**
|
|
12
|
+
* Every record has the tracker's id. A field left out means the tracker did not say, and the store keeps what it
|
|
13
|
+
* held; `null` means the tracker said there is none. Times are epoch milliseconds.
|
|
14
|
+
*/
|
|
15
|
+
interface TrackerRecord {
|
|
16
|
+
externalId: string;
|
|
17
|
+
createdAt?: number | null;
|
|
18
|
+
updatedAt?: number | null;
|
|
19
|
+
/** The tracker archived it: it still exists, and a read that asks for archived rows lists it. */
|
|
20
|
+
archivedAt?: number | null;
|
|
21
|
+
}
|
|
22
|
+
export interface TrackerTeam extends TrackerRecord {
|
|
23
|
+
name: string;
|
|
24
|
+
/** The short key an issue's key starts with: `ENG`. */
|
|
25
|
+
key?: string | null;
|
|
26
|
+
}
|
|
27
|
+
export interface TrackerUser extends TrackerRecord {
|
|
28
|
+
name: string;
|
|
29
|
+
/** How the store joins the user to a person it already knows: by this exact address. */
|
|
30
|
+
email?: string | null;
|
|
31
|
+
active?: boolean | null;
|
|
32
|
+
}
|
|
33
|
+
export interface TrackerState extends TrackerRecord {
|
|
34
|
+
name: string;
|
|
35
|
+
type: StateType;
|
|
36
|
+
team?: string | null;
|
|
37
|
+
/** Any numbers; the order they give is the board's. */
|
|
38
|
+
position?: number | null;
|
|
39
|
+
}
|
|
40
|
+
export interface TrackerLabel extends TrackerRecord {
|
|
41
|
+
name: string;
|
|
42
|
+
team?: string | null;
|
|
43
|
+
}
|
|
44
|
+
export interface TrackerProject extends TrackerRecord {
|
|
45
|
+
name: string;
|
|
46
|
+
description?: string | null;
|
|
47
|
+
/** The tracker's own word for where the project stands: `planned`, `started`. */
|
|
48
|
+
status?: string | null;
|
|
49
|
+
/** A user's id. */
|
|
50
|
+
lead?: string | null;
|
|
51
|
+
teams?: string[];
|
|
52
|
+
/** `YYYY-MM-DD`. */
|
|
53
|
+
targetDate?: string | null;
|
|
54
|
+
url?: string | null;
|
|
55
|
+
}
|
|
56
|
+
export interface TrackerIssue extends TrackerRecord {
|
|
57
|
+
title: string;
|
|
58
|
+
/** The readable key people say: `ENG-12`. */
|
|
59
|
+
key?: string | null;
|
|
60
|
+
description?: string | null;
|
|
61
|
+
state?: string | null;
|
|
62
|
+
team?: string | null;
|
|
63
|
+
project?: string | null;
|
|
64
|
+
/** Users' ids. */
|
|
65
|
+
assignee?: string | null;
|
|
66
|
+
creator?: string | null;
|
|
67
|
+
labels?: string[];
|
|
68
|
+
/** The issue this one is a part of. */
|
|
69
|
+
parent?: string | null;
|
|
70
|
+
/** 0 is none, then 1 the most urgent: Linear's scale, which a tracker with another one maps onto. */
|
|
71
|
+
priority?: number | null;
|
|
72
|
+
/** `YYYY-MM-DD`. */
|
|
73
|
+
dueDate?: string | null;
|
|
74
|
+
completedAt?: number | null;
|
|
75
|
+
canceledAt?: number | null;
|
|
76
|
+
url?: string | null;
|
|
77
|
+
}
|
|
78
|
+
export interface TrackerComment extends TrackerRecord {
|
|
79
|
+
issue: string;
|
|
80
|
+
body: string;
|
|
81
|
+
/** A user's id; none when an integration wrote it. */
|
|
82
|
+
author?: string | null;
|
|
83
|
+
url?: string | null;
|
|
84
|
+
}
|
|
85
|
+
export interface TrackerRecords {
|
|
86
|
+
team: TrackerTeam;
|
|
87
|
+
user: TrackerUser;
|
|
88
|
+
state: TrackerState;
|
|
89
|
+
label: TrackerLabel;
|
|
90
|
+
project: TrackerProject;
|
|
91
|
+
issue: TrackerIssue;
|
|
92
|
+
comment: TrackerComment;
|
|
93
|
+
}
|
|
94
|
+
/** The record's title in lists and search: an issue's title, a comment's start, anything else's name. */
|
|
95
|
+
export declare const trackerTitleOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string;
|
|
96
|
+
/** The record's text that search reads beside its title: a description or a comment's body. */
|
|
97
|
+
export declare const trackerBodyOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string | null | undefined;
|
|
98
|
+
/** The record its row hangs under: a comment's issue, a state's or a label's team. */
|
|
99
|
+
export declare const trackerParentOf: <K extends TrackerKind>(kind: K, record: TrackerRecords[K]) => string | null | undefined;
|
|
100
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an issue tracker holds that the store copies (Linear, and any tracker after it): its teams, users, workflow
|
|
3
|
+
* states, labels, projects, issues and the comments on them. Teams, users, states and labels come before the
|
|
4
|
+
* projects and issues that name them.
|
|
5
|
+
*/
|
|
6
|
+
export const TRACKER_KINDS = ["team", "user", "state", "label", "project", "issue", "comment"];
|
|
7
|
+
/** Where an issue in a state stands in its work, whatever the team named the state. */
|
|
8
|
+
export const STATE_TYPES = ["triage", "backlog", "unstarted", "started", "completed", "canceled"];
|
|
9
|
+
/** The record's title in lists and search: an issue's title, a comment's start, anything else's name. */
|
|
10
|
+
export const trackerTitleOf = (kind, record) => kind === "issue"
|
|
11
|
+
? record.title
|
|
12
|
+
: kind === "comment"
|
|
13
|
+
? record.body.split("\n")[0]?.slice(0, 120) || "(comment)"
|
|
14
|
+
: record.name;
|
|
15
|
+
/** The record's text that search reads beside its title: a description or a comment's body. */
|
|
16
|
+
export const trackerBodyOf = (kind, record) => kind === "comment"
|
|
17
|
+
? record.body
|
|
18
|
+
: kind === "issue" || kind === "project"
|
|
19
|
+
? record.description
|
|
20
|
+
: null;
|
|
21
|
+
/** The record its row hangs under: a comment's issue, a state's or a label's team. */
|
|
22
|
+
export const trackerParentOf = (kind, record) => kind === "comment"
|
|
23
|
+
? record.issue
|
|
24
|
+
: kind === "state" || kind === "label"
|
|
25
|
+
? record.team
|
|
26
|
+
: kind === "issue"
|
|
27
|
+
? record.team
|
|
28
|
+
: null;
|
package/dist/errors/reasons.js
CHANGED
|
@@ -487,6 +487,7 @@ const OTHERS = [
|
|
|
487
487
|
validation("crm.owner-unknown", "owner: names no CRM user: me without a known sign-in user, or not a user id"),
|
|
488
488
|
validation("crm.write-unsupported", "the CRM does not take this write, or does not recognise a repeated one"),
|
|
489
489
|
validation("crm.unlisted-held", "a list of every id would mark most of a kind deleted; nothing was, until --rescan"),
|
|
490
|
+
validation("tracker.unlisted-held", "a tracker's id list would mark too much deleted, or the sign-in read only part; nothing was, until --rescan"),
|
|
490
491
|
validation("crm.narrowing-held", "the default scope mine would mark most of a kind's stored rows deleted; none is, until the owner sets the scope"),
|
|
491
492
|
validation("crm.unassigned-dropped", "the CRM does not let this sign-in choose a user in unassigned; that user's deals are not copied"),
|
|
492
493
|
validation("crm.not-reported", "the CRM did not list users or departments; what they would say is unknown, nothing withdrawn"),
|
package/dist/manifest/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { CrmManifest } from "../crm/manifest/manifest.js";
|
|
2
2
|
import type { OAuthProvider } from "../oauth/provider.js";
|
|
3
|
+
import type { TrackerManifest } from "../tracker/manifest/manifest.js";
|
|
3
4
|
/**
|
|
4
5
|
* The operation that answers whose the token is, and where its answer holds the account's id (and a name to show):
|
|
5
6
|
* `{ operation: "getV2Self", id: "workspace_id", name: "workspace_name" }`. `session start` checks a token with it.
|
|
@@ -29,7 +30,7 @@ export type CliAuth = {
|
|
|
29
30
|
/** The provider sends a new refresh token on each refresh; the spec cannot say so. */
|
|
30
31
|
rotating?: boolean;
|
|
31
32
|
};
|
|
32
|
-
export declare const CLI_CATEGORIES: readonly ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "other"];
|
|
33
|
+
export declare const CLI_CATEGORIES: readonly ["messenger", "mail", "notes", "files", "meetings", "calendar", "crm", "tracker", "other"];
|
|
33
34
|
export type CliCategory = (typeof CLI_CATEGORIES)[number];
|
|
34
35
|
/** One file, `wirecat.config.ts`, that `new --from-config` builds a CLI from. */
|
|
35
36
|
export interface CliConfig {
|
|
@@ -47,21 +48,24 @@ export interface CliConfig {
|
|
|
47
48
|
};
|
|
48
49
|
/** `from`: the https URL the description is published at. */
|
|
49
50
|
spec: {
|
|
50
|
-
kind: "openapi" | "swagger";
|
|
51
|
+
kind: "openapi" | "swagger" | "graphql";
|
|
51
52
|
from: string;
|
|
52
53
|
};
|
|
53
54
|
auth: CliAuth;
|
|
54
55
|
/** cli-template's `--category`; `other` is any API outside them. */
|
|
55
56
|
category: CliCategory;
|
|
56
|
-
/**
|
|
57
|
-
|
|
57
|
+
/**
|
|
58
|
+
* A crm or tracker CLI's source; checked against the generated API by `parseCrmManifest` or `parseTrackerManifest`
|
|
59
|
+
* once the api group exists.
|
|
60
|
+
*/
|
|
61
|
+
source?: CrmManifest | TrackerManifest;
|
|
58
62
|
/** The module of named hooks, relative to the config: `./src/hooks.ts`. */
|
|
59
63
|
hooks?: string;
|
|
60
64
|
}
|
|
61
65
|
/** Types the config in the editor; it returns what it is given. */
|
|
62
66
|
export declare const defineCli: (config: CliConfig) => CliConfig;
|
|
63
67
|
/**
|
|
64
|
-
* The config checked against its shape; every error names where it is. A
|
|
68
|
+
* The config checked against its shape; every error names where it is. A crm or tracker CLI needs its source. `source` comes back
|
|
65
69
|
* unchecked: `parseCrmManifest` checks it against the generated API.
|
|
66
70
|
*/
|
|
67
71
|
export declare const parseCliConfig: (input: unknown) => CliConfig;
|