@larksuiteoapi/core
Version:
larksuite open api core sdk
74 lines • 3.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getInternalAppSettingsByEnv = exports.getISVAppSettingsByEnv = exports.newInternalAppSettings = exports.newISVAppSettings = exports.newInternalAppSettingsWithOpts = exports.newISVAppSettingsWithOpts = exports.AppSettings = void 0;
const constants_1 = require("../constants/constants");
class AppSettings {
constructor(appType, opts) {
if (!opts.appID || !opts.appSecret) {
throw new Error("appID or appSecret is empty");
}
this.appType = appType;
this.appID = opts.appID;
this.appSecret = opts.appSecret;
this.encryptKey = opts.encryptKey;
this.verificationToken = opts.verificationToken;
this.helpDeskID = opts.helpDeskID;
this.helpDeskToken = opts.helpDeskToken;
}
helpDeskAuthorization() {
if (this.helpDeskID && this.helpDeskToken) {
return Buffer.from(this.helpDeskID + ":" + this.helpDeskToken).toString('base64');
}
return "";
}
}
exports.AppSettings = AppSettings;
function newISVAppSettingsWithOpts(opts) {
return new AppSettings(constants_1.AppType.ISV, opts);
}
exports.newISVAppSettingsWithOpts = newISVAppSettingsWithOpts;
function newInternalAppSettingsWithOpts(opts) {
return new AppSettings(constants_1.AppType.Internal, opts);
}
exports.newInternalAppSettingsWithOpts = newInternalAppSettingsWithOpts;
function newISVAppSettings(appID, appSecret, verificationToken, encryptKey) {
return new AppSettings(constants_1.AppType.ISV, {
appID: appID,
appSecret: appSecret,
verificationToken: verificationToken,
encryptKey: encryptKey
});
}
exports.newISVAppSettings = newISVAppSettings;
function newInternalAppSettings(appID, appSecret, verificationToken, encryptKey) {
return new AppSettings(constants_1.AppType.Internal, {
appID: appID,
appSecret: appSecret,
verificationToken: verificationToken,
encryptKey: encryptKey
});
}
exports.newInternalAppSettings = newInternalAppSettings;
function getISVAppSettingsByEnv() {
return new AppSettings(constants_1.AppType.ISV, {
appID: process.env["APP_ID"],
appSecret: process.env["APP_SECRET"],
verificationToken: process.env["VERIFICATION_TOKEN"],
encryptKey: process.env["ENCRYPT_KEY"],
helpDeskID: process.env["HELP_DESK_ID"],
helpDeskToken: process.env["HELP_DESK_TOKEN"]
});
}
exports.getISVAppSettingsByEnv = getISVAppSettingsByEnv;
function getInternalAppSettingsByEnv() {
return new AppSettings(constants_1.AppType.Internal, {
appID: process.env["APP_ID"],
appSecret: process.env["APP_SECRET"],
verificationToken: process.env["VERIFICATION_TOKEN"],
encryptKey: process.env["ENCRYPT_KEY"],
helpDeskID: process.env["HELP_DESK_ID"],
helpDeskToken: process.env["HELP_DESK_TOKEN"]
});
}
exports.getInternalAppSettingsByEnv = getInternalAppSettingsByEnv;
//# sourceMappingURL=settings.js.map