@memberjunction/core-entities 5.24.0 → 5.26.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/dist/engines/FileStorageEngine.d.ts +21 -5
- package/dist/engines/FileStorageEngine.d.ts.map +1 -1
- package/dist/engines/FileStorageEngine.js +24 -4
- package/dist/engines/FileStorageEngine.js.map +1 -1
- package/dist/engines/GeoDataEngine.d.ts +141 -0
- package/dist/engines/GeoDataEngine.d.ts.map +1 -0
- package/dist/engines/GeoDataEngine.js +425 -0
- package/dist/engines/GeoDataEngine.js.map +1 -0
- package/dist/engines/InstanceConfigEngine.d.ts +105 -0
- package/dist/engines/InstanceConfigEngine.d.ts.map +1 -0
- package/dist/engines/InstanceConfigEngine.js +198 -0
- package/dist/engines/InstanceConfigEngine.js.map +1 -0
- package/dist/engines/SearchEngineBase.d.ts +76 -0
- package/dist/engines/SearchEngineBase.d.ts.map +1 -0
- package/dist/engines/SearchEngineBase.js +141 -0
- package/dist/engines/SearchEngineBase.js.map +1 -0
- package/dist/engines/UserInfoEngine.d.ts +15 -1
- package/dist/engines/UserInfoEngine.d.ts.map +1 -1
- package/dist/engines/UserInfoEngine.js +45 -0
- package/dist/engines/UserInfoEngine.js.map +1 -1
- package/dist/engines/artifacts.d.ts +13 -0
- package/dist/engines/artifacts.d.ts.map +1 -1
- package/dist/engines/artifacts.js +25 -0
- package/dist/engines/artifacts.js.map +1 -1
- package/dist/generated/entity_subclasses.d.ts +1653 -71
- package/dist/generated/entity_subclasses.d.ts.map +1 -1
- package/dist/generated/entity_subclasses.js +2476 -123
- package/dist/generated/entity_subclasses.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
import { BaseEngine, LogStatus } from "@memberjunction/core";
|
|
8
|
+
import { RegisterForStartup } from "@memberjunction/core";
|
|
9
|
+
/**
|
|
10
|
+
* GeoDataEngine provides cached, in-memory access to Country and StateProvince
|
|
11
|
+
* reference data. Loaded once at startup via @RegisterForStartup, all lookups
|
|
12
|
+
* are O(1) via pre-built Maps keyed by common lookup patterns.
|
|
13
|
+
*
|
|
14
|
+
* Usage:
|
|
15
|
+
* ```typescript
|
|
16
|
+
* const engine = GeoDataEngine.Instance;
|
|
17
|
+
* const country = engine.GetCountryByISO2('US');
|
|
18
|
+
* const state = engine.GetStateByCode('US-country-id', 'CO');
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
let GeoDataEngine = class GeoDataEngine extends BaseEngine {
|
|
22
|
+
constructor() {
|
|
23
|
+
super(...arguments);
|
|
24
|
+
this._countries = [];
|
|
25
|
+
this._stateProvinces = [];
|
|
26
|
+
// Pre-built lookup Maps for O(1) access
|
|
27
|
+
this._countriesByISO2 = new Map();
|
|
28
|
+
this._countriesByISO3 = new Map();
|
|
29
|
+
this._countriesByName = new Map();
|
|
30
|
+
this._countriesById = new Map();
|
|
31
|
+
this._statesByCountryAndCode = new Map();
|
|
32
|
+
this._statesByCountryAndName = new Map();
|
|
33
|
+
this._statesById = new Map();
|
|
34
|
+
// Pre-parsed geometry caches for point-in-polygon testing
|
|
35
|
+
this._countryGeometries = [];
|
|
36
|
+
this._stateGeometries = [];
|
|
37
|
+
/** Maps countryId → array of state geometries for that country */
|
|
38
|
+
this._stateGeometriesByCountry = new Map();
|
|
39
|
+
}
|
|
40
|
+
static get Instance() {
|
|
41
|
+
return super.getInstance();
|
|
42
|
+
}
|
|
43
|
+
async Config(forceRefresh, contextUser, provider) {
|
|
44
|
+
const configs = [
|
|
45
|
+
{
|
|
46
|
+
Type: 'entity',
|
|
47
|
+
EntityName: 'MJ: Countries',
|
|
48
|
+
PropertyName: '_countries',
|
|
49
|
+
CacheLocal: true,
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
Type: 'entity',
|
|
53
|
+
EntityName: 'MJ: State Provinces',
|
|
54
|
+
PropertyName: '_stateProvinces',
|
|
55
|
+
CacheLocal: true,
|
|
56
|
+
}
|
|
57
|
+
];
|
|
58
|
+
await this.Load(configs, provider, forceRefresh, contextUser);
|
|
59
|
+
}
|
|
60
|
+
async AdditionalLoading(_contextUser) {
|
|
61
|
+
this.buildLookupMaps();
|
|
62
|
+
this.buildGeometryCaches();
|
|
63
|
+
}
|
|
64
|
+
// ================================================================
|
|
65
|
+
// Cached data getters
|
|
66
|
+
// ================================================================
|
|
67
|
+
get Countries() {
|
|
68
|
+
return this._countries || [];
|
|
69
|
+
}
|
|
70
|
+
get StateProvinces() {
|
|
71
|
+
return this._stateProvinces || [];
|
|
72
|
+
}
|
|
73
|
+
// ================================================================
|
|
74
|
+
// Country lookups — all O(1)
|
|
75
|
+
// ================================================================
|
|
76
|
+
GetCountryByISO2(iso2) {
|
|
77
|
+
if (!iso2)
|
|
78
|
+
return undefined;
|
|
79
|
+
return this._countriesByISO2.get(iso2.trim().toUpperCase());
|
|
80
|
+
}
|
|
81
|
+
GetCountryByISO3(iso3) {
|
|
82
|
+
if (!iso3)
|
|
83
|
+
return undefined;
|
|
84
|
+
return this._countriesByISO3.get(iso3.trim().toUpperCase());
|
|
85
|
+
}
|
|
86
|
+
GetCountryByName(name) {
|
|
87
|
+
if (!name)
|
|
88
|
+
return undefined;
|
|
89
|
+
return this._countriesByName.get(name.trim().toLowerCase());
|
|
90
|
+
}
|
|
91
|
+
GetCountryById(id) {
|
|
92
|
+
if (!id)
|
|
93
|
+
return undefined;
|
|
94
|
+
return this._countriesById.get(id.toLowerCase());
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Resolve a country from a text value that could be a name, ISO2, or ISO3 code.
|
|
98
|
+
* Tries ISO2 first (most common), then ISO3, then name match.
|
|
99
|
+
*/
|
|
100
|
+
ResolveCountry(value) {
|
|
101
|
+
if (!value)
|
|
102
|
+
return undefined;
|
|
103
|
+
const trimmed = value.trim();
|
|
104
|
+
// Try ISO2 (2-char codes like "US", "GB")
|
|
105
|
+
if (trimmed.length === 2) {
|
|
106
|
+
const byISO2 = this.GetCountryByISO2(trimmed);
|
|
107
|
+
if (byISO2)
|
|
108
|
+
return byISO2;
|
|
109
|
+
}
|
|
110
|
+
// Try ISO3 (3-char codes like "USA", "GBR")
|
|
111
|
+
if (trimmed.length === 3) {
|
|
112
|
+
const byISO3 = this.GetCountryByISO3(trimmed);
|
|
113
|
+
if (byISO3)
|
|
114
|
+
return byISO3;
|
|
115
|
+
}
|
|
116
|
+
// Try name match
|
|
117
|
+
return this.GetCountryByName(trimmed);
|
|
118
|
+
}
|
|
119
|
+
// ================================================================
|
|
120
|
+
// State/Province lookups — all O(1)
|
|
121
|
+
// ================================================================
|
|
122
|
+
/**
|
|
123
|
+
* Look up a state/province by its Code within a specific country.
|
|
124
|
+
* @param countryId - The country's UUID
|
|
125
|
+
* @param code - The state/province code (e.g., "CO", "ON", "NSW")
|
|
126
|
+
*/
|
|
127
|
+
GetStateByCode(countryId, code) {
|
|
128
|
+
if (!countryId || !code)
|
|
129
|
+
return undefined;
|
|
130
|
+
const key = `${countryId.toLowerCase()}|${code.trim().toUpperCase()}`;
|
|
131
|
+
return this._statesByCountryAndCode.get(key);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Look up a state/province by its Name within a specific country.
|
|
135
|
+
* @param countryId - The country's UUID
|
|
136
|
+
* @param name - The state/province name (e.g., "Colorado", "Ontario")
|
|
137
|
+
*/
|
|
138
|
+
GetStateByName(countryId, name) {
|
|
139
|
+
if (!countryId || !name)
|
|
140
|
+
return undefined;
|
|
141
|
+
const key = `${countryId.toLowerCase()}|${name.trim().toLowerCase()}`;
|
|
142
|
+
return this._statesByCountryAndName.get(key);
|
|
143
|
+
}
|
|
144
|
+
GetStateById(id) {
|
|
145
|
+
if (!id)
|
|
146
|
+
return undefined;
|
|
147
|
+
return this._statesById.get(id.toLowerCase());
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Resolve a state/province from a text value within a country.
|
|
151
|
+
* Tries code first, then name match.
|
|
152
|
+
*/
|
|
153
|
+
ResolveState(countryId, value) {
|
|
154
|
+
if (!countryId || !value)
|
|
155
|
+
return undefined;
|
|
156
|
+
const byCode = this.GetStateByCode(countryId, value);
|
|
157
|
+
if (byCode)
|
|
158
|
+
return byCode;
|
|
159
|
+
return this.GetStateByName(countryId, value);
|
|
160
|
+
}
|
|
161
|
+
// ================================================================
|
|
162
|
+
// Point-in-polygon resolution — coordinate-based lookups
|
|
163
|
+
// ================================================================
|
|
164
|
+
/**
|
|
165
|
+
* Resolve a lat/lng coordinate to its containing country and state/province
|
|
166
|
+
* using point-in-polygon testing against cached BoundaryGeoJSON data.
|
|
167
|
+
* No text matching — purely geometric.
|
|
168
|
+
*
|
|
169
|
+
* @param lat - Latitude (-90 to 90)
|
|
170
|
+
* @param lng - Longitude (-180 to 180)
|
|
171
|
+
* @returns The matched country and state/province, or undefined for each if no match
|
|
172
|
+
*/
|
|
173
|
+
ResolvePointToLocation(lat, lng) {
|
|
174
|
+
const country = this.ResolvePointToCountry(lat, lng);
|
|
175
|
+
const state = country ? this.ResolvePointToState(lat, lng, country.ID) : undefined;
|
|
176
|
+
return { Country: country, State: state };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Resolve a lat/lng coordinate to its containing country.
|
|
180
|
+
* Uses bounding-box pre-filtering then ray-casting point-in-polygon.
|
|
181
|
+
*/
|
|
182
|
+
ResolvePointToCountry(lat, lng) {
|
|
183
|
+
for (const geom of this._countryGeometries) {
|
|
184
|
+
if (this.pointInCachedGeometry(lat, lng, geom)) {
|
|
185
|
+
return this._countriesById.get(geom.entityId);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Resolve a lat/lng coordinate to its containing state/province within a known country.
|
|
192
|
+
* If countryId is not provided, resolves the country first.
|
|
193
|
+
*/
|
|
194
|
+
ResolvePointToState(lat, lng, countryId) {
|
|
195
|
+
let resolvedCountryId = countryId?.toLowerCase();
|
|
196
|
+
if (!resolvedCountryId) {
|
|
197
|
+
const country = this.ResolvePointToCountry(lat, lng);
|
|
198
|
+
if (!country)
|
|
199
|
+
return undefined;
|
|
200
|
+
resolvedCountryId = country.ID.toLowerCase();
|
|
201
|
+
}
|
|
202
|
+
const stateGeoms = this._stateGeometriesByCountry.get(resolvedCountryId);
|
|
203
|
+
if (!stateGeoms)
|
|
204
|
+
return undefined;
|
|
205
|
+
for (const geom of stateGeoms) {
|
|
206
|
+
if (this.pointInCachedGeometry(lat, lng, geom)) {
|
|
207
|
+
return this._statesById.get(geom.entityId);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return undefined;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Batch-resolve multiple lat/lng points in parallel.
|
|
214
|
+
* Each point is resolved independently — ideal for choropleth grouping.
|
|
215
|
+
*
|
|
216
|
+
* @param points - Array of {lat, lng} coordinates
|
|
217
|
+
* @returns Array of GeoPointResolution in the same order as input
|
|
218
|
+
*/
|
|
219
|
+
ResolvePoints(points) {
|
|
220
|
+
return points.map(p => this.ResolvePointToLocation(p.lat, p.lng));
|
|
221
|
+
}
|
|
222
|
+
// ================================================================
|
|
223
|
+
// Private — point-in-polygon geometry
|
|
224
|
+
// ================================================================
|
|
225
|
+
/**
|
|
226
|
+
* Test if a point falls inside a CachedGeometry (bbox pre-filter + ray-casting).
|
|
227
|
+
*/
|
|
228
|
+
pointInCachedGeometry(lat, lng, geom) {
|
|
229
|
+
// Fast rejection via overall bounding box
|
|
230
|
+
if (!this.pointInBBox(lat, lng, geom.bbox))
|
|
231
|
+
return false;
|
|
232
|
+
// Test each polygon (MultiPolygon support)
|
|
233
|
+
for (const poly of geom.polygons) {
|
|
234
|
+
if (!this.pointInBBox(lat, lng, poly.bbox))
|
|
235
|
+
continue;
|
|
236
|
+
if (this.pointInPolygonRings(lat, lng, poly.rings))
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Check if a point is inside a bounding box.
|
|
243
|
+
* BBox format: [minLng, minLat, maxLng, maxLat]
|
|
244
|
+
*/
|
|
245
|
+
pointInBBox(lat, lng, bbox) {
|
|
246
|
+
return lng >= bbox[0] && lat >= bbox[1] && lng <= bbox[2] && lat <= bbox[3];
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Ray-casting point-in-polygon for a polygon with rings.
|
|
250
|
+
* First ring is the outer boundary (must be inside).
|
|
251
|
+
* Subsequent rings are holes (must NOT be inside).
|
|
252
|
+
*/
|
|
253
|
+
pointInPolygonRings(lat, lng, rings) {
|
|
254
|
+
if (rings.length === 0)
|
|
255
|
+
return false;
|
|
256
|
+
// Must be inside the outer ring
|
|
257
|
+
if (!this.rayCast(lat, lng, rings[0]))
|
|
258
|
+
return false;
|
|
259
|
+
// Must NOT be inside any hole
|
|
260
|
+
for (let i = 1; i < rings.length; i++) {
|
|
261
|
+
if (this.rayCast(lat, lng, rings[i]))
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Ray-casting algorithm: cast a horizontal ray from the point eastward,
|
|
268
|
+
* count how many polygon edges it crosses. Odd = inside.
|
|
269
|
+
* Coordinates are [lng, lat] pairs (GeoJSON convention).
|
|
270
|
+
*/
|
|
271
|
+
rayCast(lat, lng, ring) {
|
|
272
|
+
let inside = false;
|
|
273
|
+
const n = ring.length;
|
|
274
|
+
for (let i = 0, j = n - 1; i < n; j = i++) {
|
|
275
|
+
const xi = ring[i][0], yi = ring[i][1]; // lng, lat of vertex i
|
|
276
|
+
const xj = ring[j][0], yj = ring[j][1]; // lng, lat of vertex j
|
|
277
|
+
// Check if the ray crosses this edge
|
|
278
|
+
if ((yi > lat) !== (yj > lat) &&
|
|
279
|
+
lng < (xj - xi) * (lat - yi) / (yj - yi) + xi) {
|
|
280
|
+
inside = !inside;
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
return inside;
|
|
284
|
+
}
|
|
285
|
+
// ================================================================
|
|
286
|
+
// Private — geometry cache building
|
|
287
|
+
// ================================================================
|
|
288
|
+
/**
|
|
289
|
+
* Parse all BoundaryGeoJSON data and build indexed geometry caches.
|
|
290
|
+
* Called once during AdditionalLoading after entities are loaded.
|
|
291
|
+
*/
|
|
292
|
+
buildGeometryCaches() {
|
|
293
|
+
this._countryGeometries = [];
|
|
294
|
+
this._stateGeometries = [];
|
|
295
|
+
this._stateGeometriesByCountry.clear();
|
|
296
|
+
let countryParsed = 0;
|
|
297
|
+
let stateParsed = 0;
|
|
298
|
+
// Parse country boundaries
|
|
299
|
+
for (const country of this._countries) {
|
|
300
|
+
const geom = this.parseEntityBoundary(country.ID, country.BoundaryGeoJSON);
|
|
301
|
+
if (geom) {
|
|
302
|
+
this._countryGeometries.push(geom);
|
|
303
|
+
countryParsed++;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// Parse state/province boundaries, indexed by country
|
|
307
|
+
for (const state of this._stateProvinces) {
|
|
308
|
+
const geom = this.parseEntityBoundary(state.ID, state.BoundaryGeoJSON);
|
|
309
|
+
if (geom) {
|
|
310
|
+
this._stateGeometries.push(geom);
|
|
311
|
+
stateParsed++;
|
|
312
|
+
const countryKey = state.CountryID.toLowerCase();
|
|
313
|
+
let arr = this._stateGeometriesByCountry.get(countryKey);
|
|
314
|
+
if (!arr) {
|
|
315
|
+
arr = [];
|
|
316
|
+
this._stateGeometriesByCountry.set(countryKey, arr);
|
|
317
|
+
}
|
|
318
|
+
arr.push(geom);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
LogStatus(`GeoDataEngine: parsed ${countryParsed} country and ${stateParsed} state/province boundaries for point-in-polygon`);
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Parse a BoundaryGeoJSON value into a CachedGeometry.
|
|
325
|
+
* Supports GeoJSON Feature, Polygon, and MultiPolygon types.
|
|
326
|
+
* Returns null if the boundary is missing or unparseable.
|
|
327
|
+
*/
|
|
328
|
+
parseEntityBoundary(entityId, boundaryGeoJSON) {
|
|
329
|
+
if (!boundaryGeoJSON)
|
|
330
|
+
return null;
|
|
331
|
+
try {
|
|
332
|
+
const raw = typeof boundaryGeoJSON === 'string' ? JSON.parse(boundaryGeoJSON) : boundaryGeoJSON;
|
|
333
|
+
const geometry = raw.type === 'Feature' ? raw.geometry : raw;
|
|
334
|
+
if (!geometry || !geometry.coordinates)
|
|
335
|
+
return null;
|
|
336
|
+
const polygons = [];
|
|
337
|
+
if (geometry.type === 'Polygon') {
|
|
338
|
+
const parsed = this.parsePolygonCoordinates(geometry.coordinates);
|
|
339
|
+
if (parsed)
|
|
340
|
+
polygons.push(parsed);
|
|
341
|
+
}
|
|
342
|
+
else if (geometry.type === 'MultiPolygon') {
|
|
343
|
+
for (const polyCoords of geometry.coordinates) {
|
|
344
|
+
const parsed = this.parsePolygonCoordinates(polyCoords);
|
|
345
|
+
if (parsed)
|
|
346
|
+
polygons.push(parsed);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
if (polygons.length === 0)
|
|
350
|
+
return null;
|
|
351
|
+
// Compute overall bounding box across all polygons
|
|
352
|
+
const overallBbox = [
|
|
353
|
+
Math.min(...polygons.map(p => p.bbox[0])),
|
|
354
|
+
Math.min(...polygons.map(p => p.bbox[1])),
|
|
355
|
+
Math.max(...polygons.map(p => p.bbox[2])),
|
|
356
|
+
Math.max(...polygons.map(p => p.bbox[3]))
|
|
357
|
+
];
|
|
358
|
+
return { entityId: entityId.toLowerCase(), polygons, bbox: overallBbox };
|
|
359
|
+
}
|
|
360
|
+
catch {
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Parse a single Polygon's coordinate rings and compute its bounding box.
|
|
366
|
+
* GeoJSON Polygon coordinates: [ outerRing, ...holeRings ]
|
|
367
|
+
* Each ring is an array of [lng, lat] pairs.
|
|
368
|
+
*/
|
|
369
|
+
parsePolygonCoordinates(coordinates) {
|
|
370
|
+
if (!coordinates || coordinates.length === 0)
|
|
371
|
+
return null;
|
|
372
|
+
let minLng = Infinity, minLat = Infinity, maxLng = -Infinity, maxLat = -Infinity;
|
|
373
|
+
// Compute bbox from the outer ring (first ring)
|
|
374
|
+
for (const point of coordinates[0]) {
|
|
375
|
+
if (point[0] < minLng)
|
|
376
|
+
minLng = point[0];
|
|
377
|
+
if (point[1] < minLat)
|
|
378
|
+
minLat = point[1];
|
|
379
|
+
if (point[0] > maxLng)
|
|
380
|
+
maxLng = point[0];
|
|
381
|
+
if (point[1] > maxLat)
|
|
382
|
+
maxLat = point[1];
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
rings: coordinates,
|
|
386
|
+
bbox: [minLng, minLat, maxLng, maxLat]
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
// ================================================================
|
|
390
|
+
// Private — build O(1) lookup maps
|
|
391
|
+
// ================================================================
|
|
392
|
+
buildLookupMaps() {
|
|
393
|
+
this._countriesByISO2.clear();
|
|
394
|
+
this._countriesByISO3.clear();
|
|
395
|
+
this._countriesByName.clear();
|
|
396
|
+
this._countriesById.clear();
|
|
397
|
+
this._statesByCountryAndCode.clear();
|
|
398
|
+
this._statesByCountryAndName.clear();
|
|
399
|
+
this._statesById.clear();
|
|
400
|
+
for (const c of this._countries) {
|
|
401
|
+
if (c.ISO2)
|
|
402
|
+
this._countriesByISO2.set(c.ISO2.trim().toUpperCase(), c);
|
|
403
|
+
if (c.ISO3)
|
|
404
|
+
this._countriesByISO3.set(c.ISO3.trim().toUpperCase(), c);
|
|
405
|
+
if (c.Name)
|
|
406
|
+
this._countriesByName.set(c.Name.trim().toLowerCase(), c);
|
|
407
|
+
this._countriesById.set(c.ID.toLowerCase(), c);
|
|
408
|
+
}
|
|
409
|
+
for (const s of this._stateProvinces) {
|
|
410
|
+
const countryKey = s.CountryID.toLowerCase();
|
|
411
|
+
if (s.Code) {
|
|
412
|
+
this._statesByCountryAndCode.set(`${countryKey}|${s.Code.trim().toUpperCase()}`, s);
|
|
413
|
+
}
|
|
414
|
+
if (s.Name) {
|
|
415
|
+
this._statesByCountryAndName.set(`${countryKey}|${s.Name.trim().toLowerCase()}`, s);
|
|
416
|
+
}
|
|
417
|
+
this._statesById.set(s.ID.toLowerCase(), s);
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
GeoDataEngine = __decorate([
|
|
422
|
+
RegisterForStartup()
|
|
423
|
+
], GeoDataEngine);
|
|
424
|
+
export { GeoDataEngine };
|
|
425
|
+
//# sourceMappingURL=GeoDataEngine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GeoDataEngine.js","sourceRoot":"","sources":["../../src/engines/GeoDataEngine.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,UAAU,EAAyD,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACpH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAqC1D;;;;;;;;;;;GAWG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,UAAyB;IAArD;;QAKK,eAAU,GAAsB,EAAE,CAAC;QACnC,oBAAe,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,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YACxF,CAAC;YACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,CAAC;QAChD,CAAC;IACL,CAAC;CACJ,CAAA;AApaY,aAAa;IADzB,kBAAkB,EAAE;GACR,aAAa,CAoazB"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { BaseEngine, IMetadataProvider, UserInfo } from "@memberjunction/core";
|
|
2
|
+
import { MJInstanceConfigurationEntity } from "../generated/entity_subclasses.js";
|
|
3
|
+
/**
|
|
4
|
+
* InstanceConfigEngine provides centralized, cached access to instance-level feature configuration.
|
|
5
|
+
* It loads all MJ: Instance Configurations records into memory and provides typed getters
|
|
6
|
+
* for boolean, number, string, and JSON values by FeatureKey.
|
|
7
|
+
*
|
|
8
|
+
* Uses BaseEngine for automatic caching and entity-event-based auto-refresh so that
|
|
9
|
+
* configuration changes are reflected without requiring a manual reload.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const engine = InstanceConfigEngine.Instance;
|
|
14
|
+
* await engine.Config(false, contextUser);
|
|
15
|
+
*
|
|
16
|
+
* // Read a boolean flag
|
|
17
|
+
* const searchEnabled = engine.GetBoolean('Shell.SearchBar.Enabled');
|
|
18
|
+
*
|
|
19
|
+
* // Read a number with a custom default
|
|
20
|
+
* const maxResults = engine.GetNumber('Search.MaxResults', 50);
|
|
21
|
+
*
|
|
22
|
+
* // Read a JSON object
|
|
23
|
+
* const uiConfig = engine.GetJSON<{ theme: string }>('UI.DefaultConfig');
|
|
24
|
+
*
|
|
25
|
+
* // Admin: update a setting
|
|
26
|
+
* await engine.Set('Shell.SearchBar.Enabled', 'true', contextUser);
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare class InstanceConfigEngine extends BaseEngine<InstanceConfigEngine> {
|
|
30
|
+
/**
|
|
31
|
+
* Returns the global instance of the class. This is a singleton class, so there
|
|
32
|
+
* is only one instance of it in the application. Do not directly create new instances
|
|
33
|
+
* of it, always use this method to get the instance.
|
|
34
|
+
*/
|
|
35
|
+
static get Instance(): InstanceConfigEngine;
|
|
36
|
+
private _configs;
|
|
37
|
+
/**
|
|
38
|
+
* Configures the engine by loading all instance configuration records from the database.
|
|
39
|
+
* @param forceRefresh - If true, forces a refresh from the database even if data is cached
|
|
40
|
+
* @param contextUser - Optional user context for server-side operations
|
|
41
|
+
* @param provider - Optional metadata provider
|
|
42
|
+
*/
|
|
43
|
+
Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>;
|
|
44
|
+
/** All instance configuration records */
|
|
45
|
+
get InstanceConfigs(): MJInstanceConfigurationEntity[];
|
|
46
|
+
/**
|
|
47
|
+
* Find a configuration record by its FeatureKey.
|
|
48
|
+
* @param featureKey - The dot-notation feature key (e.g. 'Shell.SearchBar.Enabled')
|
|
49
|
+
* @returns The configuration entity, or undefined if not found
|
|
50
|
+
*/
|
|
51
|
+
GetConfigByKey(featureKey: string): MJInstanceConfigurationEntity | undefined;
|
|
52
|
+
/**
|
|
53
|
+
* Get all configuration records for a given category.
|
|
54
|
+
* @param category - The category to filter by (e.g. 'General', 'Search')
|
|
55
|
+
* @returns Array of matching configuration entities
|
|
56
|
+
*/
|
|
57
|
+
GetConfigsByCategory(category: string): MJInstanceConfigurationEntity[];
|
|
58
|
+
/**
|
|
59
|
+
* Get the raw string value for a feature key. Returns the record's Value if non-empty,
|
|
60
|
+
* otherwise falls back to DefaultValue, then to undefined.
|
|
61
|
+
* @param featureKey - The dot-notation feature key
|
|
62
|
+
* @returns The value string, or undefined if the key is not found
|
|
63
|
+
*/
|
|
64
|
+
Get(featureKey: string): string | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* Get a boolean value for a feature key. Interprets 'true' (case-insensitive) as true,
|
|
67
|
+
* everything else as false. Returns the provided default if the key is not found.
|
|
68
|
+
* @param featureKey - The dot-notation feature key
|
|
69
|
+
* @param defaultValue - Value to return if the key is not found (defaults to true)
|
|
70
|
+
*/
|
|
71
|
+
GetBoolean(featureKey: string, defaultValue?: boolean): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get a numeric value for a feature key. Returns the provided default if the key
|
|
74
|
+
* is not found or the value cannot be parsed as a number.
|
|
75
|
+
* @param featureKey - The dot-notation feature key
|
|
76
|
+
* @param defaultValue - Value to return if the key is not found or unparseable (defaults to 0)
|
|
77
|
+
*/
|
|
78
|
+
GetNumber(featureKey: string, defaultValue?: number): number;
|
|
79
|
+
/**
|
|
80
|
+
* Get a JSON-parsed value for a feature key. Returns the provided default if the key
|
|
81
|
+
* is not found or the value cannot be parsed as JSON.
|
|
82
|
+
* @param featureKey - The dot-notation feature key
|
|
83
|
+
* @param defaultValue - Value to return if the key is not found or unparseable
|
|
84
|
+
*/
|
|
85
|
+
GetJSON<T>(featureKey: string, defaultValue?: T): T | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Update the Value of an existing configuration record. This method updates the
|
|
88
|
+
* record in the database and refreshes the local cache entry.
|
|
89
|
+
*
|
|
90
|
+
* Note: This only updates existing records. To create new configuration entries,
|
|
91
|
+
* use the standard entity creation workflow.
|
|
92
|
+
*
|
|
93
|
+
* @param featureKey - The dot-notation feature key to update
|
|
94
|
+
* @param value - The new value string
|
|
95
|
+
* @param contextUser - Optional user context (required on server-side)
|
|
96
|
+
* @returns true if the save succeeded, false otherwise
|
|
97
|
+
*/
|
|
98
|
+
Set(featureKey: string, value: string, contextUser?: UserInfo): Promise<boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Resolve the effective value for a configuration record. Returns Value if
|
|
101
|
+
* it is non-empty, otherwise falls back to DefaultValue.
|
|
102
|
+
*/
|
|
103
|
+
private ResolveValue;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=InstanceConfigEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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