@ltorresu82/firmagob-client 0.1.0 → 0.1.2

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 CHANGED
@@ -1,5 +1,8 @@
1
1
  # @ltorresu82/firmagob-client
2
2
 
3
+ [![CI](https://github.com/ltorresu82/firmagob-client/actions/workflows/ci.yml/badge.svg)](https://github.com/ltorresu82/firmagob-client/actions/workflows/ci.yml)
4
+ [![npm version](https://img.shields.io/npm/v/@ltorresu82/firmagob-client.svg)](https://www.npmjs.com/package/@ltorresu82/firmagob-client)
5
+
3
6
  Cliente TypeScript para integrar FirmaGob Chile sin depender de librerias PDF deprecadas.
4
7
 
5
8
  Estado inicial:
@@ -50,7 +53,7 @@ const response = await client.signHashes([
50
53
  ]);
51
54
  ```
52
55
 
53
- El JWT incluye los claims `entity`, `run`, `purpose` y `expiration`. Por defecto el token expira en 5 minutos, alineado con los ejemplos oficiales. Se puede ajustar con `tokenTtlSeconds` si el ambiente lo requiere.
56
+ El JWT incluye los claims `entity`, `run`, `purpose`, `expiration` e `iat`. Por defecto el token expira en 5 minutos, alineado con los ejemplos oficiales. `expiration` se serializa como `yyyy-MM-dd'T'HH:mm:ss`. Se puede ajustar con `tokenTtlSeconds` si el ambiente lo requiere.
54
57
 
55
58
  ## PDF con firma externa
56
59
 
@@ -102,6 +105,14 @@ El ejemplo escribe evidencia temporal en `tmp/sandbox-hash/`.
102
105
 
103
106
  Para solicitar credenciales a la institucion o al equipo FirmaGob, ver [docs/credentials.md](docs/credentials.md).
104
107
 
108
+ ## Ejemplos de integracion
109
+
110
+ Ejemplos completos con CLI Node.js, API Hono y app Astro:
111
+
112
+ ```text
113
+ https://github.com/ltorresu82/firmagob-client-examples
114
+ ```
115
+
105
116
  ## Desarrollo
106
117
 
107
118
  ```bash
@@ -35,7 +35,8 @@ export type FirmaGobSignOutput = {
35
35
  otpExpired: boolean;
36
36
  filesSigned: number;
37
37
  signedFailed: number;
38
- objectReceived: number;
38
+ objectsReceived?: number;
39
+ objectReceived?: number;
39
40
  };
40
41
  status: number;
41
42
  error?: string;
@@ -57,12 +57,14 @@ export class FirmaGobClient {
57
57
  }
58
58
  createToken(now = new Date()) {
59
59
  const tokenTtlSeconds = this.config.tokenTtlSeconds ?? DEFAULT_TOKEN_TTL_SECONDS;
60
+ const expiration = new Date(now.getTime() + tokenTtlSeconds * 1000);
60
61
  const header = base64UrlEncodeJson({ alg: "HS256", typ: "JWT" });
61
62
  const payload = base64UrlEncodeJson({
62
63
  entity: this.config.entity,
63
64
  run: this.config.run,
64
65
  purpose: this.config.purpose ?? Purpose.Unattended,
65
- expiration: new Date(now.getTime() + tokenTtlSeconds * 1000).toISOString(),
66
+ expiration: formatFirmaGobDateTime(expiration),
67
+ iat: Math.floor(now.getTime() / 1000),
66
68
  });
67
69
  const unsignedToken = `${header}.${payload}`;
68
70
  const signature = createHmac("sha256", this.config.secret)
@@ -108,6 +110,9 @@ function assertRequired(name, value) {
108
110
  function base64UrlEncodeJson(value) {
109
111
  return Buffer.from(JSON.stringify(value)).toString("base64url");
110
112
  }
113
+ function formatFirmaGobDateTime(date) {
114
+ return date.toISOString().slice(0, 19);
115
+ }
111
116
  function parseJsonResponse(body) {
112
117
  try {
113
118
  return JSON.parse(body);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ltorresu82/firmagob-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Cliente TypeScript para integrar FirmaGob Chile con firma por hash y PDFs firmados externamente",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -16,7 +16,7 @@
16
16
  "clean": "node -e \"import('node:fs').then(fs => fs.rmSync('dist', { recursive: true, force: true }))\"",
17
17
  "build": "npm run clean && tsc -p tsconfig.build.json",
18
18
  "build:test": "npm run clean && tsc -p tsconfig.json",
19
- "test": "npm run build:test && node --test dist/**/*.test.js",
19
+ "test": "npm run build:test && node --test dist/firmagob-client.test.js dist/pdf-external-signature.test.js",
20
20
  "validate:sandbox": "npm run build && node examples/sign-hash-sandbox.js",
21
21
  "validate:sandbox:dry-run": "npm run build && node examples/sign-hash-sandbox.js --dry-run",
22
22
  "publish:dry-run": "npm publish --dry-run --access public",