@terreno/admin-backend 57.3.0 → 57.4.0

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 (44) hide show
  1. package/bunfig.toml +9 -1
  2. package/dist/adminApp.d.ts +20 -2
  3. package/dist/adminApp.js +468 -363
  4. package/dist/adminConfigIdentity.d.ts +1 -0
  5. package/dist/adminConfigIdentity.js +1 -0
  6. package/dist/adminMigrations.d.ts +10 -0
  7. package/dist/adminMigrations.js +205 -0
  8. package/dist/adminScriptJob.d.ts +32 -0
  9. package/dist/adminScriptJob.js +360 -0
  10. package/dist/adminTextSearch.d.ts +1 -0
  11. package/dist/adminTextSearch.js +1 -0
  12. package/dist/adminUiV2.d.ts +2 -0
  13. package/dist/aggregateAdmin.js +2 -0
  14. package/dist/enrichAdminListFilters.d.ts +7 -0
  15. package/dist/enrichAdminListFilters.js +37 -0
  16. package/dist/filterParser.js +139 -12
  17. package/dist/index.d.ts +2 -0
  18. package/dist/index.js +4 -1
  19. package/dist/legacy.js +4 -2
  20. package/dist/resolvedAdminModel.js +2 -1
  21. package/package.json +7 -7
  22. package/src/adminApp.migrations.test.ts +232 -0
  23. package/src/adminApp.models.test.ts +645 -1
  24. package/src/adminApp.syncMeta.test.ts +237 -0
  25. package/src/adminApp.test.ts +92 -0
  26. package/src/adminApp.ts +344 -124
  27. package/src/adminConfigIdentity.ts +1 -0
  28. package/src/adminHttpGoldens.test.ts +337 -0
  29. package/src/adminMigrations.ts +157 -0
  30. package/src/adminScriptJob.test.ts +297 -0
  31. package/src/adminScriptJob.ts +271 -0
  32. package/src/adminSyncMutationAuthMismatch.test.ts +650 -0
  33. package/src/adminTextSearch.test.ts +28 -0
  34. package/src/adminTextSearch.ts +1 -0
  35. package/src/adminUiV2.ts +2 -0
  36. package/src/aggregateAdmin.test.ts +125 -0
  37. package/src/aggregateAdmin.ts +2 -0
  38. package/src/enrichAdminListFilters.test.ts +44 -0
  39. package/src/enrichAdminListFilters.ts +29 -0
  40. package/src/filterParser.test.ts +95 -0
  41. package/src/filterParser.ts +156 -10
  42. package/src/index.ts +2 -0
  43. package/src/legacy.ts +5 -1
  44. package/src/resolvedAdminModel.ts +2 -1
@@ -2,11 +2,13 @@ import {describe, expect, it} from "bun:test";
2
2
  import type {AdminConfig, AdminContribution, TerrenoPlugin} from "@terreno/api";
3
3
  import {modelRouter, Permissions} from "@terreno/api";
4
4
  import {FoodModel} from "@terreno/api/testing";
5
+ import {assert} from "chai";
5
6
 
6
7
  import type {AdminModelConfig} from "./adminApp";
7
8
  import {
8
9
  aggregateAdminContributions,
9
10
  aggregateFromTerrenoApp,
11
+ collectPluginAdminContributions,
10
12
  collectRegisteredAdminModels,
11
13
  } from "./aggregateAdmin";
12
14
  import {resetLegacyDeprecationWarningsForTests} from "./legacy";
@@ -75,6 +77,56 @@ describe("aggregateAdminContributions", () => {
75
77
  expect(aggregated.widgetIds).toEqual(["feature-flags-overrides"]);
76
78
  });
77
79
 
80
+ it("forwards custom screen group metadata from plugin contributions", () => {
81
+ const aggregated = aggregateAdminContributions({
82
+ pluginContributions: [
83
+ {
84
+ customScreens: [
85
+ {
86
+ displayName: "Overview",
87
+ group: "Announcements",
88
+ icon: "bullhorn",
89
+ name: "announcements",
90
+ },
91
+ ],
92
+ },
93
+ ],
94
+ });
95
+
96
+ assert.equal(aggregated.customScreens[0]?.group, "Announcements");
97
+ assert.equal(aggregated.customScreens[0]?.icon, "bullhorn");
98
+ });
99
+
100
+ it("merges unique scripts, screens, and widget ids and skips duplicates", () => {
101
+ const runner = async (): Promise<void> => {};
102
+ const aggregated = aggregateAdminContributions({
103
+ pluginContributions: [
104
+ {
105
+ customScreens: [{displayName: "Docs", name: "documents"}],
106
+ homeWidgets: [{displayName: "A", id: "w1"}],
107
+ scripts: [{description: "one", name: "seed", runner}],
108
+ },
109
+ {
110
+ customScreens: [
111
+ {displayName: "Docs again", name: "documents"},
112
+ {displayName: "Flags", name: "flags"},
113
+ ],
114
+ homeWidgets: [
115
+ {displayName: "A", id: "w1"},
116
+ {displayName: "B", id: "w2"},
117
+ ],
118
+ scripts: [
119
+ {description: "dup", name: "seed", runner},
120
+ {description: "two", name: "wipe", runner},
121
+ ],
122
+ },
123
+ ],
124
+ });
125
+ expect(aggregated.customScreens.map((screen) => screen.name)).toEqual(["documents", "flags"]);
126
+ expect(aggregated.scripts.map((script) => script.name)).toEqual(["seed", "wipe"]);
127
+ expect(aggregated.widgetIds).toEqual(["w1", "w2"]);
128
+ });
129
+
78
130
  it("forwards populatePaths from plugin model contributions", () => {
79
131
  const aggregated = aggregateAdminContributions({
80
132
  pluginContributions: [
@@ -127,6 +179,57 @@ describe("aggregateAdminContributions", () => {
127
179
  })
128
180
  ).toThrow(/Duplicate admin modelRouter routePath/);
129
181
  });
182
+
183
+ it("merges plugin scripts and custom screens, skipping duplicate names", () => {
184
+ const pluginContribution: AdminContribution = {
185
+ customScreens: [
186
+ {displayName: "Flags", name: "feature-flags"},
187
+ {displayName: "Flags again", name: "feature-flags"},
188
+ ],
189
+ scripts: [
190
+ {
191
+ description: "Seed foods",
192
+ name: "seed-foods",
193
+ runner: async () => ({results: [], success: true}),
194
+ },
195
+ {
196
+ description: "Duplicate seed",
197
+ name: "seed-foods",
198
+ runner: async () => ({results: [], success: true}),
199
+ },
200
+ ],
201
+ };
202
+
203
+ const aggregated = aggregateAdminContributions({
204
+ pluginContributions: [pluginContribution],
205
+ });
206
+
207
+ assert.deepEqual(
208
+ aggregated.customScreens.map((screen) => screen.name),
209
+ ["feature-flags"]
210
+ );
211
+ assert.equal(aggregated.customScreens[0]?.displayName, "Flags");
212
+ assert.deepEqual(
213
+ aggregated.scripts.map((script) => script.name),
214
+ ["seed-foods"]
215
+ );
216
+ assert.equal(aggregated.scripts[0]?.description, "Seed foods");
217
+ });
218
+
219
+ it("skips duplicate home widget ids", () => {
220
+ const aggregated = aggregateAdminContributions({
221
+ pluginContributions: [
222
+ {
223
+ homeWidgets: [
224
+ {displayName: "Overrides", id: "feature-flags-overrides"},
225
+ {displayName: "Overrides again", id: "feature-flags-overrides"},
226
+ ],
227
+ },
228
+ ],
229
+ });
230
+
231
+ assert.deepEqual(aggregated.widgetIds, ["feature-flags-overrides"]);
232
+ });
130
233
  });
131
234
 
132
235
  describe("aggregateFromTerrenoApp", () => {
@@ -153,6 +256,16 @@ describe("aggregateFromTerrenoApp", () => {
153
256
  expect(aggregated.models).toHaveLength(1);
154
257
  expect(aggregated.models[0]?.routePath).toBe("/feature-flags");
155
258
  });
259
+
260
+ it("ignores plugins without an admin contribution", () => {
261
+ expect(
262
+ collectPluginAdminContributions({
263
+ getPlugins: () => [{register() {}}],
264
+ getRegistrations: () => [],
265
+ } as never)
266
+ ).toEqual([]);
267
+ expect(collectPluginAdminContributions()).toEqual([]);
268
+ });
156
269
  });
157
270
 
158
271
  const anyPermissions = {
@@ -164,6 +277,18 @@ const anyPermissions = {
164
277
  };
165
278
 
166
279
  describe("collectRegisteredAdminModels", () => {
280
+ it("returns an empty list without a TerrenoApp", () => {
281
+ expect(collectRegisteredAdminModels()).toEqual([]);
282
+ });
283
+
284
+ it("skips non-modelRouter registrations", () => {
285
+ const registered = collectRegisteredAdminModels({
286
+ getPlugins: () => [],
287
+ getRegistrations: () => [{__type: "plugin", register() {}} as never],
288
+ } as never);
289
+ expect(registered).toEqual([]);
290
+ });
291
+
167
292
  it("does not copy the public queryFilter onto admin CRUD", () => {
168
293
  const registered = collectRegisteredAdminModels({
169
294
  getPlugins: () => [],
@@ -37,6 +37,8 @@ const contributionScriptToConfig = (script: AdminScriptContribution): AdminScrip
37
37
  const contributionScreenToConfig = (screen: AdminCustomScreen): AdminCustomScreenConfig => ({
38
38
  adminAccess: screen.adminAccess,
39
39
  displayName: screen.displayName,
40
+ group: screen.group,
41
+ icon: screen.icon,
40
42
  name: screen.name,
41
43
  });
42
44
 
@@ -0,0 +1,44 @@
1
+ import {describe, expect, it} from "bun:test";
2
+ import mongoose from "mongoose";
3
+ import type {AdminListFilter} from "./adminUiV2";
4
+ import {enrichAdminListFilters} from "./enrichAdminListFilters";
5
+
6
+ const prioritySchema = new mongoose.Schema({
7
+ name: {required: true, type: String},
8
+ priority: {enum: ["low", "high"], type: String},
9
+ status: {enum: ["open", "closed"], required: true, type: String},
10
+ });
11
+ const PriorityModel =
12
+ mongoose.models.AdminEnrichPriority ?? mongoose.model("AdminEnrichPriority", prioritySchema);
13
+
14
+ describe("enrichAdminListFilters", () => {
15
+ it("sets allowEmpty for optional choice filters from the schema", () => {
16
+ const filters: AdminListFilter[] = [
17
+ {
18
+ choices: [{label: "High", value: "high"}],
19
+ field: "priority",
20
+ kind: "choice",
21
+ },
22
+ {
23
+ choices: [{label: "Open", value: "open"}],
24
+ field: "status",
25
+ kind: "choice",
26
+ },
27
+ ];
28
+ const enriched = enrichAdminListFilters(filters, PriorityModel);
29
+ expect(enriched?.[0]).toEqual({...filters[0], allowEmpty: true});
30
+ expect(enriched?.[1]).toEqual(filters[1]);
31
+ });
32
+
33
+ it("preserves explicit allowEmpty", () => {
34
+ const filters: AdminListFilter[] = [
35
+ {
36
+ allowEmpty: false,
37
+ choices: [{label: "High", value: "high"}],
38
+ field: "priority",
39
+ kind: "choice",
40
+ },
41
+ ];
42
+ expect(enrichAdminListFilters(filters, PriorityModel)).toEqual(filters);
43
+ });
44
+ });
@@ -0,0 +1,29 @@
1
+ import type {Model} from "mongoose";
2
+
3
+ import type {AdminListFilter} from "./adminUiV2";
4
+
5
+ /**
6
+ * Derives `allowEmpty` for optional choice filters from the Mongoose schema when not
7
+ * set explicitly on admin config.
8
+ */
9
+ export const enrichAdminListFilters = (
10
+ filters: AdminListFilter[] | undefined,
11
+ model: Model<unknown>
12
+ ): AdminListFilter[] | undefined => {
13
+ if (!filters) {
14
+ return filters;
15
+ }
16
+ return filters.map((filter) => {
17
+ if (filter.kind !== "choice") {
18
+ return filter;
19
+ }
20
+ if (filter.allowEmpty !== undefined) {
21
+ return filter;
22
+ }
23
+ const path = model.schema.path(filter.field);
24
+ if (!path || path.isRequired) {
25
+ return filter;
26
+ }
27
+ return {...filter, allowEmpty: true};
28
+ });
29
+ };
@@ -1,5 +1,7 @@
1
1
  import {describe, expect, it} from "bun:test";
2
2
 
3
+ import {ADMIN_LIST_CHOICE_EMPTY_VALUE} from "@terreno/api";
4
+
3
5
  import type {AdminListFilter} from "./adminUiV2";
4
6
  import {parseAdminListFilters} from "./filterParser";
5
7
 
@@ -53,6 +55,59 @@ describe("parseAdminListFilters", () => {
53
55
  expect(errors.$where).toBeDefined();
54
56
  });
55
57
 
58
+ it("parses choice $in and text $regex filters", () => {
59
+ const {errors, filter} = parseAdminListFilters(
60
+ {
61
+ name: {$options: "i", $regex: "ali"},
62
+ role: {$in: ["staff", "admin"]},
63
+ },
64
+ [
65
+ {
66
+ choices: [
67
+ {label: "Staff", value: "staff"},
68
+ {label: "Admin", value: "admin"},
69
+ ],
70
+ field: "role",
71
+ kind: "choice",
72
+ },
73
+ {field: "name", kind: "text"},
74
+ ]
75
+ );
76
+
77
+ expect(errors).toEqual({});
78
+ expect(filter.role).toEqual({$in: ["staff", "admin"]});
79
+ expect(filter.name).toEqual({$options: "i", $regex: "ali"});
80
+ });
81
+
82
+ it("rejects invalid choice $in values and top-level $or", () => {
83
+ const {errors} = parseAdminListFilters(
84
+ {
85
+ $or: [{name: "alice"}],
86
+ role: {$in: ["missing"]},
87
+ },
88
+ [{choices: [{label: "Staff", value: "staff"}], field: "role", kind: "choice"}]
89
+ );
90
+
91
+ expect(errors.role).toBeDefined();
92
+ expect(errors.$or).toBeDefined();
93
+ });
94
+
95
+ it("rejects executable regex patterns and undeclared nested operators", () => {
96
+ const {errors} = parseAdminListFilters(
97
+ {
98
+ name: {$options: "i", $regex: ".*"},
99
+ role: {$in: ["staff"], $ne: "admin"},
100
+ },
101
+ [
102
+ {choices: [{label: "Staff", value: "staff"}], field: "role", kind: "choice"},
103
+ {field: "name", kind: "text"},
104
+ ]
105
+ );
106
+
107
+ expect(errors.name).toBeDefined();
108
+ expect(errors.role).toBeDefined();
109
+ });
110
+
56
111
  it("drops prototype pollution keys without surfacing them as filter errors", () => {
57
112
  const {errors, filter} = parseAdminListFilters(
58
113
  {
@@ -65,4 +120,44 @@ describe("parseAdminListFilters", () => {
65
120
  expect(errors).toEqual({});
66
121
  expect(filter.admin).toBe(true);
67
122
  });
123
+
124
+ it("maps empty sentinel to null for optional choice filters", () => {
125
+ const priorityFilter: AdminListFilter = {
126
+ allowEmpty: true,
127
+ choices: [
128
+ {label: "High", value: "high"},
129
+ {label: "Low", value: "low"},
130
+ ],
131
+ field: "priority",
132
+ kind: "choice",
133
+ };
134
+
135
+ const emptyOnly = parseAdminListFilters({priority: {$in: [ADMIN_LIST_CHOICE_EMPTY_VALUE]}}, [
136
+ priorityFilter,
137
+ ]);
138
+ expect(emptyOnly.errors).toEqual({});
139
+ expect(emptyOnly.filter.priority).toBeNull();
140
+
141
+ const highOnly = parseAdminListFilters({priority: "high"}, [priorityFilter]);
142
+ expect(highOnly.errors).toEqual({});
143
+ expect(highOnly.filter.priority).toBe("high");
144
+
145
+ const combined = parseAdminListFilters(
146
+ {priority: {$in: ["high", ADMIN_LIST_CHOICE_EMPTY_VALUE]}},
147
+ [priorityFilter]
148
+ );
149
+ expect(combined.errors).toEqual({});
150
+ expect(combined.filter.priority).toEqual({$in: ["high", null]});
151
+ });
152
+
153
+ it("rejects empty sentinel when allowEmpty is false", () => {
154
+ const {errors} = parseAdminListFilters({priority: {$in: [ADMIN_LIST_CHOICE_EMPTY_VALUE]}}, [
155
+ {
156
+ choices: [{label: "High", value: "high"}],
157
+ field: "priority",
158
+ kind: "choice",
159
+ },
160
+ ]);
161
+ expect(errors.priority).toBeDefined();
162
+ });
68
163
  });
@@ -1,9 +1,25 @@
1
- import type {AdminFilter} from "@terreno/api";
2
- import {logger} from "@terreno/api";
1
+ import type {AdminFilter, AdminFilterChoice} from "@terreno/api";
2
+ import {ADMIN_LIST_CHOICE_EMPTY_VALUE, logger} from "@terreno/api";
3
3
  import {DateTime} from "luxon";
4
4
  import mongoose from "mongoose";
5
5
 
6
6
  const POLLUTION_KEYS = new Set(["__proto__", "constructor", "prototype"]);
7
+ const REGEX_META_CHARACTERS = new Set([
8
+ "\\",
9
+ ".",
10
+ "*",
11
+ "+",
12
+ "?",
13
+ "^",
14
+ "$",
15
+ "{",
16
+ "}",
17
+ "(",
18
+ ")",
19
+ "|",
20
+ "[",
21
+ "]",
22
+ ]);
7
23
 
8
24
  const isOperatorKey = (key: string): boolean => {
9
25
  return key.startsWith("$");
@@ -31,6 +47,29 @@ const scalarString = (value: unknown): string | undefined => {
31
47
  return undefined;
32
48
  };
33
49
 
50
+ const hasOnlyKeys = (record: Record<string, unknown>, allowedKeys: string[]): boolean => {
51
+ const allowed = new Set(allowedKeys);
52
+ return Object.keys(record).every((key) => allowed.has(key));
53
+ };
54
+
55
+ const isEscapedRegexLiteral = (value: string): boolean => {
56
+ for (let index = 0; index < value.length; index += 1) {
57
+ const character = value[index];
58
+ if (character === "\\") {
59
+ const escapedCharacter = value[index + 1];
60
+ if (!escapedCharacter || !REGEX_META_CHARACTERS.has(escapedCharacter)) {
61
+ return false;
62
+ }
63
+ index += 1;
64
+ continue;
65
+ }
66
+ if (REGEX_META_CHARACTERS.has(character)) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ };
72
+
34
73
  const parseBooleanFilter = (
35
74
  field: string,
36
75
  value: unknown
@@ -60,20 +99,115 @@ const parseTextFilter = (
60
99
  return {ok: true, value: scalar};
61
100
  };
62
101
 
102
+ const parseTextRegexFilter = (
103
+ field: string,
104
+ value: unknown
105
+ ): {ok: true; value: {$options: "i"; $regex: string}} | {ok: false; error: string} => {
106
+ if (value == null || typeof value !== "object" || Array.isArray(value)) {
107
+ return {error: `${field} must be a case-insensitive regex filter`, ok: false};
108
+ }
109
+ const record = value as Record<string, unknown> & {$options?: unknown; $regex?: unknown};
110
+ if (!hasOnlyKeys(record, ["$options", "$regex"])) {
111
+ return {error: `${field} contains an unsupported regex operator`, ok: false};
112
+ }
113
+ if (record.$options !== "i") {
114
+ return {error: `${field} must use $options "i"`, ok: false};
115
+ }
116
+ const regex = scalarString(record.$regex);
117
+ if (!regex || !isEscapedRegexLiteral(regex)) {
118
+ return {error: `${field} must include an escaped literal $regex pattern`, ok: false};
119
+ }
120
+ return {ok: true, value: {$options: "i", $regex: regex}};
121
+ };
122
+
123
+ type ChoiceMongoValue = null | string | {$in: (null | string)[]};
124
+
125
+ const normalizeChoiceMongoValue = (values: (null | string)[]): ChoiceMongoValue => {
126
+ if (values.length === 1) {
127
+ return values[0];
128
+ }
129
+ return {$in: values};
130
+ };
131
+
132
+ const parseChoiceWireValue = (
133
+ field: string,
134
+ wireValue: string,
135
+ choices: {label: string; value: string}[],
136
+ allowEmpty: boolean
137
+ ): {ok: true; value: null | string} | {ok: false; error: string} => {
138
+ if (wireValue === ADMIN_LIST_CHOICE_EMPTY_VALUE) {
139
+ if (!allowEmpty) {
140
+ return {
141
+ error: `${field} must be one of: ${choices.map((choice) => choice.value).join(", ")}`,
142
+ ok: false,
143
+ };
144
+ }
145
+ return {ok: true, value: null};
146
+ }
147
+ const allowed = new Set(choices.map((choice) => choice.value));
148
+ if (!allowed.has(wireValue)) {
149
+ return {error: `${field} must be one of: ${[...allowed].join(", ")}`, ok: false};
150
+ }
151
+ return {ok: true, value: wireValue};
152
+ };
153
+
63
154
  const parseChoiceFilter = (
64
155
  field: string,
65
156
  value: unknown,
66
- choices: {label: string; value: string}[]
67
- ): {ok: true; value: string} | {ok: false; error: string} => {
157
+ declared: AdminFilterChoice
158
+ ): {ok: true; value: ChoiceMongoValue} | {ok: false; error: string} => {
68
159
  const parsed = parseTextFilter(field, value);
69
160
  if (!parsed.ok) {
70
161
  return parsed;
71
162
  }
72
- const allowed = new Set(choices.map((choice) => choice.value));
73
- if (!allowed.has(parsed.value)) {
74
- return {error: `${field} must be one of: ${[...allowed].join(", ")}`, ok: false};
163
+ const wire = parseChoiceWireValue(
164
+ field,
165
+ parsed.value,
166
+ declared.choices,
167
+ declared.allowEmpty === true
168
+ );
169
+ if (!wire.ok) {
170
+ return wire;
75
171
  }
76
- return parsed;
172
+ return {ok: true, value: wire.value};
173
+ };
174
+
175
+ const parseChoiceInFilter = (
176
+ field: string,
177
+ value: unknown,
178
+ declared: AdminFilterChoice
179
+ ): {ok: true; value: ChoiceMongoValue} | {ok: false; error: string} => {
180
+ if (value == null || typeof value !== "object" || Array.isArray(value)) {
181
+ return {error: `${field} must be a multi-value choice filter`, ok: false};
182
+ }
183
+ const record = value as Record<string, unknown> & {$in?: unknown};
184
+ if (!hasOnlyKeys(record, ["$in"])) {
185
+ return {error: `${field} contains an unsupported choice operator`, ok: false};
186
+ }
187
+ if (!Array.isArray(record.$in)) {
188
+ return {error: `${field} must use $in with string values`, ok: false};
189
+ }
190
+ const mongoValues: (null | string)[] = [];
191
+ for (const entry of record.$in) {
192
+ const scalar = scalarString(entry);
193
+ if (!scalar) {
194
+ return {error: `${field} must use $in with string values`, ok: false};
195
+ }
196
+ const wire = parseChoiceWireValue(
197
+ field,
198
+ scalar,
199
+ declared.choices,
200
+ declared.allowEmpty === true
201
+ );
202
+ if (!wire.ok) {
203
+ return wire;
204
+ }
205
+ mongoValues.push(wire.value);
206
+ }
207
+ if (mongoValues.length === 0) {
208
+ return {error: `${field} must include at least one choice`, ok: false};
209
+ }
210
+ return {ok: true, value: normalizeChoiceMongoValue(mongoValues)};
77
211
  };
78
212
 
79
213
  const parseRefFilter = (
@@ -149,7 +283,13 @@ export const parseAdminListFilters = (
149
283
  continue;
150
284
  }
151
285
  consumedKeys.add(field);
152
- const parsed = parseTextFilter(field, safeQuery[field]);
286
+ const raw = safeQuery[field];
287
+ const regexParsed = parseTextRegexFilter(field, raw);
288
+ if (regexParsed.ok) {
289
+ filter[field] = regexParsed.value;
290
+ continue;
291
+ }
292
+ const parsed = parseTextFilter(field, raw);
153
293
  if (!parsed.ok) {
154
294
  errors[field] = parsed.error;
155
295
  continue;
@@ -163,7 +303,13 @@ export const parseAdminListFilters = (
163
303
  continue;
164
304
  }
165
305
  consumedKeys.add(field);
166
- const parsed = parseChoiceFilter(field, safeQuery[field], declared.choices);
306
+ const raw = safeQuery[field];
307
+ const inParsed = parseChoiceInFilter(field, raw, declared);
308
+ if (inParsed.ok) {
309
+ filter[field] = inParsed.value;
310
+ continue;
311
+ }
312
+ const parsed = parseChoiceFilter(field, raw, declared);
167
313
  if (!parsed.ok) {
168
314
  errors[field] = parsed.error;
169
315
  continue;
package/src/index.ts CHANGED
@@ -29,6 +29,8 @@ export type {
29
29
  AdminScriptConfig,
30
30
  } from "./adminApp";
31
31
  export {AdminApp, adminOwnedBy} from "./adminApp";
32
+ export type {AdminScriptJobPayload, AdminScriptJobTarget} from "./adminScriptJob";
33
+ export {ADMIN_SCRIPT_JOB_NAME, defineAdminScriptJob} from "./adminScriptJob";
32
34
  export * from "./adminUiV2";
33
35
  export type {AggregatedAdminContributions} from "./aggregateAdmin";
34
36
  export {
package/src/legacy.ts CHANGED
@@ -2,6 +2,7 @@ import type {AdminConfig} from "@terreno/api";
2
2
  import {logger} from "@terreno/api";
3
3
 
4
4
  import type {AdminModelConfig} from "./adminApp";
5
+ import {enrichAdminListFilters} from "./enrichAdminListFilters";
5
6
  import type {ResolvedAdminModel} from "./resolvedAdminModel";
6
7
  import {normalizeAdminRoutePath} from "./routePath";
7
8
 
@@ -24,6 +25,8 @@ export const convertLegacyModelConfig = (config: AdminModelConfig): ResolvedAdmi
24
25
  );
25
26
  }
26
27
 
28
+ const filters = enrichAdminListFilters(config.filters, config.model);
29
+
27
30
  const admin: AdminConfig = {
28
31
  actions: config.actions,
29
32
  autocompleteFields: undefined,
@@ -34,7 +37,7 @@ export const convertLegacyModelConfig = (config: AdminModelConfig): ResolvedAdmi
34
37
  fieldOrder: config.fieldOrder,
35
38
  fieldOverrides: config.fieldOverrides,
36
39
  fieldsets: config.fieldsets,
37
- filters: config.filters,
40
+ filters,
38
41
  group: config.group,
39
42
  hiddenFields: config.hiddenFields,
40
43
  listDisplay: config.listDisplay,
@@ -51,6 +54,7 @@ export const convertLegacyModelConfig = (config: AdminModelConfig): ResolvedAdmi
51
54
  return {
52
55
  ...config,
53
56
  admin,
57
+ filters,
54
58
  routePath: normalizeAdminRoutePath(config.routePath),
55
59
  source: "legacy",
56
60
  sourceLabel: config.displayName,
@@ -3,6 +3,7 @@ import type {Model} from "mongoose";
3
3
 
4
4
  import type {AdminModelConfig} from "./adminApp";
5
5
  import type {AdminListFilter, AdminModelPermissionsInput} from "./adminUiV2";
6
+ import {enrichAdminListFilters} from "./enrichAdminListFilters";
6
7
  import {normalizeAdminRoutePath} from "./routePath";
7
8
 
8
9
  export type AdminModelSource = "legacy" | "plugin" | "registered";
@@ -90,7 +91,7 @@ export const resolvedModelFromAdminConfig = ({
90
91
  fieldOrder: admin.fieldOrder,
91
92
  fieldOverrides: admin.fieldOverrides,
92
93
  fieldsets: admin.fieldsets,
93
- filters: admin.filters as AdminListFilter[] | undefined,
94
+ filters: enrichAdminListFilters(admin.filters as AdminListFilter[] | undefined, model),
94
95
  group: admin.group,
95
96
  hiddenFields: admin.hiddenFields,
96
97
  icon: admin.icon,