curtain-web-api 1.0.27 → 1.0.29

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,3 +1,4 @@
1
+ /// <reference types="pouchdb-core" />
1
2
  import { User } from "./curtain-user";
2
3
  export declare const replacer: (key: any, value: any) => any;
3
4
  export declare const reviver: (key: any, value: any) => any;
@@ -13,11 +14,11 @@ export declare class CurtainWebAPI {
13
14
  axiosInstance: import("axios").AxiosInstance;
14
15
  baseURL: string;
15
16
  constructor(baseURL?: string);
16
- login(username: string, password: string): Promise<User>;
17
+ login(username: string, password: string): Promise<PouchDB.Core.Response>;
17
18
  getUserInfo(): Promise<User>;
18
19
  logout(): Promise<void>;
19
20
  refresh(): Promise<import("axios").AxiosResponse<any, any>>;
20
- ORCIDLogin(authorizationCode: string, redirectURI: string): Promise<User>;
21
+ ORCIDLogin(authorizationCode: string, redirectURI: string): Promise<PouchDB.Core.Response>;
21
22
  checkIfRefreshTokenExpired(): boolean;
22
23
  deleteCurtainLink(curtainLinkID: string): Promise<import("axios").AxiosResponse<any, any>>;
23
24
  putSettings(settings: any, enable?: boolean, description?: string, sessionType?: string, onUploadProgress?: any): Promise<import("axios").AxiosResponse<any, any>>;
@@ -139,8 +139,7 @@ class CurtainWebAPI {
139
139
  this.user.access_token = response.data.access;
140
140
  this.user.refresh_token = response.data.refresh;
141
141
  this.user.loginStatus = true;
142
- this.user.saveIntoDB().then();
143
- return this.getUserInfo();
142
+ return this.user.saveIntoDB();
144
143
  });
145
144
  }
146
145
  getUserInfo() {
@@ -188,8 +187,8 @@ class CurtainWebAPI {
188
187
  this.user.access_token = response.data.access;
189
188
  this.user.refresh_token = response.data.refresh;
190
189
  this.user.loginStatus = true;
191
- this.user.saveIntoDB().then();
192
- return this.getUserInfo();
190
+ console.log(this.user.loginStatus);
191
+ return this.user.saveIntoDB();
193
192
  });
194
193
  }
195
194
  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<void | undefined>;
27
+ saveIntoDB(): Promise<PouchDB.Core.Response>;
28
28
  loadFromDB(): Promise<void>;
29
29
  clearDB(): Promise<void>;
30
30
  reset(): void;
@@ -87,28 +87,47 @@ class User {
87
87
  });
88
88
  }
89
89
  saveIntoDB() {
90
- return this.db.put({
91
- _id: "user",
92
- access_token: this.access_token,
93
- refresh_token: this.refresh_token,
94
- username: this.username,
95
- loginStatus: this.loginStatus,
96
- isStaff: this.isStaff,
97
- id: this.id,
98
- totalCurtain: this.totalCurtain,
99
- canDelete: this.canDelete,
100
- curtainLinkLimit: this.curtainLinkLimit,
101
- curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
102
- lastAccessTokenUpdate: this.lastAccessTokenUpdate,
103
- lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
104
- }).then((response) => {
105
- console.log(response);
106
- }).catch((error) => {
107
- console.log(error);
108
- console.log(this.loginStatus);
109
- if (error.name === "conflict") {
110
- return this.updateDB();
90
+ console.log(this.loginStatus);
91
+ return this.db.get("user").catch((error) => {
92
+ if (error.name === "not_found") {
93
+ console.log(this.loginStatus);
94
+ return {
95
+ _id: "user",
96
+ access_token: this.access_token,
97
+ refresh_token: this.refresh_token,
98
+ username: this.username,
99
+ loginStatus: this.loginStatus,
100
+ isStaff: this.isStaff,
101
+ id: this.id,
102
+ totalCurtain: this.totalCurtain,
103
+ canDelete: this.canDelete,
104
+ curtainLinkLimit: this.curtainLinkLimit,
105
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
106
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
107
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
108
+ };
111
109
  }
110
+ else {
111
+ throw error;
112
+ }
113
+ }).then((doc) => {
114
+ console.log(this.loginStatus);
115
+ return this.db.put({
116
+ _id: "user",
117
+ _rev: doc._rev,
118
+ access_token: this.access_token,
119
+ refresh_token: this.refresh_token,
120
+ username: this.username,
121
+ loginStatus: this.loginStatus,
122
+ isStaff: this.isStaff,
123
+ id: this.id,
124
+ totalCurtain: this.totalCurtain,
125
+ canDelete: this.canDelete,
126
+ curtainLinkLimit: this.curtainLinkLimit,
127
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
128
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
129
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
130
+ });
112
131
  });
113
132
  }
114
133
  loadFromDB() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "curtain-web-api",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -117,8 +117,7 @@ export class CurtainWebAPI {
117
117
  this.user.access_token = response.data.access;
118
118
  this.user.refresh_token = response.data.refresh;
119
119
  this.user.loginStatus = true;
120
- this.user.saveIntoDB().then();
121
- return this.getUserInfo();
120
+ return this.user.saveIntoDB()
122
121
  });
123
122
  }
124
123
 
@@ -172,8 +171,8 @@ export class CurtainWebAPI {
172
171
  this.user.access_token = response.data.access;
173
172
  this.user.refresh_token = response.data.refresh;
174
173
  this.user.loginStatus = true;
175
- this.user.saveIntoDB().then();
176
- return this.getUserInfo();
174
+ console.log(this.user.loginStatus)
175
+ return this.user.saveIntoDB()
177
176
  })
178
177
  }
179
178
 
@@ -95,29 +95,47 @@ export class User {
95
95
  }
96
96
 
97
97
  saveIntoDB() {
98
- return this.db.put({
99
- _id: "user",
100
- access_token: this.access_token,
101
- refresh_token: this.refresh_token,
102
- username: this.username,
103
- loginStatus: this.loginStatus,
104
- isStaff: this.isStaff,
105
- id: this.id,
106
- totalCurtain: this.totalCurtain,
107
- canDelete: this.canDelete,
108
- curtainLinkLimit: this.curtainLinkLimit,
109
- curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
110
- lastAccessTokenUpdate: this.lastAccessTokenUpdate,
111
- lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
112
- }).then((response) => {
113
- console.log(response);
114
- }).catch((error) => {
115
- console.log(error);
116
- console.log(this.loginStatus);
117
- if (error.name === "conflict") {
118
- return this.updateDB();
98
+ console.log(this.loginStatus)
99
+ return this.db.get("user").catch((error) => {
100
+ if (error.name === "not_found") {
101
+ console.log(this.loginStatus)
102
+ return {
103
+ _id: "user",
104
+ access_token: this.access_token,
105
+ refresh_token: this.refresh_token,
106
+ username: this.username,
107
+ loginStatus: this.loginStatus,
108
+ isStaff: this.isStaff,
109
+ id: this.id,
110
+ totalCurtain: this.totalCurtain,
111
+ canDelete: this.canDelete,
112
+ curtainLinkLimit: this.curtainLinkLimit,
113
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
114
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
115
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
119
116
  }
120
- });
117
+ } else {
118
+ throw error
119
+ }
120
+ }).then((doc: any) => {
121
+ console.log(this.loginStatus)
122
+ return this.db.put({
123
+ _id: "user",
124
+ _rev: doc._rev,
125
+ access_token: this.access_token,
126
+ refresh_token: this.refresh_token,
127
+ username: this.username,
128
+ loginStatus: this.loginStatus,
129
+ isStaff: this.isStaff,
130
+ id: this.id,
131
+ totalCurtain: this.totalCurtain,
132
+ canDelete: this.canDelete,
133
+ curtainLinkLimit: this.curtainLinkLimit,
134
+ curtainLinkLimitExceeded: this.curtainLinkLimitExceeded,
135
+ lastAccessTokenUpdate: this.lastAccessTokenUpdate,
136
+ lastRefreshTokenUpdate: this.lastRefreshTokenUpdate
137
+ })
138
+ })
121
139
  }
122
140
 
123
141
  loadFromDB() {