@dripfi/drip-sdk 1.2.13 → 1.2.15
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/DripApi.d.ts +2 -0
- package/dist/DripApi.js +19 -0
- package/dist/DripSdk.d.ts +1 -1
- package/dist/DripSdk.js +2 -4
- package/dist/types/AuthenticationStatus.d.ts +15 -3
- package/dist/types/AuthenticationStatus.js +17 -0
- package/package.json +1 -1
package/dist/DripApi.d.ts
CHANGED
@@ -11,6 +11,7 @@ import { LoyaltyCard } from './types/LoyaltyCard';
|
|
11
11
|
import { BeansBalance } from './types/BeansBalance';
|
12
12
|
import { PerqToBeansSwapInfo } from './types/PerqToBeansSwapInfo';
|
13
13
|
import BeanEntry from './types/BeanEntry';
|
14
|
+
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
14
15
|
export declare const IMPERSONATOR_HEADER = "impersonatorAddress";
|
15
16
|
export default class DripApi {
|
16
17
|
route: string;
|
@@ -62,4 +63,5 @@ export default class DripApi {
|
|
62
63
|
getLoyaltyCardBoost(rewardId: string, token: string, headers?: Headers): Promise<number>;
|
63
64
|
getSwapPerqForBeansInfo(): Promise<PerqToBeansSwapInfo>;
|
64
65
|
fetchBeansHistory(walletAddress: string, token: string, headers?: Headers): Promise<BeanEntry[]>;
|
66
|
+
checkTokenStatus(token: string): Promise<AuthenticationStatus>;
|
65
67
|
}
|
package/dist/DripApi.js
CHANGED
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.IMPERSONATOR_HEADER = void 0;
|
13
13
|
const ethers_1 = require("ethers");
|
14
14
|
const DripConfig_1 = require("./DripConfig");
|
15
|
+
const AuthenticationStatus_1 = require("./types/AuthenticationStatus");
|
15
16
|
const WETH_TOKEN_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2';
|
16
17
|
exports.IMPERSONATOR_HEADER = 'impersonatorAddress';
|
17
18
|
const AUTHORIZATION_HEADER = 'Authorization';
|
@@ -524,5 +525,23 @@ class DripApi {
|
|
524
525
|
}
|
525
526
|
});
|
526
527
|
}
|
528
|
+
checkTokenStatus(token) {
|
529
|
+
return __awaiter(this, void 0, void 0, function* () {
|
530
|
+
try {
|
531
|
+
const reqHeaders = new Headers();
|
532
|
+
reqHeaders.append(AUTHORIZATION_HEADER, token);
|
533
|
+
const res = yield fetch(`${this.route}/api-be/auth/validateToken`, {
|
534
|
+
method: 'GET',
|
535
|
+
headers: reqHeaders,
|
536
|
+
});
|
537
|
+
const data = yield res.json();
|
538
|
+
return res.ok ? new AuthenticationStatus_1.ValidStatus(data.address, token) : new AuthenticationStatus_1.ErrorStatus(data.error);
|
539
|
+
}
|
540
|
+
catch (error) {
|
541
|
+
console.log(error);
|
542
|
+
return new AuthenticationStatus_1.ErrorStatus(error === null || error === void 0 ? void 0 : error.message);
|
543
|
+
}
|
544
|
+
});
|
545
|
+
}
|
527
546
|
}
|
528
547
|
exports.default = DripApi;
|
package/dist/DripSdk.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
import { BigNumber, Signer } from 'ethers';
|
2
|
-
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
3
2
|
import { UserRewards } from './types/UserRewards';
|
4
3
|
import { VaultStats } from './types/VaultStats';
|
5
4
|
import { UserBalance } from './types/UserBalance';
|
@@ -13,6 +12,7 @@ import { BeansBalance } from './types/BeansBalance';
|
|
13
12
|
import { PerqToBeansSwapInfo } from './types/PerqToBeansSwapInfo';
|
14
13
|
import BeanEntry from './types/BeanEntry';
|
15
14
|
import { VestingInfo } from './types/VestingInfo';
|
15
|
+
import { AuthenticationStatus } from './types/AuthenticationStatus';
|
16
16
|
export default class DripSdk {
|
17
17
|
private dripApi;
|
18
18
|
private dripTokenContract;
|
package/dist/DripSdk.js
CHANGED
@@ -23,6 +23,7 @@ const DripTokenRecyclerContract_1 = __importDefault(require("./contracts/DripTok
|
|
23
23
|
const DripSwapAndRecyclerContract_1 = __importDefault(require("./contracts/DripSwapAndRecyclerContract"));
|
24
24
|
const PerqVestingContract_1 = __importDefault(require("./contracts/PerqVestingContract"));
|
25
25
|
const utils_1 = require("ethers/lib/utils");
|
26
|
+
const AuthenticationStatus_1 = require("./types/AuthenticationStatus");
|
26
27
|
class DripSdk {
|
27
28
|
constructor(chain, signer, dripRoute) {
|
28
29
|
this.signer = signer;
|
@@ -70,10 +71,7 @@ class DripSdk {
|
|
70
71
|
const userAddress = yield this.signer.getAddress();
|
71
72
|
const cookieName = `auth_${userAddress.toLowerCase()}`;
|
72
73
|
const authToken = js_cookie_1.default.get(cookieName);
|
73
|
-
|
74
|
-
return { isAuthenticated: false, message: 'Auth token not found' };
|
75
|
-
}
|
76
|
-
return { isAuthenticated: true, address: userAddress.toLowerCase(), token: authToken };
|
74
|
+
return !authToken ? new AuthenticationStatus_1.ErrorStatus('Auth token not found') : yield this.dripApi.checkTokenStatus(authToken);
|
77
75
|
});
|
78
76
|
}
|
79
77
|
authenticate() {
|
@@ -1,6 +1,18 @@
|
|
1
|
-
export
|
1
|
+
export interface AuthenticationStatus {
|
2
|
+
message: string;
|
2
3
|
isAuthenticated: boolean;
|
3
4
|
address?: string;
|
4
5
|
token?: string;
|
5
|
-
|
6
|
-
|
6
|
+
}
|
7
|
+
export declare class ValidStatus implements AuthenticationStatus {
|
8
|
+
message: string;
|
9
|
+
isAuthenticated: boolean;
|
10
|
+
address: string;
|
11
|
+
token: string;
|
12
|
+
constructor(address: string, token: string);
|
13
|
+
}
|
14
|
+
export declare class ErrorStatus implements AuthenticationStatus {
|
15
|
+
message: string;
|
16
|
+
isAuthenticated: boolean;
|
17
|
+
constructor(message: string);
|
18
|
+
}
|
@@ -1,2 +1,19 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.ErrorStatus = exports.ValidStatus = void 0;
|
4
|
+
class ValidStatus {
|
5
|
+
constructor(address, token) {
|
6
|
+
this.message = 'Valid Token';
|
7
|
+
this.isAuthenticated = true;
|
8
|
+
this.address = address;
|
9
|
+
this.token = token;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
exports.ValidStatus = ValidStatus;
|
13
|
+
class ErrorStatus {
|
14
|
+
constructor(message) {
|
15
|
+
this.isAuthenticated = false;
|
16
|
+
this.message = message;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
exports.ErrorStatus = ErrorStatus;
|