@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.
- package/ai-docs/instructions/service-code-format/09-realtime-triggers.md +18 -3
- package/dist/cli.js +38 -24
- package/dist/cli.js.map +2 -2
- package/dist/index.js +37 -23
- package/dist/index.js.map +2 -2
- package/dist/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +9 -6
- package/dist/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +5 -0
- package/package.json +1 -1
- package/runtime/index.js +37 -23
- package/runtime/index.js.map +2 -2
- package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +9 -6
- package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +5 -0
package/dist/index.js
CHANGED
|
@@ -7937,16 +7937,6 @@ var RealtimeSetup = class {
|
|
|
7937
7937
|
}
|
|
7938
7938
|
return true;
|
|
7939
7939
|
}
|
|
7940
|
-
// Fan one resolved event out over the configured instances of its trigger. An `eventName` this service
|
|
7941
|
-
// does not declare is DECLINED outright — `{ ids: [], enrichedEventData: null }`, no instance offered up
|
|
7942
|
-
// and no per-event seam run. That is deliberately not the same case as a trigger which declares no
|
|
7943
|
-
// `match`: `matches()` already answers "fires always" for that one, so resolve the name FIRST and never
|
|
7944
|
-
// let the two share a branch.
|
|
7945
|
-
//
|
|
7946
|
-
// Declining is the GUARANTEE here, not an accident of a past fix, and it is why this seam is ruled the
|
|
7947
|
-
// opposite way to `#toSubTriggers`. This is the DATA PLANE: the platform has already answered the
|
|
7948
|
-
// provider and detached this work, so a throw reaches nobody — and worse, it aborts every remaining event
|
|
7949
|
-
// of the same delivery, dropping the good ones beside the stale name.
|
|
7950
7940
|
/**
|
|
7951
7941
|
* The event data `match` decides on: the delivered data plus whatever `extendMatchData` fetched, read ONCE
|
|
7952
7942
|
* for every instance — the case is an id-only webhook (Xero names an invoice, not its type or status) whose
|
|
@@ -7956,9 +7946,9 @@ var RealtimeSetup = class {
|
|
|
7956
7946
|
* would abort the delivery's other events. So it is logged and the instances are matched against the data
|
|
7957
7947
|
* that WAS delivered — an instance filtering on the missing fields declines, an unfiltered one still fires.
|
|
7958
7948
|
*/
|
|
7959
|
-
async #withMatchData(trigger, eventData, webhookData, ctx) {
|
|
7949
|
+
async #withMatchData(trigger, eventData, instances, webhookData, ctx) {
|
|
7960
7950
|
try {
|
|
7961
|
-
const extra = await trigger.extendMatchData(eventData, ctx, webhookData);
|
|
7951
|
+
const extra = await trigger.extendMatchData(eventData, instances, ctx, webhookData);
|
|
7962
7952
|
return extra && typeof extra === "object" ? { ...eventData, ...extra } : eventData;
|
|
7963
7953
|
} catch (error) {
|
|
7964
7954
|
ctx.logger.warn(
|
|
@@ -7967,16 +7957,26 @@ var RealtimeSetup = class {
|
|
|
7967
7957
|
return eventData;
|
|
7968
7958
|
}
|
|
7969
7959
|
}
|
|
7960
|
+
// Fan one resolved event out over the configured instances of its trigger. An `eventName` this service
|
|
7961
|
+
// does not declare is DECLINED outright — `{ ids: [], enrichedEventData: null }`, no instance offered up
|
|
7962
|
+
// and no per-event seam run. That is deliberately not the same case as a trigger which declares no
|
|
7963
|
+
// `match`: `matches()` already answers "fires always" for that one, so resolve the name FIRST and never
|
|
7964
|
+
// let the two share a branch.
|
|
7965
|
+
//
|
|
7966
|
+
// Declining is the GUARANTEE here, not an accident of a past fix, and it is why this seam is ruled the
|
|
7967
|
+
// opposite way to `#toSubTriggers`. This is the DATA PLANE: the platform has already answered the
|
|
7968
|
+
// provider and detached this work, so a throw reaches nobody — and worse, it aborts every remaining event
|
|
7969
|
+
// of the same delivery, dropping the good ones beside the stale name.
|
|
7970
7970
|
async #selectMatched(invocation, ctx) {
|
|
7971
7971
|
const trigger = invocation.eventName ? this.extension.findRealtimeTrigger(invocation.eventName) : void 0;
|
|
7972
7972
|
if (!trigger) {
|
|
7973
7973
|
return { ids: [], enrichedEventData: null };
|
|
7974
7974
|
}
|
|
7975
7975
|
const webhookData = invocation.webhookData ?? null;
|
|
7976
|
-
const instances = invocation.triggers ?? [];
|
|
7977
|
-
const eventData = trigger.needsMatchData(instances
|
|
7976
|
+
const instances = (invocation.triggers ?? []).map((instance) => ({ id: instance.id, params: instance.data ?? {} }));
|
|
7977
|
+
const eventData = trigger.needsMatchData(instances) ? await this.#withMatchData(trigger, invocation.eventData, instances, webhookData, ctx) : invocation.eventData;
|
|
7978
7978
|
const verdicts = await Promise.all(
|
|
7979
|
-
instances.map((instance) => trigger.matches(instance.
|
|
7979
|
+
instances.map((instance) => trigger.matches(instance.params, eventData, webhookData))
|
|
7980
7980
|
);
|
|
7981
7981
|
const ids = instances.filter((_instance, index) => verdicts[index]).map((instance) => instance.id);
|
|
7982
7982
|
const enrichedEventData = ids.length && trigger.hasExtendResult() ? await trigger.extendResult(eventData, ctx, webhookData) : null;
|
|
@@ -7985,6 +7985,9 @@ var RealtimeSetup = class {
|
|
|
7985
7985
|
};
|
|
7986
7986
|
|
|
7987
7987
|
// ../../flow-extension-runner/src/v2/realtime-triggers/trigger-method.ts
|
|
7988
|
+
function isFilled(value) {
|
|
7989
|
+
return value != null && value !== "";
|
|
7990
|
+
}
|
|
7988
7991
|
var RealtimeTriggerMethod = class extends ExtensionMethod {
|
|
7989
7992
|
constructor(extension, props) {
|
|
7990
7993
|
super(extension);
|
|
@@ -8037,17 +8040,28 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
|
|
|
8037
8040
|
return this.props.extendEventData?.({ requestBody, providerEventData });
|
|
8038
8041
|
}
|
|
8039
8042
|
/**
|
|
8040
|
-
* Whether `extendMatchData` should run
|
|
8041
|
-
*
|
|
8042
|
-
*
|
|
8043
|
+
* Whether `extendMatchData` should run before these instances are matched. Only when something will READ its
|
|
8044
|
+
* result — otherwise the API call is pure cost, paid on every event:
|
|
8045
|
+
* - no instances, or no `match` → nothing to decide (with no `match` every instance fires);
|
|
8046
|
+
* - declarative `match`, and no instance fills any of its params → every instance matches regardless,
|
|
8047
|
+
* since an empty param means "any". This is the v1 rule: read the resource only when a flow filters.
|
|
8048
|
+
* A predicate `match` is opaque, so the hook runs and receives the instances to make that call itself.
|
|
8043
8049
|
*/
|
|
8044
|
-
needsMatchData(
|
|
8045
|
-
|
|
8050
|
+
needsMatchData(instances) {
|
|
8051
|
+
const match = this.props.match;
|
|
8052
|
+
if (typeof this.props.extendMatchData !== "function" || !match || !instances.length) {
|
|
8053
|
+
return false;
|
|
8054
|
+
}
|
|
8055
|
+
if (typeof match === "function") {
|
|
8056
|
+
return true;
|
|
8057
|
+
}
|
|
8058
|
+
const filterKeys = Object.keys(match);
|
|
8059
|
+
return instances.some((instance) => filterKeys.some((key) => isFilled(instance.params[key])));
|
|
8046
8060
|
}
|
|
8047
8061
|
// Runs ONCE per event, before any instance is matched, with the full handler bag (`apiRequest` on the
|
|
8048
8062
|
// connection's token) — for an instance filter on data the delivery does not carry.
|
|
8049
|
-
extendMatchData(providerEventData, ctx, webhookData = null) {
|
|
8050
|
-
return this.props.extendMatchData?.(ctx.bagWith({ providerEventData, webhookData }));
|
|
8063
|
+
extendMatchData(providerEventData, instances, ctx, webhookData = null) {
|
|
8064
|
+
return this.props.extendMatchData?.(ctx.bagWith({ providerEventData, webhookData, instances }));
|
|
8051
8065
|
}
|
|
8052
8066
|
/**
|
|
8053
8067
|
* Whether one CONFIGURED INSTANCE of this trigger cares about an event. Declarative form: type-coerced
|
|
@@ -8068,7 +8082,7 @@ var RealtimeTriggerMethod = class extends ExtensionMethod {
|
|
|
8068
8082
|
}
|
|
8069
8083
|
for (const [paramKey, path19] of Object.entries(match)) {
|
|
8070
8084
|
const paramValue = params[paramKey];
|
|
8071
|
-
if (paramValue
|
|
8085
|
+
if (!isFilled(paramValue)) {
|
|
8072
8086
|
continue;
|
|
8073
8087
|
}
|
|
8074
8088
|
if (`${paramValue}` !== `${getPath(providerEventData, path19)}`) {
|