serverless / platform-sdk

Serverless Platform SDK
Apache License 2.0
17 stars 7 forks source link
faas serverless serverless-applications

Platform SDK (deprecated)

Note: This package is deprecated in favor of @serverless/platform-client. It accepts only bug fixes

Functional SDK for the Serverless Platfrom.

Project Status

Build Status license coverage Known Vulnerabilities

Contents

installation

npm i -s @serverless/platform-sdk

Functions

login

Opens a browser for the user to login, along with a running server awaiting auth data once the user logs in.

Parameters

None

Returns

Promise resolving to the following object:

Example

const { login } = require('@serverless/platform-sdk')

const { username, accessToken, idToken, expiresAt } = await login()

refreshToken

Refreshes Auth0 idToken

Parameters

refresh token string

Returns

Promise resolving to the following object:

Example

const { refreshToken } = require('@serverless/platform-sdk')

const { id_token, access_token, expires_in } = await refreshToken('some-refresh-token')

createAccessKey

Creates a platform access key for the authenticated user.

Parameters

Object

Returns

Promise resolving to an accessKey string, that is the access key.

Example

const { createAccessKey } = require('@serverless/platform-sdk')

const data = {
  username: 'eahefnawy',
  tenant: 'eahefnawy',
  idToken: 'abc',
  title: 'Framework'
}

const accessKey = await createAccessKey(data)

archiveService

Archives a service in the platform.

Parameters

Object

Returns

None

Example

const { archiveService } = require('@serverless/platform-sdk')

const data = {
  tenant: 'eahefnawy',
  accessKey: 'abc',
  app: 'my-app',
  name: 'my-service',
  provider: 'aws',
  region: 'us-east-1'
}

await archiveService(data)

getServiceUrl

Constructs a service url based on passed-in data.

Parameters

Object

Returns

The service url string.

Example

const { getServiceUrl } = require('@serverless/platform-sdk')

const data = {
  tenant: 'eahefnawy',
  app: 'my-app',
  name: 'my-service'
}

const serviceUrl = getServiceUrl(data)

listTenants

Lists the tenants for a given username

Parameters

Object

Returns

Array of objects, each represents a single tenant data model.

Example

const { listTenants } = require('@serverless/platform-sdk')

const data = {
  username: 'eahefnawy',
  idToken: 'abc'
}

const tenants = await listTenants(data)

createDeploymnet

Creates a platform deployment

Parameters

Object

Returns

Object - Deployment model

Example

const { createDeployment } = require('@serverless/platform-sdk')

const data = {
  tenant: 'eahefnawy',
  app: 'my-app',
  serviceName: 'my-service',
  accessKey: 'abc',
  files: {
    'serverless-state.json': {
      //...snip...
    }
  }
}

const { id } = await createDeployment(data)

updateDeployment

Updates a platform deployment

Parameters

Object

Returns

Object - Deployment model

Example

const { updateDeployment } = require('@serverless/platform-sdk')

const data = {
  tenant: 'eahefnawy',
  app: 'my-app',
  serviceName: 'my-service',
  deploymentId: 'abc',
  status: 'failed',
  accessKey: 'abc',
  computedData: {
    // ...snip...
  }
}

const { id } = await updateDeployment(data)

getApp

Gets a platform app

Parameters

Object

Returns

Object - App model

Example

const { getApp } = require('@serverless/platform-sdk')

const data = {
  tenant: 'eahefnawy',
  app: 'my-app',
  token: 'abc'
}

const app = await getApp(data)

createApp

Creates a platform app

Parameters

Object

Returns

Object - App model

Example

const { createApp } = require('@serverless/platform-sdk')

const data = {
  tenant: 'eahefnawy',
  app: 'my-app',
  token: 'abc'
}

const app = await createApp(data)