@salesforce/lds-adapters-industries-tearsheet 1.124.2 → 1.124.4

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.
@@ -6,348 +6,348 @@
6
6
 
7
7
  import { serializeStructuredKey, StoreKeyMap } from '@luvio/engine';
8
8
 
9
- const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
- const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = 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$1(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
- };
9
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
+ const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = 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$1(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
51
  const keyPrefix = 'tearsheet';
52
52
 
53
- const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
54
- const { isArray: ArrayIsArray } = Array;
55
- const { stringify: JSONStringify } = JSON;
56
- function createLink(ref) {
57
- return {
58
- __ref: serializeStructuredKey(ref),
59
- };
53
+ const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
54
+ const { isArray: ArrayIsArray } = Array;
55
+ const { stringify: JSONStringify } = JSON;
56
+ function createLink(ref) {
57
+ return {
58
+ __ref: serializeStructuredKey(ref),
59
+ };
60
60
  }
61
61
 
62
- function validate$1(obj, path = 'TearsheetRepresentation') {
63
- const v_error = (() => {
64
- if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
65
- return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
66
- }
67
- const obj_id = obj.id;
68
- const path_id = path + '.id';
69
- if (typeof obj_id !== 'string') {
70
- return new TypeError('Expected "string" but received "' + typeof obj_id + '" (at "' + path_id + '")');
71
- }
72
- const obj_title = obj.title;
73
- const path_title = path + '.title';
74
- if (typeof obj_title !== 'string') {
75
- return new TypeError('Expected "string" but received "' + typeof obj_title + '" (at "' + path_title + '")');
76
- }
77
- })();
78
- return v_error === undefined ? null : v_error;
79
- }
80
- function deepFreeze$1(input) {
81
- ObjectFreeze(input);
62
+ function validate$1(obj, path = 'TearsheetRepresentation') {
63
+ const v_error = (() => {
64
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
65
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
66
+ }
67
+ const obj_id = obj.id;
68
+ const path_id = path + '.id';
69
+ if (typeof obj_id !== 'string') {
70
+ return new TypeError('Expected "string" but received "' + typeof obj_id + '" (at "' + path_id + '")');
71
+ }
72
+ const obj_title = obj.title;
73
+ const path_title = path + '.title';
74
+ if (typeof obj_title !== 'string') {
75
+ return new TypeError('Expected "string" but received "' + typeof obj_title + '" (at "' + path_title + '")');
76
+ }
77
+ })();
78
+ return v_error === undefined ? null : v_error;
79
+ }
80
+ function deepFreeze$1(input) {
81
+ ObjectFreeze(input);
82
82
  }
83
83
 
84
- const TTL = 1000;
85
- const VERSION = "33cf28595aef16a27da68accf962bce3";
86
- function validate(obj, path = 'TearsheetListRepresentation') {
87
- const v_error = (() => {
88
- if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
89
- return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
90
- }
91
- const obj_data = obj.data;
92
- const path_data = path + '.data';
93
- if (!ArrayIsArray(obj_data)) {
94
- return new TypeError('Expected "array" but received "' + typeof obj_data + '" (at "' + path_data + '")');
95
- }
96
- for (let i = 0; i < obj_data.length; i++) {
97
- const obj_data_item = obj_data[i];
98
- const path_data_item = path_data + '[' + i + ']';
99
- const referencepath_data_itemValidationError = validate$1(obj_data_item, path_data_item);
100
- if (referencepath_data_itemValidationError !== null) {
101
- let message = 'Object doesn\'t match TearsheetRepresentation (at "' + path_data_item + '")\n';
102
- message += referencepath_data_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
103
- return new TypeError(message);
104
- }
105
- }
106
- })();
107
- return v_error === undefined ? null : v_error;
108
- }
109
- const RepresentationType = 'TearsheetListRepresentation';
110
- function normalize(input, existing, path, luvio, store, timestamp) {
111
- return input;
112
- }
113
- const select$1 = function TearsheetListRepresentationSelect() {
114
- return {
115
- kind: 'Fragment',
116
- version: VERSION,
117
- private: [],
118
- opaque: true
119
- };
120
- };
121
- function equals(existing, incoming) {
122
- if (JSONStringify(incoming) !== JSONStringify(existing)) {
123
- return false;
124
- }
125
- return true;
126
- }
127
- function deepFreeze(input) {
128
- const input_data = input.data;
129
- for (let i = 0; i < input_data.length; i++) {
130
- const input_data_item = input_data[i];
131
- deepFreeze$1(input_data_item);
132
- }
133
- ObjectFreeze(input_data);
134
- ObjectFreeze(input);
135
- }
136
- const ingest = function TearsheetListRepresentationIngest(input, path, luvio, store, timestamp) {
137
- if (process.env.NODE_ENV !== 'production') {
138
- const validateError = validate(input);
139
- if (validateError !== null) {
140
- throw validateError;
141
- }
142
- }
143
- const key = path.fullPath;
144
- const existingRecord = store.readEntry(key);
145
- const ttlToUse = TTL;
146
- let incomingRecord = normalize(input, store.readEntry(key), {
147
- fullPath: key,
148
- parent: path.parent,
149
- propertyName: path.propertyName,
150
- ttl: ttlToUse
151
- });
152
- deepFreeze(input);
153
- if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
154
- luvio.storePublish(key, incomingRecord);
155
- }
156
- {
157
- const storeMetadataParams = {
158
- ttl: ttlToUse,
159
- namespace: "tearsheet",
160
- version: VERSION,
161
- representationName: RepresentationType,
162
- };
163
- luvio.publishStoreMetadata(key, storeMetadataParams);
164
- }
165
- return createLink(key);
166
- };
167
- function getTypeCacheKeys(luvio, input, fullPathFactory) {
168
- const rootKeySet = new StoreKeyMap();
169
- // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
170
- const rootKey = fullPathFactory();
171
- rootKeySet.set(rootKey, {
172
- namespace: keyPrefix,
173
- representationName: RepresentationType,
174
- mergeable: false
175
- });
176
- return rootKeySet;
84
+ const TTL = 1000;
85
+ const VERSION = "33cf28595aef16a27da68accf962bce3";
86
+ function validate(obj, path = 'TearsheetListRepresentation') {
87
+ const v_error = (() => {
88
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
89
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
90
+ }
91
+ const obj_data = obj.data;
92
+ const path_data = path + '.data';
93
+ if (!ArrayIsArray(obj_data)) {
94
+ return new TypeError('Expected "array" but received "' + typeof obj_data + '" (at "' + path_data + '")');
95
+ }
96
+ for (let i = 0; i < obj_data.length; i++) {
97
+ const obj_data_item = obj_data[i];
98
+ const path_data_item = path_data + '[' + i + ']';
99
+ const referencepath_data_itemValidationError = validate$1(obj_data_item, path_data_item);
100
+ if (referencepath_data_itemValidationError !== null) {
101
+ let message = 'Object doesn\'t match TearsheetRepresentation (at "' + path_data_item + '")\n';
102
+ message += referencepath_data_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
103
+ return new TypeError(message);
104
+ }
105
+ }
106
+ })();
107
+ return v_error === undefined ? null : v_error;
108
+ }
109
+ const RepresentationType = 'TearsheetListRepresentation';
110
+ function normalize(input, existing, path, luvio, store, timestamp) {
111
+ return input;
112
+ }
113
+ const select$1 = function TearsheetListRepresentationSelect() {
114
+ return {
115
+ kind: 'Fragment',
116
+ version: VERSION,
117
+ private: [],
118
+ opaque: true
119
+ };
120
+ };
121
+ function equals(existing, incoming) {
122
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
123
+ return false;
124
+ }
125
+ return true;
126
+ }
127
+ function deepFreeze(input) {
128
+ const input_data = input.data;
129
+ for (let i = 0; i < input_data.length; i++) {
130
+ const input_data_item = input_data[i];
131
+ deepFreeze$1(input_data_item);
132
+ }
133
+ ObjectFreeze(input_data);
134
+ ObjectFreeze(input);
135
+ }
136
+ const ingest = function TearsheetListRepresentationIngest(input, path, luvio, store, timestamp) {
137
+ if (process.env.NODE_ENV !== 'production') {
138
+ const validateError = validate(input);
139
+ if (validateError !== null) {
140
+ throw validateError;
141
+ }
142
+ }
143
+ const key = path.fullPath;
144
+ const existingRecord = store.readEntry(key);
145
+ const ttlToUse = TTL;
146
+ let incomingRecord = normalize(input, store.readEntry(key), {
147
+ fullPath: key,
148
+ parent: path.parent,
149
+ propertyName: path.propertyName,
150
+ ttl: ttlToUse
151
+ });
152
+ deepFreeze(input);
153
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
154
+ luvio.storePublish(key, incomingRecord);
155
+ }
156
+ {
157
+ const storeMetadataParams = {
158
+ ttl: ttlToUse,
159
+ namespace: "tearsheet",
160
+ version: VERSION,
161
+ representationName: RepresentationType,
162
+ };
163
+ luvio.publishStoreMetadata(key, storeMetadataParams);
164
+ }
165
+ return createLink(key);
166
+ };
167
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
168
+ const rootKeySet = new StoreKeyMap();
169
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
170
+ const rootKey = fullPathFactory();
171
+ rootKeySet.set(rootKey, {
172
+ namespace: keyPrefix,
173
+ representationName: RepresentationType,
174
+ mergeable: false
175
+ });
176
+ return rootKeySet;
177
177
  }
178
178
 
179
- function select(luvio, params) {
180
- return select$1();
181
- }
182
- function keyBuilder$1(luvio, params) {
183
- return keyPrefix + '::TearsheetListRepresentation:(' + 'limit:' + params.queryParams.limit + ',' + 'offset:' + params.queryParams.offset + ',' + 'templateType:' + params.queryParams.templateType + ',' + 'accountId:' + params.urlParams.accountId + ')';
184
- }
185
- function getResponseCacheKeys(luvio, resourceParams, response) {
186
- return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
187
- }
188
- function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
189
- const { body } = response;
190
- const key = keyBuilder$1(luvio, resourceParams);
191
- luvio.storeIngest(key, ingest, body);
192
- const snapshot = luvio.storeLookup({
193
- recordId: key,
194
- node: select(),
195
- variables: {},
196
- }, snapshotRefresh);
197
- if (process.env.NODE_ENV !== 'production') {
198
- if (snapshot.state !== 'Fulfilled') {
199
- throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
200
- }
201
- }
202
- return snapshot;
203
- }
204
- function ingestError(luvio, params, error, snapshotRefresh) {
205
- const key = keyBuilder$1(luvio, params);
206
- const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
207
- const storeMetadataParams = {
208
- ttl: TTL,
209
- namespace: keyPrefix,
210
- version: VERSION,
211
- representationName: RepresentationType
212
- };
213
- luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
214
- return errorSnapshot;
215
- }
216
- function createResourceRequest(config) {
217
- const headers = {};
218
- return {
219
- baseUri: '/services/data/v58.0',
220
- basePath: '/connect/financialservices/tearsheets/' + config.urlParams.accountId + '',
221
- method: 'get',
222
- body: null,
223
- urlParams: config.urlParams,
224
- queryParams: config.queryParams,
225
- headers,
226
- priority: 'normal',
227
- };
179
+ function select(luvio, params) {
180
+ return select$1();
181
+ }
182
+ function keyBuilder$1(luvio, params) {
183
+ return keyPrefix + '::TearsheetListRepresentation:(' + 'limit:' + params.queryParams.limit + ',' + 'offset:' + params.queryParams.offset + ',' + 'templateType:' + params.queryParams.templateType + ',' + 'accountId:' + params.urlParams.accountId + ')';
184
+ }
185
+ function getResponseCacheKeys(luvio, resourceParams, response) {
186
+ return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
187
+ }
188
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
189
+ const { body } = response;
190
+ const key = keyBuilder$1(luvio, resourceParams);
191
+ luvio.storeIngest(key, ingest, body);
192
+ const snapshot = luvio.storeLookup({
193
+ recordId: key,
194
+ node: select(),
195
+ variables: {},
196
+ }, snapshotRefresh);
197
+ if (process.env.NODE_ENV !== 'production') {
198
+ if (snapshot.state !== 'Fulfilled') {
199
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
200
+ }
201
+ }
202
+ return snapshot;
203
+ }
204
+ function ingestError(luvio, params, error, snapshotRefresh) {
205
+ const key = keyBuilder$1(luvio, params);
206
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
207
+ const storeMetadataParams = {
208
+ ttl: TTL,
209
+ namespace: keyPrefix,
210
+ version: VERSION,
211
+ representationName: RepresentationType
212
+ };
213
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
214
+ return errorSnapshot;
215
+ }
216
+ function createResourceRequest(config) {
217
+ const headers = {};
218
+ return {
219
+ baseUri: '/services/data/v58.0',
220
+ basePath: '/connect/financialservices/tearsheets/' + config.urlParams.accountId + '',
221
+ method: 'get',
222
+ body: null,
223
+ urlParams: config.urlParams,
224
+ queryParams: config.queryParams,
225
+ headers,
226
+ priority: 'normal',
227
+ };
228
228
  }
229
229
 
230
- const getTearsheets_ConfigPropertyNames = {
231
- displayName: 'getTearsheets',
232
- parameters: {
233
- required: ['accountId'],
234
- optional: ['limit', 'offset', 'templateType']
235
- }
236
- };
237
- function createResourceParams(config) {
238
- const resourceParams = {
239
- urlParams: {
240
- accountId: config.accountId
241
- },
242
- queryParams: {
243
- limit: config.limit, offset: config.offset, templateType: config.templateType
244
- }
245
- };
246
- return resourceParams;
247
- }
248
- function keyBuilder(luvio, config) {
249
- const resourceParams = createResourceParams(config);
250
- return keyBuilder$1(luvio, resourceParams);
251
- }
252
- function typeCheckConfig(untrustedConfig) {
253
- const config = {};
254
- const untrustedConfig_accountId = untrustedConfig.accountId;
255
- if (typeof untrustedConfig_accountId === 'string') {
256
- config.accountId = untrustedConfig_accountId;
257
- }
258
- const untrustedConfig_limit = untrustedConfig.limit;
259
- if (typeof untrustedConfig_limit === 'number' && Math.floor(untrustedConfig_limit) === untrustedConfig_limit) {
260
- config.limit = untrustedConfig_limit;
261
- }
262
- const untrustedConfig_offset = untrustedConfig.offset;
263
- if (typeof untrustedConfig_offset === 'number' && Math.floor(untrustedConfig_offset) === untrustedConfig_offset) {
264
- config.offset = untrustedConfig_offset;
265
- }
266
- const untrustedConfig_templateType = untrustedConfig.templateType;
267
- if (typeof untrustedConfig_templateType === 'string') {
268
- config.templateType = untrustedConfig_templateType;
269
- }
270
- return config;
271
- }
272
- function validateAdapterConfig(untrustedConfig, configPropertyNames) {
273
- if (!untrustedIsObject(untrustedConfig)) {
274
- return null;
275
- }
276
- if (process.env.NODE_ENV !== 'production') {
277
- validateConfig(untrustedConfig, configPropertyNames);
278
- }
279
- const config = typeCheckConfig(untrustedConfig);
280
- if (!areRequiredParametersPresent(config, configPropertyNames)) {
281
- return null;
282
- }
283
- return config;
284
- }
285
- function adapterFragment(luvio, config) {
286
- createResourceParams(config);
287
- return select();
288
- }
289
- function onFetchResponseSuccess(luvio, config, resourceParams, response) {
290
- const snapshot = ingestSuccess(luvio, resourceParams, response, {
291
- config,
292
- resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
293
- });
294
- return luvio.storeBroadcast().then(() => snapshot);
295
- }
296
- function onFetchResponseError(luvio, config, resourceParams, response) {
297
- const snapshot = ingestError(luvio, resourceParams, response, {
298
- config,
299
- resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
300
- });
301
- return luvio.storeBroadcast().then(() => snapshot);
302
- }
303
- function buildNetworkSnapshot(luvio, config, options) {
304
- const resourceParams = createResourceParams(config);
305
- const request = createResourceRequest(resourceParams);
306
- return luvio.dispatchResourceRequest(request, options)
307
- .then((response) => {
308
- return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
309
- }, (response) => {
310
- return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
311
- });
312
- }
313
- function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
314
- const { luvio, config } = context;
315
- const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
316
- const dispatchOptions = {
317
- resourceRequestContext: {
318
- requestCorrelator,
319
- luvioRequestMethod: undefined,
320
- },
321
- eventObservers
322
- };
323
- if (networkPriority !== 'normal') {
324
- dispatchOptions.overrides = {
325
- priority: networkPriority
326
- };
327
- }
328
- return buildNetworkSnapshot(luvio, config, dispatchOptions);
329
- }
330
- function buildCachedSnapshotCachePolicy(context, storeLookup) {
331
- const { luvio, config } = context;
332
- const selector = {
333
- recordId: keyBuilder(luvio, config),
334
- node: adapterFragment(luvio, config),
335
- variables: {},
336
- };
337
- const cacheSnapshot = storeLookup(selector, {
338
- config,
339
- resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
340
- });
341
- return cacheSnapshot;
342
- }
343
- const getTearsheetsAdapterFactory = (luvio) => function tearsheet__getTearsheets(untrustedConfig, requestContext) {
344
- const config = validateAdapterConfig(untrustedConfig, getTearsheets_ConfigPropertyNames);
345
- // Invalid or incomplete config
346
- if (config === null) {
347
- return null;
348
- }
349
- return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
350
- buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
230
+ const getTearsheets_ConfigPropertyNames = {
231
+ displayName: 'getTearsheets',
232
+ parameters: {
233
+ required: ['accountId'],
234
+ optional: ['limit', 'offset', 'templateType']
235
+ }
236
+ };
237
+ function createResourceParams(config) {
238
+ const resourceParams = {
239
+ urlParams: {
240
+ accountId: config.accountId
241
+ },
242
+ queryParams: {
243
+ limit: config.limit, offset: config.offset, templateType: config.templateType
244
+ }
245
+ };
246
+ return resourceParams;
247
+ }
248
+ function keyBuilder(luvio, config) {
249
+ const resourceParams = createResourceParams(config);
250
+ return keyBuilder$1(luvio, resourceParams);
251
+ }
252
+ function typeCheckConfig(untrustedConfig) {
253
+ const config = {};
254
+ const untrustedConfig_accountId = untrustedConfig.accountId;
255
+ if (typeof untrustedConfig_accountId === 'string') {
256
+ config.accountId = untrustedConfig_accountId;
257
+ }
258
+ const untrustedConfig_limit = untrustedConfig.limit;
259
+ if (typeof untrustedConfig_limit === 'number' && Math.floor(untrustedConfig_limit) === untrustedConfig_limit) {
260
+ config.limit = untrustedConfig_limit;
261
+ }
262
+ const untrustedConfig_offset = untrustedConfig.offset;
263
+ if (typeof untrustedConfig_offset === 'number' && Math.floor(untrustedConfig_offset) === untrustedConfig_offset) {
264
+ config.offset = untrustedConfig_offset;
265
+ }
266
+ const untrustedConfig_templateType = untrustedConfig.templateType;
267
+ if (typeof untrustedConfig_templateType === 'string') {
268
+ config.templateType = untrustedConfig_templateType;
269
+ }
270
+ return config;
271
+ }
272
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
273
+ if (!untrustedIsObject(untrustedConfig)) {
274
+ return null;
275
+ }
276
+ if (process.env.NODE_ENV !== 'production') {
277
+ validateConfig(untrustedConfig, configPropertyNames);
278
+ }
279
+ const config = typeCheckConfig(untrustedConfig);
280
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
281
+ return null;
282
+ }
283
+ return config;
284
+ }
285
+ function adapterFragment(luvio, config) {
286
+ createResourceParams(config);
287
+ return select();
288
+ }
289
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
290
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
291
+ config,
292
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
293
+ });
294
+ return luvio.storeBroadcast().then(() => snapshot);
295
+ }
296
+ function onFetchResponseError(luvio, config, resourceParams, response) {
297
+ const snapshot = ingestError(luvio, resourceParams, response, {
298
+ config,
299
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
300
+ });
301
+ return luvio.storeBroadcast().then(() => snapshot);
302
+ }
303
+ function buildNetworkSnapshot(luvio, config, options) {
304
+ const resourceParams = createResourceParams(config);
305
+ const request = createResourceRequest(resourceParams);
306
+ return luvio.dispatchResourceRequest(request, options)
307
+ .then((response) => {
308
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
309
+ }, (response) => {
310
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
311
+ });
312
+ }
313
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
314
+ const { luvio, config } = context;
315
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
316
+ const dispatchOptions = {
317
+ resourceRequestContext: {
318
+ requestCorrelator,
319
+ luvioRequestMethod: undefined,
320
+ },
321
+ eventObservers
322
+ };
323
+ if (networkPriority !== 'normal') {
324
+ dispatchOptions.overrides = {
325
+ priority: networkPriority
326
+ };
327
+ }
328
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
329
+ }
330
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
331
+ const { luvio, config } = context;
332
+ const selector = {
333
+ recordId: keyBuilder(luvio, config),
334
+ node: adapterFragment(luvio, config),
335
+ variables: {},
336
+ };
337
+ const cacheSnapshot = storeLookup(selector, {
338
+ config,
339
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
340
+ });
341
+ return cacheSnapshot;
342
+ }
343
+ const getTearsheetsAdapterFactory = (luvio) => function tearsheet__getTearsheets(untrustedConfig, requestContext) {
344
+ const config = validateAdapterConfig(untrustedConfig, getTearsheets_ConfigPropertyNames);
345
+ // Invalid or incomplete config
346
+ if (config === null) {
347
+ return null;
348
+ }
349
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
350
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
351
351
  };
352
352
 
353
353
  export { getTearsheetsAdapterFactory };