@salesforce/lds-adapters-sales-evfsdk 0.1.0-dev1

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,751 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ import { serializeStructuredKey, ingestShape, deepFreeze, StoreKeyMap, createResourceParams as createResourceParams$2, typeCheckConfig as typeCheckConfig$2, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$1 } from '@luvio/engine';
8
+
9
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
+ const { keys: ObjectKeys, create: ObjectCreate } = Object;
11
+ const { isArray: ArrayIsArray$1 } = Array;
12
+ /**
13
+ * Validates an adapter config is well-formed.
14
+ * @param config The config to validate.
15
+ * @param adapter The adapter validation configuration.
16
+ * @param oneOf The keys the config must contain at least one of.
17
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
18
+ */
19
+ function validateConfig(config, adapter, oneOf) {
20
+ const { displayName } = adapter;
21
+ const { required, optional, unsupported } = adapter.parameters;
22
+ if (config === undefined ||
23
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
24
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
25
+ }
26
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
27
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
28
+ }
29
+ if (unsupported !== undefined &&
30
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
31
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
32
+ }
33
+ const supported = required.concat(optional);
34
+ if (ObjectKeys(config).some(key => !supported.includes(key))) {
35
+ throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
36
+ }
37
+ }
38
+ function untrustedIsObject(untrusted) {
39
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
40
+ }
41
+ function areRequiredParametersPresent(config, configPropertyNames) {
42
+ return configPropertyNames.parameters.required.every(req => req in config);
43
+ }
44
+ const snapshotRefreshOptions = {
45
+ overrides: {
46
+ headers: {
47
+ 'Cache-Control': 'no-cache',
48
+ },
49
+ }
50
+ };
51
+ function generateParamConfigMetadata(name, required, resourceType, typeCheckShape, isArrayShape = false, coerceFn) {
52
+ return {
53
+ name,
54
+ required,
55
+ resourceType,
56
+ typeCheckShape,
57
+ isArrayShape,
58
+ coerceFn,
59
+ };
60
+ }
61
+ function buildAdapterValidationConfig(displayName, paramsMeta) {
62
+ const required = paramsMeta.filter(p => p.required).map(p => p.name);
63
+ const optional = paramsMeta.filter(p => !p.required).map(p => p.name);
64
+ return {
65
+ displayName,
66
+ parameters: {
67
+ required,
68
+ optional,
69
+ }
70
+ };
71
+ }
72
+ const keyPrefix = 'evfSdk';
73
+
74
+ const { isArray: ArrayIsArray } = Array;
75
+ function equalsArray(a, b, equalsItem) {
76
+ const aLength = a.length;
77
+ const bLength = b.length;
78
+ if (aLength !== bLength) {
79
+ return false;
80
+ }
81
+ for (let i = 0; i < aLength; i++) {
82
+ if (equalsItem(a[i], b[i]) === false) {
83
+ return false;
84
+ }
85
+ }
86
+ return true;
87
+ }
88
+ function createLink(ref) {
89
+ return {
90
+ __ref: serializeStructuredKey(ref),
91
+ };
92
+ }
93
+
94
+ function validate$3(obj, path = 'ContextualDataInput') {
95
+ const v_error = (() => {
96
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
97
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
98
+ }
99
+ if (obj.clientSession !== undefined) {
100
+ const obj_clientSession = obj.clientSession;
101
+ const path_clientSession = path + '.clientSession';
102
+ let obj_clientSession_union0 = null;
103
+ const obj_clientSession_union0_error = (() => {
104
+ if (typeof obj_clientSession !== 'string') {
105
+ return new TypeError('Expected "string" but received "' + typeof obj_clientSession + '" (at "' + path_clientSession + '")');
106
+ }
107
+ })();
108
+ if (obj_clientSession_union0_error != null) {
109
+ obj_clientSession_union0 = obj_clientSession_union0_error.message;
110
+ }
111
+ let obj_clientSession_union1 = null;
112
+ const obj_clientSession_union1_error = (() => {
113
+ if (obj_clientSession !== null) {
114
+ return new TypeError('Expected "null" but received "' + typeof obj_clientSession + '" (at "' + path_clientSession + '")');
115
+ }
116
+ })();
117
+ if (obj_clientSession_union1_error != null) {
118
+ obj_clientSession_union1 = obj_clientSession_union1_error.message;
119
+ }
120
+ if (obj_clientSession_union0 && obj_clientSession_union1) {
121
+ let message = 'Object doesn\'t match union (at "' + path_clientSession + '")';
122
+ message += '\n' + obj_clientSession_union0.split('\n').map((line) => '\t' + line).join('\n');
123
+ message += '\n' + obj_clientSession_union1.split('\n').map((line) => '\t' + line).join('\n');
124
+ return new TypeError(message);
125
+ }
126
+ }
127
+ if (obj.entity !== undefined) {
128
+ const obj_entity = obj.entity;
129
+ const path_entity = path + '.entity';
130
+ let obj_entity_union0 = null;
131
+ const obj_entity_union0_error = (() => {
132
+ if (typeof obj_entity !== 'string') {
133
+ return new TypeError('Expected "string" but received "' + typeof obj_entity + '" (at "' + path_entity + '")');
134
+ }
135
+ })();
136
+ if (obj_entity_union0_error != null) {
137
+ obj_entity_union0 = obj_entity_union0_error.message;
138
+ }
139
+ let obj_entity_union1 = null;
140
+ const obj_entity_union1_error = (() => {
141
+ if (obj_entity !== null) {
142
+ return new TypeError('Expected "null" but received "' + typeof obj_entity + '" (at "' + path_entity + '")');
143
+ }
144
+ })();
145
+ if (obj_entity_union1_error != null) {
146
+ obj_entity_union1 = obj_entity_union1_error.message;
147
+ }
148
+ if (obj_entity_union0 && obj_entity_union1) {
149
+ let message = 'Object doesn\'t match union (at "' + path_entity + '")';
150
+ message += '\n' + obj_entity_union0.split('\n').map((line) => '\t' + line).join('\n');
151
+ message += '\n' + obj_entity_union1.split('\n').map((line) => '\t' + line).join('\n');
152
+ return new TypeError(message);
153
+ }
154
+ }
155
+ if (obj.entityType !== undefined) {
156
+ const obj_entityType = obj.entityType;
157
+ const path_entityType = path + '.entityType';
158
+ let obj_entityType_union0 = null;
159
+ const obj_entityType_union0_error = (() => {
160
+ if (typeof obj_entityType !== 'string') {
161
+ return new TypeError('Expected "string" but received "' + typeof obj_entityType + '" (at "' + path_entityType + '")');
162
+ }
163
+ })();
164
+ if (obj_entityType_union0_error != null) {
165
+ obj_entityType_union0 = obj_entityType_union0_error.message;
166
+ }
167
+ let obj_entityType_union1 = null;
168
+ const obj_entityType_union1_error = (() => {
169
+ if (obj_entityType !== null) {
170
+ return new TypeError('Expected "null" but received "' + typeof obj_entityType + '" (at "' + path_entityType + '")');
171
+ }
172
+ })();
173
+ if (obj_entityType_union1_error != null) {
174
+ obj_entityType_union1 = obj_entityType_union1_error.message;
175
+ }
176
+ if (obj_entityType_union0 && obj_entityType_union1) {
177
+ let message = 'Object doesn\'t match union (at "' + path_entityType + '")';
178
+ message += '\n' + obj_entityType_union0.split('\n').map((line) => '\t' + line).join('\n');
179
+ message += '\n' + obj_entityType_union1.split('\n').map((line) => '\t' + line).join('\n');
180
+ return new TypeError(message);
181
+ }
182
+ }
183
+ if (obj.loggedAt !== undefined) {
184
+ obj.loggedAt;
185
+ }
186
+ if (obj.loggerAppName !== undefined) {
187
+ const obj_loggerAppName = obj.loggerAppName;
188
+ const path_loggerAppName = path + '.loggerAppName';
189
+ let obj_loggerAppName_union0 = null;
190
+ const obj_loggerAppName_union0_error = (() => {
191
+ if (typeof obj_loggerAppName !== 'string') {
192
+ return new TypeError('Expected "string" but received "' + typeof obj_loggerAppName + '" (at "' + path_loggerAppName + '")');
193
+ }
194
+ })();
195
+ if (obj_loggerAppName_union0_error != null) {
196
+ obj_loggerAppName_union0 = obj_loggerAppName_union0_error.message;
197
+ }
198
+ let obj_loggerAppName_union1 = null;
199
+ const obj_loggerAppName_union1_error = (() => {
200
+ if (obj_loggerAppName !== null) {
201
+ return new TypeError('Expected "null" but received "' + typeof obj_loggerAppName + '" (at "' + path_loggerAppName + '")');
202
+ }
203
+ })();
204
+ if (obj_loggerAppName_union1_error != null) {
205
+ obj_loggerAppName_union1 = obj_loggerAppName_union1_error.message;
206
+ }
207
+ if (obj_loggerAppName_union0 && obj_loggerAppName_union1) {
208
+ let message = 'Object doesn\'t match union (at "' + path_loggerAppName + '")';
209
+ message += '\n' + obj_loggerAppName_union0.split('\n').map((line) => '\t' + line).join('\n');
210
+ message += '\n' + obj_loggerAppName_union1.split('\n').map((line) => '\t' + line).join('\n');
211
+ return new TypeError(message);
212
+ }
213
+ }
214
+ if (obj.loggerName !== undefined) {
215
+ const obj_loggerName = obj.loggerName;
216
+ const path_loggerName = path + '.loggerName';
217
+ let obj_loggerName_union0 = null;
218
+ const obj_loggerName_union0_error = (() => {
219
+ if (typeof obj_loggerName !== 'string') {
220
+ return new TypeError('Expected "string" but received "' + typeof obj_loggerName + '" (at "' + path_loggerName + '")');
221
+ }
222
+ })();
223
+ if (obj_loggerName_union0_error != null) {
224
+ obj_loggerName_union0 = obj_loggerName_union0_error.message;
225
+ }
226
+ let obj_loggerName_union1 = null;
227
+ const obj_loggerName_union1_error = (() => {
228
+ if (obj_loggerName !== null) {
229
+ return new TypeError('Expected "null" but received "' + typeof obj_loggerName + '" (at "' + path_loggerName + '")');
230
+ }
231
+ })();
232
+ if (obj_loggerName_union1_error != null) {
233
+ obj_loggerName_union1 = obj_loggerName_union1_error.message;
234
+ }
235
+ if (obj_loggerName_union0 && obj_loggerName_union1) {
236
+ let message = 'Object doesn\'t match union (at "' + path_loggerName + '")';
237
+ message += '\n' + obj_loggerName_union0.split('\n').map((line) => '\t' + line).join('\n');
238
+ message += '\n' + obj_loggerName_union1.split('\n').map((line) => '\t' + line).join('\n');
239
+ return new TypeError(message);
240
+ }
241
+ }
242
+ if (obj.pageContext !== undefined) {
243
+ const obj_pageContext = obj.pageContext;
244
+ const path_pageContext = path + '.pageContext';
245
+ let obj_pageContext_union0 = null;
246
+ const obj_pageContext_union0_error = (() => {
247
+ if (typeof obj_pageContext !== 'string') {
248
+ return new TypeError('Expected "string" but received "' + typeof obj_pageContext + '" (at "' + path_pageContext + '")');
249
+ }
250
+ })();
251
+ if (obj_pageContext_union0_error != null) {
252
+ obj_pageContext_union0 = obj_pageContext_union0_error.message;
253
+ }
254
+ let obj_pageContext_union1 = null;
255
+ const obj_pageContext_union1_error = (() => {
256
+ if (obj_pageContext !== null) {
257
+ return new TypeError('Expected "null" but received "' + typeof obj_pageContext + '" (at "' + path_pageContext + '")');
258
+ }
259
+ })();
260
+ if (obj_pageContext_union1_error != null) {
261
+ obj_pageContext_union1 = obj_pageContext_union1_error.message;
262
+ }
263
+ if (obj_pageContext_union0 && obj_pageContext_union1) {
264
+ let message = 'Object doesn\'t match union (at "' + path_pageContext + '")';
265
+ message += '\n' + obj_pageContext_union0.split('\n').map((line) => '\t' + line).join('\n');
266
+ message += '\n' + obj_pageContext_union1.split('\n').map((line) => '\t' + line).join('\n');
267
+ return new TypeError(message);
268
+ }
269
+ }
270
+ if (obj.pageUrl !== undefined) {
271
+ const obj_pageUrl = obj.pageUrl;
272
+ const path_pageUrl = path + '.pageUrl';
273
+ let obj_pageUrl_union0 = null;
274
+ const obj_pageUrl_union0_error = (() => {
275
+ if (typeof obj_pageUrl !== 'string') {
276
+ return new TypeError('Expected "string" but received "' + typeof obj_pageUrl + '" (at "' + path_pageUrl + '")');
277
+ }
278
+ })();
279
+ if (obj_pageUrl_union0_error != null) {
280
+ obj_pageUrl_union0 = obj_pageUrl_union0_error.message;
281
+ }
282
+ let obj_pageUrl_union1 = null;
283
+ const obj_pageUrl_union1_error = (() => {
284
+ if (obj_pageUrl !== null) {
285
+ return new TypeError('Expected "null" but received "' + typeof obj_pageUrl + '" (at "' + path_pageUrl + '")');
286
+ }
287
+ })();
288
+ if (obj_pageUrl_union1_error != null) {
289
+ obj_pageUrl_union1 = obj_pageUrl_union1_error.message;
290
+ }
291
+ if (obj_pageUrl_union0 && obj_pageUrl_union1) {
292
+ let message = 'Object doesn\'t match union (at "' + path_pageUrl + '")';
293
+ message += '\n' + obj_pageUrl_union0.split('\n').map((line) => '\t' + line).join('\n');
294
+ message += '\n' + obj_pageUrl_union1.split('\n').map((line) => '\t' + line).join('\n');
295
+ return new TypeError(message);
296
+ }
297
+ }
298
+ })();
299
+ return v_error === undefined ? null : v_error;
300
+ }
301
+
302
+ const VERSION$2 = "6cd59f422d42dae130829d614e96fd00";
303
+ function validate$2(obj, path = 'ResponseStatus') {
304
+ const v_error = (() => {
305
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
306
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
307
+ }
308
+ const obj_code = obj.code;
309
+ const path_code = path + '.code';
310
+ if (typeof obj_code !== 'string') {
311
+ return new TypeError('Expected "string" but received "' + typeof obj_code + '" (at "' + path_code + '")');
312
+ }
313
+ const obj_message = obj.message;
314
+ const path_message = path + '.message';
315
+ if (typeof obj_message !== 'string') {
316
+ return new TypeError('Expected "string" but received "' + typeof obj_message + '" (at "' + path_message + '")');
317
+ }
318
+ })();
319
+ return v_error === undefined ? null : v_error;
320
+ }
321
+ const select$4 = function ResponseStatusSelect() {
322
+ return {
323
+ kind: 'Fragment',
324
+ version: VERSION$2,
325
+ private: [],
326
+ selections: [
327
+ {
328
+ name: 'code',
329
+ kind: 'Scalar'
330
+ },
331
+ {
332
+ name: 'message',
333
+ kind: 'Scalar'
334
+ }
335
+ ]
336
+ };
337
+ };
338
+ function equals$2(existing, incoming) {
339
+ const existing_code = existing.code;
340
+ const incoming_code = incoming.code;
341
+ if (!(existing_code === incoming_code)) {
342
+ return false;
343
+ }
344
+ const existing_message = existing.message;
345
+ const incoming_message = incoming.message;
346
+ if (!(existing_message === incoming_message)) {
347
+ return false;
348
+ }
349
+ return true;
350
+ }
351
+
352
+ const VERSION$1 = "8e3c59d1edb1e360b97a3a87ead05a6e";
353
+ function validate$1(obj, path = 'PublishEventOutput') {
354
+ const v_error = (() => {
355
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
356
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
357
+ }
358
+ const obj_status = obj.status;
359
+ const path_status = path + '.status';
360
+ const referencepath_statusValidationError = validate$2(obj_status, path_status);
361
+ if (referencepath_statusValidationError !== null) {
362
+ let message = 'Object doesn\'t match ResponseStatus (at "' + path_status + '")\n';
363
+ message += referencepath_statusValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
364
+ return new TypeError(message);
365
+ }
366
+ })();
367
+ return v_error === undefined ? null : v_error;
368
+ }
369
+ const RepresentationType$1 = 'PublishEventOutput';
370
+ function keyBuilder$2(luvio, config) {
371
+ return keyPrefix + '::' + RepresentationType$1 + ':' + config.id;
372
+ }
373
+ function keyBuilderFromType(luvio, object) {
374
+ const keyParams = {
375
+ id: object.status.message
376
+ };
377
+ return keyBuilder$2(luvio, keyParams);
378
+ }
379
+ function normalize$1(input, existing, path, luvio, store, timestamp) {
380
+ return input;
381
+ }
382
+ const select$3 = function PublishEventOutputSelect() {
383
+ const { selections: ResponseStatus__selections, opaque: ResponseStatus__opaque, } = select$4();
384
+ return {
385
+ kind: 'Fragment',
386
+ version: VERSION$1,
387
+ private: [],
388
+ selections: [
389
+ {
390
+ name: 'status',
391
+ kind: 'Object',
392
+ selections: ResponseStatus__selections
393
+ }
394
+ ]
395
+ };
396
+ };
397
+ function equals$1(existing, incoming) {
398
+ const existing_status = existing.status;
399
+ const incoming_status = incoming.status;
400
+ if (!(equals$2(existing_status, incoming_status))) {
401
+ return false;
402
+ }
403
+ return true;
404
+ }
405
+ const ingest$1 = function PublishEventOutputIngest(input, path, luvio, store, timestamp) {
406
+ if (process.env.NODE_ENV !== 'production') {
407
+ const validateError = validate$1(input);
408
+ if (validateError !== null) {
409
+ throw validateError;
410
+ }
411
+ }
412
+ const key = keyBuilderFromType(luvio, input);
413
+ const ttlToUse = path.ttl !== undefined ? path.ttl : 30000;
414
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$1, "evfSdk", VERSION$1, RepresentationType$1, equals$1);
415
+ return createLink(key);
416
+ };
417
+ function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
418
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
419
+ const rootKey = keyBuilderFromType(luvio, input);
420
+ rootKeySet.set(rootKey, {
421
+ namespace: keyPrefix,
422
+ representationName: RepresentationType$1,
423
+ mergeable: false
424
+ });
425
+ }
426
+
427
+ function select$2(luvio, params) {
428
+ return select$3();
429
+ }
430
+ function getResponseCacheKeys$1(storeKeyMap, luvio, resourceParams, response) {
431
+ getTypeCacheKeys$1(storeKeyMap, luvio, response);
432
+ }
433
+ function ingestSuccess$1(luvio, resourceParams, response) {
434
+ const { body } = response;
435
+ const key = keyBuilderFromType(luvio, body);
436
+ luvio.storeIngest(key, ingest$1, body);
437
+ const snapshot = luvio.storeLookup({
438
+ recordId: key,
439
+ node: select$2(),
440
+ variables: {},
441
+ });
442
+ if (process.env.NODE_ENV !== 'production') {
443
+ if (snapshot.state !== 'Fulfilled') {
444
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
445
+ }
446
+ }
447
+ deepFreeze(snapshot.data);
448
+ return snapshot;
449
+ }
450
+ function createResourceRequest$1(config) {
451
+ const headers = {};
452
+ return {
453
+ baseUri: '/services/data/v66.0',
454
+ basePath: '/connect/evf/sdk/event',
455
+ method: 'post',
456
+ body: config.body,
457
+ urlParams: {},
458
+ queryParams: {},
459
+ headers,
460
+ priority: 'normal',
461
+ };
462
+ }
463
+
464
+ const adapterName$1 = 'publishEvent';
465
+ const publishEvent_ConfigPropertyMetadata = [
466
+ generateParamConfigMetadata('contextualData', false, 2 /* Body */, 4 /* Unsupported */),
467
+ generateParamConfigMetadata('feature', true, 2 /* Body */, 0 /* String */),
468
+ generateParamConfigMetadata('name', true, 2 /* Body */, 0 /* String */),
469
+ generateParamConfigMetadata('score', true, 2 /* Body */, 3 /* Integer */),
470
+ generateParamConfigMetadata('type', true, 2 /* Body */, 0 /* String */),
471
+ ];
472
+ const publishEvent_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, publishEvent_ConfigPropertyMetadata);
473
+ const createResourceParams$1 = /*#__PURE__*/ createResourceParams$2(publishEvent_ConfigPropertyMetadata);
474
+ function typeCheckConfig$1(untrustedConfig) {
475
+ const config = {};
476
+ typeCheckConfig$2(untrustedConfig, config, publishEvent_ConfigPropertyMetadata);
477
+ const untrustedConfig_contextualData = untrustedConfig.contextualData;
478
+ const referenceContextualDataInputValidationError = validate$3(untrustedConfig_contextualData);
479
+ if (referenceContextualDataInputValidationError === null) {
480
+ config.contextualData = untrustedConfig_contextualData;
481
+ }
482
+ if (untrustedConfig_contextualData === null) {
483
+ config.contextualData = untrustedConfig_contextualData;
484
+ }
485
+ return config;
486
+ }
487
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
488
+ if (!untrustedIsObject(untrustedConfig)) {
489
+ return null;
490
+ }
491
+ if (process.env.NODE_ENV !== 'production') {
492
+ validateConfig(untrustedConfig, configPropertyNames);
493
+ }
494
+ const config = typeCheckConfig$1(untrustedConfig);
495
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
496
+ return null;
497
+ }
498
+ return config;
499
+ }
500
+ function buildNetworkSnapshot$1(luvio, config, options) {
501
+ const resourceParams = createResourceParams$1(config);
502
+ const request = createResourceRequest$1(resourceParams);
503
+ return luvio.dispatchResourceRequest(request, options)
504
+ .then((response) => {
505
+ return luvio.handleSuccessResponse(() => {
506
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response);
507
+ return luvio.storeBroadcast().then(() => snapshot);
508
+ }, () => {
509
+ const cache = new StoreKeyMap();
510
+ getResponseCacheKeys$1(cache, luvio, resourceParams, response.body);
511
+ return cache;
512
+ });
513
+ }, (response) => {
514
+ deepFreeze(response);
515
+ throw response;
516
+ });
517
+ }
518
+ const publishEventAdapterFactory = (luvio) => {
519
+ return function publishEvent(untrustedConfig) {
520
+ const config = validateAdapterConfig$1(untrustedConfig, publishEvent_ConfigPropertyNames);
521
+ // Invalid or incomplete config
522
+ if (config === null) {
523
+ throw new Error('Invalid config for "publishEvent"');
524
+ }
525
+ return buildNetworkSnapshot$1(luvio, config);
526
+ };
527
+ };
528
+
529
+ const VERSION = "944b3e6ec30480d518e5f389303c2957";
530
+ function validate(obj, path = 'EventTypesOutput') {
531
+ const v_error = (() => {
532
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
533
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
534
+ }
535
+ const obj_eventTypes = obj.eventTypes;
536
+ const path_eventTypes = path + '.eventTypes';
537
+ if (!ArrayIsArray(obj_eventTypes)) {
538
+ return new TypeError('Expected "array" but received "' + typeof obj_eventTypes + '" (at "' + path_eventTypes + '")');
539
+ }
540
+ for (let i = 0; i < obj_eventTypes.length; i++) {
541
+ const obj_eventTypes_item = obj_eventTypes[i];
542
+ const path_eventTypes_item = path_eventTypes + '[' + i + ']';
543
+ if (typeof obj_eventTypes_item !== 'string') {
544
+ return new TypeError('Expected "string" but received "' + typeof obj_eventTypes_item + '" (at "' + path_eventTypes_item + '")');
545
+ }
546
+ }
547
+ const obj_status = obj.status;
548
+ const path_status = path + '.status';
549
+ const referencepath_statusValidationError = validate$2(obj_status, path_status);
550
+ if (referencepath_statusValidationError !== null) {
551
+ let message = 'Object doesn\'t match ResponseStatus (at "' + path_status + '")\n';
552
+ message += referencepath_statusValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
553
+ return new TypeError(message);
554
+ }
555
+ })();
556
+ return v_error === undefined ? null : v_error;
557
+ }
558
+ const RepresentationType = 'EventTypesOutput';
559
+ function normalize(input, existing, path, luvio, store, timestamp) {
560
+ return input;
561
+ }
562
+ const select$1 = function EventTypesOutputSelect() {
563
+ const { selections: ResponseStatus__selections, opaque: ResponseStatus__opaque, } = select$4();
564
+ return {
565
+ kind: 'Fragment',
566
+ version: VERSION,
567
+ private: [],
568
+ selections: [
569
+ {
570
+ name: 'eventTypes',
571
+ kind: 'Scalar',
572
+ plural: true
573
+ },
574
+ {
575
+ name: 'status',
576
+ kind: 'Object',
577
+ selections: ResponseStatus__selections
578
+ }
579
+ ]
580
+ };
581
+ };
582
+ function equals(existing, incoming) {
583
+ const existing_eventTypes = existing.eventTypes;
584
+ const incoming_eventTypes = incoming.eventTypes;
585
+ const equals_eventTypes_items = equalsArray(existing_eventTypes, incoming_eventTypes, (existing_eventTypes_item, incoming_eventTypes_item) => {
586
+ if (!(existing_eventTypes_item === incoming_eventTypes_item)) {
587
+ return false;
588
+ }
589
+ });
590
+ if (equals_eventTypes_items === false) {
591
+ return false;
592
+ }
593
+ const existing_status = existing.status;
594
+ const incoming_status = incoming.status;
595
+ if (!(equals$2(existing_status, incoming_status))) {
596
+ return false;
597
+ }
598
+ return true;
599
+ }
600
+ const ingest = function EventTypesOutputIngest(input, path, luvio, store, timestamp) {
601
+ if (process.env.NODE_ENV !== 'production') {
602
+ const validateError = validate(input);
603
+ if (validateError !== null) {
604
+ throw validateError;
605
+ }
606
+ }
607
+ const key = path.fullPath;
608
+ const ttlToUse = path.ttl !== undefined ? path.ttl : 30000;
609
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize, "evfSdk", VERSION, RepresentationType, equals);
610
+ return createLink(key);
611
+ };
612
+ function getTypeCacheKeys(rootKeySet, luvio, input, fullPathFactory) {
613
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
614
+ const rootKey = fullPathFactory();
615
+ rootKeySet.set(rootKey, {
616
+ namespace: keyPrefix,
617
+ representationName: RepresentationType,
618
+ mergeable: false
619
+ });
620
+ }
621
+
622
+ function select(luvio, params) {
623
+ return select$1();
624
+ }
625
+ function keyBuilder$1(luvio, params) {
626
+ return keyPrefix + '::EventTypesOutput:(' + ')';
627
+ }
628
+ function getResponseCacheKeys(storeKeyMap, luvio, resourceParams, response) {
629
+ getTypeCacheKeys(storeKeyMap, luvio, response, () => keyBuilder$1());
630
+ }
631
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
632
+ const { body } = response;
633
+ const key = keyBuilder$1();
634
+ luvio.storeIngest(key, ingest, body);
635
+ const snapshot = luvio.storeLookup({
636
+ recordId: key,
637
+ node: select(),
638
+ variables: {},
639
+ }, snapshotRefresh);
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
+ deepFreeze(snapshot.data);
646
+ return snapshot;
647
+ }
648
+ function ingestError(luvio, params, error, snapshotRefresh) {
649
+ const key = keyBuilder$1();
650
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
651
+ luvio.storeIngestError(key, errorSnapshot);
652
+ return errorSnapshot;
653
+ }
654
+ function createResourceRequest(config) {
655
+ const headers = {};
656
+ return {
657
+ baseUri: '/services/data/v66.0',
658
+ basePath: '/connect/evf/sdk/event-types',
659
+ method: 'get',
660
+ body: null,
661
+ urlParams: {},
662
+ queryParams: {},
663
+ headers,
664
+ priority: 'normal',
665
+ };
666
+ }
667
+
668
+ const adapterName = 'getEventTypes';
669
+ const getEventTypes_ConfigPropertyMetadata = [];
670
+ const getEventTypes_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName, getEventTypes_ConfigPropertyMetadata);
671
+ const createResourceParams = /*#__PURE__*/ createResourceParams$2(getEventTypes_ConfigPropertyMetadata);
672
+ function keyBuilder(luvio, config) {
673
+ createResourceParams(config);
674
+ return keyBuilder$1();
675
+ }
676
+ function typeCheckConfig(untrustedConfig) {
677
+ const config = {};
678
+ return config;
679
+ }
680
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
681
+ if (!untrustedIsObject(untrustedConfig)) {
682
+ return null;
683
+ }
684
+ if (process.env.NODE_ENV !== 'production') {
685
+ validateConfig(untrustedConfig, configPropertyNames);
686
+ }
687
+ const config = typeCheckConfig();
688
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
689
+ return null;
690
+ }
691
+ return config;
692
+ }
693
+ function adapterFragment(luvio, config) {
694
+ createResourceParams(config);
695
+ return select();
696
+ }
697
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
698
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
699
+ config,
700
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
701
+ });
702
+ return luvio.storeBroadcast().then(() => snapshot);
703
+ }
704
+ function onFetchResponseError(luvio, config, resourceParams, response) {
705
+ const snapshot = ingestError(luvio, resourceParams, response, {
706
+ config,
707
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
708
+ });
709
+ return luvio.storeBroadcast().then(() => snapshot);
710
+ }
711
+ function buildNetworkSnapshot(luvio, config, options) {
712
+ const resourceParams = createResourceParams(config);
713
+ const request = createResourceRequest();
714
+ return luvio.dispatchResourceRequest(request, options)
715
+ .then((response) => {
716
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => {
717
+ const cache = new StoreKeyMap();
718
+ getResponseCacheKeys(cache, luvio, resourceParams, response.body);
719
+ return cache;
720
+ });
721
+ }, (response) => {
722
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
723
+ });
724
+ }
725
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
726
+ return buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext, buildNetworkSnapshot, undefined, false);
727
+ }
728
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
729
+ const { luvio, config } = context;
730
+ const selector = {
731
+ recordId: keyBuilder(luvio, config),
732
+ node: adapterFragment(luvio, config),
733
+ variables: {},
734
+ };
735
+ const cacheSnapshot = storeLookup(selector, {
736
+ config,
737
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
738
+ });
739
+ return cacheSnapshot;
740
+ }
741
+ const getEventTypesAdapterFactory = (luvio) => function evfSdk__getEventTypes(untrustedConfig, requestContext) {
742
+ const config = validateAdapterConfig(untrustedConfig, getEventTypes_ConfigPropertyNames);
743
+ // Invalid or incomplete config
744
+ if (config === null) {
745
+ return null;
746
+ }
747
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
748
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
749
+ };
750
+
751
+ export { getEventTypesAdapterFactory, publishEventAdapterFactory };