@digikare/nestjs-azure-appconfig
Version:
An azure app configuration module for nestjs
94 lines (93 loc) • 4.19 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var AppConfigModule_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AppConfigModule = void 0;
const common_1 = require("@nestjs/common");
const app_config_service_1 = require("./app-config.service");
const identity_1 = require("@azure/identity");
const app_configuration_1 = require("@azure/app-configuration");
const constants_1 = require("./constants");
const debug_1 = __importDefault(require("debug"));
const debug = debug_1.default('AppConfig:Module');
function hideSecrets(cs) {
return cs.replace(/Secret=[^;]+/g, 'Secret=*********');
}
let AppConfigModule = AppConfigModule_1 = class AppConfigModule {
static forServicePrincipal(options) {
return AppConfigModule_1.forServicePrincipalFactory({ useFactory: () => options });
}
static forServicePrincipalFactory(factoryOption) {
var _a, _b;
return {
module: AppConfigModule_1,
imports: [
...((_a = factoryOption.imports) !== null && _a !== void 0 ? _a : [])
],
providers: [
{
provide: constants_1.APP_CONFIG_OPTIONS,
useFactory: factoryOption.useFactory,
inject: (_b = factoryOption.inject) !== null && _b !== void 0 ? _b : [],
},
{
provide: constants_1.APP_CONFIG_INSTANCE,
inject: [constants_1.APP_CONFIG_OPTIONS],
useFactory: (opts) => {
var _a;
const credential = (_a = opts.credential) !== null && _a !== void 0 ? _a : new identity_1.DefaultAzureCredential();
const client = new app_configuration_1.AppConfigurationClient(opts.endpoint, credential, opts.options);
return client;
},
},
],
exports: [
app_config_service_1.AppConfigService,
],
};
}
static forConnectionString(options) {
return AppConfigModule_1.forConnectionStringFactory({ useFactory: () => options });
}
static forConnectionStringFactory(factoryOption) {
var _a, _b;
return {
module: AppConfigModule_1,
imports: [
...((_a = factoryOption.imports) !== null && _a !== void 0 ? _a : []),
],
providers: [
{
provide: constants_1.APP_CONFIG_OPTIONS,
useFactory: factoryOption.useFactory,
inject: [...((_b = factoryOption.inject) !== null && _b !== void 0 ? _b : [])],
},
{
provide: constants_1.APP_CONFIG_INSTANCE,
inject: [constants_1.APP_CONFIG_OPTIONS],
useFactory: (opts) => {
debug(`ConnectionString`, hideSecrets(opts.connectionString));
const client = new app_configuration_1.AppConfigurationClient(opts.connectionString);
return client;
},
},
app_config_service_1.AppConfigService,
],
exports: [
app_config_service_1.AppConfigService,
]
};
}
};
AppConfigModule = AppConfigModule_1 = __decorate([
common_1.Module({})
], AppConfigModule);
exports.AppConfigModule = AppConfigModule;