"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.signMiddlewareFactory=signMiddlewareFactory;const faas_server_utils_1=require("@alipay/faas-server-utils");function signMiddlewareFactory(t,a){return async function(e,d){const n=(0,faas_server_utils_1.getAlipayContext)(),i=Date.now(),r={authorization:"","x-from-app-id":n.APPID,"x-from-env-id":e.config.fromEnvId,"x-to-env-id":e.config.toEnvId,"x-from-instance-id":e.config.functionInstanceId,"x-from-function-name":e.config.functionName,"x-client-timestamp":`${i}`,"x-trace-id":n.TRACEID,"sofa-rpcid":`${n.RPCID}.${++n.rpcCount}`};t.length>0&&t.forEach(s=>{r[s]=e.req.requestOptions.headers?.[s]});const u=["x-from-app-id","x-from-env-id","x-from-instance-id","x-from-function-name","x-client-timestamp","x-to-env-id",...t].sort(),o={path:a?.decodePath?decodeURIComponent(e.req.url.pathname):e.req.url.pathname,query:e.req.url.search.substring(1),secretId:e.config.secretId,secretKey:e.config.secretKey,method:e.req.requestOptions.method,headers:r,body:e.req.signedBody||e.req.requestOptions.content,timestamp:i,signedHeaders:u};o.secretId&&(r.authorization=(0,faas_server_utils_1.sign)(o)),e.req.requestOptions.headers={...r,...e.req.requestOptions.headers},await d()}}