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AM,OAAA,CAAQ,OAAO,CAAA;AACtC,IAAA,MAAM,aAAA,CAAc,UAAU,GAAG,CAAA;AAAA,EACnC,CAAA;AACF;AAOO,IAAM,eAAA,GAAkB","file":"index.cjs","sourcesContent":["// @pandait.tech/payment-nuvei/adapters\n//\n// Runtime adapters that let the package's Web-standard handlers\n// (`(req: Request) => Promise<Response>`) run on Node/Express-style runtimes\n// such as Firebase Cloud Functions v2 (`onRequest`) or Express.\n//\n// Next.js App Router needs NO adapter — its route handlers already receive a\n// `Request` and accept a `Response`, so you export the handler directly:\n//   export const POST = createChargeHandler(deps);\n//\n// Cloud Functions v2 / Express need this bridge because they use the\n// `(req, res)` signature instead of `Request -> Response`:\n//   exports.threeDSCallback = onRequest({ cors: true },\n//     toCloudFunction(create3dsCallbackHandler({ firebase: { db } }).POST));\n\n/** Minimal structural type for a Node/Express-style request. */\nexport interface NodeRequestLike {\n  method?: string;\n  url?: string;\n  originalUrl?: string;\n  headers: Record<string, string | string[] | undefined>;\n  /** Raw request body. Cloud Functions v2 provides this as a Buffer. */\n  rawBody?: Buffer | Uint8Array;\n  /** Parsed body (Express/Functions populate this for JSON/urlencoded). */\n  body?: unknown;\n}\n\n/** Minimal structural type for a Node/Express-style response. */\nexport interface NodeResponseLike {\n  statusCode: number;\n  setHeader(name: string, value: string): void;\n  end(chunk?: string | Uint8Array): void;\n}\n\n/** A Web-standard handler: takes a Fetch `Request`, returns a `Response`. */\nexport type WebHandler = (request: Request) => Promise<Response> | Response;\n\n/** A Node/Express-style handler: `(req, res)`. */\nexport type NodeHandler = (\n  req: NodeRequestLike,\n  res: NodeResponseLike,\n) => Promise<void>;\n\nfunction buildRequest(req: NodeRequestLike): Request {\n  const headerList = req.headers ?? {};\n  const host =\n    (Array.isArray(headerList.host) ? headerList.host[0] : headerList.host) ||\n    \"localhost\";\n  const protoHeader =\n    headerList[\"x-forwarded-proto\"] ?? headerList[\"X-Forwarded-Proto\"];\n  const proto =\n    (Array.isArray(protoHeader) ? protoHeader[0] : protoHeader) || \"https\";\n  const path = req.originalUrl ?? req.url ?? \"/\";\n  const url = new URL(path, `${proto}://${host}`).toString();\n\n  const headers = new Headers();\n  for (const [key, value] of Object.entries(headerList)) {\n    if (value === undefined) continue;\n    if (Array.isArray(value)) {\n      for (const v of value) headers.append(key, v);\n    } else {\n      headers.set(key, value);\n    }\n  }\n\n  const method = (req.method ?? \"GET\").toUpperCase();\n  let body: string | undefined;\n  if (method !== \"GET\" && method !== \"HEAD\") {\n    if (req.rawBody) {\n      // Bodies handled by this package are always text (JSON / form-urlencoded);\n      // decoding to a string keeps the original bytes intact and the preserved\n      // content-type header lets Request.json()/.formData()/.text() parse it.\n      body = new TextDecoder().decode(req.rawBody);\n    } else if (req.body !== undefined && req.body !== null) {\n      body =\n        typeof req.body === \"string\" ? req.body : JSON.stringify(req.body);\n      if (!headers.has(\"content-type\") && typeof req.body !== \"string\") {\n        headers.set(\"content-type\", \"application/json\");\n      }\n    }\n  }\n\n  return new Request(url, { method, headers, body });\n}\n\nasync function writeResponse(\n  response: Response,\n  res: NodeResponseLike,\n): Promise<void> {\n  res.statusCode = response.status;\n  response.headers.forEach((value, key) => {\n    // Note: these payment handlers never emit Set-Cookie, so the single-value\n    // Headers.forEach is sufficient. If a future handler sets cookies, switch\n    // to response.headers.getSetCookie() for the Set-Cookie header.\n    res.setHeader(key, value);\n  });\n  const buf = new Uint8Array(await response.arrayBuffer());\n  res.end(buf);\n}\n\n/**\n * Wrap a Web-standard handler so it runs as a Node/Express-style `(req, res)`\n * handler. Works for Express and any runtime with a compatible req/res\n * (Node `http.ServerResponse` exposes `statusCode`/`setHeader`/`end`).\n */\nexport function toExpress(handler: WebHandler): NodeHandler {\n  return async (req, res) => {\n    const request = buildRequest(req);\n    const response = await handler(request);\n    await writeResponse(response, res);\n  };\n}\n\n/**\n * Wrap a Web-standard handler for Firebase Cloud Functions v2 `onRequest`.\n * Identical bridge to {@link toExpress} (Functions v2 req/res are Express-based);\n * provided as a named export for intent at the call site.\n */\nexport const toCloudFunction = toExpress;\n"]}