{"version":3,"sources":["../../src/v0/sdk-deprecation-headers.ts"],"sourcesContent":["/**\n * SDK deprecation warning headers — OpenAPI documentation.\n *\n * The API may attach `zapier-sdk-deprecation-*` response headers to a\n * response — any response — when sdkapi's version gate or a trusted Zapier\n * upstream service needs SDK clients to raise a deprecation notice. The\n * version gate is a global response hook on the server, so every documented\n * response — SDK API and Builder Tools API alike — may carry the headers.\n *\n * `documentSdkDeprecationHeaders` is the single writer of that\n * documentation: the SDK spec generator applies it to the published\n * openapi.yaml, and the spec merge in @zapier/openapi-spec applies it to\n * openapi-merged.yaml so Builder Tools responses are covered too. The\n * mutation is idempotent — already-documented headers are preserved.\n *\n * The headers are documented inline (`required: false`) rather than as\n * `$ref`'d components: openapi-typescript v6 cannot see requiredness\n * through a header `$ref` and would type the headers as always-present,\n * overstating the conditional runtime contract.\n */\n\nconst SDK_DEPRECATION_RESPONSE_HEADERS = {\n  \"zapier-sdk-deprecation-id\": {\n    description:\n      \"Stable identifier for an active SDK deprecation notice; clients use it to dedupe repeated notices. Only present when a trusted Zapier service raises an SDK-visible deprecation notice.\",\n    required: false,\n    schema: { type: \"string\" },\n  },\n  \"zapier-sdk-deprecation-message\": {\n    description:\n      \"Human-readable SDK deprecation warning, displayed verbatim by the Zapier SDK. Only present when a trusted Zapier service raises an SDK-visible deprecation notice.\",\n    required: false,\n    schema: { type: \"string\" },\n  },\n};\n\nconst HTTP_METHODS = [\n  \"get\",\n  \"post\",\n  \"put\",\n  \"patch\",\n  \"delete\",\n  \"head\",\n  \"options\",\n] as const;\n\n/**\n * Minimal structural view of an OpenAPI document; both the zod-to-openapi\n * generator output and the YAML-parsed merge documents satisfy it.\n */\ninterface OpenAPIDocumentLike {\n  paths?: Record<string, unknown>;\n}\n\n/**\n * Document the SDK deprecation headers on every response.\n */\nexport function documentSdkDeprecationHeaders(\n  document: OpenAPIDocumentLike,\n): void {\n  for (const pathItem of Object.values(document.paths ?? {})) {\n    if (!pathItem || typeof pathItem !== \"object\") continue;\n    for (const method of HTTP_METHODS) {\n      const operation = (pathItem as Record<string, unknown>)[method];\n      if (!operation || typeof operation !== \"object\") continue;\n      const responses = (operation as Record<string, unknown>).responses;\n      if (!responses || typeof responses !== \"object\") continue;\n      for (const response of Object.values(responses)) {\n        if (!response || typeof response !== \"object\") continue;\n        const responseObject = response as {\n          headers?: Record<string, unknown>;\n        };\n        responseObject.headers = {\n          ...SDK_DEPRECATION_RESPONSE_HEADERS,\n          ...responseObject.headers,\n        };\n      }\n    }\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqBA,IAAM,mCAAmC;AAAA,EACvC,6BAA6B;AAAA,IAC3B,aACE;AAAA,IACF,UAAU;AAAA,IACV,QAAQ,EAAE,MAAM,SAAS;AAAA,EAC3B;AAAA,EACA,kCAAkC;AAAA,IAChC,aACE;AAAA,IACF,UAAU;AAAA,IACV,QAAQ,EAAE,MAAM,SAAS;AAAA,EAC3B;AACF;AAEA,IAAM,eAAe;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAaO,SAAS,8BACd,UACM;AACN,aAAW,YAAY,OAAO,OAAO,SAAS,SAAS,CAAC,CAAC,GAAG;AAC1D,QAAI,CAAC,YAAY,OAAO,aAAa,SAAU;AAC/C,eAAW,UAAU,cAAc;AACjC,YAAM,YAAa,SAAqC,MAAM;AAC9D,UAAI,CAAC,aAAa,OAAO,cAAc,SAAU;AACjD,YAAM,YAAa,UAAsC;AACzD,UAAI,CAAC,aAAa,OAAO,cAAc,SAAU;AACjD,iBAAW,YAAY,OAAO,OAAO,SAAS,GAAG;AAC/C,YAAI,CAAC,YAAY,OAAO,aAAa,SAAU;AAC/C,cAAM,iBAAiB;AAGvB,uBAAe,UAAU;AAAA,UACvB,GAAG;AAAA,UACH,GAAG,eAAe;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}