@salesforce/lds-runtime-mobile 1.160.0 → 1.160.1

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.
Files changed (3) hide show
  1. package/dist/main.js +48 -26
  2. package/package.json +1 -1
  3. package/sfdc/main.js +48 -26
package/dist/main.js CHANGED
@@ -4905,10 +4905,56 @@ const { keys: keys$4, create: create$4, assign: assign$4, values: values$2 } = O
4905
4905
  const { stringify: stringify$4, parse: parse$4 } = JSON;
4906
4906
  const { isArray: isArray$3 } = Array;
4907
4907
 
4908
+ function clone$1(obj) {
4909
+ return parse$4(stringify$4(obj));
4910
+ }
4911
+
4912
+ /**
4913
+ * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
4914
+ * no collisions with existing draft action IDs.
4915
+ */
4916
+ function generateUniqueDraftActionId(existingIds) {
4917
+ // new id in milliseconds with some extra digits for collisions
4918
+ let newId = new Date().getTime() * 100;
4919
+ const existingAsNumbers = existingIds
4920
+ .map((id) => parseInt(id, 10))
4921
+ .filter((parsed) => !isNaN(parsed));
4922
+ let counter = 0;
4923
+ while (existingAsNumbers.includes(newId)) {
4924
+ newId += 1;
4925
+ counter += 1;
4926
+ // if the counter is 100+ then somehow this method has been called 100
4927
+ // times in one millisecond
4928
+ if (counter >= 100) {
4929
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
4930
+ throw new Error('Unable to generate unique new draft ID');
4931
+ }
4932
+ }
4933
+ return newId.toString();
4934
+ }
4935
+ /**
4936
+ Use Math.random to generate v4 RFC4122 compliant uuid
4937
+ */
4938
+ function uuidv4() {
4939
+ const uuid = [];
4940
+ for (let i = 0; i < 32; i++) {
4941
+ const random = (Math.random() * 16) | 0;
4942
+ if (i === 8 || i === 12 || i === 16 || i === 20) {
4943
+ uuid.push('-');
4944
+ }
4945
+ uuid.push((i === 12 ? 4 : i === 16 ? (random & 3) | 8 : random).toString(16));
4946
+ }
4947
+ return uuid.join('');
4948
+ }
4949
+
4950
+ const IdempotencyKey = 'Idempotency-Key';
4908
4951
  function buildLuvioOverrideForDraftAdapters(luvio, handler, extractTargetIdFromCacheKey, options = {}) {
4909
4952
  // override this to create and enqueue a new draft action, and return synthetic response
4910
4953
  const dispatchResourceRequest = async function (resourceRequest, _context) {
4911
- const { data } = await handler.enqueue(resourceRequest).catch((err) => {
4954
+ const resourceRequestCopy = clone$1(resourceRequest);
4955
+ resourceRequestCopy.headers = resourceRequestCopy.headers || {};
4956
+ resourceRequestCopy.headers[IdempotencyKey] = uuidv4();
4957
+ const { data } = await handler.enqueue(resourceRequestCopy).catch((err) => {
4912
4958
  throw transformErrorToDraftSynthesisError(err);
4913
4959
  });
4914
4960
  if (data === undefined) {
@@ -5000,30 +5046,6 @@ async function clearDraftIdSegment(durableStore) {
5000
5046
  }
5001
5047
  }
5002
5048
 
5003
- /**
5004
- * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
5005
- * no collisions with existing draft action IDs.
5006
- */
5007
- function generateUniqueDraftActionId(existingIds) {
5008
- // new id in milliseconds with some extra digits for collisions
5009
- let newId = new Date().getTime() * 100;
5010
- const existingAsNumbers = existingIds
5011
- .map((id) => parseInt(id, 10))
5012
- .filter((parsed) => !isNaN(parsed));
5013
- let counter = 0;
5014
- while (existingAsNumbers.includes(newId)) {
5015
- newId += 1;
5016
- counter += 1;
5017
- // if the counter is 100+ then somehow this method has been called 100
5018
- // times in one millisecond
5019
- if (counter >= 100) {
5020
- // eslint-disable-next-line @salesforce/lds/no-error-in-production
5021
- throw new Error('Unable to generate unique new draft ID');
5022
- }
5023
- }
5024
- return newId.toString();
5025
- }
5026
-
5027
5049
  var CustomActionResultType;
5028
5050
  (function (CustomActionResultType) {
5029
5051
  CustomActionResultType["SUCCESS"] = "SUCCESS";
@@ -16111,4 +16133,4 @@ register({
16111
16133
  });
16112
16134
 
16113
16135
  export { getRuntime, registerReportObserver, reportGraphqlQueryParseError };
16114
- // version: 1.160.0-ff4890744
16136
+ // version: 1.160.1-fa935e9ee
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/lds-runtime-mobile",
3
- "version": "1.160.0",
3
+ "version": "1.160.1",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "description": "LDS runtime for mobile/hybrid environments.",
6
6
  "main": "dist/main.js",
package/sfdc/main.js CHANGED
@@ -4905,10 +4905,56 @@ const { keys: keys$4, create: create$4, assign: assign$4, values: values$2 } = O
4905
4905
  const { stringify: stringify$4, parse: parse$4 } = JSON;
4906
4906
  const { isArray: isArray$3 } = Array;
4907
4907
 
4908
+ function clone$1(obj) {
4909
+ return parse$4(stringify$4(obj));
4910
+ }
4911
+
4912
+ /**
4913
+ * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
4914
+ * no collisions with existing draft action IDs.
4915
+ */
4916
+ function generateUniqueDraftActionId(existingIds) {
4917
+ // new id in milliseconds with some extra digits for collisions
4918
+ let newId = new Date().getTime() * 100;
4919
+ const existingAsNumbers = existingIds
4920
+ .map((id) => parseInt(id, 10))
4921
+ .filter((parsed) => !isNaN(parsed));
4922
+ let counter = 0;
4923
+ while (existingAsNumbers.includes(newId)) {
4924
+ newId += 1;
4925
+ counter += 1;
4926
+ // if the counter is 100+ then somehow this method has been called 100
4927
+ // times in one millisecond
4928
+ if (counter >= 100) {
4929
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
4930
+ throw new Error('Unable to generate unique new draft ID');
4931
+ }
4932
+ }
4933
+ return newId.toString();
4934
+ }
4935
+ /**
4936
+ Use Math.random to generate v4 RFC4122 compliant uuid
4937
+ */
4938
+ function uuidv4() {
4939
+ const uuid = [];
4940
+ for (let i = 0; i < 32; i++) {
4941
+ const random = (Math.random() * 16) | 0;
4942
+ if (i === 8 || i === 12 || i === 16 || i === 20) {
4943
+ uuid.push('-');
4944
+ }
4945
+ uuid.push((i === 12 ? 4 : i === 16 ? (random & 3) | 8 : random).toString(16));
4946
+ }
4947
+ return uuid.join('');
4948
+ }
4949
+
4950
+ const IdempotencyKey = 'Idempotency-Key';
4908
4951
  function buildLuvioOverrideForDraftAdapters(luvio, handler, extractTargetIdFromCacheKey, options = {}) {
4909
4952
  // override this to create and enqueue a new draft action, and return synthetic response
4910
4953
  const dispatchResourceRequest = async function (resourceRequest, _context) {
4911
- const { data } = await handler.enqueue(resourceRequest).catch((err) => {
4954
+ const resourceRequestCopy = clone$1(resourceRequest);
4955
+ resourceRequestCopy.headers = resourceRequestCopy.headers || {};
4956
+ resourceRequestCopy.headers[IdempotencyKey] = uuidv4();
4957
+ const { data } = await handler.enqueue(resourceRequestCopy).catch((err) => {
4912
4958
  throw transformErrorToDraftSynthesisError(err);
4913
4959
  });
4914
4960
  if (data === undefined) {
@@ -5000,30 +5046,6 @@ async function clearDraftIdSegment(durableStore) {
5000
5046
  }
5001
5047
  }
5002
5048
 
5003
- /**
5004
- * Generates a time-ordered, unique id to associate with a DraftAction. Ensures
5005
- * no collisions with existing draft action IDs.
5006
- */
5007
- function generateUniqueDraftActionId(existingIds) {
5008
- // new id in milliseconds with some extra digits for collisions
5009
- let newId = new Date().getTime() * 100;
5010
- const existingAsNumbers = existingIds
5011
- .map((id) => parseInt(id, 10))
5012
- .filter((parsed) => !isNaN(parsed));
5013
- let counter = 0;
5014
- while (existingAsNumbers.includes(newId)) {
5015
- newId += 1;
5016
- counter += 1;
5017
- // if the counter is 100+ then somehow this method has been called 100
5018
- // times in one millisecond
5019
- if (counter >= 100) {
5020
- // eslint-disable-next-line @salesforce/lds/no-error-in-production
5021
- throw new Error('Unable to generate unique new draft ID');
5022
- }
5023
- }
5024
- return newId.toString();
5025
- }
5026
-
5027
5049
  var CustomActionResultType;
5028
5050
  (function (CustomActionResultType) {
5029
5051
  CustomActionResultType["SUCCESS"] = "SUCCESS";
@@ -16111,4 +16133,4 @@ register({
16111
16133
  });
16112
16134
 
16113
16135
  export { getRuntime, registerReportObserver, reportGraphqlQueryParseError };
16114
- // version: 1.160.0-ff4890744
16136
+ // version: 1.160.1-fa935e9ee