Skip to content

Commit

Permalink
feat: shared types (VF-000) (#177)
Browse files Browse the repository at this point in the history
* feat: shared types (VF-000)

wip: wip

wip: wip

wip: wip

feat: finish

fix: nlp

* fix: some improvements

* fix: publishing

* fix: defaults

* fix: publishing

* chore: prompt typeguard

* feat: add type-guards

* fix: packages

* chore: rebuild lock file

* chore: typescript version

* chore: fix depcheck

Co-authored-by: Tyler Han <tylerhan97@gmail.com>
  • Loading branch information
z4o4z and DecathectZero authored Feb 7, 2022
1 parent 136daa2 commit 3e1a206
Show file tree
Hide file tree
Showing 290 changed files with 4,382 additions and 3,413 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint"
}
},
"cSpell.words": ["typeguard"]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Check the full description [here](packages/voice-types/README.md)

Check the full description [here](packages/chat-types/README.md)

## General Types
## Voiceflow Types

Check the full description [here](packages/general-types/README.md)
Check the full description [here](packages/voiceflow-types/README.md)

## Alexa Types

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"rimraf": "^3.0.2",
"ts-node": "^9.1.1",
"ttypescript": "^1.5.12",
"typescript": "^4.2.4"
"typescript": "4.4.3"
},
"prettier": "@voiceflow/prettier-config",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/alexa-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"dependencies": {
"@voiceflow/base-types": "^2.8.0",
"@voiceflow/common": "^7.17.0",
"@voiceflow/general-types": "^3.2.21",
"@voiceflow/voice-types": "^2.1.20",
"@voiceflow/voiceflow-types": "^3.2.21",
"ask-smapi-model": "1.14.0"
},
"files": [
Expand Down
8 changes: 4 additions & 4 deletions packages/alexa-types/src/constants/intents.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BuiltinIntent } from '@voiceflow/common';
import { Constants } from '@voiceflow/general-types';
import { VoiceflowConstants } from '@voiceflow/voiceflow-types';
import { v1 } from 'ask-smapi-model';

export type InterfaceType = v1.skill.Manifest.Interface['type'];
Expand Down Expand Up @@ -40,7 +40,7 @@ export enum IntentPrefix {
CAPTURE = 'CAPTURE',
}

export interface AlexaDefaultIntent extends Constants.DefaultIntent {
export interface DefaultIntent extends VoiceflowConstants.DefaultIntent {
keep?: string[];
}

Expand Down Expand Up @@ -184,7 +184,7 @@ export const BUILT_IN_INTENTS: BuiltinIntent[] = [
},
];

export const DEFAULT_INTENTS: Record<string, { defaults: AlexaDefaultIntent[]; builtIns: AlexaDefaultIntent[] }> = {
export const DEFAULT_INTENTS: Record<string, { defaults: DefaultIntent[]; builtIns: DefaultIntent[] }> = {
// English (AU,CA,US,UK,IN)
en: {
defaults: [
Expand Down Expand Up @@ -633,7 +633,7 @@ export const DEFAULT_INTENTS: Record<string, { defaults: AlexaDefaultIntent[]; b
},
};

export const CATCH_ALL_INTENT: Record<string, AlexaDefaultIntent> = {
export const CATCH_ALL_INTENT: Record<string, DefaultIntent> = {
en: {
name: 'VoiceFlowIntent',
samples: ['voice flow'],
Expand Down
162 changes: 81 additions & 81 deletions packages/alexa-types/src/constants/mappings.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
import { Constants as General } from '@voiceflow/general-types';
import { VoiceflowConstants } from '@voiceflow/voiceflow-types';

import { Locale } from './base';
import { AmazonIntent } from './intents';
import { SlotType } from './slots';

export const AmazonToGeneralIntentMap: Partial<Record<AmazonIntent, General.IntentName>> = {
[AmazonIntent.NO]: General.IntentName.NO,
[AmazonIntent.YES]: General.IntentName.YES,
[AmazonIntent.STOP]: General.IntentName.STOP,
[AmazonIntent.NEXT]: General.IntentName.NEXT,
[AmazonIntent.HELP]: General.IntentName.HELP,
[AmazonIntent.PAUSE]: General.IntentName.PAUSE,
[AmazonIntent.CANCEL]: General.IntentName.CANCEL,
[AmazonIntent.RESUME]: General.IntentName.RESUME,
[AmazonIntent.REPEAT]: General.IntentName.REPEAT,
[AmazonIntent.FALLBACK]: General.IntentName.NONE,
[AmazonIntent.PREVIOUS]: General.IntentName.PREVIOUS,
[AmazonIntent.START_OVER]: General.IntentName.START_OVER,
export const AmazonToVoiceflowIntentMap: Partial<Record<AmazonIntent, VoiceflowConstants.IntentName>> = {
[AmazonIntent.NO]: VoiceflowConstants.IntentName.NO,
[AmazonIntent.YES]: VoiceflowConstants.IntentName.YES,
[AmazonIntent.STOP]: VoiceflowConstants.IntentName.STOP,
[AmazonIntent.NEXT]: VoiceflowConstants.IntentName.NEXT,
[AmazonIntent.HELP]: VoiceflowConstants.IntentName.HELP,
[AmazonIntent.PAUSE]: VoiceflowConstants.IntentName.PAUSE,
[AmazonIntent.CANCEL]: VoiceflowConstants.IntentName.CANCEL,
[AmazonIntent.RESUME]: VoiceflowConstants.IntentName.RESUME,
[AmazonIntent.REPEAT]: VoiceflowConstants.IntentName.REPEAT,
[AmazonIntent.FALLBACK]: VoiceflowConstants.IntentName.NONE,
[AmazonIntent.PREVIOUS]: VoiceflowConstants.IntentName.PREVIOUS,
[AmazonIntent.START_OVER]: VoiceflowConstants.IntentName.START_OVER,
};

export const GeneralToAmazonIntentMap: Partial<Record<General.IntentName, AmazonIntent>> = {
[General.IntentName.NO]: AmazonIntent.NO,
[General.IntentName.YES]: AmazonIntent.YES,
[General.IntentName.STOP]: AmazonIntent.STOP,
[General.IntentName.NEXT]: AmazonIntent.NEXT,
[General.IntentName.HELP]: AmazonIntent.HELP,
[General.IntentName.PAUSE]: AmazonIntent.PAUSE,
[General.IntentName.CANCEL]: AmazonIntent.CANCEL,
[General.IntentName.RESUME]: AmazonIntent.RESUME,
[General.IntentName.REPEAT]: AmazonIntent.REPEAT,
[General.IntentName.NONE]: AmazonIntent.FALLBACK,
[General.IntentName.PREVIOUS]: AmazonIntent.PREVIOUS,
[General.IntentName.START_OVER]: AmazonIntent.START_OVER,
export const VoiceflowToAmazonIntentMap: Partial<Record<VoiceflowConstants.IntentName, AmazonIntent>> = {
[VoiceflowConstants.IntentName.NO]: AmazonIntent.NO,
[VoiceflowConstants.IntentName.YES]: AmazonIntent.YES,
[VoiceflowConstants.IntentName.STOP]: AmazonIntent.STOP,
[VoiceflowConstants.IntentName.NEXT]: AmazonIntent.NEXT,
[VoiceflowConstants.IntentName.HELP]: AmazonIntent.HELP,
[VoiceflowConstants.IntentName.PAUSE]: AmazonIntent.PAUSE,
[VoiceflowConstants.IntentName.CANCEL]: AmazonIntent.CANCEL,
[VoiceflowConstants.IntentName.RESUME]: AmazonIntent.RESUME,
[VoiceflowConstants.IntentName.REPEAT]: AmazonIntent.REPEAT,
[VoiceflowConstants.IntentName.NONE]: AmazonIntent.FALLBACK,
[VoiceflowConstants.IntentName.PREVIOUS]: AmazonIntent.PREVIOUS,
[VoiceflowConstants.IntentName.START_OVER]: AmazonIntent.START_OVER,
};

export const AmazonToGeneralSlotMap: Partial<Record<SlotType, General.SlotType>> = {
[SlotType.TIME]: General.SlotType.DATETIME,
[SlotType.DATE]: General.SlotType.DATETIME,
[SlotType.FOUR_DIGIT_NUMBER]: General.SlotType.NUMBER,
[SlotType.NUMBER]: General.SlotType.NUMBER,
[SlotType.PHONENUMBER]: General.SlotType.PHONENUMBER,
[SlotType.PERSON]: General.SlotType.NAME,
[SlotType.DE_FIRST_NAME]: General.SlotType.NAME,
[SlotType.GB_FIRST_NAME]: General.SlotType.NAME,
[SlotType.US_FIRST_NAME]: General.SlotType.NAME,
[SlotType.FIRSTNAME]: General.SlotType.NAME,
[SlotType.ORDINAL]: General.SlotType.ORDINAL,
export const AmazonToVoiceflowSlotMap: Partial<Record<SlotType, VoiceflowConstants.SlotType>> = {
[SlotType.TIME]: VoiceflowConstants.SlotType.DATETIME,
[SlotType.DATE]: VoiceflowConstants.SlotType.DATETIME,
[SlotType.FOUR_DIGIT_NUMBER]: VoiceflowConstants.SlotType.NUMBER,
[SlotType.NUMBER]: VoiceflowConstants.SlotType.NUMBER,
[SlotType.PHONENUMBER]: VoiceflowConstants.SlotType.PHONENUMBER,
[SlotType.PERSON]: VoiceflowConstants.SlotType.NAME,
[SlotType.DE_FIRST_NAME]: VoiceflowConstants.SlotType.NAME,
[SlotType.GB_FIRST_NAME]: VoiceflowConstants.SlotType.NAME,
[SlotType.US_FIRST_NAME]: VoiceflowConstants.SlotType.NAME,
[SlotType.FIRSTNAME]: VoiceflowConstants.SlotType.NAME,
[SlotType.ORDINAL]: VoiceflowConstants.SlotType.ORDINAL,
};

export const GeneralToAmazonSlotMap: Partial<Record<General.SlotType, SlotType>> = {
[General.SlotType.DATETIME]: SlotType.DATE,
[General.SlotType.NUMBER]: SlotType.NUMBER,
[General.SlotType.PHONENUMBER]: SlotType.PHONENUMBER,
[General.SlotType.NAME]: SlotType.FIRSTNAME,
[General.SlotType.ORDINAL]: SlotType.ORDINAL,
export const VoiceflowToAmazonSlotMap: Partial<Record<VoiceflowConstants.SlotType, SlotType>> = {
[VoiceflowConstants.SlotType.DATETIME]: SlotType.DATE,
[VoiceflowConstants.SlotType.NUMBER]: SlotType.NUMBER,
[VoiceflowConstants.SlotType.PHONENUMBER]: SlotType.PHONENUMBER,
[VoiceflowConstants.SlotType.NAME]: SlotType.FIRSTNAME,
[VoiceflowConstants.SlotType.ORDINAL]: SlotType.ORDINAL,
};

export const AmazonToGeneralLocaleMap: Record<Locale, General.Locale> = {
[Locale.EN_US]: General.Locale.EN_US,
[Locale.EN_AU]: General.Locale.EN_US,
[Locale.EN_CA]: General.Locale.EN_US,
[Locale.EN_IN]: General.Locale.EN_US,
[Locale.EN_GB]: General.Locale.EN_US,
[Locale.FR_CA]: General.Locale.FR_CA,
[Locale.ES_US]: General.Locale.ES_ES,
[Locale.FR_FR]: General.Locale.FR_FR,
[Locale.DE_DE]: General.Locale.DE_DE,
[Locale.IT_IT]: General.Locale.IT_IT,
[Locale.JA_JP]: General.Locale.JA_JP,
[Locale.ES_ES]: General.Locale.ES_ES,
[Locale.ES_MX]: General.Locale.ES_MX,
[Locale.PT_BR]: General.Locale.PT_BR,
[Locale.HI_IN]: General.Locale.HI_IN,
export const AmazonToVoiceflowLocaleMap: Record<Locale, VoiceflowConstants.Locale> = {
[Locale.EN_US]: VoiceflowConstants.Locale.EN_US,
[Locale.EN_AU]: VoiceflowConstants.Locale.EN_US,
[Locale.EN_CA]: VoiceflowConstants.Locale.EN_US,
[Locale.EN_IN]: VoiceflowConstants.Locale.EN_US,
[Locale.EN_GB]: VoiceflowConstants.Locale.EN_US,
[Locale.FR_CA]: VoiceflowConstants.Locale.FR_CA,
[Locale.ES_US]: VoiceflowConstants.Locale.ES_ES,
[Locale.FR_FR]: VoiceflowConstants.Locale.FR_FR,
[Locale.DE_DE]: VoiceflowConstants.Locale.DE_DE,
[Locale.IT_IT]: VoiceflowConstants.Locale.IT_IT,
[Locale.JA_JP]: VoiceflowConstants.Locale.JA_JP,
[Locale.ES_ES]: VoiceflowConstants.Locale.ES_ES,
[Locale.ES_MX]: VoiceflowConstants.Locale.ES_MX,
[Locale.PT_BR]: VoiceflowConstants.Locale.PT_BR,
[Locale.HI_IN]: VoiceflowConstants.Locale.HI_IN,
};

export const GeneralToAmazonLocaleMap: Record<General.Locale, Locale> = {
[General.Locale.EN_US]: Locale.EN_US,
[General.Locale.AR_AR]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.ZH_CN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.NL_NL]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.FR_FR]: Locale.FR_FR,
[General.Locale.FR_CA]: Locale.FR_CA,
[General.Locale.DE_DE]: Locale.DE_DE,
[General.Locale.GU_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.HI_IN]: Locale.HI_IN,
[General.Locale.IT_IT]: Locale.IT_IT,
[General.Locale.JA_JP]: Locale.JA_JP,
[General.Locale.KO_KR]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.MR_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.PT_BR]: Locale.PT_BR,
[General.Locale.ES_ES]: Locale.ES_ES,
[General.Locale.ES_MX]: Locale.ES_MX,
[General.Locale.TA_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.TE_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[General.Locale.TR_TR]: Locale.EN_US, // FIXME: Unsupported language by Alexa
export const VoiceflowToAmazonLocaleMap: Record<VoiceflowConstants.Locale, Locale> = {
[VoiceflowConstants.Locale.EN_US]: Locale.EN_US,
[VoiceflowConstants.Locale.AR_AR]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.ZH_CN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.NL_NL]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.FR_FR]: Locale.FR_FR,
[VoiceflowConstants.Locale.FR_CA]: Locale.FR_CA,
[VoiceflowConstants.Locale.DE_DE]: Locale.DE_DE,
[VoiceflowConstants.Locale.GU_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.HI_IN]: Locale.HI_IN,
[VoiceflowConstants.Locale.IT_IT]: Locale.IT_IT,
[VoiceflowConstants.Locale.JA_JP]: Locale.JA_JP,
[VoiceflowConstants.Locale.KO_KR]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.MR_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.PT_BR]: Locale.PT_BR,
[VoiceflowConstants.Locale.ES_ES]: Locale.ES_ES,
[VoiceflowConstants.Locale.ES_MX]: Locale.ES_MX,
[VoiceflowConstants.Locale.TA_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.TE_IN]: Locale.EN_US, // FIXME: Unsupported language by Alexa
[VoiceflowConstants.Locale.TR_TR]: Locale.EN_US, // FIXME: Unsupported language by Alexa
};
6 changes: 3 additions & 3 deletions packages/alexa-types/src/diagram.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Models } from '@voiceflow/base-types';
import { BaseModels } from '@voiceflow/base-types';

import { AnyAlexaStep } from './node';
import { AnyStep } from './node';

export interface AlexaDiagram extends Models.Diagram<AnyAlexaStep> {}
export interface Diagram extends BaseModels.Diagram.Model<AnyStep> {}
16 changes: 8 additions & 8 deletions packages/alexa-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export * as Constants from './constants';
export * as Diagram from './diagram';
export * as Node from './node';
export * as Program from './program';
export * as Project from './project';
export * as Types from './types';
export * as Utils from './utils';
export * as Version from './version';
export * as AlexaConstants from './constants';
export * as AlexaDiagram from './diagram';
export * as AlexaModels from './models';
export * as AlexaNode from './node';
export * as AlexaProgram from './program';
export * as AlexaProject from './project';
export * as AlexaUtils from './utils';
export * as AlexaVersion from './version';
File renamed without changes.
6 changes: 3 additions & 3 deletions packages/alexa-types/src/node/accountLinking.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Node, UnknownRecord } from '@voiceflow/base-types';
import { BaseNode, UnknownRecord } from '@voiceflow/base-types';

import { NodeType } from './constants';

export type StepData = UnknownRecord;

export interface Step extends Node.Utils.BaseStep<StepData> {
export interface Step extends BaseNode.Utils.BaseStep<StepData> {
type: NodeType.ACCOUNT_LINKING;
}

export interface Node extends Node.Utils.BaseNode, Node.Utils.NodeNextID {
export interface Node extends BaseNode.Utils.BaseNode, BaseNode.Utils.NodeNextID {
type: NodeType.ACCOUNT_LINKING;
link_account: true;
}
10 changes: 5 additions & 5 deletions packages/alexa-types/src/node/cancelPayment.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { Node } from '@voiceflow/base-types';
import { BaseNode } from '@voiceflow/base-types';

import { NodeType } from './constants';

export interface StepData {
productID: string;
}

export interface Step extends Node.Utils.BaseStep<StepData> {
export interface Step extends BaseNode.Utils.BaseStep<StepData> {
type: NodeType.CANCEL_PAYMENT;
}

export interface BaseTypedNode extends Node.Utils.BaseNode {
export interface BaseTypedNode extends BaseNode.Utils.BaseNode {
type: NodeType.CANCEL_PAYMENT;
}

export interface NextNode extends BaseTypedNode, Node.Utils.NodeNextID {}
export interface NextNode extends BaseTypedNode, BaseNode.Utils.NodeNextID {}

export interface CancelNode extends BaseTypedNode, Node.Utils.NodeSuccessFailID {
export interface CancelNode extends BaseTypedNode, BaseNode.Utils.NodeSuccessFailID {
cancel_product_id: string;
}

Expand Down
8 changes: 4 additions & 4 deletions packages/alexa-types/src/node/capture.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Node } from '@voiceflow/voice-types';
import { VoiceNode } from '@voiceflow/voice-types';

import { Voice } from '@/constants';

/** @deprecated */
export interface StepData extends Node.Capture.StepData<Voice> {}
export interface StepData extends VoiceNode.Capture.StepData<Voice> {}

/** @deprecated */
export interface Step extends Node.Capture.Step<StepData> {}
export interface Step extends VoiceNode.Capture.Step<StepData> {}

/** @deprecated */
export interface Node extends Node.Capture.Node {}
export interface Node extends VoiceNode.Capture.Node {}
8 changes: 4 additions & 4 deletions packages/alexa-types/src/node/captureV2.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Node } from '@voiceflow/voice-types';
import { VoiceNode } from '@voiceflow/voice-types';

import { Voice } from '@/constants';

export interface StepData extends Node.CaptureV2.StepData<Voice> {}
export interface StepData extends VoiceNode.CaptureV2.StepData<Voice> {}

export interface Step extends Node.CaptureV2.Step<StepData> {}
export interface Step extends VoiceNode.CaptureV2.Step<StepData> {}

export interface Node extends Node.CaptureV2.Node {}
export interface Node extends VoiceNode.CaptureV2.Node {}
10 changes: 5 additions & 5 deletions packages/alexa-types/src/node/display.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Node } from '@voiceflow/base-types';
import { BaseNode } from '@voiceflow/base-types';

import { NodeType } from './constants';

export interface StepData extends Omit<Node.Visual.APLStepData, 'visualType' | 'aplType'> {
type: Node.Visual.APLType;
export interface StepData extends Omit<BaseNode.Visual.APLStepData, 'visualType' | 'aplType'> {
type: BaseNode.Visual.APLType;
}

export interface Step extends Node.Utils.BaseStep<StepData> {
export interface Step extends BaseNode.Utils.BaseStep<StepData> {
type: NodeType.DISPLAY;
}

export interface Node extends Node.Utils.BaseNode, Node.Utils.NodeRequiredNextID {
export interface Node extends BaseNode.Utils.BaseNode, BaseNode.Utils.NodeRequiredNextID {
type: NodeType.DISPLAY;
datasource: string;
document: string;
Expand Down
8 changes: 4 additions & 4 deletions packages/alexa-types/src/node/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Node, Nullable } from '@voiceflow/base-types';
import { BaseNode, Nullable } from '@voiceflow/base-types';

import { NodeType } from './constants';

Expand All @@ -12,13 +12,13 @@ export interface StepData {
requestName: string;
}

export interface Step extends Node.Utils.BaseStep<StepData> {
export interface Step extends BaseNode.Utils.BaseStep<StepData> {
type: NodeType.EVENT;
}

export interface Command extends Node.Utils.BaseCommand {
export interface Command extends BaseNode.Utils.BaseCommand {
type: NodeType.EVENT;
next?: Node.Utils.NodeID;
next?: BaseNode.Utils.NodeID;
event: string;
mappings: Mapping[];
}
Loading

0 comments on commit 3e1a206

Please sign in to comment.