@postman-cse/onboarding-insights 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/action.cjs CHANGED
@@ -22147,6 +22147,35 @@ function getFinalServiceSegment(serviceName) {
22147
22147
  return lastSlash === -1 ? serviceName : serviceName.slice(lastSlash + 1);
22148
22148
  }
22149
22149
 
22150
+ // src/lib/input.ts
22151
+ function normalizeInputValue(value) {
22152
+ return String(value ?? "").trim();
22153
+ }
22154
+ function runnerInputEnvName(name) {
22155
+ return `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
22156
+ }
22157
+ function normalizedInputEnvName(name) {
22158
+ return `INPUT_${name.replace(/-/g, "_").toUpperCase()}`;
22159
+ }
22160
+ function getInput2(name, env = process.env) {
22161
+ const normalizedName = normalizedInputEnvName(name);
22162
+ const runnerName = runnerInputEnvName(name);
22163
+ const normalizedRaw = env[normalizedName];
22164
+ const runnerRaw = runnerName === normalizedName ? void 0 : env[runnerName];
22165
+ const hasNormalized = normalizedRaw !== void 0;
22166
+ const hasRunner = runnerRaw !== void 0;
22167
+ if (hasNormalized && hasRunner) {
22168
+ const normalizedValue = normalizeInputValue(normalizedRaw);
22169
+ const runnerValue = normalizeInputValue(runnerRaw);
22170
+ if (normalizedValue !== runnerValue) {
22171
+ throw new Error(
22172
+ `Conflicting values for ${name}: ${normalizedName}=${JSON.stringify(normalizedValue)} vs ${runnerName}=${JSON.stringify(runnerValue)}`
22173
+ );
22174
+ }
22175
+ }
22176
+ return normalizeInputValue(hasNormalized ? normalizedRaw : runnerRaw);
22177
+ }
22178
+
22150
22179
  // node_modules/@postman-cse/automation-telemetry-core/dist/ci-context.js
22151
22180
  function norm(value) {
22152
22181
  const trimmed = (value ?? "").trim();
@@ -22596,7 +22625,7 @@ function clamp(value, min, max, fallback) {
22596
22625
  return Math.min(max, Math.max(min, parsed));
22597
22626
  }
22598
22627
  function resolveInputs(env = process.env) {
22599
- const get = (name, fallback = "") => env[`INPUT_${name.toUpperCase().replace(/-/g, "_")}`]?.trim() || fallback;
22628
+ const get = (name, fallback = "") => getInput2(name, env) || fallback;
22600
22629
  const projectName = get("project-name");
22601
22630
  if (!projectName) throw new Error("project-name is required");
22602
22631
  const postmanAccessToken = get("postman-access-token");
package/dist/cli.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  "use strict";
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
@@ -18685,6 +18686,7 @@ __export(cli_exports, {
18685
18686
  toDotenv: () => toDotenv
18686
18687
  });
18687
18688
  module.exports = __toCommonJS(cli_exports);
18689
+ var import_node_crypto2 = require("node:crypto");
18688
18690
  var import_node_fs2 = require("node:fs");
18689
18691
  var import_promises = require("node:fs/promises");
18690
18692
  var import_node_path2 = __toESM(require("node:path"), 1);
@@ -22162,6 +22164,35 @@ function getFinalServiceSegment(serviceName) {
22162
22164
  return lastSlash === -1 ? serviceName : serviceName.slice(lastSlash + 1);
22163
22165
  }
22164
22166
 
22167
+ // src/lib/input.ts
22168
+ function normalizeInputValue(value) {
22169
+ return String(value ?? "").trim();
22170
+ }
22171
+ function runnerInputEnvName(name) {
22172
+ return `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
22173
+ }
22174
+ function normalizedInputEnvName(name) {
22175
+ return `INPUT_${name.replace(/-/g, "_").toUpperCase()}`;
22176
+ }
22177
+ function getInput2(name, env = process.env) {
22178
+ const normalizedName = normalizedInputEnvName(name);
22179
+ const runnerName = runnerInputEnvName(name);
22180
+ const normalizedRaw = env[normalizedName];
22181
+ const runnerRaw = runnerName === normalizedName ? void 0 : env[runnerName];
22182
+ const hasNormalized = normalizedRaw !== void 0;
22183
+ const hasRunner = runnerRaw !== void 0;
22184
+ if (hasNormalized && hasRunner) {
22185
+ const normalizedValue = normalizeInputValue(normalizedRaw);
22186
+ const runnerValue = normalizeInputValue(runnerRaw);
22187
+ if (normalizedValue !== runnerValue) {
22188
+ throw new Error(
22189
+ `Conflicting values for ${name}: ${normalizedName}=${JSON.stringify(normalizedValue)} vs ${runnerName}=${JSON.stringify(runnerValue)}`
22190
+ );
22191
+ }
22192
+ }
22193
+ return normalizeInputValue(hasNormalized ? normalizedRaw : runnerRaw);
22194
+ }
22195
+
22165
22196
  // node_modules/@postman-cse/automation-telemetry-core/dist/ci-context.js
22166
22197
  function norm(value) {
22167
22198
  const trimmed = (value ?? "").trim();
@@ -22611,7 +22642,7 @@ function clamp(value, min, max, fallback) {
22611
22642
  return Math.min(max, Math.max(min, parsed));
22612
22643
  }
22613
22644
  function resolveInputs(env = process.env) {
22614
- const get = (name, fallback = "") => env[`INPUT_${name.toUpperCase().replace(/-/g, "_")}`]?.trim() || fallback;
22645
+ const get = (name, fallback = "") => getInput2(name, env) || fallback;
22615
22646
  const projectName = get("project-name");
22616
22647
  if (!projectName) throw new Error("project-name is required");
22617
22648
  const postmanAccessToken = get("postman-access-token");
@@ -22846,6 +22877,24 @@ function createInsightsBifrostClient(inputs, tokenProvider, teamId, apiKey) {
22846
22877
  }
22847
22878
 
22848
22879
  // src/cli.ts
22880
+ var INPUT_NAMES = [
22881
+ "project-name",
22882
+ "workspace-id",
22883
+ "environment-id",
22884
+ "system-environment-id",
22885
+ "cluster-name",
22886
+ "repo-url",
22887
+ "postman-access-token",
22888
+ "postman-api-key",
22889
+ "credential-preflight",
22890
+ "postman-team-id",
22891
+ "github-token",
22892
+ "poll-timeout-seconds",
22893
+ "poll-interval-seconds",
22894
+ "postman-region",
22895
+ "postman-stack"
22896
+ ];
22897
+ var OUTPUT_OPTION_NAMES = ["result-json", "dotenv-path"];
22849
22898
  var ConsoleReporter = class {
22850
22899
  secretValues = [];
22851
22900
  info(message) {
@@ -22867,51 +22916,101 @@ var ConsoleReporter = class {
22867
22916
  return masked;
22868
22917
  }
22869
22918
  };
22870
- function readFlag(argv, name) {
22871
- const prefix = `--${name}=`;
22872
- for (let index = 0; index < argv.length; index += 1) {
22873
- const arg = argv[index];
22874
- if (arg === `--${name}`) {
22875
- return argv[index + 1];
22876
- }
22877
- if (arg?.startsWith(prefix)) {
22878
- return arg.slice(prefix.length);
22919
+ function normalizeCliFlag(name) {
22920
+ return normalizedInputEnvName(name);
22921
+ }
22922
+ function resolvePackageVersion() {
22923
+ const candidates = [];
22924
+ if (typeof __filename === "string") {
22925
+ candidates.push(import_node_path2.default.join(import_node_path2.default.dirname(__filename), "..", "package.json"));
22926
+ }
22927
+ candidates.push(import_node_path2.default.join(process.cwd(), "package.json"));
22928
+ for (const candidate of candidates) {
22929
+ try {
22930
+ const packageJson = JSON.parse((0, import_node_fs2.readFileSync)(candidate, "utf8"));
22931
+ if (packageJson.name === "@postman-cse/onboarding-insights" && packageJson.version) {
22932
+ return String(packageJson.version).trim();
22933
+ }
22934
+ } catch {
22879
22935
  }
22880
22936
  }
22881
- return void 0;
22937
+ return resolveActionVersion2();
22882
22938
  }
22883
- function normalizeCliFlag(name) {
22884
- return `INPUT_${name.replace(/-/g, "_").toUpperCase()}`;
22939
+ function renderHelp() {
22940
+ const inputFlags = INPUT_NAMES.map((name) => ` --${name} <value>`).join("\n");
22941
+ return [
22942
+ "Usage: postman-insights-onboard [options]",
22943
+ "",
22944
+ "Options:",
22945
+ inputFlags,
22946
+ " --result-json <path> Optional JSON output file (opt-in)",
22947
+ " --dotenv-path <path> Optional dotenv output file",
22948
+ " --help Show this help and exit",
22949
+ " --version Print version and exit",
22950
+ ""
22951
+ ].join("\n");
22885
22952
  }
22886
22953
  function parseCliArgs(argv, env = process.env) {
22887
- const inputNames = [
22888
- "project-name",
22889
- "workspace-id",
22890
- "environment-id",
22891
- "system-environment-id",
22892
- "cluster-name",
22893
- "repo-url",
22894
- "postman-access-token",
22895
- "postman-api-key",
22896
- "credential-preflight",
22897
- "postman-team-id",
22898
- "github-token",
22899
- "poll-timeout-seconds",
22900
- "poll-interval-seconds",
22901
- "postman-region",
22902
- "postman-stack"
22903
- ];
22954
+ if (argv.includes("--help") || argv.includes("-h")) {
22955
+ return { kind: "help" };
22956
+ }
22957
+ if (argv.includes("--version") || argv.includes("-V")) {
22958
+ return { kind: "version" };
22959
+ }
22960
+ const allowed = /* @__PURE__ */ new Set([...INPUT_NAMES, ...OUTPUT_OPTION_NAMES]);
22961
+ const seen = /* @__PURE__ */ new Set();
22904
22962
  const inputEnv = { ...env };
22905
- for (const name of inputNames) {
22906
- const value = readFlag(argv, name);
22907
- if (value !== void 0) {
22908
- inputEnv[normalizeCliFlag(name)] = value;
22963
+ let resultJsonPath;
22964
+ let dotenvPath;
22965
+ for (let index = 0; index < argv.length; index += 1) {
22966
+ const arg = argv[index];
22967
+ if (!arg) {
22968
+ continue;
22969
+ }
22970
+ if (!arg.startsWith("--")) {
22971
+ throw new Error(`Unexpected positional argument: ${arg}`);
22972
+ }
22973
+ const equalsIndex = arg.indexOf("=");
22974
+ const name = equalsIndex >= 0 ? arg.slice(2, equalsIndex) : arg.slice(2);
22975
+ if (!allowed.has(name)) {
22976
+ throw new Error(`Unknown option: --${name}`);
22977
+ }
22978
+ if (seen.has(name)) {
22979
+ throw new Error(`Duplicate option: --${name}`);
22980
+ }
22981
+ let value;
22982
+ if (equalsIndex >= 0) {
22983
+ value = arg.slice(equalsIndex + 1);
22984
+ } else {
22985
+ const next = argv[index + 1];
22986
+ if (next === void 0 || next.startsWith("--")) {
22987
+ throw new Error(`Missing value for --${name}`);
22988
+ }
22989
+ value = next;
22990
+ index += 1;
22991
+ }
22992
+ if (value.length === 0) {
22993
+ throw new Error(`Missing value for --${name}`);
22994
+ }
22995
+ seen.add(name);
22996
+ if (name === "result-json") {
22997
+ resultJsonPath = value;
22998
+ continue;
22909
22999
  }
23000
+ if (name === "dotenv-path") {
23001
+ dotenvPath = value;
23002
+ continue;
23003
+ }
23004
+ const normalizedName = normalizedInputEnvName(name);
23005
+ delete inputEnv[runnerInputEnvName(name)];
23006
+ delete inputEnv[normalizedName];
23007
+ inputEnv[normalizedName] = value;
22910
23008
  }
22911
23009
  return {
23010
+ kind: "run",
22912
23011
  inputEnv,
22913
- resultJsonPath: readFlag(argv, "result-json") ?? "postman-insights-onboarding-result.json",
22914
- dotenvPath: readFlag(argv, "dotenv-path")
23012
+ resultJsonPath,
23013
+ dotenvPath
22915
23014
  };
22916
23015
  }
22917
23016
  function toDotenv(outputs) {
@@ -22920,18 +23019,63 @@ function toDotenv(outputs) {
22920
23019
  value
22921
23020
  ]).map(([key, value]) => `${key}=${JSON.stringify(value)}`).join("\n");
22922
23021
  }
22923
- async function writeOptionalFile(filePath, content) {
23022
+ function assertWithinWorkspace(workspaceRoot, resolved, filePath) {
23023
+ const relative2 = import_node_path2.default.relative(workspaceRoot, resolved);
23024
+ if (relative2 === ".." || relative2.startsWith(`..${import_node_path2.default.sep}`) || import_node_path2.default.isAbsolute(relative2)) {
23025
+ throw new Error(`Output path must stay within workspace: ${filePath}`);
23026
+ }
23027
+ }
23028
+ async function findExistingAncestor(candidate) {
23029
+ let current = candidate;
23030
+ while (true) {
23031
+ try {
23032
+ return await (0, import_promises.realpath)(current);
23033
+ } catch (error2) {
23034
+ if (error2.code !== "ENOENT") {
23035
+ throw error2;
23036
+ }
23037
+ const parent = import_node_path2.default.dirname(current);
23038
+ if (parent === current) {
23039
+ throw error2;
23040
+ }
23041
+ current = parent;
23042
+ }
23043
+ }
23044
+ }
23045
+ async function validateOutputPath(filePath) {
22924
23046
  if (!filePath) {
22925
23047
  return;
22926
23048
  }
22927
- const workspaceRoot = import_node_path2.default.resolve(process.cwd());
23049
+ const workspaceRoot = await (0, import_promises.realpath)(process.cwd());
22928
23050
  const resolved = import_node_path2.default.resolve(workspaceRoot, filePath);
22929
- const relative2 = import_node_path2.default.relative(workspaceRoot, resolved);
22930
- if (relative2.startsWith("..") || import_node_path2.default.isAbsolute(relative2)) {
22931
- throw new Error(`Output path must stay within workspace: ${filePath}`);
22932
- }
23051
+ assertWithinWorkspace(workspaceRoot, resolved, filePath);
23052
+ const existingParent = await findExistingAncestor(import_node_path2.default.dirname(resolved));
23053
+ assertWithinWorkspace(workspaceRoot, existingParent, filePath);
23054
+ }
23055
+ async function writeAtomicFile(filePath, content) {
23056
+ const workspaceRoot = await (0, import_promises.realpath)(process.cwd());
23057
+ const resolved = import_node_path2.default.resolve(workspaceRoot, filePath);
23058
+ assertWithinWorkspace(workspaceRoot, resolved, filePath);
22933
23059
  await (0, import_promises.mkdir)(import_node_path2.default.dirname(resolved), { recursive: true });
22934
- await (0, import_promises.writeFile)(resolved, content, "utf8");
23060
+ const resolvedParent = await (0, import_promises.realpath)(import_node_path2.default.dirname(resolved));
23061
+ assertWithinWorkspace(workspaceRoot, resolvedParent, filePath);
23062
+ const safeTarget = import_node_path2.default.join(resolvedParent, import_node_path2.default.basename(resolved));
23063
+ const tempPath = import_node_path2.default.join(
23064
+ resolvedParent,
23065
+ `.${import_node_path2.default.basename(resolved)}.${process.pid}.${(0, import_node_crypto2.randomUUID)()}.tmp`
23066
+ );
23067
+ try {
23068
+ await (0, import_promises.writeFile)(tempPath, content, { encoding: "utf8", flag: "wx", mode: 384 });
23069
+ await (0, import_promises.rename)(tempPath, safeTarget);
23070
+ } finally {
23071
+ await (0, import_promises.rm)(tempPath, { force: true });
23072
+ }
23073
+ }
23074
+ async function writeOptionalFile(filePath, content) {
23075
+ if (!filePath) {
23076
+ return;
23077
+ }
23078
+ await writeAtomicFile(filePath, content);
22935
23079
  }
22936
23080
  function toOutputs(result) {
22937
23081
  return {
@@ -22945,7 +23089,20 @@ function toOutputs(result) {
22945
23089
  }
22946
23090
  async function runCli(argv = process.argv.slice(2), runtime = {}) {
22947
23091
  const env = runtime.env ?? process.env;
22948
- const config = parseCliArgs(argv, env);
23092
+ const writeStdout = runtime.writeStdout ?? ((chunk) => process.stdout.write(chunk));
23093
+ const parsed = parseCliArgs(argv, env);
23094
+ if (parsed.kind === "help") {
23095
+ writeStdout(renderHelp());
23096
+ return;
23097
+ }
23098
+ if (parsed.kind === "version") {
23099
+ writeStdout(`${resolvePackageVersion()}
23100
+ `);
23101
+ return;
23102
+ }
23103
+ const config = parsed;
23104
+ await validateOutputPath(config.resultJsonPath);
23105
+ await validateOutputPath(config.dotenvPath);
22949
23106
  const inputs = resolveInputs(config.inputEnv);
22950
23107
  const reporter = new ConsoleReporter();
22951
23108
  const mintHolder = {
@@ -23014,7 +23171,6 @@ async function runCli(argv = process.argv.slice(2), runtime = {}) {
23014
23171
  const jsonOutput = JSON.stringify(outputs, null, 2);
23015
23172
  await writeOptionalFile(config.resultJsonPath, jsonOutput);
23016
23173
  await writeOptionalFile(config.dotenvPath, toDotenv(outputs));
23017
- const writeStdout = runtime.writeStdout ?? ((chunk) => process.stdout.write(chunk));
23018
23174
  writeStdout(`${jsonOutput}
23019
23175
  `);
23020
23176
  }
package/dist/index.cjs CHANGED
@@ -18685,6 +18685,7 @@ __export(index_exports, {
18685
18685
  createInsightsBifrostClient: () => createInsightsBifrostClient,
18686
18686
  createInsightsTokenProvider: () => createInsightsTokenProvider,
18687
18687
  createPlannedOutputs: () => createPlannedOutputs,
18688
+ getInput: () => getInput2,
18688
18689
  getTeams: () => getTeams,
18689
18690
  parsePreflightMode: () => parsePreflightMode,
18690
18691
  resolveApiKeyAndTeamId: () => resolveApiKeyAndTeamId,
@@ -22169,6 +22170,35 @@ function getFinalServiceSegment(serviceName) {
22169
22170
  return lastSlash === -1 ? serviceName : serviceName.slice(lastSlash + 1);
22170
22171
  }
22171
22172
 
22173
+ // src/lib/input.ts
22174
+ function normalizeInputValue(value) {
22175
+ return String(value ?? "").trim();
22176
+ }
22177
+ function runnerInputEnvName(name) {
22178
+ return `INPUT_${name.replace(/ /g, "_").toUpperCase()}`;
22179
+ }
22180
+ function normalizedInputEnvName(name) {
22181
+ return `INPUT_${name.replace(/-/g, "_").toUpperCase()}`;
22182
+ }
22183
+ function getInput2(name, env = process.env) {
22184
+ const normalizedName = normalizedInputEnvName(name);
22185
+ const runnerName = runnerInputEnvName(name);
22186
+ const normalizedRaw = env[normalizedName];
22187
+ const runnerRaw = runnerName === normalizedName ? void 0 : env[runnerName];
22188
+ const hasNormalized = normalizedRaw !== void 0;
22189
+ const hasRunner = runnerRaw !== void 0;
22190
+ if (hasNormalized && hasRunner) {
22191
+ const normalizedValue = normalizeInputValue(normalizedRaw);
22192
+ const runnerValue = normalizeInputValue(runnerRaw);
22193
+ if (normalizedValue !== runnerValue) {
22194
+ throw new Error(
22195
+ `Conflicting values for ${name}: ${normalizedName}=${JSON.stringify(normalizedValue)} vs ${runnerName}=${JSON.stringify(runnerValue)}`
22196
+ );
22197
+ }
22198
+ }
22199
+ return normalizeInputValue(hasNormalized ? normalizedRaw : runnerRaw);
22200
+ }
22201
+
22172
22202
  // node_modules/@postman-cse/automation-telemetry-core/dist/ci-context.js
22173
22203
  function norm(value) {
22174
22204
  const trimmed = (value ?? "").trim();
@@ -22618,7 +22648,7 @@ function clamp(value, min, max, fallback) {
22618
22648
  return Math.min(max, Math.max(min, parsed));
22619
22649
  }
22620
22650
  function resolveInputs(env = process.env) {
22621
- const get = (name, fallback = "") => env[`INPUT_${name.toUpperCase().replace(/-/g, "_")}`]?.trim() || fallback;
22651
+ const get = (name, fallback = "") => getInput2(name, env) || fallback;
22622
22652
  const projectName = get("project-name");
22623
22653
  if (!projectName) throw new Error("project-name is required");
22624
22654
  const postmanAccessToken = get("postman-access-token");
@@ -22936,6 +22966,7 @@ async function runAction() {
22936
22966
  createInsightsBifrostClient,
22937
22967
  createInsightsTokenProvider,
22938
22968
  createPlannedOutputs,
22969
+ getInput,
22939
22970
  getTeams,
22940
22971
  parsePreflightMode,
22941
22972
  resolveApiKeyAndTeamId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@postman-cse/onboarding-insights",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "GitHub Action to onboard Postman Insights discovered services to API Catalog workspaces.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -16,7 +16,7 @@
16
16
  },
17
17
  "scripts": {
18
18
  "prepare": "git config core.hooksPath .githooks",
19
- "build": "npm run typecheck && rm -rf dist && esbuild src/index.ts --bundle --platform=node --target=node24 --format=cjs --outfile=dist/index.cjs && esbuild src/main.ts --bundle --platform=node --target=node24 --format=cjs --outfile=dist/action.cjs && esbuild src/cli.ts --bundle --platform=node --target=node24 --format=cjs --outfile=dist/cli.cjs",
19
+ "build": "npm run typecheck && rm -rf dist && esbuild src/index.ts --bundle --platform=node --target=node24 --format=cjs --outfile=dist/index.cjs && esbuild src/main.ts --bundle --platform=node --target=node24 --format=cjs --outfile=dist/action.cjs && esbuild src/cli.ts --bundle --platform=node --target=node24 --format=cjs --banner:js='#!/usr/bin/env node' --outfile=dist/cli.cjs && chmod +x dist/cli.cjs",
20
20
  "verify:dist": "npm run build && git diff --ignore-space-at-eol --text --exit-code -- dist",
21
21
  "docs:tables": "node scripts/render-action-tables.mjs --write",
22
22
  "lint": "eslint .",