@abitechdev/openchasqui 0.0.0-stage → 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ OpenChasqui
2
+ Copyright 2026 The OpenChasqui Authors
3
+
4
+ This product is licensed under the Apache License, Version 2.0.
package/README.md CHANGED
@@ -1,3 +1,254 @@
1
- # Temporary Holding Version
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/abitech-dev/abitech-openchasqui-cli/main/.github/assets/logo-dark.svg">
4
+ <img alt="OpenChasqui" src="https://raw.githubusercontent.com/abitech-dev/abitech-openchasqui-cli/main/.github/assets/logo-light.svg" width="400">
5
+ </picture>
6
+ </p>
2
7
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
8
+ <p align="center">
9
+ <strong>Tu contrato OpenAPI, entregado como colecciones de Postman y Bruno con pruebas.</strong>
10
+ </p>
11
+
12
+ <p align="center">
13
+ <a href="https://www.npmjs.com/package/@abitechdev/openchasqui"><img alt="npm" src="https://img.shields.io/npm/v/@abitechdev/openchasqui?color=c2410c&label=npm"></a>
14
+ <a href="https://github.com/abitech-dev/abitech-openchasqui-cli/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/abitech-dev/abitech-openchasqui-cli/actions/workflows/ci.yml/badge.svg"></a>
15
+ <img alt="Node.js 22 o superior" src="https://img.shields.io/badge/node-%E2%89%A522-339933">
16
+ <img alt="OpenAPI 3.0 y 3.1" src="https://img.shields.io/badge/OpenAPI-3.0%20%7C%203.1-6ba539">
17
+ <a href="https://github.com/abitech-dev/abitech-openchasqui-cli/blob/main/LICENSE"><img alt="Apache-2.0" src="https://img.shields.io/badge/license-Apache--2.0-blue"></a>
18
+ </p>
19
+
20
+ <p align="center">
21
+ <a href="#instalación">Instalación</a> ·
22
+ <a href="#inicio-rápido">Inicio rápido</a> ·
23
+ <a href="#configuración">Configuración</a> ·
24
+ <a href="#overlays">Overlays</a> ·
25
+ <a href="#políticas">Políticas</a> ·
26
+ <a href="#paquetes">Paquetes</a> ·
27
+ <a href="https://github.com/abitech-dev/abitech-openchasqui-cli/blob/main/README.en.md">English</a>
28
+ </p>
29
+
30
+ <p align="center">
31
+ <img alt="openchasqui generate seguido de una corrida de Bruno con 20 de 20 pruebas aprobadas" src="https://raw.githubusercontent.com/abitech-dev/abitech-openchasqui-cli/main/.github/assets/terminal.svg" width="760">
32
+ </p>
33
+
34
+ El _chasqui_ llevaba mensajes por la red de caminos inca. OpenChasqui lleva tu
35
+ contrato de API a cada herramienta que usa tu equipo: un comando convierte un
36
+ documento OpenAPI en colecciones con entornos, ejemplos realistas y pruebas de
37
+ contrato, y el CI evita que se desactualicen.
38
+
39
+ > [!NOTE]
40
+ > OpenChasqui está en desarrollo temprano (0.x). La configuración y el contrato
41
+ > de plugins pueden cambiar antes de la 1.0.
42
+
43
+ ## Características
44
+
45
+ | | |
46
+ | -------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
47
+ | **Una sola fuente de verdad.** Las colecciones se generan desde el contrato y nunca se editan a mano, así que no se separan de la API. | **Pruebas incluidas.** Cada petición comprueba su estado, tipo de contenido, esquema de respuesta y tiempo de respuesta. |
48
+ | **Postman y Bruno.** Postman Collection v2.1 y Bruno OpenCollection YAML en la misma corrida. | **Overlays.** Renombra, reagrupa u oculta endpoints con OpenAPI Overlay 1.0, sin tocar el contrato. |
49
+ | **Datos realistas.** Ejemplos deterministas, con DNI, RUC, celulares y ubigeo peruanos cuando los pidas. | **Seguro por defecto.** Los secretos nunca llevan valor, los ejemplos no pueden traer tokens y solo se sobrescriben sus propias carpetas. |
50
+
51
+ ## Herramientas
52
+
53
+ Elige una o varias en `targets`; `targets: [bruno]` genera solo Bruno.
54
+
55
+ | Herramienta | `targets` | Estado |
56
+ | ------------------------------------- | --------- | ------------- |
57
+ | Postman (Collection v2.1) | `postman` | Disponible |
58
+ | Bruno (OpenCollection YAML) | `bruno` | Disponible |
59
+ | Archivos `.http` (VS Code, JetBrains) | | Planeado, 1.2 |
60
+ | Insomnia | | Planeado, 1.2 |
61
+ | k6 y Playwright | | Planeado, 2.0 |
62
+
63
+ Cada herramienta es un plugin emisor; sumar una no toca el núcleo.
64
+
65
+ ## Instalación
66
+
67
+ Requiere Node.js 22 o superior. Instálalo como dependencia de desarrollo del
68
+ proyecto que tiene el contrato:
69
+
70
+ ```bash
71
+ npm i -D @abitechdev/openchasqui
72
+ pnpm add -D @abitechdev/openchasqui
73
+ yarn add -D @abitechdev/openchasqui
74
+ ```
75
+
76
+ Así el comando queda como `npx openchasqui`. También funciona sin instalar,
77
+ con `npx @abitechdev/openchasqui`.
78
+
79
+ ## Inicio rápido
80
+
81
+ En la carpeta de tu `openapi.yaml`:
82
+
83
+ ```bash
84
+ npx @abitechdev/openchasqui init # crea openchasqui.config.yaml
85
+ npx @abitechdev/openchasqui generate # escribe collections/postman y collections/bruno
86
+ npx @abitechdev/openchasqui verify # en CI: políticas en verde y colecciones al día
87
+ ```
88
+
89
+ Importa la carpeta en Postman o Bruno, o córrela desde la línea de comandos:
90
+
91
+ ```bash
92
+ npx newman run collections/postman/*.postman_collection.json \
93
+ -e collections/postman/*-dev.postman_environment.json
94
+ cd collections/bruno && npx @usebruno/cli run --env dev
95
+ ```
96
+
97
+ ## Cómo funciona
98
+
99
+ ```mermaid
100
+ flowchart LR
101
+ A[OpenAPI 3.0 / 3.1] --> B[Overlays]
102
+ B --> C[Cargador]
103
+ C --> D[Ejemplos y pruebas]
104
+ D --> E[Políticas]
105
+ E --> F[Postman v2.1]
106
+ E --> G[Bruno OpenCollection]
107
+ ```
108
+
109
+ Cada paso es un plugin. El mismo contrato produce siempre los mismos archivos,
110
+ así que `verify` detecta en CI cualquier colección desactualizada.
111
+
112
+ ## Qué obtienes
113
+
114
+ ```text
115
+ collections/
116
+ ├── postman/
117
+ │ ├── petstore.postman_collection.json
118
+ │ └── petstore-dev.postman_environment.json
119
+ └── bruno/
120
+ ├── opencollection.yml
121
+ ├── environments/dev.yml
122
+ ├── pets/
123
+ │ ├── folder.yml
124
+ │ ├── List pets.yml
125
+ │ └── Create a pet.yml
126
+ └── store/
127
+ └── Opening hours.yml
128
+ ```
129
+
130
+ Cada petición trae sus pruebas: código de estado, tipo de contenido, esquema de
131
+ la respuesta y tiempo de respuesta.
132
+
133
+ Con `data: es-pe`, los ejemplos que faltan se llenan con datos de prueba
134
+ peruanos con la forma de una consulta a RENIEC: uno o dos nombres, los dos
135
+ apellidos, una persona y un lugar por objeto, y un RUC con dígito verificador
136
+ SUNAT válido:
137
+
138
+ ```json
139
+ {
140
+ "nombres": "Isabel Lucía",
141
+ "apellidoPaterno": "Gutiérrez",
142
+ "apellidoMaterno": "Castillo",
143
+ "correo": "isabel.gutierrez@example.com",
144
+ "dni": "11067581",
145
+ "ruc": "20968504291",
146
+ "celular": "925340375",
147
+ "ubigeo": "170101",
148
+ "distrito": "Tambopata"
149
+ }
150
+ ```
151
+
152
+ ## Configuración
153
+
154
+ ```yaml
155
+ version: 1
156
+ source: openapi.yaml
157
+ overlays: [names.overlay.yaml]
158
+ data: es-pe
159
+ targets: [postman, bruno]
160
+ output: collections
161
+ environments:
162
+ qa:
163
+ variables:
164
+ baseUrl: https://api.qa.example.com
165
+ secrets: [token]
166
+ ```
167
+
168
+ | Clave | Obligatoria | Descripción |
169
+ | -------------- | ----------- | --------------------------------------------------------------------- |
170
+ | `version` | sí | Versión de la configuración, `1` |
171
+ | `source` | sí | Documento OpenAPI 3.0 o 3.1, en JSON o YAML |
172
+ | `targets` | sí | `postman`, `bruno` o ambos |
173
+ | `output` | sí | Carpeta de las colecciones, una subcarpeta por destino |
174
+ | `overlays` | no | Documentos [Overlay 1.0](https://spec.openapis.org/overlay/v1.0.html) |
175
+ | `data` | no | Ejemplos sintéticos: `generic` (por defecto) o `es-pe` |
176
+ | `environments` | no | Variables y nombres de secretos por entorno |
177
+ | `variables` | no | Nombres de las variables de URL base, token y API key |
178
+ | `tests` | no | `responseTimeMs`, la respuesta más lenta aceptable (por defecto 5000) |
179
+
180
+ `openchasqui` solo reemplaza carpetas que él mismo creó; se niega a escribir
181
+ sobre cualquier otra. Ningún entorno puede parecer de producción y un secreto
182
+ nunca lleva valor.
183
+
184
+ ## Overlays
185
+
186
+ Un overlay renombra, reagrupa o recorta la colección sin tocar el contrato. Dos
187
+ extensiones controlan la organización:
188
+
189
+ ```yaml
190
+ overlay: 1.0.0
191
+ info: { title: Nombres en español, version: 1.0.0 }
192
+ actions:
193
+ - target: $.paths['/banks'].get
194
+ update:
195
+ summary: Listar bancos
196
+ x-openchasqui-folder: Catálogos/Bancos
197
+ x-openchasqui-order: 1
198
+ - target: $.paths['/internal/metrics']
199
+ remove: true
200
+ ```
201
+
202
+ ## Políticas
203
+
204
+ `generate` y `verify` informan:
205
+
206
+ | Regla | Severidad | Cuándo |
207
+ | ------------------------ | ----------- | ---------------------------------------------------------- |
208
+ | `no-secrets-in-examples` | error | Un ejemplo contiene un JWT, una clave de nube o un token |
209
+ | `reserved-email-domains` | advertencia | Un correo de ejemplo no usa `example.com` u otro reservado |
210
+ | `success-response` | advertencia | Una operación no documenta ninguna respuesta 2xx |
211
+ | `public-write` | advertencia | Una operación de escritura no pide autenticación |
212
+
213
+ ## Paquetes
214
+
215
+ El CLI instala todo lo necesario; estos son los paquetes que lo forman.
216
+
217
+ <details>
218
+ <summary>Ver los 12 paquetes</summary>
219
+
220
+ | Paquete | Propósito |
221
+ | ----------------------------------------------------------------------------- | --------------------------------------------------- |
222
+ | [`@abitechdev/openchasqui`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/cli) | Línea de comandos |
223
+ | [`@abitechdev/openchasqui-core`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/core) | Pipeline |
224
+ | [`@abitechdev/openchasqui-spec`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/spec) | Modelo canónico y contrato de plugins |
225
+ | [`@abitechdev/openchasqui-plugin-kit`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/plugin-kit) | Utilidades para autores de plugins |
226
+ | [`@abitechdev/openchasqui-transformer-overlay`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/transformer-overlay) | Overlay 1.0 |
227
+ | [`@abitechdev/openchasqui-loader-openapi`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/loader-openapi) | Cargador de OpenAPI 3.0 y 3.1 |
228
+ | [`@abitechdev/openchasqui-generator-examples`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/generator-examples) | Ejemplos sintéticos |
229
+ | [`@abitechdev/openchasqui-generator-tests`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/generator-tests) | Pruebas de contrato |
230
+ | [`@abitechdev/openchasqui-validator-policies`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/validator-policies) | Políticas de seguridad y calidad |
231
+ | [`@abitechdev/openchasqui-emitter-postman`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/emitter-postman) | Postman Collection v2.1 |
232
+ | [`@abitechdev/openchasqui-emitter-bruno`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/emitter-bruno) | Bruno, OpenCollection YAML |
233
+ | [`@abitechdev/openchasqui-data-es-pe`](https://github.com/abitech-dev/abitech-openchasqui-cli/tree/main/packages/data-es-pe) | Datos de prueba peruanos: DNI, RUC, celular, ubigeo |
234
+
235
+ </details>
236
+
237
+ ## Hoja de ruta
238
+
239
+ | Versión | Alcance |
240
+ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
241
+ | 1.0 | Overlay 1.0, ejemplos y pruebas de contrato, políticas y cobertura, Bruno (OpenCollection) y Postman, `init` y `verify`, datos de prueba peruanos |
242
+ | 1.1 | Flujos Arazzo, GitHub Action, SARIF |
243
+ | 1.2 | `.http` e Insomnia, OpenAPI 3.2 |
244
+ | 2.0 | k6 y Playwright, contrato estable para plugins de terceros |
245
+
246
+ ## Contribuir
247
+
248
+ Los issues y pull requests son bienvenidos. Lee primero
249
+ [CONTRIBUTING.md](https://github.com/abitech-dev/abitech-openchasqui-cli/blob/main/CONTRIBUTING.md); los reportes de seguridad van por
250
+ [SECURITY.md](https://github.com/abitech-dev/abitech-openchasqui-cli/blob/main/SECURITY.md).
251
+
252
+ ## Licencia
253
+
254
+ [Apache License 2.0](https://github.com/abitech-dev/abitech-openchasqui-cli/blob/main/LICENSE). Copyright 2026 The OpenChasqui Authors.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=bin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.d.ts","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":""}
package/dist/bin.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { main } from "./main.js";
3
+ process.exitCode = await main(process.argv.slice(2));
4
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type Console } from "./project.js";
2
+ export declare function generate(configPath: string, output: Console): Promise<number>;
3
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,OAAO,EAA8B,MAAM,cAAc,CAAC;AAExE,wBAAsB,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAenF"}
@@ -0,0 +1,33 @@
1
+ import { mkdir, readdir, rm, stat, writeFile } from "node:fs/promises";
2
+ import { dirname, join, relative, sep } from "node:path";
3
+ import { OpenChasquiError } from "@abitechdev/openchasqui-core";
4
+ import { MARKER, report, runProject } from "./project.js";
5
+ export async function generate(configPath, output) {
6
+ const { outputRoot, result } = await runProject(configPath);
7
+ const failed = report(result.findings, output);
8
+ for (const { target, files } of result.outputs) {
9
+ const folder = join(outputRoot, target);
10
+ await replaceFolder(folder);
11
+ for (const file of files) {
12
+ const path = join(folder, ...file.path.split("/"));
13
+ await mkdir(dirname(path), { recursive: true });
14
+ await writeFile(path, file.contents, "utf8");
15
+ }
16
+ output.log(`${target}: ${files.length} files in ${relative(process.cwd(), folder) || "."}`);
17
+ }
18
+ return failed ? 1 : 0;
19
+ }
20
+ /** Empties a folder only if an earlier run created it. */
21
+ async function replaceFolder(folder) {
22
+ const exists = await stat(folder).then((info) => info.isDirectory(), () => false);
23
+ if (exists && (await readdir(folder)).length > 0) {
24
+ const marked = await stat(join(folder, MARKER)).then(() => true, () => false);
25
+ if (!marked) {
26
+ throw new OpenChasquiError("unsafe-output-path", `${folder}${sep} has files that openchasqui did not create; choose another output.`);
27
+ }
28
+ await rm(folder, { recursive: true });
29
+ }
30
+ await mkdir(folder, { recursive: true });
31
+ await writeFile(join(folder, MARKER), "Generated by openchasqui. Do not edit by hand.\n", "utf8");
32
+ }
33
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,C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AACxB,CAAC;AAED,0DAA0D;AAC1D,KAAK,UAAU,aAAa,CAAC,MAAc;IACzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,CACpC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,EAC5B,GAAG,EAAE,CAAC,KAAK,CACZ,CAAC;IACF,IAAI,MAAM,IAAI,CAAC,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAClD,GAAG,EAAE,CAAC,IAAI,EACV,GAAG,EAAE,CAAC,KAAK,CACZ,CAAC;QACF,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,gBAAgB,CACxB,oBAAoB,EACpB,GAAG,MAAM,GAAG,GAAG,oEAAoE,CACpF,CAAC;QACJ,CAAC;QACD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACxC,CAAC;IACD,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACzC,MAAM,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,kDAAkD,EAAE,MAAM,CAAC,CAAC;AACpG,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { main } from "./main.js";
2
+ export { type Console, MARKER } from "./project.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { main } from "./main.js";
2
+ export { MARKER } from "./project.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAgB,MAAM,EAAE,MAAM,cAAc,CAAC"}
package/dist/init.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ import type { Console } from "./project.js";
2
+ /** Writes a starting configuration next to the contract it finds. */
3
+ export declare function init(configPath: string, output: Console): Promise<number>;
4
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAU5C,qEAAqE;AACrE,wBAAsB,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAiB/E"}
package/dist/init.js ADDED
@@ -0,0 +1,51 @@
1
+ import { readFile, stat, writeFile } from "node:fs/promises";
2
+ import { basename, dirname, join } from "node:path";
3
+ import { parseDocument } from "@abitechdev/openchasqui-core";
4
+ const CANDIDATES = [
5
+ "openapi.yaml",
6
+ "openapi.yml",
7
+ "openapi.json",
8
+ "docs/openapi.yaml",
9
+ "docs/openapi.json",
10
+ ];
11
+ /** Writes a starting configuration next to the contract it finds. */
12
+ export async function init(configPath, output) {
13
+ if (await exists(configPath)) {
14
+ output.error(`${basename(configPath)} already exists; edit it instead.`);
15
+ return 1;
16
+ }
17
+ const base = dirname(configPath);
18
+ let source = "openapi.yaml";
19
+ for (const candidate of CANDIDATES) {
20
+ if (await exists(join(base, candidate))) {
21
+ source = candidate;
22
+ break;
23
+ }
24
+ }
25
+ const baseUrl = await firstServer(join(base, source));
26
+ await writeFile(configPath, template(source, baseUrl), "utf8");
27
+ output.log(`Created ${basename(configPath)} for ${source}. Run "openchasqui generate".`);
28
+ return 0;
29
+ }
30
+ async function firstServer(path) {
31
+ const text = await readFile(path, "utf8").catch(() => "");
32
+ const document = text ? parseDocument(text) : {};
33
+ const url = document.servers?.[0]?.url;
34
+ return typeof url === "string" && url ? url : "http://localhost:3000";
35
+ }
36
+ function template(source, baseUrl) {
37
+ return `version: 1
38
+ source: ${source}
39
+ targets: [postman, bruno]
40
+ output: collections
41
+ environments:
42
+ dev:
43
+ variables:
44
+ baseUrl: ${baseUrl}
45
+ secrets: [token]
46
+ `;
47
+ }
48
+ async function exists(path) {
49
+ return stat(path).then(() => true, () => false);
50
+ }
51
+ //# sourceMappingURL=init.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.js","sourceRoot":"","sources":["../src/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAG7D,MAAM,UAAU,GAAG;IACjB,cAAc;IACd,aAAa;IACb,cAAc;IACd,mBAAmB;IACnB,mBAAmB;CACpB,CAAC;AAEF,qEAAqE;AACrE,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,UAAkB,EAAE,MAAe;IAC5D,IAAI,MAAM,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;QAC7B,MAAM,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAC,UAAU,CAAC,mCAAmC,CAAC,CAAC;QACzE,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACjC,IAAI,MAAM,GAAG,cAAc,CAAC;IAC5B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACnC,IAAI,MA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@
1
+ import type { Console } from "./project.js";
2
+ /** Runs the command line and returns the process exit code. */
3
+ export declare function main(argv: readonly string[], output?: Console): Promise<number>;
4
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAmB5C,+DAA+D;AAC/D,wBAAsB,IAAI,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,MAAM,GAAE,OAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAkC9F"}
package/dist/main.js ADDED
@@ -0,0 +1,61 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { OpenChasquiError } from "@abitechdev/openchasqui-core";
5
+ import { generate } from "./generate.js";
6
+ import { init } from "./init.js";
7
+ import { verify } from "./verify.js";
8
+ const DEFAULT_CONFIG = "openchasqui.config.yaml";
9
+ const COMMANDS = { generate, verify, init };
10
+ const HELP = `Usage: openchasqui <command> [options]
11
+
12
+ Commands:
13
+ init Create a configuration for the OpenAPI document in this folder
14
+ generate Emit the collections for every target in the configuration
15
+ verify Check policies and that the collections on disk are up to date
16
+
17
+ Options:
18
+ -c, --config <file> Configuration file (default: ${DEFAULT_CONFIG})
19
+ -h, --help Show this help
20
+ -v, --version Show the version
21
+ `;
22
+ /** Runs the command line and returns the process exit code. */
23
+ export async function main(argv, output = console) {
24
+ const { values, positionals } = parseArgs({
25
+ args: [...argv],
26
+ allowPositionals: true,
27
+ options: {
28
+ config: { type: "string", short: "c", default: DEFAULT_CONFIG },
29
+ help: { type: "boolean", short: "h", default: false },
30
+ version: { type: "boolean", short: "v", default: false },
31
+ },
32
+ });
33
+ if (values.version) {
34
+ output.log(await version());
35
+ return 0;
36
+ }
37
+ const [command] = positionals;
38
+ if (values.help || !command) {
39
+ output.log(HELP);
40
+ return values.help ? 0 : 1;
41
+ }
42
+ if (!(command in COMMANDS)) {
43
+ output.error(`Unknown command "${command}".\n\n${HELP}`);
44
+ return 1;
45
+ }
46
+ try {
47
+ return await COMMANDS[command](resolve(values.config), output);
48
+ }
49
+ catch (error) {
50
+ if (error instanceof OpenChasquiError) {
51
+ output.error(`error ${error.code}: ${error.message}`);
52
+ return 1;
53
+ }
54
+ throw error;
55
+ }
56
+ }
57
+ async function version() {
58
+ const manifest = new URL("../package.json", import.meta.url);
59
+ return JSON.parse(await readFile(manifest, "utf8")).version;
60
+ }
61
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,cAAc,GAAG,yBAAyB,CAAC;AACjD,MAAM,QAAQ,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAW,CAAC;AAErD,MAAM,IAAI,GAAG;;;;;;;;uDAQ0C,cAAc;;;CAGpE,CAAC;AAEF,+DAA+D;AAC/D,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,IAAuB,EAAE,SAAkB,OAAO;IAC3E,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,SAAS,CAAC;QACxC,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;QACf,gBAAgB,EAAE,IAAI;QACtB,OAAO,EAAE;YACP,MAAM,EAAE,EAAE,IAA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,CAAC;AAED,KAAK,UAAU,OAAO;IACpB,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,iBAAiB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC7D,OAAQ,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAyB,CAAC,OAAO,CAAC;AACvF,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { type RunResult } from "@abitechdev/openchasqui-core";
2
+ import type { Finding, OpenChasquiConfig, Plugin } from "@abitechdev/openchasqui-spec";
3
+ /** Marks a folder as generated, so the next run may replace it. */
4
+ export declare const MARKER = ".openchasqui";
5
+ export declare const BUILT_IN_PLUGINS: readonly Plugin[];
6
+ export interface Console {
7
+ log(message: string): void;
8
+ error(message: string): void;
9
+ }
10
+ export interface Project {
11
+ readonly config: OpenChasquiConfig;
12
+ readonly outputRoot: string;
13
+ readonly result: RunResult;
14
+ }
15
+ /** Reads the configuration and runs the pipeline without writing anything. */
16
+ export declare function runProject(configPath: string): Promise<Project>;
17
+ export declare function report(findings: readonly Finding[], output: Console): boolean;
18
+ //# sourceMappingURL=project.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAEA,OAAO,EAAiB,KAAK,SAAS,EAAO,MAAM,8BAA8B,CAAC;AAMlF,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAIvF,mEAAmE;AACnE,eAAO,MAAM,MAAM,iBAAiB,CAAC;AAErC,eAAO,MAAM,gBAAgB,EAAE,SAAS,MAAM,EAQ7C,CAAC;AAEF,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC;CAC5B;AAED,8EAA8E;AAC9E,wBAAsB,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAMrE;AAED,wBAAgB,MAAM,CAAC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAU7E"}
@@ -0,0 +1,41 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { dirname, resolve } from "node:path";
3
+ import { parseDocument, run } from "@abitechdev/openchasqui-core";
4
+ import { brunoEmitter } from "@abitechdev/openchasqui-emitter-bruno";
5
+ import { postmanEmitter } from "@abitechdev/openchasqui-emitter-postman";
6
+ import { examplesGenerator } from "@abitechdev/openchasqui-generator-examples";
7
+ import { testsGenerator } from "@abitechdev/openchasqui-generator-tests";
8
+ import { openApiLoader } from "@abitechdev/openchasqui-loader-openapi";
9
+ import { overlayTransformer } from "@abitechdev/openchasqui-transformer-overlay";
10
+ import { policiesValidator } from "@abitechdev/openchasqui-validator-policies";
11
+ /** Marks a folder as generated, so the next run may replace it. */
12
+ export const MARKER = ".openchasqui";
13
+ export const BUILT_IN_PLUGINS = [
14
+ overlayTransformer,
15
+ openApiLoader,
16
+ examplesGenerator,
17
+ testsGenerator,
18
+ policiesValidator,
19
+ postmanEmitter,
20
+ brunoEmitter,
21
+ ];
22
+ /** Reads the configuration and runs the pipeline without writing anything. */
23
+ export async function runProject(configPath) {
24
+ const base = dirname(configPath);
25
+ const config = parseDocument(await readFile(configPath, "utf8"));
26
+ const reader = { readText: (path) => readFile(resolve(base, path), "utf8") };
27
+ const result = await run(config, { reader, plugins: BUILT_IN_PLUGINS });
28
+ return { config, outputRoot: resolve(base, config.output), result };
29
+ }
30
+ export function report(findings, output) {
31
+ for (const finding of findings) {
32
+ const where = finding.operationId
33
+ ? ` (${finding.operationId})`
34
+ : finding.file
35
+ ? ` (${finding.file})`
36
+ : "";
37
+ output.error(`${finding.severity} ${finding.rule}: ${finding.message}${where}`);
38
+ }
39
+ return findings.some((finding) => finding.severity === "error");
40
+ }
41
+ //# sourceMappingURL=project.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"project.js","sourceRoot":"","sources":["../src/project.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAkB,GAAG,EAAE,MAAM,8BAA8B,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6CAA6C,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAE/E,mEAAmE;AACnE,MAAM,CAAC,MAAM,MAAM,GAAG,cAAc,CAAC;AAErC,MAAM,CAAC,MAAM,gBAAgB,GAAsB;IACjD,kBAAkB;IAClB,aAAa;IACb,iBAAiB;IACjB,cAAc;IACd,iBAAiB;IACjB,cAAc;IACd,YAAY;CACb,CAAC;AAaF,8EAA8E;AAC9E,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IACjC,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,CAAsB,CAAC;IACtF,MAAM,MAAM,GAAG,EAAE,QAAQ,EAAE,CAAC,IAAY,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC;IACrF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,gBAAgB,EAAE,CAAC,CAAC;IACxE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;AACtE,CAAC;AAED,MAAM,UAAU,MAAM,CAAC,QAA4B,EAAE,MAAe;IAClE,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW;YAC/B,CAAC,CAAC,KAAK,OAAO,CAAC,WAAW,GAAG;YAC7B,CAAC,CAAC,OAAO,CAAC,IAAI;gBACZ,CAAC,CAAC,KAAK,OAAO,CAAC,IAAI,GAAG;gBACtB,CAAC,CAAC,EAAE,CAAC;QACT,MAAM,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,OAAO,GAAG,KAAK,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;AAClE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { type Console } from "./project.js";
2
+ /**
3
+ * Checks without writing that the policies pass and that the collections on
4
+ * disk match what the contract produces today. Built for CI.
5
+ */
6
+ export declare function verify(configPath: string, output: Console): Promise<number>;
7
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../src/verify.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,OAAO,EAA8B,MAAM,cAAc,CAAC;AAExE;;;GAGG;AACH,wBAAsB,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BjF"}
package/dist/verify.js ADDED
@@ -0,0 +1,50 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { join, relative } from "node:path";
3
+ import { MARKER, report, runProject } from "./project.js";
4
+ /**
5
+ * Checks without writing that the policies pass and that the collections on
6
+ * disk match what the contract produces today. Built for CI.
7
+ */
8
+ export async function verify(configPath, output) {
9
+ const { outputRoot, result } = await runProject(configPath);
10
+ let failed = report(result.findings, output);
11
+ for (const { target, files } of result.outputs) {
12
+ const folder = join(outputRoot, target);
13
+ const onDisk = await readTree(folder);
14
+ const expected = new Map(files.map((file) => [file.path, file.contents]));
15
+ const problems = [];
16
+ for (const [path, contents] of expected) {
17
+ if (!onDisk.has(path))
18
+ problems.push(`missing ${path}`);
19
+ else if (onDisk.get(path) !== contents)
20
+ problems.push(`outdated ${path}`);
21
+ }
22
+ for (const path of onDisk.keys()) {
23
+ if (!expected.has(path))
24
+ problems.push(`unexpected ${path}`);
25
+ }
26
+ if (problems.length > 0) {
27
+ failed = true;
28
+ output.error(`${target}: ${relative(process.cwd(), folder)} is out of date. Run "openchasqui generate".`);
29
+ for (const problem of problems.sort())
30
+ output.error(` ${problem}`);
31
+ }
32
+ else {
33
+ output.log(`${target}: up to date`);
34
+ }
35
+ }
36
+ return failed ? 1 : 0;
37
+ }
38
+ async function readTree(folder) {
39
+ const files = new Map();
40
+ const entries = await readdir(folder, { recursive: true, withFileTypes: true }).catch(() => []);
41
+ for (const entry of entries) {
42
+ if (!entry.isFile() || entry.name === MARKER) {
43
+ continue;
44
+ }
45
+ const path = join(entry.parentPath, entry.name);
46
+ files.set(relative(folder, path).split("\\").join("/"), await readFile(path, "utf8"));
47
+ }
48
+ return files;
49
+ }
50
+ //# sourceMappingURL=verify.js.map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K,CAAC,IAAI,CAAC,CAAC;QAChD,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IACxF,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@abitechdev/openchasqui",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Generate, validate and distribute API collections from OpenAPI.",
5
+ "keywords": [
6
+ "openapi",
7
+ "postman",
8
+ "bruno",
9
+ "api-testing",
10
+ "contract-testing",
11
+ "openapi-overlay",
12
+ "cli",
13
+ "peru",
14
+ "openchasqui"
15
+ ],
16
+ "license": "Apache-2.0",
17
+ "type": "module",
18
+ "bin": {
19
+ "openchasqui": "./dist/bin.js"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "src",
30
+ "NOTICE"
31
+ ],
32
+ "engines": {
33
+ "node": ">=22"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/abitech-dev/abitech-openchasqui-cli.git",
38
+ "directory": "packages/cli"
39
+ },
40
+ "dependencies": {
41
+ "@abitechdev/openchasqui-core": "^0.1.1",
42
+ "@abitechdev/openchasqui-emitter-postman": "^0.1.1",
43
+ "@abitechdev/openchasqui-emitter-bruno": "^0.1.1",
44
+ "@abitechdev/openchasqui-generator-examples": "^0.1.1",
45
+ "@abitechdev/openchasqui-loader-openapi": "^0.1.1",
46
+ "@abitechdev/openchasqui-generator-tests": "^0.1.1",
47
+ "@abitechdev/openchasqui-validator-policies": "^0.1.1",
48
+ "@abitechdev/openchasqui-spec": "^0.1.1",
49
+ "@abitechdev/openchasqui-transformer-overlay": "^0.1.1"
50
+ },
51
+ "scripts": {}
6
52
  }
package/src/bin.ts ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { main } from "./main.js";
3
+
4
+ process.exitCode = await main(process.argv.slice(2));
@@ -0,0 +1,44 @@
1
+ import { mkdir, readdir, rm, stat, writeFile } from "node:fs/promises";
2
+ import { dirname, join, relative, sep } from "node:path";
3
+ import { OpenChasquiError } from "@abitechdev/openchasqui-core";
4
+ import { type Console, MARKER, report, runProject } from "./project.js";
5
+
6
+ export async function generate(configPath: string, output: Console): Promise<number> {
7
+ const { outputRoot, result } = await runProject(configPath);
8
+ const failed = report(result.findings, output);
9
+
10
+ for (const { target, files } of result.outputs) {
11
+ const folder = join(outputRoot, target);
12
+ await replaceFolder(folder);
13
+ for (const file of files) {
14
+ const path = join(folder, ...file.path.split("/"));
15
+ await mkdir(dirname(path), { recursive: true });
16
+ await writeFile(path, file.contents, "utf8");
17
+ }
18
+ output.log(`${target}: ${files.length} files in ${relative(process.cwd(), folder) || "."}`);
19
+ }
20
+ return failed ? 1 : 0;
21
+ }
22
+
23
+ /** Empties a folder only if an earlier run created it. */
24
+ async function replaceFolder(folder: string): Promise<void> {
25
+ const exists = await stat(folder).then(
26
+ (info) => info.isDirectory(),
27
+ () => false,
28
+ );
29
+ if (exists && (await readdir(folder)).length > 0) {
30
+ const marked = await stat(join(folder, MARKER)).then(
31
+ () => true,
32
+ () => false,
33
+ );
34
+ if (!marked) {
35
+ throw new OpenChasquiError(
36
+ "unsafe-output-path",
37
+ `${folder}${sep} has files that openchasqui did not create; choose another output.`,
38
+ );
39
+ }
40
+ await rm(folder, { recursive: true });
41
+ }
42
+ await mkdir(folder, { recursive: true });
43
+ await writeFile(join(folder, MARKER), "Generated by openchasqui. Do not edit by hand.\n", "utf8");
44
+ }
package/src/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { main } from "./main.js";
2
+ export { type Console, MARKER } from "./project.js";
package/src/init.ts ADDED
@@ -0,0 +1,59 @@
1
+ import { readFile, stat, writeFile } from "node:fs/promises";
2
+ import { basename, dirname, join } from "node:path";
3
+ import { parseDocument } from "@abitechdev/openchasqui-core";
4
+ import type { Console } from "./project.js";
5
+
6
+ const CANDIDATES = [
7
+ "openapi.yaml",
8
+ "openapi.yml",
9
+ "openapi.json",
10
+ "docs/openapi.yaml",
11
+ "docs/openapi.json",
12
+ ];
13
+
14
+ /** Writes a starting configuration next to the contract it finds. */
15
+ export async function init(configPath: string, output: Console): Promise<number> {
16
+ if (await exists(configPath)) {
17
+ output.error(`${basename(configPath)} already exists; edit it instead.`);
18
+ return 1;
19
+ }
20
+ const base = dirname(configPath);
21
+ let source = "openapi.yaml";
22
+ for (const candidate of CANDIDATES) {
23
+ if (await exists(join(base, candidate))) {
24
+ source = candidate;
25
+ break;
26
+ }
27
+ }
28
+ const baseUrl = await firstServer(join(base, source));
29
+ await writeFile(configPath, template(source, baseUrl), "utf8");
30
+ output.log(`Created ${basename(configPath)} for ${source}. Run "openchasqui generate".`);
31
+ return 0;
32
+ }
33
+
34
+ async function firstServer(path: string): Promise<string> {
35
+ const text = await readFile(path, "utf8").catch(() => "");
36
+ const document = text ? (parseDocument(text) as { servers?: { url?: unknown }[] }) : {};
37
+ const url = document.servers?.[0]?.url;
38
+ return typeof url === "string" && url ? url : "http://localhost:3000";
39
+ }
40
+
41
+ function template(source: string, baseUrl: string): string {
42
+ return `version: 1
43
+ source: ${source}
44
+ targets: [postman, bruno]
45
+ output: collections
46
+ environments:
47
+ dev:
48
+ variables:
49
+ baseUrl: ${baseUrl}
50
+ secrets: [token]
51
+ `;
52
+ }
53
+
54
+ async function exists(path: string): Promise<boolean> {
55
+ return stat(path).then(
56
+ () => true,
57
+ () => false,
58
+ );
59
+ }
package/src/main.ts ADDED
@@ -0,0 +1,66 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { resolve } from "node:path";
3
+ import { parseArgs } from "node:util";
4
+ import { OpenChasquiError } from "@abitechdev/openchasqui-core";
5
+ import { generate } from "./generate.js";
6
+ import { init } from "./init.js";
7
+ import type { Console } from "./project.js";
8
+ import { verify } from "./verify.js";
9
+
10
+ const DEFAULT_CONFIG = "openchasqui.config.yaml";
11
+ const COMMANDS = { generate, verify, init } as const;
12
+
13
+ const HELP = `Usage: openchasqui <command> [options]
14
+
15
+ Commands:
16
+ init Create a configuration for the OpenAPI document in this folder
17
+ generate Emit the collections for every target in the configuration
18
+ verify Check policies and that the collections on disk are up to date
19
+
20
+ Options:
21
+ -c, --config <file> Configuration file (default: ${DEFAULT_CONFIG})
22
+ -h, --help Show this help
23
+ -v, --version Show the version
24
+ `;
25
+
26
+ /** Runs the command line and returns the process exit code. */
27
+ export async function main(argv: readonly string[], output: Console = console): Promise<number> {
28
+ const { values, positionals } = parseArgs({
29
+ args: [...argv],
30
+ allowPositionals: true,
31
+ options: {
32
+ config: { type: "string", short: "c", default: DEFAULT_CONFIG },
33
+ help: { type: "boolean", short: "h", default: false },
34
+ version: { type: "boolean", short: "v", default: false },
35
+ },
36
+ });
37
+
38
+ if (values.version) {
39
+ output.log(await version());
40
+ return 0;
41
+ }
42
+ const [command] = positionals;
43
+ if (values.help || !command) {
44
+ output.log(HELP);
45
+ return values.help ? 0 : 1;
46
+ }
47
+ if (!(command in COMMANDS)) {
48
+ output.error(`Unknown command "${command}".\n\n${HELP}`);
49
+ return 1;
50
+ }
51
+
52
+ try {
53
+ return await COMMANDS[command as keyof typeof COMMANDS](resolve(values.config), output);
54
+ } catch (error) {
55
+ if (error instanceof OpenChasquiError) {
56
+ output.error(`error ${error.code}: ${error.message}`);
57
+ return 1;
58
+ }
59
+ throw error;
60
+ }
61
+ }
62
+
63
+ async function version(): Promise<string> {
64
+ const manifest = new URL("../package.json", import.meta.url);
65
+ return (JSON.parse(await readFile(manifest, "utf8")) as { version: string }).version;
66
+ }
package/src/project.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { dirname, resolve } from "node:path";
3
+ import { parseDocument, type RunResult, run } from "@abitechdev/openchasqui-core";
4
+ import { brunoEmitter } from "@abitechdev/openchasqui-emitter-bruno";
5
+ import { postmanEmitter } from "@abitechdev/openchasqui-emitter-postman";
6
+ import { examplesGenerator } from "@abitechdev/openchasqui-generator-examples";
7
+ import { testsGenerator } from "@abitechdev/openchasqui-generator-tests";
8
+ import { openApiLoader } from "@abitechdev/openchasqui-loader-openapi";
9
+ import type { Finding, OpenChasquiConfig, Plugin } from "@abitechdev/openchasqui-spec";
10
+ import { overlayTransformer } from "@abitechdev/openchasqui-transformer-overlay";
11
+ import { policiesValidator } from "@abitechdev/openchasqui-validator-policies";
12
+
13
+ /** Marks a folder as generated, so the next run may replace it. */
14
+ export const MARKER = ".openchasqui";
15
+
16
+ export const BUILT_IN_PLUGINS: readonly Plugin[] = [
17
+ overlayTransformer,
18
+ openApiLoader,
19
+ examplesGenerator,
20
+ testsGenerator,
21
+ policiesValidator,
22
+ postmanEmitter,
23
+ brunoEmitter,
24
+ ];
25
+
26
+ export interface Console {
27
+ log(message: string): void;
28
+ error(message: string): void;
29
+ }
30
+
31
+ export interface Project {
32
+ readonly config: OpenChasquiConfig;
33
+ readonly outputRoot: string;
34
+ readonly result: RunResult;
35
+ }
36
+
37
+ /** Reads the configuration and runs the pipeline without writing anything. */
38
+ export async function runProject(configPath: string): Promise<Project> {
39
+ const base = dirname(configPath);
40
+ const config = parseDocument(await readFile(configPath, "utf8")) as OpenChasquiConfig;
41
+ const reader = { readText: (path: string) => readFile(resolve(base, path), "utf8") };
42
+ const result = await run(config, { reader, plugins: BUILT_IN_PLUGINS });
43
+ return { config, outputRoot: resolve(base, config.output), result };
44
+ }
45
+
46
+ export function report(findings: readonly Finding[], output: Console): boolean {
47
+ for (const finding of findings) {
48
+ const where = finding.operationId
49
+ ? ` (${finding.operationId})`
50
+ : finding.file
51
+ ? ` (${finding.file})`
52
+ : "";
53
+ output.error(`${finding.severity} ${finding.rule}: ${finding.message}${where}`);
54
+ }
55
+ return findings.some((finding) => finding.severity === "error");
56
+ }
package/src/verify.ts ADDED
@@ -0,0 +1,49 @@
1
+ import { readdir, readFile } from "node:fs/promises";
2
+ import { join, relative } from "node:path";
3
+ import { type Console, MARKER, report, runProject } from "./project.js";
4
+
5
+ /**
6
+ * Checks without writing that the policies pass and that the collections on
7
+ * disk match what the contract produces today. Built for CI.
8
+ */
9
+ export async function verify(configPath: string, output: Console): Promise<number> {
10
+ const { outputRoot, result } = await runProject(configPath);
11
+ let failed = report(result.findings, output);
12
+
13
+ for (const { target, files } of result.outputs) {
14
+ const folder = join(outputRoot, target);
15
+ const onDisk = await readTree(folder);
16
+ const expected = new Map(files.map((file) => [file.path, file.contents]));
17
+ const problems: string[] = [];
18
+ for (const [path, contents] of expected) {
19
+ if (!onDisk.has(path)) problems.push(`missing ${path}`);
20
+ else if (onDisk.get(path) !== contents) problems.push(`outdated ${path}`);
21
+ }
22
+ for (const path of onDisk.keys()) {
23
+ if (!expected.has(path)) problems.push(`unexpected ${path}`);
24
+ }
25
+ if (problems.length > 0) {
26
+ failed = true;
27
+ output.error(
28
+ `${target}: ${relative(process.cwd(), folder)} is out of date. Run "openchasqui generate".`,
29
+ );
30
+ for (const problem of problems.sort()) output.error(` ${problem}`);
31
+ } else {
32
+ output.log(`${target}: up to date`);
33
+ }
34
+ }
35
+ return failed ? 1 : 0;
36
+ }
37
+
38
+ async function readTree(folder: string): Promise<Map<string, string>> {
39
+ const files = new Map<string, string>();
40
+ const entries = await readdir(folder, { recursive: true, withFileTypes: true }).catch(() => []);
41
+ for (const entry of entries) {
42
+ if (!entry.isFile() || entry.name === MARKER) {
43
+ continue;
44
+ }
45
+ const path = join(entry.parentPath, entry.name);
46
+ files.set(relative(folder, path).split("\\").join("/"), await readFile(path, "utf8"));
47
+ }
48
+ return files;
49
+ }