curtain-web-api 1.0.0 → 1.0.1

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.
@@ -135,7 +135,6 @@ class CurtainWebAPI {
135
135
  headers["Content-Type"] = "application/json";
136
136
  return this.axiosInstance.post(this.logoutURL, { refresh_token: this.user.refresh_token }, { headers: headers, responseType: "json" }).then((response) => {
137
137
  this.user.clearDB();
138
- this.user = new curtain_user_1.User();
139
138
  return response;
140
139
  });
141
140
  }
@@ -167,7 +166,7 @@ class CurtainWebAPI {
167
166
  let now = new Date();
168
167
  let diff = (now.getTime() - this.user.lastRefreshTokenUpdate.getTime()) / 1000;
169
168
  diff = diff / 60 / 60;
170
- return 24 > Math.abs(Math.round(diff));
169
+ return 24 <= Math.abs(Math.round(diff));
171
170
  }
172
171
  deleteCurtainLink(curtainLinkID) {
173
172
  let headers = new axios_1.AxiosHeaders();
@@ -27,4 +27,5 @@ export declare class User {
27
27
  saveIntoDB(): Promise<void>;
28
28
  loadFromDB(): Promise<void>;
29
29
  clearDB(): Promise<void>;
30
+ reset(): void;
30
31
  }
@@ -127,11 +127,26 @@ class User {
127
127
  }
128
128
  clearDB() {
129
129
  return this.db.destroy().then((response) => {
130
+ this.reset();
130
131
  this.db = new pouchdb_1.default("curtainuser");
131
132
  return this.initiateDB();
132
133
  }).catch((error) => {
133
134
  console.log(error);
134
135
  });
135
136
  }
137
+ reset() {
138
+ this.access_token = "";
139
+ this.refresh_token = "";
140
+ this.username = "";
141
+ this.loginStatus = false;
142
+ this.isStaff = false;
143
+ this.id = 0;
144
+ this.totalCurtain = 0;
145
+ this.canDelete = false;
146
+ this.curtainLinkLimit = 0;
147
+ this.curtainLinkLimitExceeded = false;
148
+ this.lastAccessTokenUpdate = new Date();
149
+ this.lastRefreshTokenUpdate = new Date();
150
+ }
136
151
  }
137
152
  exports.User = User;
Binary file
package/curtainuser/LOG CHANGED
@@ -1 +1 @@
1
- 2023/04/15-16:03:03.770 2568 Delete type=3 #1
1
+ 2023/04/15-17:11:29.479 8a10 Delete type=3 #1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "curtain-web-api",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -117,7 +117,6 @@ export class CurtainWebAPI {
117
117
  headers["Content-Type"] = "application/json";
118
118
  return this.axiosInstance.post(this.logoutURL, {refresh_token: this.user.refresh_token}, {headers: headers, responseType:"json"}).then((response) => {
119
119
  this.user.clearDB();
120
- this.user = new User();
121
120
  return response;
122
121
  });
123
122
  }
@@ -152,7 +151,7 @@ export class CurtainWebAPI {
152
151
  let now = new Date();
153
152
  let diff = (now.getTime() - this.user.lastRefreshTokenUpdate.getTime()) / 1000;
154
153
  diff = diff/60/60;
155
- return 24 > Math.abs(Math.round(diff));
154
+ return 24 <= Math.abs(Math.round(diff));
156
155
  }
157
156
 
158
157
  deleteCurtainLink(curtainLinkID: string) {
@@ -137,10 +137,26 @@ export class User {
137
137
 
138
138
  clearDB() {
139
139
  return this.db.destroy().then((response) => {
140
+ this.reset()
140
141
  this.db = new PouchDB("curtainuser");
141
142
  return this.initiateDB();
142
143
  }).catch((error) => {
143
144
  console.log(error);
144
145
  });
145
146
  }
147
+
148
+ reset() {
149
+ this.access_token = "";
150
+ this.refresh_token = "";
151
+ this.username = "";
152
+ this.loginStatus = false;
153
+ this.isStaff = false;
154
+ this.id = 0;
155
+ this.totalCurtain = 0;
156
+ this.canDelete = false;
157
+ this.curtainLinkLimit = 0;
158
+ this.curtainLinkLimitExceeded = false;
159
+ this.lastAccessTokenUpdate = new Date();
160
+ this.lastRefreshTokenUpdate = new Date();
161
+ }
146
162
  }
@@ -34,6 +34,19 @@ describe('User', function () {
34
34
  await user.clearDB();
35
35
  await Promise.resolve()
36
36
 
37
+ assert.ok(true)
38
+ });
39
+ it("destroying user data from local storage", async () => {
40
+ const user = new User();
41
+ await user.init();
42
+ for (const i in userEx) {
43
+ user[i] = userEx[i]
44
+ }
45
+ await user.updateDB();
46
+ await user.clearDB();
47
+ await user.loadFromDB();
48
+ expect(user.username).to.equal("");
49
+ await Promise.resolve()
37
50
  assert.ok(true)
38
51
  })
39
52
  })
@@ -66,6 +79,7 @@ describe("Login", () => {
66
79
  it("check token expiry", async () => {
67
80
  const curtainLogin = new CurtainWebAPI();
68
81
  await curtainLogin.user.loadFromDB()
82
+ console.log(curtainLogin.user.lastRefreshTokenUpdate)
69
83
  const expired = curtainLogin.checkIfRefreshTokenExpired()
70
84
  expect(expired).to.equal(false)
71
85
  await Promise.resolve()
@@ -75,11 +89,16 @@ describe("Login", () => {
75
89
  })
76
90
 
77
91
  describe("Session data", () => {
92
+ it('should retrieve session meta data', async () => {
93
+ const curtainLogin = new CurtainWebAPI();
94
+ const result = await curtainLogin.getSessionSettings("546c9ed7-30a6-4a0f-aedb-880815eb7051")
95
+ });
96
+
78
97
  it('should retrieve session data', async () => {
79
98
  const curtainLogin = new CurtainWebAPI();
80
99
  const result = await curtainLogin.postSettings("546c9ed7-30a6-4a0f-aedb-880815eb7051", "")
81
- console.log(result)
82
100
  })
101
+
83
102
  });
84
103
 
85
104