@eva_solutions/auth-sdk 0.0.0-stage → 3.0.0-dev-20261107051125
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/CHANGELOG.md +290 -0
- package/LICENSE +21 -0
- package/README.md +481 -2
- package/dist/admin/index.cjs +4 -0
- package/dist/admin/index.d.cts +2 -0
- package/dist/admin/index.d.ts +2 -0
- package/dist/admin/index.js +1 -0
- package/dist/admin-DjvuvuI8.js +408 -0
- package/dist/admin-DjvuvuI8.js.map +1 -0
- package/dist/admin-Q6lbWqLM.cjs +419 -0
- package/dist/admin-Q6lbWqLM.cjs.map +1 -0
- package/dist/api-path-2Ulruz7R.cjs +34 -0
- package/dist/api-path-2Ulruz7R.cjs.map +1 -0
- package/dist/api-path-B-vSkL2H.js +29 -0
- package/dist/api-path-B-vSkL2H.js.map +1 -0
- package/dist/auth-19r-Q6X2.js +84 -0
- package/dist/auth-19r-Q6X2.js.map +1 -0
- package/dist/auth-DX1N5JA4.cjs +131 -0
- package/dist/auth-DX1N5JA4.cjs.map +1 -0
- package/dist/auth-handlers-B3iJaPln.js +343 -0
- package/dist/auth-handlers-B3iJaPln.js.map +1 -0
- package/dist/auth-handlers-BTbXKJms.d.ts +15 -0
- package/dist/auth-handlers-BTbXKJms.d.ts.map +1 -0
- package/dist/auth-handlers-CDzGFDTu.cjs +404 -0
- package/dist/auth-handlers-CDzGFDTu.cjs.map +1 -0
- package/dist/auth-handlers-DRUUTEtW.d.cts +15 -0
- package/dist/auth-handlers-DRUUTEtW.d.cts.map +1 -0
- package/dist/catalog-CHPqldcj.cjs +172 -0
- package/dist/catalog-CHPqldcj.cjs.map +1 -0
- package/dist/catalog-CIqpzgsM.d.cts +75 -0
- package/dist/catalog-CIqpzgsM.d.cts.map +1 -0
- package/dist/catalog-CIqpzgsM.d.ts +75 -0
- package/dist/catalog-CIqpzgsM.d.ts.map +1 -0
- package/dist/catalog-DqPhtCKZ.js +95 -0
- package/dist/catalog-DqPhtCKZ.js.map +1 -0
- package/dist/config-D6Tr7ev6.d.cts +95 -0
- package/dist/config-D6Tr7ev6.d.cts.map +1 -0
- package/dist/config-rl4_-VAq.d.ts +95 -0
- package/dist/config-rl4_-VAq.d.ts.map +1 -0
- package/dist/constants-BE1_9Tod.cjs +52 -0
- package/dist/constants-BE1_9Tod.cjs.map +1 -0
- package/dist/constants-BY7QZokc.js +29 -0
- package/dist/constants-BY7QZokc.js.map +1 -0
- package/dist/constants-CcbhOaAP.cjs +153 -0
- package/dist/constants-CcbhOaAP.cjs.map +1 -0
- package/dist/constants-rNuD5qJn.js +94 -0
- package/dist/constants-rNuD5qJn.js.map +1 -0
- package/dist/contracts/index.cjs +1006 -0
- package/dist/contracts/index.cjs.map +1 -0
- package/dist/contracts/index.d.cts +488 -0
- package/dist/contracts/index.d.cts.map +1 -0
- package/dist/contracts/index.d.ts +488 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +817 -0
- package/dist/contracts/index.js.map +1 -0
- package/dist/cookies-DCIcr7uy.cjs +94 -0
- package/dist/cookies-DCIcr7uy.cjs.map +1 -0
- package/dist/cookies-DKEC7AWv.js +71 -0
- package/dist/cookies-DKEC7AWv.js.map +1 -0
- package/dist/delegated-token-CVNbMNfy.js +426 -0
- package/dist/delegated-token-CVNbMNfy.js.map +1 -0
- package/dist/delegated-token-DHSK4rHI.cjs +461 -0
- package/dist/delegated-token-DHSK4rHI.cjs.map +1 -0
- package/dist/error-helpers-BenWu-_u.d.ts +105 -0
- package/dist/error-helpers-BenWu-_u.d.ts.map +1 -0
- package/dist/error-helpers-KBHUbkOM.d.cts +105 -0
- package/dist/error-helpers-KBHUbkOM.d.cts.map +1 -0
- package/dist/error-helpers-XCh4ZJ-g.cjs +282 -0
- package/dist/error-helpers-XCh4ZJ-g.cjs.map +1 -0
- package/dist/error-helpers-lnwgNOw9.js +145 -0
- package/dist/error-helpers-lnwgNOw9.js.map +1 -0
- package/dist/error-messages-CGpW1fsg.d.cts +48 -0
- package/dist/error-messages-CGpW1fsg.d.cts.map +1 -0
- package/dist/error-messages-CGpW1fsg.d.ts +48 -0
- package/dist/error-messages-CGpW1fsg.d.ts.map +1 -0
- package/dist/event-codes-BBJHon-I.cjs +48 -0
- package/dist/event-codes-BBJHon-I.cjs.map +1 -0
- package/dist/event-codes-BgcJWsov.d.cts +42 -0
- package/dist/event-codes-BgcJWsov.d.cts.map +1 -0
- package/dist/event-codes-BgcJWsov.d.ts +42 -0
- package/dist/event-codes-BgcJWsov.d.ts.map +1 -0
- package/dist/event-codes-DR5_VlaR.js +43 -0
- package/dist/event-codes-DR5_VlaR.js.map +1 -0
- package/dist/generic/index.cjs +91 -0
- package/dist/generic/index.cjs.map +1 -0
- package/dist/generic/index.d.cts +27 -0
- package/dist/generic/index.d.cts.map +1 -0
- package/dist/generic/index.d.ts +27 -0
- package/dist/generic/index.d.ts.map +1 -0
- package/dist/generic/index.js +80 -0
- package/dist/generic/index.js.map +1 -0
- package/dist/hono/index.cjs +309 -0
- package/dist/hono/index.cjs.map +1 -0
- package/dist/hono/index.d.cts +272 -0
- package/dist/hono/index.d.cts.map +1 -0
- package/dist/hono/index.d.ts +272 -0
- package/dist/hono/index.d.ts.map +1 -0
- package/dist/hono/index.js +290 -0
- package/dist/hono/index.js.map +1 -0
- package/dist/hono-openapi/index.cjs +326 -0
- package/dist/hono-openapi/index.cjs.map +1 -0
- package/dist/hono-openapi/index.d.cts +14 -0
- package/dist/hono-openapi/index.d.cts.map +1 -0
- package/dist/hono-openapi/index.d.ts +14 -0
- package/dist/hono-openapi/index.d.ts.map +1 -0
- package/dist/hono-openapi/index.js +307 -0
- package/dist/hono-openapi/index.js.map +1 -0
- package/dist/http-client-BVF3iktR.cjs +211 -0
- package/dist/http-client-BVF3iktR.cjs.map +1 -0
- package/dist/http-client-Da0-OMfc.js +206 -0
- package/dist/http-client-Da0-OMfc.js.map +1 -0
- package/dist/index-BYzDaMR9.d.ts +312 -0
- package/dist/index-BYzDaMR9.d.ts.map +1 -0
- package/dist/index-CNNMCrdl.d.ts +66 -0
- package/dist/index-CNNMCrdl.d.ts.map +1 -0
- package/dist/index-DBZoLU4E.d.ts +240 -0
- package/dist/index-DBZoLU4E.d.ts.map +1 -0
- package/dist/index-DcvQWByo.d.cts +66 -0
- package/dist/index-DcvQWByo.d.cts.map +1 -0
- package/dist/index-Dold-Ycb.d.cts +1711 -0
- package/dist/index-Dold-Ycb.d.cts.map +1 -0
- package/dist/index-Dold-Ycb.d.ts +1711 -0
- package/dist/index-Dold-Ycb.d.ts.map +1 -0
- package/dist/index-jAO62-OD.d.cts +240 -0
- package/dist/index-jAO62-OD.d.cts.map +1 -0
- package/dist/index-o7nXcl7z.d.cts +312 -0
- package/dist/index-o7nXcl7z.d.cts.map +1 -0
- package/dist/index.cjs +89 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +114 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +114 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/jwt-BBNqk0TV.cjs +155 -0
- package/dist/jwt-BBNqk0TV.cjs.map +1 -0
- package/dist/jwt-DhqgH94B.js +150 -0
- package/dist/jwt-DhqgH94B.js.map +1 -0
- package/dist/key-resolver-CESqj4-P.cjs +45 -0
- package/dist/key-resolver-CESqj4-P.cjs.map +1 -0
- package/dist/key-resolver-D56I2Zpz.js +34 -0
- package/dist/key-resolver-D56I2Zpz.js.map +1 -0
- package/dist/parse-error-response-6qOQS5y9.cjs +316 -0
- package/dist/parse-error-response-6qOQS5y9.cjs.map +1 -0
- package/dist/parse-error-response-BM9-kjs0.js +239 -0
- package/dist/parse-error-response-BM9-kjs0.js.map +1 -0
- package/dist/path-segment-C25i6aaH.cjs +29 -0
- package/dist/path-segment-C25i6aaH.cjs.map +1 -0
- package/dist/path-segment-CyqnaFrP.js +24 -0
- package/dist/path-segment-CyqnaFrP.js.map +1 -0
- package/dist/react/index.cjs +336 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +151 -0
- package/dist/react/index.d.cts.map +1 -0
- package/dist/react/index.d.ts +151 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +300 -0
- package/dist/react/index.js.map +1 -0
- package/dist/refresh-dedup-CKaHHe7m.js +14 -0
- package/dist/refresh-dedup-CKaHHe7m.js.map +1 -0
- package/dist/refresh-dedup-CLdACQXR.cjs +19 -0
- package/dist/refresh-dedup-CLdACQXR.cjs.map +1 -0
- package/dist/rolldown-runtime-CmQyd0Gu.cjs +27 -0
- package/dist/routes-DpAzgY1V.cjs +424 -0
- package/dist/routes-DpAzgY1V.cjs.map +1 -0
- package/dist/routes-F1g5aVqP.js +347 -0
- package/dist/routes-F1g5aVqP.js.map +1 -0
- package/dist/s2s/index.cjs +24 -0
- package/dist/s2s/index.d.cts +5 -0
- package/dist/s2s/index.d.ts +5 -0
- package/dist/s2s/index.js +5 -0
- package/dist/s2s-6wbotr78.cjs +926 -0
- package/dist/s2s-6wbotr78.cjs.map +1 -0
- package/dist/s2s-B_0SIQzn.js +897 -0
- package/dist/s2s-B_0SIQzn.js.map +1 -0
- package/dist/sign-C7y6xdvT.cjs +324 -0
- package/dist/sign-C7y6xdvT.cjs.map +1 -0
- package/dist/sign-HFtcYwa-.js +259 -0
- package/dist/sign-HFtcYwa-.js.map +1 -0
- package/dist/tokens-C1nzkn21.cjs +232 -0
- package/dist/tokens-C1nzkn21.cjs.map +1 -0
- package/dist/tokens-C3Z40qd7.js +107 -0
- package/dist/tokens-C3Z40qd7.js.map +1 -0
- package/dist/types-B5sf7kKE.d.cts +52 -0
- package/dist/types-B5sf7kKE.d.cts.map +1 -0
- package/dist/types-CLOIHzRu.d.ts +96 -0
- package/dist/types-CLOIHzRu.d.ts.map +1 -0
- package/dist/types-CQTZdZIF.d.ts +52 -0
- package/dist/types-CQTZdZIF.d.ts.map +1 -0
- package/dist/types-DGeQ8j4k.d.cts +538 -0
- package/dist/types-DGeQ8j4k.d.cts.map +1 -0
- package/dist/types-DIUWza9-.d.ts +538 -0
- package/dist/types-DIUWza9-.d.ts.map +1 -0
- package/dist/types-qh6ANBCV.d.cts +96 -0
- package/dist/types-qh6ANBCV.d.cts.map +1 -0
- package/dist/webhooks/index.cjs +8 -0
- package/dist/webhooks/index.d.cts +5 -0
- package/dist/webhooks/index.d.ts +5 -0
- package/dist/webhooks/index.js +4 -0
- package/dist/webhooks-B5sAWC9W.js +74 -0
- package/dist/webhooks-B5sAWC9W.js.map +1 -0
- package/dist/webhooks-Cx11psg1.cjs +79 -0
- package/dist/webhooks-Cx11psg1.cjs.map +1 -0
- package/package.json +192 -3
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { Ar as UsersBatchResponse, At as CreateEmpresaRequest, Bt as ListEmpresasQuery, C as DeleteAutorizacionRequest, Ft as EmpresaMemberResponse, H as DirectorioQuery, J as CreateGrupoRequest, Jt as UpdateEmpresaMemberRequest, Lt as EmpresaRecortadaResponse, Mt as DeactivateSucursalRequest, Nt as EmpresaDetailResponse, O as VerificarAutorizacionQuery, Pt as EmpresaEstadoResponse, Q as RenameGrupoRequest, Rt as EmpresaResponse, S as CreateAutorizacionRequest, T as ListAutorizacionesResponse, U as DirectorioResponse, Vt as ListEmpresasResponse, Wt as RemoveEmpresaMemberRequest, X as GrupoResponse, Xt as UpdateSucursalRequest, Yt as UpdateEmpresaRequest, Z as RemoveGrupoEmpresaRequest, ar as CreateSubscriptionRequest, ct as SetContratacionRequest, gr as UpdateSubscriptionRequest, jt as CreateSucursalRequest, k as VerificarAutorizacionResponse, kr as UsersBatchRequest, kt as AddEmpresaMemberRequest, ot as ContratacionResponse, q as AddGrupoEmpresaRequest, qt as SucursalResponse, st as ContratadoResponse, w as ListAutorizacionesQuery, x as AutorizacionResponse, zr as ProfileResponse, zt as GetEmpresaResponse } from "./index-Dold-Ycb.js";
|
|
2
|
+
import { f as ServiceAudience, i as DelegableAudience } from "./catalog-CIqpzgsM.js";
|
|
3
|
+
import { d as Result } from "./types-CLOIHzRu.js";
|
|
4
|
+
import "./types-CQTZdZIF.js";
|
|
5
|
+
import { JWTVerifyGetKey } from "jose";
|
|
6
|
+
/** Tolerancia por defecto al desfase de relojes, en segundos. */
|
|
7
|
+
declare const SERVICE_TOKEN_CLOCK_TOLERANCE_SECONDS = 5;
|
|
8
|
+
/**
|
|
9
|
+
* Motivos de rechazo de `verifyServiceToken`.
|
|
10
|
+
*
|
|
11
|
+
* - `token_missing` — no hay `Authorization: Bearer <jwt>` (solo lo produce el middleware).
|
|
12
|
+
* - `token_malformed` — no es un JWT bien formado.
|
|
13
|
+
* - `token_expired` — `exp` ya pasó (más la tolerancia).
|
|
14
|
+
* - `signature_invalid` — firma inválida, `kid` ausente, de otro tipo o desconocido, o algoritmo distinto de ES256.
|
|
15
|
+
* - `claims_invalid` — `typ`, `iss`, `aud`, `sub`, `client_id`, `iat`/`exp` ausentes o fuera de rango, o vida mayor al máximo.
|
|
16
|
+
* - `scope_insufficient` — el claim `scope` no cubre el permiso requerido.
|
|
17
|
+
*/
|
|
18
|
+
type ServiceTokenVerifyReason = 'token_missing' | 'token_malformed' | 'token_expired' | 'signature_invalid' | 'claims_invalid' | 'scope_insufficient';
|
|
19
|
+
type ServiceTokenVerifyError = {
|
|
20
|
+
reason: ServiceTokenVerifyReason;
|
|
21
|
+
message: string;
|
|
22
|
+
};
|
|
23
|
+
/** Datos verificados del token de servicio. */
|
|
24
|
+
type ServiceTokenClaims = {
|
|
25
|
+
/** `sub`: id interno estable del service client. Es la identidad; no cambia ni se reutiliza. */
|
|
26
|
+
serviceClientId: string;
|
|
27
|
+
/** `client_id`: slug del service client. Dato visible (logs, UI); no usarlo como identidad. */
|
|
28
|
+
serviceClientSlug: string;
|
|
29
|
+
/** Permisos del claim `scope` (separado por espacios). */
|
|
30
|
+
scopes: readonly string[];
|
|
31
|
+
/** `jti` del token, si lo trae. */
|
|
32
|
+
jti: string | undefined;
|
|
33
|
+
};
|
|
34
|
+
type ServiceTokenVerifyResult = {
|
|
35
|
+
ok: true;
|
|
36
|
+
data: ServiceTokenClaims;
|
|
37
|
+
} | {
|
|
38
|
+
ok: false;
|
|
39
|
+
error: ServiceTokenVerifyError;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Permiso exigido: uno concreto (`requiredScope`), al menos uno de varios (`anyScope`) o
|
|
43
|
+
* `scopeCheck: 'deferred'`, que no exige ninguno aquí y deja el permiso por ruta a `requireScope`
|
|
44
|
+
* (cadena Bearer + permiso por ruta). Es explícito para que olvidar el permiso no abra la ruta.
|
|
45
|
+
*/
|
|
46
|
+
type ServiceTokenScopeRequirement = {
|
|
47
|
+
requiredScope: string;
|
|
48
|
+
anyScope?: never;
|
|
49
|
+
scopeCheck?: never;
|
|
50
|
+
} | {
|
|
51
|
+
anyScope: readonly string[];
|
|
52
|
+
requiredScope?: never;
|
|
53
|
+
scopeCheck?: never;
|
|
54
|
+
} | {
|
|
55
|
+
scopeCheck: 'deferred';
|
|
56
|
+
requiredScope?: never;
|
|
57
|
+
anyScope?: never;
|
|
58
|
+
};
|
|
59
|
+
type ServiceTokenVerifyOptions = ServiceTokenScopeRequirement & {
|
|
60
|
+
/**
|
|
61
|
+
* Audiencia propia del servicio receptor (`'whatsapp-api'`), del catálogo de `auth-contracts`.
|
|
62
|
+
* Un slug de producto o cualquier otro valor lanza `TypeError`.
|
|
63
|
+
*/
|
|
64
|
+
audience: ServiceAudience;
|
|
65
|
+
/**
|
|
66
|
+
* Resolutor de claves. Por defecto el JWKS remoto del Auth Service (`getJwksKeyFn()`, requiere
|
|
67
|
+
* `configureEvaAuth({ authUrl })`). Inyectable para tests. Siempre se filtra por el prefijo
|
|
68
|
+
* `svc-`, también el inyectado.
|
|
69
|
+
*/
|
|
70
|
+
jwks?: JWTVerifyGetKey;
|
|
71
|
+
/** Vida máxima aceptada (`exp - iat`). Default: `SERVICE_TOKEN_LIFETIME_SECONDS` (300). */
|
|
72
|
+
maxLifetimeSeconds?: number;
|
|
73
|
+
/** Tolerancia de reloj. Default: `SERVICE_TOKEN_CLOCK_TOLERANCE_SECONDS` (5). */
|
|
74
|
+
clockToleranceSeconds?: number;
|
|
75
|
+
/** Overrides de mensajes (i18n). Las keys no provistas usan el default en inglés. */
|
|
76
|
+
messages?: Partial<Record<ServiceTokenVerifyReason, string>>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Verifica un token de servicio.
|
|
80
|
+
*
|
|
81
|
+
* Contrato del token (lo emite el Auth Service):
|
|
82
|
+
* - Header: `alg: 'ES256'`, `typ: 'svc-at+jwt'`, `kid` con prefijo `svc-`.
|
|
83
|
+
* - Claims: `iss: 'auth-service'`, `aud` (una sola, la del receptor), `sub` (id del service
|
|
84
|
+
* client), `client_id` (su slug), `scope` (separado por espacios), `iat`, `exp` (con
|
|
85
|
+
* `exp - iat` <= `maxLifetimeSeconds`) y `jti`.
|
|
86
|
+
*
|
|
87
|
+
* Un token de servicio es reutilizable dentro de su vida: no hay replay cache.
|
|
88
|
+
*
|
|
89
|
+
* @throws `TypeError` si `audience` no es del catálogo, si no se indica exactamente uno de
|
|
90
|
+
* `requiredScope` / `anyScope`, o si un permiso no pertenece a la audiencia.
|
|
91
|
+
* @throws Error de configuración (`EvaAuthConfigError`) si falta `authUrl` y no se inyecta `jwks`, y
|
|
92
|
+
* los fallos de red del JWKS: son errores de infraestructura, no un token inválido, así que no
|
|
93
|
+
* se degradan a un rechazo.
|
|
94
|
+
*/
|
|
95
|
+
declare function verifyServiceToken(token: string, opts: ServiceTokenVerifyOptions): Promise<ServiceTokenVerifyResult>;
|
|
96
|
+
/** Motivos de rechazo: los mismos que los del token de servicio. */
|
|
97
|
+
type DelegatedTokenVerifyReason = ServiceTokenVerifyReason;
|
|
98
|
+
type DelegatedTokenVerifyError = {
|
|
99
|
+
reason: DelegatedTokenVerifyReason;
|
|
100
|
+
message: string;
|
|
101
|
+
};
|
|
102
|
+
/** Un actor de la cadena: el servicio que intercambió el token. */
|
|
103
|
+
type DelegatedActor = {
|
|
104
|
+
/** `act.sub`: id interno estable del service client. */
|
|
105
|
+
serviceClientId: string;
|
|
106
|
+
/** `act.client_id`: slug del service client. Dato visible, no identidad. */
|
|
107
|
+
serviceClientSlug: string;
|
|
108
|
+
};
|
|
109
|
+
/** Datos verificados del token delegado. */
|
|
110
|
+
type DelegatedTokenClaims = {
|
|
111
|
+
/** `sub`: el usuario en cuyo nombre se actúa. */
|
|
112
|
+
userId: string;
|
|
113
|
+
/** `empresa`: obligatoria e inmutable en toda la cadena. */
|
|
114
|
+
empresaId: string;
|
|
115
|
+
/** `producto`: producto de origen de la cadena. */
|
|
116
|
+
producto: string;
|
|
117
|
+
/** `sid`: sesión de origen. */
|
|
118
|
+
sessionId: string;
|
|
119
|
+
/**
|
|
120
|
+
* Cadena de actores, del último (quien llama a este servicio) al primero (quien partió del
|
|
121
|
+
* access token del usuario). Siempre tiene al menos uno y como máximo `DELEGATED_TOKEN_MAX_DEPTH`.
|
|
122
|
+
*/
|
|
123
|
+
actorChain: readonly DelegatedActor[];
|
|
124
|
+
/** `client_id` del token: slug del actor, para logs y rate limit. */
|
|
125
|
+
clientId: string;
|
|
126
|
+
/** Permisos del claim `scope` (separado por espacios). */
|
|
127
|
+
scopes: readonly string[];
|
|
128
|
+
/** `jti` del token (obligatorio). */
|
|
129
|
+
jti: string;
|
|
130
|
+
};
|
|
131
|
+
type DelegatedTokenVerifyResult = {
|
|
132
|
+
ok: true;
|
|
133
|
+
data: DelegatedTokenClaims;
|
|
134
|
+
} | {
|
|
135
|
+
ok: false;
|
|
136
|
+
error: DelegatedTokenVerifyError;
|
|
137
|
+
};
|
|
138
|
+
type DelegatedTokenVerifyOptions = ServiceTokenScopeRequirement & {
|
|
139
|
+
/**
|
|
140
|
+
* Audiencia propia del servicio receptor, del catálogo delegable de `auth-contracts`. `auth-api`
|
|
141
|
+
* (o cualquier otro valor) lanza `TypeError`: Auth nunca es destino de un token delegado.
|
|
142
|
+
*/
|
|
143
|
+
audience: DelegableAudience;
|
|
144
|
+
/** Resolutor de claves; por defecto el JWKS remoto. Siempre se filtra por el prefijo `svc-`. */
|
|
145
|
+
jwks?: JWTVerifyGetKey;
|
|
146
|
+
/** Vida máxima aceptada (`exp - iat`). Default: `DELEGATED_TOKEN_LIFETIME_SECONDS` (120). */
|
|
147
|
+
maxLifetimeSeconds?: number;
|
|
148
|
+
/** Tolerancia de reloj. Default: 5 s. */
|
|
149
|
+
clockToleranceSeconds?: number;
|
|
150
|
+
/** Overrides de mensajes (i18n). */
|
|
151
|
+
messages?: Partial<Record<DelegatedTokenVerifyReason, string>>;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Verifica un token delegado.
|
|
155
|
+
*
|
|
156
|
+
* Contrato del token (lo emite el Auth Service en `POST /internal/token-exchange`):
|
|
157
|
+
* - Header: `alg: 'ES256'`, `typ: 'dlg-at+jwt'`, `kid` con prefijo `svc-`.
|
|
158
|
+
* - Claims: `iss: 'auth-service'`, `aud` (una sola, la del receptor), `sub` (el usuario),
|
|
159
|
+
* `client_id`, `act` (cadena de actores), `empresa`, `producto` y `sid` (obligatorios: la
|
|
160
|
+
* empresa es inmutable en la cadena), `scope`, `iat`, `exp` (con `exp - iat` <=
|
|
161
|
+
* `maxLifetimeSeconds`) y `jti`.
|
|
162
|
+
*
|
|
163
|
+
* Un token delegado sin empresa se rechaza (`claims_invalid`): la delegación sin empresa no existe.
|
|
164
|
+
* Es reutilizable dentro de su vida (120 s): no hay replay cache.
|
|
165
|
+
*
|
|
166
|
+
* @throws `TypeError` si `audience` no es delegable o los permisos exigidos no lo son.
|
|
167
|
+
* @throws Error de configuración si falta `authUrl` y no se inyecta `jwks`, y los fallos de red del
|
|
168
|
+
* JWKS (son de infraestructura, no un token inválido).
|
|
169
|
+
*/
|
|
170
|
+
declare function verifyDelegatedToken(token: string, opts: DelegatedTokenVerifyOptions): Promise<DelegatedTokenVerifyResult>;
|
|
171
|
+
/** Cuánto antes del vencimiento se renueva el token, en milisegundos. */
|
|
172
|
+
declare const SERVICE_TOKEN_RENEW_MARGIN_MS = 30000;
|
|
173
|
+
type ServiceTokenProviderConfig = {
|
|
174
|
+
/**
|
|
175
|
+
* URL base del Auth Service (sin `/api/v1`). Se requiere https (o http con host loopback para
|
|
176
|
+
* tests); admite path (`https://host/auth`).
|
|
177
|
+
*/
|
|
178
|
+
authUrl: string;
|
|
179
|
+
/** Slug del service client (`clientId`) que firma el pedido. */
|
|
180
|
+
clientId: string;
|
|
181
|
+
/** Clave del service client en hex (64 chars). Nunca viaja: solo firma el pedido. */
|
|
182
|
+
secretHex: string;
|
|
183
|
+
/** Servicio destino del token (`'auth-api'`, `'whatsapp-api'`). */
|
|
184
|
+
audience: string;
|
|
185
|
+
/** Permisos pedidos separados por espacio. Si falta, se piden todos los concedidos. */
|
|
186
|
+
scope?: string;
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* What the clients that call a service need from a provider: a token and a way to drop a rejected
|
|
190
|
+
* one. `createServiceTokenProvider` returns more ({@link ServiceTokenProvider}); a hand-made source
|
|
191
|
+
* (tests, another credential flow) only needs these two.
|
|
192
|
+
*/
|
|
193
|
+
type ServiceTokenSource = {
|
|
194
|
+
/**
|
|
195
|
+
* Devuelve un token vigente: el guardado mientras falten más de 30 s para su vencimiento, o uno
|
|
196
|
+
* nuevo. Los pedidos simultáneos comparten una sola llamada al Auth Service.
|
|
197
|
+
* @throws {ServiceTokenRequestError} si el Auth Service rechaza el pedido; `Error` de red si no responde.
|
|
198
|
+
*/
|
|
199
|
+
getToken(): Promise<string>;
|
|
200
|
+
/**
|
|
201
|
+
* Descarta el token guardado para que la próxima `getToken()` pida uno nuevo. Úsalo cuando el
|
|
202
|
+
* servicio destino responde 401 con un token que creías vigente, pasando ESE token:
|
|
203
|
+
* solo se descarta si sigue siendo el guardado. Así, N respuestas 401 simultáneas del mismo
|
|
204
|
+
* token provocan UN pedido nuevo (la primera descarta; las demás ven que ya no es el guardado
|
|
205
|
+
* y comparten el pedido en curso o el token renovado). Nunca descarta un pedido en curso.
|
|
206
|
+
* Sin argumento descarta el token guardado, sea cual sea.
|
|
207
|
+
*/
|
|
208
|
+
invalidate(rejectedToken?: string): void;
|
|
209
|
+
};
|
|
210
|
+
/** Input of {@link ServiceTokenProvider.exchangeToken}. */
|
|
211
|
+
type ExchangeTokenInput = {
|
|
212
|
+
/**
|
|
213
|
+
* Token to exchange: the access token of the user (`aud` = product of this actor) or a delegated
|
|
214
|
+
* token (`aud` = audience of this actor, for a re-exchange). Pass one your service has ALREADY
|
|
215
|
+
* verified (`verifyAccessToken`, `verifyDelegatedToken` or the middleware): the SDK does not.
|
|
216
|
+
*/
|
|
217
|
+
subjectToken: string;
|
|
218
|
+
/** Destination service of the delegated token: one audience with a delegation edge from this client. Never `auth-api`. */
|
|
219
|
+
audience: string;
|
|
220
|
+
/** Permissions asked for, separated by space. If absent, everything delegable on that edge. */
|
|
221
|
+
scope?: string;
|
|
222
|
+
};
|
|
223
|
+
/** A delegated token (`typ: dlg-at+jwt`) and the permissions it carries. */
|
|
224
|
+
type DelegatedTokenGrant = {
|
|
225
|
+
accessToken: string;
|
|
226
|
+
/** Permissions issued, separated by space (they can be fewer than asked for). */
|
|
227
|
+
scope: string;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Provider of service tokens for ONE (audience, scope), plus the token exchange of the same client.
|
|
231
|
+
*/
|
|
232
|
+
type ServiceTokenProvider = ServiceTokenSource & {
|
|
233
|
+
/**
|
|
234
|
+
* Exchanges a subject token for a delegated one (RFC 8693) so this service can call another one
|
|
235
|
+
* on behalf of the user. Authenticates with its own service token (`aud: auth-api`, permission
|
|
236
|
+
* `tokens:exchange`), which it obtains and renews by itself whatever the audience of this
|
|
237
|
+
* provider is.
|
|
238
|
+
*
|
|
239
|
+
* Caches the delegated token in this isolate until 30 s before its `exp` (it lives 120 s). The
|
|
240
|
+
* key is the audience, the scope and a fingerprint of the WHOLE subject token: a token with other
|
|
241
|
+
* claims (another session, user or company), or the same re-exchanged from another token of the
|
|
242
|
+
* chain (other `jti`), never reuses an entry. Errors are not cached.
|
|
243
|
+
*
|
|
244
|
+
* Returns a Result: `invalid_grant` (session closed, user or company out, product not contracted,
|
|
245
|
+
* depth or cycle) is a normal answer, not an exception. The failures of Auth keep their RFC code
|
|
246
|
+
* in `error.code` (`invalid_grant`, `invalid_target`, `invalid_scope`, `invalid_client`, ...).
|
|
247
|
+
*/
|
|
248
|
+
exchangeToken(input: ExchangeTokenInput): Promise<Result<DelegatedTokenGrant>>;
|
|
249
|
+
};
|
|
250
|
+
/** El Auth Service rechazó el pedido de token. `code` es el `error` de RFC 6749 (`invalid_client`, …). */
|
|
251
|
+
declare class ServiceTokenRequestError extends Error {
|
|
252
|
+
readonly code: string;
|
|
253
|
+
readonly status: number;
|
|
254
|
+
/** Segundos de espera que pidió Auth con `Retry-After` (429 / 503), si los mandó. */
|
|
255
|
+
readonly retryAfterSeconds?: number;
|
|
256
|
+
constructor(code: string, status: number, description?: string, retryAfterSeconds?: number);
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Crea un proveedor de tokens de servicio.
|
|
260
|
+
*
|
|
261
|
+
* Deduplica los pedidos simultáneos dentro del mismo proceso (isolate): N llamadas concurrentes a
|
|
262
|
+
* `getToken()` con el caché vacío o vencido hacen UN pedido al Auth Service. Un pedido fallido no
|
|
263
|
+
* se guarda: la siguiente llamada reintenta.
|
|
264
|
+
*
|
|
265
|
+
* Valida su configuración al crearse (audiencia del catálogo, permisos de esa audiencia, clave hex).
|
|
266
|
+
*
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* const provider = createServiceTokenProvider({
|
|
270
|
+
* authUrl: env.AUTH_URL,
|
|
271
|
+
* clientId: env.AUTH_CLIENT_ID,
|
|
272
|
+
* secretHex: env.AUTH_CLIENT_SECRET_HEX,
|
|
273
|
+
* audience: 'auth-api',
|
|
274
|
+
* })
|
|
275
|
+
* const s2s = createS2SClient({ baseUrl: env.AUTH_URL, tokenProvider: provider })
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
declare function createServiceTokenProvider(config: ServiceTokenProviderConfig): ServiceTokenProvider;
|
|
279
|
+
/**
|
|
280
|
+
* Configuración del cliente S2S.
|
|
281
|
+
*/
|
|
282
|
+
type S2SClientConfig = {
|
|
283
|
+
/**
|
|
284
|
+
* URL base del Auth Service API (sin trailing slash).
|
|
285
|
+
* Validada en `createS2SClient`: se requiere https (o http con host loopback para tests).
|
|
286
|
+
*/
|
|
287
|
+
baseUrl: string;
|
|
288
|
+
/**
|
|
289
|
+
* Proveedor del token de servicio con audiencia `auth-api` (`createServiceTokenProvider`). El
|
|
290
|
+
* cliente lo usa en cada llamada y, ante un 401, lo invalida y reintenta una vez.
|
|
291
|
+
*/
|
|
292
|
+
tokenProvider: ServiceTokenSource;
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* Partes del request necesarias para construir el canonical string SigV4-style
|
|
296
|
+
* (7 líneas: método, path, query, timestamp, nonce, clientId, hash del body).
|
|
297
|
+
*/
|
|
298
|
+
type S2SCanonicalParts = {
|
|
299
|
+
/** HTTP method en uppercase (GET, POST, PATCH, DELETE). */
|
|
300
|
+
method: string;
|
|
301
|
+
/** Pathname del request sin query string ni fragment. */
|
|
302
|
+
path: string;
|
|
303
|
+
/** Query string crudo (sin el `?`). String vacío si no hay query. */
|
|
304
|
+
rawQuery: string;
|
|
305
|
+
/** Unix timestamp en segundos como string decimal. */
|
|
306
|
+
timestamp: string;
|
|
307
|
+
/** Nonce del request: 32 hex en minúsculas (ver `generateS2SNonce`). */
|
|
308
|
+
nonce: string;
|
|
309
|
+
/** Slug del service client (clientId). */
|
|
310
|
+
clientId: string;
|
|
311
|
+
/** Bytes raw del body. GET/sin body → `new Uint8Array(0)`. */
|
|
312
|
+
bodyBytes: Uint8Array;
|
|
313
|
+
};
|
|
314
|
+
/**
|
|
315
|
+
* Resultado de `getUser` — perfil público del usuario (alias del `data` de la respuesta del
|
|
316
|
+
* contrato). El wire es `{ data: perfil }` y `result.data` es el perfil directamente, sin
|
|
317
|
+
* envoltorio. Un usuario inexistente o soft-deleted llega como error `user_not_found` (404).
|
|
318
|
+
*/
|
|
319
|
+
type S2SGetUserResult = ProfileResponse['data'];
|
|
320
|
+
/**
|
|
321
|
+
* Input para `batchUsers` — lista de IDs a consultar (alias del request del contrato).
|
|
322
|
+
* El tope de `USERS_BATCH_MAX_IDS` lo aplica el cliente, no el tipo.
|
|
323
|
+
*/
|
|
324
|
+
type S2SBatchUsersInput = UsersBatchRequest;
|
|
325
|
+
/**
|
|
326
|
+
* Resultado de `batchUsers` — usuarios activos encontrados (alias del `data` de la respuesta del
|
|
327
|
+
* contrato). IDs inválidos, inexistentes o soft-deleted se omiten.
|
|
328
|
+
*/
|
|
329
|
+
type S2SBatchUsersResult = UsersBatchResponse['data'];
|
|
330
|
+
/**
|
|
331
|
+
* Input para crear una subscription de webhook (alias del request del contrato): `url` donde el
|
|
332
|
+
* Auth Service enviará los eventos, `eventCodes` a suscribir (al menos uno) y `enabled` (por
|
|
333
|
+
* defecto `true` en el API).
|
|
334
|
+
*/
|
|
335
|
+
type CreateWebhookSubscriptionInput = CreateSubscriptionRequest;
|
|
336
|
+
/**
|
|
337
|
+
* Input para actualizar una subscription de webhook (patch parcial; alias del request del
|
|
338
|
+
* contrato).
|
|
339
|
+
*/
|
|
340
|
+
type UpdateWebhookSubscriptionInput = UpdateSubscriptionRequest;
|
|
341
|
+
/**
|
|
342
|
+
* Query params para listar deliveries.
|
|
343
|
+
*
|
|
344
|
+
* Tipo propio del SDK, no alias del contrato: el query del contrato coacciona strings a números y
|
|
345
|
+
* por eso su tipo de entrada es `unknown`; aquí `limit` y `offset` son `number`.
|
|
346
|
+
*/
|
|
347
|
+
type ListWebhookDeliveriesQuery = {
|
|
348
|
+
event_id?: string;
|
|
349
|
+
subscription_id?: string;
|
|
350
|
+
status?: 'pending' | 'delivering' | 'success' | 'expired';
|
|
351
|
+
limit?: number;
|
|
352
|
+
offset?: number;
|
|
353
|
+
};
|
|
354
|
+
/**
|
|
355
|
+
* Toda acción de una persona sobre una empresa lleva su access token como `subjectToken`: el
|
|
356
|
+
* backend del producto manda su token de servicio y, en el body, el token de la persona.
|
|
357
|
+
*/
|
|
358
|
+
type SubjectTokenInput = RemoveEmpresaMemberRequest;
|
|
359
|
+
/**
|
|
360
|
+
* Input para crear una empresa (alias del request del contrato). La persona del `subjectToken`
|
|
361
|
+
* queda como titular y el producto del actor queda en `prueba`.
|
|
362
|
+
*/
|
|
363
|
+
type CreateEmpresaInput = CreateEmpresaRequest;
|
|
364
|
+
/** Input para editar datos maestros, perfil y visibilidad (RUC y slug son inmutables). */
|
|
365
|
+
type UpdateEmpresaInput = UpdateEmpresaRequest;
|
|
366
|
+
/** Query de `listEmpresas`: `q` y `cursor` (la siguiente página sale de `nextCursor`). */
|
|
367
|
+
type ListEmpresasInput = ListEmpresasQuery;
|
|
368
|
+
/** Página de empresas contratadas por el producto del actor. */
|
|
369
|
+
type ListEmpresasResult = ListEmpresasResponse['data'];
|
|
370
|
+
/** Input para agregar un miembro (entra como `miembro`). */
|
|
371
|
+
type AddEmpresaMemberInput = AddEmpresaMemberRequest;
|
|
372
|
+
/** Input para cambiar el rol de un miembro (solo el titular). */
|
|
373
|
+
type UpdateEmpresaMemberInput = UpdateEmpresaMemberRequest;
|
|
374
|
+
/** Input para quitar un miembro; `userId` = la persona del token es salir por cuenta propia. */
|
|
375
|
+
type RemoveEmpresaMemberInput = RemoveEmpresaMemberRequest;
|
|
376
|
+
/** Input para crear una sucursal (alias del request del contrato). */
|
|
377
|
+
type CreateSucursalInput = CreateSucursalRequest;
|
|
378
|
+
/** Input para editar una sucursal. */
|
|
379
|
+
type UpdateSucursalInput = UpdateSucursalRequest;
|
|
380
|
+
/** Input para dar de baja lógica una sucursal (`activa = false`). */
|
|
381
|
+
type DeactivateSucursalInput = DeactivateSucursalRequest;
|
|
382
|
+
/** Empresa creada o editada (`data` de la respuesta). */
|
|
383
|
+
type EmpresaResult = EmpresaResponse['data'];
|
|
384
|
+
/** Vista completa de una empresa: el actor tiene su producto contratado (`vista: 'completa'`). */
|
|
385
|
+
type EmpresaDetailResult = EmpresaDetailResponse['data'];
|
|
386
|
+
/** Vista recortada para un actor sin producto: sin contacto ni miembros (`vista: 'recortada'`). */
|
|
387
|
+
type EmpresaRecortadaResult = EmpresaRecortadaResponse['data'];
|
|
388
|
+
/** Resultado de `getEmpresa`: una de las dos vistas, distinguidas por `vista`. */
|
|
389
|
+
type GetEmpresaResult = GetEmpresaResponse['data'];
|
|
390
|
+
/** Miembro agregado o con rol cambiado (`data` de la respuesta). */
|
|
391
|
+
type EmpresaMemberResult = EmpresaMemberResponse['data'];
|
|
392
|
+
/** Sucursal creada o editada (`data` de la respuesta). */
|
|
393
|
+
type SucursalResult = SucursalResponse['data'];
|
|
394
|
+
/** Estado de la empresa tras `bajaEmpresa` / `reactivarEmpresa`. */
|
|
395
|
+
type EmpresaEstadoResult = EmpresaEstadoResponse['data'];
|
|
396
|
+
/** Contratación de un producto por una empresa. */
|
|
397
|
+
type ContratacionResult = ContratacionResponse['data'];
|
|
398
|
+
/** Input de `setContratacion` (facturación y admin): estado y vencimiento. */
|
|
399
|
+
type SetContratacionInput = SetContratacionRequest;
|
|
400
|
+
/** `{ contratado }`: ¿la empresa tiene el producto en `prueba` o `activo` y sin vencer? */
|
|
401
|
+
type ContratadoResult = ContratadoResponse['data'];
|
|
402
|
+
/** Input para crear un grupo con una empresa de la persona. */
|
|
403
|
+
type CreateGrupoInput = CreateGrupoRequest;
|
|
404
|
+
/** Input para renombrar un grupo. */
|
|
405
|
+
type RenameGrupoInput = RenameGrupoRequest;
|
|
406
|
+
/** Input para agregar una empresa a un grupo. */
|
|
407
|
+
type AddGrupoEmpresaInput = AddGrupoEmpresaRequest;
|
|
408
|
+
/** Input para quitar una empresa de un grupo. */
|
|
409
|
+
type RemoveGrupoEmpresaInput = RemoveGrupoEmpresaRequest;
|
|
410
|
+
/** Grupo con los ids de sus empresas. */
|
|
411
|
+
type GrupoResult = GrupoResponse['data'];
|
|
412
|
+
/** Query del directorio: `q`, `rubro`, `ciudad` y `cursor`. */
|
|
413
|
+
type SearchDirectorioInput = DirectorioQuery;
|
|
414
|
+
/** Página del directorio: solo campos de perfil público. */
|
|
415
|
+
type DirectorioResult = DirectorioResponse['data'];
|
|
416
|
+
/** Input para conceder una autorización a otra empresa (solo permisos del catálogo entre empresas). */
|
|
417
|
+
type CreateAutorizacionInput = CreateAutorizacionRequest;
|
|
418
|
+
/** Input para revocar (otorgante) o renunciar (beneficiaria) a una autorización. */
|
|
419
|
+
type DeleteAutorizacionInput = DeleteAutorizacionRequest;
|
|
420
|
+
/** Input de `listAutorizaciones`: dirección y persona (viaja en el header `x-eva-subject-token`). */
|
|
421
|
+
type ListAutorizacionesInput = ListAutorizacionesQuery & {
|
|
422
|
+
subjectToken: string;
|
|
423
|
+
};
|
|
424
|
+
/** Autorización vigente. */
|
|
425
|
+
type AutorizacionResult = AutorizacionResponse['data'];
|
|
426
|
+
/** Autorizaciones vigentes de una empresa. */
|
|
427
|
+
type ListAutorizacionesResult = ListAutorizacionesResponse['data'];
|
|
428
|
+
/** Input de `checkAutorizacion`: otorgante, beneficiaria y permiso. */
|
|
429
|
+
type CheckAutorizacionInput = VerificarAutorizacionQuery;
|
|
430
|
+
/** `{ autorizado }`. */
|
|
431
|
+
type CheckAutorizacionResult = VerificarAutorizacionResponse['data'];
|
|
432
|
+
/**
|
|
433
|
+
* All possible reasons why an S2S request verification can fail.
|
|
434
|
+
*
|
|
435
|
+
* - `header_missing` — one or more required headers are absent (client id, timestamp, nonce, signature).
|
|
436
|
+
* - `timestamp_invalid` — the `x-eva-timestamp` header is not a valid integer string.
|
|
437
|
+
* - `timestamp_expired` — the timestamp is outside the allowed window (default ±120 s).
|
|
438
|
+
* - `nonce_malformed` — the `x-eva-nonce` header is not 32 lowercase hex chars.
|
|
439
|
+
* - `signature_malformed` — the `x-eva-signature` header is not in `sha256=<hex64>` format.
|
|
440
|
+
* - `client_unknown` — `secretStore` returned null for the given clientId.
|
|
441
|
+
* - `signature_invalid` — the HMAC signature does not match the expected value.
|
|
442
|
+
* - `replay_detected` — the `(clientId, nonce)` pair has already been seen (only when `replayCache` is configured).
|
|
443
|
+
*
|
|
444
|
+
* `client_unknown` and `signature_invalid` share the same human-readable message
|
|
445
|
+
* ("Authentication failed") to avoid revealing whether the clientId exists.
|
|
446
|
+
*/
|
|
447
|
+
type S2SVerifyReason = 'header_missing' | 'timestamp_invalid' | 'timestamp_expired' | 'nonce_malformed' | 'signature_malformed' | 'client_unknown' | 'signature_invalid' | 'replay_detected';
|
|
448
|
+
/**
|
|
449
|
+
* Discriminated union of all S2S verification failure modes.
|
|
450
|
+
* Q-E01 LOCKED — this is a module-specific type, NOT the global Result<T, E>.
|
|
451
|
+
*/
|
|
452
|
+
type S2SVerifyError = {
|
|
453
|
+
reason: S2SVerifyReason;
|
|
454
|
+
message: string;
|
|
455
|
+
};
|
|
456
|
+
/**
|
|
457
|
+
* Result of S2S verification.
|
|
458
|
+
*
|
|
459
|
+
* Use the `ok` discriminant to narrow:
|
|
460
|
+
* ```ts
|
|
461
|
+
* const result = await verifyS2SRequest(req, opts)
|
|
462
|
+
* if (!result.ok) return new Response(result.error.message, { status: 401 })
|
|
463
|
+
* const { clientId } = result.data
|
|
464
|
+
* ```
|
|
465
|
+
*/
|
|
466
|
+
type S2SVerifyResult<T> = {
|
|
467
|
+
ok: true;
|
|
468
|
+
data: T;
|
|
469
|
+
} | {
|
|
470
|
+
ok: false;
|
|
471
|
+
error: S2SVerifyError;
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* Input options for `verifyS2SRequest`.
|
|
475
|
+
*/
|
|
476
|
+
type S2SVerifyOptions = {
|
|
477
|
+
/**
|
|
478
|
+
* Callback that must return the plaintext secret (64 hex chars = 32 bytes) for the given
|
|
479
|
+
* clientId, or null if the client is unknown. The SDK applies a timing-safe dummy HMAC
|
|
480
|
+
* when null — callers MUST NOT throw; return null for unknown clients instead.
|
|
481
|
+
*/
|
|
482
|
+
secretStore: (clientId: string) => Promise<string | null>;
|
|
483
|
+
/**
|
|
484
|
+
* Override timestamp validation window in seconds.
|
|
485
|
+
* Default: `S2S_TIMESTAMP_WINDOW_SECONDS` (120).
|
|
486
|
+
*/
|
|
487
|
+
timestampWindowSeconds?: number;
|
|
488
|
+
/**
|
|
489
|
+
* Optional nonce store for replay protection. When provided, `verifyS2SRequest`
|
|
490
|
+
* calls `setIfAbsent` after a successful HMAC verify to detect replayed requests.
|
|
491
|
+
*
|
|
492
|
+
* The SDK builds the key internally as `${clientId}:${nonce}` (`nonce` is the validated
|
|
493
|
+
* `x-eva-nonce` header, 32 lowercase hex). The TTL passed to `setIfAbsent` is
|
|
494
|
+
* `2 * timestampWindowSeconds + 1` (default 241 s): the current time is floored to seconds
|
|
495
|
+
* and the window is inclusive on both sides (±W), so a request stays acceptable for 2W + 1
|
|
496
|
+
* seconds and the key must outlive that.
|
|
497
|
+
*
|
|
498
|
+
* @remarks
|
|
499
|
+
* The implementation MUST be atomic (e.g. Redis `SET key value NX EX ttl`).
|
|
500
|
+
* Non-atomic implementations are vulnerable to TOCTOU race conditions.
|
|
501
|
+
*
|
|
502
|
+
* The store SHOULD be shared across all instances of the same service that share
|
|
503
|
+
* the clientId/secret pair. Independent per-instance stores allow cross-instance
|
|
504
|
+
* replay attacks.
|
|
505
|
+
*
|
|
506
|
+
* @security Critical for replay protection — must be atomic.
|
|
507
|
+
* @security Check occurs AFTER HMAC verify (D16) to preserve timing-safe invariant.
|
|
508
|
+
*/
|
|
509
|
+
replayCache?: {
|
|
510
|
+
/**
|
|
511
|
+
* Atomically insert `key` (`${clientId}:${nonce}`) if not present, expiring after `ttlSeconds`
|
|
512
|
+
* (`2 * timestampWindowSeconds + 1`).
|
|
513
|
+
* @returns `true` if inserted (request is fresh); `false` if the key already existed (replay detected).
|
|
514
|
+
*
|
|
515
|
+
* Implementation MUST be atomic (e.g. Redis `SET ... NX EX ttl`).
|
|
516
|
+
* Non-atomic implementations are vulnerable to TOCTOU race conditions.
|
|
517
|
+
*
|
|
518
|
+
* @security Critical for replay protection — must be atomic.
|
|
519
|
+
*/
|
|
520
|
+
setIfAbsent(key: string, ttlSeconds: number): Promise<boolean>;
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Optional message overrides for i18n. Keys not provided fall back to the
|
|
524
|
+
* default English messages. An empty string `''` is respected as an explicit
|
|
525
|
+
* override (D12 LOCKED).
|
|
526
|
+
*
|
|
527
|
+
* @example
|
|
528
|
+
* ```ts
|
|
529
|
+
* messages: {
|
|
530
|
+
* timestamp_expired: 'El timestamp está fuera del rango permitido',
|
|
531
|
+
* replay_detected: 'Firma ya utilizada',
|
|
532
|
+
* }
|
|
533
|
+
* ```
|
|
534
|
+
*/
|
|
535
|
+
messages?: Partial<Record<S2SVerifyReason, string>>;
|
|
536
|
+
};
|
|
537
|
+
export { ServiceTokenRequestError as $, RenameGrupoInput as A, SearchDirectorioInput as B, ListAutorizacionesInput as C, ListWebhookDeliveriesQuery as D, ListEmpresasResult as E, S2SGetUserResult as F, UpdateEmpresaMemberInput as G, SubjectTokenInput as H, S2SVerifyError as I, DelegatedTokenGrant as J, UpdateSucursalInput as K, S2SVerifyOptions as L, S2SBatchUsersResult as M, S2SCanonicalParts as N, RemoveEmpresaMemberInput as O, S2SClientConfig as P, ServiceTokenProviderConfig as Q, S2SVerifyReason as R, GrupoResult as S, ListEmpresasInput as T, SucursalResult as U, SetContratacionInput as V, UpdateEmpresaInput as W, SERVICE_TOKEN_RENEW_MARGIN_MS as X, ExchangeTokenInput as Y, ServiceTokenProvider as Z, EmpresaEstadoResult as _, CheckAutorizacionResult as a, DelegatedTokenVerifyOptions as at, EmpresaResult as b, CreateAutorizacionInput as c, verifyDelegatedToken as ct, CreateSucursalInput as d, ServiceTokenScopeRequirement as dt, ServiceTokenSource as et, CreateWebhookSubscriptionInput as f, ServiceTokenVerifyError as ft, EmpresaDetailResult as g, verifyServiceToken as gt, DirectorioResult as h, ServiceTokenVerifyResult as ht, CheckAutorizacionInput as i, DelegatedTokenVerifyError as it, S2SBatchUsersInput as j, RemoveGrupoEmpresaInput as k, CreateEmpresaInput as l, SERVICE_TOKEN_CLOCK_TOLERANCE_SECONDS as lt, DeleteAutorizacionInput as m, ServiceTokenVerifyReason as mt, AddGrupoEmpresaInput as n, DelegatedActor as nt, ContratacionResult as o, DelegatedTokenVerifyReason as ot, DeactivateSucursalInput as p, ServiceTokenVerifyOptions as pt, UpdateWebhookSubscriptionInput as q, AutorizacionResult as r, DelegatedTokenClaims as rt, ContratadoResult as s, DelegatedTokenVerifyResult as st, AddEmpresaMemberInput as t, createServiceTokenProvider as tt, CreateGrupoInput as u, ServiceTokenClaims as ut, EmpresaMemberResult as v, ListAutorizacionesResult as w, GetEmpresaResult as x, EmpresaRecortadaResult as y, S2SVerifyResult as z };
|
|
538
|
+
//# sourceMappingURL=types-DIUWza9-.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-DIUWza9-.d.ts","names":[],"sources":["../src/s2s/service-token.ts","../src/s2s/delegated-token.ts","../src/s2s/token-provider.ts","../src/s2s/types.ts"],"mappings":";;;;;;cA4Ba;;;;;;;;;;;KAYD;KAQA;EACV,QAAQ;EACR;;;KAIU;;EAEV;;EAEA;;EAEA;;EAEA;;KAGU;EACN;EAAU,MAAM;;EAChB;EAAW,OAAO;;;;;;;KAOZ;EACN;EAAuB;EAAkB;;EACzC;EAA6B;EAAuB;;EACpD;EAAwB;EAAuB;;KAEzC,4BAA4B;;;;;EAKtC,UAAU;;;;;;EAMV,OAAO;;EAEP;;EAEA;;EAEA,WAAW,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;iBAuGN,mBACpB,eACA,MAAM,4BACL,QAAQ;;KClKC,6BAA6B;KAE7B;EACV,QAAQ;EACR;;;KAIU;;EAEV;;EAEA;;;KAIU;;EAEV;;EAEA;;EAEA;;EAEA;;;;;EAKA,qBAAqB;;EAErB;;EAEA;;EAEA;;KAGU;EACN;EAAU,MAAM;;EAChB;EAAW,OAAO;;KAEZ,8BAA8B;;;;;EAKxC,UAAU;;EAEV,OAAO;;EAEP;;EAEA;;EAEA,WAAW,QAAQ,OAAO;;;;;;;;;;;;;;;;;;;iBAiGN,qBACpB,eACA,MAAM,8BACL,QAAQ;;cC1KE;KASD;;;;;EAKV;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;KAQU;;;;;;EAMV,YAAY;;;;;;;;;EASZ,WAAW;;;KAID;;;;;;EAMV;;EAEA;;EAEA;;;KAIU;EACV;;EAEA;;;;;KAMU,uBAAuB;;;;;;;;;;;;;;;;EAgBjC,cAAc,OAAO,qBAAqB,QAAQ,OAAO;;;cAI9C,iCAAiC;WACnC;WACA;;WAEA;EAGP,YAAA,cACA,gBACA,sBACA;;;;;;;;;;;;;;;;;;;;;;iBAyKY,2BACd,QAAQ,6BACP;;;;KCxOS;;;;;EAKV;;;;;EAKA,eAAe;;;;;;KAOL;;EAEV;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA,WAAW;;;;;;;KAQD,mBAAmB;;;;;KAMnB,qBAAqB;;;;;KAMrB,sBAAsB;;;;;;KAOtB,iCAAiC;;;;;KAMjC,iCAAiC;;;;;;;KAQjC;EACV;EACA;EACA;EACA;EACA;;;;;;KAOU,oBAAoB;;;;;KAMpB,qBAAqB;;KAGrB,qBAAqB;;KAGrB,oBAAoB;;KAGpB,qBAAqB;;KAGrB,wBAAwB;;KAGxB,2BAA2B;;KAG3B,2BAA2B;;KAG3B,sBAAsB;;KAGtB,sBAAsB;;KAGtB,0BAA0B;;KAG1B,gBAAgB;;KAGhB,sBAAsB;;KAGtB,yBAAyB;;KAGzB,mBAAmB;;KAGnB,sBAAsB;;KAGtB,iBAAiB;;KAGjB,sBAAsB;;KAGtB,qBAAqB;;KAGrB,uBAAuB;;KAGvB,mBAAmB;;KAGnB,mBAAmB;;KAGnB,mBAAmB;;KAGnB,uBAAuB;;KAGvB,0BAA0B;;KAG1B,cAAc;;KAGd,wBAAwB;;KAGxB,mBAAmB;;KAGnB,0BAA0B;;KAG1B,0BAA0B;;KAG1B,0BAA0B;EACpC;;;KAIU,qBAAqB;;KAGrB,2BAA2B;;KAG3B,yBAAyB;;KAGzB,0BAA0B;;;;;;;;;;;;;;;;KAmB1B;;;;;KAcA;EACV,QAAQ;EACR;;;;;;;;;;;;KAaU,gBAAgB;EACtB;EAAU,MAAM;;EAChB;EAAW,OAAO;;;;;KAKZ;;;;;;EAMV,cAAc,qBAAqB;;;;;EAKnC;;;;;;;;;;;;;;;;;;;;;;EAsBA;;;;;;;;;;;IAWE,YAAY,aAAa,qBAAqB;;;;;;;;;;;;;;;EAehD,WAAW,QAAQ,OAAO"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Br as PublicProfile, Ci as PRIVACY_STATES, Ir as Company, Nr as Session, _i as ACTIVITY_STATES, vi as CoreErrorCode } from "./index-Dold-Ycb.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Tipo semiabierto: incluye los 12 cores (con autocomplete) y permite
|
|
4
|
+
* strings adicionales para feature-specific codes del API.
|
|
5
|
+
* Pattern idiomático TS: `LiteralType | (string & {})`.
|
|
6
|
+
*/
|
|
7
|
+
type ErrorCode = CoreErrorCode | (string & {});
|
|
8
|
+
/**
|
|
9
|
+
* Reasons internos del SDK — enum cerrado, 6 valores.
|
|
10
|
+
* Solo aplican a EvaSdkError (kind: 'sdk').
|
|
11
|
+
*/
|
|
12
|
+
declare const SDK_ERROR_REASONS: {
|
|
13
|
+
/** No hay tokens en el request (sin cookies). */
|
|
14
|
+
readonly auth_required: "auth_required";
|
|
15
|
+
/** Token presente pero inválido (signature/format/expiry). */
|
|
16
|
+
readonly token_invalid: "token_invalid";
|
|
17
|
+
/** Refresh exitoso pero el servidor no devolvió tokens nuevos. */
|
|
18
|
+
readonly refresh_no_tokens: "refresh_no_tokens";
|
|
19
|
+
/** Fallo de verificación no clasificable (post-refresh). */
|
|
20
|
+
readonly verify_failed: "verify_failed";
|
|
21
|
+
/** Error de red / fetch fallido. */
|
|
22
|
+
readonly network: "network";
|
|
23
|
+
/** Respuesta HTTP no parseable o sin el shape esperado. */
|
|
24
|
+
readonly malformed: "malformed";
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Unión cerrada de los 6 reasons internos del SDK.
|
|
28
|
+
*/
|
|
29
|
+
type SdkErrorReason = (typeof SDK_ERROR_REASONS)[keyof typeof SDK_ERROR_REASONS];
|
|
30
|
+
type ActivityState = (typeof ACTIVITY_STATES)[number];
|
|
31
|
+
type PrivacyState = (typeof PRIVACY_STATES)[number];
|
|
32
|
+
type EvaUser = PublicProfile;
|
|
33
|
+
type EvaSession = Session;
|
|
34
|
+
type EvaEmpresa = Company;
|
|
35
|
+
type EvaTokenPayload<TExtra extends Record<string, unknown> = {}> = {
|
|
36
|
+
id: string;
|
|
37
|
+
sessionId: string;
|
|
38
|
+
/** `client_id` del access token (RFC 9068): el producto. */
|
|
39
|
+
clientId: string;
|
|
40
|
+
/** Empresa activa de la sesión (claim `empresa`); ausente si no hay. */
|
|
41
|
+
empresaId?: string;
|
|
42
|
+
} & TExtra;
|
|
43
|
+
/**
|
|
44
|
+
* Error proveniente del Auth Service (respuesta HTTP con shape { error: { code, message } }).
|
|
45
|
+
* D-02 v3 LOCKED: discriminated union con kind:'api'.
|
|
46
|
+
*/
|
|
47
|
+
type EvaApiError = {
|
|
48
|
+
kind: 'api';
|
|
49
|
+
/** Error code del API (CoreErrorCode | feature-specific string). */
|
|
50
|
+
code: string;
|
|
51
|
+
/** Mensaje humano del API. */
|
|
52
|
+
message: string;
|
|
53
|
+
/** HTTP status code del API (400–503). */
|
|
54
|
+
status: number;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Error interno del SDK (red, parsing, lógica de verify).
|
|
58
|
+
* D-02 v3 LOCKED: discriminated union con kind:'sdk'.
|
|
59
|
+
*/
|
|
60
|
+
type EvaSdkError = {
|
|
61
|
+
kind: 'sdk';
|
|
62
|
+
/** Reason interno — enum cerrado (SdkErrorReason). */
|
|
63
|
+
reason: SdkErrorReason;
|
|
64
|
+
/** Mensaje descriptivo del error. */
|
|
65
|
+
message: string;
|
|
66
|
+
/** HTTP status sugerido: 401 (auth/token), 500 (verify_failed), 0 (network/malformed). */
|
|
67
|
+
status: number;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Discriminated union de todos los errores del SDK.
|
|
71
|
+
* Narrow por `.kind` para acceder a propiedades específicas de cada variante.
|
|
72
|
+
*/
|
|
73
|
+
type EvaError = EvaApiError | EvaSdkError;
|
|
74
|
+
/**
|
|
75
|
+
* Resultado de operaciones asincrónicas del SDK.
|
|
76
|
+
* D-10 LOCKED: status vive SOLO en error.status (no duplicado en el Result top-level).
|
|
77
|
+
*/
|
|
78
|
+
type Result<T> = {
|
|
79
|
+
ok: true;
|
|
80
|
+
data: T;
|
|
81
|
+
} | {
|
|
82
|
+
ok: false;
|
|
83
|
+
error: EvaError;
|
|
84
|
+
};
|
|
85
|
+
type DeviceInfo = {
|
|
86
|
+
deviceType: string;
|
|
87
|
+
os: string;
|
|
88
|
+
browser: string;
|
|
89
|
+
userAgent: string;
|
|
90
|
+
};
|
|
91
|
+
type TokenPair = {
|
|
92
|
+
accessToken: string;
|
|
93
|
+
refreshToken: string;
|
|
94
|
+
};
|
|
95
|
+
export { EvaError as a, EvaTokenPayload as c, Result as d, TokenPair as f, SdkErrorReason as h, EvaEmpresa as i, EvaUser as l, SDK_ERROR_REASONS as m, DeviceInfo as n, EvaSdkError as o, ErrorCode as p, EvaApiError as r, EvaSession as s, ActivityState as t, PrivacyState as u };
|
|
96
|
+
//# sourceMappingURL=types-qh6ANBCV.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-qh6ANBCV.d.cts","names":["_$__error_codes0.SdkErrorReason"],"sources":["../src/error-codes.ts","../src/types.ts"],"mappings":";;;;;;KA+BY,YAAY;;;;;cAMX;;;;;;;;;;;;;;;;;KAkBD,yBACF,gCAAgC;KC5C9B,wBAAwB;KACxB,uBAAuB;KAEvB,UAAU;KAEV,aAAa;KAEb,aAAa;KAEb,gBAAgB,eAAe;EACzC;EACA;;EAEA;;EAEA;IACE;;;;;KAMQ;EACV;;EAEA;;EAEA;;EAEA;;;;;;KAOU;EACV;;EAEA,QAHUA;;EAKV;;EAEA;;;;;;KAOU,WAAW,cAAc;;;;;KAMzB,OAAO;EAAO;EAAU,MAAM;;EAAQ;EAAW,OAAO;;KAExD;EACV;EACA;EACA;EACA;;KAGU;EACV;EACA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_constants = require("../constants-CcbhOaAP.cjs");
|
|
3
|
+
const require_event_codes = require("../event-codes-BBJHon-I.cjs");
|
|
4
|
+
const require_webhooks = require("../webhooks-Cx11psg1.cjs");
|
|
5
|
+
exports.EVENT_CODES = require_event_codes.EVENT_CODES;
|
|
6
|
+
exports.WEBHOOK_HEADERS = require_constants.WEBHOOK_HEADERS;
|
|
7
|
+
exports.WEBHOOK_TIMESTAMP_WINDOW_SECONDS = require_constants.WEBHOOK_TIMESTAMP_WINDOW_SECONDS;
|
|
8
|
+
exports.verifyWebhookSignature = require_webhooks.verifyWebhookSignature;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Ei as WEBHOOK_TIMESTAMP_WINDOW_SECONDS, Ti as WEBHOOK_HEADERS } from "../index-Dold-Ycb.cjs";
|
|
2
|
+
import { n as EventCode, t as EVENT_CODES } from "../event-codes-BgcJWsov.cjs";
|
|
3
|
+
import { a as WebhookSubscriptionWithSecret, i as WebhookSubscription, n as WebhookDelivery, r as WebhookPayload, t as RotateWebhookSecretResult } from "../types-B5sf7kKE.cjs";
|
|
4
|
+
import { n as verifyWebhookSignature, t as VerifyWebhookSignatureParams } from "../index-DcvQWByo.cjs";
|
|
5
|
+
export { EVENT_CODES, type EventCode, type RotateWebhookSecretResult, type VerifyWebhookSignatureParams, WEBHOOK_HEADERS, WEBHOOK_TIMESTAMP_WINDOW_SECONDS, type WebhookDelivery, type WebhookPayload, type WebhookSubscription, type WebhookSubscriptionWithSecret, verifyWebhookSignature };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Ei as WEBHOOK_TIMESTAMP_WINDOW_SECONDS, Ti as WEBHOOK_HEADERS } from "../index-Dold-Ycb.js";
|
|
2
|
+
import { n as EventCode, t as EVENT_CODES } from "../event-codes-BgcJWsov.js";
|
|
3
|
+
import { a as WebhookSubscriptionWithSecret, i as WebhookSubscription, n as WebhookDelivery, r as WebhookPayload, t as RotateWebhookSecretResult } from "../types-CQTZdZIF.js";
|
|
4
|
+
import { n as verifyWebhookSignature, t as VerifyWebhookSignatureParams } from "../index-CNNMCrdl.js";
|
|
5
|
+
export { EVENT_CODES, type EventCode, type RotateWebhookSecretResult, type VerifyWebhookSignatureParams, WEBHOOK_HEADERS, WEBHOOK_TIMESTAMP_WINDOW_SECONDS, type WebhookDelivery, type WebhookPayload, type WebhookSubscription, type WebhookSubscriptionWithSecret, verifyWebhookSignature };
|