-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added customerio group call support (#1869)
* feat: added customerio group call support * feat: endpoint reference added * feat: 500kb size limit check added * feat: object_type_id mapping support added
- Loading branch information
1 parent
5d5c1d3
commit 5e692ea
Showing
10 changed files
with
1,268 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
[ | ||
{ | ||
"destKey": "object_id", | ||
"sourceKeys": "groupId", | ||
"sourceFromGenericMap": true, | ||
"required": true | ||
}, | ||
{ | ||
"destKey": "object_type_id", | ||
"sourceKeys": "traits.objectTypeId", | ||
"metadata": { | ||
"defaultValue": "1" | ||
}, | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "userId", | ||
"sourceKeys": "userIdOnly", | ||
"sourceFromGenericMap": true, | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "email", | ||
"sourceKeys": [ | ||
"context.traits.email", | ||
"properties.email", | ||
"context.externalId.0.id" | ||
], | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "action", | ||
"sourceKeys": [ | ||
"traits.action", | ||
"properties.action" | ||
], | ||
"required": false | ||
}, | ||
{ | ||
"destKey": "attributes", | ||
"sourceKeys": "traits", | ||
"required": false, | ||
"metadata": { | ||
"excludes": [ | ||
"action" | ||
] | ||
} | ||
} | ||
] |
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,43 @@ | ||
const { MAX_BATCH_SIZE } = require('./config'); | ||
|
||
const getSizeInBytes = (obj) => { | ||
let str = null; | ||
if (typeof obj === 'string') { | ||
// If obj is a string, then use it | ||
str = obj; | ||
} else { | ||
// Else, make obj into a string | ||
str = JSON.stringify(obj); | ||
} | ||
// Get the length of the Uint8Array | ||
const bytes = new TextEncoder().encode(str).length; | ||
return bytes; | ||
}; | ||
|
||
const getEventChunks = (groupEvents) => { | ||
const eventChunks = []; | ||
let batchedData = []; | ||
let metadata = []; | ||
let size = 0; | ||
|
||
groupEvents.forEach((events) => { | ||
const objSize = getSizeInBytes(events); | ||
size += objSize; | ||
if (batchedData.length === MAX_BATCH_SIZE || size > 500000) { | ||
eventChunks.push({ data: batchedData, metadata }); | ||
batchedData = []; | ||
metadata = []; | ||
size = 0; | ||
} | ||
metadata.push(events.metadata); | ||
batchedData.push(events.message.body.JSON); | ||
}); | ||
|
||
if (batchedData.length > 0) { | ||
eventChunks.push({ data: batchedData, metadata }); | ||
} | ||
|
||
return eventChunks; | ||
}; | ||
|
||
module.exports = { getEventChunks }; |
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
Oops, something went wrong.