@nextera.one/axis-server-sdk 2.2.3 → 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,90 +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";
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";
757
803
  }
758
804
  });
759
805
 
@@ -2472,15 +2518,19 @@ function observerRefKey(ref) {
2472
2518
  function sensorRefKey(ref) {
2473
2519
  return typeof ref === "string" ? ref : ref.name;
2474
2520
  }
2475
- function mergeIntentSensorRefs(...sensorGroups) {
2521
+ function sensorBindingKey(binding) {
2522
+ return `${binding.when}:${sensorRefKey(binding.ref)}`;
2523
+ }
2524
+ function mergeIntentSensorBindings(...sensorGroups) {
2476
2525
  const merged = /* @__PURE__ */ new Map();
2477
2526
  for (const group of sensorGroups) {
2478
2527
  if (!Array.isArray(group)) continue;
2479
- for (const ref of group) {
2480
- const key = sensorRefKey(ref);
2528
+ for (const input of group) {
2529
+ const binding = toIntentSensorBinding(input);
2530
+ const key = sensorBindingKey(binding);
2481
2531
  const existing = merged.get(key);
2482
- if (!existing || typeof existing === "string" && typeof ref !== "string") {
2483
- merged.set(key, ref);
2532
+ if (!existing || typeof existing.ref === "string" && typeof binding.ref !== "string") {
2533
+ merged.set(key, binding);
2484
2534
  }
2485
2535
  }
2486
2536
  }
@@ -2783,9 +2833,9 @@ var init_intent_router = __esm({
2783
2833
  if (!handler) {
2784
2834
  throw new Error(`Intent not found: ${intent}`);
2785
2835
  }
2786
- const sensorRefs = this.intentSensors.get(intent);
2787
- if (sensorRefs && sensorRefs.length > 0) {
2788
- 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");
2789
2839
  }
2790
2840
  const decoder = this.intentDecoders.get(intent);
2791
2841
  let decodedBody = frame.body;
@@ -2827,6 +2877,12 @@ var init_intent_router = __esm({
2827
2877
  );
2828
2878
  }
2829
2879
  }
2880
+ if (sensorBindings && sensorBindings.length > 0) {
2881
+ await this.runIntentSensors(sensorBindings, intent, frame, "after", {
2882
+ decodedBody,
2883
+ effect
2884
+ });
2885
+ }
2830
2886
  }
2831
2887
  await this.emitIntentObservers(observerBindings, {
2832
2888
  event: "intent.completed",
@@ -2870,7 +2926,7 @@ var init_intent_router = __esm({
2870
2926
  methodName
2871
2927
  );
2872
2928
  const meta = Reflect.getMetadata(INTENT_METADATA_KEY, proto, methodName);
2873
- const combined = mergeIntentSensorRefs(
2929
+ const combined = mergeIntentSensorBindings(
2874
2930
  handlerSensors,
2875
2931
  Array.isArray(intentSensors) ? intentSensors : void 0,
2876
2932
  Array.isArray(meta?.is) ? meta.is : void 0
@@ -3012,8 +3068,10 @@ var init_intent_router = __esm({
3012
3068
  if (!this.observerDispatcher || bindings.length === 0) return;
3013
3069
  await this.observerDispatcher.dispatch(bindings, context);
3014
3070
  }
3015
- async runIntentSensors(sensorRefs, intent, frame) {
3016
- 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;
3017
3075
  const sensor = this.resolveIntentSensor(sensorRef);
3018
3076
  const sensorName = sensorRefKey(sensorRef);
3019
3077
  if (!sensor) {
@@ -3030,9 +3088,12 @@ var init_intent_router = __esm({
3030
3088
  frameBody: frame.body,
3031
3089
  metadata: {
3032
3090
  phase: "intent",
3091
+ stage,
3033
3092
  intent,
3034
3093
  schema: this.getSchema(intent),
3035
- validators: this.getValidators(intent)
3094
+ validators: this.getValidators(intent),
3095
+ decodedBody: extras?.decodedBody,
3096
+ effect: extras?.effect
3036
3097
  }
3037
3098
  };
3038
3099
  if (sensor.supports && !sensor.supports(sensorInput)) continue;
@@ -10676,6 +10737,8 @@ __export(index_exports, {
10676
10737
  startStage: () => startStage,
10677
10738
  tieKnot: () => tieKnot,
10678
10739
  tlv: () => tlv,
10740
+ toIntentSensorBinding: () => toIntentSensorBinding,
10741
+ toObserverBinding: () => toObserverBinding,
10679
10742
  u64be: () => u64be,
10680
10743
  unpackPasskeyLoginOptionsReq: () => unpackPasskeyLoginOptionsReq,
10681
10744
  unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
@@ -10707,6 +10770,7 @@ var init_index = __esm({
10707
10770
  init_intent_body_decorator();
10708
10771
  init_intent_sensors_decorator();
10709
10772
  init_observer_decorator();
10773
+ init_observer_decorator();
10710
10774
  init_handler_sensors_decorator();
10711
10775
  init_sensor_decorator();
10712
10776
  import_tlv_field2 = __toESM(require_tlv_field_decorator());