@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/sfdc/index.js ADDED
@@ -0,0 +1,375 @@
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 { createInstrumentedAdapter, createLDSAdapter, createWireAdapterConstructor, createImperativeAdapter } from 'force/ldsBindings';
16
+ import { withDefaultLuvio } from 'force/ldsEngine';
17
+ import { serializeStructuredKey, StoreKeyMap } from 'force/luvioEngine';
18
+
19
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
20
+ const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = Object;
21
+ const { isArray: ArrayIsArray$1 } = Array;
22
+ /**
23
+ * Validates an adapter config is well-formed.
24
+ * @param config The config to validate.
25
+ * @param adapter The adapter validation configuration.
26
+ * @param oneOf The keys the config must contain at least one of.
27
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
28
+ */
29
+ function validateConfig(config, adapter, oneOf) {
30
+ const { displayName } = adapter;
31
+ const { required, optional, unsupported } = adapter.parameters;
32
+ if (config === undefined ||
33
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
34
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
35
+ }
36
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
37
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
38
+ }
39
+ if (unsupported !== undefined &&
40
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
41
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
42
+ }
43
+ const supported = required.concat(optional);
44
+ if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
45
+ throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
46
+ }
47
+ }
48
+ function untrustedIsObject(untrusted) {
49
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
50
+ }
51
+ function areRequiredParametersPresent(config, configPropertyNames) {
52
+ return configPropertyNames.parameters.required.every(req => req in config);
53
+ }
54
+ const snapshotRefreshOptions = {
55
+ overrides: {
56
+ headers: {
57
+ 'Cache-Control': 'no-cache',
58
+ },
59
+ }
60
+ };
61
+ const keyPrefix = 'DataProviders';
62
+
63
+ const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
64
+ const { isArray: ArrayIsArray } = Array;
65
+ const { stringify: JSONStringify } = JSON;
66
+ function deepFreeze$1(value) {
67
+ // No need to freeze primitives
68
+ if (typeof value !== 'object' || value === null) {
69
+ return;
70
+ }
71
+ if (ArrayIsArray(value)) {
72
+ for (let i = 0, len = value.length; i < len; i += 1) {
73
+ deepFreeze$1(value[i]);
74
+ }
75
+ }
76
+ else {
77
+ const keys = ObjectKeys(value);
78
+ for (let i = 0, len = keys.length; i < len; i += 1) {
79
+ deepFreeze$1(value[keys[i]]);
80
+ }
81
+ }
82
+ ObjectFreeze(value);
83
+ }
84
+ function createLink(ref) {
85
+ return {
86
+ __ref: serializeStructuredKey(ref),
87
+ };
88
+ }
89
+
90
+ const TTL = 3600000;
91
+ const VERSION = "fa63b622a17d190f6bafa7967153c8be";
92
+ function validate(obj, path = 'DataProviderSchemaRepresentation') {
93
+ const v_error = (() => {
94
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
95
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
96
+ }
97
+ const obj_schema = obj.schema;
98
+ const path_schema = path + '.schema';
99
+ if (typeof obj_schema !== 'object' || ArrayIsArray(obj_schema) || obj_schema === null) {
100
+ return new TypeError('Expected "object" but received "' + typeof obj_schema + '" (at "' + path_schema + '")');
101
+ }
102
+ const obj_schema_keys = ObjectKeys(obj_schema);
103
+ for (let i = 0; i < obj_schema_keys.length; i++) {
104
+ const key = obj_schema_keys[i];
105
+ const obj_schema_prop = obj_schema[key];
106
+ const path_schema_prop = path_schema + '["' + key + '"]';
107
+ if (obj_schema_prop === undefined) {
108
+ return new TypeError('Expected "defined" but received "' + typeof obj_schema_prop + '" (at "' + path_schema_prop + '")');
109
+ }
110
+ }
111
+ })();
112
+ return v_error === undefined ? null : v_error;
113
+ }
114
+ const RepresentationType = 'DataProviderSchemaRepresentation';
115
+ function normalize(input, existing, path, luvio, store, timestamp) {
116
+ return input;
117
+ }
118
+ const select$1 = function DataProviderSchemaRepresentationSelect() {
119
+ return {
120
+ kind: 'Fragment',
121
+ version: VERSION,
122
+ private: [],
123
+ opaque: true
124
+ };
125
+ };
126
+ function equals(existing, incoming) {
127
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
128
+ return false;
129
+ }
130
+ return true;
131
+ }
132
+ function deepFreeze(input) {
133
+ const input_schema = input.schema;
134
+ const input_schema_keys = Object.keys(input_schema);
135
+ const input_schema_length = input_schema_keys.length;
136
+ for (let i = 0; i < input_schema_length; i++) {
137
+ const key = input_schema_keys[i];
138
+ const input_schema_prop = input_schema[key];
139
+ deepFreeze$1(input_schema_prop);
140
+ }
141
+ ObjectFreeze(input_schema);
142
+ ObjectFreeze(input);
143
+ }
144
+ const ingest = function DataProviderSchemaRepresentationIngest(input, path, luvio, store, timestamp) {
145
+ if (process.env.NODE_ENV !== 'production') {
146
+ const validateError = validate(input);
147
+ if (validateError !== null) {
148
+ throw validateError;
149
+ }
150
+ }
151
+ const key = path.fullPath;
152
+ const existingRecord = store.readEntry(key);
153
+ const ttlToUse = TTL;
154
+ let incomingRecord = normalize(input, store.readEntry(key), {
155
+ fullPath: key,
156
+ parent: path.parent,
157
+ propertyName: path.propertyName,
158
+ ttl: ttlToUse
159
+ });
160
+ deepFreeze(input);
161
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
162
+ luvio.storePublish(key, incomingRecord);
163
+ }
164
+ {
165
+ const storeMetadataParams = {
166
+ ttl: ttlToUse,
167
+ namespace: "DataProviders",
168
+ version: VERSION,
169
+ representationName: RepresentationType,
170
+ };
171
+ luvio.publishStoreMetadata(key, storeMetadataParams);
172
+ }
173
+ return createLink(key);
174
+ };
175
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
176
+ const rootKeySet = new StoreKeyMap();
177
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
178
+ const rootKey = fullPathFactory();
179
+ rootKeySet.set(rootKey, {
180
+ namespace: keyPrefix,
181
+ representationName: RepresentationType,
182
+ mergeable: false
183
+ });
184
+ return rootKeySet;
185
+ }
186
+
187
+ function select(luvio, params) {
188
+ return select$1();
189
+ }
190
+ function keyBuilder$1(luvio, params) {
191
+ return keyPrefix + '::DataProviderSchemaRepresentation:(' + 'config:' + params.queryParams.config + ',' + 'dataProviderFQN:' + params.urlParams.dataProviderFQN + ')';
192
+ }
193
+ function getResponseCacheKeys(luvio, resourceParams, response) {
194
+ return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
195
+ }
196
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
197
+ const { body } = response;
198
+ const key = keyBuilder$1(luvio, resourceParams);
199
+ luvio.storeIngest(key, ingest, body);
200
+ const snapshot = luvio.storeLookup({
201
+ recordId: key,
202
+ node: select(),
203
+ variables: {},
204
+ }, snapshotRefresh);
205
+ if (process.env.NODE_ENV !== 'production') {
206
+ if (snapshot.state !== 'Fulfilled') {
207
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
208
+ }
209
+ }
210
+ return snapshot;
211
+ }
212
+ function ingestError(luvio, params, error, snapshotRefresh) {
213
+ const key = keyBuilder$1(luvio, params);
214
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
215
+ const storeMetadataParams = {
216
+ ttl: TTL,
217
+ namespace: keyPrefix,
218
+ version: VERSION,
219
+ representationName: RepresentationType
220
+ };
221
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
222
+ return errorSnapshot;
223
+ }
224
+ function createResourceRequest(config) {
225
+ const headers = {};
226
+ return {
227
+ baseUri: '/services/data/v58.0',
228
+ basePath: '/connect/data-providers/' + config.urlParams.dataProviderFQN + '/schema',
229
+ method: 'get',
230
+ body: null,
231
+ urlParams: config.urlParams,
232
+ queryParams: config.queryParams,
233
+ headers,
234
+ priority: 'normal',
235
+ };
236
+ }
237
+
238
+ const getSchema_ConfigPropertyNames = {
239
+ displayName: 'getSchema',
240
+ parameters: {
241
+ required: ['dataProviderFQN'],
242
+ optional: ['config']
243
+ }
244
+ };
245
+ function createResourceParams(config) {
246
+ const resourceParams = {
247
+ urlParams: {
248
+ dataProviderFQN: config.dataProviderFQN
249
+ },
250
+ queryParams: {
251
+ config: config.config
252
+ }
253
+ };
254
+ return resourceParams;
255
+ }
256
+ function keyBuilder(luvio, config) {
257
+ const resourceParams = createResourceParams(config);
258
+ return keyBuilder$1(luvio, resourceParams);
259
+ }
260
+ function typeCheckConfig(untrustedConfig) {
261
+ const config = {};
262
+ const untrustedConfig_dataProviderFQN = untrustedConfig.dataProviderFQN;
263
+ if (typeof untrustedConfig_dataProviderFQN === 'string') {
264
+ config.dataProviderFQN = untrustedConfig_dataProviderFQN;
265
+ }
266
+ const untrustedConfig_config = untrustedConfig.config;
267
+ if (typeof untrustedConfig_config === 'string') {
268
+ config.config = untrustedConfig_config;
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 getSchemaAdapterFactory = (luvio) => function DataProviders__getSchema(untrustedConfig, requestContext) {
344
+ const config = validateAdapterConfig(untrustedConfig, getSchema_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
+ };
352
+
353
+ let getSchema;
354
+ // Imperative GET Adapters
355
+ let getSchema_imperative;
356
+ // Adapter Metadata
357
+ const getSchemaMetadata = { apiFamily: 'DataProviders', name: 'getSchema', ttl: 3600000 };
358
+ function bindExportsTo(luvio) {
359
+ // LDS Adapters
360
+ const getSchema_ldsAdapter = createInstrumentedAdapter(createLDSAdapter(luvio, 'getSchema', getSchemaAdapterFactory), getSchemaMetadata);
361
+ return {
362
+ getSchema: createWireAdapterConstructor(luvio, getSchema_ldsAdapter, getSchemaMetadata),
363
+ // Imperative GET Adapters
364
+ getSchema_imperative: createImperativeAdapter(luvio, getSchema_ldsAdapter, getSchemaMetadata)
365
+ };
366
+ }
367
+ withDefaultLuvio((luvio) => {
368
+ ({
369
+ getSchema,
370
+ getSchema_imperative
371
+ } = bindExportsTo(luvio));
372
+ });
373
+
374
+ export { getSchema, getSchema_imperative };
375
+ // version: 1.100.2-ca56bb821
@@ -0,0 +1,56 @@
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
+ DataProviderSchemaRepresentation:
29
+ description: Data Provider Schema
30
+ type: object
31
+ properties:
32
+ schema:
33
+ description: The expanded type of data provider schema.
34
+ type: object
35
+ properties:
36
+ //:
37
+ type: any # TODO W-12579297 Hand Rolled
38
+ /connect/data-providers/{dataProviderFQN}/schema:
39
+ get:
40
+ description: Gets output schema for a data provider FQN
41
+ responses:
42
+ '200':
43
+ description: Success
44
+ body:
45
+ application/json:
46
+ type: DataProviderSchemaRepresentation
47
+ queryParameters:
48
+ config:
49
+ description: A stringified config param
50
+ type: string
51
+ required: false
52
+ uriParameters:
53
+ dataProviderFQN:
54
+ description: Data Provider Fully Qualified Name
55
+ type: string
56
+ required: true
@@ -0,0 +1,17 @@
1
+ #%RAML 1.0 Overlay
2
+ extends: ./api.raml
3
+
4
+ uses:
5
+ luvio: luvio://annotations.raml
6
+
7
+ (luvio.keyPrefix): 'DataProviders'
8
+
9
+ types:
10
+ DataProviderSchemaRepresentation:
11
+ (luvio.ttl): 3600000
12
+ (luvio.opaque): true
13
+
14
+ /connect/data-providers/{dataProviderFQN}/schema:
15
+ get:
16
+ (luvio.adapter):
17
+ name: getSchema