@omnia/tooling-composers
Version:
Provide tooling to work with manifest things.
82 lines (81 loc) • 4.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebAppServiceComposer = void 0;
const models_1 = require("./models");
const Utils_1 = require("./Utils");
const CombinableSecurityProviderComposer_1 = require("./CombinableSecurityProviderComposer");
const SecurityProviderManifestRegistry_1 = require("./SecurityProviderManifestRegistry");
const ServiceManifestRegistry_1 = require("./ServiceManifestRegistry");
const BuildConfigurationRegistry_1 = require("./BuildConfigurationRegistry");
const ServiceManifestComposer_1 = require("./ServiceManifestComposer");
const models_2 = require("../../fx-models");
const ConfigurationClientServiceRegistry_1 = require("./ConfigurationClientServiceRegistry");
class WebAppServiceComposer extends ServiceManifestComposer_1.ServiceManifestComposer {
constructor(manifestId, manifestTitle, serviceOptions) {
// TODO wait hot reload update not execute composer two times
super(() => { return this; });
this.manifestId = manifestId;
this.manifestTitle = manifestTitle;
this.configuration = (configurationType) => {
return ConfigurationClientServiceRegistry_1.ConfigurationClientServiceRegistry.Add(new models_2.Guid(this.manifestId), configurationType, [this]);
};
this.withBuildOptions = (options) => {
BuildConfigurationRegistry_1.BuildConfigurationRegistry.AddBuildOptions(options);
return this;
};
this.AddRoleBasedSecurityProvider = (options) => {
if (!options) {
throw new Error("Can't add role based security provider with missing options");
}
let validScope = false;
Object.keys(models_1.SecurityRoleScopes).filter(key => models_1.SecurityRoleScopes[key] === options.scope ? validScope = true : false);
if (!validScope) {
throw new Error("Can't add role based security provider with scope: " + options.scope + " it's not a valid scope value");
}
if (!Utils_1.Utils.isValidGuid(options.providerId)) {
throw new Error("Can't add role based security provider with id: " + options.providerId + " must be a valid Guid");
}
if (!options.roleName) {
throw new Error("Can't add role based security provider with out valid role name: " + JSON.stringify(options));
}
let roleBasedProvider = {
providerId: options.providerId,
roleName: options.roleName,
scope: options.scope,
type: models_1.SecurityProviderTypes.RoleBased
};
SecurityProviderManifestRegistry_1.SecurityProviderManifestRegistry.AddSecurityProvider(roleBasedProvider);
return this;
};
this.AddCombinedSecurityProvider = (options) => {
if (!options) {
throw new Error("Can't add combined security provider with missing options");
}
if (!Utils_1.Utils.isValidGuid(options.providerId)) {
throw new Error("Can't add combined security provider with id: " + options.providerId + " must be a valid Guid");
}
let combinedProvider = {
providerId: options.providerId,
type: models_1.SecurityProviderTypes.Combined,
securityProviderRules: []
};
let cbNewRule = (allRules) => {
combinedProvider.securityProviderRules = allRules;
};
SecurityProviderManifestRegistry_1.SecurityProviderManifestRegistry.AddSecurityProvider(combinedProvider);
return new CombinableSecurityProviderComposer_1.SecurityProviderCombinableRuleComposer(cbNewRule, this);
};
if (!Utils_1.Utils.isValidGuid(this.manifestId)) {
throw new Error("Can't register omnia service with id: " + this.manifestId + " must be a valid Guid");
}
let serviceInfo = {
description: serviceOptions.description,
id: manifestId,
serviceType: models_1.ServiceTypes.WebApp,
title: manifestTitle,
optionalService: false
};
ServiceManifestRegistry_1.ServiceManifestRegistry.AddService(serviceInfo);
}
}
exports.WebAppServiceComposer = WebAppServiceComposer;