prisma-field-encryption
Advanced tools
Comparing version 1.3.2 to 1.3.3-beta.1
@@ -9,3 +9,3 @@ import { CloakKeychain, ParsedCloakKey } from '@47ng/cloak'; | ||
export declare function configureKeys(config: Configuration): KeysConfiguration; | ||
export declare function encryptOnWrite(params: MiddlewareParams, keys: KeysConfiguration, models: DMMFModels, operation: string): void; | ||
export declare function encryptOnWrite(params: MiddlewareParams, keys: KeysConfiguration, models: DMMFModels, operation: string): import(".prisma/client").Prisma.MiddlewareParams; | ||
export declare function decryptOnRead(params: MiddlewareParams, result: any, keys: KeysConfiguration, models: DMMFModels, operation: string): void; |
@@ -8,2 +8,3 @@ "use strict"; | ||
const cloak_1 = require("@47ng/cloak"); | ||
const immer_1 = __importDefault(require("immer")); | ||
const object_path_1 = __importDefault(require("object-path")); | ||
@@ -43,19 +44,21 @@ const errors_1 = require("./errors"); | ||
if (!writeOperations.includes(params.action)) { | ||
return; // No input data to encrypt | ||
return params; // No input data to encrypt | ||
} | ||
const encryptionErrors = []; | ||
(0, visitor_1.visitInputTargetFields)(params, models, function encryptFieldValue({ fieldConfig, value: clearText, path, model, field }) { | ||
if (!fieldConfig.encrypt) { | ||
return; | ||
} | ||
if (whereClauseRegExp.test(path)) { | ||
console.warn(errors_1.warnings.whereClause(operation, path)); | ||
} | ||
try { | ||
const cipherText = (0, cloak_1.encryptStringSync)(clearText, keys.encryptionKey); | ||
object_path_1.default.set(params.args, path, cipherText); | ||
} | ||
catch (error) { | ||
encryptionErrors.push(errors_1.errors.fieldEncryptionError(model, field, path, error)); | ||
} | ||
const mutatedParams = (0, immer_1.default)(params, (draft) => { | ||
(0, visitor_1.visitInputTargetFields)(draft, models, function encryptFieldValue({ fieldConfig, value: clearText, path, model, field }) { | ||
if (!fieldConfig.encrypt) { | ||
return; | ||
} | ||
if (whereClauseRegExp.test(path)) { | ||
console.warn(errors_1.warnings.whereClause(operation, path)); | ||
} | ||
try { | ||
const cipherText = (0, cloak_1.encryptStringSync)(clearText, keys.encryptionKey); | ||
object_path_1.default.set(draft.args, path, cipherText); | ||
} | ||
catch (error) { | ||
encryptionErrors.push(errors_1.errors.fieldEncryptionError(model, field, path, error)); | ||
} | ||
}); | ||
}); | ||
@@ -65,2 +68,3 @@ if (encryptionErrors.length > 0) { | ||
} | ||
return mutatedParams; | ||
} | ||
@@ -67,0 +71,0 @@ exports.encryptOnWrite = encryptOnWrite; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -6,0 +10,0 @@ if (k2 === undefined) k2 = k; |
@@ -19,5 +19,5 @@ "use strict"; | ||
// See https://github.com/prisma/prisma/issues/9522 | ||
(0, encryption_1.encryptOnWrite)(params, keys, models, operation); | ||
let result = await next(params); | ||
(0, encryption_1.decryptOnRead)(params, result, keys, models, operation); | ||
const encryptedParams = (0, encryption_1.encryptOnWrite)(params, keys, models, operation); | ||
let result = await next(encryptedParams); | ||
(0, encryption_1.decryptOnRead)(encryptedParams, result, keys, models, operation); | ||
return result; | ||
@@ -24,0 +24,0 @@ }; |
@@ -6,3 +6,2 @@ "use strict"; | ||
const makeVisitor = (models, visitor) => function visitNode(state, { key, type, node, path }) { | ||
var _a; | ||
const model = models[state.currentModel]; | ||
@@ -26,3 +25,3 @@ if (!model || !key) { | ||
key in model.fields && | ||
typeof ((_a = node) === null || _a === void 0 ? void 0 : _a.set) === 'string') { | ||
typeof (node === null || node === void 0 ? void 0 : node.set) === 'string') { | ||
const value = node.set; | ||
@@ -29,0 +28,0 @@ const targetField = { |
{ | ||
"name": "prisma-field-encryption", | ||
"version": "1.3.2", | ||
"version": "1.3.3-beta.1", | ||
"description": "Transparent field-level encryption at rest for Prisma", | ||
@@ -51,26 +51,27 @@ "main": "dist/index.js", | ||
"@47ng/cloak": "^1.1.0-beta.2", | ||
"@prisma/generator-helper": "^3.6.0", | ||
"@prisma/generator-helper": "^3.13.0", | ||
"immer": "^9.0.12", | ||
"object-path": "^0.11.8" | ||
}, | ||
"peerDependencies": { | ||
"@prisma/client": "^3.5.0" | ||
"@prisma/client": "^3.8.0" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/config-conventional": "^15.0.0", | ||
"@prisma/client": "^3.5.0", | ||
"@prisma/sdk": "^3.5.0", | ||
"@types/jest": "^27.0.3", | ||
"@types/node": "^16.11.10", | ||
"@commitlint/config-conventional": "^16.2.4", | ||
"@prisma/client": "^3.13.0", | ||
"@prisma/sdk": "^3.13.0", | ||
"@types/jest": "^27.4.1", | ||
"@types/node": "^17.0.29", | ||
"@types/object-path": "^0.11.1", | ||
"commitlint": "^15.0.0", | ||
"commitlint": "^16.2.4", | ||
"husky": "^7.0.4", | ||
"jest": "^27.3.1", | ||
"jest": "^27", | ||
"npm-run-all": "^4.1.5", | ||
"nyc": "^15.1.0", | ||
"prisma": "^3.5.0", | ||
"sqlite": "^4.0.23", | ||
"sqlite3": "^5.0.2", | ||
"ts-jest": "^27.0.7", | ||
"ts-node": "^10.4.0", | ||
"typescript": "^4.5.2" | ||
"prisma": "^3.13.0", | ||
"sqlite": "^4.1.1", | ||
"sqlite3": "^5.0.6", | ||
"ts-jest": "^27.1.4", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.6.3" | ||
}, | ||
@@ -77,0 +78,0 @@ "jest": { |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
47826
788
5
2
+ Addedimmer@^9.0.12
+ Addedimmer@9.0.21(transitive)