reply-cli 0.11.0 → 0.14.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 (39) hide show
  1. package/README.md +80 -7
  2. package/dist/index.js +2 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/operations/accounts.d.ts +6 -0
  5. package/dist/operations/accounts.js +73 -0
  6. package/dist/operations/accounts.js.map +1 -0
  7. package/dist/operations/commands.d.ts +2 -1
  8. package/dist/operations/commands.js +217 -18
  9. package/dist/operations/commands.js.map +1 -1
  10. package/dist/operations/contact-input.d.ts +7 -3
  11. package/dist/operations/contact-input.js +51 -12
  12. package/dist/operations/contact-input.js.map +1 -1
  13. package/dist/operations/contact-record.d.ts +11 -0
  14. package/dist/operations/contact-record.js +176 -0
  15. package/dist/operations/contact-record.js.map +1 -0
  16. package/dist/operations/contact.js +8 -4
  17. package/dist/operations/contact.js.map +1 -1
  18. package/dist/operations/contacts.d.ts +7 -3
  19. package/dist/operations/contacts.js +94 -29
  20. package/dist/operations/contacts.js.map +1 -1
  21. package/dist/operations/direct-send.d.ts +12 -0
  22. package/dist/operations/direct-send.js +185 -0
  23. package/dist/operations/direct-send.js.map +1 -0
  24. package/dist/operations/inbox-reply.d.ts +11 -0
  25. package/dist/operations/inbox-reply.js +160 -0
  26. package/dist/operations/inbox-reply.js.map +1 -0
  27. package/dist/operations/inbox.d.ts +19 -1
  28. package/dist/operations/inbox.js +105 -1
  29. package/dist/operations/inbox.js.map +1 -1
  30. package/dist/operations/options.d.ts +3 -2
  31. package/dist/operations/options.js +8 -4
  32. package/dist/operations/options.js.map +1 -1
  33. package/dist/operations/sequence-by-name.d.ts +9 -0
  34. package/dist/operations/sequence-by-name.js +96 -0
  35. package/dist/operations/sequence-by-name.js.map +1 -0
  36. package/dist/operations/stdin-input.d.ts +10 -0
  37. package/dist/operations/stdin-input.js +34 -0
  38. package/dist/operations/stdin-input.js.map +1 -0
  39. package/package.json +1 -1
@@ -1,12 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.read_opted_out = exports.find_contact = exports.ensure_contact = void 0;
3
+ exports.contact_not_found = exports.read_opted_out = exports.find_contact_by_address = exports.find_contact = exports.import_contact = exports.ensure_contact = void 0;
4
4
  const errors_1 = require("../utils/errors");
5
5
  const call_1 = require("./call");
6
+ const contact_input_1 = require("./contact-input");
6
7
  const LOOKUP_PAGE = 100;
7
- const LOOKUP_PAGES = 5;
8
+ const LOOKUP_PAGES = 10;
8
9
  const import_item = (p) => {
9
- const item = { email: p.email };
10
+ const item = {};
11
+ if (p.email !== undefined) {
12
+ item.email = p.email;
13
+ }
14
+ if (p.linkedin_url !== undefined) {
15
+ // Written in the form it is looked up by.
16
+ item.linkedInUrl = (0, contact_input_1.linkedin_key)(p.linkedin_url) ?? p.linkedin_url;
17
+ }
10
18
  if (p.first_name !== undefined) {
11
19
  item.firstName = p.first_name;
12
20
  }
@@ -21,19 +29,30 @@ const import_item = (p) => {
21
29
  }
22
30
  return item;
23
31
  };
24
- const names_email = (a) => (0, call_1.invalid_fields)(a)?.some(field => field.toLowerCase() === 'email') === true;
32
+ const names_field = (a, name) => (0, call_1.invalid_fields)(a)?.some(field => field.toLowerCase() === name.toLowerCase()) === true;
25
33
  // v3's import matches an existing contact by email or creates one, and says which, in one call; on
26
- // a match it fills only the contact's empty fields. Reply requires a first name here, even for an
27
- // email it already holds, and refuses an item without one as "Invalid data", which is passed on as
34
+ // a match it fills only the contact's empty fields. A contact with no email is matched by its
35
+ // LinkedIn URL instead: the import's keys add to the email rather than replace it, so that key is
36
+ // asked for only when there is no email to match. Reply requires a first name here, even for a
37
+ // contact it already holds, and refuses an item without one as "Invalid data", which is passed on as
28
38
  // reply.refused. POST /v3/contacts is not used: it also requires a first name, and for an email Reply
29
39
  // already holds it overwrites that contact and blanks every field the request did not send.
30
40
  const import_contact = async (s, person) => {
31
- const a = await (0, call_1.call_reply)(s, 'POST', '/v3/contacts/import', 'write', { items: [import_item(person)] });
32
- if (a.status === 400 && names_email(a)) {
41
+ const body = { items: [import_item(person)] };
42
+ if (person.email === undefined) {
43
+ body.options = { keys: { linkedInUrl: true } };
44
+ }
45
+ const a = await (0, call_1.call_reply)(s, 'POST', '/v3/contacts/import', 'write', body);
46
+ if (a.status === 400 && names_field(a, 'email')) {
33
47
  throw new errors_1.Operation_error('contact.invalid_email', 'Reply did not accept the contact\'s email address.', {
34
48
  status: 400, reply_code: (0, call_1.reply_code_of)(a),
35
49
  });
36
50
  }
51
+ if (a.status === 400 && names_field(a, 'linkedInUrl')) {
52
+ throw new errors_1.Operation_error('contact.invalid_linkedin_url', 'Reply did not accept the contact\'s LinkedIn URL.', {
53
+ status: 400, reply_code: (0, call_1.reply_code_of)(a),
54
+ });
55
+ }
37
56
  if (a.status === 400 && (0, call_1.reply_code_of)(a) === 'contact.limitExceeded') {
38
57
  throw new errors_1.Operation_error('account.contact_limit_reached', 'The account holds as many contacts as its plan allows.', {
39
58
  status: 400, reply_code: 'contact.limitExceeded', detail: (0, call_1.detail_of)(a),
@@ -42,8 +61,8 @@ const import_contact = async (s, person) => {
42
61
  if (a.status !== 200) {
43
62
  throw (0, call_1.refusal)(a, 'write');
44
63
  }
45
- const body = (0, call_1.expect_object)(a, 'write');
46
- const item = Array.isArray(body.items) ? body.items[0] : undefined;
64
+ const answer = (0, call_1.expect_object)(a, 'write');
65
+ const item = Array.isArray(answer.items) ? answer.items[0] : undefined;
47
66
  if (!(0, call_1.is_object)(item)) {
48
67
  throw (0, call_1.unreadable)(a, 'write');
49
68
  }
@@ -58,32 +77,49 @@ const import_contact = async (s, person) => {
58
77
  }
59
78
  return { id: item.id, created: item.status === 'created' };
60
79
  };
61
- const ensure_contact = async (s, ref) => ref.kind === 'id' ? { id: ref.id, created: false } : import_contact(s, ref.person);
62
- exports.ensure_contact = ensure_contact;
63
- // INTERIM (API gap): POST /v3/contacts/filter has no exact-email filter. Its `rules` take a
64
- // property/condition vocabulary that v3 publishes nowhere, and its `searchTerm` matches by
65
- // containment, so "ann@example.com" also finds "joann@example.com".
66
- // Needed: an exact email lookup, or a documented `rules` vocabulary.
67
- // Workaround: page through the searchTerm matches (5 pages of 100) and compare addresses exactly,
68
- // ignoring case. Refuse rather than guess when two match or the end isn't reached.
69
- const find_contact_by_exact_email = async (s, email) => {
70
- const wanted = email.toLowerCase();
71
- let found = null;
80
+ exports.import_contact = import_contact;
81
+ // What a person is looked up by: the email when there is one, else the LinkedIn URL. An entry
82
+ // counts only when it carries the same address: an email equal ignoring case, a LinkedIn URL equal
83
+ // under linkedin_key.
84
+ // INTERIM (API gap): the document does not say whether the exact lookup by LinkedIn URL ignores case.
85
+ // Needed: a lookup that matches a LinkedIn URL by its slug whatever its case, or a word that it does.
86
+ // Workaround: ask with the URL in the form it is written in (its lowercased slug) first, then as
87
+ // given, and count the matches of both together, so one slug held under two spellings is refused
88
+ // rather than half seen.
89
+ const lookup_of = (p) => {
90
+ if (p.email !== undefined) {
91
+ const wanted = p.email.toLowerCase();
92
+ return { param: 'email', values: [p.email], holds: entry => typeof entry.email === 'string' && entry.email.toLowerCase() === wanted };
93
+ }
94
+ const given = p.linkedin_url;
95
+ const wanted = (0, contact_input_1.linkedin_key)(given);
96
+ return {
97
+ param: 'linkedIn', values: wanted === given ? [wanted] : [wanted, given],
98
+ holds: entry => typeof entry.linkedInUrl === 'string' && (0, contact_input_1.linkedin_key)(entry.linkedInUrl) === wanted,
99
+ };
100
+ };
101
+ // GET /v3/contacts looks a contact up by exact email or LinkedIn URL. Each answer is read to its end,
102
+ // and only entries carrying the asked address count; the contact found so far, if any, is carried in.
103
+ // Two contacts under one address is refused rather than guessed between. An exact lookup never runs
104
+ // to pages of entries without an end, so ten such pages are an answer that can't be read, not a
105
+ // reason to guess.
106
+ const read_lookup = async (s, lookup, value, found_before) => {
107
+ let found = found_before;
72
108
  for (let page = 0; page < LOOKUP_PAGES; page++) {
73
- const a = await (0, call_1.call_reply)(s, 'POST', `/v3/contacts/filter?top=${LOOKUP_PAGE}&skip=${page * LOOKUP_PAGE}`, 'read', { searchTerm: email });
109
+ const a = await (0, call_1.call_reply)(s, 'GET', `/v3/contacts?${lookup.param}=${encodeURIComponent(value)}&top=${LOOKUP_PAGE}&skip=${page * LOOKUP_PAGE}`, 'read');
74
110
  if (a.status !== 200) {
75
111
  throw (0, call_1.refusal)(a, 'read');
76
112
  }
77
113
  const body = (0, call_1.read_page)(a);
78
114
  for (const entry of body.items) {
79
- if (!(0, call_1.is_object)(entry) || typeof entry.email !== 'string' || entry.email.toLowerCase() !== wanted) {
115
+ if (!(0, call_1.is_object)(entry) || !lookup.holds(entry)) {
80
116
  continue;
81
117
  }
82
118
  if (!(0, call_1.is_reply_id)(entry.id)) {
83
119
  throw (0, call_1.unreadable)(a, 'read');
84
120
  }
85
121
  if (found !== null && found !== entry.id) {
86
- throw new errors_1.Operation_error('contact.not_unique', 'Reply holds more than one contact with this email address.', { status: 200 });
122
+ throw new errors_1.Operation_error('contact.not_unique', 'Reply holds more than one contact under this address.', { status: 200 });
87
123
  }
88
124
  found = entry.id;
89
125
  }
@@ -91,16 +127,45 @@ const find_contact_by_exact_email = async (s, email) => {
91
127
  return found;
92
128
  }
93
129
  }
94
- throw new errors_1.Operation_error('contact.lookup_incomplete', `More than ${LOOKUP_PAGE * LOOKUP_PAGES} contacts contain this address, so it could not be decided which one is meant.`, { status: 200 });
130
+ throw new errors_1.Operation_error('reply.unavailable', 'Reply answered the exact lookup with more pages than one address can fill.', { status: 200 });
95
131
  };
96
- const find_contact = async (s, ref) => ref.kind === 'id' ? ref.id : find_contact_by_exact_email(s, ref.person.email);
132
+ const find_contact_by_address = async (s, person) => {
133
+ const lookup = lookup_of(person);
134
+ let found = null;
135
+ for (const value of lookup.values) {
136
+ found = await read_lookup(s, lookup, value, found);
137
+ }
138
+ return found;
139
+ };
140
+ exports.find_contact_by_address = find_contact_by_address;
141
+ // INTERIM (API gap): the document does not say how the import compares a LinkedIn URL when it is the
142
+ // key, so a contact Reply holds under the same slug in another case might be imported a second time.
143
+ // Needed: an import that matches a LinkedIn URL by its slug whatever its case, or a word on how it
144
+ // compares.
145
+ // Workaround: a contact with no email is looked up first, as `contact find` does, and imported only
146
+ // when Reply holds nobody under the URL. A contact with an email is imported straight away: the
147
+ // import matches it by the email.
148
+ const ensure_contact = async (s, ref) => {
149
+ if (ref.kind === 'id') {
150
+ return { id: ref.id, created: false };
151
+ }
152
+ if (ref.person.email === undefined) {
153
+ const found = await find_contact_by_address(s, ref.person);
154
+ if (found !== null) {
155
+ return { id: found, created: false };
156
+ }
157
+ }
158
+ return import_contact(s, ref.person);
159
+ };
160
+ exports.ensure_contact = ensure_contact;
161
+ const find_contact = async (s, ref) => ref.kind === 'id' ? ref.id : find_contact_by_address(s, ref.person);
97
162
  exports.find_contact = find_contact;
163
+ const contact_not_found = (contact_id, a) => new errors_1.Operation_error('contact.not_found', `This account has no contact ${contact_id}.`, { status: a.status, reply_code: (0, call_1.reply_code_of)(a) });
164
+ exports.contact_not_found = contact_not_found;
98
165
  const read_opted_out = async (s, contact_id) => {
99
166
  const a = await (0, call_1.call_reply)(s, 'GET', `/v3/contacts/${contact_id}/statuses`, 'read');
100
167
  if (a.status === 404) {
101
- throw new errors_1.Operation_error('contact.not_found', `This account has no contact ${contact_id}.`, {
102
- status: 404, reply_code: (0, call_1.reply_code_of)(a),
103
- });
168
+ throw contact_not_found(contact_id, a);
104
169
  }
105
170
  if (a.status !== 200) {
106
171
  throw (0, call_1.refusal)(a, 'read');
@@ -1 +1 @@
1
- {"version":3,"file":"contacts.js","sourceRoot":"","sources":["../../src/operations/contacts.ts"],"names":[],"mappings":";;;AAAA,4CAAgD;AAChD,iCAGgB;AAKhB,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,MAAM,WAAW,GAAG,CAAC,CAAS,EAAyB,EAAE;IACrD,MAAM,IAAI,GAA2B,EAAC,KAAK,EAAE,CAAC,CAA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,CAAC,GAAG,MAAM,IAAA,iBAAU,EAAC,CAAC,EAAE,KAAK,EAAE,gBAAgB,UAAU,WAAW,EAAE,MAAM,CAAC,CAAC;IACpF,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,EACpB,CAAC;QACG,MAAM,iBAAiB,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC3C,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,EACpB,CAAC;QACG,MAAM,IAAA,cAAO,EAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IACD,MAAM,IAAI,GAAG,IAAA,oBAAa,EAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACtC,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,SAAS,EACxC,CAAC;QACG,MAAM,IAAA,iBAAU,EAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,IAAI,CAAC,UAAU,CAAC;AAC3B,CAAC,CAAC;AAE6E,wCAAc"}
@@ -0,0 +1,12 @@
1
+ import { type Op_globals } from './options';
2
+ import type { Cli_context } from '../context';
3
+ type Direct_send_name = 'send-email' | 'linkedin-connect' | 'linkedin-message' | 'linkedin-inmail' | 'linkedin-voice';
4
+ type Direct_send_opts = {
5
+ contactId?: string;
6
+ emailAccountId?: string;
7
+ linkedinAccountId?: string;
8
+ message?: string;
9
+ };
10
+ declare const handle_direct_send: (name: Direct_send_name, opts: Direct_send_opts, ctx: Cli_context, g: Op_globals, read_stdin?: () => string) => Promise<void>;
11
+ export { handle_direct_send };
12
+ export type { Direct_send_name, Direct_send_opts };
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handle_direct_send = void 0;
4
+ const config_1 = require("../config");
5
+ const errors_1 = require("../utils/errors");
6
+ const client_1 = require("../utils/client");
7
+ const call_1 = require("./call");
8
+ const options_1 = require("./options");
9
+ const contacts_1 = require("./contacts");
10
+ const stdin_input_1 = require("./stdin-input");
11
+ const result_1 = require("./result");
12
+ // One entry per send: Reply has one endpoint for each, and each takes its text under its own names.
13
+ // The lengths are the maxLength Reply's document gives each field; where it gives none, none is set.
14
+ const DIRECT_SENDS = {
15
+ 'send-email': {
16
+ path: 'send-direct-email', what: 'email', fields: ['subject', 'body'], longest: {},
17
+ body: (id, t) => ({ emailAccountId: id, subject: t?.subject, body: t?.body }),
18
+ },
19
+ 'linkedin-connect': {
20
+ path: 'send-direct-linkedin-connect', what: 'invitation', fields: ['note'], longest: {}, text_optional: true,
21
+ body: (id, t) => (t === undefined ? { linkedInAccountId: id } : { linkedInAccountId: id, message: t.note }),
22
+ },
23
+ 'linkedin-message': {
24
+ path: 'send-direct-linkedin-message', what: 'message', fields: ['body'], longest: { body: 8000 },
25
+ body: (id, t) => ({ linkedInAccountId: id, message: t?.body }),
26
+ },
27
+ 'linkedin-inmail': {
28
+ path: 'send-direct-linkedin-inmail', what: 'InMail', fields: ['subject', 'body'], longest: { subject: 200, body: 1900 },
29
+ body: (id, t) => ({ linkedInAccountId: id, subject: t?.subject, body: t?.body }),
30
+ },
31
+ 'linkedin-voice': {
32
+ path: 'send-direct-linkedin-ai-voice', what: 'voice message', fields: ['script'], longest: { script: 1000 },
33
+ body: (id, t) => ({ linkedInAccountId: id, script: t?.script }),
34
+ },
35
+ };
36
+ const CODE = 'usage.message';
37
+ const required_id = (raw, flag, largest) => {
38
+ if (raw === undefined) {
39
+ throw new errors_1.UsageError(`No ${flag} was given.`, { code: 'usage.id' });
40
+ }
41
+ return (0, options_1.parse_id)(raw, flag, largest);
42
+ };
43
+ // The text is read from stdin only, never from the argument list, which may be logged where a
44
+ // person's words must not go. No message here repeats any of it. A length is counted in characters,
45
+ // as the document's maxLength counts them, so one outside the basic plane counts once.
46
+ const read_text = (name, send, source, read_stdin) => {
47
+ if (send.text_optional === true && source === undefined) {
48
+ return undefined;
49
+ }
50
+ const shape = `{${send.fields.map(f => `"${f}":"…"`).join(',')}}`;
51
+ const raw = (0, stdin_input_1.read_stdin_object)(source, {
52
+ flag: '--message', what: 'message', fields: send.fields, code: CODE,
53
+ hint: `Pipe it in: echo '${shape}' | ${config_1.PROGRAM_NAME} contact ${name} … --message -`,
54
+ }, read_stdin);
55
+ const text = {};
56
+ for (const field of send.fields) {
57
+ const value = raw[field];
58
+ if (typeof value !== 'string' || value.trim() === '') {
59
+ throw new errors_1.UsageError(`The message needs a ${field}: a string that is not blank.`, { code: CODE });
60
+ }
61
+ const longest = send.longest[field];
62
+ if (longest !== undefined && [...value].length > longest) {
63
+ throw new errors_1.UsageError(`The ${field} is longer than Reply takes: at most ${longest} characters.`, { code: CODE });
64
+ }
65
+ text[field] = value;
66
+ }
67
+ return text;
68
+ };
69
+ // Reply's refusals of a direct send, by status and code. Each one is definite: nothing was sent.
70
+ const REFUSALS = {
71
+ 'contact.emailAccountNotFound': {
72
+ status: 400, code: 'email_account.not_found', title: 'Reply has no mailbox by that id that this account can send from, so nothing was sent.',
73
+ },
74
+ 'contact.contactInBlackList': {
75
+ status: 400, code: 'contact.blacklisted', title: 'The contact is on the account\'s blacklist, so nothing was sent.',
76
+ },
77
+ 'directLinkedIn.featureDisabled': {
78
+ status: 403, code: 'linkedin.feature_disabled', title: 'Direct LinkedIn sends are not enabled for this account, so nothing was sent.',
79
+ },
80
+ 'directLinkedIn.noLinkedInProfile': {
81
+ status: 404, code: 'contact.no_linkedin_profile', title: 'Reply holds no LinkedIn profile URL for the contact, so nothing was sent.',
82
+ },
83
+ 'directLinkedIn.linkedInAccountNotFound': {
84
+ status: 404, code: 'linkedin.account_not_found', title: 'Reply has no LinkedIn account by that id that this account can send from, so nothing was sent.',
85
+ },
86
+ 'directLinkedIn.linkedInAccountInactive': {
87
+ status: 409, code: 'linkedin.account_inactive', title: 'The LinkedIn account is inactive, so nothing was sent.',
88
+ },
89
+ 'directLinkedIn.invalidCookie': {
90
+ status: 409, code: 'linkedin.invalid_cookie', title: 'The LinkedIn account\'s session is no longer valid, so nothing was sent; reconnect the account.',
91
+ },
92
+ 'directLinkedIn.notConnected': {
93
+ status: 409, code: 'linkedin.not_connected', title: 'The LinkedIn account is not connected with the contact, so nothing was sent.',
94
+ },
95
+ 'directLinkedIn.messageTooLong': {
96
+ status: 400, code: 'linkedin.message_too_long', title: 'Reply found the text too long, so nothing was sent.',
97
+ },
98
+ 'directLinkedIn.invitesNotesLimit': {
99
+ status: 400, code: 'linkedin.message_too_long', title: 'Reply found the note too long, so nothing was sent.',
100
+ },
101
+ 'directLinkedIn.missingVariables': {
102
+ status: 400, code: 'linkedin.missing_variables', title: 'The text holds a template variable Reply could not fill, so nothing was sent.',
103
+ },
104
+ 'directLinkedIn.salesNavRequired': {
105
+ status: 400, code: 'linkedin.sales_navigator_required', title: 'An InMail needs Sales Navigator on the LinkedIn account, so nothing was sent.',
106
+ },
107
+ 'directLinkedIn.salesNavDisconnected': {
108
+ status: 400, code: 'linkedin.sales_navigator_disconnected', title: 'The LinkedIn account\'s Sales Navigator is disconnected, so nothing was sent.',
109
+ },
110
+ 'directLinkedIn.noInMailCredits': {
111
+ status: 400, code: 'linkedin.no_inmail_credits', title: 'The LinkedIn account has no InMail credits left, so nothing was sent.',
112
+ },
113
+ 'directLinkedIn.voiceProfileMissing': {
114
+ status: 400, code: 'linkedin.voice_profile_missing', title: 'The LinkedIn account has no voice profile, so nothing was sent.',
115
+ },
116
+ 'directLinkedIn.voiceTooLong': {
117
+ status: 400, code: 'linkedin.voice_too_long', title: 'The voice message would be longer than Reply allows, so nothing was sent.',
118
+ },
119
+ };
120
+ const LIMITS = { 'directLinkedIn.dailyLimitReached': 'daily', 'directLinkedIn.weeklyLimitReached': 'weekly' };
121
+ const send_refusal = (a, contact_id) => {
122
+ const reply_code = (0, call_1.reply_code_of)(a);
123
+ if (a.status === 404 && (reply_code === 'contact.notFound' || reply_code === 'directLinkedIn.contactNotFound')) {
124
+ return (0, contacts_1.contact_not_found)(contact_id, a);
125
+ }
126
+ if (a.status === 429 && reply_code !== undefined && LIMITS[reply_code] !== undefined) {
127
+ return new errors_1.Operation_error('linkedin.limit_reached', `The LinkedIn account reached its ${LIMITS[reply_code]} limit, so nothing was sent.`, {
128
+ status: a.status, reply_code, detail: (0, call_1.detail_of)(a),
129
+ retry_after: (0, client_1.parse_retry_after)(a.headers['retry-after']) ?? undefined, details: { limit: LIMITS[reply_code] },
130
+ });
131
+ }
132
+ const known = reply_code === undefined ? undefined : REFUSALS[reply_code];
133
+ if (known !== undefined && known.status === a.status) {
134
+ return new errors_1.Operation_error(known.code, known.title, { status: a.status, reply_code, detail: (0, call_1.detail_of)(a) });
135
+ }
136
+ return (0, call_1.refusal)(a, 'write');
137
+ };
138
+ const positive_integer = (v) => typeof v === 'number' && Number.isSafeInteger(v) && v > 0 ? v : null;
139
+ // What the CLI answers for a send Reply took. Neither adds a time of its own: Reply's answer to a
140
+ // direct email carries none, and a LinkedIn send's sentAtUtc is given as Reply gives it.
141
+ const result_of = (name, contact_id, sent) => name === 'send-email'
142
+ ? {
143
+ status: 'sent', contact_id,
144
+ message_id: typeof sent.messageId === 'string' ? sent.messageId : null,
145
+ sent_at: null,
146
+ reply_status: typeof sent.status === 'string' ? sent.status : null,
147
+ }
148
+ : {
149
+ status: 'sent', contact_id,
150
+ activity_id: positive_integer(sent.linkedInActivityId),
151
+ sent_at: typeof sent.sentAtUtc === 'string' ? sent.sentAtUtc : null,
152
+ };
153
+ const handle_direct_send = async (name, opts, ctx, g, read_stdin) => {
154
+ const send = DIRECT_SENDS[name];
155
+ const contact_id = required_id(opts.contactId, '--contact-id');
156
+ // A send always names the account it goes from: Reply would send an email from the default mailbox.
157
+ const by_email = name === 'send-email';
158
+ const account_id = by_email
159
+ ? required_id(opts.emailAccountId, '--email-account-id', options_1.LARGEST_SAFE_ID)
160
+ : required_id(opts.linkedinAccountId, '--linkedin-account-id');
161
+ const ids = by_email ? { contact_id, email_account_id: account_id } : { contact_id, linkedin_account_id: account_id };
162
+ const text = read_text(name, send, opts.message, read_stdin);
163
+ const s = await (0, call_1.open_session)(ctx, g);
164
+ try {
165
+ const a = await (0, call_1.call_reply)(s, 'POST', `/v3/contacts/${contact_id}/${send.path}`, 'write', send.body(account_id, text));
166
+ if (name === 'linkedin-connect' && a.status === 409 && (0, call_1.reply_code_of)(a) === 'directLinkedIn.alreadyConnected') {
167
+ // Nothing was sent, and nothing needs to be: the contact is already a connection.
168
+ (0, result_1.print_result)({ status: 'already_connected', contact_id, activity_id: null, sent_at: null }, g);
169
+ return;
170
+ }
171
+ if (a.status !== 200) {
172
+ throw send_refusal(a, contact_id);
173
+ }
174
+ (0, result_1.print_result)(result_of(name, contact_id, (0, call_1.expect_object)(a, 'write')), g);
175
+ }
176
+ catch (e) {
177
+ // Unlike most work commands, a send is not safe to repeat: the same text would go twice.
178
+ if (e instanceof errors_1.Unknown_outcome_error) {
179
+ e.hint = `The ${send.what} may have been sent; running the command again may send it twice.`;
180
+ }
181
+ throw (0, result_1.with_ids)(e, ids);
182
+ }
183
+ };
184
+ exports.handle_direct_send = handle_direct_send;
185
+ //# sourceMappingURL=direct-send.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"direct-send.js","sourceRoot":"","sources":["../../src/operations/direct-send.ts"],"names":[],"mappings":";;;AAAA,sCAAuC;AACvC,4CAA6F;AAC7F,4CAAkD;AAClD,iCAA+G;AAC/G,uCAAqE;AACrE,yCAA6C;AAC7C,+CAAgD;AAChD,qCAAgD;AAgBhD,oGAAoG;AACpG,qGAAqG;AACrG,MAAM,YAAY,GAA0C;IACxD,YAAY,EAAE;QACV,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,EAAE,EAAE;QAClF,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,EAAC,EAAE,CAAA,CAAC,EAAC,cAAc,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,EAA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AU,CAAC,CAAC;QACtC,CAAC;QACD,IAAA,qBAAY,EAAC,SAAS,CAAC,IAAI,EAAE,UAAU,EAAE,IAAA,oBAAa,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,yFAAyF;QACzF,IAAI,CAAC,YAAY,8BAAqB,EACtC,CAAC;YACG,CAAC,CAAC,IAAI,GAAG,OAAO,IAAI,CAAC,IAAI,mEAAmE,CAAC;QACjG,CAAC;QACD,MAAM,IAAA,iBAAQ,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC;AACL,CAAC,CAAC;AAEM,gDAAkB"}
@@ -0,0 +1,11 @@
1
+ import { type Op_globals } from './options';
2
+ import type { Cli_context } from '../context';
3
+ type Reply_message = {
4
+ body: string;
5
+ reply_to_message_id?: string;
6
+ };
7
+ declare const handle_inbox_reply: (thread_arg: string, opts: {
8
+ message?: string;
9
+ }, ctx: Cli_context, g: Op_globals, read_stdin?: () => string) => Promise<void>;
10
+ export { handle_inbox_reply };
11
+ export type { Reply_message };
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handle_inbox_reply = void 0;
4
+ const config_1 = require("../config");
5
+ const errors_1 = require("../utils/errors");
6
+ const json_arg_1 = require("../utils/json-arg");
7
+ const call_1 = require("./call");
8
+ const options_1 = require("./options");
9
+ const inbox_1 = require("./inbox");
10
+ const result_1 = require("./result");
11
+ const CODE = 'usage.message';
12
+ const MESSAGE_FIELDS = ['body', 'reply_to_message_id'];
13
+ const STDIN_HINT = `Pipe it in: echo '{"body":"…"}' | ${config_1.PROGRAM_NAME} inbox reply <thread-id> --message -`;
14
+ // The reply's text is read from stdin only, never from the argument list, which may be logged
15
+ // where a person's words must not go. No message here repeats any of it.
16
+ const read_reply_message = (source, read_stdin) => {
17
+ if (source !== '-') {
18
+ throw new errors_1.UsageError(source === undefined ? 'No message was given.' : '--message takes only -: the message is read from stdin.', {
19
+ code: CODE, hint: STDIN_HINT,
20
+ });
21
+ }
22
+ let value;
23
+ try {
24
+ value = JSON.parse((read_stdin ?? json_arg_1.read_all_stdin)());
25
+ }
26
+ catch {
27
+ throw new errors_1.UsageError('The message on stdin must be JSON: {body, reply_to_message_id}.', { code: CODE });
28
+ }
29
+ if (!(0, call_1.is_object)(value)) {
30
+ throw new errors_1.UsageError('The message must be a JSON object: {body, reply_to_message_id}.', { code: CODE });
31
+ }
32
+ const unknown_field = Object.keys(value).find(k => !MESSAGE_FIELDS.includes(k));
33
+ if (unknown_field !== undefined) {
34
+ throw new errors_1.UsageError(`The message has an unknown field '${unknown_field}'.`, { code: CODE, hint: `Fields: ${MESSAGE_FIELDS.join(', ')}.` });
35
+ }
36
+ if (typeof value.body !== 'string' || value.body.trim() === '') {
37
+ throw new errors_1.UsageError('The message needs a body: a string that is not blank.', { code: CODE });
38
+ }
39
+ const reply_to = value.reply_to_message_id;
40
+ if (reply_to !== undefined && reply_to !== null && (typeof reply_to !== 'string' || reply_to === '')) {
41
+ throw new errors_1.UsageError('reply_to_message_id must be a message id: a string that is not empty.', { code: CODE });
42
+ }
43
+ return typeof reply_to === 'string' ? { body: value.body, reply_to_message_id: reply_to } : { body: value.body };
44
+ };
45
+ const channel_mismatch = (title, status, thread_channel, reply_code) => new errors_1.Operation_error('inbox.channel_mismatch', title, { status, reply_code, details: { thread_channel } });
46
+ const cli_channel = (reply_channel) => Object.keys(inbox_1.CHANNELS).find(c => inbox_1.CHANNELS[c] === reply_channel);
47
+ // The thread's outbound messages that carry a date, oldest first. The document says the inline
48
+ // history is "in order" without saying which way, so the dates decide, never the positions.
49
+ const outbound_of = (thread) => (Array.isArray(thread.messages) ? thread.messages : [])
50
+ .filter(call_1.is_object)
51
+ .filter(m => m.isOutbound === true && typeof m.date === 'string' && !isNaN(Date.parse(m.date)))
52
+ .map(m => ({ at: Date.parse(m.date), status: m.status }))
53
+ .sort((x, y) => x.at - y.at);
54
+ // Reply's send takes the thread's channel, and only an email reply may name the message it answers.
55
+ // The newest outbound message the thread already holds is kept, so a failure after the send can be
56
+ // told from one that was there before it.
57
+ const read_thread = async (s, id, message) => {
58
+ const t = await (0, call_1.call_reply)(s, 'GET', `/v3/inbox/threads/${id}`, 'read');
59
+ if (t.status === 404) {
60
+ throw (0, inbox_1.thread_not_found)(id, t);
61
+ }
62
+ if (t.status !== 200) {
63
+ throw (0, call_1.refusal)(t, 'read');
64
+ }
65
+ const thread = (0, call_1.expect_object)(t, 'read');
66
+ const raw = thread.channel;
67
+ const channel = cli_channel(raw);
68
+ if (channel === undefined) {
69
+ throw channel_mismatch('Reply takes a reply only in an email or LinkedIn thread, and this thread is neither.', 200, typeof raw === 'string' ? raw : null);
70
+ }
71
+ if (channel === 'linkedin' && message.reply_to_message_id !== undefined) {
72
+ throw channel_mismatch('reply_to_message_id answers one email message; a LinkedIn thread takes a reply to the thread only.', 200, channel);
73
+ }
74
+ return { channel, last_outbound_at: outbound_of(thread).pop()?.at ?? null };
75
+ };
76
+ // INTERIM (API gap): the 502 Reply answers when it could not deliver a reply says only that, not why.
77
+ // Needed: the failed message's status code in the 502 itself.
78
+ // Workaround: read the thread once and take the code from the newest failed outbound message that is
79
+ // newer than anything outbound the thread held before the send, so an earlier failure is never
80
+ // given as this one's reason; when Reply recorded none, the code is null. The code decides what the
81
+ // caller does next (wait out a limit, or reconnect the account), so without it every failed delivery
82
+ // would be the same answer. The read is best-effort: when it fails, the refusal stands without the code.
83
+ const failed_message_code = async (s, id, last_outbound_at) => {
84
+ let t;
85
+ try {
86
+ t = await (0, call_1.call_reply)(s, 'GET', `/v3/inbox/threads/${id}`, 'read');
87
+ }
88
+ catch (e) {
89
+ if (e instanceof errors_1.Operation_error) {
90
+ return null;
91
+ }
92
+ throw e;
93
+ }
94
+ if (t.status !== 200 || !(0, call_1.is_object)(t.data)) {
95
+ return null;
96
+ }
97
+ const failed = outbound_of(t.data)
98
+ .filter(m => last_outbound_at === null || m.at > last_outbound_at)
99
+ .map(m => m.status)
100
+ .filter(call_1.is_object)
101
+ .filter(status => status.state === 'needsAttention' && typeof status.code === 'string')
102
+ .pop();
103
+ return failed === undefined ? null : failed.code;
104
+ };
105
+ // What a send answered when it did not send.
106
+ const send_refusal = async (s, id, a, last_outbound_at) => {
107
+ const code = (0, call_1.reply_code_of)(a);
108
+ if (a.status === 502 && code === 'inboxThread.threadSendFailed') {
109
+ // Reply tried and could not deliver: a definite refusal, never an unknown outcome.
110
+ return new errors_1.Operation_error('inbox.send_failed', 'Reply could not deliver the reply, so it was not sent.', {
111
+ status: a.status, reply_code: code, detail: (0, call_1.detail_of)(a),
112
+ details: { status_code: await failed_message_code(s, id, last_outbound_at) },
113
+ });
114
+ }
115
+ if (a.status === 404) {
116
+ return (0, inbox_1.thread_not_found)(id, a);
117
+ }
118
+ if (a.status === 400 && code === 'inboxThread.channelMismatch') {
119
+ return channel_mismatch('Reply says the reply\'s channel is not the thread\'s.', a.status, null, code);
120
+ }
121
+ if (a.status === 400 && code === 'inboxThread.contactOptedOut') {
122
+ return new errors_1.Operation_error('contact.opted_out', 'The thread\'s contact is opted out, so the reply was not sent.', {
123
+ status: a.status, reply_code: code, detail: (0, call_1.detail_of)(a),
124
+ });
125
+ }
126
+ return (0, call_1.refusal)(a, 'write');
127
+ };
128
+ const handle_inbox_reply = async (thread_arg, opts, ctx, g, read_stdin) => {
129
+ const id = (0, options_1.parse_id)(thread_arg, 'Thread id');
130
+ const message = read_reply_message(opts.message, read_stdin);
131
+ const s = await (0, call_1.open_session)(ctx, g);
132
+ try {
133
+ const { channel, last_outbound_at } = await read_thread(s, id, message);
134
+ // The reply goes to the thread's contact from the account that owns the thread: no other
135
+ // recipient can be named.
136
+ const body = channel === 'email'
137
+ ? { channel: 'email', message: message.body,
138
+ ...(message.reply_to_message_id === undefined ? {} : { replyToMessageId: message.reply_to_message_id }) }
139
+ : { channel: inbox_1.CHANNELS.linkedin, message: message.body };
140
+ const a = await (0, call_1.call_reply)(s, 'POST', `/v3/inbox/threads/${id}/messages`, 'write', body);
141
+ if (a.status !== 200) {
142
+ throw await send_refusal(s, id, a, last_outbound_at);
143
+ }
144
+ const sent = (0, call_1.expect_object)(a, 'write');
145
+ (0, result_1.print_result)({
146
+ status: 'sent', thread_id: id, channel,
147
+ message_id: typeof sent.messageId === 'string' ? sent.messageId : null,
148
+ sent_at: typeof sent.date === 'string' ? sent.date : null,
149
+ }, g);
150
+ }
151
+ catch (e) {
152
+ // Unlike every other work command, a send is not safe to repeat: the same reply would go twice.
153
+ if (e instanceof errors_1.Unknown_outcome_error) {
154
+ e.hint = `The reply may have been sent; running the command again may send it twice. Read the thread with \`${config_1.PROGRAM_NAME} inbox get ${id}\` first.`;
155
+ }
156
+ throw (0, result_1.with_ids)(e, { thread_id: id });
157
+ }
158
+ };
159
+ exports.handle_inbox_reply = handle_inbox_reply;
160
+ //# sourceMappingURL=inbox-reply.js.map