File tree Expand file tree Collapse file tree 4 files changed +16
-13
lines changed Expand file tree Collapse file tree 4 files changed +16
-13
lines changed Original file line number Diff line number Diff line change 11import { version } from '../package.json' ;
2- import sha256 from './utils/sha256.mjs' ;
3- import assertKeyValue from './utils/assert-key-value.mjs' ;
4- import transformPayload from './utils/transform-payload.mjs' ;
2+ import { sha256 } from './utils/sha256.mjs' ;
3+ import { assertKeyValue } from './utils/assert-key-value.mjs' ;
4+ import { transformPayload } from './utils/transform-payload.mjs' ;
55
66const APP = 'app' ;
77const USER = 'user' ;
@@ -91,8 +91,14 @@ export class TelemetryDeck {
9191 }
9292}
9393
94- if ( window && window . td ) {
94+ // Automatically attach a TelemetryDeck instance to the window object once the SDK loads
95+ if ( window ) {
9596 const td = new TelemetryDeck ( { } ) ;
96- td . ingest ( window . td ) ;
97+
98+ // Ingest messages which where pushed to an array on the window object
99+ if ( window . td ) {
100+ td . ingest ( window . td ) ;
101+ }
102+
97103 window . td = td ;
98104}
Original file line number Diff line number Diff line change 1- const assertKeyValue = ( key , value ) => {
1+ export const assertKeyValue = ( key , value ) => {
22 if ( ! value ) {
33 throw new Error ( `TelemetryDeck: "${ key } " is not set` ) ;
44 }
55} ;
6-
7- export default assertKeyValue ;
Original file line number Diff line number Diff line change 11// https://stackoverflow.com/a/48161723/54547
2- export default async function sha256 ( message ) {
2+ export async function sha256 ( message ) {
33 // encode as UTF-8
44 const messageBuffer = new TextEncoder ( ) . encode ( message ) ;
55
@@ -12,4 +12,4 @@ export default async function sha256(message) {
1212 // convert bytes to hex string
1313 const hashHex = hashArray . map ( ( b ) => b . toString ( 16 ) . padStart ( 2 , '0' ) ) . join ( '' ) ;
1414 return hashHex ;
15- }
15+ }
Original file line number Diff line number Diff line change 1- const transformPayload = ( payload ) => Object . entries ( payload ) . map ( ( entry ) => entry . join ( ':' ) ) ;
2-
3- export default transformPayload ;
1+ export const transformPayload = ( payload ) =>
2+ Object . entries ( payload ) . map ( ( entry ) => entry . join ( ':' ) ) ;
You can’t perform that action at this time.
0 commit comments