@ptkl/toolkit 0.14.0 → 1.1.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 +19 -2
- package/dist/commands/billing.js +111 -0
- package/dist/commands/config.js +33 -0
- package/dist/commands/forge.js +241 -13
- package/dist/commands/functions.js +87 -22
- package/dist/commands/index.js +21 -1
- package/dist/commands/integration.js +146 -0
- package/dist/commands/integrations/dms.js +625 -0
- package/dist/commands/integrations/mail.js +120 -0
- package/dist/commands/integrations/payments.js +199 -0
- package/dist/commands/integrations/serbia.js +610 -0
- package/dist/commands/integrations/timber.js +120 -0
- package/dist/commands/kortex.js +203 -12
- package/dist/commands/logs.js +4 -17
- package/dist/commands/project.js +147 -0
- package/dist/commands/ratchet.js +82 -0
- package/dist/commands/sandbox.js +122 -0
- package/dist/commands/satellite.js +111 -0
- package/dist/commands/template.js +96 -0
- package/dist/commands/thunder.js +123 -0
- package/dist/commands/users.js +31 -19
- package/dist/commands/workflow.js +225 -30
- package/dist/lib/forgeDevKernelPlugin.js +2 -1
- package/dist/lib/kortex/session.js +20 -16
- package/dist/lib/scaffold.js +51 -0
- package/dist/lib/sdk.js +88 -0
- package/package.json +1 -1
|
@@ -0,0 +1,610 @@
|
|
|
1
|
+
import { readFileSync } from "fs";
|
|
2
|
+
import { Command } from "commander";
|
|
3
|
+
import { VPFR, Invoicing, NBS } from "@ptkl/sdk/beta";
|
|
4
|
+
import * as sdk from "../../lib/sdk.js";
|
|
5
|
+
import { registerCommand, withProfile } from "../../lib/scaffold.js";
|
|
6
|
+
import { integrationSub, isActive } from "../integration.js";
|
|
7
|
+
/** `ptkl integration serbia` — typed interfaces onto the Serbia-market integrations (RFC §4.3 /
|
|
8
|
+
* §6.1, layer 2; RFC lines 128-131): VPFR fiscalization + SEF/eOtpremnica e-invoicing + VAT
|
|
9
|
+
* recording (`Invoicing`) + NBS/IPS-QR + MinFin receipt extraction + Minimax accounting.
|
|
10
|
+
*
|
|
11
|
+
* Five subgroups, each pre-checking `isActive()` for its own integration id before calling
|
|
12
|
+
* through (see ../integration.ts `isActive`):
|
|
13
|
+
* - `vpfr` -> `serbia-minfin` (VPFR is nested under MinFin, mirroring `MinFin.vpfr()`)
|
|
14
|
+
* - `sef` -> `serbia-minfin` (SEF sales/purchase e-invoices, via `Invoicing`)
|
|
15
|
+
* - `eotpremnica` -> `serbia-minfin` (e-dispatch advices/receipts, via `Invoicing`)
|
|
16
|
+
* - `vat` -> `serbia-minfin` (VAT recording, via `Invoicing`)
|
|
17
|
+
* - `nbs` -> `nbs` (search + IPS QR generate/validate)
|
|
18
|
+
* - `minfin` -> `serbia-minfin` (receipt extraction + conto list)
|
|
19
|
+
* - `minimax` -> `protokol-minimax` (representative accounting surface + generic passthrough)
|
|
20
|
+
*
|
|
21
|
+
* `VPFR` and `Invoicing` only expose a generic `request(method, endpoint, params)` (plus a
|
|
22
|
+
* couple of typed helpers on `Invoicing`) — the `vpfr`/`sef`/`eotpremnica`/`vat` subcommands
|
|
23
|
+
* below wrap that generic door with the real karadjordje route shapes so the CLI surface stays
|
|
24
|
+
* typed even where the SDK client isn't. `minimax` is the one place a raw `request <method>
|
|
25
|
+
* <endpoint>` passthrough is used directly (RFC review note: ~80 methods, expose a
|
|
26
|
+
* representative set, not all of them).
|
|
27
|
+
*
|
|
28
|
+
* WP-F007 (audit-phase4-1): `eotpremnica`, `vat` and `minimax` are built in full below but then
|
|
29
|
+
* gated — integrations-api proxies only `invoices|ipsQr|deliveries|payment|services|vpfr` to
|
|
30
|
+
* karadjordje, so `/v1/eotpremnica` and `/v1/vat-recording` never reach a backend, and no
|
|
31
|
+
* minimax route exists in integrations-api or karadjordje at all. `vpfr registers update|delete`
|
|
32
|
+
* are gated too: the `vpfr` proxy only registers `["POST","GET"]` (invoices.go), so PATCH/DELETE
|
|
33
|
+
* can never pass the gateway even though they're the structurally-correct verbs. Gating (not
|
|
34
|
+
* deleting) keeps the CLI surface + real route shapes documented for whenever those backends
|
|
35
|
+
* land, while `notYetReachable`/`gateGroup` below make sure invoking them never issues a request
|
|
36
|
+
* and always fails loudly instead of surfacing a confusing 404/502 from the gateway.
|
|
37
|
+
*/
|
|
38
|
+
const MINFIN_ID = "serbia-minfin";
|
|
39
|
+
// WP-F006: was "protokol-invoicing" (no such integration id exists — always failed the
|
|
40
|
+
// precheck first with a misleading activate hint). integrations-api gates `invoices/*` on
|
|
41
|
+
// `serbia-minfin` (invoices.go:119, v1.go:111) — same id as MINFIN_ID/VPFR, since SEF/eOtpremnica/
|
|
42
|
+
// VAT are all facets of the one MinFin integration. NOTE: the karadjordje-invoicing *gateway*
|
|
43
|
+
// route (gateway.go:51, `{version}/invoices/{path}`) itself checks the id "serbian-minfin", which
|
|
44
|
+
// is a separate, server-side typo bug (no such integration can ever be active) — out of this WP's
|
|
45
|
+
// sanctioned paths (serbia.ts only); the client-side precheck below intentionally uses the real
|
|
46
|
+
// catalog id so it doesn't reproduce that same phantom-id defect on the toolkit side.
|
|
47
|
+
const INVOICING_ID = "serbia-minfin";
|
|
48
|
+
// services/nbs/* and ipsQr/* are both gated server-side on "nbs" (gateway.go:69,121); only
|
|
49
|
+
// services/receipt/* (MinFin receipt extraction, see registerMinfin below) is gated on
|
|
50
|
+
// "serbia-minfin" (gateway.go:137). NBS_ID below is already correct for nbs search + ips-qr.
|
|
51
|
+
const NBS_ID = "nbs";
|
|
52
|
+
const MINIMAX_ID = "protokol-minimax";
|
|
53
|
+
function parseJSON(label, raw) {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(raw);
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
console.error(`${label} must be valid JSON`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function unwrap(res) {
|
|
63
|
+
return res?.data ?? res;
|
|
64
|
+
}
|
|
65
|
+
// -- WP-F007 gating (audit-phase4-1) -------------------------------------------------------
|
|
66
|
+
// `notYetReachable`/`gateGroup` replace the action of a command (or every action in its subtree)
|
|
67
|
+
// with a message-and-exit, so invoking any command under a gated group fails fast — before any
|
|
68
|
+
// SDK client is constructed or request issued — instead of round-tripping to a gateway route that
|
|
69
|
+
// doesn't exist.
|
|
70
|
+
function notYetReachable(group) {
|
|
71
|
+
return () => {
|
|
72
|
+
console.error(`${group} is not yet reachable via the platform gateway (integrations-api does not proxy this surface) — tracked in audit-phase4-1`);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Overrides every action in `cmd`'s subtree (itself and all descendants) with the
|
|
77
|
+
* `notYetReachable` gate for `group`, and appends `[unavailable]` to `cmd`'s own description so
|
|
78
|
+
* it's flagged in `--help`. Used for whole subgroups (`eotpremnica`, `vat`, `minimax`) that have
|
|
79
|
+
* no reachable backend at all — the real subtree is still built (so the route shapes stay
|
|
80
|
+
* documented for when a backend lands) but no leaf can ever issue a request. */
|
|
81
|
+
function gateGroup(cmd, group) {
|
|
82
|
+
const gate = notYetReachable(group);
|
|
83
|
+
const walk = (c) => {
|
|
84
|
+
c.action(gate);
|
|
85
|
+
for (const sub of c.commands)
|
|
86
|
+
walk(sub);
|
|
87
|
+
};
|
|
88
|
+
walk(cmd);
|
|
89
|
+
cmd.description(`${cmd.description()} [unavailable]`);
|
|
90
|
+
return cmd;
|
|
91
|
+
}
|
|
92
|
+
// -- Client factories ----------------------------------------------------------------------
|
|
93
|
+
// sdk.ts (src/lib/sdk.ts) already exposes a `serbia()` accessor for SerbiaMinFin; it isn't
|
|
94
|
+
// sanctioned for this WP to extend that file with VPFR/Invoicing/NBS/Minimax accessors, so those
|
|
95
|
+
// clients are built here directly from the same options builders sdk.ts uses.
|
|
96
|
+
function vpfrClient(profile) {
|
|
97
|
+
return new VPFR(sdk.integrationsOptions(profile));
|
|
98
|
+
}
|
|
99
|
+
// WP-F006: was built from `sdk.platformOptions` — `/karadjordje/v1/...` is only reachable via the
|
|
100
|
+
// integrations gateway (`host/luma/integrations/karadjordje/v1/...`, integrations-api module
|
|
101
|
+
// `karadjordje`, GatewayControllerV1 `{version}/invoices/{path}`), exactly like `payments`.
|
|
102
|
+
function invoicingClient(profile) {
|
|
103
|
+
return new Invoicing(sdk.integrationsOptions(profile));
|
|
104
|
+
}
|
|
105
|
+
function nbsClient(profile) {
|
|
106
|
+
return new NBS(sdk.integrationsOptions(profile));
|
|
107
|
+
}
|
|
108
|
+
// `Minimax` (the client class) isn't re-exported from `@ptkl/sdk/beta`'s v0.10 index (only its
|
|
109
|
+
// types are) even though `Integrations.getMinimax()` returns one internally — going through the
|
|
110
|
+
// `Integrations` façade sidesteps that gap without needing an SDK-side change (out of this WP's
|
|
111
|
+
// sanctioned paths). Structural typing still gives every call site full type-checking.
|
|
112
|
+
function minimaxClient(profile) {
|
|
113
|
+
return sdk.integrations(profile).getMinimax();
|
|
114
|
+
}
|
|
115
|
+
class SerbiaCommand {
|
|
116
|
+
register() {
|
|
117
|
+
const cmd = new Command("serbia").description("Serbia-market integrations: VPFR fiscalization, SEF/eOtpremnica e-invoicing, VAT recording, NBS/IPS-QR, MinFin, Minimax accounting");
|
|
118
|
+
cmd.addCommand(this.registerVpfr());
|
|
119
|
+
cmd.addCommand(this.registerSef());
|
|
120
|
+
// WP-F007 (audit-phase4-1): eotpremnica/vat/minimax have no reachable backend — gated,
|
|
121
|
+
// not deleted, so the route shapes stay documented. See the module comment above.
|
|
122
|
+
cmd.addCommand(gateGroup(this.registerEotpremnica(), "eotpremnica"));
|
|
123
|
+
cmd.addCommand(gateGroup(this.registerVat(), "vat"));
|
|
124
|
+
cmd.addCommand(this.registerNbs());
|
|
125
|
+
cmd.addCommand(this.registerMinfin());
|
|
126
|
+
cmd.addCommand(gateGroup(this.registerMinimax(), "minimax"));
|
|
127
|
+
return integrationSub(cmd);
|
|
128
|
+
}
|
|
129
|
+
// -- vpfr (registers/fiscal-invoice/receipt/report/tax-rates/sync-offline, via VPFR) -----
|
|
130
|
+
registerVpfr() {
|
|
131
|
+
const cmd = new Command("vpfr").description("VPFR fiscalization: cash register CRUD, fiscal receipts, reports, tax rates, offline sync");
|
|
132
|
+
cmd.addCommand(this.registerVpfrRegisters());
|
|
133
|
+
cmd.addCommand(this.registerVpfrFiscalInvoice());
|
|
134
|
+
cmd.addCommand(this.registerVpfrReceipt());
|
|
135
|
+
cmd.addCommand(registerCommand(new Command("report")
|
|
136
|
+
.description("Get the presek stanja (Z-report) for a date range")
|
|
137
|
+
.requiredOption("--from <isoDate>", "Range start, ISO date")
|
|
138
|
+
.requiredOption("--to <isoDate>", "Range end, ISO date")).action(withProfile(async (profile, opts) => {
|
|
139
|
+
await isActive(profile, MINFIN_ID);
|
|
140
|
+
const res = await vpfrClient(profile).request("GET", "report", {
|
|
141
|
+
params: { from: opts.from, to: opts.to },
|
|
142
|
+
});
|
|
143
|
+
return unwrap(res);
|
|
144
|
+
})));
|
|
145
|
+
cmd.addCommand(registerCommand(new Command("tax-rates").description("List the fiscal tax rates/labels")).action(withProfile(async (profile) => {
|
|
146
|
+
await isActive(profile, MINFIN_ID);
|
|
147
|
+
return unwrap(await vpfrClient(profile).request("GET", "tax-rates"));
|
|
148
|
+
})));
|
|
149
|
+
cmd.addCommand(registerCommand(new Command("status").description("Get VPFR connectivity status")).action(withProfile(async (profile) => {
|
|
150
|
+
await isActive(profile, MINFIN_ID);
|
|
151
|
+
return unwrap(await vpfrClient(profile).request("GET", "status"));
|
|
152
|
+
})));
|
|
153
|
+
cmd.addCommand(registerCommand(new Command("sync-offline").description("Manually trigger a sync of offline-queued fiscal receipts")).action(withProfile(async (profile) => {
|
|
154
|
+
await isActive(profile, MINFIN_ID);
|
|
155
|
+
return unwrap(await vpfrClient(profile).request("POST", "sync-offline"));
|
|
156
|
+
})));
|
|
157
|
+
return cmd;
|
|
158
|
+
}
|
|
159
|
+
registerVpfrRegisters() {
|
|
160
|
+
const cmd = new Command("registers").description("Cash register (ESIR) CRUD");
|
|
161
|
+
cmd.addCommand(registerCommand(new Command("list").description("List cash registers")).action(withProfile(async (profile) => {
|
|
162
|
+
await isActive(profile, MINFIN_ID);
|
|
163
|
+
return unwrap(await vpfrClient(profile).request("GET", "registers"));
|
|
164
|
+
})));
|
|
165
|
+
cmd.addCommand(registerCommand(new Command("add")
|
|
166
|
+
.description("Add a cash register")
|
|
167
|
+
.requiredOption("-n, --name <name>", "Register name")
|
|
168
|
+
.requiredOption("-a, --address <address>", "Register address")
|
|
169
|
+
.requiredOption("--jid <jid>", "Tax id (JID)")
|
|
170
|
+
.requiredOption("--pak <pak>", "PAK code")
|
|
171
|
+
.option("--crt <path>", "Path to the register's client certificate file")
|
|
172
|
+
.option("--key <path>", "Path to the register's private key file")).action(withProfile(async (profile, opts) => {
|
|
173
|
+
await isActive(profile, MINFIN_ID);
|
|
174
|
+
const form = buildRegisterFormData(opts);
|
|
175
|
+
const res = await vpfrClient(profile).request("POST", "registers", { data: form });
|
|
176
|
+
return unwrap(res);
|
|
177
|
+
})));
|
|
178
|
+
// WP-F007 (audit-phase4-1): the `vpfr` gateway proxy only registers `["POST","GET"]`
|
|
179
|
+
// (invoices.go) — PATCH/DELETE can never pass it even though they're the
|
|
180
|
+
// structurally-correct verbs for update/delete, so these two are gated individually
|
|
181
|
+
// rather than the whole `registers` group (list/add above are real POST/GET and stay live).
|
|
182
|
+
cmd.addCommand(registerCommand(new Command("update")
|
|
183
|
+
.description("Update a cash register [unavailable]")
|
|
184
|
+
.argument("<registerId>", "Register id")
|
|
185
|
+
.option("-n, --name <name>", "Register name")
|
|
186
|
+
.option("-a, --address <address>", "Register address")
|
|
187
|
+
.option("--jid <jid>", "Tax id (JID)")
|
|
188
|
+
.option("--pak <pak>", "PAK code")
|
|
189
|
+
.option("--crt <path>", "Path to the register's client certificate file")
|
|
190
|
+
.option("--key <path>", "Path to the register's private key file")).action(notYetReachable("vpfr registers update")));
|
|
191
|
+
cmd.addCommand(registerCommand(new Command("delete")
|
|
192
|
+
.description("Delete a cash register [unavailable]")
|
|
193
|
+
.argument("<registerId>", "Register id")).action(notYetReachable("vpfr registers delete")));
|
|
194
|
+
return cmd;
|
|
195
|
+
}
|
|
196
|
+
registerVpfrFiscalInvoice() {
|
|
197
|
+
const cmd = new Command("fiscal-invoice").description("Fiscal receipt creation and polling");
|
|
198
|
+
cmd.addCommand(registerCommand(new Command("create")
|
|
199
|
+
.description("Create a fiscal receipt (register_id, invoice_type, transaction_type, cashier_name, payment[], items[], ...)")
|
|
200
|
+
.requiredOption("-d, --data <json>", "Fiscal receipt body as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
201
|
+
await isActive(profile, MINFIN_ID);
|
|
202
|
+
const data = parseJSON("--data", opts.data);
|
|
203
|
+
return unwrap(await vpfrClient(profile).request("POST", "fiscal-invoice", { data }));
|
|
204
|
+
})));
|
|
205
|
+
cmd.addCommand(registerCommand(new Command("get")
|
|
206
|
+
.description("Poll a fiscal receipt by request id")
|
|
207
|
+
.argument("<requestId>", "Fiscal invoice request id")).action(withProfile(async (profile, requestId) => {
|
|
208
|
+
await isActive(profile, MINFIN_ID);
|
|
209
|
+
return unwrap(await vpfrClient(profile).request("GET", `fiscal-invoice/${requestId}`));
|
|
210
|
+
})));
|
|
211
|
+
return cmd;
|
|
212
|
+
}
|
|
213
|
+
registerVpfrReceipt() {
|
|
214
|
+
const cmd = new Command("receipt").description("Fiscal receipt creation (backward-compat alias of fiscal-invoice)");
|
|
215
|
+
cmd.addCommand(registerCommand(new Command("create")
|
|
216
|
+
.description("Create a fiscal receipt (alias of `vpfr fiscal-invoice create`)")
|
|
217
|
+
.requiredOption("-d, --data <json>", "Fiscal receipt body as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
218
|
+
await isActive(profile, MINFIN_ID);
|
|
219
|
+
const data = parseJSON("--data", opts.data);
|
|
220
|
+
return unwrap(await vpfrClient(profile).request("POST", "receipt", { data }));
|
|
221
|
+
})));
|
|
222
|
+
return cmd;
|
|
223
|
+
}
|
|
224
|
+
// -- sef (sales/purchase e-invoices, accept/storno, via Invoicing) -----------------------
|
|
225
|
+
registerSef() {
|
|
226
|
+
const cmd = new Command("sef").description("SEF (Sistem Elektronskih Faktura): sales/purchase e-invoices, accept/reject, storno");
|
|
227
|
+
const sales = new Command("sales").description("Sales e-invoices");
|
|
228
|
+
sales.addCommand(registerCommand(new Command("list")
|
|
229
|
+
.description("List sales invoices for a user")
|
|
230
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
231
|
+
.option("--page <n>", "Page number", (v) => parseInt(v, 10))).action(withProfile(async (profile, opts) => {
|
|
232
|
+
await isActive(profile, INVOICING_ID);
|
|
233
|
+
// SDK `getSalesInvoices(provider, page)` param is misnamed: it maps straight onto
|
|
234
|
+
// `GET invoices/:userId/sales` — the segment is the external user id, not a provider.
|
|
235
|
+
return unwrap(await invoicingClient(profile).getSalesInvoices(opts.user, opts.page ?? 1));
|
|
236
|
+
})));
|
|
237
|
+
sales.addCommand(registerCommand(new Command("get")
|
|
238
|
+
.description("Get a single sales invoice")
|
|
239
|
+
.requiredOption("-p, --provider <provider>", "Invoicing provider id")
|
|
240
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
241
|
+
.requiredOption("-i, --id <id>", "Invoice id")).action(withProfile(async (profile, opts) => {
|
|
242
|
+
await isActive(profile, INVOICING_ID);
|
|
243
|
+
const res = await invoicingClient(profile).request("GET", `invoices/${opts.provider}/sales/${opts.user}/${opts.id}`, {});
|
|
244
|
+
return unwrap(res);
|
|
245
|
+
})));
|
|
246
|
+
sales.addCommand(registerCommand(new Command("create")
|
|
247
|
+
.description("Create a sales e-invoice")
|
|
248
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
249
|
+
.requiredOption("-d, --data <json>", "Sales invoice body as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
250
|
+
await isActive(profile, INVOICING_ID);
|
|
251
|
+
const data = parseJSON("--data", opts.data);
|
|
252
|
+
const res = await invoicingClient(profile).request("POST", `invoices/${opts.user}/sales`, { data });
|
|
253
|
+
return unwrap(res);
|
|
254
|
+
})));
|
|
255
|
+
sales.addCommand(registerCommand(new Command("storno")
|
|
256
|
+
.description("Storno (cancel) a sales e-invoice")
|
|
257
|
+
.requiredOption("-p, --provider <provider>", "Invoicing provider id")
|
|
258
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
259
|
+
.requiredOption("-i, --id <id>", "Invoice id")).action(withProfile(async (profile, opts) => {
|
|
260
|
+
await isActive(profile, INVOICING_ID);
|
|
261
|
+
const res = await invoicingClient(profile).request("POST", `invoices/${opts.provider}/sales/${opts.user}/${opts.id}/stop`, {});
|
|
262
|
+
return unwrap(res);
|
|
263
|
+
})));
|
|
264
|
+
cmd.addCommand(sales);
|
|
265
|
+
const purchase = new Command("purchase").description("Purchase e-invoices");
|
|
266
|
+
purchase.addCommand(registerCommand(new Command("list")
|
|
267
|
+
.description("List purchase invoices")
|
|
268
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
269
|
+
.option("-p, --params <json>", "Optional query params as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
270
|
+
await isActive(profile, INVOICING_ID);
|
|
271
|
+
const params = opts.params ? parseJSON("--params", opts.params) : undefined;
|
|
272
|
+
const res = await invoicingClient(profile).request("GET", `invoices/${opts.user}/purchase`, {
|
|
273
|
+
...(params ? { params } : {}),
|
|
274
|
+
});
|
|
275
|
+
return unwrap(res);
|
|
276
|
+
})));
|
|
277
|
+
purchase.addCommand(registerCommand(new Command("get")
|
|
278
|
+
.description("Get a single purchase invoice")
|
|
279
|
+
.requiredOption("-p, --provider <provider>", "Invoicing provider id")
|
|
280
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
281
|
+
.requiredOption("-i, --id <id>", "Invoice id")).action(withProfile(async (profile, opts) => {
|
|
282
|
+
await isActive(profile, INVOICING_ID);
|
|
283
|
+
const res = await invoicingClient(profile).request("GET", `invoices/${opts.provider}/purchase/${opts.user}/${opts.id}`, {});
|
|
284
|
+
return unwrap(res);
|
|
285
|
+
})));
|
|
286
|
+
purchase.addCommand(registerCommand(new Command("accept")
|
|
287
|
+
.description("Accept a purchase e-invoice")
|
|
288
|
+
.requiredOption("-p, --provider <provider>", "Invoicing provider id")
|
|
289
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
290
|
+
.requiredOption("-i, --id <id>", "Invoice id")
|
|
291
|
+
.option("-c, --comment <comment>", "Optional comment")).action(withProfile(async (profile, opts) => {
|
|
292
|
+
await isActive(profile, INVOICING_ID);
|
|
293
|
+
// SDK `acceptPurchaseInvoice(provider, id)` hits `acceptReject/{id}` (2 segments);
|
|
294
|
+
// the server route is `POST /:provider/purchase/acceptReject/:userId/:id` (3
|
|
295
|
+
// segments) and never matches — hand-roll it via the generic door instead, mirroring
|
|
296
|
+
// the sibling `reject` below.
|
|
297
|
+
const res = await invoicingClient(profile).request("POST", `invoices/${opts.provider}/purchase/acceptReject/${opts.user}/${opts.id}`, { data: { accepted: true, comment: opts.comment ?? "" } });
|
|
298
|
+
return unwrap(res);
|
|
299
|
+
})));
|
|
300
|
+
purchase.addCommand(registerCommand(new Command("reject")
|
|
301
|
+
.description("Reject a purchase e-invoice")
|
|
302
|
+
.requiredOption("-p, --provider <provider>", "Invoicing provider id")
|
|
303
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
304
|
+
.requiredOption("-i, --id <id>", "Invoice id")
|
|
305
|
+
.option("-c, --comment <comment>", "Optional comment")).action(withProfile(async (profile, opts) => {
|
|
306
|
+
await isActive(profile, INVOICING_ID);
|
|
307
|
+
const res = await invoicingClient(profile).request("POST", `invoices/${opts.provider}/purchase/acceptReject/${opts.user}/${opts.id}`, { data: { accepted: false, comment: opts.comment ?? "" } });
|
|
308
|
+
return unwrap(res);
|
|
309
|
+
})));
|
|
310
|
+
cmd.addCommand(purchase);
|
|
311
|
+
cmd.addCommand(this.registerInvoicingPassthrough("sef", "invoices/"));
|
|
312
|
+
return cmd;
|
|
313
|
+
}
|
|
314
|
+
// -- eotpremnica (e-dispatch advices/receipts, via Invoicing) ----------------------------
|
|
315
|
+
registerEotpremnica() {
|
|
316
|
+
const cmd = new Command("eotpremnica").description("eOtpremnica: e-dispatch advices and receipt advices");
|
|
317
|
+
const despatch = new Command("despatch-advices").description("Despatch advice CRUD and lifecycle actions");
|
|
318
|
+
despatch.addCommand(registerCommand(new Command("list").description("List despatch advices").requiredOption("--target-env <env>", "Target-system environment: dev | prod")).action(withProfile(async (profile, opts) => {
|
|
319
|
+
await isActive(profile, INVOICING_ID);
|
|
320
|
+
const res = await invoicingClient(profile).request("GET", `eotpremnica/${opts.targetEnv}/despatch-advices`, {});
|
|
321
|
+
return unwrap(res);
|
|
322
|
+
})));
|
|
323
|
+
despatch.addCommand(registerCommand(new Command("get")
|
|
324
|
+
.description("Get a despatch advice")
|
|
325
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
326
|
+
.argument("<id>", "Despatch advice id")).action(withProfile(async (profile, id, opts) => {
|
|
327
|
+
await isActive(profile, INVOICING_ID);
|
|
328
|
+
const res = await invoicingClient(profile).request("GET", `eotpremnica/${opts.targetEnv}/despatch-advices/${id}`, {});
|
|
329
|
+
return unwrap(res);
|
|
330
|
+
})));
|
|
331
|
+
despatch.addCommand(registerCommand(new Command("create")
|
|
332
|
+
.description("Create a despatch advice")
|
|
333
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
334
|
+
.requiredOption("-d, --data <json>", "Despatch advice body as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
335
|
+
await isActive(profile, INVOICING_ID);
|
|
336
|
+
const data = parseJSON("--data", opts.data);
|
|
337
|
+
const res = await invoicingClient(profile).request("POST", `eotpremnica/${opts.targetEnv}/despatch-advices`, { data });
|
|
338
|
+
return unwrap(res);
|
|
339
|
+
})));
|
|
340
|
+
despatch.addCommand(registerCommand(new Command("cancel")
|
|
341
|
+
.description("Cancel a despatch advice")
|
|
342
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
343
|
+
.argument("<id>", "Despatch advice id")
|
|
344
|
+
.option("-r, --reason <reason>", "Cancellation reason")).action(withProfile(async (profile, id, opts) => {
|
|
345
|
+
await isActive(profile, INVOICING_ID);
|
|
346
|
+
const res = await invoicingClient(profile).request("POST", `eotpremnica/${opts.targetEnv}/despatch-advices/${id}/cancel`, { data: opts.reason ? { reason: opts.reason } : {} });
|
|
347
|
+
return unwrap(res);
|
|
348
|
+
})));
|
|
349
|
+
despatch.addCommand(registerCommand(new Command("confirm-delivery")
|
|
350
|
+
.description("Confirm delivery of a despatch advice")
|
|
351
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
352
|
+
.argument("<id>", "Despatch advice id")).action(withProfile(async (profile, id, opts) => {
|
|
353
|
+
await isActive(profile, INVOICING_ID);
|
|
354
|
+
const res = await invoicingClient(profile).request("POST", `eotpremnica/${opts.targetEnv}/despatch-advices/${id}/confirm-delivery`, {});
|
|
355
|
+
return unwrap(res);
|
|
356
|
+
})));
|
|
357
|
+
cmd.addCommand(despatch);
|
|
358
|
+
const receipts = new Command("receipts").description("Receipt advice list/get/accept/reject");
|
|
359
|
+
receipts.addCommand(registerCommand(new Command("list").description("List receipt advices").requiredOption("--target-env <env>", "Target-system environment: dev | prod")).action(withProfile(async (profile, opts) => {
|
|
360
|
+
await isActive(profile, INVOICING_ID);
|
|
361
|
+
const res = await invoicingClient(profile).request("GET", `eotpremnica/${opts.targetEnv}/receipts`, {});
|
|
362
|
+
return unwrap(res);
|
|
363
|
+
})));
|
|
364
|
+
receipts.addCommand(registerCommand(new Command("get")
|
|
365
|
+
.description("Get a receipt advice")
|
|
366
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
367
|
+
.argument("<id>", "Receipt advice id")).action(withProfile(async (profile, id, opts) => {
|
|
368
|
+
await isActive(profile, INVOICING_ID);
|
|
369
|
+
const res = await invoicingClient(profile).request("GET", `eotpremnica/${opts.targetEnv}/receipts/${id}`, {});
|
|
370
|
+
return unwrap(res);
|
|
371
|
+
})));
|
|
372
|
+
receipts.addCommand(registerCommand(new Command("accept")
|
|
373
|
+
.description("Accept a receipt advice")
|
|
374
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
375
|
+
.argument("<id>", "Receipt advice id")).action(withProfile(async (profile, id, opts) => {
|
|
376
|
+
await isActive(profile, INVOICING_ID);
|
|
377
|
+
const res = await invoicingClient(profile).request("PATCH", `eotpremnica/${opts.targetEnv}/receipts/${id}/accept`, {});
|
|
378
|
+
return unwrap(res);
|
|
379
|
+
})));
|
|
380
|
+
receipts.addCommand(registerCommand(new Command("reject")
|
|
381
|
+
.description("Reject a receipt advice")
|
|
382
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
383
|
+
.argument("<id>", "Receipt advice id")
|
|
384
|
+
.option("-r, --reason <reason>", "Rejection reason")).action(withProfile(async (profile, id, opts) => {
|
|
385
|
+
await isActive(profile, INVOICING_ID);
|
|
386
|
+
const res = await invoicingClient(profile).request("PATCH", `eotpremnica/${opts.targetEnv}/receipts/${id}/reject`, { data: opts.reason ? { reason: opts.reason } : {} });
|
|
387
|
+
return unwrap(res);
|
|
388
|
+
})));
|
|
389
|
+
cmd.addCommand(receipts);
|
|
390
|
+
const settings = new Command("settings").description("eOtpremnica environment settings");
|
|
391
|
+
settings.addCommand(registerCommand(new Command("get").description("Get eOtpremnica settings").requiredOption("--target-env <env>", "Target-system environment: dev | prod")).action(withProfile(async (profile, opts) => {
|
|
392
|
+
await isActive(profile, INVOICING_ID);
|
|
393
|
+
const res = await invoicingClient(profile).request("GET", `eotpremnica/${opts.targetEnv}/settings`, {});
|
|
394
|
+
return unwrap(res);
|
|
395
|
+
})));
|
|
396
|
+
settings.addCommand(registerCommand(new Command("save")
|
|
397
|
+
.description("Save eOtpremnica settings")
|
|
398
|
+
.requiredOption("--target-env <env>", "Target-system environment: dev | prod")
|
|
399
|
+
.requiredOption("-d, --data <json>", "Settings body as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
400
|
+
await isActive(profile, INVOICING_ID);
|
|
401
|
+
const data = parseJSON("--data", opts.data);
|
|
402
|
+
const res = await invoicingClient(profile).request("POST", `eotpremnica/${opts.targetEnv}/settings`, { data });
|
|
403
|
+
return unwrap(res);
|
|
404
|
+
})));
|
|
405
|
+
cmd.addCommand(settings);
|
|
406
|
+
cmd.addCommand(this.registerInvoicingPassthrough("eotpremnica", "eotpremnica/"));
|
|
407
|
+
return cmd;
|
|
408
|
+
}
|
|
409
|
+
// -- vat (group + individual VAT recording, via Invoicing) -------------------------------
|
|
410
|
+
registerVat() {
|
|
411
|
+
const cmd = new Command("vat").description("VAT recording (evidencija PDV): group and individual entries");
|
|
412
|
+
for (const kind of ["group", "individual"]) {
|
|
413
|
+
const sub = new Command(kind).description(`${kind === "group" ? "Group" : "Individual"} VAT recording entries`);
|
|
414
|
+
sub.addCommand(registerCommand(new Command("list").description(`List ${kind} VAT recordings`).requiredOption("-u, --user <userId>", "User id")).action(withProfile(async (profile, opts) => {
|
|
415
|
+
await isActive(profile, INVOICING_ID);
|
|
416
|
+
const res = await invoicingClient(profile).request("GET", `vat-recording/${opts.user}/${kind}`, {});
|
|
417
|
+
return unwrap(res);
|
|
418
|
+
})));
|
|
419
|
+
sub.addCommand(registerCommand(new Command("get")
|
|
420
|
+
.description(`Get a single ${kind} VAT recording`)
|
|
421
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
422
|
+
.argument("<id>", "VAT recording id")).action(withProfile(async (profile, id, opts) => {
|
|
423
|
+
await isActive(profile, INVOICING_ID);
|
|
424
|
+
const res = await invoicingClient(profile).request("GET", `vat-recording/${opts.user}/${kind}/${id}`, {});
|
|
425
|
+
return unwrap(res);
|
|
426
|
+
})));
|
|
427
|
+
sub.addCommand(registerCommand(new Command("save")
|
|
428
|
+
.description(`Create/update a ${kind} VAT recording`)
|
|
429
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
430
|
+
.requiredOption("-d, --data <json>", "VAT recording body as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
431
|
+
await isActive(profile, INVOICING_ID);
|
|
432
|
+
const data = parseJSON("--data", opts.data);
|
|
433
|
+
const res = await invoicingClient(profile).request("POST", `vat-recording/${opts.user}/${kind}`, { data });
|
|
434
|
+
return unwrap(res);
|
|
435
|
+
})));
|
|
436
|
+
sub.addCommand(registerCommand(new Command("cancel")
|
|
437
|
+
.description(`Cancel a ${kind} VAT recording`)
|
|
438
|
+
.requiredOption("-u, --user <userId>", "User id")
|
|
439
|
+
.argument("<id>", "VAT recording id")).action(withProfile(async (profile, id, opts) => {
|
|
440
|
+
await isActive(profile, INVOICING_ID);
|
|
441
|
+
const res = await invoicingClient(profile).request("DELETE", `vat-recording/${opts.user}/${kind}/${id}`, {});
|
|
442
|
+
return unwrap(res);
|
|
443
|
+
})));
|
|
444
|
+
cmd.addCommand(sub);
|
|
445
|
+
}
|
|
446
|
+
return cmd;
|
|
447
|
+
}
|
|
448
|
+
/** Generic `<group> request <method> <endpoint>` passthrough shared by `sef`/`eotpremnica`,
|
|
449
|
+
* for the long tail of karadjordje routes not worth hand-writing a subcommand for
|
|
450
|
+
* (currencies/checkCompany/recordVat/preview/downloads/stats/sync/webhooks/...). `endpoint`
|
|
451
|
+
* is relative to the karadjordje `/karadjordje/v1/` root — `prefix` is prepended so callers
|
|
452
|
+
* only need to pass the part after e.g. `invoices/` or `eotpremnica/`. */
|
|
453
|
+
registerInvoicingPassthrough(groupName, prefix) {
|
|
454
|
+
return registerCommand(new Command("request")
|
|
455
|
+
.description(`Generic ${groupName} passthrough for routes without a dedicated subcommand (relative to karadjordje/v1/${prefix})`)
|
|
456
|
+
.argument("<method>", "HTTP method: GET | POST | PATCH | DELETE")
|
|
457
|
+
.argument("<endpoint>", `Endpoint relative to karadjordje/v1/${prefix}`)
|
|
458
|
+
.option("-d, --data <json>", "Request body as a JSON string")
|
|
459
|
+
.option("-p, --params <json>", "Query params as a JSON string")).action(withProfile(async (profile, method, endpoint, opts) => {
|
|
460
|
+
await isActive(profile, INVOICING_ID);
|
|
461
|
+
const data = opts.data ? parseJSON("--data", opts.data) : undefined;
|
|
462
|
+
const params = opts.params ? parseJSON("--params", opts.params) : undefined;
|
|
463
|
+
const res = await invoicingClient(profile).request(method.toUpperCase(), `${prefix}${endpoint}`, {
|
|
464
|
+
...(data !== undefined ? { data } : {}),
|
|
465
|
+
...(params !== undefined ? { params } : {}),
|
|
466
|
+
});
|
|
467
|
+
return unwrap(res);
|
|
468
|
+
}));
|
|
469
|
+
}
|
|
470
|
+
// -- nbs / ips-qr (via NBS) ---------------------------------------------------------------
|
|
471
|
+
registerNbs() {
|
|
472
|
+
const cmd = new Command("nbs").description("National Bank of Serbia: company search, IPS QR codes");
|
|
473
|
+
cmd.addCommand(registerCommand(new Command("search")
|
|
474
|
+
.description("Search NBS company records by VAT number")
|
|
475
|
+
.requiredOption("--vat-number <vatNumber>", "Company VAT number")).action(withProfile(async (profile, opts) => {
|
|
476
|
+
await isActive(profile, NBS_ID);
|
|
477
|
+
const res = await nbsClient(profile).nbsSearch({ vatNumber: opts.vatNumber });
|
|
478
|
+
return unwrap(res);
|
|
479
|
+
})));
|
|
480
|
+
const ipsQr = new Command("ips-qr").description("IPS QR code generation and validation");
|
|
481
|
+
ipsQr.addCommand(registerCommand(new Command("generate")
|
|
482
|
+
.description("Generate an IPS QR code (NBS payment QR)")
|
|
483
|
+
.requiredOption("-c, --code <json>", "IPS QR payload as a JSON string (NbsIpsQrCode)")
|
|
484
|
+
.requiredOption("-s, --size <size>", "QR image size in pixels", (v) => parseInt(v, 10))
|
|
485
|
+
.option("-l, --lang <lang>", "Response language")).action(withProfile(async (profile, opts) => {
|
|
486
|
+
await isActive(profile, NBS_ID);
|
|
487
|
+
const code = parseJSON("--code", opts.code);
|
|
488
|
+
const res = await nbsClient(profile).getNbsIpsQrCode(code, opts.size, opts.lang);
|
|
489
|
+
return unwrap(res);
|
|
490
|
+
})));
|
|
491
|
+
ipsQr.addCommand(registerCommand(new Command("validate")
|
|
492
|
+
.description("Validate an IPS QR code string")
|
|
493
|
+
.requiredOption("-q, --qr <qrCodeString>", "The raw QR code string to validate")
|
|
494
|
+
.option("-l, --lang <lang>", "Response language")).action(withProfile(async (profile, opts) => {
|
|
495
|
+
await isActive(profile, NBS_ID);
|
|
496
|
+
const res = await nbsClient(profile).validateNbsIpsQrCode(opts.qr, opts.lang);
|
|
497
|
+
return unwrap(res);
|
|
498
|
+
})));
|
|
499
|
+
cmd.addCommand(ipsQr);
|
|
500
|
+
return cmd;
|
|
501
|
+
}
|
|
502
|
+
// -- minfin (receipt extraction + conto, via SerbiaMinFin) -------------------------------
|
|
503
|
+
registerMinfin() {
|
|
504
|
+
const cmd = new Command("minfin").description("Serbia MinFin: fiscal receipt extraction, conto list");
|
|
505
|
+
const receipt = new Command("receipt").description("Extract structured receipt data from a fiscal QR code");
|
|
506
|
+
receipt.addCommand(registerCommand(new Command("from-url")
|
|
507
|
+
.description("Extract a receipt from the URL encoded in a fiscal QR code")
|
|
508
|
+
.requiredOption("-u, --url <url>", "The URL obtained from scanning the fiscal QR code")
|
|
509
|
+
.requiredOption("-s, --source <source>", "Source label, e.g. qr-scan")).action(withProfile(async (profile, opts) => {
|
|
510
|
+
await isActive(profile, MINFIN_ID);
|
|
511
|
+
const res = await sdk.serbia(profile).getReceiptFromUrl(opts.url, opts.source);
|
|
512
|
+
return unwrap(res);
|
|
513
|
+
})));
|
|
514
|
+
receipt.addCommand(registerCommand(new Command("from-qr")
|
|
515
|
+
.description("Extract a receipt from a base64-encoded QR code image")
|
|
516
|
+
.requiredOption("-q, --qr-code <base64>", "The QR code image, base64-encoded")
|
|
517
|
+
.requiredOption("-s, --source <source>", "Source label, e.g. qr-scan")).action(withProfile(async (profile, opts) => {
|
|
518
|
+
await isActive(profile, MINFIN_ID);
|
|
519
|
+
const res = await sdk.serbia(profile).getReceiptFromQrCode(opts.qrCode, opts.source);
|
|
520
|
+
return unwrap(res);
|
|
521
|
+
})));
|
|
522
|
+
cmd.addCommand(receipt);
|
|
523
|
+
cmd.addCommand(registerCommand(new Command("conto").description("List conto (chart of accounts) entries")).action(withProfile(async (profile) => {
|
|
524
|
+
await isActive(profile, MINFIN_ID);
|
|
525
|
+
return unwrap(await sdk.serbia(profile).getContoList());
|
|
526
|
+
})));
|
|
527
|
+
return cmd;
|
|
528
|
+
}
|
|
529
|
+
// -- minimax (representative accounting surface + generic passthrough) -------------------
|
|
530
|
+
registerMinimax() {
|
|
531
|
+
const cmd = new Command("minimax").description("Minimax accounting (~80-method REST API — representative commands + generic passthrough)");
|
|
532
|
+
cmd.addCommand(registerCommand(new Command("settings").description("Get Minimax connection settings")).action(withProfile(async (profile) => {
|
|
533
|
+
await isActive(profile, MINIMAX_ID);
|
|
534
|
+
return unwrap(await minimaxClient(profile).settings());
|
|
535
|
+
})));
|
|
536
|
+
cmd.addCommand(this.registerMinimaxResource("accounts", "getAccounts", "getAccount", "accountId"));
|
|
537
|
+
cmd.addCommand(this.registerMinimaxResource("customers", "getCustomers", "getCustomer", "customerId"));
|
|
538
|
+
cmd.addCommand(this.registerMinimaxResource("documents", "getDocuments", "getDocument", "documentId"));
|
|
539
|
+
cmd.addCommand(this.registerMinimaxResource("issued-invoices", "getIssuedInvoices", "getIssuedInvoice", "issuedInvoiceId"));
|
|
540
|
+
cmd.addCommand(this.registerMinimaxResource("journals", "getJournals", "getJournal", "journalId"));
|
|
541
|
+
cmd.addCommand(registerCommand(new Command("request")
|
|
542
|
+
.description("Generic Minimax passthrough for any of the ~80 REST methods, relative to " +
|
|
543
|
+
"/karadjordje/v1/minimax/{user}/api/orgs/{org}/")
|
|
544
|
+
.argument("<method>", "HTTP method: GET | POST | PUT | DELETE")
|
|
545
|
+
.argument("<endpoint>", "Endpoint relative to .../api/orgs/{org}/, e.g. accounts or accounts/42")
|
|
546
|
+
.requiredOption("-u, --user <userId>", "Minimax-linked user id")
|
|
547
|
+
.requiredOption("--org <organisationId>", "Minimax organisation id", (v) => parseInt(v, 10))
|
|
548
|
+
.option("-d, --data <json>", "Request body as a JSON string")
|
|
549
|
+
.option("-p, --params <json>", "Query params as a JSON string")).action(withProfile(async (profile, method, endpoint, opts) => {
|
|
550
|
+
await isActive(profile, MINIMAX_ID);
|
|
551
|
+
const data = opts.data ? parseJSON("--data", opts.data) : undefined;
|
|
552
|
+
const params = opts.params ? parseJSON("--params", opts.params) : undefined;
|
|
553
|
+
const path = `/karadjordje/v1/minimax/${opts.user}/api/orgs/${opts.org}/${endpoint}`;
|
|
554
|
+
const res = await minimaxClient(profile).client.request({
|
|
555
|
+
method: method.toUpperCase(),
|
|
556
|
+
url: path,
|
|
557
|
+
...(data !== undefined ? { data } : {}),
|
|
558
|
+
...(params !== undefined ? { params } : {}),
|
|
559
|
+
});
|
|
560
|
+
return unwrap(res);
|
|
561
|
+
})));
|
|
562
|
+
return cmd;
|
|
563
|
+
}
|
|
564
|
+
/** Builds a `list`/`get` pair for one Minimax resource off its typed `get<Plural>`/`get<Singular>`
|
|
565
|
+
* methods — the representative surface for the resource, with the full method set reachable
|
|
566
|
+
* via `minimax request` for anything not exposed here (create/update/delete/...ForSync/...). */
|
|
567
|
+
registerMinimaxResource(name, listMethod, getMethod, idFlag) {
|
|
568
|
+
const cmd = new Command(name).description(`Minimax ${name} (representative — see \`minimax request\` for the rest)`);
|
|
569
|
+
cmd.addCommand(registerCommand(new Command("list")
|
|
570
|
+
.description(`List ${name}`)
|
|
571
|
+
.requiredOption("-u, --user <userId>", "Minimax-linked user id")
|
|
572
|
+
.requiredOption("--org <organisationId>", "Minimax organisation id", (v) => parseInt(v, 10))
|
|
573
|
+
.option("-p, --params <json>", "Optional search params as a JSON string")).action(withProfile(async (profile, opts) => {
|
|
574
|
+
await isActive(profile, MINIMAX_ID);
|
|
575
|
+
const params = opts.params ? parseJSON("--params", opts.params) : undefined;
|
|
576
|
+
const client = minimaxClient(profile);
|
|
577
|
+
return unwrap(await client[listMethod](opts.user, opts.org, params));
|
|
578
|
+
})));
|
|
579
|
+
cmd.addCommand(registerCommand(new Command("get")
|
|
580
|
+
.description(`Get a single ${name.replace(/s$/, "")}`)
|
|
581
|
+
.requiredOption("-u, --user <userId>", "Minimax-linked user id")
|
|
582
|
+
.requiredOption("--org <organisationId>", "Minimax organisation id", (v) => parseInt(v, 10))
|
|
583
|
+
.requiredOption(`--id <${idFlag}>`, "Record id", (v) => parseInt(v, 10))).action(withProfile(async (profile, opts) => {
|
|
584
|
+
await isActive(profile, MINIMAX_ID);
|
|
585
|
+
const client = minimaxClient(profile);
|
|
586
|
+
return unwrap(await client[getMethod](opts.user, opts.org, opts.id));
|
|
587
|
+
})));
|
|
588
|
+
return cmd;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
/** Builds the multipart form used by `vpfr registers add|update` (register CRUD uploads an
|
|
592
|
+
* optional `crt`/`key` certificate pair alongside the register fields, matching the karadjordje
|
|
593
|
+
* `multer` fields on those routes). */
|
|
594
|
+
function buildRegisterFormData(opts) {
|
|
595
|
+
const form = new FormData();
|
|
596
|
+
if (opts.name !== undefined)
|
|
597
|
+
form.append("name", opts.name);
|
|
598
|
+
if (opts.address !== undefined)
|
|
599
|
+
form.append("address", opts.address);
|
|
600
|
+
if (opts.jid !== undefined)
|
|
601
|
+
form.append("jid", opts.jid);
|
|
602
|
+
if (opts.pak !== undefined)
|
|
603
|
+
form.append("pak", opts.pak);
|
|
604
|
+
if (opts.crt)
|
|
605
|
+
form.append("crt", new Blob([readFileSync(opts.crt)]), "cert.crt");
|
|
606
|
+
if (opts.key)
|
|
607
|
+
form.append("key", new Blob([readFileSync(opts.key)]), "cert.key");
|
|
608
|
+
return form;
|
|
609
|
+
}
|
|
610
|
+
export default new SerbiaCommand();
|