@blocklive/cli 0.0.0-stage → 0.7.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/LICENSE +3 -0
- package/README.md +202 -2
- package/dist/browser.js +194 -0
- package/dist/catalog.js +1016 -0
- package/dist/change.js +181 -0
- package/dist/cli.js +1176 -0
- package/dist/config.js +105 -0
- package/dist/csv.js +76 -0
- package/dist/errors.js +75 -0
- package/dist/http.js +189 -0
- package/dist/idempotency.js +39 -0
- package/dist/image-file.js +95 -0
- package/dist/lock.js +186 -0
- package/dist/login.js +203 -0
- package/dist/main.js +49 -0
- package/dist/read.js +155 -0
- package/dist/reads/developer-request.js +31 -0
- package/dist/reads/developers.js +53 -0
- package/dist/reads/domains.js +84 -0
- package/dist/reads/events.js +956 -0
- package/dist/reads/index.js +47 -0
- package/dist/reads/invoices.js +177 -0
- package/dist/reads/payment-account.js +177 -0
- package/dist/reads/places.js +55 -0
- package/dist/reads/promo-import.js +183 -0
- package/dist/reads/promos.js +62 -0
- package/dist/reads/requests.js +119 -0
- package/dist/reads/tickets.js +386 -0
- package/dist/safe.js +88 -0
- package/dist/secrets.js +267 -0
- package/dist/stdin.js +72 -0
- package/dist/style.js +44 -0
- package/dist/unattended.js +311 -0
- package/package.json +30 -5
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.READS = void 0;
|
|
4
|
+
// The commands beyond events and guests, by their name in the catalog
|
|
5
|
+
// (catalog.ts). Each is a file here and a line in the help. A command gets
|
|
6
|
+
// the words after its first (`claim lunar-live x.example`). Its file is
|
|
7
|
+
// loaded when it runs, so other commands don't pay for it.
|
|
8
|
+
const developers = () => require('./developers');
|
|
9
|
+
// Asked here, confirmed in the browser (requests.ts).
|
|
10
|
+
const developerRequest = () => require('./developer-request');
|
|
11
|
+
const domains = () => require('./domains');
|
|
12
|
+
// Events, their drafts, and publishing them with a sign-in allowed to
|
|
13
|
+
// (events.ts).
|
|
14
|
+
const events = () => require('./events');
|
|
15
|
+
const invoices = () => require('./invoices');
|
|
16
|
+
const paymentAccount = () => require('./payment-account');
|
|
17
|
+
const places = () => require('./places');
|
|
18
|
+
const promos = () => require('./promos');
|
|
19
|
+
const promoImport = () => require('./promo-import');
|
|
20
|
+
const requests = () => require('./requests');
|
|
21
|
+
const tickets = () => require('./tickets');
|
|
22
|
+
exports.READS = {
|
|
23
|
+
'developers list': (read, rest) => developers().listDevelopers(read, rest),
|
|
24
|
+
'developers add': (read, rest) => developerRequest().addDeveloper(read, rest),
|
|
25
|
+
'domains list': (read, rest) => domains().listDomains(read, rest),
|
|
26
|
+
'domains claim': (read, rest) => domains().claimDomain(read, rest),
|
|
27
|
+
'events create': (read, rest) => events().createEvent(read, rest),
|
|
28
|
+
'events edit': (read, rest) => events().editEvent(read, rest),
|
|
29
|
+
'event draft': (read, rest) => events().showDraft(read, rest),
|
|
30
|
+
'event publish': (read, rest) => events().publishEvent(read, rest),
|
|
31
|
+
'invoices list': (read, rest) => invoices().listInvoices(read, rest),
|
|
32
|
+
'invoice show': (read, rest) => invoices().showInvoice(read, rest),
|
|
33
|
+
'invoice issue': (read, rest) => invoices().issueInvoice(read, rest),
|
|
34
|
+
'payment-account show': (read, rest) => paymentAccount().showPaymentAccount(read, rest),
|
|
35
|
+
'payment-account choices': (read, rest) => paymentAccount().listPaymentAccountChoices(read, rest),
|
|
36
|
+
'payment-account choose': (read, rest) => paymentAccount().choosePaymentAccount(read, rest),
|
|
37
|
+
'payment-account switch': (read, rest) => paymentAccount().switchPaymentAccount(read, rest),
|
|
38
|
+
'places search': (read, rest) => places().searchPlaces(read, rest),
|
|
39
|
+
'promos list': (read, rest) => promos().listPromos(read, rest),
|
|
40
|
+
'promos import': (read, rest) => promoImport().importPromos(read, rest),
|
|
41
|
+
'promos undo': (read, rest) => promoImport().undoImport(read, rest),
|
|
42
|
+
'request show': (read, rest) => requests().showRequest(read, rest),
|
|
43
|
+
'tickets list': (read, rest) => tickets().listTickets(read, rest),
|
|
44
|
+
'tickets add': (read, rest) => tickets().addTicket(read, rest),
|
|
45
|
+
'tickets edit': (read, rest) => tickets().editTicket(read, rest),
|
|
46
|
+
'tickets remove': (read, rest) => tickets().removeTicket(read, rest),
|
|
47
|
+
};
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.issueInvoice = exports.showInvoice = exports.listInvoices = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const read_1 = require("../read");
|
|
6
|
+
const requests_1 = require("./requests");
|
|
7
|
+
const STATUS = {
|
|
8
|
+
not_enabled: 'invoicing off',
|
|
9
|
+
issued: 'issued',
|
|
10
|
+
processing: 'being made',
|
|
11
|
+
ready_to_issue: 'ready to issue',
|
|
12
|
+
missing_details: 'billing details missing',
|
|
13
|
+
seller_setup_required: 'invoice settings unfinished',
|
|
14
|
+
needs_review: 'needs review',
|
|
15
|
+
not_eligible: 'not eligible',
|
|
16
|
+
};
|
|
17
|
+
const SELLER = {
|
|
18
|
+
organiser: 'the organiser',
|
|
19
|
+
blocklive: 'Blocklive',
|
|
20
|
+
};
|
|
21
|
+
function seller(o) {
|
|
22
|
+
return o.sellerOfRecord
|
|
23
|
+
? SELLER[o.sellerOfRecord] ?? o.sellerOfRecord
|
|
24
|
+
: 'not known yet';
|
|
25
|
+
}
|
|
26
|
+
function money(minor, currency) {
|
|
27
|
+
return minor === null
|
|
28
|
+
? ''
|
|
29
|
+
: `${(minor / 100).toFixed(2)} ${currency ?? ''}`.trim();
|
|
30
|
+
}
|
|
31
|
+
async function listInvoices(read, rest) {
|
|
32
|
+
const event = (0, read_1.named)(rest, 'list', 'event');
|
|
33
|
+
if (read.values.limit !== undefined && Number(read.values.limit) > 25)
|
|
34
|
+
throw (0, errors_1.usage)('--limit is a number from 1 to 25 for invoices.');
|
|
35
|
+
const { rows, more, first } = await (0, read_1.pages)(read, `/events/${encodeURIComponent(event)}/invoices`, (body) => body.orders ?? []);
|
|
36
|
+
if (read.json) {
|
|
37
|
+
read.io.out(JSON.stringify({
|
|
38
|
+
event: first?.event,
|
|
39
|
+
enabled: first?.enabled,
|
|
40
|
+
eventSeller: first?.eventSeller,
|
|
41
|
+
orders: rows,
|
|
42
|
+
more,
|
|
43
|
+
}));
|
|
44
|
+
return errors_1.EXIT.ok;
|
|
45
|
+
}
|
|
46
|
+
const out = read.io.out;
|
|
47
|
+
out(`Invoicing: ${first?.enabled ? 'on' : 'off'} · this event's payments go to ${first?.eventSeller ? SELLER[first.eventSeller] : 'no account yet'}`);
|
|
48
|
+
out('');
|
|
49
|
+
if (!rows.length)
|
|
50
|
+
out('No orders with billing details or invoices yet.');
|
|
51
|
+
else {
|
|
52
|
+
for (const line of (0, read_1.table)([
|
|
53
|
+
['ORDER', 'BUYER', 'STATUS', 'SELLER', 'INVOICE', 'ID'],
|
|
54
|
+
...rows.map((o) => [
|
|
55
|
+
o.name ?? String(o.number ?? ''),
|
|
56
|
+
o.buyer ?? '',
|
|
57
|
+
STATUS[o.status] ?? o.status,
|
|
58
|
+
seller(o),
|
|
59
|
+
o.documents.map((d) => d.number).join(', '),
|
|
60
|
+
o.id,
|
|
61
|
+
]),
|
|
62
|
+
]))
|
|
63
|
+
out(line);
|
|
64
|
+
const waiting = rows.filter((o) => o.reason);
|
|
65
|
+
if (waiting.length) {
|
|
66
|
+
out('');
|
|
67
|
+
out('Why they wait:');
|
|
68
|
+
for (const o of waiting)
|
|
69
|
+
out(` ${o.name ?? o.number}: ${o.reason}`);
|
|
70
|
+
}
|
|
71
|
+
if (more)
|
|
72
|
+
out('More orders: use --all, or --limit.');
|
|
73
|
+
}
|
|
74
|
+
if (first?.path) {
|
|
75
|
+
out('');
|
|
76
|
+
out(`Issue invoices and change settings on Blocklive: ${read.base}${first.path}`);
|
|
77
|
+
}
|
|
78
|
+
return errors_1.EXIT.ok;
|
|
79
|
+
}
|
|
80
|
+
exports.listInvoices = listInvoices;
|
|
81
|
+
async function showInvoice(read, rest) {
|
|
82
|
+
const args = rest[0] === 'show' ? rest.slice(1) : rest;
|
|
83
|
+
if (args.length !== 1 ||
|
|
84
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(args[0]))
|
|
85
|
+
throw (0, errors_1.usage)('Name the order by its ID, as `invoices list` and `guests list --json` show it.');
|
|
86
|
+
const o = await read.client.get(`/invoices/${args[0]}`);
|
|
87
|
+
if (read.json) {
|
|
88
|
+
read.io.out(JSON.stringify(o));
|
|
89
|
+
return errors_1.EXIT.ok;
|
|
90
|
+
}
|
|
91
|
+
const out = read.io.out;
|
|
92
|
+
out(`Order ${o.name ?? o.number} · ${o.event.title} · ${(0, read_1.day)(o.orderedAt)}`);
|
|
93
|
+
out(`Status: ${STATUS[o.status] ?? o.status}`);
|
|
94
|
+
if (o.reason)
|
|
95
|
+
out(`Why: ${o.reason}`);
|
|
96
|
+
out(`Seller of record: ${seller(o)}${o.sellerFrom ? ` (from ${o.sellerFrom.replace(/_/g, ' ')})` : ''} · the event's payments now go to ${o.eventSeller ? SELLER[o.eventSeller] : 'no account'}`);
|
|
97
|
+
if (o.paymentCollectedBy === 'blocklive' &&
|
|
98
|
+
o.sellerOfRecord !== 'blocklive')
|
|
99
|
+
out('Payment collected by Blocklive, as ticketing partner');
|
|
100
|
+
if (o.billing) {
|
|
101
|
+
const b = o.billing;
|
|
102
|
+
out('');
|
|
103
|
+
out(`Bill to: ${b.legalName} (${b.buyerType}) · ${b.billingEmail}`);
|
|
104
|
+
out(` ${[
|
|
105
|
+
b.addressLine1,
|
|
106
|
+
b.addressLine2,
|
|
107
|
+
b.city,
|
|
108
|
+
b.region,
|
|
109
|
+
b.postalCode,
|
|
110
|
+
b.countryCode,
|
|
111
|
+
]
|
|
112
|
+
.filter(Boolean)
|
|
113
|
+
.join(', ')}`);
|
|
114
|
+
if (b.taxId)
|
|
115
|
+
out(` ${b.taxIdType}: ${b.taxId}`);
|
|
116
|
+
out(` Entered by the ${b.submittedSource} on ${(0, read_1.day)(b.submittedAt)}`);
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
out('No billing details yet.');
|
|
120
|
+
if (o.documents.length) {
|
|
121
|
+
out('');
|
|
122
|
+
for (const line of (0, read_1.table)([
|
|
123
|
+
['DOCUMENT', 'NUMBER', 'ISSUED', 'TOTAL', 'TAX', 'SELLER'],
|
|
124
|
+
...o.documents.map((d) => [
|
|
125
|
+
d.type === 'credit_note' ? 'credit note' : 'invoice',
|
|
126
|
+
d.number,
|
|
127
|
+
(0, read_1.day)(d.issuedAt),
|
|
128
|
+
money(d.totalMinor, d.currency),
|
|
129
|
+
money(d.taxMinor, d.currency),
|
|
130
|
+
d.seller ? SELLER[d.seller] ?? d.seller : '',
|
|
131
|
+
]),
|
|
132
|
+
]))
|
|
133
|
+
out(line);
|
|
134
|
+
}
|
|
135
|
+
if (o.path) {
|
|
136
|
+
out('');
|
|
137
|
+
out(`On Blocklive: ${read.base}${o.path}`);
|
|
138
|
+
}
|
|
139
|
+
return errors_1.EXIT.ok;
|
|
140
|
+
}
|
|
141
|
+
exports.showInvoice = showInvoice;
|
|
142
|
+
// `blocklive invoice issue <order>`: ask to issue an order's invoice. A
|
|
143
|
+
// numbered invoice is a legal document, so it is confirmed and issued on
|
|
144
|
+
// Blocklive with a new two-step code; the CLI then reads the order again and
|
|
145
|
+
// says what it has. It isn't emailed.
|
|
146
|
+
async function issueInvoice(read, rest) {
|
|
147
|
+
const [, order, ...extra] = rest;
|
|
148
|
+
if (extra.length ||
|
|
149
|
+
!order ||
|
|
150
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(order))
|
|
151
|
+
throw (0, errors_1.usage)('Name the order by its ID, as `invoices list` and `guests list --json` show it.');
|
|
152
|
+
const asked = await read.client.post(`/invoices/${order.toLowerCase()}/issue`, {});
|
|
153
|
+
const s = asked.summary;
|
|
154
|
+
read.io.err(`Asked to issue the invoice for order ${s.order.name ?? s.order.number ?? order}${asked.event ? ` of ${asked.event.title}` : ''}, to ${s.buyer?.legalName ?? 'the buyer'}, with ${seller({ sellerOfRecord: s.seller })} as seller of record.`);
|
|
155
|
+
const now = await (0, requests_1.confirmOnBlocklive)(read, asked);
|
|
156
|
+
if (!now)
|
|
157
|
+
return errors_1.EXIT.ok;
|
|
158
|
+
// What the order has now, as `invoice show` reads it.
|
|
159
|
+
const o = await read.client.get(`/invoices/${order.toLowerCase()}`);
|
|
160
|
+
if (read.json) {
|
|
161
|
+
read.io.out(JSON.stringify({ request: now, order: o }));
|
|
162
|
+
return o.status === 'issued' || o.status === 'processing'
|
|
163
|
+
? errors_1.EXIT.ok
|
|
164
|
+
: errors_1.EXIT.refused;
|
|
165
|
+
}
|
|
166
|
+
const invoice = o.documents.find((d) => d.type === 'invoice');
|
|
167
|
+
if (o.status === 'issued') {
|
|
168
|
+
read.io.out(`Issued${invoice?.number ? `: ${invoice.number}` : ''}. Send it from the invoices page.`);
|
|
169
|
+
return errors_1.EXIT.ok;
|
|
170
|
+
}
|
|
171
|
+
if (o.status === 'processing') {
|
|
172
|
+
read.io.out('Confirmed. The invoice is being made: check it with blocklive invoice show.');
|
|
173
|
+
return errors_1.EXIT.ok;
|
|
174
|
+
}
|
|
175
|
+
throw new errors_1.CliError(`Confirmed, but it wasn't issued: ${STATUS[o.status] ?? o.status}${o.reason ? ` (${o.reason})` : ''}. Run the command again once it's ready.`, errors_1.EXIT.refused, 'not_issued');
|
|
176
|
+
}
|
|
177
|
+
exports.issueInvoice = issueInvoice;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.choosePaymentAccount = exports.listPaymentAccountChoices = exports.switchPaymentAccount = exports.showPaymentAccount = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const read_1 = require("../read");
|
|
6
|
+
const requests_1 = require("./requests");
|
|
7
|
+
function account(a) {
|
|
8
|
+
if (!a)
|
|
9
|
+
return 'none yet';
|
|
10
|
+
const whose = a.whose === 'blocklive'
|
|
11
|
+
? "Blocklive's (merchant of record)"
|
|
12
|
+
: `the organiser's${a.owner ? ` (${a.owner})` : ''}`;
|
|
13
|
+
return `${a.provider} …${a.endsWith ?? ''}, ${whose}, ${a.status}`;
|
|
14
|
+
}
|
|
15
|
+
function refusal(s) {
|
|
16
|
+
return s.refused
|
|
17
|
+
? `refused (${s.cardOrders} card order${s.cardOrders === 1 ? '' : 's'})`
|
|
18
|
+
: 'allowed';
|
|
19
|
+
}
|
|
20
|
+
async function showPaymentAccount(read, rest) {
|
|
21
|
+
const name = (0, read_1.named)(rest, 'show', 'event or team');
|
|
22
|
+
let body;
|
|
23
|
+
let isEvent = true;
|
|
24
|
+
try {
|
|
25
|
+
body = await read.client.get(`/events/${encodeURIComponent(name)}/payment-account`, undefined,
|
|
26
|
+
// The name may be a team's: "not found" means try that.
|
|
27
|
+
{ notFoundAsIs: true });
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (!(error instanceof errors_1.CliError) || error.exitCode !== errors_1.EXIT.notFound)
|
|
31
|
+
throw error;
|
|
32
|
+
isEvent = false;
|
|
33
|
+
body = await read.client.get(`/payment-account/${encodeURIComponent(name)}`);
|
|
34
|
+
}
|
|
35
|
+
if (read.json) {
|
|
36
|
+
read.io.out(JSON.stringify(body));
|
|
37
|
+
return errors_1.EXIT.ok;
|
|
38
|
+
}
|
|
39
|
+
const out = read.io.out;
|
|
40
|
+
if (isEvent) {
|
|
41
|
+
out(`${body.event.title}`);
|
|
42
|
+
out(`Takes payments: ${account(body.account)}`);
|
|
43
|
+
out(`Team default: ${account(body.teamDefault)}${body.sameAsTeam ? ' (the same)' : ''}`);
|
|
44
|
+
if (body.lastChangedAt)
|
|
45
|
+
out(`Last changed: ${(0, read_1.day)(body.lastChangedAt)}`);
|
|
46
|
+
out(`Switching it: ${refusal(body.switch)}. ${body.switch.reason}`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
out(`${body.place.name} (team)`);
|
|
50
|
+
out(`Default for new events: ${account(body.teamDefault)}`);
|
|
51
|
+
if (body.lastChangedAt)
|
|
52
|
+
out(`Last changed: ${(0, read_1.day)(body.lastChangedAt)}`);
|
|
53
|
+
out(`Switching it: allowed. ${body.switch.reason}`);
|
|
54
|
+
if (body.events.length) {
|
|
55
|
+
out('');
|
|
56
|
+
for (const line of (0, read_1.table)([
|
|
57
|
+
['EVENT', 'ACCOUNT', 'SAME AS TEAM', 'SWITCH'],
|
|
58
|
+
...body.events.map((e) => [
|
|
59
|
+
e.title,
|
|
60
|
+
e.account
|
|
61
|
+
? `${e.account.provider} …${e.account.endsWith ?? ''} (${e.account.whose})`
|
|
62
|
+
: 'none yet',
|
|
63
|
+
e.sameAsTeam ? 'yes' : 'no',
|
|
64
|
+
refusal(e.switch),
|
|
65
|
+
]),
|
|
66
|
+
]))
|
|
67
|
+
out(line);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (body.path) {
|
|
71
|
+
out('');
|
|
72
|
+
out(`Payment accounts on Blocklive: ${read.base}${body.path}`);
|
|
73
|
+
}
|
|
74
|
+
return errors_1.EXIT.ok;
|
|
75
|
+
}
|
|
76
|
+
exports.showPaymentAccount = showPaymentAccount;
|
|
77
|
+
// `blocklive payment-account switch <event|team> --to <account|team>
|
|
78
|
+
// --reason …` (Paul, 8 Nov): a Blocklive admin's change, so the CLI only
|
|
79
|
+
// asks. Blocklive refuses it at once when #2951's guard would; otherwise
|
|
80
|
+
// the confirm page shows from and to and the reason, and it is done there
|
|
81
|
+
// with a new code from the authenticator. The CLI waits for the answer.
|
|
82
|
+
async function switchPaymentAccount(read, rest) {
|
|
83
|
+
const name = (0, read_1.named)(rest, 'switch', 'event or team');
|
|
84
|
+
const to = read.values.to;
|
|
85
|
+
const reason = read.values.reason;
|
|
86
|
+
if (!to || !(to === 'team' || /^[0-9a-f-]{36}$/i.test(to)))
|
|
87
|
+
throw (0, errors_1.usage)("Name the account: --to <account ID>, or --to team for an event's team default.");
|
|
88
|
+
if (!reason || reason.trim().length < 3)
|
|
89
|
+
throw (0, errors_1.usage)('Give a reason: --reason "Why it moves".');
|
|
90
|
+
let asked;
|
|
91
|
+
try {
|
|
92
|
+
asked = await read.client.post(`/events/${encodeURIComponent(name)}/payment-account/switch`, { to, reason }, undefined, { notFoundAsIs: true });
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (!(error instanceof errors_1.CliError) || error.exitCode !== errors_1.EXIT.notFound)
|
|
96
|
+
throw error;
|
|
97
|
+
asked = await read.client.post(`/payment-account/${encodeURIComponent(name)}/switch`, { to, reason });
|
|
98
|
+
}
|
|
99
|
+
read.io.err(`Asked to move the card payments of ${asked.summary.target.name} from ${account(asked.summary.from)} to ${account(asked.summary.to)}.`);
|
|
100
|
+
const now = await (0, requests_1.confirmOnBlocklive)(read, asked);
|
|
101
|
+
if (!now)
|
|
102
|
+
return errors_1.EXIT.ok;
|
|
103
|
+
if (read.json)
|
|
104
|
+
read.io.out(JSON.stringify(now));
|
|
105
|
+
else
|
|
106
|
+
read.io.out(`Done: ${asked.summary.target.name} takes payments to ${account(asked.summary.to)}.`);
|
|
107
|
+
return errors_1.EXIT.ok;
|
|
108
|
+
}
|
|
109
|
+
exports.switchPaymentAccount = switchPaymentAccount;
|
|
110
|
+
// `blocklive payment-account choices <event>` and `payment-account choose
|
|
111
|
+
// <event> --to <team|id>`: choosing where an unpublished event's card
|
|
112
|
+
// payments are paid out (migration *_cli_payout_request.sql). The CLI only
|
|
113
|
+
// asks: the request is confirmed on blocklive.io by the same person, with a
|
|
114
|
+
// new two-step code, and only then does the account change. The CLI takes
|
|
115
|
+
// no code. Accounts are named by their row's ID as `choices` prints it and
|
|
116
|
+
// shown masked: type, last four characters, whose.
|
|
117
|
+
/** An account as the confirm page and the email show it. */
|
|
118
|
+
function masked(a) {
|
|
119
|
+
if (!a)
|
|
120
|
+
return "the team's account (no account of its own)";
|
|
121
|
+
const type = a.provider === 'stripe'
|
|
122
|
+
? 'Stripe'
|
|
123
|
+
: a.provider === 'paypal'
|
|
124
|
+
? 'PayPal'
|
|
125
|
+
: 'Card account';
|
|
126
|
+
const whose = a.whose === 'blocklive' ? 'Blocklive' : a.owner ?? 'the organiser';
|
|
127
|
+
return `${type} …${(a.endsWith ?? '').slice(-4)}, ${whose}`;
|
|
128
|
+
}
|
|
129
|
+
async function listPaymentAccountChoices(read, rest) {
|
|
130
|
+
const name = (0, read_1.named)(rest, 'choices', 'event');
|
|
131
|
+
const answer = await read.client.get(`/events/${encodeURIComponent(name)}/payment-account/choices`);
|
|
132
|
+
if (read.json) {
|
|
133
|
+
read.io.out(JSON.stringify(answer));
|
|
134
|
+
return errors_1.EXIT.ok;
|
|
135
|
+
}
|
|
136
|
+
const out = read.io.out;
|
|
137
|
+
out(`${answer.event.title}: paid to ${masked(answer.account)} now.`);
|
|
138
|
+
if (answer.event.published)
|
|
139
|
+
out('It is published: its payout account is changed on blocklive.io, not from the CLI.');
|
|
140
|
+
else if (!answer.open)
|
|
141
|
+
out("Choosing a payout account from the CLI isn't open for this team yet.");
|
|
142
|
+
if (!answer.choices.length)
|
|
143
|
+
out("No other account you can ask for from here. One of Blocklive's accounts is chosen by the organization's owner or an admin: they can do it on blocklive.io.");
|
|
144
|
+
else {
|
|
145
|
+
out('It could be paid to:');
|
|
146
|
+
for (const line of (0, read_1.table)([
|
|
147
|
+
[' --TO', 'ACCOUNT'],
|
|
148
|
+
...answer.choices.map((c) => [` ${c.to}`, masked(c.account)]),
|
|
149
|
+
]))
|
|
150
|
+
out(line);
|
|
151
|
+
out(`Ask with: blocklive payment-account choose ${name} --to <team or an ID above>`);
|
|
152
|
+
}
|
|
153
|
+
return errors_1.EXIT.ok;
|
|
154
|
+
}
|
|
155
|
+
exports.listPaymentAccountChoices = listPaymentAccountChoices;
|
|
156
|
+
async function choosePaymentAccount(read, rest) {
|
|
157
|
+
const name = (0, read_1.named)(rest, 'choose', 'event');
|
|
158
|
+
const to = read.values.to;
|
|
159
|
+
if (!to ||
|
|
160
|
+
!(to === 'team' ||
|
|
161
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(to)))
|
|
162
|
+
throw (0, errors_1.usage)("Name the account: --to team for the team's own account, or --to <ID> as `blocklive payment-account choices` shows it.");
|
|
163
|
+
const asked = await read.client.post(`/events/${encodeURIComponent(name)}/payment-account/choose`, { to });
|
|
164
|
+
const title = asked.event?.title ?? name;
|
|
165
|
+
read.io.err(`Asked to change where ${title} is paid: from ${masked(asked.summary.from)} to ${masked(asked.summary.to)}. Nothing has changed yet.`);
|
|
166
|
+
const now = await (0, requests_1.confirmOnBlocklive)(read, asked, {
|
|
167
|
+
confirm: 'Confirm it on Blocklive, with a new code from your authenticator (the CLI takes no code)',
|
|
168
|
+
});
|
|
169
|
+
if (!now)
|
|
170
|
+
return errors_1.EXIT.ok;
|
|
171
|
+
if (read.json)
|
|
172
|
+
read.io.out(JSON.stringify(now));
|
|
173
|
+
else
|
|
174
|
+
read.io.out(`Done: ${title} is now paid to ${masked(asked.summary.to)}. The team's owners and admins have been told by email.`);
|
|
175
|
+
return errors_1.EXIT.ok;
|
|
176
|
+
}
|
|
177
|
+
exports.choosePaymentAccount = choosePaymentAccount;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchPlaces = exports.lookupsLeft = exports.searchText = void 0;
|
|
4
|
+
const errors_1 = require("../errors");
|
|
5
|
+
const read_1 = require("../read");
|
|
6
|
+
/** The text to search for: every word after `search`, as one line. */
|
|
7
|
+
function searchText(rest) {
|
|
8
|
+
const words = rest[0] === 'search' ? rest.slice(1) : rest;
|
|
9
|
+
const text = words.join(' ').trim();
|
|
10
|
+
if (Array.from(text).length < 3 ||
|
|
11
|
+
text.length > 120 ||
|
|
12
|
+
/[\u0000-\u001f\u007f]/.test(text))
|
|
13
|
+
throw (0, errors_1.usage)('Say what to search for, in 3 to 120 characters: blocklive places search "Royal Albert Hall, London".');
|
|
14
|
+
return text;
|
|
15
|
+
}
|
|
16
|
+
exports.searchText = searchText;
|
|
17
|
+
/** "You have 12 place lookups left today.", or nothing without a count. */
|
|
18
|
+
const lookupsLeft = (n) => typeof n === 'number' && Number.isInteger(n) && n >= 0
|
|
19
|
+
? n === 1
|
|
20
|
+
? 'You have 1 place lookup left today.'
|
|
21
|
+
: `You have ${n} place lookups left today.`
|
|
22
|
+
: undefined;
|
|
23
|
+
exports.lookupsLeft = lookupsLeft;
|
|
24
|
+
async function searchPlaces(read, rest) {
|
|
25
|
+
const query = searchText(rest);
|
|
26
|
+
const answer = await read.client.post('/places/search', { query });
|
|
27
|
+
if (read.json) {
|
|
28
|
+
read.io.out(JSON.stringify(answer));
|
|
29
|
+
return errors_1.EXIT.ok;
|
|
30
|
+
}
|
|
31
|
+
const out = read.io.out;
|
|
32
|
+
const places = Array.isArray(answer.places) ? answer.places : [];
|
|
33
|
+
if (!places.length)
|
|
34
|
+
out('Google Maps found no place for that. Try its name with its city.');
|
|
35
|
+
for (const [i, place] of places.entries()) {
|
|
36
|
+
if (i)
|
|
37
|
+
out('');
|
|
38
|
+
out(String(place.name));
|
|
39
|
+
for (const line of (0, read_1.table)([
|
|
40
|
+
[' Address', place.address ?? ''],
|
|
41
|
+
[' Place ID', place.id],
|
|
42
|
+
[' Map', place.mapsLink ?? ''],
|
|
43
|
+
].filter(([, value]) => value)))
|
|
44
|
+
out(line);
|
|
45
|
+
}
|
|
46
|
+
if (places.length) {
|
|
47
|
+
out('');
|
|
48
|
+
out("Set one as an event's place: blocklive events edit <event> --place <place ID>");
|
|
49
|
+
}
|
|
50
|
+
const remaining = (0, exports.lookupsLeft)(answer.lookupsLeft);
|
|
51
|
+
if (remaining)
|
|
52
|
+
out(remaining);
|
|
53
|
+
return errors_1.EXIT.ok;
|
|
54
|
+
}
|
|
55
|
+
exports.searchPlaces = searchPlaces;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.undoImport = exports.importPromos = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const read_1 = require("../read");
|
|
7
|
+
const requests_1 = require("./requests");
|
|
8
|
+
const SKIPPED = {
|
|
9
|
+
repeat: 'twice in the file',
|
|
10
|
+
exists: 'already on the event',
|
|
11
|
+
problem: 'problem',
|
|
12
|
+
};
|
|
13
|
+
// Asked on the terminal; with no terminal to ask on (a script, a pipe, or
|
|
14
|
+
// --json, where runCli takes the question away), only --yes goes ahead.
|
|
15
|
+
async function confirm(read, question) {
|
|
16
|
+
if (read.values.yes)
|
|
17
|
+
return true;
|
|
18
|
+
if (!read.io.ask)
|
|
19
|
+
throw (0, errors_1.usage)(`Nothing was changed. Add --yes to ${question
|
|
20
|
+
.toLowerCase()
|
|
21
|
+
.replace(/\?$/, '')} without asking.`);
|
|
22
|
+
const answer = (await read.io.ask(`${question} [y/N] `))
|
|
23
|
+
.trim()
|
|
24
|
+
.toLowerCase();
|
|
25
|
+
return answer === 'y' || answer === 'yes';
|
|
26
|
+
}
|
|
27
|
+
async function importPromos(read, rest) {
|
|
28
|
+
const event = (0, read_1.named)(rest, 'import', 'event');
|
|
29
|
+
const file = read.values.file;
|
|
30
|
+
if (!file)
|
|
31
|
+
throw (0, errors_1.usage)('Name the file: --file codes.csv (one code a line, or a CSV with a header row).');
|
|
32
|
+
let text;
|
|
33
|
+
try {
|
|
34
|
+
text = (0, fs_1.readFileSync)(file, 'utf8');
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
throw (0, errors_1.usage)(`Can't read ${file}.`);
|
|
38
|
+
}
|
|
39
|
+
if (read.values.unlimited && read.values.uses)
|
|
40
|
+
throw (0, errors_1.usage)('Use --uses or --unlimited, not both.');
|
|
41
|
+
const defaults = {
|
|
42
|
+
...(read.values.percent ? { percent: read.values.percent } : {}),
|
|
43
|
+
...(read.values.uses ? { uses: read.values.uses } : {}),
|
|
44
|
+
...(read.values.unlimited ? { unlimited: true } : {}),
|
|
45
|
+
...(read.values['per-guest']
|
|
46
|
+
? { perGuest: read.values['per-guest'] }
|
|
47
|
+
: {}),
|
|
48
|
+
tickets: (read.values.tickets ?? 'all')
|
|
49
|
+
.split(/[;|]/)
|
|
50
|
+
.map((name) => name.trim())
|
|
51
|
+
.filter(Boolean),
|
|
52
|
+
};
|
|
53
|
+
const path = `/events/${encodeURIComponent(event)}/promo-import`;
|
|
54
|
+
const plan = await read.client.post(path, {
|
|
55
|
+
step: 'plan',
|
|
56
|
+
text,
|
|
57
|
+
defaults,
|
|
58
|
+
});
|
|
59
|
+
const out = read.io.out;
|
|
60
|
+
if (!read.json) {
|
|
61
|
+
out(`${plan.event.title}: ${plan.counts.ready} code${plan.counts.ready === 1 ? '' : 's'} to import (${plan.records} ticket discount${plan.records === 1 ? '' : 's'})`);
|
|
62
|
+
const left = plan.counts.repeat + plan.counts.exists + plan.counts.problem;
|
|
63
|
+
if (left) {
|
|
64
|
+
out(`${left} line${left === 1 ? '' : 's'} left out:`);
|
|
65
|
+
for (const line of (0, read_1.table)([
|
|
66
|
+
['LINE', 'CODE', 'WHY'],
|
|
67
|
+
...plan.skipped.map((s) => [
|
|
68
|
+
String(s.line),
|
|
69
|
+
s.code,
|
|
70
|
+
s.reason ?? SKIPPED[s.status] ?? s.status,
|
|
71
|
+
]),
|
|
72
|
+
]))
|
|
73
|
+
out(` ${line}`);
|
|
74
|
+
}
|
|
75
|
+
if (plan.blocked)
|
|
76
|
+
out(`Can't import: ${plan.blocked}`);
|
|
77
|
+
}
|
|
78
|
+
if (plan.blocked || !plan.counts.ready || read.values['dry-run']) {
|
|
79
|
+
if (read.json)
|
|
80
|
+
out(JSON.stringify({ plan, imported: false }));
|
|
81
|
+
else if (read.values['dry-run'])
|
|
82
|
+
out('Dry run: nothing was imported.');
|
|
83
|
+
return plan.blocked || !plan.counts.ready ? errors_1.EXIT.refused : errors_1.EXIT.ok;
|
|
84
|
+
}
|
|
85
|
+
if (!(await confirm(read, `Ask to import ${plan.counts.ready} codes into ${plan.event.title}?`))) {
|
|
86
|
+
out('Nothing was imported.');
|
|
87
|
+
return errors_1.EXIT.ok;
|
|
88
|
+
}
|
|
89
|
+
// Only asks: confirmed on Blocklive, with two-step.
|
|
90
|
+
const asked = await read.client.post(path, {
|
|
91
|
+
step: 'request',
|
|
92
|
+
rows: plan.rows,
|
|
93
|
+
});
|
|
94
|
+
const now = await (0, requests_1.confirmOnBlocklive)(read, asked, {
|
|
95
|
+
confirm: 'Confirm the import on Blocklive, with two-step',
|
|
96
|
+
nothing: 'Nothing was imported.',
|
|
97
|
+
});
|
|
98
|
+
if (!now)
|
|
99
|
+
return errors_1.EXIT.ok;
|
|
100
|
+
if (read.json) {
|
|
101
|
+
out(JSON.stringify(now));
|
|
102
|
+
return errors_1.EXIT.ok;
|
|
103
|
+
}
|
|
104
|
+
out(`Imported ${now.result?.recordCount ?? 0} ticket discounts as drafts.`);
|
|
105
|
+
if (plan.path)
|
|
106
|
+
out(`Publish on Blocklive to put them live: ${read.base}${plan.path}`);
|
|
107
|
+
out(`Undo: blocklive promos undo ${event}`);
|
|
108
|
+
return errors_1.EXIT.ok;
|
|
109
|
+
}
|
|
110
|
+
exports.importPromos = importPromos;
|
|
111
|
+
async function undoImport(read, rest) {
|
|
112
|
+
const args = rest[0] === 'undo' ? rest.slice(1) : rest;
|
|
113
|
+
if (!args.length || args.length > 2)
|
|
114
|
+
throw (0, errors_1.usage)('Name the event, and the import: blocklive promos undo <event> <import>.');
|
|
115
|
+
const event = (0, read_1.named)([args[0]], 'undo', 'event');
|
|
116
|
+
const path = `/events/${encodeURIComponent(event)}/promo-import`;
|
|
117
|
+
const { event: shown, imports } = await read.client.get(path);
|
|
118
|
+
const yours = imports.filter((i) => i.mine);
|
|
119
|
+
if (args.length === 1) {
|
|
120
|
+
if (read.json) {
|
|
121
|
+
read.io.out(JSON.stringify({ event: shown, imports: yours }));
|
|
122
|
+
return errors_1.EXIT.ok;
|
|
123
|
+
}
|
|
124
|
+
if (!yours.length)
|
|
125
|
+
read.io.out(`You have no bulk imports at ${shown.title}.`);
|
|
126
|
+
else
|
|
127
|
+
for (const line of (0, read_1.table)([
|
|
128
|
+
['IMPORT', 'WHEN', 'CODES', 'STILL ON', ''],
|
|
129
|
+
...yours.map((i) => [
|
|
130
|
+
i.id,
|
|
131
|
+
(0, read_1.day)(i.at),
|
|
132
|
+
String(i.codes),
|
|
133
|
+
String(i.stillOn),
|
|
134
|
+
i.undoneAt
|
|
135
|
+
? `undone ${(0, read_1.day)(i.undoneAt)}`
|
|
136
|
+
: i.undoable
|
|
137
|
+
? ''
|
|
138
|
+
: "can't be undone here",
|
|
139
|
+
]),
|
|
140
|
+
]))
|
|
141
|
+
read.io.out(line);
|
|
142
|
+
return errors_1.EXIT.ok;
|
|
143
|
+
}
|
|
144
|
+
const target = yours.find((i) => i.id === args[1].toLowerCase());
|
|
145
|
+
if (!target)
|
|
146
|
+
throw new errors_1.CliError('No import of yours with that ID at this event.', errors_1.EXIT.notFound, 'not_found');
|
|
147
|
+
if (!target.undoable)
|
|
148
|
+
throw new errors_1.CliError(target.undoneAt
|
|
149
|
+
? `That import was undone on ${(0, read_1.day)(target.undoneAt)}.`
|
|
150
|
+
: "That import can't be undone here.", errors_1.EXIT.refused, 'refused');
|
|
151
|
+
// The plan: what will change, and a single-use token for it.
|
|
152
|
+
const plan = await read.client.post(`${path}/undo`, { step: 'plan', importId: target.id });
|
|
153
|
+
if (!read.json)
|
|
154
|
+
read.io.out(`Undo the import of ${(0, read_1.day)(plan.summary.at)} at ${shown.title}: ${plan.summary.stillOn} of its ${plan.summary.codes} codes are still on. Codes never published are deleted; published ones are switched off at the next publish.`);
|
|
155
|
+
// With --json and no --yes, or --dry-run: the plan, and nothing more.
|
|
156
|
+
// Its token isn't printed: it works once, for the undo that follows it
|
|
157
|
+
// here, and a later run makes its own plan.
|
|
158
|
+
if (read.values['dry-run'] || (read.json && !read.values.yes)) {
|
|
159
|
+
if (read.json)
|
|
160
|
+
read.io.out(JSON.stringify({
|
|
161
|
+
plan: {
|
|
162
|
+
event: shown,
|
|
163
|
+
import: target.id,
|
|
164
|
+
summary: plan.summary,
|
|
165
|
+
},
|
|
166
|
+
applied: false,
|
|
167
|
+
}));
|
|
168
|
+
else
|
|
169
|
+
read.io.out('Dry run: nothing was changed.');
|
|
170
|
+
return errors_1.EXIT.ok;
|
|
171
|
+
}
|
|
172
|
+
if (!(await confirm(read, 'Undo this import?'))) {
|
|
173
|
+
read.io.out('Nothing was changed.');
|
|
174
|
+
return errors_1.EXIT.ok;
|
|
175
|
+
}
|
|
176
|
+
const answer = await read.client.post(`${path}/undo`, { step: 'undo', token: plan.token });
|
|
177
|
+
if (read.json)
|
|
178
|
+
read.io.out(JSON.stringify(answer));
|
|
179
|
+
else
|
|
180
|
+
read.io.out(`Undone: ${answer.undone?.removed ?? 0} deleted, ${answer.undone?.turnedOff ?? 0} switched off.`);
|
|
181
|
+
return errors_1.EXIT.ok;
|
|
182
|
+
}
|
|
183
|
+
exports.undoImport = undoImport;
|