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
1
Versions
147
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sls-helper-plugin-janis - npm Package Compare versions

Comparing version 1.2.4 to 1.3.0

lib/api/api.js

8

CHANGELOG.md

@@ -9,2 +9,10 @@ # Changelog

## [1.3.0] - 2020-01-16
### Added
- `janis.api` hook added to implement custom APIs
### Changed
- Option `serviceName` changed to `serviceCode` in `janis.base` hook **BREAKING CHANGE**
- Added service name to naming, file path and API path in `janis.eventListener` hook
## [1.2.4] - 2019-12-27

@@ -11,0 +19,0 @@ ### Fixed

12

lib/api/base.js

@@ -5,4 +5,4 @@ 'use strict';

const startCase = require('lodash.startcase');
const kebabCase = require('lodash.kebabcase');
const startcase = require('lodash.startcase');
const kebabcase = require('lodash.kebabcase');

@@ -34,4 +34,4 @@ const { getPathParameters } = require('../utils/parameters');

const entityNameAsTitle = startCase(entityName);
const entityNameAsKebab = kebabCase(entityName);
const entityNameAsTitle = startcase(entityName);
const entityNameAsKebab = kebabcase(entityName);

@@ -64,3 +64,3 @@ const realPath = path || (pathHasId ? `/${entityNameAsKebab}/{id}` : `/${entityNameAsKebab}`);

handler: handler || 'src/lambda/RestApi/index.handler',
description: `${entityNameAsTitle} ${startCase(methodName)} API`,
description: `${entityNameAsTitle} ${startcase(methodName)} API`,
package: {

@@ -75,3 +75,3 @@ include: [

return { [`${entityNameAsTitle.replace(/ /g, '')}${startCase(methodName)}Api`]: functionConfiguration };
return { [`${entityNameAsTitle.replace(/ /g, '')}${startcase(methodName)}Api`]: functionConfiguration };
};

@@ -78,0 +78,0 @@

@@ -5,15 +5,24 @@ 'use strict';

const startCase = require('lodash.startcase');
const kebabCase = require('lodash.kebabcase');
const startcase = require('lodash.startcase');
const kebabcase = require('lodash.kebabcase');
const INTEGRATION = 'lambda';
const eventListener = ({ entityName, eventName, mustHaveClient, listenersDirName }) => {
const eventListener = ({
serviceName,
entityName,
eventName,
mustHaveClient,
listenersDirName
}) => {
const entityNameAsTitle = startCase(entityName);
const entityNameAsKebab = kebabCase(entityName);
const serviceNameAsTitle = startcase(serviceName);
const serviceAsKebab = kebabcase(serviceName);
const eventNameAsTitle = startCase(eventName);
const eventNameAsKebab = kebabCase(eventName);
const entityNameAsTitle = startcase(entityName);
const entityNameAsKebab = kebabcase(entityName);
const eventNameAsTitle = startcase(eventName);
const eventNameAsKebab = kebabcase(eventName);
const authorizer = mustHaveClient ? 'ServiceAuthorizer' : 'ServiceNoClientAuthorizer';

@@ -25,4 +34,4 @@

[listenerName]: {
handler: `src/${listenersDirName}/${entityNameAsKebab}/${eventNameAsKebab}.handler`,
description: `${entityNameAsTitle} ${eventNameAsTitle} Listener`,
handler: `src/${listenersDirName}/${serviceAsKebab}/${entityNameAsKebab}/${eventNameAsKebab}.handler`,
description: `${serviceNameAsTitle} ${entityNameAsTitle} ${eventNameAsTitle} Listener`,
events: [

@@ -32,3 +41,3 @@ {

integration: INTEGRATION,
path: `/listener/${entityNameAsKebab}/${eventNameAsKebab}`,
path: `/listener/${serviceAsKebab}/${entityNameAsKebab}/${eventNameAsKebab}`,
method: 'post',

@@ -60,2 +69,5 @@ authorizer: `\${self:custom.authorizers.${authorizer}}`,

if(!params.serviceName)
throw new Error('Missing or empty serviceName in janis.eventListener hook.');
if(!params.entityName)

@@ -62,0 +74,0 @@ throw new Error('Missing or empty entityName in janis.eventListener hook.');

@@ -11,2 +11,4 @@ 'use strict';

module.exports.api = require('./api/api');
module.exports.apiGet = require('./api/get');

@@ -13,0 +15,0 @@

'use strict';
const { inspect } = require('util');
const kebabCase = require('lodash.kebabcase');
module.exports = ({ provider, custom, package: slsPackage, ...serviceConfig }, { serviceName, servicePort, apiSecrets }) => {
const startcase = require('lodash.startcase');
const kebabcase = require('lodash.kebabcase');
if(!serviceName || typeof serviceName !== 'string')
throw new Error(`Missing or invalid serviceName in janis.base hook: ${inspect(serviceName)}`);
module.exports = ({ provider, custom, package: slsPackage, ...serviceConfig }, { serviceCode, servicePort, apiSecrets }) => {
if(!serviceCode || typeof serviceCode !== 'string')
throw new Error(`Missing or invalid serviceCode in janis.base hook: ${inspect(serviceCode)}`);
if(serviceCode !== kebabcase(serviceCode))
throw new Error(`Invalid serviceCode in janis.base hook. It must be in dash-case. Received ${serviceCode}. Recommended: ${kebabcase(serviceCode)}`);
if(!servicePort || typeof servicePort !== 'number')
throw new Error(`Missing or invalid servicePort in janis.base hook: ${inspect(servicePort)}`);
const serviceNameInLowerCase = kebabCase(serviceName);
const serviceTitle = startcase(serviceCode);
const serviceName = serviceTitle.replace(/ /g, '');

@@ -27,5 +33,5 @@ const { include, ...restOfPackage } = slsPackage || {};

endpointType: 'REGIONAL',
apiName: 'JANIS ${self:custom.humanReadableStage.${self:custom.stage}} ${self:custom.serviceName} API',
apiName: 'JANIS ${self:custom.humanReadableStage.${self:custom.stage}} ${self:custom.serviceTitle} API',
environment: {
JANIS_SERVICE_NAME: '${self:custom.serviceNameInLowerCase}',
JANIS_SERVICE_NAME: '${self:custom.serviceCode}',
JANIS_SERVICE_SECRET: '${self:custom.serviceApiSecret.${self:custom.stage}}',

@@ -62,4 +68,5 @@ JANIS_ENV: '${self:custom.stage}',

custom: {
serviceTitle,
serviceName,
serviceNameInLowerCase,
serviceCode,
stage: '${opt:stage, self:provider.stage}',

@@ -92,3 +99,3 @@ region: '${opt:region, self:provider.region}',

customDomain: {
domainName: '${self:custom.serviceNameInLowerCase}.${self:custom.janisDomains.${self:custom.stage}}',
domainName: '${self:custom.serviceCode}.${self:custom.janisDomains.${self:custom.stage}}',
basePath: 'api',

@@ -111,3 +118,3 @@ stage: '${self:custom.stage}',

stageVariables: {
serviceName: '${self:custom.serviceNameInLowerCase}'
serviceName: '${self:custom.serviceCode}'
},

@@ -126,2 +133,7 @@

prune: {
automatic: true,
number: 3
},
...(custom || {})

@@ -135,2 +147,4 @@ },

'serverless-plugin-reducer',
'serverless-plugin-split-stacks',
'serverless-plugin-prune',
'serverless-plugin-stage-variables'

@@ -137,0 +151,0 @@ ],

{
"name": "sls-helper-plugin-janis",
"version": "1.2.4",
"version": "1.3.0",
"description": "A Serverless Helper plugin to add custom helpers for JANIS Commerce",

@@ -5,0 +5,0 @@ "main": "lib/plugin.js",

@@ -13,3 +13,3 @@ # Serverless Helper Plugin JANIS

|--------|------|-------------|------------|---------------|
| serviceName | string | The service name | **Required** | |
| serviceCode | string | The service name in lowercase dash separated | **Required** | |
| servicePort | number | The service port | **Required** | |

@@ -40,4 +40,4 @@ | apiSecrets | Object | A mapping of stages to Service API Secret | | `undefined` |

| replace | boolean | Indicates whether it should replace the CORS properties or merge then with the default | false |
| origins | array<string> | An array of allowed origins | [See below](#cors-default-origins) |
| headers | array<string> | An array of allowed headers | [See below](#cors-default-headers) |
| origins | array\<string\> | An array of allowed origins | [See below](#cors-default-origins) |
| headers | array\<string\> | An array of allowed headers | [See below](#cors-default-headers) |
| allowCredentials | boolean | Indicates whether the credentials header should be set | `true` |

@@ -70,2 +70,18 @@ | maxAge | number | The time in seconds thar CORS headers should be cached | 600 |

### api
Used to implement a custom API
| Option | Type | Description | Attributes | Default value |
|--------|------|-------------|------------|---------------|
| path | string | The API path | **Required** | |
| method | string | The API HTTP Method | | `'get'` |
| methodName | string | The JANIS API Method | Enum\<list, get, post, put, patch, delete\> | Defaults to same value of `method` option |
| handler | string | The lambda handler path and function | | `'src/lambda/RestApi/index.handler'` |
| caching | boolean | Set to true to enable cache | | `false` |
| cors | boolean | Set to true to enable cors | | `false` |
| queryParameters | object | A key value to map query string parameters to a boolean indicating if it's required or not | | |
| requestHeaders | object | A key value to map headers to a boolean indicating if it's required or not | | |
| authorizer | string | The name of the authorizer | Valid authorizers: FullAuthorizer, NoClientAuthorizer, LoggedAuthorizer, ApiKeyAuthorizer, UserAuthorizer, DevUserAuthorizer, ServiceAuthorizer, ServiceNoClientAuthorizer, ClientAuthorizer | |
### apiList, apiGet, apiPost and apiPut

@@ -78,6 +94,6 @@

| entityName | string | The entity name | **Required** | |
| handler | string | The lambda handler path and function | | src/lambda/RestApi/index.handler |
| handler | string | The lambda handler path and function | | `'src/lambda/RestApi/index.handler'` |
| path | string | The API path | | `/[entity-name]` (for apiList and apiPost) or `/[entity-name]/{id}` (for apiGet and apiPut) |
| caching | boolean | Set to true to enable cache | | false |
| cors | boolean | Set to true to enable cors | | false |
| caching | boolean | Set to true to enable cache | | `false` |
| cors | boolean | Set to true to enable cors | | `false` |
| queryParameters | object | A key value to map query string parameters to a boolean indicating if it's required or not | | |

@@ -95,4 +111,4 @@ | requestHeaders | object | A key value to map headers to a boolean indicating if it's required or not | | |

| eventName | string | The event name | **Required** | |
| mustHaveClient | boolean | Indicates if authorizer must validate that client or not | | false |
| listenersDirName | string | Indicates the path where the event listener files are placed | | 'event-listeners' |
| mustHaveClient | boolean | Indicates if authorizer must validate that client or not | | `false` |
| listenersDirName | string | Indicates the path where the event listener files are placed | | `'event-listeners'` |

@@ -114,3 +130,3 @@ ## Examples

['janis.base', {
serviceName: 'Catalog',
serviceCode: 'my-service',
servicePort: 5000,

@@ -130,2 +146,8 @@ apiSecrets: {

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

@@ -132,0 +154,0 @@ entityName: 'product',

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