@nextera.one/axis-server-sdk 2.3.21 → 2.3.23

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.
package/dist/index.mjs CHANGED
@@ -673,7 +673,8 @@ var require_dto_schema_util = __commonJS({
673
673
  required: m.options.required,
674
674
  maxLen: m.options.maxLen,
675
675
  max: m.options.max,
676
- scope: m.options.scope
676
+ scope: m.options.scope,
677
+ encode: m.options.encode
677
678
  };
678
679
  });
679
680
  const validatorMetas = Reflect.getMetadata(tlv_field_decorator_1.TLV_VALIDATORS_KEY, dto) || [];
@@ -8883,9 +8884,11 @@ var init_axis_observation = __esm({
8883
8884
  });
8884
8885
 
8885
8886
  // src/security/axis-sensor-chain.service.ts
8887
+ import "reflect-metadata";
8886
8888
  var AxisSensorChainService;
8887
8889
  var init_axis_sensor_chain_service = __esm({
8888
8890
  "src/security/axis-sensor-chain.service.ts"() {
8891
+ init_sensor_decorator();
8889
8892
  init_axis_sensor();
8890
8893
  init_axis_observation();
8891
8894
  AxisSensorChainService = class {
@@ -8928,6 +8931,9 @@ var init_axis_sensor_chain_service = __esm({
8928
8931
  async evaluateSensors(sensors, input, baseDecision) {
8929
8932
  const relevantSensors = [];
8930
8933
  for (const sensor of sensors) {
8934
+ if (!this.matchesProofKind(sensor, input)) {
8935
+ continue;
8936
+ }
8931
8937
  if (!sensor.supports) {
8932
8938
  relevantSensors.push(sensor);
8933
8939
  continue;
@@ -9027,6 +9033,28 @@ var init_axis_sensor_chain_service = __esm({
9027
9033
  } : void 0
9028
9034
  };
9029
9035
  }
9036
+ matchesProofKind(sensor, input) {
9037
+ const meta = Reflect.getMetadata(
9038
+ SENSOR_METADATA_KEY,
9039
+ sensor.constructor
9040
+ );
9041
+ if (!meta || meta === true) return true;
9042
+ const currentProofKinds = this.normalizeProofKinds(
9043
+ input.metadata?.proofKind ?? input.requiredProof
9044
+ );
9045
+ const excludedProofKinds = this.normalizeProofKinds(meta.excludeProofKind);
9046
+ if (excludedProofKinds.length > 0 && currentProofKinds.some((kind) => excludedProofKinds.includes(kind))) {
9047
+ return false;
9048
+ }
9049
+ const requiredProofKinds = this.normalizeProofKinds(meta.proofKind);
9050
+ if (requiredProofKinds.length === 0) return true;
9051
+ return currentProofKinds.some((kind) => requiredProofKinds.includes(kind));
9052
+ }
9053
+ normalizeProofKinds(value) {
9054
+ if (value === void 0 || value === null) return [];
9055
+ const items = Array.isArray(value) ? value : [value];
9056
+ return items.map((item) => String(item).trim().toUpperCase()).filter(Boolean);
9057
+ }
9030
9058
  };
9031
9059
  }
9032
9060
  });
@@ -9400,10 +9428,11 @@ var init_timeline_store = __esm({
9400
9428
  });
9401
9429
 
9402
9430
  // src/utils/axis-tlv-codec.ts
9403
- function encodeAxisTlvDto(dtoClass, data) {
9431
+ function encodeAxisTlvDto(dtoClass, data, context = {}) {
9404
9432
  const schema = (0, import_dto_schema2.extractDtoSchema)(dtoClass);
9405
9433
  const items = schema.fields.flatMap((field) => {
9406
9434
  const value = data[field.name];
9435
+ if (!shouldEncodeField(field, value, data, context)) return [];
9407
9436
  if (value === void 0 || value === null) {
9408
9437
  if (field.required) {
9409
9438
  throw new Error(`Missing required TLV response field: ${field.name}`);
@@ -9414,6 +9443,42 @@ function encodeAxisTlvDto(dtoClass, data) {
9414
9443
  });
9415
9444
  return buildTLVs(items);
9416
9445
  }
9446
+ function projectAxisTlvDto(dtoClass, data, context = {}) {
9447
+ const schema = (0, import_dto_schema2.extractDtoSchema)(dtoClass);
9448
+ const result = {};
9449
+ for (const field of schema.fields) {
9450
+ const value = data[field.name];
9451
+ if (!shouldEncodeField(field, value, data, context)) continue;
9452
+ if (value === void 0 || value === null) continue;
9453
+ result[field.name] = value;
9454
+ }
9455
+ return result;
9456
+ }
9457
+ function shouldEncodeField(field, value, data, context) {
9458
+ const rule = field.encode;
9459
+ if (rule === void 0) return true;
9460
+ if (rule === false) return false;
9461
+ if (rule.onlyRoles?.length && !hasAnyRole(context, rule.onlyRoles)) {
9462
+ return false;
9463
+ }
9464
+ if (rule.exceptRoles?.length && hasAnyRole(context, rule.exceptRoles)) {
9465
+ return false;
9466
+ }
9467
+ if (rule.policy) {
9468
+ const policy = context.policies?.[rule.policy];
9469
+ if (!policy) {
9470
+ throw new Error(`Missing TLV encode policy: ${rule.policy}`);
9471
+ }
9472
+ if (!policy({ field, value, data, context })) {
9473
+ return false;
9474
+ }
9475
+ }
9476
+ return true;
9477
+ }
9478
+ function hasAnyRole(context, expectedRoles) {
9479
+ const actualRoles = context.roles ?? [];
9480
+ return expectedRoles.some((role) => actualRoles.includes(role));
9481
+ }
9417
9482
  function encodeField(field, value) {
9418
9483
  switch (field.kind) {
9419
9484
  case "utf8":
@@ -13428,6 +13493,7 @@ __export(index_exports, {
13428
13493
  parseScope: () => parseScope,
13429
13494
  parseStreamEntries: () => parseStreamEntries,
13430
13495
  projectAt: () => projectAt,
13496
+ projectAxisTlvDto: () => projectAxisTlvDto,
13431
13497
  queryFabric: () => queryFabric,
13432
13498
  recordOccurrence: () => recordOccurrence,
13433
13499
  recordSensor: () => recordSensor,
@@ -13834,6 +13900,7 @@ export {
13834
13900
  parseScope,
13835
13901
  parseStreamEntries,
13836
13902
  projectAt,
13903
+ projectAxisTlvDto,
13837
13904
  queryFabric,
13838
13905
  recordOccurrence,
13839
13906
  recordSensor,