@nextera.one/axis-server-sdk 2.2.2 → 2.2.4

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.
@@ -593,17 +593,76 @@ var init_intent_policy_decorator = __esm({
593
593
  }
594
594
  });
595
595
 
596
- // src/decorators/handler.decorator.ts
596
+ // src/decorators/handler-sensors.decorator.ts
597
597
  import "reflect-metadata";
598
- function Handler(intent) {
598
+ function HandlerSensors(sensors) {
599
599
  return (target) => {
600
- Reflect.defineMetadata(HANDLER_METADATA_KEY, { intent }, target);
600
+ Reflect.defineMetadata(HANDLER_SENSORS_KEY, sensors, target);
601
601
  };
602
602
  }
603
- var HANDLER_METADATA_KEY;
604
- var init_handler_decorator = __esm({
605
- "src/decorators/handler.decorator.ts"() {
606
- HANDLER_METADATA_KEY = "axis:handler";
603
+ var HANDLER_SENSORS_KEY;
604
+ var init_handler_sensors_decorator = __esm({
605
+ "src/decorators/handler-sensors.decorator.ts"() {
606
+ HANDLER_SENSORS_KEY = "axis:handler:sensors";
607
+ }
608
+ });
609
+
610
+ // src/decorators/observer.decorator.ts
611
+ import "reflect-metadata";
612
+ function isBindingOptions(value) {
613
+ return !!value && typeof value === "object" && "use" in value;
614
+ }
615
+ function isDefinitionOptions(value) {
616
+ return !!value && typeof value === "object" && !Array.isArray(value) && !isBindingOptions(value);
617
+ }
618
+ function toObserverBinding(input) {
619
+ if (!input) return null;
620
+ if (isBindingOptions(input)) {
621
+ const refs = Array.isArray(input.use) ? input.use : [input.use];
622
+ return { refs, tags: input.tags, events: input.events };
623
+ }
624
+ if (Array.isArray(input)) {
625
+ return { refs: input };
626
+ }
627
+ if (typeof input === "function" || typeof input === "string") {
628
+ return { refs: [input] };
629
+ }
630
+ return null;
631
+ }
632
+ function Observer(input) {
633
+ return ((target, propertyKey) => {
634
+ const binding = toObserverBinding(input);
635
+ if (binding) {
636
+ if (propertyKey !== void 0) {
637
+ const existing2 = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target, propertyKey) || [];
638
+ existing2.push(binding);
639
+ Reflect.defineMetadata(
640
+ OBSERVER_BINDINGS_KEY,
641
+ existing2,
642
+ target,
643
+ propertyKey
644
+ );
645
+ return;
646
+ }
647
+ const existing = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target) || [];
648
+ existing.push(binding);
649
+ Reflect.defineMetadata(OBSERVER_BINDINGS_KEY, existing, target);
650
+ return;
651
+ }
652
+ if (propertyKey !== void 0) {
653
+ throw new Error(
654
+ "@Observer method usage must reference one or more observer classes or names"
655
+ );
656
+ }
657
+ const definition = isDefinitionOptions(input) ? input : {};
658
+ Reflect.defineMetadata(OBSERVER_METADATA_KEY, definition, target);
659
+ });
660
+ }
661
+ var OBSERVER_METADATA_KEY, OBSERVER_BINDINGS_KEY;
662
+ var init_observer_decorator = __esm({
663
+ "src/decorators/observer.decorator.ts"() {
664
+ OBSERVER_METADATA_KEY = "axis:observer";
665
+ OBSERVER_BINDINGS_KEY = "axis:observer:bindings";
607
666
  }
608
667
  });
609
668
 
@@ -623,6 +682,21 @@ var init_intent_body_decorator = __esm({
623
682
 
624
683
  // src/decorators/intent.decorator.ts
625
684
  import "reflect-metadata";
685
+ function isIntentSensorBindingOptions(value) {
686
+ return !!value && typeof value === "object" && !Array.isArray(value) && "use" in value;
687
+ }
688
+ function toIntentSensorBinding(input) {
689
+ if (isIntentSensorBindingOptions(input)) {
690
+ return {
691
+ ref: input.use,
692
+ when: input.when || "before"
693
+ };
694
+ }
695
+ return {
696
+ ref: input,
697
+ when: "before"
698
+ };
699
+ }
626
700
  function Intent(action, options) {
627
701
  return (target, propertyKey) => {
628
702
  const metadata = { intent: action, ...options };
@@ -670,176 +744,62 @@ var init_intent_decorator = __esm({
670
744
  }
671
745
  });
672
746
 
673
- // src/decorators/intent-sensors.decorator.ts
674
- import "reflect-metadata";
675
- function IntentSensors(sensors) {
676
- return (target, propertyKey) => {
677
- Reflect.defineMetadata(INTENT_SENSORS_KEY, sensors, target, propertyKey);
678
- };
679
- }
680
- var INTENT_SENSORS_KEY;
681
- var init_intent_sensors_decorator = __esm({
682
- "src/decorators/intent-sensors.decorator.ts"() {
683
- INTENT_SENSORS_KEY = "axis:intent:sensors";
684
- }
685
- });
686
-
687
- // src/decorators/observer.decorator.ts
747
+ // src/decorators/handler.decorator.ts
688
748
  import "reflect-metadata";
689
- function isBindingOptions(value) {
690
- return !!value && typeof value === "object" && "use" in value;
691
- }
692
- function isDefinitionOptions(value) {
693
- return !!value && typeof value === "object" && !Array.isArray(value) && !isBindingOptions(value);
694
- }
695
- function toBinding(input) {
696
- if (!input) return null;
697
- if (isBindingOptions(input)) {
698
- const refs = Array.isArray(input.use) ? input.use : [input.use];
699
- return { refs, tags: input.tags, events: input.events };
700
- }
701
- if (Array.isArray(input)) {
702
- return { refs: input };
703
- }
704
- if (typeof input === "function" || typeof input === "string") {
705
- return { refs: [input] };
706
- }
707
- return null;
708
- }
709
- function Observer(input) {
710
- return ((target, propertyKey) => {
711
- const binding = toBinding(input);
712
- if (binding) {
713
- if (propertyKey !== void 0) {
714
- const existing2 = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target, propertyKey) || [];
715
- existing2.push(binding);
716
- Reflect.defineMetadata(
717
- OBSERVER_BINDINGS_KEY,
718
- existing2,
719
- target,
720
- propertyKey
721
- );
722
- return;
723
- }
724
- const existing = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target) || [];
725
- existing.push(binding);
726
- Reflect.defineMetadata(OBSERVER_BINDINGS_KEY, existing, target);
727
- return;
749
+ function Handler(intentOrOptions, options) {
750
+ return (target) => {
751
+ const intent = typeof intentOrOptions === "string" ? intentOrOptions : void 0;
752
+ const handlerOptions = typeof intentOrOptions === "string" ? options : intentOrOptions;
753
+ const sensorBindings = Array.isArray(handlerOptions?.is) ? handlerOptions.is.map(
754
+ (input) => toIntentSensorBinding(input)
755
+ ) : [];
756
+ const observerBindings = Array.isArray(
757
+ handlerOptions?.observe
758
+ ) ? handlerOptions.observe.map((input) => toObserverBinding(input)).filter((binding) => !!binding) : [];
759
+ Reflect.defineMetadata(
760
+ HANDLER_METADATA_KEY,
761
+ { intent, ...handlerOptions || {} },
762
+ target
763
+ );
764
+ if (sensorBindings.length > 0) {
765
+ const existing = Reflect.getMetadata(HANDLER_SENSORS_KEY, target) || [];
766
+ Reflect.defineMetadata(
767
+ HANDLER_SENSORS_KEY,
768
+ [...existing, ...sensorBindings],
769
+ target
770
+ );
728
771
  }
729
- if (propertyKey !== void 0) {
730
- throw new Error(
731
- "@Observer method usage must reference one or more observer classes or names"
772
+ if (observerBindings.length > 0) {
773
+ const existing = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target) || [];
774
+ Reflect.defineMetadata(
775
+ OBSERVER_BINDINGS_KEY,
776
+ [...existing, ...observerBindings],
777
+ target
732
778
  );
733
779
  }
734
- const definition = isDefinitionOptions(input) ? input : {};
735
- Reflect.defineMetadata(OBSERVER_METADATA_KEY, definition, target);
736
- });
780
+ };
737
781
  }
738
- var OBSERVER_METADATA_KEY, OBSERVER_BINDINGS_KEY;
739
- var init_observer_decorator = __esm({
740
- "src/decorators/observer.decorator.ts"() {
741
- OBSERVER_METADATA_KEY = "axis:observer";
742
- OBSERVER_BINDINGS_KEY = "axis:observer:bindings";
782
+ var HANDLER_METADATA_KEY;
783
+ var init_handler_decorator = __esm({
784
+ "src/decorators/handler.decorator.ts"() {
785
+ init_handler_sensors_decorator();
786
+ init_observer_decorator();
787
+ init_intent_decorator();
788
+ HANDLER_METADATA_KEY = "axis:handler";
743
789
  }
744
790
  });
745
791
 
746
- // src/decorators/handler-sensors.decorator.ts
792
+ // src/decorators/intent-sensors.decorator.ts
747
793
  import "reflect-metadata";
748
- function HandlerSensors(sensors) {
749
- return (target) => {
750
- Reflect.defineMetadata(HANDLER_SENSORS_KEY, sensors, target);
794
+ function IntentSensors(sensors) {
795
+ return (target, propertyKey) => {
796
+ Reflect.defineMetadata(INTENT_SENSORS_KEY, sensors, target, propertyKey);
751
797
  };
752
798
  }
753
- var HANDLER_SENSORS_KEY;
754
- var init_handler_sensors_decorator = __esm({
755
- "src/decorators/handler-sensors.decorator.ts"() {
756
- HANDLER_SENSORS_KEY = "axis:handler:sensors";
757
- }
758
- });
759
-
760
- // src/decorators/priority-order.decorator.ts
761
- var require_priority_order_decorator = __commonJS({
762
- "src/decorators/priority-order.decorator.ts"(exports) {
763
- "use strict";
764
- Object.defineProperty(exports, "__esModule", { value: true });
765
- exports.priorityOrder = exports.PRIORITY_ORDER_METADATA_KEY = void 0;
766
- exports.getPriorityOrder = getPriorityOrder2;
767
- exports.comparePriorityOrder = comparePriorityOrder2;
768
- exports.getPriorityOrderedTargets = getPriorityOrderedTargets2;
769
- exports.PriorityOrder = PriorityOrder2;
770
- __require("reflect-metadata");
771
- exports.PRIORITY_ORDER_METADATA_KEY = "axis:priority-order";
772
- var PRIORITY_ORDER_WEIGHT = {
773
- HIGH: 0,
774
- MEDIUM: 1,
775
- LOW: 2
776
- };
777
- var priorityOrderRegistry = /* @__PURE__ */ new Set();
778
- function normalizePriority(priority) {
779
- const normalized = String(priority).toUpperCase();
780
- if (normalized === "HIGH" || normalized === "MEDIUM" || normalized === "LOW") {
781
- return normalized;
782
- }
783
- throw new Error(`@PriorityOrder() received invalid priority "${String(priority)}"`);
784
- }
785
- function normalizeOrder(order) {
786
- if (typeof order !== "number" || !Number.isInteger(order) || !Number.isFinite(order) || order < 0) {
787
- throw new Error(`@PriorityOrder() requires a non-negative integer order, received "${String(order)}"`);
788
- }
789
- return order;
790
- }
791
- function isPriorityOrderOptions(value) {
792
- return !!value && typeof value === "object" && !Array.isArray(value);
793
- }
794
- function resolvePriorityOrder(priorityOrOptions, order = 0) {
795
- if (isPriorityOrderOptions(priorityOrOptions)) {
796
- return {
797
- priority: normalizePriority(priorityOrOptions.priority ?? "MEDIUM"),
798
- order: normalizeOrder(priorityOrOptions.order ?? 0)
799
- };
800
- }
801
- return {
802
- priority: normalizePriority(priorityOrOptions ?? "MEDIUM"),
803
- order: normalizeOrder(order)
804
- };
805
- }
806
- function getPriorityOrder2(target) {
807
- return Reflect.getMetadata(exports.PRIORITY_ORDER_METADATA_KEY, target) ?? null;
808
- }
809
- function comparePriorityOrder2(left, right) {
810
- const priorityDelta = PRIORITY_ORDER_WEIGHT[left.priority] - PRIORITY_ORDER_WEIGHT[right.priority];
811
- if (priorityDelta !== 0) {
812
- return priorityDelta;
813
- }
814
- return left.order - right.order;
815
- }
816
- function getPriorityOrderedTargets2(targets) {
817
- const pool = targets ? Array.from(targets) : Array.from(priorityOrderRegistry);
818
- return pool.sort((left, right) => {
819
- const leftMeta = getPriorityOrder2(left);
820
- const rightMeta = getPriorityOrder2(right);
821
- if (!leftMeta && !rightMeta) {
822
- return (left.name || "").localeCompare(right.name || "");
823
- }
824
- if (!leftMeta)
825
- return 1;
826
- if (!rightMeta)
827
- return -1;
828
- const ordered = comparePriorityOrder2(leftMeta, rightMeta);
829
- if (ordered !== 0) {
830
- return ordered;
831
- }
832
- return (left.name || "").localeCompare(right.name || "");
833
- });
834
- }
835
- function PriorityOrder2(priorityOrOptions, order = 0) {
836
- const definition = resolvePriorityOrder(priorityOrOptions, order);
837
- return (target) => {
838
- Reflect.defineMetadata(exports.PRIORITY_ORDER_METADATA_KEY, definition, target);
839
- priorityOrderRegistry.add(target);
840
- };
841
- }
842
- exports.priorityOrder = PriorityOrder2;
799
+ var INTENT_SENSORS_KEY;
800
+ var init_intent_sensors_decorator = __esm({
801
+ "src/decorators/intent-sensors.decorator.ts"() {
802
+ INTENT_SENSORS_KEY = "axis:intent:sensors";
843
803
  }
844
804
  });
845
805
 
@@ -2558,15 +2518,19 @@ function observerRefKey(ref) {
2558
2518
  function sensorRefKey(ref) {
2559
2519
  return typeof ref === "string" ? ref : ref.name;
2560
2520
  }
2561
- function mergeIntentSensorRefs(...sensorGroups) {
2521
+ function sensorBindingKey(binding) {
2522
+ return `${binding.when}:${sensorRefKey(binding.ref)}`;
2523
+ }
2524
+ function mergeIntentSensorBindings(...sensorGroups) {
2562
2525
  const merged = /* @__PURE__ */ new Map();
2563
2526
  for (const group of sensorGroups) {
2564
2527
  if (!Array.isArray(group)) continue;
2565
- for (const ref of group) {
2566
- const key = sensorRefKey(ref);
2528
+ for (const input of group) {
2529
+ const binding = toIntentSensorBinding(input);
2530
+ const key = sensorBindingKey(binding);
2567
2531
  const existing = merged.get(key);
2568
- if (!existing || typeof existing === "string" && typeof ref !== "string") {
2569
- merged.set(key, ref);
2532
+ if (!existing || typeof existing.ref === "string" && typeof binding.ref !== "string") {
2533
+ merged.set(key, binding);
2570
2534
  }
2571
2535
  }
2572
2536
  }
@@ -2869,9 +2833,9 @@ var init_intent_router = __esm({
2869
2833
  if (!handler) {
2870
2834
  throw new Error(`Intent not found: ${intent}`);
2871
2835
  }
2872
- const sensorRefs = this.intentSensors.get(intent);
2873
- if (sensorRefs && sensorRefs.length > 0) {
2874
- await this.runIntentSensors(sensorRefs, intent, frame);
2836
+ const sensorBindings = this.intentSensors.get(intent);
2837
+ if (sensorBindings && sensorBindings.length > 0) {
2838
+ await this.runIntentSensors(sensorBindings, intent, frame, "before");
2875
2839
  }
2876
2840
  const decoder = this.intentDecoders.get(intent);
2877
2841
  let decodedBody = frame.body;
@@ -2913,6 +2877,12 @@ var init_intent_router = __esm({
2913
2877
  );
2914
2878
  }
2915
2879
  }
2880
+ if (sensorBindings && sensorBindings.length > 0) {
2881
+ await this.runIntentSensors(sensorBindings, intent, frame, "after", {
2882
+ decodedBody,
2883
+ effect
2884
+ });
2885
+ }
2916
2886
  }
2917
2887
  await this.emitIntentObservers(observerBindings, {
2918
2888
  event: "intent.completed",
@@ -2956,7 +2926,7 @@ var init_intent_router = __esm({
2956
2926
  methodName
2957
2927
  );
2958
2928
  const meta = Reflect.getMetadata(INTENT_METADATA_KEY, proto, methodName);
2959
- const combined = mergeIntentSensorRefs(
2929
+ const combined = mergeIntentSensorBindings(
2960
2930
  handlerSensors,
2961
2931
  Array.isArray(intentSensors) ? intentSensors : void 0,
2962
2932
  Array.isArray(meta?.is) ? meta.is : void 0
@@ -3098,8 +3068,10 @@ var init_intent_router = __esm({
3098
3068
  if (!this.observerDispatcher || bindings.length === 0) return;
3099
3069
  await this.observerDispatcher.dispatch(bindings, context);
3100
3070
  }
3101
- async runIntentSensors(sensorRefs, intent, frame) {
3102
- for (const sensorRef of sensorRefs) {
3071
+ async runIntentSensors(sensorBindings, intent, frame, stage, extras) {
3072
+ for (const binding of sensorBindings) {
3073
+ if (binding.when !== stage && binding.when !== "both") continue;
3074
+ const sensorRef = binding.ref;
3103
3075
  const sensor = this.resolveIntentSensor(sensorRef);
3104
3076
  const sensorName = sensorRefKey(sensorRef);
3105
3077
  if (!sensor) {
@@ -3116,9 +3088,12 @@ var init_intent_router = __esm({
3116
3088
  frameBody: frame.body,
3117
3089
  metadata: {
3118
3090
  phase: "intent",
3091
+ stage,
3119
3092
  intent,
3120
3093
  schema: this.getSchema(intent),
3121
- validators: this.getValidators(intent)
3094
+ validators: this.getValidators(intent),
3095
+ decodedBody: extras?.decodedBody,
3096
+ effect: extras?.effect
3122
3097
  }
3123
3098
  };
3124
3099
  if (sensor.supports && !sensor.supports(sensorInput)) continue;
@@ -10580,7 +10555,6 @@ __export(index_exports, {
10580
10555
  ObserverDispatcherService: () => ObserverDispatcherService,
10581
10556
  ObserverRegistry: () => ObserverRegistry,
10582
10557
  PRE_DECODE_BOUNDARY: () => PRE_DECODE_BOUNDARY,
10583
- PRIORITY_ORDER_METADATA_KEY: () => import_priority_order.PRIORITY_ORDER_METADATA_KEY,
10584
10558
  PROOF_CAPABILITIES: () => PROOF_CAPABILITIES,
10585
10559
  PROOF_CAPSULE: () => PROOF_CAPSULE,
10586
10560
  PROOF_JWT: () => PROOF_JWT,
@@ -10588,7 +10562,6 @@ __export(index_exports, {
10588
10562
  PROOF_MTLS: () => PROOF_MTLS,
10589
10563
  PROOF_NONE: () => PROOF_NONE,
10590
10564
  PROOF_WITNESS: () => PROOF_WITNESS,
10591
- PriorityOrder: () => import_priority_order.PriorityOrder,
10592
10565
  ProofType: () => ProofType,
10593
10566
  ProofVerificationService: () => ProofVerificationService,
10594
10567
  REQUIRED_PROOF_METADATA_KEY: () => REQUIRED_PROOF_METADATA_KEY,
@@ -10680,7 +10653,6 @@ __export(index_exports, {
10680
10653
  canonicalizeObservation: () => canonicalizeObservation,
10681
10654
  canonicalizeWrit: () => canonicalizeWrit,
10682
10655
  classifyIntent: () => classifyIntent,
10683
- comparePriorityOrder: () => import_priority_order.comparePriorityOrder,
10684
10656
  computeReceiptHash: () => computeReceiptHash,
10685
10657
  computeSignaturePayload: () => computeSignaturePayload,
10686
10658
  createFabric: () => createFabric,
@@ -10725,8 +10697,6 @@ __export(index_exports, {
10725
10697
  getGrantStatus: () => getGrantStatus,
10726
10698
  getIrreversibleKnots: () => getIrreversibleKnots,
10727
10699
  getPresenceStatus: () => getPresenceStatus,
10728
- getPriorityOrder: () => import_priority_order.getPriorityOrder,
10729
- getPriorityOrderedTargets: () => import_priority_order.getPriorityOrderedTargets,
10730
10700
  getSignTarget: () => getSignTarget,
10731
10701
  grantCoversAction: () => grantCoversAction,
10732
10702
  hasScope: () => hasScope,
@@ -10751,7 +10721,6 @@ __export(index_exports, {
10751
10721
  parseAutoClaimEntries: () => parseAutoClaimEntries,
10752
10722
  parseScope: () => parseScope,
10753
10723
  parseStreamEntries: () => parseStreamEntries,
10754
- priorityOrder: () => import_priority_order.priorityOrder,
10755
10724
  projectAt: () => projectAt,
10756
10725
  queryFabric: () => queryFabric,
10757
10726
  recordOccurrence: () => recordOccurrence,
@@ -10768,6 +10737,8 @@ __export(index_exports, {
10768
10737
  startStage: () => startStage,
10769
10738
  tieKnot: () => tieKnot,
10770
10739
  tlv: () => tlv,
10740
+ toIntentSensorBinding: () => toIntentSensorBinding,
10741
+ toObserverBinding: () => toObserverBinding,
10771
10742
  u64be: () => u64be,
10772
10743
  unpackPasskeyLoginOptionsReq: () => unpackPasskeyLoginOptionsReq,
10773
10744
  unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
@@ -10788,7 +10759,7 @@ __export(index_exports, {
10788
10759
  weave: () => weave,
10789
10760
  withAxisExecutionContext: () => withAxisExecutionContext
10790
10761
  });
10791
- var import_priority_order, import_tlv_field2, import_dto_schema2, import_axis_id, import_axis_response;
10762
+ var import_tlv_field2, import_dto_schema2, import_axis_id, import_axis_response;
10792
10763
  var init_index = __esm({
10793
10764
  "src/index.ts"() {
10794
10765
  init_chain_decorator();
@@ -10799,9 +10770,9 @@ var init_index = __esm({
10799
10770
  init_intent_body_decorator();
10800
10771
  init_intent_sensors_decorator();
10801
10772
  init_observer_decorator();
10773
+ init_observer_decorator();
10802
10774
  init_handler_sensors_decorator();
10803
10775
  init_sensor_decorator();
10804
- import_priority_order = __toESM(require_priority_order_decorator());
10805
10776
  import_tlv_field2 = __toESM(require_tlv_field_decorator());
10806
10777
  import_dto_schema2 = __toESM(require_dto_schema_util());
10807
10778
  init_axis_tlv_dto();