ggez-banking-sdk 0.1.169 → 0.1.170
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,32 +1,44 @@
|
|
|
1
|
-
import { USR } from "../../types";
|
|
1
|
+
import { CredentialsCookies, USR } from "../../types";
|
|
2
2
|
declare class CookiesHelper {
|
|
3
|
+
private key;
|
|
4
|
+
private eventHandlers;
|
|
3
5
|
private domain;
|
|
4
6
|
private programId;
|
|
7
|
+
private Cookies;
|
|
5
8
|
constructor(programId: string);
|
|
6
|
-
GetIID(): string
|
|
7
|
-
SetIID(): string
|
|
8
|
-
ValidateIID(IID: string): string
|
|
9
|
-
isIIDValid(IID: string): boolean
|
|
10
|
-
GetDEK(): string
|
|
11
|
-
SetDEK(deviceEncryptionKey: string, USR: USR): void
|
|
12
|
-
ValidateDEK(DEK: string): string
|
|
13
|
-
GetUSR(): USR
|
|
14
|
-
SetUSR(deviceId: string, userId: string): void
|
|
15
|
-
ValidateUSR(USR: string): string
|
|
16
|
-
GetDeviceSecurityCode(): string
|
|
17
|
-
GetAccessToken(): string
|
|
18
|
-
SetAccessToken(accessToken: string, expires:
|
|
19
|
-
ValidateAccessToken(accessToken: string): string
|
|
20
|
-
GetJWTToken(): string
|
|
9
|
+
GetIID(): Promise<string>;
|
|
10
|
+
SetIID(): Promise<string>;
|
|
11
|
+
ValidateIID(IID: string): Promise<string>;
|
|
12
|
+
isIIDValid(IID: string): Promise<boolean>;
|
|
13
|
+
GetDEK(): Promise<string>;
|
|
14
|
+
SetDEK(deviceEncryptionKey: string, USR: USR): Promise<void>;
|
|
15
|
+
ValidateDEK(DEK: string): Promise<string>;
|
|
16
|
+
GetUSR(): Promise<USR>;
|
|
17
|
+
SetUSR(deviceId: string, userId: string): Promise<void>;
|
|
18
|
+
ValidateUSR(USR: string): Promise<string>;
|
|
19
|
+
GetDeviceSecurityCode(): Promise<string>;
|
|
20
|
+
GetAccessToken(): Promise<string>;
|
|
21
|
+
SetAccessToken(accessToken: string, expires: number): Promise<void>;
|
|
22
|
+
ValidateAccessToken(accessToken: string): Promise<string>;
|
|
23
|
+
GetJWTToken(): Promise<string>;
|
|
21
24
|
SetJWTToken(jwtToken: string): void;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
GET(key: string): Promise<string>;
|
|
26
|
+
SET(key: string, value: string, expires?: number): Promise<void>;
|
|
27
|
+
REMOVE(key: string): Promise<void>;
|
|
28
|
+
cookieEventHandler(e: CookieChangeEvent, params: ChangeEventParameters): Promise<void>;
|
|
29
|
+
onChangeHandler(changed: CookieInit[], params: ChangeEventParameters): Promise<void>;
|
|
30
|
+
onDeleteHandler(deleted: CookieInit[], params: ChangeEventParameters): Promise<void>;
|
|
31
|
+
addOnChangeEventListener(params: ChangeEventParameters): void;
|
|
32
|
+
removeOnChangeEventListener(): void;
|
|
33
|
+
IsAuthenticated(): Promise<boolean>;
|
|
34
|
+
GetCredentialsCookies(): Promise<CredentialsCookies>;
|
|
31
35
|
}
|
|
36
|
+
type ChangeEventParameters = {
|
|
37
|
+
IID: EventCallback;
|
|
38
|
+
USR: EventCallback;
|
|
39
|
+
DEK: EventCallback;
|
|
40
|
+
accessToken: EventCallback;
|
|
41
|
+
jwtToken: EventCallback;
|
|
42
|
+
};
|
|
43
|
+
type EventCallback = (eventType: "change" | "delete") => void;
|
|
32
44
|
export { CookiesHelper };
|
|
@@ -1,23 +1,27 @@
|
|
|
1
1
|
import { v4 } from "uuid";
|
|
2
|
-
import
|
|
3
|
-
import { CipherHelper } from "..";
|
|
2
|
+
import { CipherHelper } from "../cipherHelper";
|
|
4
3
|
class CookiesHelper {
|
|
5
4
|
// #region "Properties"
|
|
5
|
+
key;
|
|
6
|
+
eventHandlers = new Map();
|
|
6
7
|
domain = "";
|
|
7
8
|
programId = "0";
|
|
9
|
+
Cookies = window.cookieStore;
|
|
8
10
|
// #endregion
|
|
9
11
|
// #region "Constructor"
|
|
10
12
|
constructor(programId) {
|
|
11
13
|
this.domain = window.location.hostname;
|
|
12
14
|
this.programId = programId;
|
|
15
|
+
this.Cookies = window.cookieStore;
|
|
16
|
+
this.key = v4();
|
|
13
17
|
}
|
|
14
18
|
// #endregion
|
|
15
19
|
// #region "IID"
|
|
16
|
-
GetIID() {
|
|
20
|
+
async GetIID() {
|
|
17
21
|
try {
|
|
18
|
-
const IID = this.GET("IID");
|
|
22
|
+
const IID = await this.GET("IID");
|
|
19
23
|
if (!IID) {
|
|
20
|
-
return this.SetIID();
|
|
24
|
+
return await this.SetIID();
|
|
21
25
|
}
|
|
22
26
|
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
23
27
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
@@ -25,9 +29,10 @@ class CookiesHelper {
|
|
|
25
29
|
}
|
|
26
30
|
catch (error) {
|
|
27
31
|
console.error(error);
|
|
32
|
+
return "";
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
|
-
SetIID() {
|
|
35
|
+
async SetIID() {
|
|
31
36
|
try {
|
|
32
37
|
const IID = v4();
|
|
33
38
|
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
@@ -37,9 +42,10 @@ class CookiesHelper {
|
|
|
37
42
|
}
|
|
38
43
|
catch (error) {
|
|
39
44
|
console.error(error);
|
|
45
|
+
return "";
|
|
40
46
|
}
|
|
41
47
|
}
|
|
42
|
-
ValidateIID(IID) {
|
|
48
|
+
async ValidateIID(IID) {
|
|
43
49
|
try {
|
|
44
50
|
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
45
51
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
@@ -49,11 +55,12 @@ class CookiesHelper {
|
|
|
49
55
|
console.error(error);
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
|
-
isIIDValid(IID) {
|
|
58
|
+
async isIIDValid(IID) {
|
|
53
59
|
try {
|
|
54
60
|
const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
|
|
55
61
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
56
|
-
|
|
62
|
+
const currentIID = await this.GetIID();
|
|
63
|
+
return decryptedIID == currentIID;
|
|
57
64
|
}
|
|
58
65
|
catch (error) {
|
|
59
66
|
console.error(error);
|
|
@@ -61,12 +68,12 @@ class CookiesHelper {
|
|
|
61
68
|
}
|
|
62
69
|
// #endregion
|
|
63
70
|
// #region "DEK"
|
|
64
|
-
GetDEK() {
|
|
71
|
+
async GetDEK() {
|
|
65
72
|
try {
|
|
66
|
-
const IID = this.GetIID();
|
|
67
|
-
const DEK = this.GET("DEK");
|
|
68
|
-
const USR = this.GetUSR();
|
|
69
|
-
if (!DEK || !USR) {
|
|
73
|
+
const IID = await this.GetIID();
|
|
74
|
+
const DEK = await this.GET("DEK");
|
|
75
|
+
const USR = await this.GetUSR();
|
|
76
|
+
if (!DEK || !USR || !IID) {
|
|
70
77
|
return "";
|
|
71
78
|
}
|
|
72
79
|
const { key, iv } = CipherHelper.GenerateByUSRAndIID(USR, IID);
|
|
@@ -78,27 +85,29 @@ class CookiesHelper {
|
|
|
78
85
|
console.error(error);
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
|
-
SetDEK(deviceEncryptionKey, USR) {
|
|
88
|
+
async SetDEK(deviceEncryptionKey, USR) {
|
|
82
89
|
try {
|
|
83
|
-
const IID = this.GetIID();
|
|
90
|
+
const IID = await this.GetIID();
|
|
91
|
+
if (!USR || !IID)
|
|
92
|
+
return;
|
|
84
93
|
const { user_id } = USR;
|
|
85
94
|
const { key, iv } = CipherHelper.GenerateByUSRAndIID(USR, IID);
|
|
86
95
|
if (deviceEncryptionKey) {
|
|
87
96
|
const cipherKeys = CipherHelper.GenerateByUserID(user_id);
|
|
88
97
|
const encryptionKey = CipherHelper.Decrypt(deviceEncryptionKey, cipherKeys.key, cipherKeys.iv);
|
|
89
98
|
const DEK = CipherHelper.Encrypt(encryptionKey, key, iv);
|
|
90
|
-
this.SET("DEK", DEK);
|
|
99
|
+
await this.SET("DEK", DEK);
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
catch (error) {
|
|
94
103
|
console.error(error);
|
|
95
104
|
}
|
|
96
105
|
}
|
|
97
|
-
ValidateDEK(DEK) {
|
|
106
|
+
async ValidateDEK(DEK) {
|
|
98
107
|
try {
|
|
99
|
-
const IID = this.GetIID();
|
|
100
|
-
const USR = this.GetUSR();
|
|
101
|
-
if (!DEK || !USR)
|
|
108
|
+
const IID = await this.GetIID();
|
|
109
|
+
const USR = await this.GetUSR();
|
|
110
|
+
if (!DEK || !USR || !IID)
|
|
102
111
|
return null;
|
|
103
112
|
const { key, iv } = CipherHelper.GenerateByUSRAndIID(USR, IID);
|
|
104
113
|
const decryptedDEK = CipherHelper.Decrypt(DEK, key, iv);
|
|
@@ -110,38 +119,41 @@ class CookiesHelper {
|
|
|
110
119
|
}
|
|
111
120
|
// #endregion
|
|
112
121
|
// #region "USR"
|
|
113
|
-
GetUSR() {
|
|
122
|
+
async GetUSR() {
|
|
114
123
|
try {
|
|
115
|
-
const IID = this.GetIID();
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
if (!USR)
|
|
124
|
+
const IID = await this.GetIID();
|
|
125
|
+
const USR = await this.GET("USR");
|
|
126
|
+
if (!IID || !USR)
|
|
119
127
|
return null;
|
|
128
|
+
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
120
129
|
const decryptedUSR = CipherHelper.Decrypt(USR, key, iv);
|
|
121
130
|
return JSON.parse(decryptedUSR);
|
|
122
131
|
}
|
|
123
132
|
catch (error) {
|
|
124
133
|
console.error(error);
|
|
134
|
+
return null;
|
|
125
135
|
}
|
|
126
136
|
}
|
|
127
|
-
SetUSR(deviceId, userId) {
|
|
137
|
+
async SetUSR(deviceId, userId) {
|
|
128
138
|
try {
|
|
129
|
-
const IID = this.GetIID();
|
|
139
|
+
const IID = await this.GetIID();
|
|
140
|
+
if (!IID)
|
|
141
|
+
return;
|
|
130
142
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
131
143
|
const USR = JSON.stringify({
|
|
132
144
|
device_id: deviceId,
|
|
133
145
|
user_id: userId,
|
|
134
146
|
});
|
|
135
147
|
const encryptedUSR = CipherHelper.Encrypt(USR, key, iv);
|
|
136
|
-
this.SET("USR", encryptedUSR);
|
|
148
|
+
await this.SET("USR", encryptedUSR);
|
|
137
149
|
}
|
|
138
150
|
catch (error) {
|
|
139
151
|
console.error(error);
|
|
140
152
|
}
|
|
141
153
|
}
|
|
142
|
-
ValidateUSR(USR) {
|
|
154
|
+
async ValidateUSR(USR) {
|
|
143
155
|
try {
|
|
144
|
-
const IID = this.GetIID();
|
|
156
|
+
const IID = await this.GetIID();
|
|
145
157
|
if (!IID)
|
|
146
158
|
return null;
|
|
147
159
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -154,11 +166,11 @@ class CookiesHelper {
|
|
|
154
166
|
}
|
|
155
167
|
// #endregion
|
|
156
168
|
// #region "Device Security Code"
|
|
157
|
-
GetDeviceSecurityCode() {
|
|
169
|
+
async GetDeviceSecurityCode() {
|
|
158
170
|
try {
|
|
159
|
-
const IID = this.GetIID();
|
|
160
|
-
const DEK = this.GetDEK();
|
|
161
|
-
const USR = this.GetUSR();
|
|
171
|
+
const IID = await this.GetIID();
|
|
172
|
+
const DEK = await this.GetDEK();
|
|
173
|
+
const USR = await this.GetUSR();
|
|
162
174
|
if (!DEK || !USR) {
|
|
163
175
|
return "";
|
|
164
176
|
}
|
|
@@ -169,17 +181,18 @@ class CookiesHelper {
|
|
|
169
181
|
}
|
|
170
182
|
catch (error) {
|
|
171
183
|
console.error(error);
|
|
184
|
+
return "";
|
|
172
185
|
}
|
|
173
186
|
}
|
|
174
187
|
// #endregion
|
|
175
188
|
// #region "Access Token"
|
|
176
|
-
GetAccessToken() {
|
|
189
|
+
async GetAccessToken() {
|
|
177
190
|
try {
|
|
178
|
-
const IID = this.GetIID();
|
|
179
|
-
const
|
|
180
|
-
|
|
181
|
-
if (!accessToken)
|
|
191
|
+
const IID = await this.GetIID();
|
|
192
|
+
const accessToken = await this.GET("access_token");
|
|
193
|
+
if (!accessToken || !IID)
|
|
182
194
|
return "";
|
|
195
|
+
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
183
196
|
const decryptedAccessToken = CipherHelper.Decrypt(accessToken, key, iv);
|
|
184
197
|
return decryptedAccessToken;
|
|
185
198
|
}
|
|
@@ -187,20 +200,22 @@ class CookiesHelper {
|
|
|
187
200
|
console.error(error);
|
|
188
201
|
}
|
|
189
202
|
}
|
|
190
|
-
SetAccessToken(accessToken, expires) {
|
|
203
|
+
async SetAccessToken(accessToken, expires) {
|
|
191
204
|
try {
|
|
192
|
-
const IID = this.GetIID();
|
|
205
|
+
const IID = await this.GetIID();
|
|
206
|
+
if (!IID)
|
|
207
|
+
return;
|
|
193
208
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
194
209
|
const encryptedAccessToken = CipherHelper.Encrypt(accessToken, key, iv);
|
|
195
|
-
this.SET("access_token", encryptedAccessToken, expires);
|
|
210
|
+
await this.SET("access_token", encryptedAccessToken, expires);
|
|
196
211
|
}
|
|
197
212
|
catch (error) {
|
|
198
213
|
console.error(error);
|
|
199
214
|
}
|
|
200
215
|
}
|
|
201
|
-
ValidateAccessToken(accessToken) {
|
|
216
|
+
async ValidateAccessToken(accessToken) {
|
|
202
217
|
try {
|
|
203
|
-
const IID = this.GetIID();
|
|
218
|
+
const IID = await this.GetIID();
|
|
204
219
|
if (!IID)
|
|
205
220
|
return null;
|
|
206
221
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -215,13 +230,7 @@ class CookiesHelper {
|
|
|
215
230
|
// #region "JWT Token"
|
|
216
231
|
GetJWTToken() {
|
|
217
232
|
try {
|
|
218
|
-
|
|
219
|
-
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
220
|
-
const jwtToken = this.GET("jwt_token");
|
|
221
|
-
if (!jwtToken)
|
|
222
|
-
return "";
|
|
223
|
-
const decryptedAccessToken = CipherHelper.Decrypt(jwtToken, key, iv);
|
|
224
|
-
return decryptedAccessToken;
|
|
233
|
+
return this.GET("jwt_token");
|
|
225
234
|
}
|
|
226
235
|
catch (error) {
|
|
227
236
|
console.error(error);
|
|
@@ -229,23 +238,7 @@ class CookiesHelper {
|
|
|
229
238
|
}
|
|
230
239
|
SetJWTToken(jwtToken) {
|
|
231
240
|
try {
|
|
232
|
-
|
|
233
|
-
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
234
|
-
const encryptedAccessToken = CipherHelper.Encrypt(jwtToken, key, iv);
|
|
235
|
-
this.SET("jwt_token", encryptedAccessToken);
|
|
236
|
-
}
|
|
237
|
-
catch (error) {
|
|
238
|
-
console.error(error);
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
ValidateJWTToken(jwtToken) {
|
|
242
|
-
try {
|
|
243
|
-
const IID = this.GetIID();
|
|
244
|
-
if (!IID)
|
|
245
|
-
return null;
|
|
246
|
-
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
247
|
-
const decryptedAccessToken = CipherHelper.Decrypt(jwtToken, key, iv);
|
|
248
|
-
return decryptedAccessToken;
|
|
241
|
+
this.SET("jwt_token", jwtToken);
|
|
249
242
|
}
|
|
250
243
|
catch (error) {
|
|
251
244
|
console.error(error);
|
|
@@ -253,85 +246,152 @@ class CookiesHelper {
|
|
|
253
246
|
}
|
|
254
247
|
// #endregion
|
|
255
248
|
// #region "Getters & Setters"
|
|
256
|
-
GET(key) {
|
|
257
|
-
|
|
249
|
+
async GET(key) {
|
|
250
|
+
const cookie = await this.Cookies.get(key);
|
|
251
|
+
return cookie?.value || "";
|
|
258
252
|
}
|
|
259
|
-
SET(key, value, expires) {
|
|
260
|
-
const defaultExpireDate =
|
|
261
|
-
Cookies.set(
|
|
253
|
+
async SET(key, value, expires) {
|
|
254
|
+
const defaultExpireDate = Date.now() + 1000 * 60 * 60 * 24 * 365;
|
|
255
|
+
await this.Cookies.set({
|
|
256
|
+
name: key,
|
|
257
|
+
value: value,
|
|
258
|
+
domain: this.domain,
|
|
259
|
+
expires: expires || defaultExpireDate,
|
|
262
260
|
path: "/",
|
|
263
261
|
sameSite: "lax",
|
|
264
|
-
domain: this.domain || "ggez.one",
|
|
265
|
-
expires: expires || defaultExpireDate,
|
|
266
262
|
});
|
|
267
263
|
}
|
|
268
|
-
REMOVE(key) {
|
|
269
|
-
Cookies.
|
|
264
|
+
async REMOVE(key) {
|
|
265
|
+
await this.Cookies.delete(key);
|
|
270
266
|
}
|
|
271
267
|
// #endregion
|
|
272
268
|
// #region "Cookie Change Event Listener"
|
|
273
|
-
cookieEventHandler(e,
|
|
269
|
+
async cookieEventHandler(e, params) {
|
|
274
270
|
if (e.changed.length > 0) {
|
|
275
|
-
this.onChangeHandler(e.changed,
|
|
271
|
+
await this.onChangeHandler(e.changed, params);
|
|
276
272
|
}
|
|
277
273
|
if (e.deleted.length > 0) {
|
|
278
|
-
this.onDeleteHandler(e.deleted,
|
|
274
|
+
await this.onDeleteHandler(e.deleted, params);
|
|
279
275
|
}
|
|
280
276
|
}
|
|
281
|
-
async onChangeHandler(changed,
|
|
277
|
+
async onChangeHandler(changed, params) {
|
|
278
|
+
const eventType = "change";
|
|
282
279
|
const changedCookie = changed[0];
|
|
283
280
|
switch (changedCookie.name) {
|
|
284
281
|
case "IID":
|
|
285
|
-
const IID = this.GetIID();
|
|
286
|
-
const changedIID = this.ValidateIID(changedCookie.value);
|
|
282
|
+
const IID = await this.GetIID();
|
|
283
|
+
const changedIID = await this.ValidateIID(changedCookie.value);
|
|
287
284
|
if (IID != changedIID) {
|
|
288
|
-
|
|
285
|
+
params.IID(eventType);
|
|
289
286
|
}
|
|
290
287
|
break;
|
|
291
288
|
case "USR":
|
|
292
|
-
const USR = this.GetUSR();
|
|
293
|
-
const changedUSR = this.ValidateUSR(changedCookie.value);
|
|
294
|
-
if (
|
|
295
|
-
|
|
289
|
+
const USR = await this.GetUSR();
|
|
290
|
+
const changedUSR = await this.ValidateUSR(changedCookie.value);
|
|
291
|
+
if (JSON.stringify(USR) != changedUSR) {
|
|
292
|
+
params.USR(eventType);
|
|
296
293
|
}
|
|
297
294
|
break;
|
|
298
295
|
case "DEK":
|
|
299
|
-
const DEK = this.GetDEK();
|
|
300
|
-
const changedDEK = this.ValidateDEK(changedCookie.value);
|
|
296
|
+
const DEK = await this.GetDEK();
|
|
297
|
+
const changedDEK = await this.ValidateDEK(changedCookie.value);
|
|
301
298
|
if (DEK != changedDEK) {
|
|
302
|
-
|
|
299
|
+
params.DEK(eventType);
|
|
303
300
|
}
|
|
304
301
|
break;
|
|
305
302
|
case "access_token":
|
|
306
|
-
const accessToken = this.GetAccessToken();
|
|
307
|
-
|
|
303
|
+
const accessToken = await this.GetAccessToken();
|
|
304
|
+
console.log("🚀 ~ CookiesHelper ~ onChangeHandler ~ accessToken:", accessToken);
|
|
305
|
+
const changedAccessToken = await this.ValidateAccessToken(changedCookie.value);
|
|
306
|
+
console.log("🚀 ~ CookiesHelper ~ onChangeHandler ~ changedAccessToken:", changedAccessToken);
|
|
308
307
|
if (accessToken != changedAccessToken) {
|
|
309
|
-
|
|
308
|
+
params.accessToken(eventType);
|
|
310
309
|
}
|
|
311
310
|
break;
|
|
312
311
|
case "jwt_token":
|
|
313
|
-
const jwtToken = this.GetJWTToken();
|
|
314
|
-
const changedJWTToken =
|
|
312
|
+
const jwtToken = await this.GetJWTToken();
|
|
313
|
+
const changedJWTToken = changedCookie.value;
|
|
315
314
|
if (jwtToken != changedJWTToken) {
|
|
316
|
-
|
|
315
|
+
params.jwtToken(eventType);
|
|
317
316
|
}
|
|
318
317
|
break;
|
|
319
318
|
}
|
|
320
319
|
}
|
|
321
|
-
async onDeleteHandler(deleted,
|
|
320
|
+
async onDeleteHandler(deleted, params) {
|
|
321
|
+
const eventType = "delete";
|
|
322
322
|
const deletedCookie = deleted[0];
|
|
323
|
-
|
|
324
|
-
|
|
323
|
+
switch (deletedCookie.name) {
|
|
324
|
+
case "IID":
|
|
325
|
+
params.IID(eventType);
|
|
326
|
+
break;
|
|
327
|
+
case "USR":
|
|
328
|
+
params.USR(eventType);
|
|
329
|
+
break;
|
|
330
|
+
case "DEK":
|
|
331
|
+
params.DEK(eventType);
|
|
332
|
+
break;
|
|
333
|
+
case "access_token":
|
|
334
|
+
params.accessToken(eventType);
|
|
335
|
+
break;
|
|
336
|
+
case "jwt_token":
|
|
337
|
+
params.jwtToken(eventType);
|
|
338
|
+
break;
|
|
325
339
|
}
|
|
326
|
-
|
|
327
|
-
|
|
340
|
+
}
|
|
341
|
+
addOnChangeEventListener(params) {
|
|
342
|
+
const handler = (e) => this.cookieEventHandler(e, params);
|
|
343
|
+
this.eventHandlers.set(this.key, handler);
|
|
344
|
+
this.Cookies.addEventListener("change", handler);
|
|
345
|
+
}
|
|
346
|
+
removeOnChangeEventListener() {
|
|
347
|
+
const handler = this.eventHandlers.get(this.key);
|
|
348
|
+
if (handler) {
|
|
349
|
+
this.Cookies.removeEventListener("change", handler);
|
|
350
|
+
this.eventHandlers.delete(this.key);
|
|
328
351
|
}
|
|
329
352
|
}
|
|
330
|
-
|
|
331
|
-
|
|
353
|
+
// #endregion
|
|
354
|
+
// #region "Checkers"
|
|
355
|
+
async IsAuthenticated() {
|
|
356
|
+
try {
|
|
357
|
+
const IID = await this.GetIID();
|
|
358
|
+
const USR = await this.GetUSR();
|
|
359
|
+
const DEK = await this.GetDEK();
|
|
360
|
+
const accessToken = await this.GetAccessToken();
|
|
361
|
+
const jwtToken = await this.GetJWTToken();
|
|
362
|
+
return !!IID && !!USR && !!DEK && !!accessToken && !!jwtToken;
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
console.error(error);
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
332
368
|
}
|
|
333
|
-
|
|
334
|
-
|
|
369
|
+
async GetCredentialsCookies() {
|
|
370
|
+
try {
|
|
371
|
+
const IID = await this.GetIID();
|
|
372
|
+
const USR = await this.GetUSR();
|
|
373
|
+
const DEK = await this.GetDEK();
|
|
374
|
+
const accessToken = await this.GetAccessToken();
|
|
375
|
+
const jwtToken = await this.GetJWTToken();
|
|
376
|
+
const credentials = {
|
|
377
|
+
IID: IID || "",
|
|
378
|
+
USR: USR || { user_id: "0", device_id: "0" },
|
|
379
|
+
DEK: DEK || "",
|
|
380
|
+
access_token: accessToken || "",
|
|
381
|
+
jwt_token: jwtToken || "",
|
|
382
|
+
};
|
|
383
|
+
return credentials;
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
console.error(error);
|
|
387
|
+
return {
|
|
388
|
+
IID: "",
|
|
389
|
+
USR: { user_id: "0", device_id: "0" },
|
|
390
|
+
DEK: "",
|
|
391
|
+
access_token: "",
|
|
392
|
+
jwt_token: "",
|
|
393
|
+
};
|
|
394
|
+
}
|
|
335
395
|
}
|
|
336
396
|
}
|
|
337
397
|
export { CookiesHelper };
|
|
@@ -2,11 +2,9 @@ import { UserData } from "../../types";
|
|
|
2
2
|
import { CookiesHelper } from "./cookiesHelper";
|
|
3
3
|
declare class LocalStorageHelper {
|
|
4
4
|
cookiesHelper: CookiesHelper;
|
|
5
|
-
programId: string;
|
|
6
|
-
domain: string;
|
|
7
5
|
constructor(programId: string);
|
|
8
|
-
GetUserData(): UserData
|
|
9
|
-
SetUserData(userData: UserData): void
|
|
6
|
+
GetUserData(): Promise<UserData>;
|
|
7
|
+
SetUserData(userData: UserData): Promise<void>;
|
|
10
8
|
GET(key: string): string;
|
|
11
9
|
SET(key: string, value: string): void;
|
|
12
10
|
REMOVE(key: string): void;
|
|
@@ -2,22 +2,24 @@ import { CipherHelper } from "../cipherHelper";
|
|
|
2
2
|
import { CookiesHelper } from "./cookiesHelper";
|
|
3
3
|
class LocalStorageHelper {
|
|
4
4
|
cookiesHelper;
|
|
5
|
-
programId;
|
|
6
|
-
domain;
|
|
7
5
|
// #region "Constructor"
|
|
8
6
|
constructor(programId) {
|
|
9
7
|
this.cookiesHelper = new CookiesHelper(programId);
|
|
10
8
|
}
|
|
11
9
|
// #endregion
|
|
12
10
|
// #region "User Data"
|
|
13
|
-
GetUserData() {
|
|
11
|
+
async GetUserData() {
|
|
14
12
|
try {
|
|
15
|
-
const IID = this.cookiesHelper.GetIID();
|
|
13
|
+
const IID = await this.cookiesHelper.GetIID();
|
|
14
|
+
if (!IID)
|
|
15
|
+
return null;
|
|
16
16
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
17
17
|
const userData = this.GET("CUD");
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
if (userData) {
|
|
19
|
+
const decryptedUserData = CipherHelper.Decrypt(userData, key, iv);
|
|
20
|
+
if (decryptedUserData) {
|
|
21
|
+
return JSON.parse(decryptedUserData);
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
return null;
|
|
23
25
|
}
|
|
@@ -25,9 +27,11 @@ class LocalStorageHelper {
|
|
|
25
27
|
console.error(error);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
|
-
SetUserData(userData) {
|
|
30
|
+
async SetUserData(userData) {
|
|
29
31
|
try {
|
|
30
|
-
const IID = this.cookiesHelper.GetIID();
|
|
32
|
+
const IID = await this.cookiesHelper.GetIID();
|
|
33
|
+
if (!IID)
|
|
34
|
+
return;
|
|
31
35
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
32
36
|
const data = JSON.stringify(userData);
|
|
33
37
|
const encryptedUserData = CipherHelper.Encrypt(data, key, iv);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ggez-banking-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.170",
|
|
4
4
|
"description": "A Node.js package to handle GGEZ Banking API endpoints, Simplify the process of managing CRUD operations with this efficient and easy-to-use package.",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"main": "dist/index.js",
|