@wirecat/amo-cli 0.0.0-stage → 0.1.1
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 +70 -0
- package/LICENSE +204 -0
- package/README.md +265 -2
- package/contracts/wirecat.json +1356 -0
- package/dist/amo/account.d.ts +18 -0
- package/dist/amo/account.d.ts.map +1 -0
- package/dist/amo/account.js +48 -0
- package/dist/amo/account.js.map +1 -0
- package/dist/amo/allow-list.d.ts +31 -0
- package/dist/amo/allow-list.d.ts.map +1 -0
- package/dist/amo/allow-list.js +106 -0
- package/dist/amo/allow-list.js.map +1 -0
- package/dist/amo/errors.d.ts +12 -0
- package/dist/amo/errors.d.ts.map +1 -0
- package/dist/amo/errors.js +72 -0
- package/dist/amo/errors.js.map +1 -0
- package/dist/amo/json.d.ts +3 -0
- package/dist/amo/json.d.ts.map +1 -0
- package/dist/amo/json.js +3 -0
- package/dist/amo/json.js.map +1 -0
- package/dist/amo/oauth.d.ts +55 -0
- package/dist/amo/oauth.d.ts.map +1 -0
- package/dist/amo/oauth.js +189 -0
- package/dist/amo/oauth.js.map +1 -0
- package/dist/amo/operation.d.ts +45 -0
- package/dist/amo/operation.d.ts.map +1 -0
- package/dist/amo/operation.js +119 -0
- package/dist/amo/operation.js.map +1 -0
- package/dist/amo/operations.d.ts +3 -0
- package/dist/amo/operations.d.ts.map +1 -0
- package/dist/amo/operations.js +1407 -0
- package/dist/amo/operations.js.map +1 -0
- package/dist/amo/routes.d.ts +67 -0
- package/dist/amo/routes.d.ts.map +1 -0
- package/dist/amo/routes.js +65 -0
- package/dist/amo/routes.js.map +1 -0
- package/dist/amo/transport.d.ts +62 -0
- package/dist/amo/transport.d.ts.map +1 -0
- package/dist/amo/transport.js +282 -0
- package/dist/amo/transport.js.map +1 -0
- package/dist/api-keys.d.ts +47 -0
- package/dist/api-keys.d.ts.map +1 -0
- package/dist/api-keys.js +224 -0
- package/dist/api-keys.js.map +1 -0
- package/dist/bin/amo.d.ts +3 -0
- package/dist/bin/amo.d.ts.map +1 -0
- package/dist/bin/amo.js +40 -0
- package/dist/bin/amo.js.map +1 -0
- package/dist/bundle/all-profiles-3KQVWDV4.js +278 -0
- package/dist/bundle/amo.js +198 -0
- package/dist/bundle/anthropic-N5NOX7K7.js +90 -0
- package/dist/bundle/app-server-2MST5EZ5.js +245 -0
- package/dist/bundle/bun-4NHWOFX2.js +169 -0
- package/dist/bundle/bun-sqlite-DRSXPWPR.js +75 -0
- package/dist/bundle/chunk-2B24PDH7.js +1718 -0
- package/dist/bundle/chunk-2I5UVMLW.js +3232 -0
- package/dist/bundle/chunk-3IRJDH2U.js +731 -0
- package/dist/bundle/chunk-4ZAK773N.js +100 -0
- package/dist/bundle/chunk-5D4AEUVA.js +24783 -0
- package/dist/bundle/chunk-5D4Z2B5B.js +334 -0
- package/dist/bundle/chunk-5E5R65CA.js +54 -0
- package/dist/bundle/chunk-5HGGG3QO.js +73 -0
- package/dist/bundle/chunk-5RLUHTK6.js +23 -0
- package/dist/bundle/chunk-5SBLU7D7.js +63 -0
- package/dist/bundle/chunk-5Z5PEEKP.js +206 -0
- package/dist/bundle/chunk-63F65DHU.js +29 -0
- package/dist/bundle/chunk-6RS7OYTD.js +64 -0
- package/dist/bundle/chunk-73CXFE36.js +88 -0
- package/dist/bundle/chunk-7GTUZY7M.js +170 -0
- package/dist/bundle/chunk-7PKFYX7V.js +189 -0
- package/dist/bundle/chunk-7U5HJEPZ.js +1400 -0
- package/dist/bundle/chunk-A33TIM5D.js +4172 -0
- package/dist/bundle/chunk-ADEWU4P4.js +38 -0
- package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
- package/dist/bundle/chunk-AHJ4W2IL.js +106 -0
- package/dist/bundle/chunk-AUBB72VF.js +2572 -0
- package/dist/bundle/chunk-BVMNXI53.js +1266 -0
- package/dist/bundle/chunk-CDY2NJFE.js +136 -0
- package/dist/bundle/chunk-CHUKWON6.js +244 -0
- package/dist/bundle/chunk-CUZRHF34.js +230 -0
- package/dist/bundle/chunk-D72URWJE.js +532 -0
- package/dist/bundle/chunk-DAY6TSPF.js +786 -0
- package/dist/bundle/chunk-DFDN6AUB.js +21 -0
- package/dist/bundle/chunk-DJD7TBYG.js +2791 -0
- package/dist/bundle/chunk-DOSJONCX.js +1197 -0
- package/dist/bundle/chunk-DQV2IKCF.js +72 -0
- package/dist/bundle/chunk-DXGGCGRP.js +218 -0
- package/dist/bundle/chunk-EH6ZEJGT.js +932 -0
- package/dist/bundle/chunk-EPOV5UIO.js +185 -0
- package/dist/bundle/chunk-EQ7A6NA6.js +53 -0
- package/dist/bundle/chunk-EQUKVVHX.js +353 -0
- package/dist/bundle/chunk-EROSAUNP.js +133 -0
- package/dist/bundle/chunk-ESZSMZKT.js +82 -0
- package/dist/bundle/chunk-FKR3M62D.js +407 -0
- package/dist/bundle/chunk-GNTJMB6X.js +142 -0
- package/dist/bundle/chunk-GQ7VFIYM.js +316 -0
- package/dist/bundle/chunk-JH3UOHRE.js +161 -0
- package/dist/bundle/chunk-JMDLPBXK.js +1068 -0
- package/dist/bundle/chunk-JR6TSMFX.js +9435 -0
- package/dist/bundle/chunk-L6AFE73L.js +18 -0
- package/dist/bundle/chunk-LDEBZ3IX.js +238 -0
- package/dist/bundle/chunk-LGQXGOPJ.js +58 -0
- package/dist/bundle/chunk-LJQUYECN.js +6848 -0
- package/dist/bundle/chunk-LRBPT7LQ.js +95 -0
- package/dist/bundle/chunk-LSND5QYI.js +460 -0
- package/dist/bundle/chunk-NC76INB2.js +27955 -0
- package/dist/bundle/chunk-NHXJYS4R.js +1334 -0
- package/dist/bundle/chunk-NJYAL3UW.js +92 -0
- package/dist/bundle/chunk-O2UCU52O.js +4065 -0
- package/dist/bundle/chunk-ODNQU7DH.js +1028 -0
- package/dist/bundle/chunk-P3WQRTYZ.js +24 -0
- package/dist/bundle/chunk-P5LYZRKW.js +63373 -0
- package/dist/bundle/chunk-PFO76YFP.js +2003 -0
- package/dist/bundle/chunk-PM77PRB6.js +12269 -0
- package/dist/bundle/chunk-Q2VNBY4Y.js +38109 -0
- package/dist/bundle/chunk-QDMXZZG4.js +604 -0
- package/dist/bundle/chunk-QRQYUHCZ.js +761 -0
- package/dist/bundle/chunk-RPWAJYI6.js +2336 -0
- package/dist/bundle/chunk-SMSTGO2G.js +58 -0
- package/dist/bundle/chunk-SZ2V62HB.js +72 -0
- package/dist/bundle/chunk-T2UDLX76.js +259 -0
- package/dist/bundle/chunk-TGEQNS6G.js +16 -0
- package/dist/bundle/chunk-TNUFLULO.js +2333 -0
- package/dist/bundle/chunk-TZSUZGWM.js +25 -0
- package/dist/bundle/chunk-U7RLVJ34.js +274 -0
- package/dist/bundle/chunk-UBRREVLJ.js +72 -0
- package/dist/bundle/chunk-ULXQ5MJM.js +76 -0
- package/dist/bundle/chunk-UMVRT7VQ.js +46 -0
- package/dist/bundle/chunk-V77XNPXG.js +360 -0
- package/dist/bundle/chunk-VVHRQ46X.js +193 -0
- package/dist/bundle/chunk-VX37MPTJ.js +7 -0
- package/dist/bundle/chunk-WCYCUTSK.js +362 -0
- package/dist/bundle/chunk-XEFAMLSD.js +288 -0
- package/dist/bundle/chunk-XQL7FEF4.js +721 -0
- package/dist/bundle/chunk-XRTD2GCU.js +627 -0
- package/dist/bundle/chunk-Y37A3232.js +804 -0
- package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
- package/dist/bundle/chunk-ZM7I52EP.js +78 -0
- package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
- package/dist/bundle/cli-QVWTXADI.js +1193 -0
- package/dist/bundle/command-contract-QBUQBXH7.js +39 -0
- package/dist/bundle/command-server-entry-5VL5U5EE.js +168 -0
- package/dist/bundle/decode-SQ5WGNDX.js +296 -0
- package/dist/bundle/dispatch-LA4DFXJD.js +411 -0
- package/dist/bundle/dist-T54K3FJV.js +7577 -0
- package/dist/bundle/echarts-25Z3RINX.js +42501 -0
- package/dist/bundle/embed-BNOTNXMA.js +37 -0
- package/dist/bundle/embedder-BCUT7KKV.js +110 -0
- package/dist/bundle/failure-PKAC6XCT.js +24 -0
- package/dist/bundle/first-run-EO5K5GME.js +28 -0
- package/dist/bundle/first-screen-GMN3T6RW.js +39 -0
- package/dist/bundle/instructions-VLM3QAYB.js +11 -0
- package/dist/bundle/mcp-7ILNMJH5.js +167 -0
- package/dist/bundle/meeting-combined-LAMF7S2B.js +24 -0
- package/dist/bundle/meeting-model-GHMMUQ34.js +24 -0
- package/dist/bundle/meeting-semantic-BMP6323L.js +21 -0
- package/dist/bundle/node-CT3N3TNL.js +176 -0
- package/dist/bundle/node-P4E63KXA.js +2340 -0
- package/dist/bundle/node-TLZSIHIJ.js +21 -0
- package/dist/bundle/node-sqlite-MELD2SBX.js +73 -0
- package/dist/bundle/oauth-YBH5OKC2.js +19 -0
- package/dist/bundle/open-WNSBWTAG.js +22 -0
- package/dist/bundle/openai-XSNMNLW6.js +237 -0
- package/dist/bundle/process-I2QKOMM7.js +91 -0
- package/dist/bundle/program-DV73CIGP.js +4940 -0
- package/dist/bundle/prompt-SOG4AKPM.js +16 -0
- package/dist/bundle/recognize-WMQLWMXH.js +25 -0
- package/dist/bundle/remote-4BTFOLFY.js +30 -0
- package/dist/bundle/rerank-LJ3TWRNV.js +51 -0
- package/dist/bundle/serve-B6UANKXN.js +198 -0
- package/dist/bundle/server-S6XD6V6E.js +77 -0
- package/dist/bundle/server-YRH6GJ5Z.js +206 -0
- package/dist/bundle/source-DGFTA2TN.js +42 -0
- package/dist/bundle/sqlite-runtime-R7QFWFE7.js +19 -0
- package/dist/bundle/state-DIJ5YUOE.js +35 -0
- package/dist/bundle/store-6WFWW7EC.js +294 -0
- package/dist/bundle/store-FJCNZULV.js +32 -0
- package/dist/bundle/store-MYTYDV6A.js +177 -0
- package/dist/bundle/store-maintenance-command-B5TMKFMG.js +68 -0
- package/dist/bundle/writer-GP7VIMAU.js +44 -0
- package/dist/commands/account.d.ts +3 -0
- package/dist/commands/account.d.ts.map +1 -0
- package/dist/commands/account.js +86 -0
- package/dist/commands/account.js.map +1 -0
- package/dist/commands/api.d.ts +3 -0
- package/dist/commands/api.d.ts.map +1 -0
- package/dist/commands/api.js +224 -0
- package/dist/commands/api.js.map +1 -0
- package/dist/commands/crm-shared.d.ts +8 -0
- package/dist/commands/crm-shared.d.ts.map +1 -0
- package/dist/commands/crm-shared.js +111 -0
- package/dist/commands/crm-shared.js.map +1 -0
- package/dist/commands/schedule.d.ts +3 -0
- package/dist/commands/schedule.d.ts.map +1 -0
- package/dist/commands/schedule.js +9 -0
- package/dist/commands/schedule.js.map +1 -0
- package/dist/commands/session.d.ts +18 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +265 -0
- package/dist/commands/session.js.map +1 -0
- package/dist/commands/write.d.ts +14 -0
- package/dist/commands/write.d.ts.map +1 -0
- package/dist/commands/write.js +36 -0
- package/dist/commands/write.js.map +1 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +29 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +62 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +97 -0
- package/dist/context.js.map +1 -0
- package/dist/crm/activities.d.ts +32 -0
- package/dist/crm/activities.d.ts.map +1 -0
- package/dist/crm/activities.js +196 -0
- package/dist/crm/activities.js.map +1 -0
- package/dist/crm/records.d.ts +20 -0
- package/dist/crm/records.d.ts.map +1 -0
- package/dist/crm/records.js +175 -0
- package/dist/crm/records.js.map +1 -0
- package/dist/crm/source.d.ts +41 -0
- package/dist/crm/source.d.ts.map +1 -0
- package/dist/crm/source.js +673 -0
- package/dist/crm/source.js.map +1 -0
- package/dist/crm/writer.d.ts +14 -0
- package/dist/crm/writer.d.ts.map +1 -0
- package/dist/crm/writer.js +247 -0
- package/dist/crm/writer.js.map +1 -0
- package/dist/identity.d.ts +7 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +33 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/program.d.ts +6 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +91 -0
- package/dist/program.js.map +1 -0
- package/dist/reasons.d.ts +10 -0
- package/dist/reasons.d.ts.map +1 -0
- package/dist/reasons.js +35 -0
- package/dist/reasons.js.map +1 -0
- package/dist/setup/flow.d.ts +2 -0
- package/dist/setup/flow.d.ts.map +1 -0
- package/dist/setup/flow.js +127 -0
- package/dist/setup/flow.js.map +1 -0
- package/dist/setup/texts.en.json +25 -0
- package/dist/setup/texts.es.json +25 -0
- package/dist/setup/texts.ru.json +25 -0
- package/dist/store.d.ts +15 -0
- package/dist/store.d.ts.map +1 -0
- package/dist/store.js +16 -0
- package/dist/store.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/dist/wcat.d.ts +3 -0
- package/dist/wcat.d.ts.map +1 -0
- package/dist/wcat.js +4 -0
- package/dist/wcat.js.map +1 -0
- package/dist/whoami.d.ts +24 -0
- package/dist/whoami.d.ts.map +1 -0
- package/dist/whoami.js +33 -0
- package/dist/whoami.js.map +1 -0
- package/package.json +85 -4
- package/skills/amo-cli/SKILL.md +116 -0
- package/skills/amo-cli/references/mcp.md +38 -0
- package/skills/amo-cli/references/output.md +42 -0
- package/skills/amo-cli/references/reading.md +77 -0
- package/skills/amo-cli/references/setup.md +59 -0
- package/skills/amo-cli/references/writing.md +86 -0
|
@@ -0,0 +1,3232 @@
|
|
|
1
|
+
import { createRequire as __bundleRequire } from "node:module";
|
|
2
|
+
const require = __bundleRequire(import.meta.url);
|
|
3
|
+
import {
|
|
4
|
+
Command,
|
|
5
|
+
InvalidArgumentError,
|
|
6
|
+
MESSENGER_CHANGE_REFUSAL,
|
|
7
|
+
Option,
|
|
8
|
+
annotate,
|
|
9
|
+
annotateOption,
|
|
10
|
+
envName,
|
|
11
|
+
guardedWrite,
|
|
12
|
+
listOf,
|
|
13
|
+
progressLine,
|
|
14
|
+
progressOf,
|
|
15
|
+
readOnlyRefusal,
|
|
16
|
+
runBudget,
|
|
17
|
+
sharedCommand
|
|
18
|
+
} from "./chunk-PM77PRB6.js";
|
|
19
|
+
import {
|
|
20
|
+
crmIdentityId,
|
|
21
|
+
crmSettingKey,
|
|
22
|
+
readMoment,
|
|
23
|
+
seenBy
|
|
24
|
+
} from "./chunk-P5LYZRKW.js";
|
|
25
|
+
import {
|
|
26
|
+
LOG_ATTRIBUTES,
|
|
27
|
+
accountsOfList,
|
|
28
|
+
currentRun,
|
|
29
|
+
entriesOfList,
|
|
30
|
+
fitting,
|
|
31
|
+
fromLogAttributes,
|
|
32
|
+
isAccountList,
|
|
33
|
+
isGroupName,
|
|
34
|
+
keyOf,
|
|
35
|
+
logAttributes,
|
|
36
|
+
sameAs,
|
|
37
|
+
sourceOf3 as sourceOf
|
|
38
|
+
} from "./chunk-BVMNXI53.js";
|
|
39
|
+
import {
|
|
40
|
+
isCliFailure
|
|
41
|
+
} from "./chunk-UBRREVLJ.js";
|
|
42
|
+
import {
|
|
43
|
+
CEILING_KEY,
|
|
44
|
+
DEFAULT_PERMISSIONS,
|
|
45
|
+
STORE_ONLY_KEYS,
|
|
46
|
+
keyForWrite,
|
|
47
|
+
levelFor,
|
|
48
|
+
skipFlagFor,
|
|
49
|
+
stops
|
|
50
|
+
} from "./chunk-QDMXZZG4.js";
|
|
51
|
+
import {
|
|
52
|
+
e164Of,
|
|
53
|
+
foldName
|
|
54
|
+
} from "./chunk-PFO76YFP.js";
|
|
55
|
+
import {
|
|
56
|
+
CRM_KINDS,
|
|
57
|
+
DEAL_KINDS,
|
|
58
|
+
INTERNAL_NOTES,
|
|
59
|
+
currencyOf,
|
|
60
|
+
holdsKindOf,
|
|
61
|
+
isCrmUserId,
|
|
62
|
+
isDocumentAccountProvider,
|
|
63
|
+
isFolderProvider,
|
|
64
|
+
isItemKind,
|
|
65
|
+
isKind,
|
|
66
|
+
minorUnits,
|
|
67
|
+
normalCrmUserId,
|
|
68
|
+
providerNamed
|
|
69
|
+
} from "./chunk-QRQYUHCZ.js";
|
|
70
|
+
import {
|
|
71
|
+
BACKENDS,
|
|
72
|
+
EVENT_QUERY,
|
|
73
|
+
MEETING_FIELDS,
|
|
74
|
+
MEETING_FIELD_KEYS,
|
|
75
|
+
MEETING_PROJECT_EVIDENCE_QUERY,
|
|
76
|
+
MEETING_QUERY,
|
|
77
|
+
MEETING_QUERY_GUIDE,
|
|
78
|
+
MeetingError,
|
|
79
|
+
OPERATORS_BY_TYPE,
|
|
80
|
+
QUERY_LIMITS,
|
|
81
|
+
SAVE_HELP,
|
|
82
|
+
SNAKE_CASE,
|
|
83
|
+
dateRange,
|
|
84
|
+
defineQuery,
|
|
85
|
+
eventItem,
|
|
86
|
+
exportMeeting,
|
|
87
|
+
fieldsHelp,
|
|
88
|
+
fieldsNamed,
|
|
89
|
+
importFiles,
|
|
90
|
+
listed,
|
|
91
|
+
markedPassage,
|
|
92
|
+
meetingDetailsBody,
|
|
93
|
+
meetingFieldFlag,
|
|
94
|
+
meetingHitsList,
|
|
95
|
+
meetingPeople,
|
|
96
|
+
meetingShowThrough,
|
|
97
|
+
meetingSummaryAnswer,
|
|
98
|
+
meetingTranscriptAnswer,
|
|
99
|
+
meetingsListThrough,
|
|
100
|
+
meetingsQuery,
|
|
101
|
+
parseLucene,
|
|
102
|
+
pull,
|
|
103
|
+
queryDescription,
|
|
104
|
+
queryError,
|
|
105
|
+
queryFieldsOf,
|
|
106
|
+
readMeetingProjectEvidence,
|
|
107
|
+
timezoneOf,
|
|
108
|
+
validateMeetingHitSearch,
|
|
109
|
+
validateMeetingPassage,
|
|
110
|
+
validateQuery,
|
|
111
|
+
walkQuery
|
|
112
|
+
} from "./chunk-A33TIM5D.js";
|
|
113
|
+
import {
|
|
114
|
+
backoffMs,
|
|
115
|
+
logRecordOf,
|
|
116
|
+
realSleep,
|
|
117
|
+
resolvePaths,
|
|
118
|
+
writeSecurely
|
|
119
|
+
} from "./chunk-DJD7TBYG.js";
|
|
120
|
+
import {
|
|
121
|
+
description,
|
|
122
|
+
maxLength,
|
|
123
|
+
optional,
|
|
124
|
+
pipe,
|
|
125
|
+
string
|
|
126
|
+
} from "./chunk-AUBB72VF.js";
|
|
127
|
+
import {
|
|
128
|
+
CliError,
|
|
129
|
+
isCliError
|
|
130
|
+
} from "./chunk-SZ2V62HB.js";
|
|
131
|
+
import {
|
|
132
|
+
__export,
|
|
133
|
+
__name
|
|
134
|
+
} from "./chunk-ZVVMGPBJ.js";
|
|
135
|
+
|
|
136
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/services/moment.js
|
|
137
|
+
var read = /* @__PURE__ */ __name((reference, flag, now, at) => {
|
|
138
|
+
const found = readMoment(reference, flag, { ...at, now });
|
|
139
|
+
if (found === void 0)
|
|
140
|
+
throw new CliError("validation_error", `${flag} takes an ISO 8601 time, today, yesterday, or 30m, 2h, 1d ago \u2014 not "${reference.trim()}"`);
|
|
141
|
+
return found;
|
|
142
|
+
}, "read");
|
|
143
|
+
var momentOf = /* @__PURE__ */ __name((reference, flag = "--since", now = Date.now(), at = {}) => read(reference, flag, now, at).time, "momentOf");
|
|
144
|
+
var dateWindow = /* @__PURE__ */ __name(({ sinceTime, untilTime, zone, now = Date.now(), names = ["--since-time", "--until-time"] }) => {
|
|
145
|
+
const at = zone === void 0 ? {} : { zone };
|
|
146
|
+
const lower = sinceTime === void 0 ? void 0 : read(sinceTime, names[0], now, at);
|
|
147
|
+
const upper = untilTime === void 0 ? void 0 : read(untilTime, names[1], now, { ...at, end: true });
|
|
148
|
+
const since = lower?.time;
|
|
149
|
+
const until = upper?.time;
|
|
150
|
+
const readInZone = lower?.local === true || upper?.local === true;
|
|
151
|
+
const window = {
|
|
152
|
+
...since === void 0 ? {} : { since: new Date(since).toISOString() },
|
|
153
|
+
...until === void 0 ? {} : { until: new Date(until).toISOString() }
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
...since === void 0 ? {} : { since },
|
|
157
|
+
...until === void 0 ? {} : { until },
|
|
158
|
+
meta: {
|
|
159
|
+
...readInZone ? { timezone: timezoneOf(zone) } : {},
|
|
160
|
+
...since === void 0 && until === void 0 ? {} : { window }
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
}, "dateWindow");
|
|
164
|
+
|
|
165
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/meetings/cli/management.js
|
|
166
|
+
var REMOTE_READ = { remote: "read", local: "read" };
|
|
167
|
+
var REMOTE_WRITE = { remote: "write", local: "write" };
|
|
168
|
+
var minutes = /* @__PURE__ */ __name((text2) => {
|
|
169
|
+
if (!/^[1-9]\d*$/.test(text2))
|
|
170
|
+
throw new InvalidArgumentError("expected whole minutes");
|
|
171
|
+
return Number(text2);
|
|
172
|
+
}, "minutes");
|
|
173
|
+
var setting = /* @__PURE__ */ __name((text2, previous = []) => {
|
|
174
|
+
const at = text2.indexOf("=");
|
|
175
|
+
const name = text2.slice(0, at);
|
|
176
|
+
if (at < 1 || !SNAKE_CASE.test(name))
|
|
177
|
+
throw new InvalidArgumentError("expected name=value with a snake_case name, such as access_type=trusted");
|
|
178
|
+
return [...previous, [name, text2.slice(at + 1)]];
|
|
179
|
+
}, "setting");
|
|
180
|
+
var valuesOf = /* @__PURE__ */ __name((one) => one.type === "choice" ? one.values.join("|") : one.type === "boolean" ? "true|false" : "<text>", "valuesOf");
|
|
181
|
+
var changeOptions = /* @__PURE__ */ __name((command, declared, create) => {
|
|
182
|
+
const settings = declared.settings.length ? declared.settings.map((one) => `${one.name}=${valuesOf(one)}`).join(", ") : "this service has none";
|
|
183
|
+
const takes = declared.fields.map(meetingFieldFlag).join(", ") || "none of the options above";
|
|
184
|
+
const schedules = declared.fields.includes("startTime");
|
|
185
|
+
const start = !create ? "" : !schedules ? "; this service takes none, its meetings start now" : declared.fields.includes("kind") ? "; for a meeting that starts now, give --kind instant instead" : "";
|
|
186
|
+
return command.option("--title <title>", "the meeting's title").addOption(new Option("--kind <kind>", "an instant or a scheduled meeting").choices(["instant", "scheduled"])).option("--start-time <time>", `when it starts: an ISO time with its offset, 2026-11-20T10:00:00+01:00${start}`).option("--duration-minutes <minutes>", "how long it lasts, 1\u20131440", minutes).option("--timezone <zone>", "its IANA time zone, Europe/Madrid").option("--agenda <text>", "its agenda").option("--setting <name=value>", `a setting of this service; repeat it for more: ${settings}`, setting).addHelpText("after", [
|
|
187
|
+
"",
|
|
188
|
+
`This service takes ${takes}.`,
|
|
189
|
+
...declared.settings.length ? ["Its settings:", ...declared.settings.map((one) => ` ${one.name}=${valuesOf(one)} ${one.description}`)] : []
|
|
190
|
+
].join("\n"));
|
|
191
|
+
}, "changeOptions");
|
|
192
|
+
var changeOf = /* @__PURE__ */ __name((flags) => {
|
|
193
|
+
const change = Object.fromEntries(MEETING_FIELDS.flatMap((key) => flags[key] === void 0 ? [] : [[key, flags[key]]]));
|
|
194
|
+
if (!flags.setting)
|
|
195
|
+
return change;
|
|
196
|
+
const settings = /* @__PURE__ */ new Map();
|
|
197
|
+
for (const [name, value] of flags.setting) {
|
|
198
|
+
if (settings.has(name))
|
|
199
|
+
throw new CliError("validation_error", `--setting ${name} is given twice`);
|
|
200
|
+
settings.set(name, value);
|
|
201
|
+
}
|
|
202
|
+
return { ...change, settings: Object.fromEntries(settings) };
|
|
203
|
+
}, "changeOf");
|
|
204
|
+
var meetingOf = /* @__PURE__ */ __name((one) => ({
|
|
205
|
+
id: one.id,
|
|
206
|
+
title: one.title,
|
|
207
|
+
kind: one.kind,
|
|
208
|
+
start_time: one.startTime,
|
|
209
|
+
duration_minutes: one.durationMinutes,
|
|
210
|
+
timezone: one.timezone,
|
|
211
|
+
agenda: one.agenda,
|
|
212
|
+
join_url: one.joinUrl
|
|
213
|
+
}), "meetingOf");
|
|
214
|
+
var receiptItem = /* @__PURE__ */ __name((receipt) => {
|
|
215
|
+
const { change } = receipt;
|
|
216
|
+
return {
|
|
217
|
+
action: receipt.action,
|
|
218
|
+
provider: receipt.scope.provider,
|
|
219
|
+
account: receipt.scope.account,
|
|
220
|
+
...receipt.id === void 0 ? {} : { id: receipt.id },
|
|
221
|
+
...receipt.occurrenceId === void 0 ? {} : { occurrence_id: receipt.occurrenceId },
|
|
222
|
+
...change ? {
|
|
223
|
+
change: {
|
|
224
|
+
...Object.fromEntries(MEETING_FIELDS.flatMap((key) => change[key] === void 0 ? [] : [[MEETING_FIELD_KEYS[key], change[key]]])),
|
|
225
|
+
...change.settings === void 0 ? {} : { settings: { ...change.settings } }
|
|
226
|
+
}
|
|
227
|
+
} : {},
|
|
228
|
+
applied: receipt.applied,
|
|
229
|
+
...receipt.meeting ? { meeting: meetingOf(receipt.meeting), untrusted: ["meeting.title", "meeting.agenda", "meeting.join_url"] } : {}
|
|
230
|
+
};
|
|
231
|
+
}, "receiptItem");
|
|
232
|
+
var addMeetingManagementCommands = /* @__PURE__ */ __name((group, deps) => {
|
|
233
|
+
const { management, print, output, inRun, askFirst } = deps;
|
|
234
|
+
const signalled = /* @__PURE__ */ __name(() => {
|
|
235
|
+
const signal = deps.signal?.();
|
|
236
|
+
return signal ? { signal } : {};
|
|
237
|
+
}, "signalled");
|
|
238
|
+
const has = /* @__PURE__ */ __name((name) => management.capabilities.includes(name), "has");
|
|
239
|
+
const mutation = /* @__PURE__ */ __name((command) => ({
|
|
240
|
+
apply: true,
|
|
241
|
+
dryRun: command.optsWithGlobals().dryRun === true,
|
|
242
|
+
...signalled(),
|
|
243
|
+
confirm: /* @__PURE__ */ __name(async () => {
|
|
244
|
+
if (!askFirst)
|
|
245
|
+
throw new CliError("configuration_error", "this tool cannot ask before it changes a meeting on the service");
|
|
246
|
+
await askFirst(command);
|
|
247
|
+
}, "confirm")
|
|
248
|
+
}), "mutation");
|
|
249
|
+
const write = /* @__PURE__ */ __name((name) => annotate(group.command(name), { effects: REMOTE_WRITE, offline: false, output: { entity: "meeting_change" } }), "write");
|
|
250
|
+
const target = /* @__PURE__ */ __name((command) => command.argument("<meeting>", "the service's id of the meeting"), "target");
|
|
251
|
+
if (has("create"))
|
|
252
|
+
output(changeOptions(write("create").description("create a meeting on the service"), management.fields.create, true)).action(async (flags, command) => inRun(command, async () => print({ item: receiptItem(await management.create(changeOf(flags), mutation(command))) }, command)));
|
|
253
|
+
if (has("update"))
|
|
254
|
+
output(changeOptions(target(write("update").description("change a meeting on the service")), management.fields.update, false)).action(async (id2, flags, command) => inRun(command, async () => print({ item: receiptItem(await management.update(id2, changeOf(flags), mutation(command))) }, command)));
|
|
255
|
+
if (has("cancel"))
|
|
256
|
+
output(target(write("cancel").description("cancel a meeting on the service")).option("--occurrence-id <id>", "cancel only this occurrence of a repeating meeting")).action(async (id2, flags, command) => inRun(command, async () => print({
|
|
257
|
+
item: receiptItem(await management.cancel(id2, {
|
|
258
|
+
...mutation(command),
|
|
259
|
+
...flags.occurrenceId === void 0 ? {} : { occurrenceId: flags.occurrenceId }
|
|
260
|
+
}))
|
|
261
|
+
}, command)));
|
|
262
|
+
if (has("invitation"))
|
|
263
|
+
output(target(annotate(group.command("invitation"), {
|
|
264
|
+
effects: REMOTE_READ,
|
|
265
|
+
offline: false,
|
|
266
|
+
output: { entity: "meeting_invitation" }
|
|
267
|
+
}).description("the invitation text the service writes for a meeting"))).action(async (id2, _flags, command) => inRun(command, async () => print({ item: { ...await management.invitation(id2, signalled()), untrusted: ["invitation"] } }, command)));
|
|
268
|
+
}, "addMeetingManagementCommands");
|
|
269
|
+
|
|
270
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/meetings/cli/query-options.js
|
|
271
|
+
var queryWordsAfterOptions = /* @__PURE__ */ __name((command) => {
|
|
272
|
+
command.allowUnknownOption();
|
|
273
|
+
const parse = command.parseOptions.bind(command);
|
|
274
|
+
command.parseOptions = (args) => {
|
|
275
|
+
const parsed = parse(args);
|
|
276
|
+
const end = parsed.unknown.indexOf("--");
|
|
277
|
+
const help = command._getHelpOption();
|
|
278
|
+
const typo = parsed.unknown.slice(0, end < 0 ? void 0 : end).find((word) => word.startsWith("--") && !help?.is(word));
|
|
279
|
+
if (typo !== void 0) {
|
|
280
|
+
command.allowUnknownOption(false);
|
|
281
|
+
command.unknownOption(typo);
|
|
282
|
+
}
|
|
283
|
+
if (end >= 0)
|
|
284
|
+
parsed.unknown.splice(end, 1);
|
|
285
|
+
return parsed;
|
|
286
|
+
};
|
|
287
|
+
return command;
|
|
288
|
+
}, "queryWordsAfterOptions");
|
|
289
|
+
|
|
290
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/meetings/cli/passage.js
|
|
291
|
+
var count = /* @__PURE__ */ __name((value) => {
|
|
292
|
+
if (!/^(0|[1-9]\d*)$/.test(value) || !Number.isSafeInteger(Number(value)))
|
|
293
|
+
throw new CliError("validation_error", "expected a nonnegative safe integer");
|
|
294
|
+
return Number(value);
|
|
295
|
+
}, "count");
|
|
296
|
+
var meetingPassageRequest = /* @__PURE__ */ __name((reference, options, signal) => {
|
|
297
|
+
const input = {
|
|
298
|
+
before: options.beforeN,
|
|
299
|
+
after: options.afterN,
|
|
300
|
+
bytes: options.bytes,
|
|
301
|
+
max_read_bytes: options.maxReadBytes,
|
|
302
|
+
expected_fingerprint: options.expectedFingerprint,
|
|
303
|
+
format: options.format ?? "text",
|
|
304
|
+
signal
|
|
305
|
+
};
|
|
306
|
+
validateMeetingPassage(reference, input);
|
|
307
|
+
signal?.throwIfAborted();
|
|
308
|
+
return input;
|
|
309
|
+
}, "meetingPassageRequest");
|
|
310
|
+
var createMeetingPassageCommandDefinition = /* @__PURE__ */ __name((program) => {
|
|
311
|
+
const meetings = program.commands.find((command) => command.name() === "meetings");
|
|
312
|
+
if (!meetings)
|
|
313
|
+
throw new CliError("configuration_error", "meeting command group is unavailable");
|
|
314
|
+
return annotate(meetings.command("passage").description("read a cited cue with bounded context before and after it").argument("<reference>", "retained transcript cue reference from a search hit").option("--before-n <n>", "preceding cues (default 3)", count).option("--after-n <n>", "following cues (default 3); at most 999 surrounding cues in total", count).option("--bytes <bytes>", "cue JSON byte budget (default 65536); the anchor must fit", count).option("--max-read-bytes <bytes>", "stored text byte budget (default 4194304); boundary probes read metadata only", count).option("--expected-fingerprint <hash>", "reject a changed anchor using its previously read cue fingerprint").addOption(new Option("--format <format>", "compact text, Markdown or structured JSON").choices(["text", "markdown", "json"]).default("text")), {
|
|
315
|
+
origin: "handwritten",
|
|
316
|
+
effects: { remote: "none", local: "read" },
|
|
317
|
+
output: { entity: "meeting_passage" },
|
|
318
|
+
examples: [`${program.name()} meetings passage meeting:1/1/1/0 --json`]
|
|
319
|
+
});
|
|
320
|
+
}, "createMeetingPassageCommandDefinition");
|
|
321
|
+
var addMeetingPassageCommandDefinition = /* @__PURE__ */ __name((program, deps) => createMeetingPassageCommand(program).action(async (reference, options, command) => {
|
|
322
|
+
const globals = command.optsWithGlobals();
|
|
323
|
+
const format = globals.json || globals.jsonl ? "json" : options.format ?? "text";
|
|
324
|
+
const input = meetingPassageRequest(reference, { ...options, format }, deps.signal());
|
|
325
|
+
const result = markedPassage(await deps.read(reference, input));
|
|
326
|
+
input.signal?.throwIfAborted();
|
|
327
|
+
deps.output(result, format);
|
|
328
|
+
}), "addMeetingPassageCommandDefinition");
|
|
329
|
+
var createMeetingPassageCommand = sharedCommand(createMeetingPassageCommandDefinition);
|
|
330
|
+
var addMeetingPassageCommand = sharedCommand(addMeetingPassageCommandDefinition);
|
|
331
|
+
|
|
332
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/meetings/cli/project-evidence.js
|
|
333
|
+
var integer = /* @__PURE__ */ __name((value) => {
|
|
334
|
+
if (!/^[1-9]\d*$/.test(value) || !Number.isSafeInteger(Number(value)))
|
|
335
|
+
throw new CliError("validation_error", "expected a positive safe integer");
|
|
336
|
+
return Number(value);
|
|
337
|
+
}, "integer");
|
|
338
|
+
var addMeetingProjectEvidenceCommandDefinition = /* @__PURE__ */ __name((program, deps) => {
|
|
339
|
+
const group = program.commands.find((command) => command.name() === "meetings");
|
|
340
|
+
if (!group)
|
|
341
|
+
throw new CliError("configuration_error", "meeting command group is unavailable");
|
|
342
|
+
const projects = group.commands.find((command) => command.name() === "projects") ?? group.command("projects").description("project-name evidence in stored meetings");
|
|
343
|
+
return annotate(queryWordsAfterOptions(projects.command("evidence").description("find cited project-name and alias evidence in the local meeting index; does not refresh it or confirm membership")).argument("<project>", "existing project name, key or explicit alias").argument("[query...]", "exact ID fields and a UTC started_at range, joined by AND").addHelpText("after", `
|
|
344
|
+
${fieldsHelp(MEETING_PROJECT_EVIDENCE_QUERY)}`).option("--limit <n>", "hits in one name page, 1 through 1000 (default 100)", integer).option("--cursor <cursor>", "continue with the same project and frozen selection from next").option("--max-read-bytes <bytes>", "word-read byte budget, at most 67108864 (default 4194304)", integer).action(async (project, words, options) => {
|
|
345
|
+
deps.output(await readMeetingProjectEvidence(deps.read, project, { ...options, query: words.join(" "), signal: deps.signal() }, deps.now?.()));
|
|
346
|
+
}), {
|
|
347
|
+
origin: "handwritten",
|
|
348
|
+
effects: { remote: "none", local: "read" },
|
|
349
|
+
query: MEETING_PROJECT_EVIDENCE_QUERY,
|
|
350
|
+
output: { entity: "meeting_project_evidence" }
|
|
351
|
+
});
|
|
352
|
+
}, "addMeetingProjectEvidenceCommandDefinition");
|
|
353
|
+
var addMeetingProjectEvidenceCommand = sharedCommand(addMeetingProjectEvidenceCommandDefinition);
|
|
354
|
+
|
|
355
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/meetings/cli/search.js
|
|
356
|
+
var moment = /* @__PURE__ */ __name((flag, end, readIn) => (value) => {
|
|
357
|
+
const { since, until, meta } = dateWindow(end ? { untilTime: value, names: [flag, flag] } : { sinceTime: value, names: [flag, flag] });
|
|
358
|
+
if (meta.timezone)
|
|
359
|
+
readIn(meta.timezone);
|
|
360
|
+
return end ? until : since;
|
|
361
|
+
}, "moment");
|
|
362
|
+
var integer2 = /* @__PURE__ */ __name((value) => {
|
|
363
|
+
if (!/^[1-9]\d*$/.test(value) || !Number.isSafeInteger(Number(value)))
|
|
364
|
+
throw new CliError("validation_error", "expected a positive safe integer");
|
|
365
|
+
return Number(value);
|
|
366
|
+
}, "integer");
|
|
367
|
+
var createMeetingSearchCommandDefinition = /* @__PURE__ */ __name((program) => {
|
|
368
|
+
let search = program.commands.find((command2) => command2.name() === "search");
|
|
369
|
+
if (!search) {
|
|
370
|
+
search = new Command("search").description("search the stored resources");
|
|
371
|
+
program.addCommand(search);
|
|
372
|
+
}
|
|
373
|
+
const readIn = /* @__PURE__ */ __name((zone) => command.setOptionValue("timesReadIn", zone), "readIn");
|
|
374
|
+
const command = search.command("meetings").description("find words in stored meetings, indexing new ones first").argument("<query>", 'words, OR, (groups), -word, "a phrase", "a b"~N (within N lines), exact:word, from:"Name" (who said the line); date>=30d, project:, tag:, topic: choose meetings; a word also matches its other forms and spellings speech recognition garbled').option("--meeting-id <id>", "only this stored meeting", integer2).option("--identity-id <id>", "meetings with this participant identity; does not say who spoke a hit", integer2).option("--person-id <id>", "meetings with a participant linked to this person", integer2).option("--event-id <id>", "only meetings linked to this stored event", integer2).option("--series-id <id>", "only meetings in this stored series", integer2).option("--project <project>", "meetings confirmed in this project, by name, key or alias").option("--tag <name>", "meetings with this tag, by name or alias").option("--topic-name <name>", "meetings with this topic, by name or alias").option("--since-time <time>", "meetings starting at or after this ISO 8601 date or time, or 30m, 2h, 7d ago", moment("--since-time", false, readIn)).option("--until-time <time>", "meetings starting at or before this ISO 8601 date or time; a date alone covers that whole local day", moment("--until-time", true, readIn)).option("--limit <n>", "how many hits, 1 through 1000; the profile's defaults.limit when absent", integer2).option("--cursor <cursor>", "continue from the previous page's page.next_cursor, with the same query and filters").option("--max-read-bytes <bytes>", "most stored bytes to read, 1 through 67108864 (default 4194304)", integer2);
|
|
375
|
+
annotate(command, {
|
|
376
|
+
origin: "handwritten",
|
|
377
|
+
effects: { remote: "none", local: "read" },
|
|
378
|
+
output: { entity: "meeting_hit" }
|
|
379
|
+
});
|
|
380
|
+
return command;
|
|
381
|
+
}, "createMeetingSearchCommandDefinition");
|
|
382
|
+
var meetingHitSearchRequest = /* @__PURE__ */ __name((query, options, limit, signal) => {
|
|
383
|
+
const request = {
|
|
384
|
+
meetingId: options.meetingId,
|
|
385
|
+
participantIdentityId: options.identityId,
|
|
386
|
+
personId: options.personId,
|
|
387
|
+
eventId: options.eventId,
|
|
388
|
+
meetingSeriesId: options.seriesId,
|
|
389
|
+
project: options.project,
|
|
390
|
+
tag: options.tag,
|
|
391
|
+
topic: options.topicName ?? options.topic,
|
|
392
|
+
since: options.sinceTime,
|
|
393
|
+
until: options.untilTime,
|
|
394
|
+
limit: options.limit ?? limit,
|
|
395
|
+
after: options.cursor,
|
|
396
|
+
maxReadBytes: options.maxReadBytes,
|
|
397
|
+
signal
|
|
398
|
+
};
|
|
399
|
+
validateMeetingHitSearch(query, request);
|
|
400
|
+
signal?.throwIfAborted();
|
|
401
|
+
return request;
|
|
402
|
+
}, "meetingHitSearchRequest");
|
|
403
|
+
var meetingSearchArguments = /* @__PURE__ */ __name((query, options) => Object.fromEntries(Object.entries({
|
|
404
|
+
query,
|
|
405
|
+
meeting_id: options.meetingId?.toString(),
|
|
406
|
+
identity_id: options.identityId?.toString(),
|
|
407
|
+
person_id: options.personId?.toString(),
|
|
408
|
+
event_id: options.eventId?.toString(),
|
|
409
|
+
series_id: options.seriesId?.toString(),
|
|
410
|
+
project: options.project,
|
|
411
|
+
tag: options.tag,
|
|
412
|
+
topic_name: options.topicName ?? options.topic,
|
|
413
|
+
since_time: options.sinceTime === void 0 ? void 0 : new Date(options.sinceTime).toISOString(),
|
|
414
|
+
until_time: options.untilTime === void 0 ? void 0 : new Date(options.untilTime).toISOString(),
|
|
415
|
+
max_read_bytes: options.maxReadBytes ?? 4194304
|
|
416
|
+
}).filter(([, value]) => value !== void 0)), "meetingSearchArguments");
|
|
417
|
+
var meetingSearchMeta = /* @__PURE__ */ __name((options) => {
|
|
418
|
+
const window = {
|
|
419
|
+
...options.sinceTime === void 0 ? {} : { since: new Date(options.sinceTime).toISOString() },
|
|
420
|
+
...options.untilTime === void 0 ? {} : { until: new Date(options.untilTime).toISOString() }
|
|
421
|
+
};
|
|
422
|
+
return {
|
|
423
|
+
...options.timesReadIn === void 0 ? {} : { timezone: options.timesReadIn },
|
|
424
|
+
...Object.keys(window).length === 0 ? {} : { window }
|
|
425
|
+
};
|
|
426
|
+
}, "meetingSearchMeta");
|
|
427
|
+
var addMeetingSearchCommandDefinition = /* @__PURE__ */ __name((program, deps) => createMeetingSearchCommand(program).action(async (query, options, command) => {
|
|
428
|
+
const request = meetingHitSearchRequest(query, options, deps.pagingOf(command).limit, deps.signal());
|
|
429
|
+
deps.output(meetingHitsList(await deps.search(query, request, options), request.limit, "search meetings", meetingSearchArguments(query, options), meetingSearchMeta(options)));
|
|
430
|
+
}), "addMeetingSearchCommandDefinition");
|
|
431
|
+
var createMeetingSearchCommand = sharedCommand(createMeetingSearchCommandDefinition);
|
|
432
|
+
var addMeetingSearchCommand = sharedCommand(addMeetingSearchCommandDefinition);
|
|
433
|
+
|
|
434
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/meetings/cli/index.js
|
|
435
|
+
var EVENT_UNTRUSTED = ["title", "description", "location"];
|
|
436
|
+
var integer3 = /* @__PURE__ */ __name((text2) => {
|
|
437
|
+
if (!/^[1-9]\d*$/.test(text2) || !Number.isSafeInteger(Number(text2)))
|
|
438
|
+
throw new InvalidArgumentError("expected a positive integer");
|
|
439
|
+
return Number(text2);
|
|
440
|
+
}, "integer");
|
|
441
|
+
var lookbackDays = /* @__PURE__ */ __name((text2) => {
|
|
442
|
+
if (!/^(0|[1-9]\d*)$/.test(text2) || Number(text2) > 31)
|
|
443
|
+
throw new InvalidArgumentError("expected an integer from 0 through 31 days");
|
|
444
|
+
return Number(text2);
|
|
445
|
+
}, "lookbackDays");
|
|
446
|
+
var LOCAL_READ = { remote: "none", local: "read" };
|
|
447
|
+
var REMOTE_READ2 = { remote: "read", local: "read" };
|
|
448
|
+
var backendOf = /* @__PURE__ */ __name((value) => {
|
|
449
|
+
if (!BACKENDS.includes(value))
|
|
450
|
+
throw new InvalidArgumentError("expected archive, server or both");
|
|
451
|
+
return value;
|
|
452
|
+
}, "backendOf");
|
|
453
|
+
var backendOption = /* @__PURE__ */ __name((command) => command.option("--backend <archive|server|both>", "where to read: the store (archive), the service (server), or both, kept in the store (default: both)", backendOf), "backendOption");
|
|
454
|
+
var BACKEND_HELP = "--backend both asks the service with the part of the query it can filter, keeps what it returns, then runs the whole query over the store; each item says found_in archive, server or both. --offline reads the store only.";
|
|
455
|
+
var LOCAL_WRITE = { remote: "none", local: "write" };
|
|
456
|
+
var FETCH = { remote: "read", local: "write" };
|
|
457
|
+
var addMeetingCommandsDefinition = /* @__PURE__ */ __name((program, deps) => {
|
|
458
|
+
const group = annotate(program.command("meetings").description("stored meetings and their records"), {
|
|
459
|
+
effects: { remote: "none", local: "none" }
|
|
460
|
+
});
|
|
461
|
+
const output = /* @__PURE__ */ __name((command) => command, "output");
|
|
462
|
+
const print = /* @__PURE__ */ __name((value, command) => {
|
|
463
|
+
const opts = command.optsWithGlobals();
|
|
464
|
+
deps.write(value, opts.json ? "json" : opts.jsonl ? "jsonl" : "text", command);
|
|
465
|
+
}, "print");
|
|
466
|
+
const access = /* @__PURE__ */ __name((command, backend) => {
|
|
467
|
+
const signal = deps.signal?.();
|
|
468
|
+
return {
|
|
469
|
+
...backend === void 0 ? {} : { backend },
|
|
470
|
+
offline: command.optsWithGlobals().offline === true,
|
|
471
|
+
timezone: timezoneOf(deps.timezone),
|
|
472
|
+
...deps.now ? { now: deps.now() } : {},
|
|
473
|
+
...signal ? { signal } : {}
|
|
474
|
+
};
|
|
475
|
+
}, "access");
|
|
476
|
+
const list = queryWordsAfterOptions(group.command("list").description("meetings, newest first: the service's and the stored ones, kept in the store")).argument("[query...]", "field:value terms that narrow the list \u2014 the fields are below").addHelpText("after", `
|
|
477
|
+
${fieldsHelp(MEETING_QUERY, MEETING_QUERY_GUIDE)}
|
|
478
|
+
${BACKEND_HELP}`);
|
|
479
|
+
annotate(list, {
|
|
480
|
+
effects: REMOTE_READ2,
|
|
481
|
+
partial: true,
|
|
482
|
+
query: defineQuery(MEETING_QUERY),
|
|
483
|
+
output: { entity: "meeting" }
|
|
484
|
+
});
|
|
485
|
+
backendOption(output(list)).option("--limit <n>", "meetings per page; the profile's defaults.limit when absent", integer3).option("--page <n>", "which page, starting at 1", integer3).action(async (words, opts, command) => {
|
|
486
|
+
const query = meetingsQuery(words.join(" "));
|
|
487
|
+
const { limit, page } = deps.pagingOf(command);
|
|
488
|
+
await deps.inRun(command, async () => {
|
|
489
|
+
const { server: _server, ...answer } = await meetingsListThrough(deps.source, deps.store, {
|
|
490
|
+
accountId: deps.accountId,
|
|
491
|
+
limit,
|
|
492
|
+
offset: (page - 1) * limit,
|
|
493
|
+
...query ? { query } : {}
|
|
494
|
+
}, access(command, opts.backend));
|
|
495
|
+
print(answer, command);
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
backendOption(output(annotate(group.command("show"), { effects: REMOTE_READ2, partial: true, output: { entity: "meeting_details" } }).description("show a meeting, read again from the service with its people, transcript and documents").argument("<meeting>", "the stored meeting's number, its meeting: ref, or the service's id (provider_id)").addHelpText("after", `${SAVE_HELP}
|
|
499
|
+
${BACKEND_HELP}`))).action(async (meeting, opts, command) => {
|
|
500
|
+
await deps.inRun(command, async () => {
|
|
501
|
+
const shown = await meetingShowThrough(deps.source, deps.store, deps.accountId, meeting, access(command, opts.backend));
|
|
502
|
+
const { item } = await meetingDetailsBody(deps.store, shown.details);
|
|
503
|
+
print({
|
|
504
|
+
item: shown.foundIn ? { ...item, found_in: shown.foundIn } : item,
|
|
505
|
+
...shown.missing ? { missing: shown.missing } : {},
|
|
506
|
+
...shown.meta ? { meta: shown.meta } : {}
|
|
507
|
+
}, command);
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
output(annotate(group.command("transcript"), { effects: LOCAL_READ, output: { entity: "meeting_transcript" } }).description("show current meeting transcripts").argument("<meeting>", "stored meeting id", integer3).option("--history", "include superseded transcript versions").addHelpText("after", SAVE_HELP)).action(async (id2, opts, command) => {
|
|
511
|
+
print(await meetingTranscriptAnswer(deps.store, id2, deps.accountId, { history: opts.history }), command);
|
|
512
|
+
});
|
|
513
|
+
output(annotate(group.command("summary"), { effects: LOCAL_READ, output: { entity: "meeting_summary" } }).description("show stored meeting summaries").argument("<meeting>", "stored meeting id", integer3)).action(async (id2, _opts, command) => {
|
|
514
|
+
print(await meetingSummaryAnswer(deps.store, id2, deps.accountId), command);
|
|
515
|
+
});
|
|
516
|
+
const exporter = output(annotate(group.command("export"), { effects: LOCAL_WRITE, output: { entity: "meeting_export" } }).description("export a meeting as Markdown or one transcript as WebVTT").argument("<meeting>", "stored meeting id", integer3).addOption(new Option("--format <format>", "export format").choices(["markdown", "vtt"]).default("markdown")).option("--transcript-id <id>", "export a specific transcript version", integer3).addOption(
|
|
517
|
+
// Not over MCP: an agent would choose where on the owner's disk to write; it gets the content in the answer.
|
|
518
|
+
annotateOption(new Option("--output <file>", "write content to a new file through the host's writer"), {
|
|
519
|
+
mcp: false
|
|
520
|
+
})
|
|
521
|
+
));
|
|
522
|
+
deps.newFileOutput?.(exporter, "output");
|
|
523
|
+
exporter.action(async (id2, opts, command) => {
|
|
524
|
+
if (opts.output !== void 0 && !opts.output.trim())
|
|
525
|
+
throw new MeetingError("validation_error", "output path must not be empty");
|
|
526
|
+
if (opts.output !== void 0 && !deps.writeFile)
|
|
527
|
+
throw new MeetingError("configuration_error", "the host has no export file writer");
|
|
528
|
+
const result = await exportMeeting(deps.store, id2, {
|
|
529
|
+
accountId: deps.accountId,
|
|
530
|
+
format: opts.format,
|
|
531
|
+
transcriptId: opts.transcriptId
|
|
532
|
+
});
|
|
533
|
+
if (opts.output !== void 0) {
|
|
534
|
+
await deps.writeFile?.(opts.output, result.content);
|
|
535
|
+
print({ meetingId: result.meetingId, format: result.format, output: opts.output }, command);
|
|
536
|
+
} else
|
|
537
|
+
print(result, command);
|
|
538
|
+
});
|
|
539
|
+
output(annotate(group.command("people"), { effects: LOCAL_READ, output: { entity: "meeting_participants" } }).description("find meeting participants by name or email").argument("<query>", "a name or an email address")).option("--limit <n>", "most matching observations per page, 1\u20131000 (default 50)", integer3).option("--scan-limit <n>", "most participant observations to inspect, 1\u201310000 (default 1000)", integer3).option("--max-read-bytes <bytes>", "most stored name and email bytes to read (default 1048576)", integer3).option("--cursor <cursor>", "continue with the same name query and selected account").action(async (query, opts, command) => {
|
|
540
|
+
const found = await meetingPeople(deps.store, query, deps.accountId, {
|
|
541
|
+
limit: opts.limit,
|
|
542
|
+
scanLimit: opts.scanLimit,
|
|
543
|
+
maxReadBytes: opts.maxReadBytes,
|
|
544
|
+
cursor: opts.cursor
|
|
545
|
+
});
|
|
546
|
+
print(found, command);
|
|
547
|
+
});
|
|
548
|
+
output(annotate(group.command("sync"), {
|
|
549
|
+
effects: FETCH,
|
|
550
|
+
offline: false,
|
|
551
|
+
output: { entity: "meeting_ingestion" },
|
|
552
|
+
// Only a sync that stops itself at its budget may outlive the one-shot deadline.
|
|
553
|
+
...deps.budgetOf ? { cooperative: true, partial: true } : {}
|
|
554
|
+
}).description("bring the stored meetings up to date from the connected account, oldest first; a run that stops before its deadline keeps what it saved and the next one goes on from there")).option("--since-time <time>", "fetch meetings starting at or after this ISO 8601 date or time, or 30m, 2h, 7d ago", (text2) => dateWindow({ sinceTime: text2, ...deps.timezone ? { zone: deps.timezone } : {}, now: deps.now?.() }).since).option("--lookback-days <days>", "revisit recent occurrences for late transcripts (0\u201331)", lookbackDays).option("--rescan", "read the last 30 days again, not only what came after the last sync").action(async (opts, command) => {
|
|
555
|
+
const source = deps.source;
|
|
556
|
+
if (!source)
|
|
557
|
+
throw new MeetingError("configuration_error", "meeting source is unavailable");
|
|
558
|
+
await deps.inRun(command, async () => print(await pull(source, deps.store, {
|
|
559
|
+
accountId: deps.accountId,
|
|
560
|
+
since: opts.sinceTime === void 0 ? void 0 : new Date(opts.sinceTime).toISOString(),
|
|
561
|
+
now: deps.now?.(),
|
|
562
|
+
...opts.lookbackDays === void 0 ? {} : { lookbackMs: opts.lookbackDays * 864e5 },
|
|
563
|
+
...opts.rescan ? { rescan: true } : {},
|
|
564
|
+
...deps.budgetOf ? { budget: deps.budgetOf(command) } : {}
|
|
565
|
+
}), command));
|
|
566
|
+
});
|
|
567
|
+
const importCommand = annotate(group.command("import"), {
|
|
568
|
+
effects: LOCAL_WRITE,
|
|
569
|
+
output: { entity: "meeting_ingestion" }
|
|
570
|
+
}).description("import downloaded meeting transcripts").argument("<folder>", "folder of transcripts downloaded from the provider");
|
|
571
|
+
if (deps.importHelp)
|
|
572
|
+
importCommand.addHelpText("after", `
|
|
573
|
+
${deps.importHelp}`);
|
|
574
|
+
output(importCommand).action(async (folder, _opts, command) => {
|
|
575
|
+
if (!deps.readFiles)
|
|
576
|
+
throw new MeetingError("configuration_error", "file reader is unavailable");
|
|
577
|
+
const files = await deps.readFiles(folder);
|
|
578
|
+
if (files.some((file) => file.meeting.accountId !== deps.accountId))
|
|
579
|
+
throw new MeetingError("validation_error", "file account differs from selected account");
|
|
580
|
+
print(await importFiles(files, deps.store, deps.now?.()), command);
|
|
581
|
+
});
|
|
582
|
+
output(annotate(group.command("repair"), {
|
|
583
|
+
effects: LOCAL_WRITE,
|
|
584
|
+
output: { entity: "meeting_repair" }
|
|
585
|
+
}).description("preview filling in what older builds left out of stored transcripts (their language); --yes stores it")).option("--yes", "store the detected languages; otherwise only preview").action(async (opts, command) => {
|
|
586
|
+
if (!deps.store.fillTranscriptLanguages)
|
|
587
|
+
throw new MeetingError("configuration_error", "this store cannot fill transcript languages");
|
|
588
|
+
print(await deps.store.fillTranscriptLanguages({
|
|
589
|
+
accountId: deps.accountId,
|
|
590
|
+
apply: opts.yes === true,
|
|
591
|
+
now: deps.now?.() ?? Date.now()
|
|
592
|
+
}), command);
|
|
593
|
+
});
|
|
594
|
+
if (deps.management)
|
|
595
|
+
addMeetingManagementCommands(group, {
|
|
596
|
+
management: deps.management,
|
|
597
|
+
print,
|
|
598
|
+
output,
|
|
599
|
+
inRun: deps.inRun,
|
|
600
|
+
...deps.askFirst ? { askFirst: deps.askFirst } : {},
|
|
601
|
+
...deps.signal ? { signal: deps.signal } : {}
|
|
602
|
+
});
|
|
603
|
+
const eventList = queryWordsAfterOptions(annotate(program.command("events").description("the owner's stored events"), {
|
|
604
|
+
effects: { remote: "none", local: "none" }
|
|
605
|
+
}).command("list")).description("list stored events").argument("[query...]", "event id, origin or time fields that narrow the list").addHelpText("after", `
|
|
606
|
+
${fieldsHelp(EVENT_QUERY, MEETING_QUERY_GUIDE)}`);
|
|
607
|
+
annotate(eventList, { effects: LOCAL_READ, output: { entity: "event" }, query: EVENT_QUERY });
|
|
608
|
+
output(eventList).action(async (words, _opts, command) => {
|
|
609
|
+
const query = words.length ? parseLucene(words.join(" "), { defaultField: "none", command: "events list" }) : void 0;
|
|
610
|
+
if (query)
|
|
611
|
+
validateQuery(query, EVENT_QUERY, { command: "events list" });
|
|
612
|
+
if (query && !deps.store.queryEvents)
|
|
613
|
+
throw new MeetingError("validation_error", "this store cannot filter events");
|
|
614
|
+
const events = query ? await deps.store.queryEvents?.(query) : await deps.store.events();
|
|
615
|
+
print(listed((events ?? []).map((one) => ({ ...eventItem(one), untrusted: [...EVENT_UNTRUSTED] }))), command);
|
|
616
|
+
});
|
|
617
|
+
}, "addMeetingCommandsDefinition");
|
|
618
|
+
var addMeetingCommands = sharedCommand(addMeetingCommandsDefinition);
|
|
619
|
+
|
|
620
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/cli/list-query.js
|
|
621
|
+
var LIST_QUERY_GUIDE = "https://github.com/WireCatLabs/cli-core/blob/main/docs/search/query-language.md";
|
|
622
|
+
var QUERY_ARGUMENT = "field:value terms that narrow the list \u2014 the fields are below";
|
|
623
|
+
var withQuery = /* @__PURE__ */ __name((command, registry) => {
|
|
624
|
+
const query = defineQuery(registry);
|
|
625
|
+
annotate(command, { query, output: { entity: registry.entity } });
|
|
626
|
+
const shown = askable(query);
|
|
627
|
+
queryWordsAfterOptions(command).argument("[query...]", shown.length > 0 ? QUERY_ARGUMENT : "field:value terms; this list filters by none yet");
|
|
628
|
+
if (shown.length > 0)
|
|
629
|
+
command.addHelpText("after", `
|
|
630
|
+
${fieldsHelp({ ...query, fields: shown }, LIST_QUERY_GUIDE)}`);
|
|
631
|
+
return command;
|
|
632
|
+
}, "withQuery");
|
|
633
|
+
var unfilteredQuery = /* @__PURE__ */ __name((entity, schema) => ({
|
|
634
|
+
entity,
|
|
635
|
+
backend: "native",
|
|
636
|
+
fields: queryFieldsOf(schema, {})
|
|
637
|
+
}), "unfilteredQuery");
|
|
638
|
+
var commandPath = /* @__PURE__ */ __name((command) => {
|
|
639
|
+
const words = [];
|
|
640
|
+
for (let at = command; at?.parent; at = at.parent)
|
|
641
|
+
words.unshift(at.name());
|
|
642
|
+
return words.join(" ");
|
|
643
|
+
}, "commandPath");
|
|
644
|
+
var withTomorrow = /* @__PURE__ */ __name((query, registry, zone = timezoneOf(), now = Date.now()) => {
|
|
645
|
+
const times = new Set(registry.fields.filter(({ type }) => type === "time").map(({ name }) => name));
|
|
646
|
+
const date = /* @__PURE__ */ new Date(`${new Intl.DateTimeFormat("en-CA", { timeZone: zone }).format(now)}T00:00:00Z`);
|
|
647
|
+
date.setUTCDate(date.getUTCDate() + 1);
|
|
648
|
+
const tomorrow = date.toISOString().slice(0, 10);
|
|
649
|
+
const day = /* @__PURE__ */ __name((value) => value.toLowerCase() === "tomorrow" ? tomorrow : value, "day");
|
|
650
|
+
const map = /* @__PURE__ */ __name((node) => node.kind === "predicate" ? times.has(node.field) ? { ...node, value: day(node.value), ...node.upper === void 0 ? {} : { upper: day(node.upper) } } : node : { ...node, clauses: node.clauses.map((clause) => ({ ...clause, node: map(clause.node) })) }, "map");
|
|
651
|
+
return { ...query, root: map(query.root) };
|
|
652
|
+
}, "withTomorrow");
|
|
653
|
+
var listQuery = /* @__PURE__ */ __name((text2, registry, command, { defaultField = "none" } = {}) => {
|
|
654
|
+
const context = { command, guide: LIST_QUERY_GUIDE };
|
|
655
|
+
const signed = text2.replace(/(^|[\s(])([\p{L}_][\p{L}\p{N}_.]*:)\+([^\s()"]+)/gu, '$1$2"+$3"');
|
|
656
|
+
const parsed = signed.trim() === "" ? void 0 : parseLucene(signed, { defaultField, ...context });
|
|
657
|
+
const typed = parsed && withTomorrow(parsed, registry);
|
|
658
|
+
if (typed)
|
|
659
|
+
validateQuery(typed, registry, context);
|
|
660
|
+
const named2 = typed ? fieldsNamed(typed) : /* @__PURE__ */ new Set();
|
|
661
|
+
const defaults = (registry.defaults ?? []).filter((term) => !named2.has(term.replace(/^-/, "").split(/[:<>=]/)[0] ?? "")).map((term) => parseLucene(term, { defaultField: "none", ...context }).root);
|
|
662
|
+
const roots = [...typed ? [typed.root] : [], ...defaults];
|
|
663
|
+
if (roots.length === 0)
|
|
664
|
+
return void 0;
|
|
665
|
+
if (roots.length === 1 && typed)
|
|
666
|
+
return typed;
|
|
667
|
+
return {
|
|
668
|
+
version: 1,
|
|
669
|
+
language: "lucene-v1",
|
|
670
|
+
root: {
|
|
671
|
+
kind: "boolean",
|
|
672
|
+
clauses: roots.map((node) => ({ occur: "must", node })),
|
|
673
|
+
span: { start: 0, end: text2.length }
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
}, "listQuery");
|
|
677
|
+
var typedQuery = /* @__PURE__ */ __name((words) => typeof words === "string" ? words : (words ?? []).join(" "), "typedQuery");
|
|
678
|
+
var EVERY = Number.MAX_SAFE_INTEGER - 1;
|
|
679
|
+
var pageOf = /* @__PURE__ */ __name(({ limit, page, all }) => all ? { limit: EVERY, offset: 0 } : { limit, offset: (page - 1) * limit }, "pageOf");
|
|
680
|
+
var pagedList = /* @__PURE__ */ __name((command, { limit, page, all }, { items, hasMore, ...rest }) => listOf(command, {
|
|
681
|
+
...rest,
|
|
682
|
+
items,
|
|
683
|
+
limit: all ? Math.max(1, items.length) : limit,
|
|
684
|
+
has_more: all ? false : hasMore,
|
|
685
|
+
page
|
|
686
|
+
}), "pagedList");
|
|
687
|
+
var askable = /* @__PURE__ */ __name((registry) => registry.backend === "native" ? registry.fields.filter((field) => field.native) : registry.fields, "askable");
|
|
688
|
+
var queryArgument = /* @__PURE__ */ __name((registry) => optional(pipe(string(), maxLength(QUERY_LIMITS.bytes), description(queryDescription(registry)))), "queryArgument");
|
|
689
|
+
var negatableOf = /* @__PURE__ */ __name((registry) => askable(registry).filter((field) => field.negatable).map((field) => field.name), "negatableOf");
|
|
690
|
+
var nativeTerms = /* @__PURE__ */ __name((ast, command) => new Map([...nativeTermLists(ast, command)].map(([field, [node]]) => [field, node])), "nativeTerms");
|
|
691
|
+
var nativeTermLists = /* @__PURE__ */ __name((ast, command, repeatable = [], negatable = []) => {
|
|
692
|
+
const terms = /* @__PURE__ */ new Map();
|
|
693
|
+
if (!ast)
|
|
694
|
+
return terms;
|
|
695
|
+
const context = { command, guide: LIST_QUERY_GUIDE };
|
|
696
|
+
const add = /* @__PURE__ */ __name((node) => {
|
|
697
|
+
if (node.kind === "boolean") {
|
|
698
|
+
for (const clause of node.clauses) {
|
|
699
|
+
const excluded = clause.occur === "must_not" && clause.node.kind === "predicate" && negatable.includes(clause.node.field);
|
|
700
|
+
if (excluded && clause.node.kind === "predicate") {
|
|
701
|
+
const key = `-${clause.node.field}`;
|
|
702
|
+
terms.set(key, [...terms.get(key) ?? [], clause.node]);
|
|
703
|
+
continue;
|
|
704
|
+
}
|
|
705
|
+
if (clause.occur !== "must")
|
|
706
|
+
queryError("query.unsupported-placement", clause.node.span, negatable.length ? `this list takes only field:value terms joined by AND, and -field:value for ${negatable.join(", ")}` : "this list takes only field:value terms joined by AND", context);
|
|
707
|
+
add(clause.node);
|
|
708
|
+
}
|
|
709
|
+
return;
|
|
710
|
+
}
|
|
711
|
+
const held = terms.get(node.field);
|
|
712
|
+
if (held && !repeatable.includes(node.field))
|
|
713
|
+
queryError("query.unsupported-placement", node.span, `${node.field} only once here`, context);
|
|
714
|
+
terms.set(node.field, [...held ?? [], node]);
|
|
715
|
+
}, "add");
|
|
716
|
+
add(ast.root);
|
|
717
|
+
return terms;
|
|
718
|
+
}, "nativeTermLists");
|
|
719
|
+
var queryTerms = /* @__PURE__ */ __name((words, registry, command, ranged = []) => {
|
|
720
|
+
const terms = /* @__PURE__ */ new Map();
|
|
721
|
+
for (const [field, node] of nativeTerms(listQuery(typedQuery(words), registry, command), command)) {
|
|
722
|
+
if (ranged.includes(field))
|
|
723
|
+
continue;
|
|
724
|
+
if (node.operator !== "term" && node.operator !== "phrase")
|
|
725
|
+
queryError("query.unsupported-placement", node.span, `${field} takes one whole value here`, {
|
|
726
|
+
command,
|
|
727
|
+
guide: LIST_QUERY_GUIDE
|
|
728
|
+
});
|
|
729
|
+
const enumerated = registry.fields.find(({ name }) => name === field)?.type === "enum";
|
|
730
|
+
terms.set(field, enumerated ? node.value.toLowerCase() : node.value);
|
|
731
|
+
}
|
|
732
|
+
return terms;
|
|
733
|
+
}, "queryTerms");
|
|
734
|
+
var timeBounds = /* @__PURE__ */ __name((term, zone = timezoneOf(), now) => {
|
|
735
|
+
if (!term)
|
|
736
|
+
return {};
|
|
737
|
+
const upper = term.operator === "range" ? term.upper ?? "*" : term.value;
|
|
738
|
+
const range2 = dateRange(term.value, upper, term.operator === "range" ? term.lower_inclusive !== false : true, term.operator === "range" ? term.upper_inclusive !== false : true, zone, term.span, now);
|
|
739
|
+
const until = range2.upper === void 0 ? void 0 : range2.upper - (range2.upper_inclusive ? 0 : 1);
|
|
740
|
+
return {
|
|
741
|
+
...range2.lower === void 0 ? {} : { since: range2.lower },
|
|
742
|
+
...until === void 0 ? {} : { until },
|
|
743
|
+
meta: {
|
|
744
|
+
timezone: zone,
|
|
745
|
+
window: {
|
|
746
|
+
...range2.lower === void 0 ? {} : { since: new Date(range2.lower).toISOString() },
|
|
747
|
+
...until === void 0 ? {} : { until: new Date(until).toISOString() }
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
}, "timeBounds");
|
|
752
|
+
var searchText = /* @__PURE__ */ __name((term) => term === void 0 ? void 0 : term.value.replace(/^\*+|\*+$/g, ""), "searchText");
|
|
753
|
+
var nativeField = /* @__PURE__ */ __name((field) => ({ ...field, native: true }), "nativeField");
|
|
754
|
+
var termField = /* @__PURE__ */ __name((name, type, example, more = {}) => nativeField({
|
|
755
|
+
name,
|
|
756
|
+
type,
|
|
757
|
+
operators: OPERATORS_BY_TYPE[type].filter((operator) => operator === "term" || operator === "phrase"),
|
|
758
|
+
example,
|
|
759
|
+
...more
|
|
760
|
+
}), "termField");
|
|
761
|
+
var queryHelp = /* @__PURE__ */ __name((registry) => `
|
|
762
|
+
${fieldsHelp(registry, LIST_QUERY_GUIDE)}`, "queryHelp");
|
|
763
|
+
|
|
764
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/guard.js
|
|
765
|
+
import { randomUUID } from "node:crypto";
|
|
766
|
+
|
|
767
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/flood.js
|
|
768
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
769
|
+
import { dirname, join } from "node:path";
|
|
770
|
+
var MOST_DEADLINES = 50;
|
|
771
|
+
var LIMITED_HOLD_MS = 60 * 60 * 1e3;
|
|
772
|
+
var FROZEN_HOLD_MS = 24 * 60 * 60 * 1e3;
|
|
773
|
+
var NO_END = "9999-12-31T23:59:59.999Z";
|
|
774
|
+
var holdEnd = /* @__PURE__ */ __name((block, show = (iso) => iso) => block.until === null ? "until lifted" : `until ${show(block.until)}`, "holdEnd");
|
|
775
|
+
var floodPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "flood", `${profile}.json`), "floodPathFor");
|
|
776
|
+
var FloodMemory = class {
|
|
777
|
+
static {
|
|
778
|
+
__name(this, "FloodMemory");
|
|
779
|
+
}
|
|
780
|
+
path;
|
|
781
|
+
now;
|
|
782
|
+
constructor(path, now = Date.now) {
|
|
783
|
+
this.path = path;
|
|
784
|
+
this.now = now;
|
|
785
|
+
}
|
|
786
|
+
/** What is still in force; anything expired is left out. */
|
|
787
|
+
read() {
|
|
788
|
+
const now = this.now();
|
|
789
|
+
let raw;
|
|
790
|
+
try {
|
|
791
|
+
raw = JSON.parse(readFileSync(this.path, "utf8"));
|
|
792
|
+
} catch {
|
|
793
|
+
return { deadlines: [] };
|
|
794
|
+
}
|
|
795
|
+
const alive = /* @__PURE__ */ __name((until) => typeof until === "string" && Date.parse(until) > now, "alive");
|
|
796
|
+
const deadlines = Array.isArray(raw.deadlines) ? raw.deadlines.filter((one) => typeof one?.operation === "string" && alive(one.until)) : [];
|
|
797
|
+
const block = raw.sendBlock && (raw.sendBlock.until === NO_END ? { ...raw.sendBlock, until: null } : raw.sendBlock);
|
|
798
|
+
const held = block && (block.until === null || alive(block.until));
|
|
799
|
+
return { deadlines, ...held ? { sendBlock: block } : {} };
|
|
800
|
+
}
|
|
801
|
+
/** The deadline this call is still under: one for its chat, or one for the call in every chat. */
|
|
802
|
+
owed(operation, chatId) {
|
|
803
|
+
return this.read().deadlines.filter((one) => one.operation === operation && (one.chatId === void 0 || one.chatId === chatId)).sort((a, b) => b.until.localeCompare(a.until))[0];
|
|
804
|
+
}
|
|
805
|
+
remember(deadline) {
|
|
806
|
+
const { waitMs, ...rest } = deadline;
|
|
807
|
+
const kept2 = { ...rest, until: new Date(this.now() + waitMs).toISOString() };
|
|
808
|
+
const state = this.read();
|
|
809
|
+
const others = state.deadlines.filter((one) => one.operation !== kept2.operation || one.chatId !== kept2.chatId);
|
|
810
|
+
const deadlines = [...others, kept2].sort((a, b) => b.until.localeCompare(a.until)).slice(0, MOST_DEADLINES);
|
|
811
|
+
this.#write({ ...state, deadlines });
|
|
812
|
+
return kept2;
|
|
813
|
+
}
|
|
814
|
+
sendBlock() {
|
|
815
|
+
return this.read().sendBlock;
|
|
816
|
+
}
|
|
817
|
+
/** A ban the messenger gave no end for holds until lifted; a spam limit or a freeze without one, for a while. */
|
|
818
|
+
block(block) {
|
|
819
|
+
const now = this.now();
|
|
820
|
+
const holdMs = { limited: LIMITED_HOLD_MS, frozen: FROZEN_HOLD_MS, banned: void 0 }[block.state];
|
|
821
|
+
const kept2 = {
|
|
822
|
+
...block,
|
|
823
|
+
since: new Date(now).toISOString(),
|
|
824
|
+
until: block.until ?? (holdMs === void 0 ? null : new Date(now + holdMs).toISOString())
|
|
825
|
+
};
|
|
826
|
+
this.#write({ ...this.read(), sendBlock: kept2 });
|
|
827
|
+
return kept2;
|
|
828
|
+
}
|
|
829
|
+
/** Lifts only a block of this state: an account found not frozen may still be limited for spam. */
|
|
830
|
+
unblock(state) {
|
|
831
|
+
const { sendBlock, ...rest } = this.read();
|
|
832
|
+
if (sendBlock?.state === state)
|
|
833
|
+
this.#write(rest);
|
|
834
|
+
}
|
|
835
|
+
/** Forgets every wait and lifts the hold, and answers with what was still in force. */
|
|
836
|
+
clear() {
|
|
837
|
+
const cleared2 = this.read();
|
|
838
|
+
this.#write({ deadlines: [] });
|
|
839
|
+
return cleared2;
|
|
840
|
+
}
|
|
841
|
+
#write({ sendBlock, ...rest }) {
|
|
842
|
+
const state = sendBlock ? { ...rest, sendBlock: { ...sendBlock, until: sendBlock.until ?? NO_END } } : rest;
|
|
843
|
+
mkdirSync(dirname(this.path), { recursive: true, mode: 448 });
|
|
844
|
+
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
845
|
+
writeFileSync(temporary, `${JSON.stringify(state)}
|
|
846
|
+
`, { mode: 384 });
|
|
847
|
+
renameSync(temporary, this.path);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/journal.js
|
|
852
|
+
import { appendFileSync, mkdirSync as mkdirSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
853
|
+
import { dirname as dirname3, join as join2 } from "node:path";
|
|
854
|
+
|
|
855
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/file-lock.js
|
|
856
|
+
import { closeSync, mkdirSync as mkdirSync2, openSync, statSync, unlinkSync } from "node:fs";
|
|
857
|
+
import { dirname as dirname2 } from "node:path";
|
|
858
|
+
var LOCK_WAIT_MS = 5e3;
|
|
859
|
+
var LOCK_STALE_MS = 3e4;
|
|
860
|
+
var RETRY_MS = 20;
|
|
861
|
+
var pause = new Int32Array(new SharedArrayBuffer(4));
|
|
862
|
+
var withFileLock = /* @__PURE__ */ __name((path, what, body, waitMs = LOCK_WAIT_MS) => {
|
|
863
|
+
const lock = lockFor(path);
|
|
864
|
+
const deadline = Date.now() + waitMs;
|
|
865
|
+
while (!taken(lock)) {
|
|
866
|
+
if (Date.now() >= deadline)
|
|
867
|
+
throw lockTimeout(what, waitMs, lock);
|
|
868
|
+
Atomics.wait(pause, 0, 0, RETRY_MS);
|
|
869
|
+
}
|
|
870
|
+
return holding(lock, body);
|
|
871
|
+
}, "withFileLock");
|
|
872
|
+
var withFileLockAsync = /* @__PURE__ */ __name(async (path, what, body, waitMs = LOCK_WAIT_MS, sleep = realSleep) => {
|
|
873
|
+
const lock = lockFor(path);
|
|
874
|
+
const deadline = Date.now() + waitMs;
|
|
875
|
+
while (!taken(lock)) {
|
|
876
|
+
if (Date.now() >= deadline)
|
|
877
|
+
throw lockTimeout(what, waitMs, lock);
|
|
878
|
+
await sleep(RETRY_MS);
|
|
879
|
+
}
|
|
880
|
+
return holding(lock, body);
|
|
881
|
+
}, "withFileLockAsync");
|
|
882
|
+
var lockFor = /* @__PURE__ */ __name((path) => {
|
|
883
|
+
mkdirSync2(dirname2(path), { recursive: true, mode: 448 });
|
|
884
|
+
return `${path}.lock`;
|
|
885
|
+
}, "lockFor");
|
|
886
|
+
var taken = /* @__PURE__ */ __name((lock) => {
|
|
887
|
+
for (; ; ) {
|
|
888
|
+
try {
|
|
889
|
+
closeSync(openSync(lock, "wx", 384));
|
|
890
|
+
return true;
|
|
891
|
+
} catch (error) {
|
|
892
|
+
if (error.code !== "EEXIST")
|
|
893
|
+
throw error;
|
|
894
|
+
if (Date.now() - lockTime(lock) <= LOCK_STALE_MS)
|
|
895
|
+
return false;
|
|
896
|
+
try {
|
|
897
|
+
unlinkSync(lock);
|
|
898
|
+
} catch {
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}, "taken");
|
|
903
|
+
var holding = /* @__PURE__ */ __name((lock, body) => {
|
|
904
|
+
try {
|
|
905
|
+
return body();
|
|
906
|
+
} finally {
|
|
907
|
+
try {
|
|
908
|
+
unlinkSync(lock);
|
|
909
|
+
} catch {
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
}, "holding");
|
|
913
|
+
var lockTimeout = /* @__PURE__ */ __name((what, waitMs, lock) => new CliError("timeout", `${what} stayed locked for ${waitMs / 1e3}s (${lock})`), "lockTimeout");
|
|
914
|
+
var lockTime = /* @__PURE__ */ __name((lock) => {
|
|
915
|
+
try {
|
|
916
|
+
return statSync(lock).mtimeMs;
|
|
917
|
+
} catch {
|
|
918
|
+
return Date.now();
|
|
919
|
+
}
|
|
920
|
+
}, "lockTime");
|
|
921
|
+
|
|
922
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/journal.js
|
|
923
|
+
var sendsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join2(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "sends", `${profile}.jsonl`), "sendsPathFor");
|
|
924
|
+
var SendJournal = class {
|
|
925
|
+
static {
|
|
926
|
+
__name(this, "SendJournal");
|
|
927
|
+
}
|
|
928
|
+
path;
|
|
929
|
+
resource;
|
|
930
|
+
constructor(path, resource = { service: "unknown", version: "unknown" }) {
|
|
931
|
+
this.path = path;
|
|
932
|
+
this.resource = resource;
|
|
933
|
+
}
|
|
934
|
+
/**
|
|
935
|
+
* Runs `body` with the journal to itself, across processes: two sends at the limit must not both
|
|
936
|
+
* read "one left". A lock file opened with `wx`, because `flock` is not there on Windows.
|
|
937
|
+
*/
|
|
938
|
+
locked(body) {
|
|
939
|
+
return withFileLock(this.path, "the send journal", body);
|
|
940
|
+
}
|
|
941
|
+
/** `locked` without blocking the thread while another process holds the journal: what `serve` uses. */
|
|
942
|
+
lockedAsync(body) {
|
|
943
|
+
return withFileLockAsync(this.path, "the send journal", body);
|
|
944
|
+
}
|
|
945
|
+
append(entry) {
|
|
946
|
+
const { at, ...attributes } = entry;
|
|
947
|
+
const { runId, command, traceId } = currentRun();
|
|
948
|
+
const record = logRecordOf({
|
|
949
|
+
severity: entry.outcome === "sent" || entry.outcome === "reserved" ? "info" : "warn",
|
|
950
|
+
event: logAttributes({ event: "send.recorded", ...attributes }),
|
|
951
|
+
time: at,
|
|
952
|
+
runId,
|
|
953
|
+
...traceId === void 0 ? {} : { traceId },
|
|
954
|
+
command,
|
|
955
|
+
resource: this.resource,
|
|
956
|
+
allow: LOG_ATTRIBUTES
|
|
957
|
+
});
|
|
958
|
+
mkdirSync3(dirname3(this.path), { recursive: true, mode: 448 });
|
|
959
|
+
appendFileSync(this.path, `${JSON.stringify(record)}
|
|
960
|
+
`, { mode: 384 });
|
|
961
|
+
}
|
|
962
|
+
/**
|
|
963
|
+
* Oldest first, each reservation folded into its outcome; one with no outcome yet is in flight,
|
|
964
|
+
* or its process died. A line that does not parse is skipped: a torn last write must not block sending.
|
|
965
|
+
*/
|
|
966
|
+
entries(filter) {
|
|
967
|
+
const lines = this.#lines();
|
|
968
|
+
const settled = new Set(lines.filter((entry) => entry.outcome !== "reserved").map((entry) => entry.reservation));
|
|
969
|
+
const entries = lines.filter((entry) => entry.outcome !== "reserved" || !settled.has(entry.reservation)).map(({ reservation, ...entry }) => entry.outcome === "reserved" ? { ...entry, reservation } : entry).map(withSendId);
|
|
970
|
+
return filter === void 0 ? entries : entries.filter((entry) => (filter.outcome === void 0 || entry.outcome === filter.outcome) && (filter.chatId === void 0 || entry.chatId === filter.chatId) && (filter.operationId === void 0 || entry.operationId === filter.operationId) && (filter.errorCode === void 0 || entry.errorCode === filter.errorCode) && (filter.key === void 0 || entry.key === filter.key));
|
|
971
|
+
}
|
|
972
|
+
#lines() {
|
|
973
|
+
let text2;
|
|
974
|
+
try {
|
|
975
|
+
text2 = readFileSync2(this.path, "utf8");
|
|
976
|
+
} catch {
|
|
977
|
+
return [];
|
|
978
|
+
}
|
|
979
|
+
return text2.split("\n").filter((line) => line.trim() !== "").flatMap((line) => {
|
|
980
|
+
try {
|
|
981
|
+
return [entryOf(JSON.parse(line))];
|
|
982
|
+
} catch {
|
|
983
|
+
return [];
|
|
984
|
+
}
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
};
|
|
988
|
+
var entryOf = /* @__PURE__ */ __name((line) => {
|
|
989
|
+
if (!("attributes" in line))
|
|
990
|
+
return line;
|
|
991
|
+
const { event: _, ...attributes } = line.attributes;
|
|
992
|
+
return { at: line.time, ...fromLogAttributes(attributes) };
|
|
993
|
+
}, "entryOf");
|
|
994
|
+
var withSendId = /* @__PURE__ */ __name((entry) => {
|
|
995
|
+
const { cid, ...rest } = entry;
|
|
996
|
+
return cid === void 0 || rest.sendId !== void 0 ? rest : { ...rest, sendId: String(cid) };
|
|
997
|
+
}, "withSendId");
|
|
998
|
+
|
|
999
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/recipients.js
|
|
1000
|
+
import { existsSync, readFileSync as readFileSync3, rmSync } from "node:fs";
|
|
1001
|
+
import { join as join3 } from "node:path";
|
|
1002
|
+
var recipientsPathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join3(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "profiles", `${profile}.recipients.json`), "recipientsPathFor");
|
|
1003
|
+
var RecipientList = class {
|
|
1004
|
+
static {
|
|
1005
|
+
__name(this, "RecipientList");
|
|
1006
|
+
}
|
|
1007
|
+
path;
|
|
1008
|
+
command;
|
|
1009
|
+
lockWaitMs;
|
|
1010
|
+
/** `command` names the program in the hint that turns the list off. */
|
|
1011
|
+
constructor(path, command, lockWaitMs) {
|
|
1012
|
+
this.path = path;
|
|
1013
|
+
this.command = command;
|
|
1014
|
+
this.lockWaitMs = lockWaitMs;
|
|
1015
|
+
}
|
|
1016
|
+
/** `undefined` when the list is off. A file that cannot be read refuses rather than opening up. */
|
|
1017
|
+
read() {
|
|
1018
|
+
if (!existsSync(this.path))
|
|
1019
|
+
return void 0;
|
|
1020
|
+
try {
|
|
1021
|
+
const parsed = JSON.parse(readFileSync3(this.path, "utf8"));
|
|
1022
|
+
if (!Array.isArray(parsed.chats))
|
|
1023
|
+
throw new Error("no `chats` array");
|
|
1024
|
+
return parsed.chats;
|
|
1025
|
+
} catch (error) {
|
|
1026
|
+
throw new CliError("configuration_error", `the recipient list ${this.path} cannot be read (${error instanceof Error ? error.message : String(error)}) \u2014 fix the file or turn the list off with \`${this.command} recipients clear\``);
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
list(filter = {}) {
|
|
1030
|
+
const chats = this.read();
|
|
1031
|
+
return {
|
|
1032
|
+
state: chats === void 0 ? "off" : chats.length === 0 ? "empty" : "on",
|
|
1033
|
+
items: (chats ?? []).filter((chat) => (filter.id === void 0 || chat.id === filter.id) && (filter.title === void 0 || chat.title?.toLocaleLowerCase() === filter.title.toLocaleLowerCase()))
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
/** Whether it was new. Adding one again fills in a partner an older entry was stored without. */
|
|
1037
|
+
add(recipient) {
|
|
1038
|
+
return this.#locked(() => this.#added(recipient));
|
|
1039
|
+
}
|
|
1040
|
+
/** `add` waiting for the lock on timers: `recipients add` connects, so it runs inside `serve` when one holds the account. */
|
|
1041
|
+
addAsync(recipient) {
|
|
1042
|
+
return withFileLockAsync(this.path, "the recipient list", () => this.#added(recipient), this.lockWaitMs);
|
|
1043
|
+
}
|
|
1044
|
+
#added(recipient) {
|
|
1045
|
+
const chats = this.read() ?? [];
|
|
1046
|
+
const known = chats.find((chat) => chat.id === recipient.id);
|
|
1047
|
+
if (known) {
|
|
1048
|
+
if (recipient.partnerId && !known.partnerId) {
|
|
1049
|
+
this.#write(chats.map((chat) => chat === known ? { ...known, partnerId: recipient.partnerId } : chat));
|
|
1050
|
+
}
|
|
1051
|
+
return false;
|
|
1052
|
+
}
|
|
1053
|
+
this.#write([...chats, recipient]);
|
|
1054
|
+
return true;
|
|
1055
|
+
}
|
|
1056
|
+
/** The id or the title as it was stored; `undefined` when neither matched. */
|
|
1057
|
+
remove(reference) {
|
|
1058
|
+
return this.#locked(() => {
|
|
1059
|
+
const chats = this.read() ?? [];
|
|
1060
|
+
const wanted = reference.trim();
|
|
1061
|
+
const gone = chats.find((chat) => chat.id === wanted) ?? chats.find((chat) => chat.title?.toLocaleLowerCase() === wanted.toLocaleLowerCase());
|
|
1062
|
+
if (gone)
|
|
1063
|
+
this.#write(chats.filter((chat) => chat !== gone));
|
|
1064
|
+
return gone;
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
/**
|
|
1068
|
+
* The chat the messenger now names `to`: its entry, and a partner of that id, follow it. Only an entry already there
|
|
1069
|
+
* changes, and no list is created, so the list never opens up. Whether anything changed.
|
|
1070
|
+
*/
|
|
1071
|
+
async rekey(from, to) {
|
|
1072
|
+
if (from === to)
|
|
1073
|
+
return false;
|
|
1074
|
+
return withFileLockAsync(this.path, "the recipient list", () => {
|
|
1075
|
+
const chats = this.read();
|
|
1076
|
+
if (!chats?.some((chat) => chat.id === from || chat.partnerId === from))
|
|
1077
|
+
return false;
|
|
1078
|
+
const held = chats.some((chat) => chat.id === to);
|
|
1079
|
+
this.#write(chats.filter((chat) => !(held && chat.id === from)).map((chat) => ({
|
|
1080
|
+
...chat,
|
|
1081
|
+
...chat.id === from ? { id: to } : {},
|
|
1082
|
+
...chat.partnerId === from ? { partnerId: to } : {}
|
|
1083
|
+
})));
|
|
1084
|
+
return true;
|
|
1085
|
+
}, this.lockWaitMs);
|
|
1086
|
+
}
|
|
1087
|
+
/** Whether there was a list to turn off. */
|
|
1088
|
+
off() {
|
|
1089
|
+
return this.#locked(() => {
|
|
1090
|
+
if (!existsSync(this.path))
|
|
1091
|
+
return false;
|
|
1092
|
+
rmSync(this.path);
|
|
1093
|
+
return true;
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
/**
|
|
1097
|
+
* Every change reads and writes under one lock: a `serve` re-keying while the owner removes a chat must not write
|
|
1098
|
+
* the removed chat back. A lock held too long refuses the change and leaves the list as it was. Blocks the thread
|
|
1099
|
+
* while it waits: for callers that cannot be async, and `recipients remove` and `clear`, which never
|
|
1100
|
+
* connect and so never run inside `serve`.
|
|
1101
|
+
*/
|
|
1102
|
+
#locked(body) {
|
|
1103
|
+
return withFileLock(this.path, "the recipient list", body, this.lockWaitMs);
|
|
1104
|
+
}
|
|
1105
|
+
#write(chats) {
|
|
1106
|
+
writeSecurely(this.path, `${JSON.stringify({ chats }, null, 2)}
|
|
1107
|
+
`, 384);
|
|
1108
|
+
}
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/guard.js
|
|
1112
|
+
var HOUR_MS = 60 * 60 * 1e3;
|
|
1113
|
+
var countsTowardLimit = /* @__PURE__ */ __name(({ kind = "message", action, notify }) => kind === "message" || kind === "forward" || kind === "edit" || kind === "delete" || kind === "pin" && notify === true || action === "create" || action === "members.add" || action === "requests.accept" || action === "join" || action === "contact-import", "countsTowardLimit");
|
|
1114
|
+
var weightOf = /* @__PURE__ */ __name(({ kind = "message", action, count: count2, people }) => kind === "delete" || kind === "message" && action === void 0 ? Math.max(1, count2 ?? 1) : action === "create" || action === "members.add" || action === "requests.accept" || action === "contact-import" ? Math.max(1, people ?? count2 ?? 1) : 1, "weightOf");
|
|
1115
|
+
var timeOf = /* @__PURE__ */ __name((entry) => {
|
|
1116
|
+
const scheduled = entry.scheduledFor === void 0 ? Number.NaN : Date.parse(entry.scheduledFor);
|
|
1117
|
+
return Number.isNaN(scheduled) ? Date.parse(entry.at) : scheduled;
|
|
1118
|
+
}, "timeOf");
|
|
1119
|
+
var ceilingRefusal = /* @__PURE__ */ __name((key, command) => new CliError("permission_error", `${key} is not allowed: setup's answer keeps every WireCat tool read-only; the owner changes it at a terminal with \`${command} setup\``, { permission: key }), "ceilingRefusal");
|
|
1120
|
+
var levelRefusal = /* @__PURE__ */ __name((refused, fix = `${refused.command} ${refused.profile} config set permissions.${refused.key} allow`) => refused.named === CEILING_KEY ? ceilingRefusal(refused.key, refused.command) : new CliError("permission_error", `profile ${refused.profile} does not let ${refused.key} write (permissions.${refused.named} is ${refused.level}, from the ${refused.permissionSources[refused.named ?? ""] ?? "default"}); to allow it: ${fix}`, { permission: refused.key }), "levelRefusal");
|
|
1121
|
+
var sendGuard = /* @__PURE__ */ __name(({ profile, recipients, command = recipients.command, readOnlyLock, permissions, permissionSources = {}, permissionDefaults, permissionFix, ask = refuseToAsk, sendsPerHour, journal, flood, warn, now = /* @__PURE__ */ __name(() => /* @__PURE__ */ new Date(), "now") }) => {
|
|
1122
|
+
const currentPermissions = /* @__PURE__ */ __name(() => typeof permissions === "function" ? permissions() : permissions, "currentPermissions");
|
|
1123
|
+
let reservation;
|
|
1124
|
+
const answered = /* @__PURE__ */ new WeakSet();
|
|
1125
|
+
const refuseReadOnly = /* @__PURE__ */ __name(({ key }) => {
|
|
1126
|
+
if (key !== void 0 && STORE_ONLY_KEYS.has(key))
|
|
1127
|
+
return;
|
|
1128
|
+
if (readOnlyLock)
|
|
1129
|
+
throw readOnlyRefusal(readOnlyLock, MESSENGER_CHANGE_REFUSAL);
|
|
1130
|
+
}, "refuseReadOnly");
|
|
1131
|
+
const refuseHeld = /* @__PURE__ */ __name(({ key }) => {
|
|
1132
|
+
if (key !== void 0 && STORE_ONLY_KEYS.has(key))
|
|
1133
|
+
return;
|
|
1134
|
+
const block = flood?.sendBlock();
|
|
1135
|
+
if (!block)
|
|
1136
|
+
return;
|
|
1137
|
+
throw new CliError("permission_error", `profile ${profile} holds its writes ${holdEnd(block)}: ${block.hint} \u2014 reads still work; do not retry: the owner checks the account with \`${command} ${profile} doctor --online\`, and lifts the hold with \`${command} ${profile} flood clear\` once it is over`, { sendBlock: block, standing: { state: block.state, hint: block.hint } });
|
|
1138
|
+
}, "refuseHeld");
|
|
1139
|
+
const permitted = /* @__PURE__ */ __name((request) => {
|
|
1140
|
+
const { chatId, kind = "message", action, personIds } = request;
|
|
1141
|
+
refuseReadOnly(request);
|
|
1142
|
+
const levels = currentPermissions();
|
|
1143
|
+
if (levels !== void 0) {
|
|
1144
|
+
const key = request.key ?? keyForWrite(kind, action);
|
|
1145
|
+
const { level, key: named2 } = levelFor(levels, key, permissionDefaults);
|
|
1146
|
+
if (stops(level, key))
|
|
1147
|
+
throw levelRefusal({ profile, command, key, level, named: named2, permissionSources }, permissionFix?.(request, key));
|
|
1148
|
+
if (level === "ask" && !answered.has(request)) {
|
|
1149
|
+
throw new CliError("confirmation_required", `${key} asks before it acts, and it was not asked`);
|
|
1150
|
+
}
|
|
1151
|
+
}
|
|
1152
|
+
const allowed = recipients.read();
|
|
1153
|
+
if (chatId !== null && allowed && !allowed.some((chat) => chat.id === chatId)) {
|
|
1154
|
+
throw new CliError("confirmation_required", `chat ${chatId} is not on the recipient list of profile ${profile} \u2014 the owner adds it with \`${command} ${profile} recipients add ${chatId}\``, { chat_id: chatId });
|
|
1155
|
+
}
|
|
1156
|
+
const strangers = allowed ? (personIds ?? []).filter((id2) => !allowed.some((chat) => chat.partnerId === id2)) : [];
|
|
1157
|
+
if (strangers.length > 0) {
|
|
1158
|
+
throw new CliError("confirmation_required", `${strangers.join(", ")} ${strangers.length === 1 ? "is" : "are"} not on the recipient list of profile ${profile} \u2014 the owner adds the one-to-one chat with each person (\`${command} ${profile} recipients add <chat>\`); a chat added to the list earlier is added again to be recognised`, { person_ids: strangers });
|
|
1159
|
+
}
|
|
1160
|
+
}, "permitted");
|
|
1161
|
+
const withinLimit = /* @__PURE__ */ __name((request, entries) => {
|
|
1162
|
+
const { chatId, sendId } = request;
|
|
1163
|
+
const asked = { ...request, people: request.personIds?.length ?? request.count };
|
|
1164
|
+
const count2 = weightOf(asked);
|
|
1165
|
+
if (count2 > sendsPerHour) {
|
|
1166
|
+
throw new CliError("rate_limited", `${count2} at once is more than the hourly limit of profile ${profile} (sendsPerHour ${sendsPerHour}) \u2014 do fewer at a time`);
|
|
1167
|
+
}
|
|
1168
|
+
const at = request.scheduledFor ? Date.parse(request.scheduledFor) : now().getTime();
|
|
1169
|
+
if (Number.isNaN(at))
|
|
1170
|
+
throw new CliError("validation_error", `"${request.scheduledFor}" is not a time to send at \u2014 use ISO 8601`);
|
|
1171
|
+
const counted = entries.filter(countsTowardLimit).filter((entry) => entry.outcome === "sent" || entry.outcome === "outcome_unknown" || entry.outcome === "reserved").filter((entry) => Math.abs(timeOf(entry) - at) < HOUR_MS);
|
|
1172
|
+
const unsure = /* @__PURE__ */ __name((entry) => entry.outcome === "outcome_unknown", "unsure");
|
|
1173
|
+
const same = /* @__PURE__ */ __name((a, b) => a.sendId !== void 0 && a.sendId === b.sendId && a.chatId === b.chatId, "same");
|
|
1174
|
+
const last = [...counted].reverse().find((entry) => same(entry, { chatId, sendId }));
|
|
1175
|
+
if (sendId !== void 0 && last && unsure(last)) {
|
|
1176
|
+
if (last.sendAs !== request.sendAs) {
|
|
1177
|
+
throw new CliError("validation_error", "this send id was tried under another identity; repeat it with the same --send-as, or it may post twice", { operation_id: sendId, retryable: false });
|
|
1178
|
+
}
|
|
1179
|
+
return false;
|
|
1180
|
+
}
|
|
1181
|
+
const recent = counted.filter((entry, index) => !(unsure(entry) && counted.slice(index + 1).some((later) => same(later, entry)))).map((entry) => ({ time: timeOf(entry), weight: weightOf(entry) })).sort((a, b) => a.time - b.time);
|
|
1182
|
+
const used = recent.reduce((sum, { weight }) => sum + weight, 0);
|
|
1183
|
+
if (used + count2 > sendsPerHour) {
|
|
1184
|
+
let freed = 0;
|
|
1185
|
+
const opening = recent.find(({ weight }) => {
|
|
1186
|
+
freed += weight;
|
|
1187
|
+
return used - freed + count2 <= sendsPerHour;
|
|
1188
|
+
});
|
|
1189
|
+
const nextMs = (opening?.time ?? 0) + HOUR_MS;
|
|
1190
|
+
const next = new Date(nextMs).toISOString();
|
|
1191
|
+
throw new CliError("rate_limited", `profile ${profile} has sent ${used} messages in the hour around ${new Date(at).toISOString()}, and its limit is ${sendsPerHour} (sendsPerHour) \u2014 the next send is possible at ${next}`, { retry_after_ms: nextMs - now().getTime(), retry_at: next });
|
|
1192
|
+
}
|
|
1193
|
+
return true;
|
|
1194
|
+
}, "withinLimit");
|
|
1195
|
+
const counting = /* @__PURE__ */ __name((request) => {
|
|
1196
|
+
permitted(request);
|
|
1197
|
+
refuseHeld(request);
|
|
1198
|
+
const asked = { ...request, people: request.personIds?.length ?? request.count };
|
|
1199
|
+
const creatingTopic = request.kind === "chat" && request.action === "topic-create";
|
|
1200
|
+
if (!countsTowardLimit(asked) && !creatingTopic)
|
|
1201
|
+
return void 0;
|
|
1202
|
+
const checked = /* @__PURE__ */ __name((entries) => {
|
|
1203
|
+
if (!creatingTopic)
|
|
1204
|
+
return withinLimit(request, entries);
|
|
1205
|
+
if (request.sendId === void 0)
|
|
1206
|
+
throw new CliError("validation_error", "a topic creation needs an attempt id");
|
|
1207
|
+
if (entries.some((entry) => entry.action === "topic-create" && entry.sendId === request.sendId && ["sent", "outcome_unknown", "reserved"].includes(entry.outcome))) {
|
|
1208
|
+
throw new CliError("validation_error", "this topic creation was already attempted; check topics list and do not repeat an unknown creation", { operation_id: request.sendId, retryable: false });
|
|
1209
|
+
}
|
|
1210
|
+
return true;
|
|
1211
|
+
}, "checked");
|
|
1212
|
+
const reserving = /* @__PURE__ */ __name(() => {
|
|
1213
|
+
if (!checked(journal.entries()))
|
|
1214
|
+
return;
|
|
1215
|
+
const id2 = randomUUID();
|
|
1216
|
+
const { chatId, kind, action, sendId, operationId, scheduledFor, notify } = request;
|
|
1217
|
+
journal.append({
|
|
1218
|
+
at: now().toISOString(),
|
|
1219
|
+
profile,
|
|
1220
|
+
chatId,
|
|
1221
|
+
outcome: "reserved",
|
|
1222
|
+
reservation: id2,
|
|
1223
|
+
...kind ? { kind } : {},
|
|
1224
|
+
...action ? { action } : {},
|
|
1225
|
+
...asked.people === void 0 ? {} : kind === "delete" || kind === "message" || kind === void 0 ? { count: asked.people } : { people: asked.people },
|
|
1226
|
+
...sendId === void 0 ? {} : { sendId },
|
|
1227
|
+
...operationId === void 0 ? {} : { operationId },
|
|
1228
|
+
...scheduledFor ? { scheduledFor } : {},
|
|
1229
|
+
...notify === void 0 ? {} : { notify }
|
|
1230
|
+
});
|
|
1231
|
+
reservation = id2;
|
|
1232
|
+
}, "reserving");
|
|
1233
|
+
return { checked, reserving };
|
|
1234
|
+
}, "counting");
|
|
1235
|
+
return {
|
|
1236
|
+
ask: /* @__PURE__ */ __name(async (request) => {
|
|
1237
|
+
refuseReadOnly(request);
|
|
1238
|
+
const levels = currentPermissions();
|
|
1239
|
+
if (levels === void 0)
|
|
1240
|
+
return;
|
|
1241
|
+
const key = request.key ?? keyForWrite(request.kind ?? "message", request.action);
|
|
1242
|
+
if (levelFor(levels, key, permissionDefaults).level !== "ask")
|
|
1243
|
+
return;
|
|
1244
|
+
refuseHeld(request);
|
|
1245
|
+
await ask(key, request);
|
|
1246
|
+
answered.add(request);
|
|
1247
|
+
}, "ask"),
|
|
1248
|
+
check: /* @__PURE__ */ __name((request, { reserve = true } = {}) => {
|
|
1249
|
+
const counted = counting(request);
|
|
1250
|
+
if (!counted)
|
|
1251
|
+
return;
|
|
1252
|
+
if (reserve)
|
|
1253
|
+
journal.locked(counted.reserving);
|
|
1254
|
+
else
|
|
1255
|
+
counted.checked(journal.entries());
|
|
1256
|
+
}, "check"),
|
|
1257
|
+
reserve: /* @__PURE__ */ __name(async (request) => {
|
|
1258
|
+
const counted = counting(request);
|
|
1259
|
+
if (counted)
|
|
1260
|
+
await journal.lockedAsync(counted.reserving);
|
|
1261
|
+
}, "reserve"),
|
|
1262
|
+
// After a send, a failure to write here must not become the command's answer: the message is
|
|
1263
|
+
// already with a person, and an error would invite the caller to send it again.
|
|
1264
|
+
record: /* @__PURE__ */ __name((entry) => {
|
|
1265
|
+
const { personIds: _, ...kept2 } = entry;
|
|
1266
|
+
const settles = entry.outcome === "refused" ? void 0 : reservation;
|
|
1267
|
+
reservation = void 0;
|
|
1268
|
+
try {
|
|
1269
|
+
journal.append({ at: now().toISOString(), profile, ...kept2, ...settles ? { reservation: settles } : {} });
|
|
1270
|
+
} catch (error) {
|
|
1271
|
+
warn(`this send is not in the send journal: ${journalFailure(error)}`, {
|
|
1272
|
+
event: "warning",
|
|
1273
|
+
code: "send_not_journaled",
|
|
1274
|
+
operation: "sends.journal"
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
}, "record")
|
|
1278
|
+
};
|
|
1279
|
+
}, "sendGuard");
|
|
1280
|
+
var refuseToAsk = /* @__PURE__ */ __name(async (key) => {
|
|
1281
|
+
throw new CliError("confirmation_required", `${key} asks before it acts (its permission level is ask), and nobody is here to answer \u2014 add ${skipFlagFor(key)} to go ahead`);
|
|
1282
|
+
}, "refuseToAsk");
|
|
1283
|
+
var guardFor = /* @__PURE__ */ __name((app, settings, warn, env = process.env, ask) => sendGuard({
|
|
1284
|
+
profile: settings.profile,
|
|
1285
|
+
command: app.command,
|
|
1286
|
+
...settings.readOnlyLock ? { readOnlyLock: settings.readOnlyLock } : {},
|
|
1287
|
+
permissions: /* @__PURE__ */ __name(() => settings.permissions, "permissions"),
|
|
1288
|
+
permissionSources: settings.permissionSources,
|
|
1289
|
+
...settings.permissionDefaults ? { permissionDefaults: settings.permissionDefaults } : {},
|
|
1290
|
+
...ask ? { ask } : {},
|
|
1291
|
+
sendsPerHour: settings.sendsPerHour,
|
|
1292
|
+
journal: new SendJournal(sendsPathFor(app, settings.profile, env), { service: app.command, version: app.version }),
|
|
1293
|
+
recipients: new RecipientList(recipientsPathFor(app, settings.profile, env), app.command),
|
|
1294
|
+
flood: new FloodMemory(floodPathFor(app, settings.profile, env)),
|
|
1295
|
+
warn
|
|
1296
|
+
}), "guardFor");
|
|
1297
|
+
var journalFailure = /* @__PURE__ */ __name((error) => error?.code ?? (error instanceof Error ? error.name : "error"), "journalFailure");
|
|
1298
|
+
|
|
1299
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/keyed-guard.js
|
|
1300
|
+
var keyedGuard = /* @__PURE__ */ __name((build, ask, levelOf, extra) => {
|
|
1301
|
+
let question;
|
|
1302
|
+
let answered = false;
|
|
1303
|
+
const guard = build(async (key, request) => {
|
|
1304
|
+
if (answered)
|
|
1305
|
+
return;
|
|
1306
|
+
await ask(question || key, request);
|
|
1307
|
+
answered = true;
|
|
1308
|
+
});
|
|
1309
|
+
const probes = /* @__PURE__ */ new WeakMap();
|
|
1310
|
+
const all = /* @__PURE__ */ __name((request) => {
|
|
1311
|
+
let found = probes.get(request);
|
|
1312
|
+
if (!found) {
|
|
1313
|
+
found = extra.map((key) => ({ chatId: null, kind: "read", key }));
|
|
1314
|
+
probes.set(request, found);
|
|
1315
|
+
}
|
|
1316
|
+
return [request, ...found];
|
|
1317
|
+
}, "all");
|
|
1318
|
+
const levelOfRequest = /* @__PURE__ */ __name(({ key }) => levelOf(key ?? ""), "levelOfRequest");
|
|
1319
|
+
const refuse = /* @__PURE__ */ __name((request) => {
|
|
1320
|
+
const refused = all(request).find((one) => stops(levelOfRequest(one), one.key ?? ""));
|
|
1321
|
+
if (refused)
|
|
1322
|
+
guard.check(refused, { reserve: false });
|
|
1323
|
+
}, "refuse");
|
|
1324
|
+
return {
|
|
1325
|
+
refuse,
|
|
1326
|
+
ask: /* @__PURE__ */ __name(async (request) => {
|
|
1327
|
+
refuse(request);
|
|
1328
|
+
question = all(request).filter((one) => levelOfRequest(one) === "ask").map(({ key }) => key).join(" and ");
|
|
1329
|
+
for (const one of all(request))
|
|
1330
|
+
await guard.ask?.(one);
|
|
1331
|
+
}, "ask"),
|
|
1332
|
+
check: /* @__PURE__ */ __name((request, options) => {
|
|
1333
|
+
for (const one of all(request).slice(1))
|
|
1334
|
+
guard.check(one, { reserve: false });
|
|
1335
|
+
guard.check(request, options);
|
|
1336
|
+
}, "check"),
|
|
1337
|
+
...guard.reserve ? { reserve: guard.reserve } : {},
|
|
1338
|
+
record: /* @__PURE__ */ __name((entry) => guard.record(entry), "record")
|
|
1339
|
+
};
|
|
1340
|
+
}, "keyedGuard");
|
|
1341
|
+
|
|
1342
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/send-id.js
|
|
1343
|
+
import { randomBytes } from "node:crypto";
|
|
1344
|
+
var newSendId = /* @__PURE__ */ __name(() => randomBytes(8).readBigInt64BE().toString(), "newSendId");
|
|
1345
|
+
var newOperationId = newSendId;
|
|
1346
|
+
|
|
1347
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/foreign-contacts.js
|
|
1348
|
+
import { readFileSync as readFileSync4 } from "node:fs";
|
|
1349
|
+
import { join as join4 } from "node:path";
|
|
1350
|
+
var DAILY_FOREIGN_CONTACTS = 100;
|
|
1351
|
+
var foreignContactsPathFor = /* @__PURE__ */ __name((app, account, env = process.env, user) => join4(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "crm", "foreign-contacts", `${[account.provider, account.account, ...user ? [user] : []].join("-").replace(/[^\w.-]+/gu, "_")}.json`), "foreignContactsPathFor");
|
|
1352
|
+
var shownIn = /* @__PURE__ */ __name((file, day) => {
|
|
1353
|
+
try {
|
|
1354
|
+
const found = JSON.parse(readFileSync4(file, "utf8"));
|
|
1355
|
+
return found.day === day && Array.isArray(found.seen) ? { day, seen: found.seen.map(String) } : { day, seen: [] };
|
|
1356
|
+
} catch {
|
|
1357
|
+
return { day, seen: [] };
|
|
1358
|
+
}
|
|
1359
|
+
}, "shownIn");
|
|
1360
|
+
var stripped = /* @__PURE__ */ __name((record, fields) => {
|
|
1361
|
+
const { phones, emails, email, phone, contactTypes: _types, ...rest } = record;
|
|
1362
|
+
const own = new Set([...phones ?? [], ...emails ?? [], email, phone].filter((one) => !!one));
|
|
1363
|
+
const holding2 = new Set(fields.filter((field) => field.holds).map((field) => field.code));
|
|
1364
|
+
const repeats = /* @__PURE__ */ __name((value) => (Array.isArray(value) ? value : [value]).some((one) => typeof one === "string" && own.has(one.trim())), "repeats");
|
|
1365
|
+
const metadata = rest.metadata;
|
|
1366
|
+
if (metadata)
|
|
1367
|
+
rest.metadata = fields.length ? Object.fromEntries(Object.entries(metadata).filter(([code, one]) => !holding2.has(code) && !repeats(one.value))) : {};
|
|
1368
|
+
return rest;
|
|
1369
|
+
}, "stripped");
|
|
1370
|
+
var foreignContacts = /* @__PURE__ */ __name((source, file, options = {}) => {
|
|
1371
|
+
let admin;
|
|
1372
|
+
const definitions = {};
|
|
1373
|
+
const limited = /* @__PURE__ */ __name(async () => {
|
|
1374
|
+
if (!source.isAdmin)
|
|
1375
|
+
return false;
|
|
1376
|
+
admin ??= source.isAdmin();
|
|
1377
|
+
return !await admin;
|
|
1378
|
+
}, "limited");
|
|
1379
|
+
const own = /* @__PURE__ */ __name(async (kind, records) => {
|
|
1380
|
+
const self = source.self ? String(await source.self()) : void 0;
|
|
1381
|
+
const mine = new Set(records.filter((one) => self && one.assignee === self).map((one) => one.externalId));
|
|
1382
|
+
const rest = records.filter((one) => !mine.has(one.externalId)).map((one) => one.externalId);
|
|
1383
|
+
if (rest.length && source.ownClients && (kind === "person" || kind === "organization"))
|
|
1384
|
+
for (const id2 of await source.ownClients(kind, rest))
|
|
1385
|
+
mine.add(id2);
|
|
1386
|
+
return mine;
|
|
1387
|
+
}, "own");
|
|
1388
|
+
return {
|
|
1389
|
+
async strip(kind, records) {
|
|
1390
|
+
if (!await limited() || records.length === 0)
|
|
1391
|
+
return records;
|
|
1392
|
+
const mine = await own(kind, records);
|
|
1393
|
+
if (records.every((one) => mine.has(one.externalId)))
|
|
1394
|
+
return records;
|
|
1395
|
+
definitions[kind] ??= Promise.resolve(source.fields?.(kind)).then((found) => found ?? []);
|
|
1396
|
+
const fields = await definitions[kind];
|
|
1397
|
+
return records.map((one) => mine.has(one.externalId) ? one : stripped(one, fields));
|
|
1398
|
+
},
|
|
1399
|
+
async own(kind, record) {
|
|
1400
|
+
return !await limited() || (await own(kind, [record])).has(record.externalId);
|
|
1401
|
+
},
|
|
1402
|
+
async spend(kind, record) {
|
|
1403
|
+
if (!await limited() || (await own(kind, [record])).has(record.externalId))
|
|
1404
|
+
return;
|
|
1405
|
+
const key = `${kind}:${record.externalId}`;
|
|
1406
|
+
if (!file)
|
|
1407
|
+
throw new Error("foreignContacts: spend needs the count file");
|
|
1408
|
+
const path = await file();
|
|
1409
|
+
const day = new Date(options.now?.() ?? Date.now()).toISOString().slice(0, 10);
|
|
1410
|
+
await withFileLockAsync(path, "the day's count of foreign contacts", () => {
|
|
1411
|
+
const shown = shownIn(path, day);
|
|
1412
|
+
if (shown.seen.includes(key))
|
|
1413
|
+
return;
|
|
1414
|
+
if (shown.seen.length >= DAILY_FOREIGN_CONTACTS)
|
|
1415
|
+
throw new CliError("permission_error", `${DAILY_FOREIGN_CONTACTS} records that are not yours (contacts, companies, or the files of deals, leads, contacts and companies) were read today, the most a day; your own records are not counted, and the CRM's administrator has no limit`, { reason: "crm.foreign-contacts-spent", limit: DAILY_FOREIGN_CONTACTS });
|
|
1416
|
+
writeSecurely(path, JSON.stringify({ day, seen: [...shown.seen, key] }), 384);
|
|
1417
|
+
}, options.lockWaitMs);
|
|
1418
|
+
}
|
|
1419
|
+
};
|
|
1420
|
+
}, "foreignContacts");
|
|
1421
|
+
var refuseForeignClientReads = /* @__PURE__ */ __name(async (source, readsClients, method) => {
|
|
1422
|
+
if (!readsClients || !source.isAdmin || await source.isAdmin())
|
|
1423
|
+
return;
|
|
1424
|
+
throw new CliError("permission_error", `${method} reads contacts or companies, which only the CRM's administrator reads through api call: your clients come with sync, and another one with people show or organizations show, ${DAILY_FOREIGN_CONTACTS} a day`, { reason: "crm.client-reads-admin-only", sent: false });
|
|
1425
|
+
}, "refuseForeignClientReads");
|
|
1426
|
+
|
|
1427
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/writer.js
|
|
1428
|
+
var CRM_ASSIGN_OTHERS_KEY = "crm.assign-others";
|
|
1429
|
+
var CRM_WRITE_KEYS = [CRM_ASSIGN_OTHERS_KEY];
|
|
1430
|
+
var PLURALS = {
|
|
1431
|
+
deals: "deal",
|
|
1432
|
+
leads: "lead",
|
|
1433
|
+
people: "person",
|
|
1434
|
+
organizations: "organization"
|
|
1435
|
+
};
|
|
1436
|
+
var VERB_OF = {
|
|
1437
|
+
create: "create",
|
|
1438
|
+
update: "update",
|
|
1439
|
+
move: "move",
|
|
1440
|
+
close: "close",
|
|
1441
|
+
delete: "remove"
|
|
1442
|
+
};
|
|
1443
|
+
var crmAlsoChecks = /* @__PURE__ */ __name((also) => (path) => {
|
|
1444
|
+
const [noun, command] = path;
|
|
1445
|
+
const kind = noun === void 0 ? void 0 : PLURALS[noun];
|
|
1446
|
+
const verb = command === void 0 ? void 0 : VERB_OF[command];
|
|
1447
|
+
if (path.length !== 2 || kind === void 0 || verb === void 0)
|
|
1448
|
+
return [];
|
|
1449
|
+
const close = { key: `${noun}.close`, when: "a won or lost stage" };
|
|
1450
|
+
const assign = { key: CRM_ASSIGN_OTHERS_KEY, when: "--owner other than the sign-in's user" };
|
|
1451
|
+
const implied = kind === "person" || kind === "organization" ? verb === "create" || verb === "update" ? [assign] : [] : verb === "create" || verb === "update" ? [{ key: `${noun}.move`, when: "--stage" }, close, assign] : verb === "move" ? [close] : [];
|
|
1452
|
+
return [...implied, ...also?.(kind, verb) ?? []];
|
|
1453
|
+
}, "crmAlsoChecks");
|
|
1454
|
+
var CRM_WRITE_DEFAULTS = {
|
|
1455
|
+
"deals.delete": "ask",
|
|
1456
|
+
"leads.delete": "ask",
|
|
1457
|
+
[CRM_ASSIGN_OTHERS_KEY]: "deny"
|
|
1458
|
+
};
|
|
1459
|
+
|
|
1460
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/writes.js
|
|
1461
|
+
var moneyChecked = /* @__PURE__ */ __name((check, param) => {
|
|
1462
|
+
try {
|
|
1463
|
+
check();
|
|
1464
|
+
} catch (error) {
|
|
1465
|
+
if (isCliError(error))
|
|
1466
|
+
throw new CliError(error.code, error.message, { ...error.details, param });
|
|
1467
|
+
throw error;
|
|
1468
|
+
}
|
|
1469
|
+
}, "moneyChecked");
|
|
1470
|
+
var PLURAL = {
|
|
1471
|
+
deal: "deals",
|
|
1472
|
+
lead: "leads",
|
|
1473
|
+
person: "people",
|
|
1474
|
+
organization: "organizations"
|
|
1475
|
+
};
|
|
1476
|
+
var COMMAND = {
|
|
1477
|
+
create: "create",
|
|
1478
|
+
update: "update",
|
|
1479
|
+
move: "move",
|
|
1480
|
+
close: "close",
|
|
1481
|
+
remove: "delete"
|
|
1482
|
+
};
|
|
1483
|
+
var keyOf2 = /* @__PURE__ */ __name((kind, verb) => `${PLURAL[kind]}.${COMMAND[verb]}`, "keyOf");
|
|
1484
|
+
var OPERATION_ID = /^[\x21-\x7e]{1,255}$/u;
|
|
1485
|
+
var DECIMAL = /^\d{1,16}(\.\d{1,6})?$/u;
|
|
1486
|
+
var CURRENCY = /^[A-Z]{3}$/u;
|
|
1487
|
+
var DAY = /^\d{4}-\d{2}-\d{2}$/u;
|
|
1488
|
+
var FIELD_CODE = /^[A-Za-z][\w.-]{0,99}$/u;
|
|
1489
|
+
var invalid = /* @__PURE__ */ __name((message, param) => new CliError("validation_error", message, { reason: "deal.field", ...param ? { param } : {} }), "invalid");
|
|
1490
|
+
var supported = /* @__PURE__ */ __name((writer, kind, verb) => {
|
|
1491
|
+
const { kinds, verbs } = writer.capabilities;
|
|
1492
|
+
if (!kinds.includes(kind) || !verbs.includes(verb))
|
|
1493
|
+
throw new CliError("validation_error", `this CRM does not take a ${COMMAND[verb]} of ${PLURAL[kind]}`, {
|
|
1494
|
+
reason: "crm.write-unsupported",
|
|
1495
|
+
sent: false
|
|
1496
|
+
});
|
|
1497
|
+
}, "supported");
|
|
1498
|
+
var operationOf = /* @__PURE__ */ __name((context, given) => {
|
|
1499
|
+
if (given === void 0)
|
|
1500
|
+
return newOperationId();
|
|
1501
|
+
const name = context.names?.id ?? "--operation-id";
|
|
1502
|
+
if (!context.writes.writer.capabilities.idempotent)
|
|
1503
|
+
throw new CliError("validation_error", `this CRM does not recognise a repeated write, so ${name} would do it a second time; sync and look before writing again`, { reason: "crm.write-unsupported", param: name, sent: false });
|
|
1504
|
+
if (!OPERATION_ID.test(given))
|
|
1505
|
+
throw new CliError("validation_error", `${name} takes 1 to 255 printable characters with no spaces`, {
|
|
1506
|
+
param: name
|
|
1507
|
+
});
|
|
1508
|
+
return given;
|
|
1509
|
+
}, "operationOf");
|
|
1510
|
+
var copyOf = /* @__PURE__ */ __name(async (context, kind, reference) => {
|
|
1511
|
+
if (!reference.startsWith(`${kind}:`))
|
|
1512
|
+
throw new CliError("validation_error", `name the ${kind} as ${kind}:<id>, as a list shows it`, {
|
|
1513
|
+
reason: "ref.malformed"
|
|
1514
|
+
});
|
|
1515
|
+
const found = await context.store.deals.get(reference);
|
|
1516
|
+
const { provider, account } = context.account;
|
|
1517
|
+
if (found.account?.provider !== provider || found.account.account !== account || found.externalId === null)
|
|
1518
|
+
throw new CliError("not_found", `${reference} is not a copy from this profile's CRM account`);
|
|
1519
|
+
return found;
|
|
1520
|
+
}, "copyOf");
|
|
1521
|
+
var pipelineOf = /* @__PURE__ */ __name(async (context, kind, reference, param = "--pipeline", window = {}) => {
|
|
1522
|
+
const scope = { ...window, ...kind ? { kind } : {}, account: context.account };
|
|
1523
|
+
if (reference !== void 0) {
|
|
1524
|
+
const found = await context.store.deals.pipeline(reference, scope);
|
|
1525
|
+
if (found.externalId === null)
|
|
1526
|
+
throw new CliError("not_found", `${reference} is not a pipeline of this CRM account`);
|
|
1527
|
+
return found;
|
|
1528
|
+
}
|
|
1529
|
+
const all = await context.store.deals.pipelines(scope);
|
|
1530
|
+
if (all.length === 1)
|
|
1531
|
+
return context.store.deals.pipeline(all[0].ref, scope);
|
|
1532
|
+
const what = kind ? `${kind} pipeline` : "pipeline";
|
|
1533
|
+
throw new CliError("validation_error", all.length === 0 ? `no ${what} of this CRM is stored; run sync first` : `this CRM has ${all.length} ${what}s; name one${param.startsWith("--") ? ` with ${param}` : ""}: ` + all.map(({ name, ref }) => `${name} (${ref})`).join(", "), { reason: "crm.pipeline-required", param, allowed: all.map(({ ref }) => ref) });
|
|
1534
|
+
}, "pipelineOf");
|
|
1535
|
+
var stageOf = /* @__PURE__ */ __name((pipeline, given) => {
|
|
1536
|
+
const byId = pipeline.stages.find((stage) => stage.externalId === given);
|
|
1537
|
+
if (byId)
|
|
1538
|
+
return byId;
|
|
1539
|
+
const folded = given.trim().toLocaleLowerCase();
|
|
1540
|
+
const named2 = pipeline.stages.filter((stage) => stage.name.toLocaleLowerCase() === folded);
|
|
1541
|
+
if (named2.length === 1)
|
|
1542
|
+
return named2[0];
|
|
1543
|
+
throw new CliError("validation_error", `${pipeline.name} has ${named2.length ? "more than one" : "no"} stage ${given}: ` + pipeline.stages.map(({ name }) => name).join(", "), { reason: "deal.stage", param: "--stage" });
|
|
1544
|
+
}, "stageOf");
|
|
1545
|
+
var validDay = /* @__PURE__ */ __name((text2) => {
|
|
1546
|
+
const date = /* @__PURE__ */ new Date(`${text2}T00:00:00Z`);
|
|
1547
|
+
return DAY.test(text2) && !Number.isNaN(date.getTime()) && date.toISOString().startsWith(text2);
|
|
1548
|
+
}, "validDay");
|
|
1549
|
+
var fieldsOf = /* @__PURE__ */ __name((input, pipeline, currency) => {
|
|
1550
|
+
const fields = {};
|
|
1551
|
+
if (input.title !== void 0) {
|
|
1552
|
+
if (!input.title.trim())
|
|
1553
|
+
throw invalid("a title is never empty", "--title");
|
|
1554
|
+
fields.title = input.title.trim();
|
|
1555
|
+
}
|
|
1556
|
+
if (pipeline && input.pipeline !== void 0)
|
|
1557
|
+
fields.pipeline = pipeline.externalId;
|
|
1558
|
+
const stage = pipeline && input.stage !== void 0 ? stageOf(pipeline, input.stage) : void 0;
|
|
1559
|
+
if (stage)
|
|
1560
|
+
fields.stage = stage.externalId;
|
|
1561
|
+
if (input.amount !== void 0 || input.currency !== void 0) {
|
|
1562
|
+
const code = (input.currency ?? currency ?? "").toUpperCase();
|
|
1563
|
+
if (input.amount === void 0)
|
|
1564
|
+
throw invalid("--currency goes with --amount", "--amount");
|
|
1565
|
+
if (!DECIMAL.test(input.amount))
|
|
1566
|
+
throw invalid("--amount is a decimal such as 1500.50", "--amount");
|
|
1567
|
+
if (!CURRENCY.test(code))
|
|
1568
|
+
throw invalid("--amount needs --currency, an ISO 4217 code such as EUR", "--currency");
|
|
1569
|
+
moneyChecked(() => currencyOf(code), "--currency");
|
|
1570
|
+
moneyChecked(() => minorUnits(input.amount, code, "--amount"), "--amount");
|
|
1571
|
+
fields.amount = input.amount;
|
|
1572
|
+
fields.currency = code;
|
|
1573
|
+
}
|
|
1574
|
+
if (input.closeDate !== void 0) {
|
|
1575
|
+
if (!validDay(input.closeDate))
|
|
1576
|
+
throw invalid("--close-date is a day, YYYY-MM-DD", "--close-date");
|
|
1577
|
+
fields.closeDate = input.closeDate;
|
|
1578
|
+
}
|
|
1579
|
+
if (input.owner !== void 0) {
|
|
1580
|
+
if (!input.owner.trim())
|
|
1581
|
+
throw invalid("--owner is the CRM user's id", "--owner");
|
|
1582
|
+
fields.owner = input.owner.trim();
|
|
1583
|
+
}
|
|
1584
|
+
return { fields, stage };
|
|
1585
|
+
}, "fieldsOf");
|
|
1586
|
+
var foldFieldName = /* @__PURE__ */ __name((name) => foldName(name.trim()).replace(/[\s_]+/gu, " "), "foldFieldName");
|
|
1587
|
+
var named = /* @__PURE__ */ __name(({ code, label }) => ({ code, label }), "named");
|
|
1588
|
+
var unknownField = /* @__PURE__ */ __name((fields, name, param = "--field") => {
|
|
1589
|
+
const want = foldFieldName(name);
|
|
1590
|
+
const close = fields.filter((field) => [field.code, field.label ?? ""].some((one) => {
|
|
1591
|
+
const other = foldFieldName(one);
|
|
1592
|
+
return other !== "" && (other.includes(want) || want.includes(other));
|
|
1593
|
+
}));
|
|
1594
|
+
return new CliError("validation_error", `no custom field is named ${name}${close.length ? "; close ones are in candidates" : ""} \u2014 \`fields list\` lists them`, { reason: "field.unknown", param, candidates: close.map(named) });
|
|
1595
|
+
}, "unknownField");
|
|
1596
|
+
var fieldNamed = /* @__PURE__ */ __name((fields, name, param = "--field") => {
|
|
1597
|
+
const want = foldFieldName(name);
|
|
1598
|
+
const byCode = fields.find((field) => foldFieldName(field.code) === want);
|
|
1599
|
+
if (byCode)
|
|
1600
|
+
return byCode;
|
|
1601
|
+
const labelled = fields.filter((field) => field.label !== null && foldFieldName(field.label) === want);
|
|
1602
|
+
if (labelled.length === 1)
|
|
1603
|
+
return labelled[0];
|
|
1604
|
+
if (labelled.length > 1)
|
|
1605
|
+
throw new CliError("validation_error", `${labelled.length} custom fields are labelled ${name}; name one by its code`, {
|
|
1606
|
+
reason: "field.ambiguous",
|
|
1607
|
+
param,
|
|
1608
|
+
candidates: labelled.map(named)
|
|
1609
|
+
});
|
|
1610
|
+
throw unknownField(fields, name, param);
|
|
1611
|
+
}, "fieldNamed");
|
|
1612
|
+
var optionOf = /* @__PURE__ */ __name((field, value, param = "--field") => {
|
|
1613
|
+
if (!field.options)
|
|
1614
|
+
return value;
|
|
1615
|
+
const want = foldFieldName(value);
|
|
1616
|
+
const byId = field.options.find((option) => option.id === value.trim());
|
|
1617
|
+
const named2 = byId ? [] : field.options.filter((option) => foldFieldName(option.label) === want);
|
|
1618
|
+
if (named2.length > 1)
|
|
1619
|
+
throw new CliError("validation_error", `${field.label ?? field.code} has ${named2.length} options named ${value}; name one by its id`, {
|
|
1620
|
+
reason: "field.ambiguous-option",
|
|
1621
|
+
param,
|
|
1622
|
+
field: field.code,
|
|
1623
|
+
candidates: named2
|
|
1624
|
+
});
|
|
1625
|
+
const found = byId ?? named2[0];
|
|
1626
|
+
if (!found)
|
|
1627
|
+
throw new CliError("validation_error", `${field.label ?? field.code} has no option ${value}`, {
|
|
1628
|
+
reason: "field.unknown-option",
|
|
1629
|
+
param,
|
|
1630
|
+
field: field.code,
|
|
1631
|
+
allowed: field.options
|
|
1632
|
+
});
|
|
1633
|
+
return found.id;
|
|
1634
|
+
}, "optionOf");
|
|
1635
|
+
var fieldPairsOf = /* @__PURE__ */ __name((typed) => typed.map((one) => {
|
|
1636
|
+
const at = one.indexOf("=");
|
|
1637
|
+
if (at <= 0 || one.slice(0, at).trim() === "")
|
|
1638
|
+
throw new CliError("validation_error", `--field takes <key>=<value>; got ${one}`, { param: "--field" });
|
|
1639
|
+
return [one.slice(0, at), one.slice(at + 1)];
|
|
1640
|
+
}), "fieldPairsOf");
|
|
1641
|
+
var crmCustomValues = /* @__PURE__ */ __name((fields, pairs) => {
|
|
1642
|
+
const values = /* @__PURE__ */ new Map();
|
|
1643
|
+
for (const [name, value] of pairs) {
|
|
1644
|
+
const field = fields.length ? fieldNamed(fields, name) : null;
|
|
1645
|
+
const code = field?.code ?? name.trim();
|
|
1646
|
+
if (!field && !FIELD_CODE.test(code))
|
|
1647
|
+
throw invalid(`${name} is not a field code`, "--field");
|
|
1648
|
+
const held = values.get(code) ?? { field, all: [] };
|
|
1649
|
+
held.all.push(value === "" ? null : field ? optionOf(field, value) : value);
|
|
1650
|
+
values.set(code, held);
|
|
1651
|
+
}
|
|
1652
|
+
return Object.fromEntries([...values].map(([code, { field, all }]) => {
|
|
1653
|
+
const given = all.filter((one) => one !== null);
|
|
1654
|
+
if (field?.multiple)
|
|
1655
|
+
return [code, given.length ? given : null];
|
|
1656
|
+
if (all.length > 1)
|
|
1657
|
+
throw new CliError("validation_error", `${field?.label ?? code} holds one value; give --field once`, {
|
|
1658
|
+
reason: "deal.field",
|
|
1659
|
+
param: "--field",
|
|
1660
|
+
field: code
|
|
1661
|
+
});
|
|
1662
|
+
return [code, all[0] ?? null];
|
|
1663
|
+
}));
|
|
1664
|
+
}, "crmCustomValues");
|
|
1665
|
+
var customOf = /* @__PURE__ */ __name(async (context, kind, pairs) => pairs?.length ? crmCustomValues(await context.store.crm.fields(context.account, kind), pairs) : void 0, "customOf");
|
|
1666
|
+
var keysOf = /* @__PURE__ */ __name((context, kind, verb, { stage, owner }) => {
|
|
1667
|
+
const extra = [];
|
|
1668
|
+
if (stage && verb !== "move")
|
|
1669
|
+
extra.push(keyOf2(kind, "move"));
|
|
1670
|
+
if (stage && stage.outcome !== "open")
|
|
1671
|
+
extra.push(keyOf2(kind, "close"));
|
|
1672
|
+
if (owner != null && owner !== context.writes.self)
|
|
1673
|
+
extra.push(CRM_ASSIGN_OTHERS_KEY);
|
|
1674
|
+
return { key: keyOf2(kind, verb), extra: [...extra, ...context.writes.alsoChecks?.(kind, verb) ?? []] };
|
|
1675
|
+
}, "keysOf");
|
|
1676
|
+
var guardOf = /* @__PURE__ */ __name((context, extra) => {
|
|
1677
|
+
const settings = context.writes.settings();
|
|
1678
|
+
const defaults = { ...DEFAULT_PERMISSIONS, ...CRM_WRITE_DEFAULTS, ...settings.permissionDefaults };
|
|
1679
|
+
return keyedGuard((ask) => guardFor(context.writes.app, { ...settings, sendsPerHour: Number.MAX_SAFE_INTEGER, permissionDefaults: defaults }, context.writes.warn ?? (() => {
|
|
1680
|
+
}), context.writes.env, ask), context.ask, (key) => levelFor(settings.permissions, key, defaults).level, extra);
|
|
1681
|
+
}, "guardOf");
|
|
1682
|
+
var written = /* @__PURE__ */ __name(async (context, { key, extra }, operationId, act) => {
|
|
1683
|
+
try {
|
|
1684
|
+
const done = await guardedWrite(guardOf(context, extra), { chatId: null, kind: "edit", key, operationId }, async () => {
|
|
1685
|
+
try {
|
|
1686
|
+
return { item: await act(), unread: null };
|
|
1687
|
+
} catch (error) {
|
|
1688
|
+
if (isCliError(error) && error.details.sent === true)
|
|
1689
|
+
return { item: null, unread: error };
|
|
1690
|
+
throw error;
|
|
1691
|
+
}
|
|
1692
|
+
});
|
|
1693
|
+
if (done.unread)
|
|
1694
|
+
throw new CliError(done.unread.code, `${done.unread.message} \u2014 the CRM made the change; sync to store it, do not write it again`, { ...done.unread.details, operation_id: operationId });
|
|
1695
|
+
return done.item;
|
|
1696
|
+
} catch (error) {
|
|
1697
|
+
if (!isCliError(error) || error.code !== "outcome_unknown")
|
|
1698
|
+
throw error;
|
|
1699
|
+
const name = context.names?.id ?? "--operation-id";
|
|
1700
|
+
throw new CliError("outcome_unknown", context.writes.writer.capabilities.idempotent ? `${error.message} \u2014 repeat it with ${name} ${operationId}: the CRM answers a repeat from its record instead of doing it again` : `${error.message} \u2014 sync and look at the CRM before writing again: this CRM would do it a second time`, { ...error.details, operation_id: operationId });
|
|
1701
|
+
}
|
|
1702
|
+
}, "written");
|
|
1703
|
+
var kept = /* @__PURE__ */ __name(async (context, kind, item, operationId) => {
|
|
1704
|
+
const fail = /* @__PURE__ */ __name((why, details = {}) => new CliError("invalid_response", `the CRM wrote ${kind} ${item.externalId}, but the local store did not keep it (${why}); sync to store it \u2014 do not write it again`, { ...details, operation_id: operationId, external_id: item.externalId, sent: true }), "fail");
|
|
1705
|
+
try {
|
|
1706
|
+
let saved = await context.store.crm.saveItems(context.account, kind, [item]);
|
|
1707
|
+
if (saved.skipped[0]?.reason === "crm.stage-unknown" && context.source) {
|
|
1708
|
+
await context.store.crm.savePipelines(context.account, kind, await context.source().pipelines(kind));
|
|
1709
|
+
saved = await context.store.crm.saveItems(context.account, kind, [item]);
|
|
1710
|
+
}
|
|
1711
|
+
const [skipped] = saved.skipped;
|
|
1712
|
+
if (skipped)
|
|
1713
|
+
throw fail(skipped.message, { reason: skipped.reason });
|
|
1714
|
+
const reference = await context.store.crm.refOf(context.account, kind, item.externalId);
|
|
1715
|
+
if (reference === null)
|
|
1716
|
+
throw fail("it is not found after the save");
|
|
1717
|
+
return await context.store.deals.get(reference);
|
|
1718
|
+
} catch (error) {
|
|
1719
|
+
if (isCliError(error) && error.code === "invalid_response" && error.details.sent === true)
|
|
1720
|
+
throw error;
|
|
1721
|
+
throw fail(error instanceof Error ? error.message : String(error), isCliError(error) ? error.details : {});
|
|
1722
|
+
}
|
|
1723
|
+
}, "kept");
|
|
1724
|
+
var createCrmItem = /* @__PURE__ */ __name(async (context, kind, input, options = {}) => {
|
|
1725
|
+
const { writer } = context.writes;
|
|
1726
|
+
supported(writer, kind, "create");
|
|
1727
|
+
if (input.title === void 0)
|
|
1728
|
+
throw invalid(`a new ${kind} needs --title`, "--title");
|
|
1729
|
+
const pipeline = await pipelineOf(context, kind, input.pipeline);
|
|
1730
|
+
const { fields, stage } = fieldsOf({ ...input, pipeline: pipeline.ref }, pipeline, null);
|
|
1731
|
+
const custom = await customOf(context, kind, input.custom);
|
|
1732
|
+
if (custom)
|
|
1733
|
+
fields.custom = custom;
|
|
1734
|
+
const operationId = operationOf(context, options.operationId);
|
|
1735
|
+
const item = await written(context, keysOf(context, kind, "create", { stage, owner: fields.owner }), operationId, () => writer.create(kind, fields, { operationId }));
|
|
1736
|
+
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
1737
|
+
}, "createCrmItem");
|
|
1738
|
+
var updateCrmItem = /* @__PURE__ */ __name(async (context, kind, reference, input, options = {}) => {
|
|
1739
|
+
const { writer } = context.writes;
|
|
1740
|
+
supported(writer, kind, "update");
|
|
1741
|
+
const copy = await copyOf(context, kind, reference);
|
|
1742
|
+
if (input.pipeline !== void 0 && input.stage === void 0)
|
|
1743
|
+
throw invalid("a new --pipeline needs the --stage it goes to there", "--stage");
|
|
1744
|
+
const pipeline = input.stage === void 0 ? void 0 : await pipelineOf(context, kind, input.pipeline === void 0 ? copy.pipeline : input.pipeline);
|
|
1745
|
+
const { fields, stage } = fieldsOf(input, pipeline, copy.currency);
|
|
1746
|
+
const custom = await customOf(context, kind, input.custom);
|
|
1747
|
+
if (custom)
|
|
1748
|
+
fields.custom = custom;
|
|
1749
|
+
if (Object.keys(fields).length === 0)
|
|
1750
|
+
throw invalid("nothing to change: name a field");
|
|
1751
|
+
const operationId = operationOf(context, options.operationId);
|
|
1752
|
+
const item = await written(context, keysOf(context, kind, "update", { stage, owner: fields.owner }), operationId, () => writer.update(kind, copy.externalId, fields, { operationId }));
|
|
1753
|
+
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
1754
|
+
}, "updateCrmItem");
|
|
1755
|
+
var moveCrmItem = /* @__PURE__ */ __name(async (context, kind, reference, stageName, options = {}) => {
|
|
1756
|
+
const { writer } = context.writes;
|
|
1757
|
+
supported(writer, kind, "move");
|
|
1758
|
+
const copy = await copyOf(context, kind, reference);
|
|
1759
|
+
const stage = stageOf(await pipelineOf(context, kind, copy.pipeline), stageName);
|
|
1760
|
+
const operationId = operationOf(context, options.operationId);
|
|
1761
|
+
const item = await written(context, keysOf(context, kind, "move", { stage }), operationId, () => writer.move(kind, copy.externalId, stage.externalId, { operationId }));
|
|
1762
|
+
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
1763
|
+
}, "moveCrmItem");
|
|
1764
|
+
var closeCrmItem = /* @__PURE__ */ __name(async (context, kind, reference, outcome, options = {}) => {
|
|
1765
|
+
const { writer } = context.writes;
|
|
1766
|
+
supported(writer, kind, "close");
|
|
1767
|
+
if (outcome !== "won" && outcome !== "lost")
|
|
1768
|
+
throw invalid("a close is won or lost");
|
|
1769
|
+
const copy = await copyOf(context, kind, reference);
|
|
1770
|
+
const reason = options.reason?.trim();
|
|
1771
|
+
if (reason !== void 0 && (reason === "" || reason.length > 2e3))
|
|
1772
|
+
throw invalid("--reason is 1 to 2000 characters", "--reason");
|
|
1773
|
+
const operationId = operationOf(context, options.operationId);
|
|
1774
|
+
const item = await written(context, keysOf(context, kind, "close", {}), operationId, () => writer.close(kind, copy.externalId, outcome, { operationId, ...reason ? { reason } : {} }));
|
|
1775
|
+
return { operationId, item: await kept(context, kind, item, operationId) };
|
|
1776
|
+
}, "closeCrmItem");
|
|
1777
|
+
var removeCrmItem = /* @__PURE__ */ __name(async (context, kind, reference, options = {}) => {
|
|
1778
|
+
const { writer } = context.writes;
|
|
1779
|
+
supported(writer, kind, "remove");
|
|
1780
|
+
const copy = await copyOf(context, kind, reference);
|
|
1781
|
+
const operationId = operationOf(context, options.operationId);
|
|
1782
|
+
await written(context, keysOf(context, kind, "remove", {}), operationId, () => writer.remove(kind, copy.externalId, { operationId }));
|
|
1783
|
+
const removed = await context.store.crm.remove(context.account, kind, [copy.externalId]);
|
|
1784
|
+
return { operationId, ref: copy.ref, removed };
|
|
1785
|
+
}, "removeCrmItem");
|
|
1786
|
+
var EMAIL = /^[^\s@]{1,64}@[^\s@]{1,255}$/u;
|
|
1787
|
+
var RECORD_ID = /^[\w.:-]{1,100}$/u;
|
|
1788
|
+
var PERSON_ONLY = ["firstName", "lastName", "position"];
|
|
1789
|
+
var recordInvalid = /* @__PURE__ */ __name((message, param) => new CliError("validation_error", message, { reason: "crm.record-field", ...param ? { param } : {} }), "recordInvalid");
|
|
1790
|
+
var cleared = /* @__PURE__ */ __name((value) => value === void 0 ? void 0 : value.trim() || null, "cleared");
|
|
1791
|
+
var listed2 = /* @__PURE__ */ __name((values, param, valid) => {
|
|
1792
|
+
if (values === void 0)
|
|
1793
|
+
return void 0;
|
|
1794
|
+
const all = values.map((one) => one.trim());
|
|
1795
|
+
if (all.length === 1 && all[0] === "")
|
|
1796
|
+
return [];
|
|
1797
|
+
for (const one of all)
|
|
1798
|
+
if (one === "" || one.length > 320 || valid && !valid.test(one))
|
|
1799
|
+
throw recordInvalid(`${param} got ${one}`, param);
|
|
1800
|
+
return all;
|
|
1801
|
+
}, "listed");
|
|
1802
|
+
var recordFieldsOf = /* @__PURE__ */ __name((kind, input) => {
|
|
1803
|
+
if (kind === "organization") {
|
|
1804
|
+
const given = PERSON_ONLY.find((one) => input[one] !== void 0);
|
|
1805
|
+
if (given)
|
|
1806
|
+
throw recordInvalid(`a company has no ${given}`);
|
|
1807
|
+
}
|
|
1808
|
+
const fields = {};
|
|
1809
|
+
if (input.name !== void 0) {
|
|
1810
|
+
if (!input.name.trim())
|
|
1811
|
+
throw recordInvalid("--name is never empty", "--name");
|
|
1812
|
+
fields.name = input.name.trim();
|
|
1813
|
+
}
|
|
1814
|
+
const parts = { firstName: cleared(input.firstName), lastName: cleared(input.lastName) };
|
|
1815
|
+
const position = cleared(input.position);
|
|
1816
|
+
if (parts.firstName !== void 0)
|
|
1817
|
+
fields.firstName = parts.firstName;
|
|
1818
|
+
if (parts.lastName !== void 0)
|
|
1819
|
+
fields.lastName = parts.lastName;
|
|
1820
|
+
if (position !== void 0)
|
|
1821
|
+
fields.position = position;
|
|
1822
|
+
const emails = listed2(input.emails, "--email", EMAIL);
|
|
1823
|
+
const phones = listed2(input.phones, "--phone")?.map((phone) => {
|
|
1824
|
+
const international = e164Of(phone, void 0);
|
|
1825
|
+
if (typeof international !== "string")
|
|
1826
|
+
throw recordInvalid(`--phone takes a number in international form, starting with +: not ${phone}`, "--phone");
|
|
1827
|
+
return international;
|
|
1828
|
+
});
|
|
1829
|
+
if (emails)
|
|
1830
|
+
fields.emails = emails;
|
|
1831
|
+
if (phones)
|
|
1832
|
+
fields.phones = phones;
|
|
1833
|
+
if (input.owner !== void 0) {
|
|
1834
|
+
if (!input.owner.trim())
|
|
1835
|
+
throw recordInvalid("--owner is the CRM user's id", "--owner");
|
|
1836
|
+
fields.owner = input.owner.trim();
|
|
1837
|
+
}
|
|
1838
|
+
return fields;
|
|
1839
|
+
}, "recordFieldsOf");
|
|
1840
|
+
var keptRecord = /* @__PURE__ */ __name(async (context, kind, record) => {
|
|
1841
|
+
try {
|
|
1842
|
+
const saved = kind === "person" ? await context.store.crm.savePeople(context.account, [record]) : await context.store.crm.saveOrganizations(context.account, [record]);
|
|
1843
|
+
const [skipped] = saved.skipped;
|
|
1844
|
+
if (skipped)
|
|
1845
|
+
throw new Error(skipped.message);
|
|
1846
|
+
} catch (error) {
|
|
1847
|
+
throw new CliError("invalid_response", `the CRM wrote ${kind} ${record.externalId}, but the local store did not keep it (${error instanceof Error ? error.message : String(error)}); sync to store it \u2014 do not write it again`, { external_id: record.externalId, sent: true });
|
|
1848
|
+
}
|
|
1849
|
+
}, "keptRecord");
|
|
1850
|
+
var forgotten = /* @__PURE__ */ __name(async (context, kind, record) => (kind === "organization" ? await context.store.crm.remove(context.account, kind, [record.externalId]) : (await context.store.crm.removeContact(context.account, record.externalId)).contacts) > 0, "forgotten");
|
|
1851
|
+
var writeRecord = /* @__PURE__ */ __name(async (context, kind, verb, fields, operationId, act) => {
|
|
1852
|
+
if (!context.source)
|
|
1853
|
+
throw new CliError("configuration_error", "a contact or company write needs the CRM source to tell your clients");
|
|
1854
|
+
const rule = foreignContacts(context.source(), void 0);
|
|
1855
|
+
const record = await written(context, keysOf(context, kind, verb, { owner: fields.owner }), operationId, act);
|
|
1856
|
+
const stored = await rule.own(kind, record);
|
|
1857
|
+
let removed;
|
|
1858
|
+
try {
|
|
1859
|
+
if (stored)
|
|
1860
|
+
await keptRecord(context, kind, record);
|
|
1861
|
+
else if (verb === "update")
|
|
1862
|
+
removed = await forgotten(context, kind, record);
|
|
1863
|
+
} catch (error) {
|
|
1864
|
+
if (isCliError(error))
|
|
1865
|
+
throw new CliError(error.code, error.message, { ...error.details, operation_id: operationId });
|
|
1866
|
+
throw error;
|
|
1867
|
+
}
|
|
1868
|
+
const [shown] = stored ? [record] : await rule.strip(kind, [record]);
|
|
1869
|
+
return {
|
|
1870
|
+
operationId,
|
|
1871
|
+
record: shown,
|
|
1872
|
+
stored,
|
|
1873
|
+
...removed === void 0 ? {} : { removed }
|
|
1874
|
+
};
|
|
1875
|
+
}, "writeRecord");
|
|
1876
|
+
var createCrmRecord = /* @__PURE__ */ __name(async (context, kind, input, options = {}) => {
|
|
1877
|
+
const { writer } = context.writes;
|
|
1878
|
+
supported(writer, kind, "create");
|
|
1879
|
+
const fields = recordFieldsOf(kind, input);
|
|
1880
|
+
if (kind === "organization" && fields.name === void 0)
|
|
1881
|
+
throw recordInvalid("a new company needs --name", "--name");
|
|
1882
|
+
if (kind === "person" && !fields.name && !fields.firstName && !fields.lastName)
|
|
1883
|
+
throw recordInvalid("a new contact needs --name, --first-name or --last-name", "--name");
|
|
1884
|
+
const custom = await customOf(context, kind, input.custom);
|
|
1885
|
+
if (custom)
|
|
1886
|
+
fields.custom = custom;
|
|
1887
|
+
const operationId = operationOf(context, options.operationId);
|
|
1888
|
+
return writeRecord(context, kind, "create", fields, operationId, () => writer.create(kind, fields, { operationId }));
|
|
1889
|
+
}, "createCrmRecord");
|
|
1890
|
+
var updateCrmRecord = /* @__PURE__ */ __name(async (context, kind, externalId, input, options = {}) => {
|
|
1891
|
+
const { writer } = context.writes;
|
|
1892
|
+
supported(writer, kind, "update");
|
|
1893
|
+
if (!RECORD_ID.test(externalId))
|
|
1894
|
+
throw new CliError("validation_error", `name the ${kind} by the CRM's id, as a list prints it`, {
|
|
1895
|
+
reason: "ref.malformed"
|
|
1896
|
+
});
|
|
1897
|
+
const fields = recordFieldsOf(kind, input);
|
|
1898
|
+
const custom = await customOf(context, kind, input.custom);
|
|
1899
|
+
if (custom)
|
|
1900
|
+
fields.custom = custom;
|
|
1901
|
+
if (Object.keys(fields).length === 0)
|
|
1902
|
+
throw recordInvalid("nothing to change: name a field");
|
|
1903
|
+
const operationId = operationOf(context, options.operationId);
|
|
1904
|
+
return writeRecord(context, kind, "update", fields, operationId, () => writer.update(kind, externalId, fields, { operationId }));
|
|
1905
|
+
}, "updateCrmRecord");
|
|
1906
|
+
|
|
1907
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/values.js
|
|
1908
|
+
var values_exports = {};
|
|
1909
|
+
__export(values_exports, {
|
|
1910
|
+
amountOf: () => amountOf,
|
|
1911
|
+
crmValuesOf: () => crmValuesOf,
|
|
1912
|
+
epoch: () => epoch,
|
|
1913
|
+
fieldOf: () => fieldOf,
|
|
1914
|
+
fullName: () => fullName,
|
|
1915
|
+
id: () => id,
|
|
1916
|
+
ids: () => ids,
|
|
1917
|
+
isRaw: () => isRaw,
|
|
1918
|
+
number: () => number,
|
|
1919
|
+
rawsOf: () => rawsOf,
|
|
1920
|
+
text: () => text,
|
|
1921
|
+
time: () => time
|
|
1922
|
+
});
|
|
1923
|
+
|
|
1924
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/source.js
|
|
1925
|
+
var CRM_FILE_SOURCES = ["record", "field", "document", "activity", "comment"];
|
|
1926
|
+
|
|
1927
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/files.js
|
|
1928
|
+
var parseCrmFileId = /* @__PURE__ */ __name((id2) => {
|
|
1929
|
+
const [kind = "", owner = "", source = "", ...rest] = id2.trim().split(":");
|
|
1930
|
+
const providerId = rest.join(":");
|
|
1931
|
+
if (!CRM_KINDS.includes(kind) || !/^[\w.-]+$/u.test(owner) || !CRM_FILE_SOURCES.includes(source) || !providerId)
|
|
1932
|
+
throw new CliError("validation_error", "a file id is <owner kind>:<owner id>:<source>:<id>, as files list prints it, such as deal:12:record:345", { reason: "ref.malformed" });
|
|
1933
|
+
return { owner: { kind, id: owner }, source, providerId };
|
|
1934
|
+
}, "parseCrmFileId");
|
|
1935
|
+
var foldKey = /* @__PURE__ */ __name((key) => key.replaceAll("_", "").toLowerCase(), "foldKey");
|
|
1936
|
+
var DOWNLOAD_KEYS = new Set(["DOWNLOAD_URL", "downloadUrl", "fileUrl", "CALL_RECORD_URL", "archiveLink", "publicUrl"].map(foldKey));
|
|
1937
|
+
var isDownloadKey = /* @__PURE__ */ __name((key) => DOWNLOAD_KEYS.has(foldKey(key)) || foldKey(key).endsWith("machine"), "isDownloadKey");
|
|
1938
|
+
var WEBHOOK = /\/rest\/\d+\/[^/\s"'?#]+\//iu;
|
|
1939
|
+
var PORTAL_PATH = /\/rest\/|show_file\.php/iu;
|
|
1940
|
+
var TOKEN_QUERY = /(?:[?&]|&)(?:auth|token|access_token)=[^&#\s]/iu;
|
|
1941
|
+
var CREDENTIAL = /(?:[?&]|&)(?:auth|access_token|api_token|x-amz-signature)=[^&#\s]/iu;
|
|
1942
|
+
var isTokened = /* @__PURE__ */ __name((value) => WEBHOOK.test(value) || CREDENTIAL.test(value) || PORTAL_PATH.test(value) && TOKEN_QUERY.test(value), "isTokened");
|
|
1943
|
+
var LINK_REMOVED = "[link removed]";
|
|
1944
|
+
var withoutFileLinks = /* @__PURE__ */ __name((body) => {
|
|
1945
|
+
const walk2 = /* @__PURE__ */ __name((value, key) => {
|
|
1946
|
+
if (typeof value === "string")
|
|
1947
|
+
return isTokened(value) ? LINK_REMOVED : value;
|
|
1948
|
+
if (Array.isArray(value))
|
|
1949
|
+
return value.map((one) => walk2(one));
|
|
1950
|
+
if (value === null || typeof value !== "object")
|
|
1951
|
+
return value;
|
|
1952
|
+
return Object.fromEntries(Object.entries(value).map(([name, one]) => [
|
|
1953
|
+
name,
|
|
1954
|
+
(isDownloadKey(name) || key === "_links" && name === "download") && one !== null && one !== "" ? LINK_REMOVED : walk2(one, name)
|
|
1955
|
+
]));
|
|
1956
|
+
}, "walk");
|
|
1957
|
+
return walk2(body);
|
|
1958
|
+
}, "withoutFileLinks");
|
|
1959
|
+
|
|
1960
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/values.js
|
|
1961
|
+
var isRaw = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isRaw");
|
|
1962
|
+
var fieldOf = /* @__PURE__ */ __name((value, key) => isRaw(value) ? value[key] : void 0, "fieldOf");
|
|
1963
|
+
var rawsOf = /* @__PURE__ */ __name((value) => Array.isArray(value) ? value.filter(isRaw) : [], "rawsOf");
|
|
1964
|
+
var text = /* @__PURE__ */ __name((value) => {
|
|
1965
|
+
if (typeof value !== "string" && typeof value !== "number")
|
|
1966
|
+
return null;
|
|
1967
|
+
const trimmed = String(value).trim();
|
|
1968
|
+
return trimmed === "" ? null : trimmed;
|
|
1969
|
+
}, "text");
|
|
1970
|
+
var id = /* @__PURE__ */ __name((value) => {
|
|
1971
|
+
const found = text(value);
|
|
1972
|
+
return found === null || found === "0" ? null : found;
|
|
1973
|
+
}, "id");
|
|
1974
|
+
var ids = /* @__PURE__ */ __name((value) => Array.isArray(value) ? value.map(id).filter((one) => one !== null) : [], "ids");
|
|
1975
|
+
var number = /* @__PURE__ */ __name((value) => {
|
|
1976
|
+
if (value === null || value === void 0 || value === "")
|
|
1977
|
+
return null;
|
|
1978
|
+
const found = Number(value);
|
|
1979
|
+
return Number.isFinite(found) ? found : null;
|
|
1980
|
+
}, "number");
|
|
1981
|
+
var time = /* @__PURE__ */ __name((value) => {
|
|
1982
|
+
if (typeof value === "number") {
|
|
1983
|
+
if (!Number.isFinite(value) || value <= 0)
|
|
1984
|
+
return null;
|
|
1985
|
+
return new Date(value > 1e11 ? value : value * 1e3).toISOString();
|
|
1986
|
+
}
|
|
1987
|
+
const found = text(value);
|
|
1988
|
+
if (found === null)
|
|
1989
|
+
return null;
|
|
1990
|
+
const parsed = new Date(found);
|
|
1991
|
+
return Number.isNaN(parsed.getTime()) ? null : parsed.toISOString();
|
|
1992
|
+
}, "time");
|
|
1993
|
+
var epoch = /* @__PURE__ */ __name((value) => {
|
|
1994
|
+
const found = time(value);
|
|
1995
|
+
return found === null ? null : Date.parse(found);
|
|
1996
|
+
}, "epoch");
|
|
1997
|
+
var amountOf = /* @__PURE__ */ __name((value, currency) => {
|
|
1998
|
+
const found = number(value);
|
|
1999
|
+
const code = text(currency)?.toUpperCase() ?? null;
|
|
2000
|
+
if (found === null || found <= 0 || code === null)
|
|
2001
|
+
return { amount: null, currency: null };
|
|
2002
|
+
return { amount: typeof value === "string" ? value.trim() : String(found), currency: code };
|
|
2003
|
+
}, "amountOf");
|
|
2004
|
+
var fullName = /* @__PURE__ */ __name((...parts) => parts.map(text).filter((part) => part !== null).join(" ") || null, "fullName");
|
|
2005
|
+
var optionLabel = /* @__PURE__ */ __name((field, option) => field.options?.find(({ id: id2 }) => id2 === String(option))?.label ?? String(option), "optionLabel");
|
|
2006
|
+
var crmValuesOf = /* @__PURE__ */ __name((values, fields) => {
|
|
2007
|
+
const byCode = new Map(fields.map((field) => [field.code, field]));
|
|
2008
|
+
return Object.fromEntries(Object.entries(values).map(([code, value]) => {
|
|
2009
|
+
const field = byCode.get(code);
|
|
2010
|
+
const label = field?.label ?? null;
|
|
2011
|
+
if (!field?.options)
|
|
2012
|
+
return [code, { label, value: withoutFileLinks(value) }];
|
|
2013
|
+
if (Array.isArray(value))
|
|
2014
|
+
return [code, { label, value: value.map((one) => optionLabel(field, one)), option_id: value.map(String) }];
|
|
2015
|
+
return [code, { label, value: optionLabel(field, value), option_id: String(value) }];
|
|
2016
|
+
}));
|
|
2017
|
+
}, "crmValuesOf");
|
|
2018
|
+
|
|
2019
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/file-fetch.js
|
|
2020
|
+
var EXCHANGE_MS = 60 * 60 * 1e3;
|
|
2021
|
+
|
|
2022
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/sends/pace.js
|
|
2023
|
+
import { readFileSync as readFileSync5, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
2024
|
+
import { join as join5 } from "node:path";
|
|
2025
|
+
var DEFAULT_PACE = { perMinute: 60, burst: 20 };
|
|
2026
|
+
var pacePathFor = /* @__PURE__ */ __name((app, profile, env = process.env) => join5(resolvePaths({ appName: app.appName, prefix: app.envPrefix, env }).state, "pace", `${profile}.json`), "pacePathFor");
|
|
2027
|
+
var Pacer = class {
|
|
2028
|
+
static {
|
|
2029
|
+
__name(this, "Pacer");
|
|
2030
|
+
}
|
|
2031
|
+
path;
|
|
2032
|
+
rate;
|
|
2033
|
+
now;
|
|
2034
|
+
constructor(path, rate, now = Date.now) {
|
|
2035
|
+
this.path = path;
|
|
2036
|
+
this.rate = rate;
|
|
2037
|
+
this.now = now;
|
|
2038
|
+
}
|
|
2039
|
+
get interval() {
|
|
2040
|
+
return this.rate.perMinute > 0 ? 6e4 / this.rate.perMinute : 0;
|
|
2041
|
+
}
|
|
2042
|
+
/** When this call may go; reserved at once, so the next caller in any process lines up behind it. */
|
|
2043
|
+
async reserve() {
|
|
2044
|
+
if (this.interval === 0)
|
|
2045
|
+
return this.now();
|
|
2046
|
+
return withFileLockAsync(this.path, "the request pace", () => {
|
|
2047
|
+
const now = this.now();
|
|
2048
|
+
const tat = Math.max(this.read(now), now);
|
|
2049
|
+
this.write(tat + this.interval, now);
|
|
2050
|
+
return Math.max(now, tat - this.rate.burst * this.interval);
|
|
2051
|
+
});
|
|
2052
|
+
}
|
|
2053
|
+
/** The messenger asked every caller to wait: nothing goes before `now + waitMs`, in any process. */
|
|
2054
|
+
async holdFor(waitMs) {
|
|
2055
|
+
if (this.interval === 0)
|
|
2056
|
+
return;
|
|
2057
|
+
await withFileLockAsync(this.path, "the request pace", () => {
|
|
2058
|
+
const now = this.now();
|
|
2059
|
+
const hold = now + waitMs + this.rate.burst * this.interval;
|
|
2060
|
+
this.write(Math.max(this.read(now), hold), now);
|
|
2061
|
+
});
|
|
2062
|
+
}
|
|
2063
|
+
/** The owner's `flood clear`: every process may go again at once. */
|
|
2064
|
+
async reset() {
|
|
2065
|
+
await withFileLockAsync(this.path, "the request pace", () => this.write(0, this.now()));
|
|
2066
|
+
}
|
|
2067
|
+
read(now) {
|
|
2068
|
+
try {
|
|
2069
|
+
const file = JSON.parse(readFileSync5(this.path, "utf8"));
|
|
2070
|
+
const tat = Number(file.tat);
|
|
2071
|
+
if (!Number.isFinite(tat))
|
|
2072
|
+
return 0;
|
|
2073
|
+
const at = Number(file.at);
|
|
2074
|
+
return Number.isFinite(at) && at > now ? now + Math.max(0, tat - at) : tat;
|
|
2075
|
+
} catch {
|
|
2076
|
+
return 0;
|
|
2077
|
+
}
|
|
2078
|
+
}
|
|
2079
|
+
write(tat, at) {
|
|
2080
|
+
const temporary = `${this.path}.${process.pid}.tmp`;
|
|
2081
|
+
writeFileSync2(temporary, JSON.stringify({ tat, at }), { mode: 384 });
|
|
2082
|
+
renameSync2(temporary, this.path);
|
|
2083
|
+
}
|
|
2084
|
+
};
|
|
2085
|
+
var ANNOUNCE_WAIT_MS = 5e3;
|
|
2086
|
+
var LONGEST_PACE_WAIT_MS = 5 * 6e4;
|
|
2087
|
+
var waitForTurn = /* @__PURE__ */ __name(async (pacer, options) => {
|
|
2088
|
+
const { name, operation, warn } = options;
|
|
2089
|
+
const now = options.now ?? Date.now;
|
|
2090
|
+
let at = now();
|
|
2091
|
+
try {
|
|
2092
|
+
at = await pacer.reserve();
|
|
2093
|
+
} catch (error) {
|
|
2094
|
+
warn?.(`could not remember ${name}'s wait (${error instanceof Error ? error.message : String(error)})`, {
|
|
2095
|
+
event: "warning",
|
|
2096
|
+
code: "wait_not_remembered",
|
|
2097
|
+
operation
|
|
2098
|
+
});
|
|
2099
|
+
}
|
|
2100
|
+
const waitMs = at - now();
|
|
2101
|
+
if (waitMs <= 0)
|
|
2102
|
+
return;
|
|
2103
|
+
if (waitMs > (options.longestWaitMs ?? LONGEST_PACE_WAIT_MS))
|
|
2104
|
+
throw new CliError("rate_limited", `this profile's next request to ${name} has to wait ${Math.ceil(waitMs / 1e3)} s more \u2014 nothing was sent to ${name}`, { retry_after_ms: waitMs, retry_at: new Date(at).toISOString(), remembered: true });
|
|
2105
|
+
if (waitMs >= ANNOUNCE_WAIT_MS) {
|
|
2106
|
+
const seconds = Math.ceil(waitMs / 1e3);
|
|
2107
|
+
warn?.(`waiting ${seconds} s to keep this profile's pace with ${name}`, {
|
|
2108
|
+
event: "warning",
|
|
2109
|
+
code: "pace_wait",
|
|
2110
|
+
operation,
|
|
2111
|
+
counts: { seconds }
|
|
2112
|
+
});
|
|
2113
|
+
}
|
|
2114
|
+
await (options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(waitMs);
|
|
2115
|
+
}, "waitForTurn");
|
|
2116
|
+
|
|
2117
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/provider-call.js
|
|
2118
|
+
var RETRY = { retries: 3, baseDelayMs: 1e3, maxDelayMs: 1e4, maxRetryAfterMs: 3e4 };
|
|
2119
|
+
var UNANSWERED = /* @__PURE__ */ new Set(["timeout", "network_error", "provider_unavailable", "cancelled", "invalid_response"]);
|
|
2120
|
+
var unanswered = /* @__PURE__ */ __name((error) => !isCliError(error) || UNANSWERED.has(error.code) && error.details.sent !== false, "unanswered");
|
|
2121
|
+
var providerCall = /* @__PURE__ */ __name(async (options) => {
|
|
2122
|
+
const retries = options.retries ?? RETRY.retries;
|
|
2123
|
+
const sleep = options.sleep ?? ((ms) => realSleep(ms));
|
|
2124
|
+
let refreshed = false;
|
|
2125
|
+
for (let attempt = 1; ; attempt++) {
|
|
2126
|
+
if (options.pace)
|
|
2127
|
+
await waitForTurn(options.pace.pacer, options.pace);
|
|
2128
|
+
try {
|
|
2129
|
+
return await options.send();
|
|
2130
|
+
} catch (error) {
|
|
2131
|
+
if (!refreshed && options.refresh && isCliError(error) && error.code === "authentication_error" && error.details.reason === "oauth.expired") {
|
|
2132
|
+
refreshed = true;
|
|
2133
|
+
if (await options.refresh())
|
|
2134
|
+
continue;
|
|
2135
|
+
throw error;
|
|
2136
|
+
}
|
|
2137
|
+
if (options.write && unanswered(error))
|
|
2138
|
+
throw new CliError("outcome_unknown", `${error instanceof Error ? error.message : String(error)}; the CRM may or may not have carried it out`, { ...isCliError(error) ? error.details : {}, retryable: false });
|
|
2139
|
+
if (!isCliError(error))
|
|
2140
|
+
throw error;
|
|
2141
|
+
const asked = error.details.retry_after_ms;
|
|
2142
|
+
const wait = typeof asked === "number" ? asked : backoffMs(attempt, RETRY, options.random ?? Math.random);
|
|
2143
|
+
const again = error.code === "rate_limited" || !options.write && error.details.retryable === true;
|
|
2144
|
+
if (!again || wait > RETRY.maxRetryAfterMs || attempt > retries)
|
|
2145
|
+
throw error;
|
|
2146
|
+
if (error.code === "rate_limited")
|
|
2147
|
+
await options.pace?.pacer.holdFor(wait);
|
|
2148
|
+
await sleep(wait);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
}, "providerCall");
|
|
2152
|
+
|
|
2153
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/query.js
|
|
2154
|
+
var valueFor = /* @__PURE__ */ __name((kind, raw, name) => {
|
|
2155
|
+
if (kind === "id") {
|
|
2156
|
+
if (!/^[\w.:-]{1,100}$/u.test(raw))
|
|
2157
|
+
throw new CliError("validation_error", `${name} takes an id; got ${raw}`, { reason: "query.bad-value" });
|
|
2158
|
+
return raw;
|
|
2159
|
+
}
|
|
2160
|
+
if (kind !== "number")
|
|
2161
|
+
return raw;
|
|
2162
|
+
const found = Number(raw);
|
|
2163
|
+
if (raw.trim() === "" || !Number.isFinite(found))
|
|
2164
|
+
throw new CliError("validation_error", `${name} takes a number; got ${raw}`, { reason: "query.bad-value" });
|
|
2165
|
+
return found;
|
|
2166
|
+
}, "valueFor");
|
|
2167
|
+
var range = /* @__PURE__ */ __name((node, map, name) => [
|
|
2168
|
+
...node.value === "*" ? [] : [
|
|
2169
|
+
{
|
|
2170
|
+
field: map.field,
|
|
2171
|
+
op: node.lower_inclusive === false ? ">" : ">=",
|
|
2172
|
+
value: valueFor(map.kind, node.value, name)
|
|
2173
|
+
}
|
|
2174
|
+
],
|
|
2175
|
+
...node.upper === void 0 || node.upper === "*" ? [] : [
|
|
2176
|
+
{
|
|
2177
|
+
field: map.field,
|
|
2178
|
+
op: node.upper_inclusive === false ? "<" : "<=",
|
|
2179
|
+
value: valueFor(map.kind, node.upper, name)
|
|
2180
|
+
}
|
|
2181
|
+
]
|
|
2182
|
+
], "range");
|
|
2183
|
+
var conditionsOf = /* @__PURE__ */ __name((terms, fields, hooks = {}) => [...terms].flatMap(([name, node]) => {
|
|
2184
|
+
const map = fields[name];
|
|
2185
|
+
if (!map)
|
|
2186
|
+
throw new CliError("validation_error", `the CRM cannot filter by ${name}`, { reason: "query.unsupported-field" });
|
|
2187
|
+
if (map.kind === "time") {
|
|
2188
|
+
const at = hooks.time ?? ((ms) => ms);
|
|
2189
|
+
const { since, until } = timeBounds(node);
|
|
2190
|
+
return [
|
|
2191
|
+
...since === void 0 ? [] : [{ field: map.field, op: ">=", value: at(since) }],
|
|
2192
|
+
...until === void 0 ? [] : [{ field: map.field, op: "<=", value: at(until) }]
|
|
2193
|
+
];
|
|
2194
|
+
}
|
|
2195
|
+
if (node.operator === "range")
|
|
2196
|
+
return range(node, map, name);
|
|
2197
|
+
return [{ field: map.field, op: "=", value: valueFor(map.kind, node.value, name) }];
|
|
2198
|
+
}), "conditionsOf");
|
|
2199
|
+
var customNames = /* @__PURE__ */ __name((text2, registry, command, defaultField = "none") => {
|
|
2200
|
+
if (text2.trim() === "")
|
|
2201
|
+
return [];
|
|
2202
|
+
const known = new Set(registry.fields.map((field) => field.name));
|
|
2203
|
+
const named2 = walkQuery(parseLucene(text2, { defaultField, command, guide: LIST_QUERY_GUIDE }).root).filter((term) => !term.implicit).map((term) => term.field);
|
|
2204
|
+
return [...new Set(named2.filter((name) => !known.has(name)))];
|
|
2205
|
+
}, "customNames");
|
|
2206
|
+
var filterableFields = /* @__PURE__ */ __name((fields, names) => names.map((name) => {
|
|
2207
|
+
const field = fieldNamed(fields, name, "--query");
|
|
2208
|
+
if (!field.filterable)
|
|
2209
|
+
throw new CliError("validation_error", `the CRM cannot filter a list by ${field.label ?? field.code}`, {
|
|
2210
|
+
reason: "field.not-filterable",
|
|
2211
|
+
field: field.code
|
|
2212
|
+
});
|
|
2213
|
+
return [name, field];
|
|
2214
|
+
}), "filterableFields");
|
|
2215
|
+
var withCustomFields = /* @__PURE__ */ __name((registry, chosen) => ({
|
|
2216
|
+
...registry,
|
|
2217
|
+
fields: [
|
|
2218
|
+
...registry.fields,
|
|
2219
|
+
...chosen.map(([name]) => ({ name, type: "kw", operators: ["term", "phrase"], example: `${name}:x`, native: true }))
|
|
2220
|
+
]
|
|
2221
|
+
}), "withCustomFields");
|
|
2222
|
+
var customValue = /* @__PURE__ */ __name((field, typed, hooks) => {
|
|
2223
|
+
const value = field.options ? optionOf(field, typed, "--query") : typed;
|
|
2224
|
+
const number2 = Number(value);
|
|
2225
|
+
return hooks.numeric?.(field) && value.trim() !== "" && Number.isFinite(number2) ? number2 : value;
|
|
2226
|
+
}, "customValue");
|
|
2227
|
+
var customConditions = /* @__PURE__ */ __name((terms, chosen, hooks = {}) => chosen.flatMap(([name, field]) => {
|
|
2228
|
+
const term = terms.get(name);
|
|
2229
|
+
terms.delete(name);
|
|
2230
|
+
return term ? [{ field: field.code, op: "=", value: customValue(field, term.value, hooks) }] : [];
|
|
2231
|
+
}), "customConditions");
|
|
2232
|
+
var wantedCodes = /* @__PURE__ */ __name((paths) => {
|
|
2233
|
+
if (!paths)
|
|
2234
|
+
return void 0;
|
|
2235
|
+
const parts = paths.split(",").map((path) => path.trim().replace(/^items\./, "").split("."));
|
|
2236
|
+
const metadata = parts.filter(([top]) => top === "provider_metadata");
|
|
2237
|
+
if (metadata.some((part) => part.length === 1))
|
|
2238
|
+
return "all";
|
|
2239
|
+
const codes = metadata.flatMap(([, code]) => code ? [code] : []);
|
|
2240
|
+
return codes.length ? [...new Set(codes)] : void 0;
|
|
2241
|
+
}, "wantedCodes");
|
|
2242
|
+
var selectedCodes = /* @__PURE__ */ __name((fields, wanted) => {
|
|
2243
|
+
if (wanted === void 0)
|
|
2244
|
+
return [];
|
|
2245
|
+
if (wanted === "all")
|
|
2246
|
+
return fields.map((field) => field.code);
|
|
2247
|
+
return wanted.map((code) => {
|
|
2248
|
+
if (!fields.some((field) => field.code === code))
|
|
2249
|
+
throw unknownField(fields, code, "--json");
|
|
2250
|
+
return code;
|
|
2251
|
+
});
|
|
2252
|
+
}, "selectedCodes");
|
|
2253
|
+
|
|
2254
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/search/groups.js
|
|
2255
|
+
var ALL = "all";
|
|
2256
|
+
var OWNER_NOTES = { provider: "notes", account: INTERNAL_NOTES };
|
|
2257
|
+
var NOT_GROUP_NAMES = /* @__PURE__ */ new Set([ALL, "bots"]);
|
|
2258
|
+
var hasGroup = /* @__PURE__ */ __name((groups, name) => Object.hasOwn(groups, name), "hasGroup");
|
|
2259
|
+
var membersOf = /* @__PURE__ */ __name((entries, context, unresolved) => {
|
|
2260
|
+
const members = /* @__PURE__ */ new Map();
|
|
2261
|
+
for (const entry of entries)
|
|
2262
|
+
try {
|
|
2263
|
+
for (const { provider, account } of accountsOfList(entry, context)) {
|
|
2264
|
+
const known = members.get(keyOf({ provider, account }));
|
|
2265
|
+
if (known)
|
|
2266
|
+
known.entries.push(entry);
|
|
2267
|
+
else
|
|
2268
|
+
members.set(keyOf({ provider, account }), {
|
|
2269
|
+
provider,
|
|
2270
|
+
account,
|
|
2271
|
+
entries: [entry],
|
|
2272
|
+
reason: "setting",
|
|
2273
|
+
profiles: [],
|
|
2274
|
+
also_in: []
|
|
2275
|
+
});
|
|
2276
|
+
}
|
|
2277
|
+
} catch (error) {
|
|
2278
|
+
if (!(error instanceof CliError))
|
|
2279
|
+
throw error;
|
|
2280
|
+
unresolved.push(entry);
|
|
2281
|
+
}
|
|
2282
|
+
return [...members.values()];
|
|
2283
|
+
}, "membersOf");
|
|
2284
|
+
var groupMembership = /* @__PURE__ */ __name((context) => {
|
|
2285
|
+
const plain = { ...context, groups: {} };
|
|
2286
|
+
const unresolved = [];
|
|
2287
|
+
const groups = {};
|
|
2288
|
+
for (const [name, entries] of Object.entries(context.groups))
|
|
2289
|
+
if (name !== ALL)
|
|
2290
|
+
groups[name] = membersOf(entries, plain, unresolved);
|
|
2291
|
+
const system = [OWNER_NOTES, ...context.held.filter(({ id: id2 }) => id2 === 0)].map(keyOf);
|
|
2292
|
+
const every = accountsOfList(ALL, plain).filter((one) => !system.includes(keyOf(one))).map(({ provider, account }) => ({
|
|
2293
|
+
provider,
|
|
2294
|
+
account,
|
|
2295
|
+
entries: [sourceOf({ provider, account })],
|
|
2296
|
+
reason: "all",
|
|
2297
|
+
profiles: [],
|
|
2298
|
+
also_in: []
|
|
2299
|
+
}));
|
|
2300
|
+
const recorded = Object.entries(context.profiles).flatMap(([app, named2]) => Object.entries(named2).map(([profile, key]) => ({ app, profile, key })));
|
|
2301
|
+
const holding2 = /* @__PURE__ */ new Map();
|
|
2302
|
+
for (const [name, members] of Object.entries(groups))
|
|
2303
|
+
for (const one of members)
|
|
2304
|
+
holding2.set(keyOf(one), [...holding2.get(keyOf(one)) ?? [], name]);
|
|
2305
|
+
for (const [name, members] of [...Object.entries(groups), [ALL, every]])
|
|
2306
|
+
for (const one of members) {
|
|
2307
|
+
one.scope = context.held.find(sameAs(one))?.scope ?? "personal";
|
|
2308
|
+
one.profiles = recorded.filter(({ key }) => sameAs(key)(one)).map(({ app, profile }) => `${app} ${profile}`);
|
|
2309
|
+
one.also_in = (holding2.get(keyOf(one)) ?? []).filter((other) => other !== name);
|
|
2310
|
+
}
|
|
2311
|
+
const duplicates = [...holding2.entries()].filter(([, names]) => names.length > 1).map(([key, names]) => ({ member: key.replace("\0", ":"), groups: names }));
|
|
2312
|
+
const shared = /* @__PURE__ */ __name((app, profile) => hasGroup(context.groups, profile) || recorded.some((other) => other.app !== app && other.profile === profile), "shared");
|
|
2313
|
+
const suggested = recorded.filter(({ app, profile, key }) => isGroupName(profile) && !NOT_GROUP_NAMES.has(profile.toLowerCase()) && shared(app, profile) && !holding2.get(keyOf(key))?.includes(profile)).map(({ app, profile, key }) => ({
|
|
2314
|
+
group: profile,
|
|
2315
|
+
member: sourceOf(key),
|
|
2316
|
+
because: `profile named ${profile} (${app} ${profile})`
|
|
2317
|
+
}));
|
|
2318
|
+
return { groups: { ...groups, [ALL]: every }, duplicates, suggested, unresolved };
|
|
2319
|
+
}, "groupMembership");
|
|
2320
|
+
var inGroupOf = /* @__PURE__ */ __name((context, group) => (key) => group === ALL || (hasGroup(context.membership.groups, group) ? context.membership.groups[group] ?? [] : []).some(sameAs(key)), "inGroupOf");
|
|
2321
|
+
var groupEntries = /* @__PURE__ */ __name((saved) => ({
|
|
2322
|
+
...Object.fromEntries(Object.entries(saved).filter(([name]) => name !== ALL)),
|
|
2323
|
+
[ALL]: [ALL]
|
|
2324
|
+
}), "groupEntries");
|
|
2325
|
+
|
|
2326
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/services/search-kind.js
|
|
2327
|
+
var NO_MAIL = "no_mail";
|
|
2328
|
+
var MAIL = "email";
|
|
2329
|
+
var groupLockOf = /* @__PURE__ */ __name((app, env) => {
|
|
2330
|
+
const lock = app === void 0 || env === void 0 ? void 0 : env[envName(app, "GROUP_LOCK")]?.trim();
|
|
2331
|
+
return lock && lock.toLowerCase() !== ALL ? lock : void 0;
|
|
2332
|
+
}, "groupLockOf");
|
|
2333
|
+
var listContextOf = /* @__PURE__ */ __name(async (store, account, app, stored, env) => {
|
|
2334
|
+
const all = stored ?? await store.accounts.storedAccounts();
|
|
2335
|
+
const held = all.some((one) => one.provider === account.provider && one.account === account.account) ? all : [...all, { id: 0, ...account, name: null, scope: "personal" }];
|
|
2336
|
+
const context = {
|
|
2337
|
+
held,
|
|
2338
|
+
groups: await store.accounts.accountGroups(),
|
|
2339
|
+
profiles: await store.accounts.profiles(),
|
|
2340
|
+
running: { provider: account.provider, ...app ? { command: app.command } : {} }
|
|
2341
|
+
};
|
|
2342
|
+
const membership = groupMembership(context);
|
|
2343
|
+
const groups = groupEntries(context.groups);
|
|
2344
|
+
const lock = groupLockOf(app, env);
|
|
2345
|
+
if (lock === void 0)
|
|
2346
|
+
return { ...context, groups, membership };
|
|
2347
|
+
const members = hasGroup(membership.groups, lock) ? membership.groups[lock] : void 0;
|
|
2348
|
+
if (!members)
|
|
2349
|
+
throw new CliError("permission_error", `this process is locked to group ${lock} (${envName(app, "GROUP_LOCK")}), which does not exist`);
|
|
2350
|
+
const only = new Set([...members, OWNER_NOTES].map(keyOf));
|
|
2351
|
+
const listedAs = /* @__PURE__ */ __name((one) => isFolderProvider(one.provider) || isDocumentAccountProvider(one.provider) ? { provider: "notes", account: String(one.id) } : one, "listedAs");
|
|
2352
|
+
return {
|
|
2353
|
+
...context,
|
|
2354
|
+
held: held.filter((one) => only.has(keyOf(listedAs(one)))),
|
|
2355
|
+
groups: { [lock]: groups[lock] ?? [] },
|
|
2356
|
+
membership: {
|
|
2357
|
+
groups: { [lock]: members },
|
|
2358
|
+
duplicates: membership.duplicates.filter(({ groups: names }) => names.includes(lock)),
|
|
2359
|
+
suggested: membership.suggested.filter(({ group }) => group === lock),
|
|
2360
|
+
unresolved: membership.unresolved
|
|
2361
|
+
},
|
|
2362
|
+
only
|
|
2363
|
+
};
|
|
2364
|
+
}, "listContextOf");
|
|
2365
|
+
var listedAccounts = /* @__PURE__ */ __name(async (store, account, source, app, kind, env) => {
|
|
2366
|
+
const lock = groupLockOf(app, env);
|
|
2367
|
+
if (source === void 0 && lock === void 0)
|
|
2368
|
+
return void 0;
|
|
2369
|
+
const stored = await store.accounts.storedAccounts();
|
|
2370
|
+
const registered = source !== void 0 && (isKind(source) || providerNamed(source) !== void 0 && !stored.some(({ provider }) => provider === source));
|
|
2371
|
+
if (lock === void 0 && source !== void 0 && !isAccountList(source) && !registered)
|
|
2372
|
+
return void 0;
|
|
2373
|
+
const entries = entriesOfList(source ?? `group:${lock}`, await listContextOf(store, account, app, stored, env));
|
|
2374
|
+
return fitting(entries, kind ? [kind] : ["messages", "mail"], `${app ? `${app.command} ` : ""}search ${kind ?? "messages"}`);
|
|
2375
|
+
}, "listedAccounts");
|
|
2376
|
+
var accountsOfKind = /* @__PURE__ */ __name((kind, chosen, held, explicit, command = void 0, mailAccount, listed3 = false) => {
|
|
2377
|
+
if (mailAccount !== void 0 && kind !== "mail")
|
|
2378
|
+
throw new CliError("validation_error", "--account names a mail account \u2014 memo search mail reads it");
|
|
2379
|
+
if (kind === void 0)
|
|
2380
|
+
return chosen;
|
|
2381
|
+
if (kind === "messages") {
|
|
2382
|
+
if (explicit === MAIL)
|
|
2383
|
+
throw new CliError("validation_error", "mail is searched with `memo search mail`, not search messages");
|
|
2384
|
+
return chosen.filter(({ provider }) => holdsKindOf(provider, "messages"));
|
|
2385
|
+
}
|
|
2386
|
+
if (explicit !== void 0 && explicit !== MAIL && explicit !== "all")
|
|
2387
|
+
throw new CliError("validation_error", `search mail reads mail only \u2014 \`${command === void 0 ? "" : `${command} `}search messages\` searches ${explicit}`);
|
|
2388
|
+
const mail = (listed3 ? chosen : held).filter(({ provider }) => holdsKindOf(provider, "mail"));
|
|
2389
|
+
if (mail.length === 0)
|
|
2390
|
+
throw new CliError("not_found", "no mail in the store yet \u2014 `memo sync --only mail --since-time <time>` imports it", {
|
|
2391
|
+
reason: NO_MAIL
|
|
2392
|
+
});
|
|
2393
|
+
const address = mailAccount?.trim().toLowerCase();
|
|
2394
|
+
const chosenMail = address === void 0 ? mail : mail.filter(({ account }) => account === address);
|
|
2395
|
+
if (chosenMail.length === 0)
|
|
2396
|
+
throw new CliError("not_found", `no mail account ${mailAccount} in the store \u2014 it holds ${mail.map(({ account }) => account).join(", ")}`);
|
|
2397
|
+
return chosenMail.map(({ provider, account }) => ({ provider, account }));
|
|
2398
|
+
}, "accountsOfKind");
|
|
2399
|
+
|
|
2400
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/group-hint.js
|
|
2401
|
+
var workGroupHint = /* @__PURE__ */ __name((key) => `add it to a work group: \`memo groups add work ${key.provider}:${key.account}\``, "workGroupHint");
|
|
2402
|
+
var ungroupedHint = /* @__PURE__ */ __name(async (store, key) => {
|
|
2403
|
+
const { groups } = (await listContextOf(store, key, void 0)).membership;
|
|
2404
|
+
const grouped = Object.entries(groups).some(([name, members]) => name !== ALL && members.some(sameAs(key)));
|
|
2405
|
+
return grouped ? void 0 : workGroupHint(key);
|
|
2406
|
+
}, "ungroupedHint");
|
|
2407
|
+
|
|
2408
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/viewer.js
|
|
2409
|
+
var VIEWERS = "crm:viewers";
|
|
2410
|
+
var viewersOf = /* @__PURE__ */ __name(async (store, account) => {
|
|
2411
|
+
try {
|
|
2412
|
+
const found = JSON.parse((await store.sync.syncState(account, VIEWERS))?.value ?? "null");
|
|
2413
|
+
if (!found || typeof found.limited !== "boolean")
|
|
2414
|
+
return void 0;
|
|
2415
|
+
return { limited: found.limited, admins: typeof found.admins === "object" && found.admins ? found.admins : {} };
|
|
2416
|
+
} catch {
|
|
2417
|
+
return void 0;
|
|
2418
|
+
}
|
|
2419
|
+
}, "viewersOf");
|
|
2420
|
+
var recordCrmViewer = /* @__PURE__ */ __name(async (source, store, account, self) => {
|
|
2421
|
+
const limited = self !== void 0 || source.isAdmin !== void 0;
|
|
2422
|
+
const known = await viewersOf(store, account);
|
|
2423
|
+
const admins = { ...known?.admins ?? {} };
|
|
2424
|
+
if (self !== void 0)
|
|
2425
|
+
admins[self] = source.isAdmin ? await source.isAdmin().catch(() => false) : false;
|
|
2426
|
+
await store.sync.setSyncState(account, VIEWERS, JSON.stringify({ limited, admins }));
|
|
2427
|
+
}, "recordCrmViewer");
|
|
2428
|
+
var crmViewerOf = /* @__PURE__ */ __name(async (store, account, user) => {
|
|
2429
|
+
const known = await viewersOf(store, account);
|
|
2430
|
+
if (known?.limited === false)
|
|
2431
|
+
return { viewer: void 0 };
|
|
2432
|
+
const id2 = user === null ? void 0 : normalCrmUserId(user);
|
|
2433
|
+
if (id2 !== void 0 && known?.admins[id2] === true)
|
|
2434
|
+
return { viewer: void 0 };
|
|
2435
|
+
if (id2 === void 0)
|
|
2436
|
+
return {
|
|
2437
|
+
viewer: { account, assignee: null },
|
|
2438
|
+
note: "this profile's sign-in names no CRM user, so offline reads show none of the copy's deals and leads: sign in again (session start) so the sign-in keeps its user"
|
|
2439
|
+
};
|
|
2440
|
+
const viewer = { account, assignee: crmIdentityId(account, id2, "user") };
|
|
2441
|
+
return known ? { viewer } : {
|
|
2442
|
+
viewer,
|
|
2443
|
+
note: "no sync of this version recorded who may read this copy, so offline reads show only your own deals and leads: run sync once"
|
|
2444
|
+
};
|
|
2445
|
+
}, "crmViewerOf");
|
|
2446
|
+
var shortened = /* @__PURE__ */ new WeakMap();
|
|
2447
|
+
var viewerOf = /* @__PURE__ */ __name(async (run) => {
|
|
2448
|
+
const { viewer, note } = await crmViewerOf(run.store, run.account, run.user);
|
|
2449
|
+
if (note)
|
|
2450
|
+
shortened.set(run, note);
|
|
2451
|
+
return viewer;
|
|
2452
|
+
}, "viewerOf");
|
|
2453
|
+
var withReadableDeal = /* @__PURE__ */ __name(async (store, viewers, row) => {
|
|
2454
|
+
const limiting = viewers.filter((one) => one !== void 0);
|
|
2455
|
+
if (row.deal === null || limiting.length === 0)
|
|
2456
|
+
return row;
|
|
2457
|
+
const target = await store.deals.get(row.deal).catch(() => void 0);
|
|
2458
|
+
const seen = target !== void 0 && limiting.every((viewer) => seenBy(viewer, {
|
|
2459
|
+
provider: target.account?.provider,
|
|
2460
|
+
account: target.account?.account,
|
|
2461
|
+
assignee: target.assignee
|
|
2462
|
+
}));
|
|
2463
|
+
return seen ? row : { ...row, deal: null };
|
|
2464
|
+
}, "withReadableDeal");
|
|
2465
|
+
var ownerOf = /* @__PURE__ */ __name(async (run, owner) => {
|
|
2466
|
+
if (owner === "none")
|
|
2467
|
+
return null;
|
|
2468
|
+
if (owner === "me") {
|
|
2469
|
+
const self = run.user ?? await run.store.crm.ownUser(run.account);
|
|
2470
|
+
if (!self)
|
|
2471
|
+
throw new CliError("validation_error", "this CRM names no user for the sign-in: use owner:<user id>", {
|
|
2472
|
+
reason: "crm.owner-unknown"
|
|
2473
|
+
});
|
|
2474
|
+
return crmIdentityId(run.account, normalCrmUserId(self), "user");
|
|
2475
|
+
}
|
|
2476
|
+
if (!isCrmUserId(owner))
|
|
2477
|
+
throw new CliError("validation_error", `owner takes me, none or the CRM's user id, not ${owner}`, {
|
|
2478
|
+
reason: "crm.owner-unknown"
|
|
2479
|
+
});
|
|
2480
|
+
return crmIdentityId(run.account, normalCrmUserId(owner), "user");
|
|
2481
|
+
}, "ownerOf");
|
|
2482
|
+
|
|
2483
|
+
// node_modules/.pnpm/@wirecat+cli-core@0.691.0_@wirecat+cli-base@0.113.0_commander@15.0.0_esbuild@0.28.2_typ_9a2e508bb6f63e7e29f0d776540ec8fd/node_modules/@wirecat/cli-core/dist/crm/sync.js
|
|
2484
|
+
var DAY2 = 864e5;
|
|
2485
|
+
var CLOCK_MARGIN = 60 * 6e4;
|
|
2486
|
+
var MOST_UNLISTED = 0.5;
|
|
2487
|
+
var GUARDED_FROM = 10;
|
|
2488
|
+
var isToken = /* @__PURE__ */ __name((value) => value === null || typeof value === "string", "isToken");
|
|
2489
|
+
var parseCrmCursor = /* @__PURE__ */ __name((value) => {
|
|
2490
|
+
if (value == null)
|
|
2491
|
+
return null;
|
|
2492
|
+
try {
|
|
2493
|
+
const cursor = JSON.parse(value);
|
|
2494
|
+
if (cursor?.v !== 1 || !isToken(cursor.token) || typeof cursor.done !== "number")
|
|
2495
|
+
return null;
|
|
2496
|
+
const round = cursor.round;
|
|
2497
|
+
const pass = cursor.pass;
|
|
2498
|
+
if (round != null && (!isToken(round.from) || !isToken(round.page) || typeof round.reset !== "boolean"))
|
|
2499
|
+
return null;
|
|
2500
|
+
if (pass != null && (!isToken(pass.page) || typeof pass.startedAt !== "number" || !Array.isArray(pass.seen) || pass.seen.some((id2) => typeof id2 !== "string")))
|
|
2501
|
+
return null;
|
|
2502
|
+
return {
|
|
2503
|
+
v: 1,
|
|
2504
|
+
token: cursor.token,
|
|
2505
|
+
round: round ?? null,
|
|
2506
|
+
done: cursor.done,
|
|
2507
|
+
updatedAt: typeof cursor.updatedAt === "number" ? cursor.updatedAt : null,
|
|
2508
|
+
pass: pass ?? null,
|
|
2509
|
+
passAt: typeof cursor.passAt === "number" ? cursor.passAt : 0,
|
|
2510
|
+
...typeof cursor.scope === "string" ? { scope: cursor.scope } : {},
|
|
2511
|
+
...cursor.narrowing === true ? { narrowing: true } : {}
|
|
2512
|
+
};
|
|
2513
|
+
} catch {
|
|
2514
|
+
return null;
|
|
2515
|
+
}
|
|
2516
|
+
}, "parseCrmCursor");
|
|
2517
|
+
var cursorName = /* @__PURE__ */ __name((kind) => `crm:${kind}`, "cursorName");
|
|
2518
|
+
var CONTINUE = "run sync again to continue";
|
|
2519
|
+
var fresh = /* @__PURE__ */ __name(() => ({ v: 1, token: null, round: null, done: 0, updatedAt: null, pass: null, passAt: 0 }), "fresh");
|
|
2520
|
+
var GAPS = "crm:gaps";
|
|
2521
|
+
var BudgetSpent = class extends Error {
|
|
2522
|
+
static {
|
|
2523
|
+
__name(this, "BudgetSpent");
|
|
2524
|
+
}
|
|
2525
|
+
why;
|
|
2526
|
+
constructor(why) {
|
|
2527
|
+
super(`the run's budget is spent: ${why}`);
|
|
2528
|
+
this.why = why;
|
|
2529
|
+
}
|
|
2530
|
+
};
|
|
2531
|
+
var scopeOf = /* @__PURE__ */ __name((error) => {
|
|
2532
|
+
const scope = error instanceof CliError ? error.details?.scope : void 0;
|
|
2533
|
+
return typeof scope === "string" && scope ? scope : void 0;
|
|
2534
|
+
}, "scopeOf");
|
|
2535
|
+
var refusal = /* @__PURE__ */ __name((kind, consequence, error, provider) => {
|
|
2536
|
+
const code = error instanceof CliError ? error.code : "error";
|
|
2537
|
+
const scope = scopeOf(error);
|
|
2538
|
+
const message = scope ? `${scope} scope missing: ${consequence}` : `${provider} did not list ${kind} (${code}): ${consequence}`;
|
|
2539
|
+
return { kind, reason: "refused", code, ...scope ? { scope } : {}, message };
|
|
2540
|
+
}, "refusal");
|
|
2541
|
+
var readPipelines = /* @__PURE__ */ __name(async (run, kind) => {
|
|
2542
|
+
const why = run.budget.take();
|
|
2543
|
+
if (why)
|
|
2544
|
+
return why;
|
|
2545
|
+
const pipelines = await run.source.pipelines(kind, run.context);
|
|
2546
|
+
const { saved, skipped } = await run.store.crm.savePipelines(run.account, kind, pipelines);
|
|
2547
|
+
run.report.pipelines += saved;
|
|
2548
|
+
for (const one of skipped)
|
|
2549
|
+
run.report.issues.push({ kind, ...one });
|
|
2550
|
+
return null;
|
|
2551
|
+
}, "readPipelines");
|
|
2552
|
+
var noted = /* @__PURE__ */ __name((run, kind, saved) => {
|
|
2553
|
+
for (const { externalId, ...one } of saved.issues ?? [])
|
|
2554
|
+
run.report.issues.push({ kind, ...one, ...externalId ? { externalId } : {} });
|
|
2555
|
+
run.report.skippedOwnerRejected += saved.skippedOwnerRejected ?? 0;
|
|
2556
|
+
run.unlistedUsers += saved.unlistedUsers ?? 0;
|
|
2557
|
+
run.droppedPending += saved.droppedPending ?? 0;
|
|
2558
|
+
}, "noted");
|
|
2559
|
+
var readUsers = /* @__PURE__ */ __name(async (run) => {
|
|
2560
|
+
const { source } = run;
|
|
2561
|
+
const gap = /* @__PURE__ */ __name((one) => {
|
|
2562
|
+
run.gaps.push(one);
|
|
2563
|
+
run.report.issues.push({ kind: "user", reason: "crm.not-reported", message: one.message });
|
|
2564
|
+
}, "gap");
|
|
2565
|
+
if (!source.users) {
|
|
2566
|
+
run.gaps.push({
|
|
2567
|
+
kind: "users",
|
|
2568
|
+
reason: "not-listed",
|
|
2569
|
+
message: `${source.provider} lists no users: deal owners, employees and reporting lines are unknown`
|
|
2570
|
+
});
|
|
2571
|
+
return null;
|
|
2572
|
+
}
|
|
2573
|
+
const why = run.budget.take();
|
|
2574
|
+
if (why)
|
|
2575
|
+
return why;
|
|
2576
|
+
let users;
|
|
2577
|
+
try {
|
|
2578
|
+
users = await source.users(run.context);
|
|
2579
|
+
} catch (error) {
|
|
2580
|
+
if (run.signal?.aborted || error instanceof BudgetSpent)
|
|
2581
|
+
throw error;
|
|
2582
|
+
gap(refusal("users", "nothing stored about them changed", error, source.provider));
|
|
2583
|
+
return null;
|
|
2584
|
+
}
|
|
2585
|
+
let departments;
|
|
2586
|
+
if (!source.departments)
|
|
2587
|
+
gap({
|
|
2588
|
+
kind: "departments",
|
|
2589
|
+
reason: "not-listed",
|
|
2590
|
+
message: `${source.provider} lists no departments: who reports to whom is unknown`
|
|
2591
|
+
});
|
|
2592
|
+
else {
|
|
2593
|
+
const stop = run.budget.take();
|
|
2594
|
+
if (stop)
|
|
2595
|
+
return stop;
|
|
2596
|
+
try {
|
|
2597
|
+
departments = await source.departments(run.context);
|
|
2598
|
+
} catch (error) {
|
|
2599
|
+
if (run.signal?.aborted || error instanceof BudgetSpent)
|
|
2600
|
+
throw error;
|
|
2601
|
+
gap(refusal("departments", "reporting lines unknown", error, source.provider));
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
noted(run, "user", await run.store.crm.saveUsers(run.account, users, departments));
|
|
2605
|
+
run.report.users = users.length;
|
|
2606
|
+
return null;
|
|
2607
|
+
}, "readUsers");
|
|
2608
|
+
var ACTIVITIES = "crm:activities";
|
|
2609
|
+
var ACTIVITY_DAYS = 90;
|
|
2610
|
+
var activityCursor = /* @__PURE__ */ __name((value) => {
|
|
2611
|
+
try {
|
|
2612
|
+
const parsed = value === void 0 ? void 0 : JSON.parse(value);
|
|
2613
|
+
return typeof parsed?.since === "number" ? parsed : void 0;
|
|
2614
|
+
} catch {
|
|
2615
|
+
return void 0;
|
|
2616
|
+
}
|
|
2617
|
+
}, "activityCursor");
|
|
2618
|
+
var readActivities = /* @__PURE__ */ __name(async (run) => {
|
|
2619
|
+
const { source, store, account } = run;
|
|
2620
|
+
if (!source.activities || !await store.crm.activitiesOn(account))
|
|
2621
|
+
return null;
|
|
2622
|
+
const read2 = { saved: 0, outOfScope: 0, state: "partial" };
|
|
2623
|
+
run.report.activities = read2;
|
|
2624
|
+
const saved = activityCursor((await store.sync.syncState(account, ACTIVITIES))?.value);
|
|
2625
|
+
const cursor = saved ?? { since: run.now - ACTIVITY_DAYS * DAY2, newest: 0 };
|
|
2626
|
+
for (; ; ) {
|
|
2627
|
+
const why = run.budget.take();
|
|
2628
|
+
if (why)
|
|
2629
|
+
return why;
|
|
2630
|
+
let page;
|
|
2631
|
+
try {
|
|
2632
|
+
page = await source.activities.call(source, cursor.since, cursor.page, run.context);
|
|
2633
|
+
} catch (error) {
|
|
2634
|
+
if (run.signal?.aborted || error instanceof BudgetSpent)
|
|
2635
|
+
throw error;
|
|
2636
|
+
if (!scopeOf(error))
|
|
2637
|
+
throw error;
|
|
2638
|
+
run.gaps.push(refusal("activities", "no activity or task was read", error, source.provider));
|
|
2639
|
+
return null;
|
|
2640
|
+
}
|
|
2641
|
+
const done = await store.crm.saveActivities(account, page.items);
|
|
2642
|
+
read2.saved += done.saved;
|
|
2643
|
+
read2.outOfScope += done.outOfScope;
|
|
2644
|
+
cursor.newest = Math.max(cursor.newest, ...page.items.map((one) => one.updatedAt));
|
|
2645
|
+
run.moved();
|
|
2646
|
+
if (page.hasMore && page.nextCursor !== void 0) {
|
|
2647
|
+
cursor.page = page.nextCursor;
|
|
2648
|
+
await store.sync.setSyncState(account, ACTIVITIES, JSON.stringify(cursor));
|
|
2649
|
+
if (run.signal?.aborted)
|
|
2650
|
+
return "cancelled";
|
|
2651
|
+
continue;
|
|
2652
|
+
}
|
|
2653
|
+
const next = page.cursor != null ? Number(page.cursor) : cursor.newest || cursor.since;
|
|
2654
|
+
await store.sync.setSyncState(account, ACTIVITIES, JSON.stringify({ since: next, newest: 0 }));
|
|
2655
|
+
read2.state = "complete";
|
|
2656
|
+
return null;
|
|
2657
|
+
}
|
|
2658
|
+
}, "readActivities");
|
|
2659
|
+
var STAGE_HISTORY = "crm:stage-history:";
|
|
2660
|
+
var HISTORY_DAYS = ACTIVITY_DAYS;
|
|
2661
|
+
var readStageHistory = /* @__PURE__ */ __name(async (run) => {
|
|
2662
|
+
const { source, store, account } = run;
|
|
2663
|
+
if (!source.stageHistory)
|
|
2664
|
+
return null;
|
|
2665
|
+
const since = run.now - HISTORY_DAYS * DAY2;
|
|
2666
|
+
for (const kind of DEAL_KINDS.filter((one) => source.traits.kinds.includes(one))) {
|
|
2667
|
+
const key = `${STAGE_HISTORY}${kind}`;
|
|
2668
|
+
let after = (await store.sync.syncState(account, key))?.value;
|
|
2669
|
+
for (; ; ) {
|
|
2670
|
+
const why = run.budget.take();
|
|
2671
|
+
if (why)
|
|
2672
|
+
return why;
|
|
2673
|
+
const page = await source.stageHistory.call(source, kind, since, after, run.context);
|
|
2674
|
+
await store.crm.saveStageEntries(account, page.items);
|
|
2675
|
+
run.moved();
|
|
2676
|
+
const next = page.hasMore ? page.nextCursor : page.cursor ?? after;
|
|
2677
|
+
if (next !== void 0 && next !== null) {
|
|
2678
|
+
after = next;
|
|
2679
|
+
await store.sync.setSyncState(account, key, next);
|
|
2680
|
+
}
|
|
2681
|
+
if (!page.hasMore || page.nextCursor === void 0)
|
|
2682
|
+
break;
|
|
2683
|
+
if (run.signal?.aborted)
|
|
2684
|
+
return "cancelled";
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
await store.crm.expireStageEntries(account);
|
|
2688
|
+
return null;
|
|
2689
|
+
}, "readStageHistory");
|
|
2690
|
+
var stopping = /* @__PURE__ */ __name(async (step) => {
|
|
2691
|
+
try {
|
|
2692
|
+
return await step();
|
|
2693
|
+
} catch (error) {
|
|
2694
|
+
if (error instanceof BudgetSpent)
|
|
2695
|
+
return error.why;
|
|
2696
|
+
throw error;
|
|
2697
|
+
}
|
|
2698
|
+
}, "stopping");
|
|
2699
|
+
var readFields = /* @__PURE__ */ __name(async (run, kind) => {
|
|
2700
|
+
const why = run.budget.take();
|
|
2701
|
+
if (why)
|
|
2702
|
+
return why;
|
|
2703
|
+
const fields = await run.source.fields.call(run.source, kind, run.context);
|
|
2704
|
+
const { skipped } = await run.store.crm.saveFields(run.account, kind, fields);
|
|
2705
|
+
for (const one of skipped)
|
|
2706
|
+
run.report.issues.push({ kind, ...one });
|
|
2707
|
+
return null;
|
|
2708
|
+
}, "readFields");
|
|
2709
|
+
var savePage = /* @__PURE__ */ __name(async (run, kind, page) => {
|
|
2710
|
+
const { store, account } = run;
|
|
2711
|
+
if (!isItemKind(kind)) {
|
|
2712
|
+
const saved2 = kind === "person" ? await store.crm.savePeople(account, page.items) : await store.crm.saveOrganizations(account, page.items);
|
|
2713
|
+
noted(run, kind, saved2);
|
|
2714
|
+
return { saved: saved2.saved, stop: null };
|
|
2715
|
+
}
|
|
2716
|
+
const items = page.items;
|
|
2717
|
+
const users = { users: run.source.users !== void 0 };
|
|
2718
|
+
const first = await store.crm.saveItems(account, kind, items, users);
|
|
2719
|
+
noted(run, kind, first);
|
|
2720
|
+
let { saved, skipped } = first;
|
|
2721
|
+
let stop = null;
|
|
2722
|
+
if (skipped.some(({ reason }) => reason === "crm.stage-unknown") && !run.pipelinesReread.has(kind)) {
|
|
2723
|
+
run.pipelinesReread.add(kind);
|
|
2724
|
+
stop = await readPipelines(run, kind);
|
|
2725
|
+
if (!stop) {
|
|
2726
|
+
const again = new Set(skipped.filter(({ reason }) => reason === "crm.stage-unknown").map(({ externalId }) => externalId));
|
|
2727
|
+
const retried = await store.crm.saveItems(account, kind, items.filter(({ externalId }) => again.has(externalId)), users);
|
|
2728
|
+
noted(run, kind, retried);
|
|
2729
|
+
saved += retried.saved;
|
|
2730
|
+
skipped = [...skipped.filter(({ reason }) => reason !== "crm.stage-unknown"), ...retried.skipped];
|
|
2731
|
+
}
|
|
2732
|
+
}
|
|
2733
|
+
for (const one of skipped)
|
|
2734
|
+
run.report.issues.push({ kind, ...one });
|
|
2735
|
+
return { saved, stop };
|
|
2736
|
+
}, "savePage");
|
|
2737
|
+
var scopeIds = /* @__PURE__ */ __name((scope) => scope.mode === "all" ? null : [...new Set(scope.also.length ? scope.also : [scope.self])].sort(), "scopeIds");
|
|
2738
|
+
var scopeKey = /* @__PURE__ */ __name((scope) => {
|
|
2739
|
+
const ids2 = scopeIds(scope);
|
|
2740
|
+
return ids2 ? `mine:${ids2.join(",")}` : "all";
|
|
2741
|
+
}, "scopeKey");
|
|
2742
|
+
var idsOfKey = /* @__PURE__ */ __name((key) => key.startsWith("mine:") ? key.slice(5).split(",") : null, "idsOfKey");
|
|
2743
|
+
var appliedScope = /* @__PURE__ */ __name((cursor) => {
|
|
2744
|
+
if (cursor === null)
|
|
2745
|
+
return null;
|
|
2746
|
+
const users = idsOfKey(cursor.scope ?? "all");
|
|
2747
|
+
return users === null ? { mode: "all" } : { mode: "mine", users };
|
|
2748
|
+
}, "appliedScope");
|
|
2749
|
+
var inScope = /* @__PURE__ */ __name((ids2, item) => ids2 === null || item.assignee == null || ids2.includes(item.assignee), "inScope");
|
|
2750
|
+
var normalAssignee = /* @__PURE__ */ __name((item) => item.assignee == null ? item : { ...item, assignee: normalCrmUserId(item.assignee) }, "normalAssignee");
|
|
2751
|
+
var syncKind = /* @__PURE__ */ __name(async (run, kind, options, result) => {
|
|
2752
|
+
const { source, store, account, now, budget, signal } = run;
|
|
2753
|
+
const name = cursorName(kind);
|
|
2754
|
+
let cursor = parseCrmCursor((await store.sync.syncState(account, name))?.value) ?? fresh();
|
|
2755
|
+
if (options.rescan)
|
|
2756
|
+
cursor = { ...cursor, round: { from: null, page: null, reset: false }, done: 0, pass: null, passAt: 0 };
|
|
2757
|
+
const scope = scopeKey(run.scope);
|
|
2758
|
+
const ids2 = isItemKind(kind) ? scopeIds(run.scope) : null;
|
|
2759
|
+
const listedUnder = cursor.scope ?? "all";
|
|
2760
|
+
const before = idsOfKey(listedUnder);
|
|
2761
|
+
const changed = isItemKind(kind) && listedUnder !== scope;
|
|
2762
|
+
let held = false;
|
|
2763
|
+
if (isItemKind(kind) && ids2 && (cursor.narrowing === true || changed && (before === null || before.some((id2) => !ids2.includes(id2))))) {
|
|
2764
|
+
const leaving = await store.crm.removeOutOfScope(account, kind, ids2, { dryRun: true });
|
|
2765
|
+
const stored = await store.crm.count(account, kind);
|
|
2766
|
+
held = !run.scopeSet && leaving > stored * MOST_UNLISTED;
|
|
2767
|
+
if (held) {
|
|
2768
|
+
result.held = true;
|
|
2769
|
+
run.report.issues.push({
|
|
2770
|
+
kind,
|
|
2771
|
+
reason: "crm.narrowing-held",
|
|
2772
|
+
message: `scope mine keeps the ${kind}s of user ${ids2.join(", ")}: ${leaving} of the ${stored} stored would be marked deleted; none was, and none will be until the owner sets ${crmSettingKey(account, "scope")} to mine or all`
|
|
2773
|
+
});
|
|
2774
|
+
} else
|
|
2775
|
+
result.outOfScope += await store.crm.removeOutOfScope(account, kind, ids2);
|
|
2776
|
+
}
|
|
2777
|
+
if (changed || cursor.narrowing) {
|
|
2778
|
+
const widened = changed && before !== null && (ids2 === null || ids2.some((id2) => !before.includes(id2)));
|
|
2779
|
+
const { narrowing: _done, ...rest } = cursor;
|
|
2780
|
+
cursor = {
|
|
2781
|
+
...rest,
|
|
2782
|
+
...widened ? { round: { from: null, page: null, reset: false }, done: 0 } : {},
|
|
2783
|
+
scope,
|
|
2784
|
+
...held ? { narrowing: true } : {}
|
|
2785
|
+
};
|
|
2786
|
+
}
|
|
2787
|
+
let round = cursor.round ?? { from: cursor.token, page: null, reset: false };
|
|
2788
|
+
if (cursor.round === null)
|
|
2789
|
+
cursor = { ...cursor, done: 0 };
|
|
2790
|
+
let listed3 = false;
|
|
2791
|
+
const show = /* @__PURE__ */ __name(() => Object.assign(result, { round: round.from === null ? "full" : "changes", reset: round.reset }), "show");
|
|
2792
|
+
show();
|
|
2793
|
+
const save = /* @__PURE__ */ __name(async (patch = {}) => {
|
|
2794
|
+
cursor = { ...cursor, round: listed3 ? null : round, updatedAt: now, ...patch };
|
|
2795
|
+
await store.sync.setSyncState(account, name, JSON.stringify(cursor));
|
|
2796
|
+
}, "save");
|
|
2797
|
+
let restarted = false;
|
|
2798
|
+
const pages = /* @__PURE__ */ new Set();
|
|
2799
|
+
for (; ; ) {
|
|
2800
|
+
const why = budget.take();
|
|
2801
|
+
if (why)
|
|
2802
|
+
return why;
|
|
2803
|
+
const page = await source.changes(kind, round.from, round.page ?? void 0, run.context);
|
|
2804
|
+
if (signal?.aborted)
|
|
2805
|
+
return "cancelled";
|
|
2806
|
+
if ("reset" in page) {
|
|
2807
|
+
if (round.page !== null && !restarted) {
|
|
2808
|
+
restarted = true;
|
|
2809
|
+
round = { ...round, page: null };
|
|
2810
|
+
} else if (round.from === null)
|
|
2811
|
+
throw new CliError("invalid_response", `${source.provider} refused a full list as a dead cursor`);
|
|
2812
|
+
else
|
|
2813
|
+
round = { from: null, page: null, reset: true };
|
|
2814
|
+
cursor = { ...cursor, done: 0 };
|
|
2815
|
+
show();
|
|
2816
|
+
await save();
|
|
2817
|
+
continue;
|
|
2818
|
+
}
|
|
2819
|
+
const items = isItemKind(kind) ? page.items.map(normalAssignee) : page.items;
|
|
2820
|
+
const kept2 = isItemKind(kind) ? items.filter((item) => inScope(ids2, item)) : items;
|
|
2821
|
+
const { saved, stop } = await savePage(run, kind, { ...page, items: kept2 });
|
|
2822
|
+
result.saved += saved;
|
|
2823
|
+
if (page.removed?.length)
|
|
2824
|
+
result.removed += await store.crm.remove(account, kind, page.removed);
|
|
2825
|
+
if (kept2.length < items.length && !held) {
|
|
2826
|
+
const left = items.filter((item) => !inScope(ids2, item)).map(({ externalId }) => externalId);
|
|
2827
|
+
result.outOfScope += await store.crm.remove(account, kind, left);
|
|
2828
|
+
}
|
|
2829
|
+
run.moved();
|
|
2830
|
+
if (stop) {
|
|
2831
|
+
await save();
|
|
2832
|
+
return stop;
|
|
2833
|
+
}
|
|
2834
|
+
cursor = { ...cursor, done: cursor.done + saved };
|
|
2835
|
+
if (!page.hasMore) {
|
|
2836
|
+
listed3 = true;
|
|
2837
|
+
await save({ token: page.cursor ?? null });
|
|
2838
|
+
break;
|
|
2839
|
+
}
|
|
2840
|
+
if (page.nextCursor === void 0)
|
|
2841
|
+
throw new CliError("invalid_response", `${source.provider} said there are more pages but gave no cursor`);
|
|
2842
|
+
if (pages.has(page.nextCursor))
|
|
2843
|
+
throw new CliError("invalid_response", `${source.provider} returned the same page twice`);
|
|
2844
|
+
pages.add(page.nextCursor);
|
|
2845
|
+
round = { ...round, page: page.nextCursor };
|
|
2846
|
+
await save();
|
|
2847
|
+
}
|
|
2848
|
+
const passes = source.ids && !source.traits.removedInChanges && kind !== "person";
|
|
2849
|
+
const due = cursor.pass !== null || now - cursor.passAt >= (options.passEvery ?? DAY2);
|
|
2850
|
+
const listedOf = held && ids2 ? { users: ids2 } : {};
|
|
2851
|
+
if (passes && due) {
|
|
2852
|
+
const ids3 = source.ids;
|
|
2853
|
+
let pass = cursor.pass ?? { page: null, startedAt: now, seen: [] };
|
|
2854
|
+
for (; ; ) {
|
|
2855
|
+
const why = budget.take();
|
|
2856
|
+
if (why) {
|
|
2857
|
+
result.pass = "partial";
|
|
2858
|
+
await save({ pass });
|
|
2859
|
+
return why;
|
|
2860
|
+
}
|
|
2861
|
+
const page = await ids3.call(source, kind, pass.page ?? void 0, run.context);
|
|
2862
|
+
if (signal?.aborted)
|
|
2863
|
+
return "cancelled";
|
|
2864
|
+
if (page.hasMore && page.nextCursor === void 0)
|
|
2865
|
+
throw new CliError("invalid_response", `${source.provider} said there are more ids but gave no cursor`);
|
|
2866
|
+
pass = { ...pass, seen: [...pass.seen, ...page.items], page: page.hasMore ? page.nextCursor ?? null : null };
|
|
2867
|
+
run.moved();
|
|
2868
|
+
if (!page.hasMore)
|
|
2869
|
+
break;
|
|
2870
|
+
await save({ pass });
|
|
2871
|
+
}
|
|
2872
|
+
const before2 = pass.startedAt - CLOCK_MARGIN;
|
|
2873
|
+
const stored = await store.crm.count(account, kind);
|
|
2874
|
+
const unlisted = await store.crm.removeUnlisted(account, kind, pass.seen, before2, { ...listedOf, dryRun: true });
|
|
2875
|
+
const emptied = pass.seen.length === 0 && unlisted > 0;
|
|
2876
|
+
if (!options.rescan && (emptied || stored >= GUARDED_FROM && unlisted > stored * MOST_UNLISTED)) {
|
|
2877
|
+
result.pass = "held";
|
|
2878
|
+
run.report.issues.push({
|
|
2879
|
+
kind,
|
|
2880
|
+
reason: "crm.unlisted-held",
|
|
2881
|
+
message: `${source.provider} listed ${pass.seen.length} ${kind} ids, so ${unlisted} of the ${stored} stored would be marked deleted; nothing was \u2014 check the sign-in's rights, then run sync --rescan to let it through`
|
|
2882
|
+
});
|
|
2883
|
+
} else {
|
|
2884
|
+
result.unlisted = await store.crm.removeUnlisted(account, kind, pass.seen, before2, listedOf);
|
|
2885
|
+
result.pass = "complete";
|
|
2886
|
+
}
|
|
2887
|
+
await save({ pass: null, passAt: pass.startedAt });
|
|
2888
|
+
}
|
|
2889
|
+
result.state = "complete";
|
|
2890
|
+
return null;
|
|
2891
|
+
}, "syncKind");
|
|
2892
|
+
var syncCrm = /* @__PURE__ */ __name(async (source, store, account, options = {}) => {
|
|
2893
|
+
const now = options.now ?? Date.now();
|
|
2894
|
+
const budget = options.budget ?? runBudget();
|
|
2895
|
+
const setting2 = await store.crm.scope(account);
|
|
2896
|
+
const self = source.self ? normalCrmUserId(await source.self()) : void 0;
|
|
2897
|
+
if (self !== void 0 && !isCrmUserId(self))
|
|
2898
|
+
throw new CliError("invalid_response", `${source.provider} named its sign-in's user as "${self}", not a user id`);
|
|
2899
|
+
await recordCrmViewer(source, store, account, self);
|
|
2900
|
+
if (self !== void 0) {
|
|
2901
|
+
const owner = await store.crm.ownUser(account);
|
|
2902
|
+
if (owner === void 0)
|
|
2903
|
+
await store.crm.saveOwnUser(account, self);
|
|
2904
|
+
else if (owner !== self) {
|
|
2905
|
+
const setting3 = crmSettingKey(account, "self");
|
|
2906
|
+
throw new CliError("validation_error", `this account's copy is user ${owner}'s, and this sign-in is user ${self}: one copy holds one user's deals, under scope all too, since ${setting3} decides whose deals a later scope mine keeps; "config unset ${setting3}" gives the copy to this sign-in`, { setting: setting3 });
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
const listed3 = setting2.mode === "mine" ? setting2.also.map(normalCrmUserId) : [];
|
|
2910
|
+
const allowed = self !== void 0 && source.unassigned && listed3.length && listed3.every(isCrmUserId) ? await source.unassigned(listed3) : { kept: listed3 };
|
|
2911
|
+
const dropped = listed3.filter((id2) => !allowed.kept.includes(id2));
|
|
2912
|
+
const scope = self !== void 0 && setting2.mode === "mine" ? { mode: "mine", self, also: listed3.filter((id2) => !dropped.includes(id2)) } : { mode: "all" };
|
|
2913
|
+
const report = {
|
|
2914
|
+
provider: source.provider,
|
|
2915
|
+
account: account.account,
|
|
2916
|
+
scope,
|
|
2917
|
+
pipelines: 0,
|
|
2918
|
+
skippedOwnerRejected: 0,
|
|
2919
|
+
synced: [],
|
|
2920
|
+
issues: [],
|
|
2921
|
+
complete: true,
|
|
2922
|
+
state: "complete",
|
|
2923
|
+
progress: { requests: 0, saved: 0, steps: 0 }
|
|
2924
|
+
};
|
|
2925
|
+
if (dropped.length)
|
|
2926
|
+
report.issues.push({
|
|
2927
|
+
kind: "deal",
|
|
2928
|
+
reason: "crm.unassigned-dropped",
|
|
2929
|
+
message: `${crmSettingKey(account, "unassigned")} names user ${dropped.join(", ")}, not chosen: ${allowed.message ?? `${source.provider} refused them`}; their deals and leads are not copied`
|
|
2930
|
+
});
|
|
2931
|
+
let steps = 0;
|
|
2932
|
+
const run = {
|
|
2933
|
+
source,
|
|
2934
|
+
scope,
|
|
2935
|
+
scopeSet: setting2.mode === "mine" && setting2.explicit,
|
|
2936
|
+
store,
|
|
2937
|
+
account,
|
|
2938
|
+
now,
|
|
2939
|
+
budget,
|
|
2940
|
+
signal: options.signal,
|
|
2941
|
+
report,
|
|
2942
|
+
pipelinesReread: /* @__PURE__ */ new Set(),
|
|
2943
|
+
moved: /* @__PURE__ */ __name(() => {
|
|
2944
|
+
steps += 1;
|
|
2945
|
+
}, "moved"),
|
|
2946
|
+
gaps: CRM_KINDS.filter((kind) => !source.traits.kinds.includes(kind)).map((kind) => ({
|
|
2947
|
+
kind,
|
|
2948
|
+
reason: "not-listed",
|
|
2949
|
+
message: `${source.provider} has no ${kind}s`
|
|
2950
|
+
})),
|
|
2951
|
+
context: {
|
|
2952
|
+
spend: /* @__PURE__ */ __name(() => {
|
|
2953
|
+
const why = budget.take();
|
|
2954
|
+
if (why)
|
|
2955
|
+
throw new BudgetSpent(why);
|
|
2956
|
+
}, "spend"),
|
|
2957
|
+
gap: /* @__PURE__ */ __name(({ kind, message, scope: scope2 }) => run.gaps.push({ kind, reason: "partial", message, ...scope2 ? { scope: scope2 } : {} }), "gap"),
|
|
2958
|
+
scope
|
|
2959
|
+
},
|
|
2960
|
+
unlistedUsers: 0,
|
|
2961
|
+
droppedPending: 0
|
|
2962
|
+
};
|
|
2963
|
+
const kinds = CRM_KINDS.filter((kind) => source.traits.kinds.includes(kind));
|
|
2964
|
+
const cursors = await Promise.all(kinds.map((kind) => store.sync.syncState(account, cursorName(kind))));
|
|
2965
|
+
const first = cursors.every((cursor) => cursor === void 0);
|
|
2966
|
+
const malformed = scope.mode === "mine" && setting2.mode === "mine" ? setting2.also.find((id2) => !isCrmUserId(id2)) : void 0;
|
|
2967
|
+
let stopped = null;
|
|
2968
|
+
for (const kind of DEAL_KINDS)
|
|
2969
|
+
if (!stopped && kinds.includes(kind)) {
|
|
2970
|
+
stopped = await stopping(() => readPipelines(run, kind));
|
|
2971
|
+
if (options.signal?.aborted)
|
|
2972
|
+
stopped = "cancelled";
|
|
2973
|
+
}
|
|
2974
|
+
if (run.source.fields) {
|
|
2975
|
+
for (const kind of kinds)
|
|
2976
|
+
if (!stopped) {
|
|
2977
|
+
stopped = await stopping(() => readFields(run, kind));
|
|
2978
|
+
if (options.signal?.aborted)
|
|
2979
|
+
stopped = "cancelled";
|
|
2980
|
+
}
|
|
2981
|
+
}
|
|
2982
|
+
let usersRead = false;
|
|
2983
|
+
for (const kind of kinds) {
|
|
2984
|
+
if (!usersRead && isItemKind(kind)) {
|
|
2985
|
+
usersRead = true;
|
|
2986
|
+
if (!stopped)
|
|
2987
|
+
stopped = await stopping(() => readUsers(run));
|
|
2988
|
+
}
|
|
2989
|
+
const result = {
|
|
2990
|
+
kind,
|
|
2991
|
+
round: "changes",
|
|
2992
|
+
reset: false,
|
|
2993
|
+
state: "partial",
|
|
2994
|
+
saved: 0,
|
|
2995
|
+
removed: 0,
|
|
2996
|
+
unlisted: 0,
|
|
2997
|
+
outOfScope: 0
|
|
2998
|
+
};
|
|
2999
|
+
report.synced.push(result);
|
|
3000
|
+
if (stopped)
|
|
3001
|
+
continue;
|
|
3002
|
+
if (malformed !== void 0 && isItemKind(kind)) {
|
|
3003
|
+
Object.assign(result, {
|
|
3004
|
+
error: `unassigned holds "${malformed}", not a numeric user id: no ${kind} was read`,
|
|
3005
|
+
setting: crmSettingKey(account, "unassigned")
|
|
3006
|
+
});
|
|
3007
|
+
continue;
|
|
3008
|
+
}
|
|
3009
|
+
try {
|
|
3010
|
+
stopped = await syncKind(run, kind, options, result);
|
|
3011
|
+
if (kind === "organization")
|
|
3012
|
+
noted(run, kind, await store.crm.saveCompanyTypes(account));
|
|
3013
|
+
} catch (error) {
|
|
3014
|
+
if (options.signal?.aborted) {
|
|
3015
|
+
stopped = "cancelled";
|
|
3016
|
+
continue;
|
|
3017
|
+
}
|
|
3018
|
+
if (error instanceof BudgetSpent) {
|
|
3019
|
+
stopped = error.why;
|
|
3020
|
+
continue;
|
|
3021
|
+
}
|
|
3022
|
+
if (scopeOf(error))
|
|
3023
|
+
run.gaps.push(refusal(kind, `no ${kind} was read`, error, source.provider));
|
|
3024
|
+
result.error = isCliFailure(error) ? error.message : `the ${kind} copy could not be synced`;
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
run.droppedPending += (await store.crm.retryPending(account)).dropped;
|
|
3028
|
+
const rowsStopped = stopped;
|
|
3029
|
+
if (!stopped && kinds.some(isItemKind)) {
|
|
3030
|
+
try {
|
|
3031
|
+
stopped = await stopping(() => readActivities(run));
|
|
3032
|
+
} catch (error) {
|
|
3033
|
+
if (options.signal?.aborted)
|
|
3034
|
+
stopped = "cancelled";
|
|
3035
|
+
else
|
|
3036
|
+
report.issues.push({
|
|
3037
|
+
kind: "deal",
|
|
3038
|
+
reason: "crm.activities-failed",
|
|
3039
|
+
message: isCliFailure(error) ? error.message : "the activities could not be read"
|
|
3040
|
+
});
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
3043
|
+
if (!stopped && kinds.some(isItemKind)) {
|
|
3044
|
+
try {
|
|
3045
|
+
stopped = await stopping(() => readStageHistory(run));
|
|
3046
|
+
} catch (error) {
|
|
3047
|
+
if (options.signal?.aborted)
|
|
3048
|
+
stopped = "cancelled";
|
|
3049
|
+
else
|
|
3050
|
+
report.issues.push({
|
|
3051
|
+
kind: "deal",
|
|
3052
|
+
reason: "crm.stage-history-failed",
|
|
3053
|
+
message: isCliFailure(error) ? error.message : "the stage history could not be read"
|
|
3054
|
+
});
|
|
3055
|
+
}
|
|
3056
|
+
}
|
|
3057
|
+
const narrowed = report.synced.some((one) => one.outOfScope > 0);
|
|
3058
|
+
const whole = report.synced.every((one) => one.state === "complete" && one.error === void 0 && !one.held && one.pass !== "held");
|
|
3059
|
+
if (scope.mode === "mine" && (options.rescan || narrowed) && whole && !rowsStopped && kinds.includes("person"))
|
|
3060
|
+
report.contactsRemoved = await store.crm.removeContacts(account, { users: scopeIds(scope) ?? [], before: now });
|
|
3061
|
+
if (run.unlistedUsers)
|
|
3062
|
+
report.issues.push({
|
|
3063
|
+
kind: "deal",
|
|
3064
|
+
reason: "crm.not-reported",
|
|
3065
|
+
message: `${run.unlistedUsers} deal owner(s) are ${source.provider} users this CRM does not list; no owner was stored for them`
|
|
3066
|
+
});
|
|
3067
|
+
if (run.droppedPending)
|
|
3068
|
+
report.issues.push({
|
|
3069
|
+
kind: "deal",
|
|
3070
|
+
reason: "crm.pending-dropped",
|
|
3071
|
+
message: `${run.droppedPending} relationship(s) waited too long for a contact, user or company that never came and were dropped`
|
|
3072
|
+
});
|
|
3073
|
+
await store.sync.setSyncState(account, GAPS, JSON.stringify(run.gaps));
|
|
3074
|
+
report.progress = {
|
|
3075
|
+
requests: budget.used,
|
|
3076
|
+
saved: report.synced.reduce((sum, one) => sum + one.saved, 0),
|
|
3077
|
+
steps
|
|
3078
|
+
};
|
|
3079
|
+
report.complete = report.synced.every((one) => one.state === "complete" && one.error === void 0);
|
|
3080
|
+
report.state = report.complete && stopped === null ? "complete" : "partial";
|
|
3081
|
+
if (stopped)
|
|
3082
|
+
report.stopped = stopped;
|
|
3083
|
+
if (report.state === "partial") {
|
|
3084
|
+
report.complete = false;
|
|
3085
|
+
report.hint = CONTINUE;
|
|
3086
|
+
}
|
|
3087
|
+
const groupHint = first ? await ungroupedHint(store, account) : void 0;
|
|
3088
|
+
if (groupHint)
|
|
3089
|
+
report.groupHint = groupHint;
|
|
3090
|
+
return report;
|
|
3091
|
+
}, "syncCrm");
|
|
3092
|
+
var SYNC_FAILED = "crm:sync-failed";
|
|
3093
|
+
var SYNCED_FROM = "crm:synced-from";
|
|
3094
|
+
var syncRecorded = /* @__PURE__ */ __name(async (...args) => {
|
|
3095
|
+
const [, store, account, options] = args;
|
|
3096
|
+
const at = options?.now ?? Date.now();
|
|
3097
|
+
const record = /* @__PURE__ */ __name((kinds) => store.sync.setSyncState(account, SYNC_FAILED, kinds.length ? JSON.stringify({ at, kinds }) : "").catch(() => void 0), "record");
|
|
3098
|
+
try {
|
|
3099
|
+
const report = await syncCrm(...args);
|
|
3100
|
+
const failed = report.synced.filter((one) => one.error !== void 0).map((one) => one.kind);
|
|
3101
|
+
await record(failed);
|
|
3102
|
+
if (report.state === "complete" && !failed.length)
|
|
3103
|
+
await store.sync.setSyncState(account, SYNCED_FROM, String(at));
|
|
3104
|
+
return report;
|
|
3105
|
+
} catch (error) {
|
|
3106
|
+
await record(["all"]);
|
|
3107
|
+
throw error;
|
|
3108
|
+
}
|
|
3109
|
+
}, "syncRecorded");
|
|
3110
|
+
var crmStatus = /* @__PURE__ */ __name(async (store, account, { profile, now, kinds = CRM_KINDS }) => {
|
|
3111
|
+
const saved = await store.crm.scope(account);
|
|
3112
|
+
const setting2 = { setting: saved.mode, explicit: saved.mode === "all" || saved.explicit };
|
|
3113
|
+
const items = [];
|
|
3114
|
+
for (const kind of kinds) {
|
|
3115
|
+
const cursor = parseCrmCursor((await store.sync.syncState(account, cursorName(kind)))?.value);
|
|
3116
|
+
const progress = progressOf({
|
|
3117
|
+
job: `crm ${kind}`,
|
|
3118
|
+
profile,
|
|
3119
|
+
done: cursor?.done ?? 0,
|
|
3120
|
+
complete: cursor !== null && cursor.round === null && cursor.pass === null,
|
|
3121
|
+
...cursor?.updatedAt == null ? {} : { updatedAt: new Date(cursor.updatedAt).toISOString() },
|
|
3122
|
+
now: new Date(now)
|
|
3123
|
+
});
|
|
3124
|
+
items.push({
|
|
3125
|
+
kind,
|
|
3126
|
+
round: cursor?.round ? cursor.round.from === null ? "full" : "changes" : null,
|
|
3127
|
+
id_pass: cursor?.pass ? "partial" : cursor?.passAt ? new Date(cursor.passAt).toISOString() : null,
|
|
3128
|
+
stored: await store.crm.count(account, kind),
|
|
3129
|
+
...isItemKind(kind) ? { scope: { ...setting2, applied: appliedScope(cursor), ...cursor?.narrowing ? { held: true } : {} } } : {},
|
|
3130
|
+
...progress,
|
|
3131
|
+
line: progressLine(progress)
|
|
3132
|
+
});
|
|
3133
|
+
}
|
|
3134
|
+
return { items, page: 1, limit: Math.max(1, items.length), hasMore: false };
|
|
3135
|
+
}, "crmStatus");
|
|
3136
|
+
|
|
3137
|
+
export {
|
|
3138
|
+
newSendId,
|
|
3139
|
+
newOperationId,
|
|
3140
|
+
OWNER_NOTES,
|
|
3141
|
+
NOT_GROUP_NAMES,
|
|
3142
|
+
inGroupOf,
|
|
3143
|
+
MAIL,
|
|
3144
|
+
groupLockOf,
|
|
3145
|
+
listContextOf,
|
|
3146
|
+
listedAccounts,
|
|
3147
|
+
accountsOfKind,
|
|
3148
|
+
momentOf,
|
|
3149
|
+
dateWindow,
|
|
3150
|
+
parseCrmFileId,
|
|
3151
|
+
withoutFileLinks,
|
|
3152
|
+
foreignContactsPathFor,
|
|
3153
|
+
foreignContacts,
|
|
3154
|
+
refuseForeignClientReads,
|
|
3155
|
+
DEFAULT_PACE,
|
|
3156
|
+
pacePathFor,
|
|
3157
|
+
Pacer,
|
|
3158
|
+
waitForTurn,
|
|
3159
|
+
providerCall,
|
|
3160
|
+
meetingPassageRequest,
|
|
3161
|
+
createMeetingPassageCommand,
|
|
3162
|
+
meetingHitSearchRequest,
|
|
3163
|
+
meetingSearchArguments,
|
|
3164
|
+
meetingSearchMeta,
|
|
3165
|
+
createMeetingSearchCommand,
|
|
3166
|
+
addMeetingCommands,
|
|
3167
|
+
LIST_QUERY_GUIDE,
|
|
3168
|
+
QUERY_ARGUMENT,
|
|
3169
|
+
withQuery,
|
|
3170
|
+
unfilteredQuery,
|
|
3171
|
+
commandPath,
|
|
3172
|
+
listQuery,
|
|
3173
|
+
typedQuery,
|
|
3174
|
+
pageOf,
|
|
3175
|
+
pagedList,
|
|
3176
|
+
queryArgument,
|
|
3177
|
+
negatableOf,
|
|
3178
|
+
nativeTerms,
|
|
3179
|
+
nativeTermLists,
|
|
3180
|
+
queryTerms,
|
|
3181
|
+
timeBounds,
|
|
3182
|
+
searchText,
|
|
3183
|
+
nativeField,
|
|
3184
|
+
termField,
|
|
3185
|
+
queryHelp,
|
|
3186
|
+
holdEnd,
|
|
3187
|
+
floodPathFor,
|
|
3188
|
+
FloodMemory,
|
|
3189
|
+
sendsPathFor,
|
|
3190
|
+
SendJournal,
|
|
3191
|
+
recipientsPathFor,
|
|
3192
|
+
RecipientList,
|
|
3193
|
+
ceilingRefusal,
|
|
3194
|
+
levelRefusal,
|
|
3195
|
+
sendGuard,
|
|
3196
|
+
guardFor,
|
|
3197
|
+
keyedGuard,
|
|
3198
|
+
CRM_ASSIGN_OTHERS_KEY,
|
|
3199
|
+
CRM_WRITE_KEYS,
|
|
3200
|
+
crmAlsoChecks,
|
|
3201
|
+
CRM_WRITE_DEFAULTS,
|
|
3202
|
+
pipelineOf,
|
|
3203
|
+
foldFieldName,
|
|
3204
|
+
fieldNamed,
|
|
3205
|
+
optionOf,
|
|
3206
|
+
fieldPairsOf,
|
|
3207
|
+
createCrmItem,
|
|
3208
|
+
updateCrmItem,
|
|
3209
|
+
moveCrmItem,
|
|
3210
|
+
closeCrmItem,
|
|
3211
|
+
removeCrmItem,
|
|
3212
|
+
RECORD_ID,
|
|
3213
|
+
createCrmRecord,
|
|
3214
|
+
updateCrmRecord,
|
|
3215
|
+
conditionsOf,
|
|
3216
|
+
customNames,
|
|
3217
|
+
filterableFields,
|
|
3218
|
+
withCustomFields,
|
|
3219
|
+
customConditions,
|
|
3220
|
+
wantedCodes,
|
|
3221
|
+
selectedCodes,
|
|
3222
|
+
crmViewerOf,
|
|
3223
|
+
shortened,
|
|
3224
|
+
viewerOf,
|
|
3225
|
+
withReadableDeal,
|
|
3226
|
+
ownerOf,
|
|
3227
|
+
SYNC_FAILED,
|
|
3228
|
+
SYNCED_FROM,
|
|
3229
|
+
syncRecorded,
|
|
3230
|
+
crmStatus,
|
|
3231
|
+
values_exports
|
|
3232
|
+
};
|