ggez-banking-sdk 0.1.151 → 0.1.152

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.
@@ -4,7 +4,7 @@ declare class CipherHelper {
4
4
  static Decrypt: (cipherText: string, key: string, iv: string) => string;
5
5
  static Generate: (code: string) => CipherKeyIV;
6
6
  static GenerateByUSRAndIID: (USR: USR, IID: string) => CipherKeyIV;
7
- static GenerateByProgramID: () => CipherKeyIV;
7
+ static GenerateByProgramID: (programId: number) => CipherKeyIV;
8
8
  static GenerateByUserID: (user_id: string) => CipherKeyIV;
9
9
  static GenerateByInstallationID: (IID: string) => CipherKeyIV;
10
10
  static PaddingLeft: (value: string, length: number, paddingChar: string) => string;
@@ -66,9 +66,8 @@ class CipherHelper {
66
66
  return { key: "", iv: "" };
67
67
  }
68
68
  };
69
- static GenerateByProgramID = () => {
69
+ static GenerateByProgramID = (programId) => {
70
70
  try {
71
- const programId = process.env.NEXT_PUBLIC_PROGRAM_ID || process.env.VITE_PROGRAM_ID;
72
71
  if (!programId) {
73
72
  throw new Error("Program ID is not defined");
74
73
  }
@@ -1,31 +1,34 @@
1
1
  import { UserData, USR } from "../types";
2
2
  declare class CookiesHelper {
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;
3
+ private domain;
4
+ private programId;
5
+ constructor(programId: number, domain: string);
6
+ GetIID(): any;
7
+ SetIID(): void;
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: Date): void;
19
+ ValidateAccessToken(accessToken: string): string;
20
+ GetJWTToken(): string;
21
+ SetJWTToken(jwtToken: string): void;
22
+ ValidateJWTToken(jwtToken: string): string;
23
+ GetUserData(): UserData;
24
+ SetUserData(userData: UserData): void;
25
+ GET(key: string): string | undefined;
26
+ SET(key: string, value: string, expires?: Date): void;
27
+ REMOVE(key: string): void;
28
+ cookieEventHandler(e: CookieChangeEvent, callback: () => void): void;
29
+ onChangeHandler(changed: CookieInit[], callback: () => void): void;
30
+ onDeleteHandler(deleted: CookieInit[], callback: () => void): void;
31
+ addOnChangeEventListener(callback: () => void): void;
32
+ removeOnChangeEventListener(callback: () => void): void;
30
33
  }
31
34
  export { CookiesHelper };
@@ -2,15 +2,25 @@ import { v4 } from "uuid";
2
2
  import Cookies from "js-cookie";
3
3
  import { CipherHelper } from ".";
4
4
  class CookiesHelper {
5
+ // #region "Properties"
6
+ domain = "";
7
+ programId = 0;
8
+ // #endregion
9
+ // #region "Constructor"
10
+ constructor(programId, domain) {
11
+ this.programId = programId;
12
+ this.domain = domain;
13
+ }
14
+ // #endregion
5
15
  // #region "IID"
6
- static GetIID() {
16
+ GetIID() {
7
17
  try {
8
18
  const IID = this.GET("IID");
9
19
  if (!IID) {
10
20
  this.SetIID();
11
21
  return this.GetIID();
12
22
  }
13
- const { key, iv } = CipherHelper.GenerateByProgramID();
23
+ const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
14
24
  const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
15
25
  return decryptedIID;
16
26
  }
@@ -18,10 +28,10 @@ class CookiesHelper {
18
28
  console.error(error);
19
29
  }
20
30
  }
21
- static SetIID() {
31
+ SetIID() {
22
32
  try {
23
33
  const IID = v4();
24
- const { key, iv } = CipherHelper.GenerateByProgramID();
34
+ const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
25
35
  const encryptedIID = CipherHelper.Encrypt(IID, key, iv);
26
36
  this.SET("IID", encryptedIID);
27
37
  }
@@ -29,9 +39,9 @@ class CookiesHelper {
29
39
  console.error(error);
30
40
  }
31
41
  }
32
- static ValidateIID(IID) {
42
+ ValidateIID(IID) {
33
43
  try {
34
- const { key, iv } = CipherHelper.GenerateByProgramID();
44
+ const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
35
45
  const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
36
46
  return decryptedIID;
37
47
  }
@@ -39,9 +49,9 @@ class CookiesHelper {
39
49
  console.error(error);
40
50
  }
41
51
  }
42
- static isIIDValid(IID) {
52
+ isIIDValid(IID) {
43
53
  try {
44
- const { key, iv } = CipherHelper.GenerateByProgramID();
54
+ const { key, iv } = CipherHelper.GenerateByProgramID(this.programId);
45
55
  const decryptedIID = CipherHelper.Decrypt(IID, key, iv);
46
56
  return decryptedIID == this.GetIID();
47
57
  }
@@ -51,7 +61,7 @@ class CookiesHelper {
51
61
  }
52
62
  // #endregion
53
63
  // #region "DEK"
54
- static GetDEK() {
64
+ GetDEK() {
55
65
  try {
56
66
  const IID = this.GetIID();
57
67
  const DEK = this.GET("DEK");
@@ -68,7 +78,7 @@ class CookiesHelper {
68
78
  console.error(error);
69
79
  }
70
80
  }
71
- static SetDEK(deviceEncryptionKey, USR) {
81
+ SetDEK(deviceEncryptionKey, USR) {
72
82
  try {
73
83
  const IID = this.GetIID();
74
84
  const { user_id } = USR;
@@ -84,7 +94,7 @@ class CookiesHelper {
84
94
  console.error(error);
85
95
  }
86
96
  }
87
- static ValidateDEK(DEK) {
97
+ ValidateDEK(DEK) {
88
98
  try {
89
99
  const IID = this.GetIID();
90
100
  const USR = this.GetUSR();
@@ -100,7 +110,7 @@ class CookiesHelper {
100
110
  }
101
111
  // #endregion
102
112
  // #region "USR"
103
- static GetUSR() {
113
+ GetUSR() {
104
114
  try {
105
115
  const IID = this.GetIID();
106
116
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -112,7 +122,7 @@ class CookiesHelper {
112
122
  console.error(error);
113
123
  }
114
124
  }
115
- static SetUSR(deviceId, userId) {
125
+ SetUSR(deviceId, userId) {
116
126
  try {
117
127
  const IID = this.GetIID();
118
128
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -127,7 +137,7 @@ class CookiesHelper {
127
137
  console.error(error);
128
138
  }
129
139
  }
130
- static ValidateUSR(USR) {
140
+ ValidateUSR(USR) {
131
141
  try {
132
142
  const IID = this.GetIID();
133
143
  if (!IID)
@@ -142,7 +152,7 @@ class CookiesHelper {
142
152
  }
143
153
  // #endregion
144
154
  // #region "Device Security Code"
145
- static GetDeviceSecurityCode() {
155
+ GetDeviceSecurityCode() {
146
156
  try {
147
157
  const IID = this.GetIID();
148
158
  const DEK = this.GetDEK();
@@ -161,7 +171,7 @@ class CookiesHelper {
161
171
  }
162
172
  // #endregion
163
173
  // #region "Access Token"
164
- static GetAccessToken() {
174
+ GetAccessToken() {
165
175
  try {
166
176
  const IID = this.GetIID();
167
177
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -173,7 +183,7 @@ class CookiesHelper {
173
183
  console.error(error);
174
184
  }
175
185
  }
176
- static SetAccessToken(accessToken, expires) {
186
+ SetAccessToken(accessToken, expires) {
177
187
  try {
178
188
  const IID = this.GetIID();
179
189
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -184,7 +194,7 @@ class CookiesHelper {
184
194
  console.error(error);
185
195
  }
186
196
  }
187
- static ValidateAccessToken(accessToken) {
197
+ ValidateAccessToken(accessToken) {
188
198
  try {
189
199
  const IID = this.GetIID();
190
200
  if (!IID)
@@ -199,7 +209,7 @@ class CookiesHelper {
199
209
  }
200
210
  // #endregion
201
211
  // #region "JWT Token"
202
- static GetJWTToken() {
212
+ GetJWTToken() {
203
213
  try {
204
214
  const IID = this.GetIID();
205
215
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -211,7 +221,7 @@ class CookiesHelper {
211
221
  console.error(error);
212
222
  }
213
223
  }
214
- static SetJWTToken(jwtToken) {
224
+ SetJWTToken(jwtToken) {
215
225
  try {
216
226
  const IID = this.GetIID();
217
227
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -222,7 +232,7 @@ class CookiesHelper {
222
232
  console.error(error);
223
233
  }
224
234
  }
225
- static ValidateJWTToken(jwtToken) {
235
+ ValidateJWTToken(jwtToken) {
226
236
  try {
227
237
  const IID = this.GetIID();
228
238
  if (!IID)
@@ -237,7 +247,7 @@ class CookiesHelper {
237
247
  }
238
248
  // #endregion
239
249
  // #region "User Data"
240
- static GetUserData() {
250
+ GetUserData() {
241
251
  try {
242
252
  const IID = this.GetIID();
243
253
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -252,7 +262,7 @@ class CookiesHelper {
252
262
  console.error(error);
253
263
  }
254
264
  }
255
- static SetUserData(userData) {
265
+ SetUserData(userData) {
256
266
  try {
257
267
  const IID = this.GetIID();
258
268
  const { key, iv } = CipherHelper.GenerateByInstallationID(IID);
@@ -266,24 +276,24 @@ class CookiesHelper {
266
276
  }
267
277
  // #endregion
268
278
  // #region "Getters & Setters"
269
- static GET(key) {
279
+ GET(key) {
270
280
  return Cookies.get(key);
271
281
  }
272
- static SET(key, value, expires) {
282
+ SET(key, value, expires) {
273
283
  const defaultExpireDate = new Date(Date.now() + 1000 * 60 * 60 * 24 * 365);
274
284
  Cookies.set(key, value, {
275
285
  path: "/",
276
286
  sameSite: "lax",
277
- domain: process.env.NEXT_PUBLIC_DOMAIN || process.env.VITE_DOMAIN || "ggez.one",
287
+ domain: this.domain || "ggez.one",
278
288
  expires: expires || defaultExpireDate,
279
289
  });
280
290
  }
281
- static REMOVE(key) {
291
+ REMOVE(key) {
282
292
  Cookies.remove(key);
283
293
  }
284
294
  // #endregion
285
295
  // #region "Cookie Change Event Listener"
286
- static cookieEventHandler(e, callback) {
296
+ cookieEventHandler(e, callback) {
287
297
  if (e.changed.length > 0) {
288
298
  this.onChangeHandler(e.changed, callback);
289
299
  }
@@ -291,7 +301,7 @@ class CookiesHelper {
291
301
  this.onDeleteHandler(e.deleted, callback);
292
302
  }
293
303
  }
294
- static onChangeHandler(changed, callback) {
304
+ onChangeHandler(changed, callback) {
295
305
  const changedCookie = changed[0];
296
306
  switch (changedCookie.name) {
297
307
  case "IID":
@@ -317,7 +327,7 @@ class CookiesHelper {
317
327
  break;
318
328
  case "access_token":
319
329
  const accessToken = this.GetAccessToken();
320
- const changedAccessToken = CookiesHelper.ValidateAccessToken(changedCookie.value);
330
+ const changedAccessToken = this.ValidateAccessToken(changedCookie.value);
321
331
  if (accessToken != changedAccessToken) {
322
332
  callback();
323
333
  }
@@ -331,16 +341,16 @@ class CookiesHelper {
331
341
  break;
332
342
  }
333
343
  }
334
- static onDeleteHandler(deleted, callback) {
344
+ onDeleteHandler(deleted, callback) {
335
345
  const deletedCookie = deleted[0];
336
346
  if (["DEK", "USR", "IID", "access_token", "jwt_token"].includes(deletedCookie.name)) {
337
347
  callback();
338
348
  }
339
349
  }
340
- static addOnChangeEventListener(callback) {
350
+ addOnChangeEventListener(callback) {
341
351
  window.cookieStore.addEventListener("change", (e) => this.cookieEventHandler(e, callback));
342
352
  }
343
- static removeOnChangeEventListener(callback) {
353
+ removeOnChangeEventListener(callback) {
344
354
  window.cookieStore.removeEventListener("change", (e) => this.cookieEventHandler(e, callback));
345
355
  }
346
356
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ggez-banking-sdk",
3
- "version": "0.1.151",
3
+ "version": "0.1.152",
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",