@meowinc/meow-sdk 0.2.0 → 0.3.0

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,4 +4,4 @@ export interface Response {
4
4
  name: string;
5
5
  }[];
6
6
  }
7
- export declare function request(): Promise<import("ts-result-meow").Result<Response, string>>;
7
+ export declare function request(): Promise<import("@meowinc/result").Result<Response, string>>;
@@ -2,8 +2,10 @@ import { MeowResult } from "../../types";
2
2
  export interface Response {
3
3
  id: string;
4
4
  name: string;
5
+ type: "web" | "mobile";
5
6
  owner: {
6
7
  id: number;
8
+ login: string;
7
9
  name: string;
8
10
  };
9
11
  }
@@ -3,6 +3,6 @@ export declare class AppRequests {
3
3
  private readonly authProvider;
4
4
  constructor(authProvider: AuthorizationProvider);
5
5
  create(displayId: string, name: string, type: "web" | "mobile"): Promise<import("../../types").MeowResult<void>>;
6
- getAppList(): Promise<import("ts-result-meow").Result<import("./get-app-list").Response, string>>;
6
+ getAppList(): Promise<import("@meowinc/result").Result<import("./get-app-list").Response, string>>;
7
7
  getByDisplayId(displayId: string): Promise<import("../../types").MeowResult<import("./get-by-display-id").Response>>;
8
8
  }
@@ -1,7 +1,9 @@
1
+ import { ACCOUNT_API } from "..";
1
2
  import { ErrorToMessage } from "../../error";
2
3
  import { HttpClient } from "../../http-client";
3
4
  export async function request(mailbox, authorizationProvider) {
4
5
  return await new HttpClient()
6
+ .withUrl(`${ACCOUNT_API}/v1/auth/2fa/email`)
5
7
  .withAuthorization(authorizationProvider)
6
8
  .withMethodPost()
7
9
  .withJsonBody({
@@ -1,7 +1,9 @@
1
+ import { ACCOUNT_API } from "..";
1
2
  import { ErrorToMessage } from "../../error";
2
3
  import { HttpClient } from "../../http-client";
3
4
  export async function request(sessionId, code, authorizationProvider) {
4
5
  return await new HttpClient()
6
+ .withUrl(`${ACCOUNT_API}/v1/auth/2fa/email/submit`)
5
7
  .withMethodPost()
6
8
  .withAuthorization(authorizationProvider)
7
9
  .withJsonBody({
@@ -7,5 +7,5 @@ export interface Response {
7
7
  status: string;
8
8
  registrationDate: Date;
9
9
  }
10
- export declare function request(login: string): Promise<import("ts-result-meow").Result<Response, string>>;
10
+ export declare function request(login: string): Promise<import("@meowinc/result").Result<Response, string>>;
11
11
  export {};
@@ -2,5 +2,5 @@ import { AuthorizationProvider } from "../../auth-provider";
2
2
  export declare class UserRequests {
3
3
  private readonly authProvider;
4
4
  constructor(authProvider: AuthorizationProvider);
5
- getUserByLogin(login: string): Promise<import("ts-result-meow").Result<import("./get-user-by-login").Response, string>>;
5
+ getUserByLogin(login: string): Promise<import("@meowinc/result").Result<import("./get-user-by-login").Response, string>>;
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import type { AuthorizationProvider } from "./auth-provider";
2
- import { Result } from "ts-result-meow";
3
2
  import { HttpError, type AppError } from "./error";
3
+ import { Result } from "@meowinc/result";
4
4
  export declare class HttpClient {
5
5
  private url;
6
6
  private headers;
@@ -1,7 +1,7 @@
1
- import { Result } from "ts-result-meow";
2
1
  import { HttpError } from "./error";
3
2
  import { AccessToken } from "./token";
4
3
  import { ACCOUNT_API } from "./account";
4
+ import { Result } from "@meowinc/result";
5
5
  export class HttpClient {
6
6
  url = "";
7
7
  headers = {};
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import { MeowResult, UndefinedString } from "./types";
5
5
  export { AuthorizationProvider } from "./auth-provider";
6
6
  export { UndefinedString };
7
7
  export { AccessToken } from "./token";
8
+ export { MeowUtils } from "./utils";
8
9
  export type AuthorizationUpdateHandler = (data: {
9
10
  accessToken: UndefinedString;
10
11
  refreshToken: UndefinedString;
@@ -21,5 +22,6 @@ export declare class MeowSdkClient<T extends AuthorizationProvider> {
21
22
  getAccessToken(): UndefinedString;
22
23
  onAuthorizationUpdated(callback: AuthorizationUpdateHandler): this;
23
24
  tryUpdateAuth(): Promise<MeowResult<void>>;
25
+ isContainsExpectedPermissions(expected: string[]): boolean;
24
26
  static fromAuthorizationProvider<T extends AuthorizationProvider>(provider: AuthorizationProvider): MeowSdkClient<T>;
25
27
  }
package/dist/index.js CHANGED
@@ -4,7 +4,9 @@ import { updateAuthorization } from "./http-client";
4
4
  import { MailClient } from "./mail";
5
5
  import { AccessToken } from "./token";
6
6
  import { MeowResult } from "./types";
7
+ import { MeowUtils } from "./utils";
7
8
  export { AccessToken } from "./token";
9
+ export { MeowUtils } from "./utils";
8
10
  export class MeowSdkClient {
9
11
  account;
10
12
  mail;
@@ -50,6 +52,14 @@ export class MeowSdkClient {
50
52
  this.updateTokens(accessToken, refreshToken);
51
53
  return MeowResult.withOk((function () { })());
52
54
  }
55
+ isContainsExpectedPermissions(expected) {
56
+ const token = this.getAccessToken();
57
+ if (!token) {
58
+ return false;
59
+ }
60
+ const parsedToken = new AccessToken(token);
61
+ return MeowUtils.checkRequiredPermissions(expected, parsedToken.permissions());
62
+ }
53
63
  static fromAuthorizationProvider(provider) {
54
64
  return new MeowSdkClient(provider);
55
65
  }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Result } from "ts-result-meow";
1
+ import { Result } from "@meowinc/result";
2
2
  export type UndefinedString = string | undefined;
3
3
  export type UserRole = "root" | "admin" | "user" | "inactive";
4
4
  type MeowError = string;
package/dist/types.js CHANGED
@@ -1,3 +1,3 @@
1
- import { Result } from "ts-result-meow";
1
+ import { Result } from "@meowinc/result";
2
2
  export class MeowResult extends Result {
3
3
  }
@@ -0,0 +1,3 @@
1
+ export declare class MeowUtils {
2
+ static checkRequiredPermissions(expected: string[], permissions: string[]): boolean;
3
+ }
package/dist/utils.js ADDED
@@ -0,0 +1,5 @@
1
+ export class MeowUtils {
2
+ static checkRequiredPermissions(expected, permissions) {
3
+ return permissions.every((permission) => expected.includes(permission));
4
+ }
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meowinc/meow-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Meow SDK",
5
5
  "keywords": [
6
6
  "sdk"
@@ -23,7 +23,7 @@
23
23
  "prettier": "prettier ./src --write"
24
24
  },
25
25
  "dependencies": {
26
- "ts-result-meow": ">=0.0.13",
26
+ "@meowinc/result": ">=0.0.13",
27
27
  "jwt-decode": ">=4"
28
28
  },
29
29
  "devDependencies": {