@dealmachine/cli 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1141 -0
  3. package/dist/agents/dealmachine-playbook.md +936 -0
  4. package/dist/commands/account.d.ts +5 -0
  5. package/dist/commands/account.d.ts.map +1 -0
  6. package/dist/commands/account.js +17 -0
  7. package/dist/commands/account.js.map +1 -0
  8. package/dist/commands/activity.d.ts +16 -0
  9. package/dist/commands/activity.d.ts.map +1 -0
  10. package/dist/commands/activity.js +110 -0
  11. package/dist/commands/activity.js.map +1 -0
  12. package/dist/commands/addresses.d.ts +9 -0
  13. package/dist/commands/addresses.d.ts.map +1 -0
  14. package/dist/commands/addresses.js +63 -0
  15. package/dist/commands/addresses.js.map +1 -0
  16. package/dist/commands/agents.d.ts +10 -0
  17. package/dist/commands/agents.d.ts.map +1 -0
  18. package/dist/commands/agents.js +115 -0
  19. package/dist/commands/agents.js.map +1 -0
  20. package/dist/commands/comps.d.ts +16 -0
  21. package/dist/commands/comps.d.ts.map +1 -0
  22. package/dist/commands/comps.js +131 -0
  23. package/dist/commands/comps.js.map +1 -0
  24. package/dist/commands/config.d.ts +7 -0
  25. package/dist/commands/config.d.ts.map +1 -0
  26. package/dist/commands/config.js +83 -0
  27. package/dist/commands/config.js.map +1 -0
  28. package/dist/commands/crm.d.ts +122 -0
  29. package/dist/commands/crm.d.ts.map +1 -0
  30. package/dist/commands/crm.js +519 -0
  31. package/dist/commands/crm.js.map +1 -0
  32. package/dist/commands/dev.d.ts +8 -0
  33. package/dist/commands/dev.d.ts.map +1 -0
  34. package/dist/commands/dev.js +102 -0
  35. package/dist/commands/dev.js.map +1 -0
  36. package/dist/commands/dialer.d.ts +79 -0
  37. package/dist/commands/dialer.d.ts.map +1 -0
  38. package/dist/commands/dialer.js +389 -0
  39. package/dist/commands/dialer.js.map +1 -0
  40. package/dist/commands/enrich.d.ts +46 -0
  41. package/dist/commands/enrich.d.ts.map +1 -0
  42. package/dist/commands/enrich.js +649 -0
  43. package/dist/commands/enrich.js.map +1 -0
  44. package/dist/commands/exports.d.ts +13 -0
  45. package/dist/commands/exports.d.ts.map +1 -0
  46. package/dist/commands/exports.js +92 -0
  47. package/dist/commands/exports.js.map +1 -0
  48. package/dist/commands/fields.d.ts +12 -0
  49. package/dist/commands/fields.d.ts.map +1 -0
  50. package/dist/commands/fields.js +43 -0
  51. package/dist/commands/fields.js.map +1 -0
  52. package/dist/commands/filters.d.ts +12 -0
  53. package/dist/commands/filters.d.ts.map +1 -0
  54. package/dist/commands/filters.js +41 -0
  55. package/dist/commands/filters.js.map +1 -0
  56. package/dist/commands/lists.d.ts +62 -0
  57. package/dist/commands/lists.d.ts.map +1 -0
  58. package/dist/commands/lists.js +329 -0
  59. package/dist/commands/lists.js.map +1 -0
  60. package/dist/commands/locations.d.ts +15 -0
  61. package/dist/commands/locations.d.ts.map +1 -0
  62. package/dist/commands/locations.js +68 -0
  63. package/dist/commands/locations.js.map +1 -0
  64. package/dist/commands/login.d.ts +11 -0
  65. package/dist/commands/login.d.ts.map +1 -0
  66. package/dist/commands/login.js +144 -0
  67. package/dist/commands/login.js.map +1 -0
  68. package/dist/commands/logout.d.ts +5 -0
  69. package/dist/commands/logout.d.ts.map +1 -0
  70. package/dist/commands/logout.js +24 -0
  71. package/dist/commands/logout.js.map +1 -0
  72. package/dist/commands/mail.d.ts +112 -0
  73. package/dist/commands/mail.d.ts.map +1 -0
  74. package/dist/commands/mail.js +727 -0
  75. package/dist/commands/mail.js.map +1 -0
  76. package/dist/commands/people.d.ts +36 -0
  77. package/dist/commands/people.d.ts.map +1 -0
  78. package/dist/commands/people.js +226 -0
  79. package/dist/commands/people.js.map +1 -0
  80. package/dist/commands/phones.d.ts +9 -0
  81. package/dist/commands/phones.d.ts.map +1 -0
  82. package/dist/commands/phones.js +53 -0
  83. package/dist/commands/phones.js.map +1 -0
  84. package/dist/commands/properties.d.ts +38 -0
  85. package/dist/commands/properties.d.ts.map +1 -0
  86. package/dist/commands/properties.js +225 -0
  87. package/dist/commands/properties.js.map +1 -0
  88. package/dist/commands/subscription.d.ts +7 -0
  89. package/dist/commands/subscription.d.ts.map +1 -0
  90. package/dist/commands/subscription.js +36 -0
  91. package/dist/commands/subscription.js.map +1 -0
  92. package/dist/commands/tasks.d.ts +28 -0
  93. package/dist/commands/tasks.d.ts.map +1 -0
  94. package/dist/commands/tasks.js +128 -0
  95. package/dist/commands/tasks.js.map +1 -0
  96. package/dist/commands/usage.d.ts +7 -0
  97. package/dist/commands/usage.d.ts.map +1 -0
  98. package/dist/commands/usage.js +41 -0
  99. package/dist/commands/usage.js.map +1 -0
  100. package/dist/commands/whoami.d.ts +9 -0
  101. package/dist/commands/whoami.d.ts.map +1 -0
  102. package/dist/commands/whoami.js +40 -0
  103. package/dist/commands/whoami.js.map +1 -0
  104. package/dist/index.d.ts +3 -0
  105. package/dist/index.d.ts.map +1 -0
  106. package/dist/index.js +1942 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/lib/api.d.ts +53 -0
  109. package/dist/lib/api.d.ts.map +1 -0
  110. package/dist/lib/api.js +110 -0
  111. package/dist/lib/api.js.map +1 -0
  112. package/dist/lib/client.d.ts +18 -0
  113. package/dist/lib/client.d.ts.map +1 -0
  114. package/dist/lib/client.js +88 -0
  115. package/dist/lib/client.js.map +1 -0
  116. package/dist/lib/config.d.ts +22 -0
  117. package/dist/lib/config.d.ts.map +1 -0
  118. package/dist/lib/config.js +65 -0
  119. package/dist/lib/config.js.map +1 -0
  120. package/dist/lib/output.d.ts +36 -0
  121. package/dist/lib/output.d.ts.map +1 -0
  122. package/dist/lib/output.js +164 -0
  123. package/dist/lib/output.js.map +1 -0
  124. package/dist/lib/searchProtocol.d.ts +10 -0
  125. package/dist/lib/searchProtocol.d.ts.map +1 -0
  126. package/dist/lib/searchProtocol.js +46 -0
  127. package/dist/lib/searchProtocol.js.map +1 -0
  128. package/package.json +52 -0
package/dist/index.js ADDED
@@ -0,0 +1,1942 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { login } from './commands/login.js';
4
+ import { logout } from './commands/logout.js';
5
+ import { whoami } from './commands/whoami.js';
6
+ import { configGet, configSet, configPath } from './commands/config.js';
7
+ import { account } from './commands/account.js';
8
+ import { usage } from './commands/usage.js';
9
+ import { agentsGuide, agentsPlaybook } from './commands/agents.js';
10
+ import { propertiesSearch, propertiesCount, propertiesGet, propertiesIds, propertiesExport, } from './commands/properties.js';
11
+ import { peopleSearch, peopleCount, peopleGet, peopleIds, peopleExport, } from './commands/people.js';
12
+ import { enrichAddress, enrichLatLng, enrichApn, enrichEmail, enrichPhone, enrichName, } from './commands/enrich.js';
13
+ import { filters } from './commands/filters.js';
14
+ import { fields } from './commands/fields.js';
15
+ import { activitySearch, activityGet } from './commands/activity.js';
16
+ import { addressesValidate } from './commands/addresses.js';
17
+ import { licenseAdd, licenseList, licenseRemove } from './commands/dev.js';
18
+ import { comps } from './commands/comps.js';
19
+ import { locationsSearch, locationsGet } from './commands/locations.js';
20
+ import { phonesDnc } from './commands/phones.js';
21
+ import { exportsList, exportsGet } from './commands/exports.js';
22
+ import { subscriptionStatus } from './commands/subscription.js';
23
+ import { listsList, listsCreate, listsGet, listsUpdate, listsDelete, listsBuild, listsImport, listsItems, listsAdd, listsRemove, listsExport, } from './commands/lists.js';
24
+ import { tasksList, tasksGet, tasksCreate, tasksUpdate, tasksDelete } from './commands/tasks.js';
25
+ import { crmPipelines, crmOpportunitiesList, crmOpportunitiesGet, crmOpportunitiesCreate, crmOpportunitiesUpdate, crmOpportunitiesDelete, crmOpportunitiesMove, crmTasksList, crmTasksCreate, crmTasksUpdate, crmNotesList, crmNotesCreate, crmNotesUpdate, crmRecordsList, crmRecordsLink, crmRecordsUnlink, crmLabelsList, crmLabelsCreate, crmLabelsUpdate, crmLabelsDelete, crmOpportunityLabelsAdd, crmOpportunityLabelsRemove, crmSubscribersList, crmSubscribersAdd, crmSubscribersRemove, crmActivity, } from './commands/crm.js';
26
+ import { dialerCallsList, dialerCallsGet, dialerCallsStats, dialerNotesList, dialerNotesCreate, dialerNotesDelete, dialerQueuesList, dialerQueuesCreate, dialerQueuesDelete, dialerQueueItemsList, dialerQueueItemsAdd, dialerQueueItemsUpdate, dialerQueueItemsRemove, dialerDispositions, dialerSuppressionList, dialerSuppressionCheck, dialerSuppressionAdd, } from './commands/dialer.js';
27
+ import { mailCampaignsList, mailCampaignsCreate, mailCampaignsGet, mailCampaignsUpdate, mailCampaignsDelete, mailCampaignsSend, mailCampaignsPause, mailCampaignsResume, mailCampaignsRecipients, mailCampaignsAnalytics, mailCampaignsCostEstimate, mailDesignsList, mailDesignsCreate, mailDesignsGet, mailDesignsUpdate, mailDesignsDelete, mailReturnAddressesList, mailReturnAddressesCreate, mailReturnAddressesGet, mailReturnAddressesUpdate, mailReturnAddressesDelete, mailReturnAddressesSetDefault, mailWalletBalance, mailWalletAddFunds, mailWalletTransactions, mailWalletPricing, } from './commands/mail.js';
28
+ const program = new Command();
29
+ program
30
+ .name('dm')
31
+ .description('DealMachine CLI - Property intelligence from the command line')
32
+ .version('0.1.0')
33
+ .option('--quiet', 'Suppress spinners and decorative output (agent-friendly, also DM_QUIET=1)')
34
+ .addHelpText('after', `
35
+ Examples:
36
+ dm login --key dm_sk_live_abc123 Login with an API key
37
+ dm properties search -f query.json Search properties from a file
38
+ dm enrich address "123 Main St" Enrich a single address
39
+ dm lists search --json List all lists as JSON
40
+ dm crm opportunities list --json List CRM opportunities
41
+
42
+ Tip: Every subcommand supports --help with examples.
43
+ Use --json on any command for machine-readable output.
44
+ Pipe JSON via stdin: echo '{}' | dm properties search
45
+
46
+ Agents:
47
+ dm agents guide Print concise agent usage guidance
48
+ dm agents playbook Print the full DealMachine Playbook
49
+
50
+ Agent defaults: use --json and --quiet, fetch filters and fields before searches,
51
+ and count before credit-consuming commands.`);
52
+ // ============================================================================
53
+ // Agent commands
54
+ // ============================================================================
55
+ const agentsCmd = program
56
+ .command('agents')
57
+ .description('Agent bootstrap help and DealMachine Playbook contents')
58
+ .option('--json', 'Output as JSON')
59
+ .addHelpText('after', `
60
+ Examples:
61
+ dm agents Print concise agent usage guidance
62
+ dm agents guide --json Print agent guidance as JSON
63
+ dm agents playbook Print the full DealMachine Playbook
64
+ dm agents skill Alias for dm agents playbook`)
65
+ .action(async (options, command) => {
66
+ await agentsGuide(command.optsWithGlobals());
67
+ });
68
+ agentsCmd
69
+ .command('guide')
70
+ .description('Print concise guidance for agents using the CLI')
71
+ .option('--json', 'Output as JSON')
72
+ .addHelpText('after', `
73
+ Examples:
74
+ dm agents guide Print concise agent usage guidance
75
+ dm agents guide --json Print agent guidance as JSON`)
76
+ .action(async (options, command) => {
77
+ await agentsGuide(command.optsWithGlobals());
78
+ });
79
+ agentsCmd
80
+ .command('playbook')
81
+ .alias('skill')
82
+ .description('Print the bundled DealMachine Playbook for agent workflows')
83
+ .option('--json', 'Output as JSON')
84
+ .addHelpText('after', `
85
+ Examples:
86
+ dm agents playbook Print the full Playbook Markdown
87
+ dm agents playbook --json Print the Playbook as JSON
88
+ dm agents skill Alias for dm agents playbook`)
89
+ .action(async (options, command) => {
90
+ await agentsPlaybook(command.optsWithGlobals());
91
+ });
92
+ // ============================================================================
93
+ // Auth commands
94
+ // ============================================================================
95
+ program
96
+ .command('login')
97
+ .description('Authenticate with your DealMachine account')
98
+ .option('--no-browser', 'Do not automatically open the browser')
99
+ .option('--key <api-key>', 'Login directly with an API key (skips browser)')
100
+ .option('--env <environment>', 'API environment: local or production (default: production)')
101
+ .addHelpText('after', `
102
+ Examples:
103
+ dm login Interactive browser login
104
+ dm login --key dm_sk_live_abc123 Login with an API key (non-interactive)
105
+ dm login --env local --no-browser Login to local env without opening browser`)
106
+ .action(async (options) => {
107
+ if (options.env) {
108
+ process.env.DM_ENV = options.env;
109
+ }
110
+ await login({ noBrowser: options.browser === false, key: options.key, env: options.env });
111
+ });
112
+ program
113
+ .command('logout')
114
+ .description('Remove stored credentials')
115
+ .addHelpText('after', `
116
+ Examples:
117
+ dm logout Remove stored API key and config`)
118
+ .action(async () => {
119
+ await logout();
120
+ });
121
+ program
122
+ .command('whoami')
123
+ .description('Show current authentication status')
124
+ .option('--verify', 'Verify credentials with the API')
125
+ .addHelpText('after', `
126
+ Examples:
127
+ dm whoami Show stored credentials
128
+ dm whoami --verify Verify credentials against the API`)
129
+ .action(async (options) => {
130
+ await whoami(options);
131
+ });
132
+ // ============================================================================
133
+ // Config commands
134
+ // ============================================================================
135
+ const configCmd = program.command('config').description('View and modify configuration');
136
+ configCmd
137
+ .command('get [key]')
138
+ .description('Get a configuration value (or all values)')
139
+ .addHelpText('after', `
140
+ Examples:
141
+ dm config get Show all config values
142
+ dm config get apiEnvironment Show a specific config value`)
143
+ .action(async (key) => {
144
+ await configGet(key);
145
+ });
146
+ configCmd
147
+ .command('set <key> <value>')
148
+ .description('Set a configuration value')
149
+ .addHelpText('after', `
150
+ Examples:
151
+ dm config set apiEnvironment production Switch to production API
152
+ dm config set apiEnvironment local Switch to local API`)
153
+ .action(async (key, value) => {
154
+ await configSet(key, value);
155
+ });
156
+ configCmd
157
+ .command('path')
158
+ .description('Show config file path')
159
+ .addHelpText('after', `
160
+ Examples:
161
+ dm config path Print path to ~/.dealmachine/config.json`)
162
+ .action(async () => {
163
+ await configPath();
164
+ });
165
+ // ============================================================================
166
+ // Account commands
167
+ // ============================================================================
168
+ program
169
+ .command('account')
170
+ .description('Show account information')
171
+ .option('--json', 'Output as JSON')
172
+ .addHelpText('after', `
173
+ Examples:
174
+ dm account Show account details
175
+ dm account --json Show account details as JSON`)
176
+ .action(async (options) => {
177
+ await account();
178
+ });
179
+ program
180
+ .command('usage')
181
+ .description('Show credit usage for current billing cycle')
182
+ .option('--json', 'Output as JSON')
183
+ .addHelpText('after', `
184
+ Examples:
185
+ dm usage Show credit usage summary
186
+ dm usage --json Show credit usage as JSON`)
187
+ .action(async (options) => {
188
+ await usage(options);
189
+ });
190
+ // ============================================================================
191
+ // Subscription commands
192
+ // ============================================================================
193
+ const subscriptionCmd = program
194
+ .command('subscription')
195
+ .alias('sub')
196
+ .description('View subscription status and manage trial');
197
+ subscriptionCmd
198
+ .command('status')
199
+ .description('Show current subscription status, plan, trial, and credit caps')
200
+ .option('--json', 'Output as JSON')
201
+ .addHelpText('after', `
202
+ Examples:
203
+ dm subscription status
204
+ dm subscription status --json
205
+ dm sub status --json`)
206
+ .action(async (options) => {
207
+ await subscriptionStatus(options);
208
+ });
209
+ // ============================================================================
210
+ // Locations commands
211
+ // ============================================================================
212
+ const locationsCmd = program
213
+ .command('locations')
214
+ .alias('loc')
215
+ .description('Search and look up US locations (states, counties, zip codes)');
216
+ locationsCmd
217
+ .command('search')
218
+ .alias('ls')
219
+ .description('Search locations by name')
220
+ .requiredOption('-q, --query <text>', 'Search query (e.g., "Harris", "78704")')
221
+ .option('--type <type>', 'Filter by type: state, county, zip_code')
222
+ .option('--state <code>', 'Filter by state (two-letter abbreviation, e.g., TX)')
223
+ .option('-p, --page <n>', 'Page number')
224
+ .option('--per-page <n>', 'Results per page (max 100)')
225
+ .option('--json', 'Output as JSON')
226
+ .addHelpText('after', `
227
+ Examples:
228
+ dm locations search -q "Harris" --json
229
+ dm locations search -q "787" --type zip_code --state TX
230
+ dm loc search -q "California" --type state --json`)
231
+ .action(async (options) => {
232
+ await locationsSearch(options);
233
+ });
234
+ locationsCmd
235
+ .command('get <locationId>')
236
+ .description('Get a location by ID (e.g., loc_county_48201)')
237
+ .option('--json', 'Output as JSON')
238
+ .addHelpText('after', `
239
+ Examples:
240
+ dm locations get loc_county_48201 --json
241
+ dm locations get loc_state_TX
242
+ dm loc get loc_zip_code_78704 --json`)
243
+ .action(async (locationId, options) => {
244
+ await locationsGet(locationId, options);
245
+ });
246
+ // ============================================================================
247
+ // Phones commands
248
+ // ============================================================================
249
+ const phonesCmd = program.command('phones').description('Phone number utilities (DNC check)');
250
+ phonesCmd
251
+ .command('dnc [phoneNumber]')
252
+ .description('Check Do Not Call registry status for phone numbers')
253
+ .option('--body <json>', 'Request body as JSON string')
254
+ .option('-f, --file <path>', 'Read request body from a JSON file')
255
+ .option('--json', 'Output as JSON')
256
+ .addHelpText('after', `
257
+ Examples:
258
+ dm phones dnc "5125551234" --json
259
+ dm phones dnc --body '{"phones":[{"number":"5125551234"},{"number":"5125559876"}]}'
260
+ dm phones dnc -f phones.json --json`)
261
+ .action(async (phoneNumber, options) => {
262
+ await phonesDnc(phoneNumber, options);
263
+ });
264
+ // ============================================================================
265
+ // Exports commands
266
+ // ============================================================================
267
+ const exportsCmd = program.command('exports').description('View past exports and download files');
268
+ exportsCmd
269
+ .command('list')
270
+ .alias('ls')
271
+ .description('List past exports')
272
+ .option('--limit <n>', 'Number of exports to return (1-100, default 25)')
273
+ .option('--offset <n>', 'Number to skip (default 0)')
274
+ .option('--status <status>', 'Filter by status: pending, processing, completed, failed')
275
+ .option('--json', 'Output as JSON')
276
+ .addHelpText('after', `
277
+ Examples:
278
+ dm exports list --json
279
+ dm exports list --status completed --limit 10
280
+ dm exports ls --status processing`)
281
+ .action(async (options) => {
282
+ await exportsList(options);
283
+ });
284
+ exportsCmd
285
+ .command('get <exportId>')
286
+ .description('Get export details and download URLs')
287
+ .option('--json', 'Output as JSON')
288
+ .addHelpText('after', `
289
+ Examples:
290
+ dm exports get abc-123 --json`)
291
+ .action(async (exportId, options) => {
292
+ await exportsGet(exportId, options);
293
+ });
294
+ // ============================================================================
295
+ // Properties commands
296
+ // ============================================================================
297
+ const propertiesCmd = program
298
+ .command('properties')
299
+ .alias('prop')
300
+ .description('Search and look up properties');
301
+ propertiesCmd
302
+ .command('search')
303
+ .description('Search properties with filters and locations')
304
+ .option('--body <json>', 'Request body as JSON string')
305
+ .option('-f, --file <path>', 'Read request body from a JSON file')
306
+ .option('--include-lists <ids>', 'Comma-separated list IDs to include')
307
+ .option('--exclude-lists <ids>', 'Comma-separated list IDs to exclude')
308
+ .option('--exclude-previously-exported', 'Exclude records already exported by this organization')
309
+ .option('--bigquery-data-environment <n>', 'Query Builder data environment: 1 production, 2 staging, 3 development')
310
+ .option('--json', 'Output as JSON')
311
+ .addHelpText('after', `
312
+ Examples:
313
+ dm properties search --body '{"locations":[{"type":"zip_code","code":"78704"}]}'
314
+ dm properties search -f search-query.json
315
+ dm properties search -f query.json --json
316
+ cat query.json | dm properties search --json`)
317
+ .action(async (options) => {
318
+ await propertiesSearch(options);
319
+ });
320
+ propertiesCmd
321
+ .command('count')
322
+ .description('Count properties matching filters (no credits consumed)')
323
+ .option('--body <json>', 'Request body as JSON string')
324
+ .option('-f, --file <path>', 'Read request body from a JSON file')
325
+ .option('--include-lists <ids>', 'Comma-separated list IDs to include')
326
+ .option('--exclude-lists <ids>', 'Comma-separated list IDs to exclude')
327
+ .option('--exclude-previously-exported', 'Exclude records already exported by this organization')
328
+ .option('--bigquery-data-environment <n>', 'Query Builder data environment: 1 production, 2 staging, 3 development')
329
+ .option('--json', 'Output as JSON')
330
+ .addHelpText('after', `
331
+ Examples:
332
+ dm properties count --body '{"locations":[{"type":"zip_code","code":"78704"}]}'
333
+ dm properties count -f query.json --json`)
334
+ .action(async (options) => {
335
+ await propertiesCount(options);
336
+ });
337
+ propertiesCmd
338
+ .command('get <id>')
339
+ .description('Get a property by ID (e.g., prop_12345)')
340
+ .option('--contact-audience <audience>', 'Include contacts: owners, owners_and_family, renters, residents, all')
341
+ .option('--json', 'Output as JSON')
342
+ .addHelpText('after', `
343
+ Examples:
344
+ dm properties get prop_12345
345
+ dm properties get prop_12345 --contact-audience owners --json`)
346
+ .action(async (id, options) => {
347
+ await propertiesGet(id, options);
348
+ });
349
+ propertiesCmd
350
+ .command('ids [ids...]')
351
+ .description('Get multiple properties by IDs')
352
+ .option('--body <json>', 'Request body as JSON string')
353
+ .option('-f, --file <path>', 'Read request body from a JSON file')
354
+ .option('--contact-audience <audience>', 'Include contacts: owners, owners_and_family, renters, residents, all')
355
+ .option('--json', 'Output as JSON')
356
+ .addHelpText('after', `
357
+ Examples:
358
+ dm properties ids prop_111 prop_222 prop_333 --json
359
+ dm properties ids --body '{"ids":["prop_111","prop_222"]}'`)
360
+ .action(async (ids, options) => {
361
+ await propertiesIds({ ...options, ids: ids.length > 0 ? ids : undefined });
362
+ });
363
+ propertiesCmd
364
+ .command('export')
365
+ .description('Export property-owner contacts as CSV by default (up to 1,000,000 records)')
366
+ .option('--body <json>', 'Request body as JSON string')
367
+ .option('-f, --file <path>', 'Read request body from a JSON file')
368
+ .option('--include-lists <ids>', 'Comma-separated list IDs to include')
369
+ .option('--exclude-lists <ids>', 'Comma-separated list IDs to exclude')
370
+ .option('--exclude-previously-exported', 'Exclude records already exported by this organization')
371
+ .option('--contact-audience <audience>', 'Contact audience: owners (default), owners_and_family, renters, residents, none')
372
+ .option('--anchor <type>', 'Row anchor: person (default owner contacts), phone, email, or property')
373
+ .option('--bigquery-data-environment <n>', 'Query Builder data environment: 1 production, 2 staging, 3 development')
374
+ .option('--require-phone', 'Only include records where the contact has a phone number')
375
+ .option('--require-email', 'Only include records where the contact has an email address')
376
+ .option('--mobile-only', 'Only include mobile phone numbers')
377
+ .option('--landline-only', 'Only include landline phone numbers')
378
+ .option('--scrub-dnc', 'Exclude contacts on the Do Not Call registry')
379
+ .option('--json', 'Output as JSON')
380
+ .addHelpText('after', `
381
+ Examples:
382
+ dm properties export -f query.json --json
383
+ dm properties export -f query.json --require-phone --scrub-dnc
384
+ dm properties export --body '{"locations":[{"type":"state","code":"TX"}]}' --mobile-only
385
+ dm properties export -f query.json --anchor property --contact-audience none`)
386
+ .action(async (options) => {
387
+ await propertiesExport(options);
388
+ });
389
+ // ============================================================================
390
+ // Comps commands
391
+ // ============================================================================
392
+ program
393
+ .command('comps [property_ids...]')
394
+ .description('Find comparable properties (sales comps) for one or more properties')
395
+ .option('--body <json>', 'Request body as JSON string')
396
+ .option('-f, --file <path>', 'Read request body from a JSON file')
397
+ .option('--radius <miles>', 'Search radius in miles (default: 1)')
398
+ .option('--timeframe <period>', 'Timeframe: 3months, 6months, 12months, all (default: 6months)')
399
+ .option('--limit <n>', 'Max comps per property (default: 25, max: 100)')
400
+ .option('--sort-by <field>', 'Sort by: distance, price, date, match (default: match)')
401
+ .option('--sort-direction <dir>', 'Sort direction: asc, desc (default: desc)')
402
+ .option('--include-foreclosures', 'Include foreclosure sales')
403
+ .option('--json', 'Output as JSON')
404
+ .addHelpText('after', `
405
+ Examples:
406
+ dm comps prop_12345 --json
407
+ dm comps prop_111 prop_222 --radius 0.5 --timeframe 3months
408
+ dm comps prop_12345 --sort-by price --sort-direction asc --limit 10
409
+ dm comps --body '{"property_ids":["prop_12345"]}' --include-foreclosures`)
410
+ .action(async (propertyIds, options) => {
411
+ await comps(propertyIds || [], options);
412
+ });
413
+ // ============================================================================
414
+ // Lists commands
415
+ // ============================================================================
416
+ const listsCmd = program.command('lists').description('Manage saved lists');
417
+ listsCmd
418
+ .command('search')
419
+ .alias('ls')
420
+ .description('Search and list all saved lists')
421
+ .option('--search <term>', 'Search lists by name')
422
+ .option('--source-type <type>', 'Filter by source type: properties or people')
423
+ .option('--sort <order>', 'Sort order: newest, oldest, name, count')
424
+ .option('-p, --page <n>', 'Page number')
425
+ .option('--per-page <n>', 'Results per page')
426
+ .option('--json', 'Output as JSON')
427
+ .addHelpText('after', `
428
+ Examples:
429
+ dm lists search List all lists
430
+ dm lists search --source-type properties --sort newest --json
431
+ dm lists search --search "Austin" --per-page 50`)
432
+ .action(async (options) => {
433
+ await listsList(options);
434
+ });
435
+ listsCmd
436
+ .command('create')
437
+ .description('Create a new list')
438
+ .requiredOption('--name <name>', 'List name')
439
+ .option('--source-type <type>', 'Source type: properties or people')
440
+ .option('--ids <csv>', 'Comma-separated record IDs to pre-populate (max 250)')
441
+ .option('--body <json>', 'Request body as JSON (filters/locations)')
442
+ .option('-f, --file <path>', 'Read request body from a JSON file')
443
+ .option('--json', 'Output as JSON')
444
+ .addHelpText('after', `
445
+ Examples:
446
+ dm lists create --name "Austin Leads"
447
+ dm lists create --name "TX Owners" --source-type properties --json
448
+ dm lists create --name "Import" --ids 100,200,300`)
449
+ .action(async (options) => {
450
+ await listsCreate(options);
451
+ });
452
+ listsCmd
453
+ .command('get <id>')
454
+ .description('Get details of a specific list')
455
+ .option('--json', 'Output as JSON')
456
+ .addHelpText('after', `
457
+ Examples:
458
+ dm lists get list_abc123
459
+ dm lists get list_abc123 --json`)
460
+ .action(async (id, options) => {
461
+ await listsGet(id, options);
462
+ });
463
+ listsCmd
464
+ .command('update <id>')
465
+ .description('Update a list')
466
+ .option('--name <name>', 'New list name')
467
+ .option('--json', 'Output as JSON')
468
+ .addHelpText('after', `
469
+ Examples:
470
+ dm lists update list_abc123 --name "Renamed List"`)
471
+ .action(async (id, options) => {
472
+ await listsUpdate(id, options);
473
+ });
474
+ listsCmd
475
+ .command('delete <id>')
476
+ .description('Delete a list and all its items')
477
+ .option('--dry-run', 'Preview what would be deleted without making changes')
478
+ .option('--json', 'Output as JSON')
479
+ .addHelpText('after', `
480
+ Examples:
481
+ dm lists delete list_abc123
482
+ dm lists delete list_abc123 --dry-run Preview deletion
483
+ dm lists delete list_abc123 --json`)
484
+ .action(async (id, options) => {
485
+ if (options.dryRun) {
486
+ console.log(`Would delete list ${id} and all its items.`);
487
+ console.log('No changes made (--dry-run).');
488
+ return;
489
+ }
490
+ await listsDelete(id, options);
491
+ });
492
+ listsCmd
493
+ .command('build <id>')
494
+ .description('Build a list from search filters')
495
+ .option('--body <json>', 'Request body as JSON (filters/locations)')
496
+ .option('-f, --file <path>', 'Read request body from a JSON file')
497
+ .option('--json', 'Output as JSON')
498
+ .addHelpText('after', `
499
+ Examples:
500
+ dm lists build list_abc123 -f filters.json
501
+ dm lists build list_abc123 --body '{"locations":[{"type":"zip_code","code":"78704"}]}'
502
+
503
+ Note: Building is async. Poll status with: dm lists get list_abc123`)
504
+ .action(async (id, options) => {
505
+ await listsBuild(id, options);
506
+ });
507
+ listsCmd
508
+ .command('import <id>')
509
+ .description('Import IDs into a list')
510
+ .option('--ids <csv>', 'Comma-separated list of IDs')
511
+ .option('--source-type <type>', 'Source type: properties or people')
512
+ .option('--body <json>', 'Request body as JSON')
513
+ .option('-f, --file <path>', 'Read request body from a JSON file')
514
+ .option('--json', 'Output as JSON')
515
+ .addHelpText('after', `
516
+ Examples:
517
+ dm lists import list_abc123 --ids 100,200,300 --source-type properties
518
+ dm lists import list_abc123 -f import.json
519
+
520
+ Note: Import is async. Poll status with: dm lists get list_abc123`)
521
+ .action(async (id, options) => {
522
+ await listsImport(id, options);
523
+ });
524
+ listsCmd
525
+ .command('items <id>')
526
+ .description('List items in a list')
527
+ .option('-p, --page <n>', 'Page number')
528
+ .option('--per-page <n>', 'Results per page')
529
+ .option('--json', 'Output as JSON')
530
+ .addHelpText('after', `
531
+ Examples:
532
+ dm lists items list_abc123
533
+ dm lists items list_abc123 --page 2 --per-page 100 --json`)
534
+ .action(async (id, options) => {
535
+ await listsItems(id, options);
536
+ });
537
+ listsCmd
538
+ .command('add <id>')
539
+ .description('Add items to a list')
540
+ .requiredOption('--ids <csv>', 'Comma-separated list of IDs to add')
541
+ .option('--id-type <type>', 'ID type: internal_property_id or internal_person_id')
542
+ .option('--json', 'Output as JSON')
543
+ .addHelpText('after', `
544
+ Examples:
545
+ dm lists add list_abc123 --ids 100,200,300
546
+ dm lists add list_abc123 --ids 100,200 --id-type internal_property_id --json`)
547
+ .action(async (id, options) => {
548
+ await listsAdd(id, options);
549
+ });
550
+ listsCmd
551
+ .command('remove <id>')
552
+ .description('Remove items from a list')
553
+ .requiredOption('--ids <csv>', 'Comma-separated list of IDs to remove')
554
+ .option('--id-type <type>', 'ID type: internal_property_id or internal_person_id')
555
+ .option('--dry-run', 'Preview what would be removed without making changes')
556
+ .option('--json', 'Output as JSON')
557
+ .addHelpText('after', `
558
+ Examples:
559
+ dm lists remove list_abc123 --ids 100,200,300
560
+ dm lists remove list_abc123 --ids 100 --dry-run Preview removal`)
561
+ .action(async (id, options) => {
562
+ if (options.dryRun) {
563
+ const ids = options.ids.split(',').map((s) => s.trim());
564
+ console.log(`Would remove ${ids.length} item(s) from list ${id}.`);
565
+ console.log('No changes made (--dry-run).');
566
+ return;
567
+ }
568
+ await listsRemove(id, options);
569
+ });
570
+ listsCmd
571
+ .command('export <id>')
572
+ .description('Export list items (credits charged per record)')
573
+ .option('--fields <csv>', 'Comma-separated list of fields to export')
574
+ .option('--anchor <type>', 'Anchor type: property or person')
575
+ .option('--json', 'Output as JSON')
576
+ .addHelpText('after', `
577
+ Examples:
578
+ dm lists export list_abc123 --json
579
+ dm lists export list_abc123 --fields name,address,phone --anchor property`)
580
+ .action(async (id, options) => {
581
+ await listsExport(id, options);
582
+ });
583
+ // ============================================================================
584
+ // People commands
585
+ // ============================================================================
586
+ const peopleCmd = program.command('people').description('Search and look up people');
587
+ peopleCmd
588
+ .command('search')
589
+ .description('Search people with filters and locations')
590
+ .option('--body <json>', 'Request body as JSON string')
591
+ .option('-f, --file <path>', 'Read request body from a JSON file')
592
+ .option('--include-lists <ids>', 'Comma-separated list IDs to include')
593
+ .option('--exclude-lists <ids>', 'Comma-separated list IDs to exclude')
594
+ .option('--exclude-previously-exported', 'Exclude records already exported by this organization')
595
+ .option('--bigquery-data-environment <n>', 'Query Builder data environment: 1 production, 2 staging, 3 development')
596
+ .option('--json', 'Output as JSON')
597
+ .addHelpText('after', `
598
+ Examples:
599
+ dm people search -f people-query.json --json
600
+ dm people search --body '{"locations":[{"type":"zip_code","code":"78704"}]}'`)
601
+ .action(async (options) => {
602
+ await peopleSearch(options);
603
+ });
604
+ peopleCmd
605
+ .command('count')
606
+ .description('Count people matching filters (no credits consumed)')
607
+ .option('--body <json>', 'Request body as JSON string')
608
+ .option('-f, --file <path>', 'Read request body from a JSON file')
609
+ .option('--include-lists <ids>', 'Comma-separated list IDs to include')
610
+ .option('--exclude-lists <ids>', 'Comma-separated list IDs to exclude')
611
+ .option('--exclude-previously-exported', 'Exclude records already exported by this organization')
612
+ .option('--bigquery-data-environment <n>', 'Query Builder data environment: 1 production, 2 staging, 3 development')
613
+ .option('--json', 'Output as JSON')
614
+ .addHelpText('after', `
615
+ Examples:
616
+ dm people count -f query.json --json
617
+ dm people count --body '{"locations":[{"type":"state","code":"TX"}]}'`)
618
+ .action(async (options) => {
619
+ await peopleCount(options);
620
+ });
621
+ peopleCmd
622
+ .command('get <id>')
623
+ .description('Get a person by ID (e.g., per_12345)')
624
+ .option('--include-properties', 'Include associated properties')
625
+ .option('--json', 'Output as JSON')
626
+ .addHelpText('after', `
627
+ Examples:
628
+ dm people get per_12345
629
+ dm people get per_12345 --include-properties --json`)
630
+ .action(async (id, options) => {
631
+ await peopleGet(id, options);
632
+ });
633
+ peopleCmd
634
+ .command('ids [ids...]')
635
+ .description('Get multiple people by IDs')
636
+ .option('--body <json>', 'Request body as JSON string')
637
+ .option('-f, --file <path>', 'Read request body from a JSON file')
638
+ .option('--include-properties', 'Include associated properties')
639
+ .option('--json', 'Output as JSON')
640
+ .addHelpText('after', `
641
+ Examples:
642
+ dm people ids per_111 per_222 per_333 --json
643
+ dm people ids --body '{"ids":["per_111","per_222"]}' --include-properties`)
644
+ .action(async (ids, options) => {
645
+ await peopleIds({ ...options, ids: ids.length > 0 ? ids : undefined });
646
+ });
647
+ peopleCmd
648
+ .command('export')
649
+ .description('Export people as CSV (up to 1,000,000 records)')
650
+ .option('--body <json>', 'Request body as JSON string')
651
+ .option('-f, --file <path>', 'Read request body from a JSON file')
652
+ .option('--include-lists <ids>', 'Comma-separated list IDs to include')
653
+ .option('--exclude-lists <ids>', 'Comma-separated list IDs to exclude')
654
+ .option('--exclude-previously-exported', 'Exclude records already exported by this organization')
655
+ .option('--bigquery-data-environment <n>', 'Query Builder data environment: 1 production, 2 staging, 3 development')
656
+ .option('--require-phone', 'Only include records where the contact has a phone number')
657
+ .option('--require-email', 'Only include records where the contact has an email address')
658
+ .option('--mobile-only', 'Only include mobile phone numbers')
659
+ .option('--landline-only', 'Only include landline phone numbers')
660
+ .option('--scrub-dnc', 'Exclude contacts on the Do Not Call registry')
661
+ .option('--json', 'Output as JSON')
662
+ .addHelpText('after', `
663
+ Examples:
664
+ dm people export -f query.json --json
665
+ dm people export -f query.json --require-phone --scrub-dnc`)
666
+ .action(async (options) => {
667
+ await peopleExport(options);
668
+ });
669
+ // ============================================================================
670
+ // Enrichment commands
671
+ // ============================================================================
672
+ const enrichCmd = program
673
+ .command('enrich')
674
+ .description('Enrich data by address, coordinates, email, phone, or name');
675
+ enrichCmd
676
+ .command('address [address]')
677
+ .description('Look up a property by street address')
678
+ .option('--body <json>', 'Request body as JSON string')
679
+ .option('-f, --file <path>', 'Read request body from a JSON file (JSON or CSV)')
680
+ .option('--contact-audience <audience>', 'Include contacts: owners, owners_and_family, renters, residents')
681
+ .option('--json', 'Output as JSON')
682
+ .addHelpText('after', `
683
+ Examples:
684
+ dm enrich address "123 Main St, Austin, TX 78704" --json
685
+ dm enrich address "123 Main St, Austin, TX" --contact-audience owners
686
+ dm enrich address -f addresses.csv --json Batch enrich from CSV
687
+ dm enrich address --body '{"addresses":[{"full_address":"123 Main St, Austin, TX"}]}'`)
688
+ .action(async (address, options) => {
689
+ await enrichAddress(address, options);
690
+ });
691
+ enrichCmd
692
+ .command('latlng [coords]')
693
+ .description('Look up a property by lat,lng coordinates')
694
+ .option('--body <json>', 'Request body as JSON string')
695
+ .option('-f, --file <path>', 'Read request body from a JSON file (JSON or CSV)')
696
+ .option('--contact-audience <audience>', 'Include contacts: owners, owners_and_family, renters, residents')
697
+ .option('--json', 'Output as JSON')
698
+ .addHelpText('after', `
699
+ Examples:
700
+ dm enrich latlng "30.2672,-97.7431" --json
701
+ dm enrich latlng -f coordinates.csv --contact-audience owners`)
702
+ .action(async (coords, options) => {
703
+ await enrichLatLng(coords, options);
704
+ });
705
+ enrichCmd
706
+ .command('apn [apn]')
707
+ .description("Look up a property by Assessor's Parcel Number")
708
+ .option('--body <json>', 'Request body as JSON string')
709
+ .option('-f, --file <path>', 'Read request body from a JSON file (JSON or CSV)')
710
+ .option('--state <code>', 'Narrow by state (e.g., TX)')
711
+ .option('--zip <code>', 'Narrow by ZIP code')
712
+ .option('--contact-audience <audience>', 'Include contacts: owners, owners_and_family, renters, residents')
713
+ .option('--json', 'Output as JSON')
714
+ .addHelpText('after', `
715
+ Examples:
716
+ dm enrich apn "01-2345-0067" --state TX --json
717
+ dm enrich apn -f parcels.csv --state TX`)
718
+ .action(async (apn, options) => {
719
+ await enrichApn(apn, options);
720
+ });
721
+ enrichCmd
722
+ .command('email [email]')
723
+ .description('Look up a person by email address')
724
+ .option('--body <json>', 'Request body as JSON string')
725
+ .option('-f, --file <path>', 'Read request body from a JSON file (JSON or CSV)')
726
+ .option('--include-properties', 'Include associated properties')
727
+ .option('--json', 'Output as JSON')
728
+ .addHelpText('after', `
729
+ Examples:
730
+ dm enrich email "john@example.com" --json
731
+ dm enrich email "john@example.com" --include-properties
732
+ dm enrich email -f emails.csv --json Batch enrich from CSV`)
733
+ .action(async (email, options) => {
734
+ await enrichEmail(email, options);
735
+ });
736
+ enrichCmd
737
+ .command('phone [phone]')
738
+ .description('Look up a person by phone number')
739
+ .option('--body <json>', 'Request body as JSON string')
740
+ .option('-f, --file <path>', 'Read request body from a JSON file (JSON or CSV)')
741
+ .option('--include-properties', 'Include associated properties')
742
+ .option('--json', 'Output as JSON')
743
+ .addHelpText('after', `
744
+ Examples:
745
+ dm enrich phone "5125551234" --json
746
+ dm enrich phone -f phones.csv --include-properties`)
747
+ .action(async (phone, options) => {
748
+ await enrichPhone(phone, options);
749
+ });
750
+ enrichCmd
751
+ .command('name [name]')
752
+ .description('Look up people by name (e.g., "David Oster")')
753
+ .option('--body <json>', 'Request body as JSON string')
754
+ .option('-f, --file <path>', 'Read request body from a JSON file (JSON or CSV)')
755
+ .option('--state <code>', 'Narrow by state (e.g., TX)')
756
+ .option('--zip <code>', 'Narrow by ZIP code')
757
+ .option('--include-properties', 'Include associated properties')
758
+ .option('--page <n>', 'Page number')
759
+ .option('--per-page <n>', 'Results per page')
760
+ .option('--json', 'Output as JSON')
761
+ .addHelpText('after', `
762
+ Examples:
763
+ dm enrich name "David Oster" --state TX --json
764
+ dm enrich name "Jane Smith" --zip 78704 --include-properties
765
+ dm enrich name -f names.csv --state TX`)
766
+ .action(async (name, options) => {
767
+ await enrichName(name, options);
768
+ });
769
+ // ============================================================================
770
+ // Filters & Fields
771
+ // ============================================================================
772
+ program
773
+ .command('filters')
774
+ .description('List available filters for search queries')
775
+ .option('--source-type <type>', 'Filter by source: properties or people')
776
+ .option('--group-id <id>', 'Filter by group ID')
777
+ .option('--search <term>', 'Search filters by name')
778
+ .option('--page <n>', 'Page number')
779
+ .option('--per-page <n>', 'Results per page')
780
+ .option('--json', 'Output as JSON')
781
+ .addHelpText('after', `
782
+ Examples:
783
+ dm filters --json List all filters
784
+ dm filters --source-type properties --search "owner"
785
+ dm filters --source-type people --per-page 100 --json`)
786
+ .action(async (options) => {
787
+ await filters(options);
788
+ });
789
+ program
790
+ .command('fields')
791
+ .description('List available data fields')
792
+ .option('--source-type <type>', 'Filter by source: properties or people')
793
+ .option('--group-id <id>', 'Filter by group ID')
794
+ .option('--search <term>', 'Search fields by name')
795
+ .option('--page <n>', 'Page number')
796
+ .option('--per-page <n>', 'Results per page')
797
+ .option('--json', 'Output as JSON')
798
+ .addHelpText('after', `
799
+ Examples:
800
+ dm fields --json List all fields
801
+ dm fields --source-type properties --search "value"
802
+ dm fields --source-type people --per-page 100 --json`)
803
+ .action(async (options) => {
804
+ await fields(options);
805
+ });
806
+ // ============================================================================
807
+ // Activity commands
808
+ // ============================================================================
809
+ const activityCmd = program.command('activity').description('View API activity history');
810
+ activityCmd
811
+ .command('search')
812
+ .description('Search past API activity')
813
+ .option('--body <json>', 'Request body as JSON string')
814
+ .option('-f, --file <path>', 'Read request body from a JSON file')
815
+ .option('-t, --types <types...>', 'Filter by activity types (e.g., search_properties enrich_address)')
816
+ .option('-q, --query <text>', 'Free-text search across activity')
817
+ .option('--page <n>', 'Page number')
818
+ .option('--per-page <n>', 'Results per page')
819
+ .option('--json', 'Output as JSON')
820
+ .addHelpText('after', `
821
+ Examples:
822
+ dm activity search --json
823
+ dm activity search --types search_properties enrich_address
824
+ dm activity search --query "Austin" --page 2 --json`)
825
+ .action(async (options) => {
826
+ await activitySearch(options);
827
+ });
828
+ activityCmd
829
+ .command('get <id>')
830
+ .description('Get details of a specific activity record')
831
+ .option('--json', 'Output as JSON')
832
+ .addHelpText('after', `
833
+ Examples:
834
+ dm activity get act_abc123 --json`)
835
+ .action(async (id, options) => {
836
+ await activityGet(id, options);
837
+ });
838
+ // ============================================================================
839
+ // Address validation
840
+ // ============================================================================
841
+ const addressesCmd = program.command('addresses').description('Validate and standardize addresses');
842
+ addressesCmd
843
+ .command('validate [address]')
844
+ .description('Validate addresses via USPS')
845
+ .option('--body <json>', 'Request body as JSON string')
846
+ .option('-f, --file <path>', 'Read request body from a JSON file')
847
+ .option('--json', 'Output as JSON')
848
+ .addHelpText('after', `
849
+ Examples:
850
+ dm addresses validate "123 Main St, Austin, TX 78704" --json
851
+ dm addresses validate -f addresses.json`)
852
+ .action(async (address, options) => {
853
+ await addressesValidate(address, options);
854
+ });
855
+ // ============================================================================
856
+ // Tasks commands
857
+ // ============================================================================
858
+ const tasksCmd = program
859
+ .command('tasks')
860
+ .description('Manage tasks (create, list, update, complete, delete)');
861
+ tasksCmd
862
+ .command('list')
863
+ .alias('ls')
864
+ .description('List tasks')
865
+ .option('--status <status>', 'Filter by status: open, completed, all')
866
+ .option('--search <term>', 'Search tasks by title')
867
+ .option('--assigned-to <userId>', 'Filter by assigned user ID')
868
+ .option('-p, --page <n>', 'Page number')
869
+ .option('--per-page <n>', 'Results per page')
870
+ .option('--json', 'Output as JSON')
871
+ .addHelpText('after', `
872
+ Examples:
873
+ dm tasks list --json
874
+ dm tasks list --status open --assigned-to user_123
875
+ dm tasks list --search "follow up" --per-page 50`)
876
+ .action(async (options) => {
877
+ await tasksList({
878
+ status: options.status,
879
+ search: options.search,
880
+ assignedToUserId: options.assignedTo,
881
+ page: options.page,
882
+ perPage: options.perPage,
883
+ json: options.json,
884
+ });
885
+ });
886
+ tasksCmd
887
+ .command('get <id>')
888
+ .description('Get task details')
889
+ .option('--json', 'Output as JSON')
890
+ .addHelpText('after', `
891
+ Examples:
892
+ dm tasks get task_abc123 --json`)
893
+ .action(async (id, options) => {
894
+ await tasksGet(id, options);
895
+ });
896
+ tasksCmd
897
+ .command('create')
898
+ .description('Create a task')
899
+ .option('--body <json>', 'Request body as JSON string')
900
+ .option('-f, --file <path>', 'Read request body from a JSON file')
901
+ .option('--json', 'Output as JSON')
902
+ .addHelpText('after', `
903
+ Examples:
904
+ dm tasks create --body '{"title":"Call owner","due_date":"2025-01-15"}' --json
905
+ dm tasks create -f task.json`)
906
+ .action(async (options) => {
907
+ await tasksCreate(options);
908
+ });
909
+ tasksCmd
910
+ .command('update <id>')
911
+ .description('Update a task')
912
+ .option('--body <json>', 'Request body as JSON string')
913
+ .option('-f, --file <path>', 'Read request body from a JSON file')
914
+ .option('--json', 'Output as JSON')
915
+ .addHelpText('after', `
916
+ Examples:
917
+ dm tasks update task_abc123 --body '{"status":"completed"}' --json`)
918
+ .action(async (id, options) => {
919
+ await tasksUpdate(id, options);
920
+ });
921
+ tasksCmd
922
+ .command('delete <id>')
923
+ .description('Delete a task')
924
+ .option('--dry-run', 'Preview what would be deleted without making changes')
925
+ .option('--json', 'Output as JSON')
926
+ .addHelpText('after', `
927
+ Examples:
928
+ dm tasks delete task_abc123
929
+ dm tasks delete task_abc123 --dry-run Preview deletion`)
930
+ .action(async (id, options) => {
931
+ if (options.dryRun) {
932
+ console.log(`Would delete task ${id}.`);
933
+ console.log('No changes made (--dry-run).');
934
+ return;
935
+ }
936
+ await tasksDelete(id, options);
937
+ });
938
+ // ============================================================================
939
+ // CRM commands
940
+ // ============================================================================
941
+ const crmCmd = program
942
+ .command('crm')
943
+ .description('Manage CRM pipelines, opportunities, tasks, notes, records, and labels');
944
+ crmCmd
945
+ .command('pipelines')
946
+ .description('List pipelines with stages and opportunity counts')
947
+ .option('--json', 'Output as JSON')
948
+ .addHelpText('after', `
949
+ Examples:
950
+ dm crm pipelines --json`)
951
+ .action(async (options) => {
952
+ await crmPipelines(options);
953
+ });
954
+ const crmOppCmd = crmCmd
955
+ .command('opportunities')
956
+ .alias('opp')
957
+ .description('Manage CRM opportunities');
958
+ crmOppCmd
959
+ .command('list')
960
+ .alias('ls')
961
+ .description('List/search opportunities')
962
+ .option('--pipeline-id <id>', 'Filter by pipeline ID')
963
+ .option('--stage-id <id>', 'Filter by stage ID')
964
+ .option('--search <term>', 'Search by name')
965
+ .option('--priority <level>', 'Filter by priority: low, medium, high, urgent')
966
+ .option('-p, --page <n>', 'Page number')
967
+ .option('--per-page <n>', 'Results per page')
968
+ .option('--json', 'Output as JSON')
969
+ .addHelpText('after', `
970
+ Examples:
971
+ dm crm opportunities list --json
972
+ dm crm opp list --pipeline-id pipe_123 --priority high
973
+ dm crm opp ls --search "Main St" --per-page 50`)
974
+ .action(async (options) => {
975
+ await crmOpportunitiesList(options);
976
+ });
977
+ crmOppCmd
978
+ .command('get <id>')
979
+ .description('Get opportunity details')
980
+ .option('--json', 'Output as JSON')
981
+ .addHelpText('after', `
982
+ Examples:
983
+ dm crm opp get opp_abc123 --json`)
984
+ .action(async (id, options) => {
985
+ await crmOpportunitiesGet(id, options);
986
+ });
987
+ crmOppCmd
988
+ .command('create')
989
+ .description('Create an opportunity')
990
+ .option('--body <json>', 'Request body as JSON string')
991
+ .option('-f, --file <path>', 'Read request body from a JSON file')
992
+ .option('--json', 'Output as JSON')
993
+ .addHelpText('after', `
994
+ Examples:
995
+ dm crm opp create --body '{"name":"123 Main St","pipeline_id":"pipe_123","stage_id":"stage_456"}' --json
996
+ dm crm opp create -f opportunity.json`)
997
+ .action(async (options) => {
998
+ await crmOpportunitiesCreate(options);
999
+ });
1000
+ crmOppCmd
1001
+ .command('update <id>')
1002
+ .description('Update an opportunity')
1003
+ .option('--body <json>', 'Request body as JSON string')
1004
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1005
+ .option('--json', 'Output as JSON')
1006
+ .addHelpText('after', `
1007
+ Examples:
1008
+ dm crm opp update opp_abc123 --body '{"priority":"high"}' --json`)
1009
+ .action(async (id, options) => {
1010
+ await crmOpportunitiesUpdate(id, options);
1011
+ });
1012
+ crmOppCmd
1013
+ .command('delete <id>')
1014
+ .description('Delete an opportunity')
1015
+ .option('--dry-run', 'Preview what would be deleted without making changes')
1016
+ .option('--json', 'Output as JSON')
1017
+ .addHelpText('after', `
1018
+ Examples:
1019
+ dm crm opp delete opp_abc123
1020
+ dm crm opp delete opp_abc123 --dry-run Preview deletion`)
1021
+ .action(async (id, options) => {
1022
+ if (options.dryRun) {
1023
+ console.log(`Would delete opportunity ${id}.`);
1024
+ console.log('No changes made (--dry-run).');
1025
+ return;
1026
+ }
1027
+ await crmOpportunitiesDelete(id, options);
1028
+ });
1029
+ crmOppCmd
1030
+ .command('move <id>')
1031
+ .description('Move opportunity to a different stage')
1032
+ .option('--body <json>', 'Request body as JSON string (stage_id required)')
1033
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1034
+ .option('--json', 'Output as JSON')
1035
+ .addHelpText('after', `
1036
+ Examples:
1037
+ dm crm opp move opp_abc123 --body '{"stage_id":"stage_789"}' --json`)
1038
+ .action(async (id, options) => {
1039
+ await crmOpportunitiesMove(id, options);
1040
+ });
1041
+ const crmTaskCmd = crmCmd.command('tasks').description('Manage CRM tasks');
1042
+ crmTaskCmd
1043
+ .command('list <opportunityId>')
1044
+ .alias('ls')
1045
+ .description('List tasks for an opportunity')
1046
+ .option('-p, --page <n>', 'Page number')
1047
+ .option('--per-page <n>', 'Results per page')
1048
+ .option('--json', 'Output as JSON')
1049
+ .addHelpText('after', `
1050
+ Examples:
1051
+ dm crm tasks list opp_abc123 --json`)
1052
+ .action(async (opportunityId, options) => {
1053
+ await crmTasksList(opportunityId, options);
1054
+ });
1055
+ crmTaskCmd
1056
+ .command('create <opportunityId>')
1057
+ .description('Create a task on an opportunity')
1058
+ .option('--body <json>', 'Request body as JSON string')
1059
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1060
+ .option('--json', 'Output as JSON')
1061
+ .addHelpText('after', `
1062
+ Examples:
1063
+ dm crm tasks create opp_abc123 --body '{"title":"Call owner"}' --json`)
1064
+ .action(async (opportunityId, options) => {
1065
+ await crmTasksCreate(opportunityId, options);
1066
+ });
1067
+ crmTaskCmd
1068
+ .command('update <opportunityId> <taskId>')
1069
+ .description('Update a task')
1070
+ .option('--body <json>', 'Request body as JSON string')
1071
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1072
+ .option('--json', 'Output as JSON')
1073
+ .addHelpText('after', `
1074
+ Examples:
1075
+ dm crm tasks update opp_abc123 task_456 --body '{"status":"completed"}' --json`)
1076
+ .action(async (opportunityId, taskId, options) => {
1077
+ await crmTasksUpdate(opportunityId, taskId, options);
1078
+ });
1079
+ const crmNoteCmd = crmCmd.command('notes').description('Manage CRM notes');
1080
+ crmNoteCmd
1081
+ .command('list <opportunityId>')
1082
+ .alias('ls')
1083
+ .description('List notes for an opportunity')
1084
+ .option('-p, --page <n>', 'Page number')
1085
+ .option('--per-page <n>', 'Results per page')
1086
+ .option('--json', 'Output as JSON')
1087
+ .addHelpText('after', `
1088
+ Examples:
1089
+ dm crm notes list opp_abc123 --json`)
1090
+ .action(async (opportunityId, options) => {
1091
+ await crmNotesList(opportunityId, options);
1092
+ });
1093
+ crmNoteCmd
1094
+ .command('create <opportunityId>')
1095
+ .description('Create a note on an opportunity')
1096
+ .option('--body <json>', 'Request body as JSON string')
1097
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1098
+ .option('--json', 'Output as JSON')
1099
+ .addHelpText('after', `
1100
+ Examples:
1101
+ dm crm notes create opp_abc123 --body '{"content":"Spoke with owner, interested in selling."}' --json`)
1102
+ .action(async (opportunityId, options) => {
1103
+ await crmNotesCreate(opportunityId, options);
1104
+ });
1105
+ crmNoteCmd
1106
+ .command('update <opportunityId> <noteId>')
1107
+ .description('Update a note')
1108
+ .option('--body <json>', 'Request body as JSON string')
1109
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1110
+ .option('--json', 'Output as JSON')
1111
+ .addHelpText('after', `
1112
+ Examples:
1113
+ dm crm notes update opp_abc123 note_456 --body '{"content":"Updated note."}' --json`)
1114
+ .action(async (opportunityId, noteId, options) => {
1115
+ await crmNotesUpdate(opportunityId, noteId, options);
1116
+ });
1117
+ const crmRecordCmd = crmCmd
1118
+ .command('records')
1119
+ .description('Manage linked records on opportunities');
1120
+ crmRecordCmd
1121
+ .command('list <opportunityId>')
1122
+ .alias('ls')
1123
+ .description('List records linked to an opportunity')
1124
+ .option('--json', 'Output as JSON')
1125
+ .addHelpText('after', `
1126
+ Examples:
1127
+ dm crm records list opp_abc123 --json`)
1128
+ .action(async (opportunityId, options) => {
1129
+ await crmRecordsList(opportunityId, options);
1130
+ });
1131
+ crmRecordCmd
1132
+ .command('link <opportunityId>')
1133
+ .description('Link a record to an opportunity')
1134
+ .option('--body <json>', 'Request body as JSON string')
1135
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1136
+ .option('--json', 'Output as JSON')
1137
+ .addHelpText('after', `
1138
+ Examples:
1139
+ dm crm records link opp_abc123 --body '{"record_id":"prop_456","record_type":"property"}' --json`)
1140
+ .action(async (opportunityId, options) => {
1141
+ await crmRecordsLink(opportunityId, options);
1142
+ });
1143
+ crmRecordCmd
1144
+ .command('unlink <opportunityId> <recordId>')
1145
+ .description('Unlink a record from an opportunity')
1146
+ .option('--dry-run', 'Preview what would be unlinked without making changes')
1147
+ .option('--json', 'Output as JSON')
1148
+ .addHelpText('after', `
1149
+ Examples:
1150
+ dm crm records unlink opp_abc123 rec_456
1151
+ dm crm records unlink opp_abc123 rec_456 --dry-run`)
1152
+ .action(async (opportunityId, recordId, options) => {
1153
+ if (options.dryRun) {
1154
+ console.log(`Would unlink record ${recordId} from opportunity ${opportunityId}.`);
1155
+ console.log('No changes made (--dry-run).');
1156
+ return;
1157
+ }
1158
+ await crmRecordsUnlink(opportunityId, recordId, options);
1159
+ });
1160
+ const crmLabelCmd = crmCmd.command('labels').description('Manage CRM labels');
1161
+ crmLabelCmd
1162
+ .command('list')
1163
+ .alias('ls')
1164
+ .description('List all CRM labels')
1165
+ .option('--json', 'Output as JSON')
1166
+ .addHelpText('after', `
1167
+ Examples:
1168
+ dm crm labels list --json`)
1169
+ .action(async (options) => {
1170
+ await crmLabelsList(options);
1171
+ });
1172
+ crmLabelCmd
1173
+ .command('create')
1174
+ .description('Create a label')
1175
+ .option('--body <json>', 'Request body as JSON string')
1176
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1177
+ .option('--json', 'Output as JSON')
1178
+ .addHelpText('after', `
1179
+ Examples:
1180
+ dm crm labels create --body '{"name":"Hot Lead","color":"red"}' --json`)
1181
+ .action(async (options) => {
1182
+ await crmLabelsCreate(options);
1183
+ });
1184
+ crmLabelCmd
1185
+ .command('update <id>')
1186
+ .description('Update a label')
1187
+ .option('--body <json>', 'Request body as JSON string')
1188
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1189
+ .option('--json', 'Output as JSON')
1190
+ .addHelpText('after', `
1191
+ Examples:
1192
+ dm crm labels update label_abc123 --body '{"name":"Warm Lead"}' --json`)
1193
+ .action(async (id, options) => {
1194
+ await crmLabelsUpdate(id, options);
1195
+ });
1196
+ crmLabelCmd
1197
+ .command('delete <id>')
1198
+ .description('Delete a label')
1199
+ .option('--dry-run', 'Preview what would be deleted without making changes')
1200
+ .option('--json', 'Output as JSON')
1201
+ .addHelpText('after', `
1202
+ Examples:
1203
+ dm crm labels delete label_abc123
1204
+ dm crm labels delete label_abc123 --dry-run`)
1205
+ .action(async (id, options) => {
1206
+ if (options.dryRun) {
1207
+ console.log(`Would delete label ${id}.`);
1208
+ console.log('No changes made (--dry-run).');
1209
+ return;
1210
+ }
1211
+ await crmLabelsDelete(id, options);
1212
+ });
1213
+ // ── Opportunity Labels (add/remove on opportunities) ──
1214
+ const crmOppLabelCmd = crmOppCmd.command('labels').description('Manage labels on an opportunity');
1215
+ crmOppLabelCmd
1216
+ .command('add <opportunityId>')
1217
+ .description('Add a label to an opportunity')
1218
+ .option('--label-id <id>', 'Label ID to add')
1219
+ .option('--body <json>', 'Request body as JSON string')
1220
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1221
+ .option('--json', 'Output as JSON')
1222
+ .addHelpText('after', `
1223
+ Examples:
1224
+ dm crm opp labels add opp_abc123 --label-id label_456
1225
+ dm crm opp labels add opp_abc123 --body '{"label_id":"label_456"}' --json`)
1226
+ .action(async (opportunityId, options) => {
1227
+ await crmOpportunityLabelsAdd(opportunityId, options);
1228
+ });
1229
+ crmOppLabelCmd
1230
+ .command('remove <opportunityId> <labelId>')
1231
+ .description('Remove a label from an opportunity')
1232
+ .option('--json', 'Output as JSON')
1233
+ .addHelpText('after', `
1234
+ Examples:
1235
+ dm crm opp labels remove opp_abc123 label_456`)
1236
+ .action(async (opportunityId, labelId, options) => {
1237
+ await crmOpportunityLabelsRemove(opportunityId, labelId, options);
1238
+ });
1239
+ // ── Opportunity Subscribers ──
1240
+ const crmSubCmd = crmOppCmd
1241
+ .command('subscribers')
1242
+ .alias('subs')
1243
+ .description('Manage opportunity subscribers');
1244
+ crmSubCmd
1245
+ .command('list <opportunityId>')
1246
+ .alias('ls')
1247
+ .description('List subscribers of an opportunity')
1248
+ .option('--json', 'Output as JSON')
1249
+ .addHelpText('after', `
1250
+ Examples:
1251
+ dm crm opp subscribers list opp_abc123 --json
1252
+ dm crm opp subs ls opp_abc123`)
1253
+ .action(async (opportunityId, options) => {
1254
+ await crmSubscribersList(opportunityId, options);
1255
+ });
1256
+ crmSubCmd
1257
+ .command('add <opportunityId>')
1258
+ .description('Subscribe a user to an opportunity')
1259
+ .option('--user-id <id>', 'User ID to subscribe')
1260
+ .option('--body <json>', 'Request body as JSON string')
1261
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1262
+ .option('--json', 'Output as JSON')
1263
+ .addHelpText('after', `
1264
+ Examples:
1265
+ dm crm opp subscribers add opp_abc123 --user-id 42
1266
+ dm crm opp subs add opp_abc123 --body '{"user_id":42}' --json`)
1267
+ .action(async (opportunityId, options) => {
1268
+ await crmSubscribersAdd(opportunityId, options);
1269
+ });
1270
+ crmSubCmd
1271
+ .command('remove <opportunityId>')
1272
+ .description('Unsubscribe a user from an opportunity')
1273
+ .requiredOption('--user-id <id>', 'User ID to unsubscribe')
1274
+ .option('--json', 'Output as JSON')
1275
+ .addHelpText('after', `
1276
+ Examples:
1277
+ dm crm opp subscribers remove opp_abc123 --user-id 42`)
1278
+ .action(async (opportunityId, options) => {
1279
+ await crmSubscribersRemove(opportunityId, options);
1280
+ });
1281
+ crmCmd
1282
+ .command('activity <opportunityId>')
1283
+ .description('View activity feed for an opportunity')
1284
+ .option('--cursor <cursor>', 'Cursor for pagination')
1285
+ .option('--limit <n>', 'Items per page')
1286
+ .option('--category <cat>', 'Filter by category')
1287
+ .option('--json', 'Output as JSON')
1288
+ .addHelpText('after', `
1289
+ Examples:
1290
+ dm crm activity opp_abc123 --json
1291
+ dm crm activity opp_abc123 --category notes --limit 20`)
1292
+ .action(async (opportunityId, options) => {
1293
+ await crmActivity(opportunityId, options);
1294
+ });
1295
+ // ============================================================================
1296
+ // Dialer commands
1297
+ // ============================================================================
1298
+ const dialerCmd = program
1299
+ .command('dialer')
1300
+ .description('Manage dialer queues, calls, dispositions, and suppression');
1301
+ // ── Calls ──
1302
+ const dialerCallsCmd = dialerCmd.command('calls').description('View call history and stats');
1303
+ dialerCallsCmd
1304
+ .command('list')
1305
+ .alias('ls')
1306
+ .description('List call history')
1307
+ .option('--status <status>', 'Filter by status: initiating, ringing, answered, completed, failed, busy, no_answer, cancelled')
1308
+ .option('--search <term>', 'Search by contact name or phone number')
1309
+ .option('--date-from <date>', 'Filter from date (ISO 8601)')
1310
+ .option('--date-to <date>', 'Filter to date (ISO 8601)')
1311
+ .option('-p, --page <n>', 'Page number')
1312
+ .option('--per-page <n>', 'Results per page')
1313
+ .option('--json', 'Output as JSON')
1314
+ .addHelpText('after', `
1315
+ Examples:
1316
+ dm dialer calls list --json
1317
+ dm dialer calls list --status completed --date-from 2025-01-01
1318
+ dm dialer calls list --search "5125551234" --per-page 50`)
1319
+ .action(async (options) => {
1320
+ await dialerCallsList(options);
1321
+ });
1322
+ dialerCallsCmd
1323
+ .command('get <uuid>')
1324
+ .description('Get call details by UUID')
1325
+ .option('--json', 'Output as JSON')
1326
+ .addHelpText('after', `
1327
+ Examples:
1328
+ dm dialer calls get call_uuid_123 --json`)
1329
+ .action(async (uuid, options) => {
1330
+ await dialerCallsGet(uuid, options);
1331
+ });
1332
+ dialerCallsCmd
1333
+ .command('stats')
1334
+ .description('Get call statistics')
1335
+ .option('--date-from <date>', 'Filter from date (ISO 8601)')
1336
+ .option('--date-to <date>', 'Filter to date (ISO 8601)')
1337
+ .option('--json', 'Output as JSON')
1338
+ .addHelpText('after', `
1339
+ Examples:
1340
+ dm dialer calls stats --json
1341
+ dm dialer calls stats --date-from 2025-01-01 --date-to 2025-01-31`)
1342
+ .action(async (options) => {
1343
+ await dialerCallsStats(options);
1344
+ });
1345
+ // ── Call Notes ──
1346
+ const dialerNotesCmd = dialerCmd.command('notes').description('Manage call notes');
1347
+ dialerNotesCmd
1348
+ .command('list <callUuid>')
1349
+ .alias('ls')
1350
+ .description('List notes for a call')
1351
+ .option('--json', 'Output as JSON')
1352
+ .addHelpText('after', `
1353
+ Examples:
1354
+ dm dialer notes list call_uuid_123 --json`)
1355
+ .action(async (callUuid, options) => {
1356
+ await dialerNotesList(callUuid, options);
1357
+ });
1358
+ dialerNotesCmd
1359
+ .command('create <callUuid>')
1360
+ .description('Add a note to a call')
1361
+ .option('--body <json>', 'Request body as JSON string')
1362
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1363
+ .option('--json', 'Output as JSON')
1364
+ .addHelpText('after', `
1365
+ Examples:
1366
+ dm dialer notes create call_uuid_123 --body '{"content":"Left voicemail."}' --json`)
1367
+ .action(async (callUuid, options) => {
1368
+ await dialerNotesCreate(callUuid, options);
1369
+ });
1370
+ dialerNotesCmd
1371
+ .command('delete <callUuid> <noteId>')
1372
+ .description('Delete a call note')
1373
+ .option('--dry-run', 'Preview what would be deleted without making changes')
1374
+ .option('--json', 'Output as JSON')
1375
+ .addHelpText('after', `
1376
+ Examples:
1377
+ dm dialer notes delete call_uuid_123 note_456
1378
+ dm dialer notes delete call_uuid_123 note_456 --dry-run`)
1379
+ .action(async (callUuid, noteId, options) => {
1380
+ if (options.dryRun) {
1381
+ console.log(`Would delete note ${noteId} from call ${callUuid}.`);
1382
+ console.log('No changes made (--dry-run).');
1383
+ return;
1384
+ }
1385
+ await dialerNotesDelete(callUuid, noteId, options);
1386
+ });
1387
+ // ── Queues ──
1388
+ const dialerQueuesCmd = dialerCmd.command('queues').description('Manage dialer queues');
1389
+ dialerQueuesCmd
1390
+ .command('list')
1391
+ .alias('ls')
1392
+ .description('List all dialer queues')
1393
+ .option('--json', 'Output as JSON')
1394
+ .addHelpText('after', `
1395
+ Examples:
1396
+ dm dialer queues list --json`)
1397
+ .action(async (options) => {
1398
+ await dialerQueuesList(options);
1399
+ });
1400
+ dialerQueuesCmd
1401
+ .command('create')
1402
+ .description('Create a new queue')
1403
+ .option('--body <json>', 'Request body as JSON string')
1404
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1405
+ .option('--json', 'Output as JSON')
1406
+ .addHelpText('after', `
1407
+ Examples:
1408
+ dm dialer queues create --body '{"name":"Morning Calls"}' --json`)
1409
+ .action(async (options) => {
1410
+ await dialerQueuesCreate(options);
1411
+ });
1412
+ dialerQueuesCmd
1413
+ .command('delete <id>')
1414
+ .description('Delete a queue')
1415
+ .option('--dry-run', 'Preview what would be deleted without making changes')
1416
+ .option('--json', 'Output as JSON')
1417
+ .addHelpText('after', `
1418
+ Examples:
1419
+ dm dialer queues delete queue_abc123
1420
+ dm dialer queues delete queue_abc123 --dry-run`)
1421
+ .action(async (id, options) => {
1422
+ if (options.dryRun) {
1423
+ console.log(`Would delete queue ${id} and all its items.`);
1424
+ console.log('No changes made (--dry-run).');
1425
+ return;
1426
+ }
1427
+ await dialerQueuesDelete(id, options);
1428
+ });
1429
+ // ── Queue Items ──
1430
+ const dialerItemsCmd = dialerCmd.command('items').description('Manage queue items');
1431
+ dialerItemsCmd
1432
+ .command('list <queueId>')
1433
+ .alias('ls')
1434
+ .description('List items in a queue')
1435
+ .option('--status <status>', 'Filter by status: pending, in_progress, completed, skipped, deferred')
1436
+ .option('-p, --page <n>', 'Page number')
1437
+ .option('--per-page <n>', 'Results per page')
1438
+ .option('--json', 'Output as JSON')
1439
+ .addHelpText('after', `
1440
+ Examples:
1441
+ dm dialer items list queue_abc123 --json
1442
+ dm dialer items list queue_abc123 --status pending --per-page 50`)
1443
+ .action(async (queueId, options) => {
1444
+ await dialerQueueItemsList(queueId, options);
1445
+ });
1446
+ dialerItemsCmd
1447
+ .command('add <queueId>')
1448
+ .description('Add items to a queue')
1449
+ .option('--body <json>', 'Request body as JSON string')
1450
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1451
+ .option('--json', 'Output as JSON')
1452
+ .addHelpText('after', `
1453
+ Examples:
1454
+ dm dialer items add queue_abc123 --body '{"phone_numbers":["5125551234"]}' --json`)
1455
+ .action(async (queueId, options) => {
1456
+ await dialerQueueItemsAdd(queueId, options);
1457
+ });
1458
+ dialerItemsCmd
1459
+ .command('update <queueId> <itemId>')
1460
+ .description('Update a queue item')
1461
+ .option('--body <json>', 'Request body as JSON string')
1462
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1463
+ .option('--json', 'Output as JSON')
1464
+ .addHelpText('after', `
1465
+ Examples:
1466
+ dm dialer items update queue_abc123 item_456 --body '{"status":"skipped"}' --json`)
1467
+ .action(async (queueId, itemId, options) => {
1468
+ await dialerQueueItemsUpdate(queueId, itemId, options);
1469
+ });
1470
+ dialerItemsCmd
1471
+ .command('remove <queueId> <itemId>')
1472
+ .description('Remove an item from a queue')
1473
+ .option('--dry-run', 'Preview what would be removed without making changes')
1474
+ .option('--json', 'Output as JSON')
1475
+ .addHelpText('after', `
1476
+ Examples:
1477
+ dm dialer items remove queue_abc123 item_456
1478
+ dm dialer items remove queue_abc123 item_456 --dry-run`)
1479
+ .action(async (queueId, itemId, options) => {
1480
+ if (options.dryRun) {
1481
+ console.log(`Would remove item ${itemId} from queue ${queueId}.`);
1482
+ console.log('No changes made (--dry-run).');
1483
+ return;
1484
+ }
1485
+ await dialerQueueItemsRemove(queueId, itemId, options);
1486
+ });
1487
+ // ── Dispositions ──
1488
+ dialerCmd
1489
+ .command('dispositions')
1490
+ .description('List call dispositions')
1491
+ .option('--json', 'Output as JSON')
1492
+ .addHelpText('after', `
1493
+ Examples:
1494
+ dm dialer dispositions --json`)
1495
+ .action(async (options) => {
1496
+ await dialerDispositions(options);
1497
+ });
1498
+ // ── Suppression ──
1499
+ const dialerSuppCmd = dialerCmd
1500
+ .command('suppression')
1501
+ .description('Manage suppression list (Do Not Call)');
1502
+ dialerSuppCmd
1503
+ .command('list')
1504
+ .alias('ls')
1505
+ .description('List suppressed phone numbers')
1506
+ .option('--search <term>', 'Search by phone number')
1507
+ .option('-p, --page <n>', 'Page number')
1508
+ .option('--per-page <n>', 'Results per page')
1509
+ .option('--json', 'Output as JSON')
1510
+ .addHelpText('after', `
1511
+ Examples:
1512
+ dm dialer suppression list --json
1513
+ dm dialer suppression list --search "512" --per-page 100`)
1514
+ .action(async (options) => {
1515
+ await dialerSuppressionList(options);
1516
+ });
1517
+ dialerSuppCmd
1518
+ .command('check <phoneNumber>')
1519
+ .description('Check if a phone number is suppressed')
1520
+ .option('--json', 'Output as JSON')
1521
+ .addHelpText('after', `
1522
+ Examples:
1523
+ dm dialer suppression check 5125551234 --json`)
1524
+ .action(async (phoneNumber, options) => {
1525
+ await dialerSuppressionCheck(phoneNumber, options);
1526
+ });
1527
+ dialerSuppCmd
1528
+ .command('add')
1529
+ .description('Add a phone number to the suppression list')
1530
+ .option('--body <json>', 'Request body as JSON string')
1531
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1532
+ .option('--json', 'Output as JSON')
1533
+ .addHelpText('after', `
1534
+ Examples:
1535
+ dm dialer suppression add --body '{"phone_number":"5125551234","reason":"Do not contact"}' --json`)
1536
+ .action(async (options) => {
1537
+ await dialerSuppressionAdd(options);
1538
+ });
1539
+ // ============================================================================
1540
+ // Mail commands
1541
+ // ============================================================================
1542
+ const mailCmd = program
1543
+ .command('mail')
1544
+ .description('Manage direct mail campaigns, designs, return addresses, and wallet');
1545
+ // ── Campaigns ──
1546
+ const mailCampaignsCmd = mailCmd
1547
+ .command('campaigns')
1548
+ .alias('camp')
1549
+ .description('Manage mail campaigns');
1550
+ mailCampaignsCmd
1551
+ .command('list')
1552
+ .alias('ls')
1553
+ .description('List mail campaigns')
1554
+ .option('--status <status>', 'Filter by status: draft, active, paused, completed, cancelled')
1555
+ .option('--search <term>', 'Search by campaign name')
1556
+ .option('-p, --page <n>', 'Page number')
1557
+ .option('--per-page <n>', 'Results per page')
1558
+ .option('--json', 'Output as JSON')
1559
+ .addHelpText('after', `
1560
+ Examples:
1561
+ dm mail campaigns list --json
1562
+ dm mail camp ls --status active
1563
+ dm mail campaigns list --search "Austin" --per-page 50`)
1564
+ .action(async (options) => {
1565
+ await mailCampaignsList(options);
1566
+ });
1567
+ mailCampaignsCmd
1568
+ .command('create')
1569
+ .description('Create a mail campaign')
1570
+ .option('--body <json>', 'Request body as JSON string')
1571
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1572
+ .option('--json', 'Output as JSON')
1573
+ .addHelpText('after', `
1574
+ Examples:
1575
+ dm mail campaigns create -f campaign.json --json
1576
+ dm mail campaigns create --body '{"name":"Austin Owners","property_ids":[123],"address_to":"owner","steps":[{"design_prompt":"Professional postcard"}]}'
1577
+
1578
+ Note: Set "launch": true in body to send immediately, or leave as draft.`)
1579
+ .action(async (options) => {
1580
+ await mailCampaignsCreate(options);
1581
+ });
1582
+ mailCampaignsCmd
1583
+ .command('get <id>')
1584
+ .description('Get campaign details')
1585
+ .option('--json', 'Output as JSON')
1586
+ .addHelpText('after', `
1587
+ Examples:
1588
+ dm mail campaigns get camp_abc123 --json`)
1589
+ .action(async (id, options) => {
1590
+ await mailCampaignsGet(id, options);
1591
+ });
1592
+ mailCampaignsCmd
1593
+ .command('update <id>')
1594
+ .description('Update a draft campaign')
1595
+ .option('--body <json>', 'Request body as JSON string')
1596
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1597
+ .option('--json', 'Output as JSON')
1598
+ .addHelpText('after', `
1599
+ Examples:
1600
+ dm mail campaigns update camp_abc123 --body '{"name":"Updated Name"}' --json
1601
+
1602
+ Note: Only draft campaigns can be updated.`)
1603
+ .action(async (id, options) => {
1604
+ await mailCampaignsUpdate(id, options);
1605
+ });
1606
+ mailCampaignsCmd
1607
+ .command('delete <id>')
1608
+ .description('Cancel a campaign')
1609
+ .option('--dry-run', 'Preview what would be cancelled without making changes')
1610
+ .option('--json', 'Output as JSON')
1611
+ .addHelpText('after', `
1612
+ Examples:
1613
+ dm mail campaigns delete camp_abc123
1614
+ dm mail campaigns delete camp_abc123 --dry-run
1615
+
1616
+ Note: Active campaigns will stop sending. Already-submitted mail cannot be recalled.`)
1617
+ .action(async (id, options) => {
1618
+ if (options.dryRun) {
1619
+ console.log(`Would cancel campaign ${id}. Already-submitted mail cannot be recalled.`);
1620
+ console.log('No changes made (--dry-run).');
1621
+ return;
1622
+ }
1623
+ await mailCampaignsDelete(id, options);
1624
+ });
1625
+ mailCampaignsCmd
1626
+ .command('send <id>')
1627
+ .description('Launch a draft campaign')
1628
+ .option('--dry-run', 'Check cost estimate without launching')
1629
+ .option('--json', 'Output as JSON')
1630
+ .addHelpText('after', `
1631
+ Examples:
1632
+ dm mail campaigns send camp_abc123 --json
1633
+ dm mail campaigns send camp_abc123 --dry-run Check cost before sending
1634
+
1635
+ Note: Verify wallet balance first with: dm mail wallet balance`)
1636
+ .action(async (id, options) => {
1637
+ if (options.dryRun) {
1638
+ await mailCampaignsCostEstimate(id, options);
1639
+ return;
1640
+ }
1641
+ await mailCampaignsSend(id, options);
1642
+ });
1643
+ mailCampaignsCmd
1644
+ .command('pause <id>')
1645
+ .description('Pause an active campaign')
1646
+ .option('--json', 'Output as JSON')
1647
+ .addHelpText('after', `
1648
+ Examples:
1649
+ dm mail campaigns pause camp_abc123`)
1650
+ .action(async (id, options) => {
1651
+ await mailCampaignsPause(id, options);
1652
+ });
1653
+ mailCampaignsCmd
1654
+ .command('resume <id>')
1655
+ .description('Resume a paused campaign')
1656
+ .option('--json', 'Output as JSON')
1657
+ .addHelpText('after', `
1658
+ Examples:
1659
+ dm mail campaigns resume camp_abc123`)
1660
+ .action(async (id, options) => {
1661
+ await mailCampaignsResume(id, options);
1662
+ });
1663
+ mailCampaignsCmd
1664
+ .command('recipients <id>')
1665
+ .description('List campaign recipients')
1666
+ .option('-p, --page <n>', 'Page number')
1667
+ .option('--per-page <n>', 'Results per page')
1668
+ .option('--json', 'Output as JSON')
1669
+ .addHelpText('after', `
1670
+ Examples:
1671
+ dm mail campaigns recipients camp_abc123 --json
1672
+ dm mail campaigns recipients camp_abc123 --per-page 100`)
1673
+ .action(async (id, options) => {
1674
+ await mailCampaignsRecipients(id, options);
1675
+ });
1676
+ mailCampaignsCmd
1677
+ .command('analytics <id>')
1678
+ .description('Get campaign delivery and response analytics')
1679
+ .option('--json', 'Output as JSON')
1680
+ .addHelpText('after', `
1681
+ Examples:
1682
+ dm mail campaigns analytics camp_abc123 --json`)
1683
+ .action(async (id, options) => {
1684
+ await mailCampaignsAnalytics(id, options);
1685
+ });
1686
+ mailCampaignsCmd
1687
+ .command('cost-estimate <id>')
1688
+ .description('Estimate campaign cost before sending')
1689
+ .option('--json', 'Output as JSON')
1690
+ .addHelpText('after', `
1691
+ Examples:
1692
+ dm mail campaigns cost-estimate camp_abc123 --json`)
1693
+ .action(async (id, options) => {
1694
+ await mailCampaignsCostEstimate(id, options);
1695
+ });
1696
+ // ── Designs ──
1697
+ const mailDesignsCmd = mailCmd.command('designs').description('Manage postcard designs');
1698
+ mailDesignsCmd
1699
+ .command('list')
1700
+ .alias('ls')
1701
+ .description('List designs')
1702
+ .option('--status <status>', 'Filter by status: draft, active, archived')
1703
+ .option('--size <size>', 'Filter by size: 4x6, 6x9, 6x11')
1704
+ .option('--search <term>', 'Search by name')
1705
+ .option('-p, --page <n>', 'Page number')
1706
+ .option('--per-page <n>', 'Results per page')
1707
+ .option('--json', 'Output as JSON')
1708
+ .addHelpText('after', `
1709
+ Examples:
1710
+ dm mail designs list --json
1711
+ dm mail designs list --status active --size 4x6
1712
+ dm mail designs list --search "professional"`)
1713
+ .action(async (options) => {
1714
+ await mailDesignsList(options);
1715
+ });
1716
+ mailDesignsCmd
1717
+ .command('create')
1718
+ .description('Create a postcard design')
1719
+ .option('--body <json>', 'Request body as JSON string')
1720
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1721
+ .option('--json', 'Output as JSON')
1722
+ .addHelpText('after', `
1723
+ Examples:
1724
+ dm mail designs create --body '{"name":"My Card","prompt":"Professional real estate postcard","size":"4x6"}' --json
1725
+ dm mail designs create -f design.json
1726
+
1727
+ Note: Provide either "prompt" (AI-generated) or "html_front" (custom HTML).`)
1728
+ .action(async (options) => {
1729
+ await mailDesignsCreate(options);
1730
+ });
1731
+ mailDesignsCmd
1732
+ .command('get <id>')
1733
+ .description('Get design details')
1734
+ .option('--json', 'Output as JSON')
1735
+ .addHelpText('after', `
1736
+ Examples:
1737
+ dm mail designs get des_abc123 --json`)
1738
+ .action(async (id, options) => {
1739
+ await mailDesignsGet(id, options);
1740
+ });
1741
+ mailDesignsCmd
1742
+ .command('update <id>')
1743
+ .description('Update a design')
1744
+ .option('--body <json>', 'Request body as JSON string')
1745
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1746
+ .option('--json', 'Output as JSON')
1747
+ .addHelpText('after', `
1748
+ Examples:
1749
+ dm mail designs update des_abc123 --body '{"name":"Updated Name","publish":true}' --json
1750
+
1751
+ Note: Set "publish": true to promote draft HTML to active.`)
1752
+ .action(async (id, options) => {
1753
+ await mailDesignsUpdate(id, options);
1754
+ });
1755
+ mailDesignsCmd
1756
+ .command('delete <id>')
1757
+ .description('Delete a design')
1758
+ .option('--dry-run', 'Preview what would be deleted without making changes')
1759
+ .option('--json', 'Output as JSON')
1760
+ .addHelpText('after', `
1761
+ Examples:
1762
+ dm mail designs delete des_abc123
1763
+ dm mail designs delete des_abc123 --dry-run
1764
+
1765
+ Note: Designs used in active campaigns cannot be deleted.`)
1766
+ .action(async (id, options) => {
1767
+ if (options.dryRun) {
1768
+ console.log(`Would delete design ${id}.`);
1769
+ console.log('No changes made (--dry-run).');
1770
+ return;
1771
+ }
1772
+ await mailDesignsDelete(id, options);
1773
+ });
1774
+ // ── Return Addresses ──
1775
+ const mailAddressesCmd = mailCmd
1776
+ .command('return-addresses')
1777
+ .alias('addr')
1778
+ .description('Manage return addresses for mail campaigns');
1779
+ mailAddressesCmd
1780
+ .command('list')
1781
+ .alias('ls')
1782
+ .description('List return addresses')
1783
+ .option('--json', 'Output as JSON')
1784
+ .addHelpText('after', `
1785
+ Examples:
1786
+ dm mail return-addresses list --json
1787
+ dm mail addr ls --json`)
1788
+ .action(async (options) => {
1789
+ await mailReturnAddressesList(options);
1790
+ });
1791
+ mailAddressesCmd
1792
+ .command('create')
1793
+ .description('Create a return address (USPS-validated)')
1794
+ .option('--body <json>', 'Request body as JSON string')
1795
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1796
+ .option('--json', 'Output as JSON')
1797
+ .addHelpText('after', `
1798
+ Examples:
1799
+ dm mail addr create --body '{"name":"DealMachine","address_1":"123 Main St","city":"Austin","state":"TX","zip":"78704"}' --json
1800
+ dm mail addr create --body '{"name":"Office","label":"HQ","address_1":"456 Oak","city":"Dallas","state":"TX","zip":"75201","set_as_default":true}'`)
1801
+ .action(async (options) => {
1802
+ await mailReturnAddressesCreate(options);
1803
+ });
1804
+ mailAddressesCmd
1805
+ .command('get <id>')
1806
+ .description('Get return address details')
1807
+ .option('--json', 'Output as JSON')
1808
+ .addHelpText('after', `
1809
+ Examples:
1810
+ dm mail addr get addr_abc123 --json`)
1811
+ .action(async (id, options) => {
1812
+ await mailReturnAddressesGet(id, options);
1813
+ });
1814
+ mailAddressesCmd
1815
+ .command('update <id>')
1816
+ .description('Update a return address (re-validated by USPS)')
1817
+ .option('--body <json>', 'Request body as JSON string')
1818
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1819
+ .option('--json', 'Output as JSON')
1820
+ .addHelpText('after', `
1821
+ Examples:
1822
+ dm mail addr update addr_abc123 --body '{"name":"New Name"}' --json`)
1823
+ .action(async (id, options) => {
1824
+ await mailReturnAddressesUpdate(id, options);
1825
+ });
1826
+ mailAddressesCmd
1827
+ .command('delete <id>')
1828
+ .description('Delete a return address')
1829
+ .option('--dry-run', 'Preview what would be deleted without making changes')
1830
+ .option('--json', 'Output as JSON')
1831
+ .addHelpText('after', `
1832
+ Examples:
1833
+ dm mail addr delete addr_abc123
1834
+ dm mail addr delete addr_abc123 --dry-run
1835
+
1836
+ Note: Cannot delete the default address. Set another as default first.`)
1837
+ .action(async (id, options) => {
1838
+ if (options.dryRun) {
1839
+ console.log(`Would delete return address ${id}.`);
1840
+ console.log('No changes made (--dry-run).');
1841
+ return;
1842
+ }
1843
+ await mailReturnAddressesDelete(id, options);
1844
+ });
1845
+ mailAddressesCmd
1846
+ .command('set-default <id>')
1847
+ .description('Set a return address as the default')
1848
+ .option('--json', 'Output as JSON')
1849
+ .addHelpText('after', `
1850
+ Examples:
1851
+ dm mail addr set-default addr_abc123`)
1852
+ .action(async (id, options) => {
1853
+ await mailReturnAddressesSetDefault(id, options);
1854
+ });
1855
+ // ── Wallet ──
1856
+ const mailWalletCmd = mailCmd
1857
+ .command('wallet')
1858
+ .description('Manage mail wallet balance and transactions');
1859
+ mailWalletCmd
1860
+ .command('balance')
1861
+ .description('Get wallet balance')
1862
+ .option('--json', 'Output as JSON')
1863
+ .addHelpText('after', `
1864
+ Examples:
1865
+ dm mail wallet balance --json`)
1866
+ .action(async (options) => {
1867
+ await mailWalletBalance(options);
1868
+ });
1869
+ mailWalletCmd
1870
+ .command('add-funds')
1871
+ .description('Add credits to your mail wallet ($50–$10,000)')
1872
+ .option('--body <json>', 'Request body as JSON string')
1873
+ .option('-f, --file <path>', 'Read request body from a JSON file')
1874
+ .option('--json', 'Output as JSON')
1875
+ .addHelpText('after', `
1876
+ Examples:
1877
+ dm mail wallet add-funds --body '{"amount_cents":5000}' --json Add $50
1878
+ dm mail wallet add-funds --body '{"amount_cents":10000,"payment_method_id":"pm_..."}' --json`)
1879
+ .action(async (options) => {
1880
+ await mailWalletAddFunds(options);
1881
+ });
1882
+ mailWalletCmd
1883
+ .command('transactions')
1884
+ .alias('txns')
1885
+ .description('List wallet transactions')
1886
+ .option('--type <type>', 'Filter by type: purchase, spend, refund')
1887
+ .option('--reference-type <type>', 'Filter by reference type: campaign, stripe_payment')
1888
+ .option('--campaign-id <id>', 'Filter by campaign ID')
1889
+ .option('-p, --page <n>', 'Page number')
1890
+ .option('--per-page <n>', 'Results per page')
1891
+ .option('--json', 'Output as JSON')
1892
+ .addHelpText('after', `
1893
+ Examples:
1894
+ dm mail wallet transactions --json
1895
+ dm mail wallet txns --type spend --campaign-id camp_abc123
1896
+ dm mail wallet transactions --type purchase --per-page 50`)
1897
+ .action(async (options) => {
1898
+ await mailWalletTransactions(options);
1899
+ });
1900
+ mailWalletCmd
1901
+ .command('pricing')
1902
+ .description('Get postcard pricing for your plan')
1903
+ .option('--json', 'Output as JSON')
1904
+ .addHelpText('after', `
1905
+ Examples:
1906
+ dm mail wallet pricing --json`)
1907
+ .action(async (options) => {
1908
+ await mailWalletPricing(options);
1909
+ });
1910
+ // ============================================================================
1911
+ // Dev commands (local DB operations)
1912
+ // ============================================================================
1913
+ const devCmd = program
1914
+ .command('dev')
1915
+ .description('Local development utilities (requires Docker MySQL)');
1916
+ const devLicenseCmd = devCmd.command('license').description('Manage API key licenses');
1917
+ devLicenseCmd
1918
+ .command('add <key_id>')
1919
+ .description('Add a license to an API key')
1920
+ .requiredOption('--type <type>', 'License type: state, county, zip_code, or unlimited')
1921
+ .option('--code <code>', 'Location code (state abbrev, FIPS, or ZIP)')
1922
+ .option('--expires <date>', 'Expiration date (ISO format)')
1923
+ .action(async (keyId, options) => {
1924
+ await licenseAdd(keyId, options);
1925
+ });
1926
+ devLicenseCmd
1927
+ .command('list [key_id]')
1928
+ .description('List licenses (optionally filter by key_id)')
1929
+ .action(async (keyId) => {
1930
+ await licenseList(keyId);
1931
+ });
1932
+ devLicenseCmd
1933
+ .command('remove <license_id>')
1934
+ .description('Remove a license by ID')
1935
+ .action(async (licenseId) => {
1936
+ await licenseRemove(licenseId);
1937
+ });
1938
+ // ============================================================================
1939
+ // Parse and execute
1940
+ // ============================================================================
1941
+ program.parse();
1942
+ //# sourceMappingURL=index.js.map