@salesforce/lds-runtime-mobile 1.313.0 → 1.314.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.
package/dist/main.js CHANGED
@@ -18,7 +18,7 @@
18
18
  import { withRegistration, register } from '@salesforce/lds-default-luvio';
19
19
  import { setupInstrumentation, instrumentAdapter as instrumentAdapter$1, instrumentLuvio, setLdsAdaptersUiapiInstrumentation, setLdsNetworkAdapterInstrumentation } from '@salesforce/lds-instrumentation';
20
20
  import { HttpStatusCode, setBypassDeepFreeze, StoreKeySet, serializeStructuredKey, StringKeyInMemoryStore, Reader, deepFreeze, emitAdapterEvent, StoreKeyMap, createCustomAdapterEventEmitter, isFileReference, Environment, Luvio, InMemoryStore } from '@luvio/engine';
21
- import { RECORD_ID_PREFIX, RECORD_FIELDS_KEY_JUNCTION, RECORD_REPRESENTATION_NAME, extractRecordIdFromStoreKey, keyBuilderQuickActionExecutionRepresentation, ingestQuickActionExecutionRepresentation, keyBuilderContentDocumentCompositeRepresentation, getResponseCacheKeysContentDocumentCompositeRepresentation, keyBuilderFromTypeContentDocumentCompositeRepresentation, ingestContentDocumentCompositeRepresentation, keyBuilderRecord, isStoreKeyRecordViewEntity, getTypeCacheKeysRecord, keyBuilderFromTypeRecordRepresentation, ingestRecord, RecordRepresentationVersion, getRecordId18, getRecordsAdapterFactory, RecordRepresentationRepresentationType, ObjectInfoRepresentationType, getRecordAdapterFactory, getObjectInfoAdapterFactory, getObjectInfosAdapterFactory, getObjectInfoDirectoryAdapterFactory, UiApiNamespace, RecordRepresentationType, RecordRepresentationTTL } from '@salesforce/lds-adapters-uiapi-mobile';
21
+ import { RECORD_ID_PREFIX, RECORD_FIELDS_KEY_JUNCTION, RECORD_REPRESENTATION_NAME, extractRecordIdFromStoreKey, keyBuilderQuickActionExecutionRepresentation, ingestQuickActionExecutionRepresentation, keyBuilderContentDocumentCompositeRepresentation, getResponseCacheKeysContentDocumentCompositeRepresentation, keyBuilderFromTypeContentDocumentCompositeRepresentation, ingestContentDocumentCompositeRepresentation, keyBuilderRecord, isStoreKeyRecordViewEntity, getTypeCacheKeysRecord, keyBuilderFromTypeRecordRepresentation, ingestRecord, RecordRepresentationVersion, buildRecordRepKeyFromId, getRecordId18, getRecordsAdapterFactory, RecordRepresentationRepresentationType, ObjectInfoRepresentationType, getRecordAdapterFactory, getObjectInfoAdapterFactory, getObjectInfosAdapterFactory, getObjectInfoDirectoryAdapterFactory, UiApiNamespace, RecordRepresentationType, RecordRepresentationTTL } from '@salesforce/lds-adapters-uiapi-mobile';
22
22
  import ldsIdempotencyWriteDisabled from '@salesforce/gate/lds.idempotencyWriteDisabled';
23
23
  import ldsBackdatingEnabled from '@salesforce/gate/lds.backdatingEnabled';
24
24
  import { Kind as Kind$1, buildSchema, isObjectType, defaultFieldResolver, visit, execute, parse as parse$7, extendSchema, isScalarType } from '@luvio/graphql-parser';
@@ -1842,6 +1842,63 @@ var QueueOperationType;
1842
1842
  QueueOperationType["Update"] = "update";
1843
1843
  })(QueueOperationType || (QueueOperationType = {}));
1844
1844
 
1845
+ const { keys: keys$6, create: create$6, assign: assign$6, values: values$4 } = Object;
1846
+ const { stringify: stringify$5, parse: parse$5 } = JSON;
1847
+ const { isArray: isArray$3 } = Array;
1848
+
1849
+ const DraftIdMappingKeyPrefix240 = 'DraftIdMapping::';
1850
+ const DRAFT_ID_MAPPINGS_SEGMENT = 'DRAFT_ID_MAPPINGS';
1851
+ function isLegacyDraftIdMapping(key, data) {
1852
+ return key.startsWith(DraftIdMappingKeyPrefix240);
1853
+ }
1854
+ // TODO [W-11677776]: in 242 we changed the format to store keys instead of ids
1855
+ // this can be removed when we drop support for id storing
1856
+ function getRecordKeyForId$1(id) {
1857
+ return `UiApi::RecordRepresentation:${id}`;
1858
+ }
1859
+ /**
1860
+ *
1861
+ * @param mappingIds (optional) requested mapping ids, if undefined all will be retrieved
1862
+ */
1863
+ async function getDraftIdMappings(durableStore, mappingIds) {
1864
+ const mappings = [];
1865
+ let durableStoreOperation;
1866
+ if (mappingIds === undefined) {
1867
+ durableStoreOperation =
1868
+ durableStore.getAllEntries(DRAFT_ID_MAPPINGS_SEGMENT);
1869
+ }
1870
+ else {
1871
+ durableStoreOperation = durableStore.getEntries(mappingIds, DRAFT_ID_MAPPINGS_SEGMENT);
1872
+ }
1873
+ const entries = await durableStoreOperation;
1874
+ if (entries === undefined) {
1875
+ return mappings;
1876
+ }
1877
+ const keys$1 = keys$6(entries);
1878
+ for (const key of keys$1) {
1879
+ const entry = entries[key].data;
1880
+ if (isLegacyDraftIdMapping(key)) {
1881
+ mappings.push({
1882
+ draftKey: getRecordKeyForId$1(entry.draftId),
1883
+ canonicalKey: getRecordKeyForId$1(entry.canonicalId),
1884
+ });
1885
+ }
1886
+ else {
1887
+ mappings.push(entry);
1888
+ }
1889
+ }
1890
+ return mappings;
1891
+ }
1892
+ async function clearDraftIdSegment(durableStore) {
1893
+ const entries = await durableStore.getAllEntries(DRAFT_ID_MAPPINGS_SEGMENT);
1894
+ if (entries) {
1895
+ const keys$1 = keys$6(entries);
1896
+ if (keys$1.length > 0) {
1897
+ await durableStore.evictEntries(keys$1, DRAFT_ID_MAPPINGS_SEGMENT);
1898
+ }
1899
+ }
1900
+ }
1901
+
1845
1902
  class DraftSynthesisError extends Error {
1846
1903
  constructor(message, errorType) {
1847
1904
  super(message);
@@ -1929,14 +1986,6 @@ function createDraftSynthesisErrorResponse(message = 'failed to synthesize draft
1929
1986
  return new DraftErrorFetchResponse(HttpStatusCode.BadRequest, error);
1930
1987
  }
1931
1988
 
1932
- const { keys: keys$6, create: create$6, assign: assign$6, values: values$4 } = Object;
1933
- const { stringify: stringify$5, parse: parse$5 } = JSON;
1934
- const { isArray: isArray$3 } = Array;
1935
-
1936
- function clone$1(obj) {
1937
- return parse$5(stringify$5(obj));
1938
- }
1939
-
1940
1989
  /**
1941
1990
  * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
1942
1991
  * no collisions with existing draft action IDs.
@@ -1961,125 +2010,6 @@ function generateUniqueDraftActionId(existingIds) {
1961
2010
  return newId.toString();
1962
2011
  }
1963
2012
 
1964
- const HTTP_HEADER_RETRY_AFTER = 'Retry-After';
1965
- const HTTP_HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
1966
- const ERROR_CODE_IDEMPOTENCY_FEATURE_NOT_ENABLED = 'IDEMPOTENCY_FEATURE_NOT_ENABLED';
1967
- const ERROR_CODE_IDEMPOTENCY_NOT_SUPPORTED = 'IDEMPOTENCY_NOT_SUPPORTED';
1968
- const ERROR_CODE_IDEMPOTENCY_KEY_USED_DIFFERENT_USER = 'IDEMPOTENCY_KEY_USED_DIFFERENT_USER';
1969
- const ERROR_CODE_IDEMPOTENCY_CONCURRENT_REQUEST = 'IDEMPOTENCY_CONCURRENT_REQUEST';
1970
- const ERROR_CODE_IDEMPOTENCY_KEY_ALREADY_USED = 'IDEMPOTENCY_KEY_ALREADY_USED';
1971
- const ERROR_CODE_IDEMPOTENCY_BACKEND_OPERATION_ERROR = 'IDEMPOTENCY_BACKEND_OPERATION_ERROR';
1972
- /**
1973
- * Get the retry after in milliseconds from the response headers, undefined if not specified.
1974
- * The header could have two different format.
1975
- * Retry-After: <http-date>, like Wed, 21 Oct 2015 07:28:00 GMT
1976
- * Retry-After: <delay-seconds>, like 1.5s
1977
- * @param headers http headers
1978
- * @returns the time to delat in millisconds.
1979
- */
1980
- function getRetryAfterInMs(headers) {
1981
- const retryAfterHeader = headers && headers[HTTP_HEADER_RETRY_AFTER];
1982
- if (retryAfterHeader === undefined) {
1983
- return undefined;
1984
- }
1985
- const delayInSecond = parseFloat(retryAfterHeader);
1986
- if (retryAfterHeader === delayInSecond.toString()) {
1987
- return Math.round(delayInSecond * 1000);
1988
- }
1989
- const delayUntilDateTime = Date.parse(retryAfterHeader);
1990
- if (isNaN(delayUntilDateTime)) {
1991
- return undefined;
1992
- }
1993
- return delayUntilDateTime - Date.now();
1994
- }
1995
-
1996
- function buildLuvioOverrideForDraftAdapters(luvio, handler, extractTargetIdFromCacheKey) {
1997
- // override this to create and enqueue a new draft action, and return synthetic response
1998
- const dispatchResourceRequest = async function (resourceRequest, _context) {
1999
- const resourceRequestCopy = clone$1(resourceRequest);
2000
- resourceRequestCopy.headers = resourceRequestCopy.headers || {};
2001
- if (handler.hasIdempotencySupport()) {
2002
- resourceRequestCopy.headers[HTTP_HEADER_IDEMPOTENCY_KEY] = uuidv4();
2003
- }
2004
- const { data } = await handler.enqueue(resourceRequestCopy).catch((err) => {
2005
- throw transformErrorToDraftSynthesisError(err);
2006
- });
2007
- if (data === undefined) {
2008
- return Promise.reject(createDraftSynthesisErrorResponse());
2009
- }
2010
- return createOkResponse(data);
2011
- };
2012
- // override this to use an infinitely large ttl so the cache entry never expires
2013
- const publishStoreMetadata = function (key, storeMetadataParams) {
2014
- // if we aren't publishing a draft then use base luvio method
2015
- const id = extractTargetIdFromCacheKey(key);
2016
- if (id === undefined || !handler.isDraftId(id)) {
2017
- return luvio.publishStoreMetadata(key, storeMetadataParams);
2018
- }
2019
- return luvio.publishStoreMetadata(key, {
2020
- ...storeMetadataParams,
2021
- ttl: Number.MAX_SAFE_INTEGER,
2022
- });
2023
- };
2024
- return create$6(luvio, {
2025
- dispatchResourceRequest: { value: dispatchResourceRequest },
2026
- publishStoreMetadata: { value: publishStoreMetadata },
2027
- });
2028
- }
2029
-
2030
- const DraftIdMappingKeyPrefix240 = 'DraftIdMapping::';
2031
- const DRAFT_ID_MAPPINGS_SEGMENT = 'DRAFT_ID_MAPPINGS';
2032
- function isLegacyDraftIdMapping(key, data) {
2033
- return key.startsWith(DraftIdMappingKeyPrefix240);
2034
- }
2035
- // TODO [W-11677776]: in 242 we changed the format to store keys instead of ids
2036
- // this can be removed when we drop support for id storing
2037
- function getRecordKeyForId$1(id) {
2038
- return `UiApi::RecordRepresentation:${id}`;
2039
- }
2040
- /**
2041
- *
2042
- * @param mappingIds (optional) requested mapping ids, if undefined all will be retrieved
2043
- */
2044
- async function getDraftIdMappings(durableStore, mappingIds) {
2045
- const mappings = [];
2046
- let durableStoreOperation;
2047
- if (mappingIds === undefined) {
2048
- durableStoreOperation =
2049
- durableStore.getAllEntries(DRAFT_ID_MAPPINGS_SEGMENT);
2050
- }
2051
- else {
2052
- durableStoreOperation = durableStore.getEntries(mappingIds, DRAFT_ID_MAPPINGS_SEGMENT);
2053
- }
2054
- const entries = await durableStoreOperation;
2055
- if (entries === undefined) {
2056
- return mappings;
2057
- }
2058
- const keys$1 = keys$6(entries);
2059
- for (const key of keys$1) {
2060
- const entry = entries[key].data;
2061
- if (isLegacyDraftIdMapping(key)) {
2062
- mappings.push({
2063
- draftKey: getRecordKeyForId$1(entry.draftId),
2064
- canonicalKey: getRecordKeyForId$1(entry.canonicalId),
2065
- });
2066
- }
2067
- else {
2068
- mappings.push(entry);
2069
- }
2070
- }
2071
- return mappings;
2072
- }
2073
- async function clearDraftIdSegment(durableStore) {
2074
- const entries = await durableStore.getAllEntries(DRAFT_ID_MAPPINGS_SEGMENT);
2075
- if (entries) {
2076
- const keys$1 = keys$6(entries);
2077
- if (keys$1.length > 0) {
2078
- await durableStore.evictEntries(keys$1, DRAFT_ID_MAPPINGS_SEGMENT);
2079
- }
2080
- }
2081
- }
2082
-
2083
2013
  var CustomActionResultType;
2084
2014
  (function (CustomActionResultType) {
2085
2015
  CustomActionResultType["SUCCESS"] = "SUCCESS";
@@ -2307,11 +2237,7 @@ class DurableDraftQueue {
2307
2237
  if (this.state === DraftQueueState.Started) {
2308
2238
  this.processNextAction();
2309
2239
  }
2310
- const actionData = (await handler.getDataForAction(pendingAction));
2311
- return {
2312
- action: pendingAction,
2313
- data: actionData,
2314
- };
2240
+ return pendingAction;
2315
2241
  },
2316
2242
  });
2317
2243
  }
@@ -2653,6 +2579,10 @@ class DurableDraftQueue {
2653
2579
  }
2654
2580
  }
2655
2581
 
2582
+ function clone$1(obj) {
2583
+ return parse$5(stringify$5(obj));
2584
+ }
2585
+
2656
2586
  const DRAFT_ACTION_KEY_JUNCTION = '__DraftAction__';
2657
2587
  function buildDraftDurableStoreKey(recordKey, draftActionId) {
2658
2588
  return `${recordKey}${DRAFT_ACTION_KEY_JUNCTION}${draftActionId}`;
@@ -2862,6 +2792,38 @@ class DurableDraftStore {
2862
2792
  }
2863
2793
  }
2864
2794
 
2795
+ const HTTP_HEADER_RETRY_AFTER = 'Retry-After';
2796
+ const HTTP_HEADER_IDEMPOTENCY_KEY = 'Idempotency-Key';
2797
+ const ERROR_CODE_IDEMPOTENCY_FEATURE_NOT_ENABLED = 'IDEMPOTENCY_FEATURE_NOT_ENABLED';
2798
+ const ERROR_CODE_IDEMPOTENCY_NOT_SUPPORTED = 'IDEMPOTENCY_NOT_SUPPORTED';
2799
+ const ERROR_CODE_IDEMPOTENCY_KEY_USED_DIFFERENT_USER = 'IDEMPOTENCY_KEY_USED_DIFFERENT_USER';
2800
+ const ERROR_CODE_IDEMPOTENCY_CONCURRENT_REQUEST = 'IDEMPOTENCY_CONCURRENT_REQUEST';
2801
+ const ERROR_CODE_IDEMPOTENCY_KEY_ALREADY_USED = 'IDEMPOTENCY_KEY_ALREADY_USED';
2802
+ const ERROR_CODE_IDEMPOTENCY_BACKEND_OPERATION_ERROR = 'IDEMPOTENCY_BACKEND_OPERATION_ERROR';
2803
+ /**
2804
+ * Get the retry after in milliseconds from the response headers, undefined if not specified.
2805
+ * The header could have two different format.
2806
+ * Retry-After: <http-date>, like Wed, 21 Oct 2015 07:28:00 GMT
2807
+ * Retry-After: <delay-seconds>, like 1.5s
2808
+ * @param headers http headers
2809
+ * @returns the time to delat in millisconds.
2810
+ */
2811
+ function getRetryAfterInMs(headers) {
2812
+ const retryAfterHeader = headers && headers[HTTP_HEADER_RETRY_AFTER];
2813
+ if (retryAfterHeader === undefined) {
2814
+ return undefined;
2815
+ }
2816
+ const delayInSecond = parseFloat(retryAfterHeader);
2817
+ if (retryAfterHeader === delayInSecond.toString()) {
2818
+ return Math.round(delayInSecond * 1000);
2819
+ }
2820
+ const delayUntilDateTime = Date.parse(retryAfterHeader);
2821
+ if (isNaN(delayUntilDateTime)) {
2822
+ return undefined;
2823
+ }
2824
+ return delayUntilDateTime - Date.now();
2825
+ }
2826
+
2865
2827
  const DEFAULT_FIELD_LAST_MODIFIED_DATE$1 = 'LastModifiedDate';
2866
2828
  const DEFAULT_FIELD_CREATED_DATE$1 = 'CreatedDate';
2867
2829
  class AbstractResourceRequestActionHandler {
@@ -3460,7 +3422,7 @@ class DraftManager {
3460
3422
  tag,
3461
3423
  })
3462
3424
  .then((result) => {
3463
- return this.buildDraftQueueItem(result.action);
3425
+ return this.buildDraftQueueItem(result);
3464
3426
  });
3465
3427
  }
3466
3428
  /**
@@ -5146,79 +5108,6 @@ function isBackdatingFieldEditable(objectInfo, backdatingFieldName, attributeNam
5146
5108
  !draftActionFieldNames.includes(backdatingFieldName));
5147
5109
  }
5148
5110
 
5149
- /**
5150
- * This function takes an unknown error and normalizes it to an Error object
5151
- */
5152
- function normalizeError$1(error) {
5153
- if (typeof error === 'object' && error instanceof Error) {
5154
- return error;
5155
- }
5156
- else if (typeof error === 'string') {
5157
- return new Error(error);
5158
- }
5159
- return new Error(stringify$4(error));
5160
- }
5161
-
5162
- const PERFORM_QUICK_ACTION_ENDPOINT_REGEX = /^\/ui-api\/actions\/perform-quick-action\/.*$/;
5163
- /**
5164
- * Checks if a provided resource request is a POST operation on the record
5165
- * endpoint. If so, it returns true indicating that the request should be enqueued instead of
5166
- * hitting the network.
5167
- * @param request the resource request
5168
- */
5169
- function isRequestPerformQuickAction(request) {
5170
- const { basePath, method } = request;
5171
- return method === 'post' && PERFORM_QUICK_ACTION_ENDPOINT_REGEX.test(basePath);
5172
- }
5173
- function performQuickActionDraftEnvironment(luvio, env, handler) {
5174
- const dispatchResourceRequest = async function (request, context, eventObservers) {
5175
- if (isRequestPerformQuickAction(request) === false) {
5176
- // only override requests to createRecord endpoint
5177
- return env.dispatchResourceRequest(request, context, eventObservers);
5178
- }
5179
- const { data } = await handler.enqueue(request).catch((err) => {
5180
- throw createDraftSynthesisErrorResponse(normalizeError$1(err).message);
5181
- });
5182
- if (data === undefined) {
5183
- return Promise.reject(createDraftSynthesisErrorResponse());
5184
- }
5185
- return createOkResponse(data);
5186
- };
5187
- return create$5(env, {
5188
- dispatchResourceRequest: { value: dispatchResourceRequest },
5189
- });
5190
- }
5191
-
5192
- const PERFORM_UPDATE_RECORD_QUICK_ACTION_ENDPOINT_REGEX = /^\/ui-api\/actions\/perform-quick-action\/.*$/;
5193
- /**
5194
- * Checks if a provided resource request is a PATCH operation on the record
5195
- * endpoint. If so, it returns true indicating that the request should be enqueued instead of
5196
- * hitting the network.
5197
- * @param request the resource request
5198
- */
5199
- function isRequestPerformUpdateRecordQuickAction(request) {
5200
- const { basePath, method } = request;
5201
- return method === 'patch' && PERFORM_UPDATE_RECORD_QUICK_ACTION_ENDPOINT_REGEX.test(basePath);
5202
- }
5203
- function performUpdateRecordQuickActionDraftEnvironment(luvio, env, handler) {
5204
- const dispatchResourceRequest = async function (request, context, eventObservers) {
5205
- if (isRequestPerformUpdateRecordQuickAction(request) === false) {
5206
- // only override requests to createRecord endpoint
5207
- return env.dispatchResourceRequest(request, context, eventObservers);
5208
- }
5209
- const { data } = await handler.enqueue(request).catch((err) => {
5210
- throw createDraftSynthesisErrorResponse(normalizeError$1(err).message);
5211
- });
5212
- if (data === undefined) {
5213
- return Promise.reject(createDraftSynthesisErrorResponse());
5214
- }
5215
- return createOkResponse(data);
5216
- };
5217
- return create$5(env, {
5218
- dispatchResourceRequest: { value: dispatchResourceRequest },
5219
- });
5220
- }
5221
-
5222
5111
  class UiApiDraftRecordService {
5223
5112
  constructor(draftQueue, getLuvio, durableStore, objectInfoAdapter, generateId, userId, formatDisplayValue) {
5224
5113
  this.recordEffectingHandlers = {};
@@ -5655,7 +5544,6 @@ function isCreateContentDocumentAndVersionDraftAdapterEvent(customEvent) {
5655
5544
 
5656
5545
  // so eslint doesn't complain about nimbus
5657
5546
  /* global __nimbus */
5658
- const ContentDocumentCompositeKeyPrefix = 'UiApi::ContentDocumentCompositeRepresentation:';
5659
5547
  function chunkToBase64(chunk) {
5660
5548
  let binary = '';
5661
5549
  const chunkSize = 32 * 1024;
@@ -5676,16 +5564,8 @@ async function streamBufferToBinaryStore(binaryStore, buffer, mimeType) {
5676
5564
  await binaryStore.closeStream(uri);
5677
5565
  return uri;
5678
5566
  }
5679
- function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore, actionHandler) {
5680
- const overriddenLuvio = buildLuvioOverrideForDraftAdapters(luvio, actionHandler, (key) => {
5681
- // if the key is for our top-level response shape
5682
- if (key.startsWith(ContentDocumentCompositeKeyPrefix)) {
5683
- return key.replace(ContentDocumentCompositeKeyPrefix, '');
5684
- }
5685
- // else it's a record rep
5686
- return extractRecordIdFromStoreKey(key);
5687
- });
5688
- return async function createContentDocumentAndVersionDraftAdapter(config, buildNetworkSnapshot, requestContext) {
5567
+ function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore, actionHandler, durableStore) {
5568
+ return async function createContentDocumentAndVersionDraftAdapter(config, buildResourceRequest, requestContext) {
5689
5569
  const context = requestContext || {};
5690
5570
  const observers = context.eventObservers
5691
5571
  ? context.eventObservers
@@ -5724,58 +5604,81 @@ function createContentDocumentAndVersionDraftAdapterFactory(luvio, binaryStore,
5724
5604
  handle,
5725
5605
  mimeType,
5726
5606
  });
5727
- const snapshot = await buildNetworkSnapshot(overriddenLuvio, config);
5728
- // if there was an error then don't leave the binary store polluted with orphaned file
5729
- if (snapshot.state === 'Error') {
5607
+ const resourceRequest = buildResourceRequest(config);
5608
+ if (actionHandler.hasIdempotencySupport()) {
5609
+ resourceRequest.headers['Idempotency-Key'] = uuidv4();
5610
+ }
5611
+ const action = await actionHandler.enqueue(resourceRequest).catch(async (error) => {
5730
5612
  eventEmitter({
5731
5613
  type: 'create-content-document-and-version-synthesized-response-error',
5732
5614
  handle,
5733
5615
  mimeType,
5734
- error: snapshot.error,
5616
+ error: error,
5735
5617
  });
5618
+ // if there was an error then don't leave the binary store polluted with orphaned file
5736
5619
  await binaryStore.delete(handle);
5620
+ throw transformErrorToDraftSynthesisError(error);
5621
+ });
5622
+ eventEmitter({
5623
+ type: 'create-content-document-and-version-synthesized-response-success',
5624
+ handle,
5625
+ });
5626
+ const { contentDocumentId, contentVersionId, contentDocumentLinkId } = actionHandler.getIdsFromAction(action);
5627
+ const [contentDocument, contentVersion, contentDocumentLink] = await Promise.all([
5628
+ getDenormalizedRecord(buildRecordRepKeyFromId(contentDocumentId), durableStore),
5629
+ getDenormalizedRecord(buildRecordRepKeyFromId(contentVersionId), durableStore),
5630
+ getDenormalizedRecord(buildRecordRepKeyFromId(contentDocumentLinkId), durableStore),
5631
+ ]);
5632
+ if (contentDocument === undefined ||
5633
+ contentVersion === undefined ||
5634
+ contentDocumentLink === undefined) {
5635
+ return luvio.errorSnapshot(createDraftSynthesisErrorResponse('Failed to find drafted records'));
5636
+ }
5637
+ // drafted snapshots include all fields, we want to match server response
5638
+ // (which is a subset of all fields) so before we return to userland we'll
5639
+ // pair down the fields
5640
+ const trimmedDownData = {
5641
+ ...{
5642
+ contentDocument: filterOutPrivateProperties(filterOutReferenceNonScalarFields(contentDocument)),
5643
+ contentVersion: filterOutPrivateProperties(filterOutReferenceNonScalarFields(contentVersion)),
5644
+ contentDocumentLinks: [
5645
+ filterOutPrivateProperties(filterOutReferenceNonScalarFields(contentDocumentLink)),
5646
+ ],
5647
+ },
5648
+ };
5649
+ // content document
5650
+ const cdFields = {};
5651
+ for (const field of RESPONSE_CONTENT_DOCUMENT_FIELDS) {
5652
+ cdFields[field] = trimmedDownData.contentDocument.fields[field];
5653
+ }
5654
+ trimmedDownData.contentDocument = {
5655
+ ...trimmedDownData.contentDocument,
5656
+ fields: cdFields,
5657
+ };
5658
+ // content document link (should be the only entry in array)
5659
+ if (trimmedDownData.contentDocumentLinks.length === 1) {
5660
+ const cdl = trimmedDownData.contentDocumentLinks[0];
5661
+ const cdlFields = {};
5662
+ for (const field of RESPONSE_CONTENT_DOCUMENT_LINK_FIELDS) {
5663
+ cdlFields[field] = cdl.fields[field];
5664
+ }
5665
+ trimmedDownData.contentDocumentLinks = [{ ...cdl, fields: cdlFields }];
5737
5666
  }
5738
- if (snapshot.data !== undefined) {
5739
- eventEmitter({
5740
- type: 'create-content-document-and-version-synthesized-response-success',
5741
- handle,
5742
- });
5743
- // drafted snapshots include all fields, we want to match server response
5744
- // (which is a subset of all fields) so before we return to userland we'll
5745
- // pair down the fields
5746
- const trimmedDownData = { ...snapshot.data };
5747
- // content document
5748
- const cdFields = {};
5749
- for (const field of RESPONSE_CONTENT_DOCUMENT_FIELDS) {
5750
- cdFields[field] = trimmedDownData.contentDocument.fields[field];
5751
- }
5752
- trimmedDownData.contentDocument = {
5753
- ...trimmedDownData.contentDocument,
5754
- fields: cdFields,
5755
- };
5756
- // content document link (should be the only entry in array)
5757
- if (trimmedDownData.contentDocumentLinks.length === 1) {
5758
- const cdl = trimmedDownData.contentDocumentLinks[0];
5759
- const cdlFields = {};
5760
- for (const field of RESPONSE_CONTENT_DOCUMENT_LINK_FIELDS) {
5761
- cdlFields[field] = cdl.fields[field];
5762
- }
5763
- trimmedDownData.contentDocumentLinks = [{ ...cdl, fields: cdlFields }];
5764
- }
5765
- // content version
5766
- const cvFields = {};
5767
- for (const field of RESPONSE_CONTENT_VERSION_FIELDS) {
5768
- cvFields[field] = trimmedDownData.contentVersion.fields[field];
5769
- }
5770
- trimmedDownData.contentVersion = {
5771
- ...trimmedDownData.contentVersion,
5772
- fields: cvFields,
5773
- };
5774
- freeze$1(trimmedDownData);
5775
- snapshot.data = trimmedDownData;
5667
+ // content version
5668
+ const cvFields = {};
5669
+ for (const field of RESPONSE_CONTENT_VERSION_FIELDS) {
5670
+ cvFields[field] = trimmedDownData.contentVersion.fields[field];
5776
5671
  }
5672
+ trimmedDownData.contentVersion = {
5673
+ ...trimmedDownData.contentVersion,
5674
+ fields: cvFields,
5675
+ };
5676
+ freeze$1(trimmedDownData);
5777
5677
  eventEmitter({ type: 'create-content-document-and-version-draft-finished' });
5778
- return snapshot;
5678
+ return {
5679
+ state: 'Fulfilled',
5680
+ data: trimmedDownData,
5681
+ };
5779
5682
  };
5780
5683
  }
5781
5684
 
@@ -5875,10 +5778,14 @@ class ContentDocumentCompositeRepresentationActionHandler extends AbstractResour
5875
5778
  contentDocumentId: id,
5876
5779
  });
5877
5780
  }
5878
- async getDataForAction(action) {
5781
+ getIdsFromAction(action) {
5879
5782
  const contentDocumentId = action.targetId;
5880
5783
  const contentVersionId = action.metadata[CONTENT_VERSION_DRAFT_ID_KEY];
5881
5784
  const contentDocumentLinkId = action.metadata[CONTENT_DOCUMENT_LINK_DRAFT_ID_KEY];
5785
+ return { contentDocumentId, contentDocumentLinkId, contentVersionId };
5786
+ }
5787
+ async getDataForAction(action) {
5788
+ const { contentDocumentId, contentVersionId, contentDocumentLinkId } = this.getIdsFromAction(action);
5882
5789
  const fileReference = getFileReferenceFromResourceRequest(action.data);
5883
5790
  if (!contentDocumentId ||
5884
5791
  !contentVersionId ||
@@ -5923,6 +5830,9 @@ class ContentDocumentCompositeRepresentationActionHandler extends AbstractResour
5923
5830
  contentVersion: contentVersionResolved,
5924
5831
  };
5925
5832
  }
5833
+ handleActionEnqueued(action) {
5834
+ return this.reingestRecord(action);
5835
+ }
5926
5836
  // override this so we can delete the binary file
5927
5837
  async handleActionRemoved(action) {
5928
5838
  // TODO [W-11239473]: check if we can just immediately evict instead of calling
@@ -6173,13 +6083,15 @@ function getDescriptionFromResourceRequest(request) {
6173
6083
  function createRecordDraftAdapterFactory(actionHandler, durableStore) {
6174
6084
  return async function createRecordDraftAdapter(config, createResourceRequest) {
6175
6085
  const request = createResourceRequest(config);
6176
- request.headers['Idempotency-Key'] = uuidv4();
6086
+ if (actionHandler.hasIdempotencySupport()) {
6087
+ request.headers['Idempotency-Key'] = uuidv4();
6088
+ }
6177
6089
  request.queryParams = request.queryParams || {};
6178
6090
  request.queryParams['includeFieldsInBody'] = true;
6179
- const result = await actionHandler.enqueue(request).catch((err) => {
6091
+ const action = await actionHandler.enqueue(request).catch((err) => {
6180
6092
  throw transformErrorToDraftSynthesisError(err);
6181
6093
  });
6182
- const record = await getDenormalizedRecord(result.action.tag, durableStore);
6094
+ const record = await getDenormalizedRecord(action.tag, durableStore);
6183
6095
  if (record) {
6184
6096
  return {
6185
6097
  state: 'Fulfilled',
@@ -6199,13 +6111,15 @@ function createRecordDraftAdapterFactory(actionHandler, durableStore) {
6199
6111
  function updateRecordDraftAdapterFactory(actionHandler, durableStore) {
6200
6112
  return async function createRecordDraftAdapter(config, createResourceRequest) {
6201
6113
  const request = createResourceRequest(config);
6202
- request.headers['Idempotency-Key'] = uuidv4();
6114
+ if (actionHandler.hasIdempotencySupport()) {
6115
+ request.headers['Idempotency-Key'] = uuidv4();
6116
+ }
6203
6117
  request.queryParams = request.queryParams || {};
6204
6118
  request.queryParams['includeFieldsInBody'] = true;
6205
- const result = await actionHandler.enqueue(request).catch((err) => {
6119
+ const action = await actionHandler.enqueue(request).catch((err) => {
6206
6120
  throw transformErrorToDraftSynthesisError(err);
6207
6121
  });
6208
- const record = await getDenormalizedRecord(result.action.tag, durableStore);
6122
+ const record = await getDenormalizedRecord(action.tag, durableStore);
6209
6123
  if (record) {
6210
6124
  return {
6211
6125
  state: 'Fulfilled',
@@ -6228,6 +6142,58 @@ function deleteRecordDraftAdapterFactory(actionHandler) {
6228
6142
  };
6229
6143
  }
6230
6144
 
6145
+ /* istanbul ignore file - covered by integration tests */
6146
+ /**
6147
+ * @param luvio The runtime's luvio instance
6148
+ * @param actionHandler The UIAPI Record action handler. NOTE: this adapter doesn't
6149
+ * register it with the DraftQueue, runtime should set that up
6150
+ */
6151
+ function performQuickActionDraftAdapterFactory(actionHandler) {
6152
+ return async function performQuickActionDraftAdapter(config, createResourceRequest) {
6153
+ const request = createResourceRequest(config);
6154
+ const action = await actionHandler.enqueue(request).catch((err) => {
6155
+ const error = transformErrorToDraftSynthesisError(err);
6156
+ deepFreeze(error);
6157
+ throw error;
6158
+ });
6159
+ const data = await actionHandler.getDataForAction(action);
6160
+ if (data) {
6161
+ return {
6162
+ state: 'Fulfilled',
6163
+ data,
6164
+ };
6165
+ }
6166
+ throw createDraftSynthesisErrorResponse();
6167
+ };
6168
+ }
6169
+
6170
+ /* istanbul ignore file - covered by integration tests */
6171
+ /**
6172
+ * @param luvio The runtime's luvio instance
6173
+ * @param actionHandler The UIAPI Record action handler. NOTE: this adapter doesn't
6174
+ * register it with the DraftQueue, runtime should set that up
6175
+ */
6176
+ function performUpdateRecordQuickActionDraftAdapterFactory(actionHandler) {
6177
+ return async function performUpdateRecordQuickActionDraftAdapter(config, createResourceRequest) {
6178
+ const request = createResourceRequest(config);
6179
+ const action = await actionHandler.enqueue(request).catch((err) => {
6180
+ const error = transformErrorToDraftSynthesisError(err);
6181
+ deepFreeze(error);
6182
+ throw error;
6183
+ });
6184
+ const data = await actionHandler.getDataForAction(action);
6185
+ if (data) {
6186
+ return {
6187
+ state: 'Fulfilled',
6188
+ data,
6189
+ };
6190
+ }
6191
+ const error = createDraftSynthesisErrorResponse();
6192
+ deepFreeze(error);
6193
+ throw error;
6194
+ };
6195
+ }
6196
+
6231
6197
  function serializeFieldArguments(argumentNodes, variables) {
6232
6198
  const mutableArgumentNodes = Object.assign([], argumentNodes);
6233
6199
  return `args__(${mutableArgumentNodes
@@ -15087,7 +15053,7 @@ class PrimingNetworkError extends Error {
15087
15053
  this.httpCode = httpCode;
15088
15054
  }
15089
15055
  isServiceProtectionError() {
15090
- // When CSP kicks-in, we get 429/503 errors back - https://salesforce.quip.com/20HZA5BN5xgx
15056
+ // When CSP kicks-in, we get 429/503 errors back
15091
15057
  return this.httpCode === 429 || this.httpCode === 503;
15092
15058
  }
15093
15059
  }
@@ -15375,7 +15341,7 @@ class NimbusPrimingNetworkAdapter {
15375
15341
  batchQuery: configs,
15376
15342
  }),
15377
15343
  headers: {
15378
- // This header is needed to get back 429/503 error code when CSP kicks-in - https://salesforce.quip.com/20HZA5BN5xgx
15344
+ // This header is needed to get back 429/503 error code when CSP kicks-in
15379
15345
  Cos: '0x04',
15380
15346
  },
15381
15347
  queryParams: {},
@@ -15937,8 +15903,6 @@ function getRuntime() {
15937
15903
  durableStore: lazyDurableStore,
15938
15904
  isDraftId: isGenerated,
15939
15905
  }, draftEnv);
15940
- draftEnv = performQuickActionDraftEnvironment(lazyLuvio, draftEnv, quickActionHandler);
15941
- draftEnv = performUpdateRecordQuickActionDraftEnvironment(lazyLuvio, draftEnv, updateRecordQuickActionHandler);
15942
15906
  lazyEnvironment = draftEnv;
15943
15907
  lazyLuvio = new Luvio(lazyEnvironment, {
15944
15908
  instrument: instrumentLuvio,
@@ -15965,16 +15929,20 @@ function getRuntime() {
15965
15929
  const environmentAwareGraphQLBatchAdapter = environmentAwareGraphQLBatchAdapterFactory(lazyObjectInfoService, lazyLuvio, isGenerated);
15966
15930
  setEnvironmentAwareGraphQLBatchAdapter(environmentAwareGraphQLBatchAdapter);
15967
15931
  };
15968
- const draftAwareCreateContentDocumentAndVersionAdapter = createContentDocumentAndVersionDraftAdapterFactory(lazyLuvio, NimbusBinaryStore, contentDocumentCompositeActionHandler);
15932
+ const draftAwareCreateContentDocumentAndVersionAdapter = createContentDocumentAndVersionDraftAdapterFactory(lazyLuvio, NimbusBinaryStore, contentDocumentCompositeActionHandler, lazyDurableStore);
15969
15933
  const draftAwareCreateRecord = createRecordDraftAdapterFactory(uiApiRecordHandler, lazyDurableStore);
15970
15934
  const draftAwareUpdateRecord = updateRecordDraftAdapterFactory(uiApiRecordHandler, lazyDurableStore);
15971
15935
  const draftAwareDeleteRecord = deleteRecordDraftAdapterFactory(uiApiRecordHandler);
15936
+ const draftAwarePeformQuickAction = performQuickActionDraftAdapterFactory(quickActionHandler);
15937
+ const draftAwarePerformUpdateRecordQuickActionAdapter = performUpdateRecordQuickActionDraftAdapterFactory(updateRecordQuickActionHandler);
15972
15938
  withRegistration('@salesforce/lds-adapters-uiapi-mobile', (registration) => {
15973
15939
  setLdsAdaptersUiapiInstrumentation(registration);
15974
15940
  registration.configuration.setDraftAwareCreateContentDocumentAndVersionAdapter(draftAwareCreateContentDocumentAndVersionAdapter);
15975
15941
  registration.configuration.setDraftAwareCreateRecordAdapter(draftAwareCreateRecord);
15976
15942
  registration.configuration.setDraftAwareUpdateRecordAdapter(draftAwareUpdateRecord);
15977
15943
  registration.configuration.setDraftAwareDeleteRecordAdapter(draftAwareDeleteRecord);
15944
+ registration.configuration.setDraftAwarePerformQuickActionAdapter(draftAwarePeformQuickAction);
15945
+ registration.configuration.setDraftAwarePerformUpdateRecordQuickActionAdapter(draftAwarePerformUpdateRecordQuickActionAdapter);
15978
15946
  configureUIAPIGraphQL(registration);
15979
15947
  });
15980
15948
  withRegistration('@salesforce/lds-adapters-uiapi-mobile/graphql', configureUIAPIGraphQL);
@@ -16012,4 +15980,4 @@ register({
16012
15980
  });
16013
15981
 
16014
15982
  export { O11Y_NAMESPACE_LDS_MOBILE, getRuntime, registerReportObserver, reportGraphqlQueryParseError };
16015
- // version: 1.313.0-bf88d762e3
15983
+ // version: 1.314.0-5a451c78cd