@salesforce/lds-adapters-platform-named-credential 1.247.0 → 1.249.0

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.
@@ -4,10 +4,10 @@
4
4
  * For full license text, see the LICENSE.txt file
5
5
  */
6
6
 
7
- import { serializeStructuredKey, StoreKeyMap, deepFreeze, createResourceParams as createResourceParams$3, typeCheckConfig as typeCheckConfig$3, ingestShape, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$1 } from '@luvio/engine';
7
+ import { serializeStructuredKey, ingestShape, StoreKeyMap, deepFreeze, createResourceParams as createResourceParams$6, typeCheckConfig as typeCheckConfig$6, buildNetworkSnapshotCachePolicy as buildNetworkSnapshotCachePolicy$2 } from '@luvio/engine';
8
8
 
9
9
  const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
- const { keys: ObjectKeys, create: ObjectCreate } = Object;
10
+ const { keys: ObjectKeys$1, create: ObjectCreate$1 } = Object;
11
11
  const { isArray: ArrayIsArray$1 } = Array;
12
12
  /**
13
13
  * Validates an adapter config is well-formed.
@@ -31,7 +31,7 @@ function validateConfig(config, adapter, oneOf) {
31
31
  throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
32
32
  }
33
33
  const supported = required.concat(optional);
34
- if (ObjectKeys(config).some(key => !supported.includes(key))) {
34
+ if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
35
35
  throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
36
36
  }
37
37
  }
@@ -71,7 +71,9 @@ function buildAdapterValidationConfig(displayName, paramsMeta) {
71
71
  }
72
72
  const keyPrefix = 'named-credential';
73
73
 
74
+ const { keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
74
75
  const { isArray: ArrayIsArray } = Array;
76
+ const { stringify: JSONStringify } = JSON;
75
77
  function equalsArray(a, b, equalsItem) {
76
78
  const aLength = a.length;
77
79
  const bLength = b.length;
@@ -91,20 +93,218 @@ function createLink(ref) {
91
93
  };
92
94
  }
93
95
 
96
+ function validate$8(obj, path = 'CredentialValueRepresentation') {
97
+ const v_error = (() => {
98
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
99
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
100
+ }
101
+ const obj_encrypted = obj.encrypted;
102
+ const path_encrypted = path + '.encrypted';
103
+ if (typeof obj_encrypted !== 'boolean') {
104
+ return new TypeError('Expected "boolean" but received "' + typeof obj_encrypted + '" (at "' + path_encrypted + '")');
105
+ }
106
+ if (obj.revision !== undefined) {
107
+ const obj_revision = obj.revision;
108
+ const path_revision = path + '.revision';
109
+ let obj_revision_union0 = null;
110
+ const obj_revision_union0_error = (() => {
111
+ if (typeof obj_revision !== 'number' || (typeof obj_revision === 'number' && Math.floor(obj_revision) !== obj_revision)) {
112
+ return new TypeError('Expected "integer" but received "' + typeof obj_revision + '" (at "' + path_revision + '")');
113
+ }
114
+ })();
115
+ if (obj_revision_union0_error != null) {
116
+ obj_revision_union0 = obj_revision_union0_error.message;
117
+ }
118
+ let obj_revision_union1 = null;
119
+ const obj_revision_union1_error = (() => {
120
+ if (obj_revision !== null) {
121
+ return new TypeError('Expected "null" but received "' + typeof obj_revision + '" (at "' + path_revision + '")');
122
+ }
123
+ })();
124
+ if (obj_revision_union1_error != null) {
125
+ obj_revision_union1 = obj_revision_union1_error.message;
126
+ }
127
+ if (obj_revision_union0 && obj_revision_union1) {
128
+ let message = 'Object doesn\'t match union (at "' + path_revision + '")';
129
+ message += '\n' + obj_revision_union0.split('\n').map((line) => '\t' + line).join('\n');
130
+ message += '\n' + obj_revision_union1.split('\n').map((line) => '\t' + line).join('\n');
131
+ return new TypeError(message);
132
+ }
133
+ }
134
+ if (obj.value !== undefined) {
135
+ const obj_value = obj.value;
136
+ const path_value = path + '.value';
137
+ let obj_value_union0 = null;
138
+ const obj_value_union0_error = (() => {
139
+ if (typeof obj_value !== 'string') {
140
+ return new TypeError('Expected "string" but received "' + typeof obj_value + '" (at "' + path_value + '")');
141
+ }
142
+ })();
143
+ if (obj_value_union0_error != null) {
144
+ obj_value_union0 = obj_value_union0_error.message;
145
+ }
146
+ let obj_value_union1 = null;
147
+ const obj_value_union1_error = (() => {
148
+ if (obj_value !== null) {
149
+ return new TypeError('Expected "null" but received "' + typeof obj_value + '" (at "' + path_value + '")');
150
+ }
151
+ })();
152
+ if (obj_value_union1_error != null) {
153
+ obj_value_union1 = obj_value_union1_error.message;
154
+ }
155
+ if (obj_value_union0 && obj_value_union1) {
156
+ let message = 'Object doesn\'t match union (at "' + path_value + '")';
157
+ message += '\n' + obj_value_union0.split('\n').map((line) => '\t' + line).join('\n');
158
+ message += '\n' + obj_value_union1.split('\n').map((line) => '\t' + line).join('\n');
159
+ return new TypeError(message);
160
+ }
161
+ }
162
+ })();
163
+ return v_error === undefined ? null : v_error;
164
+ }
165
+
166
+ const TTL = 100;
167
+ const VERSION$5 = "cea79b36245bc9456aff9b5c491058d0";
168
+ function validate$7(obj, path = 'CredentialRepresentation') {
169
+ const v_error = (() => {
170
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
171
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
172
+ }
173
+ if (obj.authenticationProtocol !== undefined) {
174
+ const obj_authenticationProtocol = obj.authenticationProtocol;
175
+ const path_authenticationProtocol = path + '.authenticationProtocol';
176
+ if (typeof obj_authenticationProtocol !== 'string') {
177
+ return new TypeError('Expected "string" but received "' + typeof obj_authenticationProtocol + '" (at "' + path_authenticationProtocol + '")');
178
+ }
179
+ }
180
+ if (obj.authenticationProtocolVariant !== undefined) {
181
+ const obj_authenticationProtocolVariant = obj.authenticationProtocolVariant;
182
+ const path_authenticationProtocolVariant = path + '.authenticationProtocolVariant';
183
+ if (typeof obj_authenticationProtocolVariant !== 'string') {
184
+ return new TypeError('Expected "string" but received "' + typeof obj_authenticationProtocolVariant + '" (at "' + path_authenticationProtocolVariant + '")');
185
+ }
186
+ }
187
+ const obj_authenticationStatus = obj.authenticationStatus;
188
+ const path_authenticationStatus = path + '.authenticationStatus';
189
+ if (typeof obj_authenticationStatus !== 'string') {
190
+ return new TypeError('Expected "string" but received "' + typeof obj_authenticationStatus + '" (at "' + path_authenticationStatus + '")');
191
+ }
192
+ const obj_credentials = obj.credentials;
193
+ const path_credentials = path + '.credentials';
194
+ if (typeof obj_credentials !== 'object' || ArrayIsArray(obj_credentials) || obj_credentials === null) {
195
+ return new TypeError('Expected "object" but received "' + typeof obj_credentials + '" (at "' + path_credentials + '")');
196
+ }
197
+ const obj_credentials_keys = ObjectKeys(obj_credentials);
198
+ for (let i = 0; i < obj_credentials_keys.length; i++) {
199
+ const key = obj_credentials_keys[i];
200
+ const obj_credentials_prop = obj_credentials[key];
201
+ const path_credentials_prop = path_credentials + '["' + key + '"]';
202
+ const referencepath_credentials_propValidationError = validate$8(obj_credentials_prop, path_credentials_prop);
203
+ if (referencepath_credentials_propValidationError !== null) {
204
+ let message = 'Object doesn\'t match CredentialValueRepresentation (at "' + path_credentials_prop + '")\n';
205
+ message += referencepath_credentials_propValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
206
+ return new TypeError(message);
207
+ }
208
+ }
209
+ const obj_externalCredential = obj.externalCredential;
210
+ const path_externalCredential = path + '.externalCredential';
211
+ if (typeof obj_externalCredential !== 'string') {
212
+ return new TypeError('Expected "string" but received "' + typeof obj_externalCredential + '" (at "' + path_externalCredential + '")');
213
+ }
214
+ const obj_principalName = obj.principalName;
215
+ const path_principalName = path + '.principalName';
216
+ let obj_principalName_union0 = null;
217
+ const obj_principalName_union0_error = (() => {
218
+ if (typeof obj_principalName !== 'string') {
219
+ return new TypeError('Expected "string" but received "' + typeof obj_principalName + '" (at "' + path_principalName + '")');
220
+ }
221
+ })();
222
+ if (obj_principalName_union0_error != null) {
223
+ obj_principalName_union0 = obj_principalName_union0_error.message;
224
+ }
225
+ let obj_principalName_union1 = null;
226
+ const obj_principalName_union1_error = (() => {
227
+ if (obj_principalName !== null) {
228
+ return new TypeError('Expected "null" but received "' + typeof obj_principalName + '" (at "' + path_principalName + '")');
229
+ }
230
+ })();
231
+ if (obj_principalName_union1_error != null) {
232
+ obj_principalName_union1 = obj_principalName_union1_error.message;
233
+ }
234
+ if (obj_principalName_union0 && obj_principalName_union1) {
235
+ let message = 'Object doesn\'t match union (at "' + path_principalName + '")';
236
+ message += '\n' + obj_principalName_union0.split('\n').map((line) => '\t' + line).join('\n');
237
+ message += '\n' + obj_principalName_union1.split('\n').map((line) => '\t' + line).join('\n');
238
+ return new TypeError(message);
239
+ }
240
+ const obj_principalType = obj.principalType;
241
+ const path_principalType = path + '.principalType';
242
+ if (typeof obj_principalType !== 'string') {
243
+ return new TypeError('Expected "string" but received "' + typeof obj_principalType + '" (at "' + path_principalType + '")');
244
+ }
245
+ })();
246
+ return v_error === undefined ? null : v_error;
247
+ }
94
248
  const RepresentationType$3 = 'CredentialRepresentation';
95
- function keyBuilder$5(luvio, config) {
249
+ function keyBuilder$7(luvio, config) {
96
250
  return keyPrefix + '::' + RepresentationType$3 + ':' + config.externalCredential + ':' + config.principalType + ':' + (config.principalName === null ? '' : config.principalName);
97
251
  }
252
+ function keyBuilderFromType$2(luvio, object) {
253
+ const keyParams = {
254
+ externalCredential: object.externalCredential,
255
+ principalType: object.principalType,
256
+ principalName: object.principalName
257
+ };
258
+ return keyBuilder$7(luvio, keyParams);
259
+ }
260
+ function normalize$3(input, existing, path, luvio, store, timestamp) {
261
+ return input;
262
+ }
263
+ const select$a = function CredentialRepresentationSelect() {
264
+ return {
265
+ kind: 'Fragment',
266
+ version: VERSION$5,
267
+ private: [],
268
+ opaque: true
269
+ };
270
+ };
271
+ function equals$5(existing, incoming) {
272
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
273
+ return false;
274
+ }
275
+ return true;
276
+ }
277
+ const ingest$3 = function CredentialRepresentationIngest(input, path, luvio, store, timestamp) {
278
+ if (process.env.NODE_ENV !== 'production') {
279
+ const validateError = validate$7(input);
280
+ if (validateError !== null) {
281
+ throw validateError;
282
+ }
283
+ }
284
+ const key = keyBuilderFromType$2(luvio, input);
285
+ const ttlToUse = TTL;
286
+ ingestShape(input, path, luvio, store, timestamp, ttlToUse, key, normalize$3, "named-credential", VERSION$5, RepresentationType$3, equals$5);
287
+ return createLink(key);
288
+ };
289
+ function getTypeCacheKeys$3(rootKeySet, luvio, input, fullPathFactory) {
290
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
291
+ const rootKey = keyBuilderFromType$2(luvio, input);
292
+ rootKeySet.set(rootKey, {
293
+ namespace: keyPrefix,
294
+ representationName: RepresentationType$3,
295
+ mergeable: false
296
+ });
297
+ }
98
298
 
99
- function keyBuilder$4(luvio, params) {
100
- return keyBuilder$5(luvio, {
299
+ function keyBuilder$6(luvio, params) {
300
+ return keyBuilder$7(luvio, {
101
301
  externalCredential: params.queryParams.externalCredential || '',
102
302
  principalType: params.queryParams.principalType || '',
103
303
  principalName: params.queryParams.principalName || ''
104
304
  });
105
305
  }
106
- function getResponseCacheKeys$2(cacheKeyMap, luvio, resourceParams) {
107
- const key = keyBuilder$4(luvio, resourceParams);
306
+ function getResponseCacheKeys$5(cacheKeyMap, luvio, resourceParams) {
307
+ const key = keyBuilder$6(luvio, resourceParams);
108
308
  cacheKeyMap.set(key, {
109
309
  namespace: keyPrefix,
110
310
  representationName: RepresentationType$3,
@@ -112,10 +312,10 @@ function getResponseCacheKeys$2(cacheKeyMap, luvio, resourceParams) {
112
312
  });
113
313
  }
114
314
  function evictSuccess(luvio, resourceParams) {
115
- const key = keyBuilder$4(luvio, resourceParams);
315
+ const key = keyBuilder$6(luvio, resourceParams);
116
316
  luvio.storeEvict(key);
117
317
  }
118
- function createResourceRequest$2(config) {
318
+ function createResourceRequest$5(config) {
119
319
  const headers = {};
120
320
  return {
121
321
  baseUri: '/services/data/v60.0',
@@ -129,17 +329,403 @@ function createResourceRequest$2(config) {
129
329
  };
130
330
  }
131
331
 
132
- const adapterName$2 = 'deleteCredential';
332
+ const adapterName$5 = 'deleteCredential';
133
333
  const deleteCredential_ConfigPropertyMetadata = [
134
334
  generateParamConfigMetadata('externalCredential', false, 1 /* QueryParameter */, 0 /* String */),
135
335
  generateParamConfigMetadata('principalName', false, 1 /* QueryParameter */, 0 /* String */),
136
336
  generateParamConfigMetadata('principalType', false, 1 /* QueryParameter */, 0 /* String */),
137
337
  ];
138
- const deleteCredential_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$2, deleteCredential_ConfigPropertyMetadata);
139
- const createResourceParams$2 = /*#__PURE__*/ createResourceParams$3(deleteCredential_ConfigPropertyMetadata);
338
+ const deleteCredential_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$5, deleteCredential_ConfigPropertyMetadata);
339
+ const createResourceParams$5 = /*#__PURE__*/ createResourceParams$6(deleteCredential_ConfigPropertyMetadata);
340
+ function typeCheckConfig$5(untrustedConfig) {
341
+ const config = {};
342
+ typeCheckConfig$6(untrustedConfig, config, deleteCredential_ConfigPropertyMetadata);
343
+ return config;
344
+ }
345
+ function validateAdapterConfig$5(untrustedConfig, configPropertyNames) {
346
+ if (!untrustedIsObject(untrustedConfig)) {
347
+ return null;
348
+ }
349
+ if (process.env.NODE_ENV !== 'production') {
350
+ validateConfig(untrustedConfig, configPropertyNames);
351
+ }
352
+ const config = typeCheckConfig$5(untrustedConfig);
353
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
354
+ return null;
355
+ }
356
+ return config;
357
+ }
358
+ function buildNetworkSnapshot$5(luvio, config, options) {
359
+ const resourceParams = createResourceParams$5(config);
360
+ const request = createResourceRequest$5(resourceParams);
361
+ return luvio.dispatchResourceRequest(request, options)
362
+ .then(() => {
363
+ return luvio.handleSuccessResponse(() => {
364
+ evictSuccess(luvio, resourceParams);
365
+ return luvio.storeBroadcast();
366
+ }, () => {
367
+ const cache = new StoreKeyMap();
368
+ getResponseCacheKeys$5(cache, luvio, resourceParams);
369
+ return cache;
370
+ });
371
+ }, (response) => {
372
+ deepFreeze(response);
373
+ throw response;
374
+ });
375
+ }
376
+ const deleteCredentialAdapterFactory = (luvio) => {
377
+ return function namedCredentialdeleteCredential(untrustedConfig) {
378
+ const config = validateAdapterConfig$5(untrustedConfig, deleteCredential_ConfigPropertyNames);
379
+ // Invalid or incomplete config
380
+ if (config === null) {
381
+ throw new Error(`Invalid config for "${adapterName$5}"`);
382
+ }
383
+ return buildNetworkSnapshot$5(luvio, config);
384
+ };
385
+ };
386
+
387
+ function select$9(luvio, params) {
388
+ return select$a();
389
+ }
390
+ function keyBuilder$5(luvio, params) {
391
+ return keyBuilder$7(luvio, {
392
+ externalCredential: params.queryParams.externalCredential || '',
393
+ principalType: params.queryParams.principalType || '',
394
+ principalName: params.queryParams.principalName || ''
395
+ });
396
+ }
397
+ function getResponseCacheKeys$4(storeKeyMap, luvio, resourceParams, response) {
398
+ getTypeCacheKeys$3(storeKeyMap, luvio, response);
399
+ }
400
+ function ingestSuccess$4(luvio, resourceParams, response, snapshotRefresh) {
401
+ const { body } = response;
402
+ const key = keyBuilder$5(luvio, resourceParams);
403
+ luvio.storeIngest(key, ingest$3, body);
404
+ const snapshot = luvio.storeLookup({
405
+ recordId: key,
406
+ node: select$9(),
407
+ variables: {},
408
+ }, snapshotRefresh);
409
+ if (process.env.NODE_ENV !== 'production') {
410
+ if (snapshot.state !== 'Fulfilled') {
411
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
412
+ }
413
+ }
414
+ deepFreeze(snapshot.data);
415
+ return snapshot;
416
+ }
417
+ function ingestError$1(luvio, params, error, snapshotRefresh) {
418
+ const key = keyBuilder$5(luvio, params);
419
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
420
+ const storeMetadataParams = {
421
+ ttl: TTL,
422
+ namespace: keyPrefix,
423
+ version: VERSION$5,
424
+ representationName: RepresentationType$3
425
+ };
426
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
427
+ return errorSnapshot;
428
+ }
429
+ function createResourceRequest$4(config) {
430
+ const headers = {};
431
+ return {
432
+ baseUri: '/services/data/v60.0',
433
+ basePath: '/named-credentials/credential',
434
+ method: 'get',
435
+ body: null,
436
+ urlParams: {},
437
+ queryParams: config.queryParams,
438
+ headers,
439
+ priority: 'normal',
440
+ };
441
+ }
442
+
443
+ const adapterName$4 = 'getCredential';
444
+ const getCredential_ConfigPropertyMetadata = [
445
+ generateParamConfigMetadata('externalCredential', false, 1 /* QueryParameter */, 0 /* String */),
446
+ generateParamConfigMetadata('principalName', false, 1 /* QueryParameter */, 0 /* String */),
447
+ generateParamConfigMetadata('principalType', false, 1 /* QueryParameter */, 0 /* String */),
448
+ ];
449
+ const getCredential_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$4, getCredential_ConfigPropertyMetadata);
450
+ const createResourceParams$4 = /*#__PURE__*/ createResourceParams$6(getCredential_ConfigPropertyMetadata);
451
+ function keyBuilder$4(luvio, config) {
452
+ const resourceParams = createResourceParams$4(config);
453
+ return keyBuilder$5(luvio, resourceParams);
454
+ }
455
+ function typeCheckConfig$4(untrustedConfig) {
456
+ const config = {};
457
+ typeCheckConfig$6(untrustedConfig, config, getCredential_ConfigPropertyMetadata);
458
+ return config;
459
+ }
460
+ function validateAdapterConfig$4(untrustedConfig, configPropertyNames) {
461
+ if (!untrustedIsObject(untrustedConfig)) {
462
+ return null;
463
+ }
464
+ if (process.env.NODE_ENV !== 'production') {
465
+ validateConfig(untrustedConfig, configPropertyNames);
466
+ }
467
+ const config = typeCheckConfig$4(untrustedConfig);
468
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
469
+ return null;
470
+ }
471
+ return config;
472
+ }
473
+ function adapterFragment$1(luvio, config) {
474
+ createResourceParams$4(config);
475
+ return select$9();
476
+ }
477
+ function onFetchResponseSuccess$1(luvio, config, resourceParams, response) {
478
+ const snapshot = ingestSuccess$4(luvio, resourceParams, response, {
479
+ config,
480
+ resolve: () => buildNetworkSnapshot$4(luvio, config, snapshotRefreshOptions)
481
+ });
482
+ return luvio.storeBroadcast().then(() => snapshot);
483
+ }
484
+ function onFetchResponseError$1(luvio, config, resourceParams, response) {
485
+ const snapshot = ingestError$1(luvio, resourceParams, response, {
486
+ config,
487
+ resolve: () => buildNetworkSnapshot$4(luvio, config, snapshotRefreshOptions)
488
+ });
489
+ return luvio.storeBroadcast().then(() => snapshot);
490
+ }
491
+ function buildNetworkSnapshot$4(luvio, config, options) {
492
+ const resourceParams = createResourceParams$4(config);
493
+ const request = createResourceRequest$4(resourceParams);
494
+ return luvio.dispatchResourceRequest(request, options)
495
+ .then((response) => {
496
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess$1(luvio, config, resourceParams, response), () => {
497
+ const cache = new StoreKeyMap();
498
+ getResponseCacheKeys$4(cache, luvio, resourceParams, response.body);
499
+ return cache;
500
+ });
501
+ }, (response) => {
502
+ return luvio.handleErrorResponse(() => onFetchResponseError$1(luvio, config, resourceParams, response));
503
+ });
504
+ }
505
+ function buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext) {
506
+ return buildNetworkSnapshotCachePolicy$2(context, coercedAdapterRequestContext, buildNetworkSnapshot$4, undefined, false);
507
+ }
508
+ function buildCachedSnapshotCachePolicy$1(context, storeLookup) {
509
+ const { luvio, config } = context;
510
+ const selector = {
511
+ recordId: keyBuilder$4(luvio, config),
512
+ node: adapterFragment$1(luvio, config),
513
+ variables: {},
514
+ };
515
+ const cacheSnapshot = storeLookup(selector, {
516
+ config,
517
+ resolve: () => buildNetworkSnapshot$4(luvio, config, snapshotRefreshOptions)
518
+ });
519
+ return cacheSnapshot;
520
+ }
521
+ const getCredentialAdapterFactory = (luvio) => function namedCredential__getCredential(untrustedConfig, requestContext) {
522
+ const config = validateAdapterConfig$4(untrustedConfig, getCredential_ConfigPropertyNames);
523
+ // Invalid or incomplete config
524
+ if (config === null) {
525
+ return null;
526
+ }
527
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
528
+ buildCachedSnapshotCachePolicy$1, buildNetworkSnapshotCachePolicy$1);
529
+ };
530
+
531
+ function validate$6(obj, path = 'CredentialInputRepresentation') {
532
+ const v_error = (() => {
533
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
534
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
535
+ }
536
+ if (obj.authenticationProtocol !== undefined) {
537
+ const obj_authenticationProtocol = obj.authenticationProtocol;
538
+ const path_authenticationProtocol = path + '.authenticationProtocol';
539
+ if (typeof obj_authenticationProtocol !== 'string') {
540
+ return new TypeError('Expected "string" but received "' + typeof obj_authenticationProtocol + '" (at "' + path_authenticationProtocol + '")');
541
+ }
542
+ }
543
+ if (obj.authenticationProtocolVariant !== undefined) {
544
+ const obj_authenticationProtocolVariant = obj.authenticationProtocolVariant;
545
+ const path_authenticationProtocolVariant = path + '.authenticationProtocolVariant';
546
+ if (typeof obj_authenticationProtocolVariant !== 'string') {
547
+ return new TypeError('Expected "string" but received "' + typeof obj_authenticationProtocolVariant + '" (at "' + path_authenticationProtocolVariant + '")');
548
+ }
549
+ }
550
+ const obj_credentials = obj.credentials;
551
+ const path_credentials = path + '.credentials';
552
+ if (typeof obj_credentials !== 'object' || ArrayIsArray(obj_credentials) || obj_credentials === null) {
553
+ return new TypeError('Expected "object" but received "' + typeof obj_credentials + '" (at "' + path_credentials + '")');
554
+ }
555
+ const obj_credentials_keys = ObjectKeys(obj_credentials);
556
+ for (let i = 0; i < obj_credentials_keys.length; i++) {
557
+ const key = obj_credentials_keys[i];
558
+ const obj_credentials_prop = obj_credentials[key];
559
+ const path_credentials_prop = path_credentials + '["' + key + '"]';
560
+ if (typeof obj_credentials_prop !== 'object' || ArrayIsArray(obj_credentials_prop) || obj_credentials_prop === null) {
561
+ return new TypeError('Expected "object" but received "' + typeof obj_credentials_prop + '" (at "' + path_credentials_prop + '")');
562
+ }
563
+ }
564
+ const obj_externalCredential = obj.externalCredential;
565
+ const path_externalCredential = path + '.externalCredential';
566
+ if (typeof obj_externalCredential !== 'string') {
567
+ return new TypeError('Expected "string" but received "' + typeof obj_externalCredential + '" (at "' + path_externalCredential + '")');
568
+ }
569
+ const obj_principalName = obj.principalName;
570
+ const path_principalName = path + '.principalName';
571
+ if (typeof obj_principalName !== 'string') {
572
+ return new TypeError('Expected "string" but received "' + typeof obj_principalName + '" (at "' + path_principalName + '")');
573
+ }
574
+ const obj_principalType = obj.principalType;
575
+ const path_principalType = path + '.principalType';
576
+ if (typeof obj_principalType !== 'string') {
577
+ return new TypeError('Expected "string" but received "' + typeof obj_principalType + '" (at "' + path_principalType + '")');
578
+ }
579
+ })();
580
+ return v_error === undefined ? null : v_error;
581
+ }
582
+
583
+ function select$8(luvio, params) {
584
+ return select$a();
585
+ }
586
+ function getResponseCacheKeys$3(storeKeyMap, luvio, resourceParams, response) {
587
+ getTypeCacheKeys$3(storeKeyMap, luvio, response);
588
+ }
589
+ function ingestSuccess$3(luvio, resourceParams, response) {
590
+ const { body } = response;
591
+ const key = keyBuilderFromType$2(luvio, body);
592
+ luvio.storeIngest(key, ingest$3, body);
593
+ const snapshot = luvio.storeLookup({
594
+ recordId: key,
595
+ node: select$8(),
596
+ variables: {},
597
+ });
598
+ if (process.env.NODE_ENV !== 'production') {
599
+ if (snapshot.state !== 'Fulfilled') {
600
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
601
+ }
602
+ }
603
+ deepFreeze(snapshot.data);
604
+ return snapshot;
605
+ }
606
+ function createResourceRequest$3(config) {
607
+ const headers = {};
608
+ return {
609
+ baseUri: '/services/data/v60.0',
610
+ basePath: '/named-credentials/credential',
611
+ method: 'post',
612
+ body: config.body,
613
+ urlParams: {},
614
+ queryParams: config.queryParams,
615
+ headers,
616
+ priority: 'normal',
617
+ };
618
+ }
619
+
620
+ const adapterName$3 = 'createCredential';
621
+ const createCredential_ConfigPropertyMetadata = [
622
+ generateParamConfigMetadata('action', false, 1 /* QueryParameter */, 0 /* String */),
623
+ generateParamConfigMetadata('requestBody', true, 2 /* Body */, 4 /* Unsupported */),
624
+ ];
625
+ const createCredential_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$3, createCredential_ConfigPropertyMetadata);
626
+ const createResourceParams$3 = /*#__PURE__*/ createResourceParams$6(createCredential_ConfigPropertyMetadata);
627
+ function typeCheckConfig$3(untrustedConfig) {
628
+ const config = {};
629
+ typeCheckConfig$6(untrustedConfig, config, createCredential_ConfigPropertyMetadata);
630
+ const untrustedConfig_requestBody = untrustedConfig.requestBody;
631
+ const referenceCredentialInputRepresentationValidationError = validate$6(untrustedConfig_requestBody);
632
+ if (referenceCredentialInputRepresentationValidationError === null) {
633
+ config.requestBody = untrustedConfig_requestBody;
634
+ }
635
+ return config;
636
+ }
637
+ function validateAdapterConfig$3(untrustedConfig, configPropertyNames) {
638
+ if (!untrustedIsObject(untrustedConfig)) {
639
+ return null;
640
+ }
641
+ if (process.env.NODE_ENV !== 'production') {
642
+ validateConfig(untrustedConfig, configPropertyNames);
643
+ }
644
+ const config = typeCheckConfig$3(untrustedConfig);
645
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
646
+ return null;
647
+ }
648
+ return config;
649
+ }
650
+ function buildNetworkSnapshot$3(luvio, config, options) {
651
+ const resourceParams = createResourceParams$3(config);
652
+ const request = createResourceRequest$3(resourceParams);
653
+ return luvio.dispatchResourceRequest(request, options)
654
+ .then((response) => {
655
+ return luvio.handleSuccessResponse(() => {
656
+ const snapshot = ingestSuccess$3(luvio, resourceParams, response);
657
+ return luvio.storeBroadcast().then(() => snapshot);
658
+ }, () => {
659
+ const cache = new StoreKeyMap();
660
+ getResponseCacheKeys$3(cache, luvio, resourceParams, response.body);
661
+ return cache;
662
+ });
663
+ }, (response) => {
664
+ deepFreeze(response);
665
+ throw response;
666
+ });
667
+ }
668
+ const createCredentialAdapterFactory = (luvio) => {
669
+ return function createCredential(untrustedConfig) {
670
+ const config = validateAdapterConfig$3(untrustedConfig, createCredential_ConfigPropertyNames);
671
+ // Invalid or incomplete config
672
+ if (config === null) {
673
+ throw new Error('Invalid config for "createCredential"');
674
+ }
675
+ return buildNetworkSnapshot$3(luvio, config);
676
+ };
677
+ };
678
+
679
+ function select$7(luvio, params) {
680
+ return select$a();
681
+ }
682
+ function getResponseCacheKeys$2(storeKeyMap, luvio, resourceParams, response) {
683
+ getTypeCacheKeys$3(storeKeyMap, luvio, response);
684
+ }
685
+ function ingestSuccess$2(luvio, resourceParams, response) {
686
+ const { body } = response;
687
+ const key = keyBuilderFromType$2(luvio, body);
688
+ luvio.storeIngest(key, ingest$3, body);
689
+ const snapshot = luvio.storeLookup({
690
+ recordId: key,
691
+ node: select$7(),
692
+ variables: {},
693
+ });
694
+ if (process.env.NODE_ENV !== 'production') {
695
+ if (snapshot.state !== 'Fulfilled') {
696
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
697
+ }
698
+ }
699
+ deepFreeze(snapshot.data);
700
+ return snapshot;
701
+ }
702
+ function createResourceRequest$2(config) {
703
+ const headers = {};
704
+ return {
705
+ baseUri: '/services/data/v60.0',
706
+ basePath: '/named-credentials/credential',
707
+ method: 'put',
708
+ body: config.body,
709
+ urlParams: {},
710
+ queryParams: {},
711
+ headers,
712
+ priority: 'normal',
713
+ };
714
+ }
715
+
716
+ const adapterName$2 = 'updateCredential';
717
+ const updateCredential_ConfigPropertyMetadata = [
718
+ generateParamConfigMetadata('requestBody', true, 2 /* Body */, 4 /* Unsupported */),
719
+ ];
720
+ const updateCredential_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$2, updateCredential_ConfigPropertyMetadata);
721
+ const createResourceParams$2 = /*#__PURE__*/ createResourceParams$6(updateCredential_ConfigPropertyMetadata);
140
722
  function typeCheckConfig$2(untrustedConfig) {
141
723
  const config = {};
142
- typeCheckConfig$3(untrustedConfig, config, deleteCredential_ConfigPropertyMetadata);
724
+ const untrustedConfig_requestBody = untrustedConfig.requestBody;
725
+ const referenceCredentialInputRepresentationValidationError = validate$6(untrustedConfig_requestBody);
726
+ if (referenceCredentialInputRepresentationValidationError === null) {
727
+ config.requestBody = untrustedConfig_requestBody;
728
+ }
143
729
  return config;
144
730
  }
145
731
  function validateAdapterConfig$2(untrustedConfig, configPropertyNames) {
@@ -159,13 +745,13 @@ function buildNetworkSnapshot$2(luvio, config, options) {
159
745
  const resourceParams = createResourceParams$2(config);
160
746
  const request = createResourceRequest$2(resourceParams);
161
747
  return luvio.dispatchResourceRequest(request, options)
162
- .then(() => {
748
+ .then((response) => {
163
749
  return luvio.handleSuccessResponse(() => {
164
- evictSuccess(luvio, resourceParams);
165
- return luvio.storeBroadcast();
750
+ const snapshot = ingestSuccess$2(luvio, resourceParams, response);
751
+ return luvio.storeBroadcast().then(() => snapshot);
166
752
  }, () => {
167
753
  const cache = new StoreKeyMap();
168
- getResponseCacheKeys$2(cache, luvio, resourceParams);
754
+ getResponseCacheKeys$2(cache, luvio, resourceParams, response.body);
169
755
  return cache;
170
756
  });
171
757
  }, (response) => {
@@ -173,12 +759,12 @@ function buildNetworkSnapshot$2(luvio, config, options) {
173
759
  throw response;
174
760
  });
175
761
  }
176
- const deleteCredentialAdapterFactory = (luvio) => {
177
- return function namedCredentialdeleteCredential(untrustedConfig) {
178
- const config = validateAdapterConfig$2(untrustedConfig, deleteCredential_ConfigPropertyNames);
762
+ const updateCredentialAdapterFactory = (luvio) => {
763
+ return function updateCredential(untrustedConfig) {
764
+ const config = validateAdapterConfig$2(untrustedConfig, updateCredential_ConfigPropertyNames);
179
765
  // Invalid or incomplete config
180
766
  if (config === null) {
181
- throw new Error(`Invalid config for "${adapterName$2}"`);
767
+ throw new Error('Invalid config for "updateCredential"');
182
768
  }
183
769
  return buildNetworkSnapshot$2(luvio, config);
184
770
  };
@@ -367,7 +953,7 @@ const getOAuthCredentialAuthUrl_ConfigPropertyMetadata = [
367
953
  generateParamConfigMetadata('requestBody', true, 2 /* Body */, 4 /* Unsupported */),
368
954
  ];
369
955
  const getOAuthCredentialAuthUrl_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName$1, getOAuthCredentialAuthUrl_ConfigPropertyMetadata);
370
- const createResourceParams$1 = /*#__PURE__*/ createResourceParams$3(getOAuthCredentialAuthUrl_ConfigPropertyMetadata);
956
+ const createResourceParams$1 = /*#__PURE__*/ createResourceParams$6(getOAuthCredentialAuthUrl_ConfigPropertyMetadata);
371
957
  function typeCheckConfig$1(untrustedConfig) {
372
958
  const config = {};
373
959
  const untrustedConfig_requestBody = untrustedConfig.requestBody;
@@ -853,7 +1439,7 @@ function createResourceRequest(config) {
853
1439
  const adapterName = 'getExternalCredentials';
854
1440
  const getExternalCredentials_ConfigPropertyMetadata = [];
855
1441
  const getExternalCredentials_ConfigPropertyNames = /*#__PURE__*/ buildAdapterValidationConfig(adapterName, getExternalCredentials_ConfigPropertyMetadata);
856
- const createResourceParams = /*#__PURE__*/ createResourceParams$3(getExternalCredentials_ConfigPropertyMetadata);
1442
+ const createResourceParams = /*#__PURE__*/ createResourceParams$6(getExternalCredentials_ConfigPropertyMetadata);
857
1443
  function keyBuilder(luvio, config) {
858
1444
  createResourceParams(config);
859
1445
  return keyBuilder$1();
@@ -908,7 +1494,7 @@ function buildNetworkSnapshot(luvio, config, options) {
908
1494
  });
909
1495
  }
910
1496
  function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
911
- return buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext, buildNetworkSnapshot, undefined, false);
1497
+ return buildNetworkSnapshotCachePolicy$2(context, coercedAdapterRequestContext, buildNetworkSnapshot, undefined, false);
912
1498
  }
913
1499
  function buildCachedSnapshotCachePolicy(context, storeLookup) {
914
1500
  const { luvio, config } = context;
@@ -933,4 +1519,4 @@ const getExternalCredentialsAdapterFactory = (luvio) => function namedCredential
933
1519
  buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
934
1520
  };
935
1521
 
936
- export { deleteCredentialAdapterFactory, getExternalCredentialsAdapterFactory, getOAuthCredentialAuthUrlAdapterFactory };
1522
+ export { createCredentialAdapterFactory, deleteCredentialAdapterFactory, getCredentialAdapterFactory, getExternalCredentialsAdapterFactory, getOAuthCredentialAuthUrlAdapterFactory, updateCredentialAdapterFactory };