reply-cli 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +104 -361
- package/dist/commands/auth.d.ts +5 -0
- package/dist/commands/auth.js +31 -0
- package/dist/commands/auth.js.map +1 -0
- package/dist/commands/contacts.d.ts +26 -11
- package/dist/commands/contacts.js +284 -193
- package/dist/commands/contacts.js.map +1 -1
- package/dist/commands/email-accounts.d.ts +11 -0
- package/dist/commands/email-accounts.js +97 -0
- package/dist/commands/email-accounts.js.map +1 -0
- package/dist/commands/inbox.d.ts +30 -0
- package/dist/commands/inbox.js +225 -0
- package/dist/commands/inbox.js.map +1 -0
- package/dist/commands/lists.d.ts +20 -0
- package/dist/commands/lists.js +137 -0
- package/dist/commands/lists.js.map +1 -0
- package/dist/commands/reports.d.ts +10 -0
- package/dist/commands/reports.js +70 -0
- package/dist/commands/reports.js.map +1 -0
- package/dist/commands/schedules.d.ts +1 -4
- package/dist/commands/schedules.js +19 -79
- package/dist/commands/schedules.js.map +1 -1
- package/dist/commands/sequence-contacts.d.ts +17 -6
- package/dist/commands/sequence-contacts.js +105 -117
- package/dist/commands/sequence-contacts.js.map +1 -1
- package/dist/commands/sequences-stats.d.ts +39 -4
- package/dist/commands/sequences-stats.js +75 -159
- package/dist/commands/sequences-stats.js.map +1 -1
- package/dist/commands/sequences.d.ts +16 -6
- package/dist/commands/sequences.js +118 -132
- package/dist/commands/sequences.js.map +1 -1
- package/dist/index.js +61 -26
- package/dist/index.js.map +1 -1
- package/dist/utils/client.d.ts +29 -2
- package/dist/utils/client.js +73 -54
- package/dist/utils/client.js.map +1 -1
- package/dist/utils/command.d.ts +8 -1
- package/dist/utils/command.js +32 -1
- package/dist/utils/command.js.map +1 -1
- package/dist/utils/csv.d.ts +19 -0
- package/dist/utils/csv.js +118 -0
- package/dist/utils/csv.js.map +1 -0
- package/dist/utils/output.d.ts +12 -3
- package/dist/utils/output.js +17 -7
- package/dist/utils/output.js.map +1 -1
- package/dist/utils/pagination.d.ts +22 -0
- package/dist/utils/pagination.js +37 -0
- package/dist/utils/pagination.js.map +1 -0
- package/dist/utils/resolve.d.ts +4 -0
- package/dist/utils/resolve.js +34 -0
- package/dist/utils/resolve.js.map +1 -0
- package/package.json +3 -3
- package/dist/commands/accounts.d.ts +0 -6
- package/dist/commands/accounts.js +0 -62
- package/dist/commands/accounts.js.map +0 -1
- package/dist/commands/import.d.ts +0 -6
- package/dist/commands/import.js +0 -137
- package/dist/commands/import.js.map +0 -1
|
@@ -1,17 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
6
|
+
exports.handle_import = exports.handle_statuses = exports.handle_search = exports.handle_delete = exports.handle_update = exports.handle_create = exports.handle_get = exports.handle_list = exports.contacts_command = void 0;
|
|
4
7
|
const commander_1 = require("commander");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
5
9
|
const client_1 = require("../utils/client");
|
|
6
10
|
const auth_1 = require("../utils/auth");
|
|
11
|
+
const command_1 = require("../utils/command");
|
|
12
|
+
const pagination_1 = require("../utils/pagination");
|
|
13
|
+
const resolve_1 = require("../utils/resolve");
|
|
14
|
+
const csv_1 = require("../utils/csv");
|
|
7
15
|
const output_1 = require("../utils/output");
|
|
8
|
-
const
|
|
16
|
+
const IMPORT_BATCH_SIZE = 1000;
|
|
17
|
+
const contact_table = (contacts) => {
|
|
18
|
+
(0, output_1.print_table)(contacts.map(c => ({
|
|
19
|
+
ID: String(c.id),
|
|
20
|
+
Email: c.email || '—',
|
|
21
|
+
Name: (0, output_1.truncate)(`${c.firstName || ''} ${c.lastName || ''}`.trim() || '—', 25),
|
|
22
|
+
Company: (0, output_1.truncate)(c.company || '—', 20),
|
|
23
|
+
Title: (0, output_1.truncate)(c.title || '—', 20),
|
|
24
|
+
Added: (0, output_1.format_date)(c.addingDate || ''),
|
|
25
|
+
})), ['ID', 'Email', 'Name', 'Company', 'Title', 'Added']);
|
|
26
|
+
};
|
|
9
27
|
const handle_list = async (api_key, opts) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
28
|
+
if (opts.all) {
|
|
29
|
+
const result = await (0, pagination_1.fetch_all)(api_key, '/contacts');
|
|
30
|
+
if (opts.json || opts.pretty) {
|
|
31
|
+
(0, output_1.print)(result, opts);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
contact_table(result.items);
|
|
35
|
+
(0, output_1.info)(`\nTotal: ${result.count} contacts (${result.pagesFetched} pages)`);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const top = parseInt(opts.limit || '25', 10);
|
|
39
|
+
const skip = parseInt(opts.skip || '0', 10);
|
|
40
|
+
const result = await (0, client_1.get)(api_key, `/contacts?top=${top}&skip=${skip}`);
|
|
41
|
+
if (!result?.items?.length) {
|
|
15
42
|
(0, output_1.info)('No contacts found.');
|
|
16
43
|
return;
|
|
17
44
|
}
|
|
@@ -19,39 +46,32 @@ const handle_list = async (api_key, opts) => {
|
|
|
19
46
|
(0, output_1.print)(result, opts);
|
|
20
47
|
return;
|
|
21
48
|
}
|
|
22
|
-
(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
Name: (0, output_1.truncate)(`${p.firstName || ''} ${p.lastName || ''}`.trim(), 25),
|
|
26
|
-
Company: (0, output_1.truncate)(p.company || '—', 20),
|
|
27
|
-
Title: (0, output_1.truncate)(p.title || '—', 20),
|
|
28
|
-
Added: (0, output_1.format_date)(p.addingDate),
|
|
29
|
-
})), ['ID', 'Email', 'Name', 'Company', 'Title', 'Added']);
|
|
30
|
-
const total = result?.total;
|
|
31
|
-
const pages_count = result?.pagesCount;
|
|
32
|
-
if (total)
|
|
33
|
-
(0, output_1.info)(`\nShowing page ${page}/${pages_count || '?'} (${people.length} of ${total} contacts). Use --page N to paginate.`);
|
|
49
|
+
contact_table(result.items);
|
|
50
|
+
(0, output_1.info)(`\nShowing ${result.items.length} contacts (skip: ${skip}).`
|
|
51
|
+
+ (result.hasMore ? ' More available — use --skip or --all.' : ''));
|
|
34
52
|
};
|
|
35
53
|
exports.handle_list = handle_list;
|
|
36
54
|
const handle_get = async (api_key, id_or_email, print_opts) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
55
|
+
let contact;
|
|
56
|
+
if ((0, resolve_1.is_email)(id_or_email)) {
|
|
57
|
+
const res = await (0, client_1.get)(api_key, `/contacts?email=${encodeURIComponent(id_or_email)}`);
|
|
58
|
+
contact = res?.items?.[0] ?? null;
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
contact = await (0, client_1.get)(api_key, `/contacts/${id_or_email}`);
|
|
62
|
+
if (!contact) {
|
|
42
63
|
(0, output_1.info)('Contact not found.');
|
|
43
64
|
return;
|
|
44
65
|
}
|
|
45
|
-
(0, output_1.print)(
|
|
66
|
+
(0, output_1.print)(contact, { ...print_opts, pretty: print_opts.pretty ?? true });
|
|
46
67
|
};
|
|
47
68
|
exports.handle_get = handle_get;
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
firstName
|
|
54
|
-
};
|
|
69
|
+
const contact_body_from_opts = (opts) => {
|
|
70
|
+
const body = {};
|
|
71
|
+
if (opts.email)
|
|
72
|
+
body.email = opts.email;
|
|
73
|
+
if (opts.firstName)
|
|
74
|
+
body.firstName = opts.firstName;
|
|
55
75
|
if (opts.lastName)
|
|
56
76
|
body.lastName = opts.lastName;
|
|
57
77
|
if (opts.company)
|
|
@@ -61,152 +81,229 @@ const handle_create = async (api_key, opts, print_opts) => {
|
|
|
61
81
|
if (opts.phone)
|
|
62
82
|
body.phone = opts.phone;
|
|
63
83
|
if (opts.linkedin)
|
|
64
|
-
body.
|
|
84
|
+
body.linkedInUrl = opts.linkedin;
|
|
65
85
|
if (opts.city)
|
|
66
86
|
body.city = opts.city;
|
|
67
87
|
if (opts.state)
|
|
68
88
|
body.state = opts.state;
|
|
69
89
|
if (opts.country)
|
|
70
90
|
body.country = opts.country;
|
|
71
|
-
if (opts.
|
|
72
|
-
body.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
if (opts.industry)
|
|
92
|
+
body.industry = opts.industry;
|
|
93
|
+
if (opts.notes)
|
|
94
|
+
body.notes = opts.notes;
|
|
95
|
+
return body;
|
|
96
|
+
};
|
|
97
|
+
const parse_custom_pairs = (custom) => custom.split(',').map(pair => {
|
|
98
|
+
const [key, ...val_parts] = pair.split('=');
|
|
99
|
+
return { key: key.trim(), value: val_parts.join('=').trim() };
|
|
100
|
+
});
|
|
101
|
+
const handle_create = async (api_key, opts, print_opts) => {
|
|
102
|
+
if (!opts.email && !opts.linkedin)
|
|
103
|
+
(0, output_1.fail)('Required: --email (or --linkedin)');
|
|
104
|
+
const body = contact_body_from_opts(opts);
|
|
105
|
+
if (opts.custom)
|
|
106
|
+
body.customFields = parse_custom_pairs(opts.custom);
|
|
107
|
+
const result = await (0, client_1.post)(api_key, '/contacts', body);
|
|
108
|
+
(0, output_1.success)(`Contact created: ${result.firstName || ''} ${result.lastName || ''} <${result.email || '—'}> (ID: ${result.id})`);
|
|
79
109
|
if (print_opts.json || print_opts.pretty)
|
|
80
110
|
(0, output_1.print)(result, print_opts);
|
|
81
111
|
};
|
|
82
112
|
exports.handle_create = handle_create;
|
|
83
|
-
const handle_update = async (api_key, opts, print_opts) => {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (opts.
|
|
88
|
-
body.
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (opts.title)
|
|
94
|
-
body.title = opts.title;
|
|
95
|
-
if (opts.phone)
|
|
96
|
-
body.phone = opts.phone;
|
|
97
|
-
if (opts.linkedin)
|
|
98
|
-
body.linkedInProfile = opts.linkedin;
|
|
99
|
-
if (opts.city)
|
|
100
|
-
body.city = opts.city;
|
|
101
|
-
if (opts.state)
|
|
102
|
-
body.state = opts.state;
|
|
103
|
-
if (opts.country)
|
|
104
|
-
body.country = opts.country;
|
|
105
|
-
const result = await (0, client_1.post)(api_key, '/v1/people', body);
|
|
106
|
-
(0, output_1.success)(`Contact updated: ${result.email} (ID: ${result.id})`);
|
|
113
|
+
const handle_update = async (api_key, id_or_email, opts, print_opts) => {
|
|
114
|
+
const id = await (0, resolve_1.resolve_contact_id)(api_key, id_or_email);
|
|
115
|
+
const body = contact_body_from_opts(opts);
|
|
116
|
+
// PATCH custom fields are matched by name (or id), not key
|
|
117
|
+
if (opts.custom)
|
|
118
|
+
body.customFields = parse_custom_pairs(opts.custom).map(f => ({ name: f.key, value: f.value }));
|
|
119
|
+
if (!Object.keys(body).length)
|
|
120
|
+
(0, output_1.fail)('Nothing to update — pass at least one field flag.');
|
|
121
|
+
const result = await (0, client_1.patch)(api_key, `/contacts/${id}`, body);
|
|
122
|
+
(0, output_1.success)(`Contact updated: ${result.email || result.id} (ID: ${result.id})`);
|
|
107
123
|
if (print_opts.json || print_opts.pretty)
|
|
108
124
|
(0, output_1.print)(result, print_opts);
|
|
109
125
|
};
|
|
110
126
|
exports.handle_update = handle_update;
|
|
111
|
-
const handle_delete = async (api_key, id_or_email) => {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
await (0, client_1.del)(api_key, `/v1/people/?id=${id_or_email}`);
|
|
118
|
-
(0, output_1.success)(`Deleted contact ID: ${id_or_email}`);
|
|
119
|
-
}
|
|
127
|
+
const handle_delete = async (api_key, id_or_email, opts) => {
|
|
128
|
+
const id = await (0, resolve_1.resolve_contact_id)(api_key, id_or_email);
|
|
129
|
+
await (0, command_1.confirm_or_abort)(`Delete contact ${id_or_email} (ID: ${id})? This cannot be undone.`, opts);
|
|
130
|
+
await (0, client_1.del)(api_key, `/contacts/${id}`);
|
|
131
|
+
(0, output_1.success)(`Deleted contact: ${id_or_email} (ID: ${id})`);
|
|
120
132
|
};
|
|
121
133
|
exports.handle_delete = handle_delete;
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
const parse_rules = (rules) => rules.map(rule => {
|
|
135
|
+
const eq = rule.indexOf('=');
|
|
136
|
+
const colon = rule.indexOf(':', eq + 1);
|
|
137
|
+
if (eq < 1 || colon < 0)
|
|
138
|
+
(0, output_1.fail)(`Invalid --rule format: ${rule}\n Expected: property=condition:value (e.g. country=equals:Germany)`);
|
|
139
|
+
return {
|
|
140
|
+
property: rule.slice(0, eq).trim(),
|
|
141
|
+
condition: rule.slice(eq + 1, colon).trim(),
|
|
142
|
+
value: rule.slice(colon + 1).trim() || null,
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
const handle_search = async (api_key, opts) => {
|
|
146
|
+
const body = {};
|
|
147
|
+
if (opts.term)
|
|
148
|
+
body.searchTerm = opts.term;
|
|
149
|
+
if (opts.list)
|
|
150
|
+
body.listId = parseInt(opts.list, 10);
|
|
151
|
+
if (opts.sequence)
|
|
152
|
+
body.sequenceId = parseInt(opts.sequence, 10);
|
|
153
|
+
if (opts.rule?.length)
|
|
154
|
+
body.rules = parse_rules(opts.rule);
|
|
155
|
+
if (!Object.keys(body).length)
|
|
156
|
+
(0, output_1.fail)('Provide at least one of --term, --list, --sequence, or --rule.');
|
|
157
|
+
if (opts.all) {
|
|
158
|
+
const result = await (0, pagination_1.fetch_all)(api_key, '/contacts/filter', { method: 'POST', body });
|
|
159
|
+
if (opts.json || opts.pretty) {
|
|
160
|
+
(0, output_1.print)(result, opts);
|
|
161
|
+
return;
|
|
128
162
|
}
|
|
129
|
-
|
|
130
|
-
|
|
163
|
+
contact_table(result.items);
|
|
164
|
+
(0, output_1.info)(`\nTotal: ${result.count} contacts (${result.pagesFetched} pages)`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const top = parseInt(opts.limit || '25', 10);
|
|
168
|
+
const skip = parseInt(opts.skip || '0', 10);
|
|
169
|
+
const result = await (0, client_1.post)(api_key, (0, pagination_1.with_query)('/contacts/filter', top, skip), body);
|
|
170
|
+
if (!result?.items?.length) {
|
|
171
|
+
(0, output_1.info)('No contacts matched.');
|
|
172
|
+
return;
|
|
131
173
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
(0, output_1.success)(`Found contact IDs: ${result.ids.join(', ')}`);
|
|
136
|
-
else
|
|
137
|
-
(0, output_1.info)('No contacts found for that LinkedIn URL.');
|
|
174
|
+
if (opts.json || opts.pretty) {
|
|
175
|
+
(0, output_1.print)(result, opts);
|
|
176
|
+
return;
|
|
138
177
|
}
|
|
139
|
-
|
|
140
|
-
|
|
178
|
+
contact_table(result.items);
|
|
179
|
+
(0, output_1.info)(`\nShowing ${result.items.length} contacts.`
|
|
180
|
+
+ (result.hasMore ? ' More available — use --skip or --all.' : ''));
|
|
141
181
|
};
|
|
142
182
|
exports.handle_search = handle_search;
|
|
143
|
-
const
|
|
144
|
-
await (0,
|
|
145
|
-
(0,
|
|
146
|
-
};
|
|
147
|
-
exports.handle_mark_replied = handle_mark_replied;
|
|
148
|
-
const handle_mark_finished = async (api_key, email) => {
|
|
149
|
-
await (0, client_1.post)(api_key, '/v1/actions/markasfinished', { email });
|
|
150
|
-
(0, output_1.success)(`Contact ${email} marked as finished in all sequences.`);
|
|
151
|
-
};
|
|
152
|
-
exports.handle_mark_finished = handle_mark_finished;
|
|
153
|
-
const handle_opt_out = async (api_key, email) => {
|
|
154
|
-
await (0, client_1.post)(api_key, '/v1/actions/removepersonfromallcampaigns', { email });
|
|
155
|
-
(0, output_1.success)(`Contact ${email} removed from all sequences (opted out).`);
|
|
156
|
-
};
|
|
157
|
-
exports.handle_opt_out = handle_opt_out;
|
|
158
|
-
const handle_stats = async (api_key, email, print_opts) => {
|
|
159
|
-
const encoded_email = email.replace('@', '%40');
|
|
160
|
-
const result = await (0, client_1.get)(api_key, `/v1/stats/person?email=${encoded_email}`);
|
|
161
|
-
if (!result) {
|
|
162
|
-
(0, output_1.info)('Contact not found.');
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
183
|
+
const handle_statuses = async (api_key, id_or_email, print_opts) => {
|
|
184
|
+
const id = await (0, resolve_1.resolve_contact_id)(api_key, id_or_email);
|
|
185
|
+
const result = await (0, client_1.get)(api_key, `/contacts/${id}/statuses`);
|
|
165
186
|
if (print_opts.json || print_opts.pretty) {
|
|
166
187
|
(0, output_1.print)(result, print_opts);
|
|
167
188
|
return;
|
|
168
189
|
}
|
|
169
|
-
console.log(`\nContact: ${output_1.pc.bold(result.
|
|
170
|
-
console.log(` Email: ${result.email}`);
|
|
171
|
-
console.log(` Blocked: ${result.isBlocked ? output_1.pc.red('Yes') : output_1.pc.green('No')}`);
|
|
190
|
+
console.log(`\nContact ID: ${output_1.pc.bold(String(result.contactId))}`);
|
|
172
191
|
console.log(` Opted out: ${result.isOptedOut ? output_1.pc.red('Yes') : output_1.pc.green('No')}`);
|
|
173
|
-
console.log();
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (c.emails?.length) {
|
|
184
|
-
console.log(output_1.pc.bold(`\n ${c.name} — Emails:`));
|
|
185
|
-
for (const e of c.emails) {
|
|
186
|
-
const status = e.isOpened ? output_1.pc.green('opened') : output_1.pc.dim('not opened');
|
|
187
|
-
const reply = e.isReplied ? ` | ${output_1.pc.green('replied')}` : '';
|
|
188
|
-
console.log(` ${output_1.pc.dim((0, output_1.format_date)(e.sentDate))} ${output_1.pc.cyan((0, output_1.truncate)(e.subject || '(no subject)', 50))} [${status}${reply}]`);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
+
console.log(` Call: ${result.callStatus}`);
|
|
193
|
+
console.log(` Meeting: ${result.meetingStatus === 'meetingBooked' ? output_1.pc.green('Booked') : '—'}`);
|
|
194
|
+
if (result.sequences?.length) {
|
|
195
|
+
console.log();
|
|
196
|
+
(0, output_1.print_table)(result.sequences.map(s => ({
|
|
197
|
+
Sequence: (0, output_1.truncate)(s.sequenceName || String(s.sequenceId), 30),
|
|
198
|
+
Status: s.statusInSequence,
|
|
199
|
+
Replied: s.emailDisposition?.isReplied ? output_1.pc.green('Yes') : 'No',
|
|
200
|
+
Bounced: s.emailDisposition?.isBounced ? output_1.pc.red('Yes') : 'No',
|
|
201
|
+
})), ['Sequence', 'Status', 'Replied', 'Bounced']);
|
|
192
202
|
}
|
|
193
203
|
else
|
|
194
|
-
(0, output_1.info)('
|
|
204
|
+
(0, output_1.info)('\nNot in any sequences.');
|
|
195
205
|
};
|
|
196
|
-
exports.
|
|
206
|
+
exports.handle_statuses = handle_statuses;
|
|
207
|
+
const handle_import = async (api_key, file_path, opts) => {
|
|
208
|
+
if (!file_path || !fs_1.default.existsSync(file_path))
|
|
209
|
+
(0, output_1.fail)(`CSV file not found: ${file_path}`);
|
|
210
|
+
const { headers, rows } = (0, csv_1.parse_csv)(fs_1.default.readFileSync(file_path, 'utf-8'));
|
|
211
|
+
if (!headers.length || !rows.length)
|
|
212
|
+
(0, output_1.fail)('CSV file is empty or has no data rows.');
|
|
213
|
+
let overrides = {};
|
|
214
|
+
if (opts.mapping) {
|
|
215
|
+
try {
|
|
216
|
+
overrides = JSON.parse(opts.mapping);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
(0, output_1.fail)('--mapping must be valid JSON, e.g. \'{"email":"Email Address"}\'');
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let mapping;
|
|
223
|
+
try {
|
|
224
|
+
mapping = (0, csv_1.map_columns)(headers, overrides);
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
return (0, output_1.fail)(e.message);
|
|
228
|
+
}
|
|
229
|
+
if (!mapping.mapped.length)
|
|
230
|
+
(0, output_1.fail)('No CSV columns could be mapped to Reply fields.\n'
|
|
231
|
+
+ ` Columns found: ${headers.join(', ')}\n`
|
|
232
|
+
+ ` Use --mapping '{"field":"CSV Header"}'. Valid fields: ${csv_1.STANDARD_FIELDS.join(', ')}`);
|
|
233
|
+
const items = (0, csv_1.rows_to_items)(rows, mapping);
|
|
234
|
+
const options = {};
|
|
235
|
+
if (opts.list)
|
|
236
|
+
options.listIds = [parseInt(opts.list, 10)];
|
|
237
|
+
if (opts.sequence)
|
|
238
|
+
options.sequenceId = parseInt(opts.sequence, 10);
|
|
239
|
+
if (opts.skipExisting)
|
|
240
|
+
options.skipExisting = true;
|
|
241
|
+
if (opts.overwrite)
|
|
242
|
+
options.overwriteExisting = true;
|
|
243
|
+
if (opts.detectTimezone)
|
|
244
|
+
options.detectTimeZone = true;
|
|
245
|
+
if (mapping.unmapped.length)
|
|
246
|
+
(0, output_1.warn)(`Unmapped CSV columns (ignored): ${mapping.unmapped.join(', ')}`);
|
|
247
|
+
for (const { header, field } of mapping.mapped)
|
|
248
|
+
(0, output_1.info)(` ${header} → ${field}`);
|
|
249
|
+
if (opts.dryRun) {
|
|
250
|
+
(0, output_1.print_dry_run)({
|
|
251
|
+
dryRun: true,
|
|
252
|
+
action: 'contacts.import',
|
|
253
|
+
method: 'POST',
|
|
254
|
+
path: '/v3/contacts/import',
|
|
255
|
+
payload: {
|
|
256
|
+
mapping: mapping.mapped.map(m => ({ column: m.header, field: m.field })),
|
|
257
|
+
unmappedColumns: mapping.unmapped,
|
|
258
|
+
options,
|
|
259
|
+
sampleItems: items.slice(0, 5),
|
|
260
|
+
},
|
|
261
|
+
affected: items.length,
|
|
262
|
+
}, opts);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
await (0, command_1.confirm_or_abort)(`Import ${items.length} contacts from ${file_path}`
|
|
266
|
+
+ (opts.list ? ` into list ${opts.list}` : '')
|
|
267
|
+
+ (opts.sequence ? ` and add to sequence ${opts.sequence}` : '') + '?', opts);
|
|
268
|
+
const totals = { added: 0, updated: 0, skipped: 0, failed: 0 };
|
|
269
|
+
const failures = [];
|
|
270
|
+
for (let offset = 0; offset < items.length; offset += IMPORT_BATCH_SIZE) {
|
|
271
|
+
const batch = items.slice(offset, offset + IMPORT_BATCH_SIZE);
|
|
272
|
+
const result = await (0, client_1.post)(api_key, '/contacts/import', { items: batch, options });
|
|
273
|
+
totals.added += result.added;
|
|
274
|
+
totals.updated += result.updated;
|
|
275
|
+
totals.skipped += result.skipped;
|
|
276
|
+
totals.failed += result.failed;
|
|
277
|
+
result.items.forEach((item, i) => {
|
|
278
|
+
if (item.status === 'failed')
|
|
279
|
+
failures.push({ row: offset + i + 2, error: item.error });
|
|
280
|
+
});
|
|
281
|
+
if (items.length > IMPORT_BATCH_SIZE)
|
|
282
|
+
(0, output_1.info)(`Batch ${Math.floor(offset / IMPORT_BATCH_SIZE) + 1}: ${batch.length} items sent.`);
|
|
283
|
+
}
|
|
284
|
+
(0, output_1.success)(`Import complete: ${totals.added} added, ${totals.updated} updated, `
|
|
285
|
+
+ `${totals.skipped} skipped, ${totals.failed} failed.`);
|
|
286
|
+
for (const f of failures.slice(0, 20))
|
|
287
|
+
(0, output_1.warn)(` Row ${f.row}: ${f.error || 'unknown error'}`);
|
|
288
|
+
if (failures.length > 20)
|
|
289
|
+
(0, output_1.warn)(` …and ${failures.length - 20} more failures.`);
|
|
290
|
+
if (opts.json || opts.pretty)
|
|
291
|
+
(0, output_1.print)({ action: 'contacts.import', ...totals, failures }, opts);
|
|
292
|
+
if (totals.failed > 0)
|
|
293
|
+
process.exit(1);
|
|
294
|
+
};
|
|
295
|
+
exports.handle_import = handle_import;
|
|
197
296
|
const contacts_command = new commander_1.Command('contacts')
|
|
198
297
|
.description('Manage contacts (prospects)');
|
|
199
298
|
exports.contacts_command = contacts_command;
|
|
200
|
-
contacts_command
|
|
299
|
+
(0, command_1.with_pagination_opts)(contacts_command
|
|
201
300
|
.command('list')
|
|
202
|
-
.description('List contacts
|
|
203
|
-
.
|
|
204
|
-
.option('--limit <n>', 'Contacts per page (default: 25)')
|
|
205
|
-
.addHelpText('after', '\nExamples:\n reply contacts list\n reply contacts list --page 2 --limit 50')
|
|
301
|
+
.description('List contacts'))
|
|
302
|
+
.addHelpText('after', '\nExamples:\n reply contacts list\n reply contacts list --limit 100 --skip 100\n reply contacts list --all --json')
|
|
206
303
|
.action(async function () {
|
|
207
304
|
const opts = this.optsWithGlobals();
|
|
208
305
|
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
209
|
-
await handle_list(key,
|
|
306
|
+
await handle_list(key, opts);
|
|
210
307
|
});
|
|
211
308
|
contacts_command
|
|
212
309
|
.command('get')
|
|
@@ -221,8 +318,8 @@ contacts_command
|
|
|
221
318
|
contacts_command
|
|
222
319
|
.command('create')
|
|
223
320
|
.description('Create a new contact')
|
|
224
|
-
.
|
|
225
|
-
.
|
|
321
|
+
.option('--email <email>', 'Email address')
|
|
322
|
+
.option('--first-name <name>', 'First name')
|
|
226
323
|
.option('--last-name <name>', 'Last name')
|
|
227
324
|
.option('--company <company>', 'Company name')
|
|
228
325
|
.option('--title <title>', 'Job title')
|
|
@@ -231,8 +328,10 @@ contacts_command
|
|
|
231
328
|
.option('--city <city>', 'City')
|
|
232
329
|
.option('--state <state>', 'State')
|
|
233
330
|
.option('--country <country>', 'Country')
|
|
331
|
+
.option('--industry <industry>', 'Industry')
|
|
332
|
+
.option('--notes <notes>', 'Notes')
|
|
234
333
|
.option('--custom <fields>', 'Custom fields: Key1=Val1,Key2=Val2')
|
|
235
|
-
.addHelpText('after', '\nExamples:\n reply contacts create --email john@co.com --first-name John --company Acme')
|
|
334
|
+
.addHelpText('after', '\nRequires --email or --linkedin.\n\nExamples:\n reply contacts create --email john@co.com --first-name John --company Acme')
|
|
236
335
|
.action(async function () {
|
|
237
336
|
const opts = this.optsWithGlobals();
|
|
238
337
|
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
@@ -240,8 +339,9 @@ contacts_command
|
|
|
240
339
|
});
|
|
241
340
|
contacts_command
|
|
242
341
|
.command('update')
|
|
243
|
-
.description('Update an existing contact
|
|
244
|
-
.
|
|
342
|
+
.description('Update an existing contact by ID or email')
|
|
343
|
+
.argument('<id-or-email>', 'Contact ID or email address')
|
|
344
|
+
.option('--email <email>', 'New email address')
|
|
245
345
|
.option('--first-name <name>', 'First name')
|
|
246
346
|
.option('--last-name <name>', 'Last name')
|
|
247
347
|
.option('--company <company>', 'Company name')
|
|
@@ -251,71 +351,62 @@ contacts_command
|
|
|
251
351
|
.option('--city <city>', 'City')
|
|
252
352
|
.option('--state <state>', 'State')
|
|
253
353
|
.option('--country <country>', 'Country')
|
|
254
|
-
.
|
|
255
|
-
.
|
|
354
|
+
.option('--industry <industry>', 'Industry')
|
|
355
|
+
.option('--notes <notes>', 'Notes')
|
|
356
|
+
.option('--custom <fields>', 'Custom fields by name: Name1=Val1,Name2=Val2')
|
|
357
|
+
.addHelpText('after', '\nExamples:\n reply contacts update john@co.com --company "New Corp"\n reply contacts update 12345678 --title CTO')
|
|
358
|
+
.action(async function (id_or_email) {
|
|
256
359
|
const opts = this.optsWithGlobals();
|
|
257
360
|
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
258
|
-
await handle_update(key, opts, { json: opts.json, pretty: opts.pretty });
|
|
361
|
+
await handle_update(key, id_or_email, opts, { json: opts.json, pretty: opts.pretty });
|
|
259
362
|
});
|
|
260
|
-
contacts_command
|
|
363
|
+
(0, command_1.with_confirm_opts)(contacts_command
|
|
261
364
|
.command('delete')
|
|
262
365
|
.description('Delete a contact by ID or email')
|
|
263
|
-
.argument('<id-or-email>', 'Contact ID or email address')
|
|
264
|
-
.addHelpText('after', '\nExamples:\n reply contacts delete john@example.com
|
|
366
|
+
.argument('<id-or-email>', 'Contact ID or email address'))
|
|
367
|
+
.addHelpText('after', '\nExamples:\n reply contacts delete john@example.com --yes')
|
|
265
368
|
.action(async function (id_or_email) {
|
|
266
369
|
const opts = this.optsWithGlobals();
|
|
267
370
|
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
268
|
-
await handle_delete(key, id_or_email);
|
|
371
|
+
await handle_delete(key, id_or_email, { yes: opts.yes });
|
|
269
372
|
});
|
|
270
|
-
contacts_command
|
|
373
|
+
(0, command_1.with_pagination_opts)(contacts_command
|
|
271
374
|
.command('search')
|
|
272
|
-
.description('Search
|
|
273
|
-
.option('--
|
|
274
|
-
.option('--
|
|
275
|
-
.
|
|
375
|
+
.description('Search contacts with filters')
|
|
376
|
+
.option('--term <text>', 'Free-text search term')
|
|
377
|
+
.option('--list <id>', 'Only contacts in this list')
|
|
378
|
+
.option('--sequence <id>', 'Only contacts in this sequence')
|
|
379
|
+
.option('--rule <rule...>', 'Filter rule: property=condition:value (repeatable)'))
|
|
380
|
+
.addHelpText('after', '\nExamples:\n reply contacts search --term "acme.com"\n reply contacts search --list 42 --all --json\n reply contacts search --rule country=equals:Germany')
|
|
276
381
|
.action(async function () {
|
|
277
382
|
const opts = this.optsWithGlobals();
|
|
278
383
|
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
279
|
-
await handle_search(key,
|
|
280
|
-
});
|
|
281
|
-
contacts_command
|
|
282
|
-
.command('mark-replied')
|
|
283
|
-
.description('Mark a contact as replied in all sequences')
|
|
284
|
-
.argument('<email>', 'Contact email address')
|
|
285
|
-
.addHelpText('after', '\nExamples:\n reply contacts mark-replied john@co.com')
|
|
286
|
-
.action(async function (email) {
|
|
287
|
-
const opts = this.optsWithGlobals();
|
|
288
|
-
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
289
|
-
await handle_mark_replied(key, email);
|
|
290
|
-
});
|
|
291
|
-
contacts_command
|
|
292
|
-
.command('mark-finished')
|
|
293
|
-
.description('Mark a contact as finished in all sequences')
|
|
294
|
-
.argument('<email>', 'Contact email address')
|
|
295
|
-
.addHelpText('after', '\nExamples:\n reply contacts mark-finished john@co.com')
|
|
296
|
-
.action(async function (email) {
|
|
297
|
-
const opts = this.optsWithGlobals();
|
|
298
|
-
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
299
|
-
await handle_mark_finished(key, email);
|
|
384
|
+
await handle_search(key, opts);
|
|
300
385
|
});
|
|
301
386
|
contacts_command
|
|
302
|
-
.command('
|
|
303
|
-
.description('
|
|
304
|
-
.argument('<email>', 'Contact email address')
|
|
305
|
-
.addHelpText('after', '\nExamples:\n reply contacts
|
|
306
|
-
.action(async function (
|
|
387
|
+
.command('statuses')
|
|
388
|
+
.description('Show a contact\'s opt-out, call, meeting, and per-sequence status')
|
|
389
|
+
.argument('<id-or-email>', 'Contact ID or email address')
|
|
390
|
+
.addHelpText('after', '\nExamples:\n reply contacts statuses john@co.com')
|
|
391
|
+
.action(async function (id_or_email) {
|
|
307
392
|
const opts = this.optsWithGlobals();
|
|
308
393
|
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
309
|
-
await
|
|
394
|
+
await handle_statuses(key, id_or_email, { json: opts.json, pretty: opts.pretty });
|
|
310
395
|
});
|
|
311
|
-
contacts_command
|
|
312
|
-
.command('
|
|
313
|
-
.description('
|
|
314
|
-
.argument('<
|
|
315
|
-
.
|
|
316
|
-
.
|
|
396
|
+
(0, command_1.with_confirm_opts)(contacts_command
|
|
397
|
+
.command('import')
|
|
398
|
+
.description('Import contacts from a CSV file')
|
|
399
|
+
.argument('<file>', 'Path to CSV file')
|
|
400
|
+
.option('--mapping <json>', 'Override column mapping: {"field":"CSV Header"}')
|
|
401
|
+
.option('--list <id>', 'Add imported contacts to a list')
|
|
402
|
+
.option('--sequence <id>', 'Add imported contacts to a sequence')
|
|
403
|
+
.option('--skip-existing', 'Skip contacts that already exist')
|
|
404
|
+
.option('--overwrite', 'Overwrite fields of existing contacts')
|
|
405
|
+
.option('--detect-timezone', 'Detect timezone from location'), { dry_run: true })
|
|
406
|
+
.addHelpText('after', '\nColumns are auto-mapped by header name; use --mapping to override.\nAlways run with --dry-run first to check the mapping.\n\nExamples:\n reply contacts import prospects.csv --dry-run\n reply contacts import prospects.csv --list 42 --skip-existing --yes --json')
|
|
407
|
+
.action(async function (file) {
|
|
317
408
|
const opts = this.optsWithGlobals();
|
|
318
409
|
const key = (0, auth_1.resolve_api_key)(opts.apiKey);
|
|
319
|
-
await
|
|
410
|
+
await handle_import(key, file, opts);
|
|
320
411
|
});
|
|
321
412
|
//# sourceMappingURL=contacts.js.map
|