Skip to content

Commit 6fb80bb

Browse files
committed
add campaignState filter
1 parent a5d497b commit 6fb80bb

File tree

4 files changed

+63
-36
lines changed

4 files changed

+63
-36
lines changed

COMMANDS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ Retrieve campaigns
144144

145145
| Option | Type | Required | Description |
146146
|--------|------|----------|-------------|
147+
| `--campaignState` | enum[] | no | Filter campaigns by state. Can specify multiple states. Valid states: Draft, Ready, Scheduled, Running, Finished, Starting, Aborted, Recurring, Archived |
147148
| `--order` | `asc` \| `desc` | no | Sort direction (asc or desc) |
148149
| `--page` | number | no | Page number (starting at 1) |
149150
| `--pageSize` | number | no | Number of results to return per page (defaults to 20, maximum of 1000) |

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@
5959
"update-commands": "node scripts/update-commands.js"
6060
},
6161
"dependencies": {
62-
"@iterable/api": "0.9.1",
62+
"@iterable/api": "0.10.0",
6363
"@primno/dpapi": "2.0.1",
6464
"boxen": "8.0.1",
6565
"chalk": "5.6.2",
6666
"cli-table3": "0.6.5",
6767
"inquirer": "13.3.2",
6868
"ora": "9.3.0",
69-
"zod": "4.1.11",
69+
"zod": "4.3.6",
7070
"zod-opts": "1.0.0"
7171
},
7272
"devDependencies": {

pnpm-lock.yaml

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/parser.ts

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,27 @@ function getSchemaShape(schema: z.ZodType): Record<string, z.ZodType> {
2222
return {};
2323
}
2424

25-
function canZodOptsHandle(fieldSchema: z.ZodType): boolean {
25+
/**
26+
* zod-opts supports z.array(z.string()) and z.array(z.number()) but not
27+
* z.array(z.enum([...])). For those, substitute z.array(z.string()) so
28+
* the CLI accepts space-separated values. The final schema.parse() in
29+
* parseCommand validates the enum values.
30+
*/
31+
function coerceForZodOpts(fieldSchema: z.ZodType): z.ZodType {
32+
const inner = unwrapSchema(fieldSchema);
33+
if (inner instanceof z.ZodArray) {
34+
const element = unwrapSchema(inner.element as z.ZodType);
35+
if (element instanceof z.ZodEnum) {
36+
const coerced = z.array(z.string());
37+
return fieldSchema instanceof z.ZodOptional
38+
? coerced.optional()
39+
: coerced;
40+
}
41+
}
42+
return fieldSchema;
43+
}
44+
45+
function zodOptsProbe(fieldSchema: z.ZodType): boolean {
2646
try {
2747
parser()
2848
.options({ _probe: { type: fieldSchema.optional() } })
@@ -34,6 +54,12 @@ function canZodOptsHandle(fieldSchema: z.ZodType): boolean {
3454
}
3555
}
3656

57+
function canZodOptsHandle(fieldSchema: z.ZodType): boolean {
58+
if (zodOptsProbe(fieldSchema)) return true;
59+
const coerced = coerceForZodOpts(fieldSchema);
60+
return coerced !== fieldSchema && zodOptsProbe(coerced);
61+
}
62+
3763
// Only return scalar defaults for display in --help and COMMANDS.md.
3864
// Complex defaults (objects, arrays) are omitted since those fields are
3965
// rendered as JSON fallback inputs where showing a default isn't useful.
@@ -218,7 +244,7 @@ export function buildParser(
218244
} else {
219245
const fieldSchema = shape[field.name];
220246
if (fieldSchema) {
221-
options[field.name] = { type: fieldSchema };
247+
options[field.name] = { type: coerceForZodOpts(fieldSchema) };
222248
}
223249
}
224250
}

0 commit comments

Comments
 (0)