"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const tape_1 = __importDefault(require("tape-promise/tape"));
const uuid_1 = require("uuid");
const promises_1 = require("fs/promises");
const cactus_core_api_1 = require("@hyperledger/cactus-core-api");
const public_api_1 = require("../../../main/typescript/public-api");
const logLevel = "TRACE";
(0, tape_1.default)("can install plugins at runtime with specified version based on imports", async (t) => {
    const pluginsPath = path_1.default.join(__dirname, "../../../../../../", // walk back up to the project root
    ".tmp/test/test-cmd-api-server/plugin-import-from-github_test/", // the dir path from the root
    (0, uuid_1.v4)());
    const pluginManagerOptionsJson = JSON.stringify({ pluginsPath });
    const configService = new public_api_1.ConfigService();
    const apiServerOptions = await configService.newExampleConfig();
    apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson;
    apiServerOptions.authorizationProtocol = public_api_1.AuthorizationProtocol.NONE;
    apiServerOptions.configFile = "";
    apiServerOptions.apiCorsDomainCsv = "*";
    apiServerOptions.apiPort = 0;
    apiServerOptions.cockpitPort = 0;
    apiServerOptions.grpcPort = 0;
    apiServerOptions.crpcPort = 0;
    apiServerOptions.apiTlsEnabled = false;
    apiServerOptions.plugins = [
        {
            packageName: "@hyperledger/cactus-dummy-package",
            type: cactus_core_api_1.PluginImportType.Local,
            action: cactus_core_api_1.PluginImportAction.Install,
            options: {
                instanceId: (0, uuid_1.v4)(),
                keychainId: (0, uuid_1.v4)(),
                logLevel,
                packageSrc: "https://gitpkg.now.sh/hyperledger/cactus/packages/cactus-cmd-api-server/src/test/resources/cactus-dummy-package?main",
            },
        },
    ];
    const config = await configService.newExampleConfigConvict(apiServerOptions);
    const apiServer = new public_api_1.ApiServer({
        config: config.getProperties(),
    });
    const startResponse = apiServer.start();
    await t.doesNotReject(startResponse, "failed to start API server with dynamic plugin imports configured for it...");
    t.ok(startResponse, "startResponse truthy OK");
    const packageFilePath = path_1.default.join(pluginsPath, apiServerOptions.plugins[0].options.instanceId, "node_modules", `${apiServerOptions.plugins[0].packageName}`, "package.json");
    const pkgJsonStr = await (0, promises_1.readFile)(packageFilePath, "utf-8");
    const { name, version } = JSON.parse(pkgJsonStr);
    t.comment(name);
    t.comment(version);
    t.strictEquals(name, apiServerOptions.plugins[0].packageName, `Package name strictly equal to ${apiServerOptions.plugins[0].packageName}`);
    tape_1.default.onFinish(() => apiServer.shutdown());
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGx1Z2luLWltcG9ydC1mcm9tLWdpdGh1Yi50ZXN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vc3JjL3Rlc3QvdHlwZXNjcmlwdC9pbnRlZ3JhdGlvbi9wbHVnaW4taW1wb3J0LWZyb20tZ2l0aHViLnRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxnREFBd0I7QUFDeEIsNkRBQStDO0FBQy9DLCtCQUFvQztBQUNwQywwQ0FBdUM7QUFFdkMsa0VBR3NDO0FBQ3RDLG9FQUk2QztBQUU3QyxNQUFNLFFBQVEsR0FBaUIsT0FBTyxDQUFDO0FBRXZDLElBQUEsY0FBSSxFQUFDLHdFQUF3RSxFQUFFLEtBQUssRUFBRSxDQUFPLEVBQUUsRUFBRTtJQUMvRixNQUFNLFdBQVcsR0FBRyxjQUFJLENBQUMsSUFBSSxDQUMzQixTQUFTLEVBQ1Qsb0JBQW9CLEVBQUUsbUNBQW1DO0lBQ3pELCtEQUErRCxFQUFFLDZCQUE2QjtJQUM5RixJQUFBLFNBQU0sR0FBRSxDQUNULENBQUM7SUFDRixNQUFNLHdCQUF3QixHQUFHLElBQUksQ0FBQyxTQUFTLENBQUMsRUFBRSxXQUFXLEVBQUUsQ0FBQyxDQUFDO0lBRWpFLE1BQU0sYUFBYSxHQUFHLElBQUksMEJBQWEsRU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