UNPKG

ask-cli

Version:

Alexa Skills Kit (ASK) Command Line Interfaces

44 lines (43 loc) 2.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateDialogArgs = void 0; const smapi_client_1 = require("../../clients/smapi-client"); /** * Validates if a skill is enabled for simulation. Calls Skill Management apis (SMAPI) to achieve this. * @param {*} dialogMode encapsulates configuration required validate skill information * @param {*} callback */ async function validateDialogArgs(dialogMode) { var _a, _b, _c; const { smapiClient, skillId, stage, locale } = dialogMode; const response = await smapiClient.skill.manifest.getManifest(skillId, stage); if ((0, smapi_client_1.isSmapiError)(response)) { throw smapiErrorMsg("get-manifest", response); } const apis = (_a = response.body.manifest) === null || _a === void 0 ? void 0 : _a.apis; if (!apis) { throw 'Ensure "manifest.apis" object exists in the skill manifest.'; } const apisKeys = Object.keys(apis); if (!apisKeys || apisKeys.length !== 1) { throw "Dialog command only supports custom skill type."; } if (apisKeys[0] !== "custom") { throw `Dialog command only supports custom skill type, but current skill is a "${apisKeys[0]}" type.`; } const locales = (_c = (_b = response.body.manifest) === null || _b === void 0 ? void 0 : _b.publishingInformation) === null || _c === void 0 ? void 0 : _c.locales; if (!locales) { throw 'Ensure the "manifest.publishingInformation.locales" exists in the skill manifest before simulating your skill.'; } if (!locales[locale]) { throw `Locale ${locale} was not found for your skill. Ensure the locale you want to simulate exists in your publishingInformation.`; } const enableResponse = await smapiClient.skill.getSkillEnablement(skillId, stage); if ((0, smapi_client_1.isSmapiError)(enableResponse)) { throw smapiErrorMsg("get-skill-enablement", enableResponse); } } exports.validateDialogArgs = validateDialogArgs; function smapiErrorMsg(operation, res) { return `SMAPI ${operation} request error: ${res.statusCode} - ${res.body.message}`; }