Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions 16 src/telemetrydeck.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { version } from '../package.json';
import sha256 from './utils/sha256.mjs';
import assertKeyValue from './utils/assert-key-value.mjs';
import transformPayload from './utils/transform-payload.mjs';
import { sha256 } from './utils/sha256.mjs';
import { assertKeyValue } from './utils/assert-key-value.mjs';
import { transformPayload } from './utils/transform-payload.mjs';

const APP = 'app';
const USER = 'user';
Expand Down Expand Up @@ -91,8 +91,14 @@ export class TelemetryDeck {
}
}

if (window && window.td) {
// Automatically attach a TelemetryDeck instance to the window object once the SDK loads
if (window) {
const td = new TelemetryDeck({});
td.ingest(window.td);

// Ingest messages which where pushed to an array on the window object
if (window.td) {
td.ingest(window.td);
}

window.td = td;
}
4 changes: 1 addition & 3 deletions 4 src/utils/assert-key-value.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const assertKeyValue = (key, value) => {
export const assertKeyValue = (key, value) => {
if (!value) {
throw new Error(`TelemetryDeck: "${key}" is not set`);
}
};

export default assertKeyValue;
4 changes: 2 additions & 2 deletions 4 src/utils/sha256.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// https://stackoverflow.com/a/48161723/54547
export default async function sha256(message) {
export async function sha256(message) {
// encode as UTF-8
const messageBuffer = new TextEncoder().encode(message);

Expand All @@ -12,4 +12,4 @@ export default async function sha256(message) {
// convert bytes to hex string
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
return hashHex;
}
}
5 changes: 2 additions & 3 deletions 5 src/utils/transform-payload.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
const transformPayload = (payload) => Object.entries(payload).map((entry) => entry.join(':'));

export default transformPayload;
export const transformPayload = (payload) =>
Object.entries(payload).map((entry) => entry.join(':'));
Morty Proxy This is a proxified and sanitized view of the page, visit original site.