@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
@@ -0,0 +1,649 @@
1
+ /**
2
+ * Enrichment commands — address, latlng, apn, email, phone, name
3
+ */
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import chalk from 'chalk';
7
+ import { apiRequest } from '../lib/client.js';
8
+ import { parseRequestBody, printJson, printHeader, printTable, printTotals, printCredits, printWarning, printPagination, truncate, createSpinner, } from '../lib/output.js';
9
+ // ============================================================================
10
+ // CSV + Batch Helpers
11
+ // ============================================================================
12
+ const API_BATCH_LIMIT = 250;
13
+ /** Parse a CSV file into an array of objects keyed by lowercase column headers. */
14
+ function parseCsv(filePath) {
15
+ const content = fs.readFileSync(filePath, 'utf-8');
16
+ const lines = content.split(/\r?\n/).filter((l) => l.trim());
17
+ if (lines.length < 2)
18
+ return [];
19
+ const headers = lines[0].split(',').map((h) => h.trim().toLowerCase());
20
+ return lines.slice(1).map((line) => {
21
+ const values = line.split(',').map((v) => v.trim());
22
+ const obj = {};
23
+ headers.forEach((h, i) => { obj[h] = values[i] || ''; });
24
+ return obj;
25
+ });
26
+ }
27
+ function isCsvFile(filePath) {
28
+ return path.extname(filePath).toLowerCase() === '.csv';
29
+ }
30
+ /** Find first matching column name from a list of candidates. */
31
+ function findColumn(row, ...candidates) {
32
+ for (const c of candidates) {
33
+ if (c in row)
34
+ return c;
35
+ }
36
+ return null;
37
+ }
38
+ /** Merge multiple batch responses into one. */
39
+ function mergeResponses(responses) {
40
+ const merged = {
41
+ data: [],
42
+ totals: { submitted: 0, matched: 0, unmatched: 0 },
43
+ credits: { used: 0, properties: 0, people: 0, deduplicated: 0 },
44
+ };
45
+ for (const r of responses) {
46
+ merged.data.push(...r.data);
47
+ merged.totals.submitted += r.totals.submitted;
48
+ merged.totals.matched += r.totals.matched;
49
+ merged.totals.unmatched += r.totals.unmatched;
50
+ merged.credits.used += r.credits.used;
51
+ merged.credits.properties += r.credits.properties;
52
+ merged.credits.people += r.credits.people;
53
+ merged.credits.deduplicated += r.credits.deduplicated;
54
+ if (r.warning)
55
+ merged.warning = r.warning;
56
+ }
57
+ return merged;
58
+ }
59
+ /**
60
+ * Generic batch enrichment runner.
61
+ * Splits items into chunks of 250, calls the API endpoint for each, and merges results.
62
+ */
63
+ async function runBatchEnrichment(opts) {
64
+ const { items, arrayKey, endpoint, label, extraBody } = opts;
65
+ const responses = [];
66
+ const totalBatches = Math.ceil(items.length / API_BATCH_LIMIT);
67
+ const spinner = createSpinner(`Enriching ${items.length} ${label} (batch 1/${totalBatches})...`).start();
68
+ for (let i = 0; i < items.length; i += API_BATCH_LIMIT) {
69
+ const batch = items.slice(i, i + API_BATCH_LIMIT);
70
+ const batchNum = Math.floor(i / API_BATCH_LIMIT) + 1;
71
+ spinner.text = `Enriching ${items.length} ${label} (batch ${batchNum}/${totalBatches})...`;
72
+ const body = { [arrayKey]: batch, ...extraBody };
73
+ const data = await apiRequest(endpoint, {
74
+ method: 'POST',
75
+ body,
76
+ });
77
+ responses.push(data);
78
+ if (data.warning && data.warning.includes('credit limit reached')) {
79
+ spinner.warn(`Data credit limit reached at batch ${batchNum}/${totalBatches}`);
80
+ break;
81
+ }
82
+ }
83
+ if (!spinner.isSpinning) {
84
+ // spinner.warn already stopped it
85
+ }
86
+ else {
87
+ spinner.succeed(`Enriched ${items.length} ${label} in ${totalBatches} batch(es)`);
88
+ }
89
+ return mergeResponses(responses);
90
+ }
91
+ // ============================================================================
92
+ // Address
93
+ // ============================================================================
94
+ export async function enrichAddress(address, options) {
95
+ // CSV file support
96
+ if (!address && options.file && isCsvFile(options.file)) {
97
+ const rows = parseCsv(options.file);
98
+ if (rows.length === 0) {
99
+ console.error(chalk.red('Error: CSV file is empty.'));
100
+ process.exit(1);
101
+ }
102
+ // Support: full_address, or street+city+state+zip columns
103
+ const fullAddrCol = findColumn(rows[0], 'full_address', 'address');
104
+ let items;
105
+ if (fullAddrCol) {
106
+ items = rows.map((r) => ({ full_address: r[fullAddrCol] })).filter((a) => a.full_address);
107
+ }
108
+ else {
109
+ const streetCol = findColumn(rows[0], 'street', 'street_address', 'address_line_1');
110
+ const cityCol = findColumn(rows[0], 'city');
111
+ const stateCol = findColumn(rows[0], 'state');
112
+ const zipCol = findColumn(rows[0], 'zip', 'zip_code', 'zipcode', 'postal_code');
113
+ if (!streetCol) {
114
+ console.error(chalk.red('Error: CSV must have "full_address" or "street" column.'));
115
+ process.exit(1);
116
+ }
117
+ items = rows.map((r) => ({
118
+ street: r[streetCol],
119
+ ...(cityCol && { city: r[cityCol] }),
120
+ ...(stateCol && { state: r[stateCol] }),
121
+ ...(zipCol && { zip: r[zipCol] }),
122
+ })).filter((a) => a.street);
123
+ }
124
+ const extraBody = {};
125
+ if (options.contactAudience)
126
+ extraBody.contact_audience = options.contactAudience;
127
+ const merged = await runBatchEnrichment({
128
+ items,
129
+ arrayKey: 'data',
130
+ endpoint: '/enrichment/address',
131
+ label: 'addresses',
132
+ extraBody,
133
+ });
134
+ if (options.json) {
135
+ printJson(merged);
136
+ return;
137
+ }
138
+ printPropertyEnrichResult('Address Enrichment', merged);
139
+ return;
140
+ }
141
+ let requestBody;
142
+ if (address) {
143
+ requestBody = { data: [{ full_address: address }] };
144
+ if (options.contactAudience)
145
+ requestBody.contact_audience = options.contactAudience;
146
+ }
147
+ else {
148
+ requestBody = await parseRequestBody(options);
149
+ }
150
+ // Auto-batch large JSON input
151
+ const addrItems = requestBody.data;
152
+ if (addrItems && addrItems.length > API_BATCH_LIMIT) {
153
+ const extraBody = { ...requestBody };
154
+ delete extraBody.data;
155
+ const merged = await runBatchEnrichment({
156
+ items: addrItems,
157
+ arrayKey: 'data',
158
+ endpoint: '/enrichment/address',
159
+ label: 'addresses',
160
+ extraBody,
161
+ });
162
+ if (options.json) {
163
+ printJson(merged);
164
+ return;
165
+ }
166
+ printPropertyEnrichResult('Address Enrichment', merged);
167
+ return;
168
+ }
169
+ const spinner = createSpinner('Enriching by address...').start();
170
+ const data = await apiRequest('/enrichment/address', {
171
+ method: 'POST',
172
+ body: requestBody,
173
+ });
174
+ spinner.stop();
175
+ if (options.json) {
176
+ printJson(data);
177
+ return;
178
+ }
179
+ printPropertyEnrichResult('Address Enrichment', data);
180
+ }
181
+ // ============================================================================
182
+ // LatLng
183
+ // ============================================================================
184
+ export async function enrichLatLng(coords, options) {
185
+ // CSV file support
186
+ if (!coords && options.file && isCsvFile(options.file)) {
187
+ const rows = parseCsv(options.file);
188
+ if (rows.length === 0) {
189
+ console.error(chalk.red('Error: CSV file is empty.'));
190
+ process.exit(1);
191
+ }
192
+ const latCol = findColumn(rows[0], 'latitude', 'lat');
193
+ const lngCol = findColumn(rows[0], 'longitude', 'lng', 'lon', 'long');
194
+ if (!latCol || !lngCol) {
195
+ console.error(chalk.red('Error: CSV must have "latitude" and "longitude" columns.'));
196
+ process.exit(1);
197
+ }
198
+ const items = rows.map((r) => ({
199
+ latitude: parseFloat(r[latCol]),
200
+ longitude: parseFloat(r[lngCol]),
201
+ })).filter((c) => !isNaN(c.latitude) && !isNaN(c.longitude));
202
+ const extraBody = {};
203
+ if (options.contactAudience)
204
+ extraBody.contact_audience = options.contactAudience;
205
+ const merged = await runBatchEnrichment({
206
+ items,
207
+ arrayKey: 'data',
208
+ endpoint: '/enrichment/reverse-geocode',
209
+ label: 'coordinates',
210
+ extraBody,
211
+ });
212
+ if (options.json) {
213
+ printJson(merged);
214
+ return;
215
+ }
216
+ printPropertyEnrichResult('Coordinate Enrichment', merged);
217
+ return;
218
+ }
219
+ let requestBody;
220
+ if (coords) {
221
+ const [lat, lng] = coords.split(',').map((s) => parseFloat(s.trim()));
222
+ if (isNaN(lat) || isNaN(lng)) {
223
+ console.error(chalk.red('Error: Invalid coordinates. Use format: lat,lng (e.g., 30.25,-97.75)'));
224
+ process.exit(1);
225
+ }
226
+ requestBody = { data: [{ latitude: lat, longitude: lng }] };
227
+ if (options.contactAudience)
228
+ requestBody.contact_audience = options.contactAudience;
229
+ }
230
+ else {
231
+ requestBody = await parseRequestBody(options);
232
+ }
233
+ // Auto-batch large JSON input
234
+ const latlngItems = requestBody.data;
235
+ if (latlngItems && latlngItems.length > API_BATCH_LIMIT) {
236
+ const extraBody = { ...requestBody };
237
+ delete extraBody.data;
238
+ const merged = await runBatchEnrichment({
239
+ items: latlngItems,
240
+ arrayKey: 'data',
241
+ endpoint: '/enrichment/reverse-geocode',
242
+ label: 'coordinates',
243
+ extraBody,
244
+ });
245
+ if (options.json) {
246
+ printJson(merged);
247
+ return;
248
+ }
249
+ printPropertyEnrichResult('Coordinate Enrichment', merged);
250
+ return;
251
+ }
252
+ const spinner = createSpinner('Enriching by coordinates...').start();
253
+ const data = await apiRequest('/enrichment/reverse-geocode', {
254
+ method: 'POST',
255
+ body: requestBody,
256
+ });
257
+ spinner.stop();
258
+ if (options.json) {
259
+ printJson(data);
260
+ return;
261
+ }
262
+ printPropertyEnrichResult('Coordinate Enrichment', data);
263
+ }
264
+ // ============================================================================
265
+ // APN
266
+ // ============================================================================
267
+ export async function enrichApn(apn, options) {
268
+ // CSV file support
269
+ if (!apn && options.file && isCsvFile(options.file)) {
270
+ const rows = parseCsv(options.file);
271
+ if (rows.length === 0) {
272
+ console.error(chalk.red('Error: CSV file is empty.'));
273
+ process.exit(1);
274
+ }
275
+ const apnCol = findColumn(rows[0], 'apn', 'parcel_id', 'parcel_number');
276
+ if (!apnCol) {
277
+ console.error(chalk.red('Error: CSV must have an "apn" column.'));
278
+ process.exit(1);
279
+ }
280
+ const items = rows.map((r) => ({ apn: r[apnCol] })).filter((a) => a.apn);
281
+ const extraBody = {};
282
+ if (options.contactAudience)
283
+ extraBody.contact_audience = options.contactAudience;
284
+ if (options.state)
285
+ extraBody.location = { type: 'state', code: options.state };
286
+ else if (options.zip)
287
+ extraBody.location = { type: 'zip_code', code: options.zip };
288
+ const merged = await runBatchEnrichment({
289
+ items,
290
+ arrayKey: 'data',
291
+ endpoint: '/enrichment/apn',
292
+ label: 'APNs',
293
+ extraBody,
294
+ });
295
+ if (options.json) {
296
+ printJson(merged);
297
+ return;
298
+ }
299
+ printPropertyEnrichResult('APN Enrichment', merged);
300
+ return;
301
+ }
302
+ let requestBody;
303
+ if (apn) {
304
+ requestBody = { data: [{ apn }] };
305
+ if (options.state)
306
+ requestBody.location = { type: 'state', code: options.state };
307
+ else if (options.zip)
308
+ requestBody.location = { type: 'zip_code', code: options.zip };
309
+ if (options.contactAudience)
310
+ requestBody.contact_audience = options.contactAudience;
311
+ }
312
+ else {
313
+ requestBody = await parseRequestBody(options);
314
+ }
315
+ // Auto-batch large JSON input
316
+ const apnItems = requestBody.data;
317
+ if (apnItems && apnItems.length > API_BATCH_LIMIT) {
318
+ const extraBody = { ...requestBody };
319
+ delete extraBody.data;
320
+ const merged = await runBatchEnrichment({
321
+ items: apnItems,
322
+ arrayKey: 'data',
323
+ endpoint: '/enrichment/apn',
324
+ label: 'APNs',
325
+ extraBody,
326
+ });
327
+ if (options.json) {
328
+ printJson(merged);
329
+ return;
330
+ }
331
+ printPropertyEnrichResult('APN Enrichment', merged);
332
+ return;
333
+ }
334
+ const spinner = createSpinner('Enriching by APN...').start();
335
+ const data = await apiRequest('/enrichment/apn', {
336
+ method: 'POST',
337
+ body: requestBody,
338
+ });
339
+ spinner.stop();
340
+ if (options.json) {
341
+ printJson(data);
342
+ return;
343
+ }
344
+ printPropertyEnrichResult('APN Enrichment', data);
345
+ }
346
+ // ============================================================================
347
+ // Email
348
+ // ============================================================================
349
+ export async function enrichEmail(email, options) {
350
+ // CSV file support
351
+ if (!email && options.file && isCsvFile(options.file)) {
352
+ const rows = parseCsv(options.file);
353
+ if (rows.length === 0) {
354
+ console.error(chalk.red('Error: CSV file is empty.'));
355
+ process.exit(1);
356
+ }
357
+ const emailCol = findColumn(rows[0], 'email', 'email_address');
358
+ if (!emailCol) {
359
+ console.error(chalk.red('Error: CSV must have an "email" column.'));
360
+ process.exit(1);
361
+ }
362
+ const items = rows.map((r) => ({ email: r[emailCol] })).filter((e) => e.email);
363
+ const extraBody = {};
364
+ if (options.includeProperties)
365
+ extraBody.include_properties = true;
366
+ const merged = await runBatchEnrichment({
367
+ items,
368
+ arrayKey: 'data',
369
+ endpoint: '/enrichment/email',
370
+ label: 'emails',
371
+ extraBody,
372
+ });
373
+ if (options.json) {
374
+ printJson(merged);
375
+ return;
376
+ }
377
+ printPersonEnrichResult('Email Enrichment', merged);
378
+ return;
379
+ }
380
+ let requestBody;
381
+ if (email) {
382
+ requestBody = { data: [{ email }] };
383
+ if (options.includeProperties)
384
+ requestBody.include_properties = true;
385
+ }
386
+ else {
387
+ requestBody = await parseRequestBody(options);
388
+ }
389
+ // Auto-batch large JSON input
390
+ const emailItems = requestBody.data;
391
+ if (emailItems && emailItems.length > API_BATCH_LIMIT) {
392
+ const extraBody = { ...requestBody };
393
+ delete extraBody.data;
394
+ const merged = await runBatchEnrichment({
395
+ items: emailItems,
396
+ arrayKey: 'data',
397
+ endpoint: '/enrichment/email',
398
+ label: 'emails',
399
+ extraBody,
400
+ });
401
+ if (options.json) {
402
+ printJson(merged);
403
+ return;
404
+ }
405
+ printPersonEnrichResult('Email Enrichment', merged);
406
+ return;
407
+ }
408
+ const spinner = createSpinner('Enriching by email...').start();
409
+ const data = await apiRequest('/enrichment/email', {
410
+ method: 'POST',
411
+ body: requestBody,
412
+ });
413
+ spinner.stop();
414
+ if (options.json) {
415
+ printJson(data);
416
+ return;
417
+ }
418
+ printPersonEnrichResult('Email Enrichment', data);
419
+ }
420
+ // ============================================================================
421
+ // Phone
422
+ // ============================================================================
423
+ export async function enrichPhone(phone, options) {
424
+ // CSV file support
425
+ if (!phone && options.file && isCsvFile(options.file)) {
426
+ const rows = parseCsv(options.file);
427
+ if (rows.length === 0) {
428
+ console.error(chalk.red('Error: CSV file is empty.'));
429
+ process.exit(1);
430
+ }
431
+ const phoneCol = findColumn(rows[0], 'phone', 'phone_number');
432
+ if (!phoneCol) {
433
+ console.error(chalk.red('Error: CSV must have a "phone" column.'));
434
+ process.exit(1);
435
+ }
436
+ const items = rows.map((r) => ({ phone: r[phoneCol] })).filter((p) => p.phone);
437
+ const extraBody = {};
438
+ if (options.includeProperties)
439
+ extraBody.include_properties = true;
440
+ const merged = await runBatchEnrichment({
441
+ items,
442
+ arrayKey: 'data',
443
+ endpoint: '/enrichment/phone',
444
+ label: 'phones',
445
+ extraBody,
446
+ });
447
+ if (options.json) {
448
+ printJson(merged);
449
+ return;
450
+ }
451
+ printPersonEnrichResult('Phone Enrichment', merged);
452
+ return;
453
+ }
454
+ let requestBody;
455
+ if (phone) {
456
+ requestBody = { data: [{ phone }] };
457
+ if (options.includeProperties)
458
+ requestBody.include_properties = true;
459
+ }
460
+ else {
461
+ requestBody = await parseRequestBody(options);
462
+ }
463
+ // Auto-batch large JSON input
464
+ const phoneItems = requestBody.data;
465
+ if (phoneItems && phoneItems.length > API_BATCH_LIMIT) {
466
+ const extraBody = { ...requestBody };
467
+ delete extraBody.data;
468
+ const merged = await runBatchEnrichment({
469
+ items: phoneItems,
470
+ arrayKey: 'data',
471
+ endpoint: '/enrichment/phone',
472
+ label: 'phones',
473
+ extraBody,
474
+ });
475
+ if (options.json) {
476
+ printJson(merged);
477
+ return;
478
+ }
479
+ printPersonEnrichResult('Phone Enrichment', merged);
480
+ return;
481
+ }
482
+ const spinner = createSpinner('Enriching by phone...').start();
483
+ const data = await apiRequest('/enrichment/phone', {
484
+ method: 'POST',
485
+ body: requestBody,
486
+ });
487
+ spinner.stop();
488
+ if (options.json) {
489
+ printJson(data);
490
+ return;
491
+ }
492
+ printPersonEnrichResult('Phone Enrichment', data);
493
+ }
494
+ // ============================================================================
495
+ // Name
496
+ // ============================================================================
497
+ export async function enrichName(name, options) {
498
+ let requestBody;
499
+ if (name) {
500
+ // Parse "First Last" or just "Last"
501
+ const parts = name.trim().split(/\s+/);
502
+ const nameObj = {};
503
+ if (parts.length >= 2) {
504
+ nameObj.first_name = parts[0];
505
+ nameObj.last_name = parts.slice(1).join(' ');
506
+ }
507
+ else {
508
+ nameObj.last_name = parts[0];
509
+ }
510
+ requestBody = {
511
+ data: [nameObj],
512
+ };
513
+ // Add location if provided
514
+ if (options.state) {
515
+ requestBody.location = { type: 'state', code: options.state };
516
+ }
517
+ else if (options.zip) {
518
+ requestBody.location = { type: 'zip_code', code: options.zip };
519
+ }
520
+ if (options.includeProperties)
521
+ requestBody.include_properties = true;
522
+ if (options.page)
523
+ requestBody.page = parseInt(options.page, 10);
524
+ if (options.perPage)
525
+ requestBody.per_page = parseInt(options.perPage, 10);
526
+ }
527
+ else {
528
+ requestBody = await parseRequestBody(options);
529
+ }
530
+ const spinner = createSpinner('Enriching by name...').start();
531
+ const data = await apiRequest('/enrichment/name', {
532
+ method: 'POST',
533
+ body: requestBody,
534
+ });
535
+ spinner.stop();
536
+ if (options.json) {
537
+ printJson(data);
538
+ return;
539
+ }
540
+ printHeader('Name Enrichment');
541
+ console.log();
542
+ if (data.data.length > 0) {
543
+ const rows = data.data.map((p) => ({
544
+ id: p.dm_person_id || '',
545
+ name: truncate(String(p.full_name || ''), 25),
546
+ phones: Array.isArray(p.phones) ? String(p.phones.length) : '—',
547
+ emails: Array.isArray(p.emails) ? String(p.emails.length) : '—',
548
+ properties: Array.isArray(p.properties) ? String(p.properties.length) : '—',
549
+ }));
550
+ printTable(rows, ['id', 'name', 'phones', 'emails', 'properties']);
551
+ }
552
+ else {
553
+ console.log(chalk.dim(' No results found.'));
554
+ }
555
+ printPagination({
556
+ page: data.pagination.page,
557
+ per_page: data.pagination.per_page,
558
+ total_results: data.pagination.total,
559
+ total_pages: data.pagination.total_pages,
560
+ });
561
+ printCredits(data.credits);
562
+ console.log();
563
+ }
564
+ // ============================================================================
565
+ // Shared Output Helpers
566
+ // ============================================================================
567
+ function printPropertyEnrichResult(title, data) {
568
+ printHeader(title);
569
+ printTotals({
570
+ submitted: data.totals.submitted,
571
+ matched: data.totals.matched,
572
+ unmatched: data.totals.unmatched,
573
+ });
574
+ if (data.warning)
575
+ printWarning(data.warning);
576
+ console.log();
577
+ if (data.data.length > 0) {
578
+ const rows = data.data.map((item) => ({
579
+ matched: item.matched ? chalk.green('yes') : chalk.dim('no'),
580
+ id: item.dm_property_id || '—',
581
+ address: truncate(String(item.full_address || item.address || ''), 35),
582
+ value: item.estimated_value != null ? `$${Number(item.estimated_value).toLocaleString()}` : '—',
583
+ contacts: Array.isArray(item.contacts) ? String(item.contacts.length) : '—',
584
+ }));
585
+ printTable(rows, ['matched', 'id', 'address', 'value', 'contacts']);
586
+ printMatchWarnings(data.data);
587
+ }
588
+ printCredits(data.credits);
589
+ console.log();
590
+ }
591
+ function printMatchWarnings(items) {
592
+ const warned = items
593
+ .map((item, i) => ({ i, w: item.match_warning }))
594
+ .filter((entry) => entry.w);
595
+ if (warned.length === 0)
596
+ return;
597
+ console.log();
598
+ console.log(chalk.yellow(`! ${warned.length} item(s) had input rewritten before matching:`));
599
+ for (const { i, w } of warned) {
600
+ const parsed = w?.hint?.parsed_street;
601
+ const detail = parsed ? `parsed as "${String(parsed)}"` : (w?.message ?? '');
602
+ console.log(chalk.dim(` [${i}] ${w?.code ?? 'match_warning'}: ${detail}`));
603
+ }
604
+ }
605
+ function printPersonEnrichResult(title, data) {
606
+ printHeader(title);
607
+ printTotals({
608
+ submitted: data.totals.submitted,
609
+ matched: data.totals.matched,
610
+ unmatched: data.totals.unmatched,
611
+ });
612
+ if (data.warning)
613
+ printWarning(data.warning);
614
+ console.log();
615
+ for (const item of data.data) {
616
+ if (!item.matched) {
617
+ const input = item.input;
618
+ const inputStr = Object.values(input).filter(Boolean).join(', ');
619
+ console.log(` ${chalk.dim('✗')} ${inputStr} — ${chalk.dim('no match')}`);
620
+ continue;
621
+ }
622
+ const contacts = item.contacts;
623
+ if (!contacts || contacts.length === 0)
624
+ continue;
625
+ const input = item.input;
626
+ const inputStr = Object.values(input).filter(Boolean).join(', ');
627
+ console.log(` ${chalk.green('✓')} ${inputStr} — ${contacts.length} contact(s)`);
628
+ for (const ct of contacts) {
629
+ const name = ct.full_name || [ct.first_name, ct.last_name].filter(Boolean).join(' ') || '—';
630
+ console.log(` ${chalk.cyan(String(ct.dm_person_id || '').padEnd(18))} ${name}`);
631
+ const phones = ct.phones;
632
+ if (phones && phones.length > 0) {
633
+ for (const ph of phones) {
634
+ console.log(` ${chalk.dim('phone:')} ${ph.number || ph.phone || '—'}`);
635
+ }
636
+ }
637
+ const emails = ct.emails;
638
+ if (emails && emails.length > 0) {
639
+ for (const em of emails) {
640
+ console.log(` ${chalk.dim('email:')} ${em.address || em.email || '—'}`);
641
+ }
642
+ }
643
+ }
644
+ }
645
+ console.log();
646
+ printCredits(data.credits);
647
+ console.log();
648
+ }
649
+ //# sourceMappingURL=enrich.js.map