mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
feat(Config Schema): Schema for AWS alexaSmartHome event (#8255)
This commit is contained in:
parent
8409d61e29
commit
bd5099e150
@ -11,9 +11,19 @@ class AwsCompileAlexaSmartHomeEvents {
|
||||
'package:compileEvents': this.compileAlexaSmartHomeEvents.bind(this),
|
||||
};
|
||||
|
||||
// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8024
|
||||
this.serverless.configSchemaHandler.defineFunctionEvent('aws', 'alexaSmartHome', {
|
||||
anyOf: [{ type: 'string' }, { type: 'object' }],
|
||||
anyOf: [
|
||||
{ $ref: '#/definitions/awsAlexaEventToken' },
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
appId: { $ref: '#/definitions/awsAlexaEventToken' },
|
||||
enabled: { type: 'boolean' },
|
||||
},
|
||||
required: ['appId'],
|
||||
additionalProperties: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
@ -30,15 +40,6 @@ class AwsCompileAlexaSmartHomeEvents {
|
||||
let Action;
|
||||
|
||||
if (typeof event.alexaSmartHome === 'object') {
|
||||
if (!event.alexaSmartHome.appId) {
|
||||
const errorMessage = [
|
||||
`Missing "appId" property for alexaSmartHome event in function ${functionName}`,
|
||||
' The correct syntax is: appId: amzn1.ask.skill.xxxx-xxxx',
|
||||
' OR an object with "appId" property.',
|
||||
' Please check the docs for more info.',
|
||||
].join('');
|
||||
throw new this.serverless.classes.Error(errorMessage);
|
||||
}
|
||||
EventSourceToken = event.alexaSmartHome.appId;
|
||||
Action =
|
||||
event.alexaSmartHome.enabled !== false
|
||||
@ -47,13 +48,6 @@ class AwsCompileAlexaSmartHomeEvents {
|
||||
} else if (typeof event.alexaSmartHome === 'string') {
|
||||
EventSourceToken = event.alexaSmartHome;
|
||||
Action = 'lambda:InvokeFunction';
|
||||
} else {
|
||||
const errorMessage = [
|
||||
`Alexa Smart Home event of function "${functionName}" is not an object or string.`,
|
||||
' The correct syntax is: alexaSmartHome.',
|
||||
' Please check the docs for more info.',
|
||||
].join('');
|
||||
throw new this.serverless.classes.Error(errorMessage);
|
||||
}
|
||||
const lambdaLogicalId = this.provider.naming.getLambdaLogicalId(functionName);
|
||||
|
||||
|
||||
@ -23,36 +23,6 @@ describe('AwsCompileAlexaSmartHomeEvents', () => {
|
||||
});
|
||||
|
||||
describe('#compileAlexaSmartHomeEvents()', () => {
|
||||
it('should throw an error if alexaSmartHome event type is not a string or an object', () => {
|
||||
awsCompileAlexaSmartHomeEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
alexaSmartHome: 42,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(() => awsCompileAlexaSmartHomeEvents.compileAlexaSmartHomeEvents()).to.throw(Error);
|
||||
});
|
||||
|
||||
it('should throw an error if the "appId" property is not given', () => {
|
||||
awsCompileAlexaSmartHomeEvents.serverless.service.functions = {
|
||||
first: {
|
||||
events: [
|
||||
{
|
||||
alexaSmartHome: {
|
||||
appId: null,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
expect(() => awsCompileAlexaSmartHomeEvents.compileAlexaSmartHomeEvents()).to.throw(Error);
|
||||
});
|
||||
|
||||
it('should create corresponding resources when alexaSmartHome events are given', () => {
|
||||
awsCompileAlexaSmartHomeEvents.serverless.service.functions = {
|
||||
first: {
|
||||
|
||||
@ -142,6 +142,12 @@ class AwsProvider {
|
||||
// TODO: Complete schema, see https://github.com/serverless/serverless/issues/8016
|
||||
serverless.configSchemaHandler.defineProvider('aws', {
|
||||
definitions: {
|
||||
awsAlexaEventToken: {
|
||||
type: 'string',
|
||||
minLength: 0,
|
||||
maxLength: 256,
|
||||
pattern: '^[a-zA-Z0-9._\\-]+$',
|
||||
},
|
||||
awsArn: {
|
||||
oneOf: [
|
||||
{ $ref: '#/definitions/awsArnString' },
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user