reply-cli 0.5.0 → 0.11.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 +149 -16
- package/dist/commands/api.d.ts +2 -1
- package/dist/commands/api.js +42 -42
- package/dist/commands/api.js.map +1 -1
- package/dist/index.js +22 -7
- package/dist/index.js.map +1 -1
- package/dist/operations/call.d.ts +35 -0
- package/dist/operations/call.js +131 -0
- package/dist/operations/call.js.map +1 -0
- package/dist/operations/commands.d.ts +6 -0
- package/dist/operations/commands.js +153 -0
- package/dist/operations/commands.js.map +1 -0
- package/dist/operations/contact-input.d.ts +29 -0
- package/dist/operations/contact-input.js +84 -0
- package/dist/operations/contact-input.js.map +1 -0
- package/dist/operations/contact-list.d.ts +9 -0
- package/dist/operations/contact-list.js +50 -0
- package/dist/operations/contact-list.js.map +1 -0
- package/dist/operations/contact.d.ts +7 -0
- package/dist/operations/contact.js +49 -0
- package/dist/operations/contact.js.map +1 -0
- package/dist/operations/contacts.d.ts +11 -0
- package/dist/operations/contacts.js +115 -0
- package/dist/operations/contacts.js.map +1 -0
- package/dist/operations/inbox.d.ts +22 -0
- package/dist/operations/inbox.js +76 -0
- package/dist/operations/inbox.js.map +1 -0
- package/dist/operations/options.d.ts +18 -0
- package/dist/operations/options.js +63 -0
- package/dist/operations/options.js.map +1 -0
- package/dist/operations/result.d.ts +5 -0
- package/dist/operations/result.js +20 -0
- package/dist/operations/result.js.map +1 -0
- package/dist/operations/sequence-membership.d.ts +13 -0
- package/dist/operations/sequence-membership.js +227 -0
- package/dist/operations/sequence-membership.js.map +1 -0
- package/dist/operations/sequence-read.d.ts +26 -0
- package/dist/operations/sequence-read.js +121 -0
- package/dist/operations/sequence-read.js.map +1 -0
- package/dist/operations/sequence-state.d.ts +7 -0
- package/dist/operations/sequence-state.js +88 -0
- package/dist/operations/sequence-state.js.map +1 -0
- package/dist/skills/adapter-flat.d.ts +3 -1
- package/dist/skills/adapter-flat.js +49 -19
- package/dist/skills/adapter-flat.js.map +1 -1
- package/dist/skills/hosts.js +35 -13
- package/dist/skills/hosts.js.map +1 -1
- package/dist/skills/orchestrate.js +41 -4
- package/dist/skills/orchestrate.js.map +1 -1
- package/dist/skills/report.js +36 -10
- package/dist/skills/report.js.map +1 -1
- package/dist/skills/types.d.ts +11 -1
- package/dist/utils/client.d.ts +5 -2
- package/dist/utils/client.js +113 -78
- package/dist/utils/client.js.map +1 -1
- package/dist/utils/errors.d.ts +30 -2
- package/dist/utils/errors.js +51 -2
- package/dist/utils/errors.js.map +1 -1
- package/dist/utils/json-arg.d.ts +10 -0
- package/dist/utils/json-arg.js +45 -0
- package/dist/utils/json-arg.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SOURCES = exports.handle_inbox_get = exports.handle_inbox_list = void 0;
|
|
4
|
+
const errors_1 = require("../utils/errors");
|
|
5
|
+
const call_1 = require("./call");
|
|
6
|
+
const options_1 = require("./options");
|
|
7
|
+
const result_1 = require("./result");
|
|
8
|
+
// Reply's own `source` filter. It has no "all": without --source Reply answers its default, inbox.
|
|
9
|
+
const SOURCES = { 'inbox': 'inbox', 'sent': 'sent', 'unread': 'unread', 'ai-draft': 'aiDraft' };
|
|
10
|
+
exports.SOURCES = SOURCES;
|
|
11
|
+
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
|
+
status: a.status, reply_code: (0, call_1.reply_code_of)(a),
|
|
13
|
+
});
|
|
14
|
+
const handle_inbox_list = async (opts, ctx, g) => {
|
|
15
|
+
if ((opts.contactId === undefined) === (opts.sequenceId === undefined)) {
|
|
16
|
+
throw new errors_1.UsageError('Give exactly one of --contact-id and --sequence-id.', { code: 'usage.inbox' });
|
|
17
|
+
}
|
|
18
|
+
const filter = opts.contactId !== undefined
|
|
19
|
+
? { contactIds: [(0, options_1.parse_id)(opts.contactId, '--contact-id')] }
|
|
20
|
+
: { sequenceIds: [(0, options_1.parse_id)(opts.sequenceId, '--sequence-id')] };
|
|
21
|
+
const source = (0, options_1.parse_choice)(opts.source, '--source', Object.keys(SOURCES));
|
|
22
|
+
if (source !== undefined) {
|
|
23
|
+
filter.source = SOURCES[source];
|
|
24
|
+
}
|
|
25
|
+
if (opts.since !== undefined) {
|
|
26
|
+
// Reply's `from` keeps only threads that moved strictly after it; --since keeps the ones
|
|
27
|
+
// that moved at or after it, so Reply is asked from one millisecond earlier.
|
|
28
|
+
filter.from = new Date(Date.parse((0, options_1.parse_iso)(opts.since, '--since')) - 1).toISOString();
|
|
29
|
+
}
|
|
30
|
+
const limit = (0, options_1.parse_int_in)(opts.limit, '--limit', 1, 100, 20);
|
|
31
|
+
const offset = (0, options_1.parse_int_in)(opts.offset, '--offset', 0, 1000000, 0);
|
|
32
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
33
|
+
// A POST that changes nothing: the filter travels in the body.
|
|
34
|
+
const a = await (0, call_1.call_reply)(s, 'POST', `/v3/inbox/threads/filter?top=${limit}&skip=${offset}`, 'read', filter);
|
|
35
|
+
if (a.status !== 200) {
|
|
36
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
37
|
+
}
|
|
38
|
+
const page = (0, call_1.read_page)(a);
|
|
39
|
+
(0, result_1.print_result)({ items: page.items, has_more: page.has_more }, g);
|
|
40
|
+
};
|
|
41
|
+
exports.handle_inbox_list = handle_inbox_list;
|
|
42
|
+
// INTERIM (API gap): GET /v3/inbox/threads/{id} carries the thread's whole history inline, every
|
|
43
|
+
// body included and with no limit, and the thread has no subject of its own.
|
|
44
|
+
// Needed: a thread without its history inline, and a subject field.
|
|
45
|
+
// Workaround: drop the history (the paged messages are the history) and take the subject from the
|
|
46
|
+
// latest email message.
|
|
47
|
+
const thread_header = (thread) => {
|
|
48
|
+
const { messages, ...header } = thread;
|
|
49
|
+
const history = Array.isArray(messages) ? messages.filter(call_1.is_object) : [];
|
|
50
|
+
const latest_email = history.filter(m => m.channel === 'email').pop();
|
|
51
|
+
return { ...header, subject: typeof latest_email?.subject === 'string' ? latest_email.subject : null };
|
|
52
|
+
};
|
|
53
|
+
const handle_inbox_get = async (thread_arg, opts, ctx, g) => {
|
|
54
|
+
const id = (0, options_1.parse_id)(thread_arg, 'Thread id');
|
|
55
|
+
const limit = (0, options_1.parse_int_in)(opts.limit, '--limit', 1, 20, 20);
|
|
56
|
+
const offset = (0, options_1.parse_int_in)(opts.offset, '--offset', 0, 1000000, 0);
|
|
57
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
58
|
+
const t = await (0, call_1.call_reply)(s, 'GET', `/v3/inbox/threads/${id}`, 'read');
|
|
59
|
+
if (t.status === 404) {
|
|
60
|
+
throw 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 m = await (0, call_1.call_reply)(s, 'GET', `/v3/inbox/threads/${id}/messages?top=${limit}&skip=${offset}`, 'read');
|
|
67
|
+
if (m.status === 404) {
|
|
68
|
+
throw thread_not_found(id, m);
|
|
69
|
+
}
|
|
70
|
+
if (m.status !== 200) {
|
|
71
|
+
throw (0, call_1.refusal)(m, 'read');
|
|
72
|
+
}
|
|
73
|
+
(0, result_1.print_result)({ thread: thread_header(thread), messages: (0, call_1.read_page)(m) }, g);
|
|
74
|
+
};
|
|
75
|
+
exports.handle_inbox_get = handle_inbox_get;
|
|
76
|
+
//# sourceMappingURL=inbox.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inbox.js","sourceRoot":"","sources":["../../src/operations/inbox.ts"],"names":[],"mappings":";;;AAAA,4CAA4D;AAC5D,iCAA0H;AAC1H,uCAA2F;AAC3F,qCAAsC;AAGtC,mGAAmG;A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AAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,EACpB,CAAC;QACG,MAAM,IAAA,cAAO,EAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IACD,MAAM,MAAM,GAAG,IAAA,oBAAa,EAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IACxC,MAAM,CAAC,GAAG,MAAM,IAAA,iBAAU,EAAC,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,iBAAiB,KAAK,SAAS,MAAM,EAAE,EAAE,MAAM,CAAC,CAAC;IAC7G,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,EACpB,CAAC;QACG,MAAM,gBAAgB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAClC,CAAC;IACD,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,EACpB,CAAC;QACG,MAAM,IAAA,cAAO,EAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7B,CAAC;IACD,IAAA,qBAAY,EAAC,EAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,IAAA,gBAAS,EAAC,CAAC,CAAC,EAAC,EAAE,CAAC,CAAC,CAAC;AAC7E,CAAC,CAAC;AAEyB,4CAAgB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Command } from 'commander';
|
|
2
|
+
type Op_globals = {
|
|
3
|
+
apiKey?: string;
|
|
4
|
+
profile?: string;
|
|
5
|
+
teamId?: string;
|
|
6
|
+
userId?: string;
|
|
7
|
+
userEmail?: string;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
pretty?: boolean;
|
|
10
|
+
};
|
|
11
|
+
declare const read_op_globals: (cmd: Command) => Op_globals;
|
|
12
|
+
declare const LARGEST_REPLY_ID = 2147483647;
|
|
13
|
+
declare const parse_id: (raw: string, label: string) => number;
|
|
14
|
+
declare const parse_int_in: (raw: string | undefined, label: string, min: number, max: number, fallback: number) => number;
|
|
15
|
+
declare const parse_iso: (raw: string, label: string) => string;
|
|
16
|
+
declare const parse_choice: <T extends string>(raw: string | undefined, label: string, allowed: readonly T[]) => T | undefined;
|
|
17
|
+
export { read_op_globals, parse_id, parse_int_in, parse_iso, parse_choice, LARGEST_REPLY_ID, };
|
|
18
|
+
export type { Op_globals };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LARGEST_REPLY_ID = exports.parse_choice = exports.parse_iso = exports.parse_int_in = exports.parse_id = exports.read_op_globals = void 0;
|
|
4
|
+
const errors_1 = require("../utils/errors");
|
|
5
|
+
const read_op_globals = (cmd) => {
|
|
6
|
+
const o = cmd.optsWithGlobals();
|
|
7
|
+
return {
|
|
8
|
+
apiKey: o.apiKey, profile: o.profile,
|
|
9
|
+
teamId: o.teamId, userId: o.userId, userEmail: o.userEmail,
|
|
10
|
+
json: o.json, pretty: o.pretty,
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
exports.read_op_globals = read_op_globals;
|
|
14
|
+
const LARGEST_REPLY_ID = 2147483647;
|
|
15
|
+
exports.LARGEST_REPLY_ID = LARGEST_REPLY_ID;
|
|
16
|
+
// Reply numbers its sequences, contacts, lists and threads with positive 32-bit integers, so a
|
|
17
|
+
// value that is not one names nothing an account could hold and is refused before any call.
|
|
18
|
+
const parse_id = (raw, label) => {
|
|
19
|
+
const value = raw.trim();
|
|
20
|
+
if (!/^[1-9][0-9]{0,9}$/.test(value) || Number(value) > LARGEST_REPLY_ID) {
|
|
21
|
+
// Not echoed when it looks like an address: stderr may be logged where personal data must not go.
|
|
22
|
+
throw new errors_1.UsageError(`${label} must be a Reply id: a positive whole number.`, {
|
|
23
|
+
code: 'usage.id', hint: raw.includes('@') ? undefined : `Got: ${raw}`,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return Number(value);
|
|
27
|
+
};
|
|
28
|
+
exports.parse_id = parse_id;
|
|
29
|
+
const parse_int_in = (raw, label, min, max, fallback) => {
|
|
30
|
+
if (raw === undefined) {
|
|
31
|
+
return fallback;
|
|
32
|
+
}
|
|
33
|
+
const value = raw.trim();
|
|
34
|
+
if (!/^-?[0-9]+$/.test(value) || Number(value) < min || Number(value) > max) {
|
|
35
|
+
throw new errors_1.UsageError(`${label} must be a whole number from ${min} to ${max}.`, { code: 'usage.range', hint: `Got: ${raw}` });
|
|
36
|
+
}
|
|
37
|
+
return Number(value);
|
|
38
|
+
};
|
|
39
|
+
exports.parse_int_in = parse_int_in;
|
|
40
|
+
const ISO_8601 = /^(\d{4}-\d{2}-\d{2})(?:[T ](\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?)(Z|[+-]\d{2}:?\d{2})?)?$/i;
|
|
41
|
+
// ISO 8601 only: a date, or a date and a time. A time without a zone is taken as UTC, never as the
|
|
42
|
+
// machine's local time, which would shift a window silently.
|
|
43
|
+
const parse_iso = (raw, label) => {
|
|
44
|
+
const m = ISO_8601.exec(raw.trim());
|
|
45
|
+
const zone = m?.[3] === undefined ? 'Z' : m[3].toUpperCase().replace(/^([+-]\d{2})(\d{2})$/, '$1:$2');
|
|
46
|
+
const at = m === null ? NaN : Date.parse(`${m[1]}T${m[2] ?? '00:00'}${zone}`);
|
|
47
|
+
if (isNaN(at)) {
|
|
48
|
+
throw new errors_1.UsageError(`${label} must be a date and time, e.g. 2026-10-01T00:00:00Z.`, { code: 'usage.date', hint: `Got: ${raw}` });
|
|
49
|
+
}
|
|
50
|
+
return new Date(at).toISOString();
|
|
51
|
+
};
|
|
52
|
+
exports.parse_iso = parse_iso;
|
|
53
|
+
const parse_choice = (raw, label, allowed) => {
|
|
54
|
+
if (raw === undefined) {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
if (!allowed.includes(raw)) {
|
|
58
|
+
throw new errors_1.UsageError(`${label} must be one of: ${allowed.join(', ')}.`, { code: 'usage.choice', hint: `Got: ${raw}` });
|
|
59
|
+
}
|
|
60
|
+
return raw;
|
|
61
|
+
};
|
|
62
|
+
exports.parse_choice = parse_choice;
|
|
63
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/operations/options.ts"],"names":[],"mappings":";;;AACA,4CAA2C;AAY3C,MAAM,eAAe,GAAG,CAAC,GAAY,EAAa,EAAE;IAChD,MAAM,CAAC,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC;IAChC,OAAO;QACH,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO;QACpC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC,SAAS;QAC1D,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM;KACjC,CAAC;AACN,CAAC,CAAC;AA2DE,0CAAe;AAzDnB,MAAM,gBAAgB,GAAG,UAAU,CAAC;AAyDkC,4CAAgB;AAvDtF,+FAA+F;AAC/F,4FAA4F;AAC5F,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,KAAa,EAAS,EAAE;IACnD,MAAM,KAAK,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC;IACzB,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,gBAAgB,EACxE,CAAC;QACG,kGAAkG;QAClG,MAAM,IAAI,mBAAU,CAAC,GAAG,KAAK,+CAA+C,EAAE;YAC1E,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,GAAG,EAAE;SACxE,CAAC,CAAC;IACP,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;AACzB,CAAC,CAAC;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CAAC,IAAI,OAAO,GAAG,IAAI,EAAE,CAAC,CAAC;IAC9E,IAAI,KAAK,CAAC,EAAE,CAAC,EACb,CAAC;QACG,MAAM,IAAI,mBAAU,CAAC,GAAG,KAAK,sDAAsD,EAAE,EAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,GAAG,EAAE,EAAC,CAAC,CAAC;IACpI,CAAC;IACD,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;AACtC,CAAC,CAAC;AAe2C,8BAAS;AAbtD,MAAM,YAAY,GAAG,CAAmB,GAAuB,EAAE,KAAa,EAAE,OAAqB,EAAgB,EAAE;IACnH,IAAI,GAAG,KAAK,SAAS,EACrB,CAAC;QACG,OAAO,SAAS,CAAC;IACrB,CAAC;IACD,IAAI,CAAE,OAA6B,CAAC,QAAQ,CAAC,GAAG,CAAC,EACjD,CAAC;QACG,MAAM,IAAI,mBAAU,CAAC,GAAG,KAAK,oBAAoB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,EAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,QAAQ,GAAG,EAAE,EAAC,CAAC,CAAC;IACzH,CAAC;IACD,OAAO,GAAQ,CAAC;AACpB,CAAC,CAAC;AAGsD,oCAAY"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.with_ids = exports.print_result = void 0;
|
|
4
|
+
const output_1 = require("../utils/output");
|
|
5
|
+
const errors_1 = require("../utils/errors");
|
|
6
|
+
// Every operation prints JSON, as `reply api` does: indented by default, compact with --json.
|
|
7
|
+
const print_result = (data, g) => {
|
|
8
|
+
(0, output_1.print)(data, { json: g.json, pretty: g.pretty });
|
|
9
|
+
};
|
|
10
|
+
exports.print_result = print_result;
|
|
11
|
+
// Attaches what an operation had learned to a failure on its way out, so a caller still gets,
|
|
12
|
+
// say, the id of a contact created before the add was refused.
|
|
13
|
+
const with_ids = (error, ids) => {
|
|
14
|
+
if (error instanceof errors_1.Operation_error) {
|
|
15
|
+
error.ids = { ...ids, ...error.ids };
|
|
16
|
+
}
|
|
17
|
+
return error;
|
|
18
|
+
};
|
|
19
|
+
exports.with_ids = with_ids;
|
|
20
|
+
//# sourceMappingURL=result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/operations/result.ts"],"names":[],"mappings":";;;AAAA,4CAAsC;AACtC,4CAA0D;AAG1D,8FAA8F;AAC9F,MAAM,YAAY,GAAG,CAAC,IAAa,EAAE,CAAa,EAAO,EAAE;IACvD,IAAA,cAAK,EAAC,IAAI,EAAE,EAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAC,CAAC,CAAC;AAClD,CAAC,CAAC;AAYM,oCAAY;AAVpB,8FAA8F;AAC9F,+DAA+D;AAC/D,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAE,GAAQ,EAAU,EAAE;IAClD,IAAI,KAAK,YAAY,wBAAe,EACpC,CAAC;QACG,KAAK,CAAC,GAAG,GAAG,EAAC,GAAG,GAAG,EAAE,GAAG,KAAK,CAAC,GAAG,EAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AAEoB,4BAAQ"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Op_globals } from './options';
|
|
2
|
+
import { type Contact_flags } from './contact-input';
|
|
3
|
+
import type { Cli_context } from '../context';
|
|
4
|
+
type Add_contact_opts = Contact_flags & {
|
|
5
|
+
startStep?: string;
|
|
6
|
+
ignoreStepDelay?: boolean;
|
|
7
|
+
};
|
|
8
|
+
declare const resolve_step_position: (sequence: Record<string, unknown>, position: number) => number;
|
|
9
|
+
declare const handle_sequence_add_contact: (id_arg: string, opts: Add_contact_opts, ctx: Cli_context, g: Op_globals, read_stdin?: () => string) => Promise<void>;
|
|
10
|
+
type Remove_contact_opts = Contact_flags;
|
|
11
|
+
declare const handle_sequence_remove_contact: (id_arg: string, opts: Remove_contact_opts, ctx: Cli_context, g: Op_globals, read_stdin?: () => string) => Promise<void>;
|
|
12
|
+
export { handle_sequence_add_contact, handle_sequence_remove_contact, resolve_step_position };
|
|
13
|
+
export type { Add_contact_opts, Remove_contact_opts };
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolve_step_position = exports.handle_sequence_remove_contact = exports.handle_sequence_add_contact = void 0;
|
|
4
|
+
const errors_1 = require("../utils/errors");
|
|
5
|
+
const call_1 = require("./call");
|
|
6
|
+
const options_1 = require("./options");
|
|
7
|
+
const contact_input_1 = require("./contact-input");
|
|
8
|
+
const contacts_1 = require("./contacts");
|
|
9
|
+
const sequence_read_1 = require("./sequence-read");
|
|
10
|
+
const result_1 = require("./result");
|
|
11
|
+
const step_not_found = (position, why) => new errors_1.Operation_error('sequence.step_not_found', `There is no step ${position} to start at: ${why}.`, { status: 200 });
|
|
12
|
+
// INTERIM (API gap): a sequence's steps carry no order field. GET /v3/sequences/{id} returns them
|
|
13
|
+
// as a graph of parentId links, with the order shown only in display names like "1" and "3.1",
|
|
14
|
+
// and no endpoint maps a position to a step id.
|
|
15
|
+
// Needed: a step order field, or a position→id lookup.
|
|
16
|
+
// Workaround: walk the chain from the one step without a parent and take the Nth link. Refuse
|
|
17
|
+
// wherever the answer would be a guess: a fork, a condition, a position past the end.
|
|
18
|
+
const resolve_step_position = (sequence, position) => {
|
|
19
|
+
const steps = Array.isArray(sequence.steps) ? sequence.steps.filter(call_1.is_object) : [];
|
|
20
|
+
if (steps.length === 0) {
|
|
21
|
+
throw step_not_found(position, 'the sequence has no steps');
|
|
22
|
+
}
|
|
23
|
+
const roots = steps.filter(step => step.parentId === null || step.parentId === undefined);
|
|
24
|
+
if (roots.length !== 1) {
|
|
25
|
+
throw step_not_found(position, `its steps have ${roots.length} starting points, so they are not one chain`);
|
|
26
|
+
}
|
|
27
|
+
let at = roots[0];
|
|
28
|
+
for (let index = 1; index <= steps.length; index++) {
|
|
29
|
+
if (typeof at.type === 'string' && at.type.toLowerCase() === 'condition') {
|
|
30
|
+
throw step_not_found(position, `step ${index} is a condition, so the steps after it branch`);
|
|
31
|
+
}
|
|
32
|
+
if (index === position) {
|
|
33
|
+
if (!(0, call_1.is_reply_id)(at.id)) {
|
|
34
|
+
throw step_not_found(position, `step ${position} carries no id`);
|
|
35
|
+
}
|
|
36
|
+
return at.id;
|
|
37
|
+
}
|
|
38
|
+
const current = at;
|
|
39
|
+
const next = steps.filter(step => step.parentId === current.id);
|
|
40
|
+
if (next.length === 0) {
|
|
41
|
+
throw step_not_found(position, `the chain ends at step ${index}`);
|
|
42
|
+
}
|
|
43
|
+
if (next.length > 1) {
|
|
44
|
+
throw step_not_found(position, `step ${index} is followed by ${next.length} steps`);
|
|
45
|
+
}
|
|
46
|
+
at = next[0];
|
|
47
|
+
}
|
|
48
|
+
throw step_not_found(position, 'its steps lead back into one another');
|
|
49
|
+
};
|
|
50
|
+
exports.resolve_step_position = resolve_step_position;
|
|
51
|
+
const NOT_TAKING_PART = ['sequencecontact.notinsequence', 'contact.notfound'];
|
|
52
|
+
const SEQUENCE_MISSING = ['sequence.notfound', 'sequencecontact.sequencenotfound'];
|
|
53
|
+
// A 404 on a call that names both the sequence and the contact. Only the codes that mean the
|
|
54
|
+
// person takes no part are read that way: a missing sequence, or a code this version doesn't know,
|
|
55
|
+
// ends the command rather than being taken for "not in it".
|
|
56
|
+
const require_not_taking_part = (sequence_id, a, kind) => {
|
|
57
|
+
const code = (0, call_1.reply_code_of)(a)?.toLowerCase();
|
|
58
|
+
if (code !== undefined && NOT_TAKING_PART.includes(code)) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (code !== undefined && SEQUENCE_MISSING.includes(code)) {
|
|
62
|
+
throw (0, sequence_read_1.sequence_not_found)(sequence_id, a);
|
|
63
|
+
}
|
|
64
|
+
throw (0, call_1.refusal)(a, kind);
|
|
65
|
+
};
|
|
66
|
+
// INTERIM (API gap): POST /v3/sequences/{id}/contact-links/bulk never says that a contact is
|
|
67
|
+
// already in the sequence. For one who is, it acts as a forward-only move: a start step ahead of
|
|
68
|
+
// theirs answers "added" and moves them there, skipping the steps between; the same or an earlier
|
|
69
|
+
// step is refused with the generic invalidInput, and even then can reassign their email account.
|
|
70
|
+
// Needed: a per-item "already in sequence" answer, and a no-op for a contact who is already in.
|
|
71
|
+
// Workaround: for a contact that existed before this call, read its participation first and write
|
|
72
|
+
// nothing when it is there. It costs one extra read per add of an existing contact.
|
|
73
|
+
const participation_before_add = async (s, sequence_id, contact_id) => {
|
|
74
|
+
const a = await (0, call_1.call_reply)(s, 'GET', `/v3/sequences/${sequence_id}/contacts/${contact_id}`, 'read');
|
|
75
|
+
if (a.status === 404) {
|
|
76
|
+
require_not_taking_part(sequence_id, a, 'read');
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (a.status !== 200) {
|
|
80
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
81
|
+
}
|
|
82
|
+
(0, call_1.expect_object)(a, 'read');
|
|
83
|
+
return true;
|
|
84
|
+
};
|
|
85
|
+
// INTERIM (API gap): every per-item refusal of POST /v3/sequences/{id}/contact-links/bulk is the
|
|
86
|
+
// same invalidInput, "Contact could not be added to sequence", whether the contact is opted out,
|
|
87
|
+
// over a limit, or anything else. Opted-out contacts are skipped this way without a word.
|
|
88
|
+
// Needed: real per-item reasons (opted out, already in the sequence, limits).
|
|
89
|
+
// Workaround: after a refusal, read the contact's statuses once. Opted out → contact.opted_out;
|
|
90
|
+
// anything else → reply.refused, carrying Reply's own words.
|
|
91
|
+
const explain_not_added = async (s, contact_id, refused) => {
|
|
92
|
+
if (await (0, contacts_1.read_opted_out)(s, contact_id)) {
|
|
93
|
+
return new errors_1.Operation_error('contact.opted_out', `Contact ${contact_id} is opted out, so Reply did not add them to the sequence.`, { status: 200 });
|
|
94
|
+
}
|
|
95
|
+
return new errors_1.Operation_error('reply.refused', 'Reply did not add the contact to the sequence.', {
|
|
96
|
+
status: 200, reply_code: refused.error ?? undefined, detail: refused.details ?? undefined,
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
const add_to_sequence = async (s, sequence_id, contact_id, o) => {
|
|
100
|
+
const body = {
|
|
101
|
+
contactIds: [contact_id],
|
|
102
|
+
// Always sent, never left to Reply's default: true would take the person out of every other
|
|
103
|
+
// sequence they are in, which nobody asked for.
|
|
104
|
+
removeFromExisting: false,
|
|
105
|
+
ignoreStepDelay: o.ignore_step_delay,
|
|
106
|
+
};
|
|
107
|
+
if (o.start_step_id !== undefined) {
|
|
108
|
+
body.startStepId = o.start_step_id;
|
|
109
|
+
}
|
|
110
|
+
const a = await (0, call_1.call_reply)(s, 'POST', `/v3/sequences/${sequence_id}/contact-links/bulk`, 'write', body);
|
|
111
|
+
if (a.status === 404) {
|
|
112
|
+
throw (0, sequence_read_1.sequence_not_found)(sequence_id, a);
|
|
113
|
+
}
|
|
114
|
+
if (a.status === 400 && (0, call_1.reply_code_of)(a) === 'sequenceContact.noStepsInSequence') {
|
|
115
|
+
throw new errors_1.Operation_error('sequence.has_no_steps', `Sequence ${sequence_id} has no step to send.`, { status: 400, reply_code: (0, call_1.reply_code_of)(a) });
|
|
116
|
+
}
|
|
117
|
+
if (a.status === 400 && (0, call_1.reply_code_of)(a) === 'sequenceContact.contactLimitExceeded') {
|
|
118
|
+
throw new errors_1.Operation_error('account.contact_limit_reached', 'The account is at its plan\'s limit.', {
|
|
119
|
+
status: 400, reply_code: (0, call_1.reply_code_of)(a), detail: (0, call_1.detail_of)(a),
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (a.status !== 200) {
|
|
123
|
+
throw (0, call_1.refusal)(a, 'write');
|
|
124
|
+
}
|
|
125
|
+
const answer = (0, call_1.expect_object)(a, 'write');
|
|
126
|
+
if (Array.isArray(answer.added) && answer.added.includes(contact_id)) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const refused = (0, call_1.item_failure)(answer.notProcessed, contact_id);
|
|
130
|
+
if (refused === undefined) {
|
|
131
|
+
throw (0, call_1.unreadable)(a, 'write');
|
|
132
|
+
}
|
|
133
|
+
throw await explain_not_added(s, contact_id, refused);
|
|
134
|
+
};
|
|
135
|
+
const handle_sequence_add_contact = async (id_arg, opts, ctx, g, read_stdin) => {
|
|
136
|
+
const sequence_id = (0, options_1.parse_id)(id_arg, 'Sequence id');
|
|
137
|
+
const contact = (0, contact_input_1.read_contact_input)(opts, read_stdin);
|
|
138
|
+
const start_step = opts.startStep === undefined ? undefined : (0, options_1.parse_int_in)(opts.startStep, '--start-step', 1, 10000, 1);
|
|
139
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
140
|
+
const ids = { sequence_id };
|
|
141
|
+
try {
|
|
142
|
+
const sequence = await (0, sequence_read_1.read_sequence)(s, sequence_id);
|
|
143
|
+
if (sequence.isArchived === true) {
|
|
144
|
+
throw (0, sequence_read_1.sequence_archived)(sequence_id);
|
|
145
|
+
}
|
|
146
|
+
const start_step_id = start_step === undefined ? undefined : resolve_step_position(sequence, start_step);
|
|
147
|
+
const ensured = await (0, contacts_1.ensure_contact)(s, contact);
|
|
148
|
+
ids.contact_id = ensured.id;
|
|
149
|
+
const result = (status) => ({
|
|
150
|
+
status, sequence_id, contact_id: ensured.id, contact_created: ensured.created,
|
|
151
|
+
sequence_active: sequence.status === 'active',
|
|
152
|
+
});
|
|
153
|
+
if (!ensured.created && await participation_before_add(s, sequence_id, ensured.id)) {
|
|
154
|
+
(0, result_1.print_result)(result('already_in_sequence'), g);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
await add_to_sequence(s, sequence_id, ensured.id, { start_step_id, ignore_step_delay: opts.ignoreStepDelay === true });
|
|
158
|
+
(0, result_1.print_result)(result('added'), g);
|
|
159
|
+
}
|
|
160
|
+
catch (e) {
|
|
161
|
+
throw (0, result_1.with_ids)(e, ids);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
exports.handle_sequence_add_contact = handle_sequence_add_contact;
|
|
165
|
+
// INTERIM (API gap): GET /v3/sequences/{id}/contacts/{contact_id} and the DELETE answer one and
|
|
166
|
+
// the same 404, sequenceContact.notInSequence, whether the sequence doesn't exist, the contact
|
|
167
|
+
// doesn't exist, or the contact just isn't in it.
|
|
168
|
+
// Needed: distinct 404 codes for a missing sequence and a missing contact.
|
|
169
|
+
// Workaround: after that 404, read the sequence itself, so a mistyped sequence id is reported as
|
|
170
|
+
// sequence.not_found and not as a successful stop.
|
|
171
|
+
const confirm_sequence_after_404 = async (s, sequence_id) => {
|
|
172
|
+
await (0, sequence_read_1.read_sequence)(s, sequence_id);
|
|
173
|
+
};
|
|
174
|
+
// INTERIM (API gap): DELETE /v3/sequences/{id}/contact-links/{contact_id} also removes a
|
|
175
|
+
// participation that has finished, which changes the sequence's statistics, and its answer says
|
|
176
|
+
// nothing about what it removed.
|
|
177
|
+
// Needed: a stop that leaves finished participations alone and reports what it did.
|
|
178
|
+
// Workaround: read the participation first. A finished one, or none at all, is already stopped,
|
|
179
|
+
// and nothing is written.
|
|
180
|
+
const participation_before_remove = async (s, sequence_id, contact_id) => {
|
|
181
|
+
const a = await (0, call_1.call_reply)(s, 'GET', `/v3/sequences/${sequence_id}/contacts/${contact_id}`, 'read');
|
|
182
|
+
if (a.status === 404) {
|
|
183
|
+
require_not_taking_part(sequence_id, a, 'read');
|
|
184
|
+
await confirm_sequence_after_404(s, sequence_id);
|
|
185
|
+
return 'stopped';
|
|
186
|
+
}
|
|
187
|
+
if (a.status !== 200) {
|
|
188
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
189
|
+
}
|
|
190
|
+
return (0, call_1.expect_object)(a, 'read').statusInSequence === 'finished' ? 'stopped' : 'active';
|
|
191
|
+
};
|
|
192
|
+
const remove_from_sequence = async (s, sequence_id, contact_id) => {
|
|
193
|
+
if (await participation_before_remove(s, sequence_id, contact_id) === 'stopped') {
|
|
194
|
+
return 'not_in_sequence';
|
|
195
|
+
}
|
|
196
|
+
const a = await (0, call_1.call_reply)(s, 'DELETE', `/v3/sequences/${sequence_id}/contact-links/${contact_id}`, 'write');
|
|
197
|
+
if (a.status === 200 || a.status === 204) {
|
|
198
|
+
return 'removed';
|
|
199
|
+
}
|
|
200
|
+
if (a.status === 404) {
|
|
201
|
+
// The person left between the read and the removal.
|
|
202
|
+
require_not_taking_part(sequence_id, a, 'write');
|
|
203
|
+
return 'not_in_sequence';
|
|
204
|
+
}
|
|
205
|
+
throw (0, call_1.refusal)(a, 'write');
|
|
206
|
+
};
|
|
207
|
+
const handle_sequence_remove_contact = async (id_arg, opts, ctx, g, read_stdin) => {
|
|
208
|
+
const sequence_id = (0, options_1.parse_id)(id_arg, 'Sequence id');
|
|
209
|
+
const contact = (0, contact_input_1.read_contact_input)(opts, read_stdin);
|
|
210
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
211
|
+
const ids = { sequence_id };
|
|
212
|
+
try {
|
|
213
|
+
const contact_id = await (0, contacts_1.find_contact)(s, contact);
|
|
214
|
+
if (contact_id === null) {
|
|
215
|
+
// Nobody under this address: they take part in nothing.
|
|
216
|
+
(0, result_1.print_result)({ status: 'not_in_sequence', sequence_id, contact_id: null }, g);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
ids.contact_id = contact_id;
|
|
220
|
+
(0, result_1.print_result)({ status: await remove_from_sequence(s, sequence_id, contact_id), sequence_id, contact_id }, g);
|
|
221
|
+
}
|
|
222
|
+
catch (e) {
|
|
223
|
+
throw (0, result_1.with_ids)(e, ids);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
exports.handle_sequence_remove_contact = handle_sequence_remove_contact;
|
|
227
|
+
//# sourceMappingURL=sequence-membership.js.map
|
|
@@ -0,0 +1 @@
|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EAAE,IAAyB,EAAE,GAAgB,EAAE,CAAa,EAAE,UAAyB,EACzF,EAAE;IACd,MAAM,WAAW,GAAG,IAAA,kBAAQ,EAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IACpD,MAAM,OAAO,GAAG,IAAA,kCAAkB,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACrD,MAAM,CAAC,GAAG,MAAM,IAAA,mBAAY,EAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IACrC,MAAM,GAAG,GAAQ,EAAC,WAAW,EAAC,CAAC;IAC/B,IAAI,CAAC;QACD,MAAM,UAAU,GAAG,MAAM,IAAA,uBAAY,EAAC,CAAC,EAAE,OAAO,CAAC,CAAC;QAClD,IAAI,UAAU,KAAK,IAAI,EACvB,CAAC;YACG,wDAAwD;YACxD,IAAA,qBAAY,EAAC,EAAC,MAAM,EAAE,iBAAiB,EAAE,WAAW,EAAE,UAAU,EAAE,IAAI,EAAC,EAAE,CAAC,CAAC,CAAC;YAC5E,OAAO;QACX,CAAC;QACD,GAAG,CAAC,UAAU,GAAG,UAAU,CAAC;QAC5B,IAAA,qBAAY,EAAC,EAAC,MAAM,EAAE,MAAM,oBAAoB,CAAC,CAAC,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,WAAW,EAAE,UAAU,EAAC,EAAE,CAAC,CAAC,CAAC;IAC/G,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACT,MAAM,IAAA,iBAAQ,EAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3B,CAAC;AACL,CAAC,CAAC;AAEmC,wEAA8B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Operation_error } from '../utils/errors';
|
|
2
|
+
import { type Answer, type Op_session } from './call';
|
|
3
|
+
import { type Op_globals } from './options';
|
|
4
|
+
import type { Cli_context } from '../context';
|
|
5
|
+
declare const PRESETS: {
|
|
6
|
+
readonly 'last-week': "lastWeek";
|
|
7
|
+
readonly 'last-month': "lastMonth";
|
|
8
|
+
readonly 'last-year': "lastYear";
|
|
9
|
+
readonly 'all-time': "allTime";
|
|
10
|
+
};
|
|
11
|
+
declare const sequence_not_found: (id: number, a: Answer) => Operation_error;
|
|
12
|
+
declare const sequence_archived: (id: number, a?: Answer) => Operation_error;
|
|
13
|
+
declare const read_sequence: (s: Op_session, id: number) => Promise<Record<string, unknown>>;
|
|
14
|
+
declare const count_contacts: (s: Op_session, id: number) => Promise<number | null>;
|
|
15
|
+
declare const require_count: (s: Op_session, id: number) => Promise<number>;
|
|
16
|
+
declare const handle_sequence_get: (id_arg: string, ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
17
|
+
declare const handle_sequence_contacts: (id_arg: string, opts: {
|
|
18
|
+
limit?: string;
|
|
19
|
+
offset?: string;
|
|
20
|
+
}, ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
21
|
+
declare const handle_sequence_stats: (id_arg: string, opts: {
|
|
22
|
+
preset?: string;
|
|
23
|
+
from?: string;
|
|
24
|
+
to?: string;
|
|
25
|
+
}, ctx: Cli_context, g: Op_globals) => Promise<void>;
|
|
26
|
+
export { read_sequence, count_contacts, require_count, sequence_not_found, sequence_archived, handle_sequence_get, handle_sequence_contacts, handle_sequence_stats, PRESETS, };
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PRESETS = exports.handle_sequence_stats = exports.handle_sequence_contacts = exports.handle_sequence_get = exports.sequence_archived = exports.sequence_not_found = exports.require_count = exports.count_contacts = exports.read_sequence = void 0;
|
|
4
|
+
const errors_1 = require("../utils/errors");
|
|
5
|
+
const call_1 = require("./call");
|
|
6
|
+
const options_1 = require("./options");
|
|
7
|
+
const result_1 = require("./result");
|
|
8
|
+
const PRESETS = {
|
|
9
|
+
'last-week': 'lastWeek',
|
|
10
|
+
'last-month': 'lastMonth',
|
|
11
|
+
'last-year': 'lastYear',
|
|
12
|
+
'all-time': 'allTime',
|
|
13
|
+
};
|
|
14
|
+
exports.PRESETS = PRESETS;
|
|
15
|
+
const sequence_not_found = (id, a) => new errors_1.Operation_error('sequence.not_found', `This account has no sequence ${id}.`, { status: a.status, reply_code: (0, call_1.reply_code_of)(a) });
|
|
16
|
+
exports.sequence_not_found = sequence_not_found;
|
|
17
|
+
const sequence_archived = (id, a) => new errors_1.Operation_error('sequence.archived', `Sequence ${id} is archived.`, {
|
|
18
|
+
status: a?.status ?? 200, reply_code: a === undefined ? undefined : (0, call_1.reply_code_of)(a),
|
|
19
|
+
});
|
|
20
|
+
exports.sequence_archived = sequence_archived;
|
|
21
|
+
const read_sequence = async (s, id) => {
|
|
22
|
+
const a = await (0, call_1.call_reply)(s, 'GET', `/v3/sequences/${id}`, 'read');
|
|
23
|
+
if (a.status === 404) {
|
|
24
|
+
throw sequence_not_found(id, a);
|
|
25
|
+
}
|
|
26
|
+
if (a.status !== 200) {
|
|
27
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
28
|
+
}
|
|
29
|
+
return (0, call_1.expect_object)(a, 'read');
|
|
30
|
+
};
|
|
31
|
+
exports.read_sequence = read_sequence;
|
|
32
|
+
// Reply's own count of the people in the sequence, or null when it would not count them. The
|
|
33
|
+
// page of contacts answers an empty 200 for a sequence that doesn't exist; the count answers 404,
|
|
34
|
+
// so it is also what tells the two apart.
|
|
35
|
+
const count_contacts = async (s, id) => {
|
|
36
|
+
const a = await (0, call_1.call_reply)(s, 'GET', `/v3/sequences/${id}/contacts/count`, 'read');
|
|
37
|
+
if (a.status === 404) {
|
|
38
|
+
throw sequence_not_found(id, a);
|
|
39
|
+
}
|
|
40
|
+
if (a.status !== 200 || !(0, call_1.is_object)(a.data)) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
const count = a.data.count;
|
|
44
|
+
return typeof count === 'number' && Number.isInteger(count) && count >= 0 ? count : null;
|
|
45
|
+
};
|
|
46
|
+
exports.count_contacts = count_contacts;
|
|
47
|
+
// The count where a decision depends on it: anything but a number is that call's own failure.
|
|
48
|
+
const require_count = async (s, id) => {
|
|
49
|
+
const a = await (0, call_1.call_reply)(s, 'GET', `/v3/sequences/${id}/contacts/count`, 'read');
|
|
50
|
+
if (a.status === 404) {
|
|
51
|
+
throw sequence_not_found(id, a);
|
|
52
|
+
}
|
|
53
|
+
if (a.status !== 200) {
|
|
54
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
55
|
+
}
|
|
56
|
+
const count = (0, call_1.expect_object)(a, 'read').count;
|
|
57
|
+
if (typeof count !== 'number' || !Number.isInteger(count) || count < 0) {
|
|
58
|
+
throw (0, call_1.unreadable)(a, 'read');
|
|
59
|
+
}
|
|
60
|
+
return count;
|
|
61
|
+
};
|
|
62
|
+
exports.require_count = require_count;
|
|
63
|
+
const handle_sequence_get = async (id_arg, ctx, g) => {
|
|
64
|
+
const id = (0, options_1.parse_id)(id_arg, 'Sequence id');
|
|
65
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
66
|
+
(0, result_1.print_result)(await read_sequence(s, id), g);
|
|
67
|
+
};
|
|
68
|
+
exports.handle_sequence_get = handle_sequence_get;
|
|
69
|
+
const handle_sequence_contacts = async (id_arg, opts, ctx, g) => {
|
|
70
|
+
const id = (0, options_1.parse_id)(id_arg, 'Sequence id');
|
|
71
|
+
const limit = (0, options_1.parse_int_in)(opts.limit, '--limit', 1, 1000, 100);
|
|
72
|
+
const offset = (0, options_1.parse_int_in)(opts.offset, '--offset', 0, 1000000, 0);
|
|
73
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
74
|
+
const a = await (0, call_1.call_reply)(s, 'GET', `/v3/sequences/${id}/contacts?top=${limit}&skip=${offset}`, 'read');
|
|
75
|
+
if (a.status === 404) {
|
|
76
|
+
throw sequence_not_found(id, a);
|
|
77
|
+
}
|
|
78
|
+
if (a.status !== 200) {
|
|
79
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
80
|
+
}
|
|
81
|
+
const page = (0, call_1.read_page)(a);
|
|
82
|
+
(0, result_1.print_result)({ items: page.items, has_more: page.has_more, total: await count_contacts(s, id) }, g);
|
|
83
|
+
};
|
|
84
|
+
exports.handle_sequence_contacts = handle_sequence_contacts;
|
|
85
|
+
// INTERIM (API gap): POST /v3/sequences/{id}/stats answers a span that doesn't end after it starts
|
|
86
|
+
// with a 500, not a validation problem, so it reads as Reply being down and is asked again.
|
|
87
|
+
// Needed: a 400 validation problem for such a span.
|
|
88
|
+
// Workaround: refuse the span as a usage error before sending.
|
|
89
|
+
const stats_span = (raw_from, raw_to) => {
|
|
90
|
+
const from = (0, options_1.parse_iso)(raw_from, '--from');
|
|
91
|
+
const to = (0, options_1.parse_iso)(raw_to, '--to');
|
|
92
|
+
if (Date.parse(from) >= Date.parse(to)) {
|
|
93
|
+
throw new errors_1.UsageError('--to must be later than --from.', { code: 'usage.stats' });
|
|
94
|
+
}
|
|
95
|
+
return { from, to };
|
|
96
|
+
};
|
|
97
|
+
const handle_sequence_stats = async (id_arg, opts, ctx, g) => {
|
|
98
|
+
const id = (0, options_1.parse_id)(id_arg, 'Sequence id');
|
|
99
|
+
const preset = (0, options_1.parse_choice)(opts.preset, '--preset', Object.keys(PRESETS));
|
|
100
|
+
const by_preset = preset !== undefined;
|
|
101
|
+
const by_span = opts.from !== undefined && opts.to !== undefined;
|
|
102
|
+
const partial_span = (opts.from !== undefined) !== (opts.to !== undefined);
|
|
103
|
+
if (by_preset === by_span || partial_span) {
|
|
104
|
+
throw new errors_1.UsageError('Give the window as --preset, or as both --from and --to.', { code: 'usage.stats' });
|
|
105
|
+
}
|
|
106
|
+
const filters = preset !== undefined
|
|
107
|
+
? { dateRangePreset: PRESETS[preset] }
|
|
108
|
+
: stats_span(opts.from, opts.to);
|
|
109
|
+
const s = await (0, call_1.open_session)(ctx, g);
|
|
110
|
+
// A POST that changes nothing: the window travels in the body.
|
|
111
|
+
const a = await (0, call_1.call_reply)(s, 'POST', `/v3/sequences/${id}/stats`, 'read', { filters });
|
|
112
|
+
if (a.status === 404) {
|
|
113
|
+
throw sequence_not_found(id, a);
|
|
114
|
+
}
|
|
115
|
+
if (a.status !== 200) {
|
|
116
|
+
throw (0, call_1.refusal)(a, 'read');
|
|
117
|
+
}
|
|
118
|
+
(0, result_1.print_result)((0, call_1.expect_object)(a, 'read'), g);
|
|
119
|
+
};
|
|
120
|
+
exports.handle_sequence_stats = handle_sequence_stats;
|
|
121
|
+
//# sourceMappingURL=sequence-read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sequence-read.js","sourceRoot":"","sources":["../../src/operations/sequence-read.ts"],"names":[],"mappings":";;;AAAA,4CAA4D;AAC5D,iCAGgB;AAChB,uCAA2F;AAC3F,qCAAsC;AAGtC,MAAM,OAAO,GAAG;IACZ,WAAW,EAAE,UAAU;IACvB,YAAY,EAAE,WAAW;IACzB,WAAW,EAAE,UAAU;IACvB,UAAU,EAAE,SAAS;CACf,CAAC;AAmI+D,0BAAO;AAhIjF,MAAM,kBAAkB,GAAG,CAAC,EAAU,EAAE,CAAS,EAAkB,EAAE,CACjE,IAAI,wBAAe,CAAC,oBAAoB,EAAE,gCAAgC,EAAE,GAAG,EAAE,EAAC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,UAAU,EAAE,IAAA,oBAAa,EAAC,CAAC,CAAC,EAAC,CAAC,CAAC;AA8HrF,gDAAkB;AA5HpE,MAAM,iBAAiB,GAAG,CAAC,EAAU,EAAE,CAAU,EAAkB,EAAE,CACjE,IAAI,wBAAe,CAAC,mBAAmB,EAAE,YAAY,EAAE,eAAe,EAAE;IACpE,MAAM,EAAE,CAAC,EAAE,MAAM,IAAI,GAAG,EAAE,UAAU,EAAE,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,oBAAa,EAAC,CAAC,CAAC;CACvF,CAAC,CAAC;AAyH+D,8CAAiB;AAvHvF,MAAM,aAAa,GAAG,KAAK,EAAC,CAAa,EAAE,EAAU,EAAm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