47ng / prisma-field-encryption

Transparent field-level encryption at rest for Prisma
https://github.com/franky47/prisma-field-encryption-sandbox
MIT License
246 stars 29 forks source link

Only works for Model and not embedded Type? #74

Open zmays opened 1 year ago

zmays commented 1 year ago

using mongodb and so a lot of our encrypted fields are in embedded documents, which are done by Type instead of Model: https://www.prisma.io/docs/concepts/components/prisma-schema/data-model#defining-composite-types

I've added this lib, but only get encryption on fields defined in Models.

Supporting types on your roadmap? Want a pr for it?

franky47 commented 1 year ago

Sure, if you feel like going for a PR for this, go ahead!

This will probably require adjusting the DMMF parser to look for those Type definitions, and see how to connect that to the visitor system, which visits each node of a query to look for leaves to encrypt/decrypt, with the knowledge of what model it's currently looking at.

zmays commented 1 year ago

I'm running npm link to test some changes I made, but the require('@prisma/client').Prisma.dmmf in extensions.ts is returning undefined when I run it with my repo - ran into this before?

franky47 commented 1 year ago

This is usually a sign that you need to generate the Prisma client with prisma generate, to get the required DMMF.

FYI, if you want to explore the object structure more easily, you can use import { getDMMF } from '@prisma/internals', feed it the contents of your schema, and dump the result into a JSON file.

zmays commented 1 year ago

Thanks, it is definitely generated, I'm guessing it is trying to import from the package node_modules, instead of the source repo I linked the package to

franky47 commented 1 year ago

Yeah with npm link it may not work exactly as intended in a regular dependency install. Feel free to locally point the require to a correct relative path.

zmays commented 1 year ago

Hey sorry this has hit the backburner for me at the moment