curtain-web-api 1.0.29 → 1.0.31
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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="pouchdb-core" />
|
|
2
1
|
import { User } from "./curtain-user";
|
|
3
2
|
export declare const replacer: (key: any, value: any) => any;
|
|
4
3
|
export declare const reviver: (key: any, value: any) => any;
|
|
@@ -14,11 +13,11 @@ export declare class CurtainWebAPI {
|
|
|
14
13
|
axiosInstance: import("axios").AxiosInstance;
|
|
15
14
|
baseURL: string;
|
|
16
15
|
constructor(baseURL?: string);
|
|
17
|
-
login(username: string, password: string): Promise<
|
|
16
|
+
login(username: string, password: string): Promise<User>;
|
|
18
17
|
getUserInfo(): Promise<User>;
|
|
19
18
|
logout(): Promise<void>;
|
|
20
19
|
refresh(): Promise<import("axios").AxiosResponse<any, any>>;
|
|
21
|
-
ORCIDLogin(authorizationCode: string, redirectURI: string): Promise<
|
|
20
|
+
ORCIDLogin(authorizationCode: string, redirectURI: string): Promise<User>;
|
|
22
21
|
checkIfRefreshTokenExpired(): boolean;
|
|
23
22
|
deleteCurtainLink(curtainLinkID: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
24
23
|
putSettings(settings: any, enable?: boolean, description?: string, sessionType?: string, onUploadProgress?: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
@@ -136,16 +136,17 @@ class CurtainWebAPI {
|
|
|
136
136
|
headers["Content-Type"] = "application/json";
|
|
137
137
|
headers["withCredentials"] = "true";
|
|
138
138
|
return this.axiosInstance.post(this.loginURL, { username, password }, { headers: headers, responseType: "json" }).then((response) => {
|
|
139
|
-
this.user.access_token = response.data.access;
|
|
140
|
-
this.user.refresh_token = response.data.refresh;
|
|
141
139
|
this.user.loginStatus = true;
|
|
142
|
-
return this.user.saveIntoDB()
|
|
140
|
+
return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
|
|
141
|
+
return this.getUserInfo();
|
|
142
|
+
});
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
getUserInfo() {
|
|
146
146
|
const headers = new axios_1.AxiosHeaders();
|
|
147
147
|
headers["Accept"] = "application/json";
|
|
148
148
|
headers["Content-Type"] = "application/json";
|
|
149
|
+
console.log(this.user);
|
|
149
150
|
return this.axiosInstance.post(this.userInfoURL, {}, { headers: headers, responseType: "json" }).then((response) => {
|
|
150
151
|
this.user.canDelete = response.data.can_delete;
|
|
151
152
|
this.user.id = response.data.id;
|
|
@@ -184,11 +185,9 @@ class CurtainWebAPI {
|
|
|
184
185
|
headers["Accept"] = "application/json";
|
|
185
186
|
headers["Content-Type"] = "application/json";
|
|
186
187
|
return this.axiosInstance.post(this.orcidLoginURL, JSON.stringify({ "auth_token": authorizationCode, "redirect_uri": redirectURI }), { headers: headers, responseType: "json" }).then((response) => {
|
|
187
|
-
this.user.
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
console.log(this.user.loginStatus);
|
|
191
|
-
return this.user.saveIntoDB();
|
|
188
|
+
return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
|
|
189
|
+
return this.getUserInfo();
|
|
190
|
+
});
|
|
192
191
|
});
|
|
193
192
|
}
|
|
194
193
|
checkIfRefreshTokenExpired() {
|
|
@@ -24,7 +24,7 @@ export declare class User {
|
|
|
24
24
|
init(): Promise<void | undefined>;
|
|
25
25
|
initiateDB(): Promise<void>;
|
|
26
26
|
updateDB(): Promise<void>;
|
|
27
|
-
saveIntoDB(): Promise<PouchDB.Core.Response>;
|
|
27
|
+
saveIntoDB(accessToken: string, refreshToken: string): Promise<PouchDB.Core.Response>;
|
|
28
28
|
loadFromDB(): Promise<void>;
|
|
29
29
|
clearDB(): Promise<void>;
|
|
30
30
|
reset(): void;
|
|
@@ -86,17 +86,18 @@ class User {
|
|
|
86
86
|
console.log(error);
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
saveIntoDB() {
|
|
90
|
-
|
|
89
|
+
saveIntoDB(accessToken, refreshToken) {
|
|
90
|
+
this.access_token = accessToken;
|
|
91
|
+
this.refresh_token = refreshToken;
|
|
92
|
+
this.loginStatus = true;
|
|
91
93
|
return this.db.get("user").catch((error) => {
|
|
92
94
|
if (error.name === "not_found") {
|
|
93
|
-
console.log(this.loginStatus);
|
|
94
95
|
return {
|
|
95
96
|
_id: "user",
|
|
96
|
-
access_token:
|
|
97
|
-
refresh_token:
|
|
97
|
+
access_token: accessToken,
|
|
98
|
+
refresh_token: refreshToken,
|
|
98
99
|
username: this.username,
|
|
99
|
-
loginStatus:
|
|
100
|
+
loginStatus: true,
|
|
100
101
|
isStaff: this.isStaff,
|
|
101
102
|
id: this.id,
|
|
102
103
|
totalCurtain: this.totalCurtain,
|
|
@@ -111,14 +112,13 @@ class User {
|
|
|
111
112
|
throw error;
|
|
112
113
|
}
|
|
113
114
|
}).then((doc) => {
|
|
114
|
-
console.log(this.loginStatus);
|
|
115
115
|
return this.db.put({
|
|
116
116
|
_id: "user",
|
|
117
117
|
_rev: doc._rev,
|
|
118
|
-
access_token:
|
|
119
|
-
refresh_token:
|
|
118
|
+
access_token: accessToken,
|
|
119
|
+
refresh_token: refreshToken,
|
|
120
120
|
username: this.username,
|
|
121
|
-
loginStatus:
|
|
121
|
+
loginStatus: true,
|
|
122
122
|
isStaff: this.isStaff,
|
|
123
123
|
id: this.id,
|
|
124
124
|
totalCurtain: this.totalCurtain,
|
package/package.json
CHANGED
|
@@ -114,10 +114,10 @@ export class CurtainWebAPI {
|
|
|
114
114
|
headers["Content-Type"] = "application/json";
|
|
115
115
|
headers["withCredentials"] = "true";
|
|
116
116
|
return this.axiosInstance.post(this.loginURL, {username, password}, {headers: headers, responseType:"json"}).then((response) => {
|
|
117
|
-
this.user.access_token = response.data.access;
|
|
118
|
-
this.user.refresh_token = response.data.refresh;
|
|
119
117
|
this.user.loginStatus = true;
|
|
120
|
-
return this.user.saveIntoDB()
|
|
118
|
+
return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
|
|
119
|
+
return this.getUserInfo()
|
|
120
|
+
})
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
123
|
|
|
@@ -125,7 +125,7 @@ export class CurtainWebAPI {
|
|
|
125
125
|
const headers = new AxiosHeaders();
|
|
126
126
|
headers["Accept"] = "application/json";
|
|
127
127
|
headers["Content-Type"] = "application/json";
|
|
128
|
-
|
|
128
|
+
console.log(this.user)
|
|
129
129
|
return this.axiosInstance.post(this.userInfoURL, {}, {headers: headers, responseType: "json"}).then((response) => {
|
|
130
130
|
this.user.canDelete = response.data.can_delete;
|
|
131
131
|
this.user.id = response.data.id;
|
|
@@ -168,11 +168,9 @@ export class CurtainWebAPI {
|
|
|
168
168
|
headers["Accept"] = "application/json";
|
|
169
169
|
headers["Content-Type"] = "application/json";
|
|
170
170
|
return this.axiosInstance.post(this.orcidLoginURL, JSON.stringify({"auth_token": authorizationCode, "redirect_uri": redirectURI}), {headers: headers, responseType:"json"}).then((response) => {
|
|
171
|
-
this.user.
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
console.log(this.user.loginStatus)
|
|
175
|
-
return this.user.saveIntoDB()
|
|
171
|
+
return this.user.saveIntoDB(response.data.access, response.data.refresh).then((response) => {
|
|
172
|
+
return this.getUserInfo()
|
|
173
|
+
})
|
|
176
174
|
})
|
|
177
175
|
}
|
|
178
176
|
|
|
@@ -94,17 +94,18 @@ export class User {
|
|
|
94
94
|
});
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
saveIntoDB() {
|
|
98
|
-
|
|
97
|
+
saveIntoDB(accessToken: string, refreshToken: string) {
|
|
98
|
+
this.access_token = accessToken;
|
|
99
|
+
this.refresh_token = refreshToken;
|
|
100
|
+
this.loginStatus = true;
|
|
99
101
|
return this.db.get("user").catch((error) => {
|
|
100
102
|
if (error.name === "not_found") {
|
|
101
|
-
console.log(this.loginStatus)
|
|
102
103
|
return {
|
|
103
104
|
_id: "user",
|
|
104
|
-
access_token:
|
|
105
|
-
refresh_token:
|
|
105
|
+
access_token: accessToken,
|
|
106
|
+
refresh_token: refreshToken,
|
|
106
107
|
username: this.username,
|
|
107
|
-
loginStatus:
|
|
108
|
+
loginStatus: true,
|
|
108
109
|
isStaff: this.isStaff,
|
|
109
110
|
id: this.id,
|
|
110
111
|
totalCurtain: this.totalCurtain,
|
|
@@ -118,14 +119,13 @@ export class User {
|
|
|
118
119
|
throw error
|
|
119
120
|
}
|
|
120
121
|
}).then((doc: any) => {
|
|
121
|
-
console.log(this.loginStatus)
|
|
122
122
|
return this.db.put({
|
|
123
123
|
_id: "user",
|
|
124
124
|
_rev: doc._rev,
|
|
125
|
-
access_token:
|
|
126
|
-
refresh_token:
|
|
125
|
+
access_token: accessToken,
|
|
126
|
+
refresh_token: refreshToken,
|
|
127
127
|
username: this.username,
|
|
128
|
-
loginStatus:
|
|
128
|
+
loginStatus: true,
|
|
129
129
|
isStaff: this.isStaff,
|
|
130
130
|
id: this.id,
|
|
131
131
|
totalCurtain: this.totalCurtain,
|