reply-cli 0.11.0 → 0.13.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 +53 -7
- package/dist/operations/commands.js +143 -17
- package/dist/operations/commands.js.map +1 -1
- package/dist/operations/contact-input.d.ts +7 -3
- package/dist/operations/contact-input.js +51 -12
- package/dist/operations/contact-input.js.map +1 -1
- package/dist/operations/contact-record.d.ts +11 -0
- package/dist/operations/contact-record.js +176 -0
- package/dist/operations/contact-record.js.map +1 -0
- package/dist/operations/contact.js +8 -4
- package/dist/operations/contact.js.map +1 -1
- package/dist/operations/contacts.d.ts +7 -3
- package/dist/operations/contacts.js +94 -29
- package/dist/operations/contacts.js.map +1 -1
- package/dist/operations/inbox-reply.d.ts +11 -0
- package/dist/operations/inbox-reply.js +160 -0
- package/dist/operations/inbox-reply.js.map +1 -0
- package/dist/operations/inbox.d.ts +19 -1
- package/dist/operations/inbox.js +105 -1
- package/dist/operations/inbox.js.map +1 -1
- package/dist/operations/sequence-by-name.d.ts +9 -0
- package/dist/operations/sequence-by-name.js +96 -0
- package/dist/operations/sequence-by-name.js.map +1 -0
- package/dist/operations/stdin-input.d.ts +10 -0
- package/dist/operations/stdin-input.js +34 -0
- package/dist/operations/stdin-input.js.map +1 -0
- package/package.json +1 -1
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox-reply.js","sourceRoot":"","sources":["../../src/operations/inbox-reply.ts"],"names":[],"mappings":";;;AAAA,sCAAuC;AACvC,4CAAmF;AACnF,gDAAiD;AACjD,iCAA2I;AAC3I,uCAAoD;AACpD,mCAAiE;AACjE,qCAAgD;AAKhD,MAAM,IAAI,GAAG,eAAe,CAAC;AAC7B,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;AACvD,MAAM,UAAU,GAAG,qCAAqC,qBAAY,sCAAsC,CAAC;AAE3G,8FAA8F;AAC9F,yEAAyE;AACzE,MAAM,kBAAkB,GAAG,CAAC,MAA0B,EAAE,UAAyB,EAAgB,EAAE;IAC/F,IAAI,MAAM,KAAK,GAAG,EAClB,CAAC;QACG,MAAM,IAAI,mBAAU,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,uBAAuB,CAAC,C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ACpB,CAAC;YACG,MAAM,MAAM,YAAY,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,IAAI,GAAG,IAAA,oBAAa,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACvC,IAAA,qBAAY,EAAC;YACT,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,EAAE,OAAO;YACtC,UAAU,EAAE,OAAO,IAAI,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI;YACtE,OAAO,EAAE,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI;SAC5D,EAAE,CAAC,CAAC,CAAC;IACV,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,gGAAgG;QAChG,IAAI,CAAC,YAAY,8BAAqB,EACtC,CAAC;YACG,CAAC,CAAC,IAAI,GAAG,qGAAqG,qBAAY,cAAc,EAAE,WAAW,CAAC;QAC1J,CAAC;QACD,MAAM,IAAA,iBAAQ,EAAC,CAAC,EAAE,EAAC,SAAS,EAAE,EAAE,EAAC,CAAC,CAAC;IACvC,CAAC;AACL,CAAC,CAAC;AAEM,gDAAkB"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Operation_error } from '../utils/errors';
|
|
2
|
+
import { type Answer } from './call';
|
|
1
3
|
import { type Op_globals } from './options';
|
|
2
4
|
import type { Cli_context } from '../context';
|
|
3
5
|
declare const SOURCES: {
|
|
@@ -6,10 +8,18 @@ declare const SOURCES: {
|
|
|
6
8
|
readonly unread: "unread";
|
|
7
9
|
readonly 'ai-draft': "aiDraft";
|
|
8
10
|
};
|
|
11
|
+
declare const CHANNELS: {
|
|
12
|
+
readonly email: "email";
|
|
13
|
+
readonly linkedin: "linkedIn";
|
|
14
|
+
};
|
|
15
|
+
type Channel = keyof typeof CHANNELS;
|
|
16
|
+
declare const thread_not_found: (id: number, a: Answer) => Operation_error;
|
|
9
17
|
type Inbox_list_opts = {
|
|
10
18
|
contactId?: string;
|
|
11
19
|
sequenceId?: string;
|
|
12
20
|
source?: string;
|
|
21
|
+
channel?: string;
|
|
22
|
+
categoryId?: string;
|
|
13
23
|
since?: string;
|
|
14
24
|
limit?: string;
|
|
15
25
|
offset?: string;
|
|
@@ -19,4 +29,12 @@ declare const handle_inbox_get: (thread_arg: string, opts: {
|
|
|
19
29
|
limit?: string;
|
|
20
30
|
offset?: string;
|
|
21
31
|
}, ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
22
|
-
|
|
32
|
+
declare const handle_inbox_categories: (ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
33
|
+
declare const handle_inbox_categorize: (thread_arg: string, opts: {
|
|
34
|
+
categoryId?: string;
|
|
35
|
+
clear?: boolean;
|
|
36
|
+
}, ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
37
|
+
declare const handle_inbox_mark_read: (thread_arg: string, ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
38
|
+
declare const handle_inbox_mark_unread: (thread_arg: string, ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
39
|
+
export { handle_inbox_list, handle_inbox_get, handle_inbox_categories, handle_inbox_categorize, handle_inbox_mark_read, handle_inbox_mark_unread, thread_not_found, SOURCES, CHANNELS, };
|
|
40
|
+
export type { Channel };
|
package/dist/operations/inbox.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SOURCES = exports.handle_inbox_get = exports.handle_inbox_list = void 0;
|
|
3
|
+
exports.CHANNELS = exports.SOURCES = exports.thread_not_found = exports.handle_inbox_mark_unread = exports.handle_inbox_mark_read = exports.handle_inbox_categorize = exports.handle_inbox_categories = exports.handle_inbox_get = exports.handle_inbox_list = void 0;
|
|
4
4
|
const errors_1 = require("../utils/errors");
|
|
5
5
|
const call_1 = require("./call");
|
|
6
6
|
const options_1 = require("./options");
|
|
@@ -8,9 +8,13 @@ const result_1 = require("./result");
|
|
|
8
8
|
// Reply's own `source` filter. It has no "all": without --source Reply answers its default, inbox.
|
|
9
9
|
const SOURCES = { 'inbox': 'inbox', 'sent': 'sent', 'unread': 'unread', 'ai-draft': 'aiDraft' };
|
|
10
10
|
exports.SOURCES = SOURCES;
|
|
11
|
+
// The CLI's channel words and Reply's.
|
|
12
|
+
const CHANNELS = { 'email': 'email', 'linkedin': 'linkedIn' };
|
|
13
|
+
exports.CHANNELS = CHANNELS;
|
|
11
14
|
const thread_not_found = (id, a) => new errors_1.Operation_error('inbox.thread_not_found', `This account has no inbox thread ${id} it can see.`, {
|
|
12
15
|
status: a.status, reply_code: (0, call_1.reply_code_of)(a),
|
|
13
16
|
});
|
|
17
|
+
exports.thread_not_found = thread_not_found;
|
|
14
18
|
const handle_inbox_list = async (opts, ctx, g) => {
|
|
15
19
|
if ((opts.contactId === undefined) === (opts.sequenceId === undefined)) {
|
|
16
20
|
throw new errors_1.UsageError('Give exactly one of --contact-id and --sequence-id.', { code: 'usage.inbox' });
|
|
@@ -22,6 +26,13 @@ const handle_inbox_list = async (opts, ctx, g) => {
|
|
|
22
26
|
if (source !== undefined) {
|
|
23
27
|
filter.source = SOURCES[source];
|
|
24
28
|
}
|
|
29
|
+
const channel = (0, options_1.parse_choice)(opts.channel, '--channel', Object.keys(CHANNELS));
|
|
30
|
+
if (channel !== undefined) {
|
|
31
|
+
filter.channels = [CHANNELS[channel]];
|
|
32
|
+
}
|
|
33
|
+
if (opts.categoryId !== undefined) {
|
|
34
|
+
filter.categoryIds = [(0, options_1.parse_id)(opts.categoryId, '--category-id')];
|
|
35
|
+
}
|
|
25
36
|
if (opts.since !== undefined) {
|
|
26
37
|
// Reply's `from` keeps only threads that moved strictly after it; --since keeps the ones
|
|
27
38
|
// that moved at or after it, so Reply is asked from one millisecond earlier.
|
|
@@ -73,4 +84,97 @@ const handle_inbox_get = async (thread_arg, opts, ctx, g) => {
|
|
|
73
84
|
(0, result_1.print_result)({ thread: thread_header(thread), messages: (0, call_1.read_page)(m) }, g);
|
|
74
85
|
};
|
|
75
86
|
exports.handle_inbox_get = handle_inbox_get;
|
|
87
|
+
const handle_inbox_categories = async (ctx, g) => {
|
|
88
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
89
|
+
const a = await (0, call_1.call_reply)(s, 'GET', '/v3/inbox/threads/categories', 'read');
|
|
90
|
+
if (a.status !== 200) {
|
|
91
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
92
|
+
}
|
|
93
|
+
if (!Array.isArray(a.data)) {
|
|
94
|
+
throw (0, call_1.unreadable)(a, 'read');
|
|
95
|
+
}
|
|
96
|
+
(0, result_1.print_result)({ items: a.data }, g);
|
|
97
|
+
};
|
|
98
|
+
exports.handle_inbox_categories = handle_inbox_categories;
|
|
99
|
+
const category_not_found = (category_id, a) => new errors_1.Operation_error('inbox.category_not_found', `This account has no inbox category ${category_id}.`, {
|
|
100
|
+
status: a.status, reply_code: (0, call_1.reply_code_of)(a),
|
|
101
|
+
});
|
|
102
|
+
// INTERIM (API gap): PUT /v3/inbox/threads/{id}/category answers a category the account does not
|
|
103
|
+
// have with the same 404 and inboxThread.notFound as a thread it does not have, so on its own the
|
|
104
|
+
// answer would report an existing thread as missing.
|
|
105
|
+
// Needed: a code of its own for a missing category; the document gives inboxCategory.notFound only to
|
|
106
|
+
// the category endpoints themselves.
|
|
107
|
+
// Workaround: after that 404 on a categorize that names a category, read the thread once. When it is
|
|
108
|
+
// there, the category is what is missing. The read is best-effort: when it fails, Reply's own word
|
|
109
|
+
// stands.
|
|
110
|
+
const thread_exists = async (s, id) => {
|
|
111
|
+
try {
|
|
112
|
+
return (await (0, call_1.call_reply)(s, 'GET', `/v3/inbox/threads/${id}`, 'read')).status === 200;
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
if (e instanceof errors_1.Operation_error) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
throw e;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
// One absolute PUT, so a repeat lands on the same state. Reply clears the category on a null id.
|
|
122
|
+
const handle_inbox_categorize = async (thread_arg, opts, ctx, g) => {
|
|
123
|
+
const id = (0, options_1.parse_id)(thread_arg, 'Thread id');
|
|
124
|
+
if ((opts.categoryId === undefined) === (opts.clear !== true)) {
|
|
125
|
+
throw new errors_1.UsageError('Give exactly one of --category-id and --clear.', { code: 'usage.inbox' });
|
|
126
|
+
}
|
|
127
|
+
const category_id = opts.categoryId === undefined ? null : (0, options_1.parse_id)(opts.categoryId, '--category-id');
|
|
128
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
129
|
+
try {
|
|
130
|
+
const a = await (0, call_1.call_reply)(s, 'PUT', `/v3/inbox/threads/${id}/category`, 'write', { categoryId: category_id });
|
|
131
|
+
// Without a category named (--clear), the 404 can only be the thread's. inboxCategory.notFound is
|
|
132
|
+
// read too, should Reply ever answer this call with it; a 404 with neither code is reply.refused.
|
|
133
|
+
if (a.status === 404 && (0, call_1.reply_code_of)(a) === 'inboxThread.notFound') {
|
|
134
|
+
throw category_id !== null && await thread_exists(s, id) ? category_not_found(category_id, a) : thread_not_found(id, a);
|
|
135
|
+
}
|
|
136
|
+
if (a.status === 404 && (0, call_1.reply_code_of)(a) === 'inboxCategory.notFound') {
|
|
137
|
+
throw category_not_found(category_id, a);
|
|
138
|
+
}
|
|
139
|
+
if (a.status !== 204 && a.status !== 200) {
|
|
140
|
+
throw (0, call_1.refusal)(a, 'write');
|
|
141
|
+
}
|
|
142
|
+
(0, result_1.print_result)({ status: category_id === null ? 'cleared' : 'categorized', thread_id: id, category_id }, g);
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
throw (0, result_1.with_ids)(e, { thread_id: id });
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
exports.handle_inbox_categorize = handle_inbox_categorize;
|
|
149
|
+
// Reply marks threads only in bulk and answers with the ones it did not mark, so a thread missing
|
|
150
|
+
// from the answer is marked. No read first: a thread that is already so is answered the same way.
|
|
151
|
+
const mark_thread = async (thread_arg, read, ctx, g) => {
|
|
152
|
+
const id = (0, options_1.parse_id)(thread_arg, 'Thread id');
|
|
153
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
154
|
+
try {
|
|
155
|
+
const a = await (0, call_1.call_reply)(s, 'POST', `/v3/inbox/threads/${read ? 'mark-as-read' : 'mark-as-unread'}`, 'write', { threadIds: [id] });
|
|
156
|
+
if (a.status !== 200) {
|
|
157
|
+
throw (0, call_1.refusal)(a, 'write');
|
|
158
|
+
}
|
|
159
|
+
const failed = (0, call_1.item_failure)((0, call_1.expect_object)(a, 'write'), id);
|
|
160
|
+
if (failed?.error === 'notFound') {
|
|
161
|
+
throw new errors_1.Operation_error('inbox.thread_not_found', `This account has no inbox thread ${id} it can see.`, {
|
|
162
|
+
status: 200, reply_code: 'notFound',
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
if (failed !== undefined) {
|
|
166
|
+
throw new errors_1.Operation_error('reply.refused', `Reply did not mark the thread as ${read ? 'read' : 'unread'}.`, {
|
|
167
|
+
status: 200, reply_code: failed.error ?? undefined, detail: failed.details ?? undefined,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
(0, result_1.print_result)({ status: read ? 'read' : 'unread', thread_id: id }, g);
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
throw (0, result_1.with_ids)(e, { thread_id: id });
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const handle_inbox_mark_read = (thread_arg, ctx, g) => mark_thread(thread_arg, true, ctx, g);
|
|
177
|
+
exports.handle_inbox_mark_read = handle_inbox_mark_read;
|
|
178
|
+
const handle_inbox_mark_unread = (thread_arg, ctx, g) => mark_thread(thread_arg, false, ctx, g);
|
|
179
|
+
exports.handle_inbox_mark_unread = handle_inbox_mark_unread;
|
|
76
180
|
//# sourceMappingURL=inbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../src/operations/inbox.ts"],"names":[],"mappings":";;;AAAA,4CAA4D;AAC5D,
|
|
1
|
+
{"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../src/operations/inbox.ts"],"names":[],"mappings":";;;AAAA,4CAA4D;AAC5D,iCAGgB;AAChB,uCAA2F;AAC3F,qCAAgD;AAGhD,mGAAmG;AACnG,MAAM,OAAO,GAAG,EAAC,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAU,CAAC;AAiN/B,0BAAO;AA9M/E,uCAAuC;AACvC,MAAM,QAAQ,GAAG,EAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAU,CAAC;AA6MY,4BAAQ;AA1MzF,MAAM,gBAAgB,GAAG,CAAC,EAAU,EAAE,CAAS,EAAkB,EAAE,CAC/D,IAAI,wBAAe,CAAC,wBAAwB,EAAE,oCAAoC,EAAE,cAAc,EAAE;IAChG,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,IAAA,oBAAa,EAAC,CAAC,CAAC;CACjD,CAAC,CAAC;AAuM+C,4CAAgB;AAhMtE,MAAM,iBAAiB,GAAG,KAAK,EAAC,IAAqB,EAAE,GAAgB,EAAE,CAAa,EAAgB,EAAE;IACpG,IAAI,CAAC,IAAI,CAAC,SAAS,KAAK,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC,EACtE,CAAC;QACG,MAAM,IAAI,mBAAU,CAAC,qDAAqD,EAAE,EAAC,IAAI,EAAE,aAAa,EAAC,CAAC,CAAC;IACvG,CAAC;IACD,MAAM,MAAM,GAA4B,IAAI,CAAC,SAAS,KAAK,SAAS;QA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O,IAAI,SAAS;aAC1F,CAAC,CAAC;QACP,CAAC;QACD,IAAA,qBAAY,EAAC,EAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAC,EAAE,CAAC,CAAC,CAAC;IACvE,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAA,iBAAQ,EAAC,CAAC,EAAE,EAAC,SAAS,EAAE,EAAE,EAAC,CAAC,CAAC;IACvC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,CAAC,UAAkB,EAAE,GAAgB,EAAE,CAAa,EAAgB,EAAE,CACjG,WAAW,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;AAOtC,wDAAsB;AAL1B,MAAM,wBAAwB,GAAG,CAAC,UAAkB,EAAE,GAAgB,EAAE,CAAa,EAAgB,EAAE,CACnG,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;AAIf,4DAAwB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Op_globals } from './options';
|
|
2
|
+
import type { Cli_context } from '../context';
|
|
3
|
+
declare const handle_sequence_list: (opts: {
|
|
4
|
+
name?: string;
|
|
5
|
+
}, ctx: Cli_context, g: Op_globals, read_stdin?: () => string) => Promise<void>;
|
|
6
|
+
declare const handle_sequence_create: (opts: {
|
|
7
|
+
name?: string;
|
|
8
|
+
}, ctx: Cli_context, g: Op_globals, read_stdin?: () => string) => Promise<void>;
|
|
9
|
+
export { handle_sequence_list, handle_sequence_create };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.handle_sequence_create = exports.handle_sequence_list = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const errors_1 = require("../utils/errors");
|
|
6
|
+
const call_1 = require("./call");
|
|
7
|
+
const stdin_input_1 = require("./stdin-input");
|
|
8
|
+
const result_1 = require("./result");
|
|
9
|
+
const PAGE = 1000;
|
|
10
|
+
const PAGES = 20;
|
|
11
|
+
// The one step a sequence needs to exist: Reply refuses a sequence with none. A task is its owner's
|
|
12
|
+
// to-do and reaches nobody, even once the sequence runs; it says what it is, so whoever opens the
|
|
13
|
+
// sequence replaces it.
|
|
14
|
+
const PLACEHOLDER = {
|
|
15
|
+
type: 'task',
|
|
16
|
+
actionType: 'toDo',
|
|
17
|
+
delayInMinutes: 0,
|
|
18
|
+
description: 'Added because a sequence needs one step to exist; replace it before this sequence is ever started.',
|
|
19
|
+
};
|
|
20
|
+
// A sequence's name is a person's text: read from stdin only, sent as given, never repeated in a message.
|
|
21
|
+
const read_name = (source, command, read_stdin) => {
|
|
22
|
+
const raw = (0, stdin_input_1.read_stdin_object)(source, {
|
|
23
|
+
flag: '--name', what: 'name', fields: ['name'], code: 'usage.name',
|
|
24
|
+
hint: `Pipe it in: echo '{"name":"…"}' | ${config_1.PROGRAM_NAME} sequence ${command} --name -`,
|
|
25
|
+
}, read_stdin);
|
|
26
|
+
if (typeof raw.name !== 'string' || raw.name.trim() === '') {
|
|
27
|
+
throw new errors_1.UsageError('The name must be a string that is not blank.', { code: 'usage.name' });
|
|
28
|
+
}
|
|
29
|
+
return raw.name;
|
|
30
|
+
};
|
|
31
|
+
const words_of = (seq) => ({
|
|
32
|
+
status: typeof seq.status === 'string' ? seq.status : null,
|
|
33
|
+
is_archived: typeof seq.isArchived === 'boolean' ? seq.isArchived : null,
|
|
34
|
+
});
|
|
35
|
+
// Every sequence whose name is this one, exactly and ignoring case, archived ones included. Reply's
|
|
36
|
+
// own name filter matches part of a name, ignoring case, so it narrows the list and the names are
|
|
37
|
+
// compared here. Oldest first, so a sequence made while the pages are read lands after them rather
|
|
38
|
+
// than shifting one out of view. A name is free only once the end of the list is reached, so a list
|
|
39
|
+
// that does not end within twenty pages is refused rather than answered in part.
|
|
40
|
+
const handle_sequence_list = async (opts, ctx, g, read_stdin) => {
|
|
41
|
+
const name = read_name(opts.name, 'list', read_stdin);
|
|
42
|
+
const wanted = name.toLowerCase();
|
|
43
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
44
|
+
const items = [];
|
|
45
|
+
for (let page = 0; page < PAGES; page++) {
|
|
46
|
+
const a = await (0, call_1.call_reply)(s, 'GET', `/v3/sequences?name=${encodeURIComponent(name)}&sortBy=created&sortDirection=asc&top=${PAGE}&skip=${page * PAGE}`, 'read');
|
|
47
|
+
if (a.status !== 200) {
|
|
48
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
49
|
+
}
|
|
50
|
+
const body = (0, call_1.read_page)(a);
|
|
51
|
+
for (const entry of body.items) {
|
|
52
|
+
if (!(0, call_1.is_object)(entry) || typeof entry.name !== 'string' || entry.name.toLowerCase() !== wanted) {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (!(0, call_1.is_reply_id)(entry.id)) {
|
|
56
|
+
throw (0, call_1.unreadable)(a, 'read');
|
|
57
|
+
}
|
|
58
|
+
items.push({ id: entry.id, name: entry.name, ...words_of(entry), created_at: typeof entry.created === 'string' ? entry.created : null });
|
|
59
|
+
}
|
|
60
|
+
if (!body.has_more) {
|
|
61
|
+
(0, result_1.print_result)({ items }, g);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
throw new errors_1.Operation_error('sequence.list_incomplete', `Read ${PAGE * PAGES} sequences whose names contain this one and Reply said there were more, so it could not be decided which carry it.`, { status: 200 });
|
|
66
|
+
};
|
|
67
|
+
exports.handle_sequence_list = handle_sequence_list;
|
|
68
|
+
// The draft: the name and the one step, nothing else. Reply attaches the account's default schedule
|
|
69
|
+
// and mailbox on its own; the draft sends nothing, because it holds nobody and is never started here.
|
|
70
|
+
// Reply allows two sequences of one name, and a sequence keeps no key, so a repeat after a lost
|
|
71
|
+
// answer may make a second one.
|
|
72
|
+
const handle_sequence_create = async (opts, ctx, g, read_stdin) => {
|
|
73
|
+
const name = read_name(opts.name, 'create', read_stdin);
|
|
74
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
75
|
+
try {
|
|
76
|
+
const a = await (0, call_1.call_reply)(s, 'POST', '/v3/sequences', 'write', { name, steps: [PLACEHOLDER] });
|
|
77
|
+
if (a.status !== 201 && a.status !== 200) {
|
|
78
|
+
throw (0, call_1.refusal)(a, 'write');
|
|
79
|
+
}
|
|
80
|
+
const made = (0, call_1.expect_object)(a, 'write');
|
|
81
|
+
if (!(0, call_1.is_reply_id)(made.id)) {
|
|
82
|
+
// Reply said it made something and did not say what.
|
|
83
|
+
throw (0, call_1.unreadable)(a, 'write');
|
|
84
|
+
}
|
|
85
|
+
(0, result_1.print_result)({ sequence_id: made.id, steps_added: 1, ...words_of(made) }, g);
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
if (e instanceof errors_1.Unknown_outcome_error) {
|
|
89
|
+
e.hint = 'The sequence may have been made; running the command again may make a second one. Look for it with '
|
|
90
|
+
+ `\`${config_1.PROGRAM_NAME} sequence list --name -\` first.`;
|
|
91
|
+
}
|
|
92
|
+
throw e;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
exports.handle_sequence_create = handle_sequence_create;
|
|
96
|
+
//# sourceMappingURL=sequence-by-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence-by-name.js","sourceRoot":"","sources":["../../src/operations/sequence-by-name.ts"],"names":[],"mappings":";;;AAAA,sCAAuC;AACvC,4CAAmF;AACnF,iCAAuH;AAEvH,+CAAgD;AAChD,qCAAsC;AAGtC,MAAM,IAAI,GAAG,IAAI,CAAC;AAClB,MAAM,KAAK,GAAG,EAAE,CAAC;AAEjB,oGAAoG;AACpG,kGAAkG;AAClG,wBAAwB;AACxB,MAAM,WAAW,GAAG;IAChB,IAAI,EAAE,MAAM;IACZ,UAAU,EAAE,M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M,IAAA,iBAAU,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QACjC,CAAC;QACD,IAAA,qBAAY,EAAC,EAAC,WAAW,EAAE,IAAI,CAAC,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAC,EAAE,CAAC,CAAC,CAAC;IAC/E,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,IAAI,CAAC,YAAY,8BAAqB,EACtC,CAAC;YACG,CAAC,CAAC,IAAI,GAAG,qGAAqG;kBACxG,KAAK,qBAAY,kCAAkC,CAAC;QAC9D,CAAC;QACD,MAAM,CAAC,CAAC;IACZ,CAAC;AACL,CAAC,CAAC;AAE4B,wDAAsB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type Stdin_object_opts = {
|
|
2
|
+
flag: string;
|
|
3
|
+
what: string;
|
|
4
|
+
fields: readonly string[];
|
|
5
|
+
code: string;
|
|
6
|
+
hint: string;
|
|
7
|
+
};
|
|
8
|
+
declare const read_stdin_object: (source: string | undefined, o: Stdin_object_opts, read_stdin?: () => string) => Record<string, unknown>;
|
|
9
|
+
export { read_stdin_object };
|
|
10
|
+
export type { Stdin_object_opts };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.read_stdin_object = void 0;
|
|
4
|
+
const errors_1 = require("../utils/errors");
|
|
5
|
+
const json_arg_1 = require("../utils/json-arg");
|
|
6
|
+
const call_1 = require("./call");
|
|
7
|
+
// A person's text is read from stdin only, never from the argument list, which may be logged where
|
|
8
|
+
// it must not go; so the flag takes only '-'. No message here repeats any of the text: an unknown
|
|
9
|
+
// field is named, never its value.
|
|
10
|
+
const read_stdin_object = (source, o, read_stdin) => {
|
|
11
|
+
const shape = `{${o.fields.join(', ')}}`;
|
|
12
|
+
if (source !== '-') {
|
|
13
|
+
throw new errors_1.UsageError(source === undefined ? `No ${o.what} given.` : `${o.flag} takes only -: the ${o.what} is read from stdin.`, {
|
|
14
|
+
code: o.code, hint: o.hint,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
let value;
|
|
18
|
+
try {
|
|
19
|
+
value = JSON.parse((read_stdin ?? json_arg_1.read_all_stdin)());
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new errors_1.UsageError(`The ${o.what} on stdin must be JSON: ${shape}.`, { code: o.code });
|
|
23
|
+
}
|
|
24
|
+
if (!(0, call_1.is_object)(value)) {
|
|
25
|
+
throw new errors_1.UsageError(`The ${o.what} must be a JSON object: ${shape}.`, { code: o.code });
|
|
26
|
+
}
|
|
27
|
+
const unknown_field = Object.keys(value).find(k => !o.fields.includes(k));
|
|
28
|
+
if (unknown_field !== undefined) {
|
|
29
|
+
throw new errors_1.UsageError(`The ${o.what} has an unknown field '${unknown_field}'.`, { code: o.code, hint: `Fields: ${o.fields.join(', ')}.` });
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
};
|
|
33
|
+
exports.read_stdin_object = read_stdin_object;
|
|
34
|
+
//# sourceMappingURL=stdin-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stdin-input.js","sourceRoot":"","sources":["../../src/operations/stdin-input.ts"],"names":[],"mappings":";;;AAAA,4CAA2C;AAC3C,gDAAiD;AACjD,iCAAiC;AAUjC,mGAAmG;AACnG,kGAAkG;AAClG,mCAAmC;AACnC,MAAM,iBAAiB,GAAG,CAAC,MAA0B,EAAE,CAAoB,EAAE,UAAyB,EAA0B,EAAE;IAC9H,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;IACzC,IAAI,MAAM,KAAK,GAAG,EAClB,CAAC;QACG,MAAM,IAAI,mBAAU,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,SAAS,CAAC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