@timeax/digital-service-engine 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1967,15 +1967,13 @@ function rateOk(svcMap, candidate, primary, policy) {
1967
1967
 
1968
1968
  // src/core/validate/steps/rates.ts
1969
1969
  function validateRates(v) {
1970
- var _a, _b, _c, _d;
1971
- const ratePolicy = normalizeRatePolicy(
1972
- (_a = v.options.fallbackSettings) == null ? void 0 : _a.ratePolicy
1973
- );
1970
+ var _a, _b, _c;
1971
+ const ratePolicy = normalizeRatePolicy(v.options.ratePolicy);
1974
1972
  for (const f of v.fields) {
1975
1973
  if (!isMultiField(f)) continue;
1976
1974
  const baseRates = [];
1977
- for (const o of (_b = f.options) != null ? _b : []) {
1978
- const role = (_d = (_c = o.pricing_role) != null ? _c : f.pricing_role) != null ? _d : "base";
1975
+ for (const o of (_a = f.options) != null ? _a : []) {
1976
+ const role = (_c = (_b = o.pricing_role) != null ? _b : f.pricing_role) != null ? _c : "base";
1979
1977
  if (role !== "base") continue;
1980
1978
  const sid = o.service_id;
1981
1979
  if (!isServiceIdRef(sid)) continue;
@@ -2749,6 +2747,38 @@ function applyPolicies(errors, props, serviceMap, policies, fieldsVisibleUnder,
2749
2747
  }
2750
2748
  }
2751
2749
 
2750
+ // src/core/governance.ts
2751
+ var DEFAULT_FALLBACK_SETTINGS = {
2752
+ requireConstraintFit: true,
2753
+ ratePolicy: { kind: "lte_primary", pct: 5 },
2754
+ selectionStrategy: "priority",
2755
+ mode: "strict"
2756
+ };
2757
+ function resolveGlobalRatePolicy(options) {
2758
+ return normalizeRatePolicy(options.ratePolicy);
2759
+ }
2760
+ function resolveFallbackSettings(options) {
2761
+ var _a;
2762
+ return {
2763
+ ...DEFAULT_FALLBACK_SETTINGS,
2764
+ ...(_a = options.fallbackSettings) != null ? _a : {}
2765
+ };
2766
+ }
2767
+ function mergeValidatorOptions(defaults = {}, overrides = {}) {
2768
+ var _a, _b, _c, _d;
2769
+ const mergedFallbackSettings = {
2770
+ ...(_a = defaults.fallbackSettings) != null ? _a : {},
2771
+ ...(_b = overrides.fallbackSettings) != null ? _b : {}
2772
+ };
2773
+ return {
2774
+ ...defaults,
2775
+ ...overrides,
2776
+ policies: (_c = overrides.policies) != null ? _c : defaults.policies,
2777
+ ratePolicy: (_d = overrides.ratePolicy) != null ? _d : defaults.ratePolicy,
2778
+ fallbackSettings: Object.keys(mergedFallbackSettings).length > 0 ? mergedFallbackSettings : void 0
2779
+ };
2780
+ }
2781
+
2752
2782
  // src/core/builder.ts
2753
2783
  var import_lodash_es2 = require("lodash-es");
2754
2784
  function createBuilder(opts = {}) {
@@ -2991,7 +3021,7 @@ var BuilderImpl = class {
2991
3021
  return out;
2992
3022
  }
2993
3023
  errors() {
2994
- return validate(this.props, this.options);
3024
+ return validate(this.props, mergeValidatorOptions({}, this.options));
2995
3025
  }
2996
3026
  getOptions() {
2997
3027
  return (0, import_lodash_es2.cloneDeep)(this.options);
@@ -3278,11 +3308,14 @@ function readVisibilitySimOpts(ctx) {
3278
3308
  };
3279
3309
  }
3280
3310
  function validate(props, ctx = {}) {
3281
- var _a, _b, _c, _d;
3311
+ var _a, _b, _c;
3312
+ const options = mergeValidatorOptions({}, ctx);
3313
+ const fallbackSettings = resolveFallbackSettings(options);
3314
+ const ratePolicy = resolveGlobalRatePolicy(options);
3282
3315
  const errors = [];
3283
- const serviceMap = (_a = ctx.serviceMap) != null ? _a : {};
3316
+ const serviceMap = (_a = options.serviceMap) != null ? _a : {};
3284
3317
  const selectedKeys = new Set(
3285
- (_b = ctx.selectedOptionKeys) != null ? _b : []
3318
+ (_b = options.selectedOptionKeys) != null ? _b : []
3286
3319
  );
3287
3320
  const tags = Array.isArray(props.filters) ? props.filters : [];
3288
3321
  const fields = Array.isArray(props.fields) ? props.fields : [];
@@ -3292,8 +3325,12 @@ function validate(props, ctx = {}) {
3292
3325
  for (const f of fields) fieldById.set(f.id, f);
3293
3326
  const v = {
3294
3327
  props,
3295
- nodeMap: (_c = ctx.nodeMap) != null ? _c : buildNodeMap(props),
3296
- options: ctx,
3328
+ nodeMap: (_c = options.nodeMap) != null ? _c : buildNodeMap(props),
3329
+ options: {
3330
+ ...options,
3331
+ ratePolicy,
3332
+ fallbackSettings
3333
+ },
3297
3334
  errors,
3298
3335
  serviceMap,
3299
3336
  selectedKeys,
@@ -3308,7 +3345,7 @@ function validate(props, ctx = {}) {
3308
3345
  validateIdentity(v);
3309
3346
  validateOptionMaps(v);
3310
3347
  v.fieldsVisibleUnder = createFieldsVisibleUnder(v);
3311
- const visSim = readVisibilitySimOpts(ctx);
3348
+ const visSim = readVisibilitySimOpts(options);
3312
3349
  validateVisibility(v, visSim);
3313
3350
  applyPolicies(
3314
3351
  v.errors,
@@ -3329,7 +3366,7 @@ function validate(props, ctx = {}) {
3329
3366
  builder,
3330
3367
  services: serviceMap,
3331
3368
  tagId: tag.id,
3332
- ratePolicy: (_d = ctx.fallbackSettings) == null ? void 0 : _d.ratePolicy,
3369
+ ratePolicy,
3333
3370
  invalidFieldIds: v.invalidRateFieldIds
3334
3371
  });
3335
3372
  for (const diag of diags) {
@@ -4203,18 +4240,23 @@ function compilePolicies(raw) {
4203
4240
 
4204
4241
  // src/core/service-filter.ts
4205
4242
  function filterServicesForVisibleGroup(input, deps) {
4206
- var _a, _b, _c, _d, _e, _f;
4243
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4207
4244
  const svcMap = (_c = (_b = (_a = deps.builder).getServiceMap) == null ? void 0 : _b.call(_a)) != null ? _c : {};
4245
+ const builderOptions = (_e = (_d = deps.builder).getOptions) == null ? void 0 : _e.call(_d);
4208
4246
  const { context } = input;
4209
4247
  const usedSet = new Set(context.usedServiceIds.map(String));
4210
4248
  const primary = context.usedServiceIds[0];
4249
+ const explicitFallbackSettings = (_f = context.fallbackSettings) != null ? _f : context.fallback;
4250
+ const resolvedRatePolicy = normalizeRatePolicy(
4251
+ (_h = (_g = context.ratePolicy) != null ? _g : explicitFallbackSettings == null ? void 0 : explicitFallbackSettings.ratePolicy) != null ? _h : builderOptions == null ? void 0 : builderOptions.ratePolicy
4252
+ );
4253
+ const fallbackSettingsSource = explicitFallbackSettings != null ? explicitFallbackSettings : builderOptions == null ? void 0 : builderOptions.fallbackSettings;
4211
4254
  const fb = {
4212
- requireConstraintFit: true,
4213
- ratePolicy: { kind: "lte_primary", pct: 5 },
4214
- selectionStrategy: "priority",
4215
- mode: "strict",
4216
- ...(_d = context.fallback) != null ? _d : {}
4255
+ ...DEFAULT_FALLBACK_SETTINGS,
4256
+ ...fallbackSettingsSource != null ? fallbackSettingsSource : {},
4257
+ ratePolicy: resolvedRatePolicy
4217
4258
  };
4259
+ const policySource = (_j = (_i = context.policies) != null ? _i : builderOptions == null ? void 0 : builderOptions.policies) != null ? _j : [];
4218
4260
  const visibleServiceIds = context.selectedButtons === void 0 ? void 0 : collectVisibleServiceIds(
4219
4261
  deps.builder,
4220
4262
  context.tagId,
@@ -4239,11 +4281,11 @@ function filterServicesForVisibleGroup(input, deps) {
4239
4281
  const fitsConstraints = constraintFitOk(
4240
4282
  svcMap,
4241
4283
  cap.id,
4242
- (_e = context.effectiveConstraints) != null ? _e : {}
4284
+ (_k = context.effectiveConstraints) != null ? _k : {}
4243
4285
  );
4244
4286
  const passesRate2 = primary == null ? true : rateOk(svcMap, id, primary, fb);
4245
4287
  const polRes = evaluatePoliciesRaw(
4246
- (_f = context.policies) != null ? _f : [],
4288
+ policySource,
4247
4289
  [...context.usedServiceIds, id],
4248
4290
  svcMap,
4249
4291
  context.tagId,
@@ -6987,6 +7029,8 @@ function filterServicesForVisibleGroup2(ctx, candidates, input) {
6987
7029
  usedServiceIds: input.usedServiceIds,
6988
7030
  effectiveConstraints: input.effectiveConstraints,
6989
7031
  policies: input.policies,
7032
+ ratePolicy: input.ratePolicy,
7033
+ fallbackSettings: input.fallbackSettings,
6990
7034
  fallback: input.fallback
6991
7035
  }
6992
7036
  };