@tblabs/storage 5.5.0 → 5.5.2

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.
@@ -0,0 +1 @@
1
+ export type IEntitiesSet = string[] | "all" | "none";
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- export type IEntitiesSet = string[] | "all" | "none";
1
+ import { IEntitiesSet } from "./IEntitiesSet";
2
2
  export interface IStorageUserPrivileges {
3
3
  AddFile: {
4
4
  Datasets: IEntitiesSet;
@@ -42,3 +42,4 @@ export interface IStorageUserPrivileges {
42
42
  AddUser: boolean;
43
43
  DeleteUser: boolean;
44
44
  }
45
+ export declare const USER_PRIVILEGES_NAMES: (keyof IStorageUserPrivileges)[];
@@ -1 +1,19 @@
1
- export {};
1
+ export const USER_PRIVILEGES_NAMES = [
2
+ "GetFile",
3
+ "AddFile",
4
+ "DropDataset",
5
+ "ListFiles",
6
+ "UpdateFile",
7
+ "DeleteFile",
8
+ "CreateDataset",
9
+ "DatasetExists",
10
+ "RemoveDataset",
11
+ "MoveFile",
12
+ "GetUser",
13
+ "UpdateUser",
14
+ "AddUser",
15
+ "DeleteUser",
16
+ "ListDatasets",
17
+ "ListUsers",
18
+ "Search",
19
+ ];
@@ -1,5 +1,5 @@
1
1
  import { Message } from "../MessageBus/Message";
2
2
  import { dir } from "../Types/dir";
3
3
  export declare class LoginUserQuery extends Message {
4
- constructor(Database: dir, Password: string);
4
+ constructor(Database: dir, Password: string, Login?: string);
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import { Message } from "../MessageBus/Message";
2
2
  export class LoginUserQuery extends Message {
3
- constructor(Database, Password) {
4
- super("LoginUser", { Database, Password });
3
+ constructor(Database, Password, Login) {
4
+ super("LoginUser", { Database, Password, Login });
5
5
  }
6
6
  }
@@ -6,6 +6,7 @@ import { MessageBusResponse } from "./MessageBus/MessageBusResponse";
6
6
  import { Dataset } from "./Dataset";
7
7
  import { IStorageUser } from "./IStorageUser";
8
8
  import { IConverter } from "./IConverter";
9
+ import { IStorageUserPrivileges } from "./IStorageUserPrivileges";
9
10
  export declare class OnlineStorage {
10
11
  private server;
11
12
  private database;
@@ -15,6 +16,7 @@ export declare class OnlineStorage {
15
16
  private readonly _bus;
16
17
  private onUserChange;
17
18
  private USER_LOCAL_STORAGE_KEY;
19
+ get AvailableUserPrivileges(): (keyof IStorageUserPrivileges)[];
18
20
  get Server(): string;
19
21
  get DatabaseDir(): dir;
20
22
  constructor(server: url, database: dir, sender?: ISender, bus?: MessageBus);
@@ -30,12 +32,16 @@ export declare class OnlineStorage {
30
32
  private IsBrowserEnvironment;
31
33
  private LoadUserFromLocalStorage;
32
34
  get User(): IStorageUser;
33
- Login(password: string): Promise<IStorageUser>;
35
+ Login(password: string, login?: string): Promise<IStorageUser>;
36
+ SetLoginPolicy(): void;
37
+ GetNextPassword(): void;
38
+ SetDefaultPrivileges(byRole: Record<string, IStorageUserPrivileges>): void;
34
39
  private SaveUserInLocalStorage;
35
40
  OnUserChange(handler: (user: IStorageUser, isAuthorized: boolean, appStart: boolean) => void): this;
36
41
  Logout(): this;
37
42
  private CallOnUserChanged;
38
43
  get IsAuthorized(): boolean;
44
+ get IsNotLoggedIn(): boolean;
39
45
  SetUser(user: IStorageUser): this;
40
46
  EnableLog(): this;
41
47
  DisableLog(): this;
package/OnlineStorage.js CHANGED
@@ -11,6 +11,7 @@ import { UpdateUserCommand } from "./Messages/UpdateUserCommand";
11
11
  import { AddUserCommand } from "./Messages/AddUserCommand";
12
12
  import { DeleteUserCommand } from "./Messages/DeleteUserCommand";
13
13
  import { GetUserQuery } from "./Messages/GetUserQuery";
14
+ import { USER_PRIVILEGES_NAMES } from "./IStorageUserPrivileges";
14
15
  export class OnlineStorage {
15
16
  server;
16
17
  database;
@@ -20,6 +21,9 @@ export class OnlineStorage {
20
21
  _bus;
21
22
  onUserChange = [];
22
23
  USER_LOCAL_STORAGE_KEY = "";
24
+ get AvailableUserPrivileges() {
25
+ return USER_PRIVILEGES_NAMES;
26
+ }
23
27
  get Server() {
24
28
  return this.server;
25
29
  }
@@ -36,6 +40,7 @@ export class OnlineStorage {
36
40
  }
37
41
  }
38
42
  SetServer(server) {
43
+ this.server = server;
39
44
  this._bus.SetServer(server);
40
45
  return this;
41
46
  }
@@ -103,8 +108,8 @@ export class OnlineStorage {
103
108
  get User() {
104
109
  return this.user;
105
110
  }
106
- async Login(password) {
107
- const result = await this._bus.SendMessage(new LoginUserQuery(this.DatabaseDir, password));
111
+ async Login(password, login) {
112
+ const result = await this._bus.SendMessage(new LoginUserQuery(this.DatabaseDir, password, login));
108
113
  if (!result.IsSuccess) {
109
114
  throw new Error(`Could not login: ${result.ErrorMessage}`);
110
115
  }
@@ -114,6 +119,12 @@ export class OnlineStorage {
114
119
  this.CallOnUserChanged(false);
115
120
  return this.user;
116
121
  }
122
+ SetLoginPolicy() {
123
+ }
124
+ GetNextPassword() {
125
+ }
126
+ SetDefaultPrivileges(byRole) {
127
+ }
117
128
  SaveUserInLocalStorage() {
118
129
  if (this.IsBrowserEnvironment()) {
119
130
  window.localStorage.setItem(this.USER_LOCAL_STORAGE_KEY, JSON.stringify(this.user));
@@ -153,7 +164,10 @@ export class OnlineStorage {
153
164
  this.onUserChange.forEach(handler => handler(this.user, this.IsAuthorized, appStart));
154
165
  }
155
166
  get IsAuthorized() {
156
- return this.user.Id !== this.ANONYMOUS_USER.Id;
167
+ return this.user && this.user.Id !== this.ANONYMOUS_USER.Id;
168
+ }
169
+ get IsNotLoggedIn() {
170
+ return !this.user || this.user.Id === this.ANONYMOUS_USER.Id;
157
171
  }
158
172
  SetUser(user) {
159
173
  this.user = user;
package/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from "./Types/dir";
2
+ export * from "./IStorageUserPrivileges";
3
+ export * from "./IEntitiesSet";
4
+ export * from "./IStorageUser";
2
5
  export * from "./IConverter";
3
6
  export * from "./Converter";
4
7
  export * from "./IRepo";
package/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  export * from "./Types/dir";
2
+ export * from "./IStorageUserPrivileges";
3
+ export * from "./IEntitiesSet";
4
+ export * from "./IStorageUser";
2
5
  export * from "./IConverter";
3
6
  export * from "./Converter";
4
7
  export * from "./IRepo";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tblabs/storage",
3
- "version": "5.5.0",
3
+ "version": "5.5.2",
4
4
  "description": "online storage module with auth",
5
5
  "license": "beerware",
6
6
  "main": "index.js",
Binary file
Binary file