@flowrunner/cli 0.1.17 → 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.
- package/ai-docs/instructions/service-code-format/02-zod-types.md +139 -33
- package/ai-docs/instructions/service-code-format/03-parameters.md +3 -1
- package/ai-docs/instructions/service-code-format/05-dictionaries.md +8 -2
- package/ai-docs/instructions/service-code-format/07-actions.md +1 -1
- package/ai-docs/instructions/service-code-format/11-output-model.md +3 -0
- package/ai-docs/instructions/service-code-format/14-reference-service.md +1 -1
- package/ai-docs/instructions/service-code-format/16-gotchas.md +80 -0
- package/ai-docs/instructions/service-code-format/18-test-recipes.md +2 -1
- package/ai-docs/instructions/service-code-format/README.md +1 -1
- package/dist/cli.js +523 -82
- package/dist/cli.js.map +4 -4
- package/dist/index.js +522 -81
- package/dist/index.js.map +4 -4
- package/dist/types/flow-extension-runner/src/v2/context/execution-context.d.ts +8 -0
- package/dist/types/flow-extension-runner/src/v2/dictionaries/payload-schema.d.ts +1 -1
- package/dist/types/flow-extension-runner/src/v2/params/index.d.ts +2 -0
- package/dist/types/flow-extension-runner/src/v2/params/json/types.d.ts +2 -0
- package/dist/types/flow-extension-runner/src/v2/params/schema/date-format.d.ts +80 -0
- package/dist/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +4 -10
- package/dist/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +7 -0
- package/dist/types/flow-extension-runner/src/v2/params/schema/notices.d.ts +15 -0
- package/dist/types/flow-extension-runner/src/v2/params/widget-types.d.ts +1 -1
- package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +30 -19
- package/dist/types/flow-extension-runner/src/v2/types.d.ts +1 -1
- package/package.json +1 -1
- package/runtime/index.js +529 -82
- package/runtime/index.js.map +4 -4
- package/runtime/types/flow-extension-runner/src/v2/context/execution-context.d.ts +8 -0
- package/runtime/types/flow-extension-runner/src/v2/dictionaries/payload-schema.d.ts +1 -1
- package/runtime/types/flow-extension-runner/src/v2/params/index.d.ts +2 -0
- package/runtime/types/flow-extension-runner/src/v2/params/json/types.d.ts +2 -0
- package/runtime/types/flow-extension-runner/src/v2/params/schema/date-format.d.ts +80 -0
- package/runtime/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +4 -10
- package/runtime/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +7 -0
- package/runtime/types/flow-extension-runner/src/v2/params/schema/notices.d.ts +15 -0
- package/runtime/types/flow-extension-runner/src/v2/params/widget-types.d.ts +1 -1
- package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +30 -19
- 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.
|
|
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,39 +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
|
-
##
|
|
62
|
+
## The widget follows the type — there is no override
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
`
|
|
79
|
-
|
|
80
|
-
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
`z.
|
|
92
|
-
`
|
|
93
|
-
|
|
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:
|
|
139
|
+
|
|
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:
|
|
170
|
+
|
|
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.
|
|
94
196
|
|
|
95
197
|
## The type list is CLOSED
|
|
96
198
|
|
|
@@ -116,6 +218,9 @@ dropped out of type coercion, so the string values a flow supplies were never co
|
|
|
116
218
|
under an unrecognised modifier therefore handed `execute` `false` for an explicit `'true'`. A deploy that
|
|
117
219
|
stops is better than a parameter that looks fine and is wrong.
|
|
118
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
|
+
|
|
119
224
|
These modifiers are looked THROUGH — the parameter publishes and coerces as the type underneath:
|
|
120
225
|
|
|
121
226
|
| Modifier | Published as |
|
|
@@ -292,11 +397,12 @@ you, and `'{a:1}'` (unquoted key) is not JSON. `''` is still a blank; `'{}'` and
|
|
|
292
397
|
|
|
293
398
|
In a union, a value that already fits a branch is kept (see above), and an object or a list is **never** turned
|
|
294
399
|
into text through a `z.string()` branch: it takes a branch of its own kind or the union's error, so a malformed
|
|
295
|
-
object is reported rather than sent as JSON text.
|
|
296
|
-
not declare.
|
|
400
|
+
object is reported rather than sent as JSON text.
|
|
297
401
|
|
|
298
402
|
The flip side: an object bound by mistake to a plain text field (a subject, a name) is sent as JSON text
|
|
299
|
-
rather than refused.
|
|
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).
|
|
300
406
|
|
|
301
407
|
### What a boolean accepts
|
|
302
408
|
|
|
@@ -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
|
|
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
|
|
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
|
|
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()`.
|
|
@@ -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 {
|
|
@@ -187,6 +187,85 @@ with nothing anywhere to catch it.
|
|
|
187
187
|
- **An input flag is a param, not a response flag.** A flag that reaches you as a param — a criterion, a
|
|
188
188
|
value bound from a template — is declared `z.boolean()`, and the runtime converts it.
|
|
189
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
|
+
|
|
190
269
|
## A schema slot must be a `z.object`, or the method quietly has no inputs
|
|
191
270
|
|
|
192
271
|
`params`, `criteria` and `configItems` are containers of named fields. Hand one anything else and there is
|
|
@@ -301,6 +380,7 @@ Do not restate these here; they are covered where they belong.
|
|
|
301
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) |
|
|
302
381
|
| `ResponseError.message` is the response *body*, so it can be an object | [04-http-requests.md](04-http-requests.md) |
|
|
303
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) |
|
|
304
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) |
|
|
305
385
|
| `.default()` is not applied to realtime-trigger `match` params | [13-runtime-contracts.md](13-runtime-contracts.md) |
|
|
306
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
|
|