@eva_solutions/auth-sdk 0.0.0-stage → 3.0.0-dev-20261109133200

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.
Files changed (205) hide show
  1. package/CHANGELOG.md +290 -0
  2. package/LICENSE +21 -0
  3. package/README.md +481 -2
  4. package/dist/admin/index.cjs +4 -0
  5. package/dist/admin/index.d.cts +2 -0
  6. package/dist/admin/index.d.ts +2 -0
  7. package/dist/admin/index.js +1 -0
  8. package/dist/admin-DjvuvuI8.js +408 -0
  9. package/dist/admin-DjvuvuI8.js.map +1 -0
  10. package/dist/admin-Q6lbWqLM.cjs +419 -0
  11. package/dist/admin-Q6lbWqLM.cjs.map +1 -0
  12. package/dist/api-path-2Ulruz7R.cjs +34 -0
  13. package/dist/api-path-2Ulruz7R.cjs.map +1 -0
  14. package/dist/api-path-B-vSkL2H.js +29 -0
  15. package/dist/api-path-B-vSkL2H.js.map +1 -0
  16. package/dist/auth-19r-Q6X2.js +84 -0
  17. package/dist/auth-19r-Q6X2.js.map +1 -0
  18. package/dist/auth-DX1N5JA4.cjs +131 -0
  19. package/dist/auth-DX1N5JA4.cjs.map +1 -0
  20. package/dist/auth-handlers-B3iJaPln.js +343 -0
  21. package/dist/auth-handlers-B3iJaPln.js.map +1 -0
  22. package/dist/auth-handlers-BTbXKJms.d.ts +15 -0
  23. package/dist/auth-handlers-BTbXKJms.d.ts.map +1 -0
  24. package/dist/auth-handlers-CDzGFDTu.cjs +404 -0
  25. package/dist/auth-handlers-CDzGFDTu.cjs.map +1 -0
  26. package/dist/auth-handlers-DRUUTEtW.d.cts +15 -0
  27. package/dist/auth-handlers-DRUUTEtW.d.cts.map +1 -0
  28. package/dist/catalog-CHPqldcj.cjs +172 -0
  29. package/dist/catalog-CHPqldcj.cjs.map +1 -0
  30. package/dist/catalog-CIqpzgsM.d.cts +75 -0
  31. package/dist/catalog-CIqpzgsM.d.cts.map +1 -0
  32. package/dist/catalog-CIqpzgsM.d.ts +75 -0
  33. package/dist/catalog-CIqpzgsM.d.ts.map +1 -0
  34. package/dist/catalog-DqPhtCKZ.js +95 -0
  35. package/dist/catalog-DqPhtCKZ.js.map +1 -0
  36. package/dist/config-3avoUa9e.d.cts +95 -0
  37. package/dist/config-3avoUa9e.d.cts.map +1 -0
  38. package/dist/config-COX7rGAP.d.ts +95 -0
  39. package/dist/config-COX7rGAP.d.ts.map +1 -0
  40. package/dist/constants-BE1_9Tod.cjs +52 -0
  41. package/dist/constants-BE1_9Tod.cjs.map +1 -0
  42. package/dist/constants-BY7QZokc.js +29 -0
  43. package/dist/constants-BY7QZokc.js.map +1 -0
  44. package/dist/constants-CcbhOaAP.cjs +153 -0
  45. package/dist/constants-CcbhOaAP.cjs.map +1 -0
  46. package/dist/constants-rNuD5qJn.js +94 -0
  47. package/dist/constants-rNuD5qJn.js.map +1 -0
  48. package/dist/contracts/index.cjs +1006 -0
  49. package/dist/contracts/index.cjs.map +1 -0
  50. package/dist/contracts/index.d.cts +488 -0
  51. package/dist/contracts/index.d.cts.map +1 -0
  52. package/dist/contracts/index.d.ts +488 -0
  53. package/dist/contracts/index.d.ts.map +1 -0
  54. package/dist/contracts/index.js +817 -0
  55. package/dist/contracts/index.js.map +1 -0
  56. package/dist/cookies-DCIcr7uy.cjs +94 -0
  57. package/dist/cookies-DCIcr7uy.cjs.map +1 -0
  58. package/dist/cookies-DKEC7AWv.js +71 -0
  59. package/dist/cookies-DKEC7AWv.js.map +1 -0
  60. package/dist/delegated-token-CVNbMNfy.js +426 -0
  61. package/dist/delegated-token-CVNbMNfy.js.map +1 -0
  62. package/dist/delegated-token-DHSK4rHI.cjs +461 -0
  63. package/dist/delegated-token-DHSK4rHI.cjs.map +1 -0
  64. package/dist/error-helpers-0woh13Wd.d.cts +105 -0
  65. package/dist/error-helpers-0woh13Wd.d.cts.map +1 -0
  66. package/dist/error-helpers-Ct3AUK1I.d.ts +105 -0
  67. package/dist/error-helpers-Ct3AUK1I.d.ts.map +1 -0
  68. package/dist/error-helpers-XCh4ZJ-g.cjs +282 -0
  69. package/dist/error-helpers-XCh4ZJ-g.cjs.map +1 -0
  70. package/dist/error-helpers-lnwgNOw9.js +145 -0
  71. package/dist/error-helpers-lnwgNOw9.js.map +1 -0
  72. package/dist/error-messages-CGpW1fsg.d.cts +48 -0
  73. package/dist/error-messages-CGpW1fsg.d.cts.map +1 -0
  74. package/dist/error-messages-CGpW1fsg.d.ts +48 -0
  75. package/dist/error-messages-CGpW1fsg.d.ts.map +1 -0
  76. package/dist/event-codes-BBJHon-I.cjs +48 -0
  77. package/dist/event-codes-BBJHon-I.cjs.map +1 -0
  78. package/dist/event-codes-BgcJWsov.d.cts +42 -0
  79. package/dist/event-codes-BgcJWsov.d.cts.map +1 -0
  80. package/dist/event-codes-BgcJWsov.d.ts +42 -0
  81. package/dist/event-codes-BgcJWsov.d.ts.map +1 -0
  82. package/dist/event-codes-DR5_VlaR.js +43 -0
  83. package/dist/event-codes-DR5_VlaR.js.map +1 -0
  84. package/dist/generic/index.cjs +91 -0
  85. package/dist/generic/index.cjs.map +1 -0
  86. package/dist/generic/index.d.cts +27 -0
  87. package/dist/generic/index.d.cts.map +1 -0
  88. package/dist/generic/index.d.ts +27 -0
  89. package/dist/generic/index.d.ts.map +1 -0
  90. package/dist/generic/index.js +80 -0
  91. package/dist/generic/index.js.map +1 -0
  92. package/dist/hono/index.cjs +309 -0
  93. package/dist/hono/index.cjs.map +1 -0
  94. package/dist/hono/index.d.cts +272 -0
  95. package/dist/hono/index.d.cts.map +1 -0
  96. package/dist/hono/index.d.ts +272 -0
  97. package/dist/hono/index.d.ts.map +1 -0
  98. package/dist/hono/index.js +290 -0
  99. package/dist/hono/index.js.map +1 -0
  100. package/dist/hono-openapi/index.cjs +326 -0
  101. package/dist/hono-openapi/index.cjs.map +1 -0
  102. package/dist/hono-openapi/index.d.cts +14 -0
  103. package/dist/hono-openapi/index.d.cts.map +1 -0
  104. package/dist/hono-openapi/index.d.ts +14 -0
  105. package/dist/hono-openapi/index.d.ts.map +1 -0
  106. package/dist/hono-openapi/index.js +307 -0
  107. package/dist/hono-openapi/index.js.map +1 -0
  108. package/dist/http-client-BVF3iktR.cjs +211 -0
  109. package/dist/http-client-BVF3iktR.cjs.map +1 -0
  110. package/dist/http-client-Da0-OMfc.js +206 -0
  111. package/dist/http-client-Da0-OMfc.js.map +1 -0
  112. package/dist/index-CIH_2t7Y.d.ts +240 -0
  113. package/dist/index-CIH_2t7Y.d.ts.map +1 -0
  114. package/dist/index-CZru7c5T.d.cts +1711 -0
  115. package/dist/index-CZru7c5T.d.cts.map +1 -0
  116. package/dist/index-CZru7c5T.d.ts +1711 -0
  117. package/dist/index-CZru7c5T.d.ts.map +1 -0
  118. package/dist/index-DMVe5IJA.d.cts +240 -0
  119. package/dist/index-DMVe5IJA.d.cts.map +1 -0
  120. package/dist/index-DRWKobSp.d.ts +312 -0
  121. package/dist/index-DRWKobSp.d.ts.map +1 -0
  122. package/dist/index-DU9wJ-P2.d.cts +312 -0
  123. package/dist/index-DU9wJ-P2.d.cts.map +1 -0
  124. package/dist/index-DbiXllNy.d.cts +66 -0
  125. package/dist/index-DbiXllNy.d.cts.map +1 -0
  126. package/dist/index-z9r98qlk.d.ts +66 -0
  127. package/dist/index-z9r98qlk.d.ts.map +1 -0
  128. package/dist/index.cjs +89 -0
  129. package/dist/index.cjs.map +1 -0
  130. package/dist/index.d.cts +114 -0
  131. package/dist/index.d.cts.map +1 -0
  132. package/dist/index.d.ts +114 -0
  133. package/dist/index.d.ts.map +1 -0
  134. package/dist/index.js +28 -0
  135. package/dist/index.js.map +1 -0
  136. package/dist/jwt-BBNqk0TV.cjs +155 -0
  137. package/dist/jwt-BBNqk0TV.cjs.map +1 -0
  138. package/dist/jwt-DhqgH94B.js +150 -0
  139. package/dist/jwt-DhqgH94B.js.map +1 -0
  140. package/dist/key-resolver-CESqj4-P.cjs +45 -0
  141. package/dist/key-resolver-CESqj4-P.cjs.map +1 -0
  142. package/dist/key-resolver-D56I2Zpz.js +34 -0
  143. package/dist/key-resolver-D56I2Zpz.js.map +1 -0
  144. package/dist/parse-error-response-6qOQS5y9.cjs +316 -0
  145. package/dist/parse-error-response-6qOQS5y9.cjs.map +1 -0
  146. package/dist/parse-error-response-BM9-kjs0.js +239 -0
  147. package/dist/parse-error-response-BM9-kjs0.js.map +1 -0
  148. package/dist/path-segment-C25i6aaH.cjs +29 -0
  149. package/dist/path-segment-C25i6aaH.cjs.map +1 -0
  150. package/dist/path-segment-CyqnaFrP.js +24 -0
  151. package/dist/path-segment-CyqnaFrP.js.map +1 -0
  152. package/dist/react/index.cjs +336 -0
  153. package/dist/react/index.cjs.map +1 -0
  154. package/dist/react/index.d.cts +151 -0
  155. package/dist/react/index.d.cts.map +1 -0
  156. package/dist/react/index.d.ts +151 -0
  157. package/dist/react/index.d.ts.map +1 -0
  158. package/dist/react/index.js +300 -0
  159. package/dist/react/index.js.map +1 -0
  160. package/dist/refresh-dedup-CKaHHe7m.js +14 -0
  161. package/dist/refresh-dedup-CKaHHe7m.js.map +1 -0
  162. package/dist/refresh-dedup-CLdACQXR.cjs +19 -0
  163. package/dist/refresh-dedup-CLdACQXR.cjs.map +1 -0
  164. package/dist/rolldown-runtime-CmQyd0Gu.cjs +27 -0
  165. package/dist/routes-DpAzgY1V.cjs +424 -0
  166. package/dist/routes-DpAzgY1V.cjs.map +1 -0
  167. package/dist/routes-F1g5aVqP.js +347 -0
  168. package/dist/routes-F1g5aVqP.js.map +1 -0
  169. package/dist/s2s/index.cjs +24 -0
  170. package/dist/s2s/index.d.cts +5 -0
  171. package/dist/s2s/index.d.ts +5 -0
  172. package/dist/s2s/index.js +5 -0
  173. package/dist/s2s-6wbotr78.cjs +926 -0
  174. package/dist/s2s-6wbotr78.cjs.map +1 -0
  175. package/dist/s2s-B_0SIQzn.js +897 -0
  176. package/dist/s2s-B_0SIQzn.js.map +1 -0
  177. package/dist/sign-C7y6xdvT.cjs +324 -0
  178. package/dist/sign-C7y6xdvT.cjs.map +1 -0
  179. package/dist/sign-HFtcYwa-.js +259 -0
  180. package/dist/sign-HFtcYwa-.js.map +1 -0
  181. package/dist/tokens-C1nzkn21.cjs +232 -0
  182. package/dist/tokens-C1nzkn21.cjs.map +1 -0
  183. package/dist/tokens-C3Z40qd7.js +107 -0
  184. package/dist/tokens-C3Z40qd7.js.map +1 -0
  185. package/dist/types-Ai3iIFlB.d.cts +538 -0
  186. package/dist/types-Ai3iIFlB.d.cts.map +1 -0
  187. package/dist/types-Bxg4hCMc.d.cts +52 -0
  188. package/dist/types-Bxg4hCMc.d.cts.map +1 -0
  189. package/dist/types-CEABh1Zf.d.ts +96 -0
  190. package/dist/types-CEABh1Zf.d.ts.map +1 -0
  191. package/dist/types-Ci0Jq0xB.d.cts +96 -0
  192. package/dist/types-Ci0Jq0xB.d.cts.map +1 -0
  193. package/dist/types-DXg8BvEh.d.ts +52 -0
  194. package/dist/types-DXg8BvEh.d.ts.map +1 -0
  195. package/dist/types-_zY7QbM5.d.ts +538 -0
  196. package/dist/types-_zY7QbM5.d.ts.map +1 -0
  197. package/dist/webhooks/index.cjs +8 -0
  198. package/dist/webhooks/index.d.cts +5 -0
  199. package/dist/webhooks/index.d.ts +5 -0
  200. package/dist/webhooks/index.js +4 -0
  201. package/dist/webhooks-B5sAWC9W.js +74 -0
  202. package/dist/webhooks-B5sAWC9W.js.map +1 -0
  203. package/dist/webhooks-Cx11psg1.cjs +79 -0
  204. package/dist/webhooks-Cx11psg1.cjs.map +1 -0
  205. package/package.json +192 -3
@@ -0,0 +1,419 @@
1
+ const require_routes = require("./routes-DpAzgY1V.cjs");
2
+ const require_api_path = require("./api-path-2Ulruz7R.cjs");
3
+ const require_parse_error_response = require("./parse-error-response-6qOQS5y9.cjs");
4
+ const require_path_segment = require("./path-segment-C25i6aaH.cjs");
5
+ const require_sign = require("./sign-C7y6xdvT.cjs");
6
+ // src/admin/client.ts
7
+ /**
8
+ * Cliente Admin para provisioning de service clients y gestión de usuarios
9
+ * en el Auth Service.
10
+ *
11
+ * REQ-ADMIN-01, REQ-ADMIN-02, REQ-ADMIN-03, REQ-ADMIN-04, REQ-ADMIN-05 LOCKED.
12
+ * REQ-RESTORE-01 LOCKED: endpoint POST /admin/users/:id/restore.
13
+ *
14
+ * Autenticación: firma HMAC S2S de un service client con la marca `esAdmin` (la superficie
15
+ * `/admin` de Auth es la única, junto con el pedido de token, que conserva la firma). Una persona,
16
+ * un client: el API registra el slug que firmó como `actor`.
17
+ *
18
+ * Endpoints:
19
+ * POST /admin/service-clients → createServiceClient
20
+ * GET /admin/service-clients → listServiceClients
21
+ * GET /admin/service-clients/:slug → getServiceClient
22
+ * PATCH /admin/service-clients/:slug → updateServiceClient
23
+ * DELETE /admin/service-clients/:slug → deleteServiceClient (204)
24
+ * POST /admin/service-clients/:slug/rotate-secret → rotateServiceClientSecret
25
+ * GET /admin/service-clients/:slug/grants → listServiceClientGrants
26
+ * PUT /admin/service-clients/:slug/grants → setServiceClientGrant
27
+ * DELETE /admin/service-clients/:slug/grants/:audience → deleteServiceClientGrant (204)
28
+ * GET /admin/service-clients/:slug/delegations → listServiceClientDelegations
29
+ * PUT /admin/service-clients/:slug/delegations → setServiceClientDelegation
30
+ * DELETE /admin/service-clients/:slug/delegations/:audience → deleteServiceClientDelegation (204)
31
+ * GET /admin/productos/:slug/permisos-autorizables → getProductoPermisosAutorizables
32
+ * PUT /admin/productos/:slug/permisos-autorizables → setProductoPermisosAutorizables
33
+ * POST /admin/empresas/:id/titular → reassignEmpresaTitular
34
+ * POST /admin/empresas/:id/baja → bajaEmpresa
35
+ * POST /admin/empresas/:id/reactivar → reactivarEmpresa
36
+ * PUT /admin/empresas/:id/productos/:producto → setContratacion
37
+ * GET /admin/productos → listProductos
38
+ * POST /admin/productos → createProducto (201)
39
+ * PATCH /admin/productos/:slug → updateProducto
40
+ * POST /admin/users/:id/restore → restoreUser
41
+ * POST /admin/webhooks/republish-pending → republishPendingWebhooks
42
+ * POST /admin/maintenance/cleanup → maintenanceCleanup
43
+ *
44
+ * Los paths salen de `ADMIN_ROUTES` (contrato compartido) vía `apiPath`; el slug y el id se
45
+ * codifican como UN segmento con `encodePathSegment` (el mismo helper del cliente S2S) antes de
46
+ * insertarlos. Un slug/id vacío, `.`, `..` o que no sea string devuelve un `Result` de error
47
+ * (`kind: 'sdk'`, `reason: 'malformed'`) sin hacer la request.
48
+ */
49
+ const encoder = new TextEncoder();
50
+ /**
51
+ * Realiza un fetch autenticado S2S firmando el request con HMAC-SHA-256.
52
+ * Retorna `Result<T>` con la propiedad `data` del body de respuesta.
53
+ */
54
+ async function adminFetch({ config, method, pathname, rawQuery = "", body }) {
55
+ try {
56
+ const bodyBytes = body !== void 0 ? encoder.encode(JSON.stringify(body)) : /* @__PURE__ */ new Uint8Array(0);
57
+ const url = rawQuery ? `${config.baseUrl}${pathname}?${rawQuery}` : `${config.baseUrl}${pathname}`;
58
+ const target = new URL(url);
59
+ const headers = {
60
+ "content-type": "application/json",
61
+ ...await require_sign.signS2SHeaders({
62
+ method,
63
+ path: target.pathname,
64
+ rawQuery: target.search.slice(1),
65
+ bodyBytes,
66
+ clientId: config.clientId,
67
+ secretHex: config.secretHex
68
+ })
69
+ };
70
+ const res = await fetch(url, {
71
+ method,
72
+ headers,
73
+ body: bodyBytes.length > 0 ? JSON.stringify(body) : void 0,
74
+ signal: AbortSignal.timeout(1e4)
75
+ });
76
+ if (!res.ok) {
77
+ const responseBody = await res.json().catch(() => null);
78
+ return {
79
+ ok: false,
80
+ error: require_parse_error_response.parseErrorResponse(res.status, responseBody)
81
+ };
82
+ }
83
+ if (res.status === 204) return {
84
+ ok: true,
85
+ data: void 0
86
+ };
87
+ return {
88
+ ok: true,
89
+ data: (await res.json()).data
90
+ };
91
+ } catch (err) {
92
+ return {
93
+ ok: false,
94
+ error: {
95
+ kind: "sdk",
96
+ reason: "network",
97
+ message: err instanceof Error ? err.message : "Network error",
98
+ status: 0
99
+ }
100
+ };
101
+ }
102
+ }
103
+ /**
104
+ * Result de error para un slug/id que no se puede usar como segmento del path. Se devuelve antes
105
+ * de armar la URL: `apiPath` lanzaría con un param ausente y la promesa se rechazaría.
106
+ */
107
+ function invalidParamResult(method, param) {
108
+ return {
109
+ ok: false,
110
+ error: {
111
+ kind: "sdk",
112
+ reason: "malformed",
113
+ message: `${method}: ${param} inválido (no puede ser vacío, "." ni "..")`,
114
+ status: 0
115
+ }
116
+ };
117
+ }
118
+ /**
119
+ * Crea un cliente Admin para provisioning del Auth Service.
120
+ *
121
+ * ADVERTENCIA: solo usar desde backends o herramientas de operador seguras — el secret del
122
+ * service client admin nunca debe exponerse en el cliente/browser.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * const admin = createAdminClient({
127
+ * clientId: process.env.AUTH_ADMIN_SLUG,
128
+ * secretHex: process.env.AUTH_ADMIN_SECRET,
129
+ * baseUrl: 'https://auth.miapp.com',
130
+ * })
131
+ * const result = await admin.createServiceClient({ slug: 'mi-servicio' })
132
+ * if (!result.ok) return handleError(result.error)
133
+ * console.log('Secret (guardar ahora):', result.data.secret)
134
+ * ```
135
+ */
136
+ function createAdminClient(config) {
137
+ require_parse_error_response.validateHttpsUrl(config.baseUrl, "AdminClientConfig.baseUrl");
138
+ return {
139
+ async createServiceClient(input) {
140
+ return adminFetch({
141
+ config,
142
+ method: "POST",
143
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.createServiceClient),
144
+ body: input
145
+ });
146
+ },
147
+ async listServiceClients() {
148
+ return adminFetch({
149
+ config,
150
+ method: "GET",
151
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.listServiceClients)
152
+ });
153
+ },
154
+ async getServiceClient(slug) {
155
+ const segment = require_path_segment.encodePathSegment(slug);
156
+ if (segment === null) return invalidParamResult("getServiceClient", "slug");
157
+ return adminFetch({
158
+ config,
159
+ method: "GET",
160
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.getServiceClient, { slug: segment })
161
+ });
162
+ },
163
+ async updateServiceClient(slug, input) {
164
+ const segment = require_path_segment.encodePathSegment(slug);
165
+ if (segment === null) return invalidParamResult("updateServiceClient", "slug");
166
+ return adminFetch({
167
+ config,
168
+ method: "PATCH",
169
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.updateServiceClient, { slug: segment }),
170
+ body: input
171
+ });
172
+ },
173
+ async deleteServiceClient(slug) {
174
+ const segment = require_path_segment.encodePathSegment(slug);
175
+ if (segment === null) return invalidParamResult("deleteServiceClient", "slug");
176
+ return adminFetch({
177
+ config,
178
+ method: "DELETE",
179
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.deleteServiceClient, { slug: segment })
180
+ });
181
+ },
182
+ async rotateServiceClientSecret(slug) {
183
+ const segment = require_path_segment.encodePathSegment(slug);
184
+ if (segment === null) return invalidParamResult("rotateServiceClientSecret", "slug");
185
+ return adminFetch({
186
+ config,
187
+ method: "POST",
188
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.rotateServiceClientSecret, { slug: segment })
189
+ });
190
+ },
191
+ async listServiceClientGrants(slug) {
192
+ const segment = require_path_segment.encodePathSegment(slug);
193
+ if (segment === null) return invalidParamResult("listServiceClientGrants", "slug");
194
+ return adminFetch({
195
+ config,
196
+ method: "GET",
197
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.listServiceClientGrants, { slug: segment })
198
+ });
199
+ },
200
+ async setServiceClientGrant(slug, input) {
201
+ const segment = require_path_segment.encodePathSegment(slug);
202
+ if (segment === null) return invalidParamResult("setServiceClientGrant", "slug");
203
+ return adminFetch({
204
+ config,
205
+ method: "PUT",
206
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.setServiceClientGrant, { slug: segment }),
207
+ body: input
208
+ });
209
+ },
210
+ async deleteServiceClientGrant(slug, audience) {
211
+ const segment = require_path_segment.encodePathSegment(slug);
212
+ if (segment === null) return invalidParamResult("deleteServiceClientGrant", "slug");
213
+ const audienceSegment = require_path_segment.encodePathSegment(audience);
214
+ if (audienceSegment === null) return invalidParamResult("deleteServiceClientGrant", "audience");
215
+ return adminFetch({
216
+ config,
217
+ method: "DELETE",
218
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.deleteServiceClientGrant, {
219
+ slug: segment,
220
+ audience: audienceSegment
221
+ })
222
+ });
223
+ },
224
+ async listServiceClientDelegations(slug) {
225
+ const segment = require_path_segment.encodePathSegment(slug);
226
+ if (segment === null) return invalidParamResult("listServiceClientDelegations", "slug");
227
+ return adminFetch({
228
+ config,
229
+ method: "GET",
230
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.listServiceClientDelegations, { slug: segment })
231
+ });
232
+ },
233
+ async setServiceClientDelegation(slug, input) {
234
+ const segment = require_path_segment.encodePathSegment(slug);
235
+ if (segment === null) return invalidParamResult("setServiceClientDelegation", "slug");
236
+ return adminFetch({
237
+ config,
238
+ method: "PUT",
239
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.setServiceClientDelegation, { slug: segment }),
240
+ body: input
241
+ });
242
+ },
243
+ async deleteServiceClientDelegation(slug, audience) {
244
+ const segment = require_path_segment.encodePathSegment(slug);
245
+ if (segment === null) return invalidParamResult("deleteServiceClientDelegation", "slug");
246
+ const audienceSegment = require_path_segment.encodePathSegment(audience);
247
+ if (audienceSegment === null) return invalidParamResult("deleteServiceClientDelegation", "audience");
248
+ return adminFetch({
249
+ config,
250
+ method: "DELETE",
251
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.deleteServiceClientDelegation, {
252
+ slug: segment,
253
+ audience: audienceSegment
254
+ })
255
+ });
256
+ },
257
+ async getProductoPermisosAutorizables(slug) {
258
+ const segment = require_path_segment.encodePathSegment(slug);
259
+ if (segment === null) return invalidParamResult("getProductoPermisosAutorizables", "slug");
260
+ return adminFetch({
261
+ config,
262
+ method: "GET",
263
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.getProductoPermisosAutorizables, { slug: segment })
264
+ });
265
+ },
266
+ async setProductoPermisosAutorizables(slug, input) {
267
+ const segment = require_path_segment.encodePathSegment(slug);
268
+ if (segment === null) return invalidParamResult("setProductoPermisosAutorizables", "slug");
269
+ return adminFetch({
270
+ config,
271
+ method: "PUT",
272
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.setProductoPermisosAutorizables, { slug: segment }),
273
+ body: input
274
+ });
275
+ },
276
+ async reassignEmpresaTitular(empresaId, input) {
277
+ const segment = require_path_segment.encodePathSegment(empresaId);
278
+ if (segment === null) return invalidParamResult("reassignEmpresaTitular", "empresaId");
279
+ return adminFetch({
280
+ config,
281
+ method: "POST",
282
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.reassignEmpresaTitular, { id: segment }),
283
+ body: input
284
+ });
285
+ },
286
+ async bajaEmpresa(empresaId) {
287
+ const segment = require_path_segment.encodePathSegment(empresaId);
288
+ if (segment === null) return invalidParamResult("bajaEmpresa", "empresaId");
289
+ return adminFetch({
290
+ config,
291
+ method: "POST",
292
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.bajaEmpresa, { id: segment })
293
+ });
294
+ },
295
+ async reactivarEmpresa(empresaId) {
296
+ const segment = require_path_segment.encodePathSegment(empresaId);
297
+ if (segment === null) return invalidParamResult("reactivarEmpresa", "empresaId");
298
+ return adminFetch({
299
+ config,
300
+ method: "POST",
301
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.reactivarEmpresa, { id: segment })
302
+ });
303
+ },
304
+ async setContratacion(empresaId, producto, input) {
305
+ const segment = require_path_segment.encodePathSegment(empresaId);
306
+ if (segment === null) return invalidParamResult("setContratacion", "empresaId");
307
+ const productoSegment = require_path_segment.encodePathSegment(producto);
308
+ if (productoSegment === null) return invalidParamResult("setContratacion", "producto");
309
+ return adminFetch({
310
+ config,
311
+ method: "PUT",
312
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.setContratacion, {
313
+ id: segment,
314
+ producto: productoSegment
315
+ }),
316
+ body: input
317
+ });
318
+ },
319
+ async listProductos() {
320
+ return adminFetch({
321
+ config,
322
+ method: "GET",
323
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.listProductos)
324
+ });
325
+ },
326
+ async createProducto(input) {
327
+ return adminFetch({
328
+ config,
329
+ method: "POST",
330
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.createProducto),
331
+ body: input
332
+ });
333
+ },
334
+ async updateProducto(slug, input) {
335
+ const segment = require_path_segment.encodePathSegment(slug);
336
+ if (segment === null) return invalidParamResult("updateProducto", "slug");
337
+ return adminFetch({
338
+ config,
339
+ method: "PATCH",
340
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.updateProducto, { slug: segment }),
341
+ body: input
342
+ });
343
+ },
344
+ async restoreUser(userId) {
345
+ const segment = require_path_segment.encodePathSegment(userId);
346
+ if (segment === null) return invalidParamResult("restoreUser", "userId");
347
+ return adminFetch({
348
+ config,
349
+ method: "POST",
350
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.restoreUser, { id: segment })
351
+ });
352
+ },
353
+ async republishPendingWebhooks(query) {
354
+ const params = new URLSearchParams();
355
+ if (query?.older_than_minutes !== void 0) params.set("older_than_minutes", String(query.older_than_minutes));
356
+ if (query?.limit !== void 0) params.set("limit", String(query.limit));
357
+ return adminFetch({
358
+ config,
359
+ method: "POST",
360
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.republishPendingWebhooks),
361
+ rawQuery: params.toString()
362
+ });
363
+ },
364
+ async maintenanceCleanup(query) {
365
+ const params = new URLSearchParams();
366
+ if (query?.limit !== void 0) params.set("limit", String(query.limit));
367
+ return adminFetch({
368
+ config,
369
+ method: "POST",
370
+ pathname: require_api_path.apiPath(require_routes.ADMIN_ROUTES.maintenanceCleanup),
371
+ rawQuery: params.toString()
372
+ });
373
+ }
374
+ };
375
+ }
376
+ // src/admin/error-codes.ts
377
+ /**
378
+ * Códigos de error específicos del módulo Admin.
379
+ *
380
+ * Complementan a `ERROR_CODES` (core) para errores que solo ocurren
381
+ * en operaciones de provisioning de service clients.
382
+ *
383
+ * @example
384
+ * ```ts
385
+ * import { ADMIN_ERROR_CODES } from '@eva_solutions/auth-sdk/admin'
386
+ *
387
+ * if (!result.ok && result.error.code === ADMIN_ERROR_CODES.service_client_already_exists) {
388
+ * return res.status(409).json({ error: 'El service client ya existe' })
389
+ * }
390
+ * ```
391
+ */
392
+ const ADMIN_ERROR_CODES = {
393
+ service_client_already_exists: "service_client_already_exists",
394
+ service_client_not_found: "service_client_not_found",
395
+ /**
396
+ * `rotate-secret` perdió contra otra rotación concurrente del mismo service client (409).
397
+ * El perdedor no recibe secret; es reintentable.
398
+ */
399
+ service_client_secret_rotation_conflict: "service_client_secret_rotation_conflict",
400
+ /**
401
+ * La operación dejaría al sistema sin ningún service client admin habilitado (409): borrar,
402
+ * deshabilitar o quitarle `esAdmin` al último. No se aplica; habilita o crea otro admin.
403
+ */
404
+ last_admin_client: "last_admin_client"
405
+ };
406
+ Object.defineProperty(exports, "ADMIN_ERROR_CODES", {
407
+ enumerable: true,
408
+ get: function() {
409
+ return ADMIN_ERROR_CODES;
410
+ }
411
+ });
412
+ Object.defineProperty(exports, "createAdminClient", {
413
+ enumerable: true,
414
+ get: function() {
415
+ return createAdminClient;
416
+ }
417
+ });
418
+
419
+ //# sourceMappingURL=admin-Q6lbWqLM.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"admin-Q6lbWqLM.cjs","names":["signS2SHeaders","parseErrorResponse","apiPath","ADMIN_ROUTES","encodePathSegment"],"sources":["../src/admin/client.ts","../src/admin/error-codes.ts"],"sourcesContent":["/**\n * Cliente Admin para provisioning de service clients y gestión de usuarios\n * en el Auth Service.\n *\n * REQ-ADMIN-01, REQ-ADMIN-02, REQ-ADMIN-03, REQ-ADMIN-04, REQ-ADMIN-05 LOCKED.\n * REQ-RESTORE-01 LOCKED: endpoint POST /admin/users/:id/restore.\n *\n * Autenticación: firma HMAC S2S de un service client con la marca `esAdmin` (la superficie\n * `/admin` de Auth es la única, junto con el pedido de token, que conserva la firma). Una persona,\n * un client: el API registra el slug que firmó como `actor`.\n *\n * Endpoints:\n * POST /admin/service-clients → createServiceClient\n * GET /admin/service-clients → listServiceClients\n * GET /admin/service-clients/:slug → getServiceClient\n * PATCH /admin/service-clients/:slug → updateServiceClient\n * DELETE /admin/service-clients/:slug → deleteServiceClient (204)\n * POST /admin/service-clients/:slug/rotate-secret → rotateServiceClientSecret\n * GET /admin/service-clients/:slug/grants → listServiceClientGrants\n * PUT /admin/service-clients/:slug/grants → setServiceClientGrant\n * DELETE /admin/service-clients/:slug/grants/:audience → deleteServiceClientGrant (204)\n * GET /admin/service-clients/:slug/delegations → listServiceClientDelegations\n * PUT /admin/service-clients/:slug/delegations → setServiceClientDelegation\n * DELETE /admin/service-clients/:slug/delegations/:audience → deleteServiceClientDelegation (204)\n * GET /admin/productos/:slug/permisos-autorizables → getProductoPermisosAutorizables\n * PUT /admin/productos/:slug/permisos-autorizables → setProductoPermisosAutorizables\n * POST /admin/empresas/:id/titular → reassignEmpresaTitular\n * POST /admin/empresas/:id/baja → bajaEmpresa\n * POST /admin/empresas/:id/reactivar → reactivarEmpresa\n * PUT /admin/empresas/:id/productos/:producto → setContratacion\n * GET /admin/productos → listProductos\n * POST /admin/productos → createProducto (201)\n * PATCH /admin/productos/:slug → updateProducto\n * POST /admin/users/:id/restore → restoreUser\n * POST /admin/webhooks/republish-pending → republishPendingWebhooks\n * POST /admin/maintenance/cleanup → maintenanceCleanup\n *\n * Los paths salen de `ADMIN_ROUTES` (contrato compartido) vía `apiPath`; el slug y el id se\n * codifican como UN segmento con `encodePathSegment` (el mismo helper del cliente S2S) antes de\n * insertarlos. Un slug/id vacío, `.`, `..` o que no sea string devuelve un `Result` de error\n * (`kind: 'sdk'`, `reason: 'malformed'`) sin hacer la request.\n */\n\nimport { ADMIN_ROUTES } from '@eva_solutions/auth-contracts'\nimport { apiPath } from '../api-path'\nimport { validateHttpsUrl } from '../config'\nimport { parseErrorResponse } from '../parse-error-response'\nimport { encodePathSegment } from '../path-segment'\nimport { signS2SHeaders } from '../s2s/sign'\nimport type { Result } from '../types'\nimport type {\n AdminClientConfig,\n AdminContratacionResult,\n AdminEmpresaEstadoResult,\n AdminSetContratacionInput,\n ListServiceClientDelegationsResult,\n ProductoPermisosAutorizablesResult,\n ReassignEmpresaTitularInput,\n ReassignEmpresaTitularResult,\n ServiceClientDelegation,\n SetProductoPermisosAutorizablesInput,\n SetServiceClientDelegationInput,\n ServiceClientPublic,\n CreateServiceClientInput,\n CreateProductoInput,\n CreateServiceClientResult,\n ListProductosResult,\n ListServiceClientGrantsResult,\n ProductoResult,\n UpdateProductoInput,\n ServiceClientGrant,\n SetServiceClientGrantInput,\n UpdateServiceClientInput,\n UpdateServiceClientResult,\n RotateSecretResult,\n RestoreUserResult,\n MaintenanceCleanupQuery,\n MaintenanceCleanupResult,\n RepublishPendingWebhooksQuery,\n RepublishPendingWebhooksResult,\n} from './types'\n\nconst encoder = new TextEncoder()\n\n/**\n * Tipo del cliente Admin retornado por `createAdminClient`.\n */\nexport type AdminClient = {\n createServiceClient(\n input: CreateServiceClientInput,\n ): Promise<Result<CreateServiceClientResult>>\n listServiceClients(): Promise<Result<{ clientes: ServiceClientPublic[] }>>\n getServiceClient(\n slug: string,\n ): Promise<Result<{ cliente: ServiceClientPublic }>>\n updateServiceClient(\n slug: string,\n input: UpdateServiceClientInput,\n ): Promise<Result<UpdateServiceClientResult>>\n deleteServiceClient(slug: string): Promise<Result<void>>\n rotateServiceClientSecret(slug: string): Promise<Result<RotateSecretResult>>\n listServiceClientGrants(\n slug: string,\n ): Promise<Result<ListServiceClientGrantsResult>>\n /** Crea o reemplaza la concesión del client sobre una audiencia. */\n setServiceClientGrant(\n slug: string,\n input: SetServiceClientGrantInput,\n ): Promise<Result<{ grant: ServiceClientGrant }>>\n deleteServiceClientGrant(\n slug: string,\n audience: string,\n ): Promise<Result<void>>\n /** Lista las aristas de delegación del client (token exchange). */\n listServiceClientDelegations(\n slug: string,\n ): Promise<Result<ListServiceClientDelegationsResult>>\n /** Crea o reemplaza la arista del client hacia una audiencia delegable (`scopes`, `requiere_scope_origen`). */\n setServiceClientDelegation(\n slug: string,\n input: SetServiceClientDelegationInput,\n ): Promise<Result<{ delegation: ServiceClientDelegation }>>\n deleteServiceClientDelegation(\n slug: string,\n audience: string,\n ): Promise<Result<void>>\n /** Permisos entre empresas que el producto puede conceder en nombre de sus empresas. */\n getProductoPermisosAutorizables(\n slug: string,\n ): Promise<Result<ProductoPermisosAutorizablesResult>>\n /** Reemplaza la lista de permisos autorizables del producto (vacía = ninguno). */\n setProductoPermisosAutorizables(\n slug: string,\n input: SetProductoPermisosAutorizablesInput,\n ): Promise<Result<ProductoPermisosAutorizablesResult>>\n /** Reasigna el titular de una empresa (disputa de RUC o empresa sin titular). */\n reassignEmpresaTitular(\n empresaId: string,\n input: ReassignEmpresaTitularInput,\n ): Promise<Result<ReassignEmpresaTitularResult>>\n /** Da de baja una empresa (limpia sus sesiones activas; las autorizaciones y contrataciones dejan de valer). */\n bajaEmpresa(empresaId: string): Promise<Result<AdminEmpresaEstadoResult>>\n /** Reactiva una empresa de baja. */\n reactivarEmpresa(empresaId: string): Promise<Result<AdminEmpresaEstadoResult>>\n /** Escribe el estado y el vencimiento de la contratación de un producto por una empresa (hasta que exista facturación, así se activa a mano). */\n setContratacion(\n empresaId: string,\n producto: string,\n input: AdminSetContratacionInput,\n ): Promise<Result<AdminContratacionResult>>\n /** Lista los productos (la audiencia del access token de usuario). */\n listProductos(): Promise<Result<ListProductosResult>>\n /** Crea un producto (201). 409 si el slug existe; 400 si es una audiencia de servicio. */\n createProducto(input: CreateProductoInput): Promise<Result<ProductoResult>>\n /** Actualiza `nombre` o `enabled`. 404 si no existe; 400 con body vacío. No hay delete: se deshabilita. */\n updateProducto(\n slug: string,\n input: UpdateProductoInput,\n ): Promise<Result<ProductoResult>>\n restoreUser(userId: string): Promise<Result<RestoreUserResult>>\n republishPendingWebhooks(\n query?: RepublishPendingWebhooksQuery,\n ): Promise<Result<RepublishPendingWebhooksResult>>\n maintenanceCleanup(\n query?: MaintenanceCleanupQuery,\n ): Promise<Result<MaintenanceCleanupResult>>\n}\n\n// ---------------------------------------------------------------------------\n// Helper interno\n// ---------------------------------------------------------------------------\n\n/**\n * Realiza un fetch autenticado S2S firmando el request con HMAC-SHA-256.\n * Retorna `Result<T>` con la propiedad `data` del body de respuesta.\n */\nasync function adminFetch<T>({\n config,\n method,\n pathname,\n rawQuery = '',\n body,\n}: {\n config: AdminClientConfig\n method: string\n pathname: string\n rawQuery?: string\n body?: unknown\n}): Promise<Result<T>> {\n try {\n const bodyBytes: Uint8Array =\n body !== undefined\n ? encoder.encode(JSON.stringify(body))\n : new Uint8Array(0)\n\n const url = rawQuery\n ? `${config.baseUrl}${pathname}?${rawQuery}`\n : `${config.baseUrl}${pathname}`\n\n // Se firma el pathname y el query de la URL FINAL (incluido el prefijo de `baseUrl`), que es\n // lo que el verificador lee en `request.url`.\n const target = new URL(url)\n const authHeaders = await signS2SHeaders({\n method,\n path: target.pathname,\n rawQuery: target.search.slice(1),\n bodyBytes,\n clientId: config.clientId,\n secretHex: config.secretHex,\n })\n\n const headers: Record<string, string> = {\n 'content-type': 'application/json',\n ...authHeaders,\n }\n\n const res = await fetch(url, {\n method,\n headers,\n body: bodyBytes.length > 0 ? JSON.stringify(body) : undefined,\n signal: AbortSignal.timeout(10_000),\n })\n\n if (!res.ok) {\n const responseBody = await res.json().catch(() => null)\n return { ok: false, error: parseErrorResponse(res.status, responseBody) }\n }\n\n // 204 No Content — Result<void>\n if (res.status === 204) {\n return { ok: true, data: undefined as T }\n }\n\n const json = (await res.json()) as { data: T }\n return { ok: true, data: json.data }\n } catch (err) {\n const message = err instanceof Error ? err.message : 'Network error'\n return {\n ok: false,\n error: {\n kind: 'sdk',\n reason: 'network',\n message,\n status: 0,\n },\n }\n }\n}\n\n/**\n * Result de error para un slug/id que no se puede usar como segmento del path. Se devuelve antes\n * de armar la URL: `apiPath` lanzaría con un param ausente y la promesa se rechazaría.\n */\nfunction invalidParamResult(method: string, param: string): Result<never> {\n return {\n ok: false,\n error: {\n kind: 'sdk',\n reason: 'malformed',\n message: `${method}: ${param} inválido (no puede ser vacío, \".\" ni \"..\")`,\n status: 0,\n },\n }\n}\n\n// ---------------------------------------------------------------------------\n// Factory\n// ---------------------------------------------------------------------------\n\n/**\n * Crea un cliente Admin para provisioning del Auth Service.\n *\n * ADVERTENCIA: solo usar desde backends o herramientas de operador seguras — el secret del\n * service client admin nunca debe exponerse en el cliente/browser.\n *\n * @example\n * ```ts\n * const admin = createAdminClient({\n * clientId: process.env.AUTH_ADMIN_SLUG,\n * secretHex: process.env.AUTH_ADMIN_SECRET,\n * baseUrl: 'https://auth.miapp.com',\n * })\n * const result = await admin.createServiceClient({ slug: 'mi-servicio' })\n * if (!result.ok) return handleError(result.error)\n * console.log('Secret (guardar ahora):', result.data.secret)\n * ```\n */\nexport function createAdminClient(config: AdminClientConfig): AdminClient {\n validateHttpsUrl(config.baseUrl, 'AdminClientConfig.baseUrl')\n return {\n async createServiceClient(\n input: CreateServiceClientInput,\n ): Promise<Result<CreateServiceClientResult>> {\n return adminFetch<CreateServiceClientResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.createServiceClient),\n body: input,\n })\n },\n\n async listServiceClients(): Promise<\n Result<{ clientes: ServiceClientPublic[] }>\n > {\n return adminFetch<{ clientes: ServiceClientPublic[] }>({\n config,\n method: 'GET',\n pathname: apiPath(ADMIN_ROUTES.listServiceClients),\n })\n },\n\n async getServiceClient(\n slug: string,\n ): Promise<Result<{ cliente: ServiceClientPublic }>> {\n const segment = encodePathSegment(slug)\n if (segment === null)\n return invalidParamResult('getServiceClient', 'slug')\n return adminFetch<{ cliente: ServiceClientPublic }>({\n config,\n method: 'GET',\n pathname: apiPath(ADMIN_ROUTES.getServiceClient, { slug: segment }),\n })\n },\n\n async updateServiceClient(\n slug: string,\n input: UpdateServiceClientInput,\n ): Promise<Result<UpdateServiceClientResult>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('updateServiceClient', 'slug')\n }\n return adminFetch<UpdateServiceClientResult>({\n config,\n method: 'PATCH',\n pathname: apiPath(ADMIN_ROUTES.updateServiceClient, { slug: segment }),\n body: input,\n })\n },\n\n async deleteServiceClient(slug: string): Promise<Result<void>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('deleteServiceClient', 'slug')\n }\n return adminFetch<void>({\n config,\n method: 'DELETE',\n pathname: apiPath(ADMIN_ROUTES.deleteServiceClient, { slug: segment }),\n })\n },\n\n async rotateServiceClientSecret(\n slug: string,\n ): Promise<Result<RotateSecretResult>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('rotateServiceClientSecret', 'slug')\n }\n return adminFetch<RotateSecretResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.rotateServiceClientSecret, {\n slug: segment,\n }),\n })\n },\n\n async listServiceClientGrants(\n slug: string,\n ): Promise<Result<ListServiceClientGrantsResult>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('listServiceClientGrants', 'slug')\n }\n return adminFetch<ListServiceClientGrantsResult>({\n config,\n method: 'GET',\n pathname: apiPath(ADMIN_ROUTES.listServiceClientGrants, {\n slug: segment,\n }),\n })\n },\n\n async setServiceClientGrant(\n slug: string,\n input: SetServiceClientGrantInput,\n ): Promise<Result<{ grant: ServiceClientGrant }>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('setServiceClientGrant', 'slug')\n }\n return adminFetch<{ grant: ServiceClientGrant }>({\n config,\n method: 'PUT',\n pathname: apiPath(ADMIN_ROUTES.setServiceClientGrant, {\n slug: segment,\n }),\n body: input,\n })\n },\n\n async deleteServiceClientGrant(\n slug: string,\n audience: string,\n ): Promise<Result<void>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('deleteServiceClientGrant', 'slug')\n }\n const audienceSegment = encodePathSegment(audience)\n if (audienceSegment === null) {\n return invalidParamResult('deleteServiceClientGrant', 'audience')\n }\n return adminFetch<void>({\n config,\n method: 'DELETE',\n pathname: apiPath(ADMIN_ROUTES.deleteServiceClientGrant, {\n slug: segment,\n audience: audienceSegment,\n }),\n })\n },\n\n async listServiceClientDelegations(\n slug: string,\n ): Promise<Result<ListServiceClientDelegationsResult>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('listServiceClientDelegations', 'slug')\n }\n return adminFetch<ListServiceClientDelegationsResult>({\n config,\n method: 'GET',\n pathname: apiPath(ADMIN_ROUTES.listServiceClientDelegations, {\n slug: segment,\n }),\n })\n },\n\n async setServiceClientDelegation(\n slug: string,\n input: SetServiceClientDelegationInput,\n ): Promise<Result<{ delegation: ServiceClientDelegation }>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('setServiceClientDelegation', 'slug')\n }\n return adminFetch<{ delegation: ServiceClientDelegation }>({\n config,\n method: 'PUT',\n pathname: apiPath(ADMIN_ROUTES.setServiceClientDelegation, {\n slug: segment,\n }),\n body: input,\n })\n },\n\n async deleteServiceClientDelegation(\n slug: string,\n audience: string,\n ): Promise<Result<void>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('deleteServiceClientDelegation', 'slug')\n }\n const audienceSegment = encodePathSegment(audience)\n if (audienceSegment === null) {\n return invalidParamResult('deleteServiceClientDelegation', 'audience')\n }\n return adminFetch<void>({\n config,\n method: 'DELETE',\n pathname: apiPath(ADMIN_ROUTES.deleteServiceClientDelegation, {\n slug: segment,\n audience: audienceSegment,\n }),\n })\n },\n\n async getProductoPermisosAutorizables(\n slug: string,\n ): Promise<Result<ProductoPermisosAutorizablesResult>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('getProductoPermisosAutorizables', 'slug')\n }\n return adminFetch<ProductoPermisosAutorizablesResult>({\n config,\n method: 'GET',\n pathname: apiPath(ADMIN_ROUTES.getProductoPermisosAutorizables, {\n slug: segment,\n }),\n })\n },\n\n async setProductoPermisosAutorizables(\n slug: string,\n input: SetProductoPermisosAutorizablesInput,\n ): Promise<Result<ProductoPermisosAutorizablesResult>> {\n const segment = encodePathSegment(slug)\n if (segment === null) {\n return invalidParamResult('setProductoPermisosAutorizables', 'slug')\n }\n return adminFetch<ProductoPermisosAutorizablesResult>({\n config,\n method: 'PUT',\n pathname: apiPath(ADMIN_ROUTES.setProductoPermisosAutorizables, {\n slug: segment,\n }),\n body: input,\n })\n },\n\n async reassignEmpresaTitular(\n empresaId: string,\n input: ReassignEmpresaTitularInput,\n ): Promise<Result<ReassignEmpresaTitularResult>> {\n const segment = encodePathSegment(empresaId)\n if (segment === null) {\n return invalidParamResult('reassignEmpresaTitular', 'empresaId')\n }\n return adminFetch<ReassignEmpresaTitularResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.reassignEmpresaTitular, { id: segment }),\n body: input,\n })\n },\n\n async bajaEmpresa(\n empresaId: string,\n ): Promise<Result<AdminEmpresaEstadoResult>> {\n const segment = encodePathSegment(empresaId)\n if (segment === null) {\n return invalidParamResult('bajaEmpresa', 'empresaId')\n }\n return adminFetch<AdminEmpresaEstadoResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.bajaEmpresa, { id: segment }),\n })\n },\n\n async reactivarEmpresa(\n empresaId: string,\n ): Promise<Result<AdminEmpresaEstadoResult>> {\n const segment = encodePathSegment(empresaId)\n if (segment === null) {\n return invalidParamResult('reactivarEmpresa', 'empresaId')\n }\n return adminFetch<AdminEmpresaEstadoResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.reactivarEmpresa, { id: segment }),\n })\n },\n\n async setContratacion(\n empresaId: string,\n producto: string,\n input: AdminSetContratacionInput,\n ): Promise<Result<AdminContratacionResult>> {\n const segment = encodePathSegment(empresaId)\n if (segment === null) {\n return invalidParamResult('setContratacion', 'empresaId')\n }\n const productoSegment = encodePathSegment(producto)\n if (productoSegment === null) {\n return invalidParamResult('setContratacion', 'producto')\n }\n return adminFetch<AdminContratacionResult>({\n config,\n method: 'PUT',\n pathname: apiPath(ADMIN_ROUTES.setContratacion, {\n id: segment,\n producto: productoSegment,\n }),\n body: input,\n })\n },\n\n async listProductos(): Promise<Result<ListProductosResult>> {\n return adminFetch<ListProductosResult>({\n config,\n method: 'GET',\n pathname: apiPath(ADMIN_ROUTES.listProductos),\n })\n },\n\n async createProducto(\n input: CreateProductoInput,\n ): Promise<Result<ProductoResult>> {\n return adminFetch<ProductoResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.createProducto),\n body: input,\n })\n },\n\n async updateProducto(\n slug: string,\n input: UpdateProductoInput,\n ): Promise<Result<ProductoResult>> {\n const segment = encodePathSegment(slug)\n if (segment === null) return invalidParamResult('updateProducto', 'slug')\n return adminFetch<ProductoResult>({\n config,\n method: 'PATCH',\n pathname: apiPath(ADMIN_ROUTES.updateProducto, { slug: segment }),\n body: input,\n })\n },\n\n async restoreUser(userId: string): Promise<Result<RestoreUserResult>> {\n const segment = encodePathSegment(userId)\n if (segment === null) return invalidParamResult('restoreUser', 'userId')\n return adminFetch<RestoreUserResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.restoreUser, { id: segment }),\n })\n },\n\n async republishPendingWebhooks(\n query?: RepublishPendingWebhooksQuery,\n ): Promise<Result<RepublishPendingWebhooksResult>> {\n const params = new URLSearchParams()\n if (query?.older_than_minutes !== undefined) {\n params.set('older_than_minutes', String(query.older_than_minutes))\n }\n if (query?.limit !== undefined) {\n params.set('limit', String(query.limit))\n }\n return adminFetch<RepublishPendingWebhooksResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.republishPendingWebhooks),\n rawQuery: params.toString(),\n })\n },\n\n async maintenanceCleanup(\n query?: MaintenanceCleanupQuery,\n ): Promise<Result<MaintenanceCleanupResult>> {\n const params = new URLSearchParams()\n if (query?.limit !== undefined) {\n params.set('limit', String(query.limit))\n }\n return adminFetch<MaintenanceCleanupResult>({\n config,\n method: 'POST',\n pathname: apiPath(ADMIN_ROUTES.maintenanceCleanup),\n rawQuery: params.toString(),\n })\n },\n }\n}\n","/**\n * Códigos de error específicos del módulo Admin.\n *\n * Complementan a `ERROR_CODES` (core) para errores que solo ocurren\n * en operaciones de provisioning de service clients.\n *\n * @example\n * ```ts\n * import { ADMIN_ERROR_CODES } from '@eva_solutions/auth-sdk/admin'\n *\n * if (!result.ok && result.error.code === ADMIN_ERROR_CODES.service_client_already_exists) {\n * return res.status(409).json({ error: 'El service client ya existe' })\n * }\n * ```\n */\nexport const ADMIN_ERROR_CODES = {\n service_client_already_exists: 'service_client_already_exists',\n service_client_not_found: 'service_client_not_found',\n /**\n * `rotate-secret` perdió contra otra rotación concurrente del mismo service client (409).\n * El perdedor no recibe secret; es reintentable.\n */\n service_client_secret_rotation_conflict:\n 'service_client_secret_rotation_conflict',\n /**\n * La operación dejaría al sistema sin ningún service client admin habilitado (409): borrar,\n * deshabilitar o quitarle `esAdmin` al último. No se aplica; habilita o crea otro admin.\n */\n last_admin_client: 'last_admin_client',\n} as const\n\n/** Unión de literales de los error codes específicos del módulo Admin. */\nexport type AdminErrorCode =\n (typeof ADMIN_ERROR_CODES)[keyof typeof ADMIN_ERROR_CODES]\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkFA,MAAM,UAAU,IAAI,YAAY;;;;;AA8FhC,eAAe,WAAc,EAC3B,QACA,QACA,UACA,WAAW,IACX,QAOqB;CACrB,IAAI;EACF,MAAM,YACJ,SAAS,KAAA,IACL,QAAQ,OAAO,KAAK,UAAU,IAAI,CAAC,oBACnC,IAAI,WAAW,CAAC;EAEtB,MAAM,MAAM,WACR,GAAG,OAAO,UAAU,SAAS,GAAG,aAChC,GAAG,OAAO,UAAU;EAIxB,M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H_PARAM = /\{(\w+)\}/g;
4
+ /**
5
+ * Builds the request path of a contract route: fills every `{param}` of the descriptor path and
6
+ * returns `API_PREFIX + path`. Throws when a param is missing (a programming error, never a
7
+ * runtime condition).
8
+ *
9
+ * Every versioned route is built here, so the prefix lives in this single place. Routes that stay
10
+ * at the root (`/.well-known/jwks.json` in `jwks.ts`, `/health` in `http-client.ts`) do not go
11
+ * through this helper. Requests to `/internal/*` sign the final URL pathname, which already
12
+ * includes the prefix.
13
+ *
14
+ * Import rule (react closure): only `http-client.ts` and the S2S/admin clients import this module,
15
+ * none of them reachable from `src/react`. The by-value import of `API_PREFIX` is safe because it
16
+ * comes from the PURE `routes` module of the contract (no zod). Keep it that way: never import a
17
+ * schema module by value here.
18
+ */
19
+ function apiPath(route, params = {}) {
20
+ const filled = route.path.replace(PATH_PARAM, (_match, key) => {
21
+ const value = params[key];
22
+ if (value === void 0) throw new Error(`[eva-auth-sdk] missing path param ${key}`);
23
+ return value;
24
+ });
25
+ return `${require_routes.API_PREFIX}${filled}`;
26
+ }
27
+ Object.defineProperty(exports, "apiPath", {
28
+ enumerable: true,
29
+ get: function() {
30
+ return apiPath;
31
+ }
32
+ });
33
+
34
+ //# sourceMappingURL=api-path-2Ulruz7R.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-path-2Ulruz7R.cjs","names":["API_PREFIX"],"sources":["../src/api-path.ts"],"sourcesContent":["import { API_PREFIX } from '@eva_solutions/auth-contracts'\nimport type { RouteDescriptor } from '@eva_solutions/auth-contracts'\n\nconst PATH_PARAM = /\\{(\\w+)\\}/g\n\n/**\n * Builds the request path of a contract route: fills every `{param}` of the descriptor path and\n * returns `API_PREFIX + path`. Throws when a param is missing (a programming error, never a\n * runtime condition).\n *\n * Every versioned route is built here, so the prefix lives in this single place. Routes that stay\n * at the root (`/.well-known/jwks.json` in `jwks.ts`, `/health` in `http-client.ts`) do not go\n * through this helper. Requests to `/internal/*` sign the final URL pathname, which already\n * includes the prefix.\n *\n * Import rule (react closure): only `http-client.ts` and the S2S/admin clients import this module,\n * none of them reachable from `src/react`. The by-value import of `API_PREFIX` is safe because it\n * comes from the PURE `routes` module of the contract (no zod). Keep it that way: never import a\n * schema module by value here.\n */\nexport function apiPath(\n route: RouteDescriptor,\n params: Readonly<Record<string, string>> = {},\n): string {\n const filled = route.path.replace(PATH_PARAM, (_match, key: string) => {\n const value = params[key]\n if (value === undefined) {\n throw new Error(`[eva-auth-sdk] missing path param ${key}`)\n }\n return value\n })\n return `${API_PREFIX}${filled}`\n}\n"],"mappings":";;AAGA,MAAM,aAAa;;;;;;;;;;;;;;;;AAiBnB,SAAgB,QACd,OACA,SAA2C,CAAC,GACpC;CACR,MAAM,SAAS,MAAM,KAAK,QAAQ,aAAa,QAAQ,QAAgB;EACrE,MAAM,QAAQ,OAAO;EACrB,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MAAM,qCAAqC,KAAK;EAE5D,OAAO;CACT,CAAC;CACD,OAAO,GAAGA,eAAAA,aAAa;AACzB"}
@@ -0,0 +1,29 @@
1
+ import { n as API_PREFIX } from "./routes-F1g5aVqP.js";
2
+ // src/api-path.ts
3
+ const PATH_PARAM = /\{(\w+)\}/g;
4
+ /**
5
+ * Builds the request path of a contract route: fills every `{param}` of the descriptor path and
6
+ * returns `API_PREFIX + path`. Throws when a param is missing (a programming error, never a
7
+ * runtime condition).
8
+ *
9
+ * Every versioned route is built here, so the prefix lives in this single place. Routes that stay
10
+ * at the root (`/.well-known/jwks.json` in `jwks.ts`, `/health` in `http-client.ts`) do not go
11
+ * through this helper. Requests to `/internal/*` sign the final URL pathname, which already
12
+ * includes the prefix.
13
+ *
14
+ * Import rule (react closure): only `http-client.ts` and the S2S/admin clients import this module,
15
+ * none of them reachable from `src/react`. The by-value import of `API_PREFIX` is safe because it
16
+ * comes from the PURE `routes` module of the contract (no zod). Keep it that way: never import a
17
+ * schema module by value here.
18
+ */
19
+ function apiPath(route, params = {}) {
20
+ const filled = route.path.replace(PATH_PARAM, (_match, key) => {
21
+ const value = params[key];
22
+ if (value === void 0) throw new Error(`[eva-auth-sdk] missing path param ${key}`);
23
+ return value;
24
+ });
25
+ return `${API_PREFIX}${filled}`;
26
+ }
27
+ export { apiPath as t };
28
+
29
+ //# sourceMappingURL=api-path-B-vSkL2H.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-path-B-vSkL2H.js","names":[],"sources":["../src/api-path.ts"],"sourcesContent":["import { API_PREFIX } from '@eva_solutions/auth-contracts'\nimport type { RouteDescriptor } from '@eva_solutions/auth-contracts'\n\nconst PATH_PARAM = /\\{(\\w+)\\}/g\n\n/**\n * Builds the request path of a contract route: fills every `{param}` of the descriptor path and\n * returns `API_PREFIX + path`. Throws when a param is missing (a programming error, never a\n * runtime condition).\n *\n * Every versioned route is built here, so the prefix lives in this single place. Routes that stay\n * at the root (`/.well-known/jwks.json` in `jwks.ts`, `/health` in `http-client.ts`) do not go\n * through this helper. Requests to `/internal/*` sign the final URL pathname, which already\n * includes the prefix.\n *\n * Import rule (react closure): only `http-client.ts` and the S2S/admin clients import this module,\n * none of them reachable from `src/react`. The by-value import of `API_PREFIX` is safe because it\n * comes from the PURE `routes` module of the contract (no zod). Keep it that way: never import a\n * schema module by value here.\n */\nexport function apiPath(\n route: RouteDescriptor,\n params: Readonly<Record<string, string>> = {},\n): string {\n const filled = route.path.replace(PATH_PARAM, (_match, key: string) => {\n const value = params[key]\n if (value === undefined) {\n throw new Error(`[eva-auth-sdk] missing path param ${key}`)\n }\n return value\n })\n return `${API_PREFIX}${filled}`\n}\n"],"mappings":";;AAGA,MAAM,aAAa;;;;;;;;;;;;;;;;AAiBnB,SAAgB,QACd,OACA,SAA2C,CAAC,GACpC;CACR,MAAM,SAAS,MAAM,KAAK,QAAQ,aAAa,QAAQ,QAAgB;EACrE,MAAM,QAAQ,OAAO;EACrB,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MAAM,qCAAqC,KAAK;EAE5D,OAAO;CACT,CAAC;CACD,OAAO,GAAG,aAAa;AACzB"}
@@ -0,0 +1,84 @@
1
+ import { z } from "zod";
2
+ // ../auth-contracts/dist/errors.js
3
+ /**
4
+ * SCHEMA module (it calls `.meta()` at load time): react-reachable SDK code must not import it by
5
+ * value. It holds only the error body; the error codes live in the PURE `constants.ts`.
6
+ *
7
+ * Wire shape `{ error: { code, message } }`. `code` is an open `string`, not an enum: features add
8
+ * their own snake_case codes. Metadata uses only the zod-native metadata API, never the zod-to-openapi extension.
9
+ */
10
+ const errorResponseSchema = z.object({ error: z.object({
11
+ code: z.string().meta({ description: "Código de error enumerado (snake_case ASCII)" }),
12
+ message: z.string().meta({ description: "Mensaje human-readable del error" })
13
+ }) }).meta({ id: "ErrorBody" });
14
+ // ../auth-contracts/dist/auth.js
15
+ /**
16
+ * SCHEMA module: wire schemas of the login flow. Body schemas stay plain strict objects (no
17
+ * `.refine`), so the API can plug them into `createRoute` without changing the OpenAPI document.
18
+ * Metadata uses `.meta()` only. Refresh answers with `loginResponseSchema`; logout with the
19
+ * generic message response from `common.ts`. The refresh header schema is API-owned.
20
+ */
21
+ const INTERNATIONAL_DIALING_PREFIX = /^00/;
22
+ const phoneSchema = z.string().min(8).max(22).regex(/^\d+$/, { error: "Solo dígitos permitidos" }).transform((val) => val.replace(INTERNATIONAL_DIALING_PREFIX, "")).pipe(z.string().min(8).max(20).regex(/^[1-9]/, { error: "Formato internacional inválido" })).meta({
23
+ description: "Número de teléfono en formato internacional",
24
+ example: "5491155551234"
25
+ });
26
+ /**
27
+ * Product slug: same shape as a service client slug. It never equals a service audience; the API
28
+ * checks that with `isServiceAudience`.
29
+ */
30
+ const productoSlugSchema = z.string().regex(/^[a-z][a-z0-9-]{2,63}$/, { error: "producto debe matchear ^[a-z][a-z0-9-]{2,63}$" }).meta({
31
+ description: "Producto al que entra la persona",
32
+ example: "whatsapp-panel"
33
+ });
34
+ const getCodeRequestSchema = z.object({ phone: phoneSchema }).strict();
35
+ /**
36
+ * The two `challengeId` descriptions (here and in the login request) name no route and no path:
37
+ * route names and prefixes live only in the route descriptors, so a path change never leaves a
38
+ * stale description in the published OpenAPI document.
39
+ */
40
+ const getCodeResponseSchema = z.object({ data: z.object({
41
+ message: z.string().meta({ description: "Mensaje de confirmación" }),
42
+ challengeId: z.string().regex(/^[0-9a-f]{32}$/).meta({
43
+ description: "Identificador opaco del desafío; enviarlo en el login junto con el código. Vence con el código y se invalida con cada get-code nuevo.",
44
+ example: "9f86d081884c7d659a2feaa0c55ad015"
45
+ })
46
+ }) });
47
+ /** Login body. `challengeId` is lowercase hex and is rejected, never normalized. */
48
+ const loginRequestSchema = z.object({
49
+ phone: phoneSchema,
50
+ code: z.string().length(6).regex(/^[0-9A-Za-z]+$/, { error: "Solo dígitos y letras" }).transform((val) => val.toUpperCase()).meta({
51
+ description: "Código OTP de 6 caracteres",
52
+ example: "A1B2C3"
53
+ }),
54
+ producto: productoSlugSchema,
55
+ empresaId: z.string().min(1).max(64).optional().meta({ description: "Empresa que queda activa en la sesión (opcional)" }),
56
+ challengeId: z.string().regex(/^[0-9a-f]{32}$/, { error: "Formato de challenge inválido" }).meta({
57
+ description: "challengeId devuelto por la solicitud de código (get-code)",
58
+ example: "9f86d081884c7d659a2feaa0c55ad015"
59
+ }),
60
+ deviceType: z.string().min(1).max(50).regex(/^[\x20-\x7E\xA0-\xFF]*$/, { error: "Caracteres de control no permitidos" }).meta({
61
+ description: "Tipo de dispositivo (mobile, desktop, tablet)",
62
+ example: "mobile"
63
+ }),
64
+ os: z.string().min(1).max(100).regex(/^[\x20-\x7E\xA0-\xFF]*$/, { error: "Caracteres de control no permitidos" }).meta({
65
+ description: "Sistema operativo del dispositivo",
66
+ example: "Android 14"
67
+ }),
68
+ browser: z.string().min(1).max(100).regex(/^[\x20-\x7E\xA0-\xFF]*$/, { error: "Caracteres de control no permitidos" }).meta({
69
+ description: "Navegador o aplicación cliente",
70
+ example: "Chrome 120"
71
+ }),
72
+ userAgent: z.string().min(1).max(500).regex(/^[\x20-\x7E\xA0-\xFF]*$/, { error: "Caracteres de control no permitidos" }).meta({
73
+ description: "User-Agent completo del cliente",
74
+ example: "Mozilla/5.0 ..."
75
+ })
76
+ }).strict();
77
+ const loginResponseSchema = z.object({ data: z.object({ user: z.object({ id: z.string().meta({ description: "ID del usuario" }) }) }) });
78
+ /** Active company switch body: an id, or `null` to leave the session without one. */
79
+ const setActiveEmpresaRequestSchema = z.object({ empresaId: z.string().min(1).max(64).nullable().meta({ description: "Empresa que queda activa, o null para ninguna" }) }).strict();
80
+ /** Active company switch answer. The re-issued access token travels in the `x-eva-new-access-token` header; the refresh token does not rotate. */
81
+ const setActiveEmpresaResponseSchema = z.object({ data: z.object({ empresaId: z.string().nullable().meta({ description: "Empresa activa" }) }) });
82
+ export { productoSlugSchema as a, errorResponseSchema as c, loginResponseSchema as i, getCodeResponseSchema as n, setActiveEmpresaRequestSchema as o, loginRequestSchema as r, setActiveEmpresaResponseSchema as s, getCodeRequestSchema as t };
83
+
84
+ //# sourceMappingURL=auth-19r-Q6X2.js.map