-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlayer-registry.js
More file actions
473 lines (438 loc) · 12.4 KB
/
Copy pathlayer-registry.js
File metadata and controls
473 lines (438 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
// ============================================================================
// LAYER REGISTRY AND FIELD POLICY
// ============================================================================
// This file defines which layers are queryable, what fields are allowed,
// and what query modes are permitted. Layers not in this registry cannot
// be queried (explicit allowlist approach).
//
// STEP 1 of hardening: Server-side "Layer Registry and Field Policy"
// ============================================================================
export const QUERY_MODES = {
BY_POINT: "by_point",
BY_OBJECT_IDS: "by_object_ids",
BY_BBOX: "by_bbox",
BY_ADDRESS: "by_address",
};
export const DEFAULT_MAX_RECORDS = 10;
export const ABSOLUTE_MAX_RECORDS = 50;
export const MAX_OBJECT_IDS_PER_QUERY = 25;
export const MAX_BBOX_SIZE_DEGREES = 0.1; // ~11km at equator
export const MAX_EXPLICIT_FIELDS = 40;
export const DEFAULT_RADIUS_METERS = 100;
export const MAX_RADIUS_METERS = 1000;
export const LAYER_REGISTRY = {
// Layer 24: Official_Zoning
24: {
id: 24,
name: "Official_Zoning",
displayName: "Official Zoning Districts",
geometryType: "esriGeometryPolygon",
description: "Official zoning district boundaries for Lebanon, NH",
allowedQueryModes: [QUERY_MODES.BY_POINT, QUERY_MODES.BY_BBOX],
fieldsProfileSummary: ["OBJECTID", "ACAD_TEXT", "Text_"],
fieldsProfileFull: [
"OBJECTID",
"ACAD_TEXT",
"Text_",
"Shape__Area",
"Shape__Length",
],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 10,
allowGeometry: false,
},
// Layer 5: Address Layer (Master Address Table)
5: {
id: 5,
name: "LebanonNHMATMassGeoExport_Layer",
displayName: "Master Address Table",
geometryType: "esriGeometryPoint",
description: "Master Address Table with address points for Lebanon, NH",
allowedQueryModes: [QUERY_MODES.BY_POINT, QUERY_MODES.BY_OBJECT_IDS],
addressSearchField: "StNam_Full",
fieldsProfileSummary: [
"OBJECTID",
"AddNo_Full",
"StNam_Full",
"SubAddress",
"Inc_Muni",
"State",
"Zip_Code",
"Latitude",
"Longitude",
"d_gis_zone",
],
fieldsProfileFull: [
"OBJECTID",
"AddNo_Full",
"StNam_Full",
"SubAddress",
"County",
"Inc_Muni",
"Nbrhd_Comm",
"State",
"Zip_Code",
"Longitude",
"Latitude",
"Parcel_ID",
"MATID",
"Sewer",
"Water",
"propertyid",
"d_gis_lot_size",
"d_gis_zone",
],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 10,
allowGeometry: false,
},
// Layer 18: Parcel
18: {
id: 18,
name: "Parcel (parcel_poly)",
displayName: "Parcels",
geometryType: "esriGeometryPolygon",
description: "Property parcel boundaries for Lebanon, NH",
allowedQueryModes: [
QUERY_MODES.BY_POINT,
QUERY_MODES.BY_OBJECT_IDS,
QUERY_MODES.BY_BBOX,
],
fieldsProfileSummary: ["OBJECTID", "GIS_ID", "MAP_LOT", "CALC_ACRES"],
fieldsProfileFull: [
"OBJECTID",
"GIS_ID",
"MAP_LOT",
"SOURCE",
"CALC_ACRES",
"NOTE",
"PNTPOLYCNT",
"Shape__Area",
"Shape__Length",
],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 10,
allowGeometry: false,
},
// Layer 23: Wetland Conservation District
23: {
id: 23,
name: "Wetland Convservation District (LebWetlands)",
displayName: "Wetland Conservation District",
geometryType: "esriGeometryPolygon",
description: "Wetland conservation district boundaries",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 22: Wetland Buffer
22: {
id: 22,
name: "Wetland 100' Buffer (WetlandBuffer)",
displayName: "Wetland 100ft Buffer",
geometryType: "esriGeometryPolygon",
description: "100-foot buffer zones around wetlands",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 0: Gravity Sewer Connection
0: {
id: 0,
name: "Gravity Sewer Connection (GSewerMain100Buff)",
displayName: "Gravity Sewer Connection Zone",
geometryType: "esriGeometryPolygon",
description:
"100-foot buffer around gravity sewer mains for connection availability",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 1: Water Main Connection
1: {
id: 1,
name: "Water Main Connection (WaterMain100Buff)",
displayName: "Water Main Connection Zone",
geometryType: "esriGeometryPolygon",
description:
"100-foot buffer around water mains for connection availability",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 12: Historic District
12: {
id: 12,
name: "Historic District (hd)",
displayName: "Historic District",
geometryType: "esriGeometryPolygon",
description: "Historic district boundaries",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 13: FEMA Flood Hazard
13: {
id: 13,
name: "FEMA FLood Hazard (FEMAFlood08)",
displayName: "FEMA Flood Hazard Zones",
geometryType: "esriGeometryPolygon",
description: "FEMA flood hazard zones from 2008 data",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 14: Riverbank Protection District
14: {
id: 14,
name: "Riverbank Protection District (RiverbankBuffer)",
displayName: "Riverbank Protection District",
geometryType: "esriGeometryPolygon",
description: "Riverbank protection buffer zones",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 15: NH Shoreland Protection
15: {
id: 15,
name: "NH Shoreland Protection (ShorelandBuffer)",
displayName: "NH Shoreland Protection Zone",
geometryType: "esriGeometryPolygon",
description: "New Hampshire shoreland protection buffer zones",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 17: Current Use Property
17: {
id: 17,
name: "Current Use Property (CurrentUse)",
displayName: "Current Use Properties",
geometryType: "esriGeometryPolygon",
description: "Properties enrolled in current use tax program",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
// Layer 30: Airport Protection District
30: {
id: 30,
name: "AirProtDist",
displayName: "Airport Protection District",
geometryType: "esriGeometryPolygon",
description: "Airport protection district overlay zones",
allowedQueryModes: [QUERY_MODES.BY_POINT],
fieldsProfileSummary: ["OBJECTID"],
fieldsProfileFull: ["OBJECTID", "Shape__Area", "Shape__Length"],
blockedFields: [
"GlobalID",
"CreationDate",
"Creator",
"EditDate",
"Editor",
],
maxRecords: 5,
allowGeometry: false,
},
};
export function getLayerConfig(layerId) {
const id = typeof layerId === "string" ? parseInt(layerId, 10) : layerId;
return LAYER_REGISTRY[id] || null;
}
export function getLayerConfigByName(layerName) {
if (typeof layerName !== 'string' || layerName.trim().length === 0) {
return null;
}
const normalized = layerName.trim().toLowerCase();
return Object.values(LAYER_REGISTRY).find(layer =>
layer.name.toLowerCase() === normalized ||
layer.displayName.toLowerCase() === normalized
) || null;
}
export function isLayerAllowed(layerId) {
return getLayerConfig(layerId) !== null;
}
export function isQueryModeAllowed(layerId, mode) {
const config = getLayerConfig(layerId);
if (!config) return false;
return config.allowedQueryModes.includes(mode);
}
export function getFieldsForProfile(layerId, profile) {
const config = getLayerConfig(layerId);
if (!config) return [];
if (profile === "full") {
return config.fieldsProfileFull;
}
return config.fieldsProfileSummary;
}
export function filterBlockedFields(layerId, fields) {
const config = getLayerConfig(layerId);
if (!config) return [];
const blocked = new Set(config.blockedFields.map((f) => f.toUpperCase()));
return fields.filter((f) => !blocked.has(f.toUpperCase()));
}
export function validateExplicitFields(layerId, requestedFields, maxFields) {
const config = getLayerConfig(layerId);
if (!config) return { valid: false, error: "Layer not found" };
const limit =
typeof maxFields === "number" && maxFields > 0
? maxFields
: MAX_EXPLICIT_FIELDS;
if (requestedFields.length > limit) {
return {
valid: false,
error: `Too many fields requested. Maximum is ${limit}.`,
};
}
const allowed = new Set([
...config.fieldsProfileFull.map((f) => f.toUpperCase()),
]);
const blocked = new Set(config.blockedFields.map((f) => f.toUpperCase()));
const invalidFields = [];
const blockedRequested = [];
for (const field of requestedFields) {
const upper = field.toUpperCase();
if (blocked.has(upper)) {
blockedRequested.push(field);
} else if (!allowed.has(upper)) {
invalidFields.push(field);
}
}
if (blockedRequested.length > 0) {
return {
valid: false,
error: `Blocked fields requested: ${blockedRequested.join(", ")}`,
};
}
if (invalidFields.length > 0) {
return {
valid: false,
error: `Unknown fields requested: ${invalidFields.join(", ")}`,
};
}
return { valid: true };
}
export function getAllRegisteredLayers() {
return Object.values(LAYER_REGISTRY).map((layer) => ({
id: layer.id,
name: layer.displayName,
geometryType: layer.geometryType,
description: layer.description,
}));
}
export function getLayerMetadata(layerId) {
const config = getLayerConfig(layerId);
if (!config) return null;
return {
id: config.id,
name: config.displayName,
internalName: config.name,
geometryType: config.geometryType,
description: config.description,
allowedQueryModes: config.allowedQueryModes,
fieldsProfileSummary: config.fieldsProfileSummary,
fieldsProfileFull: config.fieldsProfileFull,
maxRecords: config.maxRecords,
allowGeometry: config.allowGeometry,
};
}