@salesforce/lds-adapters-revenue-place-quote 1.124.2 → 1.124.3

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.
@@ -1,349 +0,0 @@
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.revenuePlaceQuote = {}, global.engine));
11
- })(this, (function (exports, engine) { 'use strict';
12
-
13
- const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
14
- const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = Object;
15
- const { isArray: ArrayIsArray$1 } = Array;
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
- const { displayName } = adapter;
25
- const { required, optional, unsupported } = adapter.parameters;
26
- if (config === undefined ||
27
- required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
28
- throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
29
- }
30
- if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
31
- throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
32
- }
33
- if (unsupported !== undefined &&
34
- unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
35
- throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
36
- }
37
- const supported = required.concat(optional);
38
- if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
39
- throw new TypeError(`adapter ${displayName} configuration supports only ${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(req => req in config);
47
- }
48
- const keyPrefix = 'place-quote';
49
-
50
- const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
51
- const { isArray: ArrayIsArray } = Array;
52
- const { stringify: JSONStringify } = JSON;
53
- function deepFreeze$2(value) {
54
- // No need to freeze primitives
55
- if (typeof value !== 'object' || value === null) {
56
- return;
57
- }
58
- if (ArrayIsArray(value)) {
59
- for (let i = 0, len = value.length; i < len; i += 1) {
60
- deepFreeze$2(value[i]);
61
- }
62
- }
63
- else {
64
- const keys = ObjectKeys(value);
65
- for (let i = 0, len = keys.length; i < len; i += 1) {
66
- deepFreeze$2(value[keys[i]]);
67
- }
68
- }
69
- ObjectFreeze(value);
70
- }
71
- function createLink(ref) {
72
- return {
73
- __ref: engine.serializeStructuredKey(ref),
74
- };
75
- }
76
-
77
- function validate$2(obj, path = 'PlaceQuoteInputRepresentation') {
78
- const v_error = (() => {
79
- if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
80
- return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
81
- }
82
- const obj_graph = obj.graph;
83
- const path_graph = path + '.graph';
84
- if (typeof obj_graph !== 'object' || ArrayIsArray(obj_graph) || obj_graph === null) {
85
- return new TypeError('Expected "object" but received "' + typeof obj_graph + '" (at "' + path_graph + '")');
86
- }
87
- const obj_pricingPref = obj.pricingPref;
88
- const path_pricingPref = path + '.pricingPref';
89
- if (typeof obj_pricingPref !== 'string') {
90
- return new TypeError('Expected "string" but received "' + typeof obj_pricingPref + '" (at "' + path_pricingPref + '")');
91
- }
92
- })();
93
- return v_error === undefined ? null : v_error;
94
- }
95
-
96
- function validate$1(obj, path = 'PlaceQuoteErrorResponseRepresentation') {
97
- const v_error = (() => {
98
- if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
99
- return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
100
- }
101
- const obj_errorCode = obj.errorCode;
102
- const path_errorCode = path + '.errorCode';
103
- if (typeof obj_errorCode !== 'string') {
104
- return new TypeError('Expected "string" but received "' + typeof obj_errorCode + '" (at "' + path_errorCode + '")');
105
- }
106
- const obj_message = obj.message;
107
- const path_message = path + '.message';
108
- if (typeof obj_message !== 'string') {
109
- return new TypeError('Expected "string" but received "' + typeof obj_message + '" (at "' + path_message + '")');
110
- }
111
- const obj_referenceId = obj.referenceId;
112
- const path_referenceId = path + '.referenceId';
113
- if (typeof obj_referenceId !== 'string') {
114
- return new TypeError('Expected "string" but received "' + typeof obj_referenceId + '" (at "' + path_referenceId + '")');
115
- }
116
- })();
117
- return v_error === undefined ? null : v_error;
118
- }
119
- function deepFreeze$1(input) {
120
- ObjectFreeze(input);
121
- }
122
-
123
- const TTL = 1000;
124
- const VERSION = "32a768cba447434ebb8e37e67aed1302";
125
- function validate(obj, path = 'PlaceQuoteOutputRepresentation') {
126
- const v_error = (() => {
127
- if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
128
- return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
129
- }
130
- const obj_quoteId = obj.quoteId;
131
- const path_quoteId = path + '.quoteId';
132
- if (typeof obj_quoteId !== 'string') {
133
- return new TypeError('Expected "string" but received "' + typeof obj_quoteId + '" (at "' + path_quoteId + '")');
134
- }
135
- const obj_requestIdentifier = obj.requestIdentifier;
136
- const path_requestIdentifier = path + '.requestIdentifier';
137
- if (typeof obj_requestIdentifier !== 'string') {
138
- return new TypeError('Expected "string" but received "' + typeof obj_requestIdentifier + '" (at "' + path_requestIdentifier + '")');
139
- }
140
- const obj_responseError = obj.responseError;
141
- const path_responseError = path + '.responseError';
142
- if (!ArrayIsArray(obj_responseError)) {
143
- return new TypeError('Expected "array" but received "' + typeof obj_responseError + '" (at "' + path_responseError + '")');
144
- }
145
- for (let i = 0; i < obj_responseError.length; i++) {
146
- const obj_responseError_item = obj_responseError[i];
147
- const path_responseError_item = path_responseError + '[' + i + ']';
148
- const referencepath_responseError_itemValidationError = validate$1(obj_responseError_item, path_responseError_item);
149
- if (referencepath_responseError_itemValidationError !== null) {
150
- let message = 'Object doesn\'t match PlaceQuoteErrorResponseRepresentation (at "' + path_responseError_item + '")\n';
151
- message += referencepath_responseError_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
152
- return new TypeError(message);
153
- }
154
- }
155
- const obj_statusURL = obj.statusURL;
156
- const path_statusURL = path + '.statusURL';
157
- if (typeof obj_statusURL !== 'string') {
158
- return new TypeError('Expected "string" but received "' + typeof obj_statusURL + '" (at "' + path_statusURL + '")');
159
- }
160
- const obj_success = obj.success;
161
- const path_success = path + '.success';
162
- if (typeof obj_success !== 'boolean') {
163
- return new TypeError('Expected "boolean" but received "' + typeof obj_success + '" (at "' + path_success + '")');
164
- }
165
- })();
166
- return v_error === undefined ? null : v_error;
167
- }
168
- const RepresentationType = 'PlaceQuoteOutputRepresentation';
169
- function keyBuilder(luvio, config) {
170
- return keyPrefix + '::' + RepresentationType + ':' + config.quoteId;
171
- }
172
- function keyBuilderFromType(luvio, object) {
173
- const keyParams = {
174
- quoteId: object.quoteId
175
- };
176
- return keyBuilder(luvio, keyParams);
177
- }
178
- function normalize(input, existing, path, luvio, store, timestamp) {
179
- return input;
180
- }
181
- const select$1 = function PlaceQuoteOutputRepresentationSelect() {
182
- return {
183
- kind: 'Fragment',
184
- version: VERSION,
185
- private: [],
186
- opaque: true
187
- };
188
- };
189
- function equals(existing, incoming) {
190
- if (JSONStringify(incoming) !== JSONStringify(existing)) {
191
- return false;
192
- }
193
- return true;
194
- }
195
- function deepFreeze(input) {
196
- const input_responseError = input.responseError;
197
- for (let i = 0; i < input_responseError.length; i++) {
198
- const input_responseError_item = input_responseError[i];
199
- deepFreeze$1(input_responseError_item);
200
- }
201
- ObjectFreeze(input_responseError);
202
- ObjectFreeze(input);
203
- }
204
- const ingest = function PlaceQuoteOutputRepresentationIngest(input, path, luvio, store, timestamp) {
205
- if (process.env.NODE_ENV !== 'production') {
206
- const validateError = validate(input);
207
- if (validateError !== null) {
208
- throw validateError;
209
- }
210
- }
211
- const key = keyBuilderFromType(luvio, input);
212
- const existingRecord = store.readEntry(key);
213
- const ttlToUse = TTL;
214
- let incomingRecord = normalize(input, store.readEntry(key), {
215
- fullPath: key,
216
- parent: path.parent,
217
- propertyName: path.propertyName,
218
- ttl: ttlToUse
219
- });
220
- deepFreeze(input);
221
- if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
222
- luvio.storePublish(key, incomingRecord);
223
- }
224
- {
225
- const storeMetadataParams = {
226
- ttl: ttlToUse,
227
- namespace: "place-quote",
228
- version: VERSION,
229
- representationName: RepresentationType,
230
- };
231
- luvio.publishStoreMetadata(key, storeMetadataParams);
232
- }
233
- return createLink(key);
234
- };
235
- function getTypeCacheKeys(luvio, input, fullPathFactory) {
236
- const rootKeySet = new engine.StoreKeyMap();
237
- // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
238
- const rootKey = keyBuilderFromType(luvio, input);
239
- rootKeySet.set(rootKey, {
240
- namespace: keyPrefix,
241
- representationName: RepresentationType,
242
- mergeable: false
243
- });
244
- return rootKeySet;
245
- }
246
-
247
- function select(luvio, params) {
248
- return select$1();
249
- }
250
- function getResponseCacheKeys(luvio, resourceParams, response) {
251
- return getTypeCacheKeys(luvio, response);
252
- }
253
- function ingestSuccess(luvio, resourceParams, response) {
254
- const { body } = response;
255
- const key = keyBuilderFromType(luvio, body);
256
- luvio.storeIngest(key, ingest, body);
257
- const snapshot = luvio.storeLookup({
258
- recordId: key,
259
- node: select(),
260
- variables: {},
261
- });
262
- if (process.env.NODE_ENV !== 'production') {
263
- if (snapshot.state !== 'Fulfilled') {
264
- throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
265
- }
266
- }
267
- return snapshot;
268
- }
269
- function createResourceRequest(config) {
270
- const headers = {};
271
- return {
272
- baseUri: '/services/data/v58.0',
273
- basePath: '/commerce/quotes/actions/place',
274
- method: 'post',
275
- body: config.body,
276
- urlParams: {},
277
- queryParams: {},
278
- headers,
279
- priority: 'normal',
280
- };
281
- }
282
-
283
- const updateQuote_ConfigPropertyNames = {
284
- displayName: 'updateQuote',
285
- parameters: {
286
- required: ['PlaceQuoteInput'],
287
- optional: []
288
- }
289
- };
290
- function createResourceParams(config) {
291
- const resourceParams = {
292
- body: {
293
- PlaceQuoteInput: config.PlaceQuoteInput
294
- }
295
- };
296
- return resourceParams;
297
- }
298
- function typeCheckConfig(untrustedConfig) {
299
- const config = {};
300
- const untrustedConfig_PlaceQuoteInput = untrustedConfig.PlaceQuoteInput;
301
- const referencePlaceQuoteInputRepresentationValidationError = validate$2(untrustedConfig_PlaceQuoteInput);
302
- if (referencePlaceQuoteInputRepresentationValidationError === null) {
303
- config.PlaceQuoteInput = untrustedConfig_PlaceQuoteInput;
304
- }
305
- return config;
306
- }
307
- function validateAdapterConfig(untrustedConfig, configPropertyNames) {
308
- if (!untrustedIsObject(untrustedConfig)) {
309
- return null;
310
- }
311
- if (process.env.NODE_ENV !== 'production') {
312
- validateConfig(untrustedConfig, configPropertyNames);
313
- }
314
- const config = typeCheckConfig(untrustedConfig);
315
- if (!areRequiredParametersPresent(config, configPropertyNames)) {
316
- return null;
317
- }
318
- return config;
319
- }
320
- function buildNetworkSnapshot(luvio, config, options) {
321
- const resourceParams = createResourceParams(config);
322
- const request = createResourceRequest(resourceParams);
323
- return luvio.dispatchResourceRequest(request, options)
324
- .then((response) => {
325
- return luvio.handleSuccessResponse(() => {
326
- const snapshot = ingestSuccess(luvio, resourceParams, response);
327
- return luvio.storeBroadcast().then(() => snapshot);
328
- }, () => getResponseCacheKeys(luvio, resourceParams, response.body));
329
- }, (response) => {
330
- deepFreeze$2(response);
331
- throw response;
332
- });
333
- }
334
- const updateQuoteAdapterFactory = (luvio) => {
335
- return function updateQuote(untrustedConfig) {
336
- const config = validateAdapterConfig(untrustedConfig, updateQuote_ConfigPropertyNames);
337
- // Invalid or incomplete config
338
- if (config === null) {
339
- throw new Error('Invalid config for "updateQuote"');
340
- }
341
- return buildNetworkSnapshot(luvio, config);
342
- };
343
- };
344
-
345
- exports.updateQuoteAdapterFactory = updateQuoteAdapterFactory;
346
-
347
- Object.defineProperty(exports, '__esModule', { value: true });
348
-
349
- }));