@transitive-sdk/utils-web 0.12.2 → 0.12.4

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 (2) hide show
  1. package/dist/utils-web.js +19 -12
  2. package/package.json +1 -1
package/dist/utils-web.js CHANGED
@@ -374,7 +374,11 @@ var require_common = __commonJS({
374
374
  callback && callback(count);
375
375
  }, delay);
376
376
  };
377
- var getRandomId = () => Math.random().toString(36).slice(2);
377
+ var getRandomId = (bytes = 6) => {
378
+ const buffer = new Uint8Array(bytes);
379
+ crypto.getRandomValues(buffer);
380
+ return buffer.reduce((memo, i) => memo + i.toString(36), "");
381
+ };
378
382
  var versionCompare = (a, b) => semverCompare(semverMinVersion(a), semverMinVersion(b));
379
383
  var mergeVersions2 = (versionsObject, subTopic = void 0, options = {}) => {
380
384
  if (!versionsObject) {
@@ -649,7 +653,8 @@ var require_MqttSync = __commonJS({
649
653
  isSubTopicOf,
650
654
  versionCompare,
651
655
  encodeTopicElement,
652
- visitAncestor
656
+ visitAncestor,
657
+ getRandomId
653
658
  } = require_common();
654
659
  var { DataCache } = require_DataCache();
655
660
  var log2 = getLogger2("MqttSync");
@@ -724,25 +729,27 @@ var require_MqttSync = __commonJS({
724
729
  if (this.heartbeats == 1 && !migrate && onReady)
725
730
  onReady();
726
731
  this.heartbeats++;
727
- } else if (packet.retain || ignoreRetain) {
732
+ } else {
733
+ const json = mqttParsePayload(payload);
728
734
  let path = topicToPath2(topic);
729
735
  log2.debug("processing message", topic, path);
730
736
  if (sliceTopic) {
731
737
  path = path.slice(sliceTopic);
732
738
  topic = pathToTopic2(path);
733
739
  }
734
- const json = mqttParsePayload(payload);
735
740
  if (this.rpcHandlers[topic]) {
736
741
  this.handleRPCRequest(topic, json);
737
742
  } else if (this.rpcCallbacks[topic]) {
738
743
  this.handleRPCResponse(topic, json);
739
- } else if (this.isPublished(topic)) {
740
- this.publishedMessages.updateFromArray([...path, specialKey], json);
741
- this.data.update(topic, json, { external: true });
742
- } else if (this.isSubscribed(topic)) {
743
- log2.debug("applying received update", topic);
744
- const changes = this.data.update(topic, json);
745
- onChange && Object.keys(changes).length > 0 && onChange(changes);
744
+ } else if (packet.retain || ignoreRetain) {
745
+ if (this.isPublished(topic)) {
746
+ this.publishedMessages.updateFromArray([...path, specialKey], json);
747
+ this.data.update(topic, json, { external: true });
748
+ } else if (this.isSubscribed(topic)) {
749
+ log2.debug("applying received update", topic);
750
+ const changes = this.data.update(topic, json);
751
+ onChange && Object.keys(changes).length > 0 && onChange(changes);
752
+ }
746
753
  }
747
754
  }
748
755
  });
@@ -1157,7 +1164,7 @@ var require_MqttSync = __commonJS({
1157
1164
  * See the note about namespaces in `register`.
1158
1165
  */
1159
1166
  call(command, args, callback = void 0) {
1160
- const id = crypto.randomUUID();
1167
+ const id = getRandomId();
1161
1168
  const responseTopic = `${command}/response/${id}`;
1162
1169
  this.mqtt.subscribe(responseTopic, { rap: true, qos: 2 }, (err, granted) => {
1163
1170
  if (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/utils-web",
3
- "version": "0.12.2",
3
+ "version": "0.12.4",
4
4
  "description": "Web utils for the Transitive framework",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "repository": {