fiscalisto 0.1.2 → 0.1.3
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 +141 -12
- package/dist/core.d.ts +1 -1
- package/dist/core.js +1 -1
- package/dist/generated.d.ts +171 -12
- package/dist/generated.js +101 -0
- package/dist/mock-routes.gen.js +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { spawn, spawnSync } from "node:child_process";
|
|
11
11
|
import { createHmac } from "node:crypto";
|
|
12
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
12
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
13
13
|
import { appendFile, chmod, mkdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
14
14
|
import { homedir, hostname } from "node:os";
|
|
15
15
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -240,6 +240,7 @@ async function whoami(g) {
|
|
|
240
240
|
line(`Emisores: ${issuers.data.map((i) => `${i.tax_id}${i.status !== "active" ? dim(` (${i.status})`) : ""}`).join(", ") || dim("ninguno")}`);
|
|
241
241
|
});
|
|
242
242
|
}
|
|
243
|
+
const LANGS = ["node", "python", "php", "go", "dotnet", "java"];
|
|
243
244
|
function detectLang(dir) {
|
|
244
245
|
if (existsSync(join(dir, "package.json")))
|
|
245
246
|
return "node";
|
|
@@ -247,8 +248,15 @@ function detectLang(dir) {
|
|
|
247
248
|
return "python";
|
|
248
249
|
if (existsSync(join(dir, "composer.json")))
|
|
249
250
|
return "php";
|
|
251
|
+
if (existsSync(join(dir, "go.mod")))
|
|
252
|
+
return "go";
|
|
253
|
+
if (["pom.xml", "build.gradle", "build.gradle.kts"].some((f) => existsSync(join(dir, f))))
|
|
254
|
+
return "java";
|
|
255
|
+
if (readdirSync(dir).some((f) => /\.(csproj|fsproj|sln)$/.test(f)))
|
|
256
|
+
return "dotnet";
|
|
250
257
|
return null;
|
|
251
258
|
}
|
|
259
|
+
/** The command that adds the SDK, or null where it goes in a build file by hand (Java). */
|
|
252
260
|
function installCommand(lang, dir) {
|
|
253
261
|
if (lang === "python") {
|
|
254
262
|
if (existsSync(join(dir, "uv.lock")))
|
|
@@ -259,6 +267,12 @@ function installCommand(lang, dir) {
|
|
|
259
267
|
}
|
|
260
268
|
if (lang === "php")
|
|
261
269
|
return ["composer", "require", "fiscalisto/fiscalisto"];
|
|
270
|
+
if (lang === "go")
|
|
271
|
+
return ["go", "get", "fiscalisto.com/go"];
|
|
272
|
+
if (lang === "dotnet")
|
|
273
|
+
return ["dotnet", "add", "package", "Fiscalisto"];
|
|
274
|
+
if (lang === "java")
|
|
275
|
+
return null;
|
|
262
276
|
if (existsSync(join(dir, "bun.lock")) || existsSync(join(dir, "bun.lockb")))
|
|
263
277
|
return ["bun", "add", "fiscalisto"];
|
|
264
278
|
if (existsSync(join(dir, "pnpm-lock.yaml")))
|
|
@@ -267,6 +281,10 @@ function installCommand(lang, dir) {
|
|
|
267
281
|
return ["yarn", "add", "fiscalisto"];
|
|
268
282
|
return ["npm", "install", "fiscalisto"];
|
|
269
283
|
}
|
|
284
|
+
/** What to add to a Java build by hand. */
|
|
285
|
+
const javaDependency = (dir) => existsSync(join(dir, "pom.xml"))
|
|
286
|
+
? `pom.xml: agregue <dependency><groupId>com.fiscalisto</groupId><artifactId>fiscalisto</artifactId><version>${VERSION}</version></dependency>`
|
|
287
|
+
: `build.gradle: agregue implementation("com.fiscalisto:fiscalisto:${VERSION}")`;
|
|
270
288
|
const EXAMPLE_INVOICE = {
|
|
271
289
|
customer: {
|
|
272
290
|
tax_id: "ICV060329BY0",
|
|
@@ -350,14 +368,117 @@ echo $factura['status'], ' ', $factura['uuid'], ' ', $factura['total'], PHP_EOL;
|
|
|
350
368
|
`,
|
|
351
369
|
},
|
|
352
370
|
};
|
|
371
|
+
EXAMPLES.go = {
|
|
372
|
+
file: "fiscalisto-ejemplo/main.go",
|
|
373
|
+
run: "env $(grep -v '^#' .env | xargs) go run ./fiscalisto-ejemplo",
|
|
374
|
+
code: `// Timbra una factura de prueba con el SDK de Fiscalisto:
|
|
375
|
+
// env $(grep -v '^#' .env | xargs) go run ./fiscalisto-ejemplo
|
|
376
|
+
package main
|
|
377
|
+
|
|
378
|
+
import (
|
|
379
|
+
"context"
|
|
380
|
+
"fmt"
|
|
381
|
+
"log"
|
|
382
|
+
"time"
|
|
383
|
+
|
|
384
|
+
fiscalisto "fiscalisto.com/go"
|
|
385
|
+
)
|
|
386
|
+
|
|
387
|
+
func main() {
|
|
388
|
+
// La llave viene de FISCALISTO_API_KEY.
|
|
389
|
+
client, err := fiscalisto.NewClient("")
|
|
390
|
+
if err != nil {
|
|
391
|
+
log.Fatal(err)
|
|
392
|
+
}
|
|
393
|
+
factura, err := client.Invoices.Create(context.Background(), &fiscalisto.InvoiceCreate{
|
|
394
|
+
Customer: fiscalisto.ObjectOf(fiscalisto.InvoiceCreateCustomer{
|
|
395
|
+
TaxID: "ICV060329BY0",
|
|
396
|
+
LegalName: "INMOBILIARIA CVA",
|
|
397
|
+
TaxSystem: "601",
|
|
398
|
+
Zip: "33826",
|
|
399
|
+
}),
|
|
400
|
+
PaymentForm: fiscalisto.String("03"),
|
|
401
|
+
Items: []fiscalisto.InvoiceCreateItem{{
|
|
402
|
+
Description: fiscalisto.String("Consultoría"),
|
|
403
|
+
ProductKey: fiscalisto.String("80101500"),
|
|
404
|
+
UnitPrice: fiscalisto.Float64(1000),
|
|
405
|
+
}},
|
|
406
|
+
}, fiscalisto.WithIdempotencyKey(fmt.Sprintf("pedido-%d", time.Now().Unix()))) // use el id de su pedido
|
|
407
|
+
if err != nil {
|
|
408
|
+
log.Fatal(err)
|
|
409
|
+
}
|
|
410
|
+
fmt.Println(factura.ID)
|
|
411
|
+
}
|
|
412
|
+
`,
|
|
413
|
+
};
|
|
414
|
+
EXAMPLES.dotnet = {
|
|
415
|
+
file: "FiscalistoEjemplo.cs",
|
|
416
|
+
run: "llame a await FiscalistoEjemplo.RunAsync() con FISCALISTO_API_KEY en el entorno",
|
|
417
|
+
code: `// Timbra una factura de prueba con el SDK de Fiscalisto: await FiscalistoEjemplo.RunAsync();
|
|
418
|
+
using Fiscalisto;
|
|
419
|
+
|
|
420
|
+
public static class FiscalistoEjemplo
|
|
421
|
+
{
|
|
422
|
+
public static async Task RunAsync()
|
|
423
|
+
{
|
|
424
|
+
// La llave viene de FISCALISTO_API_KEY.
|
|
425
|
+
var fiscalisto = new FiscalistoClient();
|
|
426
|
+
var factura = await fiscalisto.Invoices.CreateAsync(new InvoiceCreate
|
|
427
|
+
{
|
|
428
|
+
Customer = new InvoiceCreateCustomer
|
|
429
|
+
{
|
|
430
|
+
TaxId = "ICV060329BY0",
|
|
431
|
+
LegalName = "INMOBILIARIA CVA",
|
|
432
|
+
TaxSystem = "601",
|
|
433
|
+
Zip = "33826",
|
|
434
|
+
},
|
|
435
|
+
PaymentForm = "03",
|
|
436
|
+
Items = new() { new() { Description = "Consultoría", ProductKey = "80101500", UnitPrice = 1000 } },
|
|
437
|
+
}, new RequestOptions { IdempotencyKey = $"pedido-{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}" }); // use el id de su pedido
|
|
438
|
+
Console.WriteLine(factura.Id);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
`,
|
|
442
|
+
};
|
|
443
|
+
EXAMPLES.java = {
|
|
444
|
+
file: "FiscalistoEjemplo.java",
|
|
445
|
+
run: "corra FiscalistoEjemplo.main con FISCALISTO_API_KEY en el entorno",
|
|
446
|
+
code: `// Timbra una factura de prueba con el SDK de Fiscalisto (FISCALISTO_API_KEY en el entorno).
|
|
447
|
+
import com.fiscalisto.FiscalistoClient;
|
|
448
|
+
import com.fiscalisto.RequestOptions;
|
|
449
|
+
import com.fiscalisto.model.InvoiceCreate;
|
|
450
|
+
import com.fiscalisto.model.InvoiceCreateCustomer;
|
|
451
|
+
import com.fiscalisto.model.InvoiceCreateItem;
|
|
452
|
+
import java.util.List;
|
|
453
|
+
|
|
454
|
+
public class FiscalistoEjemplo {
|
|
455
|
+
public static void main(String[] args) {
|
|
456
|
+
var fiscalisto = new FiscalistoClient();
|
|
457
|
+
var factura = fiscalisto.invoices().create(new InvoiceCreate()
|
|
458
|
+
.setCustomer(new InvoiceCreateCustomer()
|
|
459
|
+
.setTaxId("ICV060329BY0")
|
|
460
|
+
.setLegalName("INMOBILIARIA CVA")
|
|
461
|
+
.setTaxSystem("601")
|
|
462
|
+
.setZip("33826"))
|
|
463
|
+
.setPaymentForm("03")
|
|
464
|
+
.setItems(List.of(new InvoiceCreateItem()
|
|
465
|
+
.setDescription("Consultoría")
|
|
466
|
+
.setProductKey("80101500")
|
|
467
|
+
.setUnitPrice(1000))),
|
|
468
|
+
RequestOptions.idempotencyKey("pedido-" + System.currentTimeMillis() / 1000)); // use el id de su pedido
|
|
469
|
+
System.out.println(factura.getId());
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
`,
|
|
473
|
+
};
|
|
353
474
|
const AGENTS_SECTION = `
|
|
354
475
|
## Facturación (Fiscalisto)
|
|
355
476
|
|
|
356
477
|
Facturas electrónicas (CFDI 4.0) con la API de Fiscalisto. La llave está en \`FISCALISTO_API_KEY\`
|
|
357
478
|
(\`.env\`; \`fk_test_\` timbra en pruebas sin costo). Documentación completa para agentes:
|
|
358
|
-
https://fiscalisto.com/llms.txt y la referencia en https://api.fiscalisto.com/v1/openapi.json.
|
|
479
|
+
https://fiscalisto.com/docs/api/llms.txt y la referencia en https://api.fiscalisto.com/v1/openapi.json.
|
|
359
480
|
|
|
360
|
-
- Use el SDK \`fiscalisto\` (npm, PyPI, Packagist). Cada timbrado lleva una Idempotency-Key
|
|
481
|
+
- Use el SDK \`fiscalisto\` (npm, PyPI, Packagist, Go, Maven, NuGet). Cada timbrado lleva una Idempotency-Key
|
|
361
482
|
(el id del pedido): repetirla nunca timbra dos veces.
|
|
362
483
|
- El cliente va con su RFC, nombre, régimen y código postal exactamente como en su constancia.
|
|
363
484
|
- Para probar rechazos del SAT use los RFC de prueba (NOM010101FK9 y otros, ver "Pruebas y producción").
|
|
@@ -375,10 +496,10 @@ async function init(args, g) {
|
|
|
375
496
|
});
|
|
376
497
|
const dir = resolve(values.dir ?? ".");
|
|
377
498
|
const lang = values.lang ?? detectLang(dir);
|
|
378
|
-
if (lang && !
|
|
379
|
-
throw new UsageError(
|
|
499
|
+
if (lang && !LANGS.includes(lang))
|
|
500
|
+
throw new UsageError(`--lang es ${LANGS.join(", ")}.`);
|
|
380
501
|
if (!lang)
|
|
381
|
-
throw new UsageError(
|
|
502
|
+
throw new UsageError(`No encontré package.json, pyproject.toml/requirements.txt, composer.json, go.mod, pom.xml/build.gradle ni un .csproj aquí. Indique --lang ${LANGS.join("|")}.`);
|
|
382
503
|
if (!env.FISCALISTO_API_KEY && !g.apiKey && !(await loadConfig()).test_key)
|
|
383
504
|
await login([], g);
|
|
384
505
|
const key = g.apiKey ?? env.FISCALISTO_API_KEY ?? (await loadConfig()).test_key ?? "";
|
|
@@ -399,7 +520,9 @@ async function init(args, g) {
|
|
|
399
520
|
// The SDK.
|
|
400
521
|
const install = installCommand(lang, dir);
|
|
401
522
|
let installed = false;
|
|
402
|
-
if (!
|
|
523
|
+
if (!install)
|
|
524
|
+
done.push(javaDependency(dir));
|
|
525
|
+
else if (!values["no-install"]) {
|
|
403
526
|
const go = g.yes || !process.stdin.isTTY || json
|
|
404
527
|
? true
|
|
405
528
|
: await ask(`Instalar el SDK con «${install.join(" ")}»? [S/n] `).then((y) => y);
|
|
@@ -428,10 +551,15 @@ async function init(args, g) {
|
|
|
428
551
|
}
|
|
429
552
|
// An example that stamps.
|
|
430
553
|
const example = EXAMPLES[lang];
|
|
431
|
-
|
|
554
|
+
// Maven and Gradle compile src/main/java.
|
|
555
|
+
const exampleFile = lang === "java" && existsSync(join(dir, "src/main/java"))
|
|
556
|
+
? `src/main/java/${example.file}`
|
|
557
|
+
: example.file;
|
|
558
|
+
const examplePath = join(dir, exampleFile);
|
|
432
559
|
if (!existsSync(examplePath)) {
|
|
560
|
+
await mkdir(dirname(examplePath), { recursive: true });
|
|
433
561
|
await writeFile(examplePath, example.code);
|
|
434
|
-
done.push(`${
|
|
562
|
+
done.push(`${exampleFile}: timbra una factura de prueba`);
|
|
435
563
|
}
|
|
436
564
|
if (values.agents) {
|
|
437
565
|
const agentsPath = join(dir, existsSync(join(dir, "CLAUDE.md")) && !existsSync(join(dir, "AGENTS.md"))
|
|
@@ -1040,12 +1168,13 @@ function openPlace(args) {
|
|
|
1040
1168
|
print({ url }, () => line(url));
|
|
1041
1169
|
}
|
|
1042
1170
|
async function docs() {
|
|
1043
|
-
const
|
|
1171
|
+
const url = `${APP_URL()}/docs/api/llms.txt`;
|
|
1172
|
+
const r = await fetch(url);
|
|
1044
1173
|
if (!r.ok)
|
|
1045
1174
|
throw new Error(`No se pudo leer la documentación (${r.status}).`);
|
|
1046
1175
|
const text = await r.text();
|
|
1047
1176
|
if (json)
|
|
1048
|
-
print({ url
|
|
1177
|
+
print({ url, text });
|
|
1049
1178
|
else
|
|
1050
1179
|
process.stdout.write(text);
|
|
1051
1180
|
}
|
|
@@ -1106,7 +1235,7 @@ const HELP = `${bold("fiscalisto")} ${dim(VERSION)} · facturación electrónica
|
|
|
1106
1235
|
|
|
1107
1236
|
${bold("Empezar")}
|
|
1108
1237
|
login [--live] [--key fk_…] Inicia sesión por el navegador y guarda su llave de pruebas
|
|
1109
|
-
init [--lang node|python|php] Deja el SDK, la llave en .env y un ejemplo en su proyecto (--agents: AGENTS.md)
|
|
1238
|
+
init [--lang node|python|php|go|dotnet|java] Deja el SDK, la llave en .env y un ejemplo en su proyecto (--agents: AGENTS.md)
|
|
1110
1239
|
whoami Cuenta, modo, timbres y emisores
|
|
1111
1240
|
logout Olvida las llaves en esta computadora
|
|
1112
1241
|
|
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.3";
|
|
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.3";
|
|
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.
|