loyalty-protocol 3.0.22 → 3.0.23

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 +1,2 @@
1
1
  export declare const decryptLoyaltySessionToken: (token: string | undefined, storeIdentifier: string | undefined) => string | undefined;
2
+ export declare const encryptLoyaltySessionToken: (token: string, storeIdentifier: string) => string;
@@ -27,3 +27,21 @@ export const decryptLoyaltySessionToken = (token, storeIdentifier) => {
27
27
  return token;
28
28
  }
29
29
  };
30
+ export const encryptLoyaltySessionToken = (token, storeIdentifier) => {
31
+ let salt;
32
+ const env = process.env.LOYALTY_SALT;
33
+ if (typeof env === "object") {
34
+ salt = env[storeIdentifier];
35
+ }
36
+ else {
37
+ salt = env ? JSON.parse(env)[storeIdentifier] : undefined;
38
+ }
39
+ const key = CryptoJS.enc.Utf8.parse(salt);
40
+ const encrypted = CryptoJS.AES.encrypt(CryptoJS.enc.Utf8.parse(token?.toString()), key, {
41
+ keySize: 128 / 8,
42
+ iv: key,
43
+ mode: CryptoJS.mode.CBC,
44
+ padding: CryptoJS.pad.Pkcs7,
45
+ });
46
+ return encrypted?.toString();
47
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "loyalty-protocol",
3
- "version": "3.0.22",
3
+ "version": "3.0.23",
4
4
  "description": "",
5
5
  "main": "dist/index",
6
6
  "exports": {