@friggframework/core 0.1.0 → 0.2.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/{Delegate.js → delegate.js} +1 -1
- package/index.js +4 -0
- package/jest.config.js +5 -0
- package/package.json +31 -30
- package/{Worker.js → worker.js} +2 -6
- package/Requester.js +0 -153
- package/auth/ApiKeyBase.js +0 -30
- package/auth/OAuth2Base.js +0 -203
- package/managers/IntegrationConfigManager.js +0 -22
- package/managers/IntegrationManager.js +0 -330
- package/managers/Migrator.js +0 -190
- package/managers/ModuleManager.js +0 -178
- package/managers/SyncManager.js +0 -501
- package/objects/association/Association.js +0 -81
- package/objects/integration/Options.js +0 -70
- package/objects/migration/Options.js +0 -34
- package/objects/sync/Sync.js +0 -119
package/objects/sync/Sync.js
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
const md5 = require('md5');
|
|
2
|
-
const ModuleManager = require('../../managers/ModuleManager');
|
|
3
|
-
const { debug } = require('@friggframework/logs');
|
|
4
|
-
const { get } = require('@friggframework/assertions');
|
|
5
|
-
|
|
6
|
-
class Sync {
|
|
7
|
-
static Config = {
|
|
8
|
-
name: 'Sync',
|
|
9
|
-
|
|
10
|
-
// an array of keys we will use to form an object and then hash it. Order matters here
|
|
11
|
-
// because it will effect how the hash results
|
|
12
|
-
keys: [],
|
|
13
|
-
|
|
14
|
-
// matchOn is an array of keys that make the variable unique when combined together
|
|
15
|
-
// and is used to sync with the other objects
|
|
16
|
-
// matchOn keys _have_ to have a value, otherwise the object is not considered a match
|
|
17
|
-
matchOn: [],
|
|
18
|
-
|
|
19
|
-
// a key value mapping of module to then a list of keys that will map to
|
|
20
|
-
// an a function that takes in the module object and return the value from it
|
|
21
|
-
// format as follows:
|
|
22
|
-
// {
|
|
23
|
-
// ModuleName:{
|
|
24
|
-
// firstName:(moduleObject)=>{moduleObject['name'][0]},
|
|
25
|
-
// lastName:(moduleObject)=>{moduleObject['name'][1]},
|
|
26
|
-
// },
|
|
27
|
-
// ....
|
|
28
|
-
// }
|
|
29
|
-
moduleMap: {},
|
|
30
|
-
reverseModuleMap: {},
|
|
31
|
-
};
|
|
32
|
-
constructor(params) {
|
|
33
|
-
super(params);
|
|
34
|
-
this.data = {};
|
|
35
|
-
|
|
36
|
-
let data = get(params, 'data');
|
|
37
|
-
this.moduleName = get(params, 'moduleName');
|
|
38
|
-
this.dataIdentifier = get(params, 'dataIdentifier');
|
|
39
|
-
this.useMapping = get(params, 'useMapping', true); // Use with caution...
|
|
40
|
-
|
|
41
|
-
this.dataIdentifierHash = this.constructor.hashJSON(
|
|
42
|
-
this.dataIdentifier
|
|
43
|
-
);
|
|
44
|
-
|
|
45
|
-
if (this.useMapping) {
|
|
46
|
-
for (let key of this.constructor.Config.keys) {
|
|
47
|
-
this.data[key] =
|
|
48
|
-
this.constructor.Config.moduleMap[this.moduleName][key](
|
|
49
|
-
data
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
} else {
|
|
53
|
-
this.data = data;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// matchHash is used to find matches between two sync objects
|
|
57
|
-
// Match data _has_ to have a value
|
|
58
|
-
const matchHashData = [];
|
|
59
|
-
this.missingMatchData = false;
|
|
60
|
-
for (const key of this.constructor.Config.matchOn) {
|
|
61
|
-
if (!this.data[key]) {
|
|
62
|
-
this.missingMatchData = true;
|
|
63
|
-
debug(`Data key of ${key} was missing from MatchOn`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
matchHashData.push(this.data[key]);
|
|
67
|
-
}
|
|
68
|
-
this.matchHash = this.constructor.hashJSON(matchHashData);
|
|
69
|
-
|
|
70
|
-
this.syncId = null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
equals(syncObj) {
|
|
74
|
-
return this.matchHash === syncObj.matchHash;
|
|
75
|
-
}
|
|
76
|
-
dataKeyIsReplaceable(key) {
|
|
77
|
-
return this.data[key] === null || this.data[key] === '';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
isModuleInMap(moduleName) {
|
|
81
|
-
return this.constructor.Config.moduleMap[name];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
getName() {
|
|
85
|
-
return this.constructor.Config.name;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
getHashData(params) {
|
|
89
|
-
let omitEmptyStringsFromData = get(
|
|
90
|
-
params,
|
|
91
|
-
'omitEmptyStringsFromData',
|
|
92
|
-
false
|
|
93
|
-
);
|
|
94
|
-
let orderedData = [];
|
|
95
|
-
for (let key of this.constructor.Config.keys) {
|
|
96
|
-
if (omitEmptyStringsFromData && this.data[key] === '') {
|
|
97
|
-
this.data[key] = undefined;
|
|
98
|
-
}
|
|
99
|
-
orderedData.push(this.data[key]);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return this.constructor.hashJSON(orderedData);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
setSyncId(syncId) {
|
|
106
|
-
this.syncId = syncId;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
reverseModuleMap(moduleName) {
|
|
110
|
-
return this.constructor.Config.reverseModuleMap[moduleName](this.data);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
static hashJSON(data) {
|
|
114
|
-
let dataString = JSON.stringify(data, null, 2);
|
|
115
|
-
return md5(dataString);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
module.exports = Sync;
|