@tblabs/storage 5.2.6 → 5.2.7
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.
- package/Dataset.d.ts +2 -0
- package/Dataset.js +15 -0
- package/IStorageUser.d.ts +1 -42
- package/IStorageUser.js +0 -1
- package/IStorageUserPrivileges.d.ts +38 -0
- package/IStorageUserPrivileges.js +1 -0
- package/Messages/RegisterCommand.d.ts +1 -1
- package/OnlineStorage.d.ts +3 -2
- package/OnlineStorage.js +33 -10
- package/package.json +1 -1
- package/tblabs-storage-5.2.7.tgz +0 -0
- package/tblabs-storage-5.2.6.tgz +0 -0
package/Dataset.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { OnlineStorage } from "./OnlineStorage";
|
|
|
2
2
|
import { IConverter } from "./IConverter";
|
|
3
3
|
import { IRepo } from "./IRepo";
|
|
4
4
|
import { dir } from "./Types/dir";
|
|
5
|
+
import { IStorageUserPrivileges } from "./IStorageUserPrivileges";
|
|
5
6
|
export declare class Dataset<T extends object> implements IRepo<T> {
|
|
6
7
|
private _db;
|
|
7
8
|
private _converter;
|
|
@@ -9,6 +10,7 @@ export declare class Dataset<T extends object> implements IRepo<T> {
|
|
|
9
10
|
get Name(): string;
|
|
10
11
|
constructor(_db: OnlineStorage, _converter: IConverter<any, T>, dataset: dir);
|
|
11
12
|
private get DatasetPath();
|
|
13
|
+
CanUserDo(action: keyof IStorageUserPrivileges): boolean;
|
|
12
14
|
GetOne(id: string): Promise<T>;
|
|
13
15
|
FindOne(id: string): Promise<T | null>;
|
|
14
16
|
GetAll(): Promise<T[]>;
|
package/Dataset.js
CHANGED
|
@@ -20,6 +20,21 @@ export class Dataset {
|
|
|
20
20
|
get DatasetPath() {
|
|
21
21
|
return this._db.DatabaseDir + "/Datasets/" + this.dataset;
|
|
22
22
|
}
|
|
23
|
+
CanUserDo(action) {
|
|
24
|
+
// console.log("ACTION", action);
|
|
25
|
+
// console.log("PRIVILEGES", this._db.User.Privileges);
|
|
26
|
+
if (!this._db.User.Privileges) {
|
|
27
|
+
// console.warn("User not logged in (even if Anonymous)");
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
if (typeof this._db.User.Privileges[action] === "object" && this._db.User.Privileges[action]) {
|
|
31
|
+
return this._db.User.Privileges[action].Datasets == "all" || this._db.User.Privileges[action].Datasets.includes(this.dataset);
|
|
32
|
+
}
|
|
33
|
+
if (typeof this._db.User.Privileges[action] === "boolean" && this._db.User.Privileges[action]) {
|
|
34
|
+
return this._db.User.Privileges[action];
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
23
38
|
async GetOne(id) {
|
|
24
39
|
this._db.Log(`Fetching "${id}"...`);
|
|
25
40
|
const queryResult = await this._db.Send(new GetQuery(this._db.DatabaseDir, this.dataset, id));
|
package/IStorageUser.d.ts
CHANGED
|
@@ -1,46 +1,5 @@
|
|
|
1
|
+
import { IStorageUserPrivileges } from "./IStorageUserPrivileges";
|
|
1
2
|
import { ISender } from "./MessageBus/ISender";
|
|
2
|
-
export type IEntitiesSet = string[] | "all" | "none";
|
|
3
|
-
export type ICommandPrivilege = {
|
|
4
|
-
Datasets?: IEntitiesSet;
|
|
5
|
-
Files?: IEntitiesSet;
|
|
6
|
-
};
|
|
7
|
-
export interface IStorageUserPrivileges {
|
|
8
|
-
Add: {
|
|
9
|
-
Datasets: IEntitiesSet;
|
|
10
|
-
};
|
|
11
|
-
Update: {
|
|
12
|
-
Datasets: IEntitiesSet;
|
|
13
|
-
Files: IEntitiesSet;
|
|
14
|
-
};
|
|
15
|
-
Delete: {
|
|
16
|
-
Datasets: IEntitiesSet;
|
|
17
|
-
Files: IEntitiesSet;
|
|
18
|
-
};
|
|
19
|
-
List: {
|
|
20
|
-
Datasets: IEntitiesSet;
|
|
21
|
-
};
|
|
22
|
-
Get: {
|
|
23
|
-
Datasets: IEntitiesSet;
|
|
24
|
-
Files: IEntitiesSet;
|
|
25
|
-
};
|
|
26
|
-
Drop: {
|
|
27
|
-
Datasets: IEntitiesSet;
|
|
28
|
-
};
|
|
29
|
-
Move: {
|
|
30
|
-
Datasets: IEntitiesSet;
|
|
31
|
-
Files: IEntitiesSet;
|
|
32
|
-
};
|
|
33
|
-
Create: {
|
|
34
|
-
Datasets: IEntitiesSet;
|
|
35
|
-
};
|
|
36
|
-
Exists: {
|
|
37
|
-
Datasets: IEntitiesSet;
|
|
38
|
-
};
|
|
39
|
-
Remove: {
|
|
40
|
-
Datasets: IEntitiesSet;
|
|
41
|
-
};
|
|
42
|
-
Register: boolean;
|
|
43
|
-
}
|
|
44
3
|
export interface IStorageUser extends ISender {
|
|
45
4
|
Id: string;
|
|
46
5
|
Database: string;
|
package/IStorageUser.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export type IEntitiesSet = string[] | "all" | "none";
|
|
2
|
+
export interface IStorageUserPrivileges {
|
|
3
|
+
Add: {
|
|
4
|
+
Datasets: IEntitiesSet;
|
|
5
|
+
};
|
|
6
|
+
Update: {
|
|
7
|
+
Datasets: IEntitiesSet;
|
|
8
|
+
Files: IEntitiesSet;
|
|
9
|
+
};
|
|
10
|
+
Delete: {
|
|
11
|
+
Datasets: IEntitiesSet;
|
|
12
|
+
Files: IEntitiesSet;
|
|
13
|
+
};
|
|
14
|
+
List: {
|
|
15
|
+
Datasets: IEntitiesSet;
|
|
16
|
+
};
|
|
17
|
+
Get: {
|
|
18
|
+
Datasets: IEntitiesSet;
|
|
19
|
+
Files: IEntitiesSet;
|
|
20
|
+
};
|
|
21
|
+
Drop: {
|
|
22
|
+
Datasets: IEntitiesSet;
|
|
23
|
+
};
|
|
24
|
+
Move: {
|
|
25
|
+
Datasets: IEntitiesSet;
|
|
26
|
+
Files: IEntitiesSet;
|
|
27
|
+
};
|
|
28
|
+
Create: {
|
|
29
|
+
Datasets: IEntitiesSet;
|
|
30
|
+
};
|
|
31
|
+
Exists: {
|
|
32
|
+
Datasets: IEntitiesSet;
|
|
33
|
+
};
|
|
34
|
+
Remove: {
|
|
35
|
+
Datasets: IEntitiesSet;
|
|
36
|
+
};
|
|
37
|
+
Register: boolean;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { IStorageUserPrivileges } from "../
|
|
1
|
+
import { IStorageUserPrivileges } from "../IStorageUserPrivileges";
|
|
2
2
|
import { Message } from "../MessageBus/Message";
|
|
3
3
|
import { dir } from "../Types/dir";
|
|
4
4
|
export declare class RegisterCommand extends Message {
|
package/OnlineStorage.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ISender } from "./MessageBus/ISender";
|
|
|
4
4
|
import { MessageBus } from "./MessageBus/MessageBus";
|
|
5
5
|
import { MessageBusResponse } from "./MessageBus/MessageBusResponse";
|
|
6
6
|
import { Dataset } from "./Dataset";
|
|
7
|
-
import { IStorageUser
|
|
7
|
+
import { IStorageUser } from "./IStorageUser";
|
|
8
8
|
export declare class OnlineStorage {
|
|
9
9
|
private database;
|
|
10
10
|
private ANONYMOUS_USER;
|
|
@@ -15,13 +15,14 @@ export declare class OnlineStorage {
|
|
|
15
15
|
private readonly USER_LOCAL_STORAGE_KEY;
|
|
16
16
|
get DatabaseDir(): dir;
|
|
17
17
|
constructor(server: url, database: dir, sender?: ISender, bus?: MessageBus);
|
|
18
|
+
private WasAnonymousUserEverLoaded;
|
|
19
|
+
InitOnce(): Promise<void>;
|
|
18
20
|
private IsBrowserEnvironment;
|
|
19
21
|
private LoadUserFromLocalStorage;
|
|
20
22
|
get User(): IStorageUser;
|
|
21
23
|
Login(password: string): Promise<IStorageUser>;
|
|
22
24
|
private SaveUserInLocalStorage;
|
|
23
25
|
OnUserChange(handler: (user: IStorageUser, isAuthorized: boolean, appStart: boolean) => void): this;
|
|
24
|
-
Register(id: string, role: string, name: string, login: string, password: string, email: string, privileges: IStorageUserPrivileges, icon?: string, tags?: string[]): Promise<IStorageUser>;
|
|
25
26
|
Logout(): this;
|
|
26
27
|
private CallOnUserChanged;
|
|
27
28
|
get IsAuthorized(): boolean;
|
package/OnlineStorage.js
CHANGED
|
@@ -2,7 +2,6 @@ import { MessageBus } from "./MessageBus/MessageBus";
|
|
|
2
2
|
import { CreateCommand, ExistsCommand, RemoveCommand } from "./Messages/AddDirCommand";
|
|
3
3
|
import { MoveCommand } from "./Messages/MoveCommand";
|
|
4
4
|
import { LoginQuery } from "./Messages/LoginQuery";
|
|
5
|
-
import { RegisterCommand } from "./Messages/RegisterCommand";
|
|
6
5
|
export class OnlineStorage {
|
|
7
6
|
database;
|
|
8
7
|
ANONYMOUS_USER = { Id: "Anonymous" };
|
|
@@ -20,6 +19,18 @@ export class OnlineStorage {
|
|
|
20
19
|
this.USER_LOCAL_STORAGE_KEY = "OnlineStorage:User:" + this.database;
|
|
21
20
|
this.LoadUserFromLocalStorage(true);
|
|
22
21
|
}
|
|
22
|
+
WasAnonymousUserEverLoaded() {
|
|
23
|
+
// console.log( "aaaaAAA", this.user.Privileges)
|
|
24
|
+
return (this.User.Id === this.ANONYMOUS_USER.Id && this.user.Privileges !== undefined);
|
|
25
|
+
}
|
|
26
|
+
async InitOnce() {
|
|
27
|
+
// console.log("INIT", this.WasAnonymousUserEverLoaded());
|
|
28
|
+
if (this.WasAnonymousUserEverLoaded()) {
|
|
29
|
+
// console.log("INIT RETURN WasAnonymousUserEverLoaded()=true");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
this.user = await this.Login("Anonymous"); // TODO: Tutaj można my zrobić dedykowaną metode do pobierania ustawień użytkownika Anonymous
|
|
33
|
+
}
|
|
23
34
|
IsBrowserEnvironment() {
|
|
24
35
|
return typeof window !== "undefined" && typeof window.localStorage !== "undefined";
|
|
25
36
|
}
|
|
@@ -37,6 +48,7 @@ export class OnlineStorage {
|
|
|
37
48
|
return this.user;
|
|
38
49
|
}
|
|
39
50
|
async Login(password) {
|
|
51
|
+
// console.log("LOGIN", password);
|
|
40
52
|
const result = await this._bus.SendMessage(new LoginQuery(this.DatabaseDir, password));
|
|
41
53
|
if (!result.IsSuccess) {
|
|
42
54
|
throw new Error(`Could not login: ${result.ErrorMessage}`);
|
|
@@ -45,6 +57,7 @@ export class OnlineStorage {
|
|
|
45
57
|
this.SetUser(this.user);
|
|
46
58
|
this.SaveUserInLocalStorage();
|
|
47
59
|
this.CallOnUserChanged(false);
|
|
60
|
+
// console.log("USER LOGIN", this.user);
|
|
48
61
|
return this.user;
|
|
49
62
|
}
|
|
50
63
|
SaveUserInLocalStorage() {
|
|
@@ -57,15 +70,25 @@ export class OnlineStorage {
|
|
|
57
70
|
handler(this.user, this.IsAuthorized, true);
|
|
58
71
|
return this;
|
|
59
72
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
//
|
|
74
|
+
// UWAGA!!!!!!!!!! TAK NIE MOŻNA REJESTROWAĆ Privileges!!!!!! TO MUSI SIĘ ODBYWAĆ PRZEZ INNĄ METODE ALBO INNY MECHANIZM!!!!!!!
|
|
75
|
+
// Użytkownik nie może sam sobie nadawać uprawnień xddd
|
|
76
|
+
//
|
|
77
|
+
//
|
|
78
|
+
// public async Register(id: string, role: string, name: string,
|
|
79
|
+
// login: string, password: string, email: string,
|
|
80
|
+
// privileges: IStorageUserPrivileges,
|
|
81
|
+
// icon?: string, tags?: string[]): Promise<IStorageUser>
|
|
82
|
+
// {
|
|
83
|
+
// const createdAt = new Date();
|
|
84
|
+
// const result = await this._bus.SendMessage(new RegisterCommand(this.DatabaseDir, id, role, name, login, password, email, privileges, icon, tags, createdAt));
|
|
85
|
+
// if (!result.IsSuccess)
|
|
86
|
+
// {
|
|
87
|
+
// throw new Error(`Could not register: ${result.ErrorMessage}`);
|
|
88
|
+
// }
|
|
89
|
+
// const user = result.Result as IStorageUser;
|
|
90
|
+
// return user;
|
|
91
|
+
// }
|
|
69
92
|
Logout() {
|
|
70
93
|
this.SetUser(this.ANONYMOUS_USER);
|
|
71
94
|
this.SaveUserInLocalStorage();
|
package/package.json
CHANGED
|
Binary file
|
package/tblabs-storage-5.2.6.tgz
DELETED
|
Binary file
|