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.2.1 to 1.3.0

utils/auth.js

294

actions-sdk-app.js

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

const INPUTS_MAX = 3;
const CONVERSATION_API_SIGNATURE_HEADER = 'authorization';

@@ -82,2 +83,46 @@ // Configure logging for hosting platforms that only support console.log and console.error

/*
* Validates whether request is from Assistant through signature verification.
* Uses Google-Auth-Library to verify authorization token against given
* Google Cloud Project ID. Auth token is given in request header with key,
* "Authorization".
*
* @example
* const app = new ActionsSdkApp({request, response});
* app.isRequestFromAssistant('nodejs-cloud-test-project-1234')
* .then(() => {
* app.ask('Hey there, thanks for stopping by!');
* })
* .catch(err => {
* response.status(400).send();
* });
*
* @param {string} projectId Google Cloud Project ID for the Assistant app.
* @param {Promise} Promise resolving with ID token if request is from
* a valid source, otherwise rejects with the error reason for an invalid
* token.
* @actionssdk
*/
isRequestFromAssistant (projectId) {
debug('isRequestFromAssistant: projectId=%s', projectId);
const googleAuthClient = require('./utils/auth').googleAuthClient;
const jwtToken = this.request_.get(CONVERSATION_API_SIGNATURE_HEADER);
return new Promise((resolve, reject) => {
if (!jwtToken) {
const errorMsg = 'No incoming API Signature JWT token';
error(errorMsg);
reject(errorMsg);
}
googleAuthClient.verifyIdToken(jwtToken, projectId, (err, idToken) => {
if (err) {
error('ID token verification Failed: ' + err);
reject(err);
} else {
resolve(idToken);
}
});
});
}
/*
* Gets the request Conversation API version.

@@ -404,57 +449,2 @@ *

/**
* Asks user for delivery address.
*
* @example
* const app = new ActionsSdkApp({request, response});
* const WELCOME_INTENT = app.StandardIntents.MAIN;
* const DELIVERY_INTENT = app.StandardIntents.DELIVERY_ADDRESS;
*
* function welcomeIntent (app) {
* app.askForDeliveryAddress('To make sure I can deliver to you');
* }
*
* function addressIntent (app) {
* const postalCode = app.getDeliveryAddress().postalAddress.postalCode;
* if (isInDeliveryZone(postalCode)) {
* app.tell('Great looks like you\'re in our delivery area!');
* } else {
* app.tell('I\'m sorry it looks like we can\'t deliver to you.');
* }
* }
*
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(DELIVERY_INTENT, addressIntent);
* app.handleRequest(actionMap);
*
* @param {string} reason Reason given to user for asking delivery address.
* @param {Object=} dialogState JSON object the app uses to hold dialog state that
* will be circulated back by Assistant.
* @return {Object} HTTP response.
* @apiai
*/
askForDeliveryAddress (reason, dialogState) {
debug('askForDeliveryAddress: reason=%s', reason);
if (!reason) {
this.handleError_('reason cannot be empty');
return null;
}
const expectedIntent = this.buildExpectedIntent_(this.StandardIntents.DELIVERY_ADDRESS, []);
if (!expectedIntent) {
error('Error in building expected intent');
return null;
}
expectedIntent.inputValueData = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.DELIVERY_ADDRESS
}, {
addressOptions: {
reason: reason
}
});
const inputPrompt = this.buildInputPrompt(false,
'PLACEHOLDER_FOR_DELIVERY_ADDRESS');
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
/**
* Asks to collect user's input with a carousel.

@@ -754,32 +744,32 @@ *

JSON.stringify(permissionsSpec), JSON.stringify(dialogState));
// Build an Expected Intent object.
const expectedIntent = {
intent: this.StandardIntents.PERMISSION
};
if (this.isNotApiVersionOne_()) {
expectedIntent.inputValueData = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.PERMISSION
}, permissionsSpec);
return this.fulfillSystemIntent_(this.StandardIntents.PERMISSION,
this.InputValueDataTypes_.PERMISSION, permissionsSpec,
'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,
'PLACEHOLDER_FOR_PERMISSION');
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
const inputPrompt = this.buildInputPrompt(false, 'PLACEHOLDER_FOR_PERMISSION');
if (!dialogState) {
dialogState = {
'state': (this.state instanceof State ? this.state.getName() : this.state),
'data': this.data
};
}
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
/**
* Uses TransactionRequirementsCheckValueSpec to construct and send a
* transaction requirements request to Google.
* Uses a given intent spec to construct and send a non-TEXT intent response
* to Google.
*
* @param {Object} transactionRequirementsSpec TransactionRequirementsSpec
* object.
* @param {Object} dialogState JSON object the app uses to hold dialog state that
* @param {String} intent Name of the intent to fulfill. One of
* {@link AssistantApp#StandardIntents|StandardIntents}.
* @param {String} specType Type of the related intent spec. One of
* {@link AssistantApp#InputValueDataTypes_|InputValueDataTypes_}.
* @param {Object} intentSpec Intent Spec object. Pass null to leave empty.
* @param {String=} promptPlaceholder Some placeholder text for the response
* prompt.
* @param {Object=} dialogState JSON object the app uses to hold dialog state that
* will be circulated back by Assistant.

@@ -790,85 +780,22 @@ * @return {Object} HTTP response.

*/
fulfillTransactionRequirementsCheck_ (transactionRequirementsSpec, dialogState) {
debug('fulfillTransactionRequirementsCheck_: transactionRequirementsSpec=%s,' +
' dialogState=%s',
JSON.stringify(transactionRequirementsSpec), JSON.stringify(dialogState));
fulfillSystemIntent_ (intent, specType, intentSpec, promptPlaceholder,
dialogState) {
debug('fulfillSystemIntent_: intent=%s, specType=%s, intentSpec=%s, ' +
'promptPlaceholder=%s dialogState=%s', intent, specType,
JSON.stringify(intentSpec), promptPlaceholder, JSON.stringify(dialogState));
// Build an Expected Intent object.
const expectedIntent = {
intent: this.StandardIntents.TRANSACTION_REQUIREMENTS_CHECK
};
expectedIntent.inputValueData = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.TRANSACTION_REQ_CHECK
}, transactionRequirementsSpec);
const inputPrompt = this.buildInputPrompt(false, 'PLACEHOLDER_FOR_TXN_REQUIREMENTS');
if (!dialogState) {
dialogState = {
'state': (this.state instanceof State ? this.state.getName() : this.state),
'data': this.data
};
const expectedIntent = this.buildExpectedIntent_(intent);
if (!expectedIntent) {
error('Error in building expected intent');
return null;
}
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
/**
* Uses TransactionDecisionValueSpec to construct and send a transaction
* requirements request to Google.
*
* @param {Object} transactionDecisionValueSpec TransactionDecisionValueSpec
* object.
* @param {Object} dialogState JSON object the app uses to hold dialog state that
* will be circulated back by Assistant.
* @return {Object} HTTP response.
* @private
* @actionssdk
*/
fulfillTransactionDecision_ (transactionDecisionValueSpec, dialogState) {
debug('fulfillTransactionDecision_: transactionDecisionValueSpec=%s,' +
' dialogState=%s',
JSON.stringify(transactionDecisionValueSpec), JSON.stringify(dialogState));
// Build an Expected Intent object.
const expectedIntent = {
intent: this.StandardIntents.TRANSACTION_DECISION
};
expectedIntent.inputValueData = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.TRANSACTION_DECISION
}, transactionDecisionValueSpec);
// Send an Ask request to Assistant.
const inputPrompt = this.buildInputPrompt(false, 'PLACEHOLDER_FOR_TXN_DECISION');
if (!dialogState) {
dialogState = {
'state': (this.state instanceof State ? this.state.getName() : this.state),
'data': this.data
};
expectedIntent.inputValueData = {};
if (intentSpec) {
expectedIntent.inputValueData = Object.assign({
[this.ANY_TYPE_PROPERTY_]: specType
}, intentSpec);
}
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
/**
* Uses ConfirmationValueSpec to construct and send a confirmation request to
* Google.
*
* @param {Object} confirmationValueSpec ConfirmationValueSpec object.
* @return {Object} HTTP response.
* @private
* @actionssdk
*/
fulfillConfirmationRequest_ (confirmationValueSpec, dialogState) {
debug('fulfillConfirmationRequest_: confirmationValueSpec=%s,' +
' dialogState=%s', JSON.stringify(confirmationValueSpec),
JSON.stringify(dialogState));
// Build an Expected Intent object.
const expectedIntent = {
intent: this.StandardIntents.CONFIRMATION
};
expectedIntent.inputValueData = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.CONFIRMATION
}, confirmationValueSpec);
// Send an Ask request to Assistant.
const inputPrompt = this.buildInputPrompt(false, 'PLACEHOLDER_FOR_CONFIRMATION');
if (!dialogState) {
dialogState = {
'state': (this.state instanceof State ? this.state.getName() : this.state),
'data': this.data
};
}
const inputPrompt = this.buildInputPrompt(false, promptPlaceholder ||
'PLACEHOLDER_FOR_INTENT');
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);

@@ -878,57 +805,2 @@ }

/**
* Uses DateTimeValueSpec to construct and send a datetime request to Google.
*
* @param {Object} dateTimeValueSpec DateTimeValueSpec object.
* @return {Object} HTTP response.
* @private
* @actionssdk
*/
fulfillDateTimeRequest_ (dateTimeValueSpec, dialogState) {
debug('fulfillDateTimeRequest_: dateTimeValueSpec=%s,' +
' dialogState=%s', JSON.stringify(dateTimeValueSpec),
JSON.stringify(dialogState));
// Build an Expected Intent object.
const expectedIntent = {
intent: this.StandardIntents.DATETIME
};
expectedIntent.inputValueData = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.DATETIME
}, dateTimeValueSpec);
// Send an Ask request to Assistant.
const inputPrompt = this.buildInputPrompt(false, 'PLACEHOLDER_FOR_DATETIME');
if (!dialogState) {
dialogState = {
'state': (this.state instanceof State ? this.state.getName() : this.state),
'data': this.data
};
}
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
/**
* Construct and send a sign in request to Google.
*
* @return {Object} HTTP response.
* @private
* @actionssdk
*/
fulfillSignInRequest_ (dialogState) {
debug('fulfillSignInRequest_: dialogState=%s', JSON.stringify(dialogState));
// Build an Expected Intent object.
const expectedIntent = {
intent: this.StandardIntents.SIGN_IN
};
expectedIntent.inputValueData = {};
// Send an Ask request to Assistant.
const inputPrompt = this.buildInputPrompt(false, 'PLACEHOLDER_FOR_SIGN_IN');
if (!dialogState) {
dialogState = {
'state': (this.state instanceof State ? this.state.getName() : this.state),
'data': this.data
};
}
return this.buildAskHelper_(inputPrompt, [expectedIntent], dialogState);
}
/**
* Builds the ask response to send back to Assistant.

@@ -1002,5 +874,3 @@ *

}
const expectedIntent = {
intent: intent
};
const expectedIntent = { intent };
return expectedIntent;

@@ -1007,0 +877,0 @@ }

@@ -684,52 +684,2 @@ /**

/**
* Asks user for delivery address.
*
* @example
* const app = new ApiAiApp({request: request, response: response});
* const WELCOME_INTENT = 'input.welcome';
* const DELIVERY_INTENT = 'delivery.address';
*
* function welcomeIntent (app) {
* app.askForDeliveryAddress('To make sure I can deliver to you');
* }
*
* function addressIntent (app) {
* const postalCode = app.getDeliveryAddress().postalAddress.postalCode;
* if (isInDeliveryZone(postalCode)) {
* app.tell('Great looks like you\'re in our delivery area!');
* } else {
* app.tell('I\'m sorry it looks like we can\'t deliver to you.');
* }
* }
*
* const actionMap = new Map();
* actionMap.set(WELCOME_INTENT, welcomeIntent);
* actionMap.set(DELIVERY_INTENT, addressIntent);
* app.handleRequest(actionMap);
*
* @param {string} reason Reason given to user for asking delivery address.
* @return {Object} HTTP response.
* @apiai
*/
askForDeliveryAddress (reason) {
debug('askForDeliveryAddress: reason=%s', reason);
if (!reason) {
this.handleError_('reason cannot be empty');
return null;
}
const response = this.buildResponse_('PLACEHOLDER_FOR_DELIVERY_ADDRESS', true);
response.data.google.systemIntent = {
intent: this.StandardIntents.DELIVERY_ADDRESS
};
response.data.google.systemIntent.data = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.DELIVERY_ADDRESS
}, {
addressOptions: {
reason: reason
}
});
return this.doResponse_(response, RESPONSE_CODE_OK);
}
/**
* Tells the Assistant to render the speech response and close the mic.

@@ -1085,24 +1035,31 @@ *

const inputPrompt = 'PLACEHOLDER_FOR_PERMISSION';
const response = this.buildResponse_(inputPrompt, true);
response.data.google.systemIntent = {
intent: this.StandardIntents.PERMISSION
};
if (this.isNotApiVersionOne_()) {
response.data.google.systemIntent.data = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.PERMISSION
}, permissionsSpec);
return this.fulfillSystemIntent_(this.StandardIntents.PERMISSION,
this.InputValueDataTypes_.PERMISSION, permissionsSpec,
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);
}
return this.doResponse_(response, RESPONSE_CODE_OK);
}
/**
* Uses TransactionRequirementsCheckValueSpec to construct and send a
* transaction requirements request to Google.
* Uses a given intent spec to construct and send a non-TEXT intent response
* to Google.
*
* @param {Object} transactionRequirementsSpec TransactionRequirementsSpec
* object.
* @param {String} intent Name of the intent to fulfill. One of
* {@link AssistantApp#StandardIntents|StandardIntents}.
* @param {String} specType Type of the related intent spec. One of
* {@link AssistantApp#InputValueDataTypes_|InputValueDataTypes_}.
* @param {Object} intentSpec Intent Spec object. Pass {} to leave empty.
* @param {String=} promptPlaceholder Some placeholder text for the response
* prompt. Default is 'PLACEHOLDER_FOR_INTENT'.
* @param {Object=} dialogState JSON object the app uses to hold dialog state that
* will be circulated back by Assistant.
* @return {Object} HTTP response.

@@ -1112,95 +1069,16 @@ * @private

*/
fulfillTransactionRequirementsCheck_ (transactionRequirementsSpec) {
debug('fulfillTransactionRequirementsCheck_: transactionRequirementsSpec=%s',
JSON.stringify(transactionRequirementsSpec));
const response = this.buildResponse_('PLACEHOLDER_FOR_TXN_REQUIREMENTS', true);
response.data.google.systemIntent = {
intent: this.StandardIntents.TRANSACTION_REQUIREMENTS_CHECK
};
response.data.google.systemIntent.data = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.TRANSACTION_REQ_CHECK
}, transactionRequirementsSpec);
return this.doResponse_(response, RESPONSE_CODE_OK);
}
/**
* Uses TransactionDecisionValueSpec to construct and send a transaction
* requirements request to Google.
*
* @param {Object} transactionDecisionValueSpec TransactionDecisionValueSpec
* object.
* @return {Object} HTTP response.
* @private
* @apiai
*/
fulfillTransactionDecision_ (transactionDecisionValueSpec) {
debug('fulfillTransactionDecision_: transactionDecisionValueSpec=%s',
JSON.stringify(transactionDecisionValueSpec));
const response = this.buildResponse_('PLACEHOLDER_FOR_TXN_DECISION', true);
response.data.google.systemIntent = {
intent: this.StandardIntents.TRANSACTION_DECISION
};
response.data.google.systemIntent.data = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.TRANSACTION_DECISION
}, transactionDecisionValueSpec);
return this.doResponse_(response, RESPONSE_CODE_OK);
}
/**
* Uses ConfirmationValueSpec to construct and send a confirmation request to
* Google.
*
* @param {Object} confirmationValueSpec ConfirmationValueSpec object.
* @return {Object} HTTP response.
* @private
* @apiai
*/
fulfillConfirmationRequest_ (confirmationValueSpec) {
debug('fulfillConfirmationRequest_: confirmationValueSpec=%s',
JSON.stringify(confirmationValueSpec));
const response = this.buildResponse_('PLACEHOLDER_FOR_CONFIRMATION', true);
response.data.google.systemIntent = {
intent: this.StandardIntents.CONFIRMATION
};
response.data.google.systemIntent.data = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.CONFIRMATION
}, confirmationValueSpec);
return this.doResponse_(response, RESPONSE_CODE_OK);
}
/**
* Uses DateTimeValueSpec to construct and send a datetime request to Google.
*
* @param {Object} dateTimeValueSpec DateTimeValueSpec object.
* @return {Object} HTTP response.
* @private
* @apiai
*/
fulfillDateTimeRequest_ (dateTimeValueSpec) {
debug('fulfillDateTimeRequest_: dateTimeValueSpec=%s',
JSON.stringify(dateTimeValueSpec));
const response = this.buildResponse_('PLACEHOLDER_FOR_DATETIME', true);
response.data.google.systemIntent = {
intent: this.StandardIntents.DATETIME
};
response.data.google.systemIntent.data = Object.assign({
[this.ANY_TYPE_PROPERTY_]: this.InputValueDataTypes_.DATETIME
}, dateTimeValueSpec);
return this.doResponse_(response, RESPONSE_CODE_OK);
}
/**
* Constructs and sends a sign in request to Google.
*
* @return {Object} HTTP response.
* @private
* @apiai
*/
fulfillSignInRequest_ () {
debug('fulfillSignInRequest_');
const response = this.buildResponse_('PLACEHOLDER_FOR_SIGN_IN', true);
response.data.google.systemIntent = {
intent: this.StandardIntents.SIGN_IN
};
fulfillSystemIntent_ (intent, specType, intentSpec, promptPlaceholder,
dialogState) {
debug('fulfillSystemIntent_: intent=%s, specType=%s, intentSpec=%s, ' +
'promptPlaceholder=%s dialogState=%s', intent, specType,
JSON.stringify(intentSpec), promptPlaceholder, JSON.stringify(dialogState));
const response = this.buildResponse_(promptPlaceholder ||
'PLACEHOLDER_FOR_INTENT', true);
response.data.google.systemIntent = { intent };
response.data.google.systemIntent.data = {};
if (intentSpec) {
response.data.google.systemIntent.data = Object.assign({
[this.ANY_TYPE_PROPERTY_]: specType
}, intentSpec);
}
return this.doResponse_(response, RESPONSE_CODE_OK);

@@ -1207,0 +1085,0 @@ }

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

"main": "actions-on-google.js",
"version": "1.2.1",
"version": "1.3.0",
"license": "Apache-2.0",

@@ -43,2 +43,3 @@ "author": "Google Inc.",

"debug": "^2.2.0",
"google-auth-library": "^0.10.0",
"lodash.camelcase": "^4.3.0",

@@ -45,0 +46,0 @@ "lodash.snakecase": "^4.1.1"

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