@salesforce/lds-adapters-industries-tearsheet 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.
@@ -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
+ (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.industriesTearsheet = {}, global.engine));
11
+ })(this, (function (exports, engine) { 'use strict';
12
+
13
+ var ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
14
+ var ObjectKeys = Object.keys;
15
+ var ArrayIsArray$1 = Array.isArray;
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
+ var displayName = adapter.displayName;
25
+ var _a = adapter.parameters, required = _a.required, optional = _a.optional, unsupported = _a.unsupported;
26
+ if (config === undefined ||
27
+ required.every(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); }) === false) {
28
+ throw new TypeError("adapter ".concat(displayName, " configuration must specify ").concat(required.sort().join(', ')));
29
+ }
30
+ if (oneOf && oneOf.some(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); }) === false) {
31
+ throw new TypeError("adapter ".concat(displayName, " configuration must specify one of ").concat(oneOf.sort().join(', ')));
32
+ }
33
+ if (unsupported !== undefined &&
34
+ unsupported.some(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); })) {
35
+ throw new TypeError("adapter ".concat(displayName, " does not yet support ").concat(unsupported.sort().join(', ')));
36
+ }
37
+ var supported = required.concat(optional);
38
+ if (ObjectKeys(config).some(function (key) { return !supported.includes(key); })) {
39
+ throw new TypeError("adapter ".concat(displayName, " configuration supports only ").concat(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(function (req) { return req in config; });
47
+ }
48
+ var snapshotRefreshOptions = {
49
+ overrides: {
50
+ headers: {
51
+ 'Cache-Control': 'no-cache',
52
+ },
53
+ }
54
+ };
55
+ var keyPrefix = 'tearsheet';
56
+
57
+ var ObjectFreeze = Object.freeze;
58
+ var ArrayIsArray = Array.isArray;
59
+ var JSONStringify = JSON.stringify;
60
+ function createLink(ref) {
61
+ return {
62
+ __ref: engine.serializeStructuredKey(ref),
63
+ };
64
+ }
65
+
66
+ function validate$1(obj, path) {
67
+ if (path === void 0) { path = 'TearsheetRepresentation'; }
68
+ var v_error = (function () {
69
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
70
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
71
+ }
72
+ var obj_id = obj.id;
73
+ var path_id = path + '.id';
74
+ if (typeof obj_id !== 'string') {
75
+ return new TypeError('Expected "string" but received "' + typeof obj_id + '" (at "' + path_id + '")');
76
+ }
77
+ var obj_title = obj.title;
78
+ var path_title = path + '.title';
79
+ if (typeof obj_title !== 'string') {
80
+ return new TypeError('Expected "string" but received "' + typeof obj_title + '" (at "' + path_title + '")');
81
+ }
82
+ })();
83
+ return v_error === undefined ? null : v_error;
84
+ }
85
+ function deepFreeze$1(input) {
86
+ ObjectFreeze(input);
87
+ }
88
+
89
+ var TTL = 1000;
90
+ var VERSION = "33cf28595aef16a27da68accf962bce3";
91
+ function validate(obj, path) {
92
+ if (path === void 0) { path = 'TearsheetListRepresentation'; }
93
+ var v_error = (function () {
94
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
95
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
96
+ }
97
+ var obj_data = obj.data;
98
+ var path_data = path + '.data';
99
+ if (!ArrayIsArray(obj_data)) {
100
+ return new TypeError('Expected "array" but received "' + typeof obj_data + '" (at "' + path_data + '")');
101
+ }
102
+ for (var i = 0; i < obj_data.length; i++) {
103
+ var obj_data_item = obj_data[i];
104
+ var path_data_item = path_data + '[' + i + ']';
105
+ var referencepath_data_itemValidationError = validate$1(obj_data_item, path_data_item);
106
+ if (referencepath_data_itemValidationError !== null) {
107
+ var message = 'Object doesn\'t match TearsheetRepresentation (at "' + path_data_item + '")\n';
108
+ message += referencepath_data_itemValidationError.message.split('\n').map(function (line) { return '\t' + line; }).join('\n');
109
+ return new TypeError(message);
110
+ }
111
+ }
112
+ })();
113
+ return v_error === undefined ? null : v_error;
114
+ }
115
+ var RepresentationType = 'TearsheetListRepresentation';
116
+ function normalize(input, existing, path, luvio, store, timestamp) {
117
+ return input;
118
+ }
119
+ var select$1 = function TearsheetListRepresentationSelect() {
120
+ return {
121
+ kind: 'Fragment',
122
+ version: VERSION,
123
+ private: [],
124
+ opaque: true
125
+ };
126
+ };
127
+ function equals(existing, incoming) {
128
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
129
+ return false;
130
+ }
131
+ return true;
132
+ }
133
+ function deepFreeze(input) {
134
+ var input_data = input.data;
135
+ for (var i = 0; i < input_data.length; i++) {
136
+ var input_data_item = input_data[i];
137
+ deepFreeze$1(input_data_item);
138
+ }
139
+ ObjectFreeze(input_data);
140
+ ObjectFreeze(input);
141
+ }
142
+ var ingest = function TearsheetListRepresentationIngest(input, path, luvio, store, timestamp) {
143
+ if (process.env.NODE_ENV !== 'production') {
144
+ var validateError = validate(input);
145
+ if (validateError !== null) {
146
+ throw validateError;
147
+ }
148
+ }
149
+ var key = path.fullPath;
150
+ var existingRecord = store.readEntry(key);
151
+ var ttlToUse = TTL;
152
+ var incomingRecord = normalize(input, store.readEntry(key), {
153
+ fullPath: key,
154
+ parent: path.parent,
155
+ propertyName: path.propertyName,
156
+ ttl: ttlToUse
157
+ });
158
+ deepFreeze(input);
159
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
160
+ luvio.storePublish(key, incomingRecord);
161
+ }
162
+ {
163
+ var storeMetadataParams = {
164
+ ttl: ttlToUse,
165
+ namespace: "tearsheet",
166
+ version: VERSION,
167
+ representationName: RepresentationType,
168
+ };
169
+ luvio.publishStoreMetadata(key, storeMetadataParams);
170
+ }
171
+ return createLink(key);
172
+ };
173
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
174
+ var rootKeySet = new engine.StoreKeyMap();
175
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
176
+ var rootKey = fullPathFactory();
177
+ rootKeySet.set(rootKey, {
178
+ namespace: keyPrefix,
179
+ representationName: RepresentationType,
180
+ mergeable: false
181
+ });
182
+ return rootKeySet;
183
+ }
184
+
185
+ function select(luvio, params) {
186
+ return select$1();
187
+ }
188
+ function keyBuilder$1(luvio, params) {
189
+ return keyPrefix + '::TearsheetListRepresentation:(' + 'limit:' + params.queryParams.limit + ',' + 'offset:' + params.queryParams.offset + ',' + 'templateType:' + params.queryParams.templateType + ',' + 'accountId:' + params.urlParams.accountId + ')';
190
+ }
191
+ function getResponseCacheKeys(luvio, resourceParams, response) {
192
+ return getTypeCacheKeys(luvio, response, function () { return keyBuilder$1(luvio, resourceParams); });
193
+ }
194
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
195
+ var body = response.body;
196
+ var key = keyBuilder$1(luvio, resourceParams);
197
+ luvio.storeIngest(key, ingest, body);
198
+ var snapshot = luvio.storeLookup({
199
+ recordId: key,
200
+ node: select(),
201
+ variables: {},
202
+ }, snapshotRefresh);
203
+ if (process.env.NODE_ENV !== 'production') {
204
+ if (snapshot.state !== 'Fulfilled') {
205
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
206
+ }
207
+ }
208
+ return snapshot;
209
+ }
210
+ function ingestError(luvio, params, error, snapshotRefresh) {
211
+ var key = keyBuilder$1(luvio, params);
212
+ var errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
213
+ var storeMetadataParams = {
214
+ ttl: TTL,
215
+ namespace: keyPrefix,
216
+ version: VERSION,
217
+ representationName: RepresentationType
218
+ };
219
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
220
+ return errorSnapshot;
221
+ }
222
+ function createResourceRequest(config) {
223
+ var headers = {};
224
+ return {
225
+ baseUri: '/services/data/v58.0',
226
+ basePath: '/connect/financialservices/tearsheets/' + config.urlParams.accountId + '',
227
+ method: 'get',
228
+ body: null,
229
+ urlParams: config.urlParams,
230
+ queryParams: config.queryParams,
231
+ headers: headers,
232
+ priority: 'normal',
233
+ };
234
+ }
235
+
236
+ var getTearsheets_ConfigPropertyNames = {
237
+ displayName: 'getTearsheets',
238
+ parameters: {
239
+ required: ['accountId'],
240
+ optional: ['limit', 'offset', 'templateType']
241
+ }
242
+ };
243
+ function createResourceParams(config) {
244
+ var resourceParams = {
245
+ urlParams: {
246
+ accountId: config.accountId
247
+ },
248
+ queryParams: {
249
+ limit: config.limit, offset: config.offset, templateType: config.templateType
250
+ }
251
+ };
252
+ return resourceParams;
253
+ }
254
+ function keyBuilder(luvio, config) {
255
+ var resourceParams = createResourceParams(config);
256
+ return keyBuilder$1(luvio, resourceParams);
257
+ }
258
+ function typeCheckConfig(untrustedConfig) {
259
+ var config = {};
260
+ var untrustedConfig_accountId = untrustedConfig.accountId;
261
+ if (typeof untrustedConfig_accountId === 'string') {
262
+ config.accountId = untrustedConfig_accountId;
263
+ }
264
+ var untrustedConfig_limit = untrustedConfig.limit;
265
+ if (typeof untrustedConfig_limit === 'number' && Math.floor(untrustedConfig_limit) === untrustedConfig_limit) {
266
+ config.limit = untrustedConfig_limit;
267
+ }
268
+ var untrustedConfig_offset = untrustedConfig.offset;
269
+ if (typeof untrustedConfig_offset === 'number' && Math.floor(untrustedConfig_offset) === untrustedConfig_offset) {
270
+ config.offset = untrustedConfig_offset;
271
+ }
272
+ var untrustedConfig_templateType = untrustedConfig.templateType;
273
+ if (typeof untrustedConfig_templateType === 'string') {
274
+ config.templateType = untrustedConfig_templateType;
275
+ }
276
+ return config;
277
+ }
278
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
279
+ if (!untrustedIsObject(untrustedConfig)) {
280
+ return null;
281
+ }
282
+ if (process.env.NODE_ENV !== 'production') {
283
+ validateConfig(untrustedConfig, configPropertyNames);
284
+ }
285
+ var config = typeCheckConfig(untrustedConfig);
286
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
287
+ return null;
288
+ }
289
+ return config;
290
+ }
291
+ function adapterFragment(luvio, config) {
292
+ createResourceParams(config);
293
+ return select();
294
+ }
295
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
296
+ var snapshot = ingestSuccess(luvio, resourceParams, response, {
297
+ config: config,
298
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
299
+ });
300
+ return luvio.storeBroadcast().then(function () { return snapshot; });
301
+ }
302
+ function onFetchResponseError(luvio, config, resourceParams, response) {
303
+ var snapshot = ingestError(luvio, resourceParams, response, {
304
+ config: config,
305
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
306
+ });
307
+ return luvio.storeBroadcast().then(function () { return snapshot; });
308
+ }
309
+ function buildNetworkSnapshot(luvio, config, options) {
310
+ var resourceParams = createResourceParams(config);
311
+ var request = createResourceRequest(resourceParams);
312
+ return luvio.dispatchResourceRequest(request, options)
313
+ .then(function (response) {
314
+ return luvio.handleSuccessResponse(function () { return onFetchResponseSuccess(luvio, config, resourceParams, response); }, function () { return getResponseCacheKeys(luvio, resourceParams, response.body); });
315
+ }, function (response) {
316
+ return luvio.handleErrorResponse(function () { return onFetchResponseError(luvio, config, resourceParams, response); });
317
+ });
318
+ }
319
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
320
+ var luvio = context.luvio, config = context.config;
321
+ var networkPriority = coercedAdapterRequestContext.networkPriority, requestCorrelator = coercedAdapterRequestContext.requestCorrelator, eventObservers = coercedAdapterRequestContext.eventObservers;
322
+ var dispatchOptions = {
323
+ resourceRequestContext: {
324
+ requestCorrelator: requestCorrelator,
325
+ luvioRequestMethod: undefined,
326
+ },
327
+ eventObservers: eventObservers
328
+ };
329
+ if (networkPriority !== 'normal') {
330
+ dispatchOptions.overrides = {
331
+ priority: networkPriority
332
+ };
333
+ }
334
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
335
+ }
336
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
337
+ var luvio = context.luvio, config = context.config;
338
+ var selector = {
339
+ recordId: keyBuilder(luvio, config),
340
+ node: adapterFragment(luvio, config),
341
+ variables: {},
342
+ };
343
+ var cacheSnapshot = storeLookup(selector, {
344
+ config: config,
345
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
346
+ });
347
+ return cacheSnapshot;
348
+ }
349
+ var getTearsheetsAdapterFactory = function (luvio) { return function tearsheet__getTearsheets(untrustedConfig, requestContext) {
350
+ var config = validateAdapterConfig(untrustedConfig, getTearsheets_ConfigPropertyNames);
351
+ // Invalid or incomplete config
352
+ if (config === null) {
353
+ return null;
354
+ }
355
+ return luvio.applyCachePolicy((requestContext || {}), { config: config, luvio: luvio }, // BuildSnapshotContext
356
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
357
+ }; };
358
+
359
+ exports.getTearsheetsAdapterFactory = getTearsheetsAdapterFactory;
360
+
361
+ Object.defineProperty(exports, '__esModule', { value: true });
362
+
363
+ }));
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@salesforce/lds-adapters-industries-tearsheet",
3
+ "version": "1.100.2",
4
+ "license": "SEE LICENSE IN LICENSE.txt",
5
+ "description": "APIs for Tearsheets feature in FSC",
6
+ "main": "dist/umd/es2018/industries-tearsheet.js",
7
+ "module": "dist/es/es2018/industries-tearsheet.js",
8
+ "types": "dist/types/src/generated/artifacts/main.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "sfdc",
12
+ "src/raml/*"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/es/es2018/industries-tearsheet.js",
17
+ "require": "./dist/umd/es2018/industries-tearsheet.js",
18
+ "types": "./dist/types/src/generated/artifacts/main.d.ts"
19
+ },
20
+ "./sfdc": {
21
+ "import": "./sfdc/index.js",
22
+ "types": "./sfdc/index.d.ts",
23
+ "default": "./sfdc/index.js"
24
+ }
25
+ },
26
+ "sdfc": {
27
+ "namespace": "lightning",
28
+ "module": "industriesTearsheetApi"
29
+ },
30
+ "contributors": [
31
+ "vdamodharan@salesforce.com"
32
+ ],
33
+ "scripts": {
34
+ "build": "yarn build:raml && yarn build:services && yarn build:karma",
35
+ "build:karma": "rollup --config rollup.config.karma.js",
36
+ "build:raml": "luvio generate src/raml/luvio.raml src/generated -p '../lds-compiler-plugins'",
37
+ "build:services": "rollup --config rollup.config.js",
38
+ "clean": "rm -rf dist sfdc src/generated karma/dist",
39
+ "release:core": "../../scripts/release/core.js --adapter=lds-adapters-industries-tearsheet",
40
+ "release:corejar": "yarn build && packages/core-build/scripts/core.js --adapter=lds-adapters-industries-tearsheet",
41
+ "start": "karma start",
42
+ "test": "karma start --single-run",
43
+ "test:compat": "karma start --single-run --compat"
44
+ },
45
+ "dependencies": {
46
+ "@salesforce/lds-bindings": "^1.100.2"
47
+ },
48
+ "devDependencies": {
49
+ "@luvio/cli": "0.135.4",
50
+ "@luvio/compiler": "0.135.4",
51
+ "@luvio/engine": "0.135.4",
52
+ "@luvio/lwc-luvio": "0.135.4",
53
+ "@salesforce/lds-karma": "^1.100.2"
54
+ },
55
+ "nx": {
56
+ "targets": {
57
+ "build": {
58
+ "outputs": [
59
+ "packages/lds-adapters-industries-tearsheet/dist",
60
+ "packages/lds-adapters-industries-tearsheet/karma/dist",
61
+ "packages/lds-adapters-industries-tearsheet/sfdc",
62
+ "packages/lds-adapters-industries-tearsheet/src/generated"
63
+ ]
64
+ }
65
+ }
66
+ },
67
+ "volta": {
68
+ "extends": "../../package.json"
69
+ }
70
+ }
@@ -0,0 +1 @@
1
+ export * from '../dist/types/src/generated/artifacts/sfdc';