dexie-cloud-addon 4.0.0-beta.19 → 4.0.0-beta.22

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.
@@ -4,17 +4,17 @@ import { UserLogin } from './db/entities/UserLogin';
4
4
  import * as Rx from 'rxjs';
5
5
  import { PersistedSyncState } from './db/entities/PersistedSyncState';
6
6
  import { SyncState } from './types/SyncState';
7
- import { DexieCloudServerState } from './DexieCloudServerState';
8
7
  import { DXCUserInteraction } from './types/DXCUserInteraction';
9
8
  import { DXCWebSocketStatus } from './DXCWebSocketStatus';
10
9
  import { PermissionChecker } from './PermissionChecker';
11
10
  import { DexieCloudSyncOptions } from "./DexieCloudSyncOptions";
12
11
  import { Invite } from './Invite';
12
+ /** The API of db.cloud, where `db` is an instance of Dexie with dexie-cloud-addon active.
13
+ */
13
14
  export interface DexieCloudAPI {
14
15
  version: string;
15
16
  options: DexieCloudOptions | null;
16
17
  schema: DexieCloudSchema | null;
17
- serverState: DexieCloudServerState | null;
18
18
  currentUserId: string;
19
19
  currentUser: Rx.BehaviorSubject<UserLogin>;
20
20
  webSocketStatus: Rx.BehaviorSubject<DXCWebSocketStatus>;
@@ -30,6 +30,8 @@ export interface DexieCloudAPI {
30
30
  /** Login using Dexie Cloud OTP or Demo user.
31
31
  *
32
32
  * @param email Email to authenticate
33
+ * @param userId Optional userId to authenticate
34
+ * @param grant_type requested grant type
33
35
  */
34
36
  login(hint?: {
35
37
  email?: string;
@@ -40,14 +42,25 @@ export interface DexieCloudAPI {
40
42
  * Connect to given URL
41
43
  */
42
44
  configure(options: DexieCloudOptions): void;
43
- /** Wait until a full sync is done.
45
+ /** Trigger a sync
44
46
  *
45
47
  */
46
48
  sync(options?: DexieCloudSyncOptions): Promise<void>;
49
+ /** Method that returns an observable of the available permissions of given
50
+ * entity.
51
+ *
52
+ * @param entity Entity to check permission for
53
+ */
47
54
  permissions<T extends {
48
55
  owner: string;
49
56
  realmId: string;
50
57
  table: () => string;
51
58
  }>(entity: T): Rx.Observable<PermissionChecker<T>>;
59
+ /** Method that returns an observable of the available permissions of given
60
+ * object and table name.
61
+ *
62
+ * @param obj Object retrieved from a dexie query
63
+ * @param table Table name that the object was retrieved from
64
+ */
52
65
  permissions<T>(obj: T, table: string): Rx.Observable<PermissionChecker<T, string>>;
53
66
  }
@@ -6,9 +6,9 @@ export interface DexieCloudOptions {
6
6
  databaseUrl: string;
7
7
  requireAuth?: boolean;
8
8
  tryUseServiceWorker?: boolean;
9
+ periodicSync?: PeriodicSyncOptions;
9
10
  customLoginGui?: boolean;
10
11
  unsyncedTables?: string[];
11
- periodicSync?: PeriodicSyncOptions;
12
12
  nameSuffix?: boolean;
13
13
  disableWebSocket?: boolean;
14
14
  fetchTokens?: (tokenParams: {
@@ -3,4 +3,6 @@ export interface Invite extends DBRealmMember {
3
3
  realm?: DBRealm & {
4
4
  permissions: DBPermissionSet;
5
5
  };
6
+ accept(): Promise<void>;
7
+ reject(): Promise<void>;
6
8
  }
@@ -1,4 +1,3 @@
1
- import { DXCUserInteraction } from "../../types/DXCUserInteraction";
2
1
  export interface UserLogin {
3
2
  userId?: string;
4
3
  name?: string;
@@ -14,5 +13,4 @@ export interface UserLogin {
14
13
  nonExportablePrivateKey?: CryptoKey;
15
14
  publicKey?: CryptoKey;
16
15
  isLoggedIn?: boolean;
17
- interaction?: DXCUserInteraction;
18
16
  }
@@ -1,4 +1,5 @@
1
1
  import { ComponentChildren, h } from 'preact';
2
- export declare function Dialog({ children }: {
2
+ export declare function Dialog({ children, className }: {
3
3
  children?: ComponentChildren;
4
+ className?: string;
4
5
  }): h.JSX.Element;
@@ -1,25 +1,3 @@
1
1
  import { Dexie } from 'dexie';
2
2
  import { Invite } from './Invite';
3
- export declare const getInvitesObservable: (x: Dexie) => import("./mapValueObservable").ObservableWithCurrentValue<(Invite | {
4
- realm: import("dexie-cloud-common").DBRealm & {
5
- permissions: import("dexie-cloud-common").DBPermissionSet;
6
- };
7
- id: string;
8
- userId?: string | undefined;
9
- email?: string | undefined;
10
- name?: string | undefined;
11
- invite?: boolean | undefined;
12
- invitedDate?: Date | undefined;
13
- invitedBy?: {
14
- name: string;
15
- email: string;
16
- userId: string;
17
- } | undefined;
18
- accepted?: Date | undefined;
19
- rejected?: Date | undefined;
20
- roles?: string[] | undefined;
21
- permissions?: import("dexie-cloud-common").DBPermissionSet | undefined;
22
- realmId: string;
23
- owner: string;
24
- $ts?: number | undefined;
25
- })[]>;
3
+ export declare const getInvitesObservable: (x: Dexie) => import("./mapValueObservable").ObservableWithCurrentValue<Invite[]>;
@@ -108,7 +108,7 @@
108
108
  *
109
109
  * ==========================================================================
110
110
  *
111
- * Version 4.0.0-beta.19, Fri May 20 2022
111
+ * Version 4.0.0-beta.22, Mon Sep 05 2022
112
112
  *
113
113
  * https://dexie.org
114
114
  *
@@ -2148,10 +2148,17 @@
2148
2148
  return bytes;
2149
2149
  };
2150
2150
  var b64encode = typeof Buffer !== "undefined"
2151
- ? function (b) { return ArrayBuffer.isView(b)
2152
- ? Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString("base64")
2153
- : Buffer.from(b).toString("base64"); }
2154
- : function (b) { return btoa(String.fromCharCode.apply(null, b)); };
2151
+ ? function (b) {
2152
+ if (ArrayBuffer.isView(b)) {
2153
+ return Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString("base64");
2154
+ }
2155
+ else {
2156
+ return Buffer.from(b).toString("base64");
2157
+ }
2158
+ }
2159
+ : function (b) {
2160
+ return btoa(String.fromCharCode.apply(null, ArrayBuffer.isView(b) ? b : new Uint8Array(b)));
2161
+ };
2155
2162
  function interactWithUser(userInteraction, req) {
2156
2163
  return new Promise(function (resolve, reject) {
2157
2164
  var interactionProps = Object.assign(Object.assign({}, req), { onSubmit: function (res) {
@@ -6313,8 +6320,8 @@
6313
6320
  }
6314
6321
  };
6315
6322
  function Dialog(_k) {
6316
- var children = _k.children;
6317
- return (a$1("div", null, a$1("div", { style: Styles.Darken }), a$1("div", { style: Styles.DialogOuter }, a$1("div", { style: Styles.DialogInner }, children))));
6323
+ var children = _k.children, className = _k.className;
6324
+ return (a$1("div", { className: className }, a$1("div", { style: Styles.Darken }), a$1("div", { style: Styles.DialogOuter }, a$1("div", { style: Styles.DialogInner }, children))));
6318
6325
  }
6319
6326
  var t, u, r, o = 0, i = [], c = n.__b, f = n.__r, e = n.diffed, a = n.__c, v = n.unmount;
6320
6327
  function m(t, r) { n.__h && n.__h(u, t, o || r), o = 0; var i = u.__H || (u.__H = { __: [], __h: [] }); return t >= i.__.length && i.__.push({}), i.__[t]; }
@@ -6356,7 +6363,7 @@
6356
6363
  var _l = l({}), params = _l[0], setParams = _l[1];
6357
6364
  var firstFieldRef = s();
6358
6365
  h(function () { var _a; return (_a = firstFieldRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, []);
6359
- return (a$1(Dialog, null, a$1(y, null, a$1("h3", { style: Styles.WindowHeader }, title), alerts.map(function (alert) { return (a$1("p", { style: Styles.Alert[alert.type] }, resolveText(alert))); }), a$1("form", { onSubmit: function (ev) {
6366
+ return (a$1(Dialog, { className: "dxc-login-dlg" }, a$1(y, null, a$1("h3", { style: Styles.WindowHeader }, title), alerts.map(function (alert) { return (a$1("p", { style: Styles.Alert[alert.type] }, resolveText(alert))); }), a$1("form", { onSubmit: function (ev) {
6360
6367
  ev.preventDefault();
6361
6368
  onSubmit(params);
6362
6369
  } }, Object.entries(fields).map(function (_k, idx) {
@@ -6788,7 +6795,31 @@
6788
6795
  };
6789
6796
  var emailMembersById = membersByEmail.reduce(reducer, {});
6790
6797
  var membersById = accessControl.selfMembers.reduce(reducer, emailMembersById);
6791
- return Object.values(membersById).filter(function (m) { return !m.accepted; });
6798
+ return Object.values(membersById)
6799
+ .filter(function (invite) { return !invite.accepted && !invite.rejected; })
6800
+ .map(function (invite) { return (Object.assign(Object.assign({}, invite), { accept: function () {
6801
+ return __awaiter$1(this, void 0, void 0, function () {
6802
+ return __generator$1(this, function (_k) {
6803
+ switch (_k.label) {
6804
+ case 0: return [4 /*yield*/, db.members.update(invite.id, { accepted: new Date() })];
6805
+ case 1:
6806
+ _k.sent();
6807
+ return [2 /*return*/];
6808
+ }
6809
+ });
6810
+ });
6811
+ }, reject: function () {
6812
+ return __awaiter$1(this, void 0, void 0, function () {
6813
+ return __generator$1(this, function (_k) {
6814
+ switch (_k.label) {
6815
+ case 0: return [4 /*yield*/, db.members.update(invite.id, { rejected: new Date() })];
6816
+ case 1:
6817
+ _k.sent();
6818
+ return [2 /*return*/];
6819
+ }
6820
+ });
6821
+ });
6822
+ } })); });
6792
6823
  })), []);
6793
6824
  });
6794
6825
  function getTiedRealmId(objectId) {
@@ -6844,10 +6875,9 @@
6844
6875
  currentUserEmitter.next(UNAUTHORIZED_USER);
6845
6876
  });
6846
6877
  dexie.cloud = {
6847
- version: '4.0.0-beta.19',
6878
+ version: '4.0.0-beta.22',
6848
6879
  options: Object.assign({}, DEFAULT_OPTIONS),
6849
6880
  schema: null,
6850
- serverState: null,
6851
6881
  get currentUserId() {
6852
6882
  return currentUserEmitter.value.userId || UNAUTHORIZED_USER.userId;
6853
6883
  },
@@ -7176,7 +7206,7 @@
7176
7206
  });
7177
7207
  }
7178
7208
  }
7179
- dexieCloud.version = '4.0.0-beta.19';
7209
+ dexieCloud.version = '4.0.0-beta.22';
7180
7210
  Dexie__default["default"].Cloud = dexieCloud;
7181
7211
 
7182
7212
  exports["default"] = dexieCloud;