{"version":3,"file":"cloudflare-turnstile.mjs","names":[],"sources":["../../../../src/plugins/captcha/verify-handlers/cloudflare-turnstile.ts"],"sourcesContent":["import { betterFetch } from \"@better-fetch/fetch\";\nimport { middlewareResponse } from \"../../../utils/middleware-response\";\nimport { EXTERNAL_ERROR_CODES, INTERNAL_ERROR_CODES } from \"../error-codes\";\n\ntype Params = {\n\tsiteVerifyURL: string;\n\tsecretKey: string;\n\tcaptchaResponse: string;\n\tremoteIP?: string | undefined;\n};\n\ntype SiteVerifyResponse = {\n\tsuccess: boolean;\n\t\"error-codes\"?: string[] | undefined;\n\tchallenge_ts?: string | undefined;\n\thostname?: string | undefined;\n\taction?: string | undefined;\n\tcdata?: string | undefined;\n\tmetadata?:\n\t\t| {\n\t\t\t\tinteractive: boolean;\n\t\t  }\n\t\t| undefined;\n\tmessages?: string[] | undefined;\n};\n\nexport const cloudflareTurnstile = async ({\n\tsiteVerifyURL,\n\tcaptchaResponse,\n\tsecretKey,\n\tremoteIP,\n}: Params) => {\n\tconst response = await betterFetch<SiteVerifyResponse>(siteVerifyURL, {\n\t\tmethod: \"POST\",\n\t\theaders: { \"Content-Type\": \"application/json\" },\n\t\tbody: JSON.stringify({\n\t\t\tsecret: secretKey,\n\t\t\tresponse: captchaResponse,\n\t\t\t...(remoteIP && { remoteip: remoteIP }),\n\t\t}),\n\t});\n\n\tif (!response.data || response.error) {\n\t\tthrow new Error(INTERNAL_ERROR_CODES.SERVICE_UNAVAILABLE);\n\t}\n\n\tif (!response.data.success) {\n\t\treturn middlewareResponse({\n\t\t\tmessage: EXTERNAL_ERROR_CODES.VERIFICATION_FAILED,\n\t\t\tstatus: 403,\n\t\t});\n\t}\n\n\treturn undefined;\n};\n"],"mappings":";;;;;AA0BA,MAAa,sBAAsB,OAAO,EACzC,eACA,iBACA,WACA,eACa;CACb,MAAM,WAAW,MAAM,YAAgC,eAAe;EACrE,QAAQ;EACR,SAAS,EAAE,gBAAgB,oBAAoB;EAC/C,MAAM,KAAK,UAAU;GACpB,QAAQ;GACR,UAAU;GACV,GAAI,YAAY,EAAE,UAAU,UAAU;GACtC,CAAC;EACF,CAAC;AAEF,KAAI,CAAC,SAAS,QAAQ,SAAS,MAC9B,OAAM,IAAI,MAAM,qBAAqB,oBAAoB;AAG1D,KAAI,CAAC,SAAS,KAAK,QAClB,QAAO,mBAAmB;EACzB,SAAS,qBAAqB;EAC9B,QAAQ;EACR,CAAC"}