@postman-cse/onboarding-repo-sync 2.3.1 → 2.4.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/README.md CHANGED
@@ -113,7 +113,17 @@ with:
113
113
  monitor-id: 1e2f3a4b-monitor-id
114
114
  ```
115
115
 
116
- Repo-sync defaults to public mocks for anonymous validation. Set `mock-visibility: private` for teams that prohibit public mocks. Explicit, discovered, and newly created mocks must match the requested visibility and the expected baseline collection/environment; unknown visibility, stale URLs, and identity mismatches fail before `mock-url` is emitted. For private mocks, repo-sync emits `mock-auth-required: true` and installs a secret-free request hook in the smoke and contract collections. The runner must supply its PMAK as the transient `postmanPrivateMockApiKey` variable. Repo-sync never writes that credential to a collection, environment, output, or repository artifact.
116
+ Repo-sync defaults to public mocks for anonymous validation. Set `mock-visibility: private` for teams that prohibit public mocks. Explicit, discovered, and newly created mocks must match the requested visibility and the expected baseline collection/environment; unknown visibility, stale URLs, and identity mismatches fail before `mock-url` is emitted.
117
+
118
+ For private mocks, repo-sync emits `mock-auth-required: true` and installs a secret-free request hook in the smoke and contract collections. The hook reads the transient `postmanPrivateMockApiKey` variable and sends it as `x-api-key`, and only to `*.mock.pstmn.io` hosts, so it stays inert on runs that target a real environment. Repo-sync never writes that credential to a collection, environment, output, or repository artifact.
119
+
120
+ Where that variable comes from depends on who is running the collection:
121
+
122
+ - **Generated CI** supplies it automatically from the `POSTMAN_API_KEY` secret repo-sync already provisions for `postman login`. No extra secret and no workflow edit.
123
+ - **Manual runs in the Postman app** use the `<project> - Mock` environment, which carries `postmanPrivateMockApiKey` as an empty secret-typed variable. Paste a key with access to the mock. Requires `mock-environment-enabled: true`.
124
+ - **A runner you wire yourself** reads `mock-auth-required` and passes the variable however that system handles secrets.
125
+
126
+ A request to a private mock with no key set logs a console warning naming the variable, so a `401` explains its own fix.
117
127
 
118
128
  For manual collection validation against the resolved mock, opt in to a dedicated Postman environment:
119
129
 
package/dist/action.cjs CHANGED
@@ -134252,6 +134252,7 @@ function resolvePostmanEndpointProfile(stack, region = "us") {
134252
134252
  // src/lib/ci-workflow-template.ts
134253
134253
  var DEFAULT_POSTMAN_CLI_INSTALL_URL = POSTMAN_ENDPOINT_PROFILES.prod.cliInstallUrl;
134254
134254
  var DEFAULT_POSTMAN_CLI_WINDOWS_INSTALL_URL = POSTMAN_ENDPOINT_PROFILES.prod.cliWindowsInstallUrl;
134255
+ var PRIVATE_MOCK_AUTH_VARIABLE = "postmanPrivateMockApiKey";
134255
134256
  function validateHttpsInstallUrl(url) {
134256
134257
  const safeUrlPattern = /^https:\/\/[A-Za-z0-9.-]+\/[A-Za-z0-9._~/?=&%-]+$/;
134257
134258
  if (!safeUrlPattern.test(url)) {
@@ -134283,9 +134284,9 @@ function renderCiWorkflowTemplate(options = {}) {
134283
134284
  const rawUrl = String(options.postmanCliInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_INSTALL_URL;
134284
134285
  const installUrl = validateHttpsInstallUrl(rawUrl);
134285
134286
  const postmanRegion = resolvePostmanRegion(options.postmanRegion);
134286
- return buildCiWorkflowLines(installUrl, postmanRegion).join("\n");
134287
+ return buildCiWorkflowLines(installUrl, postmanRegion, options.privateMockAuth === true).join("\n");
134287
134288
  }
134288
- function buildCiWorkflowLines(installUrl, postmanRegion) {
134289
+ function buildCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
134289
134290
  return [
134290
134291
  "name: CI/CD Pipeline",
134291
134292
  "on:",
@@ -134352,6 +134353,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
134352
134353
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134353
134354
  " --report-events",
134354
134355
  ` --env-var "CI_ENVIRONMENT=\${{ vars.CI_ENVIRONMENT || 'Production' }}")`,
134356
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=${{ secrets.POSTMAN_API_KEY }}")'] : [],
134355
134357
  ' if [ -f "$RUNNER_TEMP/postman-ssl/client.crt" ]; then',
134356
134358
  ' CMD+=(--ssl-client-cert "$RUNNER_TEMP/postman-ssl/client.crt"',
134357
134359
  ' --ssl-client-key "$RUNNER_TEMP/postman-ssl/client.key")',
@@ -134371,6 +134373,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
134371
134373
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134372
134374
  " --report-events",
134373
134375
  ` --env-var "CI_ENVIRONMENT=\${{ vars.CI_ENVIRONMENT || 'Production' }}")`,
134376
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=${{ secrets.POSTMAN_API_KEY }}")'] : [],
134374
134377
  ' if [ -f "$RUNNER_TEMP/postman-ssl/client.crt" ]; then',
134375
134378
  ' CMD+=(--ssl-client-cert "$RUNNER_TEMP/postman-ssl/client.crt"',
134376
134379
  ' --ssl-client-key "$RUNNER_TEMP/postman-ssl/client.key")',
@@ -134386,7 +134389,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
134386
134389
  ];
134387
134390
  }
134388
134391
  var CI_WORKFLOW_TEMPLATE = renderCiWorkflowTemplate();
134389
- function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentName) {
134392
+ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentName, privateMockAuth) {
134390
134393
  return [
134391
134394
  " - pwsh: |",
134392
134395
  " $ErrorActionPreference = 'Stop'",
@@ -134398,6 +134401,7 @@ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentNam
134398
134401
  " $ciEnvironment = Resolve-AdoOptional $env:CI_ENVIRONMENT",
134399
134402
  " if ([string]::IsNullOrWhiteSpace($ciEnvironment)) { $ciEnvironment = 'Production' }",
134400
134403
  ` $arguments = @('collection', 'run', $collectionUid, '-e', $env:POSTMAN_ENVIRONMENT_UID, '--report-events', '--env-var', "CI_ENVIRONMENT=$ciEnvironment")`,
134404
+ ...privateMockAuth ? [` $arguments += @('--env-var', "${PRIVATE_MOCK_AUTH_VARIABLE}=$env:POSTMAN_API_KEY")`] : [],
134401
134405
  " $sslRoot = Join-Path $env:AGENT_TEMPDIRECTORY 'postman-ssl'",
134402
134406
  " $clientCert = Join-Path $sslRoot 'client.crt'",
134403
134407
  " $clientKey = Join-Path $sslRoot 'client.key'",
@@ -134419,10 +134423,11 @@ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentNam
134419
134423
  ` ${collectionEnvironmentName}: $(${collectionEnvironmentName})`,
134420
134424
  " POSTMAN_ENVIRONMENT_UID: $(POSTMAN_ENVIRONMENT_UID)",
134421
134425
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
134422
- " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)"
134426
+ " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
134427
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : []
134423
134428
  ];
134424
134429
  }
134425
- function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) {
134430
+ function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
134426
134431
  return [
134427
134432
  "trigger:",
134428
134433
  " branches:",
@@ -134507,12 +134512,12 @@ function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) {
134507
134512
  " POSTMAN_SSL_CLIENT_CERT_B64: $(POSTMAN_SSL_CLIENT_CERT_B64)",
134508
134513
  " POSTMAN_SSL_CLIENT_KEY_B64: $(POSTMAN_SSL_CLIENT_KEY_B64)",
134509
134514
  " POSTMAN_SSL_EXTRA_CA_CERTS_B64: $(POSTMAN_SSL_EXTRA_CA_CERTS_B64)",
134510
- ...buildAdoWindowsCollectionRunLines("Run Smoke Tests", "POSTMAN_SMOKE_COLLECTION_UID"),
134511
- ...buildAdoWindowsCollectionRunLines("Run Contract Tests", "POSTMAN_CONTRACT_COLLECTION_UID"),
134515
+ ...buildAdoWindowsCollectionRunLines("Run Smoke Tests", "POSTMAN_SMOKE_COLLECTION_UID", privateMockAuth),
134516
+ ...buildAdoWindowsCollectionRunLines("Run Contract Tests", "POSTMAN_CONTRACT_COLLECTION_UID", privateMockAuth),
134512
134517
  ""
134513
134518
  ];
134514
134519
  }
134515
- function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134520
+ function buildAdoCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
134516
134521
  return [
134517
134522
  "trigger:",
134518
134523
  " branches:",
@@ -134589,6 +134594,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134589
134594
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134590
134595
  " --report-events",
134591
134596
  ' --env-var "CI_ENVIRONMENT=${CI_ENVIRONMENT:-Production}")',
134597
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=$POSTMAN_API_KEY")'] : [],
134592
134598
  ' if [ -f "$(Agent.TempDirectory)/postman-ssl/client.crt" ]; then',
134593
134599
  ' CMD+=(--ssl-client-cert "$(Agent.TempDirectory)/postman-ssl/client.crt"',
134594
134600
  ' --ssl-client-key "$(Agent.TempDirectory)/postman-ssl/client.key")',
@@ -134604,6 +134610,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134604
134610
  " env:",
134605
134611
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
134606
134612
  " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
134613
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : [],
134607
134614
  " - script: |",
134608
134615
  " normalize_azure_optional_var() {",
134609
134616
  ' local name="$1"',
@@ -134620,6 +134627,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134620
134627
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134621
134628
  " --report-events",
134622
134629
  ' --env-var "CI_ENVIRONMENT=${CI_ENVIRONMENT:-Production}")',
134630
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=$POSTMAN_API_KEY")'] : [],
134623
134631
  ' if [ -f "$(Agent.TempDirectory)/postman-ssl/client.crt" ]; then',
134624
134632
  ' CMD+=(--ssl-client-cert "$(Agent.TempDirectory)/postman-ssl/client.crt"',
134625
134633
  ' --ssl-client-key "$(Agent.TempDirectory)/postman-ssl/client.key")',
@@ -134635,6 +134643,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134635
134643
  " env:",
134636
134644
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
134637
134645
  " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
134646
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : [],
134638
134647
  ""
134639
134648
  ];
134640
134649
  }
@@ -134696,7 +134705,8 @@ function getCiWorkflowTemplate(provider, options = {}) {
134696
134705
  const rawUrl = runnerOs === "windows" ? String(options.postmanCliWindowsInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_WINDOWS_INSTALL_URL : String(options.postmanCliInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_INSTALL_URL;
134697
134706
  const postmanRegion = resolvePostmanRegion(options.postmanRegion);
134698
134707
  const installUrl = validateHttpsInstallUrl(rawUrl);
134699
- return (runnerOs === "windows" ? buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) : buildAdoCiWorkflowLines(installUrl, postmanRegion)).join("\n");
134708
+ const privateMockAuth = options.privateMockAuth === true;
134709
+ return (runnerOs === "windows" ? buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) : buildAdoCiWorkflowLines(installUrl, postmanRegion, privateMockAuth)).join("\n");
134700
134710
  }
134701
134711
  return renderCiWorkflowTemplate(options);
134702
134712
  }
@@ -136984,16 +136994,32 @@ function requireMockVisibility(mock, requested) {
136984
136994
  }
136985
136995
  return mock;
136986
136996
  }
136987
- var PRIVATE_MOCK_AUTH_MARKER = "postman-enterprise-automation: private-mock-auth";
136988
- var PRIVATE_MOCK_AUTH_VARIABLE = "postmanPrivateMockApiKey";
136989
- var PRIVATE_MOCK_AUTH_SCRIPT = [
136990
- `// ${PRIVATE_MOCK_AUTH_MARKER}`,
136991
- `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE}');`,
136997
+ var LEGACY_PRIVATE_MOCK_AUTH_MARKER = "postman-enterprise-automation: private-mock-auth";
136998
+ var PRIVATE_MOCK_AUTH_MARKER = `${LEGACY_PRIVATE_MOCK_AUTH_MARKER}-v2`;
136999
+ var PRIVATE_MOCK_AUTH_VARIABLE2 = "postmanPrivateMockApiKey";
137000
+ var LEGACY_PRIVATE_MOCK_AUTH_SCRIPT = [
137001
+ `// ${LEGACY_PRIVATE_MOCK_AUTH_MARKER}`,
137002
+ `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE2}');`,
136992
137003
  "var privateMockHost = String(pm.request.url && pm.request.url.getHost ? pm.request.url.getHost() : '');",
136993
137004
  "if (privateMockApiKey && /(^|\\.)mock\\.pstmn\\.io$/i.test(privateMockHost)) {",
136994
137005
  " pm.request.headers.upsert({ key: 'x-api-key', value: privateMockApiKey });",
136995
137006
  "}"
136996
137007
  ].join("\n");
137008
+ var PRIVATE_MOCK_AUTH_SCRIPT = [
137009
+ `// ${PRIVATE_MOCK_AUTH_MARKER}`,
137010
+ `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE2}');`,
137011
+ "var privateMockHostValue = pm.request.url && pm.request.url.getHost ? pm.request.url.getHost() : '';",
137012
+ "var privateMockHost = Array.isArray(privateMockHostValue) ? privateMockHostValue.join('.') : String(privateMockHostValue);",
137013
+ "var isPrivateMockHost = /(^|\\.)mock\\.pstmn\\.io$/i.test(privateMockHost);",
137014
+ "if (isPrivateMockHost && privateMockApiKey) {",
137015
+ " pm.request.headers.upsert({ key: 'x-api-key', value: privateMockApiKey });",
137016
+ "} else if (isPrivateMockHost) {",
137017
+ ` console.warn('This mock server is private. Set the ${PRIVATE_MOCK_AUTH_VARIABLE2} variable to a Postman API key with access to it, or the request returns 401.');`,
137018
+ "}"
137019
+ ].join("\n");
137020
+ function removeLegacyPrivateMockAuth(code) {
137021
+ return code.split(LEGACY_PRIVATE_MOCK_AUTH_SCRIPT).join("").trim();
137022
+ }
136997
137023
  var MAX_CREATE_FLIGHTS = 256;
136998
137024
  var createFlights = /* @__PURE__ */ new Map();
136999
137025
  var PostmanGatewayAssetsClient = class {
@@ -137591,8 +137617,9 @@ var PostmanGatewayAssetsClient = class {
137591
137617
  const item = this.asRecord(response?.data) ?? listedItem;
137592
137618
  const scripts = Array.isArray(item.scripts) ? item.scripts.filter((entry) => Boolean(this.asRecord(entry))) : [];
137593
137619
  const before = scripts.find((script) => String(script.type ?? "") === "beforeRequest");
137594
- if (String(before?.code ?? "").includes(PRIVATE_MOCK_AUTH_MARKER)) continue;
137595
- const code = [String(before?.code ?? "").trim(), PRIVATE_MOCK_AUTH_SCRIPT].filter(Boolean).join("\n");
137620
+ const existingCode = String(before?.code ?? "");
137621
+ if (existingCode.includes(PRIVATE_MOCK_AUTH_MARKER)) continue;
137622
+ const code = [removeLegacyPrivateMockAuth(existingCode), PRIVATE_MOCK_AUTH_SCRIPT].filter(Boolean).join("\n");
137596
137623
  const nextScripts = [
137597
137624
  ...scripts.filter((script) => String(script.type ?? "") !== "beforeRequest"),
137598
137625
  { type: "beforeRequest", code, language: "text/javascript" }
@@ -138928,9 +138955,13 @@ function assertBranchAssetIds(inputs, decision, branchOwnedIds = process.env.POS
138928
138955
  );
138929
138956
  }
138930
138957
  }
138931
- function buildEnvironmentValues(envName, baseUrl) {
138958
+ function buildEnvironmentValues(envName, baseUrl, options = {}) {
138932
138959
  return [
138933
138960
  { key: "baseUrl", value: baseUrl, type: "default" },
138961
+ // A private mock refuses anonymous calls, so the manual-validation environment
138962
+ // carries a named, empty, secret-typed slot for the caller's own key. Repo-sync
138963
+ // never writes a value here; the developer pastes one in the Postman app.
138964
+ ...options.privateMockAuth ? [{ key: PRIVATE_MOCK_AUTH_VARIABLE2, value: "", type: "secret" }] : [],
138934
138965
  { key: "CI", value: "false", type: "default" },
138935
138966
  { key: "RESPONSE_TIME_THRESHOLD", value: "2000", type: "default" },
138936
138967
  { key: "AWS_ACCESS_KEY_ID", value: "", type: "secret" },
@@ -139377,12 +139408,12 @@ async function upsertEnvironments(inputs, dependencies, resourcesState, assetMar
139377
139408
  }
139378
139409
  return envUids;
139379
139410
  }
139380
- async function upsertMockEnvironment(inputs, dependencies, assetProjectName, mockUrl) {
139411
+ async function upsertMockEnvironment(inputs, dependencies, assetProjectName, mockUrl, privateMockAuth) {
139381
139412
  if (!inputs.mockEnvironmentEnabled || !inputs.workspaceId || !mockUrl) {
139382
139413
  return "";
139383
139414
  }
139384
139415
  const displayName = `${assetProjectName} - Mock`;
139385
- const values = buildEnvironmentValues("mock", mockUrl);
139416
+ const values = buildEnvironmentValues("mock", mockUrl, { privateMockAuth });
139386
139417
  const mask = resolveRepoSyncMasker(dependencies);
139387
139418
  try {
139388
139419
  const discovered = await dependencies.postman.findEnvironmentByName(
@@ -140111,14 +140142,16 @@ function renderCiWorkflow(inputs) {
140111
140142
  postmanCliInstallUrl: inputs.postmanCliInstallUrl,
140112
140143
  postmanCliWindowsInstallUrl: inputs.postmanCliWindowsInstallUrl,
140113
140144
  runnerOs: inputs.ciRunnerOs,
140114
- postmanRegion: inputs.postmanRegion
140145
+ postmanRegion: inputs.postmanRegion,
140146
+ privateMockAuth: inputs.mockVisibility === "private"
140115
140147
  });
140116
140148
  }
140117
140149
  return renderCiWorkflowTemplate({
140118
140150
  postmanCliInstallUrl: inputs.postmanCliInstallUrl,
140119
140151
  postmanCliWindowsInstallUrl: inputs.postmanCliWindowsInstallUrl,
140120
140152
  runnerOs: inputs.ciRunnerOs,
140121
- postmanRegion: inputs.postmanRegion
140153
+ postmanRegion: inputs.postmanRegion,
140154
+ privateMockAuth: inputs.mockVisibility === "private"
140122
140155
  });
140123
140156
  }
140124
140157
  function createRepoSummary(outputs, envUids, pushed) {
@@ -140473,18 +140506,26 @@ async function runRepoSyncInner(inputs, dependencies) {
140473
140506
  "PRIVATE_MOCK_RUNTIME_AUTH_UNAVAILABLE: The Postman client cannot configure runtime x-api-key injection."
140474
140507
  );
140475
140508
  }
140509
+ const configured = [];
140476
140510
  for (const collectionUid of [inputs.smokeCollectionId, inputs.contractCollectionId]) {
140477
140511
  if (collectionUid) {
140478
140512
  await dependencies.postman.configurePrivateMockRuntimeAuth(collectionUid);
140513
+ configured.push(collectionUid);
140479
140514
  }
140480
140515
  }
140516
+ if (configured.length > 0) {
140517
+ (dependencies.core.notice ?? dependencies.core.info)(
140518
+ `Private mock: installed a request hook on ${configured.length} collection(s) that sends the ${PRIVATE_MOCK_AUTH_VARIABLE2} variable as x-api-key, and only to *.mock.pstmn.io hosts. The generated CI workflow supplies it from the POSTMAN_API_KEY secret. For manual runs in the Postman app, set that variable to a key with access to the mock. No key is stored in the collection, environment, outputs, or repository.`
140519
+ );
140520
+ }
140481
140521
  }
140482
140522
  if (inputs.mockEnvironmentEnabled && isCanonicalWriter) {
140483
140523
  const mockEnvironmentUid = await upsertMockEnvironment(
140484
140524
  inputs,
140485
140525
  dependencies,
140486
140526
  assetProjectName,
140487
- resolvedMockUrl
140527
+ resolvedMockUrl,
140528
+ resolvedMockVisibility === "private"
140488
140529
  );
140489
140530
  outputs["mock-environment-uid"] = mockEnvironmentUid;
140490
140531
  outputs["mock-environment-status"] = mockEnvironmentUid ? "success" : "failed";
package/dist/cli.cjs CHANGED
@@ -132357,6 +132357,7 @@ function resolvePostmanEndpointProfile(stack, region = "us") {
132357
132357
  // src/lib/ci-workflow-template.ts
132358
132358
  var DEFAULT_POSTMAN_CLI_INSTALL_URL = POSTMAN_ENDPOINT_PROFILES.prod.cliInstallUrl;
132359
132359
  var DEFAULT_POSTMAN_CLI_WINDOWS_INSTALL_URL = POSTMAN_ENDPOINT_PROFILES.prod.cliWindowsInstallUrl;
132360
+ var PRIVATE_MOCK_AUTH_VARIABLE = "postmanPrivateMockApiKey";
132360
132361
  function validateHttpsInstallUrl(url) {
132361
132362
  const safeUrlPattern = /^https:\/\/[A-Za-z0-9.-]+\/[A-Za-z0-9._~/?=&%-]+$/;
132362
132363
  if (!safeUrlPattern.test(url)) {
@@ -132388,9 +132389,9 @@ function renderCiWorkflowTemplate(options = {}) {
132388
132389
  const rawUrl = String(options.postmanCliInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_INSTALL_URL;
132389
132390
  const installUrl = validateHttpsInstallUrl(rawUrl);
132390
132391
  const postmanRegion = resolvePostmanRegion(options.postmanRegion);
132391
- return buildCiWorkflowLines(installUrl, postmanRegion).join("\n");
132392
+ return buildCiWorkflowLines(installUrl, postmanRegion, options.privateMockAuth === true).join("\n");
132392
132393
  }
132393
- function buildCiWorkflowLines(installUrl, postmanRegion) {
132394
+ function buildCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
132394
132395
  return [
132395
132396
  "name: CI/CD Pipeline",
132396
132397
  "on:",
@@ -132457,6 +132458,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
132457
132458
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
132458
132459
  " --report-events",
132459
132460
  ` --env-var "CI_ENVIRONMENT=\${{ vars.CI_ENVIRONMENT || 'Production' }}")`,
132461
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=${{ secrets.POSTMAN_API_KEY }}")'] : [],
132460
132462
  ' if [ -f "$RUNNER_TEMP/postman-ssl/client.crt" ]; then',
132461
132463
  ' CMD+=(--ssl-client-cert "$RUNNER_TEMP/postman-ssl/client.crt"',
132462
132464
  ' --ssl-client-key "$RUNNER_TEMP/postman-ssl/client.key")',
@@ -132476,6 +132478,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
132476
132478
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
132477
132479
  " --report-events",
132478
132480
  ` --env-var "CI_ENVIRONMENT=\${{ vars.CI_ENVIRONMENT || 'Production' }}")`,
132481
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=${{ secrets.POSTMAN_API_KEY }}")'] : [],
132479
132482
  ' if [ -f "$RUNNER_TEMP/postman-ssl/client.crt" ]; then',
132480
132483
  ' CMD+=(--ssl-client-cert "$RUNNER_TEMP/postman-ssl/client.crt"',
132481
132484
  ' --ssl-client-key "$RUNNER_TEMP/postman-ssl/client.key")',
@@ -132491,7 +132494,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
132491
132494
  ];
132492
132495
  }
132493
132496
  var CI_WORKFLOW_TEMPLATE = renderCiWorkflowTemplate();
132494
- function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentName) {
132497
+ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentName, privateMockAuth) {
132495
132498
  return [
132496
132499
  " - pwsh: |",
132497
132500
  " $ErrorActionPreference = 'Stop'",
@@ -132503,6 +132506,7 @@ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentNam
132503
132506
  " $ciEnvironment = Resolve-AdoOptional $env:CI_ENVIRONMENT",
132504
132507
  " if ([string]::IsNullOrWhiteSpace($ciEnvironment)) { $ciEnvironment = 'Production' }",
132505
132508
  ` $arguments = @('collection', 'run', $collectionUid, '-e', $env:POSTMAN_ENVIRONMENT_UID, '--report-events', '--env-var', "CI_ENVIRONMENT=$ciEnvironment")`,
132509
+ ...privateMockAuth ? [` $arguments += @('--env-var', "${PRIVATE_MOCK_AUTH_VARIABLE}=$env:POSTMAN_API_KEY")`] : [],
132506
132510
  " $sslRoot = Join-Path $env:AGENT_TEMPDIRECTORY 'postman-ssl'",
132507
132511
  " $clientCert = Join-Path $sslRoot 'client.crt'",
132508
132512
  " $clientKey = Join-Path $sslRoot 'client.key'",
@@ -132524,10 +132528,11 @@ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentNam
132524
132528
  ` ${collectionEnvironmentName}: $(${collectionEnvironmentName})`,
132525
132529
  " POSTMAN_ENVIRONMENT_UID: $(POSTMAN_ENVIRONMENT_UID)",
132526
132530
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
132527
- " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)"
132531
+ " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
132532
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : []
132528
132533
  ];
132529
132534
  }
132530
- function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) {
132535
+ function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
132531
132536
  return [
132532
132537
  "trigger:",
132533
132538
  " branches:",
@@ -132612,12 +132617,12 @@ function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) {
132612
132617
  " POSTMAN_SSL_CLIENT_CERT_B64: $(POSTMAN_SSL_CLIENT_CERT_B64)",
132613
132618
  " POSTMAN_SSL_CLIENT_KEY_B64: $(POSTMAN_SSL_CLIENT_KEY_B64)",
132614
132619
  " POSTMAN_SSL_EXTRA_CA_CERTS_B64: $(POSTMAN_SSL_EXTRA_CA_CERTS_B64)",
132615
- ...buildAdoWindowsCollectionRunLines("Run Smoke Tests", "POSTMAN_SMOKE_COLLECTION_UID"),
132616
- ...buildAdoWindowsCollectionRunLines("Run Contract Tests", "POSTMAN_CONTRACT_COLLECTION_UID"),
132620
+ ...buildAdoWindowsCollectionRunLines("Run Smoke Tests", "POSTMAN_SMOKE_COLLECTION_UID", privateMockAuth),
132621
+ ...buildAdoWindowsCollectionRunLines("Run Contract Tests", "POSTMAN_CONTRACT_COLLECTION_UID", privateMockAuth),
132617
132622
  ""
132618
132623
  ];
132619
132624
  }
132620
- function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
132625
+ function buildAdoCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
132621
132626
  return [
132622
132627
  "trigger:",
132623
132628
  " branches:",
@@ -132694,6 +132699,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
132694
132699
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
132695
132700
  " --report-events",
132696
132701
  ' --env-var "CI_ENVIRONMENT=${CI_ENVIRONMENT:-Production}")',
132702
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=$POSTMAN_API_KEY")'] : [],
132697
132703
  ' if [ -f "$(Agent.TempDirectory)/postman-ssl/client.crt" ]; then',
132698
132704
  ' CMD+=(--ssl-client-cert "$(Agent.TempDirectory)/postman-ssl/client.crt"',
132699
132705
  ' --ssl-client-key "$(Agent.TempDirectory)/postman-ssl/client.key")',
@@ -132709,6 +132715,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
132709
132715
  " env:",
132710
132716
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
132711
132717
  " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
132718
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : [],
132712
132719
  " - script: |",
132713
132720
  " normalize_azure_optional_var() {",
132714
132721
  ' local name="$1"',
@@ -132725,6 +132732,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
132725
132732
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
132726
132733
  " --report-events",
132727
132734
  ' --env-var "CI_ENVIRONMENT=${CI_ENVIRONMENT:-Production}")',
132735
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=$POSTMAN_API_KEY")'] : [],
132728
132736
  ' if [ -f "$(Agent.TempDirectory)/postman-ssl/client.crt" ]; then',
132729
132737
  ' CMD+=(--ssl-client-cert "$(Agent.TempDirectory)/postman-ssl/client.crt"',
132730
132738
  ' --ssl-client-key "$(Agent.TempDirectory)/postman-ssl/client.key")',
@@ -132740,6 +132748,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
132740
132748
  " env:",
132741
132749
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
132742
132750
  " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
132751
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : [],
132743
132752
  ""
132744
132753
  ];
132745
132754
  }
@@ -132801,7 +132810,8 @@ function getCiWorkflowTemplate(provider, options = {}) {
132801
132810
  const rawUrl = runnerOs === "windows" ? String(options.postmanCliWindowsInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_WINDOWS_INSTALL_URL : String(options.postmanCliInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_INSTALL_URL;
132802
132811
  const postmanRegion = resolvePostmanRegion(options.postmanRegion);
132803
132812
  const installUrl = validateHttpsInstallUrl(rawUrl);
132804
- return (runnerOs === "windows" ? buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) : buildAdoCiWorkflowLines(installUrl, postmanRegion)).join("\n");
132813
+ const privateMockAuth = options.privateMockAuth === true;
132814
+ return (runnerOs === "windows" ? buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) : buildAdoCiWorkflowLines(installUrl, postmanRegion, privateMockAuth)).join("\n");
132805
132815
  }
132806
132816
  return renderCiWorkflowTemplate(options);
132807
132817
  }
@@ -135089,16 +135099,32 @@ function requireMockVisibility(mock, requested) {
135089
135099
  }
135090
135100
  return mock;
135091
135101
  }
135092
- var PRIVATE_MOCK_AUTH_MARKER = "postman-enterprise-automation: private-mock-auth";
135093
- var PRIVATE_MOCK_AUTH_VARIABLE = "postmanPrivateMockApiKey";
135094
- var PRIVATE_MOCK_AUTH_SCRIPT = [
135095
- `// ${PRIVATE_MOCK_AUTH_MARKER}`,
135096
- `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE}');`,
135102
+ var LEGACY_PRIVATE_MOCK_AUTH_MARKER = "postman-enterprise-automation: private-mock-auth";
135103
+ var PRIVATE_MOCK_AUTH_MARKER = `${LEGACY_PRIVATE_MOCK_AUTH_MARKER}-v2`;
135104
+ var PRIVATE_MOCK_AUTH_VARIABLE2 = "postmanPrivateMockApiKey";
135105
+ var LEGACY_PRIVATE_MOCK_AUTH_SCRIPT = [
135106
+ `// ${LEGACY_PRIVATE_MOCK_AUTH_MARKER}`,
135107
+ `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE2}');`,
135097
135108
  "var privateMockHost = String(pm.request.url && pm.request.url.getHost ? pm.request.url.getHost() : '');",
135098
135109
  "if (privateMockApiKey && /(^|\\.)mock\\.pstmn\\.io$/i.test(privateMockHost)) {",
135099
135110
  " pm.request.headers.upsert({ key: 'x-api-key', value: privateMockApiKey });",
135100
135111
  "}"
135101
135112
  ].join("\n");
135113
+ var PRIVATE_MOCK_AUTH_SCRIPT = [
135114
+ `// ${PRIVATE_MOCK_AUTH_MARKER}`,
135115
+ `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE2}');`,
135116
+ "var privateMockHostValue = pm.request.url && pm.request.url.getHost ? pm.request.url.getHost() : '';",
135117
+ "var privateMockHost = Array.isArray(privateMockHostValue) ? privateMockHostValue.join('.') : String(privateMockHostValue);",
135118
+ "var isPrivateMockHost = /(^|\\.)mock\\.pstmn\\.io$/i.test(privateMockHost);",
135119
+ "if (isPrivateMockHost && privateMockApiKey) {",
135120
+ " pm.request.headers.upsert({ key: 'x-api-key', value: privateMockApiKey });",
135121
+ "} else if (isPrivateMockHost) {",
135122
+ ` console.warn('This mock server is private. Set the ${PRIVATE_MOCK_AUTH_VARIABLE2} variable to a Postman API key with access to it, or the request returns 401.');`,
135123
+ "}"
135124
+ ].join("\n");
135125
+ function removeLegacyPrivateMockAuth(code) {
135126
+ return code.split(LEGACY_PRIVATE_MOCK_AUTH_SCRIPT).join("").trim();
135127
+ }
135102
135128
  var MAX_CREATE_FLIGHTS = 256;
135103
135129
  var createFlights = /* @__PURE__ */ new Map();
135104
135130
  var PostmanGatewayAssetsClient = class {
@@ -135696,8 +135722,9 @@ var PostmanGatewayAssetsClient = class {
135696
135722
  const item = this.asRecord(response?.data) ?? listedItem;
135697
135723
  const scripts = Array.isArray(item.scripts) ? item.scripts.filter((entry) => Boolean(this.asRecord(entry))) : [];
135698
135724
  const before = scripts.find((script) => String(script.type ?? "") === "beforeRequest");
135699
- if (String(before?.code ?? "").includes(PRIVATE_MOCK_AUTH_MARKER)) continue;
135700
- const code = [String(before?.code ?? "").trim(), PRIVATE_MOCK_AUTH_SCRIPT].filter(Boolean).join("\n");
135725
+ const existingCode = String(before?.code ?? "");
135726
+ if (existingCode.includes(PRIVATE_MOCK_AUTH_MARKER)) continue;
135727
+ const code = [removeLegacyPrivateMockAuth(existingCode), PRIVATE_MOCK_AUTH_SCRIPT].filter(Boolean).join("\n");
135701
135728
  const nextScripts = [
135702
135729
  ...scripts.filter((script) => String(script.type ?? "") !== "beforeRequest"),
135703
135730
  { type: "beforeRequest", code, language: "text/javascript" }
@@ -136978,9 +137005,13 @@ function assertBranchAssetIds(inputs, decision, branchOwnedIds = process.env.POS
136978
137005
  );
136979
137006
  }
136980
137007
  }
136981
- function buildEnvironmentValues(envName, baseUrl) {
137008
+ function buildEnvironmentValues(envName, baseUrl, options = {}) {
136982
137009
  return [
136983
137010
  { key: "baseUrl", value: baseUrl, type: "default" },
137011
+ // A private mock refuses anonymous calls, so the manual-validation environment
137012
+ // carries a named, empty, secret-typed slot for the caller's own key. Repo-sync
137013
+ // never writes a value here; the developer pastes one in the Postman app.
137014
+ ...options.privateMockAuth ? [{ key: PRIVATE_MOCK_AUTH_VARIABLE2, value: "", type: "secret" }] : [],
136984
137015
  { key: "CI", value: "false", type: "default" },
136985
137016
  { key: "RESPONSE_TIME_THRESHOLD", value: "2000", type: "default" },
136986
137017
  { key: "AWS_ACCESS_KEY_ID", value: "", type: "secret" },
@@ -137285,12 +137316,12 @@ async function upsertEnvironments(inputs, dependencies, resourcesState, assetMar
137285
137316
  }
137286
137317
  return envUids;
137287
137318
  }
137288
- async function upsertMockEnvironment(inputs, dependencies, assetProjectName, mockUrl) {
137319
+ async function upsertMockEnvironment(inputs, dependencies, assetProjectName, mockUrl, privateMockAuth) {
137289
137320
  if (!inputs.mockEnvironmentEnabled || !inputs.workspaceId || !mockUrl) {
137290
137321
  return "";
137291
137322
  }
137292
137323
  const displayName = `${assetProjectName} - Mock`;
137293
- const values = buildEnvironmentValues("mock", mockUrl);
137324
+ const values = buildEnvironmentValues("mock", mockUrl, { privateMockAuth });
137294
137325
  const mask = resolveRepoSyncMasker(dependencies);
137295
137326
  try {
137296
137327
  const discovered = await dependencies.postman.findEnvironmentByName(
@@ -138019,14 +138050,16 @@ function renderCiWorkflow(inputs) {
138019
138050
  postmanCliInstallUrl: inputs.postmanCliInstallUrl,
138020
138051
  postmanCliWindowsInstallUrl: inputs.postmanCliWindowsInstallUrl,
138021
138052
  runnerOs: inputs.ciRunnerOs,
138022
- postmanRegion: inputs.postmanRegion
138053
+ postmanRegion: inputs.postmanRegion,
138054
+ privateMockAuth: inputs.mockVisibility === "private"
138023
138055
  });
138024
138056
  }
138025
138057
  return renderCiWorkflowTemplate({
138026
138058
  postmanCliInstallUrl: inputs.postmanCliInstallUrl,
138027
138059
  postmanCliWindowsInstallUrl: inputs.postmanCliWindowsInstallUrl,
138028
138060
  runnerOs: inputs.ciRunnerOs,
138029
- postmanRegion: inputs.postmanRegion
138061
+ postmanRegion: inputs.postmanRegion,
138062
+ privateMockAuth: inputs.mockVisibility === "private"
138030
138063
  });
138031
138064
  }
138032
138065
  function createRepoSummary(outputs, envUids, pushed) {
@@ -138381,18 +138414,26 @@ async function runRepoSyncInner(inputs, dependencies) {
138381
138414
  "PRIVATE_MOCK_RUNTIME_AUTH_UNAVAILABLE: The Postman client cannot configure runtime x-api-key injection."
138382
138415
  );
138383
138416
  }
138417
+ const configured = [];
138384
138418
  for (const collectionUid of [inputs.smokeCollectionId, inputs.contractCollectionId]) {
138385
138419
  if (collectionUid) {
138386
138420
  await dependencies.postman.configurePrivateMockRuntimeAuth(collectionUid);
138421
+ configured.push(collectionUid);
138387
138422
  }
138388
138423
  }
138424
+ if (configured.length > 0) {
138425
+ (dependencies.core.notice ?? dependencies.core.info)(
138426
+ `Private mock: installed a request hook on ${configured.length} collection(s) that sends the ${PRIVATE_MOCK_AUTH_VARIABLE2} variable as x-api-key, and only to *.mock.pstmn.io hosts. The generated CI workflow supplies it from the POSTMAN_API_KEY secret. For manual runs in the Postman app, set that variable to a key with access to the mock. No key is stored in the collection, environment, outputs, or repository.`
138427
+ );
138428
+ }
138389
138429
  }
138390
138430
  if (inputs.mockEnvironmentEnabled && isCanonicalWriter) {
138391
138431
  const mockEnvironmentUid = await upsertMockEnvironment(
138392
138432
  inputs,
138393
138433
  dependencies,
138394
138434
  assetProjectName,
138395
- resolvedMockUrl
138435
+ resolvedMockUrl,
138436
+ resolvedMockVisibility === "private"
138396
138437
  );
138397
138438
  outputs["mock-environment-uid"] = mockEnvironmentUid;
138398
138439
  outputs["mock-environment-status"] = mockEnvironmentUid ? "success" : "failed";
@@ -139401,6 +139442,9 @@ var ConsoleReporter = class {
139401
139442
  info(message) {
139402
139443
  console.error(message);
139403
139444
  }
139445
+ notice(message) {
139446
+ console.error(`notice: ${message}`);
139447
+ }
139404
139448
  warning(message) {
139405
139449
  console.error(`warning: ${message}`);
139406
139450
  }
package/dist/index.cjs CHANGED
@@ -134274,6 +134274,7 @@ function resolvePostmanEndpointProfile(stack, region = "us") {
134274
134274
  // src/lib/ci-workflow-template.ts
134275
134275
  var DEFAULT_POSTMAN_CLI_INSTALL_URL = POSTMAN_ENDPOINT_PROFILES.prod.cliInstallUrl;
134276
134276
  var DEFAULT_POSTMAN_CLI_WINDOWS_INSTALL_URL = POSTMAN_ENDPOINT_PROFILES.prod.cliWindowsInstallUrl;
134277
+ var PRIVATE_MOCK_AUTH_VARIABLE = "postmanPrivateMockApiKey";
134277
134278
  function validateHttpsInstallUrl(url) {
134278
134279
  const safeUrlPattern = /^https:\/\/[A-Za-z0-9.-]+\/[A-Za-z0-9._~/?=&%-]+$/;
134279
134280
  if (!safeUrlPattern.test(url)) {
@@ -134305,9 +134306,9 @@ function renderCiWorkflowTemplate(options = {}) {
134305
134306
  const rawUrl = String(options.postmanCliInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_INSTALL_URL;
134306
134307
  const installUrl = validateHttpsInstallUrl(rawUrl);
134307
134308
  const postmanRegion = resolvePostmanRegion(options.postmanRegion);
134308
- return buildCiWorkflowLines(installUrl, postmanRegion).join("\n");
134309
+ return buildCiWorkflowLines(installUrl, postmanRegion, options.privateMockAuth === true).join("\n");
134309
134310
  }
134310
- function buildCiWorkflowLines(installUrl, postmanRegion) {
134311
+ function buildCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
134311
134312
  return [
134312
134313
  "name: CI/CD Pipeline",
134313
134314
  "on:",
@@ -134374,6 +134375,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
134374
134375
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134375
134376
  " --report-events",
134376
134377
  ` --env-var "CI_ENVIRONMENT=\${{ vars.CI_ENVIRONMENT || 'Production' }}")`,
134378
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=${{ secrets.POSTMAN_API_KEY }}")'] : [],
134377
134379
  ' if [ -f "$RUNNER_TEMP/postman-ssl/client.crt" ]; then',
134378
134380
  ' CMD+=(--ssl-client-cert "$RUNNER_TEMP/postman-ssl/client.crt"',
134379
134381
  ' --ssl-client-key "$RUNNER_TEMP/postman-ssl/client.key")',
@@ -134393,6 +134395,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
134393
134395
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134394
134396
  " --report-events",
134395
134397
  ` --env-var "CI_ENVIRONMENT=\${{ vars.CI_ENVIRONMENT || 'Production' }}")`,
134398
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=${{ secrets.POSTMAN_API_KEY }}")'] : [],
134396
134399
  ' if [ -f "$RUNNER_TEMP/postman-ssl/client.crt" ]; then',
134397
134400
  ' CMD+=(--ssl-client-cert "$RUNNER_TEMP/postman-ssl/client.crt"',
134398
134401
  ' --ssl-client-key "$RUNNER_TEMP/postman-ssl/client.key")',
@@ -134408,7 +134411,7 @@ function buildCiWorkflowLines(installUrl, postmanRegion) {
134408
134411
  ];
134409
134412
  }
134410
134413
  var CI_WORKFLOW_TEMPLATE = renderCiWorkflowTemplate();
134411
- function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentName) {
134414
+ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentName, privateMockAuth) {
134412
134415
  return [
134413
134416
  " - pwsh: |",
134414
134417
  " $ErrorActionPreference = 'Stop'",
@@ -134420,6 +134423,7 @@ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentNam
134420
134423
  " $ciEnvironment = Resolve-AdoOptional $env:CI_ENVIRONMENT",
134421
134424
  " if ([string]::IsNullOrWhiteSpace($ciEnvironment)) { $ciEnvironment = 'Production' }",
134422
134425
  ` $arguments = @('collection', 'run', $collectionUid, '-e', $env:POSTMAN_ENVIRONMENT_UID, '--report-events', '--env-var', "CI_ENVIRONMENT=$ciEnvironment")`,
134426
+ ...privateMockAuth ? [` $arguments += @('--env-var', "${PRIVATE_MOCK_AUTH_VARIABLE}=$env:POSTMAN_API_KEY")`] : [],
134423
134427
  " $sslRoot = Join-Path $env:AGENT_TEMPDIRECTORY 'postman-ssl'",
134424
134428
  " $clientCert = Join-Path $sslRoot 'client.crt'",
134425
134429
  " $clientKey = Join-Path $sslRoot 'client.key'",
@@ -134441,10 +134445,11 @@ function buildAdoWindowsCollectionRunLines(displayName, collectionEnvironmentNam
134441
134445
  ` ${collectionEnvironmentName}: $(${collectionEnvironmentName})`,
134442
134446
  " POSTMAN_ENVIRONMENT_UID: $(POSTMAN_ENVIRONMENT_UID)",
134443
134447
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
134444
- " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)"
134448
+ " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
134449
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : []
134445
134450
  ];
134446
134451
  }
134447
- function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) {
134452
+ function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
134448
134453
  return [
134449
134454
  "trigger:",
134450
134455
  " branches:",
@@ -134529,12 +134534,12 @@ function buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) {
134529
134534
  " POSTMAN_SSL_CLIENT_CERT_B64: $(POSTMAN_SSL_CLIENT_CERT_B64)",
134530
134535
  " POSTMAN_SSL_CLIENT_KEY_B64: $(POSTMAN_SSL_CLIENT_KEY_B64)",
134531
134536
  " POSTMAN_SSL_EXTRA_CA_CERTS_B64: $(POSTMAN_SSL_EXTRA_CA_CERTS_B64)",
134532
- ...buildAdoWindowsCollectionRunLines("Run Smoke Tests", "POSTMAN_SMOKE_COLLECTION_UID"),
134533
- ...buildAdoWindowsCollectionRunLines("Run Contract Tests", "POSTMAN_CONTRACT_COLLECTION_UID"),
134537
+ ...buildAdoWindowsCollectionRunLines("Run Smoke Tests", "POSTMAN_SMOKE_COLLECTION_UID", privateMockAuth),
134538
+ ...buildAdoWindowsCollectionRunLines("Run Contract Tests", "POSTMAN_CONTRACT_COLLECTION_UID", privateMockAuth),
134534
134539
  ""
134535
134540
  ];
134536
134541
  }
134537
- function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134542
+ function buildAdoCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) {
134538
134543
  return [
134539
134544
  "trigger:",
134540
134545
  " branches:",
@@ -134611,6 +134616,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134611
134616
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134612
134617
  " --report-events",
134613
134618
  ' --env-var "CI_ENVIRONMENT=${CI_ENVIRONMENT:-Production}")',
134619
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=$POSTMAN_API_KEY")'] : [],
134614
134620
  ' if [ -f "$(Agent.TempDirectory)/postman-ssl/client.crt" ]; then',
134615
134621
  ' CMD+=(--ssl-client-cert "$(Agent.TempDirectory)/postman-ssl/client.crt"',
134616
134622
  ' --ssl-client-key "$(Agent.TempDirectory)/postman-ssl/client.key")',
@@ -134626,6 +134632,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134626
134632
  " env:",
134627
134633
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
134628
134634
  " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
134635
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : [],
134629
134636
  " - script: |",
134630
134637
  " normalize_azure_optional_var() {",
134631
134638
  ' local name="$1"',
@@ -134642,6 +134649,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134642
134649
  ' -e "$POSTMAN_ENVIRONMENT_UID"',
134643
134650
  " --report-events",
134644
134651
  ' --env-var "CI_ENVIRONMENT=${CI_ENVIRONMENT:-Production}")',
134652
+ ...privateMockAuth ? [' CMD+=(--env-var "' + PRIVATE_MOCK_AUTH_VARIABLE + '=$POSTMAN_API_KEY")'] : [],
134645
134653
  ' if [ -f "$(Agent.TempDirectory)/postman-ssl/client.crt" ]; then',
134646
134654
  ' CMD+=(--ssl-client-cert "$(Agent.TempDirectory)/postman-ssl/client.crt"',
134647
134655
  ' --ssl-client-key "$(Agent.TempDirectory)/postman-ssl/client.key")',
@@ -134657,6 +134665,7 @@ function buildAdoCiWorkflowLines(installUrl, postmanRegion) {
134657
134665
  " env:",
134658
134666
  " CI_ENVIRONMENT: $(CI_ENVIRONMENT)",
134659
134667
  " POSTMAN_SSL_CLIENT_PASSPHRASE: $(POSTMAN_SSL_CLIENT_PASSPHRASE)",
134668
+ ...privateMockAuth ? [" POSTMAN_API_KEY: $(POSTMAN_API_KEY)"] : [],
134660
134669
  ""
134661
134670
  ];
134662
134671
  }
@@ -134718,7 +134727,8 @@ function getCiWorkflowTemplate(provider, options = {}) {
134718
134727
  const rawUrl = runnerOs === "windows" ? String(options.postmanCliWindowsInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_WINDOWS_INSTALL_URL : String(options.postmanCliInstallUrl || "").trim() || DEFAULT_POSTMAN_CLI_INSTALL_URL;
134719
134728
  const postmanRegion = resolvePostmanRegion(options.postmanRegion);
134720
134729
  const installUrl = validateHttpsInstallUrl(rawUrl);
134721
- return (runnerOs === "windows" ? buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion) : buildAdoCiWorkflowLines(installUrl, postmanRegion)).join("\n");
134730
+ const privateMockAuth = options.privateMockAuth === true;
134731
+ return (runnerOs === "windows" ? buildAdoWindowsCiWorkflowLines(installUrl, postmanRegion, privateMockAuth) : buildAdoCiWorkflowLines(installUrl, postmanRegion, privateMockAuth)).join("\n");
134722
134732
  }
134723
134733
  return renderCiWorkflowTemplate(options);
134724
134734
  }
@@ -137006,16 +137016,32 @@ function requireMockVisibility(mock, requested) {
137006
137016
  }
137007
137017
  return mock;
137008
137018
  }
137009
- var PRIVATE_MOCK_AUTH_MARKER = "postman-enterprise-automation: private-mock-auth";
137010
- var PRIVATE_MOCK_AUTH_VARIABLE = "postmanPrivateMockApiKey";
137011
- var PRIVATE_MOCK_AUTH_SCRIPT = [
137012
- `// ${PRIVATE_MOCK_AUTH_MARKER}`,
137013
- `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE}');`,
137019
+ var LEGACY_PRIVATE_MOCK_AUTH_MARKER = "postman-enterprise-automation: private-mock-auth";
137020
+ var PRIVATE_MOCK_AUTH_MARKER = `${LEGACY_PRIVATE_MOCK_AUTH_MARKER}-v2`;
137021
+ var PRIVATE_MOCK_AUTH_VARIABLE2 = "postmanPrivateMockApiKey";
137022
+ var LEGACY_PRIVATE_MOCK_AUTH_SCRIPT = [
137023
+ `// ${LEGACY_PRIVATE_MOCK_AUTH_MARKER}`,
137024
+ `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE2}');`,
137014
137025
  "var privateMockHost = String(pm.request.url && pm.request.url.getHost ? pm.request.url.getHost() : '');",
137015
137026
  "if (privateMockApiKey && /(^|\\.)mock\\.pstmn\\.io$/i.test(privateMockHost)) {",
137016
137027
  " pm.request.headers.upsert({ key: 'x-api-key', value: privateMockApiKey });",
137017
137028
  "}"
137018
137029
  ].join("\n");
137030
+ var PRIVATE_MOCK_AUTH_SCRIPT = [
137031
+ `// ${PRIVATE_MOCK_AUTH_MARKER}`,
137032
+ `var privateMockApiKey = pm.variables.get('${PRIVATE_MOCK_AUTH_VARIABLE2}');`,
137033
+ "var privateMockHostValue = pm.request.url && pm.request.url.getHost ? pm.request.url.getHost() : '';",
137034
+ "var privateMockHost = Array.isArray(privateMockHostValue) ? privateMockHostValue.join('.') : String(privateMockHostValue);",
137035
+ "var isPrivateMockHost = /(^|\\.)mock\\.pstmn\\.io$/i.test(privateMockHost);",
137036
+ "if (isPrivateMockHost && privateMockApiKey) {",
137037
+ " pm.request.headers.upsert({ key: 'x-api-key', value: privateMockApiKey });",
137038
+ "} else if (isPrivateMockHost) {",
137039
+ ` console.warn('This mock server is private. Set the ${PRIVATE_MOCK_AUTH_VARIABLE2} variable to a Postman API key with access to it, or the request returns 401.');`,
137040
+ "}"
137041
+ ].join("\n");
137042
+ function removeLegacyPrivateMockAuth(code) {
137043
+ return code.split(LEGACY_PRIVATE_MOCK_AUTH_SCRIPT).join("").trim();
137044
+ }
137019
137045
  var MAX_CREATE_FLIGHTS = 256;
137020
137046
  var createFlights = /* @__PURE__ */ new Map();
137021
137047
  var PostmanGatewayAssetsClient = class {
@@ -137613,8 +137639,9 @@ var PostmanGatewayAssetsClient = class {
137613
137639
  const item = this.asRecord(response?.data) ?? listedItem;
137614
137640
  const scripts = Array.isArray(item.scripts) ? item.scripts.filter((entry) => Boolean(this.asRecord(entry))) : [];
137615
137641
  const before = scripts.find((script) => String(script.type ?? "") === "beforeRequest");
137616
- if (String(before?.code ?? "").includes(PRIVATE_MOCK_AUTH_MARKER)) continue;
137617
- const code = [String(before?.code ?? "").trim(), PRIVATE_MOCK_AUTH_SCRIPT].filter(Boolean).join("\n");
137642
+ const existingCode = String(before?.code ?? "");
137643
+ if (existingCode.includes(PRIVATE_MOCK_AUTH_MARKER)) continue;
137644
+ const code = [removeLegacyPrivateMockAuth(existingCode), PRIVATE_MOCK_AUTH_SCRIPT].filter(Boolean).join("\n");
137618
137645
  const nextScripts = [
137619
137646
  ...scripts.filter((script) => String(script.type ?? "") !== "beforeRequest"),
137620
137647
  { type: "beforeRequest", code, language: "text/javascript" }
@@ -138950,9 +138977,13 @@ function assertBranchAssetIds(inputs, decision, branchOwnedIds = process.env.POS
138950
138977
  );
138951
138978
  }
138952
138979
  }
138953
- function buildEnvironmentValues(envName, baseUrl) {
138980
+ function buildEnvironmentValues(envName, baseUrl, options = {}) {
138954
138981
  return [
138955
138982
  { key: "baseUrl", value: baseUrl, type: "default" },
138983
+ // A private mock refuses anonymous calls, so the manual-validation environment
138984
+ // carries a named, empty, secret-typed slot for the caller's own key. Repo-sync
138985
+ // never writes a value here; the developer pastes one in the Postman app.
138986
+ ...options.privateMockAuth ? [{ key: PRIVATE_MOCK_AUTH_VARIABLE2, value: "", type: "secret" }] : [],
138956
138987
  { key: "CI", value: "false", type: "default" },
138957
138988
  { key: "RESPONSE_TIME_THRESHOLD", value: "2000", type: "default" },
138958
138989
  { key: "AWS_ACCESS_KEY_ID", value: "", type: "secret" },
@@ -139399,12 +139430,12 @@ async function upsertEnvironments(inputs, dependencies, resourcesState, assetMar
139399
139430
  }
139400
139431
  return envUids;
139401
139432
  }
139402
- async function upsertMockEnvironment(inputs, dependencies, assetProjectName, mockUrl) {
139433
+ async function upsertMockEnvironment(inputs, dependencies, assetProjectName, mockUrl, privateMockAuth) {
139403
139434
  if (!inputs.mockEnvironmentEnabled || !inputs.workspaceId || !mockUrl) {
139404
139435
  return "";
139405
139436
  }
139406
139437
  const displayName = `${assetProjectName} - Mock`;
139407
- const values = buildEnvironmentValues("mock", mockUrl);
139438
+ const values = buildEnvironmentValues("mock", mockUrl, { privateMockAuth });
139408
139439
  const mask = resolveRepoSyncMasker(dependencies);
139409
139440
  try {
139410
139441
  const discovered = await dependencies.postman.findEnvironmentByName(
@@ -140133,14 +140164,16 @@ function renderCiWorkflow(inputs) {
140133
140164
  postmanCliInstallUrl: inputs.postmanCliInstallUrl,
140134
140165
  postmanCliWindowsInstallUrl: inputs.postmanCliWindowsInstallUrl,
140135
140166
  runnerOs: inputs.ciRunnerOs,
140136
- postmanRegion: inputs.postmanRegion
140167
+ postmanRegion: inputs.postmanRegion,
140168
+ privateMockAuth: inputs.mockVisibility === "private"
140137
140169
  });
140138
140170
  }
140139
140171
  return renderCiWorkflowTemplate({
140140
140172
  postmanCliInstallUrl: inputs.postmanCliInstallUrl,
140141
140173
  postmanCliWindowsInstallUrl: inputs.postmanCliWindowsInstallUrl,
140142
140174
  runnerOs: inputs.ciRunnerOs,
140143
- postmanRegion: inputs.postmanRegion
140175
+ postmanRegion: inputs.postmanRegion,
140176
+ privateMockAuth: inputs.mockVisibility === "private"
140144
140177
  });
140145
140178
  }
140146
140179
  function createRepoSummary(outputs, envUids, pushed) {
@@ -140495,18 +140528,26 @@ async function runRepoSyncInner(inputs, dependencies) {
140495
140528
  "PRIVATE_MOCK_RUNTIME_AUTH_UNAVAILABLE: The Postman client cannot configure runtime x-api-key injection."
140496
140529
  );
140497
140530
  }
140531
+ const configured = [];
140498
140532
  for (const collectionUid of [inputs.smokeCollectionId, inputs.contractCollectionId]) {
140499
140533
  if (collectionUid) {
140500
140534
  await dependencies.postman.configurePrivateMockRuntimeAuth(collectionUid);
140535
+ configured.push(collectionUid);
140501
140536
  }
140502
140537
  }
140538
+ if (configured.length > 0) {
140539
+ (dependencies.core.notice ?? dependencies.core.info)(
140540
+ `Private mock: installed a request hook on ${configured.length} collection(s) that sends the ${PRIVATE_MOCK_AUTH_VARIABLE2} variable as x-api-key, and only to *.mock.pstmn.io hosts. The generated CI workflow supplies it from the POSTMAN_API_KEY secret. For manual runs in the Postman app, set that variable to a key with access to the mock. No key is stored in the collection, environment, outputs, or repository.`
140541
+ );
140542
+ }
140503
140543
  }
140504
140544
  if (inputs.mockEnvironmentEnabled && isCanonicalWriter) {
140505
140545
  const mockEnvironmentUid = await upsertMockEnvironment(
140506
140546
  inputs,
140507
140547
  dependencies,
140508
140548
  assetProjectName,
140509
- resolvedMockUrl
140549
+ resolvedMockUrl,
140550
+ resolvedMockVisibility === "private"
140510
140551
  );
140511
140552
  outputs["mock-environment-uid"] = mockEnvironmentUid;
140512
140553
  outputs["mock-environment-status"] = mockEnvironmentUid ? "success" : "failed";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postman-cse/onboarding-repo-sync",
3
- "version": "2.3.1",
3
+ "version": "2.4.1",
4
4
  "description": "Postman repo sync GitHub Action.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",