@meowinc/meow-sdk 0.11.0 → 0.11.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.
- package/dist/account/sessions/request-token.d.ts +9 -4
- package/dist/index.d.ts +3 -0
- package/dist/index.js +17 -5
- package/dist/token.d.ts +2 -0
- package/dist/token.js +6 -0
- package/package.json +1 -1
|
@@ -4,16 +4,21 @@ type Payload = {
|
|
|
4
4
|
type: "noVerification";
|
|
5
5
|
} | {
|
|
6
6
|
type: "loginPassword";
|
|
7
|
-
login: string;
|
|
8
7
|
password: string;
|
|
9
8
|
} | {
|
|
10
9
|
type: "twoFactor";
|
|
11
|
-
|
|
10
|
+
sessionId: string;
|
|
12
11
|
code: string;
|
|
13
12
|
};
|
|
14
|
-
export
|
|
13
|
+
export type Response = {
|
|
15
14
|
type: "success";
|
|
16
15
|
token: string;
|
|
17
|
-
}
|
|
16
|
+
} | {
|
|
17
|
+
type: "requireTwoFactorPassword";
|
|
18
|
+
sessionId: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "requireTwoFactor";
|
|
21
|
+
sessionId: string;
|
|
22
|
+
};
|
|
18
23
|
export declare function request(payload: Payload, authProvider: AuthorizationProvider): Promise<MeowResult<Response>>;
|
|
19
24
|
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AccountClient } from "./account";
|
|
|
2
2
|
import type { AuthorizationProvider } from "./auth-provider";
|
|
3
3
|
import { MailClient } from "./mail";
|
|
4
4
|
import { NotificationClient } from "./notification";
|
|
5
|
+
import { AccessToken } from "./token";
|
|
5
6
|
import { MeowResult, UndefinedString } from "./types";
|
|
6
7
|
export { AuthorizationProvider } from "./auth-provider";
|
|
7
8
|
export { UndefinedString };
|
|
@@ -22,8 +23,10 @@ export declare class MeowSdkClient<T extends AuthorizationProvider> {
|
|
|
22
23
|
updateRefreshToken(refreshToken: string): void;
|
|
23
24
|
updateTokens(accessToken: string, refreshToken: string): void;
|
|
24
25
|
getAccessToken(): UndefinedString;
|
|
26
|
+
getParsedAccessToken(): AccessToken | undefined;
|
|
25
27
|
onAuthorizationUpdated(callback: AuthorizationUpdateHandler): this;
|
|
26
28
|
tryUpdateAuth(forceUpdate?: boolean): Promise<MeowResult<void>>;
|
|
29
|
+
isContainExpectedPermission(permission: string): boolean;
|
|
27
30
|
isContainsExpectedPermissions(expected: string[]): boolean;
|
|
28
31
|
static fromAuthorizationProvider<T extends AuthorizationProvider>(provider: AuthorizationProvider): MeowSdkClient<T>;
|
|
29
32
|
}
|
package/dist/index.js
CHANGED
|
@@ -5,7 +5,6 @@ import { MailClient } from "./mail";
|
|
|
5
5
|
import { NotificationClient } from "./notification";
|
|
6
6
|
import { AccessToken } from "./token";
|
|
7
7
|
import { MeowResult } from "./types";
|
|
8
|
-
import { MeowUtils } from "./utils";
|
|
9
8
|
export { AccessToken } from "./token";
|
|
10
9
|
export { MeowUtils } from "./utils";
|
|
11
10
|
export class MeowSdkClient {
|
|
@@ -34,6 +33,13 @@ export class MeowSdkClient {
|
|
|
34
33
|
getAccessToken() {
|
|
35
34
|
return this.authProvider.getAccessToken();
|
|
36
35
|
}
|
|
36
|
+
getParsedAccessToken() {
|
|
37
|
+
const token = this.getAccessToken();
|
|
38
|
+
if (!token) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
return new AccessToken(token);
|
|
42
|
+
}
|
|
37
43
|
onAuthorizationUpdated(callback) {
|
|
38
44
|
this.authProvider.onUpdate(callback);
|
|
39
45
|
return this;
|
|
@@ -55,13 +61,19 @@ export class MeowSdkClient {
|
|
|
55
61
|
this.updateTokens(accessToken, refreshToken);
|
|
56
62
|
return MeowResult.withOk((function () { })());
|
|
57
63
|
}
|
|
64
|
+
isContainExpectedPermission(permission) {
|
|
65
|
+
const parsedToken = this.getParsedAccessToken();
|
|
66
|
+
if (!parsedToken) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return parsedToken.containsPermission(permission);
|
|
70
|
+
}
|
|
58
71
|
isContainsExpectedPermissions(expected) {
|
|
59
|
-
const
|
|
60
|
-
if (!
|
|
72
|
+
const parsedToken = this.getParsedAccessToken();
|
|
73
|
+
if (!parsedToken) {
|
|
61
74
|
return false;
|
|
62
75
|
}
|
|
63
|
-
|
|
64
|
-
return MeowUtils.checkRequiredPermissions(expected, parsedToken.permissions());
|
|
76
|
+
return parsedToken.containsPermissions(expected);
|
|
65
77
|
}
|
|
66
78
|
static fromAuthorizationProvider(provider) {
|
|
67
79
|
return new MeowSdkClient(provider);
|
package/dist/token.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare class AccessToken {
|
|
|
8
8
|
lifetime(): LifeTimeTokenData;
|
|
9
9
|
permissions(): string[];
|
|
10
10
|
raw(): string;
|
|
11
|
+
containsPermission(permission: string): boolean;
|
|
12
|
+
containsPermissions(permissions: string[]): boolean;
|
|
11
13
|
}
|
|
12
14
|
type AvailableUserRole = "root" | "admin" | "user";
|
|
13
15
|
interface UserTokenData {
|
package/dist/token.js
CHANGED
|
@@ -26,4 +26,10 @@ export class AccessToken {
|
|
|
26
26
|
raw() {
|
|
27
27
|
return this.token;
|
|
28
28
|
}
|
|
29
|
+
containsPermission(permission) {
|
|
30
|
+
return this.payload.permissions.some((p) => p === permission);
|
|
31
|
+
}
|
|
32
|
+
containsPermissions(permissions) {
|
|
33
|
+
return permissions.every((p) => this.containsPermission(p));
|
|
34
|
+
}
|
|
29
35
|
}
|