@salesforce/lds-adapters-revenue-place-quote 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.
package/sfdc/index.js ADDED
@@ -0,0 +1,363 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ /* *******************************************************************************************
8
+ * ATTENTION!
9
+ * THIS IS A GENERATED FILE FROM https://github.com/salesforce-experience-platform-emu/lds-lightning-platform
10
+ * If you would like to contribute to LDS, please follow the steps outlined in the git repo.
11
+ * Any changes made to this file in p4 will be automatically overwritten.
12
+ * *******************************************************************************************
13
+ */
14
+ /* proxy-compat-disable */
15
+ import { withDefaultLuvio } from 'force/ldsEngine';
16
+ import { serializeStructuredKey, StoreKeyMap } from 'force/luvioEngine';
17
+
18
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
19
+ const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = Object;
20
+ const { isArray: ArrayIsArray$1 } = Array;
21
+ /**
22
+ * Validates an adapter config is well-formed.
23
+ * @param config The config to validate.
24
+ * @param adapter The adapter validation configuration.
25
+ * @param oneOf The keys the config must contain at least one of.
26
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
27
+ */
28
+ function validateConfig(config, adapter, oneOf) {
29
+ const { displayName } = adapter;
30
+ const { required, optional, unsupported } = adapter.parameters;
31
+ if (config === undefined ||
32
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
33
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
34
+ }
35
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
36
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
37
+ }
38
+ if (unsupported !== undefined &&
39
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
40
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
41
+ }
42
+ const supported = required.concat(optional);
43
+ if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
44
+ throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
45
+ }
46
+ }
47
+ function untrustedIsObject(untrusted) {
48
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
49
+ }
50
+ function areRequiredParametersPresent(config, configPropertyNames) {
51
+ return configPropertyNames.parameters.required.every(req => req in config);
52
+ }
53
+ const keyPrefix = 'place-quote';
54
+
55
+ const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
56
+ const { isArray: ArrayIsArray } = Array;
57
+ const { stringify: JSONStringify } = JSON;
58
+ function deepFreeze$2(value) {
59
+ // No need to freeze primitives
60
+ if (typeof value !== 'object' || value === null) {
61
+ return;
62
+ }
63
+ if (ArrayIsArray(value)) {
64
+ for (let i = 0, len = value.length; i < len; i += 1) {
65
+ deepFreeze$2(value[i]);
66
+ }
67
+ }
68
+ else {
69
+ const keys = ObjectKeys(value);
70
+ for (let i = 0, len = keys.length; i < len; i += 1) {
71
+ deepFreeze$2(value[keys[i]]);
72
+ }
73
+ }
74
+ ObjectFreeze(value);
75
+ }
76
+ function createLink(ref) {
77
+ return {
78
+ __ref: serializeStructuredKey(ref),
79
+ };
80
+ }
81
+
82
+ function validate$2(obj, path = 'PlaceQuoteInputRepresentation') {
83
+ const v_error = (() => {
84
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
85
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
86
+ }
87
+ const obj_graph = obj.graph;
88
+ const path_graph = path + '.graph';
89
+ if (typeof obj_graph !== 'object' || ArrayIsArray(obj_graph) || obj_graph === null) {
90
+ return new TypeError('Expected "object" but received "' + typeof obj_graph + '" (at "' + path_graph + '")');
91
+ }
92
+ const obj_pricingPref = obj.pricingPref;
93
+ const path_pricingPref = path + '.pricingPref';
94
+ if (typeof obj_pricingPref !== 'string') {
95
+ return new TypeError('Expected "string" but received "' + typeof obj_pricingPref + '" (at "' + path_pricingPref + '")');
96
+ }
97
+ })();
98
+ return v_error === undefined ? null : v_error;
99
+ }
100
+
101
+ function validate$1(obj, path = 'ErrorResponseRepresentation') {
102
+ const v_error = (() => {
103
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
104
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
105
+ }
106
+ const obj_code = obj.code;
107
+ const path_code = path + '.code';
108
+ if (typeof obj_code !== 'string') {
109
+ return new TypeError('Expected "string" but received "' + typeof obj_code + '" (at "' + path_code + '")');
110
+ }
111
+ const obj_message = obj.message;
112
+ const path_message = path + '.message';
113
+ if (typeof obj_message !== 'string') {
114
+ return new TypeError('Expected "string" but received "' + typeof obj_message + '" (at "' + path_message + '")');
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 = "22e4c1bbe677338ea9ad9559e8856dfe";
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 ErrorResponseRepresentation (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 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
+ let updateQuote;
346
+ function bindExportsTo(luvio) {
347
+ function unwrapSnapshotData(factory) {
348
+ const adapter = factory(luvio);
349
+ return (config) => adapter(config).then(snapshot => snapshot.data);
350
+ }
351
+ return {
352
+ updateQuote: unwrapSnapshotData(updateQuoteAdapterFactory),
353
+ // Imperative GET Adapters
354
+ };
355
+ }
356
+ withDefaultLuvio((luvio) => {
357
+ ({
358
+ updateQuote,
359
+ } = bindExportsTo(luvio));
360
+ });
361
+
362
+ export { updateQuote };
363
+ // version: 1.100.2-ca56bb821
@@ -0,0 +1,93 @@
1
+ #%RAML 1.0
2
+ securedBy:
3
+ - OAuth2
4
+ title: Salesforce Connect API
5
+ version: '58.0'
6
+ mediaType: application/json
7
+ protocols:
8
+ - https
9
+ baseUri: /services/data/v58.0
10
+ securitySchemes:
11
+ OAuth2:
12
+ type: OAuth 2.0
13
+ settings:
14
+ authorizationUri: https://example.com/oauth/authorize
15
+ accessTokenUri: ''
16
+ authorizationGrants:
17
+ - implicit
18
+ annotationTypes:
19
+ oas-readOnly:
20
+ type: boolean
21
+ allowedTargets: TypeDeclaration
22
+ oas-collectionFormat:
23
+ type: string
24
+ oas-body-name:
25
+ type: string
26
+ allowedTargets: TypeDeclaration
27
+ types:
28
+ PlaceQuoteInputWrapperRepresentation: # TODO Hand-rolled W-8334626
29
+ description: Wrapper for place quote input representation
30
+ type: object
31
+ properties:
32
+ PlaceQuoteInput:
33
+ type: PlaceQuoteInputRepresentation
34
+ description: Place Quote Input Representation
35
+ PlaceQuoteInputRepresentation:
36
+ description: Input representation for place quote.
37
+ type: object
38
+ properties:
39
+ graph:
40
+ description: SObject Graph representing the quote structure for place quote
41
+ type: object
42
+ pricingPref:
43
+ description: Pricing Preference for place quote
44
+ type: string
45
+ enum:
46
+ - Force
47
+ - Skip
48
+ - System
49
+ PlaceQuoteOutputRepresentation:
50
+ description: Place Quote output representation
51
+ type: object
52
+ properties:
53
+ quoteId:
54
+ description: QUOTE ID
55
+ type: string
56
+ requestIdentifier:
57
+ description: Unique request identifier that can be used to poll async request
58
+ type: string
59
+ responseError:
60
+ description: response error
61
+ type: array
62
+ items:
63
+ type: ErrorResponseRepresentation
64
+ statusURL:
65
+ description: a StatusURL for tracking this operation
66
+ type: string
67
+ success:
68
+ description: success
69
+ type: boolean
70
+ ErrorResponseRepresentation:
71
+ description: Error response representation
72
+ type: object
73
+ properties:
74
+ code:
75
+ description: Code for Error
76
+ type: string
77
+ message:
78
+ description: Message stating the reason for error, if any
79
+ type: string
80
+ /commerce/quotes/actions/place:
81
+ post:
82
+ description: place quote
83
+ responses:
84
+ '200':
85
+ description: Success
86
+ body:
87
+ application/json:
88
+ type: PlaceQuoteOutputRepresentation
89
+ body:
90
+ application/json:
91
+ type: PlaceQuoteInputWrapperRepresentation
92
+ #required: false # TODO handrolled W-9314597
93
+ (oas-body-name): PlaceQuoteInput
@@ -0,0 +1,72 @@
1
+ #%RAML 1.0 Overlay
2
+ extends: ./api.raml
3
+
4
+ uses:
5
+ luvio: luvio://annotations.raml
6
+
7
+ (luvio.keyPrefix): 'place-quote'
8
+
9
+ types:
10
+ PlaceQuoteOutputRepresentation:
11
+ (luvio.ttl): 1000
12
+ (luvio.opaque): true
13
+ (luvio.key):
14
+ quoteId: quoteId
15
+
16
+ /commerce/quotes/actions/place:
17
+ post:
18
+ (luvio.adapter):
19
+ name: updateQuote
20
+ tests:
21
+ validConfigs:
22
+ - |
23
+ { "PlaceQuoteInput":
24
+ {
25
+ "pricingPref": "Force",
26
+ "graph": {
27
+ "graphId": "updateQuote",
28
+ "records": [{
29
+ "referenceId": "refQuote",
30
+ "record": {
31
+ "attributes": {
32
+ "type": "Quote",
33
+ "method": "PATCH",
34
+ "id": "0Q0RO00000033pc0AA"
35
+ }
36
+ }
37
+ },
38
+ {
39
+ "referenceId": "refQLIId",
40
+ "record": {
41
+ "attributes": {
42
+ "type": "QuoteLineItem",
43
+ "method": "PATCH",
44
+ "id": "0QLT30000000145OAA"
45
+ },
46
+ "Discount": 2
47
+ }
48
+ }]
49
+ }
50
+ }
51
+ }
52
+ invalidConfigs:
53
+ - |
54
+ {
55
+ "pricingPref": "Skip"
56
+ }
57
+ - |
58
+ {
59
+ "graph": {}
60
+ }
61
+ - |
62
+ { "PlaceQuoteInput":
63
+ {
64
+ "graph": {}
65
+ }
66
+ }
67
+ - |
68
+ { "PlaceQuoteInput":
69
+ {
70
+ "pricingPref": "force"
71
+ }
72
+ }