Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@vonage/js-onewebrtc-telemetry

Package Overview
Dependencies
Maintainers
36
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vonage/js-onewebrtc-telemetry - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

CHANGELOG.md

1

dist/index.d.ts
export * from "./interfaces";
export * from "./reporter";
export * from "./metadata";

31

dist/interfaces.d.ts

@@ -25,14 +25,2 @@ export declare enum SourceType {

/**
* Type of source using the library.
*/
sourceType: SourceType;
/**
* Some string identifier identifying the application using the library.
*/
appId: string;
/**
* The proxy URL to route all internet traffic generated by this library. This field is optional.
*/
proxyUrl?: string;
/**
* Fetch method used to request the telemetry server, fetch by default

@@ -61,2 +49,19 @@ */

}
export declare type SendableReport = Omit<Report, "timestamp" | "applicationId" | "proxyUrl" | "proxyUrl">;
export type SendableReport = Omit<Report, "timestamp" | "applicationId" | "proxyUrl" | "proxyUrl">;
/**
* Specifies the addional information being sent with the telemetry collected by the library.
*/
export type VonageMetadata = {
/**
* Type of source using the library.
*/
sourceType: SourceType;
/**
* Some string identifier identifying the application using the library.
*/
appId: string;
/**
* The proxy URL to route all internet traffic generated by this library. This field is optional.
*/
proxyUrl?: string;
};

@@ -1,1 +0,1 @@

(function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r["js-onewebrtc-telemetry"]={}))})(this,function(r){"use strict";var x=Object.defineProperty;var I=(r,o,s)=>o in r?x(r,o,{enumerable:!0,configurable:!0,writable:!0,value:s}):r[o]=s;var a=(r,o,s)=>(I(r,typeof o!="symbol"?o+"":o,s),s);var o=(t=>(t.automation="automation",t.test="test",t.vbc="vbc",t.video="video",t.voice="voice",t))(o||{});const s="hlg.tokbox.com/prod/logging/vcp_webrtc",h="https://",m=1e4;let p;const y=new Uint8Array(16);function U(){if(!p&&(p=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!p))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return p(y)}const n=[];for(let t=0;t<256;++t)n.push((t+256).toString(16).slice(1));function b(t,e=0){return(n[t[e+0]]+n[t[e+1]]+n[t[e+2]]+n[t[e+3]]+"-"+n[t[e+4]]+n[t[e+5]]+"-"+n[t[e+6]]+n[t[e+7]]+"-"+n[t[e+8]]+n[t[e+9]]+"-"+n[t[e+10]]+n[t[e+11]]+n[t[e+12]]+n[t[e+13]]+n[t[e+14]]+n[t[e+15]]).toLowerCase()}const l={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function R(t,e,c){if(l.randomUUID&&!e&&!t)return l.randomUUID();t=t||{};const i=t.random||(t.rng||U)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,e){c=c||0;for(let d=0;d<16;++d)e[c+d]=i[d];return e}return b(i)}class v{constructor(e){a(this,"uuid",R());this.config=e}async send(e){var u;if(!this.config||!this.config.appId||!this.config.sourceType)return"Missing config, report not sent";const c=new AbortController,i=setTimeout(()=>c.abort(),m);return await((u=this.config.fetch)!=null?u:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(e)),signal:c.signal}),clearTimeout(i),"success"}getUrl(){var c,i;let e=(i=(c=this.config)==null?void 0:c.proxyUrl)!=null?i:h;return e+=(e.at(-1)==="/"?"":"/")+s,e}getHeaders(){return{"Content-Type":"application/json"}}buildReport(e){var c,i,d,u,g;return{guid:this.uuid,...e,applicationId:(i=(c=this.config)==null?void 0:c.appId)!=null?i:"",source:(u=(d=this.config)==null?void 0:d.sourceType)!=null?u:"",timestamp:Date.now(),proxyUrl:(g=this.config)==null?void 0:g.proxyUrl}}}r.Reporter=v,r.SourceType=o,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
(function(s,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(s=typeof globalThis<"u"?globalThis:s||self,r(s["js-onewebrtc-telemetry"]={}))})(this,function(s){"use strict";var $=Object.defineProperty;var H=(s,r,l)=>r in s?$(s,r,{enumerable:!0,configurable:!0,writable:!0,value:l}):s[r]=l;var A=(s,r,l)=>(H(s,typeof r!="symbol"?r+"":r,l),l);var r=(e=>(e.automation="automation",e.test="test",e.vbc="vbc",e.video="video",e.voice="voice",e))(r||{});const l="hlg.tokbox.com/prod/logging/vcp_webrtc",T="https://",U=1e4;let f;const k=new Uint8Array(16);function M(){if(!f&&(f=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!f))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return f(k)}const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).slice(1));function N(e,t=0){return(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase()}const m={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function O(e,t,n){if(m.randomUUID&&!t&&!e)return m.randomUUID();e=e||{};const i=e.random||(e.rng||M)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){n=n||0;for(let a=0;a<16;++a)t[n+a]=i[a];return t}return N(i)}const c={};var u=(e=>(e.INIT="INIT",e.FORWARD="FORWARD",e.TERMINATE="TERMINATE",e.GLOBALS_SYNC="GLOBALS_SYNC",e))(u||{});function b(e){return[ImageBitmap,ReadableStream,WritableStream].some(n=>e instanceof n)}let C=0;function v(e,t,n,i,a){const d=C++;return e.postMessage({id:d,type:t,functionName:n,args:i},i.filter(p=>b(p))),new Promise(p=>{a==null||a.set(d,p)})}function g(e,t){const{id:n,type:i}=e,a=Array.isArray(t)?t:[t];postMessage({id:n,type:i,result:t},a.filter(d=>b(d)))}const w={};function I(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function E(){if(I())g({type:u.GLOBALS_SYNC},c);else{const e=[];for(const t in w){const{worker:n,resolvers:i}=w[t].workerContext;n&&e.push(v(n,u.GLOBALS_SYNC,"",[c],i))}await Promise.all(e)}}function y(e,t){if(Array.isArray(t))t.splice(0,t.length);else if(typeof t=="object")for(const n in t)delete t[n];for(const n in e)Array.isArray(e[n])?(t[n]=[],y(e[n],t[n])):typeof e[n]=="object"?(t[n]={},y(e[n],t[n])):t[n]=e[n]}async function L(e,t){const{functionName:n,args:i}=e;if(!t.instance)throw"instance not initialized";if(!n)throw"missing function name to call";if(!t.instance[n])throw`undefined function [${n}] in class ${t.instance.constructor.workerId}`;g(e,await t.instance[n](...i!=null?i:[]))}const V={};function _(e,t){if(!e.args)throw"Missing className while initializing worker";const[n,i]=e.args,a=V[n];if(a)t.instance=new a(e.args.slice(1));else throw`unknown worker class ${n}`;y(i,c),g(e,typeof t.instance!==void 0)}async function D(e,t){const{args:n}=e;if(!t.instance)throw"instance not initialized";let i;t.instance.terminate&&(i=await t.instance.terminate(...n!=null?n:[])),g(e,i)}function G(e){if(!e.args)throw"Missing globals while syncing";y(e.args[0],c),g(e,{})}function W(){const e={};onmessage=async t=>{const n=t.data;switch(n.type){case u.INIT:_(n,e);break;case u.FORWARD:L(n,e);break;case u.TERMINATE:D(n,e);break;case u.GLOBALS_SYNC:G(n);break}}}I()&&W();function j(e,t){return c[e]||(c[e]=t),[()=>c[e],async n=>{c[e]=n,await E()}]}function x(e,t){return j(e,t)}const[B,P]=x("metadata");function Y(e){P(e)}function h(){return B()}class z{constructor(t){A(this,"uuid",O());this.config=t}async send(t){var p,R,S;const{appId:n,sourceType:i}=(p=h())!=null?p:{};if(!n||!i)return"metadata missing";const a=new AbortController,d=setTimeout(()=>a.abort(),U);return await((S=(R=this.config)==null?void 0:R.fetch)!=null?S:fetch)(this.getUrl(),{method:"POST",headers:this.getHeaders(),body:JSON.stringify(this.buildReport(t)),signal:a.signal}),clearTimeout(d),"success"}getUrl(){var n;let t=(n=h().proxyUrl)!=null?n:T;return t+=(t.at(-1)==="/"?"":"/")+l,t}getHeaders(){return{"Content-Type":"application/json"}}buildReport(t){const n=h();return{guid:this.uuid,...t,applicationId:n.appId,timestamp:Date.now(),proxyUrl:n.proxyUrl,source:n.sourceType}}}s.Reporter=z,s.SourceType=r,s.getVonageMetadata=h,s.setVonageMetadata=Y,Object.defineProperties(s,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});

@@ -1,8 +0,9 @@

import { Reporter, SourceType } from "../../../src";
import { Reporter, setVonageMetadata, SourceType } from "../../../src";
async function main() {
const reporter = new Reporter({
setVonageMetadata({
appId: "js-vsp-telemetry - examples/basic",
sourceType: SourceType.test,
});
const reporter = new Reporter();
const button = document.getElementById("send");

@@ -9,0 +10,0 @@ if (button) {

{
"name": "@vonage/js-onewebrtc-telemetry",
"version": "1.0.2",
"version": "1.1.0",
"description": "Library providing telemetry logging capabilities to Vonage monitoring servers.",

@@ -13,3 +13,3 @@ "types": "./dist/index.d.ts",

"doc": "typedoc --excludeInternal --excludePrivate --excludeProtected --disableSources --out dist/docs src/index.ts",
"test": "vitest --run --threads false"
"test": "karma start --single-run"
},

@@ -33,2 +33,13 @@ "repository": {

"devDependencies": {
"@types/chai": "^4.3.3",
"@types/chai-spies": "^1.0.3",
"@types/sinon": "^10.0.13",
"chai": "^4.3.6",
"karma": "^6.4.1",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^3.1.1",
"karma-mocha": "^2.0.1",
"karma-vite3": "^1.0.3",
"mocha": "^10.0.0",
"sinon": "^14.0.1",
"typedoc": "^0.23.16",

@@ -39,7 +50,7 @@ "typedoc-github-wiki-theme": "^1.0.1",

"vite": "^3.1.0",
"vite-plugin-dts": "^1.4.1",
"vitest": "^0.27.2"
"vite-plugin-dts": "^1.4.1"
},
"dependencies": {
"@types/uuid": "^9.0.0",
"@vonage/js-workerizer": "^1.1.0",
"emittery": "^1.0.1",

@@ -46,0 +57,0 @@ "uuid": "^9.0.0"

export * from "./interfaces";
export * from "./reporter";
export * from "./metadata";

@@ -30,17 +30,2 @@ export enum SourceType {

/**
* Type of source using the library.
*/
sourceType: SourceType;
/**
* Some string identifier identifying the application using the library.
*/
appId: string;
/**
* The proxy URL to route all internet traffic generated by this library. This field is optional.
*/
proxyUrl?: string;
/**
* Fetch method used to request the telemetry server, fetch by default

@@ -76,1 +61,20 @@ */

>;
/**
* Specifies the addional information being sent with the telemetry collected by the library.
*/
export type VonageMetadata = {
/**
* Type of source using the library.
*/
sourceType: SourceType;
/**
* Some string identifier identifying the application using the library.
*/
appId: string;
/**
* The proxy URL to route all internet traffic generated by this library. This field is optional.
*/
proxyUrl?: string;
};
import { SERVER_PROTOCOL, SERVER_URI, TIMEOUT_MS } from "./constants";
import { Report, ReporterConfig, SendableReport } from "./interfaces";
import { v4 as uuid } from "uuid";
import { getVonageMetadata } from "./metadata";

@@ -11,8 +12,10 @@ export class Reporter {

public async send(report: SendableReport): Promise<string> {
if (!this.config || !this.config.appId || !this.config.sourceType) {
return "Missing config, report not sent";
const { appId, sourceType } = getVonageMetadata() ?? {};
if (!appId || !sourceType) {
return "metadata missing";
}
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), TIMEOUT_MS);
const fetcher = this.config.fetch ?? fetch;
const fetcher = this.config?.fetch ?? fetch;

@@ -31,3 +34,3 @@ await fetcher(this.getUrl(), {

private getUrl(): string {
let url = this.config?.proxyUrl ?? SERVER_PROTOCOL;
let url = getVonageMetadata().proxyUrl ?? SERVER_PROTOCOL;
url += (url.at(-1) === "/" ? "" : "/") + SERVER_URI;

@@ -44,11 +47,12 @@ return url;

private buildReport(report: SendableReport): Report {
const metadata = getVonageMetadata();
return {
guid: this.uuid,
...report,
applicationId: this.config?.appId ?? "",
source: this.config?.sourceType ?? "",
applicationId: metadata.appId,
timestamp: Date.now(),
proxyUrl: this.config?.proxyUrl,
proxyUrl: metadata.proxyUrl,
source: metadata.sourceType,
};
}
}

@@ -1,3 +0,3 @@

import { describe, it, assert } from "vitest";
import { Report, Reporter, SourceType } from "../src/index";
import { Report, Reporter, setVonageMetadata, SourceType } from "../src/index";
import { assert } from "chai";

@@ -32,8 +32,23 @@ describe("reporter", () => {

it("should not report without metadata", async () => {
let hasBeingCalled = false;
const reporter = new Reporter({
fetch: async (url: RequestInfo | URL, options?: RequestInit) => {
hasBeingCalled = true;
return undefined as any;
},
});
await reporter.send({ version: "1.0.0" });
assert(!hasBeingCalled, "Request must not be call");
});
it("should report", async () => {
let hasBeingCalled = false;
const reporter = new Reporter({
setVonageMetadata({
appId: basicReport.applicationId,
sourceType: fullReport.source as SourceType,
});
const reporter = new Reporter({
fetch: async (url: RequestInfo | URL, options?: RequestInit) => {

@@ -55,6 +70,7 @@ const data = reportFromRequestInit(options);

let hasBeingCalled = false;
const reporter = new Reporter({
setVonageMetadata({
appId: basicReport.applicationId,
sourceType: fullReport.source as SourceType,
});
const reporter = new Reporter({
fetch: async (url: RequestInfo | URL, options?: RequestInit) => {

@@ -77,6 +93,8 @@ const data = reportFromRequestInit(options);

const proxyUrl = "https://blablabla.my.awesome.proxy/";
const reporter = new Reporter({
setVonageMetadata({
appId: basicReport.applicationId,
sourceType: fullReport.source as SourceType,
proxyUrl,
});
const reporter = new Reporter({
fetch: async (url: RequestInfo | URL, options?: RequestInit) => {

@@ -83,0 +101,0 @@ const data = reportFromRequestInit(options);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc