dexie-cloud-addon 4.0.1-beta.31 → 4.0.1-beta.32

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.
@@ -155,7 +155,8 @@
155
155
  catch (_a) { }
156
156
 
157
157
  const swHolder = {};
158
- const swContainer = typeof self !== undefined && self.document && navigator.serviceWorker; // self.document is to verify we're not the SW ourself
158
+ const swContainer = typeof self !== 'undefined' && self.document && // self.document is to verify we're not the SW ourself
159
+ typeof navigator !== 'undefined' && navigator.serviceWorker;
159
160
  if (swContainer)
160
161
  swContainer.ready.then((registration) => (swHolder.registration = registration));
161
162
  if (typeof self !== 'undefined' && 'clients' in self && !self.document) {
@@ -167,6 +168,12 @@
167
168
  }
168
169
  });
169
170
  }
171
+ /** This class is a fallback for browsers that lacks BroadcastChannel but have
172
+ * service workers (which is Safari versions 11.1 through 15.3).
173
+ * Safari 15.4 with BroadcastChannel was released on 2022-03-14.
174
+ * We might be able to remove this class in a near future as Safari < 15.4 is
175
+ * already very low in market share as of 2023-03-10.
176
+ */
170
177
  class SWBroadcastChannel {
171
178
  constructor(name) {
172
179
  this.name = name;
@@ -1936,8 +1943,22 @@
1936
1943
 
1937
1944
  function randomString$1(bytes) {
1938
1945
  const buf = new Uint8Array(bytes);
1939
- crypto.getRandomValues(buf);
1940
- return btoa(String.fromCharCode.apply(null, buf));
1946
+ if (typeof crypto !== 'undefined') {
1947
+ crypto.getRandomValues(buf);
1948
+ }
1949
+ else {
1950
+ for (let i = 0; i < bytes; i++)
1951
+ buf[i] = Math.floor(Math.random() * 256);
1952
+ }
1953
+ if (typeof Buffer !== 'undefined' && Buffer.from) {
1954
+ return Buffer.from(buf).toString('base64');
1955
+ }
1956
+ else if (typeof btoa !== 'undefined') {
1957
+ return btoa(String.fromCharCode.apply(null, buf));
1958
+ }
1959
+ else {
1960
+ throw new Error('No btoa or Buffer available');
1961
+ }
1941
1962
  }
1942
1963
 
1943
1964
  function assert(b) {
@@ -3228,9 +3249,12 @@
3228
3249
  This function relies initially on navigator.onLine but then uses online and offline events
3229
3250
  which seem to be more reliable.
3230
3251
  */
3231
- let isOnline = navigator.onLine;
3232
- self.addEventListener('online', () => isOnline = true);
3233
- self.addEventListener('offline', () => isOnline = false);
3252
+ let isOnline = false;
3253
+ if (typeof self !== 'undefined' && typeof navigator !== 'undefined') {
3254
+ isOnline = navigator.onLine;
3255
+ self.addEventListener('online', () => isOnline = true);
3256
+ self.addEventListener('offline', () => isOnline = false);
3257
+ }
3234
3258
 
3235
3259
  function updateBaseRevs(db, schema, latestRevisions, serverRev) {
3236
3260
  return __awaiter(this, void 0, void 0, function* () {
@@ -5920,7 +5944,7 @@
5920
5944
  currentUserEmitter.next(UNAUTHORIZED_USER);
5921
5945
  });
5922
5946
  dexie.cloud = {
5923
- version: '4.0.1-beta.31',
5947
+ version: '4.0.1-beta.32',
5924
5948
  options: Object.assign({}, DEFAULT_OPTIONS),
5925
5949
  schema: null,
5926
5950
  get currentUserId() {
@@ -6175,7 +6199,7 @@
6175
6199
  });
6176
6200
  }
6177
6201
  }
6178
- dexieCloud.version = '4.0.1-beta.31';
6202
+ dexieCloud.version = '4.0.1-beta.32';
6179
6203
  Dexie__default["default"].Cloud = dexieCloud;
6180
6204
 
6181
6205
  // In case the SW lives for a while, let it reuse already opened connections: