@flowrunner/cli 0.1.12-dev.1 → 0.1.12-dev.2

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.
@@ -6,7 +6,7 @@ import type { SharedExtensionMethod } from '../model/model-types';
6
6
  import { MethodParams } from '../params';
7
7
  import { ResultSpec } from '../result';
8
8
  import type { ProviderPayload } from '../types';
9
- import type { RealtimeTriggerProps } from './types';
9
+ import type { RealtimeInstance, RealtimeTriggerProps } from './types';
10
10
  export declare class RealtimeTriggerMethod extends ExtensionMethod implements LoaderOwner {
11
11
  private readonly props;
12
12
  readonly params: MethodParams;
@@ -22,12 +22,15 @@ export declare class RealtimeTriggerMethod extends ExtensionMethod implements Lo
22
22
  claims(providerEventName: string): boolean;
23
23
  extendEventData(requestBody: ProviderPayload, providerEventData: ProviderPayload): Record<string, unknown> | undefined;
24
24
  /**
25
- * Whether `extendMatchData` should run for an event about to be matched against `instanceCount` instances.
26
- * Only when something will READ its result: with no instances there is nothing to decide, and with no
27
- * `match` every instance fires regardless — either way the API call would be pure cost.
25
+ * Whether `extendMatchData` should run before these instances are matched. Only when something will READ its
26
+ * result — otherwise the API call is pure cost, paid on every event:
27
+ * - no instances, or no `match` → nothing to decide (with no `match` every instance fires);
28
+ * - declarative `match`, and no instance fills any of its params → every instance matches regardless,
29
+ * since an empty param means "any". This is the v1 rule: read the resource only when a flow filters.
30
+ * A predicate `match` is opaque, so the hook runs and receives the instances to make that call itself.
28
31
  */
29
- needsMatchData(instanceCount: number): boolean;
30
- extendMatchData(providerEventData: ProviderPayload, ctx: ExecutionContext, webhookData?: ProviderPayload): Promise<Record<string, unknown> | void> | Record<string, unknown> | void;
32
+ needsMatchData(instances: RealtimeInstance[]): boolean;
33
+ extendMatchData(providerEventData: ProviderPayload, instances: RealtimeInstance[], ctx: ExecutionContext, webhookData?: ProviderPayload): Promise<Record<string, unknown> | void> | Record<string, unknown> | void;
31
34
  /**
32
35
  * Whether one CONFIGURED INSTANCE of this trigger cares about an event. Declarative form: type-coerced
33
36
  * equality per filled param, where an empty param means "any" — that is what lets a user leave a filter
@@ -119,6 +119,7 @@ export interface RealtimeTriggerProps<TShape extends ExtensionShape = AnyShape,
119
119
  extendMatchData?: (bag: HandlerBag<TShape> & {
120
120
  providerEventData: ProviderPayload;
121
121
  webhookData: ProviderPayload;
122
+ instances: RealtimeInstance<Infer<TParams>>[];
122
123
  }) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
123
124
  match?: Record<string, string> | ((bag: {
124
125
  params: Infer<TParams>;
@@ -133,6 +134,10 @@ export interface RealtimeTriggerProps<TShape extends ExtensionShape = AnyShape,
133
134
  logo?: string;
134
135
  appearanceColors?: [string, string];
135
136
  }
137
+ export interface RealtimeInstance<TParams = Record<string, unknown>> {
138
+ id: string;
139
+ params: TParams;
140
+ }
136
141
  export interface RealtimeInvocation {
137
142
  callbackUrl?: string;
138
143
  events?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flowrunner/cli",
3
- "version": "0.1.12-dev.1",
3
+ "version": "0.1.12-dev.2",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
package/runtime/index.js CHANGED
@@ -4749,16 +4749,6 @@ var RealtimeSetup = class {
4749
4749
  }
4750
4750
  return true;
4751
4751
  }
4752
- // Fan one resolved event out over the configured instances of its trigger. An `eventName` this service
4753
- // does not declare is DECLINED outright — `{ ids: [], enrichedEventData: null }`, no instance offered up
4754
- // and no per-event seam run. That is deliberately not the same case as a trigger which declares no
4755
- // `match`: `matches()` already answers "fires always" for that one, so resolve the name FIRST and never
4756
- // let the two share a branch.
4757
- //
4758
- // Declining is the GUARANTEE here, not an accident of a past fix, and it is why this seam is ruled the
4759
- // opposite way to `#toSubTriggers`. This is the DATA PLANE: the platform has already answered the
4760
- // provider and detached this work, so a throw reaches nobody — and worse, it aborts every remaining event
4761
- // of the same delivery, dropping the good ones beside the stale name.
4762
4752
  /**
4763
4753
  * The event data `match` decides on: the delivered data plus whatever `extendMatchData` fetched, read ONCE
4764
4754
  * for every instance — the case is an id-only webhook (Xero names an invoice, not its type or status) whose
@@ -4768,9 +4758,9 @@ var RealtimeSetup = class {
4768
4758
  * would abort the delivery's other events. So it is logged and the instances are matched against the data
4769
4759
  * that WAS delivered — an instance filtering on the missing fields declines, an unfiltered one still fires.
4770
4760
  */
4771
- async #withMatchData(trigger, eventData, webhookData, ctx) {
4761
+ async #withMatchData(trigger, eventData, instances, webhookData, ctx) {
4772
4762
  try {
4773
- const extra = await trigger.extendMatchData(eventData, ctx, webhookData);
4763
+ const extra = await trigger.extendMatchData(eventData, instances, ctx, webhookData);
4774
4764
  return extra && typeof extra === "object" ? { ...eventData, ...extra } : eventData;
4775
4765
  } catch (error) {
4776
4766
  ctx.logger.warn(
@@ -4779,16 +4769,26 @@ var RealtimeSetup = class {
4779
4769
  return eventData;
4780
4770
  }
4781
4771
  }
4772
+ // Fan one resolved event out over the configured instances of its trigger. An `eventName` this service
4773
+ // does not declare is DECLINED outright — `{ ids: [], enrichedEventData: null }`, no instance offered up
4774
+ // and no per-event seam run. That is deliberately not the same case as a trigger which declares no
4775
+ // `match`: `matches()` already answers "fires always" for that one, so resolve the name FIRST and never
4776
+ // let the two share a branch.
4777
+ //
4778
+ // Declining is the GUARANTEE here, not an accident of a past fix, and it is why this seam is ruled the
4779
+ // opposite way to `#toSubTriggers`. This is the DATA PLANE: the platform has already answered the
4780
+ // provider and detached this work, so a throw reaches nobody — and worse, it aborts every remaining event
4781
+ // of the same delivery, dropping the good ones beside the stale name.
4782
4782
  async #selectMatched(invocation, ctx) {
4783
4783
  const trigger = invocation.eventName ? this.extension.findRealtimeTrigger(invocation.eventName) : void 0;
4784
4784
  if (!trigger) {
4785
4785
  return { ids: [], enrichedEventData: null };
4786
4786
  }
4787
4787
  const webhookData = invocation.webhookData ?? null;
4788
- const instances = invocation.triggers ?? [];
4789
- const eventData = trigger.needsMatchData(instances.length) ? await this.#withMatchData(trigger, invocation.eventData, webhookData, ctx) : invocation.eventData;
4788
+ const instances = (invocation.triggers ?? []).map((instance) => ({ id: instance.id, params: instance.data ?? {} }));
4789
+ const eventData = trigger.needsMatchData(instances) ? await this.#withMatchData(trigger, invocation.eventData, instances, webhookData, ctx) : invocation.eventData;
4790
4790
  const verdicts = await Promise.all(
4791
- instances.map((instance) => trigger.matches(instance.data ?? {}, eventData, webhookData))
4791
+ instances.map((instance) => trigger.matches(instance.params, eventData, webhookData))
4792
4792
  );
4793
4793
  const ids = instances.filter((_instance, index) => verdicts[index]).map((instance) => instance.id);
4794
4794
  const enrichedEventData = ids.length && trigger.hasExtendResult() ? await trigger.extendResult(eventData, ctx, webhookData) : null;
@@ -4797,6 +4797,9 @@ var RealtimeSetup = class {
4797
4797
  };
4798
4798
 
4799
4799
  // ../../flow-extension-runner/src/v2/realtime-triggers/trigger-method.ts
4800
+ function isFilled(value) {
4801
+ return value != null && value !== "";
4802
+ }
4800
4803
  var RealtimeTriggerMethod = class extends ExtensionMethod {
4801
4804
  constructor(extension, props) {
4802
4805
  super(extension);
@@ -4849,17 +4852,28 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
4849
4852
  return this.props.extendEventData?.({ requestBody, providerEventData });
4850
4853
  }
4851
4854
  /**
4852
- * Whether `extendMatchData` should run for an event about to be matched against `instanceCount` instances.
4853
- * Only when something will READ its result: with no instances there is nothing to decide, and with no
4854
- * `match` every instance fires regardless — either way the API call would be pure cost.
4855
+ * Whether `extendMatchData` should run before these instances are matched. Only when something will READ its
4856
+ * result — otherwise the API call is pure cost, paid on every event:
4857
+ * - no instances, or no `match` → nothing to decide (with no `match` every instance fires);
4858
+ * - declarative `match`, and no instance fills any of its params → every instance matches regardless,
4859
+ * since an empty param means "any". This is the v1 rule: read the resource only when a flow filters.
4860
+ * A predicate `match` is opaque, so the hook runs and receives the instances to make that call itself.
4855
4861
  */
4856
- needsMatchData(instanceCount) {
4857
- return typeof this.props.extendMatchData === "function" && !!this.props.match && instanceCount > 0;
4862
+ needsMatchData(instances) {
4863
+ const match = this.props.match;
4864
+ if (typeof this.props.extendMatchData !== "function" || !match || !instances.length) {
4865
+ return false;
4866
+ }
4867
+ if (typeof match === "function") {
4868
+ return true;
4869
+ }
4870
+ const filterKeys = Object.keys(match);
4871
+ return instances.some((instance) => filterKeys.some((key) => isFilled(instance.params[key])));
4858
4872
  }
4859
4873
  // Runs ONCE per event, before any instance is matched, with the full handler bag (`apiRequest` on the
4860
4874
  // connection's token) — for an instance filter on data the delivery does not carry.
4861
- extendMatchData(providerEventData, ctx, webhookData = null) {
4862
- return this.props.extendMatchData?.(ctx.bagWith({ providerEventData, webhookData }));
4875
+ extendMatchData(providerEventData, instances, ctx, webhookData = null) {
4876
+ return this.props.extendMatchData?.(ctx.bagWith({ providerEventData, webhookData, instances }));
4863
4877
  }
4864
4878
  /**
4865
4879
  * Whether one CONFIGURED INSTANCE of this trigger cares about an event. Declarative form: type-coerced
@@ -4880,7 +4894,7 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
4880
4894
  }
4881
4895
  for (const [paramKey, path2] of Object.entries(match)) {
4882
4896
  const paramValue = params[paramKey];
4883
- if (paramValue == null || paramValue === "") {
4897
+ if (!isFilled(paramValue)) {
4884
4898
  continue;
4885
4899
  }
4886
4900
  if (`${paramValue}` !== `${getPath(providerEventData, path2)}`) {