dexie-cloud-addon 4.0.0-beta.13 → 4.0.0-beta.16

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 (45) hide show
  1. package/dist/modern/dexie-cloud-addon.js +154 -49
  2. package/dist/modern/dexie-cloud-addon.js.map +1 -1
  3. package/dist/modern/dexie-cloud-addon.min.js +1 -1
  4. package/dist/modern/dexie-cloud-addon.min.js.map +1 -1
  5. package/dist/modern/service-worker.js +152 -46
  6. package/dist/modern/service-worker.js.map +1 -1
  7. package/dist/modern/service-worker.min.js +1 -1
  8. package/dist/modern/service-worker.min.js.map +1 -1
  9. package/dist/module-es5/dexie-cloud-addon.js +109 -45
  10. package/dist/module-es5/dexie-cloud-addon.js.map +1 -1
  11. package/dist/module-es5/dexie-cloud-addon.min.js +1 -1
  12. package/dist/module-es5/dexie-cloud-addon.min.js.map +1 -1
  13. package/dist/types/DexieCloudAPI.d.ts +4 -1
  14. package/dist/types/DexieCloudEntity.d.ts +8 -0
  15. package/dist/types/Invite.d.ts +1 -1
  16. package/dist/types/WSObservable.d.ts +1 -0
  17. package/dist/types/WebSocketStatus.d.ts +1 -0
  18. package/dist/types/createMyMembersObservable.d.ts +14 -0
  19. package/dist/types/currentUserObservable.d.ts +3 -0
  20. package/dist/types/dexie-cloud-client.d.ts +1 -0
  21. package/dist/types/getGlobalRolesObservable.d.ts +5 -0
  22. package/dist/types/getInvitesObservable.d.ts +1 -1
  23. package/dist/types/helpers/BroadcastedLocalEvent.d.ts +8 -0
  24. package/dist/types/helpers/visibleState.d.ts +1 -0
  25. package/dist/types/permissionsLookup.d.ts +9 -0
  26. package/dist/types/permissionsLookupObservable.d.ts +14 -0
  27. package/dist/types/sync/globalizePrivateIds.d.ts +4 -0
  28. package/dist/types/sync/syncServerToClientOnly.d.ts +3 -0
  29. package/dist/types/types/CloudConnectionStatus.d.ts +0 -0
  30. package/dist/types/types/ConnectionStatus.d.ts +0 -0
  31. package/dist/types/types/LoginState.d.ts +41 -0
  32. package/dist/types/types/SyncConnectionStatus.d.ts +1 -0
  33. package/dist/types/types/SyncFlowStatus.d.ts +6 -0
  34. package/dist/types/types/SyncStatus.d.ts +6 -0
  35. package/dist/umd/dexie-cloud-addon.js +129 -64
  36. package/dist/umd/dexie-cloud-addon.js.map +1 -1
  37. package/dist/umd/dexie-cloud-addon.min.js +1 -1
  38. package/dist/umd/dexie-cloud-addon.min.js.map +1 -1
  39. package/dist/umd/service-worker.js +175 -69
  40. package/dist/umd/service-worker.js.map +1 -1
  41. package/dist/umd/service-worker.min.js +1 -1
  42. package/dist/umd/service-worker.min.js.map +1 -1
  43. package/dist/umd-modern/dexie-cloud-addon.js +172 -66
  44. package/dist/umd-modern/dexie-cloud-addon.js.map +1 -1
  45. package/package.json +5 -3
@@ -440,10 +440,12 @@ var timeoutProvider = {
440
440
  for (var _i = 0; _i < arguments.length; _i++) {
441
441
  args[_i] = arguments[_i];
442
442
  }
443
- return (setTimeout).apply(void 0, __spreadArray([], __read(args)));
443
+ var delegate = timeoutProvider.delegate;
444
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setTimeout) || setTimeout).apply(void 0, __spreadArray([], __read(args)));
444
445
  },
445
446
  clearTimeout: function (handle) {
446
- return (clearTimeout)(handle);
447
+ var delegate = timeoutProvider.delegate;
448
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
447
449
  },
448
450
  delegate: undefined,
449
451
  };
@@ -458,11 +460,33 @@ function reportUnhandledError(err) {
458
460
 
459
461
  function noop() { }
460
462
 
463
+ var COMPLETE_NOTIFICATION = (function () { return createNotification('C', undefined, undefined); })();
464
+ function errorNotification(error) {
465
+ return createNotification('E', undefined, error);
466
+ }
467
+ function nextNotification(value) {
468
+ return createNotification('N', value, undefined);
469
+ }
470
+ function createNotification(kind, value, error) {
471
+ return {
472
+ kind: kind,
473
+ value: value,
474
+ error: error,
475
+ };
476
+ }
477
+
478
+ var context = null;
461
479
  function errorContext(cb) {
462
480
  {
463
481
  cb();
464
482
  }
465
483
  }
484
+ function captureError(err) {
485
+ if (config.useDeprecatedSynchronousErrorHandling && context) {
486
+ context.errorThrown = true;
487
+ context.error = err;
488
+ }
489
+ }
466
490
 
467
491
  var Subscriber = (function (_super) {
468
492
  __extends(Subscriber, _super);
@@ -484,20 +508,26 @@ var Subscriber = (function (_super) {
484
508
  return new SafeSubscriber(next, error, complete);
485
509
  };
486
510
  Subscriber.prototype.next = function (value) {
487
- if (this.isStopped) ;
511
+ if (this.isStopped) {
512
+ handleStoppedNotification(nextNotification(value), this);
513
+ }
488
514
  else {
489
515
  this._next(value);
490
516
  }
491
517
  };
492
518
  Subscriber.prototype.error = function (err) {
493
- if (this.isStopped) ;
519
+ if (this.isStopped) {
520
+ handleStoppedNotification(errorNotification(err), this);
521
+ }
494
522
  else {
495
523
  this.isStopped = true;
496
524
  this._error(err);
497
525
  }
498
526
  };
499
527
  Subscriber.prototype.complete = function () {
500
- if (this.isStopped) ;
528
+ if (this.isStopped) {
529
+ handleStoppedNotification(COMPLETE_NOTIFICATION, this);
530
+ }
501
531
  else {
502
532
  this.isStopped = true;
503
533
  this._complete();
@@ -572,7 +602,10 @@ function wrapForErrorHandling(handler, instance) {
572
602
  handler.apply(void 0, __spreadArray([], __read(args)));
573
603
  }
574
604
  catch (err) {
575
- {
605
+ if (config.useDeprecatedSynchronousErrorHandling) {
606
+ captureError(err);
607
+ }
608
+ else {
576
609
  reportUnhandledError(err);
577
610
  }
578
611
  }
@@ -581,6 +614,10 @@ function wrapForErrorHandling(handler, instance) {
581
614
  function defaultErrorHandler(err) {
582
615
  throw err;
583
616
  }
617
+ function handleStoppedNotification(notification, subscriber) {
618
+ var onStoppedNotification = config.onStoppedNotification;
619
+ onStoppedNotification && timeoutProvider.setTimeout(function () { return onStoppedNotification(notification, subscriber); });
620
+ }
584
621
  var EMPTY_OBSERVER = {
585
622
  closed: true,
586
623
  next: noop,
@@ -956,10 +993,12 @@ var intervalProvider = {
956
993
  for (var _i = 0; _i < arguments.length; _i++) {
957
994
  args[_i] = arguments[_i];
958
995
  }
959
- return (setInterval).apply(void 0, __spreadArray([], __read(args)));
996
+ var delegate = intervalProvider.delegate;
997
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.setInterval) || setInterval).apply(void 0, __spreadArray([], __read(args)));
960
998
  },
961
999
  clearInterval: function (handle) {
962
- return (clearInterval)(handle);
1000
+ var delegate = intervalProvider.delegate;
1001
+ return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearInterval) || clearInterval)(handle);
963
1002
  },
964
1003
  delegate: undefined,
965
1004
  };
@@ -1048,7 +1087,7 @@ var AsyncAction = (function (_super) {
1048
1087
 
1049
1088
  var dateTimestampProvider = {
1050
1089
  now: function () {
1051
- return (Date).now();
1090
+ return (dateTimestampProvider.delegate || Date).now();
1052
1091
  },
1053
1092
  delegate: undefined,
1054
1093
  };
@@ -2167,15 +2206,18 @@ function getTablesToSyncify(db, syncState) {
2167
2206
  }
2168
2207
 
2169
2208
  function interactWithUser(userInteraction, req) {
2209
+ let done = false;
2170
2210
  return new Promise((resolve, reject) => {
2171
2211
  const interactionProps = {
2172
2212
  ...req,
2173
2213
  onSubmit: (res) => {
2174
2214
  userInteraction.next(undefined);
2215
+ done = true;
2175
2216
  resolve(res);
2176
2217
  },
2177
2218
  onCancel: () => {
2178
2219
  userInteraction.next(undefined);
2220
+ done = true;
2179
2221
  reject(new Dexie.AbortError("User cancelled"));
2180
2222
  },
2181
2223
  };
@@ -4703,7 +4745,7 @@ async function performInitialSync(db, cloudOptions, cloudSchema) {
4703
4745
  console.debug("Done initial sync");
4704
4746
  }
4705
4747
 
4706
- const USER_INACTIVITY_TIMEOUT = 300000; // 300_000;
4748
+ const USER_INACTIVITY_TIMEOUT = 180000; // 3 minutes
4707
4749
  const INACTIVE_WAIT_TIME = 20000;
4708
4750
  // This observable will be emitted to later down....
4709
4751
  const userIsActive = new BehaviorSubject(true);
@@ -4717,9 +4759,13 @@ const userIsActive = new BehaviorSubject(true);
4717
4759
  // for just a short time.
4718
4760
  const userIsReallyActive = new BehaviorSubject(true);
4719
4761
  userIsActive
4720
- .pipe(switchMap((isActive) => isActive
4721
- ? of(true)
4722
- : of(false).pipe(delay(INACTIVE_WAIT_TIME))), distinctUntilChanged())
4762
+ .pipe(switchMap((isActive) => {
4763
+ //console.debug('SyncStatus: DUBB: isActive changed to', isActive);
4764
+ return isActive
4765
+ ? of(true)
4766
+ : of(false).pipe(delay(INACTIVE_WAIT_TIME))
4767
+ ;
4768
+ }), distinctUntilChanged())
4723
4769
  .subscribe(userIsReallyActive);
4724
4770
  //
4725
4771
  // First create some corner-stone observables to build the flow on
@@ -4734,7 +4780,7 @@ const documentBecomesHidden = visibilityStateIsChanged.pipe(filter(() => documen
4734
4780
  const documentBecomesVisible = visibilityStateIsChanged.pipe(filter(() => document.visibilityState === 'visible'));
4735
4781
  // Any of various user-activity-related events happen:
4736
4782
  const userDoesSomething = typeof window !== 'undefined'
4737
- ? merge(documentBecomesVisible, fromEvent(window, 'mousemove'), fromEvent(window, 'keydown'), fromEvent(window, 'wheel'), fromEvent(window, 'touchmove'))
4783
+ ? merge(documentBecomesVisible, fromEvent(window, 'mousedown'), fromEvent(window, 'mousemove'), fromEvent(window, 'keydown'), fromEvent(window, 'wheel'), fromEvent(window, 'touchmove'))
4738
4784
  : of({});
4739
4785
  if (typeof document !== 'undefined') {
4740
4786
  //
@@ -4785,6 +4831,7 @@ class WSConnection extends Subscription$1 {
4785
4831
  constructor(databaseUrl, rev, realmSetHash, clientIdentity, token, tokenExpiration, subscriber, messageProducer, webSocketStatus) {
4786
4832
  super(() => this.teardown());
4787
4833
  this.id = ++counter;
4834
+ this.reconnecting = false;
4788
4835
  console.debug('New WebSocket Connection', this.id, token ? 'authorized' : 'unauthorized');
4789
4836
  this.databaseUrl = databaseUrl;
4790
4837
  this.rev = rev;
@@ -4804,7 +4851,7 @@ class WSConnection extends Subscription$1 {
4804
4851
  this.disconnect();
4805
4852
  }
4806
4853
  disconnect() {
4807
- this.webSocketStatus.next("disconnected");
4854
+ this.webSocketStatus.next('disconnected');
4808
4855
  if (this.pinger) {
4809
4856
  clearInterval(this.pinger);
4810
4857
  this.pinger = null;
@@ -4822,11 +4869,18 @@ class WSConnection extends Subscription$1 {
4822
4869
  }
4823
4870
  }
4824
4871
  reconnect() {
4825
- this.disconnect();
4826
- this.connect();
4872
+ if (this.reconnecting)
4873
+ return;
4874
+ this.reconnecting = true;
4875
+ try {
4876
+ this.disconnect();
4877
+ }
4878
+ catch { }
4879
+ this.connect()
4880
+ .catch(() => { })
4881
+ .then(() => (this.reconnecting = false)); // finally()
4827
4882
  }
4828
4883
  async connect() {
4829
- this.webSocketStatus.next("connecting");
4830
4884
  this.lastServerActivity = new Date();
4831
4885
  if (this.pauseUntil && this.pauseUntil > new Date()) {
4832
4886
  console.debug('WS not reconnecting just yet', {
@@ -4841,12 +4895,14 @@ class WSConnection extends Subscription$1 {
4841
4895
  if (!this.databaseUrl)
4842
4896
  throw new Error(`Cannot connect without a database URL`);
4843
4897
  if (this.closed) {
4898
+ //console.debug('SyncStatus: DUBB: Ooops it was closed!');
4844
4899
  return;
4845
4900
  }
4846
4901
  if (this.tokenExpiration && this.tokenExpiration < new Date()) {
4847
4902
  this.subscriber.error(new TokenExpiredError()); // Will be handled in connectWebSocket.ts.
4848
4903
  return;
4849
4904
  }
4905
+ this.webSocketStatus.next('connecting');
4850
4906
  this.pinger = setInterval(async () => {
4851
4907
  if (this.closed) {
4852
4908
  console.debug('pinger check', this.id, 'CLOSED.');
@@ -4893,7 +4949,7 @@ class WSConnection extends Subscription$1 {
4893
4949
  const searchParams = new URLSearchParams();
4894
4950
  if (this.subscriber.closed)
4895
4951
  return;
4896
- searchParams.set('v', "2");
4952
+ searchParams.set('v', '2');
4897
4953
  searchParams.set('rev', this.rev);
4898
4954
  searchParams.set('realmsHash', this.realmSetHash);
4899
4955
  searchParams.set('clientId', this.clientIdentity);
@@ -4932,23 +4988,30 @@ class WSConnection extends Subscription$1 {
4932
4988
  }
4933
4989
  };
4934
4990
  try {
4991
+ let everConnected = false;
4935
4992
  await new Promise((resolve, reject) => {
4936
4993
  ws.onopen = (event) => {
4937
4994
  console.debug('dexie-cloud WebSocket onopen');
4995
+ everConnected = true;
4938
4996
  resolve(null);
4939
4997
  };
4940
4998
  ws.onerror = (event) => {
4941
- const error = event.error || new Error('WebSocket Error');
4942
- this.disconnect();
4943
- this.subscriber.error(error);
4944
- this.webSocketStatus.next("error");
4945
- reject(error);
4999
+ if (!everConnected) {
5000
+ const error = event.error || new Error('WebSocket Error');
5001
+ this.subscriber.error(error);
5002
+ this.webSocketStatus.next('error');
5003
+ reject(error);
5004
+ }
5005
+ else {
5006
+ this.reconnect();
5007
+ }
4946
5008
  };
4947
5009
  });
4948
- this.messageProducerSubscription = this.messageProducer.subscribe(msg => {
5010
+ this.messageProducerSubscription = this.messageProducer.subscribe((msg) => {
4949
5011
  if (!this.closed) {
4950
- if (msg.type === 'ready' && this.webSocketStatus.value !== 'connected') {
4951
- this.webSocketStatus.next("connected");
5012
+ if (msg.type === 'ready' &&
5013
+ this.webSocketStatus.value !== 'connected') {
5014
+ this.webSocketStatus.next('connected');
4952
5015
  }
4953
5016
  this.ws?.send(TSON.stringify(msg));
4954
5017
  }
@@ -4985,9 +5048,9 @@ function connectWebSocket(db) {
4985
5048
  rev: syncState.serverRevision,
4986
5049
  })));
4987
5050
  function createObservable() {
4988
- return db.cloud.persistedSyncState.pipe(filter(syncState => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
5051
+ return db.cloud.persistedSyncState.pipe(filter((syncState) => syncState?.serverRevision), // Don't connect before there's no initial sync performed.
4989
5052
  take(1), // Don't continue waking up whenever syncState change
4990
- switchMap((syncState) => db.cloud.currentUser.pipe(map(userLogin => [userLogin, syncState]))), switchMap(([userLogin, syncState]) => userIsReallyActive.pipe(map((isActive) => [isActive ? userLogin : null, syncState]))), switchMap(async ([userLogin, syncState]) => [userLogin, await computeRealmSetHash(syncState)]), switchMap(([userLogin, realmSetHash]) =>
5053
+ switchMap((syncState) => db.cloud.currentUser.pipe(map((userLogin) => [userLogin, syncState]))), switchMap(([userLogin, syncState]) => userIsReallyActive.pipe(map((isActive) => [isActive ? userLogin : null, syncState]))), switchMap(async ([userLogin, syncState]) => [userLogin, await computeRealmSetHash(syncState)]), switchMap(([userLogin, realmSetHash]) =>
4991
5054
  // Let server end query changes from last entry of same client-ID and forward.
4992
5055
  // If no new entries, server won't bother the client. If new entries, server sends only those
4993
5056
  // and the baseRev of the last from same client-ID.
@@ -5010,7 +5073,10 @@ function connectWebSocket(db) {
5010
5073
  else {
5011
5074
  return throwError(error);
5012
5075
  }
5013
- }), catchError((error) => from$1(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()))));
5076
+ }), catchError((error) => {
5077
+ db.cloud.webSocketStatus.next("error");
5078
+ return from$1(waitAndReconnectWhenUserDoesSomething(error)).pipe(switchMap(() => createObservable()));
5079
+ }));
5014
5080
  }
5015
5081
  return createObservable().subscribe((msg) => {
5016
5082
  if (msg) {
@@ -5185,7 +5251,7 @@ function verifySchema(db) {
5185
5251
  }
5186
5252
  }
5187
5253
 
5188
- var n,u$1,i$1,t$1,r$1={},f$1=[],e$1=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function c$1(n,l){for(var u in l)n[u]=l[u];return n}function s$1(n){var l=n.parentNode;l&&l.removeChild(n);}function a$1(n,l,u){var i,t,o,r=arguments,f={};for(o in l)"key"==o?i=l[o]:"ref"==o?t=l[o]:f[o]=l[o];if(arguments.length>3)for(u=[u],o=3;o<arguments.length;o++)u.push(r[o]);if(null!=u&&(f.children=u),"function"==typeof n&&null!=n.defaultProps)for(o in n.defaultProps)void 0===f[o]&&(f[o]=n.defaultProps[o]);return v$1(n,f,i,t,null)}function v$1(l,u,i,t,o){var r={type:l,props:u,key:i,ref:t,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++n.__v:o};return null!=n.vnode&&n.vnode(r),r}function y(n){return n.children}function p$1(n,l){this.props=n,this.context=l;}function d$1(n,l){if(null==l)return n.__?d$1(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return "function"==typeof n.type?d$1(n):null}function _(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return _(n)}}function k$1(l){(!l.__d&&(l.__d=!0)&&u$1.push(l)&&!b$1.__r++||t$1!==n.debounceRendering)&&((t$1=n.debounceRendering)||i$1)(b$1);}function b$1(){for(var n;b$1.__r=u$1.length;)n=u$1.sort(function(n,l){return n.__v.__b-l.__v.__b}),u$1=[],n.some(function(n){var l,u,i,t,o,r;n.__d&&(o=(t=(l=n).__v).__e,(r=l.__P)&&(u=[],(i=c$1({},t)).__v=t.__v+1,I(r,t,i,l.__n,void 0!==r.ownerSVGElement,null!=t.__h?[o]:null,u,null==o?d$1(t):o,t.__h),T(u,t),t.__e!=o&&_(t)));});}function m$1(n,l,u,i,t,o,e,c,s,a){var h,p,_,k,b,m,w,A=i&&i.__k||f$1,P=A.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v$1(null,k,null,null,k):Array.isArray(k)?v$1(y,{children:k},null,null,null):k.__b>0?v$1(k.type,k.props,k.key,null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(_=A[h])||_&&k.key==_.key&&k.type===_.type)A[h]=void 0;else for(p=0;p<P;p++){if((_=A[p])&&k.key==_.key&&k.type===_.type){A[p]=void 0;break}_=null;}I(n,k,_=_||r$1,t,o,e,c,s,a),b=k.__e,(p=k.ref)&&_.ref!=p&&(w||(w=[]),_.ref&&w.push(_.ref,null,k),w.push(p,k.__c||b,k)),null!=b?(null==m&&(m=b),"function"==typeof k.type&&null!=k.__k&&k.__k===_.__k?k.__d=s=g$1(k,s,n):s=x$1(n,k,_,A,b,s),a||"option"!==u.type?"function"==typeof u.type&&(u.__d=s):n.value=""):s&&_.__e==s&&s.parentNode!=n&&(s=d$1(_));}for(u.__e=m,h=P;h--;)null!=A[h]&&("function"==typeof u.type&&null!=A[h].__e&&A[h].__e==u.__d&&(u.__d=d$1(i,h+1)),L(A[h],A[h]));if(w)for(h=0;h<w.length;h++)z(w[h],w[++h],w[++h]);}function g$1(n,l,u){var i,t;for(i=0;i<n.__k.length;i++)(t=n.__k[i])&&(t.__=n,l="function"==typeof t.type?g$1(t,l,u):x$1(u,t,t,n.__k,t.__e,l));return l}function x$1(n,l,u,i,t,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||t!=o||null==t.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(t),r=null;else {for(f=o,e=0;(f=f.nextSibling)&&e<i.length;e+=2)if(f==t)break n;n.insertBefore(t,o),r=o;}return void 0!==r?r:t.nextSibling}function A(n,l,u,i,t){var o;for(o in u)"children"===o||"key"===o||o in l||C(n,o,null,u[o],i);for(o in l)t&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||C(n,o,l[o],u[o],i);}function P(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||e$1.test(l)?u:u+"px";}function C(n,l,u,i,t){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else {if("string"==typeof i&&(n.style.cssText=i=""),i)for(l in i)u&&l in u||P(n.style,l,"");if(u)for(l in u)i&&u[l]===i[l]||P(n.style,l,u[l]);}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?i||n.addEventListener(l,o?H:$,o):n.removeEventListener(l,o?H:$,o);else if("dangerouslySetInnerHTML"!==l){if(t)l=l.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l));}}function $(l){this.l[l.type+!1](n.event?n.event(l):l);}function H(l){this.l[l.type+!0](n.event?n.event(l):l);}function I(l,u,i,t,o,r,f,e,s){var a,v,h,d,_,k,b,g,w,x,A,P=u.type;if(void 0!==u.constructor)return null;null!=i.__h&&(s=i.__h,e=u.__e=i.__e,u.__h=null,r=[e]),(a=n.__b)&&a(u);try{n:if("function"==typeof P){if(g=u.props,w=(a=P.contextType)&&t[a.__c],x=a?w?w.props.value:a.__:t,i.__c?b=(v=u.__c=i.__c).__=v.__E:("prototype"in P&&P.prototype.render?u.__c=v=new P(g,x):(u.__c=v=new p$1(g,x),v.constructor=P,v.render=M),w&&w.sub(v),v.props=g,v.state||(v.state={}),v.context=x,v.__n=t,h=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=P.getDerivedStateFromProps&&(v.__s==v.state&&(v.__s=c$1({},v.__s)),c$1(v.__s,P.getDerivedStateFromProps(g,v.__s))),d=v.props,_=v.state,h)null==P.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&v.__h.push(v.componentDidMount);else {if(null==P.getDerivedStateFromProps&&g!==d&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(g,x),!v.__e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(g,v.__s,x)||u.__v===i.__v){v.props=g,v.state=v.__s,u.__v!==i.__v&&(v.__d=!1),v.__v=u,u.__e=i.__e,u.__k=i.__k,u.__k.forEach(function(n){n&&(n.__=u);}),v.__h.length&&f.push(v);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(g,v.__s,x),null!=v.componentDidUpdate&&v.__h.push(function(){v.componentDidUpdate(d,_,k);});}v.context=x,v.props=g,v.state=v.__s,(a=n.__r)&&a(u),v.__d=!1,v.__v=u,v.__P=l,a=v.render(v.props,v.state,v.context),v.state=v.__s,null!=v.getChildContext&&(t=c$1(c$1({},t),v.getChildContext())),h||null==v.getSnapshotBeforeUpdate||(k=v.getSnapshotBeforeUpdate(d,_)),A=null!=a&&a.type===y&&null==a.key?a.props.children:a,m$1(l,Array.isArray(A)?A:[A],u,i,t,o,r,f,e,s),v.base=u.__e,u.__h=null,v.__h.length&&f.push(v),b&&(v.__E=v.__=null),v.__e=!1;}else null==r&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=j$1(i.__e,u,i,t,o,r,f,s);(a=n.diffed)&&a(u);}catch(l){u.__v=null,(s||null!=r)&&(u.__e=e,u.__h=!!s,r[r.indexOf(e)]=null),n.__e(l,u,i);}}function T(l,u){n.__c&&n.__c(u,l),l.some(function(u){try{l=u.__h,u.__h=[],l.some(function(n){n.call(u);});}catch(l){n.__e(l,u.__v);}});}function j$1(n,l,u,i,t,o,e,c){var a,v,h,y,p=u.props,d=l.props,_=l.type,k=0;if("svg"===_&&(t=!0),null!=o)for(;k<o.length;k++)if((a=o[k])&&(a===n||(_?a.localName==_:3==a.nodeType))){n=a,o[k]=null;break}if(null==n){if(null===_)return document.createTextNode(d);n=t?document.createElementNS("http://www.w3.org/2000/svg",_):document.createElement(_,d.is&&d),o=null,c=!1;}if(null===_)p===d||c&&n.data===d||(n.data=d);else {if(o=o&&f$1.slice.call(n.childNodes),v=(p=u.props||r$1).dangerouslySetInnerHTML,h=d.dangerouslySetInnerHTML,!c){if(null!=o)for(p={},y=0;y<n.attributes.length;y++)p[n.attributes[y].name]=n.attributes[y].value;(h||v)&&(h&&(v&&h.__html==v.__html||h.__html===n.innerHTML)||(n.innerHTML=h&&h.__html||""));}if(A(n,d,p,t,c),h)l.__k=[];else if(k=l.props.children,m$1(n,Array.isArray(k)?k:[k],l,u,i,t&&"foreignObject"!==_,o,e,n.firstChild,c),null!=o)for(k=o.length;k--;)null!=o[k]&&s$1(o[k]);c||("value"in d&&void 0!==(k=d.value)&&(k!==n.value||"progress"===_&&!k)&&C(n,"value",k,p.value,!1),"checked"in d&&void 0!==(k=d.checked)&&k!==n.checked&&C(n,"checked",k,p.checked,!1));}return n}function z(l,u,i){try{"function"==typeof l?l(u):l.current=u;}catch(l){n.__e(l,i);}}function L(l,u,i){var t,o,r;if(n.unmount&&n.unmount(l),(t=l.ref)&&(t.current&&t.current!==l.__e||z(t,null,u)),i||"function"==typeof l.type||(i=null!=(o=l.__e)),l.__e=l.__d=void 0,null!=(t=l.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount();}catch(l){n.__e(l,u);}t.base=t.__P=null;}if(t=l.__k)for(r=0;r<t.length;r++)t[r]&&L(t[r],u,i);null!=o&&s$1(o);}function M(n,l,u){return this.constructor(n,u)}function N(l,u,i){var t,o,e;n.__&&n.__(l,u),o=(t="function"==typeof i)?null:i&&i.__k||u.__k,e=[],I(u,l=(!t&&i||u).__k=a$1(y,null,[l]),o||r$1,r$1,void 0!==u.ownerSVGElement,!t&&i?[i]:o?null:u.firstChild?f$1.slice.call(u.childNodes):null,e,!t&&i?i:o?o.__e:u.firstChild,t),T(e,l);}n={__e:function(n,l){for(var u,i,t;l=l.__;)if((u=l.__c)&&!u.__)try{if((i=u.constructor)&&null!=i.getDerivedStateFromError&&(u.setState(i.getDerivedStateFromError(n)),t=u.__d),null!=u.componentDidCatch&&(u.componentDidCatch(n),t=u.__d),t)return u.__E=u}catch(l){n=l;}throw n},__v:0},p$1.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=c$1({},this.state),"function"==typeof n&&(n=n(c$1({},u),this.props)),n&&c$1(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),k$1(this));},p$1.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),k$1(this));},p$1.prototype.render=y,u$1=[],i$1="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,b$1.__r=0,0;
5254
+ var n,u$1,i$1,t$1,r$1={},f$1=[],e$1=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function c$1(n,l){for(var u in l)n[u]=l[u];return n}function s$1(n){var l=n.parentNode;l&&l.removeChild(n);}function a$1(n,l,u){var i,t,o,r=arguments,f={};for(o in l)"key"==o?i=l[o]:"ref"==o?t=l[o]:f[o]=l[o];if(arguments.length>3)for(u=[u],o=3;o<arguments.length;o++)u.push(r[o]);if(null!=u&&(f.children=u),"function"==typeof n&&null!=n.defaultProps)for(o in n.defaultProps)void 0===f[o]&&(f[o]=n.defaultProps[o]);return v$1(n,f,i,t,null)}function v$1(l,u,i,t,o){var r={type:l,props:u,key:i,ref:t,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++n.__v:o};return null!=n.vnode&&n.vnode(r),r}function y(n){return n.children}function p$1(n,l){this.props=n,this.context=l;}function d$1(n,l){if(null==l)return n.__?d$1(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return "function"==typeof n.type?d$1(n):null}function _(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return _(n)}}function k$1(l){(!l.__d&&(l.__d=!0)&&u$1.push(l)&&!b$1.__r++||t$1!==n.debounceRendering)&&((t$1=n.debounceRendering)||i$1)(b$1);}function b$1(){for(var n;b$1.__r=u$1.length;)n=u$1.sort(function(n,l){return n.__v.__b-l.__v.__b}),u$1=[],n.some(function(n){var l,u,i,t,o,r;n.__d&&(o=(t=(l=n).__v).__e,(r=l.__P)&&(u=[],(i=c$1({},t)).__v=t.__v+1,I(r,t,i,l.__n,void 0!==r.ownerSVGElement,null!=t.__h?[o]:null,u,null==o?d$1(t):o,t.__h),T(u,t),t.__e!=o&&_(t)));});}function m$1(n,l,u,i,t,o,e,c,s,a){var h,p,_,k,b,m,w,A=i&&i.__k||f$1,P=A.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v$1(null,k,null,null,k):Array.isArray(k)?v$1(y,{children:k},null,null,null):k.__b>0?v$1(k.type,k.props,k.key,null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(_=A[h])||_&&k.key==_.key&&k.type===_.type)A[h]=void 0;else for(p=0;p<P;p++){if((_=A[p])&&k.key==_.key&&k.type===_.type){A[p]=void 0;break}_=null;}I(n,k,_=_||r$1,t,o,e,c,s,a),b=k.__e,(p=k.ref)&&_.ref!=p&&(w||(w=[]),_.ref&&w.push(_.ref,null,k),w.push(p,k.__c||b,k)),null!=b?(null==m&&(m=b),"function"==typeof k.type&&null!=k.__k&&k.__k===_.__k?k.__d=s=g$1(k,s,n):s=x$1(n,k,_,A,b,s),a||"option"!==u.type?"function"==typeof u.type&&(u.__d=s):n.value=""):s&&_.__e==s&&s.parentNode!=n&&(s=d$1(_));}for(u.__e=m,h=P;h--;)null!=A[h]&&("function"==typeof u.type&&null!=A[h].__e&&A[h].__e==u.__d&&(u.__d=d$1(i,h+1)),L(A[h],A[h]));if(w)for(h=0;h<w.length;h++)z(w[h],w[++h],w[++h]);}function g$1(n,l,u){var i,t;for(i=0;i<n.__k.length;i++)(t=n.__k[i])&&(t.__=n,l="function"==typeof t.type?g$1(t,l,u):x$1(u,t,t,n.__k,t.__e,l));return l}function x$1(n,l,u,i,t,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||t!=o||null==t.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(t),r=null;else {for(f=o,e=0;(f=f.nextSibling)&&e<i.length;e+=2)if(f==t)break n;n.insertBefore(t,o),r=o;}return void 0!==r?r:t.nextSibling}function A(n,l,u,i,t){var o;for(o in u)"children"===o||"key"===o||o in l||C(n,o,null,u[o],i);for(o in l)t&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||C(n,o,l[o],u[o],i);}function P(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||e$1.test(l)?u:u+"px";}function C(n,l,u,i,t){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else {if("string"==typeof i&&(n.style.cssText=i=""),i)for(l in i)u&&l in u||P(n.style,l,"");if(u)for(l in u)i&&u[l]===i[l]||P(n.style,l,u[l]);}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?i||n.addEventListener(l,o?H:$,o):n.removeEventListener(l,o?H:$,o);else if("dangerouslySetInnerHTML"!==l){if(t)l=l.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l));}}function $(l){this.l[l.type+!1](n.event?n.event(l):l);}function H(l){this.l[l.type+!0](n.event?n.event(l):l);}function I(l,u,i,t,o,r,f,e,s){var a,v,h,d,_,k,b,g,w,x,A,P=u.type;if(void 0!==u.constructor)return null;null!=i.__h&&(s=i.__h,e=u.__e=i.__e,u.__h=null,r=[e]),(a=n.__b)&&a(u);try{n:if("function"==typeof P){if(g=u.props,w=(a=P.contextType)&&t[a.__c],x=a?w?w.props.value:a.__:t,i.__c?b=(v=u.__c=i.__c).__=v.__E:("prototype"in P&&P.prototype.render?u.__c=v=new P(g,x):(u.__c=v=new p$1(g,x),v.constructor=P,v.render=M),w&&w.sub(v),v.props=g,v.state||(v.state={}),v.context=x,v.__n=t,h=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=P.getDerivedStateFromProps&&(v.__s==v.state&&(v.__s=c$1({},v.__s)),c$1(v.__s,P.getDerivedStateFromProps(g,v.__s))),d=v.props,_=v.state,h)null==P.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&v.__h.push(v.componentDidMount);else {if(null==P.getDerivedStateFromProps&&g!==d&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(g,x),!v.__e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(g,v.__s,x)||u.__v===i.__v){v.props=g,v.state=v.__s,u.__v!==i.__v&&(v.__d=!1),v.__v=u,u.__e=i.__e,u.__k=i.__k,u.__k.forEach(function(n){n&&(n.__=u);}),v.__h.length&&f.push(v);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(g,v.__s,x),null!=v.componentDidUpdate&&v.__h.push(function(){v.componentDidUpdate(d,_,k);});}v.context=x,v.props=g,v.state=v.__s,(a=n.__r)&&a(u),v.__d=!1,v.__v=u,v.__P=l,a=v.render(v.props,v.state,v.context),v.state=v.__s,null!=v.getChildContext&&(t=c$1(c$1({},t),v.getChildContext())),h||null==v.getSnapshotBeforeUpdate||(k=v.getSnapshotBeforeUpdate(d,_)),A=null!=a&&a.type===y&&null==a.key?a.props.children:a,m$1(l,Array.isArray(A)?A:[A],u,i,t,o,r,f,e,s),v.base=u.__e,u.__h=null,v.__h.length&&f.push(v),b&&(v.__E=v.__=null),v.__e=!1;}else null==r&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=j$1(i.__e,u,i,t,o,r,f,s);(a=n.diffed)&&a(u);}catch(l){u.__v=null,(s||null!=r)&&(u.__e=e,u.__h=!!s,r[r.indexOf(e)]=null),n.__e(l,u,i);}}function T(l,u){n.__c&&n.__c(u,l),l.some(function(u){try{l=u.__h,u.__h=[],l.some(function(n){n.call(u);});}catch(l){n.__e(l,u.__v);}});}function j$1(n,l,u,i,t,o,e,c){var a,v,h,y,p=u.props,d=l.props,_=l.type,k=0;if("svg"===_&&(t=!0),null!=o)for(;k<o.length;k++)if((a=o[k])&&(a===n||(_?a.localName==_:3==a.nodeType))){n=a,o[k]=null;break}if(null==n){if(null===_)return document.createTextNode(d);n=t?document.createElementNS("http://www.w3.org/2000/svg",_):document.createElement(_,d.is&&d),o=null,c=!1;}if(null===_)p===d||c&&n.data===d||(n.data=d);else {if(o=o&&f$1.slice.call(n.childNodes),v=(p=u.props||r$1).dangerouslySetInnerHTML,h=d.dangerouslySetInnerHTML,!c){if(null!=o)for(p={},y=0;y<n.attributes.length;y++)p[n.attributes[y].name]=n.attributes[y].value;(h||v)&&(h&&(v&&h.__html==v.__html||h.__html===n.innerHTML)||(n.innerHTML=h&&h.__html||""));}if(A(n,d,p,t,c),h)l.__k=[];else if(k=l.props.children,m$1(n,Array.isArray(k)?k:[k],l,u,i,t&&"foreignObject"!==_,o,e,n.firstChild,c),null!=o)for(k=o.length;k--;)null!=o[k]&&s$1(o[k]);c||("value"in d&&void 0!==(k=d.value)&&(k!==n.value||"progress"===_&&!k)&&C(n,"value",k,p.value,!1),"checked"in d&&void 0!==(k=d.checked)&&k!==n.checked&&C(n,"checked",k,p.checked,!1));}return n}function z(l,u,i){try{"function"==typeof l?l(u):l.current=u;}catch(l){n.__e(l,i);}}function L(l,u,i){var t,o,r;if(n.unmount&&n.unmount(l),(t=l.ref)&&(t.current&&t.current!==l.__e||z(t,null,u)),i||"function"==typeof l.type||(i=null!=(o=l.__e)),l.__e=l.__d=void 0,null!=(t=l.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount();}catch(l){n.__e(l,u);}t.base=t.__P=null;}if(t=l.__k)for(r=0;r<t.length;r++)t[r]&&L(t[r],u,i);null!=o&&s$1(o);}function M(n,l,u){return this.constructor(n,u)}function N(l,u,i){var t,o,e;n.__&&n.__(l,u),o=(t="function"==typeof i)?null:i&&i.__k||u.__k,e=[],I(u,l=(!t&&i||u).__k=a$1(y,null,[l]),o||r$1,r$1,void 0!==u.ownerSVGElement,!t&&i?[i]:o?null:u.firstChild?f$1.slice.call(u.childNodes):null,e,!t&&i?i:o?o.__e:u.firstChild,t),T(e,l);}n={__e:function(n,l){for(var u,i,t;l=l.__;)if((u=l.__c)&&!u.__)try{if((i=u.constructor)&&null!=i.getDerivedStateFromError&&(u.setState(i.getDerivedStateFromError(n)),t=u.__d),null!=u.componentDidCatch&&(u.componentDidCatch(n),t=u.__d),t)return u.__E=u}catch(l){n=l;}throw n},__v:0},p$1.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=c$1({},this.state),"function"==typeof n&&(n=n(c$1({},u),this.props)),n&&c$1(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),k$1(this));},p$1.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),k$1(this));},p$1.prototype.render=y,u$1=[],i$1="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,b$1.__r=0;
5189
5255
 
5190
5256
  const Styles = {
5191
5257
  Error: {
@@ -5434,6 +5500,21 @@ function createSharedValueObservable(o, defaultValue) {
5434
5500
  return rv;
5435
5501
  }
5436
5502
 
5503
+ const getGlobalRolesObservable = associate((db) => {
5504
+ return createSharedValueObservable(liveQuery(() => db.roles
5505
+ .where({ realmId: 'rlm-public' })
5506
+ .toArray()
5507
+ .then((roles) => {
5508
+ const rv = {};
5509
+ for (const role of roles
5510
+ .slice()
5511
+ .sort((a, b) => (a.sortOrder || 0) - (b.sortOrder || 0))) {
5512
+ rv[role.name] = role;
5513
+ }
5514
+ return rv;
5515
+ })), {});
5516
+ });
5517
+
5437
5518
  const getCurrentUserEmitter = associate((db) => new BehaviorSubject(UNAUTHORIZED_USER));
5438
5519
 
5439
5520
  const getInternalAccessControlObservable = associate((db) => {
@@ -5535,18 +5616,38 @@ function mergePermissions(...permissions) {
5535
5616
  }
5536
5617
 
5537
5618
  const getPermissionsLookupObservable = associate((db) => {
5538
- const o = getInternalAccessControlObservable(db._novip);
5539
- return mapValueObservable(o, ({ selfMembers, realms, userId }) => {
5619
+ const o = createSharedValueObservable(combineLatest([
5620
+ getInternalAccessControlObservable(db._novip),
5621
+ getGlobalRolesObservable(db._novip),
5622
+ ]).pipe(map(([{ selfMembers, realms, userId }, globalRoles]) => ({
5623
+ selfMembers,
5624
+ realms,
5625
+ userId,
5626
+ globalRoles,
5627
+ }))), {
5628
+ selfMembers: [],
5629
+ realms: [],
5630
+ userId: UNAUTHORIZED_USER.userId,
5631
+ globalRoles: {},
5632
+ });
5633
+ return mapValueObservable(o, ({ selfMembers, realms, userId, globalRoles }) => {
5540
5634
  const rv = realms
5541
- .map((realm) => ({
5542
- ...realm,
5543
- permissions: realm.owner === userId
5544
- ? { manage: '*' }
5545
- : mergePermissions(...selfMembers
5546
- .filter((m) => m.realmId === realm.realmId)
5547
- .map((m) => m.permissions)
5548
- .filter((p) => p)),
5549
- }))
5635
+ .map((realm) => {
5636
+ const selfRealmMembers = selfMembers.filter((m) => m.realmId === realm.realmId);
5637
+ const directPermissionSets = selfRealmMembers
5638
+ .map((m) => m.permissions)
5639
+ .filter((p) => p);
5640
+ const rolePermissionSets = flatten(selfRealmMembers.map((m) => m.roles).filter((roleName) => roleName))
5641
+ .map((role) => globalRoles[role])
5642
+ .filter((role) => role)
5643
+ .map((role) => role.permissions);
5644
+ return {
5645
+ ...realm,
5646
+ permissions: realm.owner === userId
5647
+ ? { manage: '*' }
5648
+ : mergePermissions(...directPermissionSets, ...rolePermissionSets),
5649
+ };
5650
+ })
5550
5651
  .reduce((p, c) => ({ ...p, [c.realmId]: c }), {
5551
5652
  [userId]: {
5552
5653
  realmId: userId,
@@ -5630,7 +5731,7 @@ function permissions(dexie, obj, tableName) {
5630
5731
  const realm = permissionsLookup[realmId || dexie.cloud.currentUserId];
5631
5732
  if (!realm)
5632
5733
  return new PermissionChecker({}, tableName, !owner || owner === dexie.cloud.currentUserId);
5633
- return new PermissionChecker(realm.permissions, tableName, !owner || owner === dexie.cloud.currentUserId);
5734
+ return new PermissionChecker(realm.permissions, tableName, realmId === dexie.cloud.currentUserId || owner === dexie.cloud.currentUserId);
5634
5735
  };
5635
5736
  const o = source.pipe(map(mapper));
5636
5737
  o.getValue = () => mapper(source.getValue());
@@ -5659,6 +5760,7 @@ function dexieCloud(dexie) {
5659
5760
  //
5660
5761
  const currentUserEmitter = getCurrentUserEmitter(dexie);
5661
5762
  const subscriptions = [];
5763
+ let configuredProgramatically = false;
5662
5764
  // local sync worker - used when there's no service worker.
5663
5765
  let localSyncWorker = null;
5664
5766
  dexie.on('ready', async (dexie) => {
@@ -5685,7 +5787,7 @@ function dexieCloud(dexie) {
5685
5787
  currentUserEmitter.next(UNAUTHORIZED_USER);
5686
5788
  });
5687
5789
  dexie.cloud = {
5688
- version: '4.0.0-beta.13',
5790
+ version: '4.0.0-beta.16',
5689
5791
  options: { ...DEFAULT_OPTIONS },
5690
5792
  schema: null,
5691
5793
  serverState: null,
@@ -5706,8 +5808,10 @@ function dexieCloud(dexie) {
5706
5808
  await login(db, hint);
5707
5809
  },
5708
5810
  invites: getInvitesObservable(dexie),
5811
+ roles: getGlobalRolesObservable(dexie),
5709
5812
  configure(options) {
5710
5813
  options = dexie.cloud.options = { ...dexie.cloud.options, ...options };
5814
+ configuredProgramatically = true;
5711
5815
  if (options.databaseUrl && options.nameSuffix) {
5712
5816
  // @ts-ignore
5713
5817
  dexie.name = `${origIdbName}-${getDbNameFromDbUrl(options.databaseUrl)}`;
@@ -5794,7 +5898,7 @@ function dexieCloud(dexie) {
5794
5898
  db.getSchema(),
5795
5899
  db.getPersistedSyncState(),
5796
5900
  ]);
5797
- if (!options) {
5901
+ if (!configuredProgramatically) {
5798
5902
  // Options not specified programatically (use case for SW!)
5799
5903
  // Take persisted options:
5800
5904
  db.cloud.options = persistedOptions || null;
@@ -5802,6 +5906,8 @@ function dexieCloud(dexie) {
5802
5906
  else if (!persistedOptions ||
5803
5907
  JSON.stringify(persistedOptions) !== JSON.stringify(options)) {
5804
5908
  // Update persisted options:
5909
+ if (!options)
5910
+ throw new Error(`Internal error`); // options cannot be null if configuredProgramatically is set.
5805
5911
  await db.$syncState.put(options, 'options');
5806
5912
  }
5807
5913
  if (db.cloud.options?.tryUseServiceWorker &&
@@ -5923,7 +6029,7 @@ function dexieCloud(dexie) {
5923
6029
  }
5924
6030
  }
5925
6031
  }
5926
- dexieCloud.version = '4.0.0-beta.13';
6032
+ dexieCloud.version = '4.0.0-beta.16';
5927
6033
  Dexie.Cloud = dexieCloud;
5928
6034
 
5929
6035
  // In case the SW lives for a while, let it reuse already opened connections: