@timbrix/cli 0.3.0 → 1.0.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 +1 -1
- package/dist/commands/invoices/create.d.ts +12 -0
- package/dist/commands/invoices/create.d.ts.map +1 -0
- package/dist/commands/invoices/create.js +62 -0
- package/dist/commands/login.js +1 -1
- package/dist/commands/sat/regimenes/list.d.ts.map +1 -1
- package/dist/commands/sat/usos-cfdi/list.d.ts.map +1 -1
- package/dist/config/auth.js +1 -1
- package/dist/utils/client.d.ts +7 -0
- package/dist/utils/client.d.ts.map +1 -1
- package/dist/utils/client.js +12 -0
- package/oclif.manifest.json +53 -2
- package/package.json +16 -16
package/README.md
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Command } from "@oclif/core";
|
|
2
|
+
export default class InvoicesCreate extends Command {
|
|
3
|
+
static description: string;
|
|
4
|
+
static examples: string[];
|
|
5
|
+
static flags: {
|
|
6
|
+
"api-key": import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
7
|
+
file: import("@oclif/core/interfaces").OptionFlag<string, import("@oclif/core/interfaces").CustomOptions>;
|
|
8
|
+
output: import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
|
|
9
|
+
};
|
|
10
|
+
run(): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=create.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/invoices/create.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAO5C,MAAM,CAAC,OAAO,OAAO,cAAe,SAAQ,OAAO;IACjD,OAAgB,WAAW,SAG6C;IAExE,OAAgB,QAAQ,WAGvB;IAED,OAAgB,KAAK;;;;MAepB;IAEY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CA6ClC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { Command, Flags } from "@oclif/core";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import ora from "ora";
|
|
5
|
+
import { createApiKeyClient } from "../../utils/client.js";
|
|
6
|
+
import { getErrorMessage } from "../../utils/error.js";
|
|
7
|
+
export default class InvoicesCreate extends Command {
|
|
8
|
+
static description = "Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC. " +
|
|
9
|
+
"The issuing organization is resolved from the API key, so this command " +
|
|
10
|
+
"authenticates with --api-key instead of the `timbrix login` session.";
|
|
11
|
+
static examples = [
|
|
12
|
+
"<%= config.bin %> <%= command.id %> --api-key sk_live_... --file invoice.json",
|
|
13
|
+
"<%= config.bin %> <%= command.id %> --api-key sk_live_... --file invoice.json --output invoice.xml",
|
|
14
|
+
];
|
|
15
|
+
static flags = {
|
|
16
|
+
"api-key": Flags.string({
|
|
17
|
+
description: "Timbrix API key (needs the write:invoices scope)",
|
|
18
|
+
env: "TIMBRIX_API_KEY",
|
|
19
|
+
required: true,
|
|
20
|
+
}),
|
|
21
|
+
file: Flags.string({
|
|
22
|
+
char: "f",
|
|
23
|
+
description: "Path to a JSON file with the invoice payload (series, folioNumber, date, paymentForm, use, customer|customerId, items)",
|
|
24
|
+
required: true,
|
|
25
|
+
}),
|
|
26
|
+
output: Flags.string({
|
|
27
|
+
description: "Path to save the timbrado CFDI XML (optional)",
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
async run() {
|
|
31
|
+
const { flags } = await this.parse(InvoicesCreate);
|
|
32
|
+
const client = createApiKeyClient(flags["api-key"]);
|
|
33
|
+
let payload;
|
|
34
|
+
try {
|
|
35
|
+
payload = JSON.parse(readFileSync(flags.file, "utf-8"));
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
this.error(chalk.red(`Failed to read invoice payload file: ${getErrorMessage(error)}`));
|
|
39
|
+
}
|
|
40
|
+
const spinner = ora("Stamping invoice...").start();
|
|
41
|
+
try {
|
|
42
|
+
const invoice = await client.invoices.create(payload);
|
|
43
|
+
spinner.succeed(chalk.green("✓ Invoice stamped successfully!"));
|
|
44
|
+
this.log(chalk.gray("\nInvoice Details:"));
|
|
45
|
+
this.log(` ${chalk.bold("ID:")} ${invoice.id}`);
|
|
46
|
+
this.log(` ${chalk.bold("UUID:")} ${invoice.uuid}`);
|
|
47
|
+
this.log(` ${chalk.bold("Series/Folio:")} ${invoice.series}-${invoice.folioNumber}`);
|
|
48
|
+
this.log(` ${chalk.bold("Total:")} $${invoice.total.toFixed(2)}`);
|
|
49
|
+
if (flags.output) {
|
|
50
|
+
writeFileSync(flags.output, invoice.xml, "utf-8");
|
|
51
|
+
this.log(` ${chalk.bold("XML saved to:")} ${flags.output}`);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
this.log(chalk.gray("\nPass --output <path> to save the CFDI XML to a file."));
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
spinner.fail(chalk.red(`Failed to stamp invoice: ${getErrorMessage(error)}`));
|
|
59
|
+
this.exit(1);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
package/dist/commands/login.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/commands/sat/regimenes/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAQ5C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,OAAO;IACnD,OAAgB,WAAW,SAAgC;IAE3D,OAAgB,QAAQ,WAIvB;IAED,OAAgB,KAAK;;MAMpB;IAEY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/commands/sat/regimenes/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAQ5C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,OAAO;IACnD,OAAgB,WAAW,SAAgC;IAE3D,OAAgB,QAAQ,WAIvB;IAED,OAAgB,KAAK;;MAMpB;IAEY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAmClC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/commands/sat/usos-cfdi/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAQ5C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAClD,OAAgB,WAAW,SAA0B;IAErD,OAAgB,QAAQ,WAKvB;IAED,OAAgB,KAAK;;;MAUpB;IAEY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../../../src/commands/sat/usos-cfdi/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAS,MAAM,aAAa,CAAA;AAQ5C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,OAAO;IAClD,OAAgB,WAAW,SAA0B;IAErD,OAAgB,QAAQ,WAKvB;IAED,OAAgB,KAAK;;;MAUpB;IAEY,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC;CAgClC"}
|
package/dist/config/auth.js
CHANGED
package/dist/utils/client.d.ts
CHANGED
|
@@ -3,4 +3,11 @@ import { Timbrix } from "@timbrix/sdk";
|
|
|
3
3
|
* Create an authenticated Timbrix client
|
|
4
4
|
*/
|
|
5
5
|
export declare function createClient(): Timbrix;
|
|
6
|
+
/**
|
|
7
|
+
* Create a Timbrix client authenticated with an API key rather than the
|
|
8
|
+
* logged-in session. Used by commands whose API endpoint resolves the
|
|
9
|
+
* organization from the API key (e.g. `invoices create`), which is a
|
|
10
|
+
* different auth model than the rest of the CLI's `timbrix login` session.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createApiKeyClient(apiKey: string): Timbrix;
|
|
6
13
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAItC;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAetC"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/utils/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAItC;;GAEG;AACH,wBAAgB,YAAY,IAAI,OAAO,CAetC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAK1D"}
|
package/dist/utils/client.js
CHANGED
|
@@ -16,3 +16,15 @@ export function createClient() {
|
|
|
16
16
|
baseUrl,
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Create a Timbrix client authenticated with an API key rather than the
|
|
21
|
+
* logged-in session. Used by commands whose API endpoint resolves the
|
|
22
|
+
* organization from the API key (e.g. `invoices create`), which is a
|
|
23
|
+
* different auth model than the rest of the CLI's `timbrix login` session.
|
|
24
|
+
*/
|
|
25
|
+
export function createApiKeyClient(apiKey) {
|
|
26
|
+
return new Timbrix({
|
|
27
|
+
apiKey,
|
|
28
|
+
baseUrl: AuthManager.getBaseUrl(),
|
|
29
|
+
});
|
|
30
|
+
}
|
package/oclif.manifest.json
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"char": "u",
|
|
22
22
|
"description": "API base URL",
|
|
23
23
|
"name": "base-url",
|
|
24
|
-
"default": "http://localhost:3001
|
|
24
|
+
"default": "http://localhost:3001",
|
|
25
25
|
"hasDynamicHelp": false,
|
|
26
26
|
"multiple": false,
|
|
27
27
|
"type": "option"
|
|
@@ -489,6 +489,57 @@
|
|
|
489
489
|
"list.js"
|
|
490
490
|
]
|
|
491
491
|
},
|
|
492
|
+
"invoices:create": {
|
|
493
|
+
"aliases": [],
|
|
494
|
+
"args": {},
|
|
495
|
+
"description": "Create and stamp (timbrar) a CFDI 4.0 invoice via the configured PAC. The issuing organization is resolved from the API key, so this command authenticates with --api-key instead of the `timbrix login` session.",
|
|
496
|
+
"examples": [
|
|
497
|
+
"<%= config.bin %> <%= command.id %> --api-key sk_live_... --file invoice.json",
|
|
498
|
+
"<%= config.bin %> <%= command.id %> --api-key sk_live_... --file invoice.json --output invoice.xml"
|
|
499
|
+
],
|
|
500
|
+
"flags": {
|
|
501
|
+
"api-key": {
|
|
502
|
+
"description": "Timbrix API key (needs the write:invoices scope)",
|
|
503
|
+
"env": "TIMBRIX_API_KEY",
|
|
504
|
+
"name": "api-key",
|
|
505
|
+
"required": true,
|
|
506
|
+
"hasDynamicHelp": false,
|
|
507
|
+
"multiple": false,
|
|
508
|
+
"type": "option"
|
|
509
|
+
},
|
|
510
|
+
"file": {
|
|
511
|
+
"char": "f",
|
|
512
|
+
"description": "Path to a JSON file with the invoice payload (series, folioNumber, date, paymentForm, use, customer|customerId, items)",
|
|
513
|
+
"name": "file",
|
|
514
|
+
"required": true,
|
|
515
|
+
"hasDynamicHelp": false,
|
|
516
|
+
"multiple": false,
|
|
517
|
+
"type": "option"
|
|
518
|
+
},
|
|
519
|
+
"output": {
|
|
520
|
+
"description": "Path to save the timbrado CFDI XML (optional)",
|
|
521
|
+
"name": "output",
|
|
522
|
+
"hasDynamicHelp": false,
|
|
523
|
+
"multiple": false,
|
|
524
|
+
"type": "option"
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
"hasDynamicHelp": false,
|
|
528
|
+
"hiddenAliases": [],
|
|
529
|
+
"id": "invoices:create",
|
|
530
|
+
"pluginAlias": "@timbrix/cli",
|
|
531
|
+
"pluginName": "@timbrix/cli",
|
|
532
|
+
"pluginType": "core",
|
|
533
|
+
"strict": true,
|
|
534
|
+
"enableJsonFlag": false,
|
|
535
|
+
"isESM": true,
|
|
536
|
+
"relativePath": [
|
|
537
|
+
"dist",
|
|
538
|
+
"commands",
|
|
539
|
+
"invoices",
|
|
540
|
+
"create.js"
|
|
541
|
+
]
|
|
542
|
+
},
|
|
492
543
|
"oauth-apps:create": {
|
|
493
544
|
"aliases": [],
|
|
494
545
|
"args": {},
|
|
@@ -1368,5 +1419,5 @@
|
|
|
1368
1419
|
]
|
|
1369
1420
|
}
|
|
1370
1421
|
},
|
|
1371
|
-
"version": "0.
|
|
1422
|
+
"version": "1.0.0"
|
|
1372
1423
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timbrix/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "CLI tool for Timbrix API",
|
|
5
5
|
"author": "Ivan Sotelo",
|
|
6
6
|
"bin": {
|
|
@@ -26,28 +26,28 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org/"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@inquirer/prompts": "^8.
|
|
30
|
-
"@oclif/core": "^4.
|
|
31
|
-
"@oclif/plugin-help": "^6.2.
|
|
32
|
-
"@oclif/plugin-plugins": "^5.4.
|
|
33
|
-
"chalk": "^
|
|
29
|
+
"@inquirer/prompts": "^8.5.2",
|
|
30
|
+
"@oclif/core": "^4.13.2",
|
|
31
|
+
"@oclif/plugin-help": "^6.2.55",
|
|
32
|
+
"@oclif/plugin-plugins": "^5.4.86",
|
|
33
|
+
"chalk": "^6.0.0",
|
|
34
34
|
"cli-table3": "^0.6.5",
|
|
35
35
|
"conf": "^15.1.0",
|
|
36
|
-
"ky": "^
|
|
37
|
-
"ora": "^9.
|
|
36
|
+
"ky": "^2.0.2",
|
|
37
|
+
"ora": "^9.4.1",
|
|
38
38
|
"update-notifier": "^7.3.1",
|
|
39
|
-
"@timbrix/sdk": "0.
|
|
39
|
+
"@timbrix/sdk": "1.0.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^
|
|
42
|
+
"@types/node": "^26.1.2",
|
|
43
43
|
"@types/update-notifier": "^6.0.8",
|
|
44
|
-
"eslint": "^
|
|
45
|
-
"oclif": "^4.
|
|
44
|
+
"eslint": "^10.8.0",
|
|
45
|
+
"oclif": "^4.23.29",
|
|
46
46
|
"shx": "^0.4.0",
|
|
47
|
-
"tsx": "^4.
|
|
48
|
-
"typescript": "^
|
|
49
|
-
"@repo/
|
|
50
|
-
"@repo/
|
|
47
|
+
"tsx": "^4.23.1",
|
|
48
|
+
"typescript": "^6.0.3",
|
|
49
|
+
"@repo/eslint-config": "0.1.1",
|
|
50
|
+
"@repo/typescript-config": "0.1.0"
|
|
51
51
|
},
|
|
52
52
|
"oclif": {
|
|
53
53
|
"bin": "timbrix",
|