|
1 | 1 | import Vue from "vue";
|
2 |
| -import { Client as WarrantClient, WarrantCheck } from "@warrantdev/warrant-js"; |
| 2 | +import { WarrantClient, Check, CheckMany, FeatureCheck, PermissionCheck } from "@warrantdev/warrant-js"; |
3 | 3 |
|
4 | 4 | export interface PluginOptions {
|
5 | 5 | clientKey: string;
|
@@ -32,13 +32,46 @@ const useWarrant = (options: PluginOptions): Vue => {
|
32 | 32 |
|
33 | 33 | localStorage.setItem(LOCAL_STORAGE_KEY_SESSION_TOKEN, newSessionToken);
|
34 | 34 | },
|
35 |
| - async hasWarrant(warrantCheck: WarrantCheck): Promise<boolean> { |
| 35 | + async check(warrantCheck: Check): Promise<boolean> { |
36 | 36 | if (!this.sessionToken) {
|
37 | 37 | throw new Error("No session token provided to Warrant. You may have forgotten to call setSessionToken with a valid session token to finish initializing Warrant.");
|
38 | 38 | }
|
39 | 39 |
|
40 | 40 | this.isLoading = true;
|
41 |
| - const isAuthorized = await new WarrantClient(options.clientKey, this.sessionToken).isAuthorized(warrantCheck); |
| 41 | + const isAuthorized = await new WarrantClient({ clientKey: options.clientKey, sessionToken: this.sessionToken }).check(warrantCheck); |
| 42 | + this.isLoading = false; |
| 43 | + |
| 44 | + return isAuthorized; |
| 45 | + }, |
| 46 | + async checkMany(warrantCheck: CheckMany): Promise<boolean> { |
| 47 | + if (!this.sessionToken) { |
| 48 | + throw new Error("No session token provided to Warrant. You may have forgotten to call setSessionToken with a valid session token to finish initializing Warrant."); |
| 49 | + } |
| 50 | + |
| 51 | + this.isLoading = true; |
| 52 | + const isAuthorized = await new WarrantClient({ clientKey: options.clientKey, sessionToken: this.sessionToken }).checkMany(warrantCheck); |
| 53 | + this.isLoading = false; |
| 54 | + |
| 55 | + return isAuthorized; |
| 56 | + }, |
| 57 | + async hasPermission(warrantCheck: PermissionCheck): Promise<boolean> { |
| 58 | + if (!this.sessionToken) { |
| 59 | + throw new Error("No session token provided to Warrant. You may have forgotten to call setSessionToken with a valid session token to finish initializing Warrant."); |
| 60 | + } |
| 61 | + |
| 62 | + this.isLoading = true; |
| 63 | + const isAuthorized = await new WarrantClient({ clientKey: options.clientKey, sessionToken: this.sessionToken }).hasPermission(warrantCheck); |
| 64 | + this.isLoading = false; |
| 65 | + |
| 66 | + return isAuthorized; |
| 67 | + }, |
| 68 | + async hasFeature(warrantCheck: FeatureCheck): Promise<boolean> { |
| 69 | + if (!this.sessionToken) { |
| 70 | + throw new Error("No session token provided to Warrant. You may have forgotten to call setSessionToken with a valid session token to finish initializing Warrant."); |
| 71 | + } |
| 72 | + |
| 73 | + this.isLoading = true; |
| 74 | + const isAuthorized = await new WarrantClient({ clientKey: options.clientKey, sessionToken: this.sessionToken }).hasFeature(warrantCheck); |
42 | 75 | this.isLoading = false;
|
43 | 76 |
|
44 | 77 | return isAuthorized;
|
|
0 commit comments