16 | [ ] Regression (a behavior that used to work and stopped working in a new release)
17 | [ ] Bug report
18 | [ ] Performance issue
19 | [ ] Feature request
20 | [ ] Documentation issue or request
21 | [ ] Other... Please describe:
22 |
23 |
24 |
25 |
26 | ## Expected Behavior
27 |
28 |
29 |
30 | ## Current Behavior
31 |
32 |
33 |
34 |
35 |
36 | ## Possible Solution
37 |
38 |
39 |
40 | ## Steps to Reproduce (for bugs)
41 |
42 |
43 |
44 |
45 | ## Context
46 |
47 |
48 |
49 | ## Your Environment
50 |
51 | * ASK SDK for Node.js used: x.x.x
52 | * Operating System and version:
53 |
54 | ## Node.js and NPM Info
55 | * Node.js version used for development:
56 | * NPM version used for development:
57 |
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | ## Description
4 |
5 |
6 | ## Motivation and Context
7 |
8 |
9 |
10 | ## Testing
11 |
12 |
13 |
14 |
15 | ## Screenshots (if appropriate)
16 |
17 | ## Types of changes
18 |
19 | - [ ] Bug fix (non-breaking change which fixes an issue)
20 | - [ ] New feature (non-breaking change which adds functionality)
21 | - [ ] Breaking change (fix or feature that would cause existing functionality to change)
22 | - [ ] Docs(Add new document content)
23 | - [ ] Translate Docs(Translate document content)
24 |
25 | ## Checklist
26 |
27 |
28 | - [ ] My code follows the code style of this project
29 | - [ ] My change requires a change to the documentation
30 | - [ ] I have updated the documentation accordingly
31 | - [ ] I have read the **README** document
32 | - [ ] I have added tests to cover my changes
33 | - [ ] All new and existing tests passed
34 | - [ ] My commit message follows [Conventional Commit Guideline](https://conventionalcommits.org/)
35 |
36 | ## License
37 | - [ ] By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
38 |
39 | [issues]: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues
40 | [license]: http://aws.amazon.com/apache2.0/
41 | [cla]: http://en.wikipedia.org/wiki/Contributor_License_Agreement
42 |
--------------------------------------------------------------------------------
/.github/workflows/ask-sdk-unit-test.yml:
--------------------------------------------------------------------------------
1 | name: Unit Tests on ask-sdk
2 |
3 | on:
4 | push:
5 | branches:
6 | - 2.0.x
7 | pull_request:
8 | branches:
9 | - 2.0.x
10 |
11 | jobs:
12 | build:
13 | runs-on: ${{ matrix.os }}
14 | strategy:
15 | matrix:
16 | os: [ubuntu-latest, macos-latest, windows-latest]
17 | node: [12, 14]
18 | steps:
19 | - uses: actions/checkout@v2
20 | - name: Use Node.js ${{ matrix.node }}
21 | uses: actions/setup-node@v1
22 | with:
23 | node-version: ${{ matrix.node }}
24 | - run: npm install
25 | - run: npm run bootstrap
26 | - run: npm run build
27 | - run: npm run test
28 |
--------------------------------------------------------------------------------
/.github/workflows/ask-smapi-sdk-unit-test.yml:
--------------------------------------------------------------------------------
1 | name: Unit Tests on ask-smapi-sdk
2 |
3 | on:
4 | push:
5 | branches:
6 | - 2.0.x
7 | paths:
8 | - ask-smapi-sdk/**'
9 | pull_request:
10 | branches:
11 | - 2.0.x
12 | paths:
13 | - ask-smapi-sdk/**'
14 |
15 | defaults:
16 | run:
17 | working-directory: ask-smapi-sdk
18 |
19 | jobs:
20 | build:
21 | runs-on: ${{ matrix.os }}
22 | strategy:
23 | matrix:
24 | os: [ubuntu-latest, macos-latest, windows-latest]
25 | node: [12, 14]
26 | steps:
27 | - uses: actions/checkout@v2
28 | - name: Use Node.js ${{ matrix.node }}
29 | uses: actions/setup-node@v1
30 | with:
31 | node-version: ${{ matrix.node }}
32 | - run: npm install
33 | - run: npm run build
34 | - run: npm run test
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | dist/
2 | node_modules/
3 | typedoc/
4 | package-lock.json
5 | .DS_Store
6 |
--------------------------------------------------------------------------------
/ask-sdk-controls/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
ASK SDK Controls Framework (Beta)
8 |
9 |
10 | The ASK SDK Controls framework builds on the [ASK SDK for Node.js](https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs), offering a scalable solution for creating large, multi-turn skills in code with reusable components called *controls*.
11 |
12 | You can find the Github Repo for ASK SDK Controls at [https://github.com/alexa/ask-sdk-controls](https://github.com/alexa/ask-sdk-controls)
13 |
--------------------------------------------------------------------------------
/ask-sdk-core/.gitignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | dist/
3 | doc/
4 | node_modules/
5 | package-lock.json
6 | build
7 |
--------------------------------------------------------------------------------
/ask-sdk-core/.npmignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | doc/
3 | lib/
4 | node_modules/
5 | tst/
6 | package-lock.json
7 | tsconfig.json
8 | .eslintrc.json
9 |
--------------------------------------------------------------------------------
/ask-sdk-core/README.md:
--------------------------------------------------------------------------------
1 | Core SDK package contains basic components and default implementations of ASK SDK v2 for Node.js.
2 |
3 | ## What is ASK SDK v2 for Node.js
4 |
5 | The ASK SDK v2 for Node.js is an open-source Alexa Skill Development Kit. ASK SDK v2 for Node.js makes it easier for you to build highly engaging skills, by allowing you to spend more time on implementing features and less on writing boiler-plate code.
6 |
7 | ## Installing
8 | To use the Core SDK package, you need to install two modules: core SDK and model(peer dependency of core SDK) within your NPM project. Run the following commands in the terminal to install them:
9 |
10 | ```
11 | npm install --save ask-sdk-core
12 | ```
13 |
14 | ```
15 | npm install --save ask-sdk-model
16 | ```
17 |
18 | ## Usage and Getting Started
19 |
20 | You can find a getting started guide [here](https://developer.amazon.com/docs/alexa-skills-kit-sdk-for-nodejs/overview.html).
21 |
22 | ## Usage with TypeScript
23 | The Core SDK package for Node.js bundles TypeScript definition files for use in TypeScript projects and to support tools that can read .d.ts files. Our goal is to keep these TypeScript definition files updated with each release for any public api.
24 |
25 | ### Pre-requisites
26 | Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:
27 | - Use TypeScript v2.x
28 | - Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:
29 |
30 | ```
31 | npm install --save-dev @types/node
32 | ```
33 |
34 | ### In Node.js
35 | To use the TypeScript definition files within a Node.js project, simply import ask-sdk-core as below:
36 |
37 | In a TypeScript file:
38 |
39 | ```typescript
40 | import * as Alexa from 'ask-sdk-core';
41 | ```
42 |
43 | In a JavaScript file:
44 |
45 | ```javascript
46 | const Alexa = require('ask-sdk-core');
47 | ```
48 |
49 | ## Opening Issues
50 | For bug reports, feature requests and questions, we would like to hear about it. Search the [existing issues](https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues) and try to make sure your problem doesn’t already exist before opening a new issue. It’s helpful if you include the version of the SDK, Node.js or browser environment and OS you’re using. Please include a stack trace and reduced repro case when appropriate, too.
51 |
52 | ## License
53 | This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.
54 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/attributes/persistence/PersistenceAdapter.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { RequestEnvelope } from 'ask-sdk-model';
15 |
16 | /**
17 | * An interface for storing and retrieving persistent attributes from persistence tier given request envelope.
18 | */
19 | export interface PersistenceAdapter {
20 | getAttributes(requestEnvelope : RequestEnvelope) : Promise<{[key : string] : any}>;
21 | saveAttributes(requestEnvelope : RequestEnvelope, attributes : {[key : string] : any}) : Promise;
22 | deleteAttributes?(requestEnvelope : RequestEnvelope) : Promise;
23 | }
24 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/components/ComponentInterface.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import {
15 | Directive, Response, Slot
16 | } from 'ask-sdk-model';
17 | import { CustomSkillRequestHandler as RequestHandler } from '../dispatcher/request/handler/CustomSkillRequestHandler';
18 | import { HandlerInput } from '../dispatcher/request/handler/HandlerInput';
19 |
20 | export abstract class ComponentInterface {
21 |
22 | static launch: (options?: {
23 | slots?: {[key : string] : Slot },
24 | isUserUtteranceInput?: boolean
25 | }) => Directive;
26 |
27 | static egress: (egressInput: {
28 | intentName?:string,
29 | callBack?: ((input: HandlerInput) => Response | Promise)
30 | }) => RequestHandler;
31 | }
--------------------------------------------------------------------------------
/ask-sdk-core/lib/dispatcher/error/handler/CustomSkillErrorHandler.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { Response } from 'ask-sdk-model';
15 | import { ErrorHandler } from 'ask-sdk-runtime';
16 | import { HandlerInput } from '../../request/handler/HandlerInput';
17 |
18 | export interface CustomSkillErrorHandler extends ErrorHandler {}
19 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/dispatcher/request/handler/CustomSkillRequestHandler.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { Response } from 'ask-sdk-model';
15 | import { RequestHandler } from 'ask-sdk-runtime';
16 | import { HandlerInput } from './HandlerInput';
17 |
18 | export interface CustomSkillRequestHandler extends RequestHandler {}
19 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/dispatcher/request/handler/HandlerInput.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | 'use strict';
15 |
16 | import {
17 | RequestEnvelope,
18 | services
19 | } from 'ask-sdk-model';
20 | import { AttributesManager } from '../../../attributes/AttributesManager';
21 | import { ResponseBuilder } from '../../../response/ResponseBuilder';
22 | import ServiceClientFactory = services.ServiceClientFactory;
23 |
24 | /**
25 | * An interface that represents components passed into {@link CustomSkillRequestHandler} and {@link CustomSkillErrorHandler}.
26 | */
27 | export interface HandlerInput {
28 | requestEnvelope : RequestEnvelope;
29 | context? : any;
30 | attributesManager : AttributesManager;
31 | responseBuilder : ResponseBuilder;
32 | serviceClientFactory? : ServiceClientFactory;
33 | }
34 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/dispatcher/request/interceptor/CustomSkillRequestInterceptor.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { RequestInterceptor } from 'ask-sdk-runtime';
15 | import { HandlerInput } from '../handler/HandlerInput';
16 |
17 | export interface CustomSkillRequestInterceptor extends RequestInterceptor {}
18 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/dispatcher/request/interceptor/CustomSkillResponseInterceptor.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { Response } from 'ask-sdk-model';
15 | import { ResponseInterceptor } from 'ask-sdk-runtime';
16 | import { HandlerInput } from '../handler/HandlerInput';
17 |
18 | export interface CustomSkillResponseInterceptor extends ResponseInterceptor {}
19 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/response/PlainTextContentHelper.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { interfaces } from 'ask-sdk-model';
15 | import { TextContentHelper } from './TextContentHelper';
16 | import TextContent = interfaces.display.TextContent;
17 |
18 | /**
19 | * Responsible for building plain text content object using ask-sdk-model in Alexa skills kit display interface
20 | * https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#textcontent-object-specifications.
21 | */
22 | export class PlainTextContentHelper extends TextContentHelper {
23 | constructor() {
24 | super();
25 | }
26 |
27 | /**
28 | * @returns {interfaces.display.TextContent}
29 | */
30 | public getTextContent() : interfaces.display.TextContent {
31 | const textContent : TextContent = {};
32 |
33 | if (this.primaryText) {
34 | textContent.primaryText = {
35 | type : 'PlainText',
36 | text : this.primaryText,
37 | };
38 | }
39 |
40 | if (this.secondaryText) {
41 | textContent.secondaryText = {
42 | type : 'PlainText',
43 | text : this.secondaryText,
44 | };
45 | }
46 |
47 | if (this.tertiaryText) {
48 | textContent.tertiaryText = {
49 | type : 'PlainText',
50 | text : this.tertiaryText,
51 | };
52 | }
53 |
54 | return textContent;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/response/RichTextContentHelper.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { interfaces } from 'ask-sdk-model';
15 | import { TextContentHelper } from './TextContentHelper';
16 | import TextContent = interfaces.display.TextContent;
17 |
18 | /**
19 | * Responsible for building rich text content object using ask-sdk-model in Alexa skills kit display interface
20 | * https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#textcontent-object-specifications.
21 | */
22 | export class RichTextContentHelper extends TextContentHelper {
23 | constructor() {
24 | super();
25 | }
26 |
27 | /**
28 | * @returns {interfaces.display.TextContent}
29 | */
30 | public getTextContent() : TextContent {
31 | const textContent : TextContent = {};
32 |
33 | if (this.primaryText) {
34 | textContent.primaryText = {
35 | type : 'RichText',
36 | text : this.primaryText,
37 | };
38 | }
39 |
40 | if (this.secondaryText) {
41 | textContent.secondaryText = {
42 | type : 'RichText',
43 | text : this.secondaryText,
44 | };
45 | }
46 |
47 | if (this.tertiaryText) {
48 | textContent.tertiaryText = {
49 | type : 'RichText',
50 | text : this.tertiaryText,
51 | };
52 | }
53 |
54 | return textContent;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/response/TextContentHelper.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { interfaces } from 'ask-sdk-model';
15 | import TextContent = interfaces.display.TextContent;
16 |
17 | /**
18 | * An abstract class responsible for building text content object using ask-sdk-model in Alexa skills kit display interface
19 | * https://developer.amazon.com/docs/custom-skills/display-interface-reference.html#textcontent-object-specifications.
20 | */
21 | export abstract class TextContentHelper {
22 | protected primaryText : string;
23 | protected secondaryText : string;
24 | protected tertiaryText : string;
25 |
26 | /**
27 | * @param {string} primaryText
28 | * @returns {this}
29 | */
30 | public withPrimaryText(primaryText : string) : this {
31 | this.primaryText = primaryText;
32 |
33 | return this;
34 | }
35 |
36 | /**
37 | * @param {string} secondaryText
38 | * @returns {this}
39 | */
40 | public withSecondaryText(secondaryText : string) : this {
41 | this.secondaryText = secondaryText;
42 |
43 | return this;
44 | }
45 |
46 | /**
47 | * @param {string} tertiaryText
48 | * @returns {this}
49 | */
50 | public withTertiaryText(tertiaryText : string) : this {
51 | this.tertiaryText = tertiaryText;
52 |
53 | return this;
54 | }
55 |
56 | /**
57 | * @returns {interfaces.display.TextContent}
58 | */
59 | public abstract getTextContent() : TextContent;
60 | }
61 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/skill/CustomSkillConfiguration.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import {
15 | Response,
16 | services
17 | } from 'ask-sdk-model';
18 | import { RuntimeConfiguration } from 'ask-sdk-runtime';
19 | import { PersistenceAdapter } from '../attributes/persistence/PersistenceAdapter';
20 | import { HandlerInput} from '../dispatcher/request/handler/HandlerInput';
21 |
22 | /**
23 | * An interfaces that represents the standard components needed to build {@link CustomSkill}.
24 | */
25 | export interface CustomSkillConfiguration extends RuntimeConfiguration {
26 | persistenceAdapter? : PersistenceAdapter;
27 | apiClient? : services.ApiClient;
28 | customUserAgent? : string;
29 | skillId? : string;
30 | }
31 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/skill/SkillBuilders.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { CustomSkillBuilder } from './factory/CustomSkillBuilder';
15 | import { CustomSkillFactory } from './factory/CustomSkillFactory';
16 |
17 | /**
18 | * Provider for skill builders.
19 | */
20 | export const SkillBuilders = {
21 | custom() : CustomSkillBuilder {
22 | return CustomSkillFactory.init();
23 | },
24 | };
25 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/skill/factory/CustomSkillBuilder.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { services } from 'ask-sdk-model';
15 | import { PersistenceAdapter } from '../../attributes/persistence/PersistenceAdapter';
16 | import { BaseSkillBuilder } from './BaseSkillBuilder';
17 | import ApiClient = services.ApiClient;
18 |
19 | /**
20 | * An interface which helps building a customized skill.
21 | */
22 | export interface CustomSkillBuilder extends BaseSkillBuilder {
23 | withPersistenceAdapter(persistenceAdapter : PersistenceAdapter) : this;
24 | withApiClient(apiClient : ApiClient) : this;
25 | }
26 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/skill/factory/CustomSkillFactory.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { services } from 'ask-sdk-model';
15 | import { PersistenceAdapter } from '../../attributes/persistence/PersistenceAdapter';
16 | import { CustomSkillConfiguration } from '../CustomSkillConfiguration';
17 | import { BaseSkillFactory } from './BaseSkillFactory';
18 | import { CustomSkillBuilder } from './CustomSkillBuilder';
19 | import ApiClient = services.ApiClient;
20 |
21 | /**
22 | * Provider for {@link CustomSkillBuilder}
23 | */
24 | export class CustomSkillFactory {
25 | public static init() : CustomSkillBuilder {
26 | let thisPersistenceAdapter : PersistenceAdapter;
27 | let thisApiClient : ApiClient;
28 |
29 | const baseSkillBuilder = BaseSkillFactory.init();
30 |
31 | return {
32 | ... baseSkillBuilder,
33 | getSkillConfiguration() : CustomSkillConfiguration {
34 | const skillConfiguration = baseSkillBuilder.getSkillConfiguration();
35 |
36 | return {
37 | ...skillConfiguration,
38 | persistenceAdapter : thisPersistenceAdapter,
39 | apiClient : thisApiClient,
40 | };
41 | },
42 | withPersistenceAdapter(persistenceAdapter : PersistenceAdapter) : CustomSkillBuilder {
43 | thisPersistenceAdapter = persistenceAdapter;
44 |
45 | return this;
46 | },
47 | withApiClient(apiClient : ApiClient) : CustomSkillBuilder {
48 | thisApiClient = apiClient;
49 |
50 | return this;
51 | },
52 | };
53 | }
54 |
55 | private constructor() {}
56 | }
57 |
--------------------------------------------------------------------------------
/ask-sdk-core/lib/util/SsmlUtils.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | /**
15 | * return the string with all invalid XML characters escaped
16 | * @param input
17 | */
18 | export function escapeXmlCharacters(input : string) : string {
19 | const invalidXmlCharactersMapping = {
20 | '&' : '&',
21 | '<' : '<',
22 | '>' : '>',
23 | '"' : '"',
24 | "'" : ''',
25 | };
26 |
27 | const invalidXmlCharactersMappingReverse = Object.keys(invalidXmlCharactersMapping).reduce(
28 | /* eslint-disable-next-line */
29 | (obj : object, key : string) => {
30 | obj[invalidXmlCharactersMapping[key]] = key;
31 |
32 | return obj;
33 | },
34 | {},
35 | );
36 |
37 | // sanitize any already escaped character to ensure they are not escaped more than once
38 | const sanitizedInput = input.replace(/&|<|>|"|']/g, (c) => invalidXmlCharactersMappingReverse[c]);
39 |
40 | return sanitizedInput.replace(/[&'"><]/g, (c) => invalidXmlCharactersMapping[c]);
41 | }
42 |
--------------------------------------------------------------------------------
/ask-sdk-core/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ask-sdk-core",
3 | "version": "2.14.0",
4 | "description": "Core package for Alexa Skills Kit SDK",
5 | "main": "dist/index.js",
6 | "types": "dist/index.d.ts",
7 | "scripts": {
8 | "build": "tsc && npm run lint",
9 | "compile": "tsc",
10 | "test": "cross-env TS_NODE_FILES=true mocha -r ts-node/register \"./tst/**/*.spec.ts\"",
11 | "lint": "eslint \"lib/**/*.{ts,tsx}\" \"tst/**/*.{ts,tsx}\"",
12 | "clean": "rm -rf ./dist",
13 | "reinstall": "rm -rf ./node_modules && npm install"
14 | },
15 | "author": "Amazon.com",
16 | "contributors": [
17 | {
18 | "name": "Tianren Zhang",
19 | "email": "tianrenz@amazon.com"
20 | },
21 | {
22 | "name": "Tiantian Xie",
23 | "email": "xtiantia@amazon.com"
24 | }
25 | ],
26 | "license": "Apache-2.0",
27 | "keywords": [
28 | "Alexa",
29 | "SDK"
30 | ],
31 | "dependencies": {
32 | "ask-sdk-runtime": "^2.14.0"
33 | },
34 | "peerDependencies": {
35 | "ask-sdk-model": "^1.29.0"
36 | },
37 | "devDependencies": {
38 | "@types/chai": "^4.1.2",
39 | "@types/mocha": "^5.0.0",
40 | "@types/node": "^16.11.1",
41 | "@types/sinon": "^7.0.13",
42 | "@typescript-eslint/eslint-plugin": "^3.9.0",
43 | "@typescript-eslint/parser": "^3.9.0",
44 | "ask-sdk-model": "^1.29.0",
45 | "chai": "^4.1.2",
46 | "cross-env": "^7.0.2",
47 | "eslint": "^7.6.0",
48 | "eslint-plugin-tsdoc": "^0.2.6",
49 | "mocha": "^5.0.5",
50 | "nock": "^13.3.0",
51 | "nyc": "^14.1.1",
52 | "sinon": "^7.0.13",
53 | "ts-node": "^6.0.1",
54 | "typescript": "^4.9.5"
55 | },
56 | "repository": "github:alexa/alexa-skills-kit-sdk-for-nodejs",
57 | "bugs": "https://github.com/alexa/alexa-skill-sdk-for-nodejs/issues",
58 | "homepage": "https://github.com/alexa/alexa-skill-sdk-for-nodejs#readme"
59 | }
60 |
--------------------------------------------------------------------------------
/ask-sdk-core/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2017",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "rootDir": "./lib",
7 | "outDir" : "dist",
8 | "sourceMap" : true,
9 | "alwaysStrict" : true,
10 | "declaration" : true,
11 | "lib": []
12 | },
13 | "include": [
14 | "lib"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/mocks/error/MockAlwaysFalseErrorHandler.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { Response } from 'ask-sdk-model';
15 | import { CustomSkillErrorHandler } from '../../../lib/dispatcher/error/handler/CustomSkillErrorHandler';
16 | import { HandlerInput } from '../../../lib/dispatcher/request/handler/HandlerInput';
17 |
18 | export class MockAlwaysFalseErrorHandler implements CustomSkillErrorHandler {
19 | public canHandle(input : HandlerInput, error : Error) : boolean {
20 | return false;
21 | }
22 |
23 | public handle(input : HandlerInput, error : Error) : Response {
24 | throw new Error(`${this.constructor.name} Error: this line should never be reached!`);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/mocks/error/MockAlwaysTrueErrorHandler.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { Response } from 'ask-sdk-model';
15 | import { CustomSkillErrorHandler } from '../../../lib/dispatcher/error/handler/CustomSkillErrorHandler';
16 | import { HandlerInput } from '../../../lib/dispatcher/request/handler/HandlerInput';
17 | import { ResponseFactory } from '../../../lib/response/ResponseFactory';
18 |
19 | export class MockAlwaysTrueErrorHandler implements CustomSkillErrorHandler {
20 | public canHandle(input : HandlerInput, error : Error) : boolean {
21 | return true;
22 | }
23 |
24 | public handle(input : HandlerInput, error : Error) : Response {
25 | return input.responseBuilder
26 | .speak(`${error.name} received at ${this.constructor.name}.`)
27 | .getResponse();
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/mocks/persistence/MockPersistenceAdapter.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { RequestEnvelope } from 'ask-sdk-model';
15 | import { PersistenceAdapter } from '../../../lib/attributes/persistence/PersistenceAdapter';
16 |
17 | export class MockPersistenceAdapter implements PersistenceAdapter {
18 | public getCounter : number = 0;
19 | public saveCounter : number = 0;
20 |
21 | private partitionKey : string = 'userId';
22 | private savedAttributes : {[key : string] : any} = {
23 | key_1 : 'v1', /* eslint-disable-line camelcase */
24 | key_2 : 'v2', /* eslint-disable-line camelcase */
25 | state : 'mockState',
26 | };
27 |
28 | public async getAttributes(requestEnvelope : RequestEnvelope) : Promise<{[key : string] : any}> {
29 | this.getCounter++;
30 |
31 | const id = requestEnvelope.context.System.user.userId;
32 |
33 | if (id === this.partitionKey) {
34 | return this.savedAttributes;
35 | }
36 |
37 | throw new Error('Resource Not Found');
38 | }
39 |
40 | public async saveAttributes(requestEnvelope : RequestEnvelope, attributes : {[key : string] : any}) : Promise {
41 | this.saveCounter ++;
42 |
43 | const id = requestEnvelope.context.System.user.userId;
44 |
45 | if (id === this.partitionKey) {
46 | this.savedAttributes = attributes;
47 |
48 | return;
49 | }
50 |
51 | throw new Error('Maximum Capacity Reached');
52 | }
53 |
54 | public async deleteAttributes(requestEnvelope : RequestEnvelope) : Promise {
55 | const id = requestEnvelope.context.System.user.userId;
56 |
57 | if (id === this.partitionKey) {
58 | this.savedAttributes = {};
59 | }
60 | }
61 |
62 | public resetCounter() : void {
63 | this.getCounter = 0;
64 | this.saveCounter = 0;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/mocks/request/MockAlwaysFalseRequestHandler.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { Response } from 'ask-sdk-model';
15 | import { CustomSkillRequestHandler } from '../../../lib/dispatcher/request/handler/CustomSkillRequestHandler';
16 | import { HandlerInput } from '../../../lib/dispatcher/request/handler/HandlerInput';
17 |
18 | export class MockAlwaysFalseRequestHandler implements CustomSkillRequestHandler {
19 | public canHandle(input : HandlerInput) : boolean {
20 | return false;
21 | }
22 |
23 | public handle(input : HandlerInput) : Response {
24 | throw new Error(`${this.constructor.name} Error: this line should never be reached!`);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/mocks/request/MockAlwaysTrueRequestHandler.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { Response } from 'ask-sdk-model';
15 | import { CustomSkillRequestHandler } from '../../../lib/dispatcher/request/handler/CustomSkillRequestHandler';
16 | import { HandlerInput } from '../../../lib/dispatcher/request/handler/HandlerInput';
17 |
18 | export class MockAlwaysTrueRequestHandler implements CustomSkillRequestHandler {
19 | public canHandle(input : HandlerInput) : boolean {
20 | return true;
21 | }
22 |
23 | public async handle(input : HandlerInput) : Promise {
24 | try {
25 | const sessionAttributes = input.attributesManager.getSessionAttributes();
26 | sessionAttributes.key = 'value';
27 | input.attributesManager.setSessionAttributes(sessionAttributes);
28 | } catch (err) {} /* eslint-disable-line no-empty */
29 |
30 | try {
31 | const persistentAttributes = await input.attributesManager.getPersistentAttributes();
32 | persistentAttributes.key = 'value';
33 | input.attributesManager.setPersistentAttributes(persistentAttributes);
34 | } catch (err) {} /* eslint-disable-line no-empty */
35 |
36 | try {
37 | await input.attributesManager.savePersistentAttributes();
38 | } catch (err) {} /* eslint-disable-line no-empty */
39 |
40 | return input.responseBuilder
41 | .speak(`Request received at ${this.constructor.name}.`)
42 | .getResponse();
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/skill/SkillBuilders.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { expect } from 'chai';
15 | import { SkillBuilders } from '../../lib/skill/SkillBuilders';
16 |
17 | describe('SkillBuilders', () => {
18 | it('should be able to return CustomSkillBuilder', () => {
19 | const customSkillBuilder = SkillBuilders.custom();
20 |
21 | expect('withPersistenceAdapter' in customSkillBuilder).equal(true);
22 | expect('withApiClient' in customSkillBuilder).equal(true);
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/skill/factory/CustomSkillFactory.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { expect } from 'chai';
15 | import { DefaultApiClient } from '../../../lib/service/DefaultApiClient';
16 | import { CustomSkillFactory } from '../../../lib/skill/factory/CustomSkillFactory';
17 | import { MockPersistenceAdapter } from '../../mocks/persistence/MockPersistenceAdapter';
18 |
19 | describe('CustomSkillFactory', () => {
20 | it('should be able to add persistence adapter', () => {
21 | const config = CustomSkillFactory.init()
22 | .withPersistenceAdapter(new MockPersistenceAdapter())
23 | .getSkillConfiguration();
24 |
25 | expect(config.persistenceAdapter).instanceOf(MockPersistenceAdapter);
26 | });
27 |
28 | it('should be able to add api client', () => {
29 | const config = CustomSkillFactory.init()
30 | .withApiClient(new DefaultApiClient())
31 | .getSkillConfiguration();
32 |
33 | expect(config.apiClient).instanceOf(DefaultApiClient);
34 | });
35 | });
36 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2017",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "rootDir": "../",
7 | "outDir" : "dist",
8 | "sourceMap" : true,
9 | "alwaysStrict" : true,
10 | "declaration" : true,
11 | "lib": []
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ask-sdk-core/tst/util/SsmlUtils.spec.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { expect } from 'chai';
15 | import { escapeXmlCharacters } from '../../lib/util/SsmlUtils';
16 |
17 | describe('SsmlUtils', () => {
18 | it('should be able to escape all invalid XML characters', () => {
19 | expect(escapeXmlCharacters('<>"\'&')).eq('<>"'&');
20 | });
21 |
22 | it('should not escape any already escaped character', () => {
23 | expect(escapeXmlCharacters('&&')).eq('&&');
24 | });
25 | });
26 |
--------------------------------------------------------------------------------
/ask-sdk-dynamodb-persistence-adapter/.gitignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | dist/
3 | doc/
4 | node_modules/
5 | package-lock.json
6 | build
7 |
--------------------------------------------------------------------------------
/ask-sdk-dynamodb-persistence-adapter/.npmignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | doc/
3 | lib/
4 | node_modules/
5 | tst/
6 | package-lock.json
7 | tsconfig.json
8 | .eslintrc.json
9 |
--------------------------------------------------------------------------------
/ask-sdk-dynamodb-persistence-adapter/lib/index.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | export { DynamoDbPersistenceAdapter } from './attributes/persistence/DynamoDbPersistenceAdapter';
15 | export {
16 | PartitionKeyGenerator,
17 | PartitionKeyGenerators
18 | } from './attributes/persistence/PartitionKeyGenerators';
19 |
--------------------------------------------------------------------------------
/ask-sdk-dynamodb-persistence-adapter/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ask-sdk-dynamodb-persistence-adapter",
3 | "version": "2.14.0",
4 | "description": "DynamoDB based implementation package of PersistenceAdapter interface in ASK SDK v2 for Node.js",
5 | "main": "dist/index.js",
6 | "types": "dist/index.d.ts",
7 | "scripts": {
8 | "build": "tsc && npm run lint",
9 | "compile": "tsc",
10 | "test": "cross-env TS_NODE_FILES=true mocha -r ts-node/register \"./tst/**/*.spec.ts\"",
11 | "lint": "eslint \"lib/**/*.{ts,tsx}\" \"tst/**/*.{ts,tsx}\"",
12 | "clean": "rm -rf ./dist",
13 | "reinstall": "rm -rf ./node_modules && npm install"
14 | },
15 | "author": "Amazon.com",
16 | "contributors": [
17 | {
18 | "name": "Tianren Zhang",
19 | "email": "tianrenz@amazon.com"
20 | },
21 | {
22 | "name": "Tiantian Xie",
23 | "email": "xtiantia@amazon.com"
24 | }
25 | ],
26 | "license": "Apache-2.0",
27 | "keywords": [
28 | "Alexa",
29 | "SDK"
30 | ],
31 | "dependencies": {
32 | "aws-sdk": "^2.163.0"
33 | },
34 | "peerDependencies": {
35 | "ask-sdk-core": "^2.0.0"
36 | },
37 | "devDependencies": {
38 | "@types/chai": "^4.1.2",
39 | "@types/mocha": "^5.0.0",
40 | "@types/node": "^16.11.1",
41 | "@typescript-eslint/eslint-plugin": "^3.9.0",
42 | "@typescript-eslint/parser": "^3.9.0",
43 | "ask-sdk-core": "^2.14.0",
44 | "ask-sdk-model": "^1.29.0",
45 | "aws-sdk-mock": "^4.1.0",
46 | "chai": "^4.1.2",
47 | "cross-env": "^7.0.2",
48 | "eslint": "^7.6.0",
49 | "eslint-plugin-tsdoc": "^0.2.6",
50 | "mocha": "^5.0.5",
51 | "nyc": "^14.1.1",
52 | "ts-node": "^6.0.1",
53 | "typescript": "^4.9.5"
54 | },
55 | "repository": "github:alexa/alexa-skills-kit-sdk-for-nodejs",
56 | "bugs": "https://github.com/alexa/alexa-skill-sdk-for-nodejs/issues",
57 | "homepage": "https://github.com/alexa/alexa-skill-sdk-for-nodejs#readme"
58 | }
59 |
--------------------------------------------------------------------------------
/ask-sdk-dynamodb-persistence-adapter/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2017",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "rootDir": "./lib",
7 | "outDir" : "dist",
8 | "sourceMap" : true,
9 | "alwaysStrict" : true,
10 | "declaration" : true,
11 | "lib": []
12 | },
13 | "include": [
14 | "lib"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/ask-sdk-dynamodb-persistence-adapter/tst/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2017",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "rootDir": "./",
7 | "outDir" : "dist",
8 | "sourceMap" : true,
9 | "alwaysStrict" : true,
10 | "declaration" : true,
11 | "lib": []
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/.gitignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | dist/
3 | doc/
4 | node_modules/
5 | package-lock.json
6 | .DS_Store
7 | build
8 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/.npmignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | doc/
3 | lib/
4 | node_modules/
5 | tst/
6 | package-lock.json
7 | tsconfig.json
8 | .eslintrc.json
9 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/lib/index.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | export { ExpressAdapter } from './adapter/ExpressAdapter';
15 | export {
16 | SkillRequestSignatureVerifier,
17 | TimestampVerifier,
18 | Verifier
19 | } from './verifier';
20 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/lib/util/index.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { createAskSdkError, Skill } from 'ask-sdk-core';
15 | import { ResponseEnvelope } from 'ask-sdk-model';
16 | import { IncomingHttpHeaders } from 'http';
17 | import { Verifier } from '../verifier';
18 |
19 | /**
20 | * Verify request and dispatch
21 | *
22 | * This method first validate request with all provided verifiers
23 | * Then, invoke the skill to handle request envelope to get response
24 | * @param {IncomingHttpHeaders} httpRequestHeader Http request header
25 | * @param {string} httpRequestBody Http request body in string format
26 | * @param {Skill} skill ask-sdk-core custom skill instance
27 | * @param {Verifier[]} verifiers Array of user customized Verifier instances
28 | */
29 | export async function asyncVerifyRequestAndDispatch(httpRequestHeader: IncomingHttpHeaders, httpRequestBody: string, skill: Skill, verifiers: Verifier[]): Promise {
30 | try {
31 | await Promise.all(verifiers.map(async (verifier) => {
32 | await verifier.verify(httpRequestBody, httpRequestHeader);
33 | }));
34 | } catch (err) {
35 | throw createAskSdkError('Request verification failed', err.message);
36 | }
37 |
38 | let responseEnvelope;
39 | try {
40 | responseEnvelope = await skill.invoke(JSON.parse(httpRequestBody));
41 | } catch (err) {
42 | throw createAskSdkError('Skill dispatch failed', err.message);
43 | }
44 |
45 | return responseEnvelope;
46 | }
47 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/lib/verifier/helper.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { pki } from 'node-forge';
15 |
16 | /**
17 | * Function used to convert certificate chain string into Certificate Object Array
18 | * @param {string} certChain certificate chain in pem format
19 | * @return {pki.Certificate[]}
20 | */
21 |
22 | const CERT_START_KEY = '-----BEGIN CERTIFICATE-----';
23 | const CERT_END_KEY = '-----END CERTIFICATE-----';
24 | export function generateCertificatesArray(certChain: string): pki.Certificate[] {
25 | const certs = [];
26 | while (certChain.length > 0) {
27 | const start = certChain.indexOf(CERT_START_KEY);
28 | const end = certChain.indexOf(CERT_END_KEY) + CERT_END_KEY.length;
29 | const certString = certChain.slice(start, end);
30 | certs.push(pki.certificateFromPem(certString));
31 | certChain = certChain.slice(end).trim();
32 | }
33 |
34 | return certs;
35 | }
36 |
37 | /**
38 | * Function used to generate ca store based on input root CAs list
39 | * @param {string[]} certs root CAs in pem format
40 | */
41 | export function generateCAStore(certs: string[]): pki.CAStore {
42 | const caStore = pki.createCaStore([]);
43 |
44 | for (const cert of certs) {
45 | try {
46 | caStore.addCertificate(cert);
47 | } catch (e) {
48 | // do nothing
49 | // node-forge doesn't support ECDSA encrypted pem
50 | }
51 |
52 | }
53 |
54 | return caStore;
55 | }
56 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ask-sdk-express-adapter",
3 | "version": "2.14.0",
4 | "description": "Express adapter package for Alexa Skills Kit SDK",
5 | "main": "dist/index.js",
6 | "types": "dist/index.d.ts",
7 | "scripts": {
8 | "build": "tsc && npm run lint",
9 | "compile": "tsc",
10 | "test": "cross-env TS_NODE_FILES=true mocha -r ts-node/register \"./tst/**/*.spec.ts\"",
11 | "lint": "eslint \"lib/**/*.{ts,tsx}\" \"tst/**/*.{ts,tsx}\"",
12 | "clean": "rm -rf ./dist",
13 | "reinstall": "rm -rf ./node_modules && npm install",
14 | "coverage": "nyc -x tst -e .ts -r html -r text-summary -t coverage/.nyc_output --cache npm test"
15 | },
16 | "keywords": [
17 | "Alexa",
18 | "Skill",
19 | "SDK",
20 | "Express"
21 | ],
22 | "author": "Amazon.com",
23 | "contributors": [
24 | {
25 | "name": "Shen Chen",
26 | "email": "shench@amazon.com"
27 | }
28 | ],
29 | "license": "Apache-2.0",
30 | "dependencies": {
31 | "body-parser": "^1.18.2",
32 | "node-forge": "^1.3.0",
33 | "semver": "^7.3.4"
34 | },
35 | "peerDependencies": {
36 | "ask-sdk-core": "^2.7.0"
37 | },
38 | "devDependencies": {
39 | "@types/chai": "^4.1.2",
40 | "@types/express": "^4.16.1",
41 | "@types/mocha": "^5.0.0",
42 | "@types/node": "^16.11.1",
43 | "@types/node-forge": "^0.8.0",
44 | "@types/semver": "^7.3.4",
45 | "@types/sinon": "^7.0.13",
46 | "@types/supertest": "^2.0.7",
47 | "@typescript-eslint/eslint-plugin": "^3.9.0",
48 | "@typescript-eslint/parser": "^3.9.0",
49 | "ask-sdk-core": "^2.14.0",
50 | "ask-sdk-model": "^1.29.0",
51 | "chai": "^4.1.2",
52 | "cross-env": "^7.0.2",
53 | "eslint": "^7.6.0",
54 | "eslint-plugin-tsdoc": "^0.2.6",
55 | "express": "^4.16.4",
56 | "mocha": "^8.3.2",
57 | "nock": "^13.3.0",
58 | "nyc": "^14.1.1",
59 | "sinon": "^7.0.13",
60 | "supertest": "^3.1.0",
61 | "ts-node": "^6.0.1",
62 | "typescript": "^4.9.5"
63 | },
64 | "repository": "github:alexa/alexa-skills-kit-sdk-for-nodejs",
65 | "bugs": "https://github.com/alexa/alexa-skill-sdk-for-nodejs/issues",
66 | "homepage": "https://github.com/alexa/alexa-skill-sdk-for-nodejs#readme"
67 | }
68 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2017",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "rootDir": "./lib",
7 | "outDir" : "dist",
8 | "sourceMap" : true,
9 | "alwaysStrict" : true,
10 | "declaration" : true,
11 | "lib": []
12 | },
13 | "include": [
14 | "lib"
15 | ]
16 | }
17 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/tst/mocks/rsa_sha256_pub:
--------------------------------------------------------------------------------
1 | -----BEGIN PUBLIC KEY-----
2 | MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA5z4oJtvKEKb/JrbKYfQw
3 | kRsa/T46XGCxJEbUDQ0OyS++KXOTBn/wILCKgShRE5jxvWaG4xOPEjQjuVWuuUee
4 | tuG5zsmybqyMaQKiRbp9WNwL3dSheQWee4Kn3F86AeM8HBu1XQIR9YAqY4utLVG4
5 | J8cUUaP2ScgtJ7rSHXvak61ZTUThWi4uDhINK96Tz2UvN7qB0j5gqLE828Ii+Qdk
6 | F1TmF3XwVRwIZ6o0xhAiLmoCqta9dQO7m6etPNbQrj5Kbb4zrgaVXBABenwHh3Ix
7 | VyIILs3V9opVeuInDAmq0mMBVPEK5LARrbC3/eZKJOIuqrwMmv8tTL+vcaWgrQ4b
8 | jA0YL5gYx3w3uDVwHm0kj8IwRPYWRxxSjXvOqVPtIYN0zetjjAfJkzaRQlZO93k1
9 | rxS39PkwmeNpfk97PgM8ca9+ZHyoHQujcUTd2pCa0jAC/AJSzlr6zF/nBfTU3dIu
10 | tbxc0PhUCegh3KVjA38lRXMhSkAFaN5TAXZM1NClAUFaYaoBZdFu/MwRefNqpg+N
11 | zy47jJmD/4S56vdp/mZxWxb5rkUG1RtbHhTI9AEZsF9W3LfeO1D+hR134uvnapwp
12 | fGpTFl6lqQDcvj9nqNCpuLfM77roBNigwLnhlC30U4bHtmPlZrp4Ys5NojSkJUO1
13 | jhdLMKdwJZVUKYl7rhmhCcMCAwEAAQ==
14 | -----END PUBLIC KEY-----
15 |
--------------------------------------------------------------------------------
/ask-sdk-express-adapter/tst/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2017",
4 | "module": "commonjs",
5 | "moduleResolution": "node",
6 | "rootDir": "../",
7 | "outDir" : "dist",
8 | "sourceMap" : true,
9 | "alwaysStrict" : true,
10 | "declaration" : true,
11 | "lib": []
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/.eslintignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 | build
4 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/.gitignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | dist/
3 | doc/
4 | node_modules/
5 | package-lock.json
6 | .DS_Store
7 | .idea/
8 | .vscode/
9 | build
10 | package/
11 | *.tgz
12 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/.npmignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | doc/
3 | lib/
4 | node_modules/
5 | tst/
6 | package-lock.json
7 | tsconfig.json
8 | tslint.json
9 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Change Log
2 |
3 | # 1.1.0 (2020-11-10)
4 |
5 | This release contains the following changes :
6 |
7 | - Adding support for EU and FE.
8 |
9 | # 1.0.0 (2020-07-21)
10 |
11 | This release contains the following changes :
12 |
13 | - Initial release for local development support for ASK SDK for Node.js.
14 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/NOTICE.txt:
--------------------------------------------------------------------------------
1 | ASK SDK Local Debug for Node.js
2 | Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/LocalDebuggerInvoker.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import WsClient from 'ws';
15 | import { ClientConfigBuilder } from './builder/ClientConfigBuilder';
16 | import { SkillInvokerConfigBuilder } from './builder/SkillInvokerConfigBuilder';
17 | import { WebSocketClientConfigBuilder } from './builder/WebSocketClientConfigBuilder';
18 | import { LocalDebugClient } from './client/LocalDebugClient';
19 | import { argsParser, getHandlerFunction } from './util/ArgsParserUtils';
20 |
21 | const { argv } = argsParser();
22 |
23 | const clientConfig = new ClientConfigBuilder()
24 | .withAccessToken(argv.accessToken)
25 | .withHandlerName(argv.handlerName)
26 | .withSkillEntryFile(argv.skillEntryFile)
27 | .withSkillId(argv.skillId)
28 | .withRegion(argv.region)
29 | .build();
30 |
31 | const skillInvokerConfig = new SkillInvokerConfigBuilder()
32 | .withHandler(getHandlerFunction(clientConfig.skillEntryFile, clientConfig.handlerName))
33 | .build();
34 |
35 | const webSocketClientConfig = new WebSocketClientConfigBuilder()
36 | .withSkillId(clientConfig.skillId)
37 | .withAccessToken(clientConfig.accessToken)
38 | .withRegion(clientConfig.region)
39 | .build();
40 |
41 | const webSocketClient = new WsClient(webSocketClientConfig.webSocketServerUri, {
42 | headers: webSocketClientConfig.headers,
43 | });
44 |
45 | const client = new LocalDebugClient(webSocketClient, skillInvokerConfig);
46 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/builder/ClientConfigBuilder.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { ClientConfig } from '../config/ClientConfig';
15 |
16 | export class ClientConfigBuilder {
17 | private _skillEntryFile: string;
18 |
19 | private _handlerName: string;
20 |
21 | private _accessToken: string;
22 |
23 | private _skillId: string;
24 |
25 | private _region: string;
26 |
27 | public withSkillEntryFile(skillEntryFile: string): ClientConfigBuilder {
28 | this._skillEntryFile = skillEntryFile;
29 |
30 | return this;
31 | }
32 |
33 | public withHandlerName(handlerName: string): ClientConfigBuilder {
34 | this._handlerName = handlerName;
35 |
36 | return this;
37 | }
38 |
39 | public withAccessToken(accessToken: string): ClientConfigBuilder {
40 | this._accessToken = accessToken;
41 |
42 | return this;
43 | }
44 |
45 | public withSkillId(skillId: string): ClientConfigBuilder {
46 | this._skillId = skillId;
47 |
48 | return this;
49 | }
50 |
51 | withRegion(region: string): ClientConfigBuilder {
52 | this._region = region;
53 |
54 | return this;
55 | }
56 |
57 | public get skillEntryFile(): string {
58 | return this._skillEntryFile;
59 | }
60 |
61 | public get handlerName(): string {
62 | return this._handlerName;
63 | }
64 |
65 | public get accessToken(): string {
66 | return this._accessToken;
67 | }
68 |
69 | public get skillId(): string {
70 | return this._skillId;
71 | }
72 |
73 | public get region(): string {
74 | return this._region;
75 | }
76 |
77 | public build(): ClientConfig {
78 | return new ClientConfig(this);
79 | }
80 | }
81 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/builder/SkillInvokerConfigBuilder.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { LambdaHandler } from 'ask-sdk-core';
15 | import { SkillInvokerConfig } from '../config/SkillInvokerConfig';
16 |
17 | export class SkillInvokerConfigBuilder {
18 | private _skillHandler: LambdaHandler;
19 |
20 | public withHandler(handlerName: LambdaHandler): SkillInvokerConfigBuilder {
21 | this._skillHandler = handlerName;
22 |
23 | return this;
24 | }
25 |
26 | public get handler(): LambdaHandler {
27 | return this._skillHandler;
28 | }
29 |
30 | public build(): SkillInvokerConfig {
31 | return new SkillInvokerConfig(this);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/builder/WebSocketClientConfigBuilder.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 | import { WebSocketClientConfig } from '../config/WebSocketClientConfig';
14 | import { RegionEndpointMapping } from '../constants/Constants';
15 |
16 | export class WebSocketClientConfigBuilder {
17 | private _headers: {};
18 |
19 | private _skillId: string;
20 |
21 | private _region: string;
22 |
23 | public withSkillId(skillId: string): WebSocketClientConfigBuilder {
24 | this._skillId = skillId;
25 |
26 | return this;
27 | }
28 |
29 | public withRegion(region: string): WebSocketClientConfigBuilder {
30 | this._region = region;
31 |
32 | return this;
33 | }
34 |
35 | public withAccessToken(accessToken: string): WebSocketClientConfigBuilder {
36 | this._headers = { authorization: accessToken };
37 |
38 | return this;
39 | }
40 |
41 | public get webSocketServerUri(): string {
42 | console.log(`Region chosen: ${this._region}`);
43 | return `wss://${RegionEndpointMapping.get(
44 | this._region,
45 | )}/v1/skills/${
46 | this._skillId
47 | }/stages/development/connectCustomDebugEndpoint`;
48 | }
49 |
50 | public get headers(): {} {
51 | return this._headers;
52 | }
53 |
54 | public build(): WebSocketClientConfig {
55 | return new WebSocketClientConfig(this);
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/client/ILocalDebugClient.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import WebSocket from 'ws';
15 |
16 | export interface ILocalDebugClient {
17 | connectedEvent(): void;
18 |
19 | messageEvent(data: WebSocket.Data): void;
20 |
21 | errorEvent(event: WebSocket.ErrorEvent): void;
22 |
23 | closeEvent(event: WebSocket.CloseEvent): void;
24 |
25 | sendResponse(responseString: string): void;
26 | }
27 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/config/ClientConfig.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { ClientConfigBuilder } from '../builder/ClientConfigBuilder';
15 |
16 | export class ClientConfig {
17 | private readonly _accessToken: string;
18 |
19 | private readonly _skillId: string;
20 |
21 | private readonly _handlerName: string;
22 |
23 | private readonly _skillEntryFile: string;
24 |
25 | private readonly _region: string;
26 |
27 | constructor(clientConfigBuilder: ClientConfigBuilder) {
28 | this._skillEntryFile = clientConfigBuilder.skillEntryFile;
29 | this._handlerName = clientConfigBuilder.handlerName;
30 | this._accessToken = clientConfigBuilder.accessToken;
31 | this._skillId = clientConfigBuilder.skillId;
32 | this._region = clientConfigBuilder.region;
33 | }
34 |
35 | public get skillEntryFile(): string {
36 | return this._skillEntryFile;
37 | }
38 |
39 | public get skillId(): string {
40 | return this._skillId;
41 | }
42 |
43 | public get handlerName(): string {
44 | return this._handlerName;
45 | }
46 |
47 | public get accessToken(): string {
48 | return this._accessToken;
49 | }
50 |
51 | public get region(): string {
52 | return this._region;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/config/SkillInvokerConfig.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { LambdaHandler } from 'ask-sdk-core';
15 | import { SkillInvokerConfigBuilder } from '../builder/SkillInvokerConfigBuilder';
16 |
17 | export class SkillInvokerConfig {
18 | public readonly _handler: LambdaHandler;
19 |
20 | constructor(skillInvokerConfigBuilder: SkillInvokerConfigBuilder) {
21 | this._handler = skillInvokerConfigBuilder.handler;
22 | }
23 |
24 | public get handler(): LambdaHandler {
25 | return this._handler;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/config/WebSocketClientConfig.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { WebSocketClientConfigBuilder } from '../builder/WebSocketClientConfigBuilder';
15 |
16 | export class WebSocketClientConfig {
17 | private readonly _webSocketServerUri: string;
18 |
19 | private readonly _headers: {};
20 |
21 | constructor(webSocketClientConfigBuilder: WebSocketClientConfigBuilder) {
22 | this._webSocketServerUri = webSocketClientConfigBuilder.webSocketServerUri;
23 | this._headers = webSocketClientConfigBuilder.headers;
24 | }
25 |
26 | public get webSocketServerUri(): string {
27 | return this._webSocketServerUri;
28 | }
29 |
30 | public get headers(): {} {
31 | return this._headers;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/constants/Constants.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 | import { Map } from 'immutable';
14 |
15 | export const RegionEndpointMapping = Map({
16 | NA: 'bob-dispatch-prod-na.amazon.com',
17 | FE: 'bob-dispatch-prod-fe.amazon.com',
18 | EU: 'bob-dispatch-prod-eu.amazon.com',
19 | });
20 |
21 | export const DefaultRegion = 'NA';
22 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/lib/request/DynamicEndpointsRequest.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the 'License').
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the 'license' file accompanying this file. This file is distributed
9 | * on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | import { dynamicEndpoints } from 'ask-sdk-model';
15 |
16 | export class DynamicEndpointsRequest implements dynamicEndpoints.Request {
17 | public version: string;
18 |
19 | public type: string;
20 |
21 | public requestId: string;
22 |
23 | public requestPayload: string;
24 | }
25 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ask-sdk-local-debug",
3 | "version": "1.1.0",
4 | "description": "Local debug package for Alexa Skills Kit SDK",
5 | "main": "dist/client/WebSocketClient.js",
6 | "types": "dist/client/WebSocketClient.d.ts",
7 | "scripts": {
8 | "lint": "eslint . --ext .ts",
9 | "lint-and-fix": "eslint . --ext .ts --fix",
10 | "compile": "tsc",
11 | "cleanup": "rm -rf dist",
12 | "start": "npm run lint && npm run cleanup && npm run compile",
13 | "release": "npm run start",
14 | "pack": "npm run release && npm pack"
15 | },
16 | "author": "Amazon.com",
17 | "license": "Apache-2.0",
18 | "devDependencies": {
19 | "@types/node": "^14.0.10",
20 | "@types/ws": "^7.2.4",
21 | "@types/yargs": "^15.0.5",
22 | "@typescript-eslint/eslint-plugin": "^2.34.0",
23 | "@typescript-eslint/parser": "^2.34.0",
24 | "eslint-config-airbnb": "^18.2.0",
25 | "eslint-import-resolver-typescript": "^2.0.0",
26 | "eslint-config-prettier": "^6.11.0",
27 | "eslint-plugin-import": "^2.21.2",
28 | "eslint-plugin-json": "^2.1.1",
29 | "eslint-plugin-jsx-a11y": "^5.1.1",
30 | "eslint-plugin-prettier": "^3.1.4",
31 | "eslint-plugin-react": "^7.20.0",
32 | "eslint-plugin-eslint-comments": "^3.2.0",
33 | "prettier": "^2.0.5",
34 | "eslint": "^6.8.0",
35 | "ts-node": "^8.10.2",
36 | "tsc-watch": "^4.2.3",
37 | "typescript": "^3.9.5"
38 | },
39 | "dependencies": {
40 | "ws": "^7.3.0",
41 | "yargs": "^15.3.1",
42 | "immutable": "^4.0.0-rc.11",
43 | "ask-sdk-model": "^1.29.0",
44 | "ask-sdk-core": "^2.8.0"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/ask-sdk-local-debug/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "outDir": "./dist",
5 | "esModuleInterop": true,
6 | "allowSyntheticDefaultImports": true,
7 | "target": "es6",
8 | "noImplicitAny": true,
9 | "moduleResolution": "node",
10 | "sourceMap": true,
11 | "baseUrl": ".",
12 | "paths": {
13 | "*": ["node_modules/*"]
14 | }
15 | },
16 | "include": ["lib/**/*"]
17 | }
18 |
--------------------------------------------------------------------------------
/ask-sdk-runtime/.gitignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | dist/
3 | doc/
4 | node_modules/
5 | package-lock.json
6 | build
7 |
--------------------------------------------------------------------------------
/ask-sdk-runtime/.npmignore:
--------------------------------------------------------------------------------
1 | coverage/
2 | doc/
3 | lib/
4 | node_modules/
5 | tst/
6 | package-lock.json
7 | tsconfig.json
8 | .eslintrc.json
9 |
--------------------------------------------------------------------------------
/ask-sdk-runtime/README.md:
--------------------------------------------------------------------------------
1 | ASK SDK Runtime package contains generic components and implementations of ASK SDK v2 for Node.js.
2 |
3 | ## What is ASK SDK v2 for Node.js
4 |
5 | The ASK SDK v2 for Node.js is an open-source Alexa Skill Development Kit. ASK SDK v2 for Node.js makes it easier for you to build highly engaging skills, by allowing you to spend more time on implementing features and less on writing boiler-plate code.
6 |
7 | ## Installing
8 | To use the ASK SDK Runtime pacakge, simply run the following command in terminal:
9 |
10 | ```
11 | npm install --save ask-sdk-runtime
12 | ```
13 |
14 | ## Usage and Getting Started
15 |
16 | You can find a getting started guide [here](https://developer.amazon.com/docs/alexa-skills-kit-sdk-for-nodejs/overview.html).
17 |
18 | ## Usage with TypeScript
19 | The SDK runtime package for Node.js bundles TypeScript definition files for use in TypeScript projects and to support tools that can read .d.ts files. Our goal is to keep these TypeScript definition files updated with each release for any public api.
20 |
21 | ### Pre-requisites
22 | Before you can begin using these TypeScript definitions with your project, you need to make sure your project meets a few of these requirements:
23 | - Use TypeScript v2.x
24 | - Includes the TypeScript definitions for node. You can use npm to install this by typing the following into a terminal window:
25 |
26 | ```
27 | npm install --save-dev @types/node
28 | ```
29 |
30 | ### In Node.js
31 | To use the TypeScript definition files within a Node.js project, simply import ask-sdk-core as below:
32 |
33 | In a TypeScript file:
34 |
35 | ```typescript
36 | import * as Runtime from 'ask-sdk-runtime';
37 | ```
38 |
39 | In a JavaScript file:
40 |
41 | ```javascript
42 | const Runtime = require('ask-sdk-runtime');
43 | ```
44 |
45 | ## Opening Issues
46 | For bug reports, feature requests and questions, we would like to hear about it. Search the [existing issues](https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs/issues) and try to make sure your problem doesn’t already exist before opening a new issue. It’s helpful if you include the version of the SDK, Node.js or browser environment and OS you’re using. Please include a stack trace and reduced repro case when appropriate, too.
47 |
48 | ## License
49 | This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.
50 |
--------------------------------------------------------------------------------
/ask-sdk-runtime/lib/dispatcher/RequestDispatcher.ts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 | * Licensed under the Apache License, Version 2.0 (the "License").
4 | * You may not use this file except in compliance with the License.
5 | * A copy of the License is located at
6 | * http://www.apache.org/licenses/LICENSE-2.0
7 | *
8 | * or in the "license" file accompanying this file. This file is distributed
9 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
10 | * express or implied. See the License for the specific language governing
11 | * permissions and limitations under the License.
12 | */
13 |
14 | /**
15 | * An interface providing the logic for dispatching handler input to handler.
16 | */
17 | export interface RequestDispatcher {
18 | dispatch(input: Input): Promise