@primitivedotdev/cli 3.0.0-preview.18 → 3.0.0-preview.19
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/README.md +15 -0
- package/dist/{api-command-BlfqpBjp.js → api-command--2ZkNMvH.js} +630 -75
- package/dist/{machine-session-cmk2oCPL.js → machine-session-ADcw9uJm.js} +4 -4
- package/dist/{notify-session-BIElQmDi.js → notify-session-06flGBgK.js} +2 -2
- package/dist/oclif/auto-signal-worker.js +3 -3
- package/dist/oclif/auto-signals.js +1 -1
- package/dist/oclif/index.js +524 -90
- package/dist/oclif/receiver-heal.js +2 -2
- package/dist/{repeats-Dj_o6c-X-b-Y0Ejun.js → repeats-Dj_o6c-X-DTtFzwNd.js} +7 -4
- package/dist/{scoped-chat-CaiJJRMA.js → scoped-chat-C7l2BSZr.js} +1 -1
- package/dist/{signal-command-C4Eu4-1-.js → signal-command-D6oaza1W.js} +4 -4
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Bn as sdk_gen_exports, C as parseRetryAfter, H as assertAwaitingFilterRows, J as isAwaitingRejectedError, Jt as getOwnGrant, Qt as getThread, U as awaitingRejectedError, V as ReplyStateUnsupportedError, W as ensureSearchReportsReplyState, X as replyStateSurfaceForOperation, at as expectedAutomatedVerdicts, et as AutomatedFilterUnsupportedError, fn as listEndpoints, it as ensureSearchReportsAutomated, ln as listDomains, nt as automatedRejectedError, rt as automatedSurfaceForOperation, st as isAutomatedRejectedError, tt as assertAutomatedVerdict, zt as getEmail } from "./repeats-Dj_o6c-X-DTtFzwNd.js";
|
|
2
2
|
import { C as saveCliCredentials, F as agentProfilesDirectory, H as requireDefaultLoginProfile, N as agentProfileDirectory, R as loadConnectedAgentProfile, S as resolveCliAuth, W as PrimitiveApiClient, _ as deleteCliCredentials, b as loadCliCredentials, c as resolveConfigEnvironment, d as validateCliHeaderName, f as validateCliHeaderValue, i as loadCliConfig, j as AGENT_PROFILE_ENV, m as cliAccessTokenExpiresAt, p as acquireCliCredentialsLock, w as saveSignupCredentials, x as normalizeApiBaseUrl, y as detectPrimitiveKeyEnvMisname } from "./cli-config-Ms_0vNjq.js";
|
|
3
3
|
import "./oclif/global-org-flag.js";
|
|
4
4
|
import { a as thrownErrorBody } from "./json-output-saHY68hr.js";
|
|
5
5
|
import { d as readMailJson, h as writeMailJson, m as withMailLock, p as syncMailDirectory, u as privateMailPermissions } from "./shared-mail-files-BAQSGxxz.js";
|
|
6
6
|
import { Args, Command, Errors, Flags } from "@oclif/core";
|
|
7
|
-
import { existsSync, lstatSync, readFileSync, readdirSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
|
-
import { createHash } from "node:crypto";
|
|
9
|
-
import { join, win32 } from "node:path";
|
|
7
|
+
import { existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
9
|
+
import { dirname, join, win32 } from "node:path";
|
|
10
10
|
import { spawn } from "node:child_process";
|
|
11
11
|
import { createInterface } from "node:readline/promises";
|
|
12
12
|
// ../packages/api-core/src/openapi/operations.generated.ts
|
|
@@ -16353,7 +16353,7 @@ const operationManifest = [
|
|
|
16353
16353
|
"description": "Whether they can accept a rule request now under their role."
|
|
16354
16354
|
},
|
|
16355
16355
|
"missing_permission": {
|
|
16356
|
-
"description": "The permission their role lacks for accepting, when can_accept is false.",
|
|
16356
|
+
"description": "The permission their role lacks for accepting, when can_accept is false; null then means they have no own mailbox on the mail relay domains.",
|
|
16357
16357
|
"type": ["string", "null"]
|
|
16358
16358
|
},
|
|
16359
16359
|
"warning": {
|
|
@@ -16632,7 +16632,7 @@ const operationManifest = [
|
|
|
16632
16632
|
"own_mailboxes",
|
|
16633
16633
|
"selected"
|
|
16634
16634
|
],
|
|
16635
|
-
"description": "own_mailboxes (the default): mail to your own addresses and agents (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
16635
|
+
"description": "own_mailboxes (the default): mail to your own addresses and agents on the mail relay domains (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
16636
16636
|
},
|
|
16637
16637
|
"scope_selection": {
|
|
16638
16638
|
"type": "object",
|
|
@@ -17983,7 +17983,7 @@ const operationManifest = [
|
|
|
17983
17983
|
"own_mailboxes",
|
|
17984
17984
|
"selected"
|
|
17985
17985
|
],
|
|
17986
|
-
"description": "own_mailboxes (the default): mail to your own addresses and agents (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
17986
|
+
"description": "own_mailboxes (the default): mail to your own addresses and agents on the mail relay domains (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
17987
17987
|
},
|
|
17988
17988
|
"scope_selection": {
|
|
17989
17989
|
"type": "object",
|
|
@@ -20144,12 +20144,12 @@ const operationManifest = [
|
|
|
20144
20144
|
"addresses": {
|
|
20145
20145
|
"type": "array",
|
|
20146
20146
|
"items": { "type": "string" },
|
|
20147
|
-
"description": "Inboxes you can read, matching q. For someone who reads the whole organization, the inboxes known as someone's: member addresses, members' verified work emails at the organization's domains, agents' addresses and inboxes with shared access. Otherwise the inboxes your access lists (search with q for those past the first page). See may_name_unlisted for what else you may name."
|
|
20147
|
+
"description": "Inboxes on the mail relay domains you can read, matching q. For someone who reads the whole organization, the inboxes known as someone's: member addresses, members' verified work emails at the organization's domains, agents' addresses and inboxes with shared access. Otherwise the inboxes your access lists (search with q for those past the first page). See may_name_unlisted for what else you may name."
|
|
20148
20148
|
},
|
|
20149
20149
|
"domains": {
|
|
20150
20150
|
"type": "array",
|
|
20151
20151
|
"items": { "type": "string" },
|
|
20152
|
-
"description": "
|
|
20152
|
+
"description": "Mail relay domains you can read, matching q."
|
|
20153
20153
|
},
|
|
20154
20154
|
"more": {
|
|
20155
20155
|
"type": "boolean",
|
|
@@ -21290,7 +21290,7 @@ const operationManifest = [
|
|
|
21290
21290
|
"binaryResponse": false,
|
|
21291
21291
|
"bodyRequired": true,
|
|
21292
21292
|
"command": "test-email-rule",
|
|
21293
|
-
"description": "Runs a rule over received mail and reports what it would decide for each email (matched, near_miss, no_match, unclassified, skipped or not_found), with a summary of how each top-level condition and question decided. Test an unsaved tree with its kind, a saved rule by rule_id (its current version, as its author), rule_id with tree (that tree as the rule's next version, as its author, against its saved expectations; its author only), or a pending rule request by request_id (its rule as asked, as you, over your own mailboxes). It reads only mail its author can read and its scope covers. A rule you see only because it covers your own mailboxes runs as you, over only those. Without email_ids it tests the newest emails, at most 200 and none older than 30 days, plus any expected ones. Unclassified emails over 2 hours old are classified first unless classify_missing is false. It records no decision and grants nothing, and stops at about 90 seconds. Needs mail:read, the email rules feature, and a member's own full-access credential (no API key, agent key or narrowed token).",
|
|
21293
|
+
"description": "Runs a rule over received mail and reports what it would decide for each email (matched, near_miss, no_match, unclassified, skipped or not_found), with a summary of how each top-level condition and question decided. Test an unsaved tree with its kind, a saved rule by rule_id (its current version, as its author), rule_id with tree (that tree as the rule's next version, as its author, against its saved expectations; its author only), or a pending rule request by request_id (its rule as asked, as you, over your own mailboxes). It reads only mail its author can read and its scope covers. A rule you see only because it covers your own mailboxes runs as you, over only those. Without email_ids it tests the newest emails on the mail relay domains, at most 200 and none older than 30 days, plus any expected ones. Unclassified emails over 2 hours old are classified first unless classify_missing is false. It records no decision and grants nothing, and stops at about 90 seconds. Needs mail:read, the email rules feature, and a member's own full-access credential (no API key, agent key or narrowed token).",
|
|
21294
21294
|
"hasJsonBody": true,
|
|
21295
21295
|
"method": "POST",
|
|
21296
21296
|
"operationId": "testEmailRule",
|
|
@@ -21352,7 +21352,7 @@ const operationManifest = [
|
|
|
21352
21352
|
"own_mailboxes",
|
|
21353
21353
|
"selected"
|
|
21354
21354
|
],
|
|
21355
|
-
"description": "own_mailboxes (the default): mail to your own addresses and agents (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
21355
|
+
"description": "own_mailboxes (the default): mail to your own addresses and agents on the mail relay domains (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
21356
21356
|
},
|
|
21357
21357
|
"scope_selection": {
|
|
21358
21358
|
"type": "object",
|
|
@@ -21858,9 +21858,10 @@ const operationManifest = [
|
|
|
21858
21858
|
]
|
|
21859
21859
|
},
|
|
21860
21860
|
"skipped_reason": {
|
|
21861
|
-
"description": "Why a skipped email cannot be tested. unparsed: its content failed to parse, so it can never be classified. rejected: it was rejected and never delivered. content_discarded: its content has been discarded, or is being. Nothing is classified or asked about it and no stored answers are used, so it never counts as a pass. The recent window holds only mail that can be tested, apart from unparsed mail; an email you name is reported as skipped, whichever of these it is.",
|
|
21861
|
+
"description": "Why a skipped email cannot be tested. not_relay_domain: it was not received on one of the organization's mail relay domains, and rules decide only that mail. unparsed: its content failed to parse, so it can never be classified. rejected: it was rejected and never delivered. content_discarded: its content has been discarded, or is being. Nothing is classified or asked about it and no stored answers are used, so it never counts as a pass. The recent window holds only mail on the mail relay domains that can be tested, apart from unparsed mail; an email you name is reported as skipped, whichever of these it is.",
|
|
21862
21862
|
"type": "string",
|
|
21863
21863
|
"enum": [
|
|
21864
|
+
"not_relay_domain",
|
|
21864
21865
|
"unparsed",
|
|
21865
21866
|
"rejected",
|
|
21866
21867
|
"content_discarded"
|
|
@@ -22259,7 +22260,7 @@ const operationManifest = [
|
|
|
22259
22260
|
"own_mailboxes",
|
|
22260
22261
|
"selected"
|
|
22261
22262
|
],
|
|
22262
|
-
"description": "own_mailboxes (the default): mail to your own addresses and agents (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
22263
|
+
"description": "own_mailboxes (the default): mail to your own addresses and agents on the mail relay domains (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names."
|
|
22263
22264
|
},
|
|
22264
22265
|
"scope_selection": {
|
|
22265
22266
|
"type": "object",
|
|
@@ -22668,7 +22669,7 @@ const operationManifest = [
|
|
|
22668
22669
|
"own_mailboxes",
|
|
22669
22670
|
"selected"
|
|
22670
22671
|
],
|
|
22671
|
-
"description": "own_mailboxes: mail to your own addresses and agents (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names. Left out, the scope stays. A change saves a new version with the same conditions, and is refused while the rule is shared."
|
|
22672
|
+
"description": "own_mailboxes: mail to your own addresses and agents on the mail relay domains (for a rule that shares, those mail:share_own lets you share). author: all you can read, inboxes added later included. selected: what scope_selection names. Left out, the scope stays. A change saves a new version with the same conditions, and is refused while the rule is shared."
|
|
22672
22673
|
},
|
|
22673
22674
|
"scope_selection": {
|
|
22674
22675
|
"type": "object",
|
|
@@ -25680,13 +25681,6 @@ const operationManifest = [
|
|
|
25680
25681
|
"required": false,
|
|
25681
25682
|
"type": "integer"
|
|
25682
25683
|
},
|
|
25683
|
-
{
|
|
25684
|
-
"description": "Filter by domain ID",
|
|
25685
|
-
"enum": null,
|
|
25686
|
-
"name": "domain_id",
|
|
25687
|
-
"required": false,
|
|
25688
|
-
"type": "string"
|
|
25689
|
-
},
|
|
25690
25684
|
{
|
|
25691
25685
|
"description": "Filter inbound rows by lifecycle status. See `EmailStatus`\nfor what each value means. Note that the webhook delivery\nstate is a SEPARATE lifecycle on the same row; filter by\n`webhook_status` semantics is not currently supported on\nthis endpoint.\n",
|
|
25692
25686
|
"enum": null,
|
|
@@ -25844,6 +25838,13 @@ const operationManifest = [
|
|
|
25844
25838
|
"required": false,
|
|
25845
25839
|
"type": "string"
|
|
25846
25840
|
},
|
|
25841
|
+
{
|
|
25842
|
+
"description": "Domain ids, comma-separated or with the key repeated, at most 50: only mail received at one of them. Only narrows: an id you cannot read, or of another organization, matches no mail and is not reported as unknown. `meta.domain_ids` echoes the list as given.",
|
|
25843
|
+
"enum": null,
|
|
25844
|
+
"name": "domain_ids",
|
|
25845
|
+
"required": false,
|
|
25846
|
+
"type": "string"
|
|
25847
|
+
},
|
|
25847
25848
|
{
|
|
25848
25849
|
"description": "Receiver presence mail: the presence probes sent to a connected agent and its answers. Left out by default for a connected-agent credential and listed by default for any other credential. `true` lists it, `false` leaves it out. Presence mail that inbound processing verified as presence on arrival expects no answer and does not count toward `awaiting`. Presence mail stored before that verification existed keeps the `awaiting` value it was stored with, so it can still count toward `awaiting`; `include_presence=true`, or any credential other than a connected agent's, still lists it. Combines with every other filter and with both `cursor` and `since`.",
|
|
25849
25850
|
"enum": ["true", "false"],
|
|
@@ -26467,13 +26468,6 @@ const operationManifest = [
|
|
|
26467
26468
|
"required": false,
|
|
26468
26469
|
"type": "string"
|
|
26469
26470
|
},
|
|
26470
|
-
{
|
|
26471
|
-
"description": "Filter by domain ID.",
|
|
26472
|
-
"enum": null,
|
|
26473
|
-
"name": "domain_id",
|
|
26474
|
-
"required": false,
|
|
26475
|
-
"type": "string"
|
|
26476
|
-
},
|
|
26477
26471
|
{
|
|
26478
26472
|
"description": "Filter to inbound emails that are replies to a specific\noutbound send. The value is a `sent_emails.id` (UUID). At\ninbound ingest, Primitive matches the parsed In-Reply-To\nheader (or References as a fallback) against\n`sent_emails.message_id` in the same org and records the\nresolved id on `emails.reply_to_sent_email_id`. This filter\nis the strict-threading lookup behind `primitive chat` and\nany UI that wants to show the inbound reply to a given\nsend. NULL on inbound that isn't a threaded reply to one\nof your sends, so existing emails received before this\ningestion landed will not match.\n",
|
|
26479
26473
|
"enum": null,
|
|
@@ -26629,6 +26623,13 @@ const operationManifest = [
|
|
|
26629
26623
|
"name": "include",
|
|
26630
26624
|
"required": false,
|
|
26631
26625
|
"type": "string"
|
|
26626
|
+
},
|
|
26627
|
+
{
|
|
26628
|
+
"description": "Domain ids, comma-separated or with the key repeated, at most 50: received mail at one of them, and with `direction` `outbound` or `any`, sent mail from an address at one of them. Only narrows: an id you cannot read, or of another organization, matches no mail and is not reported as unknown. `meta.domain_ids` echoes the list as given.",
|
|
26629
|
+
"enum": null,
|
|
26630
|
+
"name": "domain_ids",
|
|
26631
|
+
"required": false,
|
|
26632
|
+
"type": "string"
|
|
26632
26633
|
}
|
|
26633
26634
|
],
|
|
26634
26635
|
"headerParams": [],
|
|
@@ -42494,6 +42495,16 @@ const operationManifest = [
|
|
|
42494
42495
|
"cursor": {
|
|
42495
42496
|
"type": "string",
|
|
42496
42497
|
"description": "Opaque pagination cursor from a prior response's `meta.cursor`."
|
|
42498
|
+
},
|
|
42499
|
+
"domain_ids": {
|
|
42500
|
+
"type": "array",
|
|
42501
|
+
"items": {
|
|
42502
|
+
"type": "string",
|
|
42503
|
+
"format": "uuid"
|
|
42504
|
+
},
|
|
42505
|
+
"minItems": 1,
|
|
42506
|
+
"maxItems": 50,
|
|
42507
|
+
"description": "Domain ids, at most 50: only received mail at one of them, tested on the ranked candidates, so a page can hold fewer than `limit` results. Received mail only: refused with corpus `outbound`, and the default corpus becomes `inbound`. Only narrows: an id you cannot read, or of another organization, matches no mail and is not reported as unknown. `meta.domain_ids` echoes the list as given."
|
|
42497
42508
|
}
|
|
42498
42509
|
}
|
|
42499
42510
|
},
|
|
@@ -46028,6 +46039,13 @@ const operationManifest = [
|
|
|
46028
46039
|
"required": false,
|
|
46029
46040
|
"type": "string"
|
|
46030
46041
|
},
|
|
46042
|
+
{
|
|
46043
|
+
"description": "Domain ids, comma-separated or with the key repeated, at most 50: only sends from an address at one of them. Only narrows: an id you cannot read, or of another organization, matches no mail and is not reported as unknown. `meta.domain_ids` echoes the list as given.",
|
|
46044
|
+
"enum": null,
|
|
46045
|
+
"name": "domain_ids",
|
|
46046
|
+
"required": false,
|
|
46047
|
+
"type": "string"
|
|
46048
|
+
},
|
|
46031
46049
|
{
|
|
46032
46050
|
"description": "Return only sends that set this header: `Name=Value` matches that exact value, `Name` alone any value. Name and value compare case-insensitively; the value is trimmed and matched whole, not as a substring, and only the first `=` separates the two. Matches only the `headers` the send request set. History pages only: with `since` or `wait` it is a `validation_error`, as is a name that is never stored (trace, signature or credential-like). Sends made before header search was available are not matched.",
|
|
46033
46051
|
"enum": null,
|
|
@@ -52966,7 +52984,7 @@ function terminalLine(line) {
|
|
|
52966
52984
|
return sanitizeForTerminal(line).replace(BIDI_CONTROLS, "").replaceAll(/[\r\n\t]+/g, " ");
|
|
52967
52985
|
}
|
|
52968
52986
|
// src/oclif/answer-reports.ts
|
|
52969
|
-
function isRecord$
|
|
52987
|
+
function isRecord$6(value) {
|
|
52970
52988
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
52971
52989
|
}
|
|
52972
52990
|
/** Text from an answer, made safe and one line for a report: no terminal controls. */
|
|
@@ -52975,10 +52993,10 @@ function oneLine(text) {
|
|
|
52975
52993
|
}
|
|
52976
52994
|
/** One line per warning a route write answers with (createRoute, updateRoute). */
|
|
52977
52995
|
function routeWarningLines(data) {
|
|
52978
|
-
const warnings = isRecord$
|
|
52996
|
+
const warnings = isRecord$6(data) ? data.warnings : void 0;
|
|
52979
52997
|
if (!Array.isArray(warnings)) return [];
|
|
52980
52998
|
return warnings.flatMap((warning) => {
|
|
52981
|
-
if (!isRecord$
|
|
52999
|
+
if (!isRecord$6(warning)) return [];
|
|
52982
53000
|
const message = typeof warning.message === "string" ? oneLine(warning.message) : "";
|
|
52983
53001
|
if (message) return [`Route warning: ${withCliCommands(message)}`];
|
|
52984
53002
|
const code = typeof warning.code === "string" ? oneLine(warning.code) : "";
|
|
@@ -53006,11 +53024,11 @@ const DELIVERED_STATUSES = /* @__PURE__ */ new Set(["delivered", "header_confirm
|
|
|
53006
53024
|
* and has no recorded answer says so.
|
|
53007
53025
|
*/
|
|
53008
53026
|
function deliveryAttemptLines(data) {
|
|
53009
|
-
const attempts = isRecord$
|
|
53027
|
+
const attempts = isRecord$6(data) ? data.attempts : void 0;
|
|
53010
53028
|
if (!Array.isArray(attempts)) return [];
|
|
53011
53029
|
const lines = [];
|
|
53012
53030
|
for (const attempt of attempts) {
|
|
53013
|
-
if (!isRecord$
|
|
53031
|
+
if (!isRecord$6(attempt)) continue;
|
|
53014
53032
|
const text = (value) => typeof value === "string" && value ? oneLine(value) : "";
|
|
53015
53033
|
const status = text(attempt.status);
|
|
53016
53034
|
const parts = [
|
|
@@ -53036,9 +53054,9 @@ function deliveryAttemptLines(data) {
|
|
|
53036
53054
|
*/
|
|
53037
53055
|
function deliveringCell(endpoint) {
|
|
53038
53056
|
const delivery = endpoint.delivery;
|
|
53039
|
-
if (isRecord$
|
|
53057
|
+
if (isRecord$6(delivery) && typeof delivery.delivering === "boolean") {
|
|
53040
53058
|
if (delivery.delivering) return "yes";
|
|
53041
|
-
const codes = Array.isArray(delivery.reasons) ? delivery.reasons.flatMap((reason) => isRecord$
|
|
53059
|
+
const codes = Array.isArray(delivery.reasons) ? delivery.reasons.flatMap((reason) => isRecord$6(reason) && typeof reason.code === "string" && reason.code ? [oneLine(reason.code)] : []) : [];
|
|
53042
53060
|
return codes.length > 0 ? `no (${codes.join(", ")})` : "no";
|
|
53043
53061
|
}
|
|
53044
53062
|
return endpoint.kind === void 0 || endpoint.kind === "http" ? "unknown" : "-";
|
|
@@ -53049,7 +53067,7 @@ function deliveringCell(endpoint) {
|
|
|
53049
53067
|
* (DELIVERING, from `delivery`), and its name. Nothing for an empty list.
|
|
53050
53068
|
*/
|
|
53051
53069
|
function endpointDeliveryLines(data) {
|
|
53052
|
-
const rows = Array.isArray(data) ? data.filter(isRecord$
|
|
53070
|
+
const rows = Array.isArray(data) ? data.filter(isRecord$6) : [];
|
|
53053
53071
|
if (rows.length === 0) return [];
|
|
53054
53072
|
const text = (value) => typeof value === "string" && value ? oneLine(value) : "";
|
|
53055
53073
|
const table = [[
|
|
@@ -53150,7 +53168,7 @@ var CliOrgRefusedError = class extends Errors.CLIError {
|
|
|
53150
53168
|
this.orgId = params.orgId;
|
|
53151
53169
|
}
|
|
53152
53170
|
};
|
|
53153
|
-
function isRecord$
|
|
53171
|
+
function isRecord$5(value) {
|
|
53154
53172
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
53155
53173
|
}
|
|
53156
53174
|
function apiOrigin(apiBaseUrl) {
|
|
@@ -53177,7 +53195,7 @@ function isUuid(value) {
|
|
|
53177
53195
|
return /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(value);
|
|
53178
53196
|
}
|
|
53179
53197
|
function isOrgAccessToken(value) {
|
|
53180
|
-
return isRecord$
|
|
53198
|
+
return isRecord$5(value) && typeof value.access_token === "string" && value.access_token.length > 0 && value.token_type === "Bearer" && typeof value.expires_in === "number" && value.expires_in > 0 && typeof value.org_id === "string" && (value.org_name === null || typeof value.org_name === "string") && typeof value.oauth_grant_id === "string";
|
|
53181
53199
|
}
|
|
53182
53200
|
function orgTokenFromResponse(token, now = Date.now) {
|
|
53183
53201
|
return {
|
|
@@ -53224,7 +53242,7 @@ async function postTokenEndpoint(params) {
|
|
|
53224
53242
|
throw new Errors.CLIError(`Could not reach the Primitive OAuth token endpoint: ${detail}`, { exit: 1 });
|
|
53225
53243
|
}
|
|
53226
53244
|
const payload = await response.json().catch(() => null);
|
|
53227
|
-
if (response.ok && isRecord$
|
|
53245
|
+
if (response.ok && isRecord$5(payload)) return {
|
|
53228
53246
|
ok: true,
|
|
53229
53247
|
payload
|
|
53230
53248
|
};
|
|
@@ -53232,7 +53250,7 @@ async function postTokenEndpoint(params) {
|
|
|
53232
53250
|
ok: true,
|
|
53233
53251
|
payload: {}
|
|
53234
53252
|
};
|
|
53235
|
-
const record = isRecord$
|
|
53253
|
+
const record = isRecord$5(payload) ? payload : {};
|
|
53236
53254
|
return {
|
|
53237
53255
|
ok: false,
|
|
53238
53256
|
status: response.status,
|
|
@@ -53435,12 +53453,12 @@ async function fetchCliOrgs(params) {
|
|
|
53435
53453
|
}
|
|
53436
53454
|
const payload = await response.json().catch(() => null);
|
|
53437
53455
|
if (!response.ok) {
|
|
53438
|
-
const error = isRecord$
|
|
53456
|
+
const error = isRecord$5(payload) && isRecord$5(payload.error) ? payload.error : {};
|
|
53439
53457
|
if (response.status === 404 && error.code === "feature_disabled") throw new Errors.CLIError("This Primitive server does not support switching organizations for CLI logins.", { exit: 1 });
|
|
53440
53458
|
throw new Errors.CLIError(`Could not list organizations${typeof error.message === "string" ? `: ${error.message}` : ` (HTTP ${response.status}).`}`, { exit: 1 });
|
|
53441
53459
|
}
|
|
53442
|
-
const data = isRecord$
|
|
53443
|
-
if (!isRecord$
|
|
53460
|
+
const data = isRecord$5(payload) ? payload.data : null;
|
|
53461
|
+
if (!isRecord$5(data) || !Array.isArray(data.orgs)) throw new Errors.CLIError("Primitive API returned an unexpected organization list.", { exit: 1 });
|
|
53444
53462
|
return data;
|
|
53445
53463
|
}
|
|
53446
53464
|
/** How long a command waits for another CLI process to finish with the saved login. */
|
|
@@ -54105,7 +54123,7 @@ function withBooleanFlagValues(argv, flags) {
|
|
|
54105
54123
|
// src/oclif/rule-notes.ts
|
|
54106
54124
|
/** The tags whose single-object answers get the notes printer. */
|
|
54107
54125
|
const RULE_NOTES_TAGS = /* @__PURE__ */ new Set(["Email Rules", "Email Rule Oversight"]);
|
|
54108
|
-
function isRecord$
|
|
54126
|
+
function isRecord$4(value) {
|
|
54109
54127
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
54110
54128
|
}
|
|
54111
54129
|
/** Server text as a report line shows it, or "" when there is none. */
|
|
@@ -54134,12 +54152,12 @@ function list(value) {
|
|
|
54134
54152
|
* rule's, each once.
|
|
54135
54153
|
*/
|
|
54136
54154
|
function ruleNotesLines(answer) {
|
|
54137
|
-
if (!isRecord$
|
|
54138
|
-
const summary = isRecord$
|
|
54139
|
-
const rule = isRecord$
|
|
54155
|
+
if (!isRecord$4(answer)) return [];
|
|
54156
|
+
const summary = isRecord$4(answer.summary) ? answer.summary : {};
|
|
54157
|
+
const rule = isRecord$4(answer.rule) ? answer.rule : {};
|
|
54140
54158
|
const notes = (from) => NOTE_KEYS.map((key) => from[key]);
|
|
54141
54159
|
const lines = [
|
|
54142
|
-
...list(answer.scope_warnings).filter(isRecord$
|
|
54160
|
+
...list(answer.scope_warnings).filter(isRecord$4).map(scopeWarningLine),
|
|
54143
54161
|
...[
|
|
54144
54162
|
...list(answer.warnings),
|
|
54145
54163
|
answer.warning,
|
|
@@ -54161,7 +54179,7 @@ function errorDetail(error) {
|
|
|
54161
54179
|
function usageError$2(message) {
|
|
54162
54180
|
return new Errors.CLIError(message, { exit: 2 });
|
|
54163
54181
|
}
|
|
54164
|
-
function isRecord$
|
|
54182
|
+
function isRecord$3(value) {
|
|
54165
54183
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
54166
54184
|
}
|
|
54167
54185
|
/** A JSON file a flag names, parsed, or a usage error (exit 2) saying why not. */
|
|
@@ -54202,7 +54220,7 @@ function lookAlikeExpected(lookAlike) {
|
|
|
54202
54220
|
* both do not fit a label.
|
|
54203
54221
|
*/
|
|
54204
54222
|
function lookAlikeSample(lookAlike) {
|
|
54205
|
-
if (!isRecord$
|
|
54223
|
+
if (!isRecord$3(lookAlike) || !isRecord$3(lookAlike.email)) return null;
|
|
54206
54224
|
const kind = typeof lookAlike.kind === "string" ? lookAlike.kind : "";
|
|
54207
54225
|
const why = typeof lookAlike.why === "string" ? lookAlike.why.trim() : "";
|
|
54208
54226
|
const both = kind && why ? `${kind}: ${why}` : kind || why;
|
|
@@ -54219,11 +54237,11 @@ function lookAlikeSample(lookAlike) {
|
|
|
54219
54237
|
* samples file holds these, so a number means the same email in both.
|
|
54220
54238
|
*/
|
|
54221
54239
|
function lookAlikeEntries(answer) {
|
|
54222
|
-
const list = isRecord$
|
|
54240
|
+
const list = isRecord$3(answer) && Array.isArray(answer.look_alikes) ? answer.look_alikes : [];
|
|
54223
54241
|
const entries = [];
|
|
54224
54242
|
for (const item of list) {
|
|
54225
54243
|
const sample = lookAlikeSample(item);
|
|
54226
|
-
if (sample && isRecord$
|
|
54244
|
+
if (sample && isRecord$3(item)) entries.push({
|
|
54227
54245
|
lookAlike: item,
|
|
54228
54246
|
sample
|
|
54229
54247
|
});
|
|
@@ -54243,15 +54261,15 @@ function lookAlikeSamples(answer) {
|
|
|
54243
54261
|
* refused, so it never empties a rule's.
|
|
54244
54262
|
*/
|
|
54245
54263
|
function samplesFromJson(value, source) {
|
|
54246
|
-
const data = isRecord$
|
|
54247
|
-
if (isRecord$
|
|
54264
|
+
const data = isRecord$3(value) && isRecord$3(value.data) ? value.data : value;
|
|
54265
|
+
if (isRecord$3(data) && Array.isArray(data.look_alikes)) {
|
|
54248
54266
|
const samples = lookAlikeSamples(data);
|
|
54249
54267
|
if (samples.length === 0) throw usageError$2(`${source} is a generate-look-alikes answer with no look-alikes in it.`);
|
|
54250
54268
|
return samples;
|
|
54251
54269
|
}
|
|
54252
54270
|
if (!Array.isArray(data)) throw usageError$2(`${source} must hold a JSON array of samples, such as [{"expected": "no_match", "label": "a personal bill", "email": {...}}], or a generate-look-alikes answer.`);
|
|
54253
54271
|
return data.map((item, index) => {
|
|
54254
|
-
if (!isRecord$
|
|
54272
|
+
if (!isRecord$3(item)) throw usageError$2(`${source}, sample ${index + 1} (index ${index}) is not an object.`);
|
|
54255
54273
|
const { id: _id, created_at: _createdAt, ...sample } = item;
|
|
54256
54274
|
return sample;
|
|
54257
54275
|
});
|
|
@@ -54338,11 +54356,11 @@ function pickFlagHelp(flags) {
|
|
|
54338
54356
|
* match it, and what the rule decided; the counts; then the server's notes.
|
|
54339
54357
|
*/
|
|
54340
54358
|
function lookAlikesReport(data) {
|
|
54341
|
-
if (!isRecord$
|
|
54359
|
+
if (!isRecord$3(data)) return { lines: [] };
|
|
54342
54360
|
const lines = [];
|
|
54343
54361
|
lookAlikeEntries(data).forEach(({ lookAlike }, index) => {
|
|
54344
54362
|
const email = lookAlike.email;
|
|
54345
|
-
const from = isRecord$
|
|
54363
|
+
const from = isRecord$3(email.from) ? shownText(email.from.address) : "";
|
|
54346
54364
|
const subject = shownText(email.subject);
|
|
54347
54365
|
const status = shownLine(lookAlike.status) || "undecided";
|
|
54348
54366
|
const kind = shownLine(lookAlike.kind) || "other";
|
|
@@ -54353,7 +54371,7 @@ function lookAlikesReport(data) {
|
|
|
54353
54371
|
if (why) lines.push(` Why it should ${expected === "match" ? "" : "not "}match: ${why}`);
|
|
54354
54372
|
lines.push(` ${outcome} (expected ${expected})`);
|
|
54355
54373
|
});
|
|
54356
|
-
const counts = isRecord$
|
|
54374
|
+
const counts = isRecord$3(data.counts) ? data.counts : {};
|
|
54357
54375
|
const count = (key) => typeof counts[key] === "number" ? counts[key] : 0;
|
|
54358
54376
|
const dropped = count("dropped");
|
|
54359
54377
|
lines.push(`Counts: ${count("passed")} passed, ${count("failed")} failed, ${count("undecided")} undecided${dropped > 0 ? `; ${dropped} asked for did not come back` : ""}.`, ...ruleNotesLines(data));
|
|
@@ -54440,7 +54458,7 @@ function isEmailId(id) {
|
|
|
54440
54458
|
function usageError(message) {
|
|
54441
54459
|
return new Errors.CLIError(message, { exit: 2 });
|
|
54442
54460
|
}
|
|
54443
|
-
function isRecord$
|
|
54461
|
+
function isRecord$2(value) {
|
|
54444
54462
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
54445
54463
|
}
|
|
54446
54464
|
/** `count` and the word for it: "1 expectation", "2 expectations". */
|
|
@@ -54470,7 +54488,7 @@ function parseEmailIdList(values, flag) {
|
|
|
54470
54488
|
* their own flag.
|
|
54471
54489
|
*/
|
|
54472
54490
|
function checkExpectations(value, label) {
|
|
54473
|
-
if (!isRecord$
|
|
54491
|
+
if (!isRecord$2(value)) throw usageError(`${label} must hold a JSON object such as {"match": ["<email-id>"], "no_match": ["<email-id>"]}.`);
|
|
54474
54492
|
if ("samples" in value) throw usageError(`${label} takes emails by id only; give made-up emails with ${label.startsWith("--expectations-file") ? "--expectation-samples-file" : "--expect-samples-file"}.`);
|
|
54475
54493
|
return value;
|
|
54476
54494
|
}
|
|
@@ -54520,10 +54538,10 @@ function sameEmailsBodyFields(flags) {
|
|
|
54520
54538
|
const file = flags[SAME_EMAILS_FLAG];
|
|
54521
54539
|
if (typeof file !== "string") return [];
|
|
54522
54540
|
const saved = readJsonFileFlag(file, `--${SAME_EMAILS_FLAG}`);
|
|
54523
|
-
const answer = isRecord$
|
|
54524
|
-
const results = isRecord$
|
|
54541
|
+
const answer = isRecord$2(saved) && isRecord$2(saved.data) ? saved.data : saved;
|
|
54542
|
+
const results = isRecord$2(answer) && Array.isArray(answer.results) ? answer.results : null;
|
|
54525
54543
|
if (!results) throw usageError(`--${SAME_EMAILS_FLAG} ${file} is not a saved test-email-rule answer: it has no results. Save one with test-email-rule --json > answer.json.`);
|
|
54526
|
-
const ids = [...new Set(results.flatMap((result) => isRecord$
|
|
54544
|
+
const ids = [...new Set(results.flatMap((result) => isRecord$2(result) && typeof result.email_id === "string" && isEmailId(result.email_id) ? [result.email_id.toLowerCase()] : []))];
|
|
54527
54545
|
if (ids.length === 0) throw usageError(`--${SAME_EMAILS_FLAG} ${file} names no emails.`);
|
|
54528
54546
|
return [{
|
|
54529
54547
|
flag: `--${SAME_EMAILS_FLAG}`,
|
|
@@ -54558,7 +54576,7 @@ function formatFactValue(fact) {
|
|
|
54558
54576
|
const value = fact?.value;
|
|
54559
54577
|
let text;
|
|
54560
54578
|
if (Array.isArray(value)) {
|
|
54561
|
-
const per = isRecord$
|
|
54579
|
+
const per = isRecord$2(fact?.value_confidences) ? fact.value_confidences : void 0;
|
|
54562
54580
|
text = `[${value.map((item) => {
|
|
54563
54581
|
const name = String(item);
|
|
54564
54582
|
const score = per?.[name];
|
|
@@ -54588,7 +54606,7 @@ function answerConfidence(answer) {
|
|
|
54588
54606
|
* decide it. An entry that does not say it can is taken as one that cannot.
|
|
54589
54607
|
*/
|
|
54590
54608
|
function undecidedOf(entry) {
|
|
54591
|
-
const given = isRecord$
|
|
54609
|
+
const given = isRecord$2(entry) ? entry : {};
|
|
54592
54610
|
return {
|
|
54593
54611
|
reason: typeof given.reason === "string" ? given.reason : "undecided",
|
|
54594
54612
|
retryable: given.retryable === true
|
|
@@ -54625,13 +54643,13 @@ function expectationLine(result) {
|
|
|
54625
54643
|
}
|
|
54626
54644
|
/** The made-up emails a test's expectations judged, in order. */
|
|
54627
54645
|
function sampleJudgments(expectations) {
|
|
54628
|
-
return (isRecord$
|
|
54646
|
+
return (isRecord$2(expectations) && Array.isArray(expectations.samples) ? expectations.samples : []).filter(isRecord$2).map((item, position) => ({
|
|
54629
54647
|
index: typeof item.index === "number" ? item.index : position,
|
|
54630
54648
|
label: typeof item.label === "string" ? item.label : null,
|
|
54631
54649
|
expected: String(item.expected ?? ""),
|
|
54632
54650
|
outcome: String(item.outcome ?? "not_decided"),
|
|
54633
54651
|
status: String(item.status ?? "undecided"),
|
|
54634
|
-
question_answers: Array.isArray(item.question_answers) ? item.question_answers.filter(isRecord$
|
|
54652
|
+
question_answers: Array.isArray(item.question_answers) ? item.question_answers.filter(isRecord$2) : [],
|
|
54635
54653
|
entry: item
|
|
54636
54654
|
}));
|
|
54637
54655
|
}
|
|
@@ -54795,7 +54813,7 @@ function minuteUtc(value) {
|
|
|
54795
54813
|
}
|
|
54796
54814
|
/** The first line of a test report: which mail was tested. */
|
|
54797
54815
|
function windowLine(data, tested) {
|
|
54798
|
-
const window = isRecord$
|
|
54816
|
+
const window = isRecord$2(data.window) ? data.window : void 0;
|
|
54799
54817
|
const oldest = typeof window?.oldest_at === "string" ? window.oldest_at : void 0;
|
|
54800
54818
|
const newest = typeof window?.newest_at === "string" ? window.newest_at : void 0;
|
|
54801
54819
|
if (!window || !oldest || !newest) return [];
|
|
@@ -54803,12 +54821,12 @@ function windowLine(data, tested) {
|
|
|
54803
54821
|
}
|
|
54804
54822
|
/** The stderr report and exit code of a test-email-rule answer. */
|
|
54805
54823
|
function testEmailRuleReport(data) {
|
|
54806
|
-
if (!isRecord$
|
|
54824
|
+
if (!isRecord$2(data)) return { lines: [] };
|
|
54807
54825
|
const name = sampleNamer();
|
|
54808
54826
|
const result = data;
|
|
54809
54827
|
const results = Array.isArray(result.results) ? result.results : [];
|
|
54810
|
-
const summary = isRecord$
|
|
54811
|
-
const counts = isRecord$
|
|
54828
|
+
const summary = isRecord$2(result.summary) ? result.summary : void 0;
|
|
54829
|
+
const counts = isRecord$2(data.counts) ? data.counts : void 0;
|
|
54812
54830
|
return {
|
|
54813
54831
|
lines: [
|
|
54814
54832
|
...windowLine(data, (typeof counts?.emails === "number" ? counts.emails : results.length) - (typeof counts?.not_found === "number" ? counts.not_found : 0)),
|
|
@@ -55306,6 +55324,468 @@ function withFlagSuggestion(error, valid) {
|
|
|
55306
55324
|
].join("\n");
|
|
55307
55325
|
return error;
|
|
55308
55326
|
}
|
|
55327
|
+
// src/oclif/focus.ts
|
|
55328
|
+
const FOCUS_ENV = "PRIMITIVE_FOCUS_DOMAINS";
|
|
55329
|
+
/**
|
|
55330
|
+
* The request parameter each kind of listing filters domains with, a list of
|
|
55331
|
+
* domain ids, or null where the server has none. A command whose parameter is
|
|
55332
|
+
* null runs unfiltered and says the focus was not applied.
|
|
55333
|
+
*
|
|
55334
|
+
* inbound: GET /emails and GET /emails/search (the receiving domain). sent:
|
|
55335
|
+
* GET /sent-emails (the sending domain). semantic: the POST /semantic-search
|
|
55336
|
+
* body, which then searches received mail only. `many` says a focus may name
|
|
55337
|
+
* several domains; while false it names one at a time.
|
|
55338
|
+
*/
|
|
55339
|
+
const FOCUS_SERVER_SUPPORT = {
|
|
55340
|
+
inbound: "domain_ids",
|
|
55341
|
+
sent: "domain_ids",
|
|
55342
|
+
semantic: "domain_ids",
|
|
55343
|
+
many: true
|
|
55344
|
+
};
|
|
55345
|
+
const NO_FOCUS = {
|
|
55346
|
+
params: {},
|
|
55347
|
+
meta: null,
|
|
55348
|
+
line: null,
|
|
55349
|
+
focused: null,
|
|
55350
|
+
readable: null
|
|
55351
|
+
};
|
|
55352
|
+
const DOMAIN_FLAG_DESCRIPTION = "Only mail on this domain, by name, for this command (overrides the saved focus and PRIMITIVE_FOCUS_DOMAINS). See `primitive focus`.";
|
|
55353
|
+
const ALL_DOMAINS_FLAG_DESCRIPTION = "Mail on every domain this credential reads, for this command, ignoring the saved focus and PRIMITIVE_FOCUS_DOMAINS.";
|
|
55354
|
+
/** The two focus flags every focused listing takes. */
|
|
55355
|
+
/**
|
|
55356
|
+
* The two focus flags every focused listing takes. `unfiltered` marks a
|
|
55357
|
+
* command the server cannot filter by domain yet, whose --domain is refused.
|
|
55358
|
+
*/
|
|
55359
|
+
function focusFlags(unfiltered = false) {
|
|
55360
|
+
return {
|
|
55361
|
+
domain: Flags.string({
|
|
55362
|
+
description: unfiltered ? "Not available here yet: this command cannot filter by domain, so it lists every domain. See `primitive focus`." : DOMAIN_FLAG_DESCRIPTION,
|
|
55363
|
+
multiple: true,
|
|
55364
|
+
multipleNonGreedy: true
|
|
55365
|
+
}),
|
|
55366
|
+
"all-domains": Flags.boolean({ description: ALL_DOMAINS_FLAG_DESCRIPTION })
|
|
55367
|
+
};
|
|
55368
|
+
}
|
|
55369
|
+
function focusFlagValues(flags) {
|
|
55370
|
+
const domain = flags.domain;
|
|
55371
|
+
return {
|
|
55372
|
+
domain: Array.isArray(domain) ? domain.filter((d) => typeof d === "string") : typeof domain === "string" ? [domain] : void 0,
|
|
55373
|
+
allDomains: flags["all-domains"] === true
|
|
55374
|
+
};
|
|
55375
|
+
}
|
|
55376
|
+
const FOCUS_FILE = "focus.json";
|
|
55377
|
+
function focusProfile(configDir, auth) {
|
|
55378
|
+
const name = auth.connectedAgent?.profileName;
|
|
55379
|
+
if (name) return {
|
|
55380
|
+
kind: "agent",
|
|
55381
|
+
name,
|
|
55382
|
+
path: join(agentProfileDirectory(configDir, name), FOCUS_FILE)
|
|
55383
|
+
};
|
|
55384
|
+
return {
|
|
55385
|
+
kind: "member",
|
|
55386
|
+
path: join(configDir, FOCUS_FILE)
|
|
55387
|
+
};
|
|
55388
|
+
}
|
|
55389
|
+
function isRecord$1(value) {
|
|
55390
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
55391
|
+
}
|
|
55392
|
+
function parseChoice(value) {
|
|
55393
|
+
if (!isRecord$1(value)) return null;
|
|
55394
|
+
if (value.all === true) return { all: true };
|
|
55395
|
+
if (!Array.isArray(value.domains)) return null;
|
|
55396
|
+
const domains = [];
|
|
55397
|
+
for (const entry of value.domains) {
|
|
55398
|
+
if (!isRecord$1(entry) || typeof entry.name !== "string" || typeof entry.id !== "string") return null;
|
|
55399
|
+
domains.push({
|
|
55400
|
+
name: entry.name,
|
|
55401
|
+
id: entry.id
|
|
55402
|
+
});
|
|
55403
|
+
}
|
|
55404
|
+
return domains.length > 0 ? { domains } : null;
|
|
55405
|
+
}
|
|
55406
|
+
function parseSaved(value) {
|
|
55407
|
+
if (!isRecord$1(value)) return null;
|
|
55408
|
+
return {
|
|
55409
|
+
choice: parseChoice(value.choice),
|
|
55410
|
+
...typeof value.chosen_at === "string" ? { chosen_at: value.chosen_at } : {}
|
|
55411
|
+
};
|
|
55412
|
+
}
|
|
55413
|
+
function readFocusFile(path) {
|
|
55414
|
+
let raw;
|
|
55415
|
+
try {
|
|
55416
|
+
raw = readFileSync(path, "utf8");
|
|
55417
|
+
} catch {
|
|
55418
|
+
return {
|
|
55419
|
+
version: 1,
|
|
55420
|
+
orgs: {}
|
|
55421
|
+
};
|
|
55422
|
+
}
|
|
55423
|
+
try {
|
|
55424
|
+
const parsed = JSON.parse(raw);
|
|
55425
|
+
if (!isRecord$1(parsed) || !isRecord$1(parsed.orgs)) return {
|
|
55426
|
+
version: 1,
|
|
55427
|
+
orgs: {}
|
|
55428
|
+
};
|
|
55429
|
+
const orgs = {};
|
|
55430
|
+
for (const [org, saved] of Object.entries(parsed.orgs)) {
|
|
55431
|
+
const value = parseSaved(saved);
|
|
55432
|
+
if (value) orgs[org] = value;
|
|
55433
|
+
}
|
|
55434
|
+
return {
|
|
55435
|
+
version: 1,
|
|
55436
|
+
orgs
|
|
55437
|
+
};
|
|
55438
|
+
} catch {
|
|
55439
|
+
return {
|
|
55440
|
+
version: 1,
|
|
55441
|
+
orgs: {}
|
|
55442
|
+
};
|
|
55443
|
+
}
|
|
55444
|
+
}
|
|
55445
|
+
function writeFocusFile(path, file) {
|
|
55446
|
+
mkdirSync(dirname(path), {
|
|
55447
|
+
recursive: true,
|
|
55448
|
+
mode: 448
|
|
55449
|
+
});
|
|
55450
|
+
const temporary = `${path}.${process.pid}.${randomUUID()}.tmp`;
|
|
55451
|
+
try {
|
|
55452
|
+
writeFileSync(temporary, `${JSON.stringify(file, null, 2)}\n`, { mode: 384 });
|
|
55453
|
+
renameSync(temporary, path);
|
|
55454
|
+
} catch (error) {
|
|
55455
|
+
rmSync(temporary, { force: true });
|
|
55456
|
+
throw error;
|
|
55457
|
+
}
|
|
55458
|
+
}
|
|
55459
|
+
function loadSavedFocus(profile, orgId) {
|
|
55460
|
+
return readFocusFile(profile.path).orgs[orgId] ?? null;
|
|
55461
|
+
}
|
|
55462
|
+
function saveFocus(profile, orgId, update) {
|
|
55463
|
+
const file = readFocusFile(profile.path);
|
|
55464
|
+
const next = update(file.orgs[orgId] ?? null);
|
|
55465
|
+
if (next === null) delete file.orgs[orgId];
|
|
55466
|
+
else file.orgs[orgId] = next;
|
|
55467
|
+
writeFocusFile(profile.path, file);
|
|
55468
|
+
}
|
|
55469
|
+
/** How long reading the domains may take before focus gives up on them. */
|
|
55470
|
+
const DOMAINS_TIMEOUT_MS = 5e3;
|
|
55471
|
+
/**
|
|
55472
|
+
* The verified domains this credential can read mail on, from GET /domains,
|
|
55473
|
+
* which lists only the domains a credential confined to some mailboxes
|
|
55474
|
+
* reaches. Null when they cannot be read.
|
|
55475
|
+
*/
|
|
55476
|
+
async function readReadableDomains(client, timeoutMs = DOMAINS_TIMEOUT_MS) {
|
|
55477
|
+
try {
|
|
55478
|
+
const result = await listDomains({
|
|
55479
|
+
client,
|
|
55480
|
+
responseStyle: "fields",
|
|
55481
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
55482
|
+
});
|
|
55483
|
+
if (result.error) return null;
|
|
55484
|
+
const rows = result.data?.data;
|
|
55485
|
+
if (!Array.isArray(rows)) return null;
|
|
55486
|
+
let orgId = null;
|
|
55487
|
+
const domains = [];
|
|
55488
|
+
for (const row of rows) {
|
|
55489
|
+
if (!isRecord$1(row) || row.verified !== true) continue;
|
|
55490
|
+
if (typeof row.id !== "string" || typeof row.domain !== "string") continue;
|
|
55491
|
+
if (typeof row.org_id === "string") orgId ??= row.org_id;
|
|
55492
|
+
domains.push({
|
|
55493
|
+
name: row.domain.toLowerCase(),
|
|
55494
|
+
id: row.id
|
|
55495
|
+
});
|
|
55496
|
+
}
|
|
55497
|
+
domains.sort((a, b) => a.name.localeCompare(b.name));
|
|
55498
|
+
return {
|
|
55499
|
+
orgId,
|
|
55500
|
+
domains
|
|
55501
|
+
};
|
|
55502
|
+
} catch {
|
|
55503
|
+
return null;
|
|
55504
|
+
}
|
|
55505
|
+
}
|
|
55506
|
+
function focusError(message, code, exit, details) {
|
|
55507
|
+
const error = new Errors.CLIError(message, {
|
|
55508
|
+
exit,
|
|
55509
|
+
code
|
|
55510
|
+
});
|
|
55511
|
+
if (details) error.details = details;
|
|
55512
|
+
return error;
|
|
55513
|
+
}
|
|
55514
|
+
function joinNames(names) {
|
|
55515
|
+
if (names.length <= 1) return names[0] ?? "";
|
|
55516
|
+
return `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`;
|
|
55517
|
+
}
|
|
55518
|
+
/** The refusal a multi-domain credential sees once before it chooses. */
|
|
55519
|
+
function focusRequiredError(domains) {
|
|
55520
|
+
const names = domains.map((d) => d.name);
|
|
55521
|
+
const example = names[0] ?? "<domain>";
|
|
55522
|
+
return focusError(`This credential reads mail on ${names.length} domains: ${joinNames(names)}. Choose which this profile lists and searches: \`primitive focus set ${example}\` (one or more domains) or \`primitive focus set --all\` (every domain). The choice is saved for this profile, and listings and searches are refused until it is made; for one command, pass --domain <name> or --all-domains.`, "focus_required", 2, {
|
|
55523
|
+
domains: names,
|
|
55524
|
+
choices: ["primitive focus set <domain...>", "primitive focus set --all"]
|
|
55525
|
+
});
|
|
55526
|
+
}
|
|
55527
|
+
/** Refused while the server filters one domain at a time. */
|
|
55528
|
+
function oneDomainAtATimeError(names) {
|
|
55529
|
+
return focusError(`A focus names one domain for now (got ${joinNames(names)}): mail listings filter one domain at a time. Name one, or use --all-domains.`, "usage_error", 2);
|
|
55530
|
+
}
|
|
55531
|
+
/** Whether a focus may name more than one domain. */
|
|
55532
|
+
function manyDomainsSupported() {
|
|
55533
|
+
return FOCUS_SERVER_SUPPORT.many;
|
|
55534
|
+
}
|
|
55535
|
+
/** Names normalized: trimmed, lower case, without duplicates. */
|
|
55536
|
+
function normalizeDomainNames(names) {
|
|
55537
|
+
const seen = /* @__PURE__ */ new Set();
|
|
55538
|
+
for (const raw of names) for (const part of raw.split(/[\s,]+/)) {
|
|
55539
|
+
const name = part.trim().toLowerCase().replace(/\.$/, "");
|
|
55540
|
+
if (name) seen.add(name);
|
|
55541
|
+
}
|
|
55542
|
+
return [...seen];
|
|
55543
|
+
}
|
|
55544
|
+
/** The named domains, looked up among the readable ones, or an error naming those missing. */
|
|
55545
|
+
function resolveDomainNames(names, readable, origin) {
|
|
55546
|
+
const byName = new Map(readable.map((d) => [d.name, d]));
|
|
55547
|
+
const missing = names.filter((n) => !byName.has(n));
|
|
55548
|
+
if (missing.length > 0) throw focusError(`${origin} names ${joinNames(missing)}, which ${missing.length === 1 ? "is not a domain" : "are not domains"} this credential reads mail on. ${readable.length > 0 ? `It reads ${joinNames(readable.map((d) => d.name))}.` : "It reads no verified domain."}`, "focus_domain_unknown", 2, {
|
|
55549
|
+
unknown: missing,
|
|
55550
|
+
domains: readable.map((d) => d.name)
|
|
55551
|
+
});
|
|
55552
|
+
return names.map((n) => byName.get(n));
|
|
55553
|
+
}
|
|
55554
|
+
/** A saved domain the credential no longer reads (deleted, or access removed). */
|
|
55555
|
+
function focusDomainGoneError(gone, profile) {
|
|
55556
|
+
const names = gone.map((d) => d.name);
|
|
55557
|
+
return focusError(`The saved focus${profile.kind === "agent" ? ` of agent profile ${profile.name}` : ""} names ${joinNames(names)}, which this credential no longer reads mail on (the domain may have been deleted). Choose again with \`primitive focus set <domain...>\` or \`primitive focus set --all\`, or run \`primitive focus clear\`.`, "focus_domain_missing", 1, { missing: names });
|
|
55558
|
+
}
|
|
55559
|
+
function requested(flags, env) {
|
|
55560
|
+
if (flags.allDomains && flags.domain && flags.domain.length > 0) throw focusError("Pass --domain or --all-domains, not both.", "usage_error", 2);
|
|
55561
|
+
if (flags.allDomains) return {
|
|
55562
|
+
source: "flag",
|
|
55563
|
+
all: true
|
|
55564
|
+
};
|
|
55565
|
+
if (flags.domain && flags.domain.length > 0) {
|
|
55566
|
+
const names = normalizeDomainNames(flags.domain);
|
|
55567
|
+
if (names.length === 0) throw focusError("--domain needs a domain name.", "usage_error", 2);
|
|
55568
|
+
return {
|
|
55569
|
+
source: "flag",
|
|
55570
|
+
names
|
|
55571
|
+
};
|
|
55572
|
+
}
|
|
55573
|
+
const fromEnv = env[FOCUS_ENV]?.trim();
|
|
55574
|
+
if (fromEnv) {
|
|
55575
|
+
if (fromEnv.toLowerCase() === "all") return {
|
|
55576
|
+
source: "env",
|
|
55577
|
+
all: true
|
|
55578
|
+
};
|
|
55579
|
+
return {
|
|
55580
|
+
source: "env",
|
|
55581
|
+
names: normalizeDomainNames([fromEnv])
|
|
55582
|
+
};
|
|
55583
|
+
}
|
|
55584
|
+
return null;
|
|
55585
|
+
}
|
|
55586
|
+
const SOURCE_TEXT = {
|
|
55587
|
+
flag: "from --domain",
|
|
55588
|
+
env: `from ${FOCUS_ENV}`,
|
|
55589
|
+
profile: "saved focus"
|
|
55590
|
+
};
|
|
55591
|
+
function widenFor(source) {
|
|
55592
|
+
if (source === "flag") return ["drop --domain", "--all-domains"];
|
|
55593
|
+
if (source === "env") return ["--all-domains", `unset ${FOCUS_ENV}`];
|
|
55594
|
+
return ["--all-domains", "primitive focus clear"];
|
|
55595
|
+
}
|
|
55596
|
+
/**
|
|
55597
|
+
* How this listing is focused: from --domain or --all-domains, then
|
|
55598
|
+
* PRIMITIVE_FOCUS_DOMAINS, then the profile's saved focus. A credential that
|
|
55599
|
+
* reads mail on more than one domain and never chose is refused once with
|
|
55600
|
+
* `focus_required` (exit 2); after that refusal, or once it chose, it is
|
|
55601
|
+
* never asked again. A credential with one domain never sees any of it.
|
|
55602
|
+
*/
|
|
55603
|
+
async function resolveFocus(params) {
|
|
55604
|
+
const env = params.env ?? process.env;
|
|
55605
|
+
const asked = requested(params.flags, env);
|
|
55606
|
+
if (params.explicitScope && asked?.source !== "flag") return NO_FOCUS;
|
|
55607
|
+
if (params.conflictingFlag && asked?.source === "flag" && "names" in asked) throw focusError(`Pass --domain or ${params.conflictingFlag}, not both.`, "usage_error", 2);
|
|
55608
|
+
if (asked?.source === "flag" && "all" in asked) return {
|
|
55609
|
+
...NO_FOCUS,
|
|
55610
|
+
meta: {
|
|
55611
|
+
domains: [],
|
|
55612
|
+
all: true,
|
|
55613
|
+
source: asked.source,
|
|
55614
|
+
applied: true,
|
|
55615
|
+
widen: []
|
|
55616
|
+
}
|
|
55617
|
+
};
|
|
55618
|
+
const profile = focusProfile(params.configDir, params.auth);
|
|
55619
|
+
const readable = await (params.readDomains ?? readReadableDomains)(params.client);
|
|
55620
|
+
const orgId = readable?.orgId ?? params.auth.connectedAgent?.orgId ?? params.auth.credentials?.org_id ?? null;
|
|
55621
|
+
if (asked?.source === "env" && readable && readable.domains.length <= 1) return NO_FOCUS;
|
|
55622
|
+
if (asked && "all" in asked) return {
|
|
55623
|
+
...NO_FOCUS,
|
|
55624
|
+
meta: {
|
|
55625
|
+
domains: [],
|
|
55626
|
+
all: true,
|
|
55627
|
+
source: asked.source,
|
|
55628
|
+
applied: true,
|
|
55629
|
+
widen: []
|
|
55630
|
+
}
|
|
55631
|
+
};
|
|
55632
|
+
if (asked) {
|
|
55633
|
+
if (!readable) throw focusError(`Could not read this credential's domains to look up ${joinNames(asked.names)}; retry, or pass --all-domains.`, "focus_lookup_failed", 1);
|
|
55634
|
+
const domains = resolveDomainNames(asked.names, readable.domains, asked.source === "flag" ? "--domain" : FOCUS_ENV);
|
|
55635
|
+
return focusedOutcome(params.surface, domains, asked.source, readable);
|
|
55636
|
+
}
|
|
55637
|
+
const choice = (orgId ? loadSavedFocus(profile, orgId) : null)?.choice ?? null;
|
|
55638
|
+
if (readable && choice && "domains" in choice) {
|
|
55639
|
+
const ids = new Set(readable.domains.map((d) => d.id));
|
|
55640
|
+
const gone = choice.domains.filter((d) => !ids.has(d.id));
|
|
55641
|
+
if (gone.length > 0) throw focusDomainGoneError(gone, profile);
|
|
55642
|
+
}
|
|
55643
|
+
if (readable && readable.domains.length <= 1) return NO_FOCUS;
|
|
55644
|
+
if (choice) {
|
|
55645
|
+
if ("all" in choice) return {
|
|
55646
|
+
...NO_FOCUS,
|
|
55647
|
+
readable: readable?.domains ?? null,
|
|
55648
|
+
meta: {
|
|
55649
|
+
domains: [],
|
|
55650
|
+
all: true,
|
|
55651
|
+
source: "profile",
|
|
55652
|
+
applied: true,
|
|
55653
|
+
widen: []
|
|
55654
|
+
}
|
|
55655
|
+
};
|
|
55656
|
+
return focusedOutcome(params.surface, choice.domains, "profile", readable);
|
|
55657
|
+
}
|
|
55658
|
+
if (!readable || !orgId) return NO_FOCUS;
|
|
55659
|
+
throw focusRequiredError(readable.domains);
|
|
55660
|
+
}
|
|
55661
|
+
/** The request fields for a focus on these domains, or null where the surface cannot filter. */
|
|
55662
|
+
function focusParams(surface, domains) {
|
|
55663
|
+
const ids = domains.map((d) => d.id);
|
|
55664
|
+
const name = FOCUS_SERVER_SUPPORT[surface];
|
|
55665
|
+
if (!name) return null;
|
|
55666
|
+
if (ids.length > 50) throw focusError(`A focus names at most 50 domains (got ${ids.length}). Name fewer, or use --all-domains.`, "usage_error", 2);
|
|
55667
|
+
if (ids.length > 1 && !FOCUS_SERVER_SUPPORT.many) throw oneDomainAtATimeError(domains.map((d) => d.name));
|
|
55668
|
+
return { [name]: surface === "semantic" ? ids : ids.join(",") };
|
|
55669
|
+
}
|
|
55670
|
+
function focusedOutcome(surface, domains, source, readable) {
|
|
55671
|
+
const names = domains.map((d) => d.name);
|
|
55672
|
+
const params = focusParams(surface, domains);
|
|
55673
|
+
const widen = widenFor(source);
|
|
55674
|
+
if (params === null) {
|
|
55675
|
+
if (source === "flag") throw focusError("--domain cannot filter this command yet: it lists every domain. Leave --domain out.", "usage_error", 2);
|
|
55676
|
+
return {
|
|
55677
|
+
params: {},
|
|
55678
|
+
focused: null,
|
|
55679
|
+
readable: readable?.domains ?? null,
|
|
55680
|
+
meta: {
|
|
55681
|
+
domains: names,
|
|
55682
|
+
all: false,
|
|
55683
|
+
source,
|
|
55684
|
+
applied: false,
|
|
55685
|
+
widen
|
|
55686
|
+
},
|
|
55687
|
+
line: `Focus on ${joinNames(names)} (${SOURCE_TEXT[source]}) not applied: this command cannot filter by domain yet, so it shows every domain.`
|
|
55688
|
+
};
|
|
55689
|
+
}
|
|
55690
|
+
return {
|
|
55691
|
+
params,
|
|
55692
|
+
focused: domains,
|
|
55693
|
+
readable: readable?.domains ?? null,
|
|
55694
|
+
meta: {
|
|
55695
|
+
domains: names,
|
|
55696
|
+
all: false,
|
|
55697
|
+
source,
|
|
55698
|
+
applied: true,
|
|
55699
|
+
widen,
|
|
55700
|
+
...surface === "semantic" ? { received_only: true } : {}
|
|
55701
|
+
},
|
|
55702
|
+
line: `Showing mail on ${joinNames(names)} only (${SOURCE_TEXT[source]})${surface === "semantic" ? ", received mail only" : ""}. Widen: ${widenFor(source).join(" or ")}.`
|
|
55703
|
+
};
|
|
55704
|
+
}
|
|
55705
|
+
/** A listing answer's total as an ElsewhereCount, or null when it has none. */
|
|
55706
|
+
function countFromMeta(data, bound) {
|
|
55707
|
+
const meta = isRecord$1(data) && isRecord$1(data.meta) ? data.meta : null;
|
|
55708
|
+
if (!meta || typeof meta.total !== "number") return null;
|
|
55709
|
+
return {
|
|
55710
|
+
total: meta.total,
|
|
55711
|
+
bound: bound ?? (meta.total_capped === true ? "atLeast" : void 0)
|
|
55712
|
+
};
|
|
55713
|
+
}
|
|
55714
|
+
/**
|
|
55715
|
+
* The note an empty focused result adds: how much matching mail the other
|
|
55716
|
+
* domains hold. `countElsewhere` runs the same request without the focus and
|
|
55717
|
+
* returns its count, or null when it cannot be read. Null when the result was
|
|
55718
|
+
* not focused.
|
|
55719
|
+
*/
|
|
55720
|
+
async function focusEmptyHint(outcome, countElsewhere) {
|
|
55721
|
+
if (!outcome.focused) return null;
|
|
55722
|
+
const names = joinNames(outcome.focused.map((d) => d.name));
|
|
55723
|
+
let count;
|
|
55724
|
+
try {
|
|
55725
|
+
count = await countElsewhere();
|
|
55726
|
+
} catch {
|
|
55727
|
+
count = null;
|
|
55728
|
+
}
|
|
55729
|
+
const total = count?.total ?? null;
|
|
55730
|
+
const prefix = count?.bound === "atLeast" ? "at least " : count?.bound === "upTo" ? "up to " : "";
|
|
55731
|
+
if (total === null) return `Nothing matched on ${names}. Other domains may hold matching mail: pass --all-domains to look.`;
|
|
55732
|
+
if (total === 0) return `Nothing matched on ${names}, and nothing matches on the other domains either.`;
|
|
55733
|
+
return `Nothing matched on ${names}; ${prefix}${total} matching email${total === 1 ? "" : "s"} on other domains. Pass --all-domains to see ${total === 1 && !count?.bound ? "it" : "them"}.`;
|
|
55734
|
+
}
|
|
55735
|
+
/**
|
|
55736
|
+
* Whether a search query scopes itself with a domain: or to: filter. Quoted
|
|
55737
|
+
* phrases are text, not filters, so they are left out.
|
|
55738
|
+
*/
|
|
55739
|
+
function queryScopesItself(q) {
|
|
55740
|
+
if (!q) return false;
|
|
55741
|
+
const unquoted = q.replace(/"(?:\\"|[^"])*"/g, " ");
|
|
55742
|
+
return /(?:^|\s)(?:domain|to):/i.test(unquoted);
|
|
55743
|
+
}
|
|
55744
|
+
/**
|
|
55745
|
+
* Semantic search filters domains on received mail only, and refuses a domain
|
|
55746
|
+
* filter with sent mail in --corpus. Such a search keeps every domain and says
|
|
55747
|
+
* the focus was not applied; a --domain given with it is refused.
|
|
55748
|
+
*/
|
|
55749
|
+
function focusForCorpus(outcome, corpus) {
|
|
55750
|
+
if (!outcome.focused || !corpus?.includes("outbound")) return outcome;
|
|
55751
|
+
const names = outcome.focused.map((d) => d.name);
|
|
55752
|
+
const source = outcome.meta?.source ?? "profile";
|
|
55753
|
+
if (source === "flag") throw focusError("--domain filters received mail only: drop --corpus outbound, or leave --domain out.", "usage_error", 2);
|
|
55754
|
+
return {
|
|
55755
|
+
...outcome,
|
|
55756
|
+
params: {},
|
|
55757
|
+
focused: null,
|
|
55758
|
+
meta: outcome.meta ? {
|
|
55759
|
+
...outcome.meta,
|
|
55760
|
+
applied: false,
|
|
55761
|
+
received_only: void 0
|
|
55762
|
+
} : null,
|
|
55763
|
+
line: `Focus on ${joinNames(names)} (${SOURCE_TEXT[source]}) not applied: --corpus outbound includes sent mail, which a domain focus does not filter, so this search covers every domain.`
|
|
55764
|
+
};
|
|
55765
|
+
}
|
|
55766
|
+
/** Remove the focus fields from a query, for the elsewhere count. */
|
|
55767
|
+
function withoutFocus(query, outcome) {
|
|
55768
|
+
const rest = { ...query };
|
|
55769
|
+
for (const key of Object.keys(outcome.params)) delete rest[key];
|
|
55770
|
+
return rest;
|
|
55771
|
+
}
|
|
55772
|
+
/** Write the focus line to stderr unless --json. */
|
|
55773
|
+
function writeFocusLine(outcome, json) {
|
|
55774
|
+
if (!json && outcome.line) process.stderr.write(`${outcome.line}\n`);
|
|
55775
|
+
}
|
|
55776
|
+
/** The envelope with `meta.focus` added, when there is a focus to report. */
|
|
55777
|
+
function withFocusMeta(envelope, outcome) {
|
|
55778
|
+
if (!outcome.meta || envelope === null || typeof envelope !== "object") return envelope;
|
|
55779
|
+
const record = envelope;
|
|
55780
|
+
const meta = isRecord$1(record.meta) ? record.meta : {};
|
|
55781
|
+
return {
|
|
55782
|
+
...record,
|
|
55783
|
+
meta: {
|
|
55784
|
+
...meta,
|
|
55785
|
+
focus: outcome.meta
|
|
55786
|
+
}
|
|
55787
|
+
};
|
|
55788
|
+
}
|
|
55309
55789
|
// src/oclif/from-verified-filter.ts
|
|
55310
55790
|
/**
|
|
55311
55791
|
* The `from_verified` filter on GET /emails and GET /emails/search: the
|
|
@@ -57076,7 +57556,7 @@ function savedConnectedProfiles(configDir, exclude) {
|
|
|
57076
57556
|
*/
|
|
57077
57557
|
async function otherProfiles(configDir, session, current) {
|
|
57078
57558
|
if (session) try {
|
|
57079
|
-
const { connectedProfilesForSession } = await import("./machine-session-
|
|
57559
|
+
const { connectedProfilesForSession } = await import("./machine-session-ADcw9uJm.js").then((n) => n.s);
|
|
57080
57560
|
return {
|
|
57081
57561
|
inSession: true,
|
|
57082
57562
|
profiles: connectedProfilesForSession(configDir, session, current)
|
|
@@ -58077,6 +58557,14 @@ function buildFlags(operation) {
|
|
|
58077
58557
|
default: true,
|
|
58078
58558
|
description: ATTACHMENT_WAIT_FLAG_DESCRIPTION
|
|
58079
58559
|
});
|
|
58560
|
+
if (FOCUS_OPERATIONS[operation.sdkName]) {
|
|
58561
|
+
const spec = FOCUS_OPERATIONS[operation.sdkName];
|
|
58562
|
+
const unfiltered = spec?.surface !== void 0 && spec.surface !== "inbound" && FOCUS_SERVER_SUPPORT[spec.surface] === null;
|
|
58563
|
+
for (const [name, flag] of Object.entries(focusFlags(unfiltered))) {
|
|
58564
|
+
if (flags[name] !== void 0) throw new Error(`${operation.sdkName}: --${name} is both a generated flag and the focus flag`);
|
|
58565
|
+
flags[name] = flag;
|
|
58566
|
+
}
|
|
58567
|
+
}
|
|
58080
58568
|
const extension = OPERATION_EXTENSIONS[operation.sdkName];
|
|
58081
58569
|
for (const [name, flag] of Object.entries(extension?.flags ?? {})) {
|
|
58082
58570
|
if (flags[name] !== void 0) throw new Error(`${operation.sdkName}: --${name} is both a generated flag and a CLI extension flag`);
|
|
@@ -58226,6 +58714,44 @@ const OPERATION_SUCCESS_HOOKS = { verifyAgentSignup: ({ envelope, configDir, api
|
|
|
58226
58714
|
});
|
|
58227
58715
|
writeStderr("Credentials saved to the CLI config; `primitive whoami` will work on the next call.\n");
|
|
58228
58716
|
} };
|
|
58717
|
+
/**
|
|
58718
|
+
* The generated listings that follow the domain focus, keyed by sdkName: the
|
|
58719
|
+
* kind of listing, and the query parameters that give a request a scope of
|
|
58720
|
+
* its own, which then wins over the session's and the profile's focus.
|
|
58721
|
+
*/
|
|
58722
|
+
const FOCUS_OPERATIONS = {
|
|
58723
|
+
listEmails: {
|
|
58724
|
+
surface: "inbound",
|
|
58725
|
+
scopeParams: [
|
|
58726
|
+
"domain_ids",
|
|
58727
|
+
"recipient",
|
|
58728
|
+
"thread_id"
|
|
58729
|
+
],
|
|
58730
|
+
countParam: "count"
|
|
58731
|
+
},
|
|
58732
|
+
searchEmails: {
|
|
58733
|
+
surface: "inbound",
|
|
58734
|
+
scopeParams: [
|
|
58735
|
+
"domain_ids",
|
|
58736
|
+
"to",
|
|
58737
|
+
"thread_id",
|
|
58738
|
+
"reply_to_sent_email_id"
|
|
58739
|
+
],
|
|
58740
|
+
scopeDsl: true,
|
|
58741
|
+
countParam: "count"
|
|
58742
|
+
},
|
|
58743
|
+
listSentEmails: {
|
|
58744
|
+
surface: "sent",
|
|
58745
|
+
scopeParams: ["from", "domain_ids"]
|
|
58746
|
+
}
|
|
58747
|
+
};
|
|
58748
|
+
/** Whether a query already scopes itself to some domain or mailbox. */
|
|
58749
|
+
function queryHasOwnScope(sdkName, query) {
|
|
58750
|
+
const spec = FOCUS_OPERATIONS[sdkName];
|
|
58751
|
+
if (!spec) return false;
|
|
58752
|
+
if (spec.scopeParams.some((name) => query[name] !== void 0)) return true;
|
|
58753
|
+
return Boolean(spec.scopeDsl && typeof query.q === "string" && queryScopesItself(query.q));
|
|
58754
|
+
}
|
|
58229
58755
|
function createOperationCommand(operation) {
|
|
58230
58756
|
const { flags, bodyFieldFlagToProperty, headerFlagToName } = buildFlags(operation);
|
|
58231
58757
|
const dashboardOnly = isDashboardOnly(operation);
|
|
@@ -58309,7 +58835,21 @@ function createOperationCommand(operation) {
|
|
|
58309
58835
|
if (tooLong) throw new Errors.CLIError(tooLong, { exit: 2 });
|
|
58310
58836
|
const operationFn = sdk_gen_exports[operation.sdkName];
|
|
58311
58837
|
const given = collectValues(operation.queryParams, parsedFlags, operation.sdkName);
|
|
58312
|
-
const
|
|
58838
|
+
const unfocused = operation.sdkName === "listSentEmails" ? withMineDefault(given, parsedFlags) : given;
|
|
58839
|
+
const focusSpec = FOCUS_OPERATIONS[operation.sdkName];
|
|
58840
|
+
const focus = focusSpec ? await resolveFocus({
|
|
58841
|
+
surface: focusSpec.surface,
|
|
58842
|
+
configDir: this.config.configDir,
|
|
58843
|
+
auth,
|
|
58844
|
+
client: apiClient.client,
|
|
58845
|
+
flags: focusFlagValues(parsedFlags),
|
|
58846
|
+
explicitScope: queryHasOwnScope(operation.sdkName, unfocused),
|
|
58847
|
+
conflictingFlag: unfocused.domain_ids !== void 0 ? "--domain-ids" : void 0
|
|
58848
|
+
}) : NO_FOCUS;
|
|
58849
|
+
const query = {
|
|
58850
|
+
...unfocused,
|
|
58851
|
+
...focus.params
|
|
58852
|
+
};
|
|
58313
58853
|
const replyStateSurface = replyStateSurfaceForOperation(operation.sdkName, query);
|
|
58314
58854
|
const automatedSurface = automatedSurfaceForOperation(operation.sdkName, query);
|
|
58315
58855
|
const fromVerified = fromVerifiedExpectation(operation.sdkName, query);
|
|
@@ -58477,6 +59017,7 @@ function createOperationCommand(operation) {
|
|
|
58477
59017
|
return;
|
|
58478
59018
|
}
|
|
58479
59019
|
const jsonOutput = parsedFlags.json === true;
|
|
59020
|
+
writeFocusLine(focus, jsonOutput);
|
|
58480
59021
|
const cursor = envelope?.meta?.cursor;
|
|
58481
59022
|
if (cursor && !jsonOutput) process.stderr.write(`next cursor: ${cursor}\n`);
|
|
58482
59023
|
if (pagingNote && !jsonOutput) process.stderr.write(`${pagingNote}\n`);
|
|
@@ -58493,6 +59034,20 @@ function createOperationCommand(operation) {
|
|
|
58493
59034
|
if (hint && jsonOutput) summary.push(hint);
|
|
58494
59035
|
else if (hint) process.stderr.write(`${hint}\n`);
|
|
58495
59036
|
}
|
|
59037
|
+
if (Array.isArray(envelope?.data) && envelope.data.length === 0 && focus.focused && query.since === void 0 && query.cursor === void 0) {
|
|
59038
|
+
const countParam = focusSpec?.countParam;
|
|
59039
|
+
const note = await focusEmptyHint(focus, async () => {
|
|
59040
|
+
const counted = await callOperation(void 0, {
|
|
59041
|
+
...withoutFocus(query, focus),
|
|
59042
|
+
limit: 1,
|
|
59043
|
+
...countParam ? { [countParam]: "true" } : {}
|
|
59044
|
+
});
|
|
59045
|
+
if (counted.error) return null;
|
|
59046
|
+
return countFromMeta(counted.data);
|
|
59047
|
+
});
|
|
59048
|
+
if (note && jsonOutput) summary.push(note);
|
|
59049
|
+
else if (note) process.stderr.write(`${note}\n`);
|
|
59050
|
+
}
|
|
58496
59051
|
if (!jsonOutput) for (const line of metaNoteLines(envelope?.meta)) process.stderr.write(`${line}\n`);
|
|
58497
59052
|
writeIdempotentReplayBannerIfReplay(envelope?.data, { write: (chunk) => {
|
|
58498
59053
|
process.stderr.write(chunk);
|
|
@@ -58539,7 +59094,7 @@ function createOperationCommand(operation) {
|
|
|
58539
59094
|
}
|
|
58540
59095
|
};
|
|
58541
59096
|
}
|
|
58542
|
-
let printed = jsonOutput ? operationJsonDocument(envelope, summary) : operationOutputPayload(envelope);
|
|
59097
|
+
let printed = jsonOutput ? operationJsonDocument(withFocusMeta(envelope, focus), summary) : operationOutputPayload(envelope);
|
|
58543
59098
|
if (jsonOutput && report?.exitCode && report.error && printed !== null && typeof printed === "object" && !Array.isArray(printed)) printed = {
|
|
58544
59099
|
...printed,
|
|
58545
59100
|
error: report.error
|
|
@@ -58583,4 +59138,4 @@ function emptyDeliveriesHint(sdkName, query) {
|
|
|
58583
59138
|
function canonicalizeCliReferences(description) {
|
|
58584
59139
|
return description.replaceAll("`primitive emails:latest`", "`primitive emails latest`").replaceAll("`primitive describe emails:get-email | jq '.responseSchema.properties'`", "`primitive describe emails:get | jq '.responseSchema.properties'`");
|
|
58585
59140
|
}
|
|
58586
|
-
export { interactionNextActions as $,
|
|
59141
|
+
export { interactionNextActions as $, loadSavedFocus as $t, openBrowser as A, credentialsFromUserLogin as An, thrownErrorExitCode as At, serverRelationship as B, setKnownCommands as Bn, detectRuntimeSession as Bt, approveThenRerunHint as C, createCliApiClient as Cn, sendErrorMessage as Ct, canOfferCopyHotkey as D, selectedOrgFromEnv as Dn, sentHistoryWindowStart as Dt, withApproval as E, resolveCliApiRequestConfig as En, sendWaitClampNotice as Et, formatMailWakeLine as F, roleKeyText as Fn, generatedAgentName as Ft, claimPendingMail as G, NO_FOCUS as Gt, wakeReadCommand as H, formatAlreadySentNotice as Ht, latestOwnOutbound as I, switchCurrentOrg as In, identitySuggestions as It, pendingMailPath as J, focusFlagValues as Jt, clearConsumedPendingMail as K, countFromMeta as Kt, readThreadContext as L, routeWarningLines as Ln, loadSkillLine as Lt, bareAddress as M, isBuiltInRoleKey as Mn, cliInvocation as Mt, describeWake as N, revokeUserLogin as Nn, connectNextSteps as Nt, formatBrowserLoginInstructions as O, CliOrgRefusedError as On, serializeErrorPayload as Ot, displayAddress as P, roleKeyLabel as Pn, defaultConnectionName as Pt, interactionHumanLine as Q, joinNames as Qt, sentInThread as R, sanitizeForTerminal as Rn, currentMailSessionKey as Rt, STEP_UP_TOKEN_FLAG_DESCRIPTION as S, createAuthenticatedCliApiClient as Sn, reportSendCommandResult as St, terminalApprovalIo as T, refuseOrgSelectionForProfile as Tn, sendOutcomeExitCode as Tt, wakeRecipientField as U, FOCUS_ENV as Ut, skillFirstLine as V, operationManifest as Vn, runtimeSessionVariableList as Vt, wakeRelationship as W, FOCUS_SERVER_SUPPORT as Wt, recordPendingMail as X, focusForCorpus as Xt, readPendingMail as Y, focusFlags as Yt, removePendingMail as Z, focusProfile as Zt, surfaceUnauthorizedHint as _, ATTACHMENT_WAIT_FLAG_DESCRIPTION as _n, formatPriorRepliesCheckSkipped as _t, createOperationCommand as a, resolveDomainNames as an, MAX_SEND_WAIT_TIMEOUT_MS as at, BROWSER_FLAG_DESCRIPTION as b, ConnectedAgentKeyRequiredError as bn, formatSendRecordFailureSummary as bt, formatErrorPayload as c, withFocusMeta as cn, assertValidIdempotencyKey as ct, isGrantRefusal as d, withFlagSuggestion as dn, checkPriorReplies as dt, manyDomainsSupported as en, readEmailInteraction as et, networkErrorHint as f, emptyEmailListHint as fn, classifySendError as ft, runWithTiming as g, isEmailId as gn, formatDeletedEarlierSendNotice as gt, refusesCredential as h, formatFact as hn, followUpCommandPrefix as ht, TIME_FLAG_DESCRIPTION as i, readReadableDomains as in, IDEMPOTENCY_KEY_FLAG_DESCRIPTION as it, explainPendingMailNotFound as j, fetchCliOrgs as jn, DEFAULT_ENROLL_NAME as jt, listenForCopyHotkey as k, RESTRICTED_ROLE_NOTE as kn, successfulSendOutcome as kt, hasControlCharacter as l, withoutFocus as ln, buildFollowUpCommand as lt, readTextFileFlag as m, readCallerMailFor as mn, excludeSignalReplies as mt, API_ERROR_CODES as n, oneDomainAtATimeError as nn, replyInteractionWarning as nt, extractErrorCode as o, resolveFocus as on, SEND_OUTCOME_HELP as ot, parameterFlagName as p, mailReach as pn, deriveSendIdempotencyKey as pt, clearReadPendingMail as q, focusEmptyHint as qt, OPERATION_PATH_FLAGS as r, queryScopesItself as rn, wakeInteractionSentence as rt, extractErrorPayload as s, saveFocus as sn, apiResultHttpStatus as st, API_BASE_URL_FLAG_DESCRIPTION as t, normalizeDomainNames as tn, replyExpectation as tt, headerFlagName as u, writeFocusLine as un, buildThrownSendFailureEnvelope as ut, takesStepUp as v, ATTACHMENT_WAIT_MAX_MS as vn, formatPriorRepliesWarning as vt, promptLine as w, refreshStoredCliCredentials as wn, sendIdentityFields as wt, STEP_UP_HEADER as x, SAVED_CLI_OAUTH_SESSION_EXPIRED_MESSAGE as xn, priorRepliesThatWentOut as xt, writeErrorWithHints as y, withAttachmentWait as yn, formatSendFailureSummary as yt, serverMuted as z, shownLine as zn, detectAgentRuntime as zt };
|