@flowrunner/cli 0.1.18 → 0.1.19

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 (28) hide show
  1. package/ai-docs/instructions/service-code-format/02-zod-types.md +115 -7
  2. package/ai-docs/instructions/service-code-format/11-output-model.md +3 -0
  3. package/ai-docs/instructions/service-code-format/16-gotchas.md +30 -6
  4. package/dist/cli.js +625 -48
  5. package/dist/cli.js.map +4 -4
  6. package/dist/index.js +624 -47
  7. package/dist/index.js.map +4 -4
  8. package/dist/types/flow-extension-runner/src/v2/context/execution-context.d.ts +8 -0
  9. package/dist/types/flow-extension-runner/src/v2/params/index.d.ts +2 -0
  10. package/dist/types/flow-extension-runner/src/v2/params/json/types.d.ts +2 -0
  11. package/dist/types/flow-extension-runner/src/v2/params/schema/date-format.d.ts +80 -0
  12. package/dist/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +3 -2
  13. package/dist/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +9 -2
  14. package/dist/types/flow-extension-runner/src/v2/params/schema/introspect.d.ts +8 -0
  15. package/dist/types/flow-extension-runner/src/v2/params/schema/notices.d.ts +15 -0
  16. package/dist/types/flow-extension-runner/src/v2/params/zod.d.ts +21 -0
  17. package/package.json +1 -1
  18. package/runtime/index.js +631 -48
  19. package/runtime/index.js.map +4 -4
  20. package/runtime/types/flow-extension-runner/src/v2/context/execution-context.d.ts +8 -0
  21. package/runtime/types/flow-extension-runner/src/v2/params/index.d.ts +2 -0
  22. package/runtime/types/flow-extension-runner/src/v2/params/json/types.d.ts +2 -0
  23. package/runtime/types/flow-extension-runner/src/v2/params/schema/date-format.d.ts +80 -0
  24. package/runtime/types/flow-extension-runner/src/v2/params/schema/defaults.d.ts +3 -2
  25. package/runtime/types/flow-extension-runner/src/v2/params/schema/field-plan.d.ts +9 -2
  26. package/runtime/types/flow-extension-runner/src/v2/params/schema/introspect.d.ts +8 -0
  27. package/runtime/types/flow-extension-runner/src/v2/params/schema/notices.d.ts +15 -0
  28. package/runtime/types/flow-extension-runner/src/v2/params/zod.d.ts +21 -0
@@ -12,6 +12,7 @@ and behaviors.
12
12
  | `z.boolean()` | toggle | | `.optional()` | any field | not required (required is default) |
13
13
  | `z.enum([...])` | dropdown | | `.default(v)` | any field | default value |
14
14
  | `z.date()` | date picker | | `.shared()` | config field | `shared:true` (OAuth client id/secret) |
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'` |
15
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)) |
16
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 |
@@ -71,6 +72,7 @@ what the **handler** needs, and convert in the handler:
71
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)) | — |
72
73
  | Several lines of text | `z.text()` | — |
73
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)) |
74
76
 
75
77
  **`z.json()` is not supported.** It fails when the extension loads, with a message naming the two declarations
76
78
  above. A value whose shape you don't declare is `z.unknown()`. One you do know is the shape itself, which
@@ -112,6 +114,95 @@ The top-level `params` object is the exception. It is always a `z.object()`, and
112
114
  dropped unless the action declares `dynamicParams` (see [07-actions.md](07-actions.md)). Looseness is for the
113
115
  objects **inside** it.
114
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
+ | `'HH:mm a'` | a 24-hour clock with `a` writes `13:45 PM`, which cannot be read back — use `hh:mm a` or `HH:mm` |
164
+ | `.dateFormat()` on `z.string()`, `z.date()`, or `z.iso.datetime()` without `{ local: true }` | only the three wall-clock types take a format |
165
+ | `.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')` |
166
+
167
+ ### What a date-as-text field accepts
168
+
169
+ A value picked in the editor already has your pattern. A value **bound from another block** may be any text,
170
+ and is reshaped from the characters as written:
171
+
172
+ | Declared `.dateFormat('dd/MM/yyyy')`, given | `execute` receives |
173
+ |---|---|
174
+ | `'31/01/2024'` | `'31/01/2024'` |
175
+ | `'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 |
176
+ | `'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` |
177
+ | 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()` |
178
+
179
+ - **Strict.** The text must be exactly what the pattern writes — `1/1/2024` is not `dd/MM/yyyy`, `1:45 pm` is not
180
+ `h:mm a`, and `31/02/2024` or `24:00` is no date at all.
181
+ - **Nothing is invented.** A date alone is refused by a date-and-time or a time field, rather than given a
182
+ midnight nobody picked.
183
+ - **An ISO value with `Z`** keeps its UTC date: `new Date().toISOString()` just after midnight in UTC+3 is still
184
+ yesterday's date in UTC. If the local day matters, format it in the zone you mean before it reaches the field.
185
+ - **Blank is "not set"**, as on a number: `''`, `null` and a missing value follow `.optional()` / `.nullable()` /
186
+ `.default()`. `.min()` / `.max()` are not available on these types.
187
+ - **A pattern made only of digits** (`yyyyMMdd`, `HHmm`) is fine: `20240131` is read as that date, and a value
188
+ that is no date in it (`20241331`) is refused like any other.
189
+ - **To let a flow clear a date**, declare a union with an empty branch:
190
+ `z.union([z.iso.date().dateFormat('dd/MM/yyyy'), z.literal('')]).optional()` (or with `z.date()`). The picker
191
+ stays; `''` (the flow sets the field to Empty Text, or binds an empty value) reaches `execute` as `''`, and an
192
+ untouched field arrives as `undefined`. Map `''` to the vendor's clear in the handler. **Never use `null` as
193
+ the clear signal**: a field left empty in a block arrives as `null`, so `.nullable()` would clear the date on
194
+ every run. This holds for `z.date()` as well — see [Clearing a value](#clearing-a-value).
195
+ - Inside an object or a list it behaves the same, and a failure names the property (`«Days item 2» must be …`).
196
+
197
+ ### Moving a field from `z.date()` to a date as text
198
+
199
+ A flow saved against `z.date()` holds the old picker's **timestamp**. When an author opens the block, the
200
+ console converts it to your pattern **in the author's own time zone** — the day they originally picked — and
201
+ notes *"Converted from an older saved value — check it and save."* Ask your users to open and save the flows
202
+ that use the field. A flow that is never re-saved keeps sending the timestamp: for a transition period the
203
+ runtime still accepts it, reading it in **UTC** (a day early for an author east of UTC), and after that it is
204
+ refused like any other timestamp.
205
+
115
206
  ## The type list is CLOSED
116
207
 
117
208
  The table above is what a service declares day to day. A few more types are accepted and rarely reached for:
@@ -229,7 +320,7 @@ converted:
229
320
  ```js
230
321
  limit: z.union([z.number(), z.literal('max')]) // '5' → 5 'max' → 'max'
231
322
  mode : z.union([z.boolean(), z.literal('auto')]) // 'false' → false 'auto' → 'auto'
232
- scope: z.union([z.number(), z.enum(['all', 'none'])]) // '5' → 5 'all' → 'all' 'x' → «Scope» is invalid
323
+ scope: z.union([z.number(), z.enum(['all', 'none'])]) // '5' → 5 'all' → 'all' 'x' → «Scope» must be a number, or one of: all, none
233
324
  ```
234
325
 
235
326
  Keep `z.string()` in a union only when free text really is one of the forms, and convert in the handler if
@@ -239,17 +330,33 @@ you need a number out of it. For a value that must pass through untouched whatev
239
330
  A constraint is part of "fits": `z.union([z.number().min(10), z.string()])` given `5` hands over `'5'`,
240
331
  because the number branch refuses it and the string branch takes it converted.
241
332
 
242
- ### A blank means "not set"
333
+ A value no branch accepts is refused with what **every** branch expects, in declared order: `«Scope» must be a
334
+ number, or one of: all, none`. A `z.literal('')` branch is left out, so a `''` union reads like its other
335
+ branch.
336
+
337
+ ### Clearing a value
338
+
339
+ A flow sends three kinds of "nothing", and only one of them is deliberate:
340
+
341
+ | In the block | `execute` receives |
342
+ |---|---|
343
+ | the field left untouched, or cleared | `null` → absence (`undefined` under `.optional()`) |
344
+ | the **Empty Text** chip, or a bound `''` | `''` |
345
+ | a cleared text box in the **config dialog** | `''` |
243
346
 
244
- `''` is a real value on a plain `z.string()`, which is why a cleared text box fails an optional formatted
245
- field. On a union it is absence, and that is the spelling to reach for:
347
+ `''` is a value on a plain `z.string()`. On every other type it is absence — unless you declare it with a
348
+ `z.literal('')` branch, which keeps it as a value. That is how a field lets a flow **clear** something:
246
349
 
247
350
  ```js
248
- webhookUrl: z.url().optional() // blank → «Webhook URL» is invalid — expects a URL
249
- webhookUrl: z.union([z.url(), z.literal('')]).optional() // blank → not provided
351
+ dueDate : z.union([z.date(), z.literal('')]).optional() // untouched → undefined Empty Text → '' a date → the date
352
+ webhookUrl: z.url().optional() // '' → «Webhook URL» is invalid — expects a URL
353
+ webhookUrl: z.union([z.url(), z.literal('')]).optional() // '' → '' untouched → undefined
250
354
  ```
251
355
 
252
- See [16-gotchas.md](16-gotchas.md) for the rest of that trap.
356
+ The handler decides what `''` means for the vendor: send the vendor's clear (`body.dueDate = null` when
357
+ `params.dueDate === ''`), or leave the field out (`params.webhookUrl || undefined`). Never make `null` the
358
+ clear signal — an untouched field arrives as `null`, so the vendor's value would be cleared on every run. See
359
+ [16-gotchas.md](16-gotchas.md) for the rest of that trap.
253
360
 
254
361
  ## Config fields publish a smaller set of types
255
362
 
@@ -360,6 +467,7 @@ field by its `.label()`:
360
467
  «Retries» must be at least 1
361
468
  «Site» is invalid — expects a URL, e.g. https://example.com
362
469
  «Region» must be one of: us, eu
470
+ «Scope» must be a number, or one of: all, none
363
471
  ```
364
472
 
365
473
  The console checks the *same* schema while the form is being filled in, so a config dialog reports the same
@@ -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) |
@@ -25,7 +25,8 @@ builder that prunes `''` makes the documented "leave it blank to clear it" behav
25
25
  error anywhere.
26
26
 
27
27
  **The inverse is equally sharp, and appears the moment you fix the first half.** Once `''` reaches the wire,
28
- every optional string param sends one when the flow author leaves it blank — and for an API where an absent
28
+ every optional string param sends one whenever a flow passes an empty value (a cleared config field, the Empty
29
+ Text chip, a bound `''`; a block field left untouched arrives as `null`, which is absence) — and for an API where an absent
29
30
  field means *keep the current value*, a blank one now **overwrites** it. Copy/duplicate endpoints are the
30
31
  usual place this bites: an absent caption keeps the original, an empty caption erases it.
31
32
 
@@ -41,15 +42,17 @@ documentation.
41
42
  ### The same `''` fails a format-constrained field
42
43
 
43
44
  Because `''` is a value, it reaches the format check and fails it — and `.optional()` does not help, since
44
- the field WAS provided. A cleared text box is what sends it, so this fires the first time a flow author
45
- leaves an optional URL or email blank:
45
+ the field WAS provided. A cleared config text box sends it, and so does a flow passing an empty value, so this
46
+ fires the first time someone clears an optional URL or email:
46
47
 
47
48
  ```js
48
- webhookUrl: z.url().optional().label('Webhook URL') // blank → «Webhook URL» is invalid — expects a URL
49
- webhookUrl: z.union([z.url(), z.literal('')]).optional().label('Webhook URL') // blank → not provided
49
+ webhookUrl: z.url().optional().label('Webhook URL') // '' → «Webhook URL» is invalid — expects a URL
50
+ webhookUrl: z.union([z.url(), z.literal('')]).optional().label('Webhook URL') // '' → '' (a value)
50
51
  ```
51
52
 
52
- Declare the union wherever blank has to mean "not set". A non-empty value still has to satisfy the format.
53
+ Declare the union wherever an empty value must be accepted, then decide in the handler what `''` means:
54
+ `params.webhookUrl || undefined` when empty means "not set", the vendor's clear when it means "clear it". A
55
+ non-empty value still has to satisfy the format.
53
56
 
54
57
  ## An optional object the author never filled in is absent — but may still arrive as `{}`
55
58
 
@@ -246,6 +249,26 @@ if (listIds?.length) payload.listIds = listIds
246
249
 
247
250
  Details in [02-zod-types.md](02-zod-types.md#text-and-structures).
248
251
 
252
+ ## A date the vendor wants as text is `.dateFormat()`, never a `z.date()` you format
253
+
254
+ A `z.date()` value is an **instant**. Turning it into the text a vendor wants (`20/05/2026`, `10:00`) needs a
255
+ time zone, and your handler has none — so the usual code is wrong for every author east of UTC:
256
+
257
+ ```js
258
+ // ✗ the picker stores local midnight: 20 May picked in UTC+3 is 2026-05-19T21:00:00Z
259
+ dueDate: z.date()
260
+ // …
261
+ body.due = new Date(params.dueDate).toISOString().slice(0, 10) // '2026-05-19' — a day early
262
+
263
+ // ✓ the picker stores the day the author clicked, as text in your pattern
264
+ dueDate: z.iso.date().dateFormat('dd/MM/yyyy')
265
+ // …
266
+ body.due = params.dueDate // '20/05/2026'
267
+ ```
268
+
269
+ The same goes for `getUTCDate()` / `getUTCHours()` and hand-rolled `pad2` helpers. Keep `z.date()` for a field
270
+ whose vendor wants an instant. Details in [02-zod-types.md](02-zod-types.md#dates--an-instant-or-a-date-as-text).
271
+
249
272
  ## A schema slot must be a `z.object`, or the method quietly has no inputs
250
273
 
251
274
  `params`, `criteria` and `configItems` are containers of named fields. Hand one anything else and there is
@@ -360,6 +383,7 @@ Do not restate these here; they are covered where they belong.
360
383
  | A binary download is `.toBuffer()`, not a response encoding — an encoded body is parsed and corrupted | [04-http-requests.md](04-http-requests.md) |
361
384
  | `ResponseError.message` is the response *body*, so it can be an object | [04-http-requests.md](04-http-requests.md) |
362
385
  | A blank (`''`) fails `z.url().optional()` — `.optional()` does not cover it | this document |
386
+ | A `.dateFormat()` pattern is checked at load; `YYYY`, `DD`, and `hh` without `a` are refused | [02-zod-types.md](02-zod-types.md#dateformatpattern) |
363
387
  | 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) |
364
388
  | `.default()` is not applied to realtime-trigger `match` params | [13-runtime-contracts.md](13-runtime-contracts.md) |
365
389
  | `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) |