ggez-banking-sdk 0.1.150 → 0.1.151
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/helper/cookiesHelper.d.ts +27 -26
- package/dist/helper/cookiesHelper.js +72 -57
- package/package.json +1 -1
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
import { UserData, USR } from "../types";
|
|
2
2
|
declare class CookiesHelper {
|
|
3
|
-
static GetIID
|
|
4
|
-
static SetIID
|
|
5
|
-
static ValidateIID
|
|
6
|
-
static
|
|
7
|
-
static
|
|
8
|
-
static
|
|
9
|
-
static
|
|
10
|
-
static
|
|
11
|
-
static
|
|
12
|
-
static
|
|
13
|
-
static
|
|
14
|
-
static
|
|
15
|
-
static
|
|
16
|
-
static
|
|
17
|
-
static
|
|
18
|
-
static
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static
|
|
22
|
-
static
|
|
23
|
-
static
|
|
24
|
-
static
|
|
25
|
-
static
|
|
26
|
-
static
|
|
27
|
-
static
|
|
28
|
-
static
|
|
3
|
+
static GetIID(): any;
|
|
4
|
+
static SetIID(): void;
|
|
5
|
+
static ValidateIID(IID: string): string;
|
|
6
|
+
static isIIDValid(IID: string): boolean;
|
|
7
|
+
static GetDEK(): string;
|
|
8
|
+
static SetDEK(deviceEncryptionKey: string, USR: USR): void;
|
|
9
|
+
static ValidateDEK(DEK: string): string;
|
|
10
|
+
static GetUSR(): USR;
|
|
11
|
+
static SetUSR(deviceId: string, userId: string): void;
|
|
12
|
+
static ValidateUSR(USR: string): string;
|
|
13
|
+
static GetDeviceSecurityCode(): string;
|
|
14
|
+
static GetAccessToken(): string;
|
|
15
|
+
static SetAccessToken(accessToken: string, expires: Date): void;
|
|
16
|
+
static ValidateAccessToken(accessToken: string): string;
|
|
17
|
+
static GetJWTToken(): string;
|
|
18
|
+
static SetJWTToken(jwtToken: string): void;
|
|
19
|
+
static ValidateJWTToken(jwtToken: string): string;
|
|
20
|
+
static GetUserData(): UserData;
|
|
21
|
+
static SetUserData(userData: UserData): void;
|
|
22
|
+
static GET(key: string): string | undefined;
|
|
23
|
+
static SET(key: string, value: string, expires?: Date): void;
|
|
24
|
+
static REMOVE(key: string): void;
|
|
25
|
+
static cookieEventHandler(e: CookieChangeEvent, callback: () => void): void;
|
|
26
|
+
static onChangeHandler(changed: CookieInit[], callback: () => void): void;
|
|
27
|
+
static onDeleteHandler(deleted: CookieInit[], callback: () => void): void;
|
|
28
|
+
static addOnChangeEventListener(callback: () => void): void;
|
|
29
|
+
static removeOnChangeEventListener(callback: () => void): void;
|
|
29
30
|
}
|
|
30
31
|
export { CookiesHelper };
|
|
@@ -3,7 +3,7 @@ import Cookies from "js-cookie";
|
|
|
3
3
|
import { CipherHelper } from ".";
|
|
4
4
|
class CookiesHelper {
|
|
5
5
|
// #region "IID"
|
|
6
|
-
static GetIID
|
|
6
|
+
static GetIID() {
|
|
7
7
|
try {
|
|
8
8
|
const IID = this.GET("IID");
|
|
9
9
|
if (!IID) {
|
|
@@ -17,8 +17,8 @@ class CookiesHelper {
|
|
|
17
17
|
catch (error) {
|
|
18
18
|
console.error(error);
|
|
19
19
|
}
|
|
20
|
-
}
|
|
21
|
-
static SetIID
|
|
20
|
+
}
|
|
21
|
+
static SetIID() {
|
|
22
22
|
try {
|
|
23
23
|
const IID = v4();
|
|
24
24
|
const { key, iv } = CipherHelper.GenerateByProgramID();
|
|
@@ -28,8 +28,8 @@ class CookiesHelper {
|
|
|
28
28
|
catch (error) {
|
|
29
29
|
console.error(error);
|
|
30
30
|
}
|
|
31
|
-
}
|
|
32
|
-
static ValidateIID
|
|
31
|
+
}
|
|
32
|
+
static ValidateIID(IID) {
|
|
33
33
|
try {
|
|
34
34
|
const { key, iv } = CipherHelper.GenerateByProgramID();
|
|
35
35
|
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
@@ -38,10 +38,20 @@ class CookiesHelper {
|
|
|
38
38
|
catch (error) {
|
|
39
39
|
console.error(error);
|
|
40
40
|
}
|
|
41
|
-
}
|
|
41
|
+
}
|
|
42
|
+
static isIIDValid(IID) {
|
|
43
|
+
try {
|
|
44
|
+
const { key, iv } = CipherHelper.GenerateByProgramID();
|
|
45
|
+
const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
|
|
46
|
+
return decryptedIID == this.GetIID();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error(error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
42
52
|
// #endregion
|
|
43
53
|
// #region "DEK"
|
|
44
|
-
static GetDEK
|
|
54
|
+
static GetDEK() {
|
|
45
55
|
try {
|
|
46
56
|
const IID = this.GetIID();
|
|
47
57
|
const DEK = this.GET("DEK");
|
|
@@ -57,8 +67,8 @@ class CookiesHelper {
|
|
|
57
67
|
catch (error) {
|
|
58
68
|
console.error(error);
|
|
59
69
|
}
|
|
60
|
-
}
|
|
61
|
-
static SetDEK
|
|
70
|
+
}
|
|
71
|
+
static SetDEK(deviceEncryptionKey, USR) {
|
|
62
72
|
try {
|
|
63
73
|
const IID = this.GetIID();
|
|
64
74
|
const { user_id } = USR;
|
|
@@ -73,8 +83,8 @@ class CookiesHelper {
|
|
|
73
83
|
catch (error) {
|
|
74
84
|
console.error(error);
|
|
75
85
|
}
|
|
76
|
-
}
|
|
77
|
-
static ValidateDEK
|
|
86
|
+
}
|
|
87
|
+
static ValidateDEK(DEK) {
|
|
78
88
|
try {
|
|
79
89
|
const IID = this.GetIID();
|
|
80
90
|
const USR = this.GetUSR();
|
|
@@ -87,10 +97,10 @@ class CookiesHelper {
|
|
|
87
97
|
catch (error) {
|
|
88
98
|
console.error(error);
|
|
89
99
|
}
|
|
90
|
-
}
|
|
100
|
+
}
|
|
91
101
|
// #endregion
|
|
92
102
|
// #region "USR"
|
|
93
|
-
static GetUSR
|
|
103
|
+
static GetUSR() {
|
|
94
104
|
try {
|
|
95
105
|
const IID = this.GetIID();
|
|
96
106
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -101,8 +111,8 @@ class CookiesHelper {
|
|
|
101
111
|
catch (error) {
|
|
102
112
|
console.error(error);
|
|
103
113
|
}
|
|
104
|
-
}
|
|
105
|
-
static SetUSR
|
|
114
|
+
}
|
|
115
|
+
static SetUSR(deviceId, userId) {
|
|
106
116
|
try {
|
|
107
117
|
const IID = this.GetIID();
|
|
108
118
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -116,8 +126,8 @@ class CookiesHelper {
|
|
|
116
126
|
catch (error) {
|
|
117
127
|
console.error(error);
|
|
118
128
|
}
|
|
119
|
-
}
|
|
120
|
-
static ValidateUSR
|
|
129
|
+
}
|
|
130
|
+
static ValidateUSR(USR) {
|
|
121
131
|
try {
|
|
122
132
|
const IID = this.GetIID();
|
|
123
133
|
if (!IID)
|
|
@@ -129,10 +139,10 @@ class CookiesHelper {
|
|
|
129
139
|
catch (error) {
|
|
130
140
|
console.error(error);
|
|
131
141
|
}
|
|
132
|
-
}
|
|
142
|
+
}
|
|
133
143
|
// #endregion
|
|
134
144
|
// #region "Device Security Code"
|
|
135
|
-
static GetDeviceSecurityCode
|
|
145
|
+
static GetDeviceSecurityCode() {
|
|
136
146
|
try {
|
|
137
147
|
const IID = this.GetIID();
|
|
138
148
|
const DEK = this.GetDEK();
|
|
@@ -148,10 +158,10 @@ class CookiesHelper {
|
|
|
148
158
|
catch (error) {
|
|
149
159
|
console.error(error);
|
|
150
160
|
}
|
|
151
|
-
}
|
|
161
|
+
}
|
|
152
162
|
// #endregion
|
|
153
163
|
// #region "Access Token"
|
|
154
|
-
static GetAccessToken
|
|
164
|
+
static GetAccessToken() {
|
|
155
165
|
try {
|
|
156
166
|
const IID = this.GetIID();
|
|
157
167
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -162,8 +172,8 @@ class CookiesHelper {
|
|
|
162
172
|
catch (error) {
|
|
163
173
|
console.error(error);
|
|
164
174
|
}
|
|
165
|
-
}
|
|
166
|
-
static SetAccessToken
|
|
175
|
+
}
|
|
176
|
+
static SetAccessToken(accessToken, expires) {
|
|
167
177
|
try {
|
|
168
178
|
const IID = this.GetIID();
|
|
169
179
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -173,8 +183,8 @@ class CookiesHelper {
|
|
|
173
183
|
catch (error) {
|
|
174
184
|
console.error(error);
|
|
175
185
|
}
|
|
176
|
-
}
|
|
177
|
-
static ValidateAccessToken
|
|
186
|
+
}
|
|
187
|
+
static ValidateAccessToken(accessToken) {
|
|
178
188
|
try {
|
|
179
189
|
const IID = this.GetIID();
|
|
180
190
|
if (!IID)
|
|
@@ -186,10 +196,10 @@ class CookiesHelper {
|
|
|
186
196
|
catch (error) {
|
|
187
197
|
console.error(error);
|
|
188
198
|
}
|
|
189
|
-
}
|
|
199
|
+
}
|
|
190
200
|
// #endregion
|
|
191
201
|
// #region "JWT Token"
|
|
192
|
-
static GetJWTToken
|
|
202
|
+
static GetJWTToken() {
|
|
193
203
|
try {
|
|
194
204
|
const IID = this.GetIID();
|
|
195
205
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -200,8 +210,8 @@ class CookiesHelper {
|
|
|
200
210
|
catch (error) {
|
|
201
211
|
console.error(error);
|
|
202
212
|
}
|
|
203
|
-
}
|
|
204
|
-
static SetJWTToken
|
|
213
|
+
}
|
|
214
|
+
static SetJWTToken(jwtToken) {
|
|
205
215
|
try {
|
|
206
216
|
const IID = this.GetIID();
|
|
207
217
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -211,8 +221,8 @@ class CookiesHelper {
|
|
|
211
221
|
catch (error) {
|
|
212
222
|
console.error(error);
|
|
213
223
|
}
|
|
214
|
-
}
|
|
215
|
-
static ValidateJWTToken
|
|
224
|
+
}
|
|
225
|
+
static ValidateJWTToken(jwtToken) {
|
|
216
226
|
try {
|
|
217
227
|
const IID = this.GetIID();
|
|
218
228
|
if (!IID)
|
|
@@ -224,10 +234,10 @@ class CookiesHelper {
|
|
|
224
234
|
catch (error) {
|
|
225
235
|
console.error(error);
|
|
226
236
|
}
|
|
227
|
-
}
|
|
237
|
+
}
|
|
228
238
|
// #endregion
|
|
229
239
|
// #region "User Data"
|
|
230
|
-
static GetUserData
|
|
240
|
+
static GetUserData() {
|
|
231
241
|
try {
|
|
232
242
|
const IID = this.GetIID();
|
|
233
243
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -241,8 +251,8 @@ class CookiesHelper {
|
|
|
241
251
|
catch (error) {
|
|
242
252
|
console.error(error);
|
|
243
253
|
}
|
|
244
|
-
}
|
|
245
|
-
static SetUserData
|
|
254
|
+
}
|
|
255
|
+
static SetUserData(userData) {
|
|
246
256
|
try {
|
|
247
257
|
const IID = this.GetIID();
|
|
248
258
|
const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
|
|
@@ -253,13 +263,13 @@ class CookiesHelper {
|
|
|
253
263
|
catch (error) {
|
|
254
264
|
console.error(error);
|
|
255
265
|
}
|
|
256
|
-
}
|
|
266
|
+
}
|
|
257
267
|
// #endregion
|
|
258
268
|
// #region "Getters & Setters"
|
|
259
|
-
static GET
|
|
269
|
+
static GET(key) {
|
|
260
270
|
return Cookies.get(key);
|
|
261
|
-
}
|
|
262
|
-
static SET
|
|
271
|
+
}
|
|
272
|
+
static SET(key, value, expires) {
|
|
263
273
|
const defaultExpireDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 365);
|
|
264
274
|
Cookies.set(key, value, {
|
|
265
275
|
path: "/",
|
|
@@ -267,66 +277,71 @@ class CookiesHelper {
|
|
|
267
277
|
domain: process.env.NEXT_PUBLIC_DOMAIN || process.env.VITE_DOMAIN || "ggez.one",
|
|
268
278
|
expires: expires || defaultExpireDate,
|
|
269
279
|
});
|
|
270
|
-
}
|
|
271
|
-
static REMOVE
|
|
280
|
+
}
|
|
281
|
+
static REMOVE(key) {
|
|
272
282
|
Cookies.remove(key);
|
|
273
|
-
}
|
|
283
|
+
}
|
|
274
284
|
// #endregion
|
|
275
285
|
// #region "Cookie Change Event Listener"
|
|
276
|
-
static cookieEventHandler
|
|
286
|
+
static cookieEventHandler(e, callback) {
|
|
277
287
|
if (e.changed.length > 0) {
|
|
278
288
|
this.onChangeHandler(e.changed, callback);
|
|
279
289
|
}
|
|
280
290
|
if (e.deleted.length > 0) {
|
|
281
291
|
this.onDeleteHandler(e.deleted, callback);
|
|
282
292
|
}
|
|
283
|
-
}
|
|
284
|
-
static onChangeHandler
|
|
293
|
+
}
|
|
294
|
+
static onChangeHandler(changed, callback) {
|
|
285
295
|
const changedCookie = changed[0];
|
|
286
296
|
switch (changedCookie.name) {
|
|
287
297
|
case "IID":
|
|
288
298
|
const IID = this.GetIID();
|
|
289
|
-
|
|
299
|
+
const changedIID = this.ValidateIID(changedCookie.value);
|
|
300
|
+
if (IID != changedIID) {
|
|
290
301
|
callback();
|
|
291
302
|
}
|
|
292
303
|
break;
|
|
293
304
|
case "USR":
|
|
294
305
|
const USR = this.GetUSR();
|
|
295
|
-
|
|
306
|
+
const changedUSR = this.ValidateUSR(changedCookie.value);
|
|
307
|
+
if (USR.toString() != changedUSR) {
|
|
296
308
|
callback();
|
|
297
309
|
}
|
|
298
310
|
break;
|
|
299
311
|
case "DEK":
|
|
300
312
|
const DEK = this.GetDEK();
|
|
301
|
-
|
|
313
|
+
const changedDEK = this.ValidateDEK(changedCookie.value);
|
|
314
|
+
if (DEK != changedDEK) {
|
|
302
315
|
callback();
|
|
303
316
|
}
|
|
304
317
|
break;
|
|
305
318
|
case "access_token":
|
|
306
319
|
const accessToken = this.GetAccessToken();
|
|
307
|
-
|
|
320
|
+
const changedAccessToken = CookiesHelper.ValidateAccessToken(changedCookie.value);
|
|
321
|
+
if (accessToken != changedAccessToken) {
|
|
308
322
|
callback();
|
|
309
323
|
}
|
|
310
324
|
break;
|
|
311
325
|
case "jwt_token":
|
|
312
326
|
const jwtToken = this.GetJWTToken();
|
|
313
|
-
|
|
327
|
+
const changedJWTToken = this.ValidateJWTToken(changedCookie.value);
|
|
328
|
+
if (jwtToken != changedJWTToken) {
|
|
314
329
|
callback();
|
|
315
330
|
}
|
|
316
331
|
break;
|
|
317
332
|
}
|
|
318
|
-
}
|
|
319
|
-
static onDeleteHandler
|
|
333
|
+
}
|
|
334
|
+
static onDeleteHandler(deleted, callback) {
|
|
320
335
|
const deletedCookie = deleted[0];
|
|
321
336
|
if (["DEK", "USR", "IID", "access_token", "jwt_token"].includes(deletedCookie.name)) {
|
|
322
337
|
callback();
|
|
323
338
|
}
|
|
324
|
-
}
|
|
325
|
-
static addOnChangeEventListener
|
|
339
|
+
}
|
|
340
|
+
static addOnChangeEventListener(callback) {
|
|
326
341
|
window.cookieStore.addEventListener("change", (e) => this.cookieEventHandler(e, callback));
|
|
327
|
-
}
|
|
328
|
-
static removeOnChangeEventListener
|
|
342
|
+
}
|
|
343
|
+
static removeOnChangeEventListener(callback) {
|
|
329
344
|
window.cookieStore.removeEventListener("change", (e) => this.cookieEventHandler(e, callback));
|
|
330
|
-
}
|
|
345
|
+
}
|
|
331
346
|
}
|
|
332
347
|
export { CookiesHelper };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ggez-banking-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.151",
|
|
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",
|