@salesforce/lds-adapters-industries-explainability 1.100.2

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.
@@ -0,0 +1,728 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.industriesExplainability = {}, global.engine));
11
+ })(this, (function (exports, engine) { 'use strict';
12
+
13
+ var ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
14
+ var ObjectKeys$1 = Object.keys;
15
+ var ArrayIsArray$1 = Array.isArray;
16
+ /**
17
+ * Validates an adapter config is well-formed.
18
+ * @param config The config to validate.
19
+ * @param adapter The adapter validation configuration.
20
+ * @param oneOf The keys the config must contain at least one of.
21
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
22
+ */
23
+ function validateConfig(config, adapter, oneOf) {
24
+ var displayName = adapter.displayName;
25
+ var _a = adapter.parameters, required = _a.required, optional = _a.optional, unsupported = _a.unsupported;
26
+ if (config === undefined ||
27
+ required.every(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); }) === false) {
28
+ throw new TypeError("adapter ".concat(displayName, " configuration must specify ").concat(required.sort().join(', ')));
29
+ }
30
+ if (oneOf && oneOf.some(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); }) === false) {
31
+ throw new TypeError("adapter ".concat(displayName, " configuration must specify one of ").concat(oneOf.sort().join(', ')));
32
+ }
33
+ if (unsupported !== undefined &&
34
+ unsupported.some(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); })) {
35
+ throw new TypeError("adapter ".concat(displayName, " does not yet support ").concat(unsupported.sort().join(', ')));
36
+ }
37
+ var supported = required.concat(optional);
38
+ if (ObjectKeys$1(config).some(function (key) { return !supported.includes(key); })) {
39
+ throw new TypeError("adapter ".concat(displayName, " configuration supports only ").concat(supported.sort().join(', ')));
40
+ }
41
+ }
42
+ function untrustedIsObject(untrusted) {
43
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
44
+ }
45
+ function areRequiredParametersPresent(config, configPropertyNames) {
46
+ return configPropertyNames.parameters.required.every(function (req) { return req in config; });
47
+ }
48
+ var snapshotRefreshOptions = {
49
+ overrides: {
50
+ headers: {
51
+ 'Cache-Control': 'no-cache',
52
+ },
53
+ }
54
+ };
55
+ var keyPrefix = 'explainability';
56
+
57
+ var ObjectFreeze = Object.freeze, ObjectKeys = Object.keys;
58
+ var ArrayIsArray = Array.isArray;
59
+ var JSONStringify = JSON.stringify;
60
+ function deepFreeze$3(value) {
61
+ // No need to freeze primitives
62
+ if (typeof value !== 'object' || value === null) {
63
+ return;
64
+ }
65
+ if (ArrayIsArray(value)) {
66
+ for (var i = 0, len = value.length; i < len; i += 1) {
67
+ deepFreeze$3(value[i]);
68
+ }
69
+ }
70
+ else {
71
+ var keys = ObjectKeys(value);
72
+ for (var i = 0, len = keys.length; i < len; i += 1) {
73
+ deepFreeze$3(value[keys[i]]);
74
+ }
75
+ }
76
+ ObjectFreeze(value);
77
+ }
78
+ function createLink(ref) {
79
+ return {
80
+ __ref: engine.serializeStructuredKey(ref),
81
+ };
82
+ }
83
+
84
+ function validate$3(obj, path) {
85
+ if (path === void 0) { path = 'ExplainabilityActionLogDetailRepresentation'; }
86
+ var v_error = (function () {
87
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
88
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
89
+ }
90
+ var obj_actionContextCode = obj.actionContextCode;
91
+ var path_actionContextCode = path + '.actionContextCode';
92
+ if (typeof obj_actionContextCode !== 'string') {
93
+ return new TypeError('Expected "string" but received "' + typeof obj_actionContextCode + '" (at "' + path_actionContextCode + '")');
94
+ }
95
+ var obj_actionLog = obj.actionLog;
96
+ var path_actionLog = path + '.actionLog';
97
+ if (typeof obj_actionLog !== 'string') {
98
+ return new TypeError('Expected "string" but received "' + typeof obj_actionLog + '" (at "' + path_actionLog + '")');
99
+ }
100
+ if (obj.additionalFilter !== undefined) {
101
+ var obj_additionalFilter = obj.additionalFilter;
102
+ var path_additionalFilter = path + '.additionalFilter';
103
+ if (typeof obj_additionalFilter !== 'string') {
104
+ return new TypeError('Expected "string" but received "' + typeof obj_additionalFilter + '" (at "' + path_additionalFilter + '")');
105
+ }
106
+ }
107
+ var obj_applicationLogDate = obj.applicationLogDate;
108
+ var path_applicationLogDate = path + '.applicationLogDate';
109
+ if (typeof obj_applicationLogDate !== 'string') {
110
+ return new TypeError('Expected "string" but received "' + typeof obj_applicationLogDate + '" (at "' + path_applicationLogDate + '")');
111
+ }
112
+ var obj_applicationSubtype = obj.applicationSubtype;
113
+ var path_applicationSubtype = path + '.applicationSubtype';
114
+ if (typeof obj_applicationSubtype !== 'string') {
115
+ return new TypeError('Expected "string" but received "' + typeof obj_applicationSubtype + '" (at "' + path_applicationSubtype + '")');
116
+ }
117
+ var obj_applicationType = obj.applicationType;
118
+ var path_applicationType = path + '.applicationType';
119
+ if (typeof obj_applicationType !== 'string') {
120
+ return new TypeError('Expected "string" but received "' + typeof obj_applicationType + '" (at "' + path_applicationType + '")');
121
+ }
122
+ var obj_explainabilitySpecName = obj.explainabilitySpecName;
123
+ var path_explainabilitySpecName = path + '.explainabilitySpecName';
124
+ if (typeof obj_explainabilitySpecName !== 'string') {
125
+ return new TypeError('Expected "string" but received "' + typeof obj_explainabilitySpecName + '" (at "' + path_explainabilitySpecName + '")');
126
+ }
127
+ var obj_name = obj.name;
128
+ var path_name = path + '.name';
129
+ if (typeof obj_name !== 'string') {
130
+ return new TypeError('Expected "string" but received "' + typeof obj_name + '" (at "' + path_name + '")');
131
+ }
132
+ if (obj.primaryFilter !== undefined) {
133
+ var obj_primaryFilter = obj.primaryFilter;
134
+ var path_primaryFilter = path + '.primaryFilter';
135
+ if (typeof obj_primaryFilter !== 'string') {
136
+ return new TypeError('Expected "string" but received "' + typeof obj_primaryFilter + '" (at "' + path_primaryFilter + '")');
137
+ }
138
+ }
139
+ var obj_processType = obj.processType;
140
+ var path_processType = path + '.processType';
141
+ if (typeof obj_processType !== 'string') {
142
+ return new TypeError('Expected "string" but received "' + typeof obj_processType + '" (at "' + path_processType + '")');
143
+ }
144
+ if (obj.secondaryFilter !== undefined) {
145
+ var obj_secondaryFilter = obj.secondaryFilter;
146
+ var path_secondaryFilter = path + '.secondaryFilter';
147
+ if (typeof obj_secondaryFilter !== 'string') {
148
+ return new TypeError('Expected "string" but received "' + typeof obj_secondaryFilter + '" (at "' + path_secondaryFilter + '")');
149
+ }
150
+ }
151
+ })();
152
+ return v_error === undefined ? null : v_error;
153
+ }
154
+ function deepFreeze$2(input) {
155
+ ObjectFreeze(input);
156
+ }
157
+
158
+ var TTL$1 = 10000;
159
+ var VERSION$1 = "d0452c2b6e53e2a843a03bf30a275e18";
160
+ function validate$2(obj, path) {
161
+ if (path === void 0) { path = 'ExplainabilityActionLogsRepresentation'; }
162
+ var v_error = (function () {
163
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
164
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
165
+ }
166
+ var obj_actionLogs = obj.actionLogs;
167
+ var path_actionLogs = path + '.actionLogs';
168
+ if (!ArrayIsArray(obj_actionLogs)) {
169
+ return new TypeError('Expected "array" but received "' + typeof obj_actionLogs + '" (at "' + path_actionLogs + '")');
170
+ }
171
+ for (var i = 0; i < obj_actionLogs.length; i++) {
172
+ var obj_actionLogs_item = obj_actionLogs[i];
173
+ var path_actionLogs_item = path_actionLogs + '[' + i + ']';
174
+ var referencepath_actionLogs_itemValidationError = validate$3(obj_actionLogs_item, path_actionLogs_item);
175
+ if (referencepath_actionLogs_itemValidationError !== null) {
176
+ var message = 'Object doesn\'t match ExplainabilityActionLogDetailRepresentation (at "' + path_actionLogs_item + '")\n';
177
+ message += referencepath_actionLogs_itemValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
178
+ return new TypeError(message);
179
+ }
180
+ }
181
+ if (obj.queryMore !== undefined) {
182
+ var obj_queryMore = obj.queryMore;
183
+ var path_queryMore = path + '.queryMore';
184
+ if (typeof obj_queryMore !== 'string') {
185
+ return new TypeError('Expected "string" but received "' + typeof obj_queryMore + '" (at "' + path_queryMore + '")');
186
+ }
187
+ }
188
+ })();
189
+ return v_error === undefined ? null : v_error;
190
+ }
191
+ var RepresentationType$1 = 'ExplainabilityActionLogsRepresentation';
192
+ function normalize$1(input, existing, path, luvio, store, timestamp) {
193
+ return input;
194
+ }
195
+ var select$3 = function ExplainabilityActionLogsRepresentationSelect() {
196
+ return {
197
+ kind: 'Fragment',
198
+ version: VERSION$1,
199
+ private: [],
200
+ opaque: true
201
+ };
202
+ };
203
+ function equals$1(existing, incoming) {
204
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
205
+ return false;
206
+ }
207
+ return true;
208
+ }
209
+ function deepFreeze$1(input) {
210
+ var input_actionLogs = input.actionLogs;
211
+ for (var i = 0; i < input_actionLogs.length; i++) {
212
+ var input_actionLogs_item = input_actionLogs[i];
213
+ deepFreeze$2(input_actionLogs_item);
214
+ }
215
+ ObjectFreeze(input_actionLogs);
216
+ ObjectFreeze(input);
217
+ }
218
+ var ingest$1 = function ExplainabilityActionLogsRepresentationIngest(input, path, luvio, store, timestamp) {
219
+ if (process.env.NODE_ENV !== 'production') {
220
+ var validateError = validate$2(input);
221
+ if (validateError !== null) {
222
+ throw validateError;
223
+ }
224
+ }
225
+ var key = path.fullPath;
226
+ var existingRecord = store.readEntry(key);
227
+ var ttlToUse = TTL$1;
228
+ var incomingRecord = normalize$1(input, store.readEntry(key), {
229
+ fullPath: key,
230
+ parent: path.parent,
231
+ propertyName: path.propertyName,
232
+ ttl: ttlToUse
233
+ });
234
+ deepFreeze$1(input);
235
+ if (existingRecord === undefined || equals$1(existingRecord, incomingRecord) === false) {
236
+ luvio.storePublish(key, incomingRecord);
237
+ }
238
+ {
239
+ var storeMetadataParams = {
240
+ ttl: ttlToUse,
241
+ namespace: "explainability",
242
+ version: VERSION$1,
243
+ representationName: RepresentationType$1,
244
+ };
245
+ luvio.publishStoreMetadata(key, storeMetadataParams);
246
+ }
247
+ return createLink(key);
248
+ };
249
+ function getTypeCacheKeys$1(luvio, input, fullPathFactory) {
250
+ var rootKeySet = new engine.StoreKeyMap();
251
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
252
+ var rootKey = fullPathFactory();
253
+ rootKeySet.set(rootKey, {
254
+ namespace: keyPrefix,
255
+ representationName: RepresentationType$1,
256
+ mergeable: false
257
+ });
258
+ return rootKeySet;
259
+ }
260
+
261
+ function select$2(luvio, params) {
262
+ return select$3();
263
+ }
264
+ function keyBuilder$2(luvio, params) {
265
+ return keyPrefix + '::ExplainabilityActionLogsRepresentation:(' + 'actionContextCode:' + params.queryParams.actionContextCode + ',' + 'applicationSubType:' + params.queryParams.applicationSubType + ',' + 'applicationType:' + params.queryParams.applicationType + ',' + 'createdAfter:' + params.queryParams.createdAfter + ',' + 'createdBefore:' + params.queryParams.createdBefore + ',' + 'pageSize:' + params.queryParams.pageSize + ',' + 'processType:' + params.queryParams.processType + ',' + 'queryMore:' + params.queryParams.queryMore + ',' + 'primaryFilter:' + params.queryParams.primaryFilter + ',' + 'secondaryFilter:' + params.queryParams.secondaryFilter + ',' + 'additionalFilter:' + params.queryParams.additionalFilter + ',' + 'sortDirection:' + params.queryParams.sortDirection + ')';
266
+ }
267
+ function getResponseCacheKeys$1(luvio, resourceParams, response) {
268
+ return getTypeCacheKeys$1(luvio, response, function () { return keyBuilder$2(luvio, resourceParams); });
269
+ }
270
+ function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
271
+ var body = response.body;
272
+ var key = keyBuilder$2(luvio, resourceParams);
273
+ luvio.storeIngest(key, ingest$1, body);
274
+ var snapshot = luvio.storeLookup({
275
+ recordId: key,
276
+ node: select$2(),
277
+ variables: {},
278
+ }, snapshotRefresh);
279
+ if (process.env.NODE_ENV !== 'production') {
280
+ if (snapshot.state !== 'Fulfilled') {
281
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
282
+ }
283
+ }
284
+ return snapshot;
285
+ }
286
+ function ingestError(luvio, params, error, snapshotRefresh) {
287
+ var key = keyBuilder$2(luvio, params);
288
+ var errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
289
+ var storeMetadataParams = {
290
+ ttl: TTL$1,
291
+ namespace: keyPrefix,
292
+ version: VERSION$1,
293
+ representationName: RepresentationType$1
294
+ };
295
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
296
+ return errorSnapshot;
297
+ }
298
+ function createResourceRequest$1(config) {
299
+ var headers = {};
300
+ return {
301
+ baseUri: '/services/data/v58.0',
302
+ basePath: '/connect/decision-explainer/action-logs',
303
+ method: 'get',
304
+ body: null,
305
+ urlParams: {},
306
+ queryParams: config.queryParams,
307
+ headers: headers,
308
+ priority: 'normal',
309
+ };
310
+ }
311
+
312
+ var getExplainabilityActionLogs_ConfigPropertyNames = {
313
+ displayName: 'getExplainabilityActionLogs',
314
+ parameters: {
315
+ required: [],
316
+ optional: ['actionContextCode', 'applicationSubType', 'applicationType', 'createdAfter', 'createdBefore', 'pageSize', 'processType', 'queryMore', 'primaryFilter', 'secondaryFilter', 'additionalFilter', 'sortDirection']
317
+ }
318
+ };
319
+ function createResourceParams$1(config) {
320
+ var resourceParams = {
321
+ queryParams: {
322
+ actionContextCode: config.actionContextCode, applicationSubType: config.applicationSubType, applicationType: config.applicationType, createdAfter: config.createdAfter, createdBefore: config.createdBefore, pageSize: config.pageSize, processType: config.processType, queryMore: config.queryMore, primaryFilter: config.primaryFilter, secondaryFilter: config.secondaryFilter, additionalFilter: config.additionalFilter, sortDirection: config.sortDirection
323
+ }
324
+ };
325
+ return resourceParams;
326
+ }
327
+ function keyBuilder$1(luvio, config) {
328
+ var resourceParams = createResourceParams$1(config);
329
+ return keyBuilder$2(luvio, resourceParams);
330
+ }
331
+ function typeCheckConfig$1(untrustedConfig) {
332
+ var config = {};
333
+ var untrustedConfig_actionContextCode = untrustedConfig.actionContextCode;
334
+ if (typeof untrustedConfig_actionContextCode === 'string') {
335
+ config.actionContextCode = untrustedConfig_actionContextCode;
336
+ }
337
+ var untrustedConfig_applicationSubType = untrustedConfig.applicationSubType;
338
+ if (typeof untrustedConfig_applicationSubType === 'string') {
339
+ config.applicationSubType = untrustedConfig_applicationSubType;
340
+ }
341
+ var untrustedConfig_applicationType = untrustedConfig.applicationType;
342
+ if (typeof untrustedConfig_applicationType === 'string') {
343
+ config.applicationType = untrustedConfig_applicationType;
344
+ }
345
+ var untrustedConfig_createdAfter = untrustedConfig.createdAfter;
346
+ if (typeof untrustedConfig_createdAfter === 'string') {
347
+ config.createdAfter = untrustedConfig_createdAfter;
348
+ }
349
+ var untrustedConfig_createdBefore = untrustedConfig.createdBefore;
350
+ if (typeof untrustedConfig_createdBefore === 'string') {
351
+ config.createdBefore = untrustedConfig_createdBefore;
352
+ }
353
+ var untrustedConfig_pageSize = untrustedConfig.pageSize;
354
+ if (typeof untrustedConfig_pageSize === 'number' && Math.floor(untrustedConfig_pageSize) === untrustedConfig_pageSize) {
355
+ config.pageSize = untrustedConfig_pageSize;
356
+ }
357
+ var untrustedConfig_processType = untrustedConfig.processType;
358
+ if (typeof untrustedConfig_processType === 'string') {
359
+ config.processType = untrustedConfig_processType;
360
+ }
361
+ var untrustedConfig_queryMore = untrustedConfig.queryMore;
362
+ if (typeof untrustedConfig_queryMore === 'string') {
363
+ config.queryMore = untrustedConfig_queryMore;
364
+ }
365
+ var untrustedConfig_primaryFilter = untrustedConfig.primaryFilter;
366
+ if (typeof untrustedConfig_primaryFilter === 'string') {
367
+ config.primaryFilter = untrustedConfig_primaryFilter;
368
+ }
369
+ var untrustedConfig_secondaryFilter = untrustedConfig.secondaryFilter;
370
+ if (typeof untrustedConfig_secondaryFilter === 'string') {
371
+ config.secondaryFilter = untrustedConfig_secondaryFilter;
372
+ }
373
+ var untrustedConfig_additionalFilter = untrustedConfig.additionalFilter;
374
+ if (typeof untrustedConfig_additionalFilter === 'string') {
375
+ config.additionalFilter = untrustedConfig_additionalFilter;
376
+ }
377
+ var untrustedConfig_sortDirection = untrustedConfig.sortDirection;
378
+ if (typeof untrustedConfig_sortDirection === 'string') {
379
+ config.sortDirection = untrustedConfig_sortDirection;
380
+ }
381
+ return config;
382
+ }
383
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
384
+ if (!untrustedIsObject(untrustedConfig)) {
385
+ return null;
386
+ }
387
+ if (process.env.NODE_ENV !== 'production') {
388
+ validateConfig(untrustedConfig, configPropertyNames);
389
+ }
390
+ var config = typeCheckConfig$1(untrustedConfig);
391
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
392
+ return null;
393
+ }
394
+ return config;
395
+ }
396
+ function adapterFragment(luvio, config) {
397
+ createResourceParams$1(config);
398
+ return select$2();
399
+ }
400
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
401
+ var snapshot = ingestSuccess$1(luvio, resourceParams, response, {
402
+ config: config,
403
+ resolve: function () { return buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions); }
404
+ });
405
+ return luvio.storeBroadcast().then(function () { return snapshot; });
406
+ }
407
+ function onFetchResponseError(luvio, config, resourceParams, response) {
408
+ var snapshot = ingestError(luvio, resourceParams, response, {
409
+ config: config,
410
+ resolve: function () { return buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions); }
411
+ });
412
+ return luvio.storeBroadcast().then(function () { return snapshot; });
413
+ }
414
+ function buildNetworkSnapshot$1(luvio, config, options) {
415
+ var resourceParams = createResourceParams$1(config);
416
+ var request = createResourceRequest$1(resourceParams);
417
+ return luvio.dispatchResourceRequest(request, options)
418
+ .then(function (response) {
419
+ return luvio.handleSuccessResponse(function () { return onFetchResponseSuccess(luvio, config, resourceParams, response); }, function () { return getResponseCacheKeys$1(luvio, resourceParams, response.body); });
420
+ }, function (response) {
421
+ return luvio.handleErrorResponse(function () { return onFetchResponseError(luvio, config, resourceParams, response); });
422
+ });
423
+ }
424
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
425
+ var luvio = context.luvio, config = context.config;
426
+ var networkPriority = coercedAdapterRequestContext.networkPriority, requestCorrelator = coercedAdapterRequestContext.requestCorrelator, eventObservers = coercedAdapterRequestContext.eventObservers;
427
+ var dispatchOptions = {
428
+ resourceRequestContext: {
429
+ requestCorrelator: requestCorrelator,
430
+ luvioRequestMethod: undefined,
431
+ },
432
+ eventObservers: eventObservers
433
+ };
434
+ if (networkPriority !== 'normal') {
435
+ dispatchOptions.overrides = {
436
+ priority: networkPriority
437
+ };
438
+ }
439
+ return buildNetworkSnapshot$1(luvio, config, dispatchOptions);
440
+ }
441
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
442
+ var luvio = context.luvio, config = context.config;
443
+ var selector = {
444
+ recordId: keyBuilder$1(luvio, config),
445
+ node: adapterFragment(luvio, config),
446
+ variables: {},
447
+ };
448
+ var cacheSnapshot = storeLookup(selector, {
449
+ config: config,
450
+ resolve: function () { return buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions); }
451
+ });
452
+ return cacheSnapshot;
453
+ }
454
+ var getExplainabilityActionLogsAdapterFactory = function (luvio) { return function explainability__getExplainabilityActionLogs(untrustedConfig, requestContext) {
455
+ var config = validateAdapterConfig$1(untrustedConfig, getExplainabilityActionLogs_ConfigPropertyNames);
456
+ // Invalid or incomplete config
457
+ if (config === null) {
458
+ return null;
459
+ }
460
+ return luvio.applyCachePolicy((requestContext || {}), { config: config, luvio: luvio }, // BuildSnapshotContext
461
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
462
+ }; };
463
+
464
+ function validate$1(obj, path) {
465
+ if (path === void 0) { path = 'ExplainabilityActionLogInputRepresentation'; }
466
+ var v_error = (function () {
467
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
468
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
469
+ }
470
+ var obj_actionContextCode = obj.actionContextCode;
471
+ var path_actionContextCode = path + '.actionContextCode';
472
+ if (typeof obj_actionContextCode !== 'string') {
473
+ return new TypeError('Expected "string" but received "' + typeof obj_actionContextCode + '" (at "' + path_actionContextCode + '")');
474
+ }
475
+ var obj_actionLog = obj.actionLog;
476
+ var path_actionLog = path + '.actionLog';
477
+ if (typeof obj_actionLog !== 'string') {
478
+ return new TypeError('Expected "string" but received "' + typeof obj_actionLog + '" (at "' + path_actionLog + '")');
479
+ }
480
+ var obj_actionLogDate = obj.actionLogDate;
481
+ var path_actionLogDate = path + '.actionLogDate';
482
+ if (typeof obj_actionLogDate !== 'string') {
483
+ return new TypeError('Expected "string" but received "' + typeof obj_actionLogDate + '" (at "' + path_actionLogDate + '")');
484
+ }
485
+ if (obj.actionLogOwnerId !== undefined) {
486
+ var obj_actionLogOwnerId = obj.actionLogOwnerId;
487
+ var path_actionLogOwnerId = path + '.actionLogOwnerId';
488
+ if (typeof obj_actionLogOwnerId !== 'string') {
489
+ return new TypeError('Expected "string" but received "' + typeof obj_actionLogOwnerId + '" (at "' + path_actionLogOwnerId + '")');
490
+ }
491
+ }
492
+ if (obj.additionalFilter !== undefined) {
493
+ var obj_additionalFilter = obj.additionalFilter;
494
+ var path_additionalFilter = path + '.additionalFilter';
495
+ if (typeof obj_additionalFilter !== 'string') {
496
+ return new TypeError('Expected "string" but received "' + typeof obj_additionalFilter + '" (at "' + path_additionalFilter + '")');
497
+ }
498
+ }
499
+ if (obj.name !== undefined) {
500
+ var obj_name = obj.name;
501
+ var path_name = path + '.name';
502
+ if (typeof obj_name !== 'string') {
503
+ return new TypeError('Expected "string" but received "' + typeof obj_name + '" (at "' + path_name + '")');
504
+ }
505
+ }
506
+ if (obj.primaryFilter !== undefined) {
507
+ var obj_primaryFilter = obj.primaryFilter;
508
+ var path_primaryFilter = path + '.primaryFilter';
509
+ if (typeof obj_primaryFilter !== 'string') {
510
+ return new TypeError('Expected "string" but received "' + typeof obj_primaryFilter + '" (at "' + path_primaryFilter + '")');
511
+ }
512
+ }
513
+ if (obj.secondaryFilter !== undefined) {
514
+ var obj_secondaryFilter = obj.secondaryFilter;
515
+ var path_secondaryFilter = path + '.secondaryFilter';
516
+ if (typeof obj_secondaryFilter !== 'string') {
517
+ return new TypeError('Expected "string" but received "' + typeof obj_secondaryFilter + '" (at "' + path_secondaryFilter + '")');
518
+ }
519
+ }
520
+ var obj_specificationName = obj.specificationName;
521
+ var path_specificationName = path + '.specificationName';
522
+ if (typeof obj_specificationName !== 'string') {
523
+ return new TypeError('Expected "string" but received "' + typeof obj_specificationName + '" (at "' + path_specificationName + '")');
524
+ }
525
+ })();
526
+ return v_error === undefined ? null : v_error;
527
+ }
528
+
529
+ var TTL = 10000;
530
+ var VERSION = "0d45c6e4f0bafbddf9b0c6a50f5e1a25";
531
+ function validate(obj, path) {
532
+ if (path === void 0) { path = 'ExplainabilityActionLogCreateRepresentation'; }
533
+ var v_error = (function () {
534
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
535
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
536
+ }
537
+ if (obj.sequenceNumber !== undefined) {
538
+ var obj_sequenceNumber = obj.sequenceNumber;
539
+ var path_sequenceNumber = path + '.sequenceNumber';
540
+ if (typeof obj_sequenceNumber !== 'number' || (typeof obj_sequenceNumber === 'number' && Math.floor(obj_sequenceNumber) !== obj_sequenceNumber)) {
541
+ return new TypeError('Expected "integer" but received "' + typeof obj_sequenceNumber + '" (at "' + path_sequenceNumber + '")');
542
+ }
543
+ }
544
+ var obj_uniqueIdentifier = obj.uniqueIdentifier;
545
+ var path_uniqueIdentifier = path + '.uniqueIdentifier';
546
+ if (typeof obj_uniqueIdentifier !== 'string') {
547
+ return new TypeError('Expected "string" but received "' + typeof obj_uniqueIdentifier + '" (at "' + path_uniqueIdentifier + '")');
548
+ }
549
+ })();
550
+ return v_error === undefined ? null : v_error;
551
+ }
552
+ var RepresentationType = 'ExplainabilityActionLogCreateRepresentation';
553
+ function keyBuilder(luvio, config) {
554
+ return keyPrefix + '::' + RepresentationType + ':' + config.id;
555
+ }
556
+ function keyBuilderFromType(luvio, object) {
557
+ var keyParams = {
558
+ id: object.uniqueIdentifier
559
+ };
560
+ return keyBuilder(luvio, keyParams);
561
+ }
562
+ function normalize(input, existing, path, luvio, store, timestamp) {
563
+ return input;
564
+ }
565
+ var select$1 = function ExplainabilityActionLogCreateRepresentationSelect() {
566
+ return {
567
+ kind: 'Fragment',
568
+ version: VERSION,
569
+ private: [],
570
+ opaque: true
571
+ };
572
+ };
573
+ function equals(existing, incoming) {
574
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
575
+ return false;
576
+ }
577
+ return true;
578
+ }
579
+ function deepFreeze(input) {
580
+ ObjectFreeze(input);
581
+ }
582
+ var ingest = function ExplainabilityActionLogCreateRepresentationIngest(input, path, luvio, store, timestamp) {
583
+ if (process.env.NODE_ENV !== 'production') {
584
+ var validateError = validate(input);
585
+ if (validateError !== null) {
586
+ throw validateError;
587
+ }
588
+ }
589
+ var key = keyBuilderFromType(luvio, input);
590
+ var existingRecord = store.readEntry(key);
591
+ var ttlToUse = TTL;
592
+ var incomingRecord = normalize(input, store.readEntry(key), {
593
+ fullPath: key,
594
+ parent: path.parent,
595
+ propertyName: path.propertyName,
596
+ ttl: ttlToUse
597
+ });
598
+ deepFreeze(input);
599
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
600
+ luvio.storePublish(key, incomingRecord);
601
+ }
602
+ {
603
+ var storeMetadataParams = {
604
+ ttl: ttlToUse,
605
+ namespace: "explainability",
606
+ version: VERSION,
607
+ representationName: RepresentationType,
608
+ };
609
+ luvio.publishStoreMetadata(key, storeMetadataParams);
610
+ }
611
+ return createLink(key);
612
+ };
613
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
614
+ var rootKeySet = new engine.StoreKeyMap();
615
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
616
+ var rootKey = keyBuilderFromType(luvio, input);
617
+ rootKeySet.set(rootKey, {
618
+ namespace: keyPrefix,
619
+ representationName: RepresentationType,
620
+ mergeable: false
621
+ });
622
+ return rootKeySet;
623
+ }
624
+
625
+ function select(luvio, params) {
626
+ return select$1();
627
+ }
628
+ function getResponseCacheKeys(luvio, resourceParams, response) {
629
+ return getTypeCacheKeys(luvio, response);
630
+ }
631
+ function ingestSuccess(luvio, resourceParams, response) {
632
+ var body = response.body;
633
+ var key = keyBuilderFromType(luvio, body);
634
+ luvio.storeIngest(key, ingest, body);
635
+ var snapshot = luvio.storeLookup({
636
+ recordId: key,
637
+ node: select(),
638
+ variables: {},
639
+ });
640
+ if (process.env.NODE_ENV !== 'production') {
641
+ if (snapshot.state !== 'Fulfilled') {
642
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
643
+ }
644
+ }
645
+ return snapshot;
646
+ }
647
+ function createResourceRequest(config) {
648
+ var headers = {};
649
+ return {
650
+ baseUri: '/services/data/v58.0',
651
+ basePath: '/connect/decision-explainer/action-logs',
652
+ method: 'post',
653
+ body: config.body,
654
+ urlParams: {},
655
+ queryParams: {},
656
+ headers: headers,
657
+ priority: 'normal',
658
+ };
659
+ }
660
+
661
+ var storeExplainabilityActionLog_ConfigPropertyNames = {
662
+ displayName: 'storeExplainabilityActionLog',
663
+ parameters: {
664
+ required: ['explainabilityActionLogDefinition'],
665
+ optional: []
666
+ }
667
+ };
668
+ function createResourceParams(config) {
669
+ var resourceParams = {
670
+ body: {
671
+ explainabilityActionLogDefinition: config.explainabilityActionLogDefinition
672
+ }
673
+ };
674
+ return resourceParams;
675
+ }
676
+ function typeCheckConfig(untrustedConfig) {
677
+ var config = {};
678
+ var untrustedConfig_explainabilityActionLogDefinition = untrustedConfig.explainabilityActionLogDefinition;
679
+ var referenceExplainabilityActionLogInputRepresentationValidationError = validate$1(untrustedConfig_explainabilityActionLogDefinition);
680
+ if (referenceExplainabilityActionLogInputRepresentationValidationError === null) {
681
+ config.explainabilityActionLogDefinition = untrustedConfig_explainabilityActionLogDefinition;
682
+ }
683
+ return config;
684
+ }
685
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
686
+ if (!untrustedIsObject(untrustedConfig)) {
687
+ return null;
688
+ }
689
+ if (process.env.NODE_ENV !== 'production') {
690
+ validateConfig(untrustedConfig, configPropertyNames);
691
+ }
692
+ var config = typeCheckConfig(untrustedConfig);
693
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
694
+ return null;
695
+ }
696
+ return config;
697
+ }
698
+ function buildNetworkSnapshot(luvio, config, options) {
699
+ var resourceParams = createResourceParams(config);
700
+ var request = createResourceRequest(resourceParams);
701
+ return luvio.dispatchResourceRequest(request, options)
702
+ .then(function (response) {
703
+ return luvio.handleSuccessResponse(function () {
704
+ var snapshot = ingestSuccess(luvio, resourceParams, response);
705
+ return luvio.storeBroadcast().then(function () { return snapshot; });
706
+ }, function () { return getResponseCacheKeys(luvio, resourceParams, response.body); });
707
+ }, function (response) {
708
+ deepFreeze$3(response);
709
+ throw response;
710
+ });
711
+ }
712
+ var storeExplainabilityActionLogAdapterFactory = function (luvio) {
713
+ return function storeExplainabilityActionLog(untrustedConfig) {
714
+ var config = validateAdapterConfig(untrustedConfig, storeExplainabilityActionLog_ConfigPropertyNames);
715
+ // Invalid or incomplete config
716
+ if (config === null) {
717
+ throw new Error('Invalid config for "storeExplainabilityActionLog"');
718
+ }
719
+ return buildNetworkSnapshot(luvio, config);
720
+ };
721
+ };
722
+
723
+ exports.getExplainabilityActionLogsAdapterFactory = getExplainabilityActionLogsAdapterFactory;
724
+ exports.storeExplainabilityActionLogAdapterFactory = storeExplainabilityActionLogAdapterFactory;
725
+
726
+ Object.defineProperty(exports, '__esModule', { value: true });
727
+
728
+ }));