@sap-ux/store
Version:
NPM module for storing persistent data
33 lines • 1.52 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LEGACY_API_HUB_API_KEY = exports.LEGACY_API_HUB_API_SERVICE = void 0;
exports.migrateToLatestVersion = migrateToLatestVersion;
const i18n_1 = require("../../i18n");
const api_hub_1 = require("../../entities/api-hub");
exports.LEGACY_API_HUB_API_SERVICE = 'fiori/system/apiHub';
exports.LEGACY_API_HUB_API_KEY = 'API_HUB_API_KEY';
/**
* Do NOT export to the outside world
*/
async function migrateToLatestVersion({ dataProvider, secureStore, logger }) {
// Migrates the key from initial version where the key was written directly to the secure store
const apiKey = await secureStore.retrieve(exports.LEGACY_API_HUB_API_SERVICE, exports.LEGACY_API_HUB_API_KEY);
if (!apiKey) {
logger.debug((0, i18n_1.text)('info.noLegacyApiHubKeyFound'));
return;
}
else {
logger.info((0, i18n_1.text)('info.legacyApiHubKeyFound'));
}
const apiKeysNewFormat = await dataProvider.read(new api_hub_1.ApiHubSettingsKey());
if (!apiKeysNewFormat) {
await dataProvider.write(new api_hub_1.ApiHubSettings({ apiKey }));
logger.info((0, i18n_1.text)('info.legacyApiHubKeyMigrated'));
}
else {
logger.info((0, i18n_1.text)('info.legacyApiHubKeyNotMigrated'));
}
await secureStore.delete(exports.LEGACY_API_HUB_API_SERVICE, exports.LEGACY_API_HUB_API_KEY);
logger.info((0, i18n_1.text)('info.legacyApiHubKeyDeleted'));
}
//# sourceMappingURL=migration.js.map