@terreno/admin-backend 57.3.0 → 57.6.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.
- package/README.md +3 -3
- package/bunfig.toml +9 -1
- package/dist/adminApp.d.ts +20 -2
- package/dist/adminApp.js +1261 -1873
- package/dist/adminConfigIdentity.d.ts +1 -0
- package/dist/adminConfigIdentity.js +27 -50
- package/dist/adminMigrations.d.ts +10 -0
- package/dist/adminMigrations.js +120 -0
- package/dist/adminScriptJob.d.ts +32 -0
- package/dist/adminScriptJob.js +202 -0
- package/dist/adminTextSearch.d.ts +1 -0
- package/dist/adminTextSearch.js +22 -78
- package/dist/adminUiV2.d.ts +2 -0
- package/dist/adminUiV2.js +49 -146
- package/dist/aggregateAdmin.js +104 -227
- package/dist/documentStorageApp.js +184 -325
- package/dist/enrichAdminListFilters.d.ts +7 -0
- package/dist/enrichAdminListFilters.js +26 -0
- package/dist/filterParser.js +230 -183
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/legacy.js +21 -23
- package/dist/resolvedAdminModel.js +23 -78
- package/dist/routePath.js +3 -3
- package/dist/scriptCli.js +161 -307
- package/dist/tests/bunSetup.js +1 -1
- package/package.json +10 -10
- package/src/adminApp.migrations.test.ts +232 -0
- package/src/adminApp.models.test.ts +731 -1
- package/src/adminApp.syncMeta.test.ts +237 -0
- package/src/adminApp.test.ts +92 -0
- package/src/adminApp.ts +373 -130
- package/src/adminConfigIdentity.ts +1 -0
- package/src/adminHttpGoldens.test.ts +337 -0
- package/src/adminMigrations.ts +157 -0
- package/src/adminScriptJob.test.ts +297 -0
- package/src/adminScriptJob.ts +271 -0
- package/src/adminSyncMutationAuthMismatch.test.ts +650 -0
- package/src/adminTextSearch.test.ts +28 -0
- package/src/adminTextSearch.ts +1 -0
- package/src/adminUiV2.ts +2 -0
- package/src/aggregateAdmin.test.ts +125 -0
- package/src/aggregateAdmin.ts +2 -0
- package/src/enrichAdminListFilters.test.ts +44 -0
- package/src/enrichAdminListFilters.ts +29 -0
- package/src/filterParser.test.ts +95 -0
- package/src/filterParser.ts +156 -10
- package/src/index.ts +2 -0
- package/src/legacy.ts +5 -1
- package/src/resolvedAdminModel.ts +2 -1
- package/tsconfig.json +6 -21
package/dist/filterParser.js
CHANGED
|
@@ -1,75 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __values = (this && this.__values) || function(o) {
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
14
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
15
|
-
if (!m) return o;
|
|
16
|
-
var i = m.call(o), r, ar = [], e;
|
|
17
|
-
try {
|
|
18
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
19
|
-
}
|
|
20
|
-
catch (error) { e = { error: error }; }
|
|
21
|
-
finally {
|
|
22
|
-
try {
|
|
23
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
24
|
-
}
|
|
25
|
-
finally { if (e) throw e.error; }
|
|
26
|
-
}
|
|
27
|
-
return ar;
|
|
28
|
-
};
|
|
29
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
30
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
31
|
-
if (ar || !(i in from)) {
|
|
32
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
33
|
-
ar[i] = from[i];
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
37
|
-
};
|
|
38
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.parseAdminListFilters = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
7
|
+
const api_1 = require("@terreno/api");
|
|
8
|
+
const luxon_1 = require("luxon");
|
|
9
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
10
|
+
const POLLUTION_KEYS = new Set(["__proto__", "constructor", "prototype"]);
|
|
11
|
+
const REGEX_META_CHARACTERS = new Set([
|
|
12
|
+
"\\",
|
|
13
|
+
".",
|
|
14
|
+
"*",
|
|
15
|
+
"+",
|
|
16
|
+
"?",
|
|
17
|
+
"^",
|
|
18
|
+
"$",
|
|
19
|
+
"{",
|
|
20
|
+
"}",
|
|
21
|
+
"(",
|
|
22
|
+
")",
|
|
23
|
+
"|",
|
|
24
|
+
"[",
|
|
25
|
+
"]",
|
|
26
|
+
]);
|
|
27
|
+
const isOperatorKey = (key) => {
|
|
48
28
|
return key.startsWith("$");
|
|
49
29
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (POLLUTION_KEYS.has(key)) {
|
|
57
|
-
api_1.logger.warn("[admin] Dropping prototype-pollution query key: ".concat(key));
|
|
58
|
-
continue;
|
|
59
|
-
}
|
|
60
|
-
next[key] = value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
64
|
-
finally {
|
|
65
|
-
try {
|
|
66
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
30
|
+
const dropPollutionKeys = (query) => {
|
|
31
|
+
const next = {};
|
|
32
|
+
for (const [key, value] of Object.entries(query)) {
|
|
33
|
+
if (POLLUTION_KEYS.has(key)) {
|
|
34
|
+
api_1.logger.warn(`[admin] Dropping prototype-pollution query key: ${key}`);
|
|
35
|
+
continue;
|
|
67
36
|
}
|
|
68
|
-
|
|
37
|
+
next[key] = value;
|
|
69
38
|
}
|
|
70
39
|
return next;
|
|
71
40
|
};
|
|
72
|
-
|
|
41
|
+
const scalarString = (value) => {
|
|
73
42
|
if (typeof value === "string") {
|
|
74
43
|
return value;
|
|
75
44
|
}
|
|
@@ -78,56 +47,144 @@ var scalarString = function (value) {
|
|
|
78
47
|
}
|
|
79
48
|
return undefined;
|
|
80
49
|
};
|
|
81
|
-
|
|
82
|
-
|
|
50
|
+
const hasOnlyKeys = (record, allowedKeys) => {
|
|
51
|
+
const allowed = new Set(allowedKeys);
|
|
52
|
+
return Object.keys(record).every((key) => allowed.has(key));
|
|
53
|
+
};
|
|
54
|
+
const isEscapedRegexLiteral = (value) => {
|
|
55
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
56
|
+
const character = value[index];
|
|
57
|
+
if (character === "\\") {
|
|
58
|
+
const escapedCharacter = value[index + 1];
|
|
59
|
+
if (!escapedCharacter || !REGEX_META_CHARACTERS.has(escapedCharacter)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
index += 1;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (REGEX_META_CHARACTERS.has(character)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
};
|
|
71
|
+
const parseBooleanFilter = (field, value) => {
|
|
72
|
+
const scalar = scalarString(value);
|
|
83
73
|
if (scalar === "true") {
|
|
84
74
|
return { ok: true, value: true };
|
|
85
75
|
}
|
|
86
76
|
if (scalar === "false") {
|
|
87
77
|
return { ok: true, value: false };
|
|
88
78
|
}
|
|
89
|
-
return { error:
|
|
79
|
+
return { error: `${field} must be true or false`, ok: false };
|
|
90
80
|
};
|
|
91
|
-
|
|
92
|
-
|
|
81
|
+
const parseTextFilter = (field, value) => {
|
|
82
|
+
const scalar = scalarString(value);
|
|
93
83
|
if (scalar === undefined ||
|
|
94
84
|
Array.isArray(value) ||
|
|
95
85
|
(value != null && typeof value === "object")) {
|
|
96
|
-
return { error:
|
|
86
|
+
return { error: `${field} must be a string`, ok: false };
|
|
97
87
|
}
|
|
98
88
|
return { ok: true, value: scalar };
|
|
99
89
|
};
|
|
100
|
-
|
|
101
|
-
|
|
90
|
+
const parseTextRegexFilter = (field, value) => {
|
|
91
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
92
|
+
return { error: `${field} must be a case-insensitive regex filter`, ok: false };
|
|
93
|
+
}
|
|
94
|
+
const record = value;
|
|
95
|
+
if (!hasOnlyKeys(record, ["$options", "$regex"])) {
|
|
96
|
+
return { error: `${field} contains an unsupported regex operator`, ok: false };
|
|
97
|
+
}
|
|
98
|
+
if (record.$options !== "i") {
|
|
99
|
+
return { error: `${field} must use $options "i"`, ok: false };
|
|
100
|
+
}
|
|
101
|
+
const regex = scalarString(record.$regex);
|
|
102
|
+
if (!regex || !isEscapedRegexLiteral(regex)) {
|
|
103
|
+
return { error: `${field} must include an escaped literal $regex pattern`, ok: false };
|
|
104
|
+
}
|
|
105
|
+
return { ok: true, value: { $options: "i", $regex: regex } };
|
|
106
|
+
};
|
|
107
|
+
const normalizeChoiceMongoValue = (values) => {
|
|
108
|
+
if (values.length === 1) {
|
|
109
|
+
return values[0];
|
|
110
|
+
}
|
|
111
|
+
return { $in: values };
|
|
112
|
+
};
|
|
113
|
+
const parseChoiceWireValue = (field, wireValue, choices, allowEmpty) => {
|
|
114
|
+
if (wireValue === api_1.ADMIN_LIST_CHOICE_EMPTY_VALUE) {
|
|
115
|
+
if (!allowEmpty) {
|
|
116
|
+
return {
|
|
117
|
+
error: `${field} must be one of: ${choices.map((choice) => choice.value).join(", ")}`,
|
|
118
|
+
ok: false,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return { ok: true, value: null };
|
|
122
|
+
}
|
|
123
|
+
const allowed = new Set(choices.map((choice) => choice.value));
|
|
124
|
+
if (!allowed.has(wireValue)) {
|
|
125
|
+
return { error: `${field} must be one of: ${[...allowed].join(", ")}`, ok: false };
|
|
126
|
+
}
|
|
127
|
+
return { ok: true, value: wireValue };
|
|
128
|
+
};
|
|
129
|
+
const parseChoiceFilter = (field, value, declared) => {
|
|
130
|
+
const parsed = parseTextFilter(field, value);
|
|
102
131
|
if (!parsed.ok) {
|
|
103
132
|
return parsed;
|
|
104
133
|
}
|
|
105
|
-
|
|
106
|
-
if (!
|
|
107
|
-
return
|
|
134
|
+
const wire = parseChoiceWireValue(field, parsed.value, declared.choices, declared.allowEmpty === true);
|
|
135
|
+
if (!wire.ok) {
|
|
136
|
+
return wire;
|
|
108
137
|
}
|
|
109
|
-
return
|
|
138
|
+
return { ok: true, value: wire.value };
|
|
139
|
+
};
|
|
140
|
+
const parseChoiceInFilter = (field, value, declared) => {
|
|
141
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) {
|
|
142
|
+
return { error: `${field} must be a multi-value choice filter`, ok: false };
|
|
143
|
+
}
|
|
144
|
+
const record = value;
|
|
145
|
+
if (!hasOnlyKeys(record, ["$in"])) {
|
|
146
|
+
return { error: `${field} contains an unsupported choice operator`, ok: false };
|
|
147
|
+
}
|
|
148
|
+
if (!Array.isArray(record.$in)) {
|
|
149
|
+
return { error: `${field} must use $in with string values`, ok: false };
|
|
150
|
+
}
|
|
151
|
+
const mongoValues = [];
|
|
152
|
+
for (const entry of record.$in) {
|
|
153
|
+
const scalar = scalarString(entry);
|
|
154
|
+
if (!scalar) {
|
|
155
|
+
return { error: `${field} must use $in with string values`, ok: false };
|
|
156
|
+
}
|
|
157
|
+
const wire = parseChoiceWireValue(field, scalar, declared.choices, declared.allowEmpty === true);
|
|
158
|
+
if (!wire.ok) {
|
|
159
|
+
return wire;
|
|
160
|
+
}
|
|
161
|
+
mongoValues.push(wire.value);
|
|
162
|
+
}
|
|
163
|
+
if (mongoValues.length === 0) {
|
|
164
|
+
return { error: `${field} must include at least one choice`, ok: false };
|
|
165
|
+
}
|
|
166
|
+
return { ok: true, value: normalizeChoiceMongoValue(mongoValues) };
|
|
110
167
|
};
|
|
111
|
-
|
|
112
|
-
|
|
168
|
+
const parseRefFilter = (field, value) => {
|
|
169
|
+
const parsed = parseTextFilter(field, value);
|
|
113
170
|
if (!parsed.ok) {
|
|
114
171
|
return parsed;
|
|
115
172
|
}
|
|
116
173
|
if (!mongoose_1.default.isValidObjectId(parsed.value)) {
|
|
117
|
-
return { error:
|
|
174
|
+
return { error: `${field} must be a valid id`, ok: false };
|
|
118
175
|
}
|
|
119
176
|
return parsed;
|
|
120
177
|
};
|
|
121
|
-
|
|
122
|
-
|
|
178
|
+
const parseIsoDate = (field, value) => {
|
|
179
|
+
const scalar = scalarString(value);
|
|
123
180
|
if (scalar === undefined ||
|
|
124
181
|
Array.isArray(value) ||
|
|
125
182
|
(value != null && typeof value === "object")) {
|
|
126
|
-
return { error:
|
|
183
|
+
return { error: `${field} must be an ISO date string`, ok: false };
|
|
127
184
|
}
|
|
128
|
-
|
|
185
|
+
const parsed = luxon_1.DateTime.fromISO(scalar, { zone: "utc" });
|
|
129
186
|
if (!parsed.isValid) {
|
|
130
|
-
return { error:
|
|
187
|
+
return { error: `${field} must be an ISO date string`, ok: false };
|
|
131
188
|
}
|
|
132
189
|
return { ok: true, value: parsed.toJSDate() };
|
|
133
190
|
};
|
|
@@ -135,126 +192,116 @@ var parseIsoDate = function (field, value) {
|
|
|
135
192
|
* Parses v2-compatible list query params for declared admin filters.
|
|
136
193
|
* Undeclared keys are ignored; Mongo operator keys are rejected.
|
|
137
194
|
*/
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
var declared = filters_1_1.value;
|
|
148
|
-
var field = declared.field;
|
|
149
|
-
if (declared.kind === "boolean") {
|
|
150
|
-
if (!(field in safeQuery)) {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
|
-
consumedKeys.add(field);
|
|
154
|
-
var parsed = parseBooleanFilter(field, safeQuery[field]);
|
|
155
|
-
if (!parsed.ok) {
|
|
156
|
-
errors[field] = parsed.error;
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
filter[field] = parsed.value;
|
|
195
|
+
const parseAdminListFilters = (query, filters = []) => {
|
|
196
|
+
const safeQuery = dropPollutionKeys(query);
|
|
197
|
+
const errors = {};
|
|
198
|
+
const filter = {};
|
|
199
|
+
const consumedKeys = new Set();
|
|
200
|
+
for (const declared of filters) {
|
|
201
|
+
const field = declared.field;
|
|
202
|
+
if (declared.kind === "boolean") {
|
|
203
|
+
if (!(field in safeQuery)) {
|
|
160
204
|
continue;
|
|
161
205
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
consumedKeys.add(field);
|
|
167
|
-
var parsed = parseTextFilter(field, safeQuery[field]);
|
|
168
|
-
if (!parsed.ok) {
|
|
169
|
-
errors[field] = parsed.error;
|
|
170
|
-
continue;
|
|
171
|
-
}
|
|
172
|
-
filter[field] = parsed.value;
|
|
206
|
+
consumedKeys.add(field);
|
|
207
|
+
const parsed = parseBooleanFilter(field, safeQuery[field]);
|
|
208
|
+
if (!parsed.ok) {
|
|
209
|
+
errors[field] = parsed.error;
|
|
173
210
|
continue;
|
|
174
211
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
var parsed = parseChoiceFilter(field, safeQuery[field], declared.choices);
|
|
181
|
-
if (!parsed.ok) {
|
|
182
|
-
errors[field] = parsed.error;
|
|
183
|
-
continue;
|
|
184
|
-
}
|
|
185
|
-
filter[field] = parsed.value;
|
|
212
|
+
filter[field] = parsed.value;
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (declared.kind === "text") {
|
|
216
|
+
if (!(field in safeQuery)) {
|
|
186
217
|
continue;
|
|
187
218
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
219
|
+
consumedKeys.add(field);
|
|
220
|
+
const raw = safeQuery[field];
|
|
221
|
+
const regexParsed = parseTextRegexFilter(field, raw);
|
|
222
|
+
if (regexParsed.ok) {
|
|
223
|
+
filter[field] = regexParsed.value;
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const parsed = parseTextFilter(field, raw);
|
|
227
|
+
if (!parsed.ok) {
|
|
228
|
+
errors[field] = parsed.error;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
filter[field] = parsed.value;
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
if (declared.kind === "choice") {
|
|
235
|
+
if (!(field in safeQuery)) {
|
|
199
236
|
continue;
|
|
200
237
|
}
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
238
|
+
consumedKeys.add(field);
|
|
239
|
+
const raw = safeQuery[field];
|
|
240
|
+
const inParsed = parseChoiceInFilter(field, raw, declared);
|
|
241
|
+
if (inParsed.ok) {
|
|
242
|
+
filter[field] = inParsed.value;
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
const parsed = parseChoiceFilter(field, raw, declared);
|
|
246
|
+
if (!parsed.ok) {
|
|
247
|
+
errors[field] = parsed.error;
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
filter[field] = parsed.value;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (declared.kind === "ref") {
|
|
254
|
+
if (!(field in safeQuery)) {
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
consumedKeys.add(field);
|
|
258
|
+
const parsed = parseRefFilter(field, safeQuery[field]);
|
|
259
|
+
if (!parsed.ok) {
|
|
260
|
+
errors[field] = parsed.error;
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
filter[field] = parsed.value;
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
if (declared.kind === "dateRange") {
|
|
267
|
+
const gteKey = `${field}_gte`;
|
|
268
|
+
const lteKey = `${field}_lte`;
|
|
269
|
+
const hasGte = gteKey in safeQuery;
|
|
270
|
+
const hasLte = lteKey in safeQuery;
|
|
271
|
+
if (!hasGte && !hasLte) {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
274
|
+
const range = {};
|
|
275
|
+
if (hasGte) {
|
|
276
|
+
consumedKeys.add(gteKey);
|
|
277
|
+
const parsed = parseIsoDate(gteKey, safeQuery[gteKey]);
|
|
278
|
+
if (!parsed.ok) {
|
|
279
|
+
errors[gteKey] = parsed.error;
|
|
208
280
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
consumedKeys.add(gteKey);
|
|
212
|
-
var parsed = parseIsoDate(gteKey, safeQuery[gteKey]);
|
|
213
|
-
if (!parsed.ok) {
|
|
214
|
-
errors[gteKey] = parsed.error;
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
range.$gte = parsed.value;
|
|
218
|
-
}
|
|
281
|
+
else {
|
|
282
|
+
range.$gte = parsed.value;
|
|
219
283
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
else {
|
|
227
|
-
range.$lte = parsed.value;
|
|
228
|
-
}
|
|
284
|
+
}
|
|
285
|
+
if (hasLte) {
|
|
286
|
+
consumedKeys.add(lteKey);
|
|
287
|
+
const parsed = parseIsoDate(lteKey, safeQuery[lteKey]);
|
|
288
|
+
if (!parsed.ok) {
|
|
289
|
+
errors[lteKey] = parsed.error;
|
|
229
290
|
}
|
|
230
|
-
|
|
231
|
-
|
|
291
|
+
else {
|
|
292
|
+
range.$lte = parsed.value;
|
|
232
293
|
}
|
|
233
294
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
237
|
-
finally {
|
|
238
|
-
try {
|
|
239
|
-
if (filters_1_1 && !filters_1_1.done && (_a = filters_1.return)) _a.call(filters_1);
|
|
240
|
-
}
|
|
241
|
-
finally { if (e_2) throw e_2.error; }
|
|
242
|
-
}
|
|
243
|
-
try {
|
|
244
|
-
for (var _c = __values(Object.keys(safeQuery)), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
245
|
-
var key = _d.value;
|
|
246
|
-
if (isOperatorKey(key)) {
|
|
247
|
-
errors[key] = "Mongo operators are not allowed in admin list filters";
|
|
295
|
+
if (Object.keys(range).length > 0) {
|
|
296
|
+
filter[field] = range;
|
|
248
297
|
}
|
|
249
298
|
}
|
|
250
299
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
|
|
300
|
+
for (const key of Object.keys(safeQuery)) {
|
|
301
|
+
if (isOperatorKey(key)) {
|
|
302
|
+
errors[key] = "Mongo operators are not allowed in admin list filters";
|
|
255
303
|
}
|
|
256
|
-
finally { if (e_3) throw e_3.error; }
|
|
257
304
|
}
|
|
258
|
-
return { consumedKeys
|
|
305
|
+
return { consumedKeys, errors, filter };
|
|
259
306
|
};
|
|
260
307
|
exports.parseAdminListFilters = parseAdminListFilters;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { AdminChangeEvent, AdminChangeType, AdminConfig, AdminContribution, AdminCustomScreen, AdminFieldset, AdminFilter, AdminFilterBoolean, AdminFilterChoice, AdminFilterDateRange, AdminFilterKind, AdminFilterRef, AdminFilterText, AdminHomeConfig, AdminHomeSlots, AdminHomeWidgetContribution, AdminModelContribution, AdminModelPermissions, AdminScriptContribution, TerrenoAppAdminEvent, } from "@terreno/api";
|
|
2
2
|
export type { AdminAuditEvent, AdminCustomScreenConfig, AdminFieldOverride, AdminModelConfig, AdminOptions, AdminScriptConfig, } from "./adminApp";
|
|
3
3
|
export { AdminApp, adminOwnedBy } from "./adminApp";
|
|
4
|
+
export type { AdminScriptJobPayload, AdminScriptJobTarget } from "./adminScriptJob";
|
|
5
|
+
export { ADMIN_SCRIPT_JOB_NAME, defineAdminScriptJob } from "./adminScriptJob";
|
|
4
6
|
export * from "./adminUiV2";
|
|
5
7
|
export type { AggregatedAdminContributions } from "./aggregateAdmin";
|
|
6
8
|
export { aggregateAdminContributions, aggregateFromTerrenoApp, collectPluginAdminContributions, collectRegisteredAdminModels, } from "./aggregateAdmin";
|
package/dist/index.js
CHANGED
|
@@ -14,10 +14,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.runScriptCli = exports.normalizeAdminRoutePath = exports.resolvedModelFromAdminConfig = exports.resetLegacyDeprecationWarningsForTests = exports.convertLegacyModelConfig = exports.parseAdminListFilters = exports.DocumentStorageApp = exports.collectRegisteredAdminModels = exports.collectPluginAdminContributions = exports.aggregateFromTerrenoApp = exports.aggregateAdminContributions = exports.adminOwnedBy = exports.AdminApp = void 0;
|
|
17
|
+
exports.runScriptCli = exports.normalizeAdminRoutePath = exports.resolvedModelFromAdminConfig = exports.resetLegacyDeprecationWarningsForTests = exports.convertLegacyModelConfig = exports.parseAdminListFilters = exports.DocumentStorageApp = exports.collectRegisteredAdminModels = exports.collectPluginAdminContributions = exports.aggregateFromTerrenoApp = exports.aggregateAdminContributions = exports.defineAdminScriptJob = exports.ADMIN_SCRIPT_JOB_NAME = exports.adminOwnedBy = exports.AdminApp = void 0;
|
|
18
18
|
var adminApp_1 = require("./adminApp");
|
|
19
19
|
Object.defineProperty(exports, "AdminApp", { enumerable: true, get: function () { return adminApp_1.AdminApp; } });
|
|
20
20
|
Object.defineProperty(exports, "adminOwnedBy", { enumerable: true, get: function () { return adminApp_1.adminOwnedBy; } });
|
|
21
|
+
var adminScriptJob_1 = require("./adminScriptJob");
|
|
22
|
+
Object.defineProperty(exports, "ADMIN_SCRIPT_JOB_NAME", { enumerable: true, get: function () { return adminScriptJob_1.ADMIN_SCRIPT_JOB_NAME; } });
|
|
23
|
+
Object.defineProperty(exports, "defineAdminScriptJob", { enumerable: true, get: function () { return adminScriptJob_1.defineAdminScriptJob; } });
|
|
21
24
|
__exportStar(require("./adminUiV2"), exports);
|
|
22
25
|
var aggregateAdmin_1 = require("./aggregateAdmin");
|
|
23
26
|
Object.defineProperty(exports, "aggregateAdminContributions", { enumerable: true, get: function () { return aggregateAdmin_1.aggregateAdminContributions; } });
|
package/dist/legacy.js
CHANGED
|
@@ -1,34 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.resetLegacyDeprecationWarningsForTests = exports.convertLegacyModelConfig = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
const api_1 = require("@terreno/api");
|
|
5
|
+
const enrichAdminListFilters_1 = require("./enrichAdminListFilters");
|
|
6
|
+
const routePath_1 = require("./routePath");
|
|
7
|
+
const warnedLegacyKeys = new Set();
|
|
8
|
+
const legacyWarningKey = (config) => {
|
|
9
|
+
return `${config.model.modelName}:${(0, routePath_1.normalizeAdminRoutePath)(config.routePath)}`;
|
|
20
10
|
};
|
|
21
11
|
/**
|
|
22
12
|
* Converts legacy `AdminApp.models[]` entries into resolved admin models and emits a
|
|
23
13
|
* one-time deprecation warning per model/routePath per process.
|
|
24
14
|
*/
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const convertLegacyModelConfig = (config) => {
|
|
16
|
+
const key = legacyWarningKey(config);
|
|
27
17
|
if (!warnedLegacyKeys.has(key)) {
|
|
28
18
|
warnedLegacyKeys.add(key);
|
|
29
|
-
api_1.logger.warn(
|
|
19
|
+
api_1.logger.warn(`[admin] AdminApp.models entry "${config.displayName}" uses the legacy shape (model=${config.model.modelName}, routePath=${config.routePath}). Migrate to modelRouter({admin: {...}}) — see docs/how-to/admin-add-model.md`);
|
|
30
20
|
}
|
|
31
|
-
|
|
21
|
+
const filters = (0, enrichAdminListFilters_1.enrichAdminListFilters)(config.filters, config.model);
|
|
22
|
+
const admin = {
|
|
32
23
|
actions: config.actions,
|
|
33
24
|
autocompleteFields: undefined,
|
|
34
25
|
bulkPatchAllowlist: config.bulkPatchAllowlist,
|
|
@@ -38,7 +29,7 @@ var convertLegacyModelConfig = function (config) {
|
|
|
38
29
|
fieldOrder: config.fieldOrder,
|
|
39
30
|
fieldOverrides: config.fieldOverrides,
|
|
40
31
|
fieldsets: config.fieldsets,
|
|
41
|
-
filters
|
|
32
|
+
filters,
|
|
42
33
|
group: config.group,
|
|
43
34
|
hiddenFields: config.hiddenFields,
|
|
44
35
|
listDisplay: config.listDisplay,
|
|
@@ -51,11 +42,18 @@ var convertLegacyModelConfig = function (config) {
|
|
|
51
42
|
searchFields: config.searchFields,
|
|
52
43
|
sortableFields: config.sortableFields,
|
|
53
44
|
};
|
|
54
|
-
return
|
|
45
|
+
return {
|
|
46
|
+
...config,
|
|
47
|
+
admin,
|
|
48
|
+
filters,
|
|
49
|
+
routePath: (0, routePath_1.normalizeAdminRoutePath)(config.routePath),
|
|
50
|
+
source: "legacy",
|
|
51
|
+
sourceLabel: config.displayName,
|
|
52
|
+
};
|
|
55
53
|
};
|
|
56
54
|
exports.convertLegacyModelConfig = convertLegacyModelConfig;
|
|
57
55
|
/** @internal Test helper — clears one-time legacy deprecation warnings. */
|
|
58
|
-
|
|
56
|
+
const resetLegacyDeprecationWarningsForTests = () => {
|
|
59
57
|
warnedLegacyKeys.clear();
|
|
60
58
|
};
|
|
61
59
|
exports.resetLegacyDeprecationWarningsForTests = resetLegacyDeprecationWarningsForTests;
|