pactwork 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 adrozdenko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,193 @@
1
+ <p align="center">
2
+ <img src="./docs/logo.svg" alt="Pactwork" width="200" />
3
+ </p>
4
+
5
+ <h1 align="center">Pactwork</h1>
6
+
7
+ <p align="center">
8
+ <strong>Stop mock drift. Start shipping.</strong>
9
+ </p>
10
+
11
+ <p align="center">
12
+ <a href="https://www.npmjs.com/package/pactwork"><img src="https://img.shields.io/npm/v/pactwork.svg?style=flat-square" alt="npm version" /></a>
13
+ <a href="https://github.com/adrozdenko/pactwork/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT License" /></a>
14
+ <a href="https://github.com/adrozdenko/pactwork/actions"><img src="https://img.shields.io/github/actions/workflow/status/adrozdenko/pactwork/ci.yml?style=flat-square" alt="Build Status" /></a>
15
+ </p>
16
+
17
+ <p align="center">
18
+ <a href="#the-problem">The Problem</a> •
19
+ <a href="#quick-start">Quick Start</a> •
20
+ <a href="#commands">Commands</a> •
21
+ <a href="#ci-integration">CI Integration</a>
22
+ </p>
23
+
24
+ ---
25
+
26
+ ## The Problem
27
+
28
+ Your frontend mocks lie to you.
29
+
30
+ ```
31
+ Backend adds field → Mock doesn't have it → Tests pass → Production breaks
32
+ ```
33
+
34
+ **Pactwork fixes this.** It generates MSW handlers from your OpenAPI spec and catches drift before it reaches production.
35
+
36
+ | Before | After |
37
+ |--------|-------|
38
+ | Write mocks by hand | Generate from spec |
39
+ | Mocks drift silently | Drift detected in CI |
40
+ | Bugs found in prod | Bugs found in PR |
41
+
42
+ ---
43
+
44
+ ## Quick Start
45
+
46
+ ```bash
47
+ npm install -D pactwork msw
48
+ npx pactwork init --spec ./openapi.yaml
49
+ npx pactwork generate
50
+ npx pactwork validate
51
+ ```
52
+
53
+ Done. Your mocks stay in sync.
54
+
55
+ ---
56
+
57
+ ## How It Works
58
+
59
+ ```
60
+ OpenAPI Spec → Pactwork → MSW Handlers + Validation + CI Gate
61
+ ```
62
+
63
+ 1. **Generate** — Create MSW handlers from your spec
64
+ 2. **Validate** — Check handlers match the spec
65
+ 3. **Gate** — Block deploys when mocks drift
66
+
67
+ ---
68
+
69
+ ## Commands
70
+
71
+ | Command | What it does |
72
+ |---------|--------------|
73
+ | `pactwork init` | Set up Pactwork in your project |
74
+ | `pactwork generate` | Create MSW handlers from spec |
75
+ | `pactwork validate` | Check handlers match spec |
76
+ | `pactwork watch` | Auto-regenerate on spec changes |
77
+ | `pactwork diff` | Show what's different |
78
+ | `pactwork can-i-deploy` | CI gate — exit 0 if safe, 1 if not |
79
+
80
+ ### Common Options
81
+
82
+ ```bash
83
+ # Generate from specific spec
84
+ pactwork generate --spec ./api/openapi.yaml --output ./src/mocks
85
+
86
+ # Validate and auto-fix drift
87
+ pactwork validate --fix
88
+
89
+ # CI mode with strict exit codes
90
+ pactwork validate --ci --format github
91
+ ```
92
+
93
+ ---
94
+
95
+ ## CI Integration
96
+
97
+ Add to your pipeline:
98
+
99
+ ```yaml
100
+ - run: npx pactwork validate --ci
101
+ - run: npx pactwork can-i-deploy
102
+ ```
103
+
104
+ ### Exit Codes
105
+
106
+ | Code | Meaning |
107
+ |------|---------|
108
+ | `0` | Safe — handlers match spec |
109
+ | `1` | Drift detected |
110
+ | `2` | Warnings as errors |
111
+
112
+ ### GitHub Actions Example
113
+
114
+ ```yaml
115
+ name: Contract Check
116
+ on: [push, pull_request]
117
+ jobs:
118
+ validate:
119
+ runs-on: ubuntu-latest
120
+ steps:
121
+ - uses: actions/checkout@v4
122
+ - uses: actions/setup-node@v4
123
+ with:
124
+ node-version: '20'
125
+ - run: npm ci
126
+ - run: npx pactwork validate --ci
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Configuration
132
+
133
+ Create `pactwork.config.ts`:
134
+
135
+ ```typescript
136
+ import { defineConfig } from 'pactwork'
137
+
138
+ export default defineConfig({
139
+ spec: { path: './api/openapi.yaml' },
140
+ generate: { output: './src/mocks', typescript: true },
141
+ })
142
+ ```
143
+
144
+ | Option | Default | Description |
145
+ |--------|---------|-------------|
146
+ | `spec.path` | — | Path to OpenAPI spec |
147
+ | `generate.output` | `./src/mocks` | Where to put handlers |
148
+ | `generate.typescript` | `true` | Generate .ts files |
149
+
150
+ ---
151
+
152
+ ## Using Generated Handlers
153
+
154
+ **Browser:**
155
+
156
+ ```typescript
157
+ import { setupWorker } from 'msw/browser'
158
+ import { handlers } from './mocks/handlers'
159
+ export const worker = setupWorker(...handlers)
160
+ ```
161
+
162
+ **Node/Tests:**
163
+
164
+ ```typescript
165
+ import { setupServer } from 'msw/node'
166
+ import { handlers } from './mocks/handlers'
167
+ export const server = setupServer(...handlers)
168
+ ```
169
+
170
+ ---
171
+
172
+ ## Requirements
173
+
174
+ - Node.js 18+
175
+ - MSW 2.x
176
+
177
+ ---
178
+
179
+ ## Contributing
180
+
181
+ ```bash
182
+ git clone https://github.com/adrozdenko/pactwork.git
183
+ npm install
184
+ npm test
185
+ ```
186
+
187
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for details.
188
+
189
+ ---
190
+
191
+ ## License
192
+
193
+ MIT © [adrozdenko](https://github.com/adrozdenko)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ import '../dist/cli/index.js'
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node