@christianriedl/rest 1.0.19 → 1.0.23
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/dist/authorize.d.ts +27 -3
- package/dist/authorize.js +42 -6
- package/dist/authorize.js.map +1 -1
- package/package.json +2 -2
package/dist/authorize.d.ts
CHANGED
|
@@ -1,14 +1,35 @@
|
|
|
1
1
|
import { ILocalStorage, ILogger, IAppConfig, Dictionary } from '@christianriedl/utils';
|
|
2
2
|
import { Rest } from './rest';
|
|
3
|
+
export declare enum EScope {
|
|
4
|
+
None = 0,
|
|
5
|
+
Admin = 1,
|
|
6
|
+
Setting = 2,
|
|
7
|
+
Light = 16,
|
|
8
|
+
Shutter = 32,
|
|
9
|
+
PlugSwitch = 64,
|
|
10
|
+
Climate = 128,
|
|
11
|
+
Schedules = 256,
|
|
12
|
+
WebCam = 512,
|
|
13
|
+
Gps = 1024,
|
|
14
|
+
Media = 4096,
|
|
15
|
+
Music = 8192,
|
|
16
|
+
Video = 16384,
|
|
17
|
+
Photo = 32768,
|
|
18
|
+
Epg = 65536,
|
|
19
|
+
Office = 131072,
|
|
20
|
+
Calendar = 262144,
|
|
21
|
+
Stock = 1048576
|
|
22
|
+
}
|
|
3
23
|
export interface IAuthorizeResult {
|
|
4
24
|
mediaSecret: string;
|
|
5
25
|
smarthomeSecret: string;
|
|
6
26
|
scopes: string;
|
|
7
27
|
user: string;
|
|
28
|
+
name: string;
|
|
8
29
|
password: string;
|
|
9
30
|
}
|
|
10
31
|
export interface IMeta {
|
|
11
|
-
scopes:
|
|
32
|
+
scopes: EScope;
|
|
12
33
|
}
|
|
13
34
|
export interface IRoute {
|
|
14
35
|
path: string;
|
|
@@ -19,16 +40,19 @@ export declare class Authorize {
|
|
|
19
40
|
storage: ILocalStorage;
|
|
20
41
|
secretSmarthome: string;
|
|
21
42
|
secretMedia: string;
|
|
22
|
-
scopes:
|
|
43
|
+
scopes: EScope;
|
|
23
44
|
routes: Dictionary<IRoute>;
|
|
24
45
|
password: string;
|
|
25
46
|
config: IAppConfig;
|
|
26
47
|
get user(): string;
|
|
27
48
|
set user(value: string);
|
|
49
|
+
get name(): string;
|
|
50
|
+
set name(value: string);
|
|
28
51
|
constructor(url: string, storage: ILocalStorage, config: IAppConfig, logger: ILogger);
|
|
29
52
|
setScopes(scopes: string): void;
|
|
30
53
|
setRoutes(routes: IRoute[]): void;
|
|
31
|
-
|
|
54
|
+
checkScopeNames(scopes: string[]): boolean;
|
|
55
|
+
checkScope(scopes: EScope): boolean;
|
|
32
56
|
checkRoute(path: string): boolean;
|
|
33
57
|
authorize(user: string, password: string): Promise<IAuthorizeResult>;
|
|
34
58
|
login(user: string, password: string): Promise<IAuthorizeResult>;
|
package/dist/authorize.js
CHANGED
|
@@ -1,11 +1,34 @@
|
|
|
1
|
+
import { Helper } from '@christianriedl/utils';
|
|
1
2
|
import { Rest } from './rest';
|
|
2
3
|
import { DummyOAuth } from './oauth';
|
|
4
|
+
export var EScope;
|
|
5
|
+
(function (EScope) {
|
|
6
|
+
EScope[EScope["None"] = 0] = "None";
|
|
7
|
+
EScope[EScope["Admin"] = 1] = "Admin";
|
|
8
|
+
EScope[EScope["Setting"] = 2] = "Setting";
|
|
9
|
+
EScope[EScope["Light"] = 16] = "Light";
|
|
10
|
+
EScope[EScope["Shutter"] = 32] = "Shutter";
|
|
11
|
+
EScope[EScope["PlugSwitch"] = 64] = "PlugSwitch";
|
|
12
|
+
EScope[EScope["Climate"] = 128] = "Climate";
|
|
13
|
+
EScope[EScope["Schedules"] = 256] = "Schedules";
|
|
14
|
+
EScope[EScope["WebCam"] = 512] = "WebCam";
|
|
15
|
+
EScope[EScope["Gps"] = 1024] = "Gps";
|
|
16
|
+
EScope[EScope["Media"] = 4096] = "Media";
|
|
17
|
+
EScope[EScope["Music"] = 8192] = "Music";
|
|
18
|
+
EScope[EScope["Video"] = 16384] = "Video";
|
|
19
|
+
EScope[EScope["Photo"] = 32768] = "Photo";
|
|
20
|
+
EScope[EScope["Epg"] = 65536] = "Epg";
|
|
21
|
+
EScope[EScope["Office"] = 131072] = "Office";
|
|
22
|
+
EScope[EScope["Calendar"] = 262144] = "Calendar";
|
|
23
|
+
EScope[EScope["Stock"] = 1048576] = "Stock";
|
|
24
|
+
})(EScope || (EScope = {}));
|
|
25
|
+
;
|
|
3
26
|
export class Authorize {
|
|
4
27
|
rest;
|
|
5
28
|
storage;
|
|
6
29
|
secretSmarthome;
|
|
7
30
|
secretMedia;
|
|
8
|
-
scopes =
|
|
31
|
+
scopes = EScope.None;
|
|
9
32
|
routes = {};
|
|
10
33
|
password;
|
|
11
34
|
config;
|
|
@@ -15,6 +38,12 @@ export class Authorize {
|
|
|
15
38
|
set user(value) {
|
|
16
39
|
this.config.user = value;
|
|
17
40
|
}
|
|
41
|
+
get name() {
|
|
42
|
+
return this.config.name;
|
|
43
|
+
}
|
|
44
|
+
set name(value) {
|
|
45
|
+
this.config.user = value;
|
|
46
|
+
}
|
|
18
47
|
constructor(url, storage, config, logger) {
|
|
19
48
|
this.rest = new Rest(url, 'same-origin', new DummyOAuth(), logger);
|
|
20
49
|
this.storage = storage;
|
|
@@ -28,20 +57,26 @@ export class Authorize {
|
|
|
28
57
|
}
|
|
29
58
|
setScopes(scopes) {
|
|
30
59
|
const splitScopes = scopes.split('|');
|
|
31
|
-
for (let i = 0; i < splitScopes.length; i++)
|
|
32
|
-
this.scopes
|
|
60
|
+
for (let i = 0; i < splitScopes.length; i++) {
|
|
61
|
+
this.scopes = this.scopes | Helper.stringToEnum(EScope, splitScopes[i]);
|
|
62
|
+
}
|
|
33
63
|
}
|
|
34
64
|
setRoutes(routes) {
|
|
35
65
|
for (let i = 0; i < routes.length; i++) {
|
|
36
66
|
this.routes[routes[i].path] = routes[i];
|
|
37
67
|
}
|
|
38
68
|
}
|
|
39
|
-
|
|
40
|
-
for (let i = 0; i < scopes.length; i++)
|
|
41
|
-
|
|
69
|
+
checkScopeNames(scopes) {
|
|
70
|
+
for (let i = 0; i < scopes.length; i++) {
|
|
71
|
+
const scope = Helper.stringToEnum(EScope, scopes[i]);
|
|
72
|
+
if ((scope & this.scopes) == 0)
|
|
42
73
|
return false;
|
|
74
|
+
}
|
|
43
75
|
return true;
|
|
44
76
|
}
|
|
77
|
+
checkScope(scopes) {
|
|
78
|
+
return (this.scopes & scopes) == scopes;
|
|
79
|
+
}
|
|
45
80
|
checkRoute(path) {
|
|
46
81
|
const route = this.routes[path];
|
|
47
82
|
if (!route)
|
|
@@ -73,6 +108,7 @@ export class Authorize {
|
|
|
73
108
|
this.setScopes(res.scopes);
|
|
74
109
|
if (all) {
|
|
75
110
|
this.user = res.user;
|
|
111
|
+
this.name = res.name;
|
|
76
112
|
this.password = res.password;
|
|
77
113
|
this.secretMedia = res.mediaSecret;
|
|
78
114
|
this.secretSmarthome = res.mediaSecret;
|
package/dist/authorize.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authorize.js","sourceRoot":"","sources":["../src/authorize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkD,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/F,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,CAAN,IAAY,MAmBX;AAnBD,WAAY,MAAM;IACd,mCAAQ,CAAA;IACR,qCAAgB,CAAA;IAChB,yCAAkB,CAAA;IAClB,sCAAgB,CAAA;IAChB,0CAAkB,CAAA;IAClB,gDAAqB,CAAA;IACrB,2CAAkB,CAAA;IAClB,+CAAoB,CAAA;IACpB,yCAAiB,CAAA;IACjB,oCAAc,CAAA;IACd,wCAAgB,CAAA;IAChB,wCAAgB,CAAA;IAChB,yCAAgB,CAAA;IAChB,yCAAgB,CAAA;IAChB,qCAAc,CAAA;IACd,4CAAiB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C3B,IAAI,GAAG,EAAE;YACL,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YACrB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;YACrB,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;YAC7B,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,WAAW,CAAC;YACnC,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC,WAAW,CAAC;YACvC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,QAAQ,CAAC,CAAC;YAC/C,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC;YACrD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC;SAChE;IACL,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@christianriedl/rest",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.23",
|
|
4
4
|
"description": "REST and OAuth library based on fetch API",
|
|
5
5
|
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"author": "Christian Riedl",
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@christianriedl/utils": "^1.0.
|
|
20
|
+
"@christianriedl/utils": "^1.0.57"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"typescript": "^4.6.3",
|