@alipay/faas-server-sdk
Advanced tools
Comparing version 1.1.18-alpha.3 to 1.1.18-alpha.4
@@ -1,1 +0,1 @@ | ||
"use strict";var __importDefault=this&&this.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Httpclient=void 0;const node_assert_1=__importDefault(require("node:assert")),node_crypto_1=require("node:crypto"),node_diagnostics_channel_1=__importDefault(require("node:diagnostics_channel")),koa_compose_1=__importDefault(require("koa-compose")),faas_server_utils_1=require("@alipay/faas-server-utils"),constant_1=require("../constant"),HttpRequestContext_1=require("./HttpRequestContext"),bson_middleware_1=require("./middlewares/bson_middleware"),call_middleware_1=require("./middlewares/call_middleware"),error_handler_middleware_1=require("./middlewares/error_handler_middleware"),init_call_dataproxy_headers_middleware_1=require("./middlewares/init_call_dataproxy_headers_middleware"),init_call_functiongateway_headers_middleware_1=require("./middlewares/init_call_functiongateway_headers_middleware"),json_middleware_1=require("./middlewares/json_middleware"),sign_middleware_factory_1=require("./middlewares/sign_middleware_factory"),debug=(0,faas_server_utils_1.debuglog)("faas-server-sdk:httpRequest");class Httpclient{#t;#e;#r;constructor(t,e,s){(0,node_assert_1.default)(e,"cloud config not set"),this.#t=t,this.#e=e,this.#r=(0,koa_compose_1.default)(s)}async request(t){return(await this.requestRaw(t)).result}async requestRaw({method:t,path:e,data:s,headers:r}){const d=this.#e[this.#t]+e,i=(0,faas_server_utils_1.getAlipayContext)();r=r||{},r["x-alipay-callid"]=r["x-request-id"]=i.TRACEID||(0,node_crypto_1.randomUUID)();let n=process.env.RUNTIME_CURRENT_SOURCE||"alipay_unknown";process.env.RUNTIME_FUNCTION_NAME&&(n=`${n}:${i.ENV}:${process.env.RUNTIME_FUNCTION_NAME}`);const c=i.SOURCE||"alipay_unknown";r["x-alipay-source"]=`${c},${n}`,r["user-agent"]=constant_1.SDK_USER_AGENT,r["x-alipay-req-source"]=i.REQUEST_SOURCE,r.soure_app=i.SOURCE_APP;const o={method:t,contentType:"application/json",content:s,dataType:"json",headers:r};this.#e.timeout!==void 0&&(o.timeout=this.#e.timeout),debug("requestRaw(url:%o, options:%o)",d,o);const u={url:new URL(d),requestOptions:o},l=new HttpRequestContext_1.HttpRequestContext(u,this.#e);return await this.#r(l),l}static createFunctionHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,json_middleware_1.jsonMiddleware,(0,init_call_functiongateway_headers_middleware_1.createInitCallFunctionGatewayHeadersMiddleware)(),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-to-function-name"]),call_middleware_1.callMiddleware];return new Httpclient("functionGatewayEndpoint",t,e)}static createDatabaseHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,bson_middleware_1.bsonMiddleware,(0,init_call_dataproxy_headers_middleware_1.createInitCallDataProxyHeadersMiddleware)("mongo"),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-data-api-type","x-expire-timestamp"]),call_middleware_1.callMiddleware];return new Httpclient("functionDatabaseEndpoint",t,e)}static createStorageHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,json_middleware_1.jsonMiddleware,(0,init_call_dataproxy_headers_middleware_1.createInitCallDataProxyHeadersMiddleware)("oss"),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-data-api-type","x-expire-timestamp"]),call_middleware_1.callMiddleware];return new Httpclient("functionStorageEndpoint",t,e)}static createOpenapiHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,json_middleware_1.jsonMiddleware,(0,init_call_functiongateway_headers_middleware_1.createInitCallFunctionGatewayHeadersMiddleware)(),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-openapi","x-openapi-version"]),call_middleware_1.callMiddleware];return new Httpclient("functionGatewayEndpoint",t,e)}}exports.Httpclient=Httpclient,debug.enabled&&(node_diagnostics_channel_1.default.subscribe("urllib:request",a=>{const{request:t}=a;debug("[urllib:request] request#%s %s %o, headers: %o",t.requestId,t.args.method,t.url,t.args.headers)}),node_diagnostics_channel_1.default.subscribe("urllib:response",a=>{const{request:t,response:e,error:s}=a;debug("[urllib:response] request#%s got response %s, status: %o, size: %o, headers: %o, rt: %o, timing: %o, socket: %o, requestUrls: %o",t.requestId,s?"error":"success",e.status,e.size,e.headers,e.rt,e.timing,e.socket,e.requestUrls),s&&debug("[urllib:response] %s",s)})); | ||
"use strict";var __importDefault=this&&this.__importDefault||function(a){return a&&a.__esModule?a:{default:a}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Httpclient=void 0;const node_assert_1=__importDefault(require("node:assert")),node_crypto_1=require("node:crypto"),node_diagnostics_channel_1=__importDefault(require("node:diagnostics_channel")),koa_compose_1=__importDefault(require("koa-compose")),faas_server_utils_1=require("@alipay/faas-server-utils"),constant_1=require("../constant"),HttpRequestContext_1=require("./HttpRequestContext"),bson_middleware_1=require("./middlewares/bson_middleware"),call_middleware_1=require("./middlewares/call_middleware"),error_handler_middleware_1=require("./middlewares/error_handler_middleware"),init_call_dataproxy_headers_middleware_1=require("./middlewares/init_call_dataproxy_headers_middleware"),init_call_functiongateway_headers_middleware_1=require("./middlewares/init_call_functiongateway_headers_middleware"),json_middleware_1=require("./middlewares/json_middleware"),sign_middleware_factory_1=require("./middlewares/sign_middleware_factory"),debug=(0,faas_server_utils_1.debuglog)("faas-server-sdk:httpRequest");class Httpclient{#t;#e;#r;constructor(t,e,s){(0,node_assert_1.default)(e,"cloud config not set"),this.#t=t,this.#e=e,this.#r=(0,koa_compose_1.default)(s)}async request(t){return(await this.requestRaw(t)).result}async requestRaw({method:t,path:e,data:s,headers:r}){const d=this.#e[this.#t]+e,i=(0,faas_server_utils_1.getAlipayContext)();r=r||{},r["x-alipay-callid"]=r["x-request-id"]=i.TRACEID||(0,node_crypto_1.randomUUID)();let n=process.env.RUNTIME_CURRENT_SOURCE||"alipay_unknown";process.env.RUNTIME_FUNCTION_NAME&&(n=`${n}:${i.ENV}:${process.env.RUNTIME_FUNCTION_NAME}`);const c=i.SOURCE||"alipay_unknown";r["x-alipay-source"]=`${c},${n}`,r["user-agent"]=constant_1.SDK_USER_AGENT,r["x-alipay-req-source"]=i.REQUEST_SOURCE,r.soure_app=i.SOURCE_APP;const o={method:t,contentType:"application/json",content:s,dataType:"json",headers:r};this.#e.timeout!==void 0&&(o.timeout=this.#e.timeout),debug("requestRaw(url:%o, options:%o)",d,o);const u={url:new URL(d),requestOptions:o},l=new HttpRequestContext_1.HttpRequestContext(u,this.#e);return await this.#r(l),l}static createFunctionHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,json_middleware_1.jsonMiddleware,(0,init_call_functiongateway_headers_middleware_1.createInitCallFunctionGatewayHeadersMiddleware)(),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-to-function-name"]),call_middleware_1.callMiddleware];return new Httpclient("functionGatewayEndpoint",t,e)}static createDatabaseHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,bson_middleware_1.bsonMiddleware,(0,init_call_dataproxy_headers_middleware_1.createInitCallDataProxyHeadersMiddleware)("mongo"),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-data-api-type","x-expire-timestamp"]),call_middleware_1.callMiddleware];return new Httpclient("functionDatabaseEndpoint",t,e)}static createStorageHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,json_middleware_1.jsonMiddleware,(0,init_call_dataproxy_headers_middleware_1.createInitCallDataProxyHeadersMiddleware)("oss"),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-data-api-type","x-expire-timestamp"],{decodePath:!0}),call_middleware_1.callMiddleware];return new Httpclient("functionStorageEndpoint",t,e)}static createOpenapiHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,json_middleware_1.jsonMiddleware,(0,init_call_functiongateway_headers_middleware_1.createInitCallFunctionGatewayHeadersMiddleware)(),(0,sign_middleware_factory_1.signMiddlewareFactory)(["x-openapi","x-openapi-version"]),call_middleware_1.callMiddleware];return new Httpclient("functionGatewayEndpoint",t,e)}}exports.Httpclient=Httpclient,debug.enabled&&(node_diagnostics_channel_1.default.subscribe("urllib:request",a=>{const{request:t}=a;debug("[urllib:request] request#%s %s %o, headers: %o",t.requestId,t.args.method,t.url,t.args.headers)}),node_diagnostics_channel_1.default.subscribe("urllib:response",a=>{const{request:t,response:e,error:s}=a;debug("[urllib:response] request#%s got response %s, status: %o, size: %o, headers: %o, rt: %o, timing: %o, socket: %o, requestUrls: %o",t.requestId,s?"error":"success",e.status,e.size,e.headers,e.rt,e.timing,e.socket,e.requestUrls),s&&debug("[urllib:response] %s",s)})); |
import type { Next } from 'koa'; | ||
import { HttpRequestContext } from '../HttpRequestContext'; | ||
export declare function signMiddlewareFactory(signedHeaders: string[]): (ctx: HttpRequestContext<unknown, unknown>, next: Next) => Promise<void>; | ||
export interface SignMiddlewareOptions { | ||
decodePath?: boolean; | ||
} | ||
export declare function signMiddlewareFactory(signedHeaders: string[], options?: SignMiddlewareOptions): (ctx: HttpRequestContext<unknown, unknown>, next: Next) => Promise<void>; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.signMiddlewareFactory=void 0;const faas_server_utils_1=require("@alipay/faas-server-utils");function signMiddlewareFactory(t){return async function(e,a){const r=(0,faas_server_utils_1.getAlipayContext)(),i=Date.now(),n={authorization:"","x-from-app-id":r.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":r.TRACEID,"sofa-rpcid":`${r.RPCID}.${++r.rpcCount}`};t.length>0&&t.forEach(s=>{n[s]=e.req.requestOptions.headers?.[s]});const d=["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: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:n,body:e.req.requestOptions.content,timestamp:i,signedHeaders:d};o.secretId&&(n.authorization=(0,faas_server_utils_1.sign)(o)),e.req.requestOptions.headers={...n,...e.req.requestOptions.headers},await a()}}exports.signMiddlewareFactory=signMiddlewareFactory; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.signMiddlewareFactory=void 0;const faas_server_utils_1=require("@alipay/faas-server-utils");function signMiddlewareFactory(t,a){return async function(e,d){const r=(0,faas_server_utils_1.getAlipayContext)(),i=Date.now(),n={authorization:"","x-from-app-id":r.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":r.TRACEID,"sofa-rpcid":`${r.RPCID}.${++r.rpcCount}`};t.length>0&&t.forEach(s=>{n[s]=e.req.requestOptions.headers?.[s]});const c=["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:n,body:e.req.requestOptions.content,timestamp:i,signedHeaders:c};o.secretId&&(n.authorization=(0,faas_server_utils_1.sign)(o)),e.req.requestOptions.headers={...n,...e.req.requestOptions.headers},await d()}}exports.signMiddlewareFactory=signMiddlewareFactory; |
{ | ||
"name": "@alipay/faas-server-sdk", | ||
"version": "1.1.18-alpha.3", | ||
"version": "1.1.18-alpha.4", | ||
"description": "云函数服务 SDK", | ||
@@ -37,5 +37,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@alipay/faas-common-sdk": "^1.1.18-alpha.3", | ||
"@alipay/faas-db-builder": "^1.1.18-alpha.3", | ||
"@alipay/faas-server-utils": "^1.1.18-alpha.3", | ||
"@alipay/faas-common-sdk": "^1.1.18-alpha.4", | ||
"@alipay/faas-db-builder": "^1.1.18-alpha.4", | ||
"@alipay/faas-server-utils": "^1.1.18-alpha.4", | ||
"ali-rds": "^6.2.0", | ||
@@ -42,0 +42,0 @@ "bson": "^4.7.2", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
249791
5114