@salesforce/lds-adapters-commerce-configuration 0.1.0-dev1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,747 @@
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, StoreKeyMap, deepFreeze, createResourceParams as createResourceParams$3, typeCheckConfig as typeCheckConfig$3, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$1 } from '@luvio/engine';
8
+
9
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
+ const { keys: ObjectKeys, create: ObjectCreate } = Object;
11
+ const { isArray: ArrayIsArray$1 } = Array;
12
+ /**
13
+ * Validates an adapter config is well-formed.
14
+ * @param config The config to validate.
15
+ * @param adapter The adapter validation configuration.
16
+ * @param oneOf The keys the config must contain at least one of.
17
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
18
+ */
19
+ function validateConfig(config, adapter, oneOf) {
20
+ const { displayName } = adapter;
21
+ const { required, optional, unsupported } = adapter.parameters;
22
+ if (config === undefined ||
23
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
24
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
25
+ }
26
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
27
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
28
+ }
29
+ if (unsupported !== undefined &&
30
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
31
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
32
+ }
33
+ const supported = required.concat(optional);
34
+ if (ObjectKeys(config).some(key => !supported.includes(key))) {
35
+ throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
36
+ }
37
+ }
38
+ function untrustedIsObject(untrusted) {
39
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
40
+ }
41
+ function areRequiredParametersPresent(config, configPropertyNames) {
42
+ return configPropertyNames.parameters.required.every(req => req in config);
43
+ }
44
+ const snapshotRefreshOptions = {
45
+ overrides: {
46
+ headers: {
47
+ 'Cache-Control': 'no-cache',
48
+ },
49
+ }
50
+ };
51
+ function generateParamConfigMetadata(name, required, resourceType, typeCheckShape, isArrayShape = false, coerceFn) {
52
+ return {
53
+ name,
54
+ required,
55
+ resourceType,
56
+ typeCheckShape,
57
+ isArrayShape,
58
+ coerceFn,
59
+ };
60
+ }
61
+ function buildAdapterValidationConfig(displayName, paramsMeta) {
62
+ const required = paramsMeta.filter(p => p.required).map(p => p.name);
63
+ const optional = paramsMeta.filter(p => !p.required).map(p => p.name);
64
+ return {
65
+ displayName,
66
+ parameters: {
67
+ required,
68
+ optional,
69
+ }
70
+ };
71
+ }
72
+ const keyPrefix = 'commerce-configuration';
73
+
74
+ const { isArray: ArrayIsArray } = Array;
75
+ function equalsArray(a, b, equalsItem) {
76
+ const aLength = a.length;
77
+ const bLength = b.length;
78
+ if (aLength !== bLength) {
79
+ return false;
80
+ }
81
+ for (let i = 0; i < aLength; i++) {
82
+ if (equalsItem(a[i], b[i]) === false) {
83
+ return false;
84
+ }
85
+ }
86
+ return true;
87
+ }
88
+ function createLink(ref) {
89
+ return {
90
+ __ref: serializeStructuredKey(ref),
91
+ };
92
+ }
93
+
94
+ const TTL = 1000;
95
+ const VERSION = "3f1cb4f5f9992e44d62eef68eeaa8ee0";
96
+ function validate(obj, path = 'CommerceConfigurationAttributeOutputRepresentation') {
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
+ if (obj.booleanValue !== undefined) {
102
+ const obj_booleanValue = obj.booleanValue;
103
+ const path_booleanValue = path + '.booleanValue';
104
+ let obj_booleanValue_union0 = null;
105
+ const obj_booleanValue_union0_error = (() => {
106
+ if (typeof obj_booleanValue !== 'boolean') {
107
+ return new TypeError('Expected "boolean" but received "' + typeof obj_booleanValue + '" (at "' + path_booleanValue + '")');
108
+ }
109
+ })();
110
+ if (obj_booleanValue_union0_error != null) {
111
+ obj_booleanValue_union0 = obj_booleanValue_union0_error.message;
112
+ }
113
+ let obj_booleanValue_union1 = null;
114
+ const obj_booleanValue_union1_error = (() => {
115
+ if (obj_booleanValue !== null) {
116
+ return new TypeError('Expected "null" but received "' + typeof obj_booleanValue + '" (at "' + path_booleanValue + '")');
117
+ }
118
+ })();
119
+ if (obj_booleanValue_union1_error != null) {
120
+ obj_booleanValue_union1 = obj_booleanValue_union1_error.message;
121
+ }
122
+ if (obj_booleanValue_union0 && obj_booleanValue_union1) {
123
+ let message = 'Object doesn\'t match union (at "' + path_booleanValue + '")';
124
+ message += '\n' + obj_booleanValue_union0.split('\n').map((line) => '\t' + line).join('\n');
125
+ message += '\n' + obj_booleanValue_union1.split('\n').map((line) => '\t' + line).join('\n');
126
+ return new TypeError(message);
127
+ }
128
+ }
129
+ const obj_contextId = obj.contextId;
130
+ const path_contextId = path + '.contextId';
131
+ if (typeof obj_contextId !== 'string') {
132
+ return new TypeError('Expected "string" but received "' + typeof obj_contextId + '" (at "' + path_contextId + '")');
133
+ }
134
+ const obj_contextType = obj.contextType;
135
+ const path_contextType = path + '.contextType';
136
+ if (typeof obj_contextType !== 'string') {
137
+ return new TypeError('Expected "string" but received "' + typeof obj_contextType + '" (at "' + path_contextType + '")');
138
+ }
139
+ const obj_id = obj.id;
140
+ const path_id = path + '.id';
141
+ if (typeof obj_id !== 'string') {
142
+ return new TypeError('Expected "string" but received "' + typeof obj_id + '" (at "' + path_id + '")');
143
+ }
144
+ if (obj.integerValue !== undefined) {
145
+ const obj_integerValue = obj.integerValue;
146
+ const path_integerValue = path + '.integerValue';
147
+ let obj_integerValue_union0 = null;
148
+ const obj_integerValue_union0_error = (() => {
149
+ if (typeof obj_integerValue !== 'number' || (typeof obj_integerValue === 'number' && Math.floor(obj_integerValue) !== obj_integerValue)) {
150
+ return new TypeError('Expected "integer" but received "' + typeof obj_integerValue + '" (at "' + path_integerValue + '")');
151
+ }
152
+ })();
153
+ if (obj_integerValue_union0_error != null) {
154
+ obj_integerValue_union0 = obj_integerValue_union0_error.message;
155
+ }
156
+ let obj_integerValue_union1 = null;
157
+ const obj_integerValue_union1_error = (() => {
158
+ if (obj_integerValue !== null) {
159
+ return new TypeError('Expected "null" but received "' + typeof obj_integerValue + '" (at "' + path_integerValue + '")');
160
+ }
161
+ })();
162
+ if (obj_integerValue_union1_error != null) {
163
+ obj_integerValue_union1 = obj_integerValue_union1_error.message;
164
+ }
165
+ if (obj_integerValue_union0 && obj_integerValue_union1) {
166
+ let message = 'Object doesn\'t match union (at "' + path_integerValue + '")';
167
+ message += '\n' + obj_integerValue_union0.split('\n').map((line) => '\t' + line).join('\n');
168
+ message += '\n' + obj_integerValue_union1.split('\n').map((line) => '\t' + line).join('\n');
169
+ return new TypeError(message);
170
+ }
171
+ }
172
+ if (obj.numberValue !== undefined) {
173
+ const obj_numberValue = obj.numberValue;
174
+ const path_numberValue = path + '.numberValue';
175
+ let obj_numberValue_union0 = null;
176
+ const obj_numberValue_union0_error = (() => {
177
+ if (typeof obj_numberValue !== 'number') {
178
+ return new TypeError('Expected "number" but received "' + typeof obj_numberValue + '" (at "' + path_numberValue + '")');
179
+ }
180
+ })();
181
+ if (obj_numberValue_union0_error != null) {
182
+ obj_numberValue_union0 = obj_numberValue_union0_error.message;
183
+ }
184
+ let obj_numberValue_union1 = null;
185
+ const obj_numberValue_union1_error = (() => {
186
+ if (obj_numberValue !== null) {
187
+ return new TypeError('Expected "null" but received "' + typeof obj_numberValue + '" (at "' + path_numberValue + '")');
188
+ }
189
+ })();
190
+ if (obj_numberValue_union1_error != null) {
191
+ obj_numberValue_union1 = obj_numberValue_union1_error.message;
192
+ }
193
+ if (obj_numberValue_union0 && obj_numberValue_union1) {
194
+ let message = 'Object doesn\'t match union (at "' + path_numberValue + '")';
195
+ message += '\n' + obj_numberValue_union0.split('\n').map((line) => '\t' + line).join('\n');
196
+ message += '\n' + obj_numberValue_union1.split('\n').map((line) => '\t' + line).join('\n');
197
+ return new TypeError(message);
198
+ }
199
+ }
200
+ if (obj.stringValue !== undefined) {
201
+ const obj_stringValue = obj.stringValue;
202
+ const path_stringValue = path + '.stringValue';
203
+ let obj_stringValue_union0 = null;
204
+ const obj_stringValue_union0_error = (() => {
205
+ if (typeof obj_stringValue !== 'string') {
206
+ return new TypeError('Expected "string" but received "' + typeof obj_stringValue + '" (at "' + path_stringValue + '")');
207
+ }
208
+ })();
209
+ if (obj_stringValue_union0_error != null) {
210
+ obj_stringValue_union0 = obj_stringValue_union0_error.message;
211
+ }
212
+ let obj_stringValue_union1 = null;
213
+ const obj_stringValue_union1_error = (() => {
214
+ if (obj_stringValue !== null) {
215
+ return new TypeError('Expected "null" but received "' + typeof obj_stringValue + '" (at "' + path_stringValue + '")');
216
+ }
217
+ })();
218
+ if (obj_stringValue_union1_error != null) {
219
+ obj_stringValue_union1 = obj_stringValue_union1_error.message;
220
+ }
221
+ if (obj_stringValue_union0 && obj_stringValue_union1) {
222
+ let message = 'Object doesn\'t match union (at "' + path_stringValue + '")';
223
+ message += '\n' + obj_stringValue_union0.split('\n').map((line) => '\t' + line).join('\n');
224
+ message += '\n' + obj_stringValue_union1.split('\n').map((line) => '\t' + line).join('\n');
225
+ return new TypeError(message);
226
+ }
227
+ }
228
+ if (obj.stringValues !== undefined) {
229
+ const obj_stringValues = obj.stringValues;
230
+ const path_stringValues = path + '.stringValues';
231
+ if (!ArrayIsArray(obj_stringValues)) {
232
+ return new TypeError('Expected "array" but received "' + typeof obj_stringValues + '" (at "' + path_stringValues + '")');
233
+ }
234
+ for (let i = 0; i < obj_stringValues.length; i++) {
235
+ const obj_stringValues_item = obj_stringValues[i];
236
+ const path_stringValues_item = path_stringValues + '[' + i + ']';
237
+ if (typeof obj_stringValues_item !== 'string') {
238
+ return new TypeError('Expected "string" but received "' + typeof obj_stringValues_item + '" (at "' + path_stringValues_item + '")');
239
+ }
240
+ }
241
+ }
242
+ })();
243
+ return v_error === undefined ? null : v_error;
244
+ }
245
+ const RepresentationType = 'CommerceConfigurationAttributeOutputRepresentation';
246
+ function keyBuilder$3(luvio, config) {
247
+ return keyPrefix + '::' + RepresentationType + ':' + config.id + ':' + config.contextId + ':' + config.contextType;
248
+ }
249
+ function keyBuilderFromType(luvio, object) {
250
+ const keyParams = {
251
+ id: object.id,
252
+ contextId: object.contextId,
253
+ contextType: object.contextType
254
+ };
255
+ return keyBuilder$3(luvio, keyParams);
256
+ }
257
+ function normalize(input, existing, path, luvio, store, timestamp) {
258
+ return input;
259
+ }
260
+ const select$2 = function CommerceConfigurationAttributeOutputRepresentationSelect() {
261
+ return {
262
+ kind: 'Fragment',
263
+ version: VERSION,
264
+ private: [],
265
+ selections: [
266
+ {
267
+ name: 'booleanValue',
268
+ kind: 'Scalar',
269
+ required: false
270
+ },
271
+ {
272
+ name: 'contextId',
273
+ kind: 'Scalar'
274
+ },
275
+ {
276
+ name: 'contextType',
277
+ kind: 'Scalar'
278
+ },
279
+ {
280
+ name: 'id',
281
+ kind: 'Scalar'
282
+ },
283
+ {
284
+ name: 'integerValue',
285
+ kind: 'Scalar',
286
+ required: false
287
+ },
288
+ {
289
+ name: 'numberValue',
290
+ kind: 'Scalar',
291
+ required: false
292
+ },
293
+ {
294
+ name: 'stringValue',
295
+ kind: 'Scalar',
296
+ required: false
297
+ },
298
+ {
299
+ name: 'stringValues',
300
+ kind: 'Scalar',
301
+ plural: true,
302
+ required: false
303
+ }
304
+ ]
305
+ };
306
+ };
307
+ function equals(existing, incoming) {
308
+ const existing_contextId = existing.contextId;
309
+ const incoming_contextId = incoming.contextId;
310
+ if (!(existing_contextId === incoming_contextId)) {
311
+ return false;
312
+ }
313
+ const existing_contextType = existing.contextType;
314
+ const incoming_contextType = incoming.contextType;
315
+ if (!(existing_contextType === incoming_contextType)) {
316
+ return false;
317
+ }
318
+ const existing_id = existing.id;
319
+ const incoming_id = incoming.id;
320
+ if (!(existing_id === incoming_id)) {
321
+ return false;
322
+ }
323
+ const existing_booleanValue = existing.booleanValue;
324
+ const incoming_booleanValue = incoming.booleanValue;
325
+ // if at least one of these optionals is defined
326
+ if (existing_booleanValue !== undefined || incoming_booleanValue !== undefined) {
327
+ // if one of these is not defined we know the other is defined and therefore
328
+ // not equal
329
+ if (existing_booleanValue === undefined || incoming_booleanValue === undefined) {
330
+ return false;
331
+ }
332
+ if (!(existing_booleanValue === incoming_booleanValue)) {
333
+ return false;
334
+ }
335
+ }
336
+ const existing_integerValue = existing.integerValue;
337
+ const incoming_integerValue = incoming.integerValue;
338
+ // if at least one of these optionals is defined
339
+ if (existing_integerValue !== undefined || incoming_integerValue !== undefined) {
340
+ // if one of these is not defined we know the other is defined and therefore
341
+ // not equal
342
+ if (existing_integerValue === undefined || incoming_integerValue === undefined) {
343
+ return false;
344
+ }
345
+ if (!(existing_integerValue === incoming_integerValue)) {
346
+ return false;
347
+ }
348
+ }
349
+ const existing_numberValue = existing.numberValue;
350
+ const incoming_numberValue = incoming.numberValue;
351
+ // if at least one of these optionals is defined
352
+ if (existing_numberValue !== undefined || incoming_numberValue !== undefined) {
353
+ // if one of these is not defined we know the other is defined and therefore
354
+ // not equal
355
+ if (existing_numberValue === undefined || incoming_numberValue === undefined) {
356
+ return false;
357
+ }
358
+ if (!(existing_numberValue === incoming_numberValue)) {
359
+ return false;
360
+ }
361
+ }
362
+ const existing_stringValue = existing.stringValue;
363
+ const incoming_stringValue = incoming.stringValue;
364
+ // if at least one of these optionals is defined
365
+ if (existing_stringValue !== undefined || incoming_stringValue !== undefined) {
366
+ // if one of these is not defined we know the other is defined and therefore
367
+ // not equal
368
+ if (existing_stringValue === undefined || incoming_stringValue === undefined) {
369
+ return false;
370
+ }
371
+ if (!(existing_stringValue === incoming_stringValue)) {
372
+ return false;
373
+ }
374
+ }
375
+ const existing_stringValues = existing.stringValues;
376
+ const incoming_stringValues = incoming.stringValues;
377
+ // if at least one of these optionals is defined
378
+ if (existing_stringValues !== undefined || incoming_stringValues !== undefined) {
379
+ // if one of these is not defined we know the other is defined and therefore
380
+ // not equal
381
+ if (existing_stringValues === undefined || incoming_stringValues === undefined) {
382
+ return false;
383
+ }
384
+ const equals_stringValues_items = equalsArray(existing_stringValues, incoming_stringValues, (existing_stringValues_item, incoming_stringValues_item) => {
385
+ if (!(existing_stringValues_item === incoming_stringValues_item)) {
386
+ return false;
387
+ }
388
+ });
389
+ if (equals_stringValues_items === false) {
390
+ return false;
391
+ }
392
+ }
393
+ return true;
394
+ }
395
+ const ingest = function CommerceConfigurationAttributeOutputRepresentationIngest(input, path, luvio, store, timestamp) {
396
+ if (process.env.NODE_ENV !== 'production') {
397
+ const validateError = validate(input);
398
+ if (validateError !== null) {
399
+ throw validateError;
400
+ }
401
+ }
402
+ const key = keyBuilderFromType(luvio, input);
403
+ const ttlToUse = TTL;
404
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize, "commerce-configuration", VERSION, RepresentationType, equals);
405
+ return createLink(key);
406
+ };
407
+ function getTypeCacheKeys(rootKeySet, luvio, input, fullPathFactory) {
408
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
409
+ const rootKey = keyBuilderFromType(luvio, input);
410
+ rootKeySet.set(rootKey, {
411
+ namespace: keyPrefix,
412
+ representationName: RepresentationType,
413
+ mergeable: false
414
+ });
415
+ }
416
+
417
+ function keyBuilder$2(luvio, params) {
418
+ return keyBuilder$3(luvio, {
419
+ id: params.urlParams.attributeId,
420
+ contextId: params.urlParams.contextId,
421
+ contextType: params.urlParams.contextType
422
+ });
423
+ }
424
+ function getResponseCacheKeys$2(cacheKeyMap, luvio, resourceParams) {
425
+ const key = keyBuilder$2(luvio, resourceParams);
426
+ cacheKeyMap.set(key, {
427
+ namespace: keyPrefix,
428
+ representationName: RepresentationType,
429
+ mergeable: false
430
+ });
431
+ }
432
+ function evictSuccess(luvio, resourceParams) {
433
+ const key = keyBuilder$2(luvio, resourceParams);
434
+ luvio.storeEvict(key);
435
+ }
436
+ function createResourceRequest$2(config) {
437
+ const headers = {};
438
+ return {
439
+ baseUri: '/services/data/v66.0',
440
+ basePath: '/commerce/configuration/' + config.urlParams.attributeId + '/' + config.urlParams.contextType + '/' + config.urlParams.contextId + '',
441
+ method: 'delete',
442
+ body: null,
443
+ urlParams: config.urlParams,
444
+ queryParams: {},
445
+ headers,
446
+ priority: 'normal',
447
+ };
448
+ }
449
+
450
+ const adapterName$2 = 'deleteCommerceConfigurationAttribute';
451
+ const deleteCommerceConfigurationAttribute_ConfigPropertyMetadata = [
452
+ generateParamConfigMetadata('attributeId', true, 0 /* UrlParameter */, 0 /* String */),
453
+ generateParamConfigMetadata('contextId', true, 0 /* UrlParameter */, 0 /* String */),
454
+ generateParamConfigMetadata('contextType', true, 0 /* UrlParameter */, 0 /* String */),
455
+ ];
456
+ const deleteCommerceConfigurationAttribute_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$2, deleteCommerceConfigurationAttribute_ConfigPropertyMetadata);
457
+ const createResourceParams$2 = /*#__PURE__*/ createResourceParams$3(deleteCommerceConfigurationAttribute_ConfigPropertyMetadata);
458
+ function typeCheckConfig$2(untrustedConfig) {
459
+ const config = {};
460
+ typeCheckConfig$3(untrustedConfig, config, deleteCommerceConfigurationAttribute_ConfigPropertyMetadata);
461
+ return config;
462
+ }
463
+ function validateAdapterConfig$2(untrustedConfig, configPropertyNames) {
464
+ if (!untrustedIsObject(untrustedConfig)) {
465
+ return null;
466
+ }
467
+ if (process.env.NODE_ENV !== 'production') {
468
+ validateConfig(untrustedConfig, configPropertyNames);
469
+ }
470
+ const config = typeCheckConfig$2(untrustedConfig);
471
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
472
+ return null;
473
+ }
474
+ return config;
475
+ }
476
+ function buildNetworkSnapshot$2(luvio, config, options) {
477
+ const resourceParams = createResourceParams$2(config);
478
+ const request = createResourceRequest$2(resourceParams);
479
+ return luvio.dispatchResourceRequest(request, options)
480
+ .then(() => {
481
+ return luvio.handleSuccessResponse(() => {
482
+ evictSuccess(luvio, resourceParams);
483
+ return luvio.storeBroadcast();
484
+ }, () => {
485
+ const cache = new StoreKeyMap();
486
+ getResponseCacheKeys$2(cache, luvio, resourceParams);
487
+ return cache;
488
+ });
489
+ }, (response) => {
490
+ deepFreeze(response);
491
+ throw response;
492
+ });
493
+ }
494
+ const deleteCommerceConfigurationAttributeAdapterFactory = (luvio) => {
495
+ return function commerceConfigurationdeleteCommerceConfigurationAttribute(untrustedConfig) {
496
+ const config = validateAdapterConfig$2(untrustedConfig, deleteCommerceConfigurationAttribute_ConfigPropertyNames);
497
+ // Invalid or incomplete config
498
+ if (config === null) {
499
+ throw new Error(`Invalid config for "${adapterName$2}"`);
500
+ }
501
+ return buildNetworkSnapshot$2(luvio, config);
502
+ };
503
+ };
504
+
505
+ function select$1(luvio, params) {
506
+ return select$2();
507
+ }
508
+ function keyBuilder$1(luvio, params) {
509
+ return keyBuilder$3(luvio, {
510
+ id: params.urlParams.attributeId,
511
+ contextId: params.urlParams.contextId,
512
+ contextType: params.urlParams.contextType
513
+ });
514
+ }
515
+ function getResponseCacheKeys$1(storeKeyMap, luvio, resourceParams, response) {
516
+ getTypeCacheKeys(storeKeyMap, luvio, response);
517
+ }
518
+ function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
519
+ const { body } = response;
520
+ const key = keyBuilder$1(luvio, resourceParams);
521
+ luvio.storeIngest(key, ingest, body);
522
+ const snapshot = luvio.storeLookup({
523
+ recordId: key,
524
+ node: select$1(),
525
+ variables: {},
526
+ }, snapshotRefresh);
527
+ if (process.env.NODE_ENV !== 'production') {
528
+ if (snapshot.state !== 'Fulfilled') {
529
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
530
+ }
531
+ }
532
+ deepFreeze(snapshot.data);
533
+ return snapshot;
534
+ }
535
+ function ingestError(luvio, params, error, snapshotRefresh) {
536
+ const key = keyBuilder$1(luvio, params);
537
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
538
+ const storeMetadataParams = {
539
+ ttl: TTL,
540
+ namespace: keyPrefix,
541
+ version: VERSION,
542
+ representationName: RepresentationType
543
+ };
544
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
545
+ return errorSnapshot;
546
+ }
547
+ function createResourceRequest$1(config) {
548
+ const headers = {};
549
+ return {
550
+ baseUri: '/services/data/v66.0',
551
+ basePath: '/commerce/configuration/' + config.urlParams.attributeId + '/' + config.urlParams.contextType + '/' + config.urlParams.contextId + '',
552
+ method: 'get',
553
+ body: null,
554
+ urlParams: config.urlParams,
555
+ queryParams: config.queryParams,
556
+ headers,
557
+ priority: 'normal',
558
+ };
559
+ }
560
+
561
+ const adapterName$1 = 'getCommerceConfigurationAttribute';
562
+ const getCommerceConfigurationAttribute_ConfigPropertyMetadata = [
563
+ generateParamConfigMetadata('attributeId', true, 0 /* UrlParameter */, 0 /* String */),
564
+ generateParamConfigMetadata('contextId', true, 0 /* UrlParameter */, 0 /* String */),
565
+ generateParamConfigMetadata('contextType', true, 0 /* UrlParameter */, 0 /* String */),
566
+ generateParamConfigMetadata('fallback', false, 1 /* QueryParameter */, 1 /* Boolean */),
567
+ ];
568
+ const getCommerceConfigurationAttribute_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, getCommerceConfigurationAttribute_ConfigPropertyMetadata);
569
+ const createResourceParams$1 = /*#__PURE__*/ createResourceParams$3(getCommerceConfigurationAttribute_ConfigPropertyMetadata);
570
+ function keyBuilder(luvio, config) {
571
+ const resourceParams = createResourceParams$1(config);
572
+ return keyBuilder$1(luvio, resourceParams);
573
+ }
574
+ function typeCheckConfig$1(untrustedConfig) {
575
+ const config = {};
576
+ typeCheckConfig$3(untrustedConfig, config, getCommerceConfigurationAttribute_ConfigPropertyMetadata);
577
+ return config;
578
+ }
579
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
580
+ if (!untrustedIsObject(untrustedConfig)) {
581
+ return null;
582
+ }
583
+ if (process.env.NODE_ENV !== 'production') {
584
+ validateConfig(untrustedConfig, configPropertyNames);
585
+ }
586
+ const config = typeCheckConfig$1(untrustedConfig);
587
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
588
+ return null;
589
+ }
590
+ return config;
591
+ }
592
+ function adapterFragment(luvio, config) {
593
+ createResourceParams$1(config);
594
+ return select$1();
595
+ }
596
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
597
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response, {
598
+ config,
599
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
600
+ });
601
+ return luvio.storeBroadcast().then(() => snapshot);
602
+ }
603
+ function onFetchResponseError(luvio, config, resourceParams, response) {
604
+ const snapshot = ingestError(luvio, resourceParams, response, {
605
+ config,
606
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
607
+ });
608
+ return luvio.storeBroadcast().then(() => snapshot);
609
+ }
610
+ function buildNetworkSnapshot$1(luvio, config, options) {
611
+ const resourceParams = createResourceParams$1(config);
612
+ const request = createResourceRequest$1(resourceParams);
613
+ return luvio.dispatchResourceRequest(request, options)
614
+ .then((response) => {
615
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => {
616
+ const cache = new StoreKeyMap();
617
+ getResponseCacheKeys$1(cache, luvio, resourceParams, response.body);
618
+ return cache;
619
+ });
620
+ }, (response) => {
621
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
622
+ });
623
+ }
624
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
625
+ return buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext, buildNetworkSnapshot$1, undefined, false);
626
+ }
627
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
628
+ const { luvio, config } = context;
629
+ const selector = {
630
+ recordId: keyBuilder(luvio, config),
631
+ node: adapterFragment(luvio, config),
632
+ variables: {},
633
+ };
634
+ const cacheSnapshot = storeLookup(selector, {
635
+ config,
636
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
637
+ });
638
+ return cacheSnapshot;
639
+ }
640
+ const getCommerceConfigurationAttributeAdapterFactory = (luvio) => function commerceConfiguration__getCommerceConfigurationAttribute(untrustedConfig, requestContext) {
641
+ const config = validateAdapterConfig$1(untrustedConfig, getCommerceConfigurationAttribute_ConfigPropertyNames);
642
+ // Invalid or incomplete config
643
+ if (config === null) {
644
+ return null;
645
+ }
646
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
647
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
648
+ };
649
+
650
+ function select(luvio, params) {
651
+ return select$2();
652
+ }
653
+ function getResponseCacheKeys(storeKeyMap, luvio, resourceParams, response) {
654
+ getTypeCacheKeys(storeKeyMap, luvio, response);
655
+ }
656
+ function ingestSuccess(luvio, resourceParams, response) {
657
+ const { body } = response;
658
+ const key = keyBuilderFromType(luvio, body);
659
+ luvio.storeIngest(key, ingest, body);
660
+ const snapshot = luvio.storeLookup({
661
+ recordId: key,
662
+ node: select(),
663
+ variables: {},
664
+ });
665
+ if (process.env.NODE_ENV !== 'production') {
666
+ if (snapshot.state !== 'Fulfilled') {
667
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
668
+ }
669
+ }
670
+ deepFreeze(snapshot.data);
671
+ return snapshot;
672
+ }
673
+ function createResourceRequest(config) {
674
+ const headers = {};
675
+ return {
676
+ baseUri: '/services/data/v66.0',
677
+ basePath: '/commerce/configuration/' + config.urlParams.attributeId + '/' + config.urlParams.contextType + '/' + config.urlParams.contextId + '',
678
+ method: 'put',
679
+ body: config.body,
680
+ urlParams: config.urlParams,
681
+ queryParams: {},
682
+ headers,
683
+ priority: 'normal',
684
+ };
685
+ }
686
+
687
+ const adapterName = 'putCommerceConfigurationAttribute';
688
+ const putCommerceConfigurationAttribute_ConfigPropertyMetadata = [
689
+ generateParamConfigMetadata('attributeId', true, 0 /* UrlParameter */, 0 /* String */),
690
+ generateParamConfigMetadata('contextId', true, 0 /* UrlParameter */, 0 /* String */),
691
+ generateParamConfigMetadata('contextType', true, 0 /* UrlParameter */, 0 /* String */),
692
+ generateParamConfigMetadata('booleanValue', false, 2 /* Body */, 1 /* Boolean */),
693
+ generateParamConfigMetadata('integerValue', false, 2 /* Body */, 3 /* Integer */),
694
+ generateParamConfigMetadata('numberValue', false, 2 /* Body */, 2 /* Number */),
695
+ generateParamConfigMetadata('stringValue', false, 2 /* Body */, 0 /* String */),
696
+ generateParamConfigMetadata('stringValues', false, 2 /* Body */, 0 /* String */, true),
697
+ ];
698
+ const putCommerceConfigurationAttribute_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName, putCommerceConfigurationAttribute_ConfigPropertyMetadata);
699
+ const createResourceParams = /*#__PURE__*/ createResourceParams$3(putCommerceConfigurationAttribute_ConfigPropertyMetadata);
700
+ function typeCheckConfig(untrustedConfig) {
701
+ const config = {};
702
+ typeCheckConfig$3(untrustedConfig, config, putCommerceConfigurationAttribute_ConfigPropertyMetadata);
703
+ return config;
704
+ }
705
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
706
+ if (!untrustedIsObject(untrustedConfig)) {
707
+ return null;
708
+ }
709
+ if (process.env.NODE_ENV !== 'production') {
710
+ validateConfig(untrustedConfig, configPropertyNames);
711
+ }
712
+ const config = typeCheckConfig(untrustedConfig);
713
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
714
+ return null;
715
+ }
716
+ return config;
717
+ }
718
+ function buildNetworkSnapshot(luvio, config, options) {
719
+ const resourceParams = createResourceParams(config);
720
+ const request = createResourceRequest(resourceParams);
721
+ return luvio.dispatchResourceRequest(request, options)
722
+ .then((response) => {
723
+ return luvio.handleSuccessResponse(() => {
724
+ const snapshot = ingestSuccess(luvio, resourceParams, response);
725
+ return luvio.storeBroadcast().then(() => snapshot);
726
+ }, () => {
727
+ const cache = new StoreKeyMap();
728
+ getResponseCacheKeys(cache, luvio, resourceParams, response.body);
729
+ return cache;
730
+ });
731
+ }, (response) => {
732
+ deepFreeze(response);
733
+ throw response;
734
+ });
735
+ }
736
+ const putCommerceConfigurationAttributeAdapterFactory = (luvio) => {
737
+ return function putCommerceConfigurationAttribute(untrustedConfig) {
738
+ const config = validateAdapterConfig(untrustedConfig, putCommerceConfigurationAttribute_ConfigPropertyNames);
739
+ // Invalid or incomplete config
740
+ if (config === null) {
741
+ throw new Error('Invalid config for "putCommerceConfigurationAttribute"');
742
+ }
743
+ return buildNetworkSnapshot(luvio, config);
744
+ };
745
+ };
746
+
747
+ export { deleteCommerceConfigurationAttributeAdapterFactory, getCommerceConfigurationAttributeAdapterFactory, putCommerceConfigurationAttributeAdapterFactory };