perfect-payload 1.2.1 → 1.2.2-beta.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.
@@ -2,22 +2,157 @@ name: Stage npm package
2
2
 
3
3
  on:
4
4
  push:
5
+ # Beta:
6
+ # Run for pushes to every branch except main.
5
7
  branches:
6
- - main
8
+ - "**"
9
+ - "!main"
10
+
11
+ # Production:
12
+ # Run only when a version tag is pushed.
13
+ # Examples: v1.3.0, v1.3.1, v2.0.0
14
+ tags:
15
+ - "v*.*.*"
7
16
 
8
17
  permissions:
9
18
  contents: read
10
19
  id-token: write
11
20
 
12
21
  jobs:
13
- stage:
22
+ # ==========================================================
23
+ # 1. PACKAGE INFO
24
+ # ==========================================================
25
+ package-info:
26
+ name: Package Info
27
+ runs-on: ubuntu-latest
28
+
29
+ outputs:
30
+ name: ${{ steps.package.outputs.name }}
31
+ version: ${{ steps.package.outputs.version }}
32
+ release_type: ${{ steps.package.outputs.release_type }}
33
+
34
+ steps:
35
+ - name: Checkout repository
36
+ uses: actions/checkout@v7
37
+
38
+ - name: Read package information
39
+ id: package
40
+ shell: bash
41
+ run: |
42
+ NAME=$(node -p "require('./package.json').name")
43
+ VERSION=$(node -p "require('./package.json').version")
44
+
45
+ echo "name=$NAME" >> "$GITHUB_OUTPUT"
46
+ echo "version=$VERSION" >> "$GITHUB_OUTPUT"
47
+
48
+ if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
49
+ RELEASE_TYPE="production"
50
+ else
51
+ RELEASE_TYPE="beta"
52
+ fi
53
+
54
+ echo "release_type=$RELEASE_TYPE" >> "$GITHUB_OUTPUT"
55
+
56
+ echo "======================================"
57
+ echo "PACKAGE INFORMATION"
58
+ echo "======================================"
59
+ echo "Package: $NAME"
60
+ echo "Version: $VERSION"
61
+ echo "Release type: $RELEASE_TYPE"
62
+ echo "Git ref: $GITHUB_REF_NAME"
63
+ echo "Git ref type: $GITHUB_REF_TYPE"
64
+ echo "======================================"
65
+
66
+ # ==========================================================
67
+ # 2. VALIDATE RELEASE
68
+ # ==========================================================
69
+ validate-release:
70
+ name: Validate Release
71
+ needs: package-info
72
+ runs-on: ubuntu-latest
73
+
74
+ steps:
75
+ - name: Validate branch / tag and version
76
+ shell: bash
77
+ run: |
78
+ VERSION="${{ needs.package-info.outputs.version }}"
79
+
80
+ echo "Version: $VERSION"
81
+ echo "Ref: $GITHUB_REF_NAME"
82
+ echo "Ref type: $GITHUB_REF_TYPE"
83
+
84
+ # --------------------------------------------------
85
+ # PRODUCTION
86
+ # Must come from a Git tag.
87
+ #
88
+ # Tag: v1.3.0
89
+ # package version: 1.3.0
90
+ # --------------------------------------------------
91
+ if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
92
+
93
+ TAG="$GITHUB_REF_NAME"
94
+
95
+ if [[ "$VERSION" == *"-beta"* ]]; then
96
+ echo "::error::Production releases cannot contain -beta."
97
+ echo "::error::Current package version: $VERSION"
98
+ exit 1
99
+ fi
100
+
101
+ EXPECTED_TAG="v$VERSION"
102
+
103
+ if [[ "$TAG" != "$EXPECTED_TAG" ]]; then
104
+ echo "::error::Git tag does not match package.json version."
105
+ echo "::error::Tag: $TAG"
106
+ echo "::error::Expected tag: $EXPECTED_TAG"
107
+ exit 1
108
+ fi
109
+
110
+ echo "Valid production release."
111
+ echo "Tag $TAG matches package version $VERSION."
112
+
113
+ # --------------------------------------------------
114
+ # BETA
115
+ # Any non-main branch.
116
+ #
117
+ # Example:
118
+ # feature/custom-validator
119
+ # package version: 1.3.0-beta.0
120
+ # --------------------------------------------------
121
+ else
122
+
123
+ if [[ "$GITHUB_REF_NAME" == "main" ]]; then
124
+ echo "::error::Production releases from main pushes are disabled."
125
+ echo "::error::Create a Git tag to release production."
126
+ exit 1
127
+ fi
128
+
129
+ if [[ "$VERSION" != *"-beta"* ]]; then
130
+ echo "::error::Non-main branches must contain a beta version."
131
+ echo "::error::Current version: $VERSION"
132
+ echo "::error::Expected something like 1.3.0-beta.0"
133
+ exit 1
134
+ fi
135
+
136
+ echo "Valid beta release."
137
+ echo "Branch: $GITHUB_REF_NAME"
138
+ echo "Version: $VERSION"
139
+
140
+ fi
141
+
142
+ # ==========================================================
143
+ # 3. INSTALL DEPENDENCIES
144
+ # ==========================================================
145
+ install:
146
+ name: Install Dependencies
147
+ needs:
148
+ - package-info
149
+ - validate-release
150
+
14
151
  runs-on: ubuntu-latest
15
152
 
16
153
  steps:
17
154
  - name: Checkout repository
18
155
  uses: actions/checkout@v7
19
- with:
20
- fetch-depth: 2
21
156
 
22
157
  - name: Setup Node.js
23
158
  uses: actions/setup-node@v7
@@ -37,88 +172,161 @@ jobs:
37
172
  - name: Install dependencies
38
173
  run: npm ci
39
174
 
175
+ # ==========================================================
176
+ # 4. RUN TESTS
177
+ # ==========================================================
178
+ test:
179
+ name: Run Tests
180
+ needs: install
181
+ runs-on: ubuntu-latest
182
+
183
+ steps:
184
+ - name: Checkout repository
185
+ uses: actions/checkout@v7
186
+
187
+ - name: Setup Node.js
188
+ uses: actions/setup-node@v7
189
+ with:
190
+ node-version: 24
191
+ package-manager-cache: false
192
+
193
+ - name: Install dependencies
194
+ run: npm ci
195
+
40
196
  - name: Run tests
41
197
  run: npm test -- --passWithNoTests
42
198
 
43
- - name: Get package information
44
- id: package
199
+ # ==========================================================
200
+ # 5. CHECK NPM VERSION
201
+ # ==========================================================
202
+ check-npm:
203
+ name: Check npm Version
204
+ needs:
205
+ - package-info
206
+ - validate-release
207
+ - test
208
+
209
+ runs-on: ubuntu-latest
210
+
211
+ steps:
212
+ - name: Setup Node.js
213
+ uses: actions/setup-node@v7
214
+ with:
215
+ node-version: 24
216
+ registry-url: https://registry.npmjs.org
217
+ package-manager-cache: false
218
+
219
+ - name: Check whether version already exists
45
220
  shell: bash
46
221
  run: |
47
- NAME=$(node -p "require('./package.json').name")
48
- VERSION=$(node -p "require('./package.json').version")
222
+ NAME="${{ needs.package-info.outputs.name }}"
223
+ VERSION="${{ needs.package-info.outputs.version }}"
49
224
 
50
- echo "name=$NAME" >> "$GITHUB_OUTPUT"
51
- echo "version=$VERSION" >> "$GITHUB_OUTPUT"
225
+ echo "Checking npm for $NAME@$VERSION..."
52
226
 
53
- if [[ "$VERSION" == *"-beta."* ]]; then
54
- echo "release_type=beta" >> "$GITHUB_OUTPUT"
55
- else
56
- echo "release_type=production" >> "$GITHUB_OUTPUT"
227
+ if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then
228
+ echo "::error::$NAME@$VERSION is already published."
229
+ echo "::error::Use a new package version."
230
+ exit 1
57
231
  fi
58
232
 
59
- echo "Package: $NAME"
60
- echo "Version: $VERSION"
233
+ echo "$NAME@$VERSION is not published."
234
+ echo "Release is ready to stage."
61
235
 
62
- - name: Check whether version changed
63
- id: version
64
- shell: bash
65
- run: |
66
- CURRENT_VERSION="${{ steps.package.outputs.version }}"
67
-
68
- PREVIOUS_VERSION=$(git show HEAD^:package.json 2>/dev/null | \
69
- node -e "
70
- let data = '';
71
- process.stdin.on('data', chunk => data += chunk);
72
- process.stdin.on('end', () => {
73
- try {
74
- console.log(JSON.parse(data).version || '');
75
- } catch {
76
- console.log('');
77
- }
78
- });
79
- ")
80
-
81
- echo "Previous version: $PREVIOUS_VERSION"
82
- echo "Current version: $CURRENT_VERSION"
83
-
84
- if [[ "$CURRENT_VERSION" == "$PREVIOUS_VERSION" ]]; then
85
- echo "changed=false" >> "$GITHUB_OUTPUT"
86
- echo "Package version did not change. Nothing to stage."
87
- else
88
- echo "changed=true" >> "$GITHUB_OUTPUT"
89
- echo "New package version detected."
90
- fi
236
+ # ==========================================================
237
+ # 6. STAGE NPM PACKAGE
238
+ #
239
+ # This environment can optionally have a GitHub
240
+ # Required Reviewer configured.
241
+ #
242
+ # npm itself still requires approval + 2FA after staging.
243
+ # ==========================================================
244
+ stage-npm:
245
+ name: Stage npm Package
246
+ needs:
247
+ - package-info
248
+ - check-npm
249
+
250
+ runs-on: ubuntu-latest
91
251
 
92
- - name: Check whether version is already published
93
- if: steps.version.outputs.changed == 'true'
94
- id: published
252
+ environment:
253
+ name: npm-stage
254
+
255
+ steps:
256
+ - name: Checkout repository
257
+ uses: actions/checkout@v7
258
+
259
+ - name: Setup Node.js
260
+ uses: actions/setup-node@v7
261
+ with:
262
+ node-version: 24
263
+ registry-url: https://registry.npmjs.org
264
+ package-manager-cache: false
265
+
266
+ - name: Setup npm
267
+ run: npm install --global npm@11.19.1
268
+
269
+ - name: Show release information
95
270
  shell: bash
96
271
  run: |
97
- NAME="${{ steps.package.outputs.name }}"
98
- VERSION="${{ steps.package.outputs.version }}"
272
+ echo "======================================"
273
+ echo "READY TO STAGE"
274
+ echo "======================================"
275
+ echo "Package: ${{ needs.package-info.outputs.name }}"
276
+ echo "Version: ${{ needs.package-info.outputs.version }}"
277
+ echo "Type: ${{ needs.package-info.outputs.release_type }}"
278
+ echo "Ref: $GITHUB_REF_NAME"
279
+ echo "======================================"
99
280
 
100
- if npm view "$NAME@$VERSION" version >/dev/null 2>&1; then
101
- echo "exists=true" >> "$GITHUB_OUTPUT"
102
- echo "$NAME@$VERSION is already published."
103
- else
104
- echo "exists=false" >> "$GITHUB_OUTPUT"
105
- echo "$NAME@$VERSION is not published."
106
- fi
107
-
108
- - name: Stage beta release
281
+ # ------------------------------------------------------
282
+ # BETA
283
+ # Triggered only from non-main branch pushes.
284
+ # ------------------------------------------------------
285
+ - name: Stage Beta Package
109
286
  if: >
110
- steps.version.outputs.changed == 'true' &&
111
- steps.published.outputs.exists == 'false' &&
112
- steps.package.outputs.release_type == 'beta'
287
+ github.ref_type == 'branch' &&
288
+ needs.package-info.outputs.release_type == 'beta'
113
289
  run: |
114
- echo "Staging beta ${{ steps.package.outputs.version }}"
290
+ echo "Staging beta package..."
291
+ echo "${{ needs.package-info.outputs.name }}@${{ needs.package-info.outputs.version }}"
292
+
115
293
  npm stage publish --tag beta
116
294
 
117
- - name: Stage production release
295
+ # ------------------------------------------------------
296
+ # PRODUCTION
297
+ # Triggered ONLY from Git tags.
298
+ # ------------------------------------------------------
299
+ - name: Stage Production Package
118
300
  if: >
119
- steps.version.outputs.changed == 'true' &&
120
- steps.published.outputs.exists == 'false' &&
121
- steps.package.outputs.release_type == 'production'
301
+ github.ref_type == 'tag' &&
302
+ needs.package-info.outputs.release_type == 'production'
122
303
  run: |
123
- echo "Staging production ${{ steps.package.outputs.version }}"
304
+ echo "Staging production package..."
305
+ echo "${{ needs.package-info.outputs.name }}@${{ needs.package-info.outputs.version }}"
306
+
124
307
  npm stage publish
308
+
309
+ # ==========================================================
310
+ # 7. COMPLETION
311
+ # ==========================================================
312
+ complete:
313
+ name: npm Package Staged
314
+ needs:
315
+ - package-info
316
+ - stage-npm
317
+
318
+ runs-on: ubuntu-latest
319
+
320
+ steps:
321
+ - name: Staging completed
322
+ run: |
323
+ echo "======================================"
324
+ echo "NPM STAGING COMPLETED"
325
+ echo "======================================"
326
+ echo "Package: ${{ needs.package-info.outputs.name }}"
327
+ echo "Version: ${{ needs.package-info.outputs.version }}"
328
+ echo "Type: ${{ needs.package-info.outputs.release_type }}"
329
+ echo ""
330
+ echo "The package has been staged on npm."
331
+ echo "Review and approve it on npm with 2FA."
332
+ echo "======================================"
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "perfect-payload",
3
- "version": "1.2.1",
3
+ "version": "1.2.2-beta.0",
4
4
  "type": "module",
5
- "description": "rich json validator",
5
+ "description": "Lightweight JSON payload validation library with structured errors, nested validation, field paths, and customizable validation rules.",
6
6
  "main": "index.js",
7
7
  "scripts": {
8
8
  "test": "jest"
@@ -12,14 +12,22 @@
12
12
  "url": "git+https://github.com/kiranpoojary/perfect-payload.git"
13
13
  },
14
14
  "keywords": [
15
- "validation",
15
+ "payload-validation",
16
+ "request-validation",
17
+ "nodejs-validation",
18
+ "javascript-validation",
19
+ "api-validation",
20
+ "object-validation",
21
+ "json-validation",
22
+ "schema-validation",
23
+ "express-validation",
24
+ "fastify-validation",
25
+ "validator",
16
26
  "payload",
17
27
  "api",
18
28
  "data",
19
29
  "request-body",
20
- "response",
21
- "express",
22
- "validate"
30
+ "express"
23
31
  ],
24
32
  "author": "Kiran Poojary",
25
33
  "license": "ISC",