-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change node messageId, and update core in order to remove transient d…
…ependencies from nodejs (#670)
- Loading branch information
Showing
11 changed files
with
71 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
'@segment/analytics-core': patch | ||
--- | ||
Allow consumers to inject custom messageId into EventFactory, allowing us to remove node transient dependency on md5 library. Change node messageId to format "node-next-[unix epoch time]-[uuid]". |
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 |
---|---|---|
|
@@ -32,7 +32,6 @@ | |
}, | ||
"packageManager": "[email protected]", | ||
"dependencies": { | ||
"@lukeed/uuid": "^2.0.0", | ||
"dset": "^3.1.2", | ||
"tslib": "^2.4.0" | ||
} | ||
|
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
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,21 @@ | ||
import { createMessageId } from '../get-message-id' | ||
|
||
// https://gist.github.com/johnelliott/cf77003f72f889abbc3f32785fa3df8d | ||
const uuidv4Regex = | ||
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i | ||
|
||
describe(createMessageId, () => { | ||
it('returns a string in the format "node-next-[unix epoch time]-[uuid v4]"', () => { | ||
const msg = createMessageId().split('-') | ||
expect(msg.length).toBe(8) | ||
|
||
expect(`${msg[0]}-${msg[1]}`).toBe('node-next') | ||
|
||
const epochTimeSeg = msg[2] | ||
expect(typeof parseInt(epochTimeSeg)).toBe('number') | ||
expect(epochTimeSeg.length > 10).toBeTruthy() | ||
|
||
const uuidSeg = msg.slice(3).join('-') | ||
expect(uuidSeg).toEqual(expect.stringMatching(uuidv4Regex)) | ||
}) | ||
}) |
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,7 @@ | ||
import { EventFactory } from '@segment/analytics-core' | ||
import { createMessageId } from './get-message-id' | ||
|
||
export const createNodeEventFactory = () => | ||
new EventFactory({ | ||
createMessageId, | ||
}) |
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,10 @@ | ||
import { v4 } from '@lukeed/uuid/secure' | ||
|
||
/** | ||
* get a unique messageId with a very low chance of collisions | ||
* using @lukeed/uuid/secure uses the node crypto module, which is the fastest | ||
* @example "node-next-1668208232027-743be593-7789-4b74-8078-cbcc8894c586" | ||
*/ | ||
export const createMessageId = (): string => { | ||
return `node-next-${Date.now()}-${v4()}` | ||
} |
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