New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

actions-on-google

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

actions-on-google - npm Package Compare versions

Comparing version 1.6.1 to 1.7.0

23

.eslintrc.json

@@ -35,3 +35,24 @@ {

}],
"prefer-destructuring": "error"
"prefer-destructuring": "error",
"quotes": [ "error", "single", {
"avoidEscape": true,
"allowTemplateLiterals": true
}],
"prefer-template": "error",
"prefer-const": "error",
"no-var": "error",
"no-useless-concat": "error",
"no-multi-str": "error",
"no-else-return": "error",
"no-lonely-if": "error",
"curly": ["error", "all"],
"brace-style": ["error", "1tbs", {
"allowSingleLine": false
}],
"no-magic-numbers": ["error", {
"enforceConst": true,
"ignore": [0, 1, -1],
"ignoreArrayIndexes": false
}],
"max-len": ["error", 100]
},

@@ -38,0 +59,0 @@ "plugins": [

141

actions-sdk-app.js

@@ -24,2 +24,3 @@ /**

const { transformToCamelCase } = require('./utils/transform');
const { Limits } = require('./response-builder');

@@ -119,3 +120,3 @@ // Constants

if (err) {
error('ID token verification Failed: ' + err);
error(`ID token verification Failed: ${err}`);
reject(err);

@@ -164,3 +165,3 @@ } else {

if (err) {
error('ID token verification Failed: ' + err);
error(`ID token verification Failed: ${err}`);
reject(err);

@@ -254,5 +255,4 @@ } else {

return versionLabel;
} else {
return null;
}
return null;
}

@@ -292,3 +292,4 @@

* case app.StandardIntents.MAIN:
* const inputPrompt = app.buildInputPrompt(false, 'Welcome to action snippets! Say anything.');
* const welcome = 'Welcome to action snippets! Say anything.';
* const inputPrompt = app.buildInputPrompt(false, welcome);
* app.ask(inputPrompt);

@@ -375,5 +376,5 @@ * break;

/**
* Asks to collect user's input; all user's queries need to be sent to
* the app.
* {@link https://developers.google.com/actions/policies/general-policies#user_experience|The guidelines when prompting the user for a response must be followed at all times}.
* Asks to collect user's input; all user's queries need to be sent to the app.
* {@link https://developers.google.com/actions/policies/general-policies#user_experience|
* The guidelines when prompting the user for a response must be followed at all times}.
*

@@ -383,7 +384,13 @@ * @example

*
* const noInputs = [
* `I didn't hear a number`,
* `If you're still there, what's the number?`,
* 'What is the number?'
* ];
*
* function mainIntent (app) {
* const inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
* 'I can read out an ordinal like ' +
* '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* const ssml = '<speak>Hi! <break time="1"/> ' +
* 'I can read out an ordinal like ' +
* '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>';
* const inputPrompt = app.buildInputPrompt(true, ssml, noInputs);
* app.ask(inputPrompt);

@@ -396,5 +403,5 @@ * }

* } else {
* const inputPrompt = app.buildInputPrompt(true, '<speak>You said, <say-as interpret-as="ordinal">' +
* app.getRawInput() + '</say-as></speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* const ssml = '<speak>You said, <say-as interpret-as="ordinal">' +
* app.getRawInput() + '</say-as></speak>';
* const inputPrompt = app.buildInputPrompt(true, ssml, noInputs);
* app.ask(inputPrompt);

@@ -435,3 +442,3 @@ * }

* function welcomeIntent (app) {
* app.askWithlist('Which of these looks good?',
* app.askWithList('Which of these looks good?',
* app.buildList('List title')

@@ -476,4 +483,4 @@ * .addItems([

}
if (list.items.length < 2) {
this.handleError_('List requires at least 2 items');
if (list.items.length < Limits.OPTIONS_MIN) {
this.handleError_(`List requires at least ${Limits.OPTIONS_MIN} items`);
return null;

@@ -550,4 +557,4 @@ }

}
if (carousel.items.length < 2) {
this.handleError_('Carousel requires at least 2 items');
if (carousel.items.length < Limits.OPTIONS_MIN) {
this.handleError_(`Carousel requires at least ${Limits.OPTIONS_MIN} items`);
return null;

@@ -582,7 +589,13 @@ }

*
* const noInputs = [
* `I didn't hear a number`,
* `If you're still there, what's the number?`,
* 'What is the number?'
* ];
*
* function mainIntent (app) {
* const inputPrompt = app.buildInputPrompt(true, '<speak>Hi! <break time="1"/> ' +
* 'I can read out an ordinal like ' +
* '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* const ssml = '<speak>Hi! <break time="1"/> ' +
* 'I can read out an ordinal like ' +
* '<say-as interpret-as="ordinal">123</say-as>. Say a number.</speak>';
* const inputPrompt = app.buildInputPrompt(true, ssml, noInputs);
* app.ask(inputPrompt);

@@ -595,5 +608,5 @@ * }

* } else {
* const inputPrompt = app.buildInputPrompt(true, '<speak>You said, <say-as interpret-as="ordinal">' +
* app.getRawInput() + '</say-as></speak>',
* ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']);
* const ssml = '<speak>You said, <say-as interpret-as="ordinal">' +
* app.getRawInput() + '</say-as></speak>';
* const inputPrompt = app.buildInputPrompt(true, ssml, noInputs);
* app.ask(inputPrompt);

@@ -631,13 +644,11 @@ * }

}
} else if (textToSpeech.items) {
finalResponse.richResponse = textToSpeech;
} else if (textToSpeech.speech) {
finalResponse.richResponse = this.buildRichResponse()
.addSimpleResponse(textToSpeech);
} else {
if (textToSpeech.items) {
finalResponse.richResponse = textToSpeech;
} else if (textToSpeech.speech) {
finalResponse.richResponse = this.buildRichResponse()
.addSimpleResponse(textToSpeech);
} else {
this.handleError_('Invalid speech response. Must be string, ' +
this.handleError_('Invalid speech response. Must be string, ' +
'RichResponse or SimpleResponse.');
return null;
}
return null;
}

@@ -649,4 +660,4 @@ const response = this.buildResponseHelper_(null, false, null, finalResponse);

/**
* Builds the {@link https://developers.google.com/actions/reference/conversation#InputPrompt|InputPrompt object}
* from initial prompt and no-input prompts.
* Builds the {@link https://developers.google.com/actions/reference/conversation#InputPrompt|
* InputPrompt object} from initial prompt and no-input prompts.
*

@@ -669,3 +680,5 @@ * The App needs one initial prompt to start the conversation. If there is no user response,

* @param {Array<string>=} noInputs Array of re-prompts when the user does not respond (max 3).
* @return {Object} An {@link https://developers.google.com/actions/reference/conversation#InputPrompt|InputPrompt object}.
* @return {Object} An
* {@link https://developers.google.com/actions/reference/conversation#InputPrompt|
* InputPrompt object}.
* @actionssdk

@@ -693,8 +706,7 @@ */

};
} else {
return {
initialPrompts: this.buildPromptsFromPlainTextHelper_(initials),
noInputPrompts: this.buildPromptsFromPlainTextHelper_(noInputs)
};
}
return {
initialPrompts: this.buildPromptsFromPlainTextHelper_(initials),
noInputPrompts: this.buildPromptsFromPlainTextHelper_(noInputs)
};
}

@@ -813,14 +825,13 @@

'PLACEHOLDER_FOR_PERMISSION', dialogState);
} else {
}
// Build an Expected Intent object.
const expectedIntent = {
intent: this.StandardIntents.PERMISSION
};
expectedIntent.inputValueSpec = {
permissionValueSpec: permissionsSpec
};
const inputPrompt = this.buildInputPrompt(false,
const expectedIntent = {
intent: this.StandardIntents.PERMISSION
};
expectedIntent.inputValueSpec = {
permissionValueSpec: permissionsSpec
};
const inputPrompt = this.buildInputPrompt(false,
'PLACEHOLDER_FOR_PERMISSION');
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}

@@ -888,9 +899,7 @@

inputPrompt = this.buildInputPrompt(this.isSsml_(inputPrompt), inputPrompt);
} else {
if (inputPrompt.speech) {
inputPrompt = { richInitialPrompt: this.buildRichResponse()
} else if (inputPrompt.speech) {
inputPrompt = { richInitialPrompt: this.buildRichResponse()
.addSimpleResponse(inputPrompt) };
} else if (inputPrompt.items) {
inputPrompt = { richInitialPrompt: inputPrompt };
}
} else if (inputPrompt.items) {
inputPrompt = { richInitialPrompt: inputPrompt };
}

@@ -920,5 +929,6 @@ if (!dialogState) {

/**
* Builds an ExpectedIntent object. Refer to {@link ActionsSdkApp#newRuntimeEntity} to create the list
* of runtime entities required by this method. Runtime entities need to be defined in
* the Action Package.
* Builds an ExpectedIntent object.
* Refer to {@link ActionsSdkApp#newRuntimeEntity} to create
* the list of runtime entities required by this method.
* Runtime entities need to be defined in the Action Package.
*

@@ -928,4 +938,5 @@ * @param {string} intent Developer specified in-dialog intent inside the Action

* 'assistant.intent.action.TEXT'.
* @return {Object} An {@link https://developers.google.com/actions/reference/conversation#ExpectedIntent|ExpectedIntent object}
encapsulating the intent and the runtime entities.
* @return {Object} An
* {@link https://developers.google.com/actions/reference/conversation#ExpectedIntent|
* ExpectedIntent object} encapsulating the intent and the runtime entities.
* @private

@@ -932,0 +943,0 @@ * @actionssdk

@@ -24,2 +24,3 @@ /**

const { transformToCamelCase } = require('./utils/transform');
const { Limits } = require('./response-builder');

@@ -53,3 +54,4 @@ // Constants

/**
* This is the class that handles the communication with Dialogflow's fulfillment API.
* This is the class that handles the communication with Dialogflow's fulfillment API v1.
* Doesn't currently support Dialogflow's fulfillment API v2.
*/

@@ -284,5 +286,5 @@ class DialogflowApp extends AssistantApp {

}
for (let context of this.body_.result.contexts) {
for (const context of this.body_.result.contexts) {
if (context.name === contextName && context.parameters[argName]) {
let argument = { value: context.parameters[argName] };
const argument = { value: context.parameters[argName] };
if (context.parameters[argName + ORIGINAL_SUFFIX]) {

@@ -328,7 +330,7 @@ argument.original = context.parameters[argName + ORIGINAL_SUFFIX];

debug('getIncomingRichResponse');
let response = this.buildRichResponse();
const response = this.buildRichResponse();
if (this.body_.result &&
this.body_.result.fulfillment &&
this.body_.result.fulfillment.messages) {
for (let message of this.body_.result.fulfillment.messages) {
for (const message of this.body_.result.fulfillment.messages) {
if (!message.type) {

@@ -338,3 +340,3 @@ continue;

if (message.type === SIMPLE_RESPONSE) {
let item = {
const item = {
simpleResponse: {}

@@ -347,3 +349,3 @@ };

} else if (message.type === BASIC_CARD) {
let item = {
const item = {
basicCard: {}

@@ -395,7 +397,7 @@ };

debug('getIncomingList');
let list = this.buildList();
const list = this.buildList();
if (this.body_.result &&
this.body_.result.fulfillment &&
this.body_.result.fulfillment.messages) {
for (let message of this.body_.result.fulfillment.messages) {
for (const message of this.body_.result.fulfillment.messages) {
if (!message.type) {

@@ -442,7 +444,7 @@ continue;

debug('getIncomingCarousel');
let carousel = this.buildCarousel();
const carousel = this.buildCarousel();
if (this.body_.result &&
this.body_.result.fulfillment &&
this.body_.result.fulfillment.messages) {
for (let message of this.body_.result.fulfillment.messages) {
for (const message of this.body_.result.fulfillment.messages) {
if (!message.type) {

@@ -506,3 +508,4 @@ continue;

* Asks to collect the user's input.
* {@link https://developers.google.com/actions/policies/general-policies#user_experience|The guidelines when prompting the user for a response must be followed at all times}.
* {@link https://developers.google.com/actions/policies/general-policies#user_experience|
* The guidelines when prompting the user for a response must be followed at all times}.
*

@@ -604,4 +607,4 @@ * NOTE: Due to a bug, if you specify the no-input prompts,

}
if (list.items.length < 2) {
this.handleError_('List requires at least 2 items');
if (list.items.length < Limits.OPTIONS_MIN) {
this.handleError_(`List requires at least ${Limits.OPTIONS_MIN} items`);
return null;

@@ -685,4 +688,4 @@ }

}
if (carousel.items.length < 2) {
this.handleError_('Carousel requires at least 2 items');
if (carousel.items.length < Limits.OPTIONS_MIN) {
this.handleError_(`Carousel requires at least ${Limits.OPTIONS_MIN} items`);
return null;

@@ -804,4 +807,5 @@ }

* @property {string} name - Full name of the context.
* @property {Object} parameters - Parameters carried within this context.
See {@link https://dialogflow.com/docs/concept-actions#section-extracting-values-from-contexts|here}.
* @property {Object} parameters - Parameters carried within this context. See
* {@link https://dialogflow.com/docs/concept-actions#section-extracting-values-from-contexts|
* here}.
* @property {number} lifespan - Remaining number of intents

@@ -901,3 +905,3 @@ */

}
for (let context of this.body_.result.contexts) {
for (const context of this.body_.result.contexts) {
if (context.name === name) {

@@ -946,6 +950,5 @@ return context;

return this.body_.result.action;
} else {
error('Missing result from request body');
return null;
}
error('Missing result from request body');
return null;
}

@@ -971,3 +974,3 @@

}
let isStringResponse = typeof textToSpeech === 'string';
const isStringResponse = typeof textToSpeech === 'string';
if (!isStringResponse) {

@@ -1003,3 +1006,4 @@ if (textToSpeech.speech) {

speech: isStringResponse ? textToSpeech
: textToSpeech.items[0].simpleResponse.textToSpeech,
: textToSpeech.items[0].simpleResponse.textToSpeech ||
textToSpeech.items[0].simpleResponse.ssml,
contextOut: []

@@ -1026,3 +1030,3 @@ };

}
for (let context of Object.keys(this.contexts_)) {
for (const context of Object.keys(this.contexts_)) {
response.contextOut.push(this.contexts_[context]);

@@ -1073,12 +1077,11 @@ }

inputPrompt);
} else {
const response = this.buildResponse_(inputPrompt, true);
response.data.google.systemIntent = {
intent: this.StandardIntents.PERMISSION
};
response.data.google.systemIntent.spec = {
permissionValueSpec: permissionsSpec
};
return this.doResponse_(response, RESPONSE_CODE_OK);
}
const response = this.buildResponse_(inputPrompt, true);
response.data.google.systemIntent = {
intent: this.StandardIntents.PERMISSION
};
response.data.google.systemIntent.spec = {
permissionValueSpec: permissionsSpec
};
return this.doResponse_(response, RESPONSE_CODE_OK);
}

@@ -1085,0 +1088,0 @@

@@ -5,3 +5,3 @@ {

"main": "actions-on-google.js",
"version": "1.6.1",
"version": "1.7.0",
"license": "Apache-2.0",

@@ -8,0 +8,0 @@ "author": "Google Inc.",

@@ -24,3 +24,3 @@ # Actions On Google Client Library

### Dialogflow
### Dialogflow v1
1. Import the appropriate class:

@@ -38,2 +38,4 @@

Please note that Dialogflow v2 is not currently supported by this client library.
## References and How to report bugs

@@ -40,0 +42,0 @@ * Actions on Google documentation: [https://developers.google.com/actions/](https://developers.google.com/actions/).

@@ -28,6 +28,14 @@ /**

const LIST_ITEM_LIMIT = 30;
const CAROUSEL_ITEM_LIMIT = 10;
const Limits = {
LIST_ITEM_MAX: 30,
CAROUSEL_ITEM_MAX: 10,
OPTIONS_MIN: 2,
SIMPLE_RESPONSE_MAX: 2,
SUGGESTION_TEXT_MAX: 25
};
/**
* List of possible options to display the image in a BasicCard.
* When the aspect ratio of an image is not the same as the surface,
* this attribute changes how the image is displayed in the card.
* @readonly

@@ -114,3 +122,3 @@ * @enum {string}

/**
* @typedef {Object} RichResponseItemBasicCard
* @typedef {Object} ItemBasicCard
* @property {BasicCard} basicCard

@@ -120,3 +128,3 @@ */

/**
* @typedef {Object} RichResponseItemSimpleResponse
* @typedef {Object} ItemSimpleResponse
* @property {SimpleResponse} simpleResponse

@@ -126,7 +134,7 @@ */

/**
* @typedef {Object} RichResponseItemStructuredResponse
* @typedef {Object} ItemStructuredResponse
* @property {StructuredResponse} structuredResponse
*/
/** @typedef {RichResponseItemBasicCard | RichResponseItemSimpleResponse | RichResponseItemStructuredResponse} RichResponseItem */
/** @typedef {ItemBasicCard | ItemSimpleResponse | ItemStructuredResponse} RichResponseItem */

@@ -136,3 +144,3 @@ /**

*/
const RichResponse = class {
class RichResponse {
/**

@@ -166,3 +174,3 @@ * Constructor for RichResponse. Accepts optional RichResponse to clone.

this.items = richResponse.items;
for (let item of this.items) {
for (const item of this.items) {
if (item.basicCard) {

@@ -196,8 +204,8 @@ item.basicCard = new BasicCard(item.basicCard);

let simpleResponseCount = 0;
for (let item of this.items) {
for (const item of this.items) {
if (item.simpleResponse) {
simpleResponseCount++;
}
if (simpleResponseCount >= 2) {
error('Cannot include >2 SimpleResponses in RichResponse');
if (simpleResponseCount >= Limits.SIMPLE_RESPONSE_MAX) {
error(`Cannot include >${Limits.SIMPLE_RESPONSE_MAX} SimpleResponses in RichResponse`);
return this;

@@ -231,3 +239,3 @@ }

// Validate if basic card is already present
for (let item of this.items) {
for (const item of this.items) {
if (item.basicCard) {

@@ -257,17 +265,15 @@ error('Cannot include >1 BasicCard in RichResponse');

if (Array.isArray(suggestions)) {
for (let suggestion of suggestions) {
for (const suggestion of suggestions) {
if (this.isValidSuggestionText(suggestion)) {
this.suggestions.push({title: suggestion});
} else {
warn('Suggestion text can\'t be longer than 25 characters: ' + suggestion +
'. This suggestion won\'t be added to the list.');
warn(`Suggestion text can't be longer than 25 characters: ${suggestion}. ` +
`This suggestion won't be added to the list.`);
}
}
} else if (this.isValidSuggestionText(suggestions)) {
this.suggestions.push({title: suggestions});
} else {
if (this.isValidSuggestionText(suggestions)) {
this.suggestions.push({title: suggestions});
} else {
warn('Suggestion text can\'t be longer than 25 characters: ' + suggestions +
'. This suggestion won\'t be added to the list.');
}
warn(`Suggestion text can't be longer than 25 characters: ${suggestions}. ` +
`This suggestion won't be added to the list.`);
}

@@ -278,4 +284,4 @@ return this;

/**
* Returns true if the given suggestion text is valid to be added to the suggestion list. A valid
* text string is not longer than 25 characters.
* Returns true if the given suggestion text is valid to be added to the suggestion list.
* A valid text string is not longer than 25 characters.
*

@@ -286,7 +292,9 @@ * @param {string} suggestionText Text to validate as suggestion.

isValidSuggestionText (suggestionText) {
return suggestionText && suggestionText.length && suggestionText.length <= 25;
return suggestionText && suggestionText.length &&
suggestionText.length <= Limits.SUGGESTION_TEXT_MAX;
}
/**
* Sets the suggestion link for this rich response.
* Sets the suggestion link for this rich response. The destination site must be verified
* (https://developers.google.com/actions/console/brand-verification).
*

@@ -326,3 +334,3 @@ * @param {string} destinationName Name of the link out destination.

// Validate if RichResponse already contains StructuredResponse object
for (let item of this.items) {
for (const item of this.items) {
if (item.structuredResponse) {

@@ -361,6 +369,6 @@ debug('Cannot include >1 StructuredResponses in RichResponse');

if (typeof response === 'string') {
simpleResponseObj = isSsml(response)
simpleResponseObj = isSsml(response) || isPaddedSsml(response)
? { ssml: response } : { textToSpeech: response };
} else if (response.speech) {
simpleResponseObj = isSsml(response.speech)
simpleResponseObj = isSsml(response.speech) || isPaddedSsml(response.speech)
? { ssml: response.speech } : { textToSpeech: response.speech };

@@ -374,3 +382,3 @@ simpleResponseObj.displayText = response.displayText;

}
};
}

@@ -380,3 +388,3 @@ /**

*/
const BasicCard = class {
class BasicCard {
/**

@@ -559,3 +567,3 @@ * Constructor for BasicCard. Accepts optional BasicCard to clone.

}
};
}

@@ -565,3 +573,3 @@ /**

*/
const List = class {
class List {
/**

@@ -592,3 +600,3 @@ * Constructor for List. Accepts optional List to clone, string title, or

} else if (Array.isArray(list)) {
for (let item of list) {
for (const item of list) {
this.items.push(new OptionItem(item));

@@ -601,3 +609,3 @@ }

if (list.items) {
for (let item of list.items) {
for (const item of list.items) {
this.items.push(new OptionItem(item));

@@ -637,3 +645,3 @@ }

if (Array.isArray(optionItems)) {
for (let item of optionItems) {
for (const item of optionItems) {
this.items.push(item);

@@ -644,10 +652,9 @@ }

}
if (this.items.length > LIST_ITEM_LIMIT) {
this.items = this.items.slice(0, LIST_ITEM_LIMIT);
error('List can have no more than ' + LIST_ITEM_LIMIT +
' items');
if (this.items.length > Limits.LIST_ITEM_MAX) {
this.items = this.items.slice(0, Limits.LIST_ITEM_MAX);
error(`List can have no more than ${Limits.LIST_ITEM_MAX} items`);
}
return this;
}
};
}

@@ -657,3 +664,3 @@ /**

*/
const Carousel = class {
class Carousel {
/**

@@ -675,3 +682,3 @@ * Constructor for Carousel. Accepts optional Carousel to clone or list of

if (Array.isArray(carousel)) {
for (let item of carousel) {
for (const item of carousel) {
this.items.push(new OptionItem(item));

@@ -681,3 +688,3 @@ }

if (carousel.items) {
for (let item of carousel.items) {
for (const item of carousel.items) {
this.items.push(new OptionItem(item));

@@ -702,3 +709,3 @@ }

if (Array.isArray(optionItems)) {
for (let item of optionItems) {
for (const item of optionItems) {
this.items.push(item);

@@ -709,10 +716,9 @@ }

}
if (this.items.length > CAROUSEL_ITEM_LIMIT) {
this.items = this.items.slice(0, CAROUSEL_ITEM_LIMIT);
error('Carousel can have no more than ' + CAROUSEL_ITEM_LIMIT +
' items');
if (this.items.length > Limits.CAROUSEL_ITEM_MAX) {
this.items = this.items.slice(0, Limits.CAROUSEL_ITEM_MAX);
error(`Carousel can have no more than ${Limits.CAROUSEL_ITEM_MAX} items`);
}
return this;
}
};
}

@@ -722,3 +728,3 @@ /**

*/
const OptionItem = class {
class OptionItem {
/**

@@ -866,3 +872,3 @@ * Constructor for OptionItem. Accepts optional OptionItem to clone.

if (Array.isArray(synonyms)) {
for (let synonym of synonyms) {
for (const synonym of synonyms) {
this.optionInfo.synonyms.push(synonym);

@@ -875,3 +881,3 @@ }

}
};
}

@@ -884,6 +890,13 @@ /**

*/
function isSsml (text) {
return /^<speak\b[^>]*>([^]*?)<\/speak>$/gi.test(text);
}
const isSsml = text => /^<speak\b[^>]*>([^]*?)<\/speak>$/gi.test(text);
/**
* Check if given text contains SSML, allowing for whitespace padding.
*
* @param {string} text Text to check.
* @return {boolean} True if text contains possibly whitespace padded SSML,
* false otherwise.
*/
const isPaddedSsml = text => /^\s*<speak\b[^>]*>([^]*?)<\/speak>\s*$/gi.test(text);
module.exports = {

@@ -896,3 +909,5 @@ RichResponse,

isSsml,
ImageDisplays
isPaddedSsml,
ImageDisplays,
Limits
};
{
"rules": {
"require-jsdoc": "off",
"valid-jsdoc": "off"
}
}
"rules": {
"require-jsdoc": "off",
"valid-jsdoc": "off",
"no-magic-numbers": "off"
}
}

@@ -35,3 +35,4 @@ /**

MockRequest,
MockResponse
MockResponse,
clone
} = require('./utils/mocking');

@@ -62,3 +63,3 @@

describe('#isNotApiVersionOne_', function () {
let invalidHeader = {
const invalidHeader = {
'Content-Type': 'application/json',

@@ -92,3 +93,3 @@ 'google-assistant-api-version': 'v1',

it('Should detect v2 when header is present', function () {
let headerWithV2 = JSON.parse(JSON.stringify(headerV1));
const headerWithV2 = JSON.parse(JSON.stringify(headerV1));
headerWithV2['Google-Actions-API-Version'] = '2';

@@ -121,3 +122,3 @@ const mockRequest = new MockRequest(headerWithV2, {});

expect(app.isSsml_('<SPEAK></SPEAK>')).to.equal(true);
expect(app.isSsml_(' <speak></speak> ')).to.equal(false);
expect(app.isSsml_(' <speak></speak> ')).to.equal(true);
expect(app.isSsml_('<speak> </speak>')).to.equal(true);

@@ -147,4 +148,4 @@ expect(app.isSsml_('<speak version="1.0"></speak>')).to.equal(true);

.to.equal(true);
expect(app.isSsml_(
'<speak><say-as interpret-as="date" format="yyyymmdd" detail="1">1960-09-10</say-as></speak>'))
expect(app.isSsml_('<speak>' +
'<say-as interpret-as="date" format="yyyymmdd" detail="1">1960-09-10</say-as></speak>'))
.to.equal(true);

@@ -175,3 +176,3 @@ expect(app.isSsml_('<speak><say-as interpret-as="date" format="dm">10-9</say-as></speak>')).to

beforeEach(function () {
mockRequest = new MockRequest(headerV2, JSON.parse(JSON.stringify(dialogflowAppRequestBodyNewSessionMock)));
mockRequest = new MockRequest(headerV2, clone(dialogflowAppRequestBodyNewSessionMock));
app = new AssistantApp({request: mockRequest, response: mockResponse});

@@ -185,4 +186,5 @@

it('Should resolve a promise when actionMap contains a handler that returns a promise', function (done) {
let handler = app => {
it('Should resolve a promise when actionMap contains a handler ' +
'that returns a promise', function (done) {
const handler = app => {
return Promise.resolve('success');

@@ -202,4 +204,5 @@ };

it('Should reject a promise when actionMap contains a handler that returns a promise error', function (done) {
let handler = app => {
it('Should reject a promise when actionMap contains a handler ' +
'that returns a promise error', function (done) {
const handler = app => {
return Promise.reject(new Error('error'));

@@ -220,3 +223,3 @@ };

it('Should resolve a promise when handler function returns a promise', function (done) {
let handler = app => {
const handler = app => {
return Promise.resolve('success');

@@ -234,3 +237,3 @@ };

it('Should reject a promise when handler function returns a promise error', function (done) {
let handler = app => {
const handler = app => {
return Promise.reject(new Error('error'));

@@ -248,3 +251,3 @@ };

it('Should resolve a promise when handler function does not return a promise', function (done) {
let handler = app => {
const handler = app => {
return 'success';

@@ -261,4 +264,5 @@ };

it('Should resolve a promise when actionMap contains a handler that does not return a promise', function (done) {
let handler = app => {
it('Should resolve a promise when actionMap contains a handler ' +
'that does not return a promise', function (done) {
const handler = app => {
return 'success';

@@ -265,0 +269,0 @@ };

@@ -36,2 +36,4 @@ /**

const { clone } = require('./utils/mocking');
const { OrderUpdate } = require('.././transactions');

@@ -58,4 +60,4 @@

it('should create valid object', () => {
let richResponse = new RichResponse();
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
const richResponse = new RichResponse();
expect(clone(richResponse)).to.deep.equal({
items: [],

@@ -76,3 +78,3 @@ suggestions: []

richResponse.addSimpleResponse('This is speech');
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [

@@ -91,3 +93,3 @@ {

richResponse.addSimpleResponse('<speak>This is speech</speak>');
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [

@@ -104,2 +106,16 @@ {

it('should add a simple response w/ just whitespace padded SSML speech', () => {
richResponse.addSimpleResponse(' <speak>This is speech</speak> ');
expect(clone(richResponse)).to.deep.equal({
items: [
{
simpleResponse: {
ssml: ' <speak>This is speech</speak> '
}
}
],
suggestions: []
});
});
it('should add a simple response w/ speech and display text', () => {

@@ -110,3 +126,3 @@ richResponse.addSimpleResponse({

});
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [

@@ -129,3 +145,3 @@ {

});
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [

@@ -143,2 +159,20 @@ {

it('should add a simple response w/ whitespace padded SSML speech and display text', () => {
richResponse.addSimpleResponse({
speech: ' <speak>This is speech</speak> ',
displayText: 'This is display text'
});
expect(clone(richResponse)).to.deep.equal({
items: [
{
simpleResponse: {
ssml: ' <speak>This is speech</speak> ',
displayText: 'This is display text'
}
}
],
suggestions: []
});
});
it('not add more than two simple responses', () => {

@@ -148,3 +182,3 @@ richResponse.addSimpleResponse('text');

richResponse.addSimpleResponse('text');
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [

@@ -236,3 +270,3 @@ {

richResponse.addSuggestions('suggestion');
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [],

@@ -247,3 +281,3 @@ suggestions: [{

richResponse.addSuggestions(['suggestion one', 'suggestion two']);
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [],

@@ -262,3 +296,3 @@ suggestions: [

richResponse.addSuggestions(['suggestion one that is very long', 'suggestion two']);
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [],

@@ -272,3 +306,3 @@ suggestions: [

richResponse.addSuggestions('suggestion one that is very long');
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [],

@@ -292,3 +326,3 @@ suggestions: [

richResponse.addSuggestionLink('title', 'url');
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [],

@@ -306,3 +340,3 @@ suggestions: [],

richResponse.addSuggestionLink('replacement', 'replacement url');
expect(JSON.parse(JSON.stringify(richResponse))).to.deep.equal({
expect(clone(richResponse)).to.deep.equal({
items: [],

@@ -325,4 +359,4 @@ suggestions: [],

it('should create valid object', () => {
let basicCard = new BasicCard();
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
const basicCard = new BasicCard();
expect(clone(basicCard)).to.deep.equal({
formattedText: '',

@@ -343,3 +377,3 @@ buttons: []

basicCard.setTitle('Title');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
title: 'Title',

@@ -354,3 +388,3 @@ formattedText: '',

basicCard.setTitle('New title');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
title: 'New title',

@@ -372,3 +406,3 @@ formattedText: '',

basicCard.setSubtitle('Subtitle');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
subtitle: 'Subtitle',

@@ -383,3 +417,3 @@ formattedText: '',

basicCard.setSubtitle('New Subtitle');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
subtitle: 'New Subtitle',

@@ -401,3 +435,3 @@ formattedText: '',

basicCard.setBodyText('body text');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: 'body text',

@@ -411,3 +445,3 @@ buttons: []

basicCard.setBodyText('New body text');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: 'New body text',

@@ -428,3 +462,3 @@ buttons: []

basicCard.setImage('url', 'accessibilityText');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: '',

@@ -442,3 +476,3 @@ buttons: [],

basicCard.setImage('new.url', 'new_accessibilityText');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: '',

@@ -467,3 +501,3 @@ buttons: [],

basicCard.setImageDisplay(ImageDisplays.WHITE);
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: '',

@@ -478,3 +512,3 @@ buttons: [],

basicCard.setImageDisplay(ImageDisplays.CROPPED);
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: '',

@@ -496,3 +530,3 @@ buttons: [],

basicCard.addButton('button', 'url');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: '',

@@ -512,3 +546,3 @@ buttons: [{

basicCard.addButton('button three', 'url.three');
expect(JSON.parse(JSON.stringify(basicCard))).to.deep.equal({
expect(clone(basicCard)).to.deep.equal({
formattedText: '',

@@ -546,4 +580,4 @@ buttons: [

it('should create valid object', () => {
let list = new List();
expect(JSON.parse(JSON.stringify(list))).to.deep.equal({
const list = new List();
expect(clone(list)).to.deep.equal({
items: []

@@ -563,3 +597,3 @@ });

list.setTitle('Title');
expect(JSON.parse(JSON.stringify(list))).to.deep.equal({
expect(clone(list)).to.deep.equal({
title: 'Title',

@@ -573,3 +607,3 @@ items: []

list.setTitle('New title');
expect(JSON.parse(JSON.stringify(list))).to.deep.equal({
expect(clone(list)).to.deep.equal({
title: 'New title',

@@ -590,3 +624,3 @@ items: []

list.addItems(new OptionItem());
expect(JSON.parse(JSON.stringify(list))).to.deep.equal({
expect(clone(list)).to.deep.equal({
items: [{

@@ -604,3 +638,3 @@ title: '',

list.addItems([new OptionItem(), new OptionItem(), new OptionItem()]);
expect(JSON.parse(JSON.stringify(list))).to.deep.equal({
expect(clone(list)).to.deep.equal({
items: [

@@ -633,5 +667,5 @@ {

it('should add no more than 30 items', () => {
let optionItems = [];
const optionItems = [];
for (let i = 0; i < 35; i++) {
let optionItem = new OptionItem().setKey(i.toString());
const optionItem = new OptionItem().setKey(i.toString());
optionItems.push(optionItem);

@@ -654,4 +688,4 @@ }

it('should create valid object', () => {
let carousel = new Carousel();
expect(JSON.parse(JSON.stringify(carousel))).to.deep.equal({
const carousel = new Carousel();
expect(clone(carousel)).to.deep.equal({
items: []

@@ -671,3 +705,3 @@ });

carousel.addItems(new OptionItem());
expect(JSON.parse(JSON.stringify(carousel))).to.deep.equal({
expect(clone(carousel)).to.deep.equal({
items: [{

@@ -685,3 +719,3 @@ title: '',

carousel.addItems([new OptionItem(), new OptionItem(), new OptionItem()]);
expect(JSON.parse(JSON.stringify(carousel))).to.deep.equal({
expect(clone(carousel)).to.deep.equal({
items: [

@@ -714,5 +748,5 @@ {

it('should add no more than 10 items', () => {
let optionItems = [];
const optionItems = [];
for (let i = 0; i < 15; i++) {
let optionItem = new OptionItem().setKey(i.toString());
const optionItem = new OptionItem().setKey(i.toString());
optionItems.push(optionItem);

@@ -735,4 +769,4 @@ }

it('should create valid object', () => {
let optionItem = new OptionItem();
expect(JSON.parse(JSON.stringify(optionItem))).to.deep.equal({
const optionItem = new OptionItem();
expect(clone(optionItem)).to.deep.equal({
title: '',

@@ -756,3 +790,3 @@ optionInfo: {

optionItem.setTitle('Title');
expect(JSON.parse(JSON.stringify(optionItem))).to.deep.equal({
expect(clone(optionItem)).to.deep.equal({
title: 'Title',

@@ -769,3 +803,3 @@ optionInfo: {

optionItem.setTitle('New title');
expect(JSON.parse(JSON.stringify(optionItem))).to.deep.equal({
expect(clone(optionItem)).to.deep.equal({
title: 'New title',

@@ -789,3 +823,3 @@ optionInfo: {

optionItem.setDescription('Description');
expect(JSON.parse(JSON.stringify(optionItem))).to.deep.equal({
expect(clone(optionItem)).to.deep.equal({
title: '',

@@ -803,3 +837,3 @@ description: 'Description',

optionItem.setDescription('New Description');
expect(JSON.parse(JSON.stringify(optionItem))).to.deep.equal({
expect(clone(optionItem)).to.deep.equal({
title: '',

@@ -824,3 +858,3 @@ description: 'New Description',

optionItem.setImage('url', 'accessibilityText');
expect(JSON.parse(JSON.stringify(optionItem))).to.deep.equal({
expect(clone(optionItem)).to.deep.equal({
title: '',

@@ -841,3 +875,3 @@ optionInfo: {

optionItem.setImage('new.url', 'new_accessibilityText');
expect(JSON.parse(JSON.stringify(optionItem))).to.deep.equal({
expect(clone(optionItem)).to.deep.equal({
title: '',

@@ -844,0 +878,0 @@ optionInfo: {

@@ -36,2 +36,4 @@ /**

const { clone } = require('./utils/mocking');
// Default logger

@@ -54,4 +56,4 @@ winston.loggers.add('DEFAULT_LOGGER', {

it('should create valid object', () => {
let order = new Order('test_id');
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
const order = new Order('test_id');
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -74,3 +76,3 @@ otherItems: []

});
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -91,3 +93,3 @@ otherItems: [],

});
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -113,3 +115,3 @@ otherItems: [],

});
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -130,3 +132,3 @@ otherItems: [{

}]);
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -153,3 +155,3 @@ otherItems: [

order.setImage('http://image.com', 'ALT_TEXT', 100, 150);
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -169,3 +171,3 @@ otherItems: [],

order.setImage('http://image.com/2', 'ALT_TEXT_2');
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -190,3 +192,3 @@ otherItems: [],

order.setTermsOfService('http://example.com');
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -201,3 +203,3 @@ otherItems: [],

order.setTermsOfService('http://example.com/2');
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -219,3 +221,3 @@ otherItems: [],

order.setTotalPrice('ACTUAL', 'USD', 30, 40);
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -237,3 +239,3 @@ otherItems: [],

order.setTotalPrice('ESTIMATE', 'GBP', 60);
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -262,3 +264,3 @@ otherItems: [],

order.setTime('TIME_TYPE', 'SAMPLE_TIME');
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -279,3 +281,3 @@ otherItems: [],

order.setTime('TIME_TYPE_2', 'SAMPLE_TIME_2');
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -324,3 +326,3 @@ otherItems: [],

order.addLocation(locationOne.type, locationOne.location);
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -338,3 +340,3 @@ otherItems: [],

order.addLocation(locationTwo.type, locationTwo.location);
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -353,3 +355,3 @@ otherItems: [],

order.addLocation(locationThree.type, locationThree.location);
expect(JSON.parse(JSON.stringify(order))).to.deep.equal({
expect(clone(order)).to.deep.equal({
id: 'test_id',

@@ -372,4 +374,4 @@ otherItems: [],

it('should create valid object', () => {
let cart = new Cart('test_id');
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
const cart = new Cart('test_id');
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -391,3 +393,3 @@ lineItems: [],

cart.setMerchant('merchant_id', 'My Merchant');
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -406,3 +408,3 @@ lineItems: [],

cart.setMerchant('merchant_id_2', 'Your Merchant');
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -428,3 +430,3 @@ lineItems: [],

cart.setNotes('order notes');
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -440,3 +442,3 @@ lineItems: [],

cart.setNotes('order notes 2');
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -461,3 +463,3 @@ lineItems: [],

});
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -479,3 +481,3 @@ lineItems: [{

}]);
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -505,3 +507,3 @@ lineItems: [

});
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -523,3 +525,3 @@ lineItems: [],

}]);
expect(JSON.parse(JSON.stringify(cart))).to.deep.equal({
expect(clone(cart)).to.deep.equal({
id: 'test_id',

@@ -545,4 +547,4 @@ lineItems: [],

it('should create valid object', () => {
let lineItem = new LineItem('test_item_id', 'test_item');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
const lineItem = new LineItem('test_item_id', 'test_item');
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -565,3 +567,3 @@ name: 'test_item'

});
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -587,3 +589,3 @@ name: 'test_item',

}]);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -608,3 +610,3 @@ name: 'test_item',

lineItem.addSublines('new_item');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -625,3 +627,3 @@ name: 'test_item',

]);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -647,3 +649,3 @@ name: 'test_item',

]);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -674,3 +676,3 @@ name: 'test_item',

lineItem.setImage('http://image.com', 'ALT_TEXT', 100, 150);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -690,3 +692,3 @@ name: 'test_item',

lineItem.setImage('http://image.com/2', 'ALT_TEXT_2');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -711,3 +713,3 @@ name: 'test_item',

lineItem.setPrice('ACTUAL', 'USD', 30, 40);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -729,3 +731,3 @@ name: 'test_item',

lineItem.setPrice('ESTIMATE', 'GBP', 60);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -754,3 +756,3 @@ name: 'test_item',

lineItem.setType('REGULAR');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -765,3 +767,3 @@ name: 'test_item',

lineItem.setType('FEE');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -783,3 +785,3 @@ name: 'test_item',

lineItem.setQuantity(1);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -794,3 +796,3 @@ name: 'test_item',

lineItem.setQuantity(2);
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -812,3 +814,3 @@ name: 'test_item',

lineItem.setDescription('A great item');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -823,3 +825,3 @@ name: 'test_item',

lineItem.setDescription('A good item');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -841,3 +843,3 @@ name: 'test_item',

lineItem.setOfferId('offer');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -852,3 +854,3 @@ name: 'test_item',

lineItem.setOfferId('24 hr offer');
expect(JSON.parse(JSON.stringify(lineItem))).to.deep.equal({
expect(clone(lineItem)).to.deep.equal({
id: 'test_item_id',

@@ -868,4 +870,4 @@ name: 'test_item',

it('should create valid object with Google order ID', () => {
let orderUpdate = new OrderUpdate('order_id', true);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
const orderUpdate = new OrderUpdate('order_id', true);
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -878,4 +880,4 @@ lineItemUpdates: {},

it('should create valid object with Action order ID', () => {
let orderUpdate = new OrderUpdate('order_id', false);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
const orderUpdate = new OrderUpdate('order_id', false);
expect(clone(orderUpdate)).to.deep.equal({
actionOrderId: 'order_id',

@@ -897,3 +899,3 @@ lineItemUpdates: {},

orderUpdate.setTotalPrice('ACTUAL', 'USD', 30, 40);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -916,3 +918,3 @@ lineItemUpdates: {},

orderUpdate.setTotalPrice('ESTIMATE', 'GBP', 60);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -942,3 +944,3 @@ lineItemUpdates: {},

orderUpdate.setOrderState('CONFIRMED', 'Your order was confirmed');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -957,3 +959,3 @@ lineItemUpdates: {},

orderUpdate.setOrderState('CANCELLED', 'Your order was canceled');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -979,3 +981,3 @@ lineItemUpdates: {},

orderUpdate.setUpdateTime(200, 300);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -991,3 +993,3 @@ lineItemUpdates: {},

orderUpdate.setUpdateTime(100);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1003,3 +1005,3 @@ lineItemUpdates: {},

orderUpdate.setUpdateTime(200);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1012,3 +1014,3 @@ lineItemUpdates: {},

orderUpdate.setUpdateTime(200, 100);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1021,3 +1023,3 @@ lineItemUpdates: {},

orderUpdate.setUpdateTime(200, 1000000); // 1M ns = 1ms
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1040,3 +1042,3 @@ lineItemUpdates: {},

orderUpdate.setUserNotification('Title', 'Order updated!');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1055,3 +1057,3 @@ lineItemUpdates: {},

orderUpdate.setUserNotification('Title_2', 'Your order updated!');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1080,3 +1082,3 @@ lineItemUpdates: {},

'http://example.com/cancel');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1115,3 +1117,3 @@ lineItemUpdates: {},

{ receipt_info: 'value' });
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1131,3 +1133,3 @@ lineItemUpdates: {},

{ reason: 'value' });
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1144,3 +1146,3 @@ lineItemUpdates: {},

orderUpdate.setInfo('FAKE', { receipt_info: 'value' });
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1163,3 +1165,3 @@ lineItemUpdates: {},

'reason');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1185,3 +1187,3 @@ lineItemUpdates: {

orderUpdate.addLineItemPriceUpdate('item_id', 'ACTUAL', 'USD', 30, 40);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1200,3 +1202,3 @@ lineItemUpdates: {},

'reason');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1226,3 +1228,3 @@ lineItemUpdates: {

orderUpdate.addLineItemPriceUpdate('item_id', 'ACTUAL', 'USD', 30, 40);
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1249,3 +1251,3 @@ lineItemUpdates: {

'Confirmed item', 'reason');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1268,3 +1270,3 @@ lineItemUpdates: {

'Confirmed item');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1297,3 +1299,3 @@ lineItemUpdates: {

'Confirmed item', 'reason');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1334,3 +1336,3 @@ lineItemUpdates: {

'Confirmed item');
expect(JSON.parse(JSON.stringify(orderUpdate))).to.deep.equal({
expect(clone(orderUpdate)).to.deep.equal({
googleOrderId: 'order_id',

@@ -1337,0 +1339,0 @@ lineItemUpdates: {

@@ -97,3 +97,3 @@ /**

it('Does not convert incoming function to object', function () {
let stubFunc = function () {};
const stubFunc = function () {};
const camelCaseObject = {

@@ -204,3 +204,3 @@ keyOne: {

it('Does not convert incoming function to object', function () {
let stubFunc = function () {};
const stubFunc = function () {};
const snakeCaseObject = {

@@ -207,0 +207,0 @@ key_one: {

@@ -21,3 +21,3 @@ /**

const MockRequest = class {
class MockRequest {
constructor (headers, body) {

@@ -41,3 +41,3 @@ if (headers) {

const MockResponse = class {
class MockResponse {
constructor () {

@@ -276,5 +276,10 @@ this.statusCode = 200;

const actionsSdkAppRequestBodyNewSessionMockV2 = transformToCamelCase(actionsSdkAppRequestBodyNewSessionMock);
const actionsSdkAppRequestBodyLiveSessionMockV2 = transformToCamelCase(actionsSdkAppRequestBodyLiveSessionMock);
const actionsSdkAppRequestBodyNewSessionMockV2 =
transformToCamelCase(actionsSdkAppRequestBodyNewSessionMock);
const actionsSdkAppRequestBodyLiveSessionMockV2 =
transformToCamelCase(actionsSdkAppRequestBodyLiveSessionMock);
/** @param {Object} obj */
const clone = obj => JSON.parse(JSON.stringify(obj));
module.exports = {

@@ -292,3 +297,4 @@ dialogflowAppRequestBodyLiveSessionMock,

fakeConversationId,
fakeUserId
fakeUserId,
clone
};

@@ -761,3 +761,3 @@ /**

*/
const Order = class {
class Order {
/**

@@ -840,3 +840,3 @@ * Constructor for Order.

if (Array.isArray(items)) {
for (let item of items) {
for (const item of items) {
this.otherItems.push(item);

@@ -952,4 +952,3 @@ }

if (this.extension.locations.length >= ORDER_LOCATION_LIMIT) {
error('Order can have no more than ' + ORDER_LOCATION_LIMIT +
' associated locations');
error(`Order can have no more than ${ORDER_LOCATION_LIMIT} associated locations`);
return this;

@@ -986,3 +985,3 @@ }

}
};
}

@@ -992,3 +991,3 @@ /**

*/
const Cart = class {
class Cart {
/**

@@ -1078,3 +1077,3 @@ * Constructor for Cart.

if (Array.isArray(items)) {
for (let item of items) {
for (const item of items) {
this.lineItems.push(item);

@@ -1100,3 +1099,3 @@ }

if (Array.isArray(items)) {
for (let item of items) {
for (const item of items) {
this.otherItems.push(item);

@@ -1109,3 +1108,3 @@ }

}
};
}

@@ -1115,3 +1114,3 @@ /**

*/
const LineItem = class {
class LineItem {
/**

@@ -1322,3 +1321,3 @@ * Constructor for LineItem.

}
};
}

@@ -1328,3 +1327,3 @@ /**

*/
const OrderUpdate = class {
class OrderUpdate {
/**

@@ -1454,3 +1453,5 @@ * Constructor for OrderUpdate.

const NANOSECONDS_IN_MILLISECOND = 1000000;
let dateObj = new Date((seconds * MILLISECONDS_IN_SECOND) + (nanos / NANOSECONDS_IN_MILLISECOND));
const secondsPart = seconds * MILLISECONDS_IN_SECOND;
const nanosPart = nanos / NANOSECONDS_IN_MILLISECOND;
const dateObj = new Date(secondsPart + nanosPart);
this.updateTime = dateObj.toISOString();

@@ -1577,3 +1578,3 @@ return this;

let newPrice = {
const newPrice = {
type: priceType,

@@ -1659,3 +1660,3 @@ amount: {

// Clear out all other info properties
for (let infoType of Object.keys(TransactionValues.OrderStateInfo)) {
for (const infoType of Object.keys(TransactionValues.OrderStateInfo)) {
delete this[TransactionValues.OrderStateInfo[infoType]];

@@ -1667,3 +1668,3 @@ }

}
};
}

@@ -1670,0 +1671,0 @@ module.exports = {

@@ -19,5 +19,2 @@ /**

// Enable actions-on-google debug logging
process.env.DEBUG = 'actions-on-google:*';
// lodash helpers

@@ -110,4 +107,4 @@ const camelCase = require('lodash.camelcase');

newObject = {};
for (let key of Object.keys(object)) {
let transformedKey = keyTransformation(key);
for (const key of Object.keys(object)) {
const transformedKey = keyTransformation(key);
newObject[transformedKey] = transform(object[key], keyTransformation);

@@ -114,0 +111,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc