@salesforce/lds-adapters-experience-marketing-integration 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.
Files changed (31) hide show
  1. package/LICENSE.txt +82 -0
  2. package/dist/es/es2018/experience-marketing-integration.js +934 -0
  3. package/dist/types/src/generated/adapters/adapter-utils.d.ts +66 -0
  4. package/dist/types/src/generated/adapters/getForm.d.ts +28 -0
  5. package/dist/types/src/generated/adapters/saveForm.d.ts +16 -0
  6. package/dist/types/src/generated/adapters/submitForm.d.ts +17 -0
  7. package/dist/types/src/generated/artifacts/main.d.ts +3 -0
  8. package/dist/types/src/generated/artifacts/sfdc.d.ts +6 -0
  9. package/dist/types/src/generated/resources/getSitesMarketingIntegrationFormsByFormIdAndSiteId.d.ts +17 -0
  10. package/dist/types/src/generated/resources/postSitesMarketingIntegrationFormsBySiteId.d.ts +16 -0
  11. package/dist/types/src/generated/resources/postSitesMarketingIntegrationFormsDataByFormIdAndSiteId.d.ts +17 -0
  12. package/dist/types/src/generated/types/FormFieldInputList.d.ts +30 -0
  13. package/dist/types/src/generated/types/FormFieldInputRepresentation.d.ts +32 -0
  14. package/dist/types/src/generated/types/FormFieldList.d.ts +30 -0
  15. package/dist/types/src/generated/types/FormFieldRepresentation.d.ts +32 -0
  16. package/dist/types/src/generated/types/FormInputRepresentation.d.ts +36 -0
  17. package/dist/types/src/generated/types/FormInputWrapperRepresentation.d.ts +30 -0
  18. package/dist/types/src/generated/types/FormRepresentation.d.ts +49 -0
  19. package/dist/types/src/generated/types/FormSubmissionFieldInputList.d.ts +30 -0
  20. package/dist/types/src/generated/types/FormSubmissionFieldInputRepresentation.d.ts +32 -0
  21. package/dist/types/src/generated/types/FormSubmissionInputRepresentation.d.ts +30 -0
  22. package/dist/types/src/generated/types/FormSubmissionInputWrapperRepresentation.d.ts +30 -0
  23. package/dist/types/src/generated/types/FormSubmissionRepresentation.d.ts +39 -0
  24. package/dist/types/src/generated/types/type-utils.d.ts +39 -0
  25. package/dist/umd/es2018/experience-marketing-integration.js +944 -0
  26. package/dist/umd/es5/experience-marketing-integration.js +954 -0
  27. package/package.json +56 -0
  28. package/sfdc/index.d.ts +1 -0
  29. package/sfdc/index.js +1016 -0
  30. package/src/raml/api.raml +209 -0
  31. package/src/raml/luvio.raml +32 -0
@@ -0,0 +1,954 @@
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["experienceMarketing-integration"] = {}, 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 = 'marketing-integration';
56
+
57
+ var ObjectFreeze = Object.freeze, ObjectKeys = Object.keys;
58
+ var ArrayIsArray = Array.isArray;
59
+ function equalsArray(a, b, equalsItem) {
60
+ var aLength = a.length;
61
+ var bLength = b.length;
62
+ if (aLength !== bLength) {
63
+ return false;
64
+ }
65
+ for (var i = 0; i < aLength; i++) {
66
+ if (equalsItem(a[i], b[i]) === false) {
67
+ return false;
68
+ }
69
+ }
70
+ return true;
71
+ }
72
+ function deepFreeze(value) {
73
+ // No need to freeze primitives
74
+ if (typeof value !== 'object' || value === null) {
75
+ return;
76
+ }
77
+ if (ArrayIsArray(value)) {
78
+ for (var i = 0, len = value.length; i < len; i += 1) {
79
+ deepFreeze(value[i]);
80
+ }
81
+ }
82
+ else {
83
+ var keys = ObjectKeys(value);
84
+ for (var i = 0, len = keys.length; i < len; i += 1) {
85
+ deepFreeze(value[keys[i]]);
86
+ }
87
+ }
88
+ ObjectFreeze(value);
89
+ }
90
+ function createLink(ref) {
91
+ return {
92
+ __ref: engine.serializeStructuredKey(ref),
93
+ };
94
+ }
95
+
96
+ function validate$9(obj, path) {
97
+ if (path === void 0) { path = 'FormFieldInputRepresentation'; }
98
+ var v_error = (function () {
99
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
100
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
101
+ }
102
+ var obj_name = obj.name;
103
+ var path_name = path + '.name';
104
+ if (typeof obj_name !== 'string') {
105
+ return new TypeError('Expected "string" but received "' + typeof obj_name + '" (at "' + path_name + '")');
106
+ }
107
+ var obj_type = obj.type;
108
+ var path_type = path + '.type';
109
+ if (typeof obj_type !== 'string') {
110
+ return new TypeError('Expected "string" but received "' + typeof obj_type + '" (at "' + path_type + '")');
111
+ }
112
+ })();
113
+ return v_error === undefined ? null : v_error;
114
+ }
115
+
116
+ function validate$8(obj, path) {
117
+ if (path === void 0) { path = 'FormFieldInputList'; }
118
+ var v_error = (function () {
119
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
120
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
121
+ }
122
+ var obj_formFields = obj.formFields;
123
+ var path_formFields = path + '.formFields';
124
+ if (!ArrayIsArray(obj_formFields)) {
125
+ return new TypeError('Expected "array" but received "' + typeof obj_formFields + '" (at "' + path_formFields + '")');
126
+ }
127
+ for (var i = 0; i < obj_formFields.length; i++) {
128
+ var obj_formFields_item = obj_formFields[i];
129
+ var path_formFields_item = path_formFields + '[' + i + ']';
130
+ var referencepath_formFields_itemValidationError = validate$9(obj_formFields_item, path_formFields_item);
131
+ if (referencepath_formFields_itemValidationError !== null) {
132
+ var message = 'Object doesn\'t match FormFieldInputRepresentation (at "' + path_formFields_item + '")\n';
133
+ message += referencepath_formFields_itemValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
134
+ return new TypeError(message);
135
+ }
136
+ }
137
+ })();
138
+ return v_error === undefined ? null : v_error;
139
+ }
140
+
141
+ function validate$7(obj, path) {
142
+ if (path === void 0) { path = 'FormInputRepresentation'; }
143
+ var v_error = (function () {
144
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
145
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
146
+ }
147
+ var obj_formFieldsList = obj.formFieldsList;
148
+ var path_formFieldsList = path + '.formFieldsList';
149
+ var referencepath_formFieldsListValidationError = validate$8(obj_formFieldsList, path_formFieldsList);
150
+ if (referencepath_formFieldsListValidationError !== null) {
151
+ var message = 'Object doesn\'t match FormFieldInputList (at "' + path_formFieldsList + '")\n';
152
+ message += referencepath_formFieldsListValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
153
+ return new TypeError(message);
154
+ }
155
+ var obj_formName = obj.formName;
156
+ var path_formName = path + '.formName';
157
+ if (typeof obj_formName !== 'string') {
158
+ return new TypeError('Expected "string" but received "' + typeof obj_formName + '" (at "' + path_formName + '")');
159
+ }
160
+ var obj_memberIdentificationCode = obj.memberIdentificationCode;
161
+ var path_memberIdentificationCode = path + '.memberIdentificationCode';
162
+ if (typeof obj_memberIdentificationCode !== 'string') {
163
+ return new TypeError('Expected "string" but received "' + typeof obj_memberIdentificationCode + '" (at "' + path_memberIdentificationCode + '")');
164
+ }
165
+ })();
166
+ return v_error === undefined ? null : v_error;
167
+ }
168
+
169
+ var VERSION$3 = "dbb6d8636675e188a8a1a56ad6dead24";
170
+ function validate$6(obj, path) {
171
+ if (path === void 0) { path = 'FormFieldRepresentation'; }
172
+ var v_error = (function () {
173
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
174
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
175
+ }
176
+ var obj_name = obj.name;
177
+ var path_name = path + '.name';
178
+ if (typeof obj_name !== 'string') {
179
+ return new TypeError('Expected "string" but received "' + typeof obj_name + '" (at "' + path_name + '")');
180
+ }
181
+ var obj_type = obj.type;
182
+ var path_type = path + '.type';
183
+ if (typeof obj_type !== 'string') {
184
+ return new TypeError('Expected "string" but received "' + typeof obj_type + '" (at "' + path_type + '")');
185
+ }
186
+ })();
187
+ return v_error === undefined ? null : v_error;
188
+ }
189
+ var select$6 = function FormFieldRepresentationSelect() {
190
+ return {
191
+ kind: 'Fragment',
192
+ version: VERSION$3,
193
+ private: [],
194
+ selections: [
195
+ {
196
+ name: 'name',
197
+ kind: 'Scalar'
198
+ },
199
+ {
200
+ name: 'type',
201
+ kind: 'Scalar'
202
+ }
203
+ ]
204
+ };
205
+ };
206
+ function equals$3(existing, incoming) {
207
+ var existing_name = existing.name;
208
+ var incoming_name = incoming.name;
209
+ if (!(existing_name === incoming_name)) {
210
+ return false;
211
+ }
212
+ var existing_type = existing.type;
213
+ var incoming_type = incoming.type;
214
+ if (!(existing_type === incoming_type)) {
215
+ return false;
216
+ }
217
+ return true;
218
+ }
219
+
220
+ var VERSION$2 = "8bc86c34b586e7b5050caa1c4c45a801";
221
+ function validate$5(obj, path) {
222
+ if (path === void 0) { path = 'FormFieldList'; }
223
+ var v_error = (function () {
224
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
225
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
226
+ }
227
+ var obj_formFields = obj.formFields;
228
+ var path_formFields = path + '.formFields';
229
+ if (!ArrayIsArray(obj_formFields)) {
230
+ return new TypeError('Expected "array" but received "' + typeof obj_formFields + '" (at "' + path_formFields + '")');
231
+ }
232
+ for (var i = 0; i < obj_formFields.length; i++) {
233
+ var obj_formFields_item = obj_formFields[i];
234
+ var path_formFields_item = path_formFields + '[' + i + ']';
235
+ var referencepath_formFields_itemValidationError = validate$6(obj_formFields_item, path_formFields_item);
236
+ if (referencepath_formFields_itemValidationError !== null) {
237
+ var message = 'Object doesn\'t match FormFieldRepresentation (at "' + path_formFields_item + '")\n';
238
+ message += referencepath_formFields_itemValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
239
+ return new TypeError(message);
240
+ }
241
+ }
242
+ })();
243
+ return v_error === undefined ? null : v_error;
244
+ }
245
+ var select$5 = function FormFieldListSelect() {
246
+ var _a = select$6(), FormFieldRepresentation__selections = _a.selections;
247
+ return {
248
+ kind: 'Fragment',
249
+ version: VERSION$2,
250
+ private: [],
251
+ selections: [
252
+ {
253
+ name: 'formFields',
254
+ kind: 'Object',
255
+ plural: true,
256
+ selections: FormFieldRepresentation__selections
257
+ }
258
+ ]
259
+ };
260
+ };
261
+ function equals$2(existing, incoming) {
262
+ var existing_formFields = existing.formFields;
263
+ var incoming_formFields = incoming.formFields;
264
+ var equals_formFields_items = equalsArray(existing_formFields, incoming_formFields, function (existing_formFields_item, incoming_formFields_item) {
265
+ if (!(equals$3(existing_formFields_item, incoming_formFields_item))) {
266
+ return false;
267
+ }
268
+ });
269
+ if (equals_formFields_items === false) {
270
+ return false;
271
+ }
272
+ return true;
273
+ }
274
+
275
+ var TTL$1 = 30000;
276
+ var VERSION$1 = "3c88c4c66505e9fa43c3198e8e40cd5d";
277
+ function validate$4(obj, path) {
278
+ if (path === void 0) { path = 'FormRepresentation'; }
279
+ var v_error = (function () {
280
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
281
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
282
+ }
283
+ var obj_dataExtensionId = obj.dataExtensionId;
284
+ var path_dataExtensionId = path + '.dataExtensionId';
285
+ if (typeof obj_dataExtensionId !== 'string') {
286
+ return new TypeError('Expected "string" but received "' + typeof obj_dataExtensionId + '" (at "' + path_dataExtensionId + '")');
287
+ }
288
+ var obj_formFieldsList = obj.formFieldsList;
289
+ var path_formFieldsList = path + '.formFieldsList';
290
+ var referencepath_formFieldsListValidationError = validate$5(obj_formFieldsList, path_formFieldsList);
291
+ if (referencepath_formFieldsListValidationError !== null) {
292
+ var message = 'Object doesn\'t match FormFieldList (at "' + path_formFieldsList + '")\n';
293
+ message += referencepath_formFieldsListValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
294
+ return new TypeError(message);
295
+ }
296
+ var obj_formId = obj.formId;
297
+ var path_formId = path + '.formId';
298
+ if (typeof obj_formId !== 'string') {
299
+ return new TypeError('Expected "string" but received "' + typeof obj_formId + '" (at "' + path_formId + '")');
300
+ }
301
+ var obj_formName = obj.formName;
302
+ var path_formName = path + '.formName';
303
+ if (typeof obj_formName !== 'string') {
304
+ return new TypeError('Expected "string" but received "' + typeof obj_formName + '" (at "' + path_formName + '")');
305
+ }
306
+ })();
307
+ return v_error === undefined ? null : v_error;
308
+ }
309
+ var RepresentationType$1 = 'FormRepresentation';
310
+ function keyBuilder$3(luvio, config) {
311
+ return keyPrefix + '::' + RepresentationType$1 + ':' + config.form_id;
312
+ }
313
+ function keyBuilderFromType$1(luvio, object) {
314
+ var keyParams = {
315
+ form_id: object.formId
316
+ };
317
+ return keyBuilder$3(luvio, keyParams);
318
+ }
319
+ function normalize$1(input, existing, path, luvio, store, timestamp) {
320
+ return input;
321
+ }
322
+ var select$4 = function FormRepresentationSelect() {
323
+ var _a = select$5(), FormFieldList__selections = _a.selections;
324
+ return {
325
+ kind: 'Fragment',
326
+ version: VERSION$1,
327
+ private: [],
328
+ selections: [
329
+ {
330
+ name: 'dataExtensionId',
331
+ kind: 'Scalar'
332
+ },
333
+ {
334
+ name: 'formFieldsList',
335
+ kind: 'Object',
336
+ selections: FormFieldList__selections
337
+ },
338
+ {
339
+ name: 'formId',
340
+ kind: 'Scalar'
341
+ },
342
+ {
343
+ name: 'formName',
344
+ kind: 'Scalar'
345
+ }
346
+ ]
347
+ };
348
+ };
349
+ function equals$1(existing, incoming) {
350
+ var existing_dataExtensionId = existing.dataExtensionId;
351
+ var incoming_dataExtensionId = incoming.dataExtensionId;
352
+ if (!(existing_dataExtensionId === incoming_dataExtensionId)) {
353
+ return false;
354
+ }
355
+ var existing_formId = existing.formId;
356
+ var incoming_formId = incoming.formId;
357
+ if (!(existing_formId === incoming_formId)) {
358
+ return false;
359
+ }
360
+ var existing_formName = existing.formName;
361
+ var incoming_formName = incoming.formName;
362
+ if (!(existing_formName === incoming_formName)) {
363
+ return false;
364
+ }
365
+ var existing_formFieldsList = existing.formFieldsList;
366
+ var incoming_formFieldsList = incoming.formFieldsList;
367
+ if (!(equals$2(existing_formFieldsList, incoming_formFieldsList))) {
368
+ return false;
369
+ }
370
+ return true;
371
+ }
372
+ var ingest$1 = function FormRepresentationIngest(input, path, luvio, store, timestamp) {
373
+ if (process.env.NODE_ENV !== 'production') {
374
+ var validateError = validate$4(input);
375
+ if (validateError !== null) {
376
+ throw validateError;
377
+ }
378
+ }
379
+ var key = keyBuilderFromType$1(luvio, input);
380
+ var existingRecord = store.readEntry(key);
381
+ var ttlToUse = TTL$1;
382
+ var incomingRecord = normalize$1(input, store.readEntry(key), {
383
+ fullPath: key,
384
+ parent: path.parent,
385
+ propertyName: path.propertyName,
386
+ ttl: ttlToUse
387
+ });
388
+ if (existingRecord === undefined || equals$1(existingRecord, incomingRecord) === false) {
389
+ luvio.storePublish(key, incomingRecord);
390
+ }
391
+ {
392
+ var storeMetadataParams = {
393
+ ttl: ttlToUse,
394
+ namespace: "marketing-integration",
395
+ version: VERSION$1,
396
+ representationName: RepresentationType$1,
397
+ };
398
+ luvio.publishStoreMetadata(key, storeMetadataParams);
399
+ }
400
+ return createLink(key);
401
+ };
402
+ function getTypeCacheKeys$1(luvio, input, fullPathFactory) {
403
+ var rootKeySet = new engine.StoreKeyMap();
404
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
405
+ var rootKey = keyBuilderFromType$1(luvio, input);
406
+ rootKeySet.set(rootKey, {
407
+ namespace: keyPrefix,
408
+ representationName: RepresentationType$1,
409
+ mergeable: false
410
+ });
411
+ return rootKeySet;
412
+ }
413
+
414
+ function select$3(luvio, params) {
415
+ return select$4();
416
+ }
417
+ function getResponseCacheKeys$2(luvio, resourceParams, response) {
418
+ return getTypeCacheKeys$1(luvio, response);
419
+ }
420
+ function ingestSuccess$2(luvio, resourceParams, response) {
421
+ var body = response.body;
422
+ var key = keyBuilderFromType$1(luvio, body);
423
+ luvio.storeIngest(key, ingest$1, body);
424
+ var snapshot = luvio.storeLookup({
425
+ recordId: key,
426
+ node: select$3(),
427
+ variables: {},
428
+ });
429
+ if (process.env.NODE_ENV !== 'production') {
430
+ if (snapshot.state !== 'Fulfilled') {
431
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
432
+ }
433
+ }
434
+ return snapshot;
435
+ }
436
+ function createResourceRequest$2(config) {
437
+ var headers = {};
438
+ return {
439
+ baseUri: '/services/data/v58.0',
440
+ basePath: '/sites/' + config.urlParams.siteId + '/marketing-integration/forms',
441
+ method: 'post',
442
+ body: config.body,
443
+ urlParams: config.urlParams,
444
+ queryParams: {},
445
+ headers: headers,
446
+ priority: 'normal',
447
+ };
448
+ }
449
+
450
+ var saveForm_ConfigPropertyNames = {
451
+ displayName: 'saveForm',
452
+ parameters: {
453
+ required: ['siteId', 'formInput'],
454
+ optional: []
455
+ }
456
+ };
457
+ function createResourceParams$2(config) {
458
+ var resourceParams = {
459
+ urlParams: {
460
+ siteId: config.siteId
461
+ },
462
+ body: {
463
+ formInput: config.formInput
464
+ }
465
+ };
466
+ return resourceParams;
467
+ }
468
+ function typeCheckConfig$2(untrustedConfig) {
469
+ var config = {};
470
+ var untrustedConfig_siteId = untrustedConfig.siteId;
471
+ if (typeof untrustedConfig_siteId === 'string') {
472
+ config.siteId = untrustedConfig_siteId;
473
+ }
474
+ var untrustedConfig_formInput = untrustedConfig.formInput;
475
+ var referenceFormInputRepresentationValidationError = validate$7(untrustedConfig_formInput);
476
+ if (referenceFormInputRepresentationValidationError === null) {
477
+ config.formInput = untrustedConfig_formInput;
478
+ }
479
+ return config;
480
+ }
481
+ function validateAdapterConfig$2(untrustedConfig, configPropertyNames) {
482
+ if (!untrustedIsObject(untrustedConfig)) {
483
+ return null;
484
+ }
485
+ if (process.env.NODE_ENV !== 'production') {
486
+ validateConfig(untrustedConfig, configPropertyNames);
487
+ }
488
+ var config = typeCheckConfig$2(untrustedConfig);
489
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
490
+ return null;
491
+ }
492
+ return config;
493
+ }
494
+ function buildNetworkSnapshot$2(luvio, config, options) {
495
+ var resourceParams = createResourceParams$2(config);
496
+ var request = createResourceRequest$2(resourceParams);
497
+ return luvio.dispatchResourceRequest(request, options)
498
+ .then(function (response) {
499
+ return luvio.handleSuccessResponse(function () {
500
+ var snapshot = ingestSuccess$2(luvio, resourceParams, response);
501
+ return luvio.storeBroadcast().then(function () { return snapshot; });
502
+ }, function () { return getResponseCacheKeys$2(luvio, resourceParams, response.body); });
503
+ }, function (response) {
504
+ deepFreeze(response);
505
+ throw response;
506
+ });
507
+ }
508
+ var saveFormAdapterFactory = function (luvio) {
509
+ return function saveForm(untrustedConfig) {
510
+ var config = validateAdapterConfig$2(untrustedConfig, saveForm_ConfigPropertyNames);
511
+ // Invalid or incomplete config
512
+ if (config === null) {
513
+ throw new Error('Invalid config for "saveForm"');
514
+ }
515
+ return buildNetworkSnapshot$2(luvio, config);
516
+ };
517
+ };
518
+
519
+ function select$2(luvio, params) {
520
+ return select$4();
521
+ }
522
+ function keyBuilder$2(luvio, params) {
523
+ return keyBuilder$3(luvio, {
524
+ form_id: params.urlParams.formId
525
+ });
526
+ }
527
+ function getResponseCacheKeys$1(luvio, resourceParams, response) {
528
+ return getTypeCacheKeys$1(luvio, response);
529
+ }
530
+ function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
531
+ var body = response.body;
532
+ var key = keyBuilder$2(luvio, resourceParams);
533
+ luvio.storeIngest(key, ingest$1, body);
534
+ var snapshot = luvio.storeLookup({
535
+ recordId: key,
536
+ node: select$2(),
537
+ variables: {},
538
+ }, snapshotRefresh);
539
+ if (process.env.NODE_ENV !== 'production') {
540
+ if (snapshot.state !== 'Fulfilled') {
541
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
542
+ }
543
+ }
544
+ return snapshot;
545
+ }
546
+ function ingestError(luvio, params, error, snapshotRefresh) {
547
+ var key = keyBuilder$2(luvio, params);
548
+ var errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
549
+ var storeMetadataParams = {
550
+ ttl: TTL$1,
551
+ namespace: keyPrefix,
552
+ version: VERSION$1,
553
+ representationName: RepresentationType$1
554
+ };
555
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
556
+ return errorSnapshot;
557
+ }
558
+ function createResourceRequest$1(config) {
559
+ var headers = {};
560
+ return {
561
+ baseUri: '/services/data/v58.0',
562
+ basePath: '/sites/' + config.urlParams.siteId + '/marketing-integration/forms/' + config.urlParams.formId + '',
563
+ method: 'get',
564
+ body: null,
565
+ urlParams: config.urlParams,
566
+ queryParams: {},
567
+ headers: headers,
568
+ priority: 'normal',
569
+ };
570
+ }
571
+
572
+ var getForm_ConfigPropertyNames = {
573
+ displayName: 'getForm',
574
+ parameters: {
575
+ required: ['formId', 'siteId'],
576
+ optional: []
577
+ }
578
+ };
579
+ function createResourceParams$1(config) {
580
+ var resourceParams = {
581
+ urlParams: {
582
+ formId: config.formId, siteId: config.siteId
583
+ }
584
+ };
585
+ return resourceParams;
586
+ }
587
+ function keyBuilder$1(luvio, config) {
588
+ var resourceParams = createResourceParams$1(config);
589
+ return keyBuilder$2(luvio, resourceParams);
590
+ }
591
+ function typeCheckConfig$1(untrustedConfig) {
592
+ var config = {};
593
+ var untrustedConfig_formId = untrustedConfig.formId;
594
+ if (typeof untrustedConfig_formId === 'string') {
595
+ config.formId = untrustedConfig_formId;
596
+ }
597
+ var untrustedConfig_siteId = untrustedConfig.siteId;
598
+ if (typeof untrustedConfig_siteId === 'string') {
599
+ config.siteId = untrustedConfig_siteId;
600
+ }
601
+ return config;
602
+ }
603
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
604
+ if (!untrustedIsObject(untrustedConfig)) {
605
+ return null;
606
+ }
607
+ if (process.env.NODE_ENV !== 'production') {
608
+ validateConfig(untrustedConfig, configPropertyNames);
609
+ }
610
+ var config = typeCheckConfig$1(untrustedConfig);
611
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
612
+ return null;
613
+ }
614
+ return config;
615
+ }
616
+ function adapterFragment(luvio, config) {
617
+ createResourceParams$1(config);
618
+ return select$2();
619
+ }
620
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
621
+ var snapshot = ingestSuccess$1(luvio, resourceParams, response, {
622
+ config: config,
623
+ resolve: function () { return buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions); }
624
+ });
625
+ return luvio.storeBroadcast().then(function () { return snapshot; });
626
+ }
627
+ function onFetchResponseError(luvio, config, resourceParams, response) {
628
+ var snapshot = ingestError(luvio, resourceParams, response, {
629
+ config: config,
630
+ resolve: function () { return buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions); }
631
+ });
632
+ return luvio.storeBroadcast().then(function () { return snapshot; });
633
+ }
634
+ function buildNetworkSnapshot$1(luvio, config, options) {
635
+ var resourceParams = createResourceParams$1(config);
636
+ var request = createResourceRequest$1(resourceParams);
637
+ return luvio.dispatchResourceRequest(request, options)
638
+ .then(function (response) {
639
+ return luvio.handleSuccessResponse(function () { return onFetchResponseSuccess(luvio, config, resourceParams, response); }, function () { return getResponseCacheKeys$1(luvio, resourceParams, response.body); });
640
+ }, function (response) {
641
+ return luvio.handleErrorResponse(function () { return onFetchResponseError(luvio, config, resourceParams, response); });
642
+ });
643
+ }
644
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
645
+ var luvio = context.luvio, config = context.config;
646
+ var networkPriority = coercedAdapterRequestContext.networkPriority, requestCorrelator = coercedAdapterRequestContext.requestCorrelator, eventObservers = coercedAdapterRequestContext.eventObservers;
647
+ var dispatchOptions = {
648
+ resourceRequestContext: {
649
+ requestCorrelator: requestCorrelator,
650
+ luvioRequestMethod: undefined,
651
+ },
652
+ eventObservers: eventObservers
653
+ };
654
+ if (networkPriority !== 'normal') {
655
+ dispatchOptions.overrides = {
656
+ priority: networkPriority
657
+ };
658
+ }
659
+ return buildNetworkSnapshot$1(luvio, config, dispatchOptions);
660
+ }
661
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
662
+ var luvio = context.luvio, config = context.config;
663
+ var selector = {
664
+ recordId: keyBuilder$1(luvio, config),
665
+ node: adapterFragment(luvio, config),
666
+ variables: {},
667
+ };
668
+ var cacheSnapshot = storeLookup(selector, {
669
+ config: config,
670
+ resolve: function () { return buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions); }
671
+ });
672
+ return cacheSnapshot;
673
+ }
674
+ var getFormAdapterFactory = function (luvio) { return function marketingIntegration__getForm(untrustedConfig, requestContext) {
675
+ var config = validateAdapterConfig$1(untrustedConfig, getForm_ConfigPropertyNames);
676
+ // Invalid or incomplete config
677
+ if (config === null) {
678
+ return null;
679
+ }
680
+ return luvio.applyCachePolicy((requestContext || {}), { config: config, luvio: luvio }, // BuildSnapshotContext
681
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
682
+ }; };
683
+
684
+ function validate$3(obj, path) {
685
+ if (path === void 0) { path = 'FormSubmissionFieldInputRepresentation'; }
686
+ var v_error = (function () {
687
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
688
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
689
+ }
690
+ var obj_name = obj.name;
691
+ var path_name = path + '.name';
692
+ if (typeof obj_name !== 'string') {
693
+ return new TypeError('Expected "string" but received "' + typeof obj_name + '" (at "' + path_name + '")');
694
+ }
695
+ var obj_value = obj.value;
696
+ var path_value = path + '.value';
697
+ if (typeof obj_value !== 'string') {
698
+ return new TypeError('Expected "string" but received "' + typeof obj_value + '" (at "' + path_value + '")');
699
+ }
700
+ })();
701
+ return v_error === undefined ? null : v_error;
702
+ }
703
+
704
+ function validate$2(obj, path) {
705
+ if (path === void 0) { path = 'FormSubmissionFieldInputList'; }
706
+ var v_error = (function () {
707
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
708
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
709
+ }
710
+ var obj_formFields = obj.formFields;
711
+ var path_formFields = path + '.formFields';
712
+ if (!ArrayIsArray(obj_formFields)) {
713
+ return new TypeError('Expected "array" but received "' + typeof obj_formFields + '" (at "' + path_formFields + '")');
714
+ }
715
+ for (var i = 0; i < obj_formFields.length; i++) {
716
+ var obj_formFields_item = obj_formFields[i];
717
+ var path_formFields_item = path_formFields + '[' + i + ']';
718
+ var referencepath_formFields_itemValidationError = validate$3(obj_formFields_item, path_formFields_item);
719
+ if (referencepath_formFields_itemValidationError !== null) {
720
+ var message = 'Object doesn\'t match FormSubmissionFieldInputRepresentation (at "' + path_formFields_item + '")\n';
721
+ message += referencepath_formFields_itemValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
722
+ return new TypeError(message);
723
+ }
724
+ }
725
+ })();
726
+ return v_error === undefined ? null : v_error;
727
+ }
728
+
729
+ function validate$1(obj, path) {
730
+ if (path === void 0) { path = 'FormSubmissionInputRepresentation'; }
731
+ var v_error = (function () {
732
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
733
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
734
+ }
735
+ var obj_formFieldsList = obj.formFieldsList;
736
+ var path_formFieldsList = path + '.formFieldsList';
737
+ var referencepath_formFieldsListValidationError = validate$2(obj_formFieldsList, path_formFieldsList);
738
+ if (referencepath_formFieldsListValidationError !== null) {
739
+ var message = 'Object doesn\'t match FormSubmissionFieldInputList (at "' + path_formFieldsList + '")\n';
740
+ message += referencepath_formFieldsListValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
741
+ return new TypeError(message);
742
+ }
743
+ })();
744
+ return v_error === undefined ? null : v_error;
745
+ }
746
+
747
+ var TTL = 100;
748
+ var VERSION = "0e1b8658b45a13a4f914328ee63d79fc";
749
+ function validate(obj, path) {
750
+ if (path === void 0) { path = 'FormSubmissionRepresentation'; }
751
+ var v_error = (function () {
752
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
753
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
754
+ }
755
+ var obj_formSubmissionId = obj.formSubmissionId;
756
+ var path_formSubmissionId = path + '.formSubmissionId';
757
+ if (typeof obj_formSubmissionId !== 'string') {
758
+ return new TypeError('Expected "string" but received "' + typeof obj_formSubmissionId + '" (at "' + path_formSubmissionId + '")');
759
+ }
760
+ })();
761
+ return v_error === undefined ? null : v_error;
762
+ }
763
+ var RepresentationType = 'FormSubmissionRepresentation';
764
+ function keyBuilder(luvio, config) {
765
+ return keyPrefix + '::' + RepresentationType + ':' + config.form_submission_id;
766
+ }
767
+ function keyBuilderFromType(luvio, object) {
768
+ var keyParams = {
769
+ form_submission_id: object.formSubmissionId
770
+ };
771
+ return keyBuilder(luvio, keyParams);
772
+ }
773
+ function normalize(input, existing, path, luvio, store, timestamp) {
774
+ return input;
775
+ }
776
+ var select$1 = function FormSubmissionRepresentationSelect() {
777
+ return {
778
+ kind: 'Fragment',
779
+ version: VERSION,
780
+ private: [],
781
+ selections: [
782
+ {
783
+ name: 'formSubmissionId',
784
+ kind: 'Scalar'
785
+ }
786
+ ]
787
+ };
788
+ };
789
+ function equals(existing, incoming) {
790
+ var existing_formSubmissionId = existing.formSubmissionId;
791
+ var incoming_formSubmissionId = incoming.formSubmissionId;
792
+ if (!(existing_formSubmissionId === incoming_formSubmissionId)) {
793
+ return false;
794
+ }
795
+ return true;
796
+ }
797
+ var ingest = function FormSubmissionRepresentationIngest(input, path, luvio, store, timestamp) {
798
+ if (process.env.NODE_ENV !== 'production') {
799
+ var validateError = validate(input);
800
+ if (validateError !== null) {
801
+ throw validateError;
802
+ }
803
+ }
804
+ var key = keyBuilderFromType(luvio, input);
805
+ var existingRecord = store.readEntry(key);
806
+ var ttlToUse = TTL;
807
+ var incomingRecord = normalize(input, store.readEntry(key), {
808
+ fullPath: key,
809
+ parent: path.parent,
810
+ propertyName: path.propertyName,
811
+ ttl: ttlToUse
812
+ });
813
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
814
+ luvio.storePublish(key, incomingRecord);
815
+ }
816
+ {
817
+ var storeMetadataParams = {
818
+ ttl: ttlToUse,
819
+ namespace: "marketing-integration",
820
+ version: VERSION,
821
+ representationName: RepresentationType,
822
+ };
823
+ luvio.publishStoreMetadata(key, storeMetadataParams);
824
+ }
825
+ return createLink(key);
826
+ };
827
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
828
+ var rootKeySet = new engine.StoreKeyMap();
829
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
830
+ var rootKey = keyBuilderFromType(luvio, input);
831
+ rootKeySet.set(rootKey, {
832
+ namespace: keyPrefix,
833
+ representationName: RepresentationType,
834
+ mergeable: false
835
+ });
836
+ return rootKeySet;
837
+ }
838
+
839
+ function select(luvio, params) {
840
+ return select$1();
841
+ }
842
+ function getResponseCacheKeys(luvio, resourceParams, response) {
843
+ return getTypeCacheKeys(luvio, response);
844
+ }
845
+ function ingestSuccess(luvio, resourceParams, response) {
846
+ var body = response.body;
847
+ var key = keyBuilderFromType(luvio, body);
848
+ luvio.storeIngest(key, ingest, body);
849
+ var snapshot = luvio.storeLookup({
850
+ recordId: key,
851
+ node: select(),
852
+ variables: {},
853
+ });
854
+ if (process.env.NODE_ENV !== 'production') {
855
+ if (snapshot.state !== 'Fulfilled') {
856
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
857
+ }
858
+ }
859
+ return snapshot;
860
+ }
861
+ function createResourceRequest(config) {
862
+ var headers = {};
863
+ return {
864
+ baseUri: '/services/data/v58.0',
865
+ basePath: '/sites/' + config.urlParams.siteId + '/marketing-integration/forms/' + config.urlParams.formId + '/data',
866
+ method: 'post',
867
+ body: config.body,
868
+ urlParams: config.urlParams,
869
+ queryParams: {},
870
+ headers: headers,
871
+ priority: 'normal',
872
+ };
873
+ }
874
+
875
+ var submitForm_ConfigPropertyNames = {
876
+ displayName: 'submitForm',
877
+ parameters: {
878
+ required: ['formId', 'siteId', 'formSubmissionInput'],
879
+ optional: []
880
+ }
881
+ };
882
+ function createResourceParams(config) {
883
+ var resourceParams = {
884
+ urlParams: {
885
+ formId: config.formId, siteId: config.siteId
886
+ },
887
+ body: {
888
+ formSubmissionInput: config.formSubmissionInput
889
+ }
890
+ };
891
+ return resourceParams;
892
+ }
893
+ function typeCheckConfig(untrustedConfig) {
894
+ var config = {};
895
+ var untrustedConfig_formId = untrustedConfig.formId;
896
+ if (typeof untrustedConfig_formId === 'string') {
897
+ config.formId = untrustedConfig_formId;
898
+ }
899
+ var untrustedConfig_siteId = untrustedConfig.siteId;
900
+ if (typeof untrustedConfig_siteId === 'string') {
901
+ config.siteId = untrustedConfig_siteId;
902
+ }
903
+ var untrustedConfig_formSubmissionInput = untrustedConfig.formSubmissionInput;
904
+ var referenceFormSubmissionInputRepresentationValidationError = validate$1(untrustedConfig_formSubmissionInput);
905
+ if (referenceFormSubmissionInputRepresentationValidationError === null) {
906
+ config.formSubmissionInput = untrustedConfig_formSubmissionInput;
907
+ }
908
+ return config;
909
+ }
910
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
911
+ if (!untrustedIsObject(untrustedConfig)) {
912
+ return null;
913
+ }
914
+ if (process.env.NODE_ENV !== 'production') {
915
+ validateConfig(untrustedConfig, configPropertyNames);
916
+ }
917
+ var config = typeCheckConfig(untrustedConfig);
918
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
919
+ return null;
920
+ }
921
+ return config;
922
+ }
923
+ function buildNetworkSnapshot(luvio, config, options) {
924
+ var resourceParams = createResourceParams(config);
925
+ var request = createResourceRequest(resourceParams);
926
+ return luvio.dispatchResourceRequest(request, options)
927
+ .then(function (response) {
928
+ return luvio.handleSuccessResponse(function () {
929
+ var snapshot = ingestSuccess(luvio, resourceParams, response);
930
+ return luvio.storeBroadcast().then(function () { return snapshot; });
931
+ }, function () { return getResponseCacheKeys(luvio, resourceParams, response.body); });
932
+ }, function (response) {
933
+ deepFreeze(response);
934
+ throw response;
935
+ });
936
+ }
937
+ var submitFormAdapterFactory = function (luvio) {
938
+ return function submitForm(untrustedConfig) {
939
+ var config = validateAdapterConfig(untrustedConfig, submitForm_ConfigPropertyNames);
940
+ // Invalid or incomplete config
941
+ if (config === null) {
942
+ throw new Error('Invalid config for "submitForm"');
943
+ }
944
+ return buildNetworkSnapshot(luvio, config);
945
+ };
946
+ };
947
+
948
+ exports.getFormAdapterFactory = getFormAdapterFactory;
949
+ exports.saveFormAdapterFactory = saveFormAdapterFactory;
950
+ exports.submitFormAdapterFactory = submitFormAdapterFactory;
951
+
952
+ Object.defineProperty(exports, '__esModule', { value: true });
953
+
954
+ }));