unleash-server
Version:
Unleash is an enterprise ready feature toggles service. It provides different strategies for handling feature toggles.
61 lines • 2.34 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const notfound_error_1 = __importDefault(require("../error/notfound-error"));
const feature_schema_1 = require("../schema/feature-schema");
const events_1 = require("../types/events");
const tag_schema_1 = require("./tag-schema");
class FeatureTagService {
constructor({ tagStore, featureTagStore, eventStore, }, { getLogger }) {
this.logger = getLogger('/services/feature-tag-service.ts');
this.tagStore = tagStore;
this.featureTagStore = featureTagStore;
this.eventStore = eventStore;
}
async listTags(featureName) {
return this.featureTagStore.getAllTagsForFeature(featureName);
}
// TODO: add project Id
async addTag(featureName, tag, userName) {
await feature_schema_1.nameSchema.validateAsync({ name: featureName });
const validatedTag = await tag_schema_1.tagSchema.validateAsync(tag);
await this.createTagIfNeeded(validatedTag, userName);
await this.featureTagStore.tagFeature(featureName, validatedTag);
await this.eventStore.store({
type: events_1.FEATURE_TAGGED,
createdBy: userName,
featureName,
data: validatedTag,
});
return validatedTag;
}
async createTagIfNeeded(tag, userName) {
try {
await this.tagStore.getTag(tag.type, tag.value);
}
catch (error) {
if (error instanceof notfound_error_1.default) {
await this.tagStore.createTag(tag);
await this.eventStore.store({
type: events_1.TAG_CREATED,
createdBy: userName,
data: tag,
});
}
}
}
// TODO: add project Id
async removeTag(featureName, tag, userName) {
await this.featureTagStore.untagFeature(featureName, tag);
await this.eventStore.store({
type: events_1.FEATURE_UNTAGGED,
createdBy: userName,
featureName,
data: tag,
});
}
}
exports.default = FeatureTagService;
//# sourceMappingURL=feature-tag-service.js.map