UNPKG

@sprucelabs/spruce-cli

Version:

Command line interface for building Spruce skills.

49 lines 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const schema_1 = require("@sprucelabs/schema"); const apiClientUtil = { generateClientCacheKey: (options) => { if (options?.shouldAuthAsCurrentSkill) { return 'skill'; } if (options?.shouldAuthAsLoggedInPerson === false) { return 'anon'; } if (!options || (!options.token && !options.skillId)) { return 'loggedInPersonOrAnon'; } if (options.token) { return `person:${options.token}`; } if (options.skillId && options.apiKey) { return `skill:${options.skillId}:${options.apiKey}`; } throw new schema_1.SchemaError({ code: 'INVALID_PARAMETERS', parameters: [ !options.token && 'token', !options.skillId && 'skillId', !options.apiKey && 'apiKey', ].filter((p) => !!p), friendlyMessage: `You must pass a token to login as a person or a skillId and apiKey to login as a skill.`, }); }, skillOrAuthToAuth(auth) { let { skillId } = auth; let { id } = auth; skillId = id ?? skillId; if (!skillId) { throw new schema_1.SchemaError({ code: 'MISSING_PARAMETERS', parameters: ['auth.skillId'], }); } const skillAuth = { skillId, apiKey: auth.apiKey, }; return skillAuth; }, }; exports.default = apiClientUtil; //# sourceMappingURL=apiClient.utility.js.map