@sprucelabs/spruce-cli
Version:
Command line interface for building Spruce skills.
55 lines • 2.25 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const globby_1 = __importDefault(require("@sprucelabs/globby"));
const spruce_skill_utils_1 = require("@sprucelabs/spruce-skill-utils");
const AbstractStore_1 = __importDefault(require("../../../stores/AbstractStore"));
class PermissionStore extends AbstractStore_1.default {
name = 'permission';
async loadLocalPermissions() {
const matches = await (0, globby_1.default)('**/*.permissions.ts', {
cwd: this.cwd,
});
const namespace = this.Service('pkg').getSkillNamespace();
const imported = [];
for (const file of matches) {
const path = spruce_skill_utils_1.diskUtil.resolvePath(this.cwd, file);
const contract = (await this.Service('import').importDefault(path));
imported.push({
id: `${namespace}.${contract.id}`,
permissions: contract.permissions.map((p) => p.id),
path,
});
}
return imported;
}
async fetchContracts(options) {
const { shouldSyncCorePermissions, namespaces } = options ?? {};
let target;
const client = await this.connectToApi({
shouldAuthAsCurrentSkill: true,
});
if (!shouldSyncCorePermissions) {
const deps = this.Service('dependency').get();
target = {
namespaces: namespaces ?? deps.map((d) => d.namespace),
};
}
const [{ permissionContracts }] = await client.emitAndFlattenResponses('list-permission-contracts::v2020_12_25', {
target,
});
const local = await this.loadLocalPermissions();
const map = local.reduce((map, local) => {
map[local.id] = local.permissions;
return map;
}, {});
for (const result of permissionContracts) {
map[result.contract.id] = result.contract.permissions.map((p) => p.id);
}
return map;
}
}
exports.default = PermissionStore;
//# sourceMappingURL=PermissionStore.js.map