@salesforce/lds-adapters-platform-scale-center 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,333 @@
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, freeze: ObjectFreeze, create: ObjectCreate } = 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(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 = 'ScaleCenter';
62
+
63
+ const { isArray: ArrayIsArray } = Array;
64
+ function createLink(ref) {
65
+ return {
66
+ __ref: serializeStructuredKey(ref),
67
+ };
68
+ }
69
+
70
+ const TTL = 30000;
71
+ const VERSION = "b8f014d0e9442d4f93f4eec945f0b6e4";
72
+ function validate(obj, path = 'ScaleCenterMetricDataRepresentation') {
73
+ const v_error = (() => {
74
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
75
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
76
+ }
77
+ const obj_response = obj.response;
78
+ const path_response = path + '.response';
79
+ if (typeof obj_response !== 'string') {
80
+ return new TypeError('Expected "string" but received "' + typeof obj_response + '" (at "' + path_response + '")');
81
+ }
82
+ })();
83
+ return v_error === undefined ? null : v_error;
84
+ }
85
+ const RepresentationType = 'ScaleCenterMetricDataRepresentation';
86
+ function normalize(input, existing, path, luvio, store, timestamp) {
87
+ return input;
88
+ }
89
+ const select$1 = function ScaleCenterMetricDataRepresentationSelect() {
90
+ return {
91
+ kind: 'Fragment',
92
+ version: VERSION,
93
+ private: [],
94
+ selections: [
95
+ {
96
+ name: 'response',
97
+ kind: 'Scalar'
98
+ }
99
+ ]
100
+ };
101
+ };
102
+ function equals(existing, incoming) {
103
+ const existing_response = existing.response;
104
+ const incoming_response = incoming.response;
105
+ if (!(existing_response === incoming_response)) {
106
+ return false;
107
+ }
108
+ return true;
109
+ }
110
+ const ingest = function ScaleCenterMetricDataRepresentationIngest(input, path, luvio, store, timestamp) {
111
+ if (process.env.NODE_ENV !== 'production') {
112
+ const validateError = validate(input);
113
+ if (validateError !== null) {
114
+ throw validateError;
115
+ }
116
+ }
117
+ const key = path.fullPath;
118
+ const existingRecord = store.readEntry(key);
119
+ const ttlToUse = TTL;
120
+ let incomingRecord = normalize(input, store.readEntry(key), {
121
+ fullPath: key,
122
+ parent: path.parent,
123
+ propertyName: path.propertyName,
124
+ ttl: ttlToUse
125
+ });
126
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
127
+ luvio.storePublish(key, incomingRecord);
128
+ }
129
+ {
130
+ const storeMetadataParams = {
131
+ ttl: ttlToUse,
132
+ namespace: "ScaleCenter",
133
+ version: VERSION,
134
+ representationName: RepresentationType,
135
+ };
136
+ luvio.publishStoreMetadata(key, storeMetadataParams);
137
+ }
138
+ return createLink(key);
139
+ };
140
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
141
+ const rootKeySet = new StoreKeyMap();
142
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
143
+ const rootKey = fullPathFactory();
144
+ rootKeySet.set(rootKey, {
145
+ namespace: keyPrefix,
146
+ representationName: RepresentationType,
147
+ mergeable: false
148
+ });
149
+ return rootKeySet;
150
+ }
151
+
152
+ function select(luvio, params) {
153
+ return select$1();
154
+ }
155
+ function keyBuilder$1(luvio, params) {
156
+ return keyPrefix + '::ScaleCenterMetricDataRepresentation:(' + 'request:' + params.queryParams.request + ')';
157
+ }
158
+ function getResponseCacheKeys(luvio, resourceParams, response) {
159
+ return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
160
+ }
161
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
162
+ const { body } = response;
163
+ const key = keyBuilder$1(luvio, resourceParams);
164
+ luvio.storeIngest(key, ingest, body);
165
+ const snapshot = luvio.storeLookup({
166
+ recordId: key,
167
+ node: select(),
168
+ variables: {},
169
+ }, snapshotRefresh);
170
+ if (process.env.NODE_ENV !== 'production') {
171
+ if (snapshot.state !== 'Fulfilled') {
172
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
173
+ }
174
+ }
175
+ return snapshot;
176
+ }
177
+ function ingestError(luvio, params, error, snapshotRefresh) {
178
+ const key = keyBuilder$1(luvio, params);
179
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
180
+ const storeMetadataParams = {
181
+ ttl: TTL,
182
+ namespace: keyPrefix,
183
+ version: VERSION,
184
+ representationName: RepresentationType
185
+ };
186
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
187
+ return errorSnapshot;
188
+ }
189
+ function createResourceRequest(config) {
190
+ const headers = {};
191
+ return {
192
+ baseUri: '/services/data/v58.0',
193
+ basePath: '/scalecenter/metrics/query',
194
+ method: 'get',
195
+ body: null,
196
+ urlParams: {},
197
+ queryParams: config.queryParams,
198
+ headers,
199
+ priority: 'normal',
200
+ };
201
+ }
202
+
203
+ const queryMetrics_ConfigPropertyNames = {
204
+ displayName: 'queryMetrics',
205
+ parameters: {
206
+ required: [],
207
+ optional: ['request']
208
+ }
209
+ };
210
+ function createResourceParams(config) {
211
+ const resourceParams = {
212
+ queryParams: {
213
+ request: config.request
214
+ }
215
+ };
216
+ return resourceParams;
217
+ }
218
+ function keyBuilder(luvio, config) {
219
+ const resourceParams = createResourceParams(config);
220
+ return keyBuilder$1(luvio, resourceParams);
221
+ }
222
+ function typeCheckConfig(untrustedConfig) {
223
+ const config = {};
224
+ const untrustedConfig_request = untrustedConfig.request;
225
+ if (typeof untrustedConfig_request === 'string') {
226
+ config.request = untrustedConfig_request;
227
+ }
228
+ return config;
229
+ }
230
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
231
+ if (!untrustedIsObject(untrustedConfig)) {
232
+ return null;
233
+ }
234
+ if (process.env.NODE_ENV !== 'production') {
235
+ validateConfig(untrustedConfig, configPropertyNames);
236
+ }
237
+ const config = typeCheckConfig(untrustedConfig);
238
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
239
+ return null;
240
+ }
241
+ return config;
242
+ }
243
+ function adapterFragment(luvio, config) {
244
+ createResourceParams(config);
245
+ return select();
246
+ }
247
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
248
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
249
+ config,
250
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
251
+ });
252
+ return luvio.storeBroadcast().then(() => snapshot);
253
+ }
254
+ function onFetchResponseError(luvio, config, resourceParams, response) {
255
+ const snapshot = ingestError(luvio, resourceParams, response, {
256
+ config,
257
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
258
+ });
259
+ return luvio.storeBroadcast().then(() => snapshot);
260
+ }
261
+ function buildNetworkSnapshot(luvio, config, options) {
262
+ const resourceParams = createResourceParams(config);
263
+ const request = createResourceRequest(resourceParams);
264
+ return luvio.dispatchResourceRequest(request, options)
265
+ .then((response) => {
266
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
267
+ }, (response) => {
268
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
269
+ });
270
+ }
271
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
272
+ const { luvio, config } = context;
273
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
274
+ const dispatchOptions = {
275
+ resourceRequestContext: {
276
+ requestCorrelator,
277
+ luvioRequestMethod: undefined,
278
+ },
279
+ eventObservers
280
+ };
281
+ if (networkPriority !== 'normal') {
282
+ dispatchOptions.overrides = {
283
+ priority: networkPriority
284
+ };
285
+ }
286
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
287
+ }
288
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
289
+ const { luvio, config } = context;
290
+ const selector = {
291
+ recordId: keyBuilder(luvio, config),
292
+ node: adapterFragment(luvio, config),
293
+ variables: {},
294
+ };
295
+ const cacheSnapshot = storeLookup(selector, {
296
+ config,
297
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
298
+ });
299
+ return cacheSnapshot;
300
+ }
301
+ const queryMetricsAdapterFactory = (luvio) => function ScaleCenter__queryMetrics(untrustedConfig, requestContext) {
302
+ const config = validateAdapterConfig(untrustedConfig, queryMetrics_ConfigPropertyNames);
303
+ // Invalid or incomplete config
304
+ if (config === null) {
305
+ return null;
306
+ }
307
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
308
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
309
+ };
310
+
311
+ let queryMetrics;
312
+ // Imperative GET Adapters
313
+ let queryMetrics_imperative;
314
+ // Adapter Metadata
315
+ const queryMetricsMetadata = { apiFamily: 'ScaleCenter', name: 'queryMetrics', ttl: 30000 };
316
+ function bindExportsTo(luvio) {
317
+ // LDS Adapters
318
+ const queryMetrics_ldsAdapter = createInstrumentedAdapter(createLDSAdapter(luvio, 'queryMetrics', queryMetricsAdapterFactory), queryMetricsMetadata);
319
+ return {
320
+ queryMetrics: createWireAdapterConstructor(luvio, queryMetrics_ldsAdapter, queryMetricsMetadata),
321
+ // Imperative GET Adapters
322
+ queryMetrics_imperative: createImperativeAdapter(luvio, queryMetrics_ldsAdapter, queryMetricsMetadata)
323
+ };
324
+ }
325
+ withDefaultLuvio((luvio) => {
326
+ ({
327
+ queryMetrics,
328
+ queryMetrics_imperative
329
+ } = bindExportsTo(luvio));
330
+ });
331
+
332
+ export { queryMetrics, queryMetrics_imperative };
333
+ // version: 1.100.2-ca56bb821
@@ -0,0 +1,47 @@
1
+ #%RAML 1.0
2
+ securedBy:
3
+ - OAuth2
4
+ title: Salesforce Connect API
5
+ version: '53.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
+ ScaleCenterMetricDataRepresentation:
29
+ description: 'Metrics data for Scale Center '
30
+ type: object
31
+ properties:
32
+ response:
33
+ description: JSON Payload of data returned from Scale Center backend services
34
+ type: string
35
+ /scalecenter/metrics/query:
36
+ get:
37
+ description: Query Scale Center
38
+ responses:
39
+ '200':
40
+ description: Success
41
+ body:
42
+ application/json:
43
+ type: ScaleCenterMetricDataRepresentation
44
+ queryParameters:
45
+ request:
46
+ type: string
47
+ required: false
@@ -0,0 +1,16 @@
1
+ #%RAML 1.0 Overlay
2
+ extends: ./api.raml
3
+
4
+ uses:
5
+ luvio: luvio://annotations.raml
6
+
7
+ (luvio.keyPrefix): 'ScaleCenter'
8
+
9
+ types:
10
+ ScaleCenterMetricDataRepresentation:
11
+ (luvio.ttl): 30000
12
+
13
+ /scalecenter/metrics/query:
14
+ get:
15
+ (luvio.adapter):
16
+ name: queryMetrics