@salesforce/lds-adapters-marketing-ai4m 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 (24) hide show
  1. package/LICENSE.txt +82 -0
  2. package/dist/es/es2018/marketing-ai4m.js +791 -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/createContent.d.ts +33 -0
  5. package/dist/es/es2018/types/src/generated/adapters/modifyContent.d.ts +34 -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 +3 -0
  8. package/dist/es/es2018/types/src/generated/resources/postConnectAi4mEinsteinContent.d.ts +30 -0
  9. package/dist/es/es2018/types/src/generated/resources/postConnectAi4mEinsteinContentModification.d.ts +31 -0
  10. package/dist/es/es2018/types/src/generated/types/AudienceRepresentation.d.ts +31 -0
  11. package/dist/es/es2018/types/src/generated/types/CampaignBriefRepresentation.d.ts +49 -0
  12. package/dist/es/es2018/types/src/generated/types/CreateContentInputRepresentation.d.ts +77 -0
  13. package/dist/es/es2018/types/src/generated/types/CreateContentResponseRepresentation.d.ts +41 -0
  14. package/dist/es/es2018/types/src/generated/types/GenerativeContentInputRepresentation.d.ts +34 -0
  15. package/dist/es/es2018/types/src/generated/types/GenerativeContentRepresentation.d.ts +34 -0
  16. package/dist/es/es2018/types/src/generated/types/ModifyContentInputRepresentation.d.ts +80 -0
  17. package/dist/es/es2018/types/src/generated/types/ModifyContentResponseRepresentation.d.ts +44 -0
  18. package/dist/es/es2018/types/src/generated/types/SampleAssetsRepresentation.d.ts +28 -0
  19. package/dist/es/es2018/types/src/generated/types/type-utils.d.ts +32 -0
  20. package/package.json +67 -0
  21. package/sfdc/index.d.ts +1 -0
  22. package/sfdc/index.js +821 -0
  23. package/src/raml/api.raml +300 -0
  24. package/src/raml/luvio.raml +26 -0
@@ -0,0 +1,791 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ import { serializeStructuredKey, ingestShape, deepFreeze, StoreKeyMap, createResourceParams as createResourceParams$2, typeCheckConfig as typeCheckConfig$2 } 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
+ function generateParamConfigMetadata(name, required, resourceType, typeCheckShape, isArrayShape = false, coerceFn) {
45
+ return {
46
+ name,
47
+ required,
48
+ resourceType,
49
+ typeCheckShape,
50
+ isArrayShape,
51
+ coerceFn,
52
+ };
53
+ }
54
+ function buildAdapterValidationConfig(displayName, paramsMeta) {
55
+ const required = paramsMeta.filter(p => p.required).map(p => p.name);
56
+ const optional = paramsMeta.filter(p => !p.required).map(p => p.name);
57
+ return {
58
+ displayName,
59
+ parameters: {
60
+ required,
61
+ optional,
62
+ }
63
+ };
64
+ }
65
+ const keyPrefix = 'marketing-ai4m';
66
+
67
+ const { isArray: ArrayIsArray } = Array;
68
+ function equalsArray(a, b, equalsItem) {
69
+ const aLength = a.length;
70
+ const bLength = b.length;
71
+ if (aLength !== bLength) {
72
+ return false;
73
+ }
74
+ for (let i = 0; i < aLength; i++) {
75
+ if (equalsItem(a[i], b[i]) === false) {
76
+ return false;
77
+ }
78
+ }
79
+ return true;
80
+ }
81
+ function createLink(ref) {
82
+ return {
83
+ __ref: serializeStructuredKey(ref),
84
+ };
85
+ }
86
+
87
+ function validate$3(obj, path = 'AudienceRepresentation') {
88
+ const v_error = (() => {
89
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
90
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
91
+ }
92
+ const obj_description = obj.description;
93
+ const path_description = path + '.description';
94
+ if (typeof obj_description !== 'string') {
95
+ return new TypeError('Expected "string" but received "' + typeof obj_description + '" (at "' + path_description + '")');
96
+ }
97
+ const obj_name = obj.name;
98
+ const path_name = path + '.name';
99
+ if (typeof obj_name !== 'string') {
100
+ return new TypeError('Expected "string" but received "' + typeof obj_name + '" (at "' + path_name + '")');
101
+ }
102
+ })();
103
+ return v_error === undefined ? null : v_error;
104
+ }
105
+
106
+ const VERSION$2 = "1232dcab606e55292ad273ab0803544a";
107
+ function validate$2(obj, path = 'GenerativeContentRepresentation') {
108
+ const v_error = (() => {
109
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
110
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
111
+ }
112
+ const obj_paragraph = obj.paragraph;
113
+ const path_paragraph = path + '.paragraph';
114
+ if (!ArrayIsArray(obj_paragraph)) {
115
+ return new TypeError('Expected "array" but received "' + typeof obj_paragraph + '" (at "' + path_paragraph + '")');
116
+ }
117
+ for (let i = 0; i < obj_paragraph.length; i++) {
118
+ const obj_paragraph_item = obj_paragraph[i];
119
+ const path_paragraph_item = path_paragraph + '[' + i + ']';
120
+ if (typeof obj_paragraph_item !== 'string') {
121
+ return new TypeError('Expected "string" but received "' + typeof obj_paragraph_item + '" (at "' + path_paragraph_item + '")');
122
+ }
123
+ }
124
+ const obj_preheader = obj.preheader;
125
+ const path_preheader = path + '.preheader';
126
+ if (!ArrayIsArray(obj_preheader)) {
127
+ return new TypeError('Expected "array" but received "' + typeof obj_preheader + '" (at "' + path_preheader + '")');
128
+ }
129
+ for (let i = 0; i < obj_preheader.length; i++) {
130
+ const obj_preheader_item = obj_preheader[i];
131
+ const path_preheader_item = path_preheader + '[' + i + ']';
132
+ if (typeof obj_preheader_item !== 'string') {
133
+ return new TypeError('Expected "string" but received "' + typeof obj_preheader_item + '" (at "' + path_preheader_item + '")');
134
+ }
135
+ }
136
+ const obj_subjectLine = obj.subjectLine;
137
+ const path_subjectLine = path + '.subjectLine';
138
+ if (!ArrayIsArray(obj_subjectLine)) {
139
+ return new TypeError('Expected "array" but received "' + typeof obj_subjectLine + '" (at "' + path_subjectLine + '")');
140
+ }
141
+ for (let i = 0; i < obj_subjectLine.length; i++) {
142
+ const obj_subjectLine_item = obj_subjectLine[i];
143
+ const path_subjectLine_item = path_subjectLine + '[' + i + ']';
144
+ if (typeof obj_subjectLine_item !== 'string') {
145
+ return new TypeError('Expected "string" but received "' + typeof obj_subjectLine_item + '" (at "' + path_subjectLine_item + '")');
146
+ }
147
+ }
148
+ })();
149
+ return v_error === undefined ? null : v_error;
150
+ }
151
+ const select$4 = function GenerativeContentRepresentationSelect() {
152
+ return {
153
+ kind: 'Fragment',
154
+ version: VERSION$2,
155
+ private: [],
156
+ selections: [
157
+ {
158
+ name: 'paragraph',
159
+ kind: 'Scalar',
160
+ plural: true
161
+ },
162
+ {
163
+ name: 'preheader',
164
+ kind: 'Scalar',
165
+ plural: true
166
+ },
167
+ {
168
+ name: 'subjectLine',
169
+ kind: 'Scalar',
170
+ plural: true
171
+ }
172
+ ]
173
+ };
174
+ };
175
+ function equals$2(existing, incoming) {
176
+ const existing_paragraph = existing.paragraph;
177
+ const incoming_paragraph = incoming.paragraph;
178
+ const equals_paragraph_items = equalsArray(existing_paragraph, incoming_paragraph, (existing_paragraph_item, incoming_paragraph_item) => {
179
+ if (!(existing_paragraph_item === incoming_paragraph_item)) {
180
+ return false;
181
+ }
182
+ });
183
+ if (equals_paragraph_items === false) {
184
+ return false;
185
+ }
186
+ const existing_preheader = existing.preheader;
187
+ const incoming_preheader = incoming.preheader;
188
+ const equals_preheader_items = equalsArray(existing_preheader, incoming_preheader, (existing_preheader_item, incoming_preheader_item) => {
189
+ if (!(existing_preheader_item === incoming_preheader_item)) {
190
+ return false;
191
+ }
192
+ });
193
+ if (equals_preheader_items === false) {
194
+ return false;
195
+ }
196
+ const existing_subjectLine = existing.subjectLine;
197
+ const incoming_subjectLine = incoming.subjectLine;
198
+ const equals_subjectLine_items = equalsArray(existing_subjectLine, incoming_subjectLine, (existing_subjectLine_item, incoming_subjectLine_item) => {
199
+ if (!(existing_subjectLine_item === incoming_subjectLine_item)) {
200
+ return false;
201
+ }
202
+ });
203
+ if (equals_subjectLine_items === false) {
204
+ return false;
205
+ }
206
+ return true;
207
+ }
208
+
209
+ const TTL$1 = 300;
210
+ const VERSION$1 = "94da8161f671000cc0bd34c8e37cb065";
211
+ function validate$1(obj, path = 'CreateContentResponseRepresentation') {
212
+ const v_error = (() => {
213
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
214
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
215
+ }
216
+ const obj_content = obj.content;
217
+ const path_content = path + '.content';
218
+ const referencepath_contentValidationError = validate$2(obj_content, path_content);
219
+ if (referencepath_contentValidationError !== null) {
220
+ let message = 'Object doesn\'t match GenerativeContentRepresentation (at "' + path_content + '")\n';
221
+ message += referencepath_contentValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
222
+ return new TypeError(message);
223
+ }
224
+ const obj_generationId = obj.generationId;
225
+ const path_generationId = path + '.generationId';
226
+ if (typeof obj_generationId !== 'string') {
227
+ return new TypeError('Expected "string" but received "' + typeof obj_generationId + '" (at "' + path_generationId + '")');
228
+ }
229
+ })();
230
+ return v_error === undefined ? null : v_error;
231
+ }
232
+ const RepresentationType$1 = 'CreateContentResponseRepresentation';
233
+ function keyBuilder$1(luvio, config) {
234
+ return keyPrefix + '::' + RepresentationType$1 + ':' + config.generationId;
235
+ }
236
+ function keyBuilderFromType$1(luvio, object) {
237
+ const keyParams = {
238
+ generationId: object.generationId
239
+ };
240
+ return keyBuilder$1(luvio, keyParams);
241
+ }
242
+ function normalize$1(input, existing, path, luvio, store, timestamp) {
243
+ return input;
244
+ }
245
+ const select$3 = function CreateContentResponseRepresentationSelect() {
246
+ const { selections: GenerativeContentRepresentation__selections, opaque: GenerativeContentRepresentation__opaque, } = select$4();
247
+ return {
248
+ kind: 'Fragment',
249
+ version: VERSION$1,
250
+ private: [],
251
+ selections: [
252
+ {
253
+ name: 'content',
254
+ kind: 'Object',
255
+ selections: GenerativeContentRepresentation__selections
256
+ },
257
+ {
258
+ name: 'generationId',
259
+ kind: 'Scalar'
260
+ }
261
+ ]
262
+ };
263
+ };
264
+ function equals$1(existing, incoming) {
265
+ const existing_generationId = existing.generationId;
266
+ const incoming_generationId = incoming.generationId;
267
+ if (!(existing_generationId === incoming_generationId)) {
268
+ return false;
269
+ }
270
+ const existing_content = existing.content;
271
+ const incoming_content = incoming.content;
272
+ if (!(equals$2(existing_content, incoming_content))) {
273
+ return false;
274
+ }
275
+ return true;
276
+ }
277
+ const ingest$1 = function CreateContentResponseRepresentationIngest(input, path, luvio, store, timestamp) {
278
+ if (process.env.NODE_ENV !== 'production') {
279
+ const validateError = validate$1(input);
280
+ if (validateError !== null) {
281
+ throw validateError;
282
+ }
283
+ }
284
+ const key = keyBuilderFromType$1(luvio, input);
285
+ const ttlToUse = TTL$1;
286
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$1, "marketing-ai4m", VERSION$1, RepresentationType$1, equals$1);
287
+ return createLink(key);
288
+ };
289
+ function getTypeCacheKeys$1(rootKeySet, luvio, input, fullPathFactory) {
290
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
291
+ const rootKey = keyBuilderFromType$1(luvio, input);
292
+ rootKeySet.set(rootKey, {
293
+ namespace: keyPrefix,
294
+ representationName: RepresentationType$1,
295
+ mergeable: false
296
+ });
297
+ }
298
+
299
+ function select$2(luvio, params) {
300
+ return select$3();
301
+ }
302
+ function getResponseCacheKeys$1(storeKeyMap, luvio, resourceParams, response) {
303
+ getTypeCacheKeys$1(storeKeyMap, luvio, response);
304
+ }
305
+ function ingestSuccess$1(luvio, resourceParams, response) {
306
+ const { body } = response;
307
+ const key = keyBuilderFromType$1(luvio, body);
308
+ luvio.storeIngest(key, ingest$1, body);
309
+ const snapshot = luvio.storeLookup({
310
+ recordId: key,
311
+ node: select$2(),
312
+ variables: {},
313
+ });
314
+ if (process.env.NODE_ENV !== 'production') {
315
+ if (snapshot.state !== 'Fulfilled') {
316
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
317
+ }
318
+ }
319
+ deepFreeze(snapshot.data);
320
+ return snapshot;
321
+ }
322
+ function createResourceRequest$1(config) {
323
+ const headers = {};
324
+ return {
325
+ baseUri: '/services/data/v66.0',
326
+ basePath: '/connect/ai4m/einstein/content',
327
+ method: 'post',
328
+ body: config.body,
329
+ urlParams: {},
330
+ queryParams: {},
331
+ headers,
332
+ priority: 'normal',
333
+ };
334
+ }
335
+
336
+ const adapterName$1 = 'createContent';
337
+ const createContent_ConfigPropertyMetadata = [
338
+ generateParamConfigMetadata('brief', true, 2 /* Body */, 4 /* Unsupported */),
339
+ generateParamConfigMetadata('contentTypes', true, 2 /* Body */, 0 /* String */, true),
340
+ generateParamConfigMetadata('result', true, 2 /* Body */, 3 /* Integer */),
341
+ ];
342
+ const createContent_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, createContent_ConfigPropertyMetadata);
343
+ const createResourceParams$1 = /*#__PURE__*/ createResourceParams$2(createContent_ConfigPropertyMetadata);
344
+ function typeCheckConfig$1(untrustedConfig) {
345
+ const config = {};
346
+ typeCheckConfig$2(untrustedConfig, config, createContent_ConfigPropertyMetadata);
347
+ const untrustedConfig_brief = untrustedConfig.brief;
348
+ if (untrustedIsObject(untrustedConfig_brief)) {
349
+ const untrustedConfig_brief_object = {};
350
+ const untrustedConfig_brief_audience = untrustedConfig_brief.audience;
351
+ if (ArrayIsArray$1(untrustedConfig_brief_audience)) {
352
+ const untrustedConfig_brief_audience_array = [];
353
+ for (let i = 0, arrayLength = untrustedConfig_brief_audience.length; i < arrayLength; i++) {
354
+ const untrustedConfig_brief_audience_item = untrustedConfig_brief_audience[i];
355
+ const referenceAudienceRepresentationValidationError = validate$3(untrustedConfig_brief_audience_item);
356
+ if (referenceAudienceRepresentationValidationError === null) {
357
+ untrustedConfig_brief_audience_array.push(untrustedConfig_brief_audience_item);
358
+ }
359
+ }
360
+ untrustedConfig_brief_object.audience = untrustedConfig_brief_audience_array;
361
+ }
362
+ const untrustedConfig_brief_campaignGoals = untrustedConfig_brief.campaignGoals;
363
+ if (ArrayIsArray$1(untrustedConfig_brief_campaignGoals)) {
364
+ const untrustedConfig_brief_campaignGoals_array = [];
365
+ for (let i = 0, arrayLength = untrustedConfig_brief_campaignGoals.length; i < arrayLength; i++) {
366
+ const untrustedConfig_brief_campaignGoals_item = untrustedConfig_brief_campaignGoals[i];
367
+ if (typeof untrustedConfig_brief_campaignGoals_item === 'string') {
368
+ untrustedConfig_brief_campaignGoals_array.push(untrustedConfig_brief_campaignGoals_item);
369
+ }
370
+ }
371
+ untrustedConfig_brief_object.campaignGoals = untrustedConfig_brief_campaignGoals_array;
372
+ }
373
+ const untrustedConfig_brief_campaignName = untrustedConfig_brief.campaignName;
374
+ if (typeof untrustedConfig_brief_campaignName === 'string') {
375
+ untrustedConfig_brief_object.campaignName = untrustedConfig_brief_campaignName;
376
+ }
377
+ const untrustedConfig_brief_campaignObjective = untrustedConfig_brief.campaignObjective;
378
+ if (typeof untrustedConfig_brief_campaignObjective === 'string') {
379
+ untrustedConfig_brief_object.campaignObjective = untrustedConfig_brief_campaignObjective;
380
+ }
381
+ const untrustedConfig_brief_channels = untrustedConfig_brief.channels;
382
+ if (ArrayIsArray$1(untrustedConfig_brief_channels)) {
383
+ const untrustedConfig_brief_channels_array = [];
384
+ for (let i = 0, arrayLength = untrustedConfig_brief_channels.length; i < arrayLength; i++) {
385
+ const untrustedConfig_brief_channels_item = untrustedConfig_brief_channels[i];
386
+ if (typeof untrustedConfig_brief_channels_item === 'string') {
387
+ untrustedConfig_brief_channels_array.push(untrustedConfig_brief_channels_item);
388
+ }
389
+ }
390
+ untrustedConfig_brief_object.channels = untrustedConfig_brief_channels_array;
391
+ }
392
+ const untrustedConfig_brief_keyMessage = untrustedConfig_brief.keyMessage;
393
+ if (typeof untrustedConfig_brief_keyMessage === 'string') {
394
+ untrustedConfig_brief_object.keyMessage = untrustedConfig_brief_keyMessage;
395
+ }
396
+ const untrustedConfig_brief_sampleAssets = untrustedConfig_brief.sampleAssets;
397
+ if (untrustedIsObject(untrustedConfig_brief_sampleAssets)) {
398
+ const untrustedConfig_brief_sampleAssets_object = {};
399
+ const untrustedConfig_brief_sampleAssets_email = untrustedConfig_brief_sampleAssets.email;
400
+ if (untrustedIsObject(untrustedConfig_brief_sampleAssets_email)) {
401
+ const untrustedConfig_brief_sampleAssets_email_object = {};
402
+ const untrustedConfig_brief_sampleAssets_email_paragraph = untrustedConfig_brief_sampleAssets_email.paragraph;
403
+ if (ArrayIsArray$1(untrustedConfig_brief_sampleAssets_email_paragraph)) {
404
+ const untrustedConfig_brief_sampleAssets_email_paragraph_array = [];
405
+ for (let i = 0, arrayLength = untrustedConfig_brief_sampleAssets_email_paragraph.length; i < arrayLength; i++) {
406
+ const untrustedConfig_brief_sampleAssets_email_paragraph_item = untrustedConfig_brief_sampleAssets_email_paragraph[i];
407
+ if (typeof untrustedConfig_brief_sampleAssets_email_paragraph_item === 'string') {
408
+ untrustedConfig_brief_sampleAssets_email_paragraph_array.push(untrustedConfig_brief_sampleAssets_email_paragraph_item);
409
+ }
410
+ }
411
+ untrustedConfig_brief_sampleAssets_email_object.paragraph = untrustedConfig_brief_sampleAssets_email_paragraph_array;
412
+ }
413
+ const untrustedConfig_brief_sampleAssets_email_preheader = untrustedConfig_brief_sampleAssets_email.preheader;
414
+ if (ArrayIsArray$1(untrustedConfig_brief_sampleAssets_email_preheader)) {
415
+ const untrustedConfig_brief_sampleAssets_email_preheader_array = [];
416
+ for (let i = 0, arrayLength = untrustedConfig_brief_sampleAssets_email_preheader.length; i < arrayLength; i++) {
417
+ const untrustedConfig_brief_sampleAssets_email_preheader_item = untrustedConfig_brief_sampleAssets_email_preheader[i];
418
+ if (typeof untrustedConfig_brief_sampleAssets_email_preheader_item === 'string') {
419
+ untrustedConfig_brief_sampleAssets_email_preheader_array.push(untrustedConfig_brief_sampleAssets_email_preheader_item);
420
+ }
421
+ }
422
+ untrustedConfig_brief_sampleAssets_email_object.preheader = untrustedConfig_brief_sampleAssets_email_preheader_array;
423
+ }
424
+ const untrustedConfig_brief_sampleAssets_email_subjectLine = untrustedConfig_brief_sampleAssets_email.subjectLine;
425
+ if (ArrayIsArray$1(untrustedConfig_brief_sampleAssets_email_subjectLine)) {
426
+ const untrustedConfig_brief_sampleAssets_email_subjectLine_array = [];
427
+ for (let i = 0, arrayLength = untrustedConfig_brief_sampleAssets_email_subjectLine.length; i < arrayLength; i++) {
428
+ const untrustedConfig_brief_sampleAssets_email_subjectLine_item = untrustedConfig_brief_sampleAssets_email_subjectLine[i];
429
+ if (typeof untrustedConfig_brief_sampleAssets_email_subjectLine_item === 'string') {
430
+ untrustedConfig_brief_sampleAssets_email_subjectLine_array.push(untrustedConfig_brief_sampleAssets_email_subjectLine_item);
431
+ }
432
+ }
433
+ untrustedConfig_brief_sampleAssets_email_object.subjectLine = untrustedConfig_brief_sampleAssets_email_subjectLine_array;
434
+ }
435
+ if (untrustedConfig_brief_sampleAssets_email_object !== undefined && Object.keys(untrustedConfig_brief_sampleAssets_email_object).length >= 0) {
436
+ untrustedConfig_brief_sampleAssets_object.email = untrustedConfig_brief_sampleAssets_email_object;
437
+ }
438
+ }
439
+ if (untrustedConfig_brief_sampleAssets_object !== undefined && Object.keys(untrustedConfig_brief_sampleAssets_object).length >= 0) {
440
+ untrustedConfig_brief_object.sampleAssets = untrustedConfig_brief_sampleAssets_object;
441
+ }
442
+ }
443
+ const untrustedConfig_brief_tone = untrustedConfig_brief.tone;
444
+ if (typeof untrustedConfig_brief_tone === 'string') {
445
+ untrustedConfig_brief_object.tone = untrustedConfig_brief_tone;
446
+ }
447
+ if (untrustedConfig_brief_object !== undefined && Object.keys(untrustedConfig_brief_object).length >= 0) {
448
+ config.brief = untrustedConfig_brief_object;
449
+ }
450
+ }
451
+ return config;
452
+ }
453
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
454
+ if (!untrustedIsObject(untrustedConfig)) {
455
+ return null;
456
+ }
457
+ if (process.env.NODE_ENV !== 'production') {
458
+ validateConfig(untrustedConfig, configPropertyNames);
459
+ }
460
+ const config = typeCheckConfig$1(untrustedConfig);
461
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
462
+ return null;
463
+ }
464
+ return config;
465
+ }
466
+ function buildNetworkSnapshot$1(luvio, config, options) {
467
+ const resourceParams = createResourceParams$1(config);
468
+ const request = createResourceRequest$1(resourceParams);
469
+ return luvio.dispatchResourceRequest(request, options)
470
+ .then((response) => {
471
+ return luvio.handleSuccessResponse(() => {
472
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response);
473
+ return luvio.storeBroadcast().then(() => snapshot);
474
+ }, () => {
475
+ const cache = new StoreKeyMap();
476
+ getResponseCacheKeys$1(cache, luvio, resourceParams, response.body);
477
+ return cache;
478
+ });
479
+ }, (response) => {
480
+ deepFreeze(response);
481
+ throw response;
482
+ });
483
+ }
484
+ const createContentAdapterFactory = (luvio) => {
485
+ return function createContent(untrustedConfig) {
486
+ const config = validateAdapterConfig$1(untrustedConfig, createContent_ConfigPropertyNames);
487
+ // Invalid or incomplete config
488
+ if (config === null) {
489
+ throw new Error('Invalid config for "createContent"');
490
+ }
491
+ return buildNetworkSnapshot$1(luvio, config);
492
+ };
493
+ };
494
+
495
+ const TTL = 300;
496
+ const VERSION = "0fbe4ed1fc1fed1bd5374cde5902260b";
497
+ function validate(obj, path = 'ModifyContentResponseRepresentation') {
498
+ const v_error = (() => {
499
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
500
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
501
+ }
502
+ const obj_content = obj.content;
503
+ const path_content = path + '.content';
504
+ if (typeof obj_content !== 'string') {
505
+ return new TypeError('Expected "string" but received "' + typeof obj_content + '" (at "' + path_content + '")');
506
+ }
507
+ const obj_contentType = obj.contentType;
508
+ const path_contentType = path + '.contentType';
509
+ if (typeof obj_contentType !== 'string') {
510
+ return new TypeError('Expected "string" but received "' + typeof obj_contentType + '" (at "' + path_contentType + '")');
511
+ }
512
+ const obj_generationId = obj.generationId;
513
+ const path_generationId = path + '.generationId';
514
+ if (typeof obj_generationId !== 'string') {
515
+ return new TypeError('Expected "string" but received "' + typeof obj_generationId + '" (at "' + path_generationId + '")');
516
+ }
517
+ })();
518
+ return v_error === undefined ? null : v_error;
519
+ }
520
+ const RepresentationType = 'ModifyContentResponseRepresentation';
521
+ function keyBuilder(luvio, config) {
522
+ return keyPrefix + '::' + RepresentationType + ':' + config.generationId;
523
+ }
524
+ function keyBuilderFromType(luvio, object) {
525
+ const keyParams = {
526
+ generationId: object.generationId
527
+ };
528
+ return keyBuilder(luvio, keyParams);
529
+ }
530
+ function normalize(input, existing, path, luvio, store, timestamp) {
531
+ return input;
532
+ }
533
+ const select$1 = function ModifyContentResponseRepresentationSelect() {
534
+ return {
535
+ kind: 'Fragment',
536
+ version: VERSION,
537
+ private: [],
538
+ selections: [
539
+ {
540
+ name: 'content',
541
+ kind: 'Scalar'
542
+ },
543
+ {
544
+ name: 'contentType',
545
+ kind: 'Scalar'
546
+ },
547
+ {
548
+ name: 'generationId',
549
+ kind: 'Scalar'
550
+ }
551
+ ]
552
+ };
553
+ };
554
+ function equals(existing, incoming) {
555
+ const existing_content = existing.content;
556
+ const incoming_content = incoming.content;
557
+ if (!(existing_content === incoming_content)) {
558
+ return false;
559
+ }
560
+ const existing_contentType = existing.contentType;
561
+ const incoming_contentType = incoming.contentType;
562
+ if (!(existing_contentType === incoming_contentType)) {
563
+ return false;
564
+ }
565
+ const existing_generationId = existing.generationId;
566
+ const incoming_generationId = incoming.generationId;
567
+ if (!(existing_generationId === incoming_generationId)) {
568
+ return false;
569
+ }
570
+ return true;
571
+ }
572
+ const ingest = function ModifyContentResponseRepresentationIngest(input, path, luvio, store, timestamp) {
573
+ if (process.env.NODE_ENV !== 'production') {
574
+ const validateError = validate(input);
575
+ if (validateError !== null) {
576
+ throw validateError;
577
+ }
578
+ }
579
+ const key = keyBuilderFromType(luvio, input);
580
+ const ttlToUse = TTL;
581
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize, "marketing-ai4m", VERSION, RepresentationType, equals);
582
+ return createLink(key);
583
+ };
584
+ function getTypeCacheKeys(rootKeySet, luvio, input, fullPathFactory) {
585
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
586
+ const rootKey = keyBuilderFromType(luvio, input);
587
+ rootKeySet.set(rootKey, {
588
+ namespace: keyPrefix,
589
+ representationName: RepresentationType,
590
+ mergeable: false
591
+ });
592
+ }
593
+
594
+ function select(luvio, params) {
595
+ return select$1();
596
+ }
597
+ function getResponseCacheKeys(storeKeyMap, luvio, resourceParams, response) {
598
+ getTypeCacheKeys(storeKeyMap, luvio, response);
599
+ }
600
+ function ingestSuccess(luvio, resourceParams, response) {
601
+ const { body } = response;
602
+ const key = keyBuilderFromType(luvio, body);
603
+ luvio.storeIngest(key, ingest, body);
604
+ const snapshot = luvio.storeLookup({
605
+ recordId: key,
606
+ node: select(),
607
+ variables: {},
608
+ });
609
+ if (process.env.NODE_ENV !== 'production') {
610
+ if (snapshot.state !== 'Fulfilled') {
611
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
612
+ }
613
+ }
614
+ deepFreeze(snapshot.data);
615
+ return snapshot;
616
+ }
617
+ function createResourceRequest(config) {
618
+ const headers = {};
619
+ return {
620
+ baseUri: '/services/data/v66.0',
621
+ basePath: '/connect/ai4m/einstein/content/modification',
622
+ method: 'post',
623
+ body: config.body,
624
+ urlParams: {},
625
+ queryParams: {},
626
+ headers,
627
+ priority: 'normal',
628
+ };
629
+ }
630
+
631
+ const adapterName = 'modifyContent';
632
+ const modifyContent_ConfigPropertyMetadata = [
633
+ generateParamConfigMetadata('brief', true, 2 /* Body */, 4 /* Unsupported */),
634
+ generateParamConfigMetadata('content', true, 2 /* Body */, 0 /* String */),
635
+ generateParamConfigMetadata('contentType', true, 2 /* Body */, 0 /* String */),
636
+ generateParamConfigMetadata('instructions', true, 2 /* Body */, 0 /* String */),
637
+ ];
638
+ const modifyContent_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName, modifyContent_ConfigPropertyMetadata);
639
+ const createResourceParams = /*#__PURE__*/ createResourceParams$2(modifyContent_ConfigPropertyMetadata);
640
+ function typeCheckConfig(untrustedConfig) {
641
+ const config = {};
642
+ typeCheckConfig$2(untrustedConfig, config, modifyContent_ConfigPropertyMetadata);
643
+ const untrustedConfig_brief = untrustedConfig.brief;
644
+ if (untrustedIsObject(untrustedConfig_brief)) {
645
+ const untrustedConfig_brief_object = {};
646
+ const untrustedConfig_brief_audience = untrustedConfig_brief.audience;
647
+ if (ArrayIsArray$1(untrustedConfig_brief_audience)) {
648
+ const untrustedConfig_brief_audience_array = [];
649
+ for (let i = 0, arrayLength = untrustedConfig_brief_audience.length; i < arrayLength; i++) {
650
+ const untrustedConfig_brief_audience_item = untrustedConfig_brief_audience[i];
651
+ const referenceAudienceRepresentationValidationError = validate$3(untrustedConfig_brief_audience_item);
652
+ if (referenceAudienceRepresentationValidationError === null) {
653
+ untrustedConfig_brief_audience_array.push(untrustedConfig_brief_audience_item);
654
+ }
655
+ }
656
+ untrustedConfig_brief_object.audience = untrustedConfig_brief_audience_array;
657
+ }
658
+ const untrustedConfig_brief_campaignGoals = untrustedConfig_brief.campaignGoals;
659
+ if (ArrayIsArray$1(untrustedConfig_brief_campaignGoals)) {
660
+ const untrustedConfig_brief_campaignGoals_array = [];
661
+ for (let i = 0, arrayLength = untrustedConfig_brief_campaignGoals.length; i < arrayLength; i++) {
662
+ const untrustedConfig_brief_campaignGoals_item = untrustedConfig_brief_campaignGoals[i];
663
+ if (typeof untrustedConfig_brief_campaignGoals_item === 'string') {
664
+ untrustedConfig_brief_campaignGoals_array.push(untrustedConfig_brief_campaignGoals_item);
665
+ }
666
+ }
667
+ untrustedConfig_brief_object.campaignGoals = untrustedConfig_brief_campaignGoals_array;
668
+ }
669
+ const untrustedConfig_brief_campaignName = untrustedConfig_brief.campaignName;
670
+ if (typeof untrustedConfig_brief_campaignName === 'string') {
671
+ untrustedConfig_brief_object.campaignName = untrustedConfig_brief_campaignName;
672
+ }
673
+ const untrustedConfig_brief_campaignObjective = untrustedConfig_brief.campaignObjective;
674
+ if (typeof untrustedConfig_brief_campaignObjective === 'string') {
675
+ untrustedConfig_brief_object.campaignObjective = untrustedConfig_brief_campaignObjective;
676
+ }
677
+ const untrustedConfig_brief_channels = untrustedConfig_brief.channels;
678
+ if (ArrayIsArray$1(untrustedConfig_brief_channels)) {
679
+ const untrustedConfig_brief_channels_array = [];
680
+ for (let i = 0, arrayLength = untrustedConfig_brief_channels.length; i < arrayLength; i++) {
681
+ const untrustedConfig_brief_channels_item = untrustedConfig_brief_channels[i];
682
+ if (typeof untrustedConfig_brief_channels_item === 'string') {
683
+ untrustedConfig_brief_channels_array.push(untrustedConfig_brief_channels_item);
684
+ }
685
+ }
686
+ untrustedConfig_brief_object.channels = untrustedConfig_brief_channels_array;
687
+ }
688
+ const untrustedConfig_brief_keyMessage = untrustedConfig_brief.keyMessage;
689
+ if (typeof untrustedConfig_brief_keyMessage === 'string') {
690
+ untrustedConfig_brief_object.keyMessage = untrustedConfig_brief_keyMessage;
691
+ }
692
+ const untrustedConfig_brief_sampleAssets = untrustedConfig_brief.sampleAssets;
693
+ if (untrustedIsObject(untrustedConfig_brief_sampleAssets)) {
694
+ const untrustedConfig_brief_sampleAssets_object = {};
695
+ const untrustedConfig_brief_sampleAssets_email = untrustedConfig_brief_sampleAssets.email;
696
+ if (untrustedIsObject(untrustedConfig_brief_sampleAssets_email)) {
697
+ const untrustedConfig_brief_sampleAssets_email_object = {};
698
+ const untrustedConfig_brief_sampleAssets_email_paragraph = untrustedConfig_brief_sampleAssets_email.paragraph;
699
+ if (ArrayIsArray$1(untrustedConfig_brief_sampleAssets_email_paragraph)) {
700
+ const untrustedConfig_brief_sampleAssets_email_paragraph_array = [];
701
+ for (let i = 0, arrayLength = untrustedConfig_brief_sampleAssets_email_paragraph.length; i < arrayLength; i++) {
702
+ const untrustedConfig_brief_sampleAssets_email_paragraph_item = untrustedConfig_brief_sampleAssets_email_paragraph[i];
703
+ if (typeof untrustedConfig_brief_sampleAssets_email_paragraph_item === 'string') {
704
+ untrustedConfig_brief_sampleAssets_email_paragraph_array.push(untrustedConfig_brief_sampleAssets_email_paragraph_item);
705
+ }
706
+ }
707
+ untrustedConfig_brief_sampleAssets_email_object.paragraph = untrustedConfig_brief_sampleAssets_email_paragraph_array;
708
+ }
709
+ const untrustedConfig_brief_sampleAssets_email_preheader = untrustedConfig_brief_sampleAssets_email.preheader;
710
+ if (ArrayIsArray$1(untrustedConfig_brief_sampleAssets_email_preheader)) {
711
+ const untrustedConfig_brief_sampleAssets_email_preheader_array = [];
712
+ for (let i = 0, arrayLength = untrustedConfig_brief_sampleAssets_email_preheader.length; i < arrayLength; i++) {
713
+ const untrustedConfig_brief_sampleAssets_email_preheader_item = untrustedConfig_brief_sampleAssets_email_preheader[i];
714
+ if (typeof untrustedConfig_brief_sampleAssets_email_preheader_item === 'string') {
715
+ untrustedConfig_brief_sampleAssets_email_preheader_array.push(untrustedConfig_brief_sampleAssets_email_preheader_item);
716
+ }
717
+ }
718
+ untrustedConfig_brief_sampleAssets_email_object.preheader = untrustedConfig_brief_sampleAssets_email_preheader_array;
719
+ }
720
+ const untrustedConfig_brief_sampleAssets_email_subjectLine = untrustedConfig_brief_sampleAssets_email.subjectLine;
721
+ if (ArrayIsArray$1(untrustedConfig_brief_sampleAssets_email_subjectLine)) {
722
+ const untrustedConfig_brief_sampleAssets_email_subjectLine_array = [];
723
+ for (let i = 0, arrayLength = untrustedConfig_brief_sampleAssets_email_subjectLine.length; i < arrayLength; i++) {
724
+ const untrustedConfig_brief_sampleAssets_email_subjectLine_item = untrustedConfig_brief_sampleAssets_email_subjectLine[i];
725
+ if (typeof untrustedConfig_brief_sampleAssets_email_subjectLine_item === 'string') {
726
+ untrustedConfig_brief_sampleAssets_email_subjectLine_array.push(untrustedConfig_brief_sampleAssets_email_subjectLine_item);
727
+ }
728
+ }
729
+ untrustedConfig_brief_sampleAssets_email_object.subjectLine = untrustedConfig_brief_sampleAssets_email_subjectLine_array;
730
+ }
731
+ if (untrustedConfig_brief_sampleAssets_email_object !== undefined && Object.keys(untrustedConfig_brief_sampleAssets_email_object).length >= 0) {
732
+ untrustedConfig_brief_sampleAssets_object.email = untrustedConfig_brief_sampleAssets_email_object;
733
+ }
734
+ }
735
+ if (untrustedConfig_brief_sampleAssets_object !== undefined && Object.keys(untrustedConfig_brief_sampleAssets_object).length >= 0) {
736
+ untrustedConfig_brief_object.sampleAssets = untrustedConfig_brief_sampleAssets_object;
737
+ }
738
+ }
739
+ const untrustedConfig_brief_tone = untrustedConfig_brief.tone;
740
+ if (typeof untrustedConfig_brief_tone === 'string') {
741
+ untrustedConfig_brief_object.tone = untrustedConfig_brief_tone;
742
+ }
743
+ if (untrustedConfig_brief_object !== undefined && Object.keys(untrustedConfig_brief_object).length >= 0) {
744
+ config.brief = untrustedConfig_brief_object;
745
+ }
746
+ }
747
+ return config;
748
+ }
749
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
750
+ if (!untrustedIsObject(untrustedConfig)) {
751
+ return null;
752
+ }
753
+ if (process.env.NODE_ENV !== 'production') {
754
+ validateConfig(untrustedConfig, configPropertyNames);
755
+ }
756
+ const config = typeCheckConfig(untrustedConfig);
757
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
758
+ return null;
759
+ }
760
+ return config;
761
+ }
762
+ function buildNetworkSnapshot(luvio, config, options) {
763
+ const resourceParams = createResourceParams(config);
764
+ const request = createResourceRequest(resourceParams);
765
+ return luvio.dispatchResourceRequest(request, options)
766
+ .then((response) => {
767
+ return luvio.handleSuccessResponse(() => {
768
+ const snapshot = ingestSuccess(luvio, resourceParams, response);
769
+ return luvio.storeBroadcast().then(() => snapshot);
770
+ }, () => {
771
+ const cache = new StoreKeyMap();
772
+ getResponseCacheKeys(cache, luvio, resourceParams, response.body);
773
+ return cache;
774
+ });
775
+ }, (response) => {
776
+ deepFreeze(response);
777
+ throw response;
778
+ });
779
+ }
780
+ const modifyContentAdapterFactory = (luvio) => {
781
+ return function modifyContent(untrustedConfig) {
782
+ const config = validateAdapterConfig(untrustedConfig, modifyContent_ConfigPropertyNames);
783
+ // Invalid or incomplete config
784
+ if (config === null) {
785
+ throw new Error('Invalid config for "modifyContent"');
786
+ }
787
+ return buildNetworkSnapshot(luvio, config);
788
+ };
789
+ };
790
+
791
+ export { createContentAdapterFactory, modifyContentAdapterFactory };