@postman-cse/onboarding-bootstrap 0.14.2 → 0.15.2

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,313 @@ 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 root = asRecord(payload.session) ?? payload;
47941
+ const identity = asRecord(root.identity);
47942
+ const data = asRecord(root.data);
47943
+ const user = asRecord(data?.user);
47944
+ const roleEntries = Array.isArray(user?.roles) ? user.roles.map((entry) => coerceText(entry) ?? coerceId(entry)).filter((entry) => Boolean(entry)) : [];
47945
+ const singleRole = coerceText(user?.role);
47946
+ const roles = roleEntries.length > 0 ? roleEntries : singleRole ? [singleRole] : void 0;
47947
+ const resolved = {
47948
+ source: "iapub/sessions",
47949
+ userId: coerceId(identity?.user) ?? coerceId(user?.id),
47950
+ fullName: coerceText(user?.fullName) ?? coerceText(user?.name) ?? coerceText(user?.username),
47951
+ teamId: coerceId(identity?.team),
47952
+ teamName: coerceText(user?.teamName),
47953
+ teamDomain: coerceText(identity?.domain),
47954
+ ...roles ? { roles } : {},
47955
+ consumerType: coerceText(root.consumerType) ?? coerceText(data?.consumerType) ?? coerceText(user?.consumerType)
47956
+ };
47957
+ memoizedSessionIdentity = resolved;
47958
+ return resolved;
47959
+ } catch {
47960
+ return void 0;
47961
+ }
47962
+ }
47963
+ function describeTeam(id) {
47964
+ const label = id?.teamName ?? id?.teamDomain;
47965
+ return `team ${id?.teamId ?? "unresolved"}${label ? ` (${label})` : ""}`;
47966
+ }
47967
+ function formatIdentityLine(id, mask) {
47968
+ const teamPart = id.teamId ? describeTeam(id) : "team unresolved";
47969
+ const domainPart = id.teamDomain ? `, domain ${id.teamDomain}` : "";
47970
+ if (id.source === "pmak/me") {
47971
+ const userPart = id.userId ? `user ${id.userId}${id.fullName ? ` (${id.fullName})` : ""}, ` : "";
47972
+ return mask(`postman: PMAK identity - ${userPart}${teamPart}${domainPart}`);
47973
+ }
47974
+ return mask(
47975
+ `postman: access-token session identity - ${teamPart}${domainPart} [source: iapub/sessions]`
47976
+ );
47977
+ }
47978
+ function crossCheckIdentities(args) {
47979
+ if (args.mode === "off") {
47980
+ return { ok: true, level: "ok", message: "" };
47981
+ }
47982
+ const pmakTeamId = args.pmak?.teamId;
47983
+ const sessionTeamId = args.session?.teamId;
47984
+ if (pmakTeamId && sessionTeamId && pmakTeamId !== sessionTeamId) {
47985
+ const level = args.mode === "enforce" ? "fail" : "note";
47986
+ const lead = level === "fail" ? "credential preflight FAILED" : "credential preflight note";
47987
+ 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.";
47988
+ return {
47989
+ ok: false,
47990
+ level,
47991
+ message: args.mask(
47992
+ `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
47993
+ )
47994
+ };
47995
+ }
47996
+ if (pmakTeamId && sessionTeamId) {
47997
+ const scope = args.workspaceTeamId || args.explicitTeamId ? "parent org team" : "team";
47998
+ const label = args.pmak?.teamName ?? args.pmak?.teamDomain ?? args.session?.teamName ?? args.session?.teamDomain;
47999
+ return {
48000
+ ok: true,
48001
+ level: "ok",
48002
+ message: args.mask(
48003
+ `postman: credential preflight OK - PMAK and access token both resolve to ${scope} ${pmakTeamId}${label ? ` (${label})` : ""}`
48004
+ )
48005
+ };
48006
+ }
48007
+ const missing = [
48008
+ !pmakTeamId ? "PMAK identity" : void 0,
48009
+ !sessionTeamId ? "access-token session identity" : void 0
48010
+ ].filter(Boolean).join(" and ");
48011
+ return {
48012
+ ok: false,
48013
+ level: "note",
48014
+ message: args.mask(
48015
+ `postman: credential preflight note - cross-check skipped because the ${missing} did not resolve a team id; continuing with reactive error guidance only`
48016
+ )
48017
+ };
48018
+ }
48019
+ async function runCredentialPreflight(args) {
48020
+ if (args.mode === "off") {
48021
+ return;
48022
+ }
48023
+ const mask = args.mask;
48024
+ const apiKey = String(args.postmanApiKey || "").trim();
48025
+ const accessToken = String(args.postmanAccessToken || "").trim();
48026
+ let pmak;
48027
+ if (apiKey) {
48028
+ try {
48029
+ pmak = await resolvePmakIdentity({
48030
+ apiBaseUrl: args.apiBaseUrl,
48031
+ apiKey,
48032
+ fetchImpl: args.fetchImpl
48033
+ });
48034
+ } catch (error2) {
48035
+ args.log.warning(
48036
+ mask(
48037
+ `postman: credential preflight could not resolve PMAK identity: ${error2 instanceof Error ? error2.message : String(error2)}`
48038
+ )
48039
+ );
48040
+ }
48041
+ if (pmak) {
48042
+ args.log.info(formatIdentityLine(pmak, mask));
48043
+ } else {
48044
+ args.log.warning(
48045
+ mask("postman: credential preflight could not resolve PMAK identity from GET /me; continuing")
48046
+ );
48047
+ }
48048
+ }
48049
+ if (!accessToken) {
48050
+ args.log.info(mask("postman: Bifrost diagnostics limited: no access token"));
48051
+ return;
48052
+ }
48053
+ let session;
48054
+ try {
48055
+ session = await resolveSessionIdentity({
48056
+ iapubBaseUrl: args.iapubBaseUrl,
48057
+ accessToken,
48058
+ fetchImpl: args.fetchImpl
48059
+ });
48060
+ } catch (error2) {
48061
+ args.log.warning(
48062
+ mask(
48063
+ `postman: credential preflight could not resolve access-token session identity: ${error2 instanceof Error ? error2.message : String(error2)}`
48064
+ )
48065
+ );
48066
+ }
48067
+ if (session) {
48068
+ args.log.info(formatIdentityLine(session, mask));
48069
+ } else {
48070
+ args.log.warning(
48071
+ mask(
48072
+ "postman: credential preflight could not resolve the access-token session identity from iapub; continuing with reactive error guidance only"
48073
+ )
48074
+ );
48075
+ }
48076
+ const result = crossCheckIdentities({
48077
+ pmak,
48078
+ session,
48079
+ workspaceTeamId: args.workspaceTeamId,
48080
+ explicitTeamId: args.explicitTeamId,
48081
+ mode: args.mode,
48082
+ mask
48083
+ });
48084
+ if (!result.message) {
48085
+ return;
48086
+ }
48087
+ if (result.level === "fail") {
48088
+ throw new Error(result.message);
48089
+ }
48090
+ if (result.level === "note") {
48091
+ args.log.warning(result.message);
48092
+ return;
48093
+ }
48094
+ args.log.info(result.message);
48095
+ }
48096
+
48097
+ // src/lib/postman/error-advice.ts
48098
+ 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.";
48099
+ function workspaceTeamIdUnauthorizedAdvice(targetTeamId) {
48100
+ 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.`;
48101
+ }
48102
+ function adviseFromWorkspaceCreateError(err, targetTeamId) {
48103
+ if (err.message.includes("Only personal workspaces")) {
48104
+ return new Error(WORKSPACE_PERSONAL_ONLY_ADVICE, { cause: err });
48105
+ }
48106
+ if (targetTeamId != null && err.message.includes("You are not authorized to perform this action")) {
48107
+ return new Error(workspaceTeamIdUnauthorizedAdvice(targetTeamId), { cause: err });
48108
+ }
48109
+ return void 0;
48110
+ }
48111
+ function expiryAdvice(code) {
48112
+ 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.`;
48113
+ }
48114
+ function forbiddenAdvice(ctx) {
48115
+ 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)` : "";
48116
+ const scopedTeamId = ctx.workspaceTeamId || ctx.explicitTeamId;
48117
+ 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";
48118
+ 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.`;
48119
+ }
48120
+ function buildAdvice(status, body, ctx) {
48121
+ if (body.includes("UNAUTHENTICATED")) {
48122
+ return expiryAdvice("UNAUTHENTICATED");
48123
+ }
48124
+ if (body.includes("authenticationError")) {
48125
+ return expiryAdvice("authenticationError");
48126
+ }
48127
+ if (body.includes("Only personal workspaces")) {
48128
+ return WORKSPACE_PERSONAL_ONLY_ADVICE;
48129
+ }
48130
+ if (body.includes("projectAlreadyConnected")) {
48131
+ 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.`;
48132
+ }
48133
+ if (body.includes("invalidParamError") && body.includes("already exists")) {
48134
+ 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.`;
48135
+ }
48136
+ if (body.includes("Team feature is not available for your organization")) {
48137
+ 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.`;
48138
+ }
48139
+ if (body.includes("You are not authorized to perform this action") || status === 403 && ctx.hasAccessToken) {
48140
+ return forbiddenAdvice(ctx);
48141
+ }
48142
+ return void 0;
48143
+ }
48144
+ function adviseFromHttpError(err, ctx) {
48145
+ const body = err.responseBody || err.message || "";
48146
+ const advice = buildAdvice(err.status, body, ctx);
48147
+ if (!advice) {
48148
+ return void 0;
48149
+ }
48150
+ return new Error(ctx.mask(advice), { cause: err });
48151
+ }
48152
+
47838
48153
  // src/lib/retry.ts
47839
48154
  function sleep(delayMs) {
47840
48155
  return new Promise((resolve4) => {
@@ -47883,7 +48198,7 @@ async function retry(operation, options = {}) {
47883
48198
  }
47884
48199
 
47885
48200
  // src/lib/postman/postman-assets-client.ts
47886
- function asRecord(value) {
48201
+ function asRecord2(value) {
47887
48202
  if (!value || typeof value !== "object" || Array.isArray(value)) {
47888
48203
  return null;
47889
48204
  }
@@ -47891,8 +48206,8 @@ function asRecord(value) {
47891
48206
  }
47892
48207
  function extractWorkspacesPage(data) {
47893
48208
  const workspaces = Array.isArray(data?.workspaces) ? data.workspaces : [];
47894
- const meta = asRecord(data?.meta);
47895
- const pagination = asRecord(data?.pagination);
48209
+ const meta = asRecord2(data?.meta);
48210
+ const pagination = asRecord2(data?.pagination);
47896
48211
  const nextCursor = String(
47897
48212
  data?.nextCursor ?? data?.next_cursor ?? meta?.nextCursor ?? meta?.next_cursor ?? pagination?.nextCursor ?? pagination?.next_cursor ?? ""
47898
48213
  ).trim() || void 0;
@@ -47984,7 +48299,7 @@ var PostmanAssetsClient = class {
47984
48299
  async getTeams() {
47985
48300
  const data = await this.request("/teams");
47986
48301
  const teams = data?.data ?? [];
47987
- return Array.isArray(teams) ? teams.map((entry) => asRecord(entry)).filter((team) => Boolean(team?.id && team?.name)).map((team) => ({
48302
+ return Array.isArray(teams) ? teams.map((entry) => asRecord2(entry)).filter((team) => Boolean(team?.id && team?.name)).map((team) => ({
47988
48303
  id: Number(team.id),
47989
48304
  name: String(team.name),
47990
48305
  handle: String(team.handle || ""),
@@ -48036,34 +48351,28 @@ var PostmanAssetsClient = class {
48036
48351
  body: JSON.stringify(payload)
48037
48352
  });
48038
48353
  } 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
- );
48354
+ if (err instanceof Error) {
48355
+ const advised = adviseFromWorkspaceCreateError(err, targetTeamId);
48356
+ if (advised) {
48357
+ throw advised;
48358
+ }
48050
48359
  }
48051
48360
  throw err;
48052
48361
  }
48053
- const createdWorkspace = asRecord(created?.workspace);
48362
+ const createdWorkspace = asRecord2(created?.workspace);
48054
48363
  const workspaceId = String(createdWorkspace?.id || "").trim();
48055
48364
  if (!workspaceId) {
48056
48365
  throw new Error("Workspace create did not return an id");
48057
48366
  }
48058
48367
  const workspace = await this.request(`/workspaces/${workspaceId}`);
48059
- let visibility = asRecord(workspace?.workspace)?.visibility;
48368
+ let visibility = asRecord2(workspace?.workspace)?.visibility;
48060
48369
  if (visibility !== "team") {
48061
48370
  await this.request(`/workspaces/${workspaceId}`, {
48062
48371
  method: "PUT",
48063
48372
  body: JSON.stringify(payload)
48064
48373
  });
48065
48374
  const reread = await this.request(`/workspaces/${workspaceId}`);
48066
- visibility = asRecord(reread?.workspace)?.visibility;
48375
+ visibility = asRecord2(reread?.workspace)?.visibility;
48067
48376
  }
48068
48377
  if (typeof visibility === "string" && visibility !== "team") {
48069
48378
  let cleanedUp = false;
@@ -48092,7 +48401,7 @@ var PostmanAssetsClient = class {
48092
48401
  async getWorkspaceVisibility(workspaceId) {
48093
48402
  try {
48094
48403
  const workspace = await this.request(`/workspaces/${workspaceId}`);
48095
- const visibility = asRecord(workspace?.workspace)?.visibility;
48404
+ const visibility = asRecord2(workspace?.workspace)?.visibility;
48096
48405
  return typeof visibility === "string" ? visibility : null;
48097
48406
  } catch {
48098
48407
  return null;
@@ -48114,7 +48423,7 @@ var PostmanAssetsClient = class {
48114
48423
  nextCursor = page.nextCursor;
48115
48424
  }
48116
48425
  } while (nextCursor);
48117
- return allWorkspaces.map((entry) => asRecord(entry)).filter((workspace) => Boolean(workspace?.id && workspace?.name)).map((workspace) => ({
48426
+ return allWorkspaces.map((entry) => asRecord2(entry)).filter((workspace) => Boolean(workspace?.id && workspace?.name)).map((workspace) => ({
48118
48427
  id: String(workspace.id),
48119
48428
  name: String(workspace.name),
48120
48429
  type: String(workspace.type ?? "team")
@@ -48162,7 +48471,7 @@ var PostmanAssetsClient = class {
48162
48471
  async inviteRequesterToWorkspace(workspaceId, email) {
48163
48472
  const users = await this.request("/users");
48164
48473
  const userList = Array.isArray(users?.data) ? users.data : [];
48165
- const user = userList.map((entry) => asRecord(entry)).find((entry) => entry?.email === email);
48474
+ const user = userList.map((entry) => asRecord2(entry)).find((entry) => entry?.email === email);
48166
48475
  if (!user?.id) {
48167
48476
  return;
48168
48477
  }
@@ -48250,12 +48559,12 @@ var PostmanAssetsClient = class {
48250
48559
  }
48251
48560
  };
48252
48561
  const extractUid = (data) => {
48253
- const root = asRecord(data);
48254
- const details = asRecord(root?.details);
48562
+ const root = asRecord2(data);
48563
+ const details = asRecord2(root?.details);
48255
48564
  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);
48565
+ const firstResource = asRecord2(resources[0]);
48566
+ const collection = asRecord2(root?.collection);
48567
+ const resource = asRecord2(root?.resource);
48259
48568
  return String(
48260
48569
  firstResource?.id ?? collection?.id ?? collection?.uid ?? resource?.uid ?? resource?.id ?? ""
48261
48570
  ).trim() || void 0;
@@ -48289,9 +48598,9 @@ var PostmanAssetsClient = class {
48289
48598
  if (directUid) {
48290
48599
  return directUid;
48291
48600
  }
48292
- let taskUrl = String(generationResponse?.url ?? "") || String(generationResponse?.task_url ?? "") || String(generationResponse?.taskUrl ?? "") || String(asRecord(generationResponse?.links)?.task ?? "");
48601
+ let taskUrl = String(generationResponse?.url ?? "") || String(generationResponse?.task_url ?? "") || String(generationResponse?.taskUrl ?? "") || String(asRecord2(generationResponse?.links)?.task ?? "");
48293
48602
  if (!taskUrl) {
48294
- const task = asRecord(generationResponse?.task);
48603
+ const task = asRecord2(generationResponse?.task);
48295
48604
  const taskId = generationResponse?.taskId || task?.id || generationResponse?.id;
48296
48605
  if (!taskId) {
48297
48606
  throw new Error(
@@ -48305,8 +48614,8 @@ var PostmanAssetsClient = class {
48305
48614
  setTimeout(resolve4, 2e3);
48306
48615
  });
48307
48616
  const task = await this.request(taskUrl);
48308
- const taskRecord = asRecord(task);
48309
- const taskNested = asRecord(taskRecord?.task);
48617
+ const taskRecord = asRecord2(task);
48618
+ const taskNested = asRecord2(taskRecord?.task);
48310
48619
  const status = String(taskRecord?.status || taskNested?.status || "").toLowerCase();
48311
48620
  if (status === "completed") {
48312
48621
  const taskUid = extractUid(task);
@@ -48337,7 +48646,7 @@ var PostmanAssetsClient = class {
48337
48646
  }
48338
48647
  async injectTests(collectionUid, type2) {
48339
48648
  const collectionResponse = await this.request(`/collections/${collectionUid}`);
48340
- const collection = asRecord(collectionResponse?.collection);
48649
+ const collection = asRecord2(collectionResponse?.collection);
48341
48650
  if (!collection) {
48342
48651
  throw new Error(`Failed to fetch collection ${collectionUid}`);
48343
48652
  }
@@ -48423,7 +48732,7 @@ var PostmanAssetsClient = class {
48423
48732
  });
48424
48733
  }
48425
48734
  if (Array.isArray(itemNode.item)) {
48426
- itemNode.item.map((entry) => asRecord(entry)).filter((entry) => Boolean(entry)).forEach(injectScripts);
48735
+ itemNode.item.map((entry) => asRecord2(entry)).filter((entry) => Boolean(entry)).forEach(injectScripts);
48427
48736
  }
48428
48737
  };
48429
48738
  if (Array.isArray(collection.item)) {
@@ -48451,7 +48760,7 @@ var PostmanAssetsClient = class {
48451
48760
  }
48452
48761
  })
48453
48762
  });
48454
- const environment = asRecord(response?.environment);
48763
+ const environment = asRecord2(response?.environment);
48455
48764
  const uid = String(environment?.uid || "").trim();
48456
48765
  if (!uid) {
48457
48766
  throw new Error("Environment create did not return a UID");
@@ -48484,7 +48793,7 @@ var PostmanAssetsClient = class {
48484
48793
  }
48485
48794
  })
48486
48795
  });
48487
- const monitor = asRecord(response?.monitor);
48796
+ const monitor = asRecord2(response?.monitor);
48488
48797
  const uid = String(monitor?.uid || "").trim();
48489
48798
  if (!uid) {
48490
48799
  throw new Error("Monitor create did not return a UID");
@@ -48503,8 +48812,8 @@ var PostmanAssetsClient = class {
48503
48812
  }
48504
48813
  })
48505
48814
  });
48506
- const mock = asRecord(response?.mock);
48507
- const mockConfig = asRecord(mock?.config);
48815
+ const mock = asRecord2(response?.mock);
48816
+ const mockConfig = asRecord2(mock?.config);
48508
48817
  const uid = String(mock?.uid || "").trim();
48509
48818
  if (!uid) {
48510
48819
  throw new Error("Mock create did not return a UID");
@@ -48575,6 +48884,18 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48575
48884
  this.teamId = String(teamId || "").trim();
48576
48885
  this.orgMode = orgMode;
48577
48886
  }
48887
+ adviceContext(operation) {
48888
+ const session = getMemoizedSessionIdentity();
48889
+ return {
48890
+ operation,
48891
+ hasAccessToken: Boolean(this.accessToken),
48892
+ sessionTeamId: session?.teamId,
48893
+ sessionRoles: session?.roles,
48894
+ sessionConsumerType: session?.consumerType,
48895
+ explicitTeamId: this.teamId || void 0,
48896
+ mask: this.secretMasker
48897
+ };
48898
+ }
48578
48899
  async proxyRequest(service, method, requestPath2, body, options = {}) {
48579
48900
  const url = `${this.bifrostBaseUrl}/ws/proxy`;
48580
48901
  const headers = {
@@ -48641,7 +48962,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48641
48962
  { appVersion, query: { tag: "governance" } }
48642
48963
  );
48643
48964
  if (!listResponse.ok) {
48644
- throw await HttpError.fromResponse(listResponse, {
48965
+ const httpErr = await HttpError.fromResponse(listResponse, {
48645
48966
  method: "GET",
48646
48967
  requestHeaders: {
48647
48968
  "Content-Type": "application/json",
@@ -48652,6 +48973,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48652
48973
  secretValues: [this.accessToken],
48653
48974
  url: `${this.bifrostBaseUrl}/ws/proxy`
48654
48975
  });
48976
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("governance assignment"));
48977
+ throw advised ?? httpErr;
48655
48978
  }
48656
48979
  const groups = await listResponse.json();
48657
48980
  const group2 = (groups.workspaceGroups ?? groups.data)?.find(
@@ -48677,7 +49000,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48677
49000
  { appVersion }
48678
49001
  );
48679
49002
  if (!patchResponse.ok) {
48680
- throw await HttpError.fromResponse(patchResponse, {
49003
+ const httpErr = await HttpError.fromResponse(patchResponse, {
48681
49004
  method: "PATCH",
48682
49005
  requestHeaders: {
48683
49006
  "Content-Type": "application/json",
@@ -48688,6 +49011,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48688
49011
  secretValues: [this.accessToken],
48689
49012
  url: `${this.bifrostBaseUrl}/ws/proxy`
48690
49013
  });
49014
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("governance assignment"));
49015
+ throw advised ?? httpErr;
48691
49016
  }
48692
49017
  }
48693
49018
  async connectWorkspaceToRepository(workspaceId, repoUrl) {
@@ -48721,7 +49046,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48721
49046
  );
48722
49047
  }
48723
49048
  }
48724
- throw await HttpError.fromResponse(response, {
49049
+ const httpErr = await HttpError.fromResponse(response, {
48725
49050
  method: "POST",
48726
49051
  requestHeaders: {
48727
49052
  "Content-Type": "application/json",
@@ -48731,6 +49056,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48731
49056
  secretValues: [this.accessToken],
48732
49057
  url: `${this.bifrostBaseUrl}/ws/proxy`
48733
49058
  });
49059
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("workspace repository linking"));
49060
+ throw advised ?? httpErr;
48734
49061
  }
48735
49062
  async linkCollectionsToSpecification(specificationId, collections) {
48736
49063
  if (collections.length === 0) {
@@ -48748,7 +49075,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48748
49075
  if (response.ok) {
48749
49076
  return;
48750
49077
  }
48751
- throw await HttpError.fromResponse(response, {
49078
+ const httpErr = await HttpError.fromResponse(response, {
48752
49079
  method: "POST",
48753
49080
  requestHeaders: {
48754
49081
  "Content-Type": "application/json",
@@ -48758,6 +49085,11 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48758
49085
  secretValues: [this.accessToken],
48759
49086
  url: `${this.bifrostBaseUrl}/ws/proxy`
48760
49087
  });
49088
+ const advised = adviseFromHttpError(
49089
+ httpErr,
49090
+ this.adviceContext("collection-to-specification linking")
49091
+ );
49092
+ throw advised ?? httpErr;
48761
49093
  }
48762
49094
  async syncCollection(specificationId, collectionId) {
48763
49095
  const response = await this.proxyRequest(
@@ -48768,7 +49100,7 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48768
49100
  if (response.ok) {
48769
49101
  return;
48770
49102
  }
48771
- throw await HttpError.fromResponse(response, {
49103
+ const httpErr = await HttpError.fromResponse(response, {
48772
49104
  method: "POST",
48773
49105
  requestHeaders: {
48774
49106
  "Content-Type": "application/json",
@@ -48778,6 +49110,8 @@ var BifrostInternalIntegrationAdapter = class _BifrostInternalIntegrationAdapter
48778
49110
  secretValues: [this.accessToken],
48779
49111
  url: `${this.bifrostBaseUrl}/ws/proxy`
48780
49112
  });
49113
+ const advised = adviseFromHttpError(httpErr, this.adviceContext("collection sync"));
49114
+ throw advised ?? httpErr;
48781
49115
  }
48782
49116
  async getWorkspaceGitRepoUrl(workspaceId) {
48783
49117
  const response = await this.proxyRequest(
@@ -49351,7 +49685,7 @@ var STRIP_KEYS = /* @__PURE__ */ new Set([
49351
49685
  "discriminator",
49352
49686
  "format"
49353
49687
  ]);
49354
- function asRecord2(value) {
49688
+ function asRecord3(value) {
49355
49689
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
49356
49690
  return value;
49357
49691
  }
@@ -49363,7 +49697,7 @@ function decodePointerSegment(segment) {
49363
49697
  }
49364
49698
  function resolvePointer(root, ref) {
49365
49699
  if (!ref.startsWith("#/")) return void 0;
49366
- return ref.slice(2).split("/").map(decodePointerSegment).reduce((node, segment) => asRecord2(node)?.[segment], root);
49700
+ return ref.slice(2).split("/").map(decodePointerSegment).reduce((node, segment) => asRecord3(node)?.[segment], root);
49367
49701
  }
49368
49702
  function unsupported(message) {
49369
49703
  return { unsupported: message };
@@ -49373,7 +49707,7 @@ function mergeRequiredWithoutWriteOnly(required, writeOnlyProperties) {
49373
49707
  return values.length > 0 ? values : void 0;
49374
49708
  }
49375
49709
  function hasUnsupported(child2) {
49376
- return asRecord2(child2)?.unsupported;
49710
+ return asRecord3(child2)?.unsupported;
49377
49711
  }
49378
49712
  function rootDialect(root, version, schemaRecord) {
49379
49713
  if (version === "3.0") return DRAFT_07_SCHEMA_URI;
@@ -49393,7 +49727,7 @@ function normalizeSchema(root, schema2, options) {
49393
49727
  const bad = normalized2.map(hasUnsupported).find(Boolean);
49394
49728
  return bad ? unsupported(bad) : normalized2;
49395
49729
  }
49396
- const record = asRecord2(schema2);
49730
+ const record = asRecord3(schema2);
49397
49731
  if (!record) return schema2;
49398
49732
  const ref = typeof record.$ref === "string" ? record.$ref : "";
49399
49733
  if (ref) {
@@ -49428,10 +49762,10 @@ function normalizeSchema(root, schema2, options) {
49428
49762
  const nullable = sourceSchema.nullable === true && options.version === "3.0";
49429
49763
  delete sourceSchema.nullable;
49430
49764
  const writeOnlyProperties = /* @__PURE__ */ new Set();
49431
- const rawProperties = asRecord2(sourceSchema.properties);
49765
+ const rawProperties = asRecord3(sourceSchema.properties);
49432
49766
  if (rawProperties) {
49433
49767
  for (const [propertyName, propertySchema] of Object.entries(rawProperties)) {
49434
- if (asRecord2(propertySchema)?.writeOnly === true) writeOnlyProperties.add(propertyName);
49768
+ if (asRecord3(propertySchema)?.writeOnly === true) writeOnlyProperties.add(propertyName);
49435
49769
  }
49436
49770
  }
49437
49771
  const normalized = {};
@@ -49463,7 +49797,7 @@ function normalizeSchema(root, schema2, options) {
49463
49797
  return unsupported("Tuple array items are unsupported in OpenAPI 3.0");
49464
49798
  }
49465
49799
  if (key === "properties") {
49466
- const properties = asRecord2(value);
49800
+ const properties = asRecord3(value);
49467
49801
  if (!properties) continue;
49468
49802
  const nextProperties = {};
49469
49803
  for (const [propertyName, propertySchema] of Object.entries(properties)) {
@@ -49506,7 +49840,7 @@ function normalizeSchema(root, schema2, options) {
49506
49840
  }
49507
49841
  function packSchema(root, schema2, version) {
49508
49842
  try {
49509
- const dialect = rootDialect(root, version, asRecord2(schema2) ?? void 0);
49843
+ const dialect = rootDialect(root, version, asRecord3(schema2) ?? void 0);
49510
49844
  const normalized = normalizeSchema(root, schema2, { version, rootSchema: true, dialect });
49511
49845
  const message = hasUnsupported(normalized);
49512
49846
  return message ? unsupported(message) : { schema: normalized };
@@ -49517,7 +49851,7 @@ function packSchema(root, schema2, version) {
49517
49851
 
49518
49852
  // src/lib/spec/contract-index.ts
49519
49853
  var HTTP_METHODS = /* @__PURE__ */ new Set(["get", "put", "post", "delete", "options", "head", "patch", "trace"]);
49520
- function asRecord3(value) {
49854
+ function asRecord4(value) {
49521
49855
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
49522
49856
  return value;
49523
49857
  }
@@ -49534,12 +49868,12 @@ function detectOpenApiVersion(root) {
49534
49868
  return match[1] === "1" ? "3.1" : "3.0";
49535
49869
  }
49536
49870
  function resolveInternalRef(root, value) {
49537
- const record = asRecord3(value);
49871
+ const record = asRecord4(value);
49538
49872
  if (!record) return null;
49539
49873
  const ref = typeof record.$ref === "string" ? record.$ref : "";
49540
49874
  if (!ref) return record;
49541
49875
  if (!ref.startsWith("#/")) throw new Error(`CONTRACT_UNRESOLVED_REF: External ref remained after bundling: ${ref}`);
49542
- const resolved = asRecord3(resolvePointer(root, ref));
49876
+ const resolved = asRecord4(resolvePointer(root, ref));
49543
49877
  if (!resolved) throw new Error(`CONTRACT_UNRESOLVED_REF: Unresolved OpenAPI $ref: ${ref}`);
49544
49878
  return resolved;
49545
49879
  }
@@ -49559,11 +49893,11 @@ function normalizePath(path8) {
49559
49893
  return trimmed.split("/").map((segment, index) => index === 0 ? "" : safeDecodeSegment(segment)).join("/") || "/";
49560
49894
  }
49561
49895
  function pathItemServers(pathItem) {
49562
- return asArray2(pathItem.servers).map((entry) => asRecord3(entry)).map((entry) => typeof entry?.url === "string" ? entry.url : "").filter(Boolean);
49896
+ return asArray2(pathItem.servers).map((entry) => asRecord4(entry)).map((entry) => typeof entry?.url === "string" ? entry.url : "").filter(Boolean);
49563
49897
  }
49564
49898
  function operationServers(root, pathItem, operation) {
49565
49899
  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);
49900
+ const values = rawServers.map((entry) => asRecord4(entry)).map((entry) => typeof entry?.url === "string" ? entry.url : "").filter(Boolean);
49567
49901
  return values.length > 0 ? values : [""];
49568
49902
  }
49569
49903
  function serverPathPrefix(url) {
@@ -49584,10 +49918,10 @@ function normalizeResponseKey(status) {
49584
49918
  return /^[1-5]xx$/i.test(raw) ? raw.toUpperCase() : raw;
49585
49919
  }
49586
49920
  function collectSecurityApiKeys(root, operation) {
49587
- const securitySchemes = asRecord3(asRecord3(root.components)?.securitySchemes);
49921
+ const securitySchemes = asRecord4(asRecord4(root.components)?.securitySchemes);
49588
49922
  const requirements = operation.security === void 0 ? asArray2(root.security) : asArray2(operation.security);
49589
49923
  const names = /* @__PURE__ */ new Set();
49590
- for (const requirement of requirements.map((entry) => asRecord3(entry)).filter(Boolean)) {
49924
+ for (const requirement of requirements.map((entry) => asRecord4(entry)).filter(Boolean)) {
49591
49925
  for (const schemeName of Object.keys(requirement)) {
49592
49926
  const scheme = resolveInternalRef(root, securitySchemes?.[schemeName]);
49593
49927
  if (scheme?.type === "apiKey" && typeof scheme.name === "string" && ["query", "header"].includes(String(scheme.in))) {
@@ -49605,10 +49939,10 @@ function securitySchemeKind(scheme) {
49605
49939
  return type2;
49606
49940
  }
49607
49941
  function collectSecuritySchemeWarnings(root, operation) {
49608
- const securitySchemes = asRecord3(asRecord3(root.components)?.securitySchemes);
49942
+ const securitySchemes = asRecord4(asRecord4(root.components)?.securitySchemes);
49609
49943
  const requirements = operation.security === void 0 ? asArray2(root.security) : asArray2(operation.security);
49610
49944
  const warnings = /* @__PURE__ */ new Set();
49611
- for (const requirement of requirements.map((entry) => asRecord3(entry)).filter(Boolean)) {
49945
+ for (const requirement of requirements.map((entry) => asRecord4(entry)).filter(Boolean)) {
49612
49946
  for (const schemeName of Object.keys(requirement)) {
49613
49947
  const scheme = resolveInternalRef(root, securitySchemes?.[schemeName]);
49614
49948
  warnings.add(
@@ -49644,24 +49978,24 @@ function collectParameters(root, pathItem, operation) {
49644
49978
  function collectRequestBody(root, operation) {
49645
49979
  const body = resolveInternalRef(root, operation.requestBody);
49646
49980
  if (!body || body.required !== true) return void 0;
49647
- const content = asRecord3(body.content);
49981
+ const content = asRecord4(body.content);
49648
49982
  return {
49649
49983
  required: true,
49650
49984
  contentTypes: content ? Object.keys(content) : []
49651
49985
  };
49652
49986
  }
49653
49987
  function responseContent(root, version, response) {
49654
- const content = asRecord3(response.content);
49988
+ const content = asRecord4(response.content);
49655
49989
  if (!content) return {};
49656
49990
  const media = {};
49657
49991
  for (const [contentType, mediaObject] of Object.entries(content)) {
49658
- const schema2 = asRecord3(mediaObject)?.schema;
49992
+ const schema2 = asRecord4(mediaObject)?.schema;
49659
49993
  media[contentType] = schema2 === void 0 ? {} : packSchema(root, schema2, version);
49660
49994
  }
49661
49995
  return media;
49662
49996
  }
49663
49997
  function responseHeaders(root, version, response) {
49664
- const headers = asRecord3(response.headers);
49998
+ const headers = asRecord4(response.headers);
49665
49999
  if (!headers) return [];
49666
50000
  return Object.entries(headers).map(([name, rawHeader]) => {
49667
50001
  const header = resolveInternalRef(root, rawHeader);
@@ -49676,10 +50010,10 @@ function buildContractIndex(root) {
49676
50010
  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
50011
  if (!("openapi" in root)) throw new Error("CONTRACT_UNSUPPORTED_OPENAPI_VERSION: Dynamic contract tests require OpenAPI 3.0 or 3.1 (missing openapi)");
49678
50012
  const version = detectOpenApiVersion(root);
49679
- const paths = asRecord3(root.paths);
50013
+ const paths = asRecord4(root.paths);
49680
50014
  const operations = [];
49681
50015
  const warnings = [];
49682
- if (asRecord3(root.webhooks)) warnings.push("CONTRACT_WEBHOOKS_NOT_VALIDATED: OpenAPI webhooks are not validated by dynamic contract tests");
50016
+ if (asRecord4(root.webhooks)) warnings.push("CONTRACT_WEBHOOKS_NOT_VALIDATED: OpenAPI webhooks are not validated by dynamic contract tests");
49683
50017
  if (paths) {
49684
50018
  for (const [path8, rawPathItem] of Object.entries(paths)) {
49685
50019
  const pathItem = resolveInternalRef(root, rawPathItem);
@@ -49690,7 +50024,7 @@ function buildContractIndex(root) {
49690
50024
  const operation = resolveInternalRef(root, rawOperation);
49691
50025
  if (!operation) continue;
49692
50026
  if (operation.callbacks) warnings.push(`CONTRACT_CALLBACKS_NOT_VALIDATED: callbacks are not validated for ${lowerMethod.toUpperCase()} ${path8}`);
49693
- const responses = asRecord3(operation.responses);
50027
+ const responses = asRecord4(operation.responses);
49694
50028
  if (!responses || Object.keys(responses).length === 0) {
49695
50029
  throw new Error(`CONTRACT_OPERATION_NO_RESPONSES: ${lowerMethod.toUpperCase()} ${path8} must define at least one response`);
49696
50030
  }
@@ -49780,7 +50114,7 @@ var CONTRACT_SIZE_LIMITS = {
49780
50114
  maxTestScriptBytes: 9e5,
49781
50115
  maxCollectionUpdateBytes: 4e6
49782
50116
  };
49783
- function asRecord4(value) {
50117
+ function asRecord5(value) {
49784
50118
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
49785
50119
  return value;
49786
50120
  }
@@ -49789,7 +50123,7 @@ function asArray3(value) {
49789
50123
  }
49790
50124
  function stringifyPathSegment(segment) {
49791
50125
  if (typeof segment === "string") return segment;
49792
- const record = asRecord4(segment);
50126
+ const record = asRecord5(segment);
49793
50127
  if (!record) return String(segment ?? "");
49794
50128
  for (const key of ["value", "key", "name"]) {
49795
50129
  if (typeof record[key] === "string" && record[key]) return String(record[key]);
@@ -49807,10 +50141,10 @@ function pathFromRaw(raw) {
49807
50141
  }
49808
50142
  }
49809
50143
  function requestPath(request) {
49810
- const record = asRecord4(request);
50144
+ const record = asRecord5(request);
49811
50145
  const url = record?.url ?? request;
49812
50146
  if (typeof url === "string") return pathFromRaw(url);
49813
- const urlRecord = asRecord4(url);
50147
+ const urlRecord = asRecord5(url);
49814
50148
  if (!urlRecord) return "/";
49815
50149
  if (Array.isArray(urlRecord.path)) return normalizePath(`/${urlRecord.path.map(stringifyPathSegment).filter(Boolean).join("/")}`);
49816
50150
  if (typeof urlRecord.path === "string") return normalizePath(urlRecord.path);
@@ -49842,7 +50176,7 @@ function matchCandidate(candidate, request) {
49842
50176
  return { matched: true, staticCount, templateCount };
49843
50177
  }
49844
50178
  function matchOperation(index, request) {
49845
- const record = asRecord4(request);
50179
+ const record = asRecord5(request);
49846
50180
  const method = String(record?.method || "").toUpperCase();
49847
50181
  const path8 = requestPath(request);
49848
50182
  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 +50327,17 @@ function createSecretsResolverItem() {
49993
50327
  }
49994
50328
  function isResolverItem(item) {
49995
50329
  if (item.name !== "00 - Resolve Secrets") return false;
49996
- const request = asRecord4(item.request);
50330
+ const request = asRecord5(item.request);
49997
50331
  if (String(request?.method || "").toUpperCase() !== "POST") return false;
49998
- const headers = asArray3(request?.header).map((entry) => asRecord4(entry));
50332
+ const headers = asArray3(request?.header).map((entry) => asRecord5(entry));
49999
50333
  const target = headers.find((entry) => entry?.key === "X-Amz-Target");
50000
50334
  return String(target?.value || "") === "secretsmanager.GetSecretValue" && !requestPath(request).includes("secretsmanager");
50001
50335
  }
50002
50336
  function requestQueryNames(request) {
50003
- const url = asRecord4(request.url);
50337
+ const url = asRecord5(request.url);
50004
50338
  const names = /* @__PURE__ */ new Set();
50005
50339
  if (Array.isArray(url?.query)) {
50006
- for (const entry of url.query.map((item) => asRecord4(item)).filter(Boolean)) {
50340
+ for (const entry of url.query.map((item) => asRecord5(item)).filter(Boolean)) {
50007
50341
  if (entry.disabled !== true && typeof entry.key === "string") names.add(entry.key.toLowerCase());
50008
50342
  }
50009
50343
  }
@@ -50018,17 +50352,17 @@ function requestQueryNames(request) {
50018
50352
  }
50019
50353
  function requestHeaderNames(request) {
50020
50354
  const names = /* @__PURE__ */ new Set();
50021
- for (const entry of asArray3(request.header).map((item) => asRecord4(item)).filter(Boolean)) {
50355
+ for (const entry of asArray3(request.header).map((item) => asRecord5(item)).filter(Boolean)) {
50022
50356
  if (entry.disabled !== true && typeof entry.key === "string") names.add(entry.key.toLowerCase());
50023
50357
  }
50024
50358
  return names;
50025
50359
  }
50026
50360
  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);
50361
+ const match = asArray3(request.header).map((item) => asRecord5(item)).filter(Boolean).find((entry) => String(entry.key || "").toLowerCase() === name.toLowerCase() && entry.disabled !== true);
50028
50362
  return typeof match?.value === "string" ? match.value : void 0;
50029
50363
  }
50030
50364
  function hasRequestBody(request) {
50031
- const body = asRecord4(request.body);
50365
+ const body = asRecord5(request.body);
50032
50366
  if (!body) return false;
50033
50367
  if (typeof body.raw === "string" && body.raw.trim()) return true;
50034
50368
  return ["urlencoded", "formdata", "graphql"].some((key) => Array.isArray(body[key]) ? body[key].length > 0 : Boolean(body[key]));
@@ -50079,21 +50413,21 @@ function validateScript(script) {
50079
50413
  return void 0;
50080
50414
  }
50081
50415
  function scriptExecLines(script) {
50082
- const record = asRecord4(script);
50416
+ const record = asRecord5(script);
50083
50417
  if (!record) return [];
50084
50418
  if (Array.isArray(record.exec)) return record.exec.map((line) => String(line));
50085
50419
  if (typeof record.exec === "string") return [record.exec];
50086
50420
  return [];
50087
50421
  }
50088
50422
  function scanExecutableScripts(node, warnings) {
50089
- for (const event of asArray3(node.event).map((entry) => asRecord4(entry)).filter(Boolean)) {
50423
+ for (const event of asArray3(node.event).map((entry) => asRecord5(entry)).filter(Boolean)) {
50090
50424
  const lines = scriptExecLines(event.script);
50091
50425
  if (lines.length === 0) continue;
50092
50426
  const warning2 = validateScript(lines);
50093
50427
  if (warning2) warnings.push(warning2);
50094
50428
  }
50095
50429
  for (const child2 of asArray3(node.item)) {
50096
- const childRecord = asRecord4(child2);
50430
+ const childRecord = asRecord5(child2);
50097
50431
  if (childRecord) scanExecutableScripts(childRecord, warnings);
50098
50432
  }
50099
50433
  }
@@ -50103,7 +50437,7 @@ function instrumentContractCollection(collection, index) {
50103
50437
  const inject = (item) => {
50104
50438
  if (isResolverItem(item)) return;
50105
50439
  if (item.request) {
50106
- const request = asRecord4(item.request) ?? {};
50440
+ const request = asRecord5(item.request) ?? {};
50107
50441
  const result = matchOperation(index, request);
50108
50442
  let script;
50109
50443
  if (result.operation) {
@@ -50117,15 +50451,15 @@ function instrumentContractCollection(collection, index) {
50117
50451
  } else {
50118
50452
  script = createMappingFailureScript(`No OpenAPI operation matched request ${result.method} ${result.path}`);
50119
50453
  }
50120
- const events2 = asArray3(item.event).filter((entry) => asRecord4(entry)?.listen !== "test");
50454
+ const events2 = asArray3(item.event).filter((entry) => asRecord5(entry)?.listen !== "test");
50121
50455
  item.event = [...events2, { listen: "test", script: { type: "text/javascript", exec: script } }];
50122
50456
  }
50123
50457
  for (const child2 of asArray3(item.item)) {
50124
- const childRecord = asRecord4(child2);
50458
+ const childRecord = asRecord5(child2);
50125
50459
  if (childRecord) inject(childRecord);
50126
50460
  }
50127
50461
  };
50128
- const items = asArray3(collection.item).map((entry) => asRecord4(entry)).filter((entry) => Boolean(entry)).filter((entry) => !isResolverItem(entry));
50462
+ const items = asArray3(collection.item).map((entry) => asRecord5(entry)).filter((entry) => Boolean(entry)).filter((entry) => !isResolverItem(entry));
50129
50463
  collection.item = items;
50130
50464
  for (const item of items) inject(item);
50131
50465
  const missing = index.operations.filter((operation) => !covered.has(operation.id));
@@ -62489,7 +62823,7 @@ function compileErrors(result) {
62489
62823
 
62490
62824
  // src/lib/spec/openapi-loader.ts
62491
62825
  var import_yaml2 = __toESM(require_dist(), 1);
62492
- function asRecord5(value) {
62826
+ function asRecord6(value) {
62493
62827
  if (!value || typeof value !== "object" || Array.isArray(value)) return null;
62494
62828
  return value;
62495
62829
  }
@@ -62504,7 +62838,7 @@ function parseOpenApiDocument(content) {
62504
62838
  throw new Error("CONTRACT_SPEC_PARSE_FAILED: Spec content is not valid JSON or YAML");
62505
62839
  }
62506
62840
  }
62507
- const doc = asRecord5(parsed);
62841
+ const doc = asRecord6(parsed);
62508
62842
  if (!doc) throw new Error("CONTRACT_SPEC_PARSE_FAILED: Spec content must be a JSON or YAML object");
62509
62843
  return doc;
62510
62844
  }
@@ -62532,7 +62866,7 @@ function collectExternalRefs(node, baseUrl, refs) {
62532
62866
  node.forEach((entry) => collectExternalRefs(entry, baseUrl, refs));
62533
62867
  return;
62534
62868
  }
62535
- const record = asRecord5(node);
62869
+ const record = asRecord6(node);
62536
62870
  if (!record) return;
62537
62871
  const ref = typeof record.$ref === "string" ? record.$ref : "";
62538
62872
  if (ref && !ref.startsWith("#")) {
@@ -62870,6 +63204,11 @@ function resolveInputs(env = process.env) {
62870
63204
  governanceMappingJson: parseGovernanceMappingJson(getInput2("governance-mapping-json", env)),
62871
63205
  postmanApiKey: getInput2("postman-api-key", env) ?? "",
62872
63206
  postmanAccessToken: getInput2("postman-access-token", env),
63207
+ credentialPreflight: parseEnumInput(
63208
+ "credential-preflight",
63209
+ getInput2("credential-preflight", env),
63210
+ customerPreviewActionContract.inputs["credential-preflight"].default ?? "warn"
63211
+ ),
62873
63212
  integrationBackend,
62874
63213
  folderStrategy: parseEnumInput("folder-strategy", getInput2("folder-strategy", env), "Paths"),
62875
63214
  nestedFolderHierarchy: parseBooleanInput("nested-folder-hierarchy", getInput2("nested-folder-hierarchy", env), false),
@@ -62879,6 +63218,7 @@ function resolveInputs(env = process.env) {
62879
63218
  postmanBifrostBase: endpointProfile.bifrostBaseUrl,
62880
63219
  postmanGatewayBase: endpointProfile.gatewayBaseUrl,
62881
63220
  postmanCliInstallUrl: endpointProfile.cliInstallUrl,
63221
+ postmanIapubBase: endpointProfile.iapubBaseUrl,
62882
63222
  githubRefName: env.GITHUB_REF_NAME,
62883
63223
  githubHeadRef: env.GITHUB_HEAD_REF,
62884
63224
  githubRef: env.GITHUB_REF,
@@ -62967,6 +63307,7 @@ function readActionInputs(actionCore) {
62967
63307
  INPUT_GOVERNANCE_MAPPING_JSON: optionalInput(actionCore, "governance-mapping-json") ?? customerPreviewActionContract.inputs["governance-mapping-json"].default,
62968
63308
  INPUT_POSTMAN_API_KEY: postmanApiKey,
62969
63309
  INPUT_POSTMAN_ACCESS_TOKEN: postmanAccessToken,
63310
+ INPUT_CREDENTIAL_PREFLIGHT: optionalInput(actionCore, "credential-preflight") ?? customerPreviewActionContract.inputs["credential-preflight"].default,
62970
63311
  INPUT_INTEGRATION_BACKEND: optionalInput(actionCore, "integration-backend") ?? customerPreviewActionContract.inputs["integration-backend"].default,
62971
63312
  INPUT_FOLDER_STRATEGY: optionalInput(actionCore, "folder-strategy") ?? customerPreviewActionContract.inputs["folder-strategy"].default,
62972
63313
  INPUT_NESTED_FOLDER_HIERARCHY: optionalInput(actionCore, "nested-folder-hierarchy") ?? customerPreviewActionContract.inputs["nested-folder-hierarchy"].default,
@@ -63478,8 +63819,20 @@ For CLI usage, pass --workspace-team-id <id> or export POSTMAN_WORKSPACE_TEAM_ID
63478
63819
  governanceGroupName
63479
63820
  );
63480
63821
  } catch (error2) {
63822
+ const session = getMemoizedSessionIdentity();
63823
+ const advised = error2 instanceof HttpError ? adviseFromHttpError(error2, {
63824
+ operation: "governance assignment",
63825
+ hasAccessToken: Boolean(inputs.postmanAccessToken),
63826
+ sessionTeamId: session?.teamId,
63827
+ sessionRoles: session?.roles,
63828
+ sessionConsumerType: session?.consumerType,
63829
+ workspaceTeamId: inputs.workspaceTeamId,
63830
+ explicitTeamId: inputs.teamId || void 0,
63831
+ mask: createSecretMasker([inputs.postmanApiKey, inputs.postmanAccessToken])
63832
+ }) : void 0;
63833
+ const reported = advised ?? error2;
63481
63834
  dependencies.core.warning(
63482
- `Failed to assign governance group: ${error2 instanceof Error ? error2.message : String(error2)}`
63835
+ `Failed to assign governance group: ${reported instanceof Error ? reported.message : String(reported)}`
63483
63836
  );
63484
63837
  }
63485
63838
  }
@@ -64066,6 +64419,17 @@ For CLI usage, pass --workspace-team-id <id> or export POSTMAN_WORKSPACE_TEAM_ID
64066
64419
  }
64067
64420
  async function runAction(actionCore = core_exports, actionExec = exec_exports, actionIo = io_exports) {
64068
64421
  const inputs = readActionInputs(actionCore);
64422
+ await runCredentialPreflight({
64423
+ apiBaseUrl: inputs.postmanApiBase,
64424
+ iapubBaseUrl: inputs.postmanIapubBase,
64425
+ postmanApiKey: inputs.postmanApiKey,
64426
+ postmanAccessToken: inputs.postmanAccessToken,
64427
+ workspaceTeamId: inputs.workspaceTeamId,
64428
+ explicitTeamId: inputs.teamId || void 0,
64429
+ mode: inputs.credentialPreflight,
64430
+ mask: createSecretMasker([inputs.postmanApiKey, inputs.postmanAccessToken]),
64431
+ log: actionCore
64432
+ });
64069
64433
  let orgMode = false;
64070
64434
  if (inputs.postmanAccessToken && inputs.teamId) {
64071
64435
  try {