From 3423a601fb1efe66ef7a7bad38bc24ef64cd17f0 Mon Sep 17 00:00:00 2001 From: joelhegg Date: Sun, 7 Jan 2018 03:21:28 -0500 Subject: [PATCH] [actions-on-google] Upgrade to 1.7 (#22714) * [actions-on-google] Upgrade to 1.6.1 * [actions-on-google] Upgrade to 1.7 * Make TransactionValues a namespace to avoid issue with enums that can't be imported and acccessed properly * Use SurfaceCapabilities in more places, warning about AssistantApp enums --- types/actions-on-google/actions-sdk-app.d.ts | 50 +- types/actions-on-google/assistant-app.d.ts | 180 ++-- types/actions-on-google/dialogflow-app.d.ts | 3 +- types/actions-on-google/index.d.ts | 2 +- types/actions-on-google/response-builder.d.ts | 49 +- types/actions-on-google/transactions.d.ts | 900 +++++++++--------- 6 files changed, 628 insertions(+), 556 deletions(-) diff --git a/types/actions-on-google/actions-sdk-app.d.ts b/types/actions-on-google/actions-sdk-app.d.ts index 09a4fbe0ad..afa422fad3 100644 --- a/types/actions-on-google/actions-sdk-app.d.ts +++ b/types/actions-on-google/actions-sdk-app.d.ts @@ -224,18 +224,24 @@ export class ActionsSdkApp extends AssistantApp { getSelectedOption(): string; /** - * 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}. * * @example * const app = new ActionsSdkApp({request: request, response: response}); * + * 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, 'Hi! ' + - * 'I can read out an ordinal like ' + - * '123. Say a number.', - * ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']); + * const ssml = 'Hi! ' + + * 'I can read out an ordinal like ' + + * '123. Say a number.'; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); * app.ask(inputPrompt); * } * @@ -243,9 +249,9 @@ export class ActionsSdkApp extends AssistantApp { * if (app.getRawInput() === 'bye') { * app.tell('Goodbye!'); * } else { - * const inputPrompt = app.buildInputPrompt(true, 'You said, ' + - * app.getRawInput() + '', - * ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']); + * const ssml = 'You said, ' + + * app.getRawInput() + ''; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); * app.ask(inputPrompt); * } * } @@ -272,7 +278,7 @@ export class ActionsSdkApp extends AssistantApp { * const app = new ActionsSdkApp({request, response}); * * function welcomeIntent (app) { - * app.askWithlist('Which of these looks good?', + * app.askWithList('Which of these looks good?', * app.buildList('List title') * .addItems([ * app.buildOptionItem(SELECTION_KEY_ONE, @@ -356,11 +362,17 @@ export class ActionsSdkApp extends AssistantApp { * @example * const app = new ActionsSdkApp({request: request, response: response}); * + * 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, 'Hi! ' + - * 'I can read out an ordinal like ' + - * '123. Say a number.', - * ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']); + * const ssml = 'Hi! ' + + * 'I can read out an ordinal like ' + + * '123. Say a number.'; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); * app.ask(inputPrompt); * } * @@ -368,9 +380,9 @@ export class ActionsSdkApp extends AssistantApp { * if (app.getRawInput() === 'bye') { * app.tell('Goodbye!'); * } else { - * const inputPrompt = app.buildInputPrompt(true, 'You said, ' + - * app.getRawInput() + '', - * ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']); + * const ssml = 'You said, ' + + * app.getRawInput() + ''; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); * app.ask(inputPrompt); * } * } @@ -390,7 +402,7 @@ export class ActionsSdkApp extends AssistantApp { /** * Builds the {@link https://developers.google.com/actions/reference/conversation#InputPrompt|InputPrompt object} - * from initial prompt and no-input prompts. + * from initial prompt and no-input prompts. * * The App needs one initial prompt to start the conversation. If there is no user response, * the App re-opens the mic and renders the no-input prompts three times diff --git a/types/actions-on-google/assistant-app.d.ts b/types/actions-on-google/assistant-app.d.ts index caed5cf6cb..58d933baf2 100644 --- a/types/actions-on-google/assistant-app.d.ts +++ b/types/actions-on-google/assistant-app.d.ts @@ -1,9 +1,15 @@ import * as express from 'express'; -import { BasicCard, Carousel, List, OptionItem, RichResponse } from './response-builder'; +import { BasicCard, Carousel, ImageDisplays, List, OptionItem, RichResponse } from './response-builder'; import { ActionPaymentTransactionConfig, Cart, GooglePaymentTransactionConfig, LineItem, Location, Order, OrderUpdate, TransactionDecision, TransactionValues } from './transactions'; +// +// Note: These enums are exported due to limitations with Typescript and this +// library. If you try to import and access them they'll end up null at runtime. +// Either access them through an AssistantApp instance or AssistantApp.prototype. +// + /** * List of standard intents that the app provides. * @actionssdk @@ -36,9 +42,9 @@ export enum StandardIntents { CANCEL, /** App fires NEW_SURFACE intent when requesting handoff to a new surface from user. */ NEW_SURFACE, - /** App fires REGISTER_UPDATE intent when requesting the user to register for proactive updates. */ + /** App fires REGISTER_UPDATE intent when requesting user to register for proactive updates. */ REGISTER_UPDATE, - /** App receives CONFIGURE_UPDATES intent to indicate a custom REGISTER_UPDATE intent should be sent. */ + /** App receives CONFIGURE_UPDATES intent to indicate a REGISTER_UPDATE intent should be sent. */ CONFIGURE_UPDATES } @@ -273,7 +279,10 @@ export interface DeviceLocation { export interface User { /** Random string ID for Google user. */ userId: string; - /** User name information. Null if not requested with {@link AssistantApp#askForPermission|askForPermission(SupportedPermissions.NAME)}. */ + /** + * User name information. Null if not requested with + * {@link AssistantApp#askForPermission|askForPermission(SupportedPermissions.NAME)}. + */ userName: UserName; /** Unique Oauth2 token. Only available with account linking. */ accessToken: string; @@ -303,7 +312,7 @@ export interface Surface { */ export interface Capability { /** Name of the capability. */ - name: string; + name: SurfaceCapabilities; } /** @@ -408,6 +417,11 @@ export class AssistantApp { */ readonly SignInStatus: typeof SignInStatus; + /** + * Values related to supporting {@link ImageDisplays}. + */ + readonly ImageDisplays: typeof ImageDisplays; + /** * Values related to supporting {@link Transactions}. */ @@ -430,11 +444,17 @@ export class AssistantApp { * // Actions SDK * const app = new ActionsSdkApp({request: request, response: response}); * + * 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, 'Hi! ' + - * 'I can read out an ordinal like ' + - * '123. Say a number.', - * ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']); + * const ssml = 'Hi! ' + + * 'I can read out an ordinal like ' + + * '123. Say a number.'; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); * app.ask(inputPrompt); * } * @@ -442,9 +462,9 @@ export class AssistantApp { * if (app.getRawInput() === 'bye') { * app.tell('Goodbye!'); * } else { - * const inputPrompt = app.buildInputPrompt(true, 'You said, ' + - * app.getRawInput() + '', - * ['I didn\'t hear a number', 'If you\'re still there, what\'s the number?', 'What is the number?']); + * const ssml = 'You said, ' + + * app.getRawInput() + ''; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); * app.ask(inputPrompt); * } * } @@ -479,6 +499,87 @@ export class AssistantApp { */ handleRequest(handler: ((app: AssistantApp) => any) | (Map any>)): void; + /** + * Asynchronously handles the incoming Assistant request using a handler or Map of handlers. + * Each handler can be a function callback or Promise. + * + * @example + * // Actions SDK + * const app = new ActionsSdkApp({request: request, response: response}); + * + * 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 ssml = 'Hi! ' + + * 'I can read out an ordinal like ' + + * '123. Say a number.'; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); + * app.ask(inputPrompt); + * } + * + * function rawInput (app) { + * if (app.getRawInput() === 'bye') { + * app.tell('Goodbye!'); + * } else { + * const ssml = 'You said, ' + + * app.getRawInput() + ''; + * const inputPrompt = app.buildInputPrompt(true, ssml, noInputs); + * app.ask(inputPrompt); + * } + * } + * + * const actionMap = new Map(); + * actionMap.set(app.StandardIntents.MAIN, mainIntent); + * actionMap.set(app.StandardIntents.TEXT, rawInput); + * + * app.handleRequestAsync(actionMap) + * .then( + * (result) => { + * // handle the result + * }) + * .catch( + * (reason) => { + * // handle an error + * }); + * + * // Dialogflow + * const app = new DialogflowApp({request: req, response: res}); + * const NAME_ACTION = 'make_name'; + * const COLOR_ARGUMENT = 'color'; + * const NUMBER_ARGUMENT = 'number'; + * + * function makeName (app) { + * const number = app.getArgument(NUMBER_ARGUMENT); + * const color = app.getArgument(COLOR_ARGUMENT); + * app.tell('Alright, your silly name is ' + + * color + ' ' + number + + * '! I hope you like it. See you next time.'); + * } + * + * const actionMap = new Map(); + * actionMap.set(NAME_ACTION, makeName); + * + * app.handleRequestAsync(actionMap) + * .then( + * (result) => { + * // handle the result + * }) + * .catch( + * (reason) => { + * // handle an error + * }); + * + * @param handler The handler (or Map of handlers) for the request. + * @return Promise to resolve the result of the handler that was invoked. + * @actionssdk + * @dialogflow + */ + handleRequestAsync(handler: ((app: AssistantApp) => any) | (Map any>)): Promise; + /** * Equivalent to {@link AssistantApp#askForPermission|askForPermission}, * but allows you to prompt the user for more than one permission at once. @@ -528,8 +629,8 @@ export class AssistantApp { * which comes from AssistantApp.SupportedPermissions. * @param dialogState JSON object the app uses to hold dialog state that * will be circulated back by Assistant. Used in {@link ActionsSdkApp}. - * @return A response is sent to Assistant to ask for the user's permission; for any - * invalid input, we return null. + * @return A response is sent to Assistant to ask for the user's permission. + * For any invalid input, we return null. * @actionssdk * @dialogflow */ @@ -580,8 +681,8 @@ export class AssistantApp { * {@link AssistantApp#getArgument}. * @param dialogState JSON object the app uses to hold dialog state that * will be circulated back by Assistant. Used in {@link ActionsSdkApp}. - * @return A response is sent to Assistant to ask for the user's permission; for any - * invalid input, we return null. + * @return A response is sent to Assistant to ask for the user's permission. + * For any invalid input, we return null. * @actionssdk * @dialogflow */ @@ -679,13 +780,15 @@ export class AssistantApp { * I'll just need to get your name from Google, is that OK?'. * * Once the user accepts or denies the request, the Assistant will fire another intent: - * assistant.intent.action.PERMISSION with a boolean argument: AssistantApp.BuiltInArgNames.PERMISSION_GRANTED + * app.StandardIntents.PERMISSION with a boolean argument: app.BuiltInArgNames.PERMISSION_GRANTED * and, if granted, the information that you requested. * * Read more: * - * * {@link https://developers.google.com/actions/reference/conversation#ExpectedIntent|Supported Permissions} - * * Check if the permission has been granted with {@link AssistantApp#isPermissionGranted|isPermissionsGranted} + * * {@link https://developers.google.com/actions/reference/conversation#ExpectedIntent| + * Supported Permissions} + * * Check if the permission has been granted with + * {@link AssistantApp#isPermissionGranted|isPermissionsGranted} * * {@link AssistantApp#getDeviceLocation|getDeviceLocation} * * {@link AssistantApp#getUserName|getUserName} * @@ -896,6 +999,7 @@ export class AssistantApp { * are set in the {@link https://console.actions.google.com|Actions Console}. * Retrieve the access token in subsequent intents using * app.getUser().accessToken. + * Works only for en-* locales. * * @example * const app = new DialogflowApp({ request, response }); @@ -930,6 +1034,7 @@ export class AssistantApp { /** * Requests the user to switch to another surface during the conversation. + * Works only for en-* locales. * * @example * const app = new DialogflowApp({ request, response }); @@ -1126,41 +1231,6 @@ export class AssistantApp { */ getInputType(): number | string; - /** - * Get the argument value by name from the current intent. - * If the argument is included in originalRequest, and is not a text argument, - * the entire argument object is returned. - * - * Note: If incoming request is using an API version under 2 (e.g. 'v1'), - * the argument object will be in Proto2 format (snake_case, etc). - * - * @example - * const app = new DialogflowApp({request: request, response: response}); - * const WELCOME_INTENT = 'input.welcome'; - * const NUMBER_INTENT = 'input.number'; - * - * function welcomeIntent (app) { - * app.ask('Welcome to action snippets! Say a number.'); - * } - * - * function numberIntent (app) { - * const number = app.getArgument(NUMBER_ARGUMENT); - * app.tell('You said ' + number); - * } - * - * const actionMap = new Map(); - * actionMap.set(WELCOME_INTENT, welcomeIntent); - * actionMap.set(NUMBER_INTENT, numberIntent); - * app.handleRequest(actionMap); - * - * @param argName Name of the argument. - * @return Argument value matching argName - * or null if no matching argument. - * @dialogflow - * @actionssdk - */ - getArgumentCommon(argName: string): object; - /** * Gets transactability of user. Only use after calling * askForTransactionRequirements. Null if no result given. @@ -1258,7 +1328,7 @@ export class AssistantApp { * @dialogflow * @actionssdk */ - getSurfaceCapabilities(): string[]; + getSurfaceCapabilities(): SurfaceCapabilities[]; /** * Returns the set of other available surfaces for the user. diff --git a/types/actions-on-google/dialogflow-app.d.ts b/types/actions-on-google/dialogflow-app.d.ts index ab768241c2..4eeda87e06 100644 --- a/types/actions-on-google/dialogflow-app.d.ts +++ b/types/actions-on-google/dialogflow-app.d.ts @@ -36,7 +36,8 @@ export interface DialogflowAppOptions { } /** - * 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. */ export class DialogflowApp extends AssistantApp { /** diff --git a/types/actions-on-google/index.d.ts b/types/actions-on-google/index.d.ts index 378604411f..23a2c1483d 100644 --- a/types/actions-on-google/index.d.ts +++ b/types/actions-on-google/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for actions-on-google 1.6 +// Type definitions for actions-on-google 1.7 // Project: https://github.com/actions-on-google/actions-on-google-nodejs // Definitions by: Joel Hegg // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/types/actions-on-google/response-builder.d.ts b/types/actions-on-google/response-builder.d.ts index 5b6e3d7522..4ebb9b3007 100644 --- a/types/actions-on-google/response-builder.d.ts +++ b/types/actions-on-google/response-builder.d.ts @@ -4,6 +4,27 @@ import { OrderUpdate } from './transactions'; +/** + * 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. + */ +export enum ImageDisplays { + /** + * Pads the gaps between the image and image frame with a blurred copy of the + * same image. + */ + DEFAULT, + /** + * Fill the gap between the image and image container with white bars. + */ + WHITE, + /** + * Image is centered and resized so the image fits perfectly in the container. + */ + CROPPED +} + /** * Simple Response type. */ @@ -74,19 +95,19 @@ export interface StructuredResponse { orderUpdate: OrderUpdate; } -export interface RichResponseItemBasicCard { +export interface ItemBasicCard { basicCard: BasicCard; } -export interface RichResponseItemSimpleResponse { +export interface ItemSimpleResponse { simpleResponse: SimpleResponse; } -export interface RichResponseItemStructuredResponse { +export interface ItemStructuredResponse { structuredResponse: StructuredResponse; } -export type RichResponseItem = RichResponseItemBasicCard | RichResponseItemSimpleResponse | RichResponseItemStructuredResponse; +export type RichResponseItem = ItemBasicCard | ItemSimpleResponse | ItemStructuredResponse; /** * Class for initializing and constructing Rich Responses with chainable interface. @@ -150,7 +171,8 @@ export class RichResponse { isValidSuggestionText(suggestionText: string): boolean; /** - * 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). * * @param destinationName Name of the link out destination. * @param suggestionUrl - String URL to open when suggestion is used. @@ -240,6 +262,16 @@ export class BasicCard { */ setImage(url: string, accessibilityText: string, width?: number, height?: number): BasicCard; + /** + * Sets the display options for the image in this Basic Card. + * Use one of the image display constants. If none is chosen, + * ImageDisplays.DEFAULT will be enforced. + * + * @param option The option for displaying the image. + * @return Returns current constructed BasicCard. + */ + setImageDisplay(option: ImageDisplays): BasicCard; + /** * Adds a button below card. * @@ -402,3 +434,10 @@ export class OptionItem { * @return True if text contains SSML, false otherwise. */ export function isSsml(text: string): boolean; + +/** + * Check if given text contains SSML, allowing for whitespace padding. + * @param text Text to check. + * @return True if text contains possibly whitespace padded SSML, false otherwise. + */ +export function isPaddedSsml(text: string): boolean; diff --git a/types/actions-on-google/transactions.d.ts b/types/actions-on-google/transactions.d.ts index b4a4285fe9..59e6cd9b37 100644 --- a/types/actions-on-google/transactions.d.ts +++ b/types/actions-on-google/transactions.d.ts @@ -10,7 +10,7 @@ import { Image } from './response-builder'; */ export interface Price { /** One of Transaction.PriceType. */ - type: PriceType; + type: TransactionValues.PriceType; amount: { /** Currency code of price. */ currencyCode: string; @@ -26,7 +26,7 @@ export interface Price { */ export interface RejectionInfo { /** One of Transaction.ReasonType. */ - type: ReasonType; + type: TransactionValues.ReasonType; /** Reason for the order rejection. */ reason: string; } @@ -79,7 +79,7 @@ export interface ActionPaymentTransactionConfig { /** True if delivery address is required for the transaction. */ deliveryAddressRequired: boolean; /** One of Transactions.PaymentType. */ - type: PaymentType; + type: TransactionValues.PaymentType; /** The name of the instrument displayed on receipt. For example, for card payment, could be "VISA-1234". */ displayName: string; customerInfoOptions?: CustomerInfoOptions; @@ -95,9 +95,11 @@ export interface GooglePaymentTransactionConfig { /** Tokenization parameters provided by payment gateway. */ tokenizationParameters: object; /** List of accepted card networks. Must be any number of Transactions.CardNetwork. */ - cardNetworks: CardNetwork[]; + cardNetworks: TransactionValues.CardNetwork[]; /** True if prepaid cards are not allowed for transaction. */ prepaidCardDisallowed: boolean; + /** The type of tokenization. Default is {@see TransactionValues.PaymentMethodTokenizationType.PAYMENT_GATEWAY}. */ + tokenizationType: string; customerInfoOptions?: CustomerInfoOptions; } @@ -130,10 +132,10 @@ export interface Location { */ export interface TransactionDecision { /** One of Transactions.ConfirmationDecision. */ - userDecision: TransactionUserDecision; + userDecision: TransactionValues.TransactionUserDecision; checkResult: { /** One of Transactions.ResultType. */ - resultType: ResultType; + resultType: TransactionValues.ResultType; }; order: { /** The proposed order used in the transaction decision. */ @@ -162,490 +164,438 @@ export interface TransactionDecision { /** * Values related to supporting transactions */ -export const TransactionValues: { - /** List of transaction card networks available when paying with Google. */ - readonly CardNetwork: typeof CardNetwork; +export namespace TransactionValues { + /** + * List of transaction card networks available when paying with Google. + */ + enum CardNetwork { + /** + * Unspecified. + */ + UNSPECIFIED, + /** + * American Express. + */ + AMEX, + /** + * Discover. + */ + DISCOVER, + /** + * Master Card. + */ + MASTERCARD, + /** + * Visa. + */ + VISA, + /** + * JCB. + */ + JCB + } + /** * List of possible item types. * @deprecated Use {@link TransactionValues.LineItemType} instead. */ - readonly ItemType: typeof LineItemType; - /** List of possible item types. */ - readonly LineItemType: typeof LineItemType; - /** List of price types. */ - readonly PriceType: typeof PriceType; - /** List of possible item types. */ - readonly PaymentType: typeof PaymentType; - /** List of customer information properties that can be requested. */ - readonly CustomerInfoProperties: typeof CustomerInfoProperties; + // tslint:disable-next-line: strict-export-declare-modifiers + export import ItemType = LineItemType; + + /** + * List of possible item types. + */ + enum LineItemType { + /** + * Unspecified. + */ + UNSPECIFIED, + /** + * Regular. + */ + REGULAR, + /** + * Tax. + */ + TAX, + /** + * Discount + */ + DISCOUNT, + /** + * Gratuity + */ + GRATUITY, + /** + * Delivery + */ + DELIVERY, + /** + * Subtotal + */ + SUBTOTAL, + /** + * Fee. For everything else, there's fee. + */ + FEE + } + + /** + * List of price types. + */ + enum PriceType { + /** + * Unknown. + */ + UNKNOWN, + /** + * Estimate. + */ + ESTIMATE, + /** + * Actual. + */ + ACTUAL + } + + /** + * List of possible item types. + */ + enum PaymentType { + /** + * Unspecified. + */ + UNSPECIFIED, + /** + * Payment card. + */ + PAYMENT_CARD, + /** + * Bank. + */ + BANK, + /** + * Loyalty program. + */ + LOYALTY_PROGRAM, + /** + * On order fulfillment, such as cash on delivery. + */ + ON_FULFILLMENT, + /** + * Gift card. + */ + GIFT_CARD + } + + /** + * List of customer information properties that can be requested. + */ + enum CustomerInfoProperties { + CUSTOMER_INFO_PROPERTY_UNSPECIFIED, + EMAIL + } + /** * List of possible order confirmation user decisions * @deprecated Use {@link TransactionValues.TransactionUserDecision} instead. */ - readonly ConfirmationDecision: typeof TransactionUserDecision; - /** List of possible order confirmation user decisions */ - readonly TransactionUserDecision: typeof TransactionUserDecision; - /** List of possible order states. */ - readonly OrderState: typeof OrderState; + // tslint:disable-next-line: strict-export-declare-modifiers + export import ConfirmationDecision = TransactionUserDecision; + + /** + * List of possible order confirmation user decisions + */ + enum TransactionUserDecision { + /** + * Unspecified user decision. + */ + UNKNOWN_USER_DECISION, + /** + * Order was approved by user. + */ + ACCEPTED, + /** + * Order was declined by user. + */ + REJECTED, + /** + * Order was not declined, but the delivery address was updated during + * confirmation. + */ + DELIVERY_ADDRESS_UPDATED, + /** + * Order was not declined, but the cart was updated during confirmation. + */ + CART_CHANGE_REQUESTED + } + + /** + * List of possible order states. + */ + enum OrderState { + /** + * Order was created at the integrator's system. + */ + CREATED, + /** + * Order was rejected. + */ + REJECTED, + /** + * Order was confirmed by integrator and is active. + */ + CONFIRMED, + /** + * User cancelled the order. + */ + CANCELLED, + /** + * Order is being delivered. + */ + IN_TRANSIT, + /** + * User performed a return. + */ + RETURNED, + /** + * User received what was ordered. + */ + FULFILLED + } + /** * List of possible actions to take on the order. * @deprecated Use {@link TransactionValues.ActionType} instead. */ - readonly OrderAction: typeof ActionType; - /** List of possible actions to take on the order. */ - readonly ActionType: typeof ActionType; + // tslint:disable-next-line: strict-export-declare-modifiers + export import OrderAction = ActionType; + + /** + * List of possible actions to take on the order. + */ + enum ActionType { + /** + * Unknown action. + */ + UNKNOWN, + /** + * View details. + */ + VIEW_DETAILS, + /** + * Modify order. + */ + MODIFY, + /** + * Cancel order. + */ + CANCEL, + /** + * Return order. + */ + RETURN, + /** + * Exchange order. + */ + EXCHANGE, + /** + * Email. + */ + EMAIL, + /** + * Call. + */ + CALL, + /** + * Reorder. + */ + REORDER, + /** + * Review. + */ + REVIEW, + /** + * Customer Service. + */ + CUSTOMER_SERVICE + } + /** * List of possible types of order rejection. * @deprecated Use {@link TransactionValues.ReasonType} instead. */ - readonly RejectionType: typeof ReasonType; - /** List of possible types of order rejection. */ - readonly ReasonType: typeof ReasonType; - /** List of possible order state objects. */ - readonly OrderStateInfo: typeof OrderStateInfo; - /** List of possible order transaction requirements check result types. */ - readonly ResultType: typeof ResultType; - /** List of possible user decisions to give delivery address. */ - readonly DeliveryAddressDecision: typeof DeliveryAddressUserDecision; - /** List of possible user decisions to give delivery address. */ - readonly DeliveryAddressUserDecision: typeof DeliveryAddressUserDecision; + // tslint:disable-next-line: strict-export-declare-modifiers + export import RejectionType = ReasonType; + + /** + * List of possible types of order rejection. + */ + enum ReasonType { + /** + * Unknown + */ + UNKNOWN, + /** + * Payment was declined. + */ + PAYMENT_DECLINED + } + + /** + * List of possible order state objects. + */ + enum OrderStateInfo { + /** + * Information about order rejection. Used with {@link RejectionInfo}. + */ + REJECTION, + /** + * Information about order receipt. Used with {@link ReceiptInfo}. + */ + RECEIPT, + /** + * Information about order cancellation. Used with {@link CancellationInfo}. + */ + CANCELLATION, + /** + * Information about in-transit order. Used with {@link TransitInfo}. + */ + IN_TRANSIT, + /** + * Information about order fulfillment. Used with {@link FulfillmentInfo}. + */ + FULFILLMENT, + /** + * Information about order return. Used with {@link ReturnInfo}. + */ + RETURN + } + + /** + * List of possible order transaction requirements check result types. + */ + enum ResultType { + /** + * Unspecified. + */ + UNSPECIFIED, + /** + * OK to continue transaction. + */ + OK, + /** + * User is expected to take action, e.g. enable payments, to continue + * transaction. + */ + USER_ACTION_REQUIRED, + /** + * Transactions are not supported on current device/surface. + */ + ASSISTANT_SURFACE_NOT_SUPPORTED, + /** + * Transactions are not supported for current region/country. + */ + REGION_NOT_SUPPORTED + } + + /** + * List of possible user decisions to give delivery address. + * @deprecated Use {@link TransactionValues.DeliveryAddressUserDecision} instead. + */ + // tslint:disable-next-line: strict-export-declare-modifiers + export import DeliveryAddressDecision = DeliveryAddressUserDecision; + + /** + * List of possible user decisions to give delivery address. + */ + enum DeliveryAddressUserDecision { + /** + * Unknown. + */ + UNKNOWN, + /** + * User granted delivery address. + */ + ACCEPTED, + /** + * User denied to give delivery address. + */ + REJECTED + } + /** * List of possible order location types. * @deprecated Use {@link TransactionValues.OrderLocationType} instead. */ - readonly LocationType: typeof OrderLocationType; - /** List of possible order location types. */ - readonly OrderLocationType: typeof OrderLocationType; - /** List of possible order time types. */ - readonly TimeType: typeof TimeType; - /** List of possible tokenization types for the payment method */ - readonly PaymentMethodTokenizationType: typeof PaymentMethodTokenizationType; -}; + // tslint:disable-next-line: strict-export-declare-modifiers + export import LocationType = OrderLocationType; -/** - * List of transaction card networks available when paying with Google. - */ -export enum CardNetwork { /** - * Unspecified. + * List of possible order location types. */ - UNSPECIFIED, - /** - * American Express. - */ - AMEX, - /** - * Discover. - */ - DISCOVER, - /** - * Master Card. - */ - MASTERCARD, - /** - * Visa. - */ - VISA, - /** - * JCB. - */ - JCB -} + enum OrderLocationType { + /** + * Unknown. + */ + UNKNOWN, + /** + * Delivery location for an order. + */ + DELIVERY, + /** + * Business location of order provider. + */ + BUSINESS, + /** + * Origin of the order. + */ + ORIGIN, + /** + * Destination of the order. + */ + DESTINATION, + /** + * Pick up location of the order. + */ + PICK_UP + } -/** - * List of possible item types. - * @deprecated Use {@link TransactionValues.LineItemType} instead. - */ -export type ItemType = LineItemType; + /** + * List of possible order time types. + */ + enum TimeType { + /** + * Unknown. + */ + UNKNOWN, + /** + * Date of delivery for the order. + */ + DELIVERY_DATE, + /** + * Estimated Time of Arrival for order. + */ + ETA, + /** + * Reservation time. + */ + RESERVATION_SLOT + } -/** - * List of possible item types. - */ -export enum LineItemType { /** - * Unspecified. - */ - UNSPECIFIED, - /** - * Regular. - */ - REGULAR, - /** - * Tax. - */ - TAX, - /** - * Discount - */ - DISCOUNT, - /** - * Gratuity - */ - GRATUITY, - /** - * Delivery - */ - DELIVERY, - /** - * Subtotal - */ - SUBTOTAL, - /** - * Fee. For everything else, there's fee. - */ - FEE -} - -/** - * List of price types. - */ -export enum PriceType { - /** - * Unknown. - */ - UNKNOWN, - /** - * Estimate. - */ - ESTIMATE, - /** - * Actual. - */ - ACTUAL -} - -/** - * List of possible item types. - */ -export enum PaymentType { - /** - * Unspecified. - */ - UNSPECIFIED, - /** - * Payment card. - */ - PAYMENT_CARD, - /** - * Bank. - */ - BANK, - /** - * Loyalty program. - */ - LOYALTY_PROGRAM, - /** - * On order fulfillment, such as cash on delivery. - */ - ON_FULFILLMENT, - /** - * Gift card. - */ - GIFT_CARD -} - -/** - * List of customer information properties that can be requested. - */ -export enum CustomerInfoProperties { - CUSTOMER_INFO_PROPERTY_UNSPECIFIED, - EMAIL -} - -/** - * List of possible order confirmation user decisions - * @deprecated Use {@link TransactionValues.TransactionUserDecision} instead. - */ -export type ConfirmationDecision = TransactionUserDecision; - -/** - * List of possible order confirmation user decisions - */ -export enum TransactionUserDecision { - /** - * Unspecified user decision. - */ - UNKNOWN_USER_DECISION, - /** - * Order was approved by user. - */ - ACCEPTED, - /** - * Order was declined by user. - */ - REJECTED, - /** - * Order was not declined, but the delivery address was updated during - * confirmation. - */ - DELIVERY_ADDRESS_UPDATED, - /** - * Order was not declined, but the cart was updated during confirmation. - */ - CART_CHANGE_REQUESTED -} - -/** - * List of possible order states. - */ -export enum OrderState { - /** - * Order was created at the integrator's system. - */ - CREATED, - /** - * Order was rejected. - */ - REJECTED, - /** - * Order was confirmed by integrator and is active. - */ - CONFIRMED, - /** - * User cancelled the order. - */ - CANCELLED, - /** - * Order is being delivered. - */ - IN_TRANSIT, - /** - * User performed a return. - */ - RETURNED, - /** - * User received what was ordered. - */ - FULFILLED -} - -/** - * List of possible actions to take on the order. - * @deprecated Use {@link TransactionValues.ActionType} instead. - */ -export type OrderAction = ActionType; - -/** - * List of possible actions to take on the order. - */ -export enum ActionType { - /** - * Unknown action. - */ - UNKNOWN, - /** - * View details. - */ - VIEW_DETAILS, - /** - * Modify order. - */ - MODIFY, - /** - * Cancel order. - */ - CANCEL, - /** - * Return order. - */ - RETURN, - /** - * Exchange order. - */ - EXCHANGE, - /** - * Email. - */ - EMAIL, - /** - * Call. - */ - CALL, - /** - * Reorder. - */ - REORDER, - /** - * Review. - */ - REVIEW, - /** - * Customer Service. - */ - CUSTOMER_SERVICE -} - -/** - * List of possible types of order rejection. - * @deprecated Use {@link TransactionValues.ReasonType} instead. - */ -export type RejectionType = ReasonType; - -/** - * List of possible types of order rejection. - */ -export enum ReasonType { - /** - * Unknown - */ - UNKNOWN, - /** - * Payment was declined. - */ - PAYMENT_DECLINED -} - -/** - * List of possible order state objects. - */ -export enum OrderStateInfo { - /** - * Information about order rejection. Used with {@link RejectionInfo}. - */ - REJECTION, - /** - * Information about order receipt. Used with {@link ReceiptInfo}. - */ - RECEIPT, - /** - * Information about order cancellation. Used with {@link CancellationInfo}. - */ - CANCELLATION, - /** - * Information about in-transit order. Used with {@link TransitInfo}. - */ - IN_TRANSIT, - /** - * Information about order fulfillment. Used with {@link FulfillmentInfo}. - */ - FULFILLMENT, - /** - * Information about order return. Used with {@link ReturnInfo}. - */ - RETURN -} - -/** - * List of possible order transaction requirements check result types. - */ -export enum ResultType { - /** - * Unspecified. - */ - UNSPECIFIED, - /** - * OK to continue transaction. - */ - OK, - /** - * User is expected to take action, e.g. enable payments, to continue - * transaction. - */ - USER_ACTION_REQUIRED, - /** - * Transactions are not supported on current device/surface. - */ - ASSISTANT_SURFACE_NOT_SUPPORTED, - /** - * Transactions are not supported for current region/country. - */ - REGION_NOT_SUPPORTED -} - -/** - * List of possible user decisions to give delivery address. - * @deprecated Use {@link TransactionValues.DeliveryAddressUserDecision} instead. - */ -export type DeliveryAddressDecision = DeliveryAddressUserDecision; - -/** - * List of possible user decisions to give delivery address. - */ -export enum DeliveryAddressUserDecision { - /** - * Unknown. - */ - UNKNOWN, - /** - * User granted delivery address. - */ - ACCEPTED, - /** - * User denied to give delivery address. - */ - REJECTED -} - -/** - * List of possible order location types. - * @deprecated Use {@link TransactionValues.OrderLocationType} instead. - */ -export type LocationType = OrderLocationType; - -/** - * List of possible order location types. - */ -export enum OrderLocationType { - /** - * Unknown. - */ - UNKNOWN, - /** - * Delivery location for an order. - */ - DELIVERY, - /** - * Business location of order provider. - */ - BUSINESS, - /** - * Origin of the order. - */ - ORIGIN, - /** - * Destination of the order. - */ - DESTINATION, - /** - * Pick up location of the order. - */ - PICK_UP -} - -/** - * List of possible order time types. - */ -export enum TimeType { - /** - * Unknown. - */ - UNKNOWN, - /** - * Date of delivery for the order. - */ - DELIVERY_DATE, - /** - * Estimated Time of Arrival for order. - */ - ETA, - /** - * Reservation time. - */ - RESERVATION_SLOT -} - -/** - * List of possible tokenization types for the payment method - */ -export enum PaymentMethodTokenizationType { - /** - * Unspecified tokenization type. - */ - UNSPECIFIED_TOKENIZATION_TYPE, - /** - * Use external payment gateway tokenization API to tokenize selected payment method. - */ - PAYMENT_GATEWAY + * List of possible tokenization types for the payment method + */ + enum PaymentMethodTokenizationType { + /** + * Unspecified tokenization type. + */ + UNSPECIFIED_TOKENIZATION_TYPE, + /** + * Use external payment gateway tokenization API to tokenize selected payment method. + */ + PAYMENT_GATEWAY + } } /** @@ -740,7 +690,7 @@ export class Order { * @param nanos Partial unit count of price. * @return Returns current constructed Order. */ - setTotalPrice(priceType: PriceType, currencyCode: string, units: number, nanos?: number): Order; + setTotalPrice(priceType: TransactionValues.PriceType, currencyCode: string, units: number, nanos?: number): Order; /** * Adds an associated location to the order. Up to 2 locations can be added. @@ -749,7 +699,7 @@ export class Order { * @param location Location to add. * @return Returns current constructed Order. */ - addLocation(type: OrderLocationType, location: Location): Order; + addLocation(type: TransactionValues.OrderLocationType, location: Location): Order; /** * Sets an associated time to the order. @@ -759,7 +709,7 @@ export class Order { * of time value. Could be date, datetime, or duration. * @return Returns current constructed Order. */ - setTime(type: TimeType, time: string): Order; + setTime(type: TransactionValues.TimeType, time: string): Order; } /** @@ -872,7 +822,7 @@ export class LineItem { /** * Type of the item. One of TransactionValues.LineItemType. */ - type?: LineItemType; + type?: TransactionValues.LineItemType; /** * Quantity of the item. @@ -919,7 +869,7 @@ export class LineItem { * @param nanos Partial unit count of price. * @return Returns current constructed LineItem. */ - setPrice(priceType: PriceType, currencyCode: string, units: number, nanos?: number): LineItem; + setPrice(priceType: TransactionValues.PriceType, currencyCode: string, units: number, nanos?: number): LineItem; /** * Set the type of the item. @@ -927,7 +877,7 @@ export class LineItem { * @param type Type of the item. One of TransactionValues.LineItemType. * @return Returns current constructed LineItem. */ - setType(type: LineItemType): LineItem; + setType(type: TransactionValues.LineItemType): LineItem; /** * Set the quantity of the item. @@ -1030,7 +980,7 @@ export class OrderUpdate { * @param label Label for the order state. * @return Returns current constructed OrderUpdate. */ - setOrderState(state: OrderState, label: string): OrderUpdate; + setOrderState(state: TransactionValues.OrderState, label: string): OrderUpdate; /** * Set the update time of the order. @@ -1059,7 +1009,7 @@ export class OrderUpdate { * @param nanos Partial unit count of price. * @return Returns current constructed OrderUpdate. */ - setTotalPrice(priceType: PriceType, currencyCode: string, units: number, nanos?: number): OrderUpdate; + setTotalPrice(priceType: TransactionValues.PriceType, currencyCode: string, units: number, nanos?: number): OrderUpdate; /** * Adds an actionable item for the user to manage the order. @@ -1069,7 +1019,7 @@ export class OrderUpdate { * @param url URL to open when button is clicked. * @return Returns current constructed OrderUpdate. */ - addOrderManagementAction(type: ActionType, label: string, url: string): OrderUpdate; + addOrderManagementAction(type: TransactionValues.ActionType, label: string, url: string): OrderUpdate; /** * Adds a single price update for a particular line item in the order. @@ -1084,7 +1034,7 @@ export class OrderUpdate { * addLineItemStateUpdate. * @return Returns current constructed OrderUpdate. */ - addLineItemPriceUpdate(itemId: string, priceType: PriceType, currencyCode: string, units: number, nanos?: number, reason?: string): OrderUpdate; + addLineItemPriceUpdate(itemId: string, priceType: TransactionValues.PriceType, currencyCode: string, units: number, nanos?: number, reason?: string): OrderUpdate; /** * Adds a single state update for a particular line item in the order. @@ -1096,7 +1046,7 @@ export class OrderUpdate { * any reason given in addLineitemPriceUpdate. * @return Returns current constructed OrderUpdate. */ - addLineItemStateUpdate(itemId: string, state: OrderState, label: string, reason?: string): OrderUpdate; + addLineItemStateUpdate(itemId: string, state: TransactionValues.OrderState, label: string, reason?: string): OrderUpdate; /** * Sets some extra information about the order. Takes an order update info