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

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
@@ -1152,6 +1152,7 @@ var init_axis_chain_executor = __esm({
1152
1152
  timestamp: startedAt,
1153
1153
  chainId: envelope.chainId,
1154
1154
  stepId: step.stepId,
1155
+ handler: step.handler,
1155
1156
  intent: step.intent,
1156
1157
  envelope,
1157
1158
  step,
@@ -1186,6 +1187,7 @@ var init_axis_chain_executor = __esm({
1186
1187
  timestamp: finishedAt,
1187
1188
  chainId: envelope.chainId,
1188
1189
  stepId: step.stepId,
1190
+ handler: step.handler,
1189
1191
  intent: step.intent,
1190
1192
  effect,
1191
1193
  envelope,
@@ -1200,6 +1202,7 @@ var init_axis_chain_executor = __esm({
1200
1202
  timestamp: finishedAt,
1201
1203
  chainId: envelope.chainId,
1202
1204
  stepId: step.stepId,
1205
+ handler: step.handler,
1203
1206
  intent: step.intent,
1204
1207
  envelope,
1205
1208
  step,
@@ -1214,6 +1217,7 @@ var init_axis_chain_executor = __esm({
1214
1217
  timestamp: finishedAt,
1215
1218
  chainId: envelope.chainId,
1216
1219
  stepId: step.stepId,
1220
+ handler: step.handler,
1217
1221
  intent: step.intent,
1218
1222
  effect,
1219
1223
  envelope,
@@ -1244,6 +1248,7 @@ var init_axis_chain_executor = __esm({
1244
1248
  timestamp: finishedAt,
1245
1249
  chainId: envelope.chainId,
1246
1250
  stepId: step.stepId,
1251
+ handler: step.handler,
1247
1252
  intent: step.intent,
1248
1253
  error: error.message,
1249
1254
  envelope,
@@ -2462,6 +2467,8 @@ var init_intent_router = __esm({
2462
2467
  this.handlers = /* @__PURE__ */ new Map();
2463
2468
  /** Per-intent sensor refs (resolved through SensorRegistry at call time) */
2464
2469
  this.intentSensors = /* @__PURE__ */ new Map();
2470
+ /** Per-intent handler identifier (e.g. UsersHandler.usersPage) */
2471
+ this.intentHandlerRefs = /* @__PURE__ */ new Map();
2465
2472
  /** Per-intent body decoders */
2466
2473
  this.intentDecoders = /* @__PURE__ */ new Map();
2467
2474
  /** Per-intent TLV schemas */
@@ -2537,6 +2544,16 @@ var init_intent_router = __esm({
2537
2544
  */
2538
2545
  register(intent, handler) {
2539
2546
  this.handlers.set(intent, handler);
2547
+ if (typeof handler === "function" && handler.name) {
2548
+ this.intentHandlerRefs.set(intent, handler.name);
2549
+ } else if (handler && typeof handler === "object") {
2550
+ const objectName = handler.constructor?.name;
2551
+ if (objectName) {
2552
+ this.intentHandlerRefs.set(intent, `${objectName}.handle`);
2553
+ }
2554
+ } else {
2555
+ this.intentHandlerRefs.set(intent, `intent:${intent}`);
2556
+ }
2540
2557
  }
2541
2558
  /**
2542
2559
  * Automatically registers all `@Intent`-decorated methods from a handler instance.
@@ -2567,6 +2584,10 @@ var init_intent_router = __esm({
2567
2584
  } else {
2568
2585
  this.register(intentName, fn);
2569
2586
  }
2587
+ this.intentHandlerRefs.set(
2588
+ intentName,
2589
+ `${instance.constructor.name}.${String(route.methodName)}`
2590
+ );
2570
2591
  this.registerIntentMeta(
2571
2592
  intentName,
2572
2593
  proto,
@@ -2607,15 +2628,18 @@ var init_intent_router = __esm({
2607
2628
  async route(frame) {
2608
2629
  const start = process.hrtime();
2609
2630
  let intent = "unknown";
2631
+ let handlerRef;
2610
2632
  try {
2611
2633
  const intentBytes = frame.headers.get(TLV_INTENT);
2612
2634
  if (!intentBytes) throw new Error("Missing intent");
2613
2635
  intent = this.decoder.decode(intentBytes);
2636
+ handlerRef = this.intentHandlerRefs.get(intent);
2614
2637
  const observerBindings = this.getObservers(intent);
2615
2638
  await this.emitIntentObservers(observerBindings, {
2616
2639
  event: "intent.received",
2617
2640
  timestamp: Date.now(),
2618
2641
  intent,
2642
+ handler: handlerRef,
2619
2643
  frame
2620
2644
  });
2621
2645
  let effect;
@@ -2745,6 +2769,7 @@ var init_intent_router = __esm({
2745
2769
  event: "intent.completed",
2746
2770
  timestamp: Date.now(),
2747
2771
  intent,
2772
+ handler: handlerRef,
2748
2773
  frame,
2749
2774
  effect,
2750
2775
  metadata: effect.metadata
@@ -2756,6 +2781,7 @@ var init_intent_router = __esm({
2756
2781
  event: "intent.failed",
2757
2782
  timestamp: Date.now(),
2758
2783
  intent,
2784
+ handler: handlerRef,
2759
2785
  frame,
2760
2786
  error: e.message
2761
2787
  });
@@ -8129,6 +8155,61 @@ var init_disk_upload_file_store = __esm({
8129
8155
  function unique(values) {
8130
8156
  return Array.from(new Set(values));
8131
8157
  }
8158
+ function matchesObserverIntent(intents, intent) {
8159
+ if (!intents || intents.length === 0) {
8160
+ return true;
8161
+ }
8162
+ if (!intent) {
8163
+ return false;
8164
+ }
8165
+ return intents.includes(intent);
8166
+ }
8167
+ function normalizeHandlerToken(value) {
8168
+ return value.trim().toLowerCase();
8169
+ }
8170
+ function matchesObserverHandler(handlers, handler) {
8171
+ if (!handlers || handlers.length === 0) {
8172
+ return true;
8173
+ }
8174
+ if (!handler) {
8175
+ return false;
8176
+ }
8177
+ const normalizedHandler = normalizeHandlerToken(handler);
8178
+ return handlers.some((candidate) => {
8179
+ if (!candidate) {
8180
+ return false;
8181
+ }
8182
+ const normalizedCandidate = normalizeHandlerToken(candidate);
8183
+ return normalizedHandler === normalizedCandidate || normalizedHandler.endsWith(`.${normalizedCandidate}`) || normalizedHandler.startsWith(`${normalizedCandidate}.`) || normalizedCandidate.endsWith(`.${normalizedHandler}`) || normalizedCandidate.startsWith(`${normalizedHandler}.`);
8184
+ });
8185
+ }
8186
+ function observerRefKey2(ref) {
8187
+ return typeof ref === "string" ? ref : ref.name || "(anonymous)";
8188
+ }
8189
+ function mergeBindingRefs(...bindingGroups) {
8190
+ const merged = /* @__PURE__ */ new Map();
8191
+ for (const bindings of bindingGroups) {
8192
+ for (const binding of bindings) {
8193
+ for (const ref of binding.refs) {
8194
+ const key = observerRefKey2(ref);
8195
+ const current = merged.get(key);
8196
+ if (!current) {
8197
+ merged.set(key, {
8198
+ refs: [ref],
8199
+ tags: binding.tags ? [...new Set(binding.tags)] : void 0,
8200
+ events: binding.events ? [...new Set(binding.events)] : void 0
8201
+ });
8202
+ continue;
8203
+ }
8204
+ current.tags = Array.from(
8205
+ /* @__PURE__ */ new Set([...current.tags || [], ...binding.tags || []])
8206
+ );
8207
+ current.events = current.events === void 0 || binding.events === void 0 ? void 0 : Array.from(/* @__PURE__ */ new Set([...current.events || [], ...binding.events]));
8208
+ }
8209
+ }
8210
+ }
8211
+ return Array.from(merged.values());
8212
+ }
8132
8213
  var ObserverDispatcherService;
8133
8214
  var init_observer_dispatcher_service = __esm({
8134
8215
  "src/engine/observer-dispatcher.service.ts"() {
@@ -8139,9 +8220,20 @@ var init_observer_dispatcher_service = __esm({
8139
8220
  this.logger = createAxisLogger(_ObserverDispatcherService.name);
8140
8221
  }
8141
8222
  async dispatch(bindings, context) {
8142
- if (!bindings || bindings.length === 0) return;
8223
+ const explicitBindings = bindings || [];
8224
+ const implicitRegistrations = this.getImplicitRegistrations();
8225
+ if (!explicitBindings.length && implicitRegistrations.length === 0) {
8226
+ return;
8227
+ }
8143
8228
  const invoked = /* @__PURE__ */ new Set();
8144
- for (const binding of bindings) {
8229
+ const implicitBindings = implicitRegistrations.map(
8230
+ (registration) => ({
8231
+ refs: [registration.instance.constructor],
8232
+ events: registration.events
8233
+ })
8234
+ );
8235
+ const merged = mergeBindingRefs(explicitBindings, implicitBindings);
8236
+ for (const binding of merged) {
8145
8237
  if (binding.events && binding.events.length > 0 && !binding.events.includes(context.event)) {
8146
8238
  continue;
8147
8239
  }
@@ -8152,6 +8244,9 @@ var init_observer_dispatcher_service = __esm({
8152
8244
  continue;
8153
8245
  }
8154
8246
  if (invoked.has(registration.name)) continue;
8247
+ if (!matchesObserverIntent(registration.intents, context.intent) || !matchesObserverHandler(registration.handlers, context.handler)) {
8248
+ continue;
8249
+ }
8155
8250
  if (registration.events && registration.events.length > 0 && !registration.events.includes(context.event)) {
8156
8251
  continue;
8157
8252
  }
@@ -8177,6 +8272,9 @@ var init_observer_dispatcher_service = __esm({
8177
8272
  }
8178
8273
  }
8179
8274
  }
8275
+ getImplicitRegistrations() {
8276
+ return this.registry.list();
8277
+ }
8180
8278
  };
8181
8279
  }
8182
8280
  });