@friggframework/core 0.2.31-v1-alpha.6 → 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 -13
- 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,284 @@
|
|
|
1
|
+
const nock = require('nock');
|
|
2
|
+
const Authenticator = require('./Authenticator');
|
|
3
|
+
const { join: joinPath } = require('path');
|
|
4
|
+
const { parse: parseUrl } = require('url');
|
|
5
|
+
const { mkdir, readFile, rename, rm, writeFile } = require('fs/promises');
|
|
6
|
+
|
|
7
|
+
// TODO store in DB?
|
|
8
|
+
const tokenDirectory = joinPath(process.cwd(), 'test', '.token-cache');
|
|
9
|
+
const fixtureDirectory = joinPath(process.cwd(), 'test', 'recorded-requests');
|
|
10
|
+
nock.back.fixtures = fixtureDirectory;
|
|
11
|
+
|
|
12
|
+
// Try to rename but fail silently if the file does not exist.
|
|
13
|
+
const tryRename = async (a, b) => {
|
|
14
|
+
try {
|
|
15
|
+
await rename(a, b);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
if (error.code === 'ENOENT') {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const getJestGlobalState = () => {
|
|
24
|
+
const globalSymbols = Object.getOwnPropertySymbols(global);
|
|
25
|
+
let jestState;
|
|
26
|
+
globalSymbols.forEach((sym) => {
|
|
27
|
+
if (sym.toString() === 'Symbol(JEST_STATE_SYMBOL)') {
|
|
28
|
+
jestState = global[sym];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return jestState;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const checkForOnlies = () => {
|
|
36
|
+
let didFindOnly = false;
|
|
37
|
+
const findOnly = (child) => {
|
|
38
|
+
if (child.mode === 'only') {
|
|
39
|
+
didFindOnly = true;
|
|
40
|
+
}
|
|
41
|
+
if (child.children) {
|
|
42
|
+
child.children.forEach((nestedChild) => {
|
|
43
|
+
findOnly(nestedChild);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const jestState = getJestGlobalState();
|
|
48
|
+
const rootDescribe = jestState.rootDescribeBlock;
|
|
49
|
+
|
|
50
|
+
for (const child of rootDescribe.children) {
|
|
51
|
+
findOnly(child);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return didFindOnly;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const mockApi = (Api, classOptionByName = {}) => {
|
|
58
|
+
const {
|
|
59
|
+
authenticationMode,
|
|
60
|
+
displayName = Api.name,
|
|
61
|
+
filteringScope,
|
|
62
|
+
} = classOptionByName;
|
|
63
|
+
// The tag is the lower case display name, with any trailing 'Api' in the string removed.
|
|
64
|
+
const tag = displayName.replace(/Api$/i, '').toLowerCase();
|
|
65
|
+
const tokenFile = `${displayName}.json`;
|
|
66
|
+
const tokenFileFullPath = joinPath(tokenDirectory, tokenFile);
|
|
67
|
+
|
|
68
|
+
return class MockedApi extends Api {
|
|
69
|
+
static name = `Mocked${displayName}`;
|
|
70
|
+
static tokenResponse = null;
|
|
71
|
+
static excludedRecordingPaths = [];
|
|
72
|
+
static #context = {};
|
|
73
|
+
|
|
74
|
+
static async initialize() {
|
|
75
|
+
this.#context = {};
|
|
76
|
+
|
|
77
|
+
const didFindOnlies = checkForOnlies();
|
|
78
|
+
|
|
79
|
+
if (didFindOnlies) {
|
|
80
|
+
throw new Error(
|
|
81
|
+
'Cancelled recording API mocks because some tests were marked `.only`. Please remove any `.only`s from any `describe` blocks deeper than the root level, and all `it` blocks.'
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
this.#context.originalNockMode = nock.back.currentMode;
|
|
86
|
+
|
|
87
|
+
const { npm_config_record_apis: apisToRecordText = '' } =
|
|
88
|
+
process.env;
|
|
89
|
+
const apisToRecord = apisToRecordText
|
|
90
|
+
.split(',')
|
|
91
|
+
.map((name) => name.trim().toLowerCase());
|
|
92
|
+
|
|
93
|
+
if (apisToRecord.includes(tag)) {
|
|
94
|
+
this.#context.nockMode = 'update';
|
|
95
|
+
} else {
|
|
96
|
+
this.#context.nockMode = 'lockdown';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
nock.back.setMode(this.#context.nockMode);
|
|
100
|
+
|
|
101
|
+
const fixtureFile = `${displayName}.json`;
|
|
102
|
+
|
|
103
|
+
if (this.#context.nockMode === 'update') {
|
|
104
|
+
const fixtureFileFullPath = joinPath(
|
|
105
|
+
fixtureDirectory,
|
|
106
|
+
fixtureFile
|
|
107
|
+
);
|
|
108
|
+
const fixtureFileBackupFullPath = joinPath(
|
|
109
|
+
fixtureDirectory,
|
|
110
|
+
`.${displayName}.json.backup`
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
await tryRename(fixtureFileFullPath, fixtureFileBackupFullPath);
|
|
114
|
+
|
|
115
|
+
this.#context.restoreFixture = async () =>
|
|
116
|
+
await tryRename(
|
|
117
|
+
fixtureFileBackupFullPath,
|
|
118
|
+
fixtureFileFullPath
|
|
119
|
+
);
|
|
120
|
+
this.#context.deleteFixtureBackup = async () =>
|
|
121
|
+
await rm(fixtureFileBackupFullPath, { force: true });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const nockBack = await nock.back(fixtureFile, {
|
|
125
|
+
before: (scope) => {
|
|
126
|
+
if (filteringScope) {
|
|
127
|
+
scope.options.filteringScope = filteringScope;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
// Filter out token URLs
|
|
131
|
+
afterRecord: (recordings) =>
|
|
132
|
+
recordings.filter(
|
|
133
|
+
({ path }) =>
|
|
134
|
+
!this.excludedRecordingPaths.includes(path)
|
|
135
|
+
),
|
|
136
|
+
recorder: {
|
|
137
|
+
output_objects: true,
|
|
138
|
+
enable_reqheaders_recording: false,
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
this.#context.assertAllRequests = () =>
|
|
143
|
+
nockBack.context.assertScopesFinished();
|
|
144
|
+
this.#context.done = () => nockBack.nockDone();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static async clean() {
|
|
148
|
+
const {
|
|
149
|
+
assertAllRequests,
|
|
150
|
+
done,
|
|
151
|
+
nockMode,
|
|
152
|
+
originalNockMode,
|
|
153
|
+
restoreFixture,
|
|
154
|
+
deleteFixtureBackup,
|
|
155
|
+
} = this.#context;
|
|
156
|
+
|
|
157
|
+
const { didAllTestsPass } = global.mockApiResults;
|
|
158
|
+
|
|
159
|
+
if (done) {
|
|
160
|
+
done();
|
|
161
|
+
}
|
|
162
|
+
if (originalNockMode) {
|
|
163
|
+
nock.back.setMode(originalNockMode);
|
|
164
|
+
}
|
|
165
|
+
if (assertAllRequests && nockMode !== 'update') {
|
|
166
|
+
assertAllRequests();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
nock.cleanAll();
|
|
170
|
+
nock.restore();
|
|
171
|
+
|
|
172
|
+
if (nockMode === 'update') {
|
|
173
|
+
if (!didAllTestsPass) {
|
|
174
|
+
try {
|
|
175
|
+
await restoreFixture();
|
|
176
|
+
} finally {
|
|
177
|
+
throw new Error(
|
|
178
|
+
'Cancelled recording API mocks because some tests failed. Please fix the failing tests and try to record again.'
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
await deleteFixtureBackup();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
static async saveCachedTokenResponse() {
|
|
188
|
+
if (!this.tokenResponse) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
await mkdir(tokenDirectory, { recursive: true });
|
|
193
|
+
await writeFile(
|
|
194
|
+
tokenFileFullPath,
|
|
195
|
+
JSON.stringify(this.tokenResponse)
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static async loadCachedTokenResponse() {
|
|
200
|
+
try {
|
|
201
|
+
const tokenResponseText = await readFile(tokenFileFullPath);
|
|
202
|
+
this.tokenResponse = JSON.parse(tokenResponseText);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
if (error.code === 'ENOENT') {
|
|
205
|
+
this.tokenResponse = null;
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
static async mock(...constructorParameters) {
|
|
213
|
+
const api = new this(...constructorParameters);
|
|
214
|
+
|
|
215
|
+
if (nock.back.currentMode !== 'lockdown') {
|
|
216
|
+
await this.loadCachedTokenResponse();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// TODO read authentication mode from module package
|
|
220
|
+
if (authenticationMode === 'client_credentials') {
|
|
221
|
+
// TODO make generic (tied to crossbeam api)
|
|
222
|
+
api.grantType = 'client_credentials';
|
|
223
|
+
api.refreshAccessToken = api.getTokenFromClientCredentials;
|
|
224
|
+
|
|
225
|
+
if (process.env.CROSSBEAM_API_BASE_URL)
|
|
226
|
+
api.baseUrl = process.env.CROSSBEAM_API_BASE_URL;
|
|
227
|
+
if (process.env.CROSSBEAM_API_AUTH_URL)
|
|
228
|
+
api.tokenUri = `${process.env.CROSSBEAM_API_AUTH_URL}/oauth/token`;
|
|
229
|
+
if (process.env.CROSSBEAM_API_AUDIENCE)
|
|
230
|
+
api.audience = process.env.CROSSBEAM_API_AUDIENCE;
|
|
231
|
+
|
|
232
|
+
api.client_secret = process.env.CROSSBEAM_TEST_CLIENT_SECRET;
|
|
233
|
+
api.client_id = process.env.CROSSBEAM_TEST_CLIENT_ID;
|
|
234
|
+
api.refreshAccessToken = api.getTokenFromClientCredentials;
|
|
235
|
+
|
|
236
|
+
this.tokenResponse = await api.getTokenFromClientCredentials();
|
|
237
|
+
} else if (authenticationMode === 'puppet') {
|
|
238
|
+
throw new Error('Not yet implemented');
|
|
239
|
+
} else if (authenticationMode === 'browser') {
|
|
240
|
+
if (nock.back.currentMode !== 'lockdown') {
|
|
241
|
+
const { path: tokenPath } = parseUrl(api.tokenUri);
|
|
242
|
+
this.excludedRecordingPaths.push(tokenPath);
|
|
243
|
+
|
|
244
|
+
if (this.tokenResponse) {
|
|
245
|
+
await api.setTokens(this.tokenResponse);
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
await api.testAuth();
|
|
249
|
+
} catch {
|
|
250
|
+
this.tokenResponse = null;
|
|
251
|
+
nock.cleanAll();
|
|
252
|
+
await rm(tokenFileFullPath, {
|
|
253
|
+
force: true,
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
if (!this.tokenResponse) {
|
|
259
|
+
const url = api.authorizationUri;
|
|
260
|
+
const { data } = await Authenticator.oauth2(url);
|
|
261
|
+
const { code } = data;
|
|
262
|
+
this.tokenResponse = await api.getTokenFromCode(code);
|
|
263
|
+
await api.setTokens(this.tokenResponse);
|
|
264
|
+
nock.cleanAll();
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
} else if (authenticationMode === 'manual') {
|
|
268
|
+
// NOOP. This space intentionally left blank. No action should be performed in this mode, and the developer writing the test will handle authentication externally to this module.
|
|
269
|
+
} else {
|
|
270
|
+
throw new Error(
|
|
271
|
+
'Unrecognized authentication mode for mocked API.'
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (nock.back.currentMode !== 'lockdown') {
|
|
276
|
+
await this.saveCachedTokenResponse();
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
return api;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
module.exports = { mockApi };
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const { Auther, Credential, Entity } = require('../module-plugin');
|
|
2
|
+
const { IntegrationModel } = require('../integrations');
|
|
3
|
+
const { mongoose } = require('../database/mongoose');
|
|
4
|
+
|
|
5
|
+
async function createMockIntegration(IntegrationClassDef, userId = null, config = {},) {
|
|
6
|
+
const integration = new IntegrationClassDef();
|
|
7
|
+
userId = userId || new mongoose.Types.ObjectId();
|
|
8
|
+
integration.delegateTypes.push(...IntegrationClassDef.Config.events)
|
|
9
|
+
|
|
10
|
+
const insertOptions = {
|
|
11
|
+
new: true,
|
|
12
|
+
upsert: true,
|
|
13
|
+
setDefaultsOnInsert: true,
|
|
14
|
+
}
|
|
15
|
+
const user = {user: userId}
|
|
16
|
+
|
|
17
|
+
const credential = await Credential.findOneAndUpdate(
|
|
18
|
+
user,
|
|
19
|
+
{ $set: user },
|
|
20
|
+
insertOptions
|
|
21
|
+
);
|
|
22
|
+
const entity1 = await Entity.findOneAndUpdate(
|
|
23
|
+
user,
|
|
24
|
+
{
|
|
25
|
+
$set: {
|
|
26
|
+
credential: credential.id,
|
|
27
|
+
user: userId,
|
|
28
|
+
name: 'Test user',
|
|
29
|
+
externalId: '1234567890123456',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
insertOptions
|
|
33
|
+
);
|
|
34
|
+
const entity2 = await Entity.findOneAndUpdate(
|
|
35
|
+
user,
|
|
36
|
+
{
|
|
37
|
+
$set: {
|
|
38
|
+
credential: credential.id,
|
|
39
|
+
user: userId,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
insertOptions
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const entities = [entity1, entity2]
|
|
46
|
+
integration.record = await IntegrationModel.create({
|
|
47
|
+
entities,
|
|
48
|
+
user: userId,
|
|
49
|
+
config: {type: IntegrationClassDef.Config.name, ...config}
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
integration.id = integration.record._id
|
|
53
|
+
|
|
54
|
+
for (const i in entities){
|
|
55
|
+
const [moduleName, ModuleDef] = Object.entries(IntegrationClassDef.modules)[i];
|
|
56
|
+
const module = Auther.getInstance({definition: ModuleDef, userId: userId})
|
|
57
|
+
module.entity = entities[i];
|
|
58
|
+
integration[moduleName] = module;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return integration
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function createMockApiObject(jest, api = {}, mockMethodMap) {
|
|
65
|
+
// take in an api class and object with keys that are method names
|
|
66
|
+
// and values which are the mock response (or implementation)
|
|
67
|
+
const clone = (data) => JSON.parse(JSON.stringify(data));
|
|
68
|
+
|
|
69
|
+
for (const [methodName, mockDataOrImplementation] of Object.entries(mockMethodMap)) {
|
|
70
|
+
if (mockDataOrImplementation instanceof Function) {
|
|
71
|
+
api[methodName] = jest.fn(mockDataOrImplementation);
|
|
72
|
+
}
|
|
73
|
+
else if (api[methodName]?.constructor?.name === "AsyncFunction") {
|
|
74
|
+
api[methodName] = jest.fn().mockResolvedValue(clone(mockDataOrImplementation));
|
|
75
|
+
} else {
|
|
76
|
+
api[methodName] = jest.fn().mockReturnValue(clone(mockDataOrImplementation));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return api;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
module.exports = {createMockIntegration, createMockApiObject};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { MongoMemoryServer } = require('mongodb-memory-server');
|
|
2
|
+
|
|
3
|
+
class TestMongo {
|
|
4
|
+
#mongoServer;
|
|
5
|
+
|
|
6
|
+
// Start the in-memory mongo instance and set env variable for the app to use in its connection.
|
|
7
|
+
async start() {
|
|
8
|
+
this.#mongoServer = await MongoMemoryServer.create();
|
|
9
|
+
process.env.MONGO_URI = this.#mongoServer.getUri();
|
|
10
|
+
console.log('Started in memory mongo server', process.env.MONGO_URI);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async stop() {
|
|
14
|
+
await this.#mongoServer.stop();
|
|
15
|
+
process.env.MONGO_URI = undefined;
|
|
16
|
+
this.#mongoServer = undefined;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
TestMongo,
|
|
22
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const originalEnv = process.env;
|
|
2
|
+
|
|
3
|
+
function overrideEnvironment(overrideByKey) {
|
|
4
|
+
process.env = { ...process.env, ...overrideByKey };
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function restoreEnvironment() {
|
|
8
|
+
process.env = originalEnv;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
module.exports = { overrideEnvironment, restoreEnvironment };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# v0.2.0 (Wed Sep 06 2023)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- Bump independent versions \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# v0.1.2 (Thu Aug 03 2023)
|
|
14
|
+
|
|
15
|
+
#### 🐛 Bug Fix
|
|
16
|
+
|
|
17
|
+
- Bump independent versions \[skip ci\] ([@seanspeaks](https://github.com/seanspeaks))
|
|
18
|
+
|
|
19
|
+
#### Authors: 1
|
|
20
|
+
|
|
21
|
+
- Sean Matthews ([@seanspeaks](https://github.com/seanspeaks))
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
# v0.1.1 (Wed Jul 05 2023)
|
|
26
|
+
|
|
27
|
+
:tada: This release contains work from new contributors! :tada:
|
|
28
|
+
|
|
29
|
+
Thanks for all your work!
|
|
30
|
+
|
|
31
|
+
:heart: Leonardo Ferreira ([@leofmds](https://github.com/leofmds))
|
|
32
|
+
|
|
33
|
+
:heart: Roberto Oliveros ([@roboli](https://github.com/roboli))
|
|
34
|
+
|
|
35
|
+
:heart: Charaf ([@Fibii](https://github.com/Fibii))
|
|
36
|
+
|
|
37
|
+
#### 🐛 Bug Fix
|
|
38
|
+
|
|
39
|
+
- Add publicshConfig: public and changed license to MIT in types package [#195](https://github.com/friggframework/frigg/pull/195) ([@leofmds](https://github.com/leofmds))
|
|
40
|
+
- Add publicshConfig: public and changed license to MIT in types package ([@leofmds](https://github.com/leofmds))
|
|
41
|
+
- Feature/lef 270 list organizations sites [#192](https://github.com/friggframework/frigg/pull/192) ([@roboli](https://github.com/roboli))
|
|
42
|
+
- add types [#165](https://github.com/friggframework/frigg/pull/165) ([@Fibii](https://github.com/Fibii))
|
|
43
|
+
- add types ([@Fibii](https://github.com/Fibii))
|
|
44
|
+
|
|
45
|
+
#### Authors: 3
|
|
46
|
+
|
|
47
|
+
- Charaf ([@Fibii](https://github.com/Fibii))
|
|
48
|
+
- Leonardo Ferreira ([@leofmds](https://github.com/leofmds))
|
|
49
|
+
- Roberto Oliveros ([@roboli](https://github.com/roboli))
|
package/types/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# types
|
|
2
|
+
|
|
3
|
+
This package exports the `types` used in [Frigg](https://friggframework.org) packages.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Get Started
|
|
7
|
+
Install the package with `npm` or `yarn`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @friggframework/types
|
|
11
|
+
```
|
|
12
|
+
or
|
|
13
|
+
```bash
|
|
14
|
+
yarn add @friggframework/types
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Make sure to reference the types in your `tsconfig.json`
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
"typeRoots": [
|
|
21
|
+
"./node_modules/@types",
|
|
22
|
+
"./node_modules/@friggframework/types"
|
|
23
|
+
]
|
|
24
|
+
```
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
declare module "@friggframework/assertions" {
|
|
2
|
+
type TypeOfType =
|
|
3
|
+
| "undefined"
|
|
4
|
+
| "object"
|
|
5
|
+
| "boolean"
|
|
6
|
+
| "number"
|
|
7
|
+
| "string"
|
|
8
|
+
| "function"
|
|
9
|
+
| "symbol"
|
|
10
|
+
| "bigint";
|
|
11
|
+
|
|
12
|
+
export function get<TObject extends object, TKey extends string, TDefault>(
|
|
13
|
+
object: TObject,
|
|
14
|
+
key: TKey | undefined,
|
|
15
|
+
defaultValue: Exclude<TDefault, undefined>
|
|
16
|
+
): TKey extends keyof TObject ? TObject[TKey] : TDefault;
|
|
17
|
+
|
|
18
|
+
export function get<TObject extends object, TKey extends keyof TObject>(
|
|
19
|
+
object: TObject,
|
|
20
|
+
key: TKey
|
|
21
|
+
): TObject[TKey];
|
|
22
|
+
|
|
23
|
+
export function getAll<TObject extends object, TKey extends keyof TObject>(
|
|
24
|
+
object: TObject,
|
|
25
|
+
requiredKeys: TKey[]
|
|
26
|
+
): Partial<TObject>;
|
|
27
|
+
|
|
28
|
+
export function verifyType(value: unknown, paramType: TypeOfType): void;
|
|
29
|
+
|
|
30
|
+
export function getParamAndVerifyParamType<
|
|
31
|
+
TObject extends object,
|
|
32
|
+
TKey extends string,
|
|
33
|
+
TKeyType extends TypeOfType,
|
|
34
|
+
TDefault
|
|
35
|
+
>(
|
|
36
|
+
params: TObject,
|
|
37
|
+
key: TKey,
|
|
38
|
+
type: TKeyType,
|
|
39
|
+
defaultValue: TDefault
|
|
40
|
+
): TDefault;
|
|
41
|
+
|
|
42
|
+
export function getParamAndVerifyParamType<
|
|
43
|
+
TObject extends object,
|
|
44
|
+
TKey extends keyof TObject,
|
|
45
|
+
TKeyType extends TypeOfType
|
|
46
|
+
>(params: TObject, key: TKey, type: TKeyType): TObject[TKey];
|
|
47
|
+
|
|
48
|
+
export function getArrayParamAndVerifyParamType<
|
|
49
|
+
TObject extends object,
|
|
50
|
+
TKey extends string,
|
|
51
|
+
TKeyType extends TypeOfType,
|
|
52
|
+
TDefault
|
|
53
|
+
>(
|
|
54
|
+
params: TObject,
|
|
55
|
+
key: TKey,
|
|
56
|
+
type: TKeyType,
|
|
57
|
+
defaultValue: TDefault
|
|
58
|
+
): TDefault;
|
|
59
|
+
|
|
60
|
+
export function getArrayParamAndVerifyParamType<
|
|
61
|
+
TObject extends object,
|
|
62
|
+
TKey extends keyof TObject,
|
|
63
|
+
TKeyType extends TypeOfType
|
|
64
|
+
>(params: TObject, key: TKey, type: TKeyType): TObject[TKey];
|
|
65
|
+
|
|
66
|
+
export function getAndVerifyType<
|
|
67
|
+
TObject extends object,
|
|
68
|
+
TKey extends keyof TObject,
|
|
69
|
+
TClassType extends unknown
|
|
70
|
+
>(object: TObject, key: TKey, classType: TClassType): TObject[TKey];
|
|
71
|
+
|
|
72
|
+
export function getAndVerifyType<
|
|
73
|
+
TObject extends object,
|
|
74
|
+
TKey extends string,
|
|
75
|
+
TClassType extends unknown,
|
|
76
|
+
TDefault
|
|
77
|
+
>(
|
|
78
|
+
object: TObject,
|
|
79
|
+
key: TKey,
|
|
80
|
+
classType: TClassType,
|
|
81
|
+
defaultValue: TDefault
|
|
82
|
+
): TKey extends keyof TObject ? TObject[TKey] : TDefault;
|
|
83
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
declare module "@friggframework/associations/model" {
|
|
2
|
+
import { Model } from "mongoose";
|
|
3
|
+
|
|
4
|
+
export class Association extends Model {
|
|
5
|
+
integrationId: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
primaryObject: string;
|
|
9
|
+
objects: {
|
|
10
|
+
entityId: string;
|
|
11
|
+
objectType: string;
|
|
12
|
+
objId: string;
|
|
13
|
+
metadata?: object;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
declare module "@friggframework/associations/association" {
|
|
19
|
+
export default class Association implements IFriggAssociation {
|
|
20
|
+
data: any;
|
|
21
|
+
dataIdentifier: any;
|
|
22
|
+
dataIdentifierHash: string;
|
|
23
|
+
matchHash: string;
|
|
24
|
+
moduleName: any;
|
|
25
|
+
syncId: any;
|
|
26
|
+
|
|
27
|
+
static Config: {
|
|
28
|
+
name: "Association";
|
|
29
|
+
reverseModuleMap: {};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
constructor(params: AssociationConstructor);
|
|
33
|
+
|
|
34
|
+
dataKeyIsReplaceable(key: string): boolean;
|
|
35
|
+
|
|
36
|
+
equals(syncObj: any): boolean;
|
|
37
|
+
|
|
38
|
+
getHashData(): string;
|
|
39
|
+
|
|
40
|
+
getName(): any;
|
|
41
|
+
|
|
42
|
+
hashJSON(data: any): string;
|
|
43
|
+
|
|
44
|
+
isModuleInMap(moduleName: any): any;
|
|
45
|
+
|
|
46
|
+
reverseModuleMap(moduleName: any): any;
|
|
47
|
+
|
|
48
|
+
setSyncId(syncId: string): any;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface IFriggAssociation {
|
|
52
|
+
data: any;
|
|
53
|
+
moduleName: any;
|
|
54
|
+
dataIdentifier: any;
|
|
55
|
+
dataIdentifierHash: string;
|
|
56
|
+
matchHash: string;
|
|
57
|
+
syncId: any;
|
|
58
|
+
|
|
59
|
+
equals(syncObj: any): boolean;
|
|
60
|
+
dataKeyIsReplaceable(key: string): boolean;
|
|
61
|
+
isModuleInMap(moduleName: any): any;
|
|
62
|
+
getName(): any;
|
|
63
|
+
getHashData(): string;
|
|
64
|
+
setSyncId(syncId: string): any;
|
|
65
|
+
reverseModuleMap(moduleName: any): any;
|
|
66
|
+
hashJSON(data: any): string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
type AssociationConstructor = {
|
|
70
|
+
data: any;
|
|
71
|
+
moduleName: any;
|
|
72
|
+
dataIdentifier: any;
|
|
73
|
+
};
|
|
74
|
+
}
|
package/types/bump3.txt
ADDED
|
File without changes
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
declare module "@friggframework/core" {
|
|
2
|
+
import { SQS } from "aws-sdk";
|
|
3
|
+
|
|
4
|
+
export class Delegate implements IFriggDelegate {
|
|
5
|
+
delegate: any;
|
|
6
|
+
delegateTypes: any[];
|
|
7
|
+
|
|
8
|
+
constructor(params: Record<string, unknown> & { delegate?: unknown });
|
|
9
|
+
notify(delegateString: string, object?: any): Promise<any>;
|
|
10
|
+
receiveNotification(
|
|
11
|
+
notifier: any,
|
|
12
|
+
delegateString: string,
|
|
13
|
+
object?: any
|
|
14
|
+
): Promise<any>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface IFriggDelegate {
|
|
18
|
+
delegate: any;
|
|
19
|
+
delegateTypes: any[];
|
|
20
|
+
|
|
21
|
+
notify(delegateString: string, object?: any): Promise<any>;
|
|
22
|
+
receiveNotification(
|
|
23
|
+
notifier: any,
|
|
24
|
+
delegateString: string,
|
|
25
|
+
object?: any
|
|
26
|
+
): Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export class Worker implements IWorker {
|
|
30
|
+
getQueueURL(params: GetQueueURLParams): Promise<string | undefined>;
|
|
31
|
+
|
|
32
|
+
run(params: { Records: any }): Promise<void>;
|
|
33
|
+
|
|
34
|
+
send(params: object & { QueueUrl: any }, delay?: number): Promise<string>;
|
|
35
|
+
|
|
36
|
+
sendAsyncSQSMessage(params: SendSQSMessageParams): Promise<string>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface IWorker {
|
|
40
|
+
getQueueURL(params: GetQueueURLParams): Promise<string | undefined>;
|
|
41
|
+
run(params: { Records: any }): Promise<void>;
|
|
42
|
+
send(params: object & { QueueUrl: any }, delay?: number): Promise<string>;
|
|
43
|
+
sendAsyncSQSMessage(params: SendSQSMessageParams): Promise<string>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function loadInstalledModules(): any[];
|
|
47
|
+
|
|
48
|
+
type GetQueueURLParams = {
|
|
49
|
+
QueueName: string;
|
|
50
|
+
QueueOwnerAWSAccountId?: string;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
type SendSQSMessageParams = SQS.SendMessageRequest;
|
|
54
|
+
}
|