generated from 8iq/nodejs-hackathon-boilerplate-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(condo): DOMA-10642 add prefix to determine, that string was encr…
…ypted by manager; Do not encrypt field before database, if it is encrypted; Enhance script; Rename field;
- Loading branch information
Showing
10 changed files
with
203 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const { Text } = require('@keystonejs/fields') | ||
const get = require('lodash/get') | ||
const isNil = require('lodash/isNil') | ||
|
||
const CommonInterface = superclass => class extends superclass { | ||
|
||
/** @type {EncryptionManager} */ | ||
encryptionManager | ||
|
||
constructor () { | ||
super(...arguments) | ||
this.encryptionManager = this.config.encryptionManager | ||
} | ||
|
||
setupHooks ({ addPreSaveHook }) { | ||
|
||
addPreSaveHook(item => { | ||
const fieldIsDefined = !isNil(item) && !isNil(item[this.path]) | ||
const fieldIsEncrypted = this.encryptionManager.isEncrypted(get(item, this.path)) | ||
if (fieldIsDefined && !fieldIsEncrypted) { | ||
item[this.path] = this.encryptionManager.encrypt(item[this.path]) | ||
} | ||
return item | ||
}) | ||
|
||
} | ||
|
||
} | ||
|
||
class EncryptedTextKnexFieldAdapter extends CommonInterface(Text.adapters.knex) {} | ||
class EncryptedTextMongooseFieldAdapter extends CommonInterface(Text.adapters.mongoose) {} | ||
class EncryptedTextPrismaFieldAdapter extends CommonInterface(Text.adapters.prisma) {} | ||
|
||
module.exports = { | ||
mongoose: EncryptedTextMongooseFieldAdapter, | ||
knex: EncryptedTextKnexFieldAdapter, | ||
prisma: EncryptedTextPrismaFieldAdapter, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { Text } = require('@keystonejs/fields') | ||
|
||
const EncryptedTextAdapters = require('./adapters') | ||
const { EncryptedTextImplementation } = require('./Implementation') | ||
|
||
module.exports = { | ||
type: 'EncryptedText', | ||
implementation: EncryptedTextImplementation, | ||
views: Text.views, | ||
adapters: EncryptedTextAdapters, | ||
} |
35 changes: 0 additions & 35 deletions
35
packages/keystone/fields/SymmetricEncryptedText/adapters/index.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.