@salesforce/lds-adapters-sfap-einstein-copilot-bot 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.
Files changed (31) hide show
  1. package/LICENSE.txt +82 -0
  2. package/dist/es/es2018/sfap-einstein-copilot-bot.js +1253 -0
  3. package/dist/es/es2018/types/src/generated/adapters/adapter-utils.d.ts +62 -0
  4. package/dist/es/es2018/types/src/generated/adapters/getStatus.d.ts +26 -0
  5. package/dist/es/es2018/types/src/generated/adapters/startSession.d.ts +30 -0
  6. package/dist/es/es2018/types/src/generated/artifacts/main.d.ts +2 -0
  7. package/dist/es/es2018/types/src/generated/artifacts/sfdc.d.ts +4 -0
  8. package/dist/es/es2018/types/src/generated/resources/getEinsteinBotsV1Status.d.ts +12 -0
  9. package/dist/es/es2018/types/src/generated/resources/postEinsteinBotsV1V5.3.0BotsSessionsByBotId.d.ts +31 -0
  10. package/dist/es/es2018/types/src/generated/types/Error.d.ts +43 -0
  11. package/dist/es/es2018/types/src/generated/types/ForceConfig.d.ts +28 -0
  12. package/dist/es/es2018/types/src/generated/types/FormatTypeCapability.d.ts +27 -0
  13. package/dist/es/es2018/types/src/generated/types/HyperLink.d.ts +28 -0
  14. package/dist/es/es2018/types/src/generated/types/InitMessageEnvelope.d.ts +46 -0
  15. package/dist/es/es2018/types/src/generated/types/Links.d.ts +34 -0
  16. package/dist/es/es2018/types/src/generated/types/MessageTypeCapability.d.ts +30 -0
  17. package/dist/es/es2018/types/src/generated/types/NormalizedEntity.d.ts +35 -0
  18. package/dist/es/es2018/types/src/generated/types/NormalizedIntent.d.ts +33 -0
  19. package/dist/es/es2018/types/src/generated/types/Referrer.d.ts +31 -0
  20. package/dist/es/es2018/types/src/generated/types/ResponseEnvelope.d.ts +59 -0
  21. package/dist/es/es2018/types/src/generated/types/ResponseOptions.d.ts +37 -0
  22. package/dist/es/es2018/types/src/generated/types/ResponseOptionsVariables.d.ts +33 -0
  23. package/dist/es/es2018/types/src/generated/types/RichContentCapability.d.ts +28 -0
  24. package/dist/es/es2018/types/src/generated/types/Status.d.ts +28 -0
  25. package/dist/es/es2018/types/src/generated/types/TextInitMessage.d.ts +28 -0
  26. package/dist/es/es2018/types/src/generated/types/type-utils.d.ts +32 -0
  27. package/package.json +66 -0
  28. package/sfdc/index.d.ts +1 -0
  29. package/sfdc/index.js +1290 -0
  30. package/src/raml/api.raml +369 -0
  31. package/src/raml/luvio.raml +25 -0
@@ -0,0 +1,1253 @@
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, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$1, StoreKeyMap, createResourceParams as createResourceParams$2, typeCheckConfig as typeCheckConfig$2 } 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 = 'einstein-copilot-bot';
73
+
74
+ const { isArray: ArrayIsArray } = Array;
75
+ const { stringify: JSONStringify } = JSON;
76
+ function equalsArray(a, b, equalsItem) {
77
+ const aLength = a.length;
78
+ const bLength = b.length;
79
+ if (aLength !== bLength) {
80
+ return false;
81
+ }
82
+ for (let i = 0; i < aLength; i++) {
83
+ if (equalsItem(a[i], b[i]) === false) {
84
+ return false;
85
+ }
86
+ }
87
+ return true;
88
+ }
89
+ function createLink(ref) {
90
+ return {
91
+ __ref: serializeStructuredKey(ref),
92
+ };
93
+ }
94
+
95
+ const VERSION$5 = "2566cf5ff6dcdabe56ad935ec9feba47";
96
+ function validate$d(obj, path = 'Status') {
97
+ const v_error = (() => {
98
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
99
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
100
+ }
101
+ const obj_status = obj.status;
102
+ const path_status = path + '.status';
103
+ if (typeof obj_status !== 'string') {
104
+ return new TypeError('Expected "string" but received "' + typeof obj_status + '" (at "' + path_status + '")');
105
+ }
106
+ })();
107
+ return v_error === undefined ? null : v_error;
108
+ }
109
+ const RepresentationType$1 = 'Status';
110
+ function normalize$1(input, existing, path, luvio, store, timestamp) {
111
+ return input;
112
+ }
113
+ const select$7 = function StatusSelect() {
114
+ return {
115
+ kind: 'Fragment',
116
+ version: VERSION$5,
117
+ private: [],
118
+ selections: [
119
+ {
120
+ name: 'status',
121
+ kind: 'Scalar'
122
+ }
123
+ ]
124
+ };
125
+ };
126
+ function equals$5(existing, incoming) {
127
+ const existing_status = existing.status;
128
+ const incoming_status = incoming.status;
129
+ if (!(existing_status === incoming_status)) {
130
+ return false;
131
+ }
132
+ return true;
133
+ }
134
+ const ingest$1 = function StatusIngest(input, path, luvio, store, timestamp) {
135
+ if (process.env.NODE_ENV !== 'production') {
136
+ const validateError = validate$d(input);
137
+ if (validateError !== null) {
138
+ throw validateError;
139
+ }
140
+ }
141
+ const key = path.fullPath;
142
+ const ttlToUse = path.ttl !== undefined ? path.ttl : 500;
143
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$1, "einstein-copilot-bot", VERSION$5, RepresentationType$1, equals$5);
144
+ return createLink(key);
145
+ };
146
+ function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
147
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
148
+ const rootKey = fullPathFactory();
149
+ rootKeySet.set(rootKey, {
150
+ namespace: keyPrefix,
151
+ representationName: RepresentationType$1,
152
+ mergeable: false
153
+ });
154
+ }
155
+
156
+ function select$6(luvio, params) {
157
+ return select$7();
158
+ }
159
+ function keyBuilder$2(luvio, params) {
160
+ return keyPrefix + '::Status:(' + ')';
161
+ }
162
+ function getResponseCacheKeys$1(storeKeyMap, luvio, resourceParams, response) {
163
+ getTypeCacheKeys$1(storeKeyMap, luvio, response, () => keyBuilder$2());
164
+ }
165
+ function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
166
+ const { body } = response;
167
+ const key = keyBuilder$2();
168
+ luvio.storeIngest(key, ingest$1, body);
169
+ const snapshot = luvio.storeLookup({
170
+ recordId: key,
171
+ node: select$6(),
172
+ variables: {},
173
+ }, snapshotRefresh);
174
+ if (process.env.NODE_ENV !== 'production') {
175
+ if (snapshot.state !== 'Fulfilled') {
176
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
177
+ }
178
+ }
179
+ deepFreeze(snapshot.data);
180
+ return snapshot;
181
+ }
182
+ function ingestError(luvio, params, error, snapshotRefresh) {
183
+ const key = keyBuilder$2();
184
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
185
+ luvio.storeIngestError(key, errorSnapshot);
186
+ return errorSnapshot;
187
+ }
188
+ function createResourceRequest$1(config) {
189
+ const headers = {};
190
+ return {
191
+ baseUri: 'api.salesforce.com',
192
+ basePath: '/einstein/bots/v1/status',
193
+ method: 'get',
194
+ body: null,
195
+ urlParams: {},
196
+ queryParams: {},
197
+ headers,
198
+ priority: 'normal',
199
+ };
200
+ }
201
+
202
+ const adapterName$1 = 'getStatus';
203
+ const getStatus_ConfigPropertyMetadata = [];
204
+ const getStatus_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, getStatus_ConfigPropertyMetadata);
205
+ const createResourceParams$1 = /*#__PURE__*/ createResourceParams$2(getStatus_ConfigPropertyMetadata);
206
+ function keyBuilder$1(luvio, config) {
207
+ createResourceParams$1(config);
208
+ return keyBuilder$2();
209
+ }
210
+ function typeCheckConfig$1(untrustedConfig) {
211
+ const config = {};
212
+ return config;
213
+ }
214
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
215
+ if (!untrustedIsObject(untrustedConfig)) {
216
+ return null;
217
+ }
218
+ if (process.env.NODE_ENV !== 'production') {
219
+ validateConfig(untrustedConfig, configPropertyNames);
220
+ }
221
+ const config = typeCheckConfig$1();
222
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
223
+ return null;
224
+ }
225
+ return config;
226
+ }
227
+ function adapterFragment(luvio, config) {
228
+ createResourceParams$1(config);
229
+ return select$6();
230
+ }
231
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
232
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response, {
233
+ config,
234
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
235
+ });
236
+ return luvio.storeBroadcast().then(() => snapshot);
237
+ }
238
+ function onFetchResponseError(luvio, config, resourceParams, response) {
239
+ const snapshot = ingestError(luvio, resourceParams, response, {
240
+ config,
241
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
242
+ });
243
+ return luvio.storeBroadcast().then(() => snapshot);
244
+ }
245
+ function buildNetworkSnapshot$1(luvio, config, options) {
246
+ const resourceParams = createResourceParams$1(config);
247
+ const request = createResourceRequest$1();
248
+ return luvio.dispatchResourceRequest(request, options)
249
+ .then((response) => {
250
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => {
251
+ const cache = new StoreKeyMap();
252
+ getResponseCacheKeys$1(cache, luvio, resourceParams, response.body);
253
+ return cache;
254
+ });
255
+ }, (response) => {
256
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
257
+ });
258
+ }
259
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
260
+ return buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext, buildNetworkSnapshot$1, undefined, false);
261
+ }
262
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
263
+ const { luvio, config } = context;
264
+ const selector = {
265
+ recordId: keyBuilder$1(luvio, config),
266
+ node: adapterFragment(luvio, config),
267
+ variables: {},
268
+ };
269
+ const cacheSnapshot = storeLookup(selector, {
270
+ config,
271
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
272
+ });
273
+ return cacheSnapshot;
274
+ }
275
+ const getStatusAdapterFactory = (luvio) => function einsteinCopilotBot__getStatus(untrustedConfig, requestContext) {
276
+ const config = validateAdapterConfig$1(untrustedConfig, getStatus_ConfigPropertyNames);
277
+ // Invalid or incomplete config
278
+ if (config === null) {
279
+ return null;
280
+ }
281
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
282
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
283
+ };
284
+
285
+ function validate$c(obj, path = 'TextInitMessage') {
286
+ const v_error = (() => {
287
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
288
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
289
+ }
290
+ if (obj.text !== undefined) {
291
+ const obj_text = obj.text;
292
+ const path_text = path + '.text';
293
+ if (typeof obj_text !== 'string') {
294
+ return new TypeError('Expected "string" but received "' + typeof obj_text + '" (at "' + path_text + '")');
295
+ }
296
+ }
297
+ })();
298
+ return v_error === undefined ? null : v_error;
299
+ }
300
+
301
+ function validate$b(obj, path = 'ForceConfig') {
302
+ const v_error = (() => {
303
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
304
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
305
+ }
306
+ const obj_endpoint = obj.endpoint;
307
+ const path_endpoint = path + '.endpoint';
308
+ if (typeof obj_endpoint !== 'string') {
309
+ return new TypeError('Expected "string" but received "' + typeof obj_endpoint + '" (at "' + path_endpoint + '")');
310
+ }
311
+ })();
312
+ return v_error === undefined ? null : v_error;
313
+ }
314
+
315
+ function validate$a(obj, path = 'ResponseOptionsVariables') {
316
+ const v_error = (() => {
317
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
318
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
319
+ }
320
+ if (obj.filter !== undefined) {
321
+ const obj_filter = obj.filter;
322
+ const path_filter = path + '.filter';
323
+ if (!ArrayIsArray(obj_filter)) {
324
+ return new TypeError('Expected "array" but received "' + typeof obj_filter + '" (at "' + path_filter + '")');
325
+ }
326
+ for (let i = 0; i < obj_filter.length; i++) {
327
+ const obj_filter_item = obj_filter[i];
328
+ const path_filter_item = path_filter + '[' + i + ']';
329
+ if (typeof obj_filter_item !== 'string') {
330
+ return new TypeError('Expected "string" but received "' + typeof obj_filter_item + '" (at "' + path_filter_item + '")');
331
+ }
332
+ }
333
+ }
334
+ const obj_include = obj.include;
335
+ const path_include = path + '.include';
336
+ if (typeof obj_include !== 'boolean') {
337
+ return new TypeError('Expected "boolean" but received "' + typeof obj_include + '" (at "' + path_include + '")');
338
+ }
339
+ const obj_onlyChanged = obj.onlyChanged;
340
+ const path_onlyChanged = path + '.onlyChanged';
341
+ if (typeof obj_onlyChanged !== 'boolean') {
342
+ return new TypeError('Expected "boolean" but received "' + typeof obj_onlyChanged + '" (at "' + path_onlyChanged + '")');
343
+ }
344
+ })();
345
+ return v_error === undefined ? null : v_error;
346
+ }
347
+
348
+ function validate$9(obj, path = 'ResponseOptions') {
349
+ const v_error = (() => {
350
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
351
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
352
+ }
353
+ if (obj.entities !== undefined) {
354
+ const obj_entities = obj.entities;
355
+ const path_entities = path + '.entities';
356
+ if (typeof obj_entities !== 'boolean') {
357
+ return new TypeError('Expected "boolean" but received "' + typeof obj_entities + '" (at "' + path_entities + '")');
358
+ }
359
+ }
360
+ if (obj.intents !== undefined) {
361
+ const obj_intents = obj.intents;
362
+ const path_intents = path + '.intents';
363
+ if (typeof obj_intents !== 'boolean') {
364
+ return new TypeError('Expected "boolean" but received "' + typeof obj_intents + '" (at "' + path_intents + '")');
365
+ }
366
+ }
367
+ if (obj.metrics !== undefined) {
368
+ const obj_metrics = obj.metrics;
369
+ const path_metrics = path + '.metrics';
370
+ if (typeof obj_metrics !== 'boolean') {
371
+ return new TypeError('Expected "boolean" but received "' + typeof obj_metrics + '" (at "' + path_metrics + '")');
372
+ }
373
+ }
374
+ if (obj.variables !== undefined) {
375
+ const obj_variables = obj.variables;
376
+ const path_variables = path + '.variables';
377
+ const referencepath_variablesValidationError = validate$a(obj_variables, path_variables);
378
+ if (referencepath_variablesValidationError !== null) {
379
+ let message = 'Object doesn\'t match ResponseOptionsVariables (at "' + path_variables + '")\n';
380
+ message += referencepath_variablesValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
381
+ return new TypeError(message);
382
+ }
383
+ }
384
+ })();
385
+ return v_error === undefined ? null : v_error;
386
+ }
387
+
388
+ function validate$8(obj, path = 'FormatTypeCapability') {
389
+ const v_error = (() => {
390
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
391
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
392
+ }
393
+ const obj_formatType = obj.formatType;
394
+ const path_formatType = path + '.formatType';
395
+ if (typeof obj_formatType !== 'string') {
396
+ return new TypeError('Expected "string" but received "' + typeof obj_formatType + '" (at "' + path_formatType + '")');
397
+ }
398
+ })();
399
+ return v_error === undefined ? null : v_error;
400
+ }
401
+
402
+ function validate$7(obj, path = 'MessageTypeCapability') {
403
+ const v_error = (() => {
404
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
405
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
406
+ }
407
+ const obj_formatTypes = obj.formatTypes;
408
+ const path_formatTypes = path + '.formatTypes';
409
+ if (!ArrayIsArray(obj_formatTypes)) {
410
+ return new TypeError('Expected "array" but received "' + typeof obj_formatTypes + '" (at "' + path_formatTypes + '")');
411
+ }
412
+ for (let i = 0; i < obj_formatTypes.length; i++) {
413
+ const obj_formatTypes_item = obj_formatTypes[i];
414
+ const path_formatTypes_item = path_formatTypes + '[' + i + ']';
415
+ const referencepath_formatTypes_itemValidationError = validate$8(obj_formatTypes_item, path_formatTypes_item);
416
+ if (referencepath_formatTypes_itemValidationError !== null) {
417
+ let message = 'Object doesn\'t match FormatTypeCapability (at "' + path_formatTypes_item + '")\n';
418
+ message += referencepath_formatTypes_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
419
+ return new TypeError(message);
420
+ }
421
+ }
422
+ const obj_messageType = obj.messageType;
423
+ const path_messageType = path + '.messageType';
424
+ if (typeof obj_messageType !== 'string') {
425
+ return new TypeError('Expected "string" but received "' + typeof obj_messageType + '" (at "' + path_messageType + '")');
426
+ }
427
+ })();
428
+ return v_error === undefined ? null : v_error;
429
+ }
430
+
431
+ function validate$6(obj, path = 'RichContentCapability') {
432
+ const v_error = (() => {
433
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
434
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
435
+ }
436
+ const obj_messageTypes = obj.messageTypes;
437
+ const path_messageTypes = path + '.messageTypes';
438
+ if (!ArrayIsArray(obj_messageTypes)) {
439
+ return new TypeError('Expected "array" but received "' + typeof obj_messageTypes + '" (at "' + path_messageTypes + '")');
440
+ }
441
+ for (let i = 0; i < obj_messageTypes.length; i++) {
442
+ const obj_messageTypes_item = obj_messageTypes[i];
443
+ const path_messageTypes_item = path_messageTypes + '[' + i + ']';
444
+ const referencepath_messageTypes_itemValidationError = validate$7(obj_messageTypes_item, path_messageTypes_item);
445
+ if (referencepath_messageTypes_itemValidationError !== null) {
446
+ let message = 'Object doesn\'t match MessageTypeCapability (at "' + path_messageTypes_item + '")\n';
447
+ message += referencepath_messageTypes_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
448
+ return new TypeError(message);
449
+ }
450
+ }
451
+ })();
452
+ return v_error === undefined ? null : v_error;
453
+ }
454
+
455
+ function validate$5(obj, path = 'Referrer') {
456
+ const v_error = (() => {
457
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
458
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
459
+ }
460
+ const obj_type = obj.type;
461
+ const path_type = path + '.type';
462
+ if (typeof obj_type !== 'string') {
463
+ return new TypeError('Expected "string" but received "' + typeof obj_type + '" (at "' + path_type + '")');
464
+ }
465
+ const obj_value = obj.value;
466
+ const path_value = path + '.value';
467
+ if (typeof obj_value !== 'string') {
468
+ return new TypeError('Expected "string" but received "' + typeof obj_value + '" (at "' + path_value + '")');
469
+ }
470
+ })();
471
+ return v_error === undefined ? null : v_error;
472
+ }
473
+
474
+ const VERSION$4 = "e83b5929e31be375ae27fe73bb3382f9";
475
+ function validate$4(obj, path = 'HyperLink') {
476
+ const v_error = (() => {
477
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
478
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
479
+ }
480
+ if (obj.href !== undefined) {
481
+ const obj_href = obj.href;
482
+ const path_href = path + '.href';
483
+ if (typeof obj_href !== 'string') {
484
+ return new TypeError('Expected "string" but received "' + typeof obj_href + '" (at "' + path_href + '")');
485
+ }
486
+ }
487
+ })();
488
+ return v_error === undefined ? null : v_error;
489
+ }
490
+ const select$5 = function HyperLinkSelect() {
491
+ return {
492
+ kind: 'Fragment',
493
+ version: VERSION$4,
494
+ private: [],
495
+ selections: [
496
+ {
497
+ name: 'href',
498
+ kind: 'Scalar',
499
+ required: false
500
+ }
501
+ ]
502
+ };
503
+ };
504
+ function equals$4(existing, incoming) {
505
+ const existing_href = existing.href;
506
+ const incoming_href = incoming.href;
507
+ // if at least one of these optionals is defined
508
+ if (existing_href !== undefined || incoming_href !== undefined) {
509
+ // if one of these is not defined we know the other is defined and therefore
510
+ // not equal
511
+ if (existing_href === undefined || incoming_href === undefined) {
512
+ return false;
513
+ }
514
+ if (!(existing_href === incoming_href)) {
515
+ return false;
516
+ }
517
+ }
518
+ return true;
519
+ }
520
+
521
+ const VERSION$3 = "b2628db4df840dd65695e7c0fa116ba0";
522
+ function validate$3(obj, path = 'Links') {
523
+ const v_error = (() => {
524
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
525
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
526
+ }
527
+ if (obj.feedback !== undefined) {
528
+ const obj_feedback = obj.feedback;
529
+ const path_feedback = path + '.feedback';
530
+ const referencepath_feedbackValidationError = validate$4(obj_feedback, path_feedback);
531
+ if (referencepath_feedbackValidationError !== null) {
532
+ let message = 'Object doesn\'t match HyperLink (at "' + path_feedback + '")\n';
533
+ message += referencepath_feedbackValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
534
+ return new TypeError(message);
535
+ }
536
+ }
537
+ if (obj.messages !== undefined) {
538
+ const obj_messages = obj.messages;
539
+ const path_messages = path + '.messages';
540
+ const referencepath_messagesValidationError = validate$4(obj_messages, path_messages);
541
+ if (referencepath_messagesValidationError !== null) {
542
+ let message = 'Object doesn\'t match HyperLink (at "' + path_messages + '")\n';
543
+ message += referencepath_messagesValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
544
+ return new TypeError(message);
545
+ }
546
+ }
547
+ const obj_self = obj.self;
548
+ const path_self = path + '.self';
549
+ const referencepath_selfValidationError = validate$4(obj_self, path_self);
550
+ if (referencepath_selfValidationError !== null) {
551
+ let message = 'Object doesn\'t match HyperLink (at "' + path_self + '")\n';
552
+ message += referencepath_selfValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
553
+ return new TypeError(message);
554
+ }
555
+ if (obj.session !== undefined) {
556
+ const obj_session = obj.session;
557
+ const path_session = path + '.session';
558
+ const referencepath_sessionValidationError = validate$4(obj_session, path_session);
559
+ if (referencepath_sessionValidationError !== null) {
560
+ let message = 'Object doesn\'t match HyperLink (at "' + path_session + '")\n';
561
+ message += referencepath_sessionValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
562
+ return new TypeError(message);
563
+ }
564
+ }
565
+ })();
566
+ return v_error === undefined ? null : v_error;
567
+ }
568
+ const select$4 = function LinksSelect() {
569
+ const { selections: HyperLink__selections, opaque: HyperLink__opaque, } = select$5();
570
+ return {
571
+ kind: 'Fragment',
572
+ version: VERSION$3,
573
+ private: [],
574
+ selections: [
575
+ {
576
+ name: 'feedback',
577
+ kind: 'Object',
578
+ selections: HyperLink__selections,
579
+ required: false
580
+ },
581
+ {
582
+ name: 'messages',
583
+ kind: 'Object',
584
+ selections: HyperLink__selections,
585
+ required: false
586
+ },
587
+ {
588
+ name: 'self',
589
+ kind: 'Object',
590
+ selections: HyperLink__selections
591
+ },
592
+ {
593
+ name: 'session',
594
+ kind: 'Object',
595
+ selections: HyperLink__selections,
596
+ required: false
597
+ }
598
+ ]
599
+ };
600
+ };
601
+ function equals$3(existing, incoming) {
602
+ const existing_feedback = existing.feedback;
603
+ const incoming_feedback = incoming.feedback;
604
+ // if at least one of these optionals is defined
605
+ if (existing_feedback !== undefined || incoming_feedback !== undefined) {
606
+ // if one of these is not defined we know the other is defined and therefore
607
+ // not equal
608
+ if (existing_feedback === undefined || incoming_feedback === undefined) {
609
+ return false;
610
+ }
611
+ if (!(equals$4(existing_feedback, incoming_feedback))) {
612
+ return false;
613
+ }
614
+ }
615
+ const existing_messages = existing.messages;
616
+ const incoming_messages = incoming.messages;
617
+ // if at least one of these optionals is defined
618
+ if (existing_messages !== undefined || incoming_messages !== undefined) {
619
+ // if one of these is not defined we know the other is defined and therefore
620
+ // not equal
621
+ if (existing_messages === undefined || incoming_messages === undefined) {
622
+ return false;
623
+ }
624
+ if (!(equals$4(existing_messages, incoming_messages))) {
625
+ return false;
626
+ }
627
+ }
628
+ const existing_self = existing.self;
629
+ const incoming_self = incoming.self;
630
+ if (!(equals$4(existing_self, incoming_self))) {
631
+ return false;
632
+ }
633
+ const existing_session = existing.session;
634
+ const incoming_session = incoming.session;
635
+ // if at least one of these optionals is defined
636
+ if (existing_session !== undefined || incoming_session !== undefined) {
637
+ // if one of these is not defined we know the other is defined and therefore
638
+ // not equal
639
+ if (existing_session === undefined || incoming_session === undefined) {
640
+ return false;
641
+ }
642
+ if (!(equals$4(existing_session, incoming_session))) {
643
+ return false;
644
+ }
645
+ }
646
+ return true;
647
+ }
648
+
649
+ const VERSION$2 = "7c8373d2df008bda97299d299ec1812c";
650
+ function validate$2(obj, path = 'NormalizedEntity') {
651
+ const v_error = (() => {
652
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
653
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
654
+ }
655
+ const obj_confidenceScore = obj.confidenceScore;
656
+ const path_confidenceScore = path + '.confidenceScore';
657
+ if (typeof obj_confidenceScore !== 'number') {
658
+ return new TypeError('Expected "number" but received "' + typeof obj_confidenceScore + '" (at "' + path_confidenceScore + '")');
659
+ }
660
+ if (obj.entitySource !== undefined) {
661
+ const obj_entitySource = obj.entitySource;
662
+ const path_entitySource = path + '.entitySource';
663
+ if (typeof obj_entitySource !== 'string') {
664
+ return new TypeError('Expected "string" but received "' + typeof obj_entitySource + '" (at "' + path_entitySource + '")');
665
+ }
666
+ }
667
+ const obj_type = obj.type;
668
+ const path_type = path + '.type';
669
+ if (typeof obj_type !== 'string') {
670
+ return new TypeError('Expected "string" but received "' + typeof obj_type + '" (at "' + path_type + '")');
671
+ }
672
+ const obj_value = obj.value;
673
+ const path_value = path + '.value';
674
+ if (typeof obj_value !== 'string') {
675
+ return new TypeError('Expected "string" but received "' + typeof obj_value + '" (at "' + path_value + '")');
676
+ }
677
+ })();
678
+ return v_error === undefined ? null : v_error;
679
+ }
680
+ const select$3 = function NormalizedEntitySelect() {
681
+ return {
682
+ kind: 'Fragment',
683
+ version: VERSION$2,
684
+ private: [],
685
+ selections: [
686
+ {
687
+ name: 'confidenceScore',
688
+ kind: 'Scalar'
689
+ },
690
+ {
691
+ name: 'entitySource',
692
+ kind: 'Scalar',
693
+ required: false
694
+ },
695
+ {
696
+ name: 'type',
697
+ kind: 'Scalar'
698
+ },
699
+ {
700
+ name: 'value',
701
+ kind: 'Scalar'
702
+ }
703
+ ]
704
+ };
705
+ };
706
+ function equals$2(existing, incoming) {
707
+ const existing_confidenceScore = existing.confidenceScore;
708
+ const incoming_confidenceScore = incoming.confidenceScore;
709
+ if (!(existing_confidenceScore === incoming_confidenceScore)) {
710
+ return false;
711
+ }
712
+ const existing_entitySource = existing.entitySource;
713
+ const incoming_entitySource = incoming.entitySource;
714
+ // if at least one of these optionals is defined
715
+ if (existing_entitySource !== undefined || incoming_entitySource !== undefined) {
716
+ // if one of these is not defined we know the other is defined and therefore
717
+ // not equal
718
+ if (existing_entitySource === undefined || incoming_entitySource === undefined) {
719
+ return false;
720
+ }
721
+ if (!(existing_entitySource === incoming_entitySource)) {
722
+ return false;
723
+ }
724
+ }
725
+ const existing_type = existing.type;
726
+ const incoming_type = incoming.type;
727
+ if (!(existing_type === incoming_type)) {
728
+ return false;
729
+ }
730
+ const existing_value = existing.value;
731
+ const incoming_value = incoming.value;
732
+ if (!(existing_value === incoming_value)) {
733
+ return false;
734
+ }
735
+ return true;
736
+ }
737
+
738
+ const VERSION$1 = "dc0fc09de80bfd4fd35d43e3e123eb83";
739
+ function validate$1(obj, path = 'NormalizedIntent') {
740
+ const v_error = (() => {
741
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
742
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
743
+ }
744
+ const obj_confidenceScore = obj.confidenceScore;
745
+ const path_confidenceScore = path + '.confidenceScore';
746
+ if (typeof obj_confidenceScore !== 'number') {
747
+ return new TypeError('Expected "number" but received "' + typeof obj_confidenceScore + '" (at "' + path_confidenceScore + '")');
748
+ }
749
+ const obj_intentSource = obj.intentSource;
750
+ const path_intentSource = path + '.intentSource';
751
+ if (typeof obj_intentSource !== 'string') {
752
+ return new TypeError('Expected "string" but received "' + typeof obj_intentSource + '" (at "' + path_intentSource + '")');
753
+ }
754
+ const obj_label = obj.label;
755
+ const path_label = path + '.label';
756
+ if (typeof obj_label !== 'string') {
757
+ return new TypeError('Expected "string" but received "' + typeof obj_label + '" (at "' + path_label + '")');
758
+ }
759
+ })();
760
+ return v_error === undefined ? null : v_error;
761
+ }
762
+ const select$2 = function NormalizedIntentSelect() {
763
+ return {
764
+ kind: 'Fragment',
765
+ version: VERSION$1,
766
+ private: [],
767
+ selections: [
768
+ {
769
+ name: 'confidenceScore',
770
+ kind: 'Scalar'
771
+ },
772
+ {
773
+ name: 'intentSource',
774
+ kind: 'Scalar'
775
+ },
776
+ {
777
+ name: 'label',
778
+ kind: 'Scalar'
779
+ }
780
+ ]
781
+ };
782
+ };
783
+ function equals$1(existing, incoming) {
784
+ const existing_confidenceScore = existing.confidenceScore;
785
+ const incoming_confidenceScore = incoming.confidenceScore;
786
+ if (!(existing_confidenceScore === incoming_confidenceScore)) {
787
+ return false;
788
+ }
789
+ const existing_intentSource = existing.intentSource;
790
+ const incoming_intentSource = incoming.intentSource;
791
+ if (!(existing_intentSource === incoming_intentSource)) {
792
+ return false;
793
+ }
794
+ const existing_label = existing.label;
795
+ const incoming_label = incoming.label;
796
+ if (!(existing_label === incoming_label)) {
797
+ return false;
798
+ }
799
+ return true;
800
+ }
801
+
802
+ const TTL = 500;
803
+ const VERSION = "629ac931b0021d4de378c8cafc6a7213";
804
+ function validate(obj, path = 'ResponseEnvelope') {
805
+ const v_error = (() => {
806
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
807
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
808
+ }
809
+ const obj__links = obj._links;
810
+ const path__links = path + '._links';
811
+ const referencepath__linksValidationError = validate$3(obj__links, path__links);
812
+ if (referencepath__linksValidationError !== null) {
813
+ let message = 'Object doesn\'t match Links (at "' + path__links + '")\n';
814
+ message += referencepath__linksValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
815
+ return new TypeError(message);
816
+ }
817
+ const obj_botVersion = obj.botVersion;
818
+ const path_botVersion = path + '.botVersion';
819
+ if (typeof obj_botVersion !== 'string') {
820
+ return new TypeError('Expected "string" but received "' + typeof obj_botVersion + '" (at "' + path_botVersion + '")');
821
+ }
822
+ if (obj.entities !== undefined) {
823
+ const obj_entities = obj.entities;
824
+ const path_entities = path + '.entities';
825
+ if (!ArrayIsArray(obj_entities)) {
826
+ return new TypeError('Expected "array" but received "' + typeof obj_entities + '" (at "' + path_entities + '")');
827
+ }
828
+ for (let i = 0; i < obj_entities.length; i++) {
829
+ const obj_entities_item = obj_entities[i];
830
+ const path_entities_item = path_entities + '[' + i + ']';
831
+ const referencepath_entities_itemValidationError = validate$2(obj_entities_item, path_entities_item);
832
+ if (referencepath_entities_itemValidationError !== null) {
833
+ let message = 'Object doesn\'t match NormalizedEntity (at "' + path_entities_item + '")\n';
834
+ message += referencepath_entities_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
835
+ return new TypeError(message);
836
+ }
837
+ }
838
+ }
839
+ if (obj.intents !== undefined) {
840
+ const obj_intents = obj.intents;
841
+ const path_intents = path + '.intents';
842
+ if (!ArrayIsArray(obj_intents)) {
843
+ return new TypeError('Expected "array" but received "' + typeof obj_intents + '" (at "' + path_intents + '")');
844
+ }
845
+ for (let i = 0; i < obj_intents.length; i++) {
846
+ const obj_intents_item = obj_intents[i];
847
+ const path_intents_item = path_intents + '[' + i + ']';
848
+ const referencepath_intents_itemValidationError = validate$1(obj_intents_item, path_intents_item);
849
+ if (referencepath_intents_itemValidationError !== null) {
850
+ let message = 'Object doesn\'t match NormalizedIntent (at "' + path_intents_item + '")\n';
851
+ message += referencepath_intents_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
852
+ return new TypeError(message);
853
+ }
854
+ }
855
+ }
856
+ const obj_messages = obj.messages;
857
+ const path_messages = path + '.messages';
858
+ if (!ArrayIsArray(obj_messages)) {
859
+ return new TypeError('Expected "array" but received "' + typeof obj_messages + '" (at "' + path_messages + '")');
860
+ }
861
+ for (let i = 0; i < obj_messages.length; i++) {
862
+ const obj_messages_item = obj_messages[i];
863
+ const path_messages_item = path_messages + '[' + i + ']';
864
+ if (obj_messages_item === undefined) {
865
+ return new TypeError('Expected "defined" but received "' + typeof obj_messages_item + '" (at "' + path_messages_item + '")');
866
+ }
867
+ }
868
+ if (obj.metrics !== undefined) {
869
+ const obj_metrics = obj.metrics;
870
+ const path_metrics = path + '.metrics';
871
+ if (typeof obj_metrics !== 'object' || ArrayIsArray(obj_metrics) || obj_metrics === null) {
872
+ return new TypeError('Expected "object" but received "' + typeof obj_metrics + '" (at "' + path_metrics + '")');
873
+ }
874
+ }
875
+ const obj_processedSequenceIds = obj.processedSequenceIds;
876
+ const path_processedSequenceIds = path + '.processedSequenceIds';
877
+ if (!ArrayIsArray(obj_processedSequenceIds)) {
878
+ return new TypeError('Expected "array" but received "' + typeof obj_processedSequenceIds + '" (at "' + path_processedSequenceIds + '")');
879
+ }
880
+ for (let i = 0; i < obj_processedSequenceIds.length; i++) {
881
+ const obj_processedSequenceIds_item = obj_processedSequenceIds[i];
882
+ const path_processedSequenceIds_item = path_processedSequenceIds + '[' + i + ']';
883
+ if (typeof obj_processedSequenceIds_item !== 'number') {
884
+ return new TypeError('Expected "number" but received "' + typeof obj_processedSequenceIds_item + '" (at "' + path_processedSequenceIds_item + '")');
885
+ }
886
+ }
887
+ const obj_sessionId = obj.sessionId;
888
+ const path_sessionId = path + '.sessionId';
889
+ if (typeof obj_sessionId !== 'string') {
890
+ return new TypeError('Expected "string" but received "' + typeof obj_sessionId + '" (at "' + path_sessionId + '")');
891
+ }
892
+ if (obj.variables !== undefined) {
893
+ const obj_variables = obj.variables;
894
+ const path_variables = path + '.variables';
895
+ if (!ArrayIsArray(obj_variables)) {
896
+ return new TypeError('Expected "array" but received "' + typeof obj_variables + '" (at "' + path_variables + '")');
897
+ }
898
+ for (let i = 0; i < obj_variables.length; i++) {
899
+ const obj_variables_item = obj_variables[i];
900
+ const path_variables_item = path_variables + '[' + i + ']';
901
+ if (obj_variables_item === undefined) {
902
+ return new TypeError('Expected "defined" but received "' + typeof obj_variables_item + '" (at "' + path_variables_item + '")');
903
+ }
904
+ }
905
+ }
906
+ })();
907
+ return v_error === undefined ? null : v_error;
908
+ }
909
+ const RepresentationType = 'ResponseEnvelope';
910
+ function keyBuilder(luvio, config) {
911
+ return keyPrefix + '::' + RepresentationType + ':' + config.id;
912
+ }
913
+ function keyBuilderFromType(luvio, object) {
914
+ const keyParams = {
915
+ id: object.sessionId
916
+ };
917
+ return keyBuilder(luvio, keyParams);
918
+ }
919
+ function normalize(input, existing, path, luvio, store, timestamp) {
920
+ return input;
921
+ }
922
+ const select$1 = function ResponseEnvelopeSelect() {
923
+ const { selections: Links__selections, opaque: Links__opaque, } = select$4();
924
+ const { selections: NormalizedEntity__selections, opaque: NormalizedEntity__opaque, } = select$3();
925
+ const { selections: NormalizedIntent__selections, opaque: NormalizedIntent__opaque, } = select$2();
926
+ return {
927
+ kind: 'Fragment',
928
+ version: VERSION,
929
+ private: [],
930
+ selections: [
931
+ {
932
+ name: '_links',
933
+ kind: 'Object',
934
+ selections: Links__selections
935
+ },
936
+ {
937
+ name: 'botVersion',
938
+ kind: 'Scalar'
939
+ },
940
+ {
941
+ name: 'entities',
942
+ kind: 'Object',
943
+ plural: true,
944
+ selections: NormalizedEntity__selections,
945
+ required: false
946
+ },
947
+ {
948
+ name: 'intents',
949
+ kind: 'Object',
950
+ plural: true,
951
+ selections: NormalizedIntent__selections,
952
+ required: false
953
+ },
954
+ {
955
+ name: 'messages',
956
+ kind: 'Object',
957
+ // any
958
+ },
959
+ {
960
+ name: 'processedSequenceIds',
961
+ kind: 'Scalar',
962
+ plural: true
963
+ },
964
+ {
965
+ name: 'sessionId',
966
+ kind: 'Scalar'
967
+ },
968
+ {
969
+ name: 'variables',
970
+ kind: 'Object',
971
+ // any
972
+ }
973
+ ]
974
+ };
975
+ };
976
+ function equals(existing, incoming) {
977
+ const existing_botVersion = existing.botVersion;
978
+ const incoming_botVersion = incoming.botVersion;
979
+ if (!(existing_botVersion === incoming_botVersion)) {
980
+ return false;
981
+ }
982
+ const existing_sessionId = existing.sessionId;
983
+ const incoming_sessionId = incoming.sessionId;
984
+ if (!(existing_sessionId === incoming_sessionId)) {
985
+ return false;
986
+ }
987
+ const existing__links = existing._links;
988
+ const incoming__links = incoming._links;
989
+ if (!(equals$3(existing__links, incoming__links))) {
990
+ return false;
991
+ }
992
+ const existing_entities = existing.entities;
993
+ const incoming_entities = incoming.entities;
994
+ // if at least one of these optionals is defined
995
+ if (existing_entities !== undefined || incoming_entities !== undefined) {
996
+ // if one of these is not defined we know the other is defined and therefore
997
+ // not equal
998
+ if (existing_entities === undefined || incoming_entities === undefined) {
999
+ return false;
1000
+ }
1001
+ const equals_entities_items = equalsArray(existing_entities, incoming_entities, (existing_entities_item, incoming_entities_item) => {
1002
+ if (!(equals$2(existing_entities_item, incoming_entities_item))) {
1003
+ return false;
1004
+ }
1005
+ });
1006
+ if (equals_entities_items === false) {
1007
+ return false;
1008
+ }
1009
+ }
1010
+ const existing_intents = existing.intents;
1011
+ const incoming_intents = incoming.intents;
1012
+ // if at least one of these optionals is defined
1013
+ if (existing_intents !== undefined || incoming_intents !== undefined) {
1014
+ // if one of these is not defined we know the other is defined and therefore
1015
+ // not equal
1016
+ if (existing_intents === undefined || incoming_intents === undefined) {
1017
+ return false;
1018
+ }
1019
+ const equals_intents_items = equalsArray(existing_intents, incoming_intents, (existing_intents_item, incoming_intents_item) => {
1020
+ if (!(equals$1(existing_intents_item, incoming_intents_item))) {
1021
+ return false;
1022
+ }
1023
+ });
1024
+ if (equals_intents_items === false) {
1025
+ return false;
1026
+ }
1027
+ }
1028
+ const existing_messages = existing.messages;
1029
+ const incoming_messages = incoming.messages;
1030
+ const equals_messages_items = equalsArray(existing_messages, incoming_messages, (existing_messages_item, incoming_messages_item) => {
1031
+ if (JSONStringify(incoming_messages_item) !== JSONStringify(existing_messages_item)) {
1032
+ return false;
1033
+ }
1034
+ });
1035
+ if (equals_messages_items === false) {
1036
+ return false;
1037
+ }
1038
+ const existing_metrics = existing.metrics;
1039
+ const incoming_metrics = incoming.metrics;
1040
+ // if at least one of these optionals is defined
1041
+ if (existing_metrics !== undefined || incoming_metrics !== undefined) {
1042
+ // if one of these is not defined we know the other is defined and therefore
1043
+ // not equal
1044
+ if (existing_metrics === undefined || incoming_metrics === undefined) {
1045
+ return false;
1046
+ }
1047
+ }
1048
+ const existing_processedSequenceIds = existing.processedSequenceIds;
1049
+ const incoming_processedSequenceIds = incoming.processedSequenceIds;
1050
+ const equals_processedSequenceIds_items = equalsArray(existing_processedSequenceIds, incoming_processedSequenceIds, (existing_processedSequenceIds_item, incoming_processedSequenceIds_item) => {
1051
+ if (!(existing_processedSequenceIds_item === incoming_processedSequenceIds_item)) {
1052
+ return false;
1053
+ }
1054
+ });
1055
+ if (equals_processedSequenceIds_items === false) {
1056
+ return false;
1057
+ }
1058
+ const existing_variables = existing.variables;
1059
+ const incoming_variables = incoming.variables;
1060
+ // if at least one of these optionals is defined
1061
+ if (existing_variables !== undefined || incoming_variables !== undefined) {
1062
+ // if one of these is not defined we know the other is defined and therefore
1063
+ // not equal
1064
+ if (existing_variables === undefined || incoming_variables === undefined) {
1065
+ return false;
1066
+ }
1067
+ const equals_variables_items = equalsArray(existing_variables, incoming_variables, (existing_variables_item, incoming_variables_item) => {
1068
+ if (JSONStringify(incoming_variables_item) !== JSONStringify(existing_variables_item)) {
1069
+ return false;
1070
+ }
1071
+ });
1072
+ if (equals_variables_items === false) {
1073
+ return false;
1074
+ }
1075
+ }
1076
+ return true;
1077
+ }
1078
+ const ingest = function ResponseEnvelopeIngest(input, path, luvio, store, timestamp) {
1079
+ if (process.env.NODE_ENV !== 'production') {
1080
+ const validateError = validate(input);
1081
+ if (validateError !== null) {
1082
+ throw validateError;
1083
+ }
1084
+ }
1085
+ const key = keyBuilderFromType(luvio, input);
1086
+ const ttlToUse = TTL;
1087
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize, "einstein-copilot-bot", VERSION, RepresentationType, equals);
1088
+ return createLink(key);
1089
+ };
1090
+ function getTypeCacheKeys(rootKeySet, luvio, input, fullPathFactory) {
1091
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
1092
+ const rootKey = keyBuilderFromType(luvio, input);
1093
+ rootKeySet.set(rootKey, {
1094
+ namespace: keyPrefix,
1095
+ representationName: RepresentationType,
1096
+ mergeable: false
1097
+ });
1098
+ }
1099
+
1100
+ function select(luvio, params) {
1101
+ return select$1();
1102
+ }
1103
+ function getResponseCacheKeys(storeKeyMap, luvio, resourceParams, response) {
1104
+ getTypeCacheKeys(storeKeyMap, luvio, response);
1105
+ }
1106
+ function ingestSuccess(luvio, resourceParams, response) {
1107
+ const { body } = response;
1108
+ const key = keyBuilderFromType(luvio, body);
1109
+ luvio.storeIngest(key, ingest, body);
1110
+ const snapshot = luvio.storeLookup({
1111
+ recordId: key,
1112
+ node: select(),
1113
+ variables: {},
1114
+ });
1115
+ if (process.env.NODE_ENV !== 'production') {
1116
+ if (snapshot.state !== 'Fulfilled') {
1117
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
1118
+ }
1119
+ }
1120
+ deepFreeze(snapshot.data);
1121
+ return snapshot;
1122
+ }
1123
+ function createResourceRequest(config) {
1124
+ const headers = {};
1125
+ headers['X-Org-Id'] = config.headers.xOrgId;
1126
+ const header_xRequestID = config.headers.xRequestID;
1127
+ if (header_xRequestID !== undefined) {
1128
+ headers['X-Request-ID'] = header_xRequestID;
1129
+ }
1130
+ return {
1131
+ baseUri: 'api.salesforce.com',
1132
+ basePath: '/einstein/bots/v1/v5.3.0/bots/' + config.urlParams.botId + '/sessions',
1133
+ method: 'post',
1134
+ body: config.body,
1135
+ urlParams: config.urlParams,
1136
+ queryParams: {},
1137
+ headers,
1138
+ priority: 'normal',
1139
+ };
1140
+ }
1141
+
1142
+ const adapterName = 'startSession';
1143
+ const startSession_ConfigPropertyMetadata = [
1144
+ generateParamConfigMetadata('botId', true, 0 /* UrlParameter */, 0 /* String */),
1145
+ generateParamConfigMetadata('externalSessionKey', true, 2 /* Body */, 0 /* String */),
1146
+ generateParamConfigMetadata('message', false, 2 /* Body */, 4 /* Unsupported */),
1147
+ generateParamConfigMetadata('forceConfig', true, 2 /* Body */, 4 /* Unsupported */),
1148
+ generateParamConfigMetadata('responseOptions', false, 2 /* Body */, 4 /* Unsupported */),
1149
+ generateParamConfigMetadata('tz', false, 2 /* Body */, 4 /* Unsupported */),
1150
+ generateParamConfigMetadata('variables', false, 2 /* Body */, 4 /* Unsupported */, true),
1151
+ generateParamConfigMetadata('richContentCapabilities', true, 2 /* Body */, 4 /* Unsupported */),
1152
+ generateParamConfigMetadata('referrers', false, 2 /* Body */, 4 /* Unsupported */, true),
1153
+ generateParamConfigMetadata('xOrgId', true, 3 /* Header */, 0 /* String */),
1154
+ generateParamConfigMetadata('xRequestID', false, 3 /* Header */, 0 /* String */),
1155
+ ];
1156
+ const startSession_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName, startSession_ConfigPropertyMetadata);
1157
+ const createResourceParams = /*#__PURE__*/ createResourceParams$2(startSession_ConfigPropertyMetadata);
1158
+ function typeCheckConfig(untrustedConfig) {
1159
+ const config = {};
1160
+ typeCheckConfig$2(untrustedConfig, config, startSession_ConfigPropertyMetadata);
1161
+ const untrustedConfig_message = untrustedConfig.message;
1162
+ const referenceTextInitMessageValidationError = validate$c(untrustedConfig_message);
1163
+ if (referenceTextInitMessageValidationError === null) {
1164
+ config.message = untrustedConfig_message;
1165
+ }
1166
+ const untrustedConfig_forceConfig = untrustedConfig.forceConfig;
1167
+ const referenceForceConfigValidationError = validate$b(untrustedConfig_forceConfig);
1168
+ if (referenceForceConfigValidationError === null) {
1169
+ config.forceConfig = untrustedConfig_forceConfig;
1170
+ }
1171
+ const untrustedConfig_responseOptions = untrustedConfig.responseOptions;
1172
+ const referenceResponseOptionsValidationError = validate$9(untrustedConfig_responseOptions);
1173
+ if (referenceResponseOptionsValidationError === null) {
1174
+ config.responseOptions = untrustedConfig_responseOptions;
1175
+ }
1176
+ const untrustedConfig_tz = untrustedConfig.tz;
1177
+ if (typeof untrustedConfig_tz === 'string') {
1178
+ config.tz = untrustedConfig_tz;
1179
+ }
1180
+ if (untrustedConfig_tz === null) {
1181
+ config.tz = untrustedConfig_tz;
1182
+ }
1183
+ const untrustedConfig_variables = untrustedConfig.variables;
1184
+ if (ArrayIsArray$1(untrustedConfig_variables)) {
1185
+ const untrustedConfig_variables_array = [];
1186
+ for (let i = 0, arrayLength = untrustedConfig_variables.length; i < arrayLength; i++) {
1187
+ const untrustedConfig_variables_item = untrustedConfig_variables[i];
1188
+ untrustedConfig_variables_array.push(untrustedConfig_variables_item);
1189
+ }
1190
+ config.variables = untrustedConfig_variables_array;
1191
+ }
1192
+ const untrustedConfig_richContentCapabilities = untrustedConfig.richContentCapabilities;
1193
+ const referenceRichContentCapabilityValidationError = validate$6(untrustedConfig_richContentCapabilities);
1194
+ if (referenceRichContentCapabilityValidationError === null) {
1195
+ config.richContentCapabilities = untrustedConfig_richContentCapabilities;
1196
+ }
1197
+ const untrustedConfig_referrers = untrustedConfig.referrers;
1198
+ if (ArrayIsArray$1(untrustedConfig_referrers)) {
1199
+ const untrustedConfig_referrers_array = [];
1200
+ for (let i = 0, arrayLength = untrustedConfig_referrers.length; i < arrayLength; i++) {
1201
+ const untrustedConfig_referrers_item = untrustedConfig_referrers[i];
1202
+ const referenceReferrerValidationError = validate$5(untrustedConfig_referrers_item);
1203
+ if (referenceReferrerValidationError === null) {
1204
+ untrustedConfig_referrers_array.push(untrustedConfig_referrers_item);
1205
+ }
1206
+ }
1207
+ config.referrers = untrustedConfig_referrers_array;
1208
+ }
1209
+ return config;
1210
+ }
1211
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
1212
+ if (!untrustedIsObject(untrustedConfig)) {
1213
+ return null;
1214
+ }
1215
+ if (process.env.NODE_ENV !== 'production') {
1216
+ validateConfig(untrustedConfig, configPropertyNames);
1217
+ }
1218
+ const config = typeCheckConfig(untrustedConfig);
1219
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
1220
+ return null;
1221
+ }
1222
+ return config;
1223
+ }
1224
+ function buildNetworkSnapshot(luvio, config, options) {
1225
+ const resourceParams = createResourceParams(config);
1226
+ const request = createResourceRequest(resourceParams);
1227
+ return luvio.dispatchResourceRequest(request, options)
1228
+ .then((response) => {
1229
+ return luvio.handleSuccessResponse(() => {
1230
+ const snapshot = ingestSuccess(luvio, resourceParams, response);
1231
+ return luvio.storeBroadcast().then(() => snapshot);
1232
+ }, () => {
1233
+ const cache = new StoreKeyMap();
1234
+ getResponseCacheKeys(cache, luvio, resourceParams, response.body);
1235
+ return cache;
1236
+ });
1237
+ }, (response) => {
1238
+ deepFreeze(response);
1239
+ throw response;
1240
+ });
1241
+ }
1242
+ const startSessionAdapterFactory = (luvio) => {
1243
+ return function startSession(untrustedConfig) {
1244
+ const config = validateAdapterConfig(untrustedConfig, startSession_ConfigPropertyNames);
1245
+ // Invalid or incomplete config
1246
+ if (config === null) {
1247
+ throw new Error('Invalid config for "startSession"');
1248
+ }
1249
+ return buildNetworkSnapshot(luvio, config);
1250
+ };
1251
+ };
1252
+
1253
+ export { getStatusAdapterFactory, startSessionAdapterFactory };