@friggframework/core 0.2.31-v1-alpha-package-update.0 → 1.0.1-v1-alpha-package-update.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.
- package/assertions/CHANGELOG.md +87 -0
- package/assertions/LICENSE.md +9 -0
- package/assertions/README.md +3 -0
- package/assertions/bump.txt +1 -0
- package/assertions/get.js +139 -0
- package/assertions/index.js +19 -0
- package/assertions/is-equal.js +17 -0
- package/associations/LICENSE.md +9 -0
- package/associations/README.md +3 -0
- package/associations/association.js +78 -0
- package/associations/bump3.txt +0 -0
- package/associations/jest.config.js +5 -0
- package/associations/model.js +54 -0
- package/bump.txt +0 -0
- package/core/.eslintrc.json +3 -0
- package/{Delegate.js → core/Delegate.js} +1 -1
- package/core/LICENSE.md +9 -0
- package/{Worker.js → core/Worker.js} +2 -2
- package/core/bump3.txt +0 -0
- package/{create-handler.js → core/create-handler.js} +2 -2
- package/core/index.js +6 -0
- package/core/jest.config.js +5 -0
- package/database/.eslintrc.json +3 -0
- package/database/CHANGELOG.md +97 -0
- package/database/LICENSE.md +9 -0
- package/database/README.md +3 -0
- package/database/bump3.txt +0 -0
- package/database/index.js +17 -0
- package/database/jest.config.js +5 -0
- package/database/models/IndividualUser.js +76 -0
- package/database/models/OrganizationUser.js +29 -0
- package/database/models/State.js +9 -0
- package/database/models/Token.js +70 -0
- package/database/models/UserModel.js +7 -0
- package/database/mongo.js +45 -0
- package/database/mongoose.js +5 -0
- package/encrypt/.eslintrc.json +3 -0
- package/encrypt/CHANGELOG.md +65 -0
- package/encrypt/Cryptor.js +236 -0
- package/encrypt/Cryptor.test.js +32 -0
- package/encrypt/LICENSE.md +9 -0
- package/encrypt/README.md +3 -0
- package/encrypt/aes.js +27 -0
- package/encrypt/bump3.txt +0 -0
- package/encrypt/encrypt.js +124 -0
- package/encrypt/encrypt.test.js +1068 -0
- package/encrypt/index.js +3 -0
- package/encrypt/jest.config.js +5 -0
- package/encrypt/test-encrypt.js +107 -0
- package/errors/.eslintrc.json +3 -0
- package/errors/CHANGELOG.md +44 -0
- package/errors/LICENSE.md +9 -0
- package/errors/README.md +3 -0
- package/errors/base-error.js +23 -0
- package/errors/base-error.test.js +32 -0
- package/errors/bump.txt +1 -0
- package/errors/bump3.txt +0 -0
- package/errors/fetch-error.js +72 -0
- package/errors/fetch-error.test.js +79 -0
- package/errors/halt-error.js +10 -0
- package/errors/halt-error.test.js +11 -0
- package/errors/index.js +15 -0
- package/errors/jest.config.js +5 -0
- package/errors/validation-errors.js +23 -0
- package/errors/validation-errors.test.js +120 -0
- package/eslint-config/.eslintrc.json +3 -0
- package/eslint-config/CHANGELOG.md +17 -0
- package/eslint-config/LICENSE.md +9 -0
- package/eslint-config/README.md +3 -0
- package/eslint-config/bump3.txt +0 -0
- package/eslint-config/index.js +38 -0
- package/index.js +29 -5
- package/integrations/.eslintrc.json +3 -0
- package/integrations/CHANGELOG.md +244 -0
- package/integrations/LICENSE.md +9 -0
- package/integrations/README.md +3 -0
- package/integrations/bump3.txt +0 -0
- package/integrations/create-frigg-backend.js +31 -0
- package/integrations/index.js +19 -0
- package/integrations/integration-base.js +162 -0
- package/integrations/integration-factory.js +166 -0
- package/integrations/integration-mapping.js +43 -0
- package/integrations/integration-model.js +42 -0
- package/integrations/integration-router.js +367 -0
- package/integrations/integration-user.js +144 -0
- package/integrations/jest-setup.js +2 -0
- package/integrations/jest-teardown.js +2 -0
- package/integrations/jest.config.js +12 -0
- package/integrations/options.js +54 -0
- package/integrations/test/integration-base.test.js +143 -0
- package/lambda/README.md +3 -0
- package/lambda/TimeoutCatcher.js +43 -0
- package/lambda/TimeoutCatcher.test.js +68 -0
- package/lambda/bump3.txt +0 -0
- package/lambda/index.js +3 -0
- package/lambda/jest.config.js +3 -0
- package/logs/.eslintrc.json +3 -0
- package/logs/CHANGELOG.md +57 -0
- package/logs/LICENSE.md +9 -0
- package/logs/README.md +3 -0
- package/logs/bump3.txt +0 -0
- package/logs/index.js +7 -0
- package/logs/jest.config.js +5 -0
- package/logs/logger.js +69 -0
- package/logs/logger.test.js +76 -0
- package/migrations/README.md +3 -0
- package/migrations/bump3.txt +0 -0
- package/migrations/index.js +9 -0
- package/migrations/jest.config.js +3 -0
- package/migrations/manager.js +33 -0
- package/migrations/migrator.js +170 -0
- package/migrations/options.js +28 -0
- package/module-plugin/.eslintrc.json +3 -0
- package/module-plugin/CHANGELOG.md +224 -0
- package/module-plugin/LICENSE.md +9 -0
- package/module-plugin/ModuleConstants.js +10 -0
- package/module-plugin/README.md +3 -0
- package/module-plugin/auther.js +342 -0
- package/module-plugin/bump3.txt +0 -0
- package/module-plugin/credential.js +22 -0
- package/module-plugin/entity-manager.js +70 -0
- package/module-plugin/entity.js +46 -0
- package/module-plugin/index.js +25 -0
- package/module-plugin/jest-setup.js +3 -0
- package/module-plugin/jest-teardown.js +2 -0
- package/module-plugin/jest.config.js +20 -0
- package/module-plugin/manager.js +169 -0
- package/module-plugin/module-factory.js +60 -0
- package/module-plugin/requester/api-key.js +36 -0
- package/module-plugin/requester/basic.js +43 -0
- package/module-plugin/requester/oauth-2.js +219 -0
- package/module-plugin/requester/requester.js +150 -0
- package/module-plugin/requester/requester.test.js +28 -0
- package/module-plugin/test/auther.test.js +97 -0
- package/module-plugin/test/mock-api/api.js +29 -0
- package/module-plugin/test/mock-api/definition.js +48 -0
- package/module-plugin/test/mock-api/mocks/hubspot.js +43 -0
- package/package.json +37 -12
- package/prettier-config/.eslintrc.json +3 -0
- package/prettier-config/CHANGELOG.md +17 -0
- package/prettier-config/LICENSE.md +9 -0
- package/prettier-config/README.md +3 -0
- package/prettier-config/bump3.txt +0 -0
- package/prettier-config/index.js +6 -0
- package/syncs/README.md +3 -0
- package/syncs/bump3.txt +0 -0
- package/syncs/jest.config.js +5 -0
- package/syncs/manager.js +466 -0
- package/syncs/model.js +62 -0
- package/syncs/sync.js +114 -0
- package/test-environment/.eslintrc.json +3 -0
- package/test-environment/Authenticator.js +73 -0
- package/test-environment/CHANGELOG.md +46 -0
- package/test-environment/LICENSE.md +9 -0
- package/test-environment/README.md +3 -0
- package/test-environment/auther-definition-method-tester.js +45 -0
- package/test-environment/auther-definition-tester.js +104 -0
- package/test-environment/bump3.txt +0 -0
- package/test-environment/index.js +24 -0
- package/test-environment/integration-validator.js +2 -0
- package/test-environment/jest-global-setup.js +6 -0
- package/test-environment/jest-global-teardown.js +3 -0
- package/test-environment/jest-preset.js +14 -0
- package/test-environment/mock-api-readme.md +102 -0
- package/test-environment/mock-api.js +284 -0
- package/test-environment/mock-integration.js +82 -0
- package/test-environment/mongodb.js +22 -0
- package/test-environment/override-environment.js +11 -0
- package/types/CHANGELOG.md +49 -0
- package/types/README.md +24 -0
- package/types/assertions/index.d.ts +83 -0
- package/types/associations/index.d.ts +74 -0
- package/types/bump3.txt +0 -0
- package/types/core/index.d.ts +54 -0
- package/types/database/index.d.ts +3 -0
- package/types/encrypt/index.d.ts +5 -0
- package/types/errors/index.d.ts +66 -0
- package/types/eslint-config/index.d.ts +41 -0
- package/types/index.d.ts +14 -0
- package/types/integrations/index.d.ts +191 -0
- package/types/lambda/index.d.ts +31 -0
- package/types/logs/index.d.ts +5 -0
- package/types/module-plugin/index.d.ts +293 -0
- package/types/prettier-config/index.d.ts +6 -0
- package/types/syncs/index.d.ts +128 -0
- package/types/test-environment/index.d.ts +17 -0
- package/types/tsconfig.json +103 -0
- /package/{.eslintrc.json → assertions/.eslintrc.json} +0 -0
- /package/{bump3.txt → assertions/bump3.txt} +0 -0
- /package/{jest.config.js → assertions/jest.config.js} +0 -0
- /package/{CHANGELOG.md → core/CHANGELOG.md} +0 -0
- /package/{README.md → core/README.md} +0 -0
- /package/{load-installed-modules.js → core/load-installed-modules.js} +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const { Cryptor } = require('./Cryptor');
|
|
2
|
+
|
|
3
|
+
const updateOneEvents = [
|
|
4
|
+
'updateOne',
|
|
5
|
+
'replaceOne',
|
|
6
|
+
'findOneAndUpdate',
|
|
7
|
+
'findOneAndReplace',
|
|
8
|
+
];
|
|
9
|
+
const findOneEvents = [
|
|
10
|
+
'findOne',
|
|
11
|
+
'findOneAndDelete',
|
|
12
|
+
'findOneAndRemove',
|
|
13
|
+
'findOneAndUpdate',
|
|
14
|
+
'findOneAndReplace',
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
// The Mongoose plug-in function
|
|
18
|
+
function Encrypt(schema, options) {
|
|
19
|
+
const { STAGE, KMS_KEY_ARN, AES_KEY_ID } = process.env;
|
|
20
|
+
const isEnabledForStage =
|
|
21
|
+
['staging', 'QA', 'prod', 'encryption-test'].indexOf(STAGE) > -1;
|
|
22
|
+
|
|
23
|
+
// No-op if not enabled
|
|
24
|
+
if (!isEnabledForStage) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (KMS_KEY_ARN && AES_KEY_ID) {
|
|
29
|
+
throw new Error(
|
|
30
|
+
'Local and AWS encryption keys are both set in the environment.'
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fields = Object.values(schema.paths)
|
|
35
|
+
.map(({ path, options }) => (options.lhEncrypt === true ? path : ''))
|
|
36
|
+
.filter(Boolean);
|
|
37
|
+
|
|
38
|
+
if (!fields.length) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const cryptor = new Cryptor({
|
|
43
|
+
// Use AWS if the CMK is present
|
|
44
|
+
shouldUseAws: !!KMS_KEY_ARN,
|
|
45
|
+
// Find all the fields in the schema with lhEncrypt === true
|
|
46
|
+
fields: fields,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// ---------------------------------------------
|
|
50
|
+
// ### Encrypt fields before save/update/insert.
|
|
51
|
+
// ---------------------------------------------
|
|
52
|
+
|
|
53
|
+
schema.pre('save', async function encryptionPreSave() {
|
|
54
|
+
// `this` will be a doc
|
|
55
|
+
await cryptor.encryptFieldsInDocuments([this]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
schema.pre(
|
|
59
|
+
'insertMany',
|
|
60
|
+
async function encryptionPreInsertMany(_, docs, options) {
|
|
61
|
+
// `this` will be the model
|
|
62
|
+
if (options?.rawResult) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'Raw result not supported for insertMany with Encrypt plugin'
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
await cryptor.encryptFieldsInDocuments(docs);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
schema.pre(updateOneEvents, async function encryptionPreUpdateOne() {
|
|
73
|
+
// `this` will be a query
|
|
74
|
+
await cryptor.encryptFieldsInQuery(this);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
schema.pre('updateMany', async function encryptionPreUpdateMany() {
|
|
78
|
+
// `this` will be a query
|
|
79
|
+
cryptor.expectNotToUpdateManyEncrypted(this.getUpdate());
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
schema.pre('update', async function encryptionPreUpdate() {
|
|
83
|
+
// `this` will be a query
|
|
84
|
+
const { multiple } = this.getOptions();
|
|
85
|
+
|
|
86
|
+
if (multiple) {
|
|
87
|
+
cryptor.expectNotToUpdateManyEncrypted(this.getUpdate());
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
await cryptor.encryptFieldsInQuery(this);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// --------------------------------------------
|
|
95
|
+
// ### Decrypt documents after they are loaded.
|
|
96
|
+
// --------------------------------------------
|
|
97
|
+
schema.post('save', async function encryptionPreSave() {
|
|
98
|
+
// `this` will be a doc
|
|
99
|
+
await cryptor.decryptFieldsInDocuments([this]);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
schema.post(findOneEvents, async function encryptionPostFindOne(doc) {
|
|
103
|
+
// `this` will be a query
|
|
104
|
+
const { rawResult } = this.getOptions();
|
|
105
|
+
|
|
106
|
+
if (rawResult) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
await cryptor.decryptFieldsInDocuments([doc]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
schema.post('find', async function encryptionPostFind(docs) {
|
|
114
|
+
// `this` will be a query
|
|
115
|
+
await cryptor.decryptFieldsInDocuments(docs);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
schema.post('insertMany', async function encryptionPostInsertMany(docs) {
|
|
119
|
+
// `this` will be the model
|
|
120
|
+
await cryptor.decryptFieldsInDocuments(docs);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
module.exports = { Encrypt };
|