@postman-cse/onboarding-bootstrap 0.10.0 → 0.12.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) 2026 Postman, Inc.
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 CHANGED
@@ -32,6 +32,21 @@ Lifecycle behavior remains backward-compatible except for collection default mod
32
32
 
33
33
  If you do not set those inputs, the action refreshes collection pointers from the resolved spec and keeps one canonical spec update path.
34
34
 
35
+ ### Bootstrap phase independence
36
+
37
+ **Bootstrap succeeds independently** — it creates or updates Postman workspace and collections even if a later stage (repo sync, Insights onboarding) fails. This is intentional:
38
+
39
+ - **Postman side is self-contained:** Workspace creation, spec upload, and collection generation do not depend on repository access or merge status.
40
+ - **Repository side is async:** Later stages may fail due to repo permissions, branch protection, or pending approval. Bootstrap completion is not blocked by these downstream concerns.
41
+ - **Idempotent reruns:** If a later stage fails, subsequent reruns of the action will reuse existing Postman assets (via `workspace-id`, `spec-id`, collection IDs) and focus on the failed stage without recreating everything.
42
+
43
+ **When bootstrap fails:** The action stops and does not proceed to repo sync. Postman assets are left in the state they reached before the failure. Clear error messages identify which required bootstrap step failed (for example, spec lint or collection generation). Optional workspace enrichment steps, such as governance assignment and requester invitation, warn and continue so created workspaces and collections remain usable.
44
+
45
+ This layered design means customers can:
46
+ 1. Verify Postman workspace health independently.
47
+ 2. Debug repository issues (branch protection, permissions) separately from Postman provisioning.
48
+ 3. Reuse existing Postman assets when fixing downstream failures.
49
+
35
50
  ### Team ID derivation
36
51
 
37
52
  The action automatically derives the Postman Team ID from your `postman-api-key` via the `/me` API. There is no need to supply a separate team ID input. If the environment variable `POSTMAN_TEAM_ID` is set, that value takes precedence.
@@ -81,6 +96,10 @@ Before upload to Spec Hub, the action parses JSON or YAML OpenAPI documents and
81
96
 
82
97
  This runs in `src/index.ts` before upload. If nothing under `paths` needs changing, the original document bytes are preserved. When normalization runs, the spec is re-serialized (JSON stays JSON; YAML stays YAML). Each fix emits a **warning** in the Actions log so you can improve the source spec over time. Invalid documents that cannot be parsed are left unchanged and a warning is logged.
83
98
 
99
+ ### OpenAPI spec URL fetch safety
100
+
101
+ The root `spec-url` must be HTTPS and is fetched with pinned DNS resolution. The action blocks credential-bearing URLs, localhost/private/link-local/internal destinations, unsafe redirects, DNS rebinding attempts, and oversized OpenAPI resources before uploading content to Spec Hub. Root fetches are capped at 25 MiB, and fetch errors redact URL credentials, query strings, and fragments before logging.
102
+
84
103
  ## Usage
85
104
 
86
105
  ```yaml
@@ -122,6 +141,76 @@ jobs:
122
141
 
123
142
  If you want the action to discover prior bootstrap state automatically on reruns, commit `.postman/resources.yaml` and run the action on the ref whose state you want to reuse.
124
143
 
144
+ ## Dynamic contract tests
145
+
146
+ Dynamic contract tests harden the generated `[Contract]` collection against the resolved OpenAPI 3.0/3.1 document before any durable contract collection is overwritten.
147
+
148
+ Scope:
149
+
150
+ - Safely fetch and bundle HTTPS OpenAPI specs and HTTPS external refs.
151
+ - Validate the bundled OpenAPI document with external and file resolution disabled during validation.
152
+ - Match generated collection requests by method and canonical server/path candidates only; suffix path matching is not used.
153
+ - Require one generated request for every eligible `paths` operation.
154
+ - Validate response status codes, body presence, `Content-Type`, JSON response schemas, text/string schemas, and simple response header schemas.
155
+ - Perform static checks for required non-security query/header parameters and required request bodies.
156
+
157
+ Non-goals and limitations:
158
+
159
+ - Swagger 2.0, OAS webhooks, callbacks, and arbitrary user-authored collection requests are not fully validated.
160
+ - Security/auth requirements are not proven at runtime. API-key parameters derived from `securitySchemes` are warned as `CONTRACT_SECURITY_NOT_VALIDATED`.
161
+ - Complex non-JSON object schemas, header `content`, unsupported schema dialects, unsupported keywords, and discriminator-heavy schemas fail closed instead of generating weak tests.
162
+ - Generated scripts target Newman/Postman runtime support for ES2020-compatible JavaScript and use compiled schemasafe IIFE validators. They do not use `pm.response.to.have.jsonSchema`, `eval`, or `new Function`.
163
+
164
+ OpenAPI semantics:
165
+
166
+ - OAS 3.0 `$ref` siblings are ignored, `nullable` is converted to JSON Schema unions, boolean exclusive min/max is converted, and response `writeOnly` properties are removed from response validation.
167
+ - OAS 3.1 `$ref` siblings are applied, the default dialect is JSON Schema 2020-12, supported `$schema` values are preserved, and unsupported custom dialects fail closed.
168
+
169
+ Security and size limits:
170
+
171
+ - Only HTTPS spec URLs and external refs are allowed.
172
+ - Localhost, loopback, link-local, RFC1918, RFC6598, IANA special-use IPv4/IPv6 ranges, IPv4-mapped IPv6, `.local`, and `.internal` destinations are blocked.
173
+ - DNS results are vetted and pinned into the HTTPS socket; redirects are fully revalidated.
174
+ - Limits: 5 redirects, 100 external refs, ref depth 20, 25 MiB per fetched resource, and 25 MiB total fetched bytes.
175
+ - Generated request scripts warn above 256 KiB and fail above 900 KiB; instrumented contract collection uploads fail above 4 MiB before upload. The bundled action is also reviewed for dependency-driven size growth.
176
+
177
+ Rollback behavior:
178
+
179
+ - Spec preflight runs before Postman mutations.
180
+ - For existing spec updates, the previous normalized spec content is fetched and hashed before update.
181
+ - If linting, collection generation, instrumentation, tagging, or linking fails after an existing spec update, the action best-effort restores the previous spec content.
182
+ - If rollback fails, the action emits `CONTRACT_SPEC_ROLLBACK_FAILED` with the previous content SHA-256 for manual restoration.
183
+ - Refresh mode stages generated baseline, smoke, and contract collections and instruments the temporary contract collection before updating any durable tracked collection. If a durable refresh update fails after another durable collection was updated, the action best-effort restores previously updated collection snapshots. Collection mutations after the refresh stage, such as later tagging/linking side effects, are not automatically rolled back; rerun the action after resolving the failure to reconcile generated collections with the restored spec.
184
+
185
+ | Error code | Meaning | Remediation |
186
+ | --- | --- | --- |
187
+ | `CONTRACT_SPEC_FETCH_BLOCKED` | Spec URL, ref URL, DNS result, redirect, or socket destination was not allowed. | Use public HTTPS spec/ref URLs that do not resolve to private or local networks. |
188
+ | `CONTRACT_SPEC_FETCH_FAILED` | Allowed HTTPS fetch failed or redirected too many times. | Check availability, status codes, and redirect chains. |
189
+ | `CONTRACT_REF_LIMIT_EXCEEDED` | External ref count exceeded the configured limit. | Reduce external ref fan-out or bundle the spec upstream. |
190
+ | `CONTRACT_REF_DEPTH_EXCEEDED` | Ref nesting exceeded the configured limit. | Flatten recursive/deep ref chains. |
191
+ | `CONTRACT_REF_SIZE_EXCEEDED` | A fetched resource or total fetched bytes exceeded limits. | Reduce spec/ref size or pre-bundle the document. |
192
+ | `CONTRACT_SPEC_PARSE_FAILED` | The fetched document was not valid JSON/YAML object content. | Fix the source document syntax. |
193
+ | `CONTRACT_SPEC_VALIDATION_FAILED` | The bundled document failed OpenAPI validation. | Fix OpenAPI validation errors. |
194
+ | `CONTRACT_UNSUPPORTED_OPENAPI_VERSION` | The document was not OpenAPI 3.0 or 3.1. | Provide an OpenAPI 3.0/3.1 document. |
195
+ | `CONTRACT_NO_ELIGIBLE_OPERATIONS` | No eligible `paths` operations with responses were found. | Add path operations with responses. |
196
+ | `CONTRACT_OPERATION_NO_RESPONSES` | A `paths` operation had no response definitions. | Add at least one OpenAPI response to each path operation. |
197
+ | `CONTRACT_UNRESOLVED_REF` | A ref remained unresolved after secure bundling. | Fix the ref target or make the external ref HTTPS-accessible. |
198
+ | `CONTRACT_UNSUPPORTED_SCHEMA_DIALECT` | A schema declared an unsupported JSON Schema dialect. | Use draft-07 or 2020-12-compatible schemas. |
199
+ | `CONTRACT_SCHEMA_COMPILE_FAILED` | schemasafe could not compile a response/header schema. | Simplify or correct the unsupported schema. |
200
+ | `CONTRACT_STATIC_REQUEST_CHECK_FAILED` | Generated request missed a required non-security parameter or body. | Adjust generation options or the spec so generated requests include required shape. |
201
+ | `CONTRACT_SECURITY_NOT_VALIDATED` | Security requirements were detected but dynamic tests cannot prove auth at runtime. | Run dedicated auth tests and review generated requests for required credentials. |
202
+ | `CONTRACT_WEBHOOKS_NOT_VALIDATED` | OpenAPI webhooks were present but are not included in dynamic contract coverage. | Validate webhook behavior separately or model required behavior under `paths`. |
203
+ | `CONTRACT_CALLBACKS_NOT_VALIDATED` | Operation callbacks were present but are not included in dynamic contract coverage. | Validate callback behavior separately or add dedicated tests. |
204
+ | `CONTRACT_DUPLICATE_OPERATION_MATCH` | Multiple OpenAPI operations share the same canonical request mapping candidate. | Disambiguate paths, server prefixes, or templated routes. |
205
+ | `CONTRACT_DUPLICATE_OPERATION_REQUEST` | More than one generated request mapped to the same contract operation. | Disambiguate paths/operations or generated requests. |
206
+ | `CONTRACT_OPERATION_COVERAGE_FAILED` | Generated contract collection did not cover every eligible operation. | Regenerate the collection or fix operation paths. |
207
+ | `CONTRACT_FORBIDDEN_SCRIPT_CONSTRUCT` | Generated script included a forbidden dynamic validation construct. | Report the schema that triggered unsafe generation. |
208
+ | `CONTRACT_SCRIPT_SIZE_EXCEEDED` | A generated request test script exceeded the per-script size gate. | Reduce schema complexity or split the API. |
209
+ | `CONTRACT_COLLECTION_SIZE_EXCEEDED` | Instrumented contract collection exceeded the size gate. | Reduce schema/operation count or split the API. |
210
+ | `CONTRACT_COLLECTION_ID_COLLISION` | Baseline, smoke, and contract IDs were not pairwise distinct. | Pass distinct collection IDs or clear stale IDs. |
211
+ | `CONTRACT_PLAN_MISSING` | Contract instrumentation ran without a preflight-generated contract plan. | Rerun with dynamic contract preflight enabled and report the failure if it persists. |
212
+ | `CONTRACT_SPEC_ROLLBACK_FAILED` | Best-effort previous spec restoration failed after a later error. | Restore the previous spec content manually using the emitted SHA-256. |
213
+
125
214
  ## CLI Usage (Non-GitHub CI)
126
215
 
127
216
  The CLI is available for GitLab CI, Bitbucket Pipelines, Azure DevOps, and other CI systems.
@@ -130,9 +219,11 @@ GitHub Actions users should continue using the `action.yml` interface.
130
219
  Install globally:
131
220
 
132
221
  ```bash
133
- npm install -g postman-bootstrap-action
222
+ npm install -g @postman-cse/onboarding-bootstrap
134
223
  ```
135
224
 
225
+ The CLI package supports Node.js 20+. The examples below use Node.js 24 to match the GitHub Action runtime.
226
+
136
227
  Basic usage:
137
228
 
138
229
  ```bash
@@ -153,9 +244,9 @@ Example GitLab CI job:
153
244
 
154
245
  ```yaml
155
246
  bootstrap:
156
- image: node:20
247
+ image: node:24
157
248
  script:
158
- - npm install -g postman-bootstrap-action
249
+ - npm install -g @postman-cse/onboarding-bootstrap
159
250
  - postman-bootstrap --project-name core-payments --spec-url "$SPEC_URL" --postman-api-key "$POSTMAN_API_KEY" --postman-access-token "$POSTMAN_ACCESS_TOKEN" --result-json bootstrap-result.json --dotenv-path bootstrap.env
160
251
  artifacts:
161
252
  paths:
@@ -169,9 +260,9 @@ Example Bitbucket Pipelines step:
169
260
  pipelines:
170
261
  default:
171
262
  - step:
172
- image: node:20
263
+ image: node:24
173
264
  script:
174
- - npm install -g postman-bootstrap-action
265
+ - npm install -g @postman-cse/onboarding-bootstrap
175
266
  - postman-bootstrap --project-name core-payments --spec-url "$SPEC_URL" --postman-api-key "$POSTMAN_API_KEY" --postman-access-token "$POSTMAN_ACCESS_TOKEN" --result-json bootstrap-result.json --dotenv-path bootstrap.env
176
267
  artifacts:
177
268
  - bootstrap-result.json
@@ -184,9 +275,9 @@ Example Azure DevOps job:
184
275
  steps:
185
276
  - task: NodeTool@0
186
277
  inputs:
187
- versionSpec: '20.x'
278
+ versionSpec: '24.x'
188
279
  - script: |
189
- npm install -g postman-bootstrap-action
280
+ npm install -g @postman-cse/onboarding-bootstrap
190
281
  postman-bootstrap --project-name core-payments --spec-url "$(SPEC_URL)" --postman-api-key "$(POSTMAN_API_KEY)" --postman-access-token "$(POSTMAN_ACCESS_TOKEN)" --result-json bootstrap-result.json --dotenv-path bootstrap.env
191
282
  displayName: Bootstrap Postman assets
192
283
  - publish: bootstrap-result.json
@@ -202,7 +293,8 @@ steps:
202
293
  | `baseline-collection-id` | | Reuse an existing baseline collection. |
203
294
  | `smoke-collection-id` | | Reuse an existing smoke collection. |
204
295
  | `contract-collection-id` | | Reuse an existing contract collection. |
205
- | `collection-sync-mode` | `refresh` | Collection lifecycle policy. `reuse` keeps existing collections, `refresh` regenerates the current collection set from the latest spec, and `version` creates or reuses release-scoped collections. |
296
+ | `sync-examples` | `true` | Whether linked spec/collection relations should enable example syncing during cloud linkage. |
297
+ | `collection-sync-mode` | `refresh` | Collection lifecycle policy. `refresh` keeps the tracked collection IDs while updating them from the latest spec, and `version` creates or reuses release-scoped collections. |
206
298
  | `spec-sync-mode` | `update` | Spec lifecycle policy. `update` keeps one canonical spec current in Spec Hub, while `version` creates or reuses a release-scoped spec asset. |
207
299
  | `release-label` | | Optional release label used for versioned specs and collections. When omitted for versioned sync, the action derives one from GitHub tag or branch metadata. |
208
300
  | `project-name` | | Service name used in workspace and asset naming. |
@@ -221,7 +313,7 @@ steps:
221
313
 
222
314
  ### Collection sync
223
315
 
224
- - `reuse`: existing collection IDs are reused when available.
316
+ - `reuse`: legacy alias for `refresh`; existing collection IDs are reused when available and updated from the resolved spec.
225
317
  - `refresh`: baseline, smoke, and contract collections are regenerated from the resolved spec and become the current/default collection pointers.
226
318
  - `version`: a release-scoped collection set is created or reused from the checked-out ref's state when available.
227
319
 
@@ -244,9 +336,17 @@ If versioned sync is requested and no usable label can be derived, the run fails
244
336
 
245
337
  Current Postman asset state lives in `.postman/resources.yaml`.
246
338
 
247
- - `update` and `reuse` modes resolve current-state mappings from the checked-out ref.
339
+ - `update`, `refresh`, and legacy `reuse` modes resolve current-state mappings from the checked-out ref.
248
340
  - `version` mode reuses only the checked-out ref's mappings; release history lives in git history and tags, not in a separate manifest file or repository variables.
249
341
 
342
+ ### Cloud spec-to-collection syncing
343
+
344
+ After collections exist, bootstrap links them to the cloud specification and triggers a spec-side collection sync when `postman-access-token` is available.
345
+
346
+ - `sync-examples: true` (default) enables example syncing in that relation setup.
347
+ - `sync-examples: false` keeps the relation but disables example syncing.
348
+ - If `postman-access-token` is missing, bootstrap warns and skips the cloud link/sync step.
349
+
250
350
  ### Contract smoke monitoring
251
351
 
252
352
  This repo includes `.github/workflows/contract-smoke.yml`, a scheduled live contract check for the upstream Postman APIs used by bootstrap.
package/action.yml CHANGED
@@ -17,8 +17,12 @@ inputs:
17
17
  contract-collection-id:
18
18
  description: Existing contract collection ID
19
19
  required: false
20
+ sync-examples:
21
+ description: Whether linked spec/collection relations should enable example syncing
22
+ required: false
23
+ default: 'true'
20
24
  collection-sync-mode:
21
- description: Collection lifecycle policy (reuse, refresh, or version)
25
+ description: Collection lifecycle policy (refresh or version)
22
26
  required: false
23
27
  default: refresh
24
28
  spec-sync-mode:
@@ -52,6 +56,10 @@ inputs:
52
56
  spec-url:
53
57
  description: URL to the OpenAPI document to bootstrap
54
58
  required: true
59
+ openapi-version:
60
+ description: OpenAPI specification version override (3.0 or 3.1). When not set, the version is auto-detected from the spec content.
61
+ required: false
62
+ default: ''
55
63
  governance-mapping-json:
56
64
  description: JSON map of business domain to governance group name
57
65
  required: false
@@ -66,6 +74,18 @@ inputs:
66
74
  description: Integration backend for downstream workspace connectivity
67
75
  required: false
68
76
  default: bifrost
77
+ folder-strategy:
78
+ description: Folder organization strategy for generated collections (Paths or Tags)
79
+ required: false
80
+ default: Paths
81
+ nested-folder-hierarchy:
82
+ description: When folder-strategy is Tags, enables nested folder hierarchy
83
+ required: false
84
+ default: 'false'
85
+ request-name-source:
86
+ description: Determines how requests are named in generated collections (Fallback or URL)
87
+ required: false
88
+ default: Fallback
69
89
  outputs:
70
90
  workspace-id:
71
91
  description: Postman workspace ID
@@ -86,5 +106,5 @@ outputs:
86
106
  lint-summary-json:
87
107
  description: JSON summary of lint errors and warnings
88
108
  runs:
89
- using: node20
109
+ using: node24
90
110
  main: dist/index.cjs