@meebon/meebon-crypto 1.1.0 → 1.2.0

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.
@@ -3,6 +3,6 @@ import { MeebonCryptoKeyPair } from '../types/global';
3
3
  /**
4
4
  * Middleware Function for Encryption and Decryption
5
5
  */
6
- declare const encryptionMiddleware: ({ privateKey, publicKey, }: MeebonCryptoKeyPair) => (req: Request, res: Response, next: NextFunction) => Response<any, Record<string, any>> | undefined;
6
+ declare const encryptionMiddleware: ({ privateKey, publicKey, }: MeebonCryptoKeyPair) => (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
7
7
  export default encryptionMiddleware;
8
8
  //# sourceMappingURL=ExpressEncryptionMiddleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExpressEncryptionMiddleware.d.ts","sourceRoot":"","sources":["../lib/ExpressEncryptionMiddleware.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,QAAA,MAAM,oBAAoB,+BAAgC,mBAAmB,WAC9D,OAAO,OAAO,QAAQ,QAAQ,YAAY,mDAyBxD,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
1
+ {"version":3,"file":"ExpressEncryptionMiddleware.d.ts","sourceRoot":"","sources":["../lib/ExpressEncryptionMiddleware.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAkB,MAAM,SAAS,CAAA;AACzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD;;GAEG;AACH,QAAA,MAAM,oBAAoB,+BAAgC,mBAAmB,WACtD,OAAO,OAAO,QAAQ,QAAQ,YAAY,8CA0BhE,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import { MeebonCrypto } from './MeebonCrypto';
2
+ export declare const EncryptionMiddleware: ({ privateKey, publicKey, }: import("../types/global").MeebonCryptoKeyPair) => (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction) => void | import("express").Response<any, Record<string, any>>;
2
3
  export default MeebonCrypto;
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,oBAAoB,uPAAuB,CAAC;AACzD,eAAe,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -78,8 +78,39 @@ var MeebonCrypto = class _MeebonCrypto {
78
78
  }
79
79
  };
80
80
 
81
+ // lib/ExpressEncryptionMiddleware.ts
82
+ var encryptionMiddleware = ({ privateKey, publicKey }) => {
83
+ const output = (req, res, next) => {
84
+ if (req.body.data) {
85
+ try {
86
+ const encrypted = MeebonCrypto.encryptData(req.body.dataToEncrypt, publicKey);
87
+ req.body.data = encrypted;
88
+ } catch (error) {
89
+ return res.status(500).json({ message: "Encryption error", error: error.message });
90
+ }
91
+ }
92
+ const originalSend = res.send;
93
+ res.send = function(body) {
94
+ try {
95
+ if (body && body.encryptedData) {
96
+ const decrypted = MeebonCrypto.decryptData(body.encryptedData, privateKey);
97
+ body.decryptedData = decrypted;
98
+ }
99
+ return originalSend.call(this, body);
100
+ } catch (error) {
101
+ throw new Error(error?.message ?? error);
102
+ }
103
+ };
104
+ return next();
105
+ };
106
+ return output;
107
+ };
108
+ var ExpressEncryptionMiddleware_default = encryptionMiddleware;
109
+
81
110
  // lib/index.ts
111
+ var EncryptionMiddleware = ExpressEncryptionMiddleware_default;
82
112
  var index_default = MeebonCrypto;
83
113
  export {
114
+ EncryptionMiddleware,
84
115
  index_default as default
85
116
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meebon/meebon-crypto",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "author": "kajalanS <103587022+kajalanS@users.noreply.github.com>",
6
6
  "homepage": "https://github.com/KsoftmHub/meebon-crypto?tab=readme-ov-file#getting-started",
@@ -36,8 +36,8 @@
36
36
  "semantic-release": "semantic-release",
37
37
  "refresh": "pnpm run rm:node && pnpm i",
38
38
  "rm:node": "find . -name \"node_modules\" -type d -prune -exec rm -rf '{}' +",
39
- "ci": "tsx scripts/clean.ts --tsconfig tsconfig.json",
40
- "build": "tsx scripts/build.ts && jest"
39
+ "ci": "tsx script/clean.ts --tsconfig tsconfig.json",
40
+ "build": "tsx script/build.ts && jest"
41
41
  },
42
42
  "bugs": {
43
43
  "url": "https://github.com/KsoftmHub/meebon-crypto/issues"