@alipay/faas-server-sdk
Advanced tools
Comparing version 1.1.20 to 1.1.21-alpha.0
@@ -9,2 +9,3 @@ import { AlipayContext } from '@alipay/faas-server-utils'; | ||
import type { CallFunctionParam, CloudInitOptions, DownloadFileResult, GetDatabaseOptions, UploadFileParam, UploadFileResult } from './types'; | ||
import { WebsocketSDK } from './Websocket'; | ||
export declare function initRuntimeEnv(env: Record<string, string>): void; | ||
@@ -22,2 +23,3 @@ export declare class Cloud { | ||
get openapi(): OpenapiFunction; | ||
ws(): WebsocketSDK; | ||
getOpenapiCaller(): OpenapiCaller; | ||
@@ -24,0 +26,0 @@ getStorage(): Storage; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cloud=exports.initRuntimeEnv=void 0;const faas_server_utils_1=require("@alipay/faas-server-utils"),callFunction_1=require("./callFunction"),constant_1=require("./constant"),Database_1=require("./Database"),MySQL_1=require("./MySQL"),Redis_1=require("./Redis"),Openapi_1=require("./Openapi"),Storage_1=require("./Storage"),utils_1=require("./utils"),runtimeEnv={RUNTIME_ACCESS_KEY:process.env.RUNTIME_ACCESS_KEY||"",RUNTIME_SECRET_KEY:process.env.RUNTIME_SECRET_KEY||"",RUNTIME_ENV_ID:process.env.RUNTIME_ENV_ID||"",RUNTIME_FUNCTION_NAME:process.env.RUNTIME_FUNCTION_NAME||"",RUNTIME_FUNCTION_GATEWAY_ENDPOINT:process.env.RUNTIME_FUNCTION_GATEWAY_ENDPOINT||"",RUNTIME_FUNCTION_INSTANCE_ID:process.env.RUNTIME_FUNCTION_INSTANCE_ID||"",RUNTIME_MONGO_CLUSTER_ENDPOINT:process.env.RUNTIME_MONGO_CLUSTER_ENDPOINT||"",RUNTIME_MONGO_DATABASE_NAME:process.env.RUNTIME_MONGO_DATABASE_NAME||"",RUNTIME_OSS_ENDPOINT:process.env.RUNTIME_OSS_ENDPOINT||"",RUNTIME_MYSQL_ENDPOINT:process.env.RUNTIME_MYSQL_ENDPOINT||"",RUNTIME_REDIS_ENDPOINT:process.env.RUNTIME_REDIS_ENDPOINT||""};function initRuntimeEnv(i){Object.assign(runtimeEnv,i)}exports.initRuntimeEnv=initRuntimeEnv;class Cloud{#t;#e;#i;#n;#N;#E;constructor(){this.#t={secretId:runtimeEnv.RUNTIME_ACCESS_KEY,secretKey:runtimeEnv.RUNTIME_SECRET_KEY,fromEnvId:runtimeEnv.RUNTIME_ENV_ID,toEnvId:runtimeEnv.RUNTIME_ENV_ID,functionName:runtimeEnv.RUNTIME_FUNCTION_NAME,functionGatewayEndpoint:runtimeEnv.RUNTIME_FUNCTION_GATEWAY_ENDPOINT,functionInstanceId:runtimeEnv.RUNTIME_FUNCTION_INSTANCE_ID,functionDatabaseEndpoint:runtimeEnv.RUNTIME_MONGO_CLUSTER_ENDPOINT,functionDatabaseName:runtimeEnv.RUNTIME_MONGO_DATABASE_NAME,functionStorageEndpoint:runtimeEnv.RUNTIME_OSS_ENDPOINT,functionMysqlEndpoint:runtimeEnv.RUNTIME_MYSQL_ENDPOINT,functionRedisEndpoint:runtimeEnv.RUNTIME_REDIS_ENDPOINT,timeout:1e4}}refreshConfig(){runtimeEnv.RUNTIME_ACCESS_KEY!==void 0&&(this.#t.secretId=runtimeEnv.RUNTIME_ACCESS_KEY),runtimeEnv.RUNTIME_SECRET_KEY&&(this.#t.secretKey=runtimeEnv.RUNTIME_SECRET_KEY),runtimeEnv.RUNTIME_ENV_ID&&(this.#t.fromEnvId=runtimeEnv.RUNTIME_ENV_ID,this.#t.toEnvId||(this.#t.toEnvId=runtimeEnv.RUNTIME_ENV_ID)),runtimeEnv.RUNTIME_FUNCTION_NAME&&(this.#t.functionName=runtimeEnv.RUNTIME_FUNCTION_NAME),runtimeEnv.RUNTIME_FUNCTION_GATEWAY_ENDPOINT&&(this.#t.functionGatewayEndpoint=runtimeEnv.RUNTIME_FUNCTION_GATEWAY_ENDPOINT),runtimeEnv.RUNTIME_FUNCTION_INSTANCE_ID&&(this.#t.functionInstanceId=runtimeEnv.RUNTIME_FUNCTION_INSTANCE_ID),runtimeEnv.RUNTIME_MONGO_CLUSTER_ENDPOINT&&(this.#t.functionDatabaseEndpoint=runtimeEnv.RUNTIME_MONGO_CLUSTER_ENDPOINT),runtimeEnv.RUNTIME_MONGO_DATABASE_NAME&&(this.#t.functionDatabaseName=runtimeEnv.RUNTIME_MONGO_DATABASE_NAME),runtimeEnv.RUNTIME_OSS_ENDPOINT&&(this.#t.functionStorageEndpoint=runtimeEnv.RUNTIME_OSS_ENDPOINT),runtimeEnv.RUNTIME_MYSQL_ENDPOINT&&(this.#t.functionMysqlEndpoint=runtimeEnv.RUNTIME_MYSQL_ENDPOINT),runtimeEnv.RUNTIME_REDIS_ENDPOINT&&(this.#t.functionRedisEndpoint=runtimeEnv.RUNTIME_REDIS_ENDPOINT)}init(t){const e=this.#_(t?.env);e&&(this.#t.toEnvId=e),t?.envId&&(this.#t.toEnvId=t.envId),t?.timeout!==void 0&&(this.#t.timeout=(0,utils_1.validateTimeout)(t.timeout))}getAlipayContext(){return(0,faas_server_utils_1.getAlipayContext)()}async callFunction(t){const{config:e,...n}=t||{},N=this.#s(e?.env);return await(0,callFunction_1.createCallFunction)(N)(n)}database(t){const e=this.#s(t?.env);return new Database_1.Database({...e,throwOnNotFound:t?.throwOnNotFound!==!1,ignoreCollectionExists:t?.ignoreCollectionExists===!0,timeout:(0,utils_1.validateTimeout)(t?.timeout??e.timeout)})}mysql(){return this.#i||(this.#i=new MySQL_1.MySQL(this.#t)),this.#i}redis(t){return typeof t=="string"?new Redis_1.Redis({url:t,innerConfig:this.#t}):t&&t.host?new Redis_1.Redis({...t,innerConfig:this.#t}):(this.#n||(this.#n=new Redis_1.Redis({innerConfig:this.#t})),this.#n)}get openapi(){return this.#N||(this.#N=(0,Openapi_1.createOpenapi)(this.#t)),this.#N}getOpenapiCaller(){return this.#E||(this.#E=(0,Openapi_1.createOpenapiCaller)({config:this.#t})),this.#E}getStorage(){return this.#e||(this.#e=new Storage_1.Storage(this.#t)),this.#e}async getUploadFileURL(t){return await this.getStorage().getUploadFileURL(t)}async uploadFile(t){return await this.getStorage().uploadFile(t)}async downloadFile(t){return await this.getStorage().downloadFile(t)}async deleteFile(t){return await this.getStorage().deleteFile(t)}async getTempFileURL(t){return await this.getStorage().getTempFileURL(t)}#s(t){const e=this.#_(t);return e?{...this.#t,toEnvId:e}:this.#t}#_(t){return t&&typeof t=="string"?t:t&&t===constant_1.DYNAMIC_CURRENT_ENV?runtimeEnv.RUNTIME_ENV_ID:null}}exports.Cloud=Cloud; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cloud=exports.initRuntimeEnv=void 0;const faas_server_utils_1=require("@alipay/faas-server-utils"),callFunction_1=require("./callFunction"),constant_1=require("./constant"),Database_1=require("./Database"),MySQL_1=require("./MySQL"),Redis_1=require("./Redis"),Openapi_1=require("./Openapi"),Storage_1=require("./Storage"),utils_1=require("./utils"),Websocket_1=require("./Websocket"),runtimeEnv={RUNTIME_ACCESS_KEY:process.env.RUNTIME_ACCESS_KEY||"",RUNTIME_SECRET_KEY:process.env.RUNTIME_SECRET_KEY||"",RUNTIME_ENV_ID:process.env.RUNTIME_ENV_ID||"",RUNTIME_FUNCTION_NAME:process.env.RUNTIME_FUNCTION_NAME||"",RUNTIME_FUNCTION_GATEWAY_ENDPOINT:process.env.RUNTIME_FUNCTION_GATEWAY_ENDPOINT||"",RUNTIME_FUNCTION_INSTANCE_ID:process.env.RUNTIME_FUNCTION_INSTANCE_ID||"",RUNTIME_MONGO_CLUSTER_ENDPOINT:process.env.RUNTIME_MONGO_CLUSTER_ENDPOINT||"",RUNTIME_MONGO_DATABASE_NAME:process.env.RUNTIME_MONGO_DATABASE_NAME||"",RUNTIME_OSS_ENDPOINT:process.env.RUNTIME_OSS_ENDPOINT||"",RUNTIME_MYSQL_ENDPOINT:process.env.RUNTIME_MYSQL_ENDPOINT||"",RUNTIME_REDIS_ENDPOINT:process.env.RUNTIME_REDIS_ENDPOINT||"",RUNTIME_WS_GATEWAY_ENDPOINT:process.env.RUNTIME_WS_GATEWAY_ENDPOINT||""};function initRuntimeEnv(i){Object.assign(runtimeEnv,i)}exports.initRuntimeEnv=initRuntimeEnv;class Cloud{#t;#e;#i;#n;#N;#E;#s;constructor(){this.#t={secretId:runtimeEnv.RUNTIME_ACCESS_KEY,secretKey:runtimeEnv.RUNTIME_SECRET_KEY,fromEnvId:runtimeEnv.RUNTIME_ENV_ID,toEnvId:runtimeEnv.RUNTIME_ENV_ID,functionName:runtimeEnv.RUNTIME_FUNCTION_NAME,functionGatewayEndpoint:runtimeEnv.RUNTIME_FUNCTION_GATEWAY_ENDPOINT,functionInstanceId:runtimeEnv.RUNTIME_FUNCTION_INSTANCE_ID,functionDatabaseEndpoint:runtimeEnv.RUNTIME_MONGO_CLUSTER_ENDPOINT,functionDatabaseName:runtimeEnv.RUNTIME_MONGO_DATABASE_NAME,functionStorageEndpoint:runtimeEnv.RUNTIME_OSS_ENDPOINT,functionMysqlEndpoint:runtimeEnv.RUNTIME_MYSQL_ENDPOINT,functionRedisEndpoint:runtimeEnv.RUNTIME_REDIS_ENDPOINT,websocketGatewayEndpoint:runtimeEnv.RUNTIME_WS_GATEWAY_ENDPOINT,timeout:1e4}}refreshConfig(){runtimeEnv.RUNTIME_ACCESS_KEY!==void 0&&(this.#t.secretId=runtimeEnv.RUNTIME_ACCESS_KEY),runtimeEnv.RUNTIME_SECRET_KEY&&(this.#t.secretKey=runtimeEnv.RUNTIME_SECRET_KEY),runtimeEnv.RUNTIME_ENV_ID&&(this.#t.fromEnvId=runtimeEnv.RUNTIME_ENV_ID,this.#t.toEnvId||(this.#t.toEnvId=runtimeEnv.RUNTIME_ENV_ID)),runtimeEnv.RUNTIME_FUNCTION_NAME&&(this.#t.functionName=runtimeEnv.RUNTIME_FUNCTION_NAME),runtimeEnv.RUNTIME_FUNCTION_GATEWAY_ENDPOINT&&(this.#t.functionGatewayEndpoint=runtimeEnv.RUNTIME_FUNCTION_GATEWAY_ENDPOINT),runtimeEnv.RUNTIME_FUNCTION_INSTANCE_ID&&(this.#t.functionInstanceId=runtimeEnv.RUNTIME_FUNCTION_INSTANCE_ID),runtimeEnv.RUNTIME_MONGO_CLUSTER_ENDPOINT&&(this.#t.functionDatabaseEndpoint=runtimeEnv.RUNTIME_MONGO_CLUSTER_ENDPOINT),runtimeEnv.RUNTIME_MONGO_DATABASE_NAME&&(this.#t.functionDatabaseName=runtimeEnv.RUNTIME_MONGO_DATABASE_NAME),runtimeEnv.RUNTIME_OSS_ENDPOINT&&(this.#t.functionStorageEndpoint=runtimeEnv.RUNTIME_OSS_ENDPOINT),runtimeEnv.RUNTIME_MYSQL_ENDPOINT&&(this.#t.functionMysqlEndpoint=runtimeEnv.RUNTIME_MYSQL_ENDPOINT),runtimeEnv.RUNTIME_REDIS_ENDPOINT&&(this.#t.functionRedisEndpoint=runtimeEnv.RUNTIME_REDIS_ENDPOINT),runtimeEnv.RUNTIME_WS_GATEWAY_ENDPOINT&&(this.#t.websocketGatewayEndpoint=runtimeEnv.RUNTIME_WS_GATEWAY_ENDPOINT)}init(t){const e=this.#I(t?.env);e&&(this.#t.toEnvId=e),t?.envId&&(this.#t.toEnvId=t.envId),t?.timeout!==void 0&&(this.#t.timeout=(0,utils_1.validateTimeout)(t.timeout))}getAlipayContext(){return(0,faas_server_utils_1.getAlipayContext)()}async callFunction(t){const{config:e,...n}=t||{},N=this.#_(e?.env);return await(0,callFunction_1.createCallFunction)(N)(n)}database(t){const e=this.#_(t?.env);return new Database_1.Database({...e,throwOnNotFound:t?.throwOnNotFound!==!1,ignoreCollectionExists:t?.ignoreCollectionExists===!0,timeout:(0,utils_1.validateTimeout)(t?.timeout??e.timeout)})}mysql(){return this.#i||(this.#i=new MySQL_1.MySQL(this.#t)),this.#i}redis(t){return typeof t=="string"?new Redis_1.Redis({url:t,innerConfig:this.#t}):t&&t.host?new Redis_1.Redis({...t,innerConfig:this.#t}):(this.#n||(this.#n=new Redis_1.Redis({innerConfig:this.#t})),this.#n)}get openapi(){return this.#N||(this.#N=(0,Openapi_1.createOpenapi)(this.#t)),this.#N}ws(){return this.#s||(this.#s=new Websocket_1.WebsocketSDK(this.#t)),this.#s}getOpenapiCaller(){return this.#E||(this.#E=(0,Openapi_1.createOpenapiCaller)({config:this.#t})),this.#E}getStorage(){return this.#e||(this.#e=new Storage_1.Storage(this.#t)),this.#e}async getUploadFileURL(t){return await this.getStorage().getUploadFileURL(t)}async uploadFile(t){return await this.getStorage().uploadFile(t)}async downloadFile(t){return await this.getStorage().downloadFile(t)}async deleteFile(t){return await this.getStorage().deleteFile(t)}async getTempFileURL(t){return await this.getStorage().getTempFileURL(t)}#_(t){const e=this.#I(t);return e?{...this.#t,toEnvId:e}:this.#t}#I(t){return t&&typeof t=="string"?t:t&&t===constant_1.DYNAMIC_CURRENT_ENV?runtimeEnv.RUNTIME_ENV_ID:null}}exports.Cloud=Cloud; |
@@ -1,1 +0,1 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Collection=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),faas_server_utils_1=require("@alipay/faas-server-utils"),faas_common_sdk_1=require("@alipay/faas-common-sdk");class Collection{#e;#a;#s;#n;#t;constructor(t,e,a){this.#e=t,this.#a=e,this.#n=a,this.#s=new faas_db_builder_1.CollectionBuilder(e,{maxAddCount:1e3}),this.#t=new faas_common_sdk_1.Collection(e,{httpclient:a,type:"function",databaseName:t.functionDatabaseName,throwOnNotFound:t.throwOnNotFound})}async add(t){if(Array.isArray(t.data))return this.#r(t);const e=(0,faas_server_utils_1.getAlipayContext)(),{data:a}=t,n={...a,_openid:a._openid||e.OPENID};return this.#t.add({data:n})}async#r(t){const{options:e}=this.#s.add(t),a="POST",n=`${this.#i()}?batchCreate`,r=(0,faas_server_utils_1.getAlipayContext)();e.$create.forEach(s=>{s._openid=s._openid||r.OPENID});const i=await this.#n.request({method:a,path:n,data:e});return{_ids:faas_common_sdk_1.ResponseUtil.handleResponse(i).insertedIds.map(({_id:s})=>s)}}doc(t){return this.#t.doc(t)}limit(t){return this.#t.limit(t)}skip(t){return this.#t.skip(t)}where(t){return this.#t.where(t)}projection(t){return this.#t.projection(t)}field(t){return this.projection(t)}orderBy(t,e){return this.#t.orderBy(t,e)}aggregate(){return this.#t.aggregate()}async update(t){return await this.#t.update(t)}async updateAndReturn(t){return await this.#t.updateAndReturn(t)}async set(t){return await this.#t.set(t)}async remove(){return await this.#t.remove()}async get(){return await this.#t.get()}async count(){return await this.#t.count()}#i(){return`/${this.#e.functionDatabaseName||"faas"}/${this.#a}`}}exports.Collection=Collection; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Collection=void 0;const faas_db_builder_1=require("@alipay/faas-db-builder"),faas_server_utils_1=require("@alipay/faas-server-utils"),faas_common_sdk_1=require("@alipay/faas-common-sdk"),errors_1=require("../errors");class Collection{#e;#r;#a;#s;#t;constructor(t,e,r){this.#e=t,this.#r=e,this.#s=r,this.#a=new faas_db_builder_1.CollectionBuilder(e,{maxAddCount:1e3}),this.#t=new faas_common_sdk_1.Collection(e,{httpclient:r,type:"function",databaseName:t.functionDatabaseName,throwOnNotFound:t.throwOnNotFound})}async add(t){if(Array.isArray(t.data))return this.#i(t);if(!t?.data)throw errors_1.errors.INVALID_PARAM("data","\u4E0D\u80FD\u4E3A\u7A7A");const e=(0,faas_server_utils_1.getAlipayContext)(),{data:r}=t,s={...r,_openid:r._openid||e.OPENID};return this.#t.add({data:s})}async#i(t){const{options:e}=this.#a.add(t),r="POST",s=`${this.#n()}?batchCreate`,i=(0,faas_server_utils_1.getAlipayContext)();e.$create.forEach(a=>{a._openid=a._openid||i.OPENID});const n=await this.#s.request({method:r,path:s,data:e});return{_ids:faas_common_sdk_1.ResponseUtil.handleResponse(n).insertedIds.map(({_id:a})=>a)}}doc(t){return this.#t.doc(t)}limit(t){return this.#t.limit(t)}skip(t){return this.#t.skip(t)}where(t){return this.#t.where(t)}projection(t){return this.#t.projection(t)}field(t){return this.projection(t)}orderBy(t,e){return this.#t.orderBy(t,e)}aggregate(){return this.#t.aggregate()}async update(t){return await this.#t.update(t)}async updateAndReturn(t){return await this.#t.updateAndReturn(t)}async set(t){return await this.#t.set(t)}async remove(){return await this.#t.remove()}async get(){return await this.#t.get()}async count(){return await this.#t.count()}#n(){return`/${this.#e.functionDatabaseName||"faas"}/${this.#r}`}}exports.Collection=Collection; |
@@ -6,3 +6,3 @@ import { Middleware } from 'koa-compose'; | ||
type MiddlewareArray = Array<Middleware<HttpRequestContext<unknown, unknown>>>; | ||
type EndpointKey = 'functionGatewayEndpoint' | 'functionStorageEndpoint' | 'functionDatabaseEndpoint'; | ||
type EndpointKey = 'functionGatewayEndpoint' | 'functionStorageEndpoint' | 'functionDatabaseEndpoint' | 'websocketGatewayEndpoint'; | ||
export declare class Httpclient { | ||
@@ -17,3 +17,4 @@ #private; | ||
static createOpenapiHttpclient(config: CloudConfig): Httpclient; | ||
static createWebsocketHttpclient(config: CloudConfig): Httpclient; | ||
} | ||
export {}; |
@@ -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"],{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)})); | ||
"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"),init_call_websocketgateway_headers_middleware_1=require("./middlewares/init_call_websocketgateway_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)}static createWebsocketHttpclient(t){const e=[error_handler_middleware_1.errorHandlerMiddleware,json_middleware_1.jsonMiddleware,(0,init_call_websocketgateway_headers_middleware_1.createInitCallWebsocketGatewayHeadersMiddleware)(),(0,sign_middleware_factory_1.signMiddlewareFactory)([]),call_middleware_1.callMiddleware];return new Httpclient("websocketGatewayEndpoint",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)})); |
{ | ||
"name": "@alipay/faas-server-sdk", | ||
"version": "1.1.20", | ||
"version": "1.1.21-alpha.0", | ||
"description": "云函数服务 SDK", | ||
@@ -37,5 +37,5 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@alipay/faas-common-sdk": "^1.1.20", | ||
"@alipay/faas-db-builder": "^1.1.20", | ||
"@alipay/faas-server-utils": "^1.1.20", | ||
"@alipay/faas-common-sdk": "^1.1.21-alpha.0", | ||
"@alipay/faas-db-builder": "^1.1.21-alpha.0", | ||
"@alipay/faas-server-utils": "^1.1.21-alpha.0", | ||
"ali-rds": "^6.2.0", | ||
@@ -42,0 +42,0 @@ "bson": "^4.7.2", |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
253744
360
5150
23
23
+ Added@alipay/faas-common-sdk@1.1.21-alpha.2(transitive)
+ Added@alipay/faas-db-builder@1.1.21-alpha.2(transitive)
+ Added@alipay/faas-server-utils@1.1.21-alpha.2(transitive)
- Removed@alipay/faas-common-sdk@1.1.20(transitive)
- Removed@alipay/faas-db-builder@1.1.20(transitive)
- Removed@alipay/faas-server-utils@1.1.20(transitive)
- Removeddestroy@1.2.0(transitive)
- Removedformstream@1.4.0(transitive)
- Removedmime@2.6.0(transitive)
- Removedpause-stream@0.0.11(transitive)
- Removedthrough@2.3.8(transitive)