@flowrunner/cli 0.1.11 → 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.
Files changed (34) hide show
  1. package/ai-docs/instructions/service-code-format/01-service-structure.md +1 -0
  2. package/ai-docs/instructions/service-code-format/06-oauth2.md +20 -1
  3. package/ai-docs/instructions/service-code-format/09-realtime-triggers.md +104 -5
  4. package/ai-docs/instructions/service-code-format/11-output-model.md +1 -1
  5. package/ai-docs/instructions/service-code-format/13-runtime-contracts.md +6 -3
  6. package/dist/cli.js +149 -10410
  7. package/dist/cli.js.map +4 -4
  8. package/dist/index.js +142 -10379
  9. package/dist/index.js.map +4 -4
  10. package/dist/types/flow-extension-runner/src/v2/model/model-types.d.ts +1 -1
  11. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +12 -2
  12. package/dist/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +11 -2
  13. package/dist/types/flow-extension-runner/src/v2/types.d.ts +5 -0
  14. package/dist/types/shared/src/scheme/flowrunner/custom-elements.d.ts +8 -8
  15. package/dist/types/shared/src/scheme/shared-extensions/base.d.ts +1 -1
  16. package/dist/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +8 -8
  17. package/dist/types/shared/src/scheme/shared-extensions/extension.d.ts +8 -8
  18. package/dist/types/shared/src/scheme/shared-extensions/resolve.d.ts +6 -6
  19. package/dist/types/shared/src/scheme/shared-extensions/search.d.ts +4 -4
  20. package/dist/types/shared/src/scheme/shared-extensions/service-info.d.ts +1 -1
  21. package/package.json +4 -1
  22. package/runtime/index.js +120 -10367
  23. package/runtime/index.js.map +4 -4
  24. package/runtime/types/flow-extension-runner/src/v2/model/model-types.d.ts +1 -1
  25. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/trigger-method.d.ts +12 -2
  26. package/runtime/types/flow-extension-runner/src/v2/realtime-triggers/types.d.ts +11 -2
  27. package/runtime/types/flow-extension-runner/src/v2/types.d.ts +5 -0
  28. package/runtime/types/shared/src/scheme/flowrunner/custom-elements.d.ts +8 -8
  29. package/runtime/types/shared/src/scheme/shared-extensions/base.d.ts +1 -1
  30. package/runtime/types/shared/src/scheme/shared-extensions/custom-extensions.d.ts +8 -8
  31. package/runtime/types/shared/src/scheme/shared-extensions/extension.d.ts +8 -8
  32. package/runtime/types/shared/src/scheme/shared-extensions/resolve.d.ts +6 -6
  33. package/runtime/types/shared/src/scheme/shared-extensions/search.d.ts +4 -4
  34. package/runtime/types/shared/src/scheme/shared-extensions/service-info.d.ts +1 -1
@@ -61,6 +61,7 @@ logo for that one item. Omit it and the item inherits the service's.
61
61
  | `logo` | string | ✓ | Icon path, resolved **inside the service's `public/` folder** — see [Folder layout](#folder-layout). |
62
62
  | `appearanceColors` | `[string, string]` | – | `[primary, secondary]`. |
63
63
  | `usesFileStorage` | boolean | – | `true` provisions `ctx.files`; when false, `ctx.files` is a proxy that throws. Default false. See [10-files-api.md](10-files-api.md). |
64
+ | `serviceClassName` | string | – | **Deprecated — will be removed soon. Shared extensions only.** The class name of a shared extension rewritten from the legacy JSDoc class format (`'GeminiAIService'`). It is published as `serviceInfo.serviceClassName` (absent otherwise), so flows, configs and connections saved against the old service keep resolving to this one. Keep it unchanged once set. Never set it on a new service or a custom extension. |
64
65
  | `configItems` | `z.object` | – | App + shared config (see [02-zod-types.md](02-zod-types.md)). → `appConfigDescriptions` / `sharedConfigDescriptions`. Omit when the service needs none — see [Services with no credentials](#services-with-no-credentials); a plain object of fields is **not** accepted (see [03-parameters.md](03-parameters.md)). |
65
66
  | `initContext` | fn | – | `({ config, oauth }) => context`; runs once per invocation. Runs for OAuth flows too (`oauth` may be empty). |
66
67
  | `apiRequest` | fn | – | Shared HTTP helper (envelope-unwrap, error-normalize, redacted logging). See [04-http-requests.md](04-http-requests.md). |
@@ -23,7 +23,26 @@ for the common case; any handler below overrides its step. Combined scopes = `sc
23
23
  |---|---|---|
24
24
  | `getConnectionURL` | `{ config, context, scopes }` | `string` (authorize URL) |
25
25
  | `executeCallback` | `{ callbackObject, config, context }` | `{ token, expirationInSeconds?, refreshToken?, connectionIdentityName?, connectionIdentityImageURL?, overwrite?, userData? }` |
26
- | `refreshToken` | `{ refreshToken, config, context }` | `{ token, expirationInSeconds?, refreshToken? }` |
26
+ | `refreshToken` | `{ refreshToken, config, context, oauth }` | `{ token, expirationInSeconds?, refreshToken? }` |
27
+
28
+ `getConnectionURL` and `executeCallback` run before any token exists, so their `oauth` is empty. `refreshToken`
29
+ is different: the platform sends the connection's **current (expired) token** in the `oauth-access-token`
30
+ header, so `oauth = { accessToken, token? }` and `initContext` see it exactly as in any other handler. That is
31
+ how a composite token survives a refresh — rebuild the next one from the data in the current one, because the
32
+ provider's refresh response does not repeat what it returned at connect time:
33
+
34
+ ```js
35
+ refreshToken: async ({ refreshToken, config, oauth }) => {
36
+ const res = await exchangeRefreshToken(config, refreshToken)
37
+
38
+ // `oauth.token` is `deserializeToken(<current token>)` — carry the realm id over
39
+ return {
40
+ token : `${ res.access_token }::realm::${ oauth.token.realmId }`,
41
+ refreshToken: res.refresh_token ?? refreshToken,
42
+ expirationInSeconds: res.expires_in,
43
+ }
44
+ },
45
+ ```
27
46
 
28
47
  ## Using OAuth in handlers
29
48
 
@@ -53,7 +53,7 @@ running and the error appears in the customer's **workspace log** on each refres
53
53
  | `extractProviderEventData` | path \| fn | Base `providerEventData` handed to matched triggers. Default = whole body. |
54
54
  | `scopeAt` | path | ALL_APPS routing key path (route where `scopeAt === eventScopeId`). |
55
55
  | `verify` | object | Declarative signature check — see the field table below. |
56
- | `handshake` | fn | Endpoint verification (see table). |
56
+ | `handshake` | fn | Decides which deliveries are endpoint-verification handshakes — replaces the empty-body default (see [Handshakes](#handshakes)). |
57
57
  | `subscribe` | fn | Required (see table). |
58
58
  | `unsubscribe` | fn | Required (see table). |
59
59
  | `refresh` | fn | Optional. |
@@ -74,7 +74,7 @@ does its own lowercased retry; that behaviour does not extend to `verifyRequest`
74
74
  | `subscribe` | `callbackUrl`, `triggers:[{ id, params, providerEventName? }]`, `webhookData` (null first), `connectionId` | `{ webhookData?, eventScopeId?, refreshIntervalInSeconds? }` |
75
75
  | `unsubscribe` | `callbackUrl`, `webhookData`, `connectionId` | `{ webhookData? }` |
76
76
  | `refresh` | `callbackUrl`, `triggers:[{ id, params, providerEventName? }]`, `webhookData` | `{ webhookData?, refreshIntervalInSeconds }` |
77
- | `handshake` | `{ requestBody, headers, rawBody, webhookData }` | `{ responseToWebhook? }` (runtime adds `handshake:true`); nothing → proceed. Empty-body deliveries are auto-acked by default (no `handshake` needed). |
77
+ | `handshake` | `{ requestBody, headers, rawBody, webhookData }` | `true` → ack with a plain 200; `{ responseToWebhook }` → ack with that response (runtime adds `handshake:true`); nothing / `false` / `{}` → proceed. See [Handshakes](#handshakes). |
78
78
  | `resolveEvents` | `rawBody`, `headers`, `query`, `body`, `webhookData`, `connectionId` | `{ events:[{ id, providerEventData }], eventScopeId?, handshake?, responseToWebhook? }` |
79
79
 
80
80
  Both also still accept the **deprecated** `responseToExternalService` / `responseHeaders` — see
@@ -89,6 +89,49 @@ reconcile it. Guard the field rather than assuming it (`if (t.providerEventName)
89
89
  on it unconditionally. Nothing is left out of the bag: a name resolving to no trigger **rejects the whole
90
90
  call** — see [Unknown trigger names](#unknown-trigger-names) below.
91
91
 
92
+ ### Handshakes
93
+
94
+ A handshake is a delivery the provider sends to check the callback URL rather than to report an event. It is
95
+ acked and goes no further: no `verify`, no routing, nothing fires.
96
+
97
+ **Without a `handshake` hook, an empty body is a handshake.** A body that is `null`, `''` or `{}` is acked with
98
+ `{ handshake: true, events: [] }` and a plain 200 — the URL-verification ping most providers send. Most
99
+ services need nothing more.
100
+
101
+ **A declared `handshake` replaces that default — it does not run before it.** The hook alone decides, and an
102
+ empty body it does not claim proceeds to `verify` and `resolveEvents` like any other delivery. That is what a
103
+ provider whose real events carry **no body** needs (Google Drive puts the whole notification in `X-Goog-*`
104
+ headers): with the default in place, its events would be acked as pings and never fire.
105
+
106
+ | The hook | The delivery |
107
+ |---|---|
108
+ | returns `true` | handshake — acked with a plain 200 |
109
+ | returns `{ responseToWebhook }` (or the deprecated `responseToExternalService` / `responseHeaders`) | handshake — answered with that response |
110
+ | returns nothing, `false`, or an object with no response in it (`{}`) | not a handshake — proceeds |
111
+ | throws | answered `{ events: [], responseToWebhook: { httpStatus, body: { message } } }` — the error's own `statusCode` (or `status`) when it is a 4xx, otherwise **400** |
112
+
113
+ ```js
114
+ // Google Drive-style: a real change notification has no body. Only the channel-opened message is a handshake.
115
+ handshake: ({ headers }) => headers['x-goog-resource-state'] === 'sync',
116
+
117
+ // Slack-style: an echoed challenge — and, since the hook replaces the default, the empty-body ping too.
118
+ handshake: ({ requestBody }) => {
119
+ if (requestBody?.challenge) {
120
+ return { responseToWebhook: { rawBody: requestBody.challenge } }
121
+ }
122
+
123
+ return requestBody == null || Object.keys(requestBody).length === 0
124
+ },
125
+ ```
126
+
127
+ ⚠️ **`handshake` runs before signature verification**, so it sees an unverified request. Acking one is harmless
128
+ — a handshake never fires anything — but do not grant anything from it, and remember that a **thrown message
129
+ is sent to that unverified caller**: throw what the provider may read.
130
+
131
+ ⚠️ **Declaring `handshake` for a challenge drops the empty-body default.** If the provider also pings with an
132
+ empty body, claim it in the hook (as above), or the ping proceeds to `verify` — which answers 401 when there is
133
+ no body to check.
134
+
92
135
  ### `webhookData` on the inbound path — read-only
93
136
 
94
137
  Every inbound seam receives the **stored webhook document**: whatever `subscribe` (or `refresh`) last returned
@@ -271,6 +314,7 @@ Use `params` for **filters** — which chat, which board, which status — never
271
314
  | `params` | `z.object` | – | Trigger config — omit if it takes none (see [03-parameters.md](03-parameters.md)). |
272
315
  | `result` | value \| schema \| loader | ✓ | Emitted event shape (post-`extendResult`). |
273
316
  | `extendEventData` | fn | – | see table. |
317
+ | `extendMatchData` | fn | – | see table, and [Filtering on data the delivery does not carry](#filtering-on-data-the-delivery-does-not-carry). |
274
318
  | `match` | object \| fn | – | Instance selection (declarative object or predicate fn). |
275
319
  | `extendResult` | fn | – | see table. |
276
320
  | `oauth2Scopes` | string[] | – | Extra scopes. |
@@ -279,12 +323,67 @@ Use `params` for **filters** — which chat, which board, which status — never
279
323
  |---|---|---|
280
324
  | `extendEventData` | `{ requestBody, providerEventData }` | partial object (merged onto `providerEventData`, **pure, pre-match**) |
281
325
  | `match` (object) | `{ paramKey: 'path.in.providerEventData' }` | declarative — type-coerced equality per filled param; empty param → all |
282
- | `match` (fn) | `{ params, providerEventData, webhookData }` | `boolean` — for ranges/contains/derived logic |
326
+ | `extendMatchData` | `{ providerEventData, webhookData, instances:[{ id, params }], apiRequest, … }` (full ctx bag, on the connection's token) | partial object merged onto `providerEventData` for `match` and `extendResult` (**select, once per event, pre-match, may call API**) |
327
+ | `match` (fn) | `{ params, providerEventData, webhookData }` | `boolean` (or a Promise of one — awaited) — for ranges/contains/derived logic |
283
328
  | `extendResult` | `{ providerEventData, webhookData, apiRequest, … }` | augmented `providerEventData` (**post-match, once if matched, may call API**); surfaces as `enrichedEventData` in the runtime response |
284
329
 
285
- **Inbound runtime flow:** `handshake?` → `verify`/`verifyRequest` → read `extractProviderEventName` → for
330
+ **Inbound runtime flow:** `handshake` (or the empty-body default) → `verify`/`verifyRequest` → read `extractProviderEventName` → for
286
331
  each trigger whose `providerEventName` matches, build `providerEventData` (`extractProviderEventData` +
287
- `extendEventData`) → `match` per instance → if ≥1 matched, `extendResult` once → fire.
332
+ `extendEventData`) → *(select)* `extendMatchData` once → `match` per instance → if ≥1 matched,
333
+ `extendResult` once → fire.
334
+
335
+ ### Filtering on data the delivery does not carry
336
+
337
+ Many webhooks name a resource without describing it — Xero sends an invoice's id, not its type or status. An
338
+ instance filter on those fields can only be decided after **reading the resource**, and that needs the
339
+ connection's token, which exists only on the select seam. The hooks split along that line:
340
+
341
+ | Hook | Seam | Token / `apiRequest` | Runs | Can change who fires |
342
+ |---|---|---|---|---|
343
+ | `extendEventData` | resolve (declarative routing only — not with `resolveEvents`) | ✗ — no connection chosen yet | per trigger, per delivery | ✓ (pure) |
344
+ | `extendMatchData` | select | ✓ | once per event, **before** `match` | ✓ |
345
+ | `extendResult` | select | ✓ | once per event, **after** `match`, if ≥1 matched | ✗ |
346
+
347
+ So fetch what a filter needs in `extendMatchData`, and keep `match` declarative over the fetched fields:
348
+
349
+ ```js
350
+ ext.addRealtimeTrigger({
351
+ id : 'onInvoiceUpdated',
352
+ params: z.object({ invoiceType: z.string().optional(), status: z.string().optional() }),
353
+ extendMatchData: async ({ providerEventData, apiRequest }) => {
354
+ const response = await apiRequest({ url: `${ API_BASE_URL }/Invoices/${ encodeURIComponent(providerEventData.resourceId) }` })
355
+ const invoice = response?.Invoices?.[0]
356
+
357
+ return invoice ? { invoice: { Type: invoice.Type, Status: invoice.Status } } : {}
358
+ },
359
+ match: { invoiceType: 'invoice.Type', status: 'invoice.Status' },
360
+ })
361
+ ```
362
+
363
+ - **One read per event**, however many instances are configured — never put the read in an async `match`,
364
+ which runs once per instance.
365
+ - **Read only when a flow filters.** The runtime skips the hook when nothing would read its result: no
366
+ configured instances, no `match` declared, or a declarative `match` none of whose params any instance has
367
+ filled (an empty param means "any", so every instance matches whatever the read returns). An event with no
368
+ filtering flow therefore costs no provider call.
369
+ - **Behind a predicate `match`, decide it yourself.** The runtime cannot see which params a function reads, so
370
+ the hook always runs and receives `instances` — `[{ id, params }]` for every configured instance — to skip
371
+ the read when none of them filters on what it would fetch:
372
+
373
+ ```js
374
+ extendMatchData: async ({ providerEventData, apiRequest, instances }) => {
375
+ if (!instances.some(({ params }) => params.minAmount != null)) {
376
+ return {}
377
+ }
378
+ …
379
+ },
380
+ match: ({ params, providerEventData }) => params.minAmount == null || providerEventData.amount >= params.minAmount,
381
+ ```
382
+ - **The fired event is unchanged.** What it returns is merged onto `providerEventData` for `match` and
383
+ `extendResult` only; to put fetched data on the event, return it from `extendResult`.
384
+ - **A failed read is not a failed delivery.** If it throws, the runtime logs a warning and matches on the
385
+ delivered data: instances filtering on the missing fields decline, unfiltered ones still fire. Return `{}`
386
+ (or nothing) for "not found" to get the same outcome without the warning.
288
387
 
289
388
  **A trigger declaring no `match` fires every configured instance** — "no filter" means "fires always", and
290
389
  that is a different case from a name this service does not declare, which selects nothing (see
@@ -23,7 +23,7 @@ The names change on the way out, which matters when you inspect a built model:
23
23
 
24
24
  | Authored | Published as |
25
25
  |---|---|
26
- | `id` | `serviceInfo.serviceClassName` |
26
+ | `serviceClassName` (deprecated) | `serviceInfo.serviceClassName` — absent when not declared: `id` is not published on `serviceInfo` |
27
27
  | `name` | `serviceInfo.integrationName` |
28
28
  | `logo` | `serviceInfo.integrationIcon` |
29
29
  | `description` | `serviceInfo.description` — shown under the extension's name in the console and the block palette |
@@ -110,7 +110,7 @@ spec asserting on a query-string branch silently drives the wrong path.
110
110
 
111
111
  **`webhookData` is the webhook document the platform stored** — what `subscribe`/`refresh` last returned —
112
112
  looked up for this delivery. It reaches `handshake`, `verify`/`verifyRequest` and `resolveEvents` here, and
113
- `match`/`extendResult` on `handleTriggerSelectMatched`, and is `null` when none is stored or when the request
113
+ `extendMatchData`/`match`/`extendResult` on `handleTriggerSelectMatched`, and is `null` when none is stored or when the request
114
114
  carries no workspace to look one up for (the general callback of a service that is not app-hosted). Both
115
115
  methods only **read** it: neither response carries a `webhookData` field, so a document returned from one is
116
116
  dropped — only upsert/refresh/delete persist. The harness never supplies it on its own: pass it in
@@ -118,8 +118,11 @@ dropped — only upsert/refresh/delete persist. The harness never supplies it on
118
118
  ([09-realtime-triggers.md](09-realtime-triggers.md#webhookdata-on-the-inbound-path--read-only)).
119
119
 
120
120
  It answers `{ events: [] }` for a delivery no trigger claims, and `{ handshake: true, events: [] }` for an
121
- empty body — the runtime acks those automatically, with no `handshake` declared
122
- ([09-realtime-triggers.md](09-realtime-triggers.md)). A `verify` / `verifyRequest` that turns a delivery down
121
+ empty body (`null`, `''` or `{}`) **when the service declares no `handshake`**. A declared `handshake`
122
+ replaces that default: an empty body it does not claim proceeds to `verify` and `resolveEvents`, and a
123
+ `handshake` that throws resolves with `{ events: [], responseToWebhook: { httpStatus, body: { message } } }`
124
+ (the error's 4xx, otherwise 400) rather than rejecting
125
+ ([09-realtime-triggers.md](09-realtime-triggers.md#handshakes)). A `verify` / `verifyRequest` that turns a delivery down
123
126
  **resolves** with `{ events: [], responseToWebhook: { httpStatus: 401, rawBody: '' } }` — it does not reject,
124
127
  so assert on the returned value, not on a thrown error.
125
128