alexa-lambda-skill
Advanced tools
Comparing version 3.0.3 to 4.0.0
@@ -6,3 +6,2 @@ 'use strict'; | ||
var Promise = _interopDefault(require('bluebird')); | ||
var alexaResponse = require('alexa-response'); | ||
var $inject_Object_values = _interopDefault(require('object-values')); | ||
@@ -105,38 +104,12 @@ | ||
var NotFound = alexaResponse.say('I\'m sorry, I don\'t know how to do that.'); | ||
var Unauthorized = { code: 401, message: 'Unauthorized application ID' }; | ||
var NotFound = { code: 404, message: 'Route not found' }; | ||
var InternalServer = { code: 500, message: 'Internal skill error' }; | ||
var _Skill = (function (Skill) { | ||
return function (event, context) { | ||
var _ref = context || {}; | ||
var _ErrorCode = Object.freeze({ | ||
Unauthorized: Unauthorized, | ||
NotFound: NotFound, | ||
InternalServer: InternalServer | ||
}); | ||
var succeed = _ref.succeed; | ||
var fail = _ref.fail; | ||
var _ref2 = event || {}; | ||
var request = _ref2.request; | ||
var session = _ref2.session; | ||
var _ref3 = session || {}; | ||
var attributes = _ref3.attributes; | ||
var skill = new Skill(attributes); | ||
var result = skill.route && skill.route(request) || NotFound; | ||
return Promise.resolve(result).then(function (response) { | ||
return response.build && typeof response.build === 'function' ? response.build(attributes) : response; | ||
}).then(function (response) { | ||
succeed && succeed(response); | ||
return response; | ||
}).catch(function () { | ||
var error = arguments.length <= 0 || arguments[0] === undefined ? 'Unknown error' : arguments[0]; | ||
fail && fail(error); | ||
return error; | ||
}); | ||
}; | ||
}) | ||
var _class; | ||
@@ -153,2 +126,9 @@ var _temp; | ||
babelHelpers.createClass(Request, [{ | ||
key: 'session', | ||
value: function session(_session) { | ||
return new Request(babelHelpers.extends({}, this.state, { | ||
session: babelHelpers.extends({}, this.state.session, _session) | ||
})); | ||
} | ||
}, { | ||
key: 'intent', | ||
@@ -199,16 +179,83 @@ value: function intent(name) { | ||
return Request; | ||
}(), _class.intent = function () { | ||
}(), _class.session = function () { | ||
var _ref3; | ||
return (_ref3 = new Request()).intent.apply(_ref3, arguments); | ||
}, _class.launchRequest = function () { | ||
return (_ref3 = new Request()).session.apply(_ref3, arguments); | ||
}, _class.intent = function () { | ||
var _ref4; | ||
return (_ref4 = new Request()).launchRequest.apply(_ref4, arguments); | ||
}, _class.sessionEndedRequest = function () { | ||
return (_ref4 = new Request()).intent.apply(_ref4, arguments); | ||
}, _class.launchRequest = function () { | ||
var _ref5; | ||
return (_ref5 = new Request()).sessionEndedRequest.apply(_ref5, arguments); | ||
return (_ref5 = new Request()).launchRequest.apply(_ref5, arguments); | ||
}, _class.sessionEndedRequest = function () { | ||
var _ref6; | ||
return (_ref6 = new Request()).sessionEndedRequest.apply(_ref6, arguments); | ||
}, _temp); | ||
var isAuthorized = function isAuthorized() { | ||
var expected = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var actual = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
var isOK = !expected.applicationId || expected.applicationId === actual.applicationId; | ||
return isOK ? Promise.resolve() : Promise.reject(Unauthorized); | ||
}; | ||
var SkillAnnotation = function SkillAnnotation(options) { | ||
return function (Skill) { | ||
return function (event, context) { | ||
var _ref = context || {}; | ||
var succeed = _ref.succeed; | ||
var fail = _ref.fail; | ||
var _ref2 = event || {}; | ||
var request = _ref2.request; | ||
var session = _ref2.session; | ||
var _ref3 = session || {}; | ||
var application = _ref3.application; | ||
var attributes = _ref3.attributes; | ||
return isAuthorized(options, application).then(function () { | ||
var skill = new Skill(attributes); | ||
return skill.route && skill.route(request) || Promise.reject(NotFound); | ||
}).then(function (response) { | ||
return response.build && typeof response.build === 'function' ? response.build(attributes) : response; | ||
}).then(function (response) { | ||
succeed && succeed(response); | ||
return response; | ||
}).catch(function () { | ||
var error = arguments.length <= 0 || arguments[0] === undefined ? InternalServer : arguments[0]; | ||
fail && fail(error); | ||
return error; | ||
}); | ||
}; | ||
}; | ||
}; | ||
/******************************************************************************* | ||
* This provides multiple ways of using the @Skill annotation: | ||
* | ||
* 1. @Skill | ||
* 2. @Skill() | ||
* 3. @Skill({ applicationId: 'my-authorized-application-id' }) | ||
******************************************************************************/ | ||
var _Skill = (function () { | ||
var optionsOrSkill = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var isSkill = typeof optionsOrSkill === 'function'; | ||
var options = isSkill ? {} : optionsOrSkill; | ||
var skill = isSkill && optionsOrSkill; | ||
return isSkill ? SkillAnnotation(options)(skill) : SkillAnnotation(options); | ||
}) | ||
var annotation = function annotation(predicate) { | ||
@@ -223,10 +270,4 @@ var transform = arguments.length <= 1 || arguments[1] === undefined ? function (i) { | ||
skill.route = function () { | ||
var _skill$name; | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return route.apply(undefined, args) || predicate.apply(undefined, args) && (_skill$name = skill[name]).call.apply(_skill$name, [skill, transform.apply(undefined, args)].concat(args)); | ||
skill.route = function (request) { | ||
return route.call(this, request) || predicate(request) && skill[name].call(this, transform(request), request); | ||
}; | ||
@@ -249,4 +290,4 @@ | ||
var Intent = function Intent() { | ||
for (var _len2 = arguments.length, names = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
names[_key2] = arguments[_key2]; | ||
for (var _len = arguments.length, names = Array(_len), _key = 0; _key < _len; _key++) { | ||
names[_key] = arguments[_key]; | ||
} | ||
@@ -270,6 +311,7 @@ | ||
exports.ErrorCode = _ErrorCode; | ||
exports.Request = Request; | ||
exports.Skill = _Skill; | ||
exports.Request = Request; | ||
exports.Launch = Launch; | ||
exports.Intent = Intent; | ||
exports.SessionEnded = SessionEnded; |
@@ -1,1 +0,1 @@ | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e["default"]:e}var Promise=_interopDefault(require("bluebird")),alexaResponse=require("alexa-response"),$inject_Object_values=_interopDefault(require("object-values")),babelHelpers={};babelHelpers.classCallCheck=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},babelHelpers.createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),babelHelpers.defineProperty=function(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e},babelHelpers["extends"]=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},babelHelpers.slicedToArray=function(){function e(e,n){var t=[],r=!0,a=!1,u=void 0;try{for(var s,o=e[Symbol.iterator]();!(r=(s=o.next()).done)&&(t.push(s.value),!n||t.length!==n);r=!0);}catch(l){a=!0,u=l}finally{try{!r&&o["return"]&&o["return"]()}finally{if(a)throw u}}return t}return function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return e(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var NotFound=alexaResponse.say("I'm sorry, I don't know how to do that."),_Skill=function(e){return function(n,t){var r=t||{},a=r.succeed,u=r.fail,s=n||{},o=s.request,l=s.session,i=l||{},c=i.attributes,p=new e(c),f=p.route&&p.route(o)||NotFound;return Promise.resolve(f).then(function(e){return e.build&&"function"==typeof e.build?e.build(c):e}).then(function(e){return a&&a(e),e})["catch"](function(){var e=arguments.length<=0||void 0===arguments[0]?"Unknown error":arguments[0];return u&&u(e),e})}},_class,_temp,Request=(_temp=_class=function(){function e(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];babelHelpers.classCallCheck(this,e),this.state=n}return babelHelpers.createClass(e,[{key:"intent",value:function(n){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=Object.entries(t).reduce(function(e,n){var t=babelHelpers.slicedToArray(n,2),r=t[0],a=t[1];return babelHelpers["extends"]({},e,babelHelpers.defineProperty({},r,{name:r,value:a}))},{});return new e(babelHelpers["extends"]({},this.state,{request:{type:"IntentRequest",intent:babelHelpers["extends"]({name:n},Object.keys(r).length?{slots:r}:null)}}))}},{key:"launchRequest",value:function(){return new e(babelHelpers["extends"]({},this.state,{request:{type:"LaunchRequest"}}))}},{key:"sessionEndedRequest",value:function(){return new e(babelHelpers["extends"]({},this.state,{request:{type:"SessionEndedRequest"}}))}},{key:"build",value:function(){return babelHelpers["extends"]({},this.state)}}]),e}(),_class.intent=function(){var e;return(e=new Request).intent.apply(e,arguments)},_class.launchRequest=function(){var e;return(e=new Request).launchRequest.apply(e,arguments)},_class.sessionEndedRequest=function(){var e;return(e=new Request).sessionEndedRequest.apply(e,arguments)},_temp),annotation=function(e){var n=arguments.length<=1||void 0===arguments[1]?function(e){return e}:arguments[1];return function(t,r){var a=t.route||function(){return!1};return t.route=function(){for(var u,s=arguments.length,o=Array(s),l=0;s>l;l++)o[l]=arguments[l];return a.apply(void 0,o)||e.apply(void 0,o)&&(u=t[r]).call.apply(u,[t,n.apply(void 0,o)].concat(o))},t}},Launch=annotation(function(e){var n=e.type;return"LaunchRequest"===n}),SessionEnded=annotation(function(e){var n=e.type;return"SessionEndedRequest"===n}),Intent=function(){for(var e=arguments.length,n=Array(e),t=0;e>t;t++)n[t]=arguments[t];return annotation(function(e){var t=e.type,r=e.intent,a=void 0===r?{}:r;return"IntentRequest"===t&&n.indexOf(a.name)>=0},function(e){var n=e.intent,t=void 0===n?{}:n;return $inject_Object_values(t.slots||{}).reduce(function(e,n){var t=n.name,r=n.value;return t&&null!=r?babelHelpers["extends"]({},e,babelHelpers.defineProperty({},t,r)):e},{})})};exports.Skill=_Skill,exports.Request=Request,exports.Launch=Launch,exports.Intent=Intent,exports.SessionEnded=SessionEnded; | ||
"use strict";function _interopDefault(e){return e&&"object"==typeof e&&"default"in e?e["default"]:e}var Promise=_interopDefault(require("bluebird")),$inject_Object_values=_interopDefault(require("object-values")),babelHelpers={};babelHelpers.classCallCheck=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},babelHelpers.createClass=function(){function e(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}return function(n,t,r){return t&&e(n.prototype,t),r&&e(n,r),n}}(),babelHelpers.defineProperty=function(e,n,t){return n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t,e},babelHelpers["extends"]=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},babelHelpers.slicedToArray=function(){function e(e,n){var t=[],r=!0,u=!1,a=void 0;try{for(var o,s=e[Symbol.iterator]();!(r=(o=s.next()).done)&&(t.push(o.value),!n||t.length!==n);r=!0);}catch(i){u=!0,a=i}finally{try{!r&&s["return"]&&s["return"]()}finally{if(u)throw a}}return t}return function(n,t){if(Array.isArray(n))return n;if(Symbol.iterator in Object(n))return e(n,t);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();var Unauthorized={code:401,message:"Unauthorized application ID"},NotFound={code:404,message:"Route not found"},InternalServer={code:500,message:"Internal skill error"},_ErrorCode=Object.freeze({Unauthorized:Unauthorized,NotFound:NotFound,InternalServer:InternalServer}),_class,_temp,Request=(_temp=_class=function(){function e(){var n=arguments.length<=0||void 0===arguments[0]?{}:arguments[0];babelHelpers.classCallCheck(this,e),this.state=n}return babelHelpers.createClass(e,[{key:"session",value:function(n){return new e(babelHelpers["extends"]({},this.state,{session:babelHelpers["extends"]({},this.state.session,n)}))}},{key:"intent",value:function(n){var t=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],r=Object.entries(t).reduce(function(e,n){var t=babelHelpers.slicedToArray(n,2),r=t[0],u=t[1];return babelHelpers["extends"]({},e,babelHelpers.defineProperty({},r,{name:r,value:u}))},{});return new e(babelHelpers["extends"]({},this.state,{request:{type:"IntentRequest",intent:babelHelpers["extends"]({name:n},Object.keys(r).length?{slots:r}:null)}}))}},{key:"launchRequest",value:function(){return new e(babelHelpers["extends"]({},this.state,{request:{type:"LaunchRequest"}}))}},{key:"sessionEndedRequest",value:function(){return new e(babelHelpers["extends"]({},this.state,{request:{type:"SessionEndedRequest"}}))}},{key:"build",value:function(){return babelHelpers["extends"]({},this.state)}}]),e}(),_class.session=function(){var e;return(e=new Request).session.apply(e,arguments)},_class.intent=function(){var e;return(e=new Request).intent.apply(e,arguments)},_class.launchRequest=function(){var e;return(e=new Request).launchRequest.apply(e,arguments)},_class.sessionEndedRequest=function(){var e;return(e=new Request).sessionEndedRequest.apply(e,arguments)},_temp),isAuthorized=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n=arguments.length<=1||void 0===arguments[1]?{}:arguments[1],t=!e.applicationId||e.applicationId===n.applicationId;return t?Promise.resolve():Promise.reject(Unauthorized)},SkillAnnotation=function(e){return function(n){return function(t,r){var u=r||{},a=u.succeed,o=u.fail,s=t||{},i=s.request,l=s.session,c=l||{},d=c.application,f=c.attributes;return isAuthorized(e,d).then(function(){var e=new n(f);return e.route&&e.route(i)||Promise.reject(NotFound)}).then(function(e){return e.build&&"function"==typeof e.build?e.build(f):e}).then(function(e){return a&&a(e),e})["catch"](function(){var e=arguments.length<=0||void 0===arguments[0]?InternalServer:arguments[0];return o&&o(e),e})}}},_Skill=function(){var e=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],n="function"==typeof e,t=n?{}:e,r=n&&e;return n?SkillAnnotation(t)(r):SkillAnnotation(t)},annotation=function(e){var n=arguments.length<=1||void 0===arguments[1]?function(e){return e}:arguments[1];return function(t,r){var u=t.route||function(){return!1};return t.route=function(a){return u.call(this,a)||e(a)&&t[r].call(this,n(a),a)},t}},Launch=annotation(function(e){var n=e.type;return"LaunchRequest"===n}),SessionEnded=annotation(function(e){var n=e.type;return"SessionEndedRequest"===n}),Intent=function(){for(var e=arguments.length,n=Array(e),t=0;e>t;t++)n[t]=arguments[t];return annotation(function(e){var t=e.type,r=e.intent,u=void 0===r?{}:r;return"IntentRequest"===t&&n.indexOf(u.name)>=0},function(e){var n=e.intent,t=void 0===n?{}:n;return $inject_Object_values(t.slots||{}).reduce(function(e,n){var t=n.name,r=n.value;return t&&null!=r?babelHelpers["extends"]({},e,babelHelpers.defineProperty({},t,r)):e},{})})};exports.ErrorCode=_ErrorCode,exports.Request=Request,exports.Skill=_Skill,exports.Launch=Launch,exports.Intent=Intent,exports.SessionEnded=SessionEnded; |
@@ -9,3 +9,3 @@ { | ||
"description": "Create Alexa Skills for AWS Lambda, easily.", | ||
"version": "3.0.3", | ||
"version": "4.0.0", | ||
"main": "build/index.min.js", | ||
@@ -31,3 +31,2 @@ "jsnext:main": "src/index.js", | ||
"dependencies": { | ||
"alexa-response": "^3.0.0", | ||
"bluebird": "^3.3.4", | ||
@@ -38,3 +37,3 @@ "object-values": "^1.0.0" | ||
"ava": "^0.13.0", | ||
"babel-eslint": "^6.0.0", | ||
"babel-eslint": "^6.0.2", | ||
"babel-plugin-transform-class-properties": "^6.6.0", | ||
@@ -47,3 +46,3 @@ "babel-plugin-transform-decorators-legacy": "^1.3.4", | ||
"babel-register": "^6.7.2", | ||
"eslint": "^2.5.3", | ||
"eslint": "^2.6.0", | ||
"isomorphic-fetch": "^2.2.1", | ||
@@ -50,0 +49,0 @@ "npm-run-all": "^1.7.0", |
const annotation = (predicate, transform = i => i) => (skill, name) => { | ||
const route = skill.route || (() => false); | ||
skill.route = (...args) => { | ||
return route(...args) || (predicate(...args) && skill[name].call(skill, transform(...args), ...args)); | ||
skill.route = function(request) { | ||
return route.call(this, request) || (predicate(request) && skill[name].call(this, transform(request), request)); | ||
}; | ||
@@ -11,9 +11,5 @@ | ||
export const Launch = annotation( | ||
({ type }) => type === 'LaunchRequest' | ||
); | ||
export const Launch = annotation(({ type }) => type === 'LaunchRequest'); | ||
export const SessionEnded = annotation( | ||
({ type }) => type === 'SessionEndedRequest' | ||
); | ||
export const SessionEnded = annotation(({ type }) => type === 'SessionEndedRequest'); | ||
@@ -20,0 +16,0 @@ export const Intent = (...names) => annotation( |
@@ -0,3 +1,4 @@ | ||
export * as ErrorCode from './error-codes'; | ||
export Request from './request'; | ||
export Skill from './skill'; | ||
export Request from './request'; | ||
export { Launch, Intent, SessionEnded } from './annotations'; |
export default class Request { | ||
static session = (...args) => new Request().session(...args); | ||
static intent = (...args) => new Request().intent(...args); | ||
@@ -10,2 +11,12 @@ static launchRequest = (...args) => new Request().launchRequest(...args); | ||
session(session) { | ||
return new Request({ | ||
...this.state, | ||
session: { | ||
...this.state.session, | ||
...session | ||
} | ||
}); | ||
} | ||
intent(name, slots = {}) { | ||
@@ -12,0 +23,0 @@ const slotData = Object.entries(slots).reduce((state, [name, value]) => ({ ...state, [name]: { name, value } }), {}); |
@@ -1,19 +0,22 @@ | ||
import { say } from 'alexa-response'; | ||
import { Unauthorized, NotFound, InternalServer } from './error-codes'; | ||
const NotFound = say('I\'m sorry, I don\'t know how to do that.'); | ||
const isAuthorized = (expected = {}, actual = {}) => { | ||
const isOK = !expected.applicationId || expected.applicationId === actual.applicationId; | ||
return isOK ? Promise.resolve() : Promise.reject(Unauthorized); | ||
}; | ||
export default Skill => (event, context) => { | ||
const SkillAnnotation = (options) => (Skill) => (event, context) => { | ||
const { succeed, fail } = context || {}; | ||
const { request, session } = event || {}; | ||
const { attributes } = session || {}; | ||
const { application, attributes } = session || {}; | ||
const skill = new Skill(attributes); | ||
const result = (skill.route && skill.route(request)) || NotFound; | ||
return Promise.resolve(result).then(response => ( | ||
(response.build && typeof response.build === 'function') ? response.build(attributes) : response | ||
)).then(response => { | ||
return isAuthorized(options, application).then(() => { | ||
const skill = new Skill(attributes); | ||
return (skill.route && skill.route(request)) || Promise.reject(NotFound); | ||
}).then(response => { | ||
return (response.build && typeof response.build === 'function') ? response.build(attributes) : response; | ||
}).then(response => { | ||
succeed && succeed(response); | ||
return response; | ||
}).catch((error = 'Unknown error') => { | ||
}).catch((error = InternalServer) => { | ||
fail && fail(error); | ||
@@ -23,1 +26,17 @@ return error; | ||
}; | ||
/******************************************************************************* | ||
* This provides multiple ways of using the @Skill annotation: | ||
* | ||
* 1. @Skill | ||
* 2. @Skill() | ||
* 3. @Skill({ applicationId: 'my-authorized-application-id' }) | ||
******************************************************************************/ | ||
export default (optionsOrSkill = {}) => { | ||
const isSkill = typeof optionsOrSkill === 'function'; | ||
const options = isSkill ? {} : optionsOrSkill; | ||
const skill = isSkill && optionsOrSkill; | ||
return isSkill ? SkillAnnotation(options)(skill) : SkillAnnotation(options); | ||
}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22748
2
10
367
- Removedalexa-response@^3.0.0
- Removedalexa-response@3.2.3(transitive)
- Removedalexa-ssml-jsx@1.4.2(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedobject-assign@4.1.1(transitive)
- Removedprop-types@15.8.1(transitive)
- Removedreact-is@16.13.1(transitive)
- Removedssml-jsx@1.4.2(transitive)