@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.
package/dist/index.js CHANGED
@@ -267,17 +267,76 @@ var init_intent_policy_decorator = __esm({
267
267
  }
268
268
  });
269
269
 
270
- // src/decorators/handler.decorator.ts
271
- function Handler(intent) {
270
+ // src/decorators/handler-sensors.decorator.ts
271
+ function HandlerSensors(sensors) {
272
272
  return (target) => {
273
- Reflect.defineMetadata(HANDLER_METADATA_KEY, { intent }, target);
273
+ Reflect.defineMetadata(HANDLER_SENSORS_KEY, sensors, target);
274
274
  };
275
275
  }
276
- var import_reflect_metadata4, HANDLER_METADATA_KEY;
277
- var init_handler_decorator = __esm({
278
- "src/decorators/handler.decorator.ts"() {
276
+ var import_reflect_metadata4, HANDLER_SENSORS_KEY;
277
+ var init_handler_sensors_decorator = __esm({
278
+ "src/decorators/handler-sensors.decorator.ts"() {
279
279
  import_reflect_metadata4 = require("reflect-metadata");
280
- HANDLER_METADATA_KEY = "axis:handler";
280
+ HANDLER_SENSORS_KEY = "axis:handler:sensors";
281
+ }
282
+ });
283
+
284
+ // src/decorators/observer.decorator.ts
285
+ function isBindingOptions(value) {
286
+ return !!value && typeof value === "object" && "use" in value;
287
+ }
288
+ function isDefinitionOptions(value) {
289
+ return !!value && typeof value === "object" && !Array.isArray(value) && !isBindingOptions(value);
290
+ }
291
+ function toObserverBinding(input) {
292
+ if (!input) return null;
293
+ if (isBindingOptions(input)) {
294
+ const refs = Array.isArray(input.use) ? input.use : [input.use];
295
+ return { refs, tags: input.tags, events: input.events };
296
+ }
297
+ if (Array.isArray(input)) {
298
+ return { refs: input };
299
+ }
300
+ if (typeof input === "function" || typeof input === "string") {
301
+ return { refs: [input] };
302
+ }
303
+ return null;
304
+ }
305
+ function Observer(input) {
306
+ return ((target, propertyKey) => {
307
+ const binding = toObserverBinding(input);
308
+ if (binding) {
309
+ if (propertyKey !== void 0) {
310
+ const existing2 = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target, propertyKey) || [];
311
+ existing2.push(binding);
312
+ Reflect.defineMetadata(
313
+ OBSERVER_BINDINGS_KEY,
314
+ existing2,
315
+ target,
316
+ propertyKey
317
+ );
318
+ return;
319
+ }
320
+ const existing = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target) || [];
321
+ existing.push(binding);
322
+ Reflect.defineMetadata(OBSERVER_BINDINGS_KEY, existing, target);
323
+ return;
324
+ }
325
+ if (propertyKey !== void 0) {
326
+ throw new Error(
327
+ "@Observer method usage must reference one or more observer classes or names"
328
+ );
329
+ }
330
+ const definition = isDefinitionOptions(input) ? input : {};
331
+ Reflect.defineMetadata(OBSERVER_METADATA_KEY, definition, target);
332
+ });
333
+ }
334
+ var import_reflect_metadata5, OBSERVER_METADATA_KEY, OBSERVER_BINDINGS_KEY;
335
+ var init_observer_decorator = __esm({
336
+ "src/decorators/observer.decorator.ts"() {
337
+ import_reflect_metadata5 = require("reflect-metadata");
338
+ OBSERVER_METADATA_KEY = "axis:observer";
339
+ OBSERVER_BINDINGS_KEY = "axis:observer:bindings";
281
340
  }
282
341
  });
283
342
 
@@ -287,15 +346,30 @@ function IntentBody(decoder) {
287
346
  Reflect.defineMetadata(INTENT_BODY_KEY, decoder, target, propertyKey);
288
347
  };
289
348
  }
290
- var import_reflect_metadata5, INTENT_BODY_KEY;
349
+ var import_reflect_metadata6, INTENT_BODY_KEY;
291
350
  var init_intent_body_decorator = __esm({
292
351
  "src/decorators/intent-body.decorator.ts"() {
293
- import_reflect_metadata5 = require("reflect-metadata");
352
+ import_reflect_metadata6 = require("reflect-metadata");
294
353
  INTENT_BODY_KEY = "axis:intent:body";
295
354
  }
296
355
  });
297
356
 
298
357
  // src/decorators/intent.decorator.ts
358
+ function isIntentSensorBindingOptions(value) {
359
+ return !!value && typeof value === "object" && !Array.isArray(value) && "use" in value;
360
+ }
361
+ function toIntentSensorBinding(input) {
362
+ if (isIntentSensorBindingOptions(input)) {
363
+ return {
364
+ ref: input.use,
365
+ when: input.when || "before"
366
+ };
367
+ }
368
+ return {
369
+ ref: input,
370
+ when: "before"
371
+ };
372
+ }
299
373
  function Intent(action, options) {
300
374
  return (target, propertyKey) => {
301
375
  const metadata = { intent: action, ...options };
@@ -333,10 +407,10 @@ function Intent(action, options) {
333
407
  Reflect.defineMetadata(INTENT_ROUTES_KEY, routes, target.constructor);
334
408
  };
335
409
  }
336
- var import_reflect_metadata6, INTENT_METADATA_KEY, INTENT_ROUTES_KEY;
410
+ var import_reflect_metadata7, INTENT_METADATA_KEY, INTENT_ROUTES_KEY;
337
411
  var init_intent_decorator = __esm({
338
412
  "src/decorators/intent.decorator.ts"() {
339
- import_reflect_metadata6 = require("reflect-metadata");
413
+ import_reflect_metadata7 = require("reflect-metadata");
340
414
  init_intent_body_decorator();
341
415
  init_intent_policy_decorator();
342
416
  INTENT_METADATA_KEY = "axis:intent";
@@ -344,90 +418,62 @@ var init_intent_decorator = __esm({
344
418
  }
345
419
  });
346
420
 
347
- // src/decorators/intent-sensors.decorator.ts
348
- function IntentSensors(sensors) {
349
- return (target, propertyKey) => {
350
- Reflect.defineMetadata(INTENT_SENSORS_KEY, sensors, target, propertyKey);
351
- };
352
- }
353
- var import_reflect_metadata7, INTENT_SENSORS_KEY;
354
- var init_intent_sensors_decorator = __esm({
355
- "src/decorators/intent-sensors.decorator.ts"() {
356
- import_reflect_metadata7 = require("reflect-metadata");
357
- INTENT_SENSORS_KEY = "axis:intent:sensors";
358
- }
359
- });
360
-
361
- // src/decorators/observer.decorator.ts
362
- function isBindingOptions(value) {
363
- return !!value && typeof value === "object" && "use" in value;
364
- }
365
- function isDefinitionOptions(value) {
366
- return !!value && typeof value === "object" && !Array.isArray(value) && !isBindingOptions(value);
367
- }
368
- function toBinding(input) {
369
- if (!input) return null;
370
- if (isBindingOptions(input)) {
371
- const refs = Array.isArray(input.use) ? input.use : [input.use];
372
- return { refs, tags: input.tags, events: input.events };
373
- }
374
- if (Array.isArray(input)) {
375
- return { refs: input };
376
- }
377
- if (typeof input === "function" || typeof input === "string") {
378
- return { refs: [input] };
379
- }
380
- return null;
381
- }
382
- function Observer(input) {
383
- return ((target, propertyKey) => {
384
- const binding = toBinding(input);
385
- if (binding) {
386
- if (propertyKey !== void 0) {
387
- const existing2 = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target, propertyKey) || [];
388
- existing2.push(binding);
389
- Reflect.defineMetadata(
390
- OBSERVER_BINDINGS_KEY,
391
- existing2,
392
- target,
393
- propertyKey
394
- );
395
- return;
396
- }
397
- const existing = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target) || [];
398
- existing.push(binding);
399
- Reflect.defineMetadata(OBSERVER_BINDINGS_KEY, existing, target);
400
- return;
421
+ // src/decorators/handler.decorator.ts
422
+ function Handler(intentOrOptions, options) {
423
+ return (target) => {
424
+ const intent = typeof intentOrOptions === "string" ? intentOrOptions : void 0;
425
+ const handlerOptions = typeof intentOrOptions === "string" ? options : intentOrOptions;
426
+ const sensorBindings = Array.isArray(handlerOptions?.is) ? handlerOptions.is.map(
427
+ (input) => toIntentSensorBinding(input)
428
+ ) : [];
429
+ const observerBindings = Array.isArray(
430
+ handlerOptions?.observe
431
+ ) ? handlerOptions.observe.map((input) => toObserverBinding(input)).filter((binding) => !!binding) : [];
432
+ Reflect.defineMetadata(
433
+ HANDLER_METADATA_KEY,
434
+ { intent, ...handlerOptions || {} },
435
+ target
436
+ );
437
+ if (sensorBindings.length > 0) {
438
+ const existing = Reflect.getMetadata(HANDLER_SENSORS_KEY, target) || [];
439
+ Reflect.defineMetadata(
440
+ HANDLER_SENSORS_KEY,
441
+ [...existing, ...sensorBindings],
442
+ target
443
+ );
401
444
  }
402
- if (propertyKey !== void 0) {
403
- throw new Error(
404
- "@Observer method usage must reference one or more observer classes or names"
445
+ if (observerBindings.length > 0) {
446
+ const existing = Reflect.getMetadata(OBSERVER_BINDINGS_KEY, target) || [];
447
+ Reflect.defineMetadata(
448
+ OBSERVER_BINDINGS_KEY,
449
+ [...existing, ...observerBindings],
450
+ target
405
451
  );
406
452
  }
407
- const definition = isDefinitionOptions(input) ? input : {};
408
- Reflect.defineMetadata(OBSERVER_METADATA_KEY, definition, target);
409
- });
453
+ };
410
454
  }
411
- var import_reflect_metadata8, OBSERVER_METADATA_KEY, OBSERVER_BINDINGS_KEY;
412
- var init_observer_decorator = __esm({
413
- "src/decorators/observer.decorator.ts"() {
455
+ var import_reflect_metadata8, HANDLER_METADATA_KEY;
456
+ var init_handler_decorator = __esm({
457
+ "src/decorators/handler.decorator.ts"() {
414
458
  import_reflect_metadata8 = require("reflect-metadata");
415
- OBSERVER_METADATA_KEY = "axis:observer";
416
- OBSERVER_BINDINGS_KEY = "axis:observer:bindings";
459
+ init_handler_sensors_decorator();
460
+ init_observer_decorator();
461
+ init_intent_decorator();
462
+ HANDLER_METADATA_KEY = "axis:handler";
417
463
  }
418
464
  });
419
465
 
420
- // src/decorators/handler-sensors.decorator.ts
421
- function HandlerSensors(sensors) {
422
- return (target) => {
423
- Reflect.defineMetadata(HANDLER_SENSORS_KEY, sensors, target);
466
+ // src/decorators/intent-sensors.decorator.ts
467
+ function IntentSensors(sensors) {
468
+ return (target, propertyKey) => {
469
+ Reflect.defineMetadata(INTENT_SENSORS_KEY, sensors, target, propertyKey);
424
470
  };
425
471
  }
426
- var import_reflect_metadata9, HANDLER_SENSORS_KEY;
427
- var init_handler_sensors_decorator = __esm({
428
- "src/decorators/handler-sensors.decorator.ts"() {
472
+ var import_reflect_metadata9, INTENT_SENSORS_KEY;
473
+ var init_intent_sensors_decorator = __esm({
474
+ "src/decorators/intent-sensors.decorator.ts"() {
429
475
  import_reflect_metadata9 = require("reflect-metadata");
430
- HANDLER_SENSORS_KEY = "axis:handler:sensors";
476
+ INTENT_SENSORS_KEY = "axis:intent:sensors";
431
477
  }
432
478
  });
433
479
 
@@ -2254,15 +2300,19 @@ function observerRefKey(ref) {
2254
2300
  function sensorRefKey(ref) {
2255
2301
  return typeof ref === "string" ? ref : ref.name;
2256
2302
  }
2257
- function mergeIntentSensorRefs(...sensorGroups) {
2303
+ function sensorBindingKey(binding) {
2304
+ return `${binding.when}:${sensorRefKey(binding.ref)}`;
2305
+ }
2306
+ function mergeIntentSensorBindings(...sensorGroups) {
2258
2307
  const merged = /* @__PURE__ */ new Map();
2259
2308
  for (const group of sensorGroups) {
2260
2309
  if (!Array.isArray(group)) continue;
2261
- for (const ref of group) {
2262
- const key = sensorRefKey(ref);
2310
+ for (const input of group) {
2311
+ const binding = toIntentSensorBinding(input);
2312
+ const key = sensorBindingKey(binding);
2263
2313
  const existing = merged.get(key);
2264
- if (!existing || typeof existing === "string" && typeof ref !== "string") {
2265
- merged.set(key, ref);
2314
+ if (!existing || typeof existing.ref === "string" && typeof binding.ref !== "string") {
2315
+ merged.set(key, binding);
2266
2316
  }
2267
2317
  }
2268
2318
  }
@@ -2566,9 +2616,9 @@ var init_intent_router = __esm({
2566
2616
  if (!handler) {
2567
2617
  throw new Error(`Intent not found: ${intent}`);
2568
2618
  }
2569
- const sensorRefs = this.intentSensors.get(intent);
2570
- if (sensorRefs && sensorRefs.length > 0) {
2571
- await this.runIntentSensors(sensorRefs, intent, frame);
2619
+ const sensorBindings = this.intentSensors.get(intent);
2620
+ if (sensorBindings && sensorBindings.length > 0) {
2621
+ await this.runIntentSensors(sensorBindings, intent, frame, "before");
2572
2622
  }
2573
2623
  const decoder = this.intentDecoders.get(intent);
2574
2624
  let decodedBody = frame.body;
@@ -2610,6 +2660,12 @@ var init_intent_router = __esm({
2610
2660
  );
2611
2661
  }
2612
2662
  }
2663
+ if (sensorBindings && sensorBindings.length > 0) {
2664
+ await this.runIntentSensors(sensorBindings, intent, frame, "after", {
2665
+ decodedBody,
2666
+ effect
2667
+ });
2668
+ }
2613
2669
  }
2614
2670
  await this.emitIntentObservers(observerBindings, {
2615
2671
  event: "intent.completed",
@@ -2653,7 +2709,7 @@ var init_intent_router = __esm({
2653
2709
  methodName
2654
2710
  );
2655
2711
  const meta = Reflect.getMetadata(INTENT_METADATA_KEY, proto, methodName);
2656
- const combined = mergeIntentSensorRefs(
2712
+ const combined = mergeIntentSensorBindings(
2657
2713
  handlerSensors,
2658
2714
  Array.isArray(intentSensors) ? intentSensors : void 0,
2659
2715
  Array.isArray(meta?.is) ? meta.is : void 0
@@ -2795,8 +2851,10 @@ var init_intent_router = __esm({
2795
2851
  if (!this.observerDispatcher || bindings.length === 0) return;
2796
2852
  await this.observerDispatcher.dispatch(bindings, context);
2797
2853
  }
2798
- async runIntentSensors(sensorRefs, intent, frame) {
2799
- for (const sensorRef of sensorRefs) {
2854
+ async runIntentSensors(sensorBindings, intent, frame, stage, extras) {
2855
+ for (const binding of sensorBindings) {
2856
+ if (binding.when !== stage && binding.when !== "both") continue;
2857
+ const sensorRef = binding.ref;
2800
2858
  const sensor = this.resolveIntentSensor(sensorRef);
2801
2859
  const sensorName = sensorRefKey(sensorRef);
2802
2860
  if (!sensor) {
@@ -2813,9 +2871,12 @@ var init_intent_router = __esm({
2813
2871
  frameBody: frame.body,
2814
2872
  metadata: {
2815
2873
  phase: "intent",
2874
+ stage,
2816
2875
  intent,
2817
2876
  schema: this.getSchema(intent),
2818
- validators: this.getValidators(intent)
2877
+ validators: this.getValidators(intent),
2878
+ decodedBody: extras?.decodedBody,
2879
+ effect: extras?.effect
2819
2880
  }
2820
2881
  };
2821
2882
  if (sensor.supports && !sensor.supports(sensorInput)) continue;
@@ -12661,6 +12722,8 @@ __export(index_exports, {
12661
12722
  startStage: () => startStage,
12662
12723
  tieKnot: () => tieKnot,
12663
12724
  tlv: () => tlv,
12725
+ toIntentSensorBinding: () => toIntentSensorBinding,
12726
+ toObserverBinding: () => toObserverBinding,
12664
12727
  u64be: () => u64be,
12665
12728
  unpackPasskeyLoginOptionsReq: () => unpackPasskeyLoginOptionsReq,
12666
12729
  unpackPasskeyLoginVerifyReq: () => unpackPasskeyLoginVerifyReq,
@@ -12693,6 +12756,7 @@ var init_index = __esm({
12693
12756
  init_intent_body_decorator();
12694
12757
  init_intent_sensors_decorator();
12695
12758
  init_observer_decorator();
12759
+ init_observer_decorator();
12696
12760
  init_handler_sensors_decorator();
12697
12761
  init_sensor_decorator();
12698
12762
  import_tlv_field2 = __toESM(require_tlv_field_decorator());
@@ -13044,6 +13108,8 @@ init_index();
13044
13108
  startStage,
13045
13109
  tieKnot,
13046
13110
  tlv,
13111
+ toIntentSensorBinding,
13112
+ toObserverBinding,
13047
13113
  u64be,
13048
13114
  unpackPasskeyLoginOptionsReq,
13049
13115
  unpackPasskeyLoginVerifyReq,