@memberjunction/core 0.9.166 → 0.9.167

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 (66) hide show
  1. package/dist/generic/interfaces.d.ts +0 -2
  2. package/dist/generic/interfaces.js.map +1 -1
  3. package/dist/generic/providerBase.d.ts +0 -7
  4. package/dist/generic/providerBase.js +1 -11
  5. package/dist/generic/providerBase.js.map +1 -1
  6. package/package.json +1 -1
  7. package/dist/MJCore/src/generic/applicationInfo.d.ts +0 -26
  8. package/dist/MJCore/src/generic/applicationInfo.js +0 -57
  9. package/dist/MJCore/src/generic/applicationInfo.js.map +0 -1
  10. package/dist/MJCore/src/generic/baseEntity.d.ts +0 -195
  11. package/dist/MJCore/src/generic/baseEntity.js +0 -674
  12. package/dist/MJCore/src/generic/baseEntity.js.map +0 -1
  13. package/dist/MJCore/src/generic/baseInfo.d.ts +0 -8
  14. package/dist/MJCore/src/generic/baseInfo.js +0 -38
  15. package/dist/MJCore/src/generic/baseInfo.js.map +0 -1
  16. package/dist/MJCore/src/generic/entityInfo.d.ts +0 -520
  17. package/dist/MJCore/src/generic/entityInfo.js +0 -801
  18. package/dist/MJCore/src/generic/entityInfo.js.map +0 -1
  19. package/dist/MJCore/src/generic/interfaces.d.ts +0 -288
  20. package/dist/MJCore/src/generic/interfaces.js +0 -50
  21. package/dist/MJCore/src/generic/interfaces.js.map +0 -1
  22. package/dist/MJCore/src/generic/logging.d.ts +0 -4
  23. package/dist/MJCore/src/generic/logging.js +0 -69
  24. package/dist/MJCore/src/generic/logging.js.map +0 -1
  25. package/dist/MJCore/src/generic/metadata.d.ts +0 -201
  26. package/dist/MJCore/src/generic/metadata.js +0 -312
  27. package/dist/MJCore/src/generic/metadata.js.map +0 -1
  28. package/dist/MJCore/src/generic/providerBase.d.ts +0 -183
  29. package/dist/MJCore/src/generic/providerBase.js +0 -640
  30. package/dist/MJCore/src/generic/providerBase.js.map +0 -1
  31. package/dist/MJCore/src/generic/queryInfo.d.ts +0 -64
  32. package/dist/MJCore/src/generic/queryInfo.js +0 -124
  33. package/dist/MJCore/src/generic/queryInfo.js.map +0 -1
  34. package/dist/MJCore/src/generic/runQuery.d.ts +0 -11
  35. package/dist/MJCore/src/generic/runQuery.js +0 -26
  36. package/dist/MJCore/src/generic/runQuery.js.map +0 -1
  37. package/dist/MJCore/src/generic/runReport.d.ts +0 -11
  38. package/dist/MJCore/src/generic/runReport.js +0 -27
  39. package/dist/MJCore/src/generic/runReport.js.map +0 -1
  40. package/dist/MJCore/src/generic/securityInfo.d.ts +0 -100
  41. package/dist/MJCore/src/generic/securityInfo.js +0 -194
  42. package/dist/MJCore/src/generic/securityInfo.js.map +0 -1
  43. package/dist/MJCore/src/generic/transactionGroup.d.ts +0 -24
  44. package/dist/MJCore/src/generic/transactionGroup.js +0 -79
  45. package/dist/MJCore/src/generic/transactionGroup.js.map +0 -1
  46. package/dist/MJCore/src/generic/util.d.ts +0 -16
  47. package/dist/MJCore/src/generic/util.js +0 -151
  48. package/dist/MJCore/src/generic/util.js.map +0 -1
  49. package/dist/MJCore/src/index.d.ts +0 -16
  50. package/dist/MJCore/src/index.js +0 -44
  51. package/dist/MJCore/src/index.js.map +0 -1
  52. package/dist/MJCore/src/views/runView.d.ts +0 -112
  53. package/dist/MJCore/src/views/runView.js +0 -63
  54. package/dist/MJCore/src/views/runView.js.map +0 -1
  55. package/dist/MJCore/src/views/viewInfo.d.ts +0 -59
  56. package/dist/MJCore/src/views/viewInfo.js +0 -121
  57. package/dist/MJCore/src/views/viewInfo.js.map +0 -1
  58. package/dist/MJGlobal/src/ObjectCache.d.ts +0 -26
  59. package/dist/MJGlobal/src/ObjectCache.js +0 -55
  60. package/dist/MJGlobal/src/ObjectCache.js.map +0 -1
  61. package/dist/generic/objectCache.d.ts +0 -26
  62. package/dist/generic/objectCache.js +0 -55
  63. package/dist/generic/objectCache.js.map +0 -1
  64. package/dist/generic/viewInfo.d.ts +0 -59
  65. package/dist/generic/viewInfo.js +0 -121
  66. package/dist/generic/viewInfo.js.map +0 -1
@@ -1,640 +0,0 @@
1
- "use strict";
2
- var _a;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ProviderBase = void 0;
5
- const baseEntity_1 = require("./baseEntity");
6
- const entityInfo_1 = require("./entityInfo");
7
- const applicationInfo_1 = require("../generic/applicationInfo");
8
- const securityInfo_1 = require("./securityInfo");
9
- const global_1 = require("@memberjunction/global");
10
- const logging_1 = require("./logging");
11
- const queryInfo_1 = require("./queryInfo");
12
- class ProviderBase {
13
- constructor() {
14
- this._entities = [];
15
- this._applications = [];
16
- this._roles = [];
17
- this._rowLevelSecurityFilters = [];
18
- this._auditLogTypes = [];
19
- this._authorizations = [];
20
- this._queries = [];
21
- this._queryCategories = [];
22
- this._queryFields = [];
23
- this._queryPermissions = [];
24
- this._refresh = false;
25
- }
26
- /******** END - ABSTRACT SECTION ****************************************************************** */
27
- async Config(data) {
28
- this._ConfigData = data;
29
- this._entities = []; // make sure to clear the array first - we could get this from a hard refresh
30
- this._applications = []; // make sure to clear the array first - we could get this from a hard refresh
31
- this._queries = []; // make sure to clear the array first - we could get this from a hard refresh
32
- this._queryCategories = []; // make sure to clear the array first - we could get this from a hard refresh
33
- if (this._refresh || await this.IsRefreshNeeded()) {
34
- // either a hard refresh flag was set within Refresh(), or LocalMetadata is Obsolete
35
- // first, make sure we reset the flag to false so that if another call to this function happens
36
- // while we are waiting for the async call to finish, we dont do it again
37
- this._refresh = false;
38
- const start = new Date().getTime();
39
- const res = await this.GetAllMetadata();
40
- const end = new Date().getTime();
41
- (0, logging_1.LogStatus)(`GetAllMetadata() took ${end - start} ms`);
42
- if (res) {
43
- this.UpdateLocalMetadata(res);
44
- this._latestLocalMetadataTimestamps = this._latestRemoteMetadataTimestamps; // update this since we just used server to get all the stuff
45
- this.SaveLocalMetadataToStorage();
46
- }
47
- }
48
- return true;
49
- }
50
- BuildDatasetFilterFromConfig() {
51
- // setup the schema filters as needed
52
- const f = [];
53
- // make sure that the MJ Core schema is always included if includeSchemas are provided because if the user doesn't include them stuff will break
54
- const includeSchemaList = this.ConfigData.IncludeSchemas;
55
- const excludeSchemaList = this.ConfigData.ExcludeSchemas;
56
- const mjcSchema = this.ConfigData.MJCoreSchemaName;
57
- // check to see if the MJ Core schema is already in the list, if not add it
58
- if (includeSchemaList && includeSchemaList.length > 0 && includeSchemaList.indexOf(mjcSchema) === -1)
59
- includeSchemaList.push(mjcSchema);
60
- // check to make sure that if exclude schemas are provided, the list DOES NOT include the MJ Core schema, if it does, remove it
61
- if (excludeSchemaList && excludeSchemaList.length > 0 && excludeSchemaList.indexOf(mjcSchema) !== -1) {
62
- const index = excludeSchemaList.indexOf(mjcSchema);
63
- excludeSchemaList.splice(index, 1);
64
- (0, logging_1.LogStatus)(`Removed MJ Core schema (${mjcSchema}) from ExcludeSchemas list because it is required for the API to function correctly`);
65
- }
66
- let schemaFilter = '';
67
- if (includeSchemaList && includeSchemaList.length > 0) {
68
- schemaFilter = 'SchemaName IN (' + includeSchemaList.map(s => `'${s}'`).join(',') + ')';
69
- }
70
- if (excludeSchemaList && excludeSchemaList.length > 0) {
71
- schemaFilter = (schemaFilter.length > 0 ? ' AND ' : '') + 'SchemaName NOT IN (' + excludeSchemaList.map(s => `'${s}'`).join(',') + ')';
72
- }
73
- if (schemaFilter.length > 0) {
74
- f.push({ ItemCode: 'Entities', Filter: schemaFilter });
75
- f.push({ ItemCode: 'EntityFields', Filter: schemaFilter });
76
- }
77
- return f;
78
- }
79
- async GetAllMetadata() {
80
- try {
81
- // we are now using datasets instead of the custom metadata to GraphQL to simplify GraphQL's work as it was very slow preivously
82
- //const start1 = new Date().getTime();
83
- const f = this.BuildDatasetFilterFromConfig();
84
- const d = await this.GetDatasetByName(_a._mjMetadataDatasetName, f.length > 0 ? f : null);
85
- //const end1 = new Date().getTime();
86
- //LogStatus(`GetAllMetadata - GetDatasetByName took ${end1 - start1}ms`)
87
- //const start2 = new Date().getTime();
88
- const u = await this.GetCurrentUser();
89
- //const end2 = new Date().getTime();
90
- //LogStatus(`GetAllMetadata - GetCurrentUser took ${end2 - start2}ms`)
91
- if (d && d.Success) {
92
- // got the results, let's build our response in the format we need
93
- const allMetadata = {};
94
- for (let r of d.Results) {
95
- allMetadata[r.Code] = r.Results;
96
- }
97
- // update the entities to include the fields, permissions and relationships
98
- allMetadata.AllEntities = this.PostProcessEntityMetadata(allMetadata.Entities, allMetadata.EntityFields, allMetadata.EntityFieldValues, allMetadata.EntityPermissions, allMetadata.EntityRelationships);
99
- // update the applications to include applicationentities
100
- allMetadata.AllApplications = allMetadata.Applications.map((a) => {
101
- a.ApplicationEntities = allMetadata.ApplicationEntities.filter((ae) => ae.ApplicationName.trim().toLowerCase() === a.Name.trim().toLowerCase());
102
- return new applicationInfo_1.ApplicationInfo(this, a);
103
- });
104
- return {
105
- AllEntities: allMetadata.AllEntities,
106
- AllApplications: allMetadata.AllApplications,
107
- AllRoles: allMetadata.Roles.map((r) => new securityInfo_1.RoleInfo(r)),
108
- CurrentUser: u,
109
- AllRowLevelSecurityFilters: allMetadata.RowLevelSecurityFilters.map((r) => new securityInfo_1.RowLevelSecurityFilterInfo(r)),
110
- AllAuditLogTypes: allMetadata.AuditLogTypes.map((a) => new securityInfo_1.AuditLogTypeInfo(a)),
111
- AllAuthorizations: allMetadata.Authorizations.map((a) => new securityInfo_1.AuthorizationInfo(a)),
112
- AllQueries: allMetadata.Queries ? allMetadata.Queries.map((q) => new queryInfo_1.QueryInfo(q)) : [],
113
- AllQueryFields: allMetadata.QueryFields ? allMetadata.QueryFields.map((qf) => new queryInfo_1.QueryFieldInfo(qf)) : [],
114
- AllQueryPermissions: allMetadata.QueryPermissions ? allMetadata.QueryPermissions.map((qp) => new queryInfo_1.QueryPermissionInfo(qp)) : [],
115
- AllQueryCategories: allMetadata.QueryCategories ? allMetadata.QueryCategories.map((qc) => new queryInfo_1.QueryCategoryInfo(qc)) : []
116
- };
117
- }
118
- else {
119
- (0, logging_1.LogError)('GetAllMetadata() - Error getting metadata from server' + (d ? ': ' + d.Status : ''));
120
- }
121
- }
122
- catch (e) {
123
- (0, logging_1.LogError)(e);
124
- }
125
- }
126
- PostProcessEntityMetadata(entities, fields, fieldValues, permissions, relationships) {
127
- const result = [];
128
- if (fieldValues && fieldValues.length > 0)
129
- for (let f of fields) {
130
- // populate the field values for each field, if we have them
131
- f.EntityFieldValues = fieldValues.filter(fv => fv.EntityID === f.EntityID && fv.EntityFieldName.trim().toLowerCase() === f.Name.trim().toLowerCase());
132
- }
133
- for (let e of entities) {
134
- e.EntityFields = fields.filter(f => f.EntityID === e.ID).sort((a, b) => a.Sequence - b.Sequence);
135
- e.EntityPermissions = permissions.filter(p => p.EntityID === e.ID);
136
- e.EntityRelationships = relationships.filter(r => r.EntityID === e.ID);
137
- result.push(new entityInfo_1.EntityInfo(e));
138
- }
139
- return result;
140
- }
141
- get ConfigData() {
142
- return this._ConfigData;
143
- }
144
- get Entities() {
145
- return this._entities;
146
- }
147
- get Applications() {
148
- return this._applications;
149
- }
150
- get CurrentUser() {
151
- return this._currentUser;
152
- }
153
- get Roles() {
154
- return this._roles;
155
- }
156
- get RowLevelSecurityFilters() {
157
- return this._rowLevelSecurityFilters;
158
- }
159
- get AuditLogTypes() {
160
- return this._auditLogTypes;
161
- }
162
- get Authorizations() {
163
- return this._authorizations;
164
- }
165
- get Queries() {
166
- return this._queries;
167
- }
168
- get QueryCategories() {
169
- return this._queryCategories;
170
- }
171
- get QueryFields() {
172
- return this._queryFields;
173
- }
174
- get QueryPermissions() {
175
- return this._queryPermissions;
176
- }
177
- async Refresh() {
178
- // do nothing here, but set a _refresh flag for next time things are requested
179
- if (this.AllowRefresh) {
180
- this._refresh = true;
181
- return this.Config(this._ConfigData);
182
- }
183
- else
184
- return true; // subclass is telling us not to do any refresh ops right now
185
- }
186
- async IsRefreshNeeded() {
187
- if (this.AllowRefresh) {
188
- await this.RefreshRemoteMetadataTimestamps(); // get the latest timestamps from the server first
189
- await this.LoadLocalMetadataFromStorage(); // then, attempt to load before we check to see if it is obsolete
190
- return this.LocalMetadataObsolete();
191
- }
192
- else //subclass is telling us not to do any refresh ops right now
193
- return false;
194
- }
195
- async RefreshIfNeeded() {
196
- if (await this.IsRefreshNeeded())
197
- return this.Refresh();
198
- else
199
- return true;
200
- }
201
- async GetEntityObject(entityName, contextUser = null) {
202
- try {
203
- const entity = this.Metadata.Entities.find(e => e.Name == entityName);
204
- if (entity) {
205
- // Use the MJGlobal Class Factory to do our object instantiation
206
- try {
207
- const newObject = global_1.MJGlobal.Instance.ClassFactory.CreateInstance(baseEntity_1.BaseEntity, entityName, entity);
208
- if (contextUser)
209
- newObject.ContextCurrentUser = contextUser;
210
- return newObject;
211
- }
212
- catch (e) {
213
- (0, logging_1.LogError)(e);
214
- throw new Error(`Entity ${entityName} could not be instantiated via MJGlobal Class Factory. Make sure you have registered the class reference with MJGlobal.Instance.ClassFactory.Register(). ALSO, make sure you call LoadGeneratedEntities() from the GeneratedEntities project within your project as tree-shaking sometimes removes subclasses and could be causing this error!`);
215
- }
216
- }
217
- else
218
- throw new Error(`Entity ${entityName} not found in metadata`);
219
- }
220
- catch (ex) {
221
- (0, logging_1.LogError)(ex);
222
- return null;
223
- }
224
- }
225
- /**
226
- * Returns a list of entity dependencies, basically metadata that tells you the links to this entity from all other entities.
227
- * @param entityName
228
- * @returns
229
- */
230
- async GetEntityDependencies(entityName) {
231
- // using our metadata, find all of the foreign keys that point to this entity
232
- // go through each entity and find all the fields that have a RelatedEntity = entityName
233
- try {
234
- const eName = entityName.trim().toLowerCase();
235
- const result = [];
236
- for (let re of this.Entities) {
237
- const relatedFields = re.Fields.filter(f => f.RelatedEntity?.trim().toLowerCase() === eName);
238
- // we now have all the fields, so let's create the EntityDependency objects
239
- relatedFields.map(f => {
240
- result.push({
241
- EntityName: entityName,
242
- RelatedEntityName: re.Name,
243
- FieldName: f.Name
244
- });
245
- });
246
- }
247
- return result;
248
- }
249
- catch (e) {
250
- (0, logging_1.LogError)(e);
251
- throw e;
252
- }
253
- }
254
- /**
255
- * Gets a database by name, if required, and caches it in a format available to the client (e.g. IndexedDB, LocalStorage, File, etc). The cache method is Provider specific
256
- * If itemFilters are provided, the combination of datasetName and the filters are used to determine a match in the cache
257
- * @param datasetName
258
- * @param itemFilters
259
- */
260
- async GetAndCacheDatasetByName(datasetName, itemFilters) {
261
- // first see if we have anything in cache at all, no reason to check server dates if we dont
262
- if (await this.IsDatasetCached(datasetName, itemFilters)) {
263
- // compare the local version, if exists to the server version dates
264
- if (await this.IsDatasetCacheUpToDate(datasetName, itemFilters)) {
265
- // we're up to date, all we need to do is get the local cache and return it
266
- return this.GetCachedDataset(datasetName, itemFilters);
267
- }
268
- else {
269
- // we're out of date, so get the dataset from the server
270
- const dataset = await this.GetDatasetByName(datasetName, itemFilters);
271
- // cache it
272
- await this.CacheDataset(datasetName, itemFilters, dataset);
273
- return dataset;
274
- }
275
- }
276
- else {
277
- // get the dataset from the server
278
- const dataset = await this.GetDatasetByName(datasetName, itemFilters);
279
- // cache it
280
- await this.CacheDataset(datasetName, itemFilters, dataset);
281
- return dataset;
282
- }
283
- }
284
- /**
285
- * This routine checks to see if the local cache version of a given datasetName/itemFilters combination is up to date with the server or not
286
- * @param datasetName
287
- * @param itemFilters
288
- * @returns
289
- */
290
- async IsDatasetCacheUpToDate(datasetName, itemFilters) {
291
- const ls = this.LocalStorageProvider;
292
- if (ls) {
293
- const key = this.GetDatasetCacheKey(datasetName, itemFilters);
294
- const dateKey = key + '_date';
295
- const val = await ls.getItem(dateKey);
296
- if (val) {
297
- // we have a local cached timestamp, so compare it to the server timestamp
298
- const status = await this.GetDatasetStatusByName(datasetName, itemFilters);
299
- if (status) {
300
- const serverTimestamp = status.LatestUpdateDate.getTime();
301
- const localTimestamp = new Date(val);
302
- return localTimestamp.getTime() >= serverTimestamp;
303
- }
304
- else {
305
- return false;
306
- }
307
- }
308
- else {
309
- return false;
310
- }
311
- }
312
- }
313
- /**
314
- * This routine gets the local cached version of a given datasetName/itemFilters combination, it does NOT check the server status first and does not fall back on the server if there isn't a local cache version of this dataset/itemFilters combination
315
- * @param datasetName
316
- * @param itemFilters
317
- * @returns
318
- */
319
- async GetCachedDataset(datasetName, itemFilters) {
320
- const ls = this.LocalStorageProvider;
321
- if (ls) {
322
- const key = this.GetDatasetCacheKey(datasetName, itemFilters);
323
- const val = await ls.getItem(key);
324
- if (val) {
325
- const dataset = JSON.parse(val);
326
- return dataset;
327
- }
328
- }
329
- }
330
- /**
331
- * Stores a dataset in the local cache. If itemFilters are provided, the combination of datasetName and the filters are used to build a key and determine a match in the cache
332
- * @param datasetName
333
- * @param itemFilters
334
- * @param dataset
335
- */
336
- async CacheDataset(datasetName, itemFilters, dataset) {
337
- const ls = this.LocalStorageProvider;
338
- if (ls) {
339
- const key = this.GetDatasetCacheKey(datasetName, itemFilters);
340
- const val = JSON.stringify(dataset);
341
- await ls.setItem(key, val);
342
- const dateKey = key + '_date';
343
- const dateVal = dataset.LatestUpdateDate.toISOString();
344
- await ls.setItem(dateKey, dateVal);
345
- }
346
- }
347
- /**
348
- * Determines if a given datasetName/itemFilters combination is cached locally or not
349
- * @param datasetName
350
- * @param itemFilters
351
- * @returns
352
- */
353
- async IsDatasetCached(datasetName, itemFilters) {
354
- const ls = this.LocalStorageProvider;
355
- if (ls) {
356
- const key = this.GetDatasetCacheKey(datasetName, itemFilters);
357
- const val = await ls.getItem(key);
358
- return val !== null && val !== undefined;
359
- }
360
- }
361
- /**
362
- * Creates a key for the given datasetName and itemFilters combination
363
- * @param datasetName
364
- * @param itemFilters
365
- * @returns
366
- */
367
- GetDatasetCacheKey(datasetName, itemFilters) {
368
- return _a.localStorageRootKey + '__DATASET__' + datasetName + this.ConvertItemFiltersToUniqueKey(itemFilters);
369
- }
370
- ConvertItemFiltersToUniqueKey(itemFilters) {
371
- if (itemFilters) {
372
- const key = '{' + itemFilters.map(f => `"${f.ItemCode}":"${f.Filter}"`).join(',') + '}'; // this is a unique key for the item filters
373
- return key;
374
- }
375
- else
376
- return '';
377
- }
378
- /**
379
- * If the specified datasetName is cached, this method will clear the cache. If itemFilters are provided, the combination of datasetName and the filters are used to determine a match in the cache
380
- * @param datasetName
381
- * @param itemFilters
382
- */
383
- async ClearDatasetCache(datasetName, itemFilters) {
384
- const ls = this.LocalStorageProvider;
385
- if (ls) {
386
- const key = this.GetDatasetCacheKey(datasetName, itemFilters);
387
- await ls.remove(key);
388
- const dateKey = key + '_date';
389
- await ls.remove(dateKey);
390
- }
391
- }
392
- get LatestRemoteMetadata() {
393
- return this._latestRemoteMetadataTimestamps;
394
- }
395
- get LatestLocalMetadata() {
396
- return this._latestLocalMetadataTimestamps;
397
- }
398
- async GetLatestMetadataUpdates() {
399
- const f = this.BuildDatasetFilterFromConfig();
400
- const d = await this.GetDatasetStatusByName(_a._mjMetadataDatasetName, f.length > 0 ? f : null);
401
- if (d && d.Success) {
402
- const ret = d.EntityUpdateDates.map(e => {
403
- return {
404
- ID: e.EntityID,
405
- Type: e.EntityName,
406
- UpdatedAt: e.UpdateDate
407
- };
408
- });
409
- // combine the entityupdate dates with a single top level entry for the dataset itself
410
- ret.push({
411
- ID: -1,
412
- Type: 'All Entity Metadata',
413
- UpdatedAt: d.LatestUpdateDate
414
- });
415
- return ret;
416
- }
417
- }
418
- async RefreshRemoteMetadataTimestamps() {
419
- const mdTimeStamps = await this.GetLatestMetadataUpdates(); // sub-class implements this
420
- if (mdTimeStamps) {
421
- this._latestRemoteMetadataTimestamps = mdTimeStamps;
422
- return true;
423
- }
424
- else
425
- return false;
426
- }
427
- LocalMetadataObsolete(type) {
428
- const mdLocal = this.LatestLocalMetadata;
429
- const mdRemote = this.LatestRemoteMetadata;
430
- if (!mdLocal || !mdRemote || !mdLocal.length || !mdRemote.length || mdLocal.length === 0 || mdRemote.length === 0)
431
- return true;
432
- for (let i = 0; i < mdRemote.length; ++i) {
433
- let bProcess = true;
434
- if (type && type.length > 0)
435
- bProcess = mdRemote[i].Type.toLowerCase().trim() === type.trim().toLowerCase();
436
- if (bProcess) {
437
- const l = mdLocal.find(md => md.Type.trim().toLowerCase() === mdRemote[i].Type.trim().toLowerCase());
438
- if (!l)
439
- return true; // no match, obsolete in this case
440
- else {
441
- // we have a match, now test various things
442
- if (!l.UpdatedAt && !mdRemote[i].UpdatedAt) {
443
- // both are null, so we're good
444
- // do nothing, keep on truckin'
445
- // console.log('TEST: both are null, so we\'re good')
446
- }
447
- else if (l.UpdatedAt && mdRemote[i].UpdatedAt) {
448
- // both are not null, so we need to compare them
449
- const localTime = new Date(l.UpdatedAt);
450
- const remoteTime = new Date(mdRemote[i].UpdatedAt);
451
- if (localTime.getTime() !== remoteTime.getTime()) {
452
- return true; // we can short circuit the entire rest of the function
453
- // as one obsolete is good enough to obsolete the entire local metadata
454
- }
455
- }
456
- else
457
- return true; // one is null and the other is not, so we're obsolete without even comparing
458
- }
459
- }
460
- }
461
- // if we get here, we're not obsolete!!
462
- return false;
463
- }
464
- UpdateLocalMetadata(res) {
465
- if (res.AllEntities) {
466
- this._entities = [];
467
- for (let i = 0; i < res.AllEntities.length; i++) {
468
- this._entities.push(new entityInfo_1.EntityInfo(res.AllEntities[i]));
469
- }
470
- }
471
- if (res.AllApplications) {
472
- this._applications = [];
473
- for (let i = 0; i < res.AllApplications.length; i++) {
474
- const a = new applicationInfo_1.ApplicationInfo(this, res.AllApplications[i]);
475
- this._applications.push(a);
476
- }
477
- }
478
- if (res.AllRoles) {
479
- this._roles = [];
480
- for (let i = 0; i < res.AllRoles.length; i++) {
481
- const r = new securityInfo_1.RoleInfo(res.AllRoles[i]);
482
- this._roles.push(r);
483
- }
484
- }
485
- if (res.AllRowLevelSecurityFilters) {
486
- this._rowLevelSecurityFilters = [];
487
- for (let i = 0; i < res.AllRowLevelSecurityFilters.length; i++) {
488
- const rls = new securityInfo_1.RowLevelSecurityFilterInfo(res.AllRowLevelSecurityFilters[i]);
489
- this._rowLevelSecurityFilters.push(rls);
490
- }
491
- }
492
- if (res.AllAuditLogTypes) {
493
- this._auditLogTypes = [];
494
- for (let i = 0; i < res.AllAuditLogTypes.length; i++) {
495
- const alt = new securityInfo_1.AuditLogTypeInfo(res.AllAuditLogTypes[i]);
496
- this._auditLogTypes.push(alt);
497
- }
498
- }
499
- if (res.AllAuthorizations) {
500
- this._authorizations = [];
501
- for (let i = 0; i < res.AllAuthorizations.length; i++) {
502
- const ai = new securityInfo_1.AuthorizationInfo(this, res.AllAuthorizations[i]);
503
- this._authorizations.push(ai);
504
- }
505
- }
506
- if (res.AllQueries) {
507
- this._queries = [];
508
- for (let i = 0; i < res.AllQueries.length; i++) {
509
- const q = new queryInfo_1.QueryInfo(res.AllQueries[i]);
510
- this._queries.push(q);
511
- }
512
- }
513
- if (res.AllQueryCategories) {
514
- this._queryCategories = [];
515
- for (let i = 0; i < res.AllQueryCategories.length; i++) {
516
- const qc = new queryInfo_1.QueryCategoryInfo(res.AllQueryCategories[i]);
517
- this._queryCategories.push(qc);
518
- }
519
- }
520
- if (res.AllQueryFields) {
521
- this._queryFields = [];
522
- for (let i = 0; i < res.AllQueryFields.length; i++) {
523
- const qf = new queryInfo_1.QueryFieldInfo(res.AllQueryFields[i]);
524
- this._queryFields.push(qf);
525
- }
526
- }
527
- if (res.AllQueryPermissions) {
528
- this._queryPermissions = [];
529
- for (let i = 0; i < res.AllQueryPermissions.length; i++) {
530
- const qp = new queryInfo_1.QueryPermissionInfo(res.AllQueryPermissions[i]);
531
- this._queryPermissions.push(qp);
532
- }
533
- }
534
- if (res.CurrentUser)
535
- this._currentUser = new securityInfo_1.UserInfo(this, res.CurrentUser);
536
- }
537
- async LoadLocalMetadataFromStorage() {
538
- try {
539
- const ls = this.LocalStorageProvider;
540
- if (ls) {
541
- // execution environment supports local storage, use it
542
- this._latestLocalMetadataTimestamps = JSON.parse(await ls.getItem(_a.localStorageTimestampsKey));
543
- const e = JSON.parse(await ls.getItem(_a.localStorageEntitiesKey));
544
- const a = JSON.parse(await ls.getItem(_a.localStorageApplicationsKey));
545
- const cu = JSON.parse(await ls.getItem(_a.localStorageCurrentUserKey));
546
- const r = JSON.parse(await ls.getItem(_a.localStorageRolesKey));
547
- const rls = JSON.parse(await ls.getItem(_a.localStorageRowLevelSecurityFiltersKey));
548
- const alt = JSON.parse(await ls.getItem(_a.localStorageAuditLogTypesKey));
549
- const ai = JSON.parse(await ls.getItem(_a.localStorageAuthorizationsKey));
550
- const queries = JSON.parse(await ls.getItem(_a.localStorageQueriesKey));
551
- const qcs = JSON.parse(await ls.getItem(_a.localStorageQueryCategoriesKey));
552
- const qf = JSON.parse(await ls.getItem(_a.localStorageQueryFieldsKey));
553
- const qp = JSON.parse(await ls.getItem(_a.localStorageQueryPermissionsKey));
554
- this.UpdateLocalMetadata({
555
- AllEntities: e,
556
- AllApplications: a,
557
- CurrentUser: cu,
558
- AllRoles: r,
559
- AllRowLevelSecurityFilters: rls,
560
- AllAuditLogTypes: alt,
561
- AllAuthorizations: ai,
562
- AllQueries: queries,
563
- AllQueryCategories: qcs,
564
- AllQueryFields: qf,
565
- AllQueryPermissions: qp
566
- });
567
- }
568
- }
569
- catch (e) {
570
- // some enviroments don't support local storage
571
- }
572
- }
573
- async SaveLocalMetadataToStorage() {
574
- try {
575
- const ls = this.LocalStorageProvider;
576
- if (ls) {
577
- // execution environment supports local storage, use it
578
- await ls.setItem(_a.localStorageTimestampsKey, JSON.stringify(this._latestLocalMetadataTimestamps));
579
- await ls.setItem(_a.localStorageEntitiesKey, JSON.stringify(this._entities));
580
- await ls.setItem(_a.localStorageApplicationsKey, JSON.stringify(this._applications));
581
- await ls.setItem(_a.localStorageCurrentUserKey, JSON.stringify(this._currentUser));
582
- await ls.setItem(_a.localStorageRolesKey, JSON.stringify(this._roles));
583
- await ls.setItem(_a.localStorageRowLevelSecurityFiltersKey, JSON.stringify(this._rowLevelSecurityFilters));
584
- await ls.setItem(_a.localStorageAuditLogTypesKey, JSON.stringify(this._auditLogTypes));
585
- await ls.setItem(_a.localStorageAuthorizationsKey, JSON.stringify(this._authorizations));
586
- await ls.setItem(_a.localStorageQueriesKey, JSON.stringify(this._queries));
587
- await ls.setItem(_a.localStorageQueryCategoriesKey, JSON.stringify(this._queryCategories));
588
- await ls.setItem(_a.localStorageQueryFieldsKey, JSON.stringify(this._queryFields));
589
- await ls.setItem(_a.localStorageQueryPermissionsKey, JSON.stringify(this._queryPermissions));
590
- }
591
- }
592
- catch (e) {
593
- // some enviroments don't support local storage
594
- (0, logging_1.LogError)(e);
595
- }
596
- }
597
- async RemoveLocalMetadataFromStorage() {
598
- try {
599
- const ls = this.LocalStorageProvider;
600
- for (let i = 0; i < _a.localStorageKeys.length; i++) {
601
- await ls.remove(_a.localStorageKeys[i]);
602
- }
603
- }
604
- catch (e) {
605
- // some enviroments don't support local storage
606
- (0, logging_1.LogError)(e);
607
- }
608
- }
609
- }
610
- exports.ProviderBase = ProviderBase;
611
- _a = ProviderBase;
612
- ProviderBase._mjMetadataDatasetName = 'MJ_Metadata';
613
- ProviderBase.localStorageRootKey = '___MJCore_Metadata';
614
- ProviderBase.localStorageTimestampsKey = _a.localStorageRootKey + '_Timestamps';
615
- ProviderBase.localStorageEntitiesKey = _a.localStorageRootKey + '_Entities';
616
- ProviderBase.localStorageApplicationsKey = _a.localStorageRootKey + '_Applications';
617
- ProviderBase.localStorageCurrentUserKey = _a.localStorageRootKey + '_CurrentUser';
618
- ProviderBase.localStorageRolesKey = _a.localStorageRootKey + '_Roles';
619
- ProviderBase.localStorageRowLevelSecurityFiltersKey = _a.localStorageRootKey + '_RowLevelSecurityFilters';
620
- ProviderBase.localStorageAuditLogTypesKey = _a.localStorageRootKey + '_AuditLogTypes';
621
- ProviderBase.localStorageAuthorizationsKey = _a.localStorageRootKey + '_Authorizations';
622
- ProviderBase.localStorageQueriesKey = _a.localStorageRootKey + '_Queries';
623
- ProviderBase.localStorageQueryCategoriesKey = _a.localStorageRootKey + '_QueryCategories';
624
- ProviderBase.localStorageQueryFieldsKey = _a.localStorageRootKey + '_QueryFields';
625
- ProviderBase.localStorageQueryPermissionsKey = _a.localStorageRootKey + '_QueryPermissions';
626
- ProviderBase.localStorageKeys = [
627
- _a.localStorageTimestampsKey,
628
- _a.localStorageEntitiesKey,
629
- _a.localStorageApplicationsKey,
630
- _a.localStorageCurrentUserKey,
631
- _a.localStorageRolesKey,
632
- _a.localStorageRowLevelSecurityFiltersKey,
633
- _a.localStorageAuditLogTypesKey,
634
- _a.localStorageAuthorizationsKey,
635
- _a.localStorageQueriesKey,
636
- _a.localStorageQueryCategoriesKey,
637
- _a.localStorageQueryFieldsKey,
638
- _a.localStorageQueryPermissionsKey
639
- ];
640
- //# sourceMappingURL=providerBase.js.map