UNPKG

@jargon/platform-sdk-core

Version:

Core components of the Jargon Platform SDK for node.js

88 lines (87 loc) 3.58 kB
/// <reference types="node" /> import * as https from 'https'; import { ItemType, Platform, RenderItem, RenderParams, RenderResult, RenderStatus, ResourceManager, ResponseVariant, SelectedVariation, TypedRenderItem } from '..'; import { AlexaCard, GoogleCard, GoogleSuggestion } from '../defs'; /** Production Jargon endpoints */ export declare const JargonEndpoints: { 'aws-us-east-1': string; 'aws-eu-west-1': string; 'aws-ap-northeast-1': string; }; /** Jargon development endpoints - not for public use */ export declare const JargonDevEndpoints: { 'dev-aws-us-east-1': string; }; export interface JargonRemoteResourceManagerOptions { /** The Jargon Project ID you're requesting content for */ projectId: string; /** The content interface ID you're requesting content for. You can find this in the release * details for your deployment */ contentInterfaceId: string; /** An environment tag associated with the the content you're requesting. Note that an empty * string ('') corresponds to a deployment with no associated tags */ tag: string; /** The endpoint to connect to. Should come from JargonEndpoints */ endpoint: string; /** If true, timing information for remote calls will be logged via logFunc */ logTimings?: boolean; /** The function to use for logging. If not provided, console.log will be used */ logFunc?: (msg: string) => any; } export interface ContentItem { type: ContentType; key: string; params?: ContentParams; } export declare type ContentType = 'unknown' | 'object' | 'response' | 'string'; export interface ContentParams { [param: string]: ContentParamVal; } export interface ContentParamVal { stringVal?: string | number; itemVal?: ContentItem; } export interface GetContentResponseV1 { items: ResponseItemV1[]; } export interface ResponseItemV1 { key: string; type: ItemType; status: RenderStatus; stringVal?: string; responseVal?: ResponseBundle; objectVal?: string; } export interface ResponseBundle { speech?: string; reprompt?: string; alexaCard?: AlexaCard; alexaDirectives?: Record<string, object>; googleCard?: GoogleCard; googleSuggestions?: GoogleSuggestion[]; } export declare class JargonRemoteResourceManager implements ResourceManager { readonly locale: string; protected readonly _platform: Platform; protected readonly _agent: https.Agent; protected readonly _contentInterfaceId: string; protected readonly _endpoint: string; protected readonly _projectId: string; protected readonly _tag: string; protected readonly _logTimings: boolean; protected readonly _logFunc: (msg: string) => any; constructor(locale: string, _platform: Platform, _agent: https.Agent, options: JargonRemoteResourceManagerOptions); protected _convertParams(params: RenderParams): ContentParams; protected _convertRenderItem(item: RenderItem, type: ContentType): ContentItem; render(item: RenderItem): Promise<string>; renderBatch(items: RenderItem[]): Promise<string[]>; renderObject<T extends object>(item: RenderItem): Promise<T>; renderResponse(item: RenderItem): Promise<ResponseVariant>; renderAll(items: TypedRenderItem[]): Promise<RenderResult[]>; selectedVariation(item: RenderItem): Promise<SelectedVariation>; selectedVariations(): Promise<SelectedVariation[]>; protected _convertResponse(item: ResponseItemV1): ResponseVariant; protected getContent(items: ContentItem[]): Promise<GetContentResponseV1>; }