diff --git a/types/alexa-sdk/index.d.ts b/types/alexa-sdk/index.d.ts index 02def0b4d6..56278df11c 100644 --- a/types/alexa-sdk/index.d.ts +++ b/types/alexa-sdk/index.d.ts @@ -1,14 +1,15 @@ -// Type definitions for Alexa SDK for Node.js 1.0 +// Type definitions for Alexa SDK for Node.js 1.1 // Project: https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs // Definitions by: Pete Beegle // Huw // pascalwhoop // Ben // rk-7 +// Alex Malcoci // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 -export function handler(event: RequestBody, context: Context, callback?: (err: any, response: any) => void): AlexaObject; +export function handler(event: RequestBody, context: Context, callback?: (err: any, response: any) => void): AlexaObject; export function CreateStateHandler(state: string, obj: any): any; export let StateString: string; export type ConfirmationStatuses = "NONE" | "DENIED" | "CONFIRMED"; @@ -23,6 +24,8 @@ export type CardType = "Standard" | "Simple" | "LinkAccount" | "AskForPermission export type HintType = "PlainText"; export type DirectiveTypes = "AudioPlayer.Play" | "AudioPlayer.Stop" | "AudioPlayer.ClearQueue" | "Display.RenderTemplate" | "Hint" | "VideoApp.Launch"; export type TextContentType = "PlainText" | "RichText"; +export type MediaErrorType = "MEDIA_ERROR_UNKNOWN" | "MEDIA_ERROR_INVALID_REQUEST" | "MEDIA_ERROR_SERVICE_UNAVAILABLE" | "MEDIA_ERROR_INTERNAL_SERVER_ERROR" | "MEDIA_ERROR_INTERNAL_DEVICE_ERROR"; +export type SystemErrorType = "INVALID_RESPONSE" | "DEVICE_COMMUNICATION_ERROR" | "INTERNAL_ERROR"; //#region Types export interface CardImage { @@ -84,7 +87,7 @@ export interface Template { listItems?: ListItem[]; } -export interface AlexaObject extends Handler { +export interface AlexaObject extends Handler { _event: any; _context: any; _callback: any; @@ -98,11 +101,11 @@ export interface AlexaObject extends Handler { execute: () => void; } -export interface Handlers { +export interface Handlers { [intent: string]: (this: Handler) => void; } -export interface Handler { +export interface Handler { on: any; emit(event: string, ...args: any[]): boolean; emitWithState: any; @@ -141,7 +144,7 @@ export interface System { apiEndpoint: string; application: Application; device: any; - user: any; + user: SessionUser; } export interface AudioPlayer { token: string; @@ -151,10 +154,32 @@ export interface AudioPlayer { */ playerActivity: AudioPlayerActivity; } -export interface RequestBody { + +export interface Display { + token: string; +} + +export interface Device { + deviceId: string; + supportedInterfaces: DeviceInterfaces; +} + +export interface DeviceInterfaces { + AudioPlayer: any; + Display: any; +} + +export interface RequestContext { + AudioPlayer?: AudioPlayer; + Display?: Display; + System: System; +} + +export interface RequestBody { version: string; session: Session; request: T; + context: RequestContext; } export interface Session { @@ -187,8 +212,94 @@ export interface SessionEndedRequest extends Request { reason?: string; } +export interface AudioPlayerPlaybackRequest extends Request { + token: string; + offsetInMilliseconds: number; +} + +export interface AudioPlayerPlaybackFailedRequest extends Request { + token: string; + error: MediaError; + currentPlaybackState: AudioPlayer; +} + +export interface MediaError { + type: MediaErrorType; + message: string; +} + +export interface SystemExceptionEncounteredRequest extends Request { + error: SystemError; + cause: ErrorCause; +} + +export interface SystemError { + type: SystemErrorType; + message: string; +} + +export interface ErrorCause { + requestId: string; +} + +export interface SkillAccountRequest extends Request { + body: SkillAccountBody; +} + +export interface SkillAccountBody { + accessToken: string; +} + +export interface SkillPermissionRequest extends Request { + body: SkillPermissionBody; +} + +export interface SkillPermissionBody { + acceptedPermissions: PermissionScope[]; +} + +export interface PermissionScope { + scope: string; +} + +export interface ListEventRequest extends Request { + body: ListEventBody; +} + +export interface ListEventBody { + listId: string; + listItemIds?: string[]; +} + export interface Request { - type: "LaunchRequest" | "IntentRequest" | "SessionEndedRequest"; + type: "LaunchRequest" + | "IntentRequest" + | "SessionEndedRequest" + + | "System.ExceptionEncountered" + + | "AudioPlayer.PlaybackStarted" + | "AudioPlayer.PlaybackFinished" + | "AudioPlayer.PlaybackStopped" + | "AudioPlayer.PlaybackNearlyFinished" + + | "PlaybackController.NextCommandIssued" + | "PlaybackController.PauseCommandIssued" + | "PlaybackController.PlayCommandIssued" + | "PlaybackController.PreviousCommandIssued" + + | "AlexaSkillEvent.SkillAccountLinked" + | "AlexaSkillEvent.SkillEnabled" + | "AlexaSkillEvent.SkillDisabled" + | "AlexaSkillEvent.SkillPermissionAccepted" + | "AlexaSkillEvent.SkillPermissionChanged" + + | "AlexaHouseholdListEvent.ListCreated" + | "AlexaHouseholdListEvent.ListUpdated" + | "AlexaHouseholdListEvent.ListDeleted" + | "AlexaHouseholdListEvent.ItemsCreated" + | "AlexaHouseholdListEvent.ItemsUpdated" + | "AlexaHouseholdListEvent.ItemsDeleted"; requestId: string; timestamp: string; locale?: string; @@ -296,7 +407,7 @@ export interface ListItemObject { /** * item version (Positive integer) */ - version?: number | string; + version: number; /** * created time (ISO 8601 time format with time zone) */ @@ -348,6 +459,38 @@ export interface ListObject { * Items that belong to this list. */ items: ListItemObject[]; + + next?: ListLinks; +} + +export interface ListLinks { + next: string; +} + +export interface ListCollection { + lists: ListObject[]; +} + +export interface CreateListParams { + name: string; + state: "active"; +} + +export interface UpdateListParams { + name: string; + state: ListObjectState; + version: number; +} + +export interface CreateListItemParams { + value: string; + status: ListItemObjectStatus; +} + +export interface UpdateListItemParams { + value: string; + status: ListItemObjectStatus; + version: number; } //#endregion @@ -545,7 +688,7 @@ export namespace templateBuilders { //#region services export namespace services { - interface ApiClient { + class ApiClient { /** * Make a POST API call to the specified uri with headers and optional body * @param uri http(s?) endpoint to call @@ -582,7 +725,7 @@ export namespace services { * Create an instance of DeviceAddressService * @param [apiClient=new ApiClient()] ApiClient */ - constructor(apiClient: ApiClient); + constructor(apiClient?: ApiClient); /** * Get full address information from Alexa Device Address API @@ -607,7 +750,7 @@ export namespace services { * Creates an instance of DirectiveService. * @param [apiClient=new ApiClient()] ApiClient */ - constructor(apiClient: ApiClient); + constructor(apiClient?: ApiClient); /** * Send the specified directiveObj to Alexa directive service @@ -624,7 +767,7 @@ export namespace services { * Create an instance of ListManagementService * @param apiClient apiClient */ - constructor(apiClient: ApiClient); + constructor(apiClient?: ApiClient); /** * Set apiEndpoint address, default is "https://api.amazonalexa.com" @@ -642,80 +785,80 @@ export namespace services { /** * Retrieve the metadata for all customer lists, including the customer's default lists * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - getListsMetadata(token: string): Promise; + getListsMetadata(token: string): Promise; /** * Create a custom list. The new list name must be different than any existing list name - * @param listObject listObject + * @param params params * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - createList(listObject: ListObject, token: string): Promise; + createList(params: CreateListParams, token: string): Promise; /** * Retrieve list metadata including the items in the list with requested status * @param listId unique Id associated with the list * @param itemStatus itemsStatus can be either "active" or "completed" * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - getList(listId: string, itemStatus: ListItemObjectStatus, token: string): Promise; + getList(listId: string, itemStatus: ListItemObjectStatus, token: string): Promise; /** * Update a custom list. Only the list name or state can be updated * @param listId unique Id associated with the list - * @param listObject listObject + * @param params params * @param token bearer token for list management permission * @returns Promise */ - updateList(listId: string, listObject: ListObject, token: string): Promise; + updateList(listId: string, params: UpdateListParams, token: string): Promise; /** * Delete a custom list * @param listId unique Id associated with the list * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - deleteList(listId: string, token: string): Promise; + deleteList(listId: string, token: string): Promise; /** * Create an item in an active list or in a default list * @param listId unique Id associated with the list - * @param listItemObject listItemObject + * @param params params * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - createListItem(listId: string, listItemObject: ListItemObject, token: string): Promise; + createListItem(listId: string, params: CreateListItemParams, token: string): Promise; /** * Retrieve single item within any list by listId and itemId * @param listId unique Id associated with the list * @param itemId unique Id associated with the item * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - getListItem(listId: string, itemId: string, token: string): Promise; + getListItem(listId: string, itemId: string, token: string): Promise; /** * Update an item value or item status * @param listId unique Id associated with the list * @param itemId unique Id associated with the item - * @param listItemObject listItemObject + * @param params params * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - updateListItem(listId: string, itemId: string, listItemObject: ListItemObject, token: string): Promise; + updateListItem(listId: string, itemId: string, params: UpdateListItemParams, token: string): Promise; /** * Delete an item in the specified list * @param listId unique Id associated with the list * @param itemId unique Id associated with the item * @param token bearer token for list management permission - * @returns Promise + * @returns Promise */ - deleteListItem(listId: string, itemId: string, token: string): Promise; + deleteListItem(listId: string, itemId: string, token: string): Promise; } } //#endregion