@postman-cse/onboarding-bootstrap 0.14.2 → 0.15.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/dist/index.cjs CHANGED
@@ -46792,6 +46792,12 @@ var customerPreviewActionContract = {
46792
46792
  description: "Postman access token used for governance and workspace mutations.",
46793
46793
  required: false
46794
46794
  },
46795
+ "credential-preflight": {
46796
+ description: "Credential identity preflight policy. warn (default) logs a note and continues when postman-api-key and postman-access-token resolve to different parent orgs; enforce fails the run on that condition before any workspace is created; off skips the identity probes entirely (the reactive error guidance still applies). Promotion of the default to enforce is planned once the live e2e legs prove both directions.",
46797
+ required: false,
46798
+ default: "warn",
46799
+ allowedValues: ["enforce", "warn", "off"]
46800
+ },
46795
46801
  "integration-backend": {
46796
46802
  description: "Integration backend for downstream workspace connectivity.",
46797
46803
  required: false,
@@ -47815,13 +47821,15 @@ var POSTMAN_ENDPOINT_PROFILES = {
47815
47821
  apiBaseUrl: "https://api.getpostman.com",
47816
47822
  bifrostBaseUrl: "https://bifrost-premium-https-v4.gw.postman.com",
47817
47823
  cliInstallUrl: "https://dl-cli.pstmn.io/install/unix.sh",
47818
- gatewayBaseUrl: "https://gateway.postman.com"
47824
+ gatewayBaseUrl: "https://gateway.postman.com",
47825
+ iapubBaseUrl: "https://iapub.postman.co"
47819
47826
  },
47820
47827
  beta: {
47821
47828
  apiBaseUrl: "https://api.getpostman-beta.com",
47822
47829
  bifrostBaseUrl: "https://bifrost-https-v4.gw.postman-beta.com",
47823
47830
  cliInstallUrl: "https://dl-cli.pstmn-beta.io/install/unix.sh",
47824
- gatewayBaseUrl: "https://gateway.postman-beta.com"
47831
+ gatewayBaseUrl: "https://gateway.postman-beta.com",
47832
+ iapubBaseUrl: "https://iapub.postman.co"
47825
47833
  }
47826
47834
  };
47827
47835
  function parsePostmanStack(value) {
@@ -47835,6 +47843,311 @@ function resolvePostmanEndpointProfile(stack) {
47835
47843
  return POSTMAN_ENDPOINT_PROFILES[stack];
47836
47844
  }
47837
47845
 
47846
+ // src/lib/postman/credential-identity.ts
47847
+ var sessionPath = "/api/sessions/current";
47848
+ var pmakMemo = /* @__PURE__ */ new Map();
47849
+ var sessionMemo = /* @__PURE__ */ new Map();
47850
+ var memoizedSessionIdentity;
47851
+ function getMemoizedSessionIdentity() {
47852
+ return memoizedSessionIdentity;
47853
+ }
47854
+ function asRecord(value) {
47855
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
47856
+ return void 0;
47857
+ }
47858
+ return value;
47859
+ }
47860
+ function coerceId(raw) {
47861
+ return raw ? String(raw) : void 0;
47862
+ }
47863
+ function coerceText(raw) {
47864
+ if (typeof raw !== "string") {
47865
+ return void 0;
47866
+ }
47867
+ const trimmed = raw.trim();
47868
+ return trimmed ? trimmed : void 0;
47869
+ }
47870
+ function normalizeBaseUrl(raw) {
47871
+ return String(raw || "").replace(/\/+$/, "");
47872
+ }
47873
+ async function resolvePmakIdentity(opts) {
47874
+ const apiKey = String(opts.apiKey || "").trim();
47875
+ if (!apiKey) {
47876
+ return void 0;
47877
+ }
47878
+ const baseUrl = normalizeBaseUrl(opts.apiBaseUrl);
47879
+ const memoKey = `${baseUrl}::${apiKey}`;
47880
+ let pending = pmakMemo.get(memoKey);
47881
+ if (!pending) {
47882
+ pending = probePmakIdentity(baseUrl, apiKey, opts.fetchImpl ?? fetch);
47883
+ pmakMemo.set(memoKey, pending);
47884
+ }
47885
+ return pending;
47886
+ }
47887
+ async function probePmakIdentity(baseUrl, apiKey, fetchImpl) {
47888
+ try {
47889
+ const response = await fetchImpl(`${baseUrl}/me`, {
47890
+ method: "GET",
47891
+ headers: { "X-Api-Key": apiKey }
47892
+ });
47893
+ if (!response.ok) {
47894
+ return void 0;
47895
+ }
47896
+ const payload = asRecord(await response.json());
47897
+ const user = asRecord(payload?.user);
47898
+ if (!user) {
47899
+ return void 0;
47900
+ }
47901
+ return {
47902
+ source: "pmak/me",
47903
+ userId: coerceId(user.id),
47904
+ fullName: coerceText(user.fullName) ?? coerceText(user.username),
47905
+ teamId: coerceId(user.teamId),
47906
+ teamName: coerceText(user.teamName),
47907
+ teamDomain: coerceText(user.teamDomain)
47908
+ };
47909
+ } catch {
47910
+ return void 0;
47911
+ }
47912
+ }
47913
+ async function resolveSessionIdentity(opts) {
47914
+ const accessToken = String(opts.accessToken || "").trim();
47915
+ if (!accessToken) {
47916
+ return void 0;
47917
+ }
47918
+ const baseUrl = normalizeBaseUrl(opts.iapubBaseUrl);
47919
+ const memoKey = `${baseUrl}::${accessToken}`;
47920
+ let pending = sessionMemo.get(memoKey);
47921
+ if (!pending) {
47922
+ pending = probeSessionIdentity(baseUrl, accessToken, opts.fetchImpl ?? fetch);
47923
+ sessionMemo.set(memoKey, pending);
47924
+ }
47925
+ return pending;
47926
+ }
47927
+ async function probeSessionIdentity(baseUrl, accessToken, fetchImpl) {
47928
+ try {
47929
+ const response = await fetchImpl(`${baseUrl}${sessionPath}`, {
47930
+ method: "GET",
47931
+ headers: { "x-access-token": accessToken }
47932
+ });
47933
+ if (!response.ok) {
47934
+ return void 0;
47935
+ }
47936
+ const payload = asRecord(await response.json());
47937
+ if (!payload) {
47938
+ return void 0;
47939
+ }
47940
+ const identity = asRecord(payload.identity);
47941
+ const data = asRecord(payload.data);
47942
+ const user = asRecord(data?.user);
47943
+ const roleEntries = Array.isArray(user?.roles) ? user.roles.map((entry) => coerceText(entry) ?? coerceId(entry)).filter((entry) => Boolean(entry)) : [];
47944
+ const singleRole = coerceText(user?.role);
47945
+ const roles = roleEntries.length > 0 ? roleEntries : singleRole ? [singleRole] : void 0;
47946
+ const resolved = {
47947
+ source: "iapub/sessions",
47948
+ userId: coerceId(user?.id),
47949
+ fullName: coerceText(user?.fullName) ?? coerceText(user?.name) ?? coerceText(user?.username),
47950
+ teamId: coerceId(identity?.team),
47951
+ teamDomain: coerceText(identity?.domain),
47952
+ ...roles ? { roles } : {},
47953
+ consumerType: coerceText(payload.consumerType) ?? coerceText(data?.consumerType) ?? coerceText(user?.consumerType)
47954
+ };
47955
+ memoizedSessionIdentity = resolved;
47956
+ return resolved;
47957
+ } catch {
47958
+ return void 0;
47959
+ }
47960
+ }
47961
+ function describeTeam(id) {
47962
+ const label = id?.teamName ?? id?.teamDomain;
47963
+ return `team ${id?.teamId ?? "unresolved"}${label ? ` (${label})` : ""}`;
47964
+ }
47965
+ function formatIdentityLine(id, mask) {
47966
+ const teamPart = id.teamId ? describeTeam(id) : "team unresolved";
47967
+ const domainPart = id.teamDomain ? `, domain ${id.teamDomain}` : "";
47968
+ if (id.source === "pmak/me") {
47969
+ const userPart = id.userId ? `user ${id.userId}${id.fullName ? ` (${id.fullName})` : ""}, ` : "";
47970
+ return mask(`postman: PMAK identity - ${userPart}${teamPart}${domainPart}`);
47971
+ }
47972
+ return mask(
47973
+ `postman: access-token session identity - ${teamPart}${domainPart} [source: iapub/sessions]`
47974
+ );
47975
+ }
47976
+ function crossCheckIdentities(args) {
47977
+ if (args.mode === "off") {
47978
+ return { ok: true, level: "ok", message: "" };
47979
+ }
47980
+ const pmakTeamId = args.pmak?.teamId;
47981
+ const sessionTeamId = args.session?.teamId;
47982
+ if (pmakTeamId && sessionTeamId && pmakTeamId !== sessionTeamId) {
47983
+ const level = args.mode === "enforce" ? "fail" : "note";
47984
+ const lead = level === "fail" ? "credential preflight FAILED" : "credential preflight note";
47985
+ const fix = level === "fail" ? "Use one credential pair from a single parent org: re-mint the access token from the same parent org as postman-api-key (postman-resolve-service-token-action, or POST https://api.getpostman.com/service-account-tokens with that team's PMAK), or set postman-api-key to the matching parent org." : "Use one credential pair from a single parent org. Set credential-preflight: enforce to fail the run on this condition.";
47986
+ return {
47987
+ ok: false,
47988
+ level,
47989
+ message: args.mask(
47990
+ `postman: ${lead} - PMAK belongs to ${describeTeam(args.pmak)} but the access token's session belongs to a different parent org, ${describeTeam(args.session)}. Assets would be created against one team while Bifrost linking and governance act under the other, producing duplicate-link 400s and workspaces not visible to the other credential. ` + fix
47991
+ )
47992
+ };
47993
+ }
47994
+ if (pmakTeamId && sessionTeamId) {
47995
+ const scope = args.workspaceTeamId || args.explicitTeamId ? "parent org team" : "team";
47996
+ const label = args.pmak?.teamName ?? args.pmak?.teamDomain ?? args.session?.teamName ?? args.session?.teamDomain;
47997
+ return {
47998
+ ok: true,
47999
+ level: "ok",
48000
+ message: args.mask(
48001
+ `postman: credential preflight OK - PMAK and access token both resolve to ${scope} ${pmakTeamId}${label ? ` (${label})` : ""}`
48002
+ )
48003
+ };
48004
+ }
48005
+ const missing = [
48006
+ !pmakTeamId ? "PMAK identity" : void 0,
48007
+ !sessionTeamId ? "access-token session identity" : void 0
48008
+ ].filter(Boolean).join(" and ");
48009
+ return {
48010
+ ok: false,
48011
+ level: "note",
48012
+ message: args.mask(
48013
+ `postman: credential preflight note - cross-check skipped because the ${missing} did not resolve a team id; continuing with reactive error guidance only`
48014
+ )
48015
+ };
48016
+ }
48017
+ async function runCredentialPreflight(args) {
48018
+ if (args.mode === "off") {
48019
+ return;
48020
+ }
48021
+ const mask = args.mask;
48022
+ const apiKey = String(args.postmanApiKey || "").trim();
48023
+ const accessToken = String(args.postmanAccessToken || "").trim();
48024
+ let pmak;
48025
+ if (apiKey) {
48026
+ try {
48027
+ pmak = await resolvePmakIdentity({
48028
+ apiBaseUrl: args.apiBaseUrl,
48029
+ apiKey,
48030
+ fetchImpl: args.fetchImpl
48031
+ });
48032
+ } catch (error2) {
48033
+ args.log.warning(
48034
+ mask(
48035
+ `postman: credential preflight could not resolve PMAK identity: ${error2 instanceof Error ? error2.message : String(error2)}`
48036
+ )
48037
+ );
48038
+ }
48039
+ if (pmak) {
48040
+ args.log.info(formatIdentityLine(pmak, mask));
48041
+ } else {
48042
+ args.log.warning(
48043
+ mask("postman: credential preflight could not resolve PMAK identity from GET /me; continuing")
48044
+ );
48045
+ }
48046
+ }
48047
+ if (!accessToken) {
48048
+ args.log.info(mask("postman: Bifrost diagnostics limited: no access token"));
48049
+ return;
48050
+ }
48051
+ let session;
48052
+ try {
48053
+ session = await resolveSessionIdentity({
48054
+ iapubBaseUrl: args.iapubBaseUrl,
48055
+ accessToken,
48056
+ fetchImpl: args.fetchImpl
48057
+ });
48058
+ } catch (error2) {
48059
+ args.log.warning(
48060
+ mask(
48061
+ `postman: credential preflight could not resolve access-token session identity: ${error2 instanceof Error ? error2.message : String(error2)}`
48062
+ )
48063
+ );
48064
+ }
48065
+ if (session) {
48066
+ args.log.info(formatIdentityLine(session, mask));
48067
+ } else {
48068
+ args.log.warning(
48069
+ mask(
48070
+ "postman: credential preflight could not resolve the access-token session identity from iapub; continuing with reactive error guidance only"
48071
+ )
48072
+ );
48073
+ }
48074
+ const result = crossCheckIdentities({
48075
+ pmak,
48076
+ session,
48077
+ workspaceTeamId: args.workspaceTeamId,
48078
+ explicitTeamId: args.explicitTeamId,
48079
+ mode: args.mode,
48080
+ mask
48081
+ });
48082
+ if (!result.message) {
48083
+ return;
48084
+ }
48085
+ if (result.level === "fail") {
48086
+ throw new Error(result.message);
48087
+ }
48088
+ if (result.level === "note") {
48089
+ args.log.warning(result.message);
48090
+ return;
48091
+ }
48092
+ args.log.info(result.message);
48093
+ }
48094
+
48095
+ // src/lib/postman/error-advice.ts
48096
+ var WORKSPACE_PERSONAL_ONLY_ADVICE = "Workspace creation failed: This may be an Org-mode account that requires a workspace-team-id input. The Postman API does not allow creating team workspaces at the organization level. Use the workspace-team-id input to specify which sub-team should own this workspace.";
48097
+ function workspaceTeamIdUnauthorizedAdvice(targetTeamId) {
48098
+ return `The workspace-team-id input (${targetTeamId}) was rejected as unauthorized by the Postman API. In org-mode accounts it must be the numeric id of a sub-team this API key can access; GET https://api.getpostman.com/teams lists the available sub-teams. Fix the workspace-team-id value and re-run.`;
48099
+ }
48100
+ function adviseFromWorkspaceCreateError(err, targetTeamId) {
48101
+ if (err.message.includes("Only personal workspaces")) {
48102
+ return new Error(WORKSPACE_PERSONAL_ONLY_ADVICE, { cause: err });
48103
+ }
48104
+ if (targetTeamId != null && err.message.includes("You are not authorized to perform this action")) {
48105
+ return new Error(workspaceTeamIdUnauthorizedAdvice(targetTeamId), { cause: err });
48106
+ }
48107
+ return void 0;
48108
+ }
48109
+ function expiryAdvice(code) {
48110
+ return `postman: Bifrost rejected the access token (${code}). Service-account access tokens expire after about 1 to 1.5 hours; this run likely outlived its token. Re-mint a fresh token (postman-resolve-service-token-action, or POST https://api.getpostman.com/service-account-tokens) and re-run. If it was just minted, confirm postman-access-token is the token for the same parent org as postman-api-key.`;
48111
+ }
48112
+ function forbiddenAdvice(ctx) {
48113
+ const sessionDetail = ctx.sessionTeamId ? ` while the access token is valid (it resolved to team ${ctx.sessionTeamId}${ctx.sessionRoles && ctx.sessionRoles.length > 0 ? `, roles [${ctx.sessionRoles.join(", ")}]` : ""}${ctx.sessionConsumerType ? `, consumerType ${ctx.sessionConsumerType}` : ""} at preflight)` : "";
48114
+ const scopedTeamId = ctx.workspaceTeamId || ctx.explicitTeamId;
48115
+ const teamClause = scopedTeamId ? `, or workspace-team-id ${scopedTeamId} names a sub-team it cannot act in` : ", or the workspace-team-id / POSTMAN_TEAM_ID in use names a sub-team it cannot act in";
48116
+ return `postman: Bifrost refused ${ctx.operation || "this operation"} with 403${sessionDetail}. The token's identity lacks permission for this endpoint${teamClause}. Verify the token's role and that workspace-team-id / POSTMAN_TEAM_ID matches a sub-team from GET https://api.getpostman.com/teams.`;
48117
+ }
48118
+ function buildAdvice(status, body, ctx) {
48119
+ if (body.includes("UNAUTHENTICATED")) {
48120
+ return expiryAdvice("UNAUTHENTICATED");
48121
+ }
48122
+ if (body.includes("authenticationError")) {
48123
+ return expiryAdvice("authenticationError");
48124
+ }
48125
+ if (body.includes("Only personal workspaces")) {
48126
+ return WORKSPACE_PERSONAL_ONLY_ADVICE;
48127
+ }
48128
+ if (body.includes("projectAlreadyConnected")) {
48129
+ return `postman: ${ctx.operation || "this operation"} reports projectAlreadyConnected with no workspace id in the error body. The repository is already linked to a workspace this credential cannot see, usually one created by a different credential pair or sub-team. Delete the stale link or its workspace, then re-run with one credential pair from a single parent org.`;
48130
+ }
48131
+ if (body.includes("invalidParamError") && body.includes("already exists")) {
48132
+ return `postman: ${ctx.operation || "this operation"} hit a duplicate resource error (invalidParamError: already exists). A matching resource already exists, possibly under another credential pair or sub-team where this credential cannot see it. Identify which workspace holds the existing resource and re-run with one credential pair from a single parent org.`;
48133
+ }
48134
+ if (body.includes("Team feature is not available for your organization")) {
48135
+ return `postman: ${ctx.operation || "this operation"} failed because the team feature is not available for this organization. The credential belongs to an account whose plan lacks team features; use credentials from the intended team and confirm the plan supports this operation.`;
48136
+ }
48137
+ if (body.includes("You are not authorized to perform this action") || status === 403 && ctx.hasAccessToken) {
48138
+ return forbiddenAdvice(ctx);
48139
+ }
48140
+ return void 0;
48141
+ }
48142
+ function adviseFromHttpError(err, ctx) {
48143
+ const body = err.responseBody || err.message || "";
48144
+ const advice = buildAdvice(err.status, body, ctx);
48145
+ if (!advice) {
48146
+ return void 0;
48147
+ }
48148
+ return new Error(ctx.mask(advice), { cause: err });
48149
+ }
48150
+
47838
48151
  // src/lib/retry.ts
47839
48152
  function sleep(delayMs) {
47840
48153
  return new Promise((resolve4) => {
@@ -47883,7 +48196,7 @@ async function retry(operation, options = {}) {
47883
48196
  }
47884
48197
 
47885
48198
  // src/lib/postman/postman-assets-client.ts
47886
- function asRecord(value) {
48199
+ function asRecord2(value) {
47887
48200
  if (!value || typeof value !== "object" || Array.isArray(value)) {
47888
48201
  return null;
47889
48202
  }
@@ -47891,8 +48204,8 @@ function asRecord(value) {
47891
48204
  }
47892
48205
  function extractWorkspacesPage(data) {
47893
48206
  const workspaces = Array.isArray(data?.workspaces) ? data.workspaces : [];
47894
- const meta = asRecord(data?.meta);
47895
- const pagination = asRecord(data?.pagination);
48207
+ const meta = asRecord2(data?.meta);
48208
+ const pagination = asRecord2(data?.pagination);
47896
48209
  const nextCursor = String(
47897
48210
  data?.nextCursor ?? data?.next_cursor ?? meta?.nextCursor ?? meta?.next_cursor ?? pagination?.nextCursor ?? pagination?.next_cursor ?? ""
47898
48211
  ).trim() || void 0;
@@ -47984,7 +48297,7 @@ var PostmanAssetsClient = class {
47984
48297
  async getTeams() {
47985
48298
  const data = await this.request("/teams");
47986
48299
  const teams = data?.data ?? [];
47987
- return Array.isArray(teams) ? teams.map((entry) => asRecord(entry)).filter((team) => Boolean(team?.id && team?.name)).map((team) => ({
48300
+ return Array.isArray(teams) ? teams.map((entry) => asRecord2(entry)).filter((team) => Boolean(team?.id && team?.name)).map((team) => ({
47988
48301
  id: Number(team.id),
47989
48302
  name: String(team.name),
47990
48303
  handle: String(team.handle || ""),
@@ -48036,34 +48349,28 @@ var PostmanAssetsClient = class {
48036
48349
  body: JSON.stringify(payload)
48037
48350
  });
48038
48351
  } catch (err) {
48039
- if (err instanceof Error && err.message.includes("Only personal workspaces")) {
48040
- throw new Error(
48041
- "Workspace creation failed: This may be an Org-mode account that requires a workspace-team-id input. The Postman API does not allow creating team workspaces at the organization level. Use the workspace-team-id input to specify which sub-team should own this workspace.",
48042
- { cause: err }
48043
- );
48044
- }
48045
- if (targetTeamId != null && err instanceof Error && err.message.includes("You are not authorized to perform this action")) {
48046
- throw new Error(
48047
- `The workspace-team-id input (${targetTeamId}) was rejected as unauthorized by the Postman API. In org-mode accounts it must be the numeric id of a sub-team this API key can access; GET https://api.getpostman.com/teams lists the available sub-teams. Fix the workspace-team-id value and re-run.`,
48048
- { cause: err }
48049
- );
48352
+ if (err instanceof Error) {
48353
+ const advised = adviseFromWorkspaceCreateError(err, targetTeamId);
48354
+ if (advised) {
48355
+ throw advised;
48356
+ }
48050
48357
  }
48051
48358
  throw err;
48052
48359
  }
48053
- const createdWorkspace = asRecord(created?.workspace);
48360
+ const createdWorkspace = asRecord2(created?.workspace);
48054
48361
  const workspaceId = String(createdWorkspace?.id || "").trim();
48055
48362
  if (!workspaceId) {
48056
48363
  throw new Error("Workspace create did not return an id");
48057
48364
  }
48058
48365
  const workspace = await this.request(`/workspaces/${workspaceId}`);
48059
- let visibility = asRecord(workspace?.workspace)?.visibility;
48366
+ let visibility = asRecord2(workspace?.workspace)?.visibility;
48060
48367
  if (visibility !== "team") {
48061
48368
  await this.request(`/workspaces/${workspaceId}`, {
48062
48369
  method: "PUT",
48063
48370
  body: JSON.stringify(payload)
48064
48371
  });
48065
48372
  const reread = await this.request(`/workspaces/${workspaceId}`);
48066
- visibility = asRecord(reread?.workspace)?.visibility;
48373
+ visibility = asRecord2(reread?.workspace)?.visibility;
48067
48374
  }
48068
48375
  if (typeof visibility === "string" && visibility !== "team") {
48069
48376
  let cleanedUp = false;
@@ -48092,7 +48399,7 @@ var PostmanAssetsClient = class {
48092
48399
  async getWorkspaceVisibility(workspaceId) {
48093
48400
  try {
48094
48401
  const workspace = await this.request(`/workspaces/${workspaceId}`);
48095
- const visibility = asRecord(workspace?.workspace)?.visibility;
48402
+ const visibility = asRecord2(workspace?.workspace)?.visibility;
48096
48403
  return typeof visibility === "string" ? visibility : null;
48097
48404
  } catch {
48098
48405
  return null;
@@ -48114,7 +48421,7 @@ var PostmanAssetsClient = class {
48114
48421
  nextCursor = page.nextCursor;
48115
48422
  }
48116
48423
  } while (nextCursor);
48117
- return allWorkspaces.map((entry) => asRecord(entry)).filter((workspace) => Boolean(workspace?.id && workspace?.name)).map((workspace) => ({
48424
+ return allWorkspaces.map((entry) => asRecord2(entry)).filter((workspace) => Boolean(workspace?.id && workspace?.name)).map((workspace) => ({
48118
48425
  id: String(workspace.id),
48119
48426
  name: String(workspace.name),
48120
48427
  type: String(workspace.type ?? "team")
@@ -48162,7 +48469,7 @@ var PostmanAssetsClient = class {
48162
48469
  async inviteRequesterToWorkspace(workspaceId, email) {
48163
48470
  const users = await this.request("/users");
48164
48471
  const userList = Array.isArray(users?.data) ? users.data : [];
48165
- const user = userList.map((entry) => asRecord(entry)).find((entry) => entry?.email === email);
48472
+ const user = userList.map((entry) => asRecord2(entry)).find((entry) => entry?.email === email);
48166
48473
  if (!user?.id) {
48167
48474
  return;
48168
48475
  }
@@ -48250,12 +48557,12 @@ var PostmanAssetsClient = class {
48250
48557
  }
48251
48558
  };
48252
48559
  const extractUid = (data) => {
48253
- const root = asRecord(data);
48254
- const details = asRecord(root?.details);
48560
+ const root = asRecord2(data);
48561
+ const details = asRecord2(root?.details);
48255
48562
  const resources = Array.isArray(details?.resources) ? details.resources : [];
48256
- const firstResource = asRecord(resources[0]);
48257
- const collection = asRecord(root?.collection);
48258
- const resource = asRecord(root?.resource);
48563
+ const firstResource = asRecord2(resources[0]);
48564
+ const collection = asRecord2(root?.collection);
48565
+ const resource = asRecord2(root?.resource);
48259
48566
  return String(
48260
48567
  firstResource?.id ?? collection?.id ?? collection?.uid ?? resource?.uid ?? resource?.id ?? ""
48261
48568
  ).trim() || void 0;
@@ -48289,9 +48596,9 @@ var PostmanAssetsClient = class {
48289
48596
  if (directUid) {
48290
48597
  return directUid;
48291
48598
  }
48292
- let taskUrl = String(generationResponse?.url ?? "") || String(generationResponse?.task_url ?? "") || String(generationResponse?.taskUrl ?? "") || String(asRecord(generationResponse?.links)?.task ?? "");
48599
+ let taskUrl = String(generationResponse?.url ?? "") || String(generationResponse?.task_url ?? "") || String(generationResponse?.taskUrl ?? "") || String(asRecord2(generationResponse?.links)?.task ?? "");
48293
48600
  if (!taskUrl) {
48294
- const task = asRecord(generationResponse?.task);
48601
+ const task = asRecord2(generationResponse?.task);
48295
48602
  const taskId = generationResponse?.taskId || task?.id || generationResponse?.id;
48296
48603
  if (!taskId) {
48297
48604
  throw new Error(
@@ -48305,8 +48612,8 @@ var PostmanAssetsClient = class {
48305
48612
  setTimeout(resolve4, 2e3);
48306
48613
  });
48307
48614
  const task = await this.request(taskUrl);
48308
- const taskRecord = asRecord(task);
48309
- const taskNested = asRecord(taskRecord?.task);
48615
+ const taskRecord = asRecord2(task);
48616
+ const taskNested = asRecord2(taskRecord?.task);
48310
48617
  const status = String(taskRecord?.status || taskNested?.status || "").toLowerCase();
48311
48618
  if (status === "completed") {
48312
48619
  const taskUid = extractUid(task);
@@ -48337,7 +48644,7 @@ var PostmanAssetsClient = class {
48337
48644
  }
48338
48645
  async injectTests(collectionUid, type2) {
48339
48646
  const collectionResponse = await this.request(`/collections/${collectionUid}`);
48340
- const collection = asRecord(collectionResponse?.collection);
48647
+ const collection = asRecord2(collectionResponse?.collection);
48341
48648
  if (!collection) {
48342
48649
  throw new Error(`Failed to fetch collection ${collectionUid}`);
48343
48650
  }
@@ -48423,7 +48730,7 @@ var PostmanAssetsClient = class {
48423
48730
  });
48424
48731
  }
48425
48732
  if (Array.isArray(itemNode.item)) {
48426
- itemNode.item.map((entry) => asRecord(entry)).filter((entry) => Boolean(entry)).forEach(injectScripts);
48733
+ itemNode.item.map((entry) => asRecord2(entry)).filter((entry) => Boolean(entry)).forEach(injectScripts);
48427
48734
  }
48428
48735
  };
48429
48736
  if (Array.isArray(collection.item)) {
@@ -48451,7 +48758,7 @@ var PostmanAssetsClient = class {
48451
48758
  }
48452
48759
  })
48453
48760
  });
48454
- const environment = asRecord(response?.environment);
48761
+ const environment = asRecord2(response?.environment);
48455
48762
  const uid = String(environment?.uid || "").trim();
48456
48763
  if (!uid) {
48457
48764
  throw new Error("Environment create did not return a UID");
@@ -48484,7 +48791,7 @@ var PostmanAssetsClient = class {
48484
48791
  }
48485
48792
  })
48486
48793
  });
48487
- const monitor = asRecord(response?.monitor);
48794
+ const monitor = asRecord2(response?.monitor);
48488
48795
  const uid = String(monitor?.uid || "").trim();
48489
48796
  if (!uid) {
48490
48797
  throw new Error("Monitor create did not return a UID");
@@ -48503,8 +48810,8 @@ var PostmanAssetsClient = class {
48503
48810
  }
48504
48811
  })
48505
48812
  });
48506
- const mock = asRecord(response?.mock);
48507
- const mockConfig = asRecord(mock?.config);
48813
+ const mock = asRecord2(response?.mock);
48814
+ const mockConfig = asRecord2(mock?.config);
48508
48815
  const uid = String(mock?.uid || "").trim();
48509
48816
  if (!uid) {
48510
48817
  throw new Error("Mock create did not return a UID");
@@ -48575,6 +48882,18 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48575
48882
  this.teamId = String(teamId || "").trim();
48576
48883
  this.orgMode = orgMode;
48577
48884
  }
48885
+ adviceContext(operation) {
48886
+ const session = getMemoizedSessionIdentity();
48887
+ return {
48888
+ operation,
48889
+ hasAccessToken: Boolean(this.accessToken),
48890
+ sessionTeamId: session?.teamId,
48891
+ sessionRoles: session?.roles,
48892
+ sessionConsumerType: session?.consumerType,
48893
+ explicitTeamId: this.teamId || void 0,
48894
+ mask: this.secretMasker
48895
+ };
48896
+ }
48578
48897
  async proxyRequest(service, method, requestPath2, body, options = {}) {
48579
48898
  const url = `${this.bifrostBaseUrl}/ws/proxy`;
48580
48899
  const headers = {
@@ -48641,7 +48960,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48641
48960
  { appVersion, query: { tag: "governance" } }
48642
48961
  );
48643
48962
  if (!listResponse.ok) {
48644
- throw await HttpError.fromResponse(listResponse, {
48963
+ const httpErr = await HttpError.fromResponse(listResponse, {
48645
48964
  method: "GET",
48646
48965
  requestHeaders: {
48647
48966
  "Content-Type": "application/json",
@@ -48652,6 +48971,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48652
48971
  secretValues: [this.accessToken],
48653
48972
  url: `${this.bifrostBaseUrl}/ws/proxy`
48654
48973
  });
48974
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("governance assignment"));
48975
+ throw advised ?? httpErr;
48655
48976
  }
48656
48977
  const groups = await listResponse.json();
48657
48978
  const group2 = (groups.workspaceGroups ?? groups.data)?.find(
@@ -48677,7 +48998,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48677
48998
  { appVersion }
48678
48999
  );
48679
49000
  if (!patchResponse.ok) {
48680
- throw await HttpError.fromResponse(patchResponse, {
49001
+ const httpErr = await HttpError.fromResponse(patchResponse, {
48681
49002
  method: "PATCH",
48682
49003
  requestHeaders: {
48683
49004
  "Content-Type": "application/json",
@@ -48688,6 +49009,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48688
49009
  secretValues: [this.accessToken],
48689
49010
  url: `${this.bifrostBaseUrl}/ws/proxy`
48690
49011
  });
49012
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("governance assignment"));
49013
+ throw advised ?? httpErr;
48691
49014
  }
48692
49015
  }
48693
49016
  async connectWorkspaceToRepository(workspaceId, repoUrl) {
@@ -48721,7 +49044,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48721
49044
  );
48722
49045
  }
48723
49046
  }
48724
- throw await HttpError.fromResponse(response, {
49047
+ const httpErr = await HttpError.fromResponse(response, {
48725
49048
  method: "POST",
48726
49049
  requestHeaders: {
48727
49050
  "Content-Type": "application/json",
@@ -48731,6 +49054,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48731
49054
  secretValues: [this.accessToken],
48732
49055
  url: `${this.bifrostBaseUrl}/ws/proxy`
48733
49056
  });
49057
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("workspace repository linking"));
49058
+ throw advised ?? httpErr;
48734
49059
  }
48735
49060
  async linkCollectionsToSpecification(specificationId, collections) {
48736
49061
  if (collections.length === 0) {
@@ -48748,7 +49073,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48748
49073
  if (response.ok) {
48749
49074
  return;
48750
49075
  }
48751
- throw await HttpError.fromResponse(response, {
49076
+ const httpErr = await HttpError.fromResponse(response, {
48752
49077
  method: "POST",
48753
49078
  requestHeaders: {
48754
49079
  "Content-Type": "application/json",
@@ -48758,6 +49083,11 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48758
49083
  secretValues: [this.accessToken],
48759
49084
  url: `${this.bifrostBaseUrl}/ws/proxy`
48760
49085
  });
49086
+ const advised = adviseFromHttpError(
49087
+ httpErr,
49088
+ this.adviceContext("collection-to-specification linking")
49089
+ );
49090
+ throw advised ?? httpErr;
48761
49091
  }
48762
49092
  async syncCollection(specificationId, collectionId) {
48763
49093
  const response = await this.proxyRequest(
@@ -48768,7 +49098,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48768
49098
  if (response.ok) {
48769
49099
  return;
48770
49100
  }
48771
- throw await HttpError.fromResponse(response, {
49101
+ const httpErr = await HttpError.fromResponse(response, {
48772
49102
  method: "POST",
48773
49103
  requestHeaders: {
48774
49104
  "Content-Type": "application/json",
@@ -48778,6 +49108,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48778
49108
  secretValues: [this.accessToken],
48779
49109
  url: `${this.bifrostBaseUrl}/ws/proxy`
48780
49110
  });
49111
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("collection sync"));
49112
+ throw advised ?? httpErr;
48781
49113
  }
48782
49114
  async getWorkspaceGitRepoUrl(workspaceId) {
48783
49115
  const response = await this.proxyRequest(
@@ -49351,7 +49683,7 @@ var STRIP_KEYS = /* @__PURE__ */ new Set([
49351
49683
  "discriminator",
49352
49684
  "format"
49353
49685
  ]);
49354
- function asRecord2(value) {
49686
+ function asRecord3(value) {
49355
49687
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
49356
49688
  return value;
49357
49689
  }
@@ -49363,7 +49695,7 @@ function decodePointerSegment(segment) {
49363
49695
  }
49364
49696
  function resolvePointer(root, ref) {
49365
49697
  if (!ref.startsWith("#/")) return void 0;
49366
- return ref.slice(2).split("/").map(decodePointerSegment).reduce((node, segment) => asRecord2(node)?.[segment], root);
49698
+ return ref.slice(2).split("/").map(decodePointerSegment).reduce((node, segment) => asRecord3(node)?.[segment], root);
49367
49699
  }
49368
49700
  function unsupported(message) {
49369
49701
  return { unsupported: message };
@@ -49373,7 +49705,7 @@ function mergeRequiredWithoutWriteOnly(required, writeOnlyProperties) {
49373
49705
  return values.length > 0 ? values : void 0;
49374
49706
  }
49375
49707
  function hasUnsupported(child2) {
49376
- return asRecord2(child2)?.unsupported;
49708
+ return asRecord3(child2)?.unsupported;
49377
49709
  }
49378
49710
  function rootDialect(root, version, schemaRecord) {
49379
49711
  if (version === "3.0") return DRAFT_07_SCHEMA_URI;
@@ -49393,7 +49725,7 @@ function normalizeSchema(root, schema2, options) {
49393
49725
  const bad = normalized2.map(hasUnsupported).find(Boolean);
49394
49726
  return bad ? unsupported(bad) : normalized2;
49395
49727
  }
49396
- const record = asRecord2(schema2);
49728
+ const record = asRecord3(schema2);
49397
49729
  if (!record) return schema2;
49398
49730
  const ref = typeof record.$ref === "string" ? record.$ref : "";
49399
49731
  if (ref) {
@@ -49428,10 +49760,10 @@ function normalizeSchema(root, schema2, options) {
49428
49760
  const nullable = sourceSchema.nullable === true && options.version === "3.0";
49429
49761
  delete sourceSchema.nullable;
49430
49762
  const writeOnlyProperties = /* @__PURE__ */ new Set();
49431
- const rawProperties = asRecord2(sourceSchema.properties);
49763
+ const rawProperties = asRecord3(sourceSchema.properties);
49432
49764
  if (rawProperties) {
49433
49765
  for (const [propertyName, propertySchema] of Object.entries(rawProperties)) {
49434
- if (asRecord2(propertySchema)?.writeOnly === true) writeOnlyProperties.add(propertyName);
49766
+ if (asRecord3(propertySchema)?.writeOnly === true) writeOnlyProperties.add(propertyName);
49435
49767
  }
49436
49768
  }
49437
49769
  const normalized = {};
@@ -49463,7 +49795,7 @@ function normalizeSchema(root, schema2, options) {
49463
49795
  return unsupported("Tuple array items are unsupported in OpenAPI 3.0");
49464
49796
  }
49465
49797
  if (key === "properties") {
49466
- const properties = asRecord2(value);
49798
+ const properties = asRecord3(value);
49467
49799
  if (!properties) continue;
49468
49800
  const nextProperties = {};
49469
49801
  for (const [propertyName, propertySchema] of Object.entries(properties)) {
@@ -49506,7 +49838,7 @@ function normalizeSchema(root, schema2, options) {
49506
49838
  }
49507
49839
  function packSchema(root, schema2, version) {
49508
49840
  try {
49509
- const dialect = rootDialect(root, version, asRecord2(schema2) ?? void 0);
49841
+ const dialect = rootDialect(root, version, asRecord3(schema2) ?? void 0);
49510
49842
  const normalized = normalizeSchema(root, schema2, { version, rootSchema: true, dialect });
49511
49843
  const message = hasUnsupported(normalized);
49512
49844
  return message ? unsupported(message) : { schema: normalized };
@@ -49517,7 +49849,7 @@ function packSchema(root, schema2, version) {
49517
49849
 
49518
49850
  // src/lib/spec/contract-index.ts
49519
49851
  var HTTP_METHODS = /* @__PURE__ */ new Set(["get", "put", "post", "delete", "options", "head", "patch", "trace"]);
49520
- function asRecord3(value) {
49852
+ function asRecord4(value) {
49521
49853
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
49522
49854
  return value;
49523
49855
  }
@@ -49534,12 +49866,12 @@ function detectOpenApiVersion(root) {
49534
49866
  return match[1] === "1" ? "3.1" : "3.0";
49535
49867
  }
49536
49868
  function resolveInternalRef(root, value) {
49537
- const record = asRecord3(value);
49869
+ const record = asRecord4(value);
49538
49870
  if (!record) return null;
49539
49871
  const ref = typeof record.$ref === "string" ? record.$ref : "";
49540
49872
  if (!ref) return record;
49541
49873
  if (!ref.startsWith("#/")) throw new Error(`CONTRACT_UNRESOLVED_REF: External ref remained after bundling: ${ref}`);
49542
- const resolved = asRecord3(resolvePointer(root, ref));
49874
+ const resolved = asRecord4(resolvePointer(root, ref));
49543
49875
  if (!resolved) throw new Error(`CONTRACT_UNRESOLVED_REF: Unresolved OpenAPI $ref: ${ref}`);
49544
49876
  return resolved;
49545
49877
  }
@@ -49559,11 +49891,11 @@ function normalizePath(path8) {
49559
49891
  return trimmed.split("/").map((segment, index) => index === 0 ? "" : safeDecodeSegment(segment)).join("/") || "/";
49560
49892
  }
49561
49893
  function pathItemServers(pathItem) {
49562
- return asArray2(pathItem.servers).map((entry) => asRecord3(entry)).map((entry) => typeof entry?.url === "string" ? entry.url : "").filter(Boolean);
49894
+ return asArray2(pathItem.servers).map((entry) => asRecord4(entry)).map((entry) => typeof entry?.url === "string" ? entry.url : "").filter(Boolean);
49563
49895
  }
49564
49896
  function operationServers(root, pathItem, operation) {
49565
49897
  const rawServers = asArray2(operation.servers).length > 0 ? asArray2(operation.servers) : pathItemServers(pathItem).length > 0 ? asArray2(pathItem.servers) : asArray2(root.servers);
49566
- const values = rawServers.map((entry) => asRecord3(entry)).map((entry) => typeof entry?.url === "string" ? entry.url : "").filter(Boolean);
49898
+ const values = rawServers.map((entry) => asRecord4(entry)).map((entry) => typeof entry?.url === "string" ? entry.url : "").filter(Boolean);
49567
49899
  return values.length > 0 ? values : [""];
49568
49900
  }
49569
49901
  function serverPathPrefix(url) {
@@ -49584,10 +49916,10 @@ function normalizeResponseKey(status) {
49584
49916
  return /^[1-5]xx$/i.test(raw) ? raw.toUpperCase() : raw;
49585
49917
  }
49586
49918
  function collectSecurityApiKeys(root, operation) {
49587
- const securitySchemes = asRecord3(asRecord3(root.components)?.securitySchemes);
49919
+ const securitySchemes = asRecord4(asRecord4(root.components)?.securitySchemes);
49588
49920
  const requirements = operation.security === void 0 ? asArray2(root.security) : asArray2(operation.security);
49589
49921
  const names = /* @__PURE__ */ new Set();
49590
- for (const requirement of requirements.map((entry) => asRecord3(entry)).filter(Boolean)) {
49922
+ for (const requirement of requirements.map((entry) => asRecord4(entry)).filter(Boolean)) {
49591
49923
  for (const schemeName of Object.keys(requirement)) {
49592
49924
  const scheme = resolveInternalRef(root, securitySchemes?.[schemeName]);
49593
49925
  if (scheme?.type === "apiKey" && typeof scheme.name === "string" && ["query", "header"].includes(String(scheme.in))) {
@@ -49605,10 +49937,10 @@ function securitySchemeKind(scheme) {
49605
49937
  return type2;
49606
49938
  }
49607
49939
  function collectSecuritySchemeWarnings(root, operation) {
49608
- const securitySchemes = asRecord3(asRecord3(root.components)?.securitySchemes);
49940
+ const securitySchemes = asRecord4(asRecord4(root.components)?.securitySchemes);
49609
49941
  const requirements = operation.security === void 0 ? asArray2(root.security) : asArray2(operation.security);
49610
49942
  const warnings = /* @__PURE__ */ new Set();
49611
- for (const requirement of requirements.map((entry) => asRecord3(entry)).filter(Boolean)) {
49943
+ for (const requirement of requirements.map((entry) => asRecord4(entry)).filter(Boolean)) {
49612
49944
  for (const schemeName of Object.keys(requirement)) {
49613
49945
  const scheme = resolveInternalRef(root, securitySchemes?.[schemeName]);
49614
49946
  warnings.add(
@@ -49644,24 +49976,24 @@ function collectParameters(root, pathItem, operation) {
49644
49976
  function collectRequestBody(root, operation) {
49645
49977
  const body = resolveInternalRef(root, operation.requestBody);
49646
49978
  if (!body || body.required !== true) return void 0;
49647
- const content = asRecord3(body.content);
49979
+ const content = asRecord4(body.content);
49648
49980
  return {
49649
49981
  required: true,
49650
49982
  contentTypes: content ? Object.keys(content) : []
49651
49983
  };
49652
49984
  }
49653
49985
  function responseContent(root, version, response) {
49654
- const content = asRecord3(response.content);
49986
+ const content = asRecord4(response.content);
49655
49987
  if (!content) return {};
49656
49988
  const media = {};
49657
49989
  for (const [contentType, mediaObject] of Object.entries(content)) {
49658
- const schema2 = asRecord3(mediaObject)?.schema;
49990
+ const schema2 = asRecord4(mediaObject)?.schema;
49659
49991
  media[contentType] = schema2 === void 0 ? {} : packSchema(root, schema2, version);
49660
49992
  }
49661
49993
  return media;
49662
49994
  }
49663
49995
  function responseHeaders(root, version, response) {
49664
- const headers = asRecord3(response.headers);
49996
+ const headers = asRecord4(response.headers);
49665
49997
  if (!headers) return [];
49666
49998
  return Object.entries(headers).map(([name, rawHeader]) => {
49667
49999
  const header = resolveInternalRef(root, rawHeader);
@@ -49676,10 +50008,10 @@ function buildContractIndex(root) {
49676
50008
  if (root.swagger === "2.0") throw new Error("CONTRACT_UNSUPPORTED_OPENAPI_VERSION: Dynamic contract tests require OpenAPI 3.0 or 3.1 (found swagger 2.0)");
49677
50009
  if (!("openapi" in root)) throw new Error("CONTRACT_UNSUPPORTED_OPENAPI_VERSION: Dynamic contract tests require OpenAPI 3.0 or 3.1 (missing openapi)");
49678
50010
  const version = detectOpenApiVersion(root);
49679
- const paths = asRecord3(root.paths);
50011
+ const paths = asRecord4(root.paths);
49680
50012
  const operations = [];
49681
50013
  const warnings = [];
49682
- if (asRecord3(root.webhooks)) warnings.push("CONTRACT_WEBHOOKS_NOT_VALIDATED: OpenAPI webhooks are not validated by dynamic contract tests");
50014
+ if (asRecord4(root.webhooks)) warnings.push("CONTRACT_WEBHOOKS_NOT_VALIDATED: OpenAPI webhooks are not validated by dynamic contract tests");
49683
50015
  if (paths) {
49684
50016
  for (const [path8, rawPathItem] of Object.entries(paths)) {
49685
50017
  const pathItem = resolveInternalRef(root, rawPathItem);
@@ -49690,7 +50022,7 @@ function buildContractIndex(root) {
49690
50022
  const operation = resolveInternalRef(root, rawOperation);
49691
50023
  if (!operation) continue;
49692
50024
  if (operation.callbacks) warnings.push(`CONTRACT_CALLBACKS_NOT_VALIDATED: callbacks are not validated for ${lowerMethod.toUpperCase()} ${path8}`);
49693
- const responses = asRecord3(operation.responses);
50025
+ const responses = asRecord4(operation.responses);
49694
50026
  if (!responses || Object.keys(responses).length === 0) {
49695
50027
  throw new Error(`CONTRACT_OPERATION_NO_RESPONSES: ${lowerMethod.toUpperCase()} ${path8} must define at least one response`);
49696
50028
  }
@@ -49780,7 +50112,7 @@ var CONTRACT_SIZE_LIMITS = {
49780
50112
  maxTestScriptBytes: 9e5,
49781
50113
  maxCollectionUpdateBytes: 4e6
49782
50114
  };
49783
- function asRecord4(value) {
50115
+ function asRecord5(value) {
49784
50116
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
49785
50117
  return value;
49786
50118
  }
@@ -49789,7 +50121,7 @@ function asArray3(value) {
49789
50121
  }
49790
50122
  function stringifyPathSegment(segment) {
49791
50123
  if (typeof segment === "string") return segment;
49792
- const record = asRecord4(segment);
50124
+ const record = asRecord5(segment);
49793
50125
  if (!record) return String(segment ?? "");
49794
50126
  for (const key of ["value", "key", "name"]) {
49795
50127
  if (typeof record[key] === "string" && record[key]) return String(record[key]);
@@ -49807,10 +50139,10 @@ function pathFromRaw(raw) {
49807
50139
  }
49808
50140
  }
49809
50141
  function requestPath(request) {
49810
- const record = asRecord4(request);
50142
+ const record = asRecord5(request);
49811
50143
  const url = record?.url ?? request;
49812
50144
  if (typeof url === "string") return pathFromRaw(url);
49813
- const urlRecord = asRecord4(url);
50145
+ const urlRecord = asRecord5(url);
49814
50146
  if (!urlRecord) return "/";
49815
50147
  if (Array.isArray(urlRecord.path)) return normalizePath(`/${urlRecord.path.map(stringifyPathSegment).filter(Boolean).join("/")}`);
49816
50148
  if (typeof urlRecord.path === "string") return normalizePath(urlRecord.path);
@@ -49842,7 +50174,7 @@ function matchCandidate(candidate, request) {
49842
50174
  return { matched: true, staticCount, templateCount };
49843
50175
  }
49844
50176
  function matchOperation(index, request) {
49845
- const record = asRecord4(request);
50177
+ const record = asRecord5(request);
49846
50178
  const method = String(record?.method || "").toUpperCase();
49847
50179
  const path8 = requestPath(request);
49848
50180
  const candidates = index.operations.filter((operation) => operation.method === method).flatMap((operation) => operation.candidates.map((candidate) => ({ operation, score: matchCandidate(candidate, path8), serverFull: candidate !== normalizePath(operation.path) }))).filter((entry) => entry.score.matched).map((entry) => ({ operation: entry.operation, score: [entry.score.staticCount, entry.serverFull ? 2 : 1, -entry.score.templateCount] })).sort((a, b) => {
@@ -49993,17 +50325,17 @@ function createSecretsResolverItem() {
49993
50325
  }
49994
50326
  function isResolverItem(item) {
49995
50327
  if (item.name !== "00 - Resolve Secrets") return false;
49996
- const request = asRecord4(item.request);
50328
+ const request = asRecord5(item.request);
49997
50329
  if (String(request?.method || "").toUpperCase() !== "POST") return false;
49998
- const headers = asArray3(request?.header).map((entry) => asRecord4(entry));
50330
+ const headers = asArray3(request?.header).map((entry) => asRecord5(entry));
49999
50331
  const target = headers.find((entry) => entry?.key === "X-Amz-Target");
50000
50332
  return String(target?.value || "") === "secretsmanager.GetSecretValue" && !requestPath(request).includes("secretsmanager");
50001
50333
  }
50002
50334
  function requestQueryNames(request) {
50003
- const url = asRecord4(request.url);
50335
+ const url = asRecord5(request.url);
50004
50336
  const names = /* @__PURE__ */ new Set();
50005
50337
  if (Array.isArray(url?.query)) {
50006
- for (const entry of url.query.map((item) => asRecord4(item)).filter(Boolean)) {
50338
+ for (const entry of url.query.map((item) => asRecord5(item)).filter(Boolean)) {
50007
50339
  if (entry.disabled !== true && typeof entry.key === "string") names.add(entry.key.toLowerCase());
50008
50340
  }
50009
50341
  }
@@ -50018,17 +50350,17 @@ function requestQueryNames(request) {
50018
50350
  }
50019
50351
  function requestHeaderNames(request) {
50020
50352
  const names = /* @__PURE__ */ new Set();
50021
- for (const entry of asArray3(request.header).map((item) => asRecord4(item)).filter(Boolean)) {
50353
+ for (const entry of asArray3(request.header).map((item) => asRecord5(item)).filter(Boolean)) {
50022
50354
  if (entry.disabled !== true && typeof entry.key === "string") names.add(entry.key.toLowerCase());
50023
50355
  }
50024
50356
  return names;
50025
50357
  }
50026
50358
  function requestHeaderValue(request, name) {
50027
- const match = asArray3(request.header).map((item) => asRecord4(item)).filter(Boolean).find((entry) => String(entry.key || "").toLowerCase() === name.toLowerCase() && entry.disabled !== true);
50359
+ const match = asArray3(request.header).map((item) => asRecord5(item)).filter(Boolean).find((entry) => String(entry.key || "").toLowerCase() === name.toLowerCase() && entry.disabled !== true);
50028
50360
  return typeof match?.value === "string" ? match.value : void 0;
50029
50361
  }
50030
50362
  function hasRequestBody(request) {
50031
- const body = asRecord4(request.body);
50363
+ const body = asRecord5(request.body);
50032
50364
  if (!body) return false;
50033
50365
  if (typeof body.raw === "string" && body.raw.trim()) return true;
50034
50366
  return ["urlencoded", "formdata", "graphql"].some((key) => Array.isArray(body[key]) ? body[key].length > 0 : Boolean(body[key]));
@@ -50079,21 +50411,21 @@ function validateScript(script) {
50079
50411
  return void 0;
50080
50412
  }
50081
50413
  function scriptExecLines(script) {
50082
- const record = asRecord4(script);
50414
+ const record = asRecord5(script);
50083
50415
  if (!record) return [];
50084
50416
  if (Array.isArray(record.exec)) return record.exec.map((line) => String(line));
50085
50417
  if (typeof record.exec === "string") return [record.exec];
50086
50418
  return [];
50087
50419
  }
50088
50420
  function scanExecutableScripts(node, warnings) {
50089
- for (const event of asArray3(node.event).map((entry) => asRecord4(entry)).filter(Boolean)) {
50421
+ for (const event of asArray3(node.event).map((entry) => asRecord5(entry)).filter(Boolean)) {
50090
50422
  const lines = scriptExecLines(event.script);
50091
50423
  if (lines.length === 0) continue;
50092
50424
  const warning2 = validateScript(lines);
50093
50425
  if (warning2) warnings.push(warning2);
50094
50426
  }
50095
50427
  for (const child2 of asArray3(node.item)) {
50096
- const childRecord = asRecord4(child2);
50428
+ const childRecord = asRecord5(child2);
50097
50429
  if (childRecord) scanExecutableScripts(childRecord, warnings);
50098
50430
  }
50099
50431
  }
@@ -50103,7 +50435,7 @@ function instrumentContractCollection(collection, index) {
50103
50435
  const inject = (item) => {
50104
50436
  if (isResolverItem(item)) return;
50105
50437
  if (item.request) {
50106
- const request = asRecord4(item.request) ?? {};
50438
+ const request = asRecord5(item.request) ?? {};
50107
50439
  const result = matchOperation(index, request);
50108
50440
  let script;
50109
50441
  if (result.operation) {
@@ -50117,15 +50449,15 @@ function instrumentContractCollection(collection, index) {
50117
50449
  } else {
50118
50450
  script = createMappingFailureScript(`No OpenAPI operation matched request ${result.method} ${result.path}`);
50119
50451
  }
50120
- const events2 = asArray3(item.event).filter((entry) => asRecord4(entry)?.listen !== "test");
50452
+ const events2 = asArray3(item.event).filter((entry) => asRecord5(entry)?.listen !== "test");
50121
50453
  item.event = [...events2, { listen: "test", script: { type: "text/javascript", exec: script } }];
50122
50454
  }
50123
50455
  for (const child2 of asArray3(item.item)) {
50124
- const childRecord = asRecord4(child2);
50456
+ const childRecord = asRecord5(child2);
50125
50457
  if (childRecord) inject(childRecord);
50126
50458
  }
50127
50459
  };
50128
- const items = asArray3(collection.item).map((entry) => asRecord4(entry)).filter((entry) => Boolean(entry)).filter((entry) => !isResolverItem(entry));
50460
+ const items = asArray3(collection.item).map((entry) => asRecord5(entry)).filter((entry) => Boolean(entry)).filter((entry) => !isResolverItem(entry));
50129
50461
  collection.item = items;
50130
50462
  for (const item of items) inject(item);
50131
50463
  const missing = index.operations.filter((operation) => !covered.has(operation.id));
@@ -62489,7 +62821,7 @@ function compileErrors(result) {
62489
62821
 
62490
62822
  // src/lib/spec/openapi-loader.ts
62491
62823
  var import_yaml2 = __toESM(require_dist(), 1);
62492
- function asRecord5(value) {
62824
+ function asRecord6(value) {
62493
62825
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
62494
62826
  return value;
62495
62827
  }
@@ -62504,7 +62836,7 @@ function parseOpenApiDocument(content) {
62504
62836
  throw new Error("CONTRACT_SPEC_PARSE_FAILED: Spec content is not valid JSON or YAML");
62505
62837
  }
62506
62838
  }
62507
- const doc = asRecord5(parsed);
62839
+ const doc = asRecord6(parsed);
62508
62840
  if (!doc) throw new Error("CONTRACT_SPEC_PARSE_FAILED: Spec content must be a JSON or YAML object");
62509
62841
  return doc;
62510
62842
  }
@@ -62532,7 +62864,7 @@ function collectExternalRefs(node, baseUrl, refs) {
62532
62864
  node.forEach((entry) => collectExternalRefs(entry, baseUrl, refs));
62533
62865
  return;
62534
62866
  }
62535
- const record = asRecord5(node);
62867
+ const record = asRecord6(node);
62536
62868
  if (!record) return;
62537
62869
  const ref = typeof record.$ref === "string" ? record.$ref : "";
62538
62870
  if (ref && !ref.startsWith("#")) {
@@ -62870,6 +63202,11 @@ function resolveInputs(env = process.env) {
62870
63202
  governanceMappingJson: parseGovernanceMappingJson(getInput2("governance-mapping-json", env)),
62871
63203
  postmanApiKey: getInput2("postman-api-key", env) ?? "",
62872
63204
  postmanAccessToken: getInput2("postman-access-token", env),
63205
+ credentialPreflight: parseEnumInput(
63206
+ "credential-preflight",
63207
+ getInput2("credential-preflight", env),
63208
+ customerPreviewActionContract.inputs["credential-preflight"].default ?? "warn"
63209
+ ),
62873
63210
  integrationBackend,
62874
63211
  folderStrategy: parseEnumInput("folder-strategy", getInput2("folder-strategy", env), "Paths"),
62875
63212
  nestedFolderHierarchy: parseBooleanInput("nested-folder-hierarchy", getInput2("nested-folder-hierarchy", env), false),
@@ -62879,6 +63216,7 @@ function resolveInputs(env = process.env) {
62879
63216
  postmanBifrostBase: endpointProfile.bifrostBaseUrl,
62880
63217
  postmanGatewayBase: endpointProfile.gatewayBaseUrl,
62881
63218
  postmanCliInstallUrl: endpointProfile.cliInstallUrl,
63219
+ postmanIapubBase: endpointProfile.iapubBaseUrl,
62882
63220
  githubRefName: env.GITHUB_REF_NAME,
62883
63221
  githubHeadRef: env.GITHUB_HEAD_REF,
62884
63222
  githubRef: env.GITHUB_REF,
@@ -62967,6 +63305,7 @@ function readActionInputs(actionCore) {
62967
63305
  INPUT_GOVERNANCE_MAPPING_JSON: optionalInput(actionCore, "governance-mapping-json") ?? customerPreviewActionContract.inputs["governance-mapping-json"].default,
62968
63306
  INPUT_POSTMAN_API_KEY: postmanApiKey,
62969
63307
  INPUT_POSTMAN_ACCESS_TOKEN: postmanAccessToken,
63308
+ INPUT_CREDENTIAL_PREFLIGHT: optionalInput(actionCore, "credential-preflight") ?? customerPreviewActionContract.inputs["credential-preflight"].default,
62970
63309
  INPUT_INTEGRATION_BACKEND: optionalInput(actionCore, "integration-backend") ?? customerPreviewActionContract.inputs["integration-backend"].default,
62971
63310
  INPUT_FOLDER_STRATEGY: optionalInput(actionCore, "folder-strategy") ?? customerPreviewActionContract.inputs["folder-strategy"].default,
62972
63311
  INPUT_NESTED_FOLDER_HIERARCHY: optionalInput(actionCore, "nested-folder-hierarchy") ?? customerPreviewActionContract.inputs["nested-folder-hierarchy"].default,
@@ -63478,8 +63817,20 @@ For CLI usage, pass --workspace-team-id <id> or export POSTMAN_WORKSPACE_TEAM_ID
63478
63817
  governanceGroupName
63479
63818
  );
63480
63819
  } catch (error2) {
63820
+ const session = getMemoizedSessionIdentity();
63821
+ const advised = error2 instanceof HttpError ? adviseFromHttpError(error2, {
63822
+ operation: "governance assignment",
63823
+ hasAccessToken: Boolean(inputs.postmanAccessToken),
63824
+ sessionTeamId: session?.teamId,
63825
+ sessionRoles: session?.roles,
63826
+ sessionConsumerType: session?.consumerType,
63827
+ workspaceTeamId: inputs.workspaceTeamId,
63828
+ explicitTeamId: inputs.teamId || void 0,
63829
+ mask: createSecretMasker([inputs.postmanApiKey, inputs.postmanAccessToken])
63830
+ }) : void 0;
63831
+ const reported = advised ?? error2;
63481
63832
  dependencies.core.warning(
63482
- `Failed to assign governance group: ${error2 instanceof Error ? error2.message : String(error2)}`
63833
+ `Failed to assign governance group: ${reported instanceof Error ? reported.message : String(reported)}`
63483
63834
  );
63484
63835
  }
63485
63836
  }
@@ -64066,6 +64417,17 @@ For CLI usage, pass --workspace-team-id <id> or export POSTMAN_WORKSPACE_TEAM_ID
64066
64417
  }
64067
64418
  async function runAction(actionCore = core_exports, actionExec = exec_exports, actionIo = io_exports) {
64068
64419
  const inputs = readActionInputs(actionCore);
64420
+ await runCredentialPreflight({
64421
+ apiBaseUrl: inputs.postmanApiBase,
64422
+ iapubBaseUrl: inputs.postmanIapubBase,
64423
+ postmanApiKey: inputs.postmanApiKey,
64424
+ postmanAccessToken: inputs.postmanAccessToken,
64425
+ workspaceTeamId: inputs.workspaceTeamId,
64426
+ explicitTeamId: inputs.teamId || void 0,
64427
+ mode: inputs.credentialPreflight,
64428
+ mask: createSecretMasker([inputs.postmanApiKey, inputs.postmanAccessToken]),
64429
+ log: actionCore
64430
+ });
64069
64431
  let orgMode = false;
64070
64432
  if (inputs.postmanAccessToken && inputs.teamId) {
64071
64433
  try {