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

sls-helper-plugin-janis

Package Overview
Dependencies
Maintainers
2
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sls-helper-plugin-janis

A Serverless Helper plugin to add custom helpers for Janis Commerce

  • 5.14.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
352
decreased by-14.36%
Maintainers
2
Weekly downloads
 
Created
Source

Serverless Helper Plugin JANIS

A plugin for JANIS Commerce to use with the Serverless Helper Framework.

npm version Build status Coverage Status

Helpers

base

Used to implement a base service with minimal setup

OptionTypeDescriptionAttributesDefault value
serviceCodestringThe service name in lowercase dash separatedRequired
servicePortnumberThe service portRequired
apiSecretsObjectA mapping of stages to Service API Secretundefined

Some properties of the initial configuration have a new special meaning:

package.include and package.includeOnly
package.exclude and package.excludeOnly
package.plugins and package.pluginsOnly

This properties (if present in the initial service configuration) have the following behavior:

  • package.include, package.exclude and plugins will be appended to the hooks defaults
  • package.includeOnly, package.excludeOnly and pluginsOnly will replace entirely the hooks defaults
Trace Lambda Layer

If the env vars TRACE_ACCOUNT_ID and JANIS_TRACE_EXTENSION_VERSION are set, the Trace Lambda Layer will be set for every function by default.

apiGet and apiList are the only functions that have this behaviour changed by default.

To disable the layer, see the skipTraceLayer property in other helpers.

templates

Used to implement Lambda APIs requests and response templates as custom props

No options

authorizers

Used to implement APIs authorizers as custom props

OptionTypeDescriptionAttributesDefault value
accountIdstringIndicates the AWS account ID where the authorizers are deployedRequired

cors

Used to implement APIs CORS configuration as custom props

If options is undefined or set to true it will use the default CORS config for every property. You can also customize or override every property:

OptionTypeDescriptionDefault value
replacebooleanIndicates whether it should replace the CORS properties or merge then with the defaultfalse
originsarray<string>An array of allowed origins['*']
headersarray<string>An array of allowed headersSee below
allowCredentialsbooleanIndicates whether the credentials header should be settrue
maxAgenumberThe time in seconds thar CORS headers should be cached600
CORS Default headers:
[
	'authorization',
	'content-type',
	'janis-api-key',
	'janis-api-secret',
	'janis-client',
	'janis-service',
	'janis-entity',
	'x-api-key',
	'x-janis-page',
	'x-janis-page-size'
]

api

Used to implement a custom API

OptionTypeDescriptionAttributesDefault value
functionNamestringThe name of the lambda function. Will be used in API-{serviceName}-{functionName}-{stage}. Since 5.6.0
pathstringThe API pathRequired
methodstringThe API HTTP Method'get'
methodNamestringThe JANIS API MethodEnum<list, get, post, put, patch, delete>Defaults to same value of method option
handlerstringThe lambda handler path and function'src/lambda/RestApi/index.handler'
cachingbooleanSet to true to enable cachefalse
corsbooleanobjectSet to true to enable services default CORS, or configure as an object as explained in CORS to customize the API CORS
queryParametersobjectA key value to map query string parameters to a boolean indicating if it's required or not
requestTemplatesobjectA key value to map content types to request mapping headers. By default only application/json is enabled (Docs)
requestHeadersobjectA key value to map headers to a boolean indicating if it's required or not
authorizerstringThe name of the authorizer
timeoutnumberThe function timeout in seconds
package.includearray[string]The List of paths of files to include
skipTraceLayerbooleanSet to true if the API should not use the Trace Lambda Layerfalse
functionRawPropsobjectCustom properties to set in the function configuration
eventRawPropsobjectCustom properties to set in the event configuration

apiList, apiGet, apiPost and apiPut

Used to implement JANIS CRUD APIs.

OptionTypeDescriptionAttributesDefault value
functionNamestringThe name of the lambda function. Will be used in API-{serviceName}-{functionName}-{stage}. Since 5.6.0
entityNamestringThe entity nameRequired
handlerstringThe lambda handler path and function'src/lambda/RestApi/index.handler'
pathstringThe API path/[entity-name] (for apiList and apiPost) or /[entity-name]/{id} (for apiGet and apiPut)
cachingbooleanSet to true to enable cachefalse
corsbooleanobjectSet to true to enable services default CORS, or configure as an object as explained in CORS to customize the API CORS
queryParametersobjectA key value to map query string parameters to a boolean indicating if it's required or not
requestTemplatesobjectA key value to map content types to request mapping headers. By default only application/json is enabled (Docs)
requestHeadersobjectA key value to map headers to a boolean indicating if it's required or not
authorizerstringThe name of the authorizer
timeoutnumberThe function timeout in seconds
package.includearray[string]The List of paths of files to include
skipTraceLayerbooleanSet to true if the API should not use the Trace Lambda Layerfalse for post and put APIs, true for get and list APIs
functionRawPropsobjectCustom properties to set in the function configuration
eventRawPropsobjectCustom properties to set in the event configuration

eventListener

Used to implement JANIS Events listeners

OptionTypeDescriptionAttributesDefault value
serviceNamestringThe service nameRequired
entityNamestringThe entity nameRequired
eventNamestringThe event nameRequired
mustHaveClientbooleanIndicates if authorizer must validate that client or notfalse
listenersDirNamestringIndicates the path where the event listener files are placed'event-listeners'
authorizerstringThe name of the authorizerIf not set, it defaults to ServiceAuthorizer or ServiceNoClientAuthorizer based on the value of mustHaveClient
package.includearray[string]The List of paths of files to include
timeoutnumberThe function timeout in seconds
functionRawPropsobjectCustom properties to set in the function configuration

dbConfig

(since 3.1.0)

Used to implement JANIS Database config as secret with an auto-generated password

OptionTypeDescriptionAttributesDefault value
secretstring | objectThe secret content as an object or a JSON stringified objectRequired
secretNamestringThe secret name'janis/${self:custom.serviceCode}/${self:custom.stage}/db-config'
descriptionstringThe secret description'Database config secret for janis ${self:custom.serviceCode} ${self:custom.stage}'
passwordKeystringThe property name where the password will be generated'password'
passwordLengthnumberThe generated password length40

stateMachine

(since 4.3.0)

Used to implement AWS State Machines

OptionTypeDescriptionAttributesDefault value
namestringThe name of the state machineRequired
definitionobjectThe definition of the state machine. See more Step FunctionsRequired

It will automatically include the serverless-step-functions plugin.

It also defines 2 properties in the custom namespace:

  • custom.machines.{MachineName}.arn: The State Machine ARN
  • custom.machines.{MachineName}.name: The State Machine Name

Important: The {MachineName} in the custom.machines path will replaced be the name property converted to PascalCase. For example, if the following hook is configured

['janis.stateMachine', {
	name: 'my-super-machine',
	definition: myDefinition
}]

The following custom props will be set: custom.machines.MySuperMachine.arn and custom.machines.MySuperMachine.name

Examples

Basic Service with one CRUD operation set and an event listener

// serverless.js

'use strict';

const { helper } = require('sls-helper'); // eslint-disable-line

module.exports = helper({
	hooks: [

		['janis.base', {
			serviceCode: 'my-service',
			servicePort: 5000,
			apiSecrets: {
				beta: 'foo',
				qa: 'bar',
				prod: 'baz'
			}
		}],

		'janis.templates',

		['janis.authorizers', {
			accountId: '012345678910'
		}],

		'janis.cors',

		['janis.api', {
			path: '/hello-world',
			authorizer: 'NoClientAuthorizer',
			cors: true
		}],

		['janis.apiList', {
			entityName: 'product',
			authorizer: 'FullAuthorizer',
			cors: true
		}],

		['janis.apiGet', {
			entityName: 'product',
			authorizer: 'FullAuthorizer',
			cors: true
		}]

		['janis.apiPost', {
			entityName: 'product',
			authorizer: 'FullAuthorizer',
			cors: true
		}],

		['janis.apiPut', {
			entityName: 'product',
			authorizer: 'FullAuthorizer',
			cors: true
		}],

		['janis.apiList', {
			entityName: 'otherEntity',
			authorizer: 'FullAuthorizer',
			cors: {
				origins: ['*'], // Open to every origin
				allowCredentials: false
			}
		}],

		['janis.eventListener', {
			serviceName: 'catalog',
			entityName: 'product',
			eventName: 'created',
			mustHaveClient: true
		}],

		['janis.stateMachine', {
			name: 'StateMachineName',
			definition: {
				Comment: 'State Machine Comment',
				StartAt: 'WaitForCall',
				States: {
					WaitForCall: {
						Type: 'Wait',
						SecondsPath: '$.body.wait',
						Next: 'Finish'
					}
				}
			}
		}]

	]
}, {});

Keywords

FAQs

Package last updated on 05 Jul 2023

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