@salesforce/core
Version:
Core libraries to interact with SFDX projects, orgs, and APIs.
80 lines • 1.96 kB
JavaScript
;
/*
* Copyright (c) 2021, salesforce.com, inc.
* All rights reserved.
* Licensed under the BSD 3-Clause license.
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TokenAccessor = void 0;
const kit_1 = require("@salesforce/kit");
const tokensConfig_1 = require("../../config/tokensConfig");
class TokenAccessor extends kit_1.AsyncOptionalCreatable {
/**
* Return all tokens.
*
* @param decrypt
* @returns {SfTokens}
*/
getAll(decrypt = false) {
return this.config.getContents(decrypt) || {};
}
/**
* Return a token for the provided name.
*
* @param name
* @param decrypt
* @returns {Optional<SfToken>}
*/
get(name, decrypt = false) {
return this.config.get(name, decrypt);
}
/**
* Return true if a given name has a token associated with it.
*
* @param name
* @returns {boolean}
*/
has(name) {
return !!this.getAll()[name];
}
/**
* Set the token for the provided name.
*
* @param name
* @param token
*/
set(name, token) {
this.config.set(name, token);
}
/**
* Update the token for the provided name.
*
* @param name
* @param token
*/
update(name, token) {
this.config.update(name, token);
}
/**
* Unet the token for the provided name.
*
* @param name
*/
unset(name) {
this.config.unset(name);
}
/**
* Write the contents to the token file.
*
* @returns {Promise<SfTokens>}
*/
async write() {
return this.config.write();
}
async init() {
this.config = await tokensConfig_1.TokensConfig.create();
}
}
exports.TokenAccessor = TokenAccessor;
//# sourceMappingURL=tokenAccessor.js.map