@salesforce/lds-adapters-platform-lightning-cards 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,39 @@
1
+ import { NormalizedKeyMetadata as $64$luvio_engine_NormalizedKeyMetadata } from '@luvio/engine';
2
+ export declare const ObjectFreeze: {
3
+ <T extends Function>(f: T): T;
4
+ <T_1 extends {
5
+ [idx: string]: object | U | null | undefined;
6
+ }, U extends string | number | bigint | boolean | symbol>(o: T_1): Readonly<T_1>;
7
+ <T_2>(o: T_2): Readonly<T_2>;
8
+ }, ObjectKeys: {
9
+ (o: object): string[];
10
+ (o: {}): string[];
11
+ }, ObjectCreate: {
12
+ (o: object | null): any;
13
+ (o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
14
+ }, ObjectAssign: {
15
+ <T extends {}, U>(target: T, source: U): T & U;
16
+ <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
17
+ <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
18
+ (target: object, ...sources: any[]): any;
19
+ };
20
+ export declare const ArrayIsArray: (arg: any) => arg is any[];
21
+ export declare const JSONStringify: {
22
+ (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
23
+ (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
24
+ };
25
+ type AllowedPrimitives = boolean | string | number | Date | null;
26
+ type Value<T> = T extends AllowedPrimitives ? T : RecursivePartial<T>;
27
+ export type RecursivePartial<T> = null | {
28
+ [P in keyof T]?: T[P] extends Array<infer U> ? Array<Value<U>> | null : Value<T[P]> | null;
29
+ };
30
+ export declare function equalsArray<U, V extends U[]>(a: V, b: V, equalsItem: (itemA: U, itemB: U) => boolean | void): boolean;
31
+ export declare function equalsObject<U, V extends {
32
+ [key: string]: U;
33
+ }>(a: V, b: V, equalsProp: (propA: U, propB: U) => boolean | void): boolean;
34
+ export declare function deepFreeze(value: any): void;
35
+ export declare function createLink(ref: string | $64$luvio_engine_NormalizedKeyMetadata): {
36
+ __ref: string;
37
+ };
38
+ export declare function assignMetadataLink(entry: any, metadataKey: string | $64$luvio_engine_NormalizedKeyMetadata): void;
39
+ export {};
@@ -0,0 +1,404 @@
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.platformLightningCards = {}, global.engine));
11
+ })(this, (function (exports, engine) { 'use strict';
12
+
13
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
14
+ const { keys: ObjectKeys, freeze: ObjectFreeze, create: ObjectCreate } = 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(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 = 'LightningCards';
56
+
57
+ const { isArray: ArrayIsArray } = Array;
58
+ function equalsArray(a, b, equalsItem) {
59
+ const aLength = a.length;
60
+ const bLength = b.length;
61
+ if (aLength !== bLength) {
62
+ return false;
63
+ }
64
+ for (let i = 0; i < aLength; i++) {
65
+ if (equalsItem(a[i], b[i]) === false) {
66
+ return false;
67
+ }
68
+ }
69
+ return true;
70
+ }
71
+ function createLink(ref) {
72
+ return {
73
+ __ref: engine.serializeStructuredKey(ref),
74
+ };
75
+ }
76
+
77
+ const VERSION$1 = "9604844b9aa243e47d16987ae263be7a";
78
+ function validate$1(obj, path = 'ActivationDataRepresentation') {
79
+ const v_error = (() => {
80
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
81
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
82
+ }
83
+ const obj_isPublished = obj.isPublished;
84
+ const path_isPublished = path + '.isPublished';
85
+ if (typeof obj_isPublished !== 'boolean') {
86
+ return new TypeError('Expected "boolean" but received "' + typeof obj_isPublished + '" (at "' + path_isPublished + '")');
87
+ }
88
+ const obj_label = obj.label;
89
+ const path_label = path + '.label';
90
+ if (typeof obj_label !== 'string') {
91
+ return new TypeError('Expected "string" but received "' + typeof obj_label + '" (at "' + path_label + '")');
92
+ }
93
+ const obj_target = obj.target;
94
+ const path_target = path + '.target';
95
+ if (typeof obj_target !== 'string') {
96
+ return new TypeError('Expected "string" but received "' + typeof obj_target + '" (at "' + path_target + '")');
97
+ }
98
+ })();
99
+ return v_error === undefined ? null : v_error;
100
+ }
101
+ const select$2 = function ActivationDataRepresentationSelect() {
102
+ return {
103
+ kind: 'Fragment',
104
+ version: VERSION$1,
105
+ private: [],
106
+ selections: [
107
+ {
108
+ name: 'isPublished',
109
+ kind: 'Scalar'
110
+ },
111
+ {
112
+ name: 'label',
113
+ kind: 'Scalar'
114
+ },
115
+ {
116
+ name: 'target',
117
+ kind: 'Scalar'
118
+ }
119
+ ]
120
+ };
121
+ };
122
+ function equals$1(existing, incoming) {
123
+ const existing_isPublished = existing.isPublished;
124
+ const incoming_isPublished = incoming.isPublished;
125
+ if (!(existing_isPublished === incoming_isPublished)) {
126
+ return false;
127
+ }
128
+ const existing_label = existing.label;
129
+ const incoming_label = incoming.label;
130
+ if (!(existing_label === incoming_label)) {
131
+ return false;
132
+ }
133
+ const existing_target = existing.target;
134
+ const incoming_target = incoming.target;
135
+ if (!(existing_target === incoming_target)) {
136
+ return false;
137
+ }
138
+ return true;
139
+ }
140
+
141
+ const TTL = 30000;
142
+ const VERSION = "d7f67e7ed58904e548470ab1e88d18d3";
143
+ function validate(obj, path = 'ActivationDataCollectionRepresentation') {
144
+ const v_error = (() => {
145
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
146
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
147
+ }
148
+ const obj_activations = obj.activations;
149
+ const path_activations = path + '.activations';
150
+ if (!ArrayIsArray(obj_activations)) {
151
+ return new TypeError('Expected "array" but received "' + typeof obj_activations + '" (at "' + path_activations + '")');
152
+ }
153
+ for (let i = 0; i < obj_activations.length; i++) {
154
+ const obj_activations_item = obj_activations[i];
155
+ const path_activations_item = path_activations + '[' + i + ']';
156
+ const referencepath_activations_itemValidationError = validate$1(obj_activations_item, path_activations_item);
157
+ if (referencepath_activations_itemValidationError !== null) {
158
+ let message = 'Object doesn\'t match ActivationDataRepresentation (at "' + path_activations_item + '")\n';
159
+ message += referencepath_activations_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
160
+ return new TypeError(message);
161
+ }
162
+ }
163
+ })();
164
+ return v_error === undefined ? null : v_error;
165
+ }
166
+ const RepresentationType = 'ActivationDataCollectionRepresentation';
167
+ function normalize(input, existing, path, luvio, store, timestamp) {
168
+ return input;
169
+ }
170
+ const select$1 = function ActivationDataCollectionRepresentationSelect() {
171
+ const { selections: ActivationDataRepresentation__selections, opaque: ActivationDataRepresentation__opaque, } = select$2();
172
+ return {
173
+ kind: 'Fragment',
174
+ version: VERSION,
175
+ private: [],
176
+ selections: [
177
+ {
178
+ name: 'activations',
179
+ kind: 'Object',
180
+ plural: true,
181
+ selections: ActivationDataRepresentation__selections
182
+ }
183
+ ]
184
+ };
185
+ };
186
+ function equals(existing, incoming) {
187
+ const existing_activations = existing.activations;
188
+ const incoming_activations = incoming.activations;
189
+ const equals_activations_items = equalsArray(existing_activations, incoming_activations, (existing_activations_item, incoming_activations_item) => {
190
+ if (!(equals$1(existing_activations_item, incoming_activations_item))) {
191
+ return false;
192
+ }
193
+ });
194
+ if (equals_activations_items === false) {
195
+ return false;
196
+ }
197
+ return true;
198
+ }
199
+ const ingest = function ActivationDataCollectionRepresentationIngest(input, path, luvio, store, timestamp) {
200
+ if (process.env.NODE_ENV !== 'production') {
201
+ const validateError = validate(input);
202
+ if (validateError !== null) {
203
+ throw validateError;
204
+ }
205
+ }
206
+ const key = path.fullPath;
207
+ const existingRecord = store.readEntry(key);
208
+ const ttlToUse = TTL;
209
+ let incomingRecord = normalize(input, store.readEntry(key), {
210
+ fullPath: key,
211
+ parent: path.parent,
212
+ propertyName: path.propertyName,
213
+ ttl: ttlToUse
214
+ });
215
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
216
+ luvio.storePublish(key, incomingRecord);
217
+ }
218
+ {
219
+ const storeMetadataParams = {
220
+ ttl: ttlToUse,
221
+ namespace: "LightningCards",
222
+ version: VERSION,
223
+ representationName: RepresentationType,
224
+ };
225
+ luvio.publishStoreMetadata(key, storeMetadataParams);
226
+ }
227
+ return createLink(key);
228
+ };
229
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
230
+ const rootKeySet = new engine.StoreKeyMap();
231
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
232
+ const rootKey = fullPathFactory();
233
+ rootKeySet.set(rootKey, {
234
+ namespace: keyPrefix,
235
+ representationName: RepresentationType,
236
+ mergeable: false
237
+ });
238
+ return rootKeySet;
239
+ }
240
+
241
+ function select(luvio, params) {
242
+ return select$1();
243
+ }
244
+ function keyBuilder$1(luvio, params) {
245
+ return keyPrefix + '::ActivationDataCollectionRepresentation:(' + 'flexiPageId:' + params.urlParams.flexiPageId + ')';
246
+ }
247
+ function getResponseCacheKeys(luvio, resourceParams, response) {
248
+ return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
249
+ }
250
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
251
+ const { body } = response;
252
+ const key = keyBuilder$1(luvio, resourceParams);
253
+ luvio.storeIngest(key, ingest, body);
254
+ const snapshot = luvio.storeLookup({
255
+ recordId: key,
256
+ node: select(),
257
+ variables: {},
258
+ }, snapshotRefresh);
259
+ if (process.env.NODE_ENV !== 'production') {
260
+ if (snapshot.state !== 'Fulfilled') {
261
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
262
+ }
263
+ }
264
+ return snapshot;
265
+ }
266
+ function ingestError(luvio, params, error, snapshotRefresh) {
267
+ const key = keyBuilder$1(luvio, params);
268
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
269
+ const storeMetadataParams = {
270
+ ttl: TTL,
271
+ namespace: keyPrefix,
272
+ version: VERSION,
273
+ representationName: RepresentationType
274
+ };
275
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
276
+ return errorSnapshot;
277
+ }
278
+ function createResourceRequest(config) {
279
+ const headers = {};
280
+ return {
281
+ baseUri: '/services/data/v58.0',
282
+ basePath: '/connect/lightningcards/activationdata/' + config.urlParams.flexiPageId + '',
283
+ method: 'get',
284
+ body: null,
285
+ urlParams: config.urlParams,
286
+ queryParams: {},
287
+ headers,
288
+ priority: 'normal',
289
+ };
290
+ }
291
+
292
+ const getActivationData_ConfigPropertyNames = {
293
+ displayName: 'getActivationData',
294
+ parameters: {
295
+ required: ['flexiPageId'],
296
+ optional: []
297
+ }
298
+ };
299
+ function createResourceParams(config) {
300
+ const resourceParams = {
301
+ urlParams: {
302
+ flexiPageId: config.flexiPageId
303
+ }
304
+ };
305
+ return resourceParams;
306
+ }
307
+ function keyBuilder(luvio, config) {
308
+ const resourceParams = createResourceParams(config);
309
+ return keyBuilder$1(luvio, resourceParams);
310
+ }
311
+ function typeCheckConfig(untrustedConfig) {
312
+ const config = {};
313
+ const untrustedConfig_flexiPageId = untrustedConfig.flexiPageId;
314
+ if (typeof untrustedConfig_flexiPageId === 'string') {
315
+ config.flexiPageId = untrustedConfig_flexiPageId;
316
+ }
317
+ return config;
318
+ }
319
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
320
+ if (!untrustedIsObject(untrustedConfig)) {
321
+ return null;
322
+ }
323
+ if (process.env.NODE_ENV !== 'production') {
324
+ validateConfig(untrustedConfig, configPropertyNames);
325
+ }
326
+ const config = typeCheckConfig(untrustedConfig);
327
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
328
+ return null;
329
+ }
330
+ return config;
331
+ }
332
+ function adapterFragment(luvio, config) {
333
+ createResourceParams(config);
334
+ return select();
335
+ }
336
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
337
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
338
+ config,
339
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
340
+ });
341
+ return luvio.storeBroadcast().then(() => snapshot);
342
+ }
343
+ function onFetchResponseError(luvio, config, resourceParams, response) {
344
+ const snapshot = ingestError(luvio, resourceParams, response, {
345
+ config,
346
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
347
+ });
348
+ return luvio.storeBroadcast().then(() => snapshot);
349
+ }
350
+ function buildNetworkSnapshot(luvio, config, options) {
351
+ const resourceParams = createResourceParams(config);
352
+ const request = createResourceRequest(resourceParams);
353
+ return luvio.dispatchResourceRequest(request, options)
354
+ .then((response) => {
355
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
356
+ }, (response) => {
357
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
358
+ });
359
+ }
360
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
361
+ const { luvio, config } = context;
362
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
363
+ const dispatchOptions = {
364
+ resourceRequestContext: {
365
+ requestCorrelator,
366
+ luvioRequestMethod: undefined,
367
+ },
368
+ eventObservers
369
+ };
370
+ if (networkPriority !== 'normal') {
371
+ dispatchOptions.overrides = {
372
+ priority: networkPriority
373
+ };
374
+ }
375
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
376
+ }
377
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
378
+ const { luvio, config } = context;
379
+ const selector = {
380
+ recordId: keyBuilder(luvio, config),
381
+ node: adapterFragment(luvio, config),
382
+ variables: {},
383
+ };
384
+ const cacheSnapshot = storeLookup(selector, {
385
+ config,
386
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
387
+ });
388
+ return cacheSnapshot;
389
+ }
390
+ const getActivationDataAdapterFactory = (luvio) => function LightningCards__getActivationData(untrustedConfig, requestContext) {
391
+ const config = validateAdapterConfig(untrustedConfig, getActivationData_ConfigPropertyNames);
392
+ // Invalid or incomplete config
393
+ if (config === null) {
394
+ return null;
395
+ }
396
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
397
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
398
+ };
399
+
400
+ exports.getActivationDataAdapterFactory = getActivationDataAdapterFactory;
401
+
402
+ Object.defineProperty(exports, '__esModule', { value: true });
403
+
404
+ }));