Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@serverless/platform-client

Package Overview
Dependencies
Maintainers
4
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serverless/platform-client - npm Package Compare versions

Comparing version 0.0.6 to 0.1.0

31

Connection.js

@@ -11,2 +11,3 @@ /**

this.connection = null
this.context = {}
}

@@ -24,28 +25,13 @@

// Validate options
if (!options.org) {
return reject('connect() requires an "org" to be specified as an option')
const headers = {
'AUTHORIZATION': `Bearer ${this.sdk.accessKey}`,
'X-SERVERLESS-PLATFORM-STREAMING-FILTER': JSON.stringify(options.filter)
}
if (options.orgName) headers['X-SERVERLESS-PLATFORM-STREAMING-ORG-NAME'] = options.orgName
if (options.orgUid) headers['X-SERVERLESS-PLATFORM-STREAMING-ORG-ID'] = options.orgUid
// If no event listener is offered, create an empty one
if (!options.onEvent) {
options.onEvent = () => {}
}
// Sanitize filter
options.filter = options.filter || {}
options.filter.stageName = options.filter.stageName ? options.filter.stageName.trim() : null
options.filter.appName = options.filter.appName ? options.filter.appName.trim() : null
options.filter.instanceName = options.filter.instanceName ? options.filter.instanceName.trim() : null
// Instantiate websockets library
this.connection = new WS(
this.sdk.domains.events,
{
headers: {
'AUTHORIZATION': `Bearer ${this.sdk.accessKey}`,
'X-SERVERLESS-PLATFORM-STREAMING-ORG': options.org,
'X-SERVERLESS-PLATFORM-STREAMING-FILTER': JSON.stringify(options.filter)
}
}
{ headers }
)

@@ -66,3 +52,3 @@

self.connection.on('error', (error) => {
console.log(`Serverless Streaming: ${error}`)
console.log(`Serverless Platform Streaming: ${error}`)
})

@@ -106,5 +92,4 @@

}
}
module.exports = Connection

@@ -24,2 +24,3 @@ /**

this.platformStage = process.env.SERVERLESS_PLATFORM_STAGE || config.platformStage || 'prod'
this.context = config.context || this.context || {}
this.debugMode = config.debug || false

@@ -35,2 +36,23 @@ }

async connect(options) {
// Validate org
if (
(!options.orgName && !this.context.orgName) &&
(!options.orgUid && !this.context.orgUid)
)
{
throw new Error(`You must specify an "orgName" or "orgUid" to connect`)
}
// If no event listener is offered, create an empty one
if (!options.onEvent) {
options.onEvent = () => {}
}
// Sanitize filter
options.filter = options.filter || {}
options.filter.stageName = options.filter.stageName ? options.filter.stageName.trim() : null
options.filter.appName = options.filter.appName ? options.filter.appName.trim() : null
options.filter.instanceName = options.filter.instanceName ? options.filter.instanceName.trim() : null
// Create connection
this.connection = new Connection(this)

@@ -80,4 +102,8 @@ await this.connection.connect(options)

}
if (!event.orgName) {
throw new Error(`event must have an "orgName"`)
if (
(!event.orgName && !this.context.orgName) &&
(!event.orgUid && !this.context.orgUid)
)
{
throw new Error(`event must have an "orgName" or "orgUid"`)
}

@@ -90,8 +116,16 @@

safeEvent.event = event.event.trim()
safeEvent.orgName = event.orgName.trim()
if (event.orgName) safeEvent.orgName = event.orgName.trim()
if (event.orgUid) safeEvent.orgUid = event.orgUid.trim()
if (event.stageName) safeEvent.stageName = event.stageName.trim()
if (event.appName) safeEvent.appName = event.appName.trim()
if (event.instanceName) safeEvent.instanceName = event.instanceName.trim()
// Auto add to event body if set in context, but don't override above values
if (this.context.orgUid) safeEvent.orgUid = event.orgUid || this.context.orgUid
if (this.context.orgName) safeEvent.orgName = event.orgName || this.context.orgName
if (this.context.stageName) safeEvent.stageName = this.context.stageName
if (this.context.appName) safeEvent.appName = this.context.appName
if (this.context.instanceName) safeEvent.instanceName = this.context.instanceName
safeEvent.data = event.data || {}
return this.connection.send(safeEvent)

@@ -98,0 +132,0 @@ }

{
"name": "@serverless/platform-client",
"version": "0.0.6",
"version": "0.1.0",
"description": "",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc