@salesforce/lds-adapters-platform-data-provider 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/LICENSE.txt +82 -0
- package/dist/es/es2018/platform-data-provider.js +343 -0
- package/dist/types/src/generated/adapters/adapter-utils.d.ts +66 -0
- package/dist/types/src/generated/adapters/getSchema.d.ts +27 -0
- package/dist/types/src/generated/artifacts/main.d.ts +1 -0
- package/dist/types/src/generated/artifacts/sfdc.d.ts +3 -0
- package/dist/types/src/generated/resources/getConnectDataProvidersSchemaByDataProviderFQN.d.ts +18 -0
- package/dist/types/src/generated/types/DataProviderSchemaRepresentation.d.ts +34 -0
- package/dist/types/src/generated/types/type-utils.d.ts +39 -0
- package/dist/umd/es2018/platform-data-provider.js +351 -0
- package/dist/umd/es5/platform-data-provider.js +352 -0
- package/package.json +64 -0
- package/sfdc/index.d.ts +1 -0
- package/sfdc/index.js +375 -0
- package/src/raml/api.raml +56 -0
- package/src/raml/luvio.raml +17 -0
|
@@ -0,0 +1,351 @@
|
|
|
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.platformDataProvider = {}, 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 snapshotRefreshOptions = {
|
|
49
|
+
overrides: {
|
|
50
|
+
headers: {
|
|
51
|
+
'Cache-Control': 'no-cache',
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const keyPrefix = 'DataProviders';
|
|
56
|
+
|
|
57
|
+
const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
|
|
58
|
+
const { isArray: ArrayIsArray } = Array;
|
|
59
|
+
const { stringify: JSONStringify } = JSON;
|
|
60
|
+
function deepFreeze$1(value) {
|
|
61
|
+
// No need to freeze primitives
|
|
62
|
+
if (typeof value !== 'object' || value === null) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (ArrayIsArray(value)) {
|
|
66
|
+
for (let i = 0, len = value.length; i < len; i += 1) {
|
|
67
|
+
deepFreeze$1(value[i]);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
const keys = ObjectKeys(value);
|
|
72
|
+
for (let i = 0, len = keys.length; i < len; i += 1) {
|
|
73
|
+
deepFreeze$1(value[keys[i]]);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
ObjectFreeze(value);
|
|
77
|
+
}
|
|
78
|
+
function createLink(ref) {
|
|
79
|
+
return {
|
|
80
|
+
__ref: engine.serializeStructuredKey(ref),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const TTL = 3600000;
|
|
85
|
+
const VERSION = "fa63b622a17d190f6bafa7967153c8be";
|
|
86
|
+
function validate(obj, path = 'DataProviderSchemaRepresentation') {
|
|
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_schema = obj.schema;
|
|
92
|
+
const path_schema = path + '.schema';
|
|
93
|
+
if (typeof obj_schema !== 'object' || ArrayIsArray(obj_schema) || obj_schema === null) {
|
|
94
|
+
return new TypeError('Expected "object" but received "' + typeof obj_schema + '" (at "' + path_schema + '")');
|
|
95
|
+
}
|
|
96
|
+
const obj_schema_keys = ObjectKeys(obj_schema);
|
|
97
|
+
for (let i = 0; i < obj_schema_keys.length; i++) {
|
|
98
|
+
const key = obj_schema_keys[i];
|
|
99
|
+
const obj_schema_prop = obj_schema[key];
|
|
100
|
+
const path_schema_prop = path_schema + '["' + key + '"]';
|
|
101
|
+
if (obj_schema_prop === undefined) {
|
|
102
|
+
return new TypeError('Expected "defined" but received "' + typeof obj_schema_prop + '" (at "' + path_schema_prop + '")');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
})();
|
|
106
|
+
return v_error === undefined ? null : v_error;
|
|
107
|
+
}
|
|
108
|
+
const RepresentationType = 'DataProviderSchemaRepresentation';
|
|
109
|
+
function normalize(input, existing, path, luvio, store, timestamp) {
|
|
110
|
+
return input;
|
|
111
|
+
}
|
|
112
|
+
const select$1 = function DataProviderSchemaRepresentationSelect() {
|
|
113
|
+
return {
|
|
114
|
+
kind: 'Fragment',
|
|
115
|
+
version: VERSION,
|
|
116
|
+
private: [],
|
|
117
|
+
opaque: true
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
function equals(existing, incoming) {
|
|
121
|
+
if (JSONStringify(incoming) !== JSONStringify(existing)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
function deepFreeze(input) {
|
|
127
|
+
const input_schema = input.schema;
|
|
128
|
+
const input_schema_keys = Object.keys(input_schema);
|
|
129
|
+
const input_schema_length = input_schema_keys.length;
|
|
130
|
+
for (let i = 0; i < input_schema_length; i++) {
|
|
131
|
+
const key = input_schema_keys[i];
|
|
132
|
+
const input_schema_prop = input_schema[key];
|
|
133
|
+
deepFreeze$1(input_schema_prop);
|
|
134
|
+
}
|
|
135
|
+
ObjectFreeze(input_schema);
|
|
136
|
+
ObjectFreeze(input);
|
|
137
|
+
}
|
|
138
|
+
const ingest = function DataProviderSchemaRepresentationIngest(input, path, luvio, store, timestamp) {
|
|
139
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
140
|
+
const validateError = validate(input);
|
|
141
|
+
if (validateError !== null) {
|
|
142
|
+
throw validateError;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
const key = path.fullPath;
|
|
146
|
+
const existingRecord = store.readEntry(key);
|
|
147
|
+
const ttlToUse = TTL;
|
|
148
|
+
let incomingRecord = normalize(input, store.readEntry(key), {
|
|
149
|
+
fullPath: key,
|
|
150
|
+
parent: path.parent,
|
|
151
|
+
propertyName: path.propertyName,
|
|
152
|
+
ttl: ttlToUse
|
|
153
|
+
});
|
|
154
|
+
deepFreeze(input);
|
|
155
|
+
if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
|
|
156
|
+
luvio.storePublish(key, incomingRecord);
|
|
157
|
+
}
|
|
158
|
+
{
|
|
159
|
+
const storeMetadataParams = {
|
|
160
|
+
ttl: ttlToUse,
|
|
161
|
+
namespace: "DataProviders",
|
|
162
|
+
version: VERSION,
|
|
163
|
+
representationName: RepresentationType,
|
|
164
|
+
};
|
|
165
|
+
luvio.publishStoreMetadata(key, storeMetadataParams);
|
|
166
|
+
}
|
|
167
|
+
return createLink(key);
|
|
168
|
+
};
|
|
169
|
+
function getTypeCacheKeys(luvio, input, fullPathFactory) {
|
|
170
|
+
const rootKeySet = new engine.StoreKeyMap();
|
|
171
|
+
// root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
|
|
172
|
+
const rootKey = fullPathFactory();
|
|
173
|
+
rootKeySet.set(rootKey, {
|
|
174
|
+
namespace: keyPrefix,
|
|
175
|
+
representationName: RepresentationType,
|
|
176
|
+
mergeable: false
|
|
177
|
+
});
|
|
178
|
+
return rootKeySet;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function select(luvio, params) {
|
|
182
|
+
return select$1();
|
|
183
|
+
}
|
|
184
|
+
function keyBuilder$1(luvio, params) {
|
|
185
|
+
return keyPrefix + '::DataProviderSchemaRepresentation:(' + 'config:' + params.queryParams.config + ',' + 'dataProviderFQN:' + params.urlParams.dataProviderFQN + ')';
|
|
186
|
+
}
|
|
187
|
+
function getResponseCacheKeys(luvio, resourceParams, response) {
|
|
188
|
+
return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
|
|
189
|
+
}
|
|
190
|
+
function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
|
|
191
|
+
const { body } = response;
|
|
192
|
+
const key = keyBuilder$1(luvio, resourceParams);
|
|
193
|
+
luvio.storeIngest(key, ingest, body);
|
|
194
|
+
const snapshot = luvio.storeLookup({
|
|
195
|
+
recordId: key,
|
|
196
|
+
node: select(),
|
|
197
|
+
variables: {},
|
|
198
|
+
}, snapshotRefresh);
|
|
199
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
200
|
+
if (snapshot.state !== 'Fulfilled') {
|
|
201
|
+
throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return snapshot;
|
|
205
|
+
}
|
|
206
|
+
function ingestError(luvio, params, error, snapshotRefresh) {
|
|
207
|
+
const key = keyBuilder$1(luvio, params);
|
|
208
|
+
const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
|
|
209
|
+
const storeMetadataParams = {
|
|
210
|
+
ttl: TTL,
|
|
211
|
+
namespace: keyPrefix,
|
|
212
|
+
version: VERSION,
|
|
213
|
+
representationName: RepresentationType
|
|
214
|
+
};
|
|
215
|
+
luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
|
|
216
|
+
return errorSnapshot;
|
|
217
|
+
}
|
|
218
|
+
function createResourceRequest(config) {
|
|
219
|
+
const headers = {};
|
|
220
|
+
return {
|
|
221
|
+
baseUri: '/services/data/v58.0',
|
|
222
|
+
basePath: '/connect/data-providers/' + config.urlParams.dataProviderFQN + '/schema',
|
|
223
|
+
method: 'get',
|
|
224
|
+
body: null,
|
|
225
|
+
urlParams: config.urlParams,
|
|
226
|
+
queryParams: config.queryParams,
|
|
227
|
+
headers,
|
|
228
|
+
priority: 'normal',
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const getSchema_ConfigPropertyNames = {
|
|
233
|
+
displayName: 'getSchema',
|
|
234
|
+
parameters: {
|
|
235
|
+
required: ['dataProviderFQN'],
|
|
236
|
+
optional: ['config']
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
function createResourceParams(config) {
|
|
240
|
+
const resourceParams = {
|
|
241
|
+
urlParams: {
|
|
242
|
+
dataProviderFQN: config.dataProviderFQN
|
|
243
|
+
},
|
|
244
|
+
queryParams: {
|
|
245
|
+
config: config.config
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
return resourceParams;
|
|
249
|
+
}
|
|
250
|
+
function keyBuilder(luvio, config) {
|
|
251
|
+
const resourceParams = createResourceParams(config);
|
|
252
|
+
return keyBuilder$1(luvio, resourceParams);
|
|
253
|
+
}
|
|
254
|
+
function typeCheckConfig(untrustedConfig) {
|
|
255
|
+
const config = {};
|
|
256
|
+
const untrustedConfig_dataProviderFQN = untrustedConfig.dataProviderFQN;
|
|
257
|
+
if (typeof untrustedConfig_dataProviderFQN === 'string') {
|
|
258
|
+
config.dataProviderFQN = untrustedConfig_dataProviderFQN;
|
|
259
|
+
}
|
|
260
|
+
const untrustedConfig_config = untrustedConfig.config;
|
|
261
|
+
if (typeof untrustedConfig_config === 'string') {
|
|
262
|
+
config.config = untrustedConfig_config;
|
|
263
|
+
}
|
|
264
|
+
return config;
|
|
265
|
+
}
|
|
266
|
+
function validateAdapterConfig(untrustedConfig, configPropertyNames) {
|
|
267
|
+
if (!untrustedIsObject(untrustedConfig)) {
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
271
|
+
validateConfig(untrustedConfig, configPropertyNames);
|
|
272
|
+
}
|
|
273
|
+
const config = typeCheckConfig(untrustedConfig);
|
|
274
|
+
if (!areRequiredParametersPresent(config, configPropertyNames)) {
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
return config;
|
|
278
|
+
}
|
|
279
|
+
function adapterFragment(luvio, config) {
|
|
280
|
+
createResourceParams(config);
|
|
281
|
+
return select();
|
|
282
|
+
}
|
|
283
|
+
function onFetchResponseSuccess(luvio, config, resourceParams, response) {
|
|
284
|
+
const snapshot = ingestSuccess(luvio, resourceParams, response, {
|
|
285
|
+
config,
|
|
286
|
+
resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
|
|
287
|
+
});
|
|
288
|
+
return luvio.storeBroadcast().then(() => snapshot);
|
|
289
|
+
}
|
|
290
|
+
function onFetchResponseError(luvio, config, resourceParams, response) {
|
|
291
|
+
const snapshot = ingestError(luvio, resourceParams, response, {
|
|
292
|
+
config,
|
|
293
|
+
resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
|
|
294
|
+
});
|
|
295
|
+
return luvio.storeBroadcast().then(() => snapshot);
|
|
296
|
+
}
|
|
297
|
+
function buildNetworkSnapshot(luvio, config, options) {
|
|
298
|
+
const resourceParams = createResourceParams(config);
|
|
299
|
+
const request = createResourceRequest(resourceParams);
|
|
300
|
+
return luvio.dispatchResourceRequest(request, options)
|
|
301
|
+
.then((response) => {
|
|
302
|
+
return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
|
|
303
|
+
}, (response) => {
|
|
304
|
+
return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
|
|
308
|
+
const { luvio, config } = context;
|
|
309
|
+
const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
|
|
310
|
+
const dispatchOptions = {
|
|
311
|
+
resourceRequestContext: {
|
|
312
|
+
requestCorrelator,
|
|
313
|
+
luvioRequestMethod: undefined,
|
|
314
|
+
},
|
|
315
|
+
eventObservers
|
|
316
|
+
};
|
|
317
|
+
if (networkPriority !== 'normal') {
|
|
318
|
+
dispatchOptions.overrides = {
|
|
319
|
+
priority: networkPriority
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return buildNetworkSnapshot(luvio, config, dispatchOptions);
|
|
323
|
+
}
|
|
324
|
+
function buildCachedSnapshotCachePolicy(context, storeLookup) {
|
|
325
|
+
const { luvio, config } = context;
|
|
326
|
+
const selector = {
|
|
327
|
+
recordId: keyBuilder(luvio, config),
|
|
328
|
+
node: adapterFragment(luvio, config),
|
|
329
|
+
variables: {},
|
|
330
|
+
};
|
|
331
|
+
const cacheSnapshot = storeLookup(selector, {
|
|
332
|
+
config,
|
|
333
|
+
resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
|
|
334
|
+
});
|
|
335
|
+
return cacheSnapshot;
|
|
336
|
+
}
|
|
337
|
+
const getSchemaAdapterFactory = (luvio) => function DataProviders__getSchema(untrustedConfig, requestContext) {
|
|
338
|
+
const config = validateAdapterConfig(untrustedConfig, getSchema_ConfigPropertyNames);
|
|
339
|
+
// Invalid or incomplete config
|
|
340
|
+
if (config === null) {
|
|
341
|
+
return null;
|
|
342
|
+
}
|
|
343
|
+
return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
|
|
344
|
+
buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
exports.getSchemaAdapterFactory = getSchemaAdapterFactory;
|
|
348
|
+
|
|
349
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
350
|
+
|
|
351
|
+
}));
|