fiscalisto 0.1.3 → 0.1.5
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/dist/cli.js +53 -11
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/error-codes.d.ts +6 -0
- package/dist/error-codes.js +6 -0
- package/dist/generated.d.ts +917 -24
- package/dist/generated.js +323 -0
- package/dist/mock-routes.gen.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -40,9 +40,20 @@ function print(value, human) {
|
|
|
40
40
|
}
|
|
41
41
|
const line = (s = "") => process.stdout.write(`${s}\n`);
|
|
42
42
|
const note = (s) => process.stderr.write(`${s}\n`);
|
|
43
|
-
const money = (n, currency = "MXN") =>
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
const money = (n, currency = "MXN") => {
|
|
44
|
+
if (typeof n !== "number")
|
|
45
|
+
return "";
|
|
46
|
+
const amount = n.toLocaleString("es-MX", {
|
|
47
|
+
minimumFractionDigits: 2,
|
|
48
|
+
maximumFractionDigits: 2,
|
|
49
|
+
});
|
|
50
|
+
return currency === "MXN" || currency === "XXX" ? `$${amount}` : `${amount} ${currency}`;
|
|
51
|
+
};
|
|
52
|
+
/** What a document is worth in a list: a payment complement's total is 0, so its amount paid. */
|
|
53
|
+
const worth = (i) => {
|
|
54
|
+
const paid = i.payment;
|
|
55
|
+
return i.type === "P" && paid ? money(paid.amount, paid.currency) : money(i.total, i.currency);
|
|
56
|
+
};
|
|
46
57
|
const configPath = () => join(env.XDG_CONFIG_HOME || join(homedir(), ".config"), "fiscalisto", "config.json");
|
|
47
58
|
async function loadConfig() {
|
|
48
59
|
try {
|
|
@@ -593,7 +604,7 @@ const status = (s, width = 0) => {
|
|
|
593
604
|
return color(label.padEnd(width));
|
|
594
605
|
};
|
|
595
606
|
function showInvoice(i) {
|
|
596
|
-
line(`${bold(`${i.series ?? ""}${i.folio ?? ""}` || i.id)} ${status(i.status)} ${
|
|
607
|
+
line(`${bold(`${i.series ?? ""}${i.folio ?? ""}` || i.id)} ${status(i.status)} ${worth(i)}`);
|
|
597
608
|
line(` ${i.customer.legal_name ?? ""} ${dim(i.customer.tax_id)}`);
|
|
598
609
|
if (i.uuid)
|
|
599
610
|
line(` UUID ${i.uuid}`);
|
|
@@ -642,7 +653,9 @@ async function invoices(args, g) {
|
|
|
642
653
|
body = structuredClone(EXAMPLE_INVOICE);
|
|
643
654
|
if (!body) {
|
|
644
655
|
if (!values.customer || !values.item?.length)
|
|
645
|
-
throw new UsageError('Pase --data (JSON, @archivo o -), --example, o --customer RFC --name "NOMBRE" --regime 601 --zip 12345 --item "Descripción|clave|precio".');
|
|
656
|
+
throw new UsageError('Pase --data (JSON, @archivo o -), --example, o --customer RFC --name "NOMBRE" --regime 601 --zip 12345 --item "Descripción|clave|precio" --payment-form 03.');
|
|
657
|
+
if (!values["payment-form"] && values["payment-method"] !== "PPD")
|
|
658
|
+
throw new UsageError("Falta --payment-form: 03 transferencia, 01 efectivo, 04 tarjeta de crédito, 28 de débito (o --payment-method PPD si se la pagan después).");
|
|
646
659
|
body = {
|
|
647
660
|
customer: {
|
|
648
661
|
tax_id: values.customer.toUpperCase(),
|
|
@@ -697,7 +710,7 @@ async function invoices(args, g) {
|
|
|
697
710
|
if (!page.data.length)
|
|
698
711
|
return line(dim("Sin facturas."));
|
|
699
712
|
for (const i of page.data)
|
|
700
|
-
line(`${(`${i.series ?? ""}${i.folio ?? ""}` || "—").padEnd(8)} ${status(i.status, 10)} ${
|
|
713
|
+
line(`${(`${i.series ?? ""}${i.folio ?? ""}` || "—").padEnd(8)} ${status(i.status, 10)} ${worth(i).padStart(14)} ${(i.customer.legal_name ?? "").slice(0, 32).padEnd(32)} ${dim(i.id)}`);
|
|
701
714
|
if (page.has_more)
|
|
702
715
|
line(dim(`… hay más: --limit ${Number(values.limit) * 2}`));
|
|
703
716
|
});
|
|
@@ -803,7 +816,18 @@ async function issuers(args, g) {
|
|
|
803
816
|
method: "GET",
|
|
804
817
|
path: `/v1/issuers/${need(args[1], "fiscalisto issuers get iss_…")}`,
|
|
805
818
|
});
|
|
806
|
-
return print(issuer)
|
|
819
|
+
return print(issuer, () => {
|
|
820
|
+
line(`${bold(String(issuer.legal_name ?? issuer.tax_id))} ${dim(String(issuer.tax_id))}`);
|
|
821
|
+
line(` Estado ${String(issuer.status)}`);
|
|
822
|
+
for (const [label, key] of [
|
|
823
|
+
["Régimen", "tax_system"],
|
|
824
|
+
["C.P.", "zip"],
|
|
825
|
+
["Modo", "livemode"],
|
|
826
|
+
])
|
|
827
|
+
if (issuer[key] !== undefined && issuer[key] !== null)
|
|
828
|
+
line(` ${label.padEnd(10)} ${key === "livemode" ? (issuer[key] ? "producción" : "pruebas") : String(issuer[key])}`);
|
|
829
|
+
line(dim(` ${String(issuer.id)}`));
|
|
830
|
+
});
|
|
807
831
|
}
|
|
808
832
|
if (args[0] && args[0] !== "list")
|
|
809
833
|
throw new UsageError("fiscalisto issuers list|get");
|
|
@@ -834,10 +858,16 @@ async function events(args, g) {
|
|
|
834
858
|
options: {
|
|
835
859
|
type: { type: "string" },
|
|
836
860
|
object: { type: "string" },
|
|
861
|
+
failed: { type: "boolean" },
|
|
837
862
|
limit: { type: "string", default: "20" },
|
|
838
863
|
},
|
|
839
864
|
});
|
|
840
|
-
await simpleList(api, "/v1/events", {
|
|
865
|
+
await simpleList(api, "/v1/events", {
|
|
866
|
+
type: values.type,
|
|
867
|
+
object: values.object,
|
|
868
|
+
delivery_success: values.failed ? "false" : undefined,
|
|
869
|
+
limit: values.limit,
|
|
870
|
+
}, (e) => {
|
|
841
871
|
const o = e.data.object;
|
|
842
872
|
return `${dim(String(e.created_at))} ${String(e.type).padEnd(30)} ${o.id} ${dim(String(e.id))}`;
|
|
843
873
|
});
|
|
@@ -1107,7 +1137,11 @@ async function trigger(args, g) {
|
|
|
1107
1137
|
case "invoice.failed":
|
|
1108
1138
|
made = await stamp({
|
|
1109
1139
|
...EXAMPLE_INVOICE,
|
|
1110
|
-
customer: {
|
|
1140
|
+
customer: {
|
|
1141
|
+
...EXAMPLE_INVOICE.customer,
|
|
1142
|
+
tax_id: "NOM010101FK9",
|
|
1143
|
+
legal_name: "CLIENTE DE PRUEBA RECHAZADO",
|
|
1144
|
+
},
|
|
1111
1145
|
}).catch((e) => {
|
|
1112
1146
|
if (e instanceof FiscalistoError && e.code === "invoice_rejected")
|
|
1113
1147
|
return e.raw;
|
|
@@ -1241,7 +1275,7 @@ ${bold("Empezar")}
|
|
|
1241
1275
|
|
|
1242
1276
|
${bold("Facturas")}
|
|
1243
1277
|
invoices create --example Timbra una factura de prueba
|
|
1244
|
-
invoices create --data @f.json | --customer RFC --name … --regime 601 --zip … --item "Desc|clave|precio"
|
|
1278
|
+
invoices create --data @f.json | --customer RFC --name … --regime 601 --zip … --item "Desc|clave|precio" --payment-form 03 [--payment-method PPD] [--use G03]
|
|
1245
1279
|
invoices list [--status valid] [--customer RFC]
|
|
1246
1280
|
invoices get|pdf|xml|send <inv_…>
|
|
1247
1281
|
invoices cancel <inv_…> [--motive 02] [--substitution inv_…]
|
|
@@ -1251,7 +1285,8 @@ ${bold("Webhooks")}
|
|
|
1251
1285
|
listen [--forward-to URL] Reenvía los eventos a su computadora, firmados
|
|
1252
1286
|
trigger <evento> Crea en pruebas lo que manda ese evento (invoice.stamped, invoice.failed…)
|
|
1253
1287
|
webhooks list|create|delete|test
|
|
1254
|
-
events list
|
|
1288
|
+
events list [--type invoice.*] [--failed] Los últimos 30 días; --failed: los que algún webhook no recibió
|
|
1289
|
+
events get <evt_…>
|
|
1255
1290
|
|
|
1256
1291
|
${bold("Otros")}
|
|
1257
1292
|
issuers list|get Sus emisores
|
|
@@ -1286,6 +1321,13 @@ export async function main(argv) {
|
|
|
1286
1321
|
rest.push(a);
|
|
1287
1322
|
}
|
|
1288
1323
|
const [command, ...args] = rest;
|
|
1324
|
+
// «fiscalisto invoices create --help»: the help, not «Unknown option».
|
|
1325
|
+
if (command && args.some((a) => a === "--help" || a === "-h")) {
|
|
1326
|
+
const lines = HELP.split("\n").filter((l) => l.trimStart().startsWith(`${command} `) || l.trimStart() === command);
|
|
1327
|
+
line(lines.length ? lines.join("\n") : HELP);
|
|
1328
|
+
line(dim("\nDocumentación: https://fiscalisto.com/docs/api/cli"));
|
|
1329
|
+
return;
|
|
1330
|
+
}
|
|
1289
1331
|
try {
|
|
1290
1332
|
switch (command) {
|
|
1291
1333
|
case "login":
|
package/dist/core.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* llamar.
|
|
5
5
|
*/
|
|
6
6
|
import type { ErrorCode } from "./error-codes.js";
|
|
7
|
-
export declare const VERSION = "0.1.
|
|
7
|
+
export declare const VERSION = "0.1.5";
|
|
8
8
|
/**
|
|
9
9
|
* La versión de la API para la que se hizo este SDK: la manda en cada solicitud
|
|
10
10
|
* (Fiscalisto-Version), así actualizar la API no cambia lo que recibe hasta que actualice el SDK.
|
package/dist/core.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* errores y las listas que se recorren solas. Los recursos (generated.ts) solo dicen qué ruta
|
|
4
4
|
* llamar.
|
|
5
5
|
*/
|
|
6
|
-
export const VERSION = "0.1.
|
|
6
|
+
export const VERSION = "0.1.5";
|
|
7
7
|
/**
|
|
8
8
|
* La versión de la API para la que se hizo este SDK: la manda en cada solicitud
|
|
9
9
|
* (Fiscalisto-Version), así actualizar la API no cambia lo que recibe hasta que actualice el SDK.
|
package/dist/error-codes.d.ts
CHANGED
|
@@ -11,6 +11,10 @@ export declare const ErrorCode: {
|
|
|
11
11
|
readonly BatchInvalid: "batch_invalid";
|
|
12
12
|
/** El cuerpo pasa de 10 MB. Divida el trabajo en varios lotes. */
|
|
13
13
|
readonly BodyTooLarge: "body_too_large";
|
|
14
|
+
/** El emisor ya tiene una sucursal con ese código postal (cada una lleva el suyo); el mensaje dice cuál. Si está archivada, restáurela con archived: false. */
|
|
15
|
+
readonly BranchExists: "branch_exists";
|
|
16
|
+
/** La sucursal ya facturó, así que no se borra: archívela con archived: true y sus facturas la siguen nombrando. */
|
|
17
|
+
readonly BranchHasInvoices: "branch_has_invoices";
|
|
14
18
|
/** La API se llama desde su servidor, nunca desde el navegador: la llave secreta quedaría expuesta. */
|
|
15
19
|
readonly BrowserNotSupported: "browser_not_supported";
|
|
16
20
|
/** El SAT no aceptó la solicitud de cancelación; message dice por qué. */
|
|
@@ -59,6 +63,8 @@ export declare const ErrorCode: {
|
|
|
59
63
|
readonly InvalidJson: "invalid_json";
|
|
60
64
|
/** La respuesta no se pudo leer (api_error): no es el JSON de la API, sino la página de un proxy o de un portal de la red. status dice qué contestó. */
|
|
61
65
|
readonly InvalidResponse: "invalid_response";
|
|
66
|
+
/** Inventario no lo permite: el mensaje dice por qué (un lote que no es de ese producto, otro ajuste del mismo almacén en curso). */
|
|
67
|
+
readonly InventoryRefused: "inventory_refused";
|
|
62
68
|
/** La factura no cumple una regla del SAT que Fiscalisto revisa antes de mandarla al PAC (uso contra régimen, totales, complementos…). No se usó ningún timbre. */
|
|
63
69
|
readonly InvoiceInvalid: "invoice_invalid";
|
|
64
70
|
/** Solo una factura de ingreso PUE vigente se marca pagada o por cobrar; una PPD se paga con su complemento de pago (type P). */
|
package/dist/error-codes.js
CHANGED
|
@@ -12,6 +12,10 @@ export const ErrorCode = {
|
|
|
12
12
|
BatchInvalid: "batch_invalid",
|
|
13
13
|
/** El cuerpo pasa de 10 MB. Divida el trabajo en varios lotes. */
|
|
14
14
|
BodyTooLarge: "body_too_large",
|
|
15
|
+
/** El emisor ya tiene una sucursal con ese código postal (cada una lleva el suyo); el mensaje dice cuál. Si está archivada, restáurela con archived: false. */
|
|
16
|
+
BranchExists: "branch_exists",
|
|
17
|
+
/** La sucursal ya facturó, así que no se borra: archívela con archived: true y sus facturas la siguen nombrando. */
|
|
18
|
+
BranchHasInvoices: "branch_has_invoices",
|
|
15
19
|
/** La API se llama desde su servidor, nunca desde el navegador: la llave secreta quedaría expuesta. */
|
|
16
20
|
BrowserNotSupported: "browser_not_supported",
|
|
17
21
|
/** El SAT no aceptó la solicitud de cancelación; message dice por qué. */
|
|
@@ -60,6 +64,8 @@ export const ErrorCode = {
|
|
|
60
64
|
InvalidJson: "invalid_json",
|
|
61
65
|
/** La respuesta no se pudo leer (api_error): no es el JSON de la API, sino la página de un proxy o de un portal de la red. status dice qué contestó. */
|
|
62
66
|
InvalidResponse: "invalid_response",
|
|
67
|
+
/** Inventario no lo permite: el mensaje dice por qué (un lote que no es de ese producto, otro ajuste del mismo almacén en curso). */
|
|
68
|
+
InventoryRefused: "inventory_refused",
|
|
63
69
|
/** La factura no cumple una regla del SAT que Fiscalisto revisa antes de mandarla al PAC (uso contra régimen, totales, complementos…). No se usó ningún timbre. */
|
|
64
70
|
InvoiceInvalid: "invoice_invalid",
|
|
65
71
|
/** Solo una factura de ingreso PUE vigente se marca pagada o por cobrar; una PPD se paga con su complemento de pago (type P). */
|