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

@serverless/platform-client-china

Package Overview
Dependencies
Maintainers
7
Versions
83
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serverless/platform-client-china

This Serverless Platform SDK makes it easy to interact with the Serverless Platform and perform operations on it. Please note that there is an existing `@serverless/platform-sdk` npm module for interacting with the Serverless Inc. SaaS original platform s

  • 2.4.2
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
94K
decreased by-10.97%
Maintainers
7
Weekly downloads
 
Created
Source

Serverless Platform SDK

This Serverless Platform SDK makes it easy to interact with the Serverless Platform and perform operations on it. Please note that there is an existing @serverless/platform-sdk npm module for interacting with the Serverless Inc. SaaS original platform services. This SDK is for the new services, which are multi-cloud, self-hostable and focued on Components. At some point, we will try to merge these SDKs.

The SDK is light-weight, so that it can be used in the following: CLIs, Dashboards, Back-End Services, FaaS Layers. Please DO NOT add any big Node.js dependencies to this SDK.

This SDK should guide the interface design between Services and Clients. All Clients and Services MUST use the SDK and should never hardcode API endpoints or FaaS resources identifiers.

Quick-Start

If you are working within a Node.js environment, install the Serverless Platform Client SDK via NPM:

npm i @serverless/platform-client-china

If you are working within a web/browser environment, use the CDN hosted Serverless Platform Client SDK:

This is minified, tree-shaked, browserified. The CDN fetches it directly from NPM, so just reference any npm version, like below.

This CDN service has several locations in China, so it works well there.

// In index.html <head></head>
<!-- Load the Serverless Platform (Components) SDK -->
<script src="https://cdn.jsdelivr.net/npm/@serverless/platform-client-china@1.0.10" async></script>

You can also pin to the latest version, but this could break at any time:

// In index.html <head></head>
<!-- Load the Serverless Platform (Components) SDK -->
<script src="https://cdn.jsdelivr.net/npm/@serverless/platform-client-china" async></script>

If you are working with the dev environment of the Serverless Platform, set the following environment variable, or configure the client programmatically, as detailed below.

export SERVERLESS_PLATFORM_STAGE=dev

Here is how you require, instantiate the Client and use it:

const { ServerlessSDK } = require('@serverless/platform-client-china')

sdk = new ServerlessSDK({
  platformStage: 'dev',  // Optional.  Defaults to 'prod'
  accessKey: 'JA98JAJFASLFJSALFJASLFJ', // Optional, but recommended.  Platform Access Key needed to identify all requests.
})

const instances = await sdk.listInstances('my-org')

ServerlessSDK

The Serverless Platform SDK Class

Kind: global class

new ServerlessSDK()

Creates an instance of the SDK. Accepts a configuration object and calls the config() method. See the config() method for more information on allowed configuration.

ParamTypeDescription
[config.accessKey]stringCan either be a Serverless Platform Access Key or an ID Token.
[config.platformStage]stringThe Serverless Platform Stage you wish to interact with. This can also be set by the environment variable SERVERLESS_PLATFORM_STAGE=
[context.orgName]stringThe name of the Serverless Platform Organization you wish to interact with. If set, this value is used upon creating a Websockets connection, and auto-added to every Event you publish.
[context.orgUid]stringThe ID of the Serverless Platform Organization you wish to interact with. If set, this value is used upon creating a Websockets connection, and auto-added to every Event you publish.
[context.stageName]stringThe Serverless Platform Organization Stage you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.appName]stringThe Serverless Platform Application you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.instanceName]stringThe Serverless Platform Instance you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.componentName]stringThe Serverless Platform Component you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.componentVersion]stringThe Serverless Platform Component version you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.traceId]stringThe Serverless Platform Component version you wish to use this traceId to trace the all requests. If set, this value is auto-added to every Event you publish.

Example

const { ServerlessSDK } = require('@serverless/platform-client-china')

  const sdk = new ServerlessSDK({
    accessKey: '123456789',
    context: {
      orgName: 'my-org',
      orgUid: '1234',
      stageName: 'prod',
      appName: 'my-app',
      instanceName: 'my-instance'
    }
  })

serverlessSDK.events

events is the functions that will intercept with event bus: https://hackmd.io/_xwPrkdET2aKKr1VWcaWjQ?both, https://app.asana.com/0/1200011502754281/1200402117339672/f

Kind: instance property of ServerlessSDK
Param{object}: eventData is the event object

serverlessSDK.config() ⇒ null

Updates the SDK configuration

Kind: instance method of ServerlessSDK

ParamTypeDescription
[config.accessKey]stringCan either be a Serverless Platform Access Key or an ID Token.
[config.platformStage]stringThe Serverless Platform Stage you wish to interact with. This can also be set by the environment variable SERVERLESS_PLATFORM_STAGE=
[context.orgName]stringThe name of the Serverless Platform Organization you wish to interact with. If set, this value is used upon creating a Websockets connection, and auto-added to every Event you publish.
[context.orgUid]stringThe ID of the Serverless Platform Organization you wish to interact with. If set, this value is used upon creating a Websockets connection, and auto-added to every Event you publish.
[context.stageName]stringThe Serverless Platform Organization Stage you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.appName]stringThe Serverless Platform Application you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.instanceName]stringThe Serverless Platform Instance you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.componentName]stringThe Serverless Platform Component you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.componentVersion]stringThe Serverless Platform Component version you wish to interact with. If set, this value is auto-added to every Event you publish.
[context.traceId]stringThe Serverless Platform Component version you wish to use this traceId to trace the all requests. If set, this value is auto-added to every Event you publish.

Example

const { ServerlessSDK } = require('@serverless/platform-client-china')

  const sdk = new ServerlessSDK()
  sdk.config({
    accessKey: '123456789',
    context: {
      orgName: 'my-org',
      orgUid: '1234',
      stageName: 'prod',
      appName: 'my-app',
      instanceName: 'my-instance'
      traceId: '123-456
    }
  })

serverlessSDK.getDomain(serviceName) ⇒ string

Gets a domain for a specific service, currently CN verison only has 'events' and 'events-streaming' Registry and engine are exposed through Tencent API

Kind: instance method of ServerlessSDK
Returns: string - The domain of that service.

ParamTypeDefaultDescription
serviceNamestringnullThe name of the Serverless Platform Service you want the domain for.

serverlessSDK.connect() ⇒ null

Establishes a websockets connection with the Serverless Platform

Kind: instance method of ServerlessSDK

ParamTypeDescription
options.orgNamestringName of the Serverless Platform Org.
options.orgUidstringID of the Serverless Platform Org.
options.onEventfunctionA function that handles events recieved from the Serverless Platform
options.filterstringFilters which events this connection should receive
options.filter.stageNamestringTells the SDK to only receive events on a specific stage
options.filter.appNamestringTells the SDK to only receive events on a specific app
options.filter.instanceNamestringTells the SDK to only receive events on a specific service

serverlessSDK.disconnect() ⇒ null

Disconnects a websockets connection with the Serverless Platform

Kind: instance method of ServerlessSDK

serverlessSDK.isConnected() ⇒ boolean

Checks if the SDK is currently connected to the Serverless Platform

Kind: instance method of ServerlessSDK
Returns: boolean - Will return true if the websocket connection is active.

serverlessSDK.publish() ⇒ null

Publishes a Serverless Platform Event via Websockets. The use-case for this is asynchronous publishing, where you do not want to synchronous auth requests, where every message must be authorized first, adding latency.

Kind: instance method of ServerlessSDK

serverlessSDK.createComponent(orgName, componentName)

DEPRECATED: this method is deprecated, use createPackage instead Returns a new Component as a Javascript object.

Kind: instance method of ServerlessSDK

ParamTypeDefaultDescription
orgName*The name of the Serverless Platform Organization.
componentName*The name of the Serverless Platform Stage.

serverlessSDK.publishComponent(componentDefinition) ⇒ object

DEPRECATED: this method is deprecated, use publishPackage instead This method publishes a Component to the Serverless Platform Registry. This method accepts a Component Definition (e.g. serverless.component.yml) as an object. In the Component Definition, it looks at the 'main' property to find the path to the Component source directory. Then it collects that directory, adds in the special Component Handler, and packages everything into a zip file. After that, it fetches secure upload URLs and uploads the Component to the Serverless Registry. Once a Component has been uploaded to the Registry, the Registry must do some background processing to publish it, while that's happening, this method polls the API to see when the Component is finished being processed, and then returns the published definition.

Kind: instance method of ServerlessSDK
Returns: object - The published Component definition is returned from the Platform API.

ParamTypeDescription
componentDefinition*An object containing the properties of a registryPackage.

serverlessSDK.getComponent(componentName, componentVersion) ⇒ object

DEPRECATED: this method is deprecated, use getPackage instead Get Component

Kind: instance method of ServerlessSDK
Returns: object - Returns a Component definition from the Registry.

ParamTypeDefaultDescription
componentName*The name of the Component within the Registry.
componentVersion*The version of a specific Component within the Registry. If this is not included, this method will always return the latest version.

serverlessSDK.listComponents(orgUid, filter)

DEPRECATED: this method is deprecated, use listPackages instead List Components

Kind: instance method of ServerlessSDK

ParamTypeDefaultDescription
orgUid*The org ID which components belongs to
filter*The filter we can apply

serverlessSDK.generateInstanceId(orgUid, stageName, appUid, instanceName) ⇒ object

Returns a properly formatted ID for an Instance

Kind: instance method of ServerlessSDK
Returns: object - Returns a properly formatted ID for an Instance

ParamTypeDescription
orgUid*The Uid of the Serverless Platform Organization.
stageName*The name of the Serverless Platform Stage.
appUid*The Uid of the Serverless Platform Application.
instanceName*The name of the Serverless Platform Instance.

serverlessSDK.validateInstance(instanceToValidate) ⇒ object

Validates the properties of an Instance, as well as auto-corrects shortened syntax (e.g. org => orgName)

Kind: instance method of ServerlessSDK
Returns: object - Returns a validated, formatted version of the Instance

ParamTypeDescription
instanceToValidate*The Serverless Platform Instance you want to validate.

serverlessSDK.createInstance(orgName, stageName, appName, instanceName) ⇒ object

Returns a new Instance as a Javascript object.

Kind: instance method of ServerlessSDK
Returns: object - Returns a new Instance definition as a Javascript Object.

ParamTypeDefaultDescription
orgName*The name of the Serverless Platform Organization.
stageName*The name of the Serverless Platform Stage.
appName*The name of the Serverless Platform Application.
instanceName*The name of the Serverless Platform Instance.

serverlessSDK.getInstance(orgName, stageName, appName, instanceName)

Get an Instance from the Serverless Platform by it's name and the names of its Organization, Stage, Application.

Kind: instance method of ServerlessSDK

ParamTypeDefaultDescription
orgName*The name of the Serverless Platform Organization.
stageName*The name of the Serverless Platform Stage.
appName*The name of the Serverless Platform Application.
instanceName*The name of the Serverless Platform Instance.

serverlessSDK.listInstances(orgName, orgUid)

List all Component Instances within an Org, given an org name or org UId

Kind: instance method of ServerlessSDK

ParamTypeDefaultDescription
orgName*Optional. Must include either orgName or orgUid.
orgUid*Optional. Must include either orgName or orgUid.

serverlessSDK.run(action, instanceData, credentials, options)

Run an action on a Component Instance. Is an asynchronous call by default, but you can perform this synchronously if you set options.sync. Please note that synchronous runs have a 24 second timeout limit. That is not ideal for long operations, and is not recommended for deployments.

Kind: instance method of ServerlessSDK

ParamType
action*
instanceData*
credentials*
options*

serverlessSDK.runFinish(method, instanceData)

Run Finish

Kind: instance method of ServerlessSDK

ParamTypeDefaultDescription
methodstringnullThe action that was performed on the component.
instanceDataobjectAn object representing your Instance definition.

serverlessSDK.deploy()

Performs a 'deploy' action and polls the 'getInstance' endpoint until its 'instanceStatus' reflects a successful deployment, or error.

Kind: instance method of ServerlessSDK

serverlessSDK.remove()

Performs a 'remove' action and polls the 'getInstance' endpoint until its 'instanceStatus' reflects a successful deployment, or error.

Kind: instance method of ServerlessSDK

serverlessSDK.startInterceptingLogs()

Intercepts console 'log' 'debug' and 'error' methods, and sends their data to the Serverless Platform as an Event, before writing to stdout.

Kind: instance method of ServerlessSDK

serverlessSDK.stopInterceptingLogs()

Stop intercepting console methods

Kind: instance method of ServerlessSDK

serverlessSDK.paramSet()

CLI set parameters

Kind: instance method of ServerlessSDK
Param{object}:: The value of parameters settings
Stage{string}:: Which stage to store
App{string}:: Which app it belongs to
Params{object}:: The param key and param value to store

serverlessSDK.paramList()

CLI list parameters

Kind: instance method of ServerlessSDK
Param{object}:: The value of parameters settings
Stage{string}:: Which stage to find from
App{string}:: Which app it belongs to
Params{array<string>}:: Which parameters to find out

serverlessSDK.bindRole()

Init user's roles

Kind: instance method of ServerlessSDK
Param{object}:: credentials of the user

Publishing the SDK

Before publishing the SDK, be sure to run the pre-publish script, which browserifies the code and updates its documentation, by running: npm run pre-publish within the sdk folder.


© Serverless Inc.

FAQs

Package last updated on 20 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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