@flowrunner/cli 0.1.16 → 0.1.18-dev.1

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 (38) hide show
  1. package/ai-docs/instructions/service-code-format/02-zod-types.md +169 -29
  2. package/ai-docs/instructions/service-code-format/03-parameters.md +3 -1
  3. package/ai-docs/instructions/service-code-format/05-dictionaries.md +8 -2
  4. package/ai-docs/instructions/service-code-format/07-actions.md +5 -1
  5. package/ai-docs/instructions/service-code-format/11-output-model.md +3 -0
  6. package/ai-docs/instructions/service-code-format/14-reference-service.md +1 -1
  7. package/ai-docs/instructions/service-code-format/16-gotchas.md +111 -0
  8. package/ai-docs/instructions/service-code-format/18-test-recipes.md +2 -1
  9. package/ai-docs/instructions/service-code-format/README.md +1 -1
  10. package/dist/cli.js +559 -88
  11. package/dist/cli.js.map +4 -4
  12. package/dist/index.js +558 -87
  13. package/dist/index.js.map +4 -4
  14. package/dist/types/flow-extension-runner/src/v2/context/execution-context.d.ts +8 -0
  15. package/dist/types/flow-extension-runner/src/v2/dictionaries/payload-schema.d.ts +1 -1
  16. package/dist/types/flow-extension-runner/src/v2/params/index.d.ts +2 -0
  17. package/dist/types/flow-extension-runner/src/v2/params/json/types.d.ts +2 -0
  18. package/dist/types/flow-extension-runner/src/v2/params/schema/date-format.d.ts +80 -0
  19. package/dist/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +4 -10
  20. package/dist/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +7 -0
  21. package/dist/types/flow-extension-runner/src/v2/params/schema/notices.d.ts +15 -0
  22. package/dist/types/flow-extension-runner/src/v2/params/widget-types.d.ts +1 -1
  23. package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +30 -19
  24. package/dist/types/flow-extension-runner/src/v2/types.d.ts +1 -1
  25. package/package.json +1 -1
  26. package/runtime/index.js +565 -88
  27. package/runtime/index.js.map +4 -4
  28. package/runtime/types/flow-extension-runner/src/v2/context/execution-context.d.ts +8 -0
  29. package/runtime/types/flow-extension-runner/src/v2/dictionaries/payload-schema.d.ts +1 -1
  30. package/runtime/types/flow-extension-runner/src/v2/params/index.d.ts +2 -0
  31. package/runtime/types/flow-extension-runner/src/v2/params/json/types.d.ts +2 -0
  32. package/runtime/types/flow-extension-runner/src/v2/params/schema/date-format.d.ts +80 -0
  33. package/runtime/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +4 -10
  34. package/runtime/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +7 -0
  35. package/runtime/types/flow-extension-runner/src/v2/params/schema/notices.d.ts +15 -0
  36. package/runtime/types/flow-extension-runner/src/v2/params/widget-types.d.ts +1 -1
  37. package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +30 -19
  38. package/runtime/types/flow-extension-runner/src/v2/types.d.ts +1 -1
@@ -8,12 +8,13 @@ and behaviors.
8
8
  |---|---|---|---|---|---|
9
9
  | `z.string()` | single-line | | `.label(text)` | any field | display label (native `meta.title`) |
10
10
  | `z.text()` | multi-line | | `.describe(text)` | any field | description / config hint |
11
- | `z.json()` | multi-line — arbitrary JSON, **parsed for you** | | | | |
12
11
  | `z.number()` | numeric stepper | | `.example(v)` | field / result | sample value (native `meta.examples`) |
13
12
  | `z.boolean()` | toggle | | `.optional()` | any field | not required (required is default) |
14
13
  | `z.enum([...])` | dropdown | | `.default(v)` | any field | default value |
15
14
  | `z.date()` | date picker | | `.shared()` | config field | `shared:true` (OAuth client id/secret) |
16
- | `z.object({...})` | nested form | | `.dictionary(ref)` | param field | dynamic options + auto `dependsOn` (see [05-dictionaries.md](05-dictionaries.md)) |
15
+ | `z.iso.date()`, `z.iso.datetime({ local: true })`, `z.iso.time()` | date / date-and-time / time picker that stores **text** — see [Dates](#dates--an-instant-or-a-date-as-text) | | `.dateFormat(pattern)` | those three | the text `execute` receives: `'dd/MM/yyyy'` → `'31/01/2024'` |
16
+ | `z.object({...})` | nested form — **drops** the keys it does not declare | | `.dictionary(ref)` | param field | dynamic options + auto `dependsOn` (see [05-dictionaries.md](05-dictionaries.md)) |
17
+ | `z.looseObject({...})` | nested form — **keeps** the keys it does not declare; see [`z.object` or `z.looseObject`](#zobject-or-zlooseobject) | | | | |
17
18
  | `z.array(inner)` | list | | `.labels({ value: 'Label' })` | `z.enum` | UI shows the label; the flow stores and `execute` receives the VALUE |
18
19
  | `z.union([...])` | the **first** branch's widget — see below | | | | |
19
20
  | `z.filesUploadOptions([...])`, `z.filesListOptions([...])`, `z.filesGetOptions([...])`, `z.filesDeleteOptions([...])` | nested form — the platform's own file-storage options, one group per Files call (see [03-parameters.md](03-parameters.md)) | | | | |
@@ -58,38 +59,140 @@ Notes:
58
59
  (There is no `.map({ Label: value })` — it took its argument the other way round, treating labels as the
59
60
  accepted values. It throws when the service loads, naming `.labels()`.)
60
61
 
61
- ## `z.json()` — a JSON value typed into a textarea
62
+ ## The widget follows the type — there is no override
62
63
 
63
- Use it for a parameter whose shape you do not want to declare: a request body to pass through, a bag of
64
- options an API takes verbatim.
64
+ There is no option for choosing a widget. The type you declare decides **both** the widget and the value
65
+ your handler receives. When the vendor wants something the obvious declaration doesn't give you, choose by
66
+ what the **handler** needs, and convert in the handler:
67
+
68
+ | You need | Declare | Why not the obvious spelling |
69
+ |---|---|---|
70
+ | A checkbox, and the vendor wants the text `'true'` / `'false'` | `z.boolean()`, and send `String(params.flag)` (or the spelling the vendor documents) | `z.string()` draws a text box. `z.enum(['true', 'false'])` draws a dropdown |
71
+ | Any value from the flow (text, a number, an object, a list) passed through as given | `z.unknown()` (`.required()` if it must be set) | — |
72
+ | An object or list whose shape you know, which the author may also supply as JSON text | `z.object({ … })` / `z.array(…)`: they draw a real form **and** accept JSON text (see [Text and structures](#text-and-structures)) | — |
73
+ | Several lines of text | `z.text()` | — |
74
+ | Several values (ids, emails, tags), even when the vendor wants them comma-separated | `z.array(<element>)`, and `.join(',')` at the request if the vendor needs text | A comma-separated `z.string()` gets a bound list as JSON text, which `.split(',')` breaks ([16-gotchas.md](16-gotchas.md#a-list-is-a-zarray-never-comma-separated-text-you-split)) |
75
+ | A calendar date or a wall-clock time the vendor wants as text (`20/05/2026`, `2026-05-20`, `10:00`) | `z.iso.date().dateFormat('dd/MM/yyyy')` (or `z.iso.datetime({ local: true })` / `z.iso.time()`) — see [Dates](#dates--an-instant-or-a-date-as-text) | `z.date()` hands you an instant; formatting it yourself needs a time zone you do not have, and is a day early for an author east of UTC ([16-gotchas.md](16-gotchas.md#a-date-the-vendor-wants-as-text-is-dateformat-never-a-zdate-you-format)) |
76
+
77
+ **`z.json()` is not supported.** It fails when the extension loads, with a message naming the two declarations
78
+ above. A value whose shape you don't declare is `z.unknown()`. One you do know is the shape itself, which
79
+ also accepts JSON text, so nothing is lost. `z.unknown()` passes text through **as text**: if the author may
80
+ type JSON into it, parse it yourself.
81
+
82
+ ## `z.object` or `z.looseObject`
83
+
84
+ Both draw the same nested form and publish the same model. They differ in what your handler receives. A
85
+ `z.object()` **drops every key it does not declare**: silently, with nothing refused and nothing logged. A
86
+ `z.looseObject()` checks and converts the keys it declares and passes the rest through untouched.
65
87
 
66
88
  ```js
67
- params: z.object({
68
- payload: z.json().label('Payload').describe('Sent as the request body.'),
69
- }),
70
- execute: async ({ params }) => {
71
- // `params.payload` is already a JSON VALUE — an object, an array, a number. Not text.
72
- return apiRequest({ url: '/items', method: 'POST', body: params.payload })
73
- }
89
+ z.array(z.object({ name: z.string() })) // [{ name: 'a', fields: [1] }] → [{ name: 'a' }]
90
+ z.array(z.looseObject({ name: z.string() })) // [{ name: 'a', fields: [1] }] → [{ name: 'a', fields: [1] }]
74
91
  ```
75
92
 
76
- The field renders as a textarea and the caller supplies **text**, so the parameter publishes as a string —
77
- but the runtime parses it before your handler runs, and `execute` receives the parsed value. **Never call
78
- `JSON.parse` on it yourself.**
93
+ Choose by what the handler does with the object:
94
+
95
+ - **It forwards the object to the API as is → `z.looseObject({ … })`.** Declare the fields the form should
96
+ draw. Everything else the caller sends, including fields the vendor adds later, still reaches the API. A
97
+ free-form map with no fields to draw is `z.looseObject({})`.
98
+ - **It reads named fields and builds its own request → `z.object({ … })`.** Dropping an undeclared key is the
99
+ point there: the object is a whitelist.
100
+
101
+ The forwarding case is easy to get wrong when you first declare a shape. For example, a list of tables is
102
+ sent to the API, but its element is declared as `z.object({ name })` to draw a *Name* field. Every table then
103
+ reaches the API as `{ name }`. The API creates tables with no columns and reports success.
104
+
105
+ Looseness applies to **one level**. A `z.looseObject()` inside a `z.object()` keeps its own extra keys, but the
106
+ outer object still drops its own. Declare each level that is forwarded as loose.
107
+
108
+ `z.record(z.string(), v)` adds something only when **each value** must be checked against `v`:
109
+ `z.record(z.string(), z.number())` converts `{ a: '1' }` to `{ a: 1 }`. A `z.record(z.string(), z.unknown())`
110
+ behaves exactly like `z.looseObject({})`. They publish the same model and pass the same values through, so
111
+ prefer the shorter one.
112
+
113
+ The top-level `params` object is the exception. It is always a `z.object()`, and its undeclared fields are
114
+ dropped unless the action declares `dynamicParams` (see [07-actions.md](07-actions.md)). Looseness is for the
115
+ objects **inside** it.
116
+
117
+ ## Dates — an instant, or a date as text
118
+
119
+ Two different things are called "a date", and they are declared differently:
120
+
121
+ | The vendor wants | Declare | Widget | `execute` receives |
122
+ |---|---|---|---|
123
+ | an **instant** — a moment, the same everywhere (`scheduled_at: 2026-05-20T07:00:00Z`) | `z.date()` (the value as sent) or `z.coerce.date()` (a `Date`) | date picker | what the caller sent / a `Date` |
124
+ | a **calendar date** as text | `z.iso.date()` | date picker | `'2024-01-31'` |
125
+ | | `z.iso.date().dateFormat('dd/MM/yyyy')` | date picker | `'31/01/2024'` |
126
+ | a **wall-clock date and time** as text, read in the vendor's zone | `z.iso.datetime({ local: true })` | date-and-time picker | `'2024-01-31T13:45'` |
127
+ | | `z.iso.datetime({ local: true }).dateFormat('dd/MM/yy HH:mm')` | date-and-time picker | `'31/01/24 13:45'` |
128
+ | a **time of day** as text | `z.iso.time()` | time picker | `'13:45'` |
129
+ | | `z.iso.time().dateFormat('h:mm a')` | time picker | `'1:45 PM'` |
130
+
131
+ A date as text is **text from end to end**: the picker builds it from the day and time the author clicked, the
132
+ flow stores it as text, and your handler receives it in your pattern. Nothing converts it through a time zone,
133
+ so 31 January picked in UTC+3 stays 31 January. `z.iso.datetime()` **without** `{ local: true }` is an instant
134
+ with a zone and stays a text box.
135
+
136
+ ### `.dateFormat(pattern)`
137
+
138
+ The pattern uses these tokens, and only these:
79
139
 
80
- - **Text that will not parse is rejected** the way any wrong-typed value is: the user sees
81
- `«Payload» must be valid JSON` against the field, before your handler is reached.
82
- - **A value that is already a structure passes through untouched** — a flow can bind the parameter to an
83
- expression that evaluates to an object rather than to text, and both work.
84
- - **Every JSON value is accepted**, not just objects and arrays: `42`, `"text"`, `true` and `null` all parse.
85
- Bare words do not — JSON wants a string quoted, so `hello` is refused and `"hello"` is accepted.
86
- - **Required by default**, like every other field; add `.optional()` if it is not.
87
- - Its inferred TypeScript type is `unknown`, because that is honestly what arbitrary JSON is. Narrow it in
88
- your handler before reading properties off it.
140
+ | Token | Meaning | 31 Jan 2024, 13:45:30 |
141
+ |---|---|---|
142
+ | `yyyy` / `yy` | year | `2024` / `24` |
143
+ | `MM` / `M` | month | `01` / `1` |
144
+ | `dd` / `d` | day of the month | `31` / `31` |
145
+ | `HH` / `H` | hour, 0–23 | `13` / `13` |
146
+ | `hh` / `h` | hour, 1–12 — needs `a` | `01` / `1` |
147
+ | `mm` | minute | `45` |
148
+ | `ss` | second | `30` |
149
+ | `a` | AM / PM | `PM` |
150
+ | `'text'` | literal text | `'at'` → `at` |
151
+
152
+ Any other character that is not a letter (`/ - . : , space`) is written as is. Without `.dateFormat()` the
153
+ value is ISO: `yyyy-MM-dd`, `yyyy-MM-ddTHH:mm` (with seconds when the value had them), `HH:mm`.
154
+
155
+ **Checked when the extension loads**, naming the parameter — so a mistake stops `flowrunner deploy`:
156
+
157
+ | You wrote | Refused because |
158
+ |---|---|
159
+ | `'DD/MM/YYYY'`, `'dd/mm/YYYY'` | `YYYY` is the week-numbering year, `DD` the day of the year, `mm` minutes — the message suggests `dd/MM/yyyy` |
160
+ | `'dd/MM/yyyy HH:mm'` on `z.iso.date()` | a date has no time of day — declare `z.iso.datetime({ local: true })` |
161
+ | `'dd/MM'` on `z.iso.time()`, `'MM/yyyy'` on `z.iso.date()` | a time has no date; every part of a date must be in its pattern |
162
+ | `'hh:mm'` | a 12-hour clock without `a` cannot be read back — add `a`, or use `HH` |
163
+ | `.dateFormat()` on `z.string()`, `z.date()`, or `z.iso.datetime()` without `{ local: true }` | only the three wall-clock types take a format |
164
+ | `.default('2024-01-31')` with `.dateFormat('dd/MM/yyyy')` | a default is handed to `execute` as written, so write it in the field's own format: `.default('31/01/2024')` |
165
+
166
+ ### What a date-as-text field accepts
167
+
168
+ A value picked in the editor already has your pattern. A value **bound from another block** may be any text,
169
+ and is reshaped from the characters as written:
89
170
 
90
- `z.json()` declares nothing about the value's SHAPE. When you do know the shape, declare it — a
91
- `z.object({ … })` gives the user a real form and gives you a checked value, where this gives a textarea and
92
- `unknown`.
171
+ | Declared `.dateFormat('dd/MM/yyyy')`, given | `execute` receives |
172
+ |---|---|
173
+ | `'31/01/2024'` | `'31/01/2024'` |
174
+ | `'2024-01-31'`, `'2024-01-31T23:30:00+03:00'`, `'2024-01-31T23:30:00Z'` | `'31/01/2024'` — the date **as written**; a zone is dropped, never applied |
175
+ | `'31/02/2024'`, `'1/1/2024'`, `'01/31/2024'` | refused: `«Due Date» must be a date in dd/MM/yyyy, e.g. 31/01/2024` |
176
+ | a timestamp (`1706659200000`) | refused, with the same message — a timestamp is an instant, and turning it into a day needs a time zone. A field that takes one is `z.date()` |
177
+
178
+ - **Strict.** The text must be exactly what the pattern writes — `1/1/2024` is not `dd/MM/yyyy`, `1:45 pm` is not
179
+ `h:mm a`, and `31/02/2024` or `24:00` is no date at all.
180
+ - **Nothing is invented.** A date alone is refused by a date-and-time or a time field, rather than given a
181
+ midnight nobody picked.
182
+ - **An ISO value with `Z`** keeps its UTC date: `new Date().toISOString()` just after midnight in UTC+3 is still
183
+ yesterday's date in UTC. If the local day matters, format it in the zone you mean before it reaches the field.
184
+ - **Blank is "not set"**, as on a number: `''`, `null` and a missing value follow `.optional()` / `.nullable()` /
185
+ `.default()`. `.min()` / `.max()` are not available on these types.
186
+ - Inside an object or a list it behaves the same, and a failure names the property (`«Days item 2» must be …`).
187
+
188
+ ### Moving a field from `z.date()` to a date as text
189
+
190
+ A flow saved against `z.date()` holds the old picker's **timestamp**. When an author opens the block, the
191
+ console converts it to your pattern **in the author's own time zone** — the day they originally picked — and
192
+ notes *"Converted from an older saved value — check it and save."* Ask your users to open and save the flows
193
+ that use the field. A flow that is never re-saved keeps sending the timestamp: for a transition period the
194
+ runtime still accepts it, reading it in **UTC** (a day early for an author east of UTC), and after that it is
195
+ refused like any other timestamp.
93
196
 
94
197
  ## The type list is CLOSED
95
198
 
@@ -115,6 +218,9 @@ dropped out of type coercion, so the string values a flow supplies were never co
115
218
  under an unrecognised modifier therefore handed `execute` `false` for an explicit `'true'`. A deploy that
116
219
  stops is better than a parameter that looks fine and is wrong.
117
220
 
221
+ `z.json()` is refused too, even earlier: the call itself throws, naming `z.unknown()` and the declared
222
+ shape (see [The widget follows the type](#the-widget-follows-the-type--there-is-no-override)).
223
+
118
224
  These modifiers are looked THROUGH — the parameter publishes and coerces as the type underneath:
119
225
 
120
226
  | Modifier | Published as |
@@ -257,7 +363,7 @@ The two other differences are structural:
257
363
 
258
364
  | Declared in `configItems` | What happens |
259
365
  |---|---|
260
- | `z.object({...})`, `z.array(inner)` | **no config control** — a config value is one field, not a form. Declare structured input as a param |
366
+ | `z.object({...})`, `z.array(inner)` | **a plain text box** that takes the value as JSON text (`{"region":"eu"}`, `["a","b"]`), parsed and checked like any object or list — see [Text and structures](#text-and-structures). Usable, but a poor form: prefer a param for structured input |
261
367
  | `.dictionary(ref)` | **ignored** — a config value is resolved before any method runs, so there is no invocation to fetch options for. Use `z.enum([...])` for a fixed set of choices |
262
368
 
263
369
  `z.date()` in a config field is a date, with no time of day. Declare a string if you need one.
@@ -267,6 +373,37 @@ conversion.** `z.coerce.*` does not add to it, so `z.coerce.number()` and `z.num
267
373
  as do the boolean and string forms. The one exception is `z.date()` — declare **`z.coerce.date()`** when your handler wants a real `Date`
268
374
  instance rather than the string or epoch-millis the caller sent.
269
375
 
376
+ ### Text and structures
377
+
378
+ Text and structured values convert into each other, so a value survives a trip through a text box or an
379
+ expression either way:
380
+
381
+ - **A text field takes any value.** An object or a list given to `z.string()`, `z.text()` or a format becomes
382
+ its JSON text. `null` and a missing value are still blanks, never the text `'null'`.
383
+ - **An object or list field takes JSON text.** Text given to `z.object()`, `z.looseObject()`, `z.record()` or
384
+ `z.array()` is parsed when it is JSON of the matching kind — `{…}` for an object or record, `[…]` for a list —
385
+ and then converted and checked like any other value.
386
+
387
+ ```js
388
+ note : z.string() // { a: 1 } → '{"a":1}'
389
+ title: z.string().max(5) // { a: 1 } → «Title» must be at most 5 (checks run on the text)
390
+ point: z.object({ x: z.number() }) // '{"x":"1"}' → { x: 1 }
391
+ ids : z.array(z.number()) // '[1,"2"]' → [1, 2]
392
+ ids : z.array(z.number()) // '1,2' → «Ids» must be an array (not JSON — not split)
393
+ ```
394
+
395
+ Anything that is not JSON of the right kind is refused as before: a comma-separated value is not split for
396
+ you, and `'{a:1}'` (unquoted key) is not JSON. `''` is still a blank; `'{}'` and `'[]'` are values.
397
+
398
+ In a union, a value that already fits a branch is kept (see above), and an object or a list is **never** turned
399
+ into text through a `z.string()` branch: it takes a branch of its own kind or the union's error, so a malformed
400
+ object is reported rather than sent as JSON text.
401
+
402
+ The flip side: an object bound by mistake to a plain text field (a subject, a name) is sent as JSON text
403
+ rather than refused. The same applies to a list bound to a text param: it arrives as `'["1","5"]'`, not
404
+ `'1,5'`. So a param that holds several values is a `z.array(…)`, never comma-separated text the handler
405
+ splits. See [16-gotchas.md](16-gotchas.md#a-list-is-a-zarray-never-comma-separated-text-you-split).
406
+
270
407
  ### What a boolean accepts
271
408
 
272
409
  A `z.boolean()` is rarely filled in by hand — its value usually arrives from a spreadsheet column, a CSV
@@ -282,12 +419,15 @@ booleans `true`/`false` and the numbers `1`/`0`:
282
419
  So `'YES'`, `' Off '` and `'Enabled'` all work.
283
420
 
284
421
  **Anything else is a validation error, not a guess.** `'maybe'`, `'2'`, `'tr'`, a list or an object each
285
- fail with `«Field» is invalid — expects true or false`. That matters more than the width of the list: a
422
+ fail with `«Field» must be true or false`. That matters more than the width of the list: a
286
423
  conversion that quietly turned an unrecognised value into `false` would read an explicit *on* as *off* and
287
424
  never say so.
288
425
 
289
426
  A blank is absence rather than `false` — see [16-gotchas.md](16-gotchas.md).
290
427
 
428
+ This list applies to **params** only. A vendor's response is never converted: compare a response flag with the
429
+ value the vendor documents — see [16-gotchas.md](16-gotchas.md#conversion-runs-on-the-way-in-never-on-the-way-back).
430
+
291
431
  If you need a spelling that is not listed, the test for adding one is that **it has an unambiguous opposite
292
432
  and the pair is added together.** A word with no opposite is a status, not a boolean, and belongs in a
293
433
  `z.enum([...])`.
@@ -160,7 +160,9 @@ rather than quietly publishing an empty settings panel.
160
160
  > hands the flow nothing. If your action's result carries a URL, leave `generateUrl` out of the whitelist and
161
161
  > pass `true` yourself — the flow author has no way to know that turning it off breaks the block.
162
162
 
163
- **The group is also the contract at runtime.** A `z.object` strips what it does not declare, so
163
+ **The group is also the contract at runtime.** A `z.object` strips what it does not declare (here that is
164
+ the point; an object you forward to an API wants `z.looseObject()`, see
165
+ [02-zod-types.md](02-zod-types.md#zobject-or-zlooseobject)), so
164
166
  `z.filesUploadOptions(['scope'])` hands your handler `{ scope }` and nothing else, with the platform default
165
167
  already filled in. Anything you did not expose is yours to pass:
166
168
 
@@ -59,6 +59,12 @@ const tableIdParam = z.string()
59
59
 
60
60
  - The `execute` bag is the shared handler context (see [07-actions.md](07-actions.md)) plus `search`,
61
61
  `cursor`, and the resolved `criteria`.
62
+ - **`search` is always text, trimmed.** It is `''` when the author opened the dropdown without typing or typed
63
+ only spaces, and never `undefined` or `null`. So never guard or convert it: no `String(search)`,
64
+ `search?.trim()` or `(search || '')`. Check it with `if (search)`.
65
+ ⚠️ **Never send it to the API as is.** A query key or body field set to `''` is sent as an empty filter
66
+ (`?name=`), which some APIs read as "name is empty" and answer with nothing. Leave it out when nothing was
67
+ typed: `query: { name: search || undefined }`.
62
68
  - Return `{ items, cursor }` for paginated sources, or a bare `items` array when there is no pagination.
63
69
  - **The `id` starts with `get` and ends with `Dictionary`**, and the const holding the ref carries the same
64
70
  name — so the declaration and every `.dictionary(ref)` read alike.
@@ -145,12 +151,12 @@ const getChatsDictionary = ext.dictionary({
145
151
  description: 'Type a numeric chat ID or @username to resolve the chat.',
146
152
  result : { items: [{ label: 'Team Standup (group)', value: '-1001234567890' }], cursor: null },
147
153
  execute : async ({ search, apiRequest }) => {
148
- if (!search?.trim()) {
154
+ if (!search) {
149
155
  return { items: [], cursor: null }
150
156
  }
151
157
 
152
158
  try {
153
- const chat = await apiRequest({ url: '/getChat', query: { chat_id: search.trim() } })
159
+ const chat = await apiRequest({ url: '/getChat', query: { chat_id: search } })
154
160
 
155
161
  return { items: [{ label: `${ chat.title ?? chat.username } (${ chat.type })`, value: String(chat.id) }] }
156
162
  } catch (error) {
@@ -19,7 +19,7 @@ Actions are the primary operations a service exposes. Register one with `ext.add
19
19
 
20
20
  The runtime parses the incoming input against `params` **before** `execute` runs, so a handler can trust
21
21
  what it receives: defaults are applied, values are coerced by the schema, and unknown fields are stripped
22
- (an action with `dynamicParams` keeps them — its generated fields aren't in the static schema; a `z.looseObject()` keeps the keys it does not declare, which is how a `.dynamicProps()` field keeps its loaded fields). A violation
22
+ (an action with `dynamicParams` keeps them — its generated fields aren't in the static schema; a `z.looseObject()` keeps the keys it does not declare, which is how a `.dynamicProps()` field keeps its loaded fields; see [02-zod-types.md](02-zod-types.md#zobject-or-zlooseobject) for which one a nested object needs). A violation
23
23
  rejects the call with `FR_EXT_INVALID_METHOD_INPUT` and the offending param paths; don't re-check required
24
24
  params by hand inside `execute`. Declare optionality honestly — a `z.string()` that the flow may legitimately
25
25
  leave empty must be `.optional()`.
@@ -104,6 +104,10 @@ execute: async ({ params, apiRequest }) => {
104
104
  The same applies to a list endpoint: return the items **and** the paging fields around them, not a bare
105
105
  array. Adding a derived field is fine — spread the response and add to it — but the original fields stay.
106
106
 
107
+ A response is not converted the way params are: a vendor's `"0"` arrives as the string `"0"`, which is truthy.
108
+ Branch on a response flag by comparing it with the value the vendor documents — see
109
+ [16-gotchas.md](16-gotchas.md#conversion-runs-on-the-way-in-never-on-the-way-back).
110
+
107
111
  ## `execute` context bag
108
112
 
109
113
  The same bag is passed to actions, dictionaries, triggers, and result-loaders (accessed via arguments,
@@ -94,6 +94,9 @@ There is no `.uiComponent()`; the widget follows the zod type (after unwrapping
94
94
  | `z.number()` | `NUMBER` | `NUMERIC_STEPPER` |
95
95
  | `z.boolean()` | `BOOLEAN` | `TOGGLE` |
96
96
  | `z.date()` | `STRING` | `DATE_PICKER` |
97
+ | `z.iso.date()` | `STRING` | `DATE_PICKER` + `valueKind: 'string'` + `format` (the `.dateFormat()` pattern, else `yyyy-MM-dd`) |
98
+ | `z.iso.datetime({ local: true })` | `STRING` | `DATE_TIME_PICKER` + `valueKind: 'string'` + `format` (else `yyyy-MM-dd'T'HH:mm`) |
99
+ | `z.iso.time()` | `STRING` | `TIME_PICKER` + `valueKind: 'string'` + `format` (else `HH:mm`) |
97
100
  | `z.enum([...])` | `STRING` | `DROPDOWN` — `{ value, label }` pairs when `.labels()` is declared, else the enum values |
98
101
  | `z.object({...})` | `OBJECT` | — (recurses into `properties`) |
99
102
  | `z.array(inner)` | `LIST` | — (`items.type` from the element) |
@@ -101,7 +101,7 @@ const getBoardsDictionary = ext.dictionary({
101
101
  execute : async ({ search, cursor, criteria, apiRequest }) => {
102
102
  const response = await apiRequest({
103
103
  url : `/workspaces/${ criteria.workspaceId }/boards`,
104
- query: { q: search, cursor },
104
+ query: { q: search || undefined, cursor }, // '' when nothing was typed: no filter, not an empty one
105
105
  })
106
106
 
107
107
  return {
@@ -156,6 +156,116 @@ The general rule: when one value is reachable in more than one form, either deri
156
156
  place, or make the derivation itself idempotent to the difference. This applies to anything `initContext`
157
157
  touches — a base URL with or without a trailing slash, an id as a string or a number.
158
158
 
159
+ ## Conversion runs on the way in, never on the way back
160
+
161
+ A `z.boolean()` **param** accepts `yes`, `on`, `1`, `'false'` and the rest of the list in
162
+ [02-zod-types.md](02-zod-types.md#what-a-boolean-accepts). Nothing like that happens to what a **vendor** sends
163
+ back: a response is not declared, so it reaches your code exactly as the API serialized it. A flag sent as the
164
+ string `"0"` is truthy:
165
+
166
+ ```js
167
+ note: record.is_active ? 'Active' : 'Archived' // ✗ "0" → 'Active'
168
+ ```
169
+
170
+ That shipped as a disconnected device badged *Online*, unverified senders offered as verified, and archived
171
+ projects labelled *Active* — and in a dictionary's `note` or `label` it is a wrong choice made by a person,
172
+ with nothing anywhere to catch it.
173
+
174
+ **Compare the flag strictly against the value the vendor documents**, at the point you branch on it:
175
+
176
+ | The vendor documents | Branch on |
177
+ |---|---|
178
+ | a JSON boolean | `entry.toll_free === true` |
179
+ | `'1'` / `'0'` | `form.is_active === '1'` |
180
+ | `'true'` / `'false'` | `rule.hidden === 'true'` |
181
+
182
+ - **Read the vendor's docs (or a real response) per field** for the form it sends, and test with that form.
183
+ - **Widen only where the vendor really varies** — one endpoint answering `1` and another `"1"`:
184
+ `[1, '1'].includes(entry.active)`. Not a helper that knows ten spellings.
185
+ - **A pass-through is not this trap.** `list.counts.subscribed ?? 0` forwards a value; only a *branch* on a
186
+ flag can invert one.
187
+ - **An input flag is a param, not a response flag.** A flag that reaches you as a param — a criterion, a
188
+ value bound from a template — is declared `z.boolean()`, and the runtime converts it.
189
+
190
+ ## An object you forward must be a `z.looseObject`
191
+
192
+ A `z.object({ … })` drops every key it does not declare, at every depth. Nothing is refused and nothing is
193
+ logged: your handler simply receives a smaller object than the caller sent. If the handler then forwards
194
+ that object to the API, the request is missing every field the schema did not name, and the call still
195
+ succeeds.
196
+
197
+ ```js
198
+ // ✗ forwarded as is: each table reaches the API as { name }, so its columns are lost
199
+ tables: z.array(z.object({ name: z.string().label('Name') })).label('Tables'),
200
+
201
+ // ✓ the form still draws Name; fields, description and anything the vendor adds pass through
202
+ tables: z.array(z.looseObject({ name: z.string().label('Name') })).label('Tables'),
203
+ ```
204
+
205
+ - **The handler forwards the object → `z.looseObject({ … })`.** Declare only the fields the form should draw.
206
+ - **The handler reads named fields and builds its own request → `z.object({ … })`.** There the dropping is a
207
+ whitelist, which is what you want.
208
+ - **It is easiest to get wrong when you first declare a shape**, for example an element described only in
209
+ prose until now. Adding the shape also adds a filter on every key you did not think to list.
210
+ - **Each level is separate.** A loose object inside a plain one keeps its own extra keys, but the outer object
211
+ still drops its own.
212
+
213
+ Details in [02-zod-types.md](02-zod-types.md#zobject-or-zlooseobject).
214
+
215
+ ## A list is a `z.array`, never comma-separated text you split
216
+
217
+ A param that holds several values, such as ids, emails or tags, is declared as a list of its element type. Do
218
+ not declare it as a "comma-separated" `z.string()` that the handler splits:
219
+
220
+ ```js
221
+ // ✗ a bound list arrives as JSON text: '["1","5"]'.split(',') → ['["1"', '"5"]'] → parseInt → [NaN, NaN],
222
+ // which the API receives as [null, null], and the call still succeeds
223
+ listIds: z.string().label('List IDs').describe('Comma-separated list IDs (e.g. \'1,5,12\').').optional(),
224
+ …
225
+ if (listIds) payload.listIds = listIds.split(',').map(id => parseInt(id.trim(), 10))
226
+
227
+ // ✓ every element is converted and checked before execute runs
228
+ listIds: z.array(z.number()).label('List IDs').describe('IDs of the contact lists to add the contact to.').optional(),
229
+ …
230
+ if (listIds?.length) payload.listIds = listIds
231
+ ```
232
+
233
+ - **The handler gets a real array of the declared type.** `['1', '5']` arrives as `[1, 5]`, and `[1, 'x']` is
234
+ refused with `«List IDs item 2» must be a number`. Do not split, trim or `parseInt` it again.
235
+ - **Choose the element type from the vendor's API docs:** `z.number()` for integer ids, `z.string()` for string
236
+ ids and tags, `z.email()`, `z.url()`, or `z.enum([...])` for a fixed set of values.
237
+ - **A vendor that wants comma text on the wire** (`?fields=a,b`) still gets a `z.array(...)` param. Join it
238
+ with `.join(',')` where you build the request, and nowhere else.
239
+ - **Text is not split for you.** `'1,5,12'` given to a list param is refused with `«List IDs» must be an
240
+ array`. JSON text (`'[1,5,12]'`) is parsed.
241
+ - **Keep the elements required.** A `null` or missing element is then refused with
242
+ `«List IDs item 2» is required`, so no gap reaches the handler. Under `z.string().optional()`,
243
+ `.nullable()` or `z.unknown()` elements, and in any list a vendor sends back, a gap does get through. There,
244
+ turn an element into text with `String(x ?? '')`. `String(x)` gives `'null'` / `'undefined'`, and `x || ''`
245
+ also erases `0` and `false`.
246
+
247
+ Details in [02-zod-types.md](02-zod-types.md#text-and-structures).
248
+
249
+ ## A date the vendor wants as text is `.dateFormat()`, never a `z.date()` you format
250
+
251
+ A `z.date()` value is an **instant**. Turning it into the text a vendor wants (`20/05/2026`, `10:00`) needs a
252
+ time zone, and your handler has none — so the usual code is wrong for every author east of UTC:
253
+
254
+ ```js
255
+ // ✗ the picker stores local midnight: 20 May picked in UTC+3 is 2026-05-19T21:00:00Z
256
+ dueDate: z.date()
257
+ // …
258
+ body.due = new Date(params.dueDate).toISOString().slice(0, 10) // '2026-05-19' — a day early
259
+
260
+ // ✓ the picker stores the day the author clicked, as text in your pattern
261
+ dueDate: z.iso.date().dateFormat('dd/MM/yyyy')
262
+ // …
263
+ body.due = params.dueDate // '20/05/2026'
264
+ ```
265
+
266
+ The same goes for `getUTCDate()` / `getUTCHours()` and hand-rolled `pad2` helpers. Keep `z.date()` for a field
267
+ whose vendor wants an instant. Details in [02-zod-types.md](02-zod-types.md#dates--an-instant-or-a-date-as-text).
268
+
159
269
  ## A schema slot must be a `z.object`, or the method quietly has no inputs
160
270
 
161
271
  `params`, `criteria` and `configItems` are containers of named fields. Hand one anything else and there is
@@ -270,6 +380,7 @@ Do not restate these here; they are covered where they belong.
270
380
  | A binary download is `.toBuffer()`, not a response encoding — an encoded body is parsed and corrupted | [04-http-requests.md](04-http-requests.md) |
271
381
  | `ResponseError.message` is the response *body*, so it can be an object | [04-http-requests.md](04-http-requests.md) |
272
382
  | A blank (`''`) fails `z.url().optional()` — `.optional()` does not cover it | this document |
383
+ | A `.dateFormat()` pattern is checked at load; `YYYY`, `DD`, and `hh` without `a` are refused | [02-zod-types.md](02-zod-types.md#dateformatpattern) |
273
384
  | Secrets in logs, credentials in the URL, credentials or caller headers sent to an origin the service didn't choose, upload MIME type | [19-security.md](19-security.md) |
274
385
  | `.default()` is not applied to realtime-trigger `match` params | [13-runtime-contracts.md](13-runtime-contracts.md) |
275
386
  | `rawBody` is **absent**, not empty, when there is nothing to verify — hashing `''` looks like a bad signature | [09-realtime-triggers.md](09-realtime-triggers.md) |
@@ -11,7 +11,8 @@ touches a file does not need *Files API*.
11
11
 
12
12
  `{ search?, cursor?, criteria? }` in, `{ items: [{ label, value, note? }], cursor }` out
13
13
  ([05-dictionaries.md](05-dictionaries.md)). Cover the mapping, a case-insensitive search, an absent
14
- `search` listing everything, and empty data answering `{ items: [], cursor: null }`.
14
+ `search` listing everything, and empty data answering `{ items: [], cursor: null }`. For an absent `search`,
15
+ assert the exact request too: `execute` receives it as `''`, and the filter must be left out, not sent empty.
15
16
 
16
17
  **A dictionary is invoked through a single `payload` param** — the runner synthesizes it, you never declare
17
18
  it ([05-dictionaries.md](05-dictionaries.md)). So `methodData` wraps the whole `{ search, cursor, criteria }`
@@ -62,7 +62,7 @@ conditional groups that apply, together.
62
62
  | 4 | [04-http-requests.md](04-http-requests.md) | the shared `apiRequest` helper, and the `Flowrunner.Request` client under it — sending model, methods, query, headers, bodies, multipart, responses, `ResponseError` |
63
63
  | 5 | [05-dictionaries.md](05-dictionaries.md) | `ext.dictionary(props)` — dynamic param options; `label` (→ `operationName`, always set it), `criteria` → auto `dependsOn`, optional `result` sample |
64
64
  | 6 | [07-actions.md](07-actions.md) | `ext.addAction(props)`, the shared `execute` context bag, and input validation |
65
- | 7 | [16-gotchas.md](16-gotchas.md) | Cross-cutting traps that fail *silently* — empty-string params, lookup tables keyed by user input, dictionary error handling. Deliberately short |
65
+ | 7 | [16-gotchas.md](16-gotchas.md) | Cross-cutting traps that fail *silently* — empty-string params, lookup tables keyed by user input, dictionary error handling, a forwarded object that drops its keys, a list declared as comma-separated text. Deliberately short |
66
66
  | 8 | [19-security.md](19-security.md) | Four silent security mistakes: secrets in logs, credentials in the URL, credentials or headers sent where the service didn't choose, upload MIME type. Short — check a service against it before calling it done |
67
67
  | 9 | [14-reference-service.md](14-reference-service.md) | A complete verified service exercising the whole surface — **read this instead of the CLI templates** |
68
68