-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: few sources migrated to v2 completely
- Loading branch information
1 parent
05f4790
commit 72c146c
Showing
27 changed files
with
147 additions
and
34 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
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,86 @@ | ||
const set = require('set-value'); | ||
const get = require('get-value'); | ||
|
||
const { getValueFromMessage } = require('../v0/util'); | ||
|
||
const context = (integration) => ({ | ||
library: { | ||
name: 'unknown', | ||
version: 'unknown', | ||
}, | ||
integration: { | ||
name: integration, | ||
}, | ||
}); | ||
|
||
class Message { | ||
constructor(integration) { | ||
this.context = context(integration); | ||
this.integrations = { | ||
[integration]: false, | ||
}; | ||
} | ||
|
||
setEventName(name) { | ||
this.event = name; | ||
} | ||
|
||
setEventType(type) { | ||
this.type = type; | ||
} | ||
|
||
setProperty(name, value) { | ||
set(this, name, value); | ||
} | ||
|
||
setProperties(event, mapping) { | ||
Object.keys(mapping).forEach((key) => { | ||
const setVal = get(event, key); | ||
let destKeys = mapping[key]; | ||
if (!Array.isArray(destKeys)) { | ||
destKeys = [destKeys]; | ||
} | ||
destKeys.forEach((destKey) => { | ||
const existingVal = get(this, destKey); | ||
// do not set if val setVal nil | ||
// give higher pref to first key in mapping.json in case of same value | ||
if ( | ||
setVal !== null && | ||
setVal !== undefined && | ||
(existingVal === null || existingVal === undefined) | ||
) { | ||
set(this, destKey, setVal); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
setPropertiesV2(event, mappingJson) { | ||
mappingJson.forEach((mapping) => { | ||
const { sourceKeys } = mapping; | ||
let { destKeys } = mapping; | ||
const setVal = getValueFromMessage(event, sourceKeys); | ||
if (!Array.isArray(destKeys)) { | ||
destKeys = [destKeys]; | ||
} | ||
destKeys.forEach((destKey) => { | ||
const existingVal = get(this, destKey); | ||
// do not set if val setVal nil | ||
// give higher pref to first key in mapping.json in case of same value | ||
if ( | ||
setVal !== null && | ||
setVal !== undefined && | ||
(existingVal === null || existingVal === undefined) | ||
) { | ||
set(this, destKey, setVal); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
setTimestamp(timestamp) { | ||
this.timestamp = timestamp; | ||
} | ||
} | ||
|
||
module.exports = Message; |
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