New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@timberio/browser

Package Overview
Dependencies
Maintainers
5
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@timberio/browser - npm Package Compare versions

Comparing version 0.20.2 to 0.21.0

8

dist/cjs/src/browser.js

@@ -8,3 +8,4 @@ "use strict";

const core_1 = require("@timberio/core");
const helpers_1 = require("./helpers");
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// import { getUserAgent } from "./helpers";
class Browser extends core_1.Base {

@@ -19,4 +20,5 @@ constructor(apiKey, options) {

"Content-Type": "application/json",
Authorization: `Basic ${btoa(this._apiKey)}`,
"User-Agent": helpers_1.getUserAgent()
Authorization: `Basic ${btoa(this._apiKey)}`
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// "User-Agent": getUserAgent()
},

@@ -23,0 +25,0 @@ body: JSON.stringify(logs)

@@ -9,4 +9,5 @@ "use strict";

const browser_1 = require("./browser");
const helpers_1 = require("./helpers");
const package_json_1 = require("../package.json");
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// import { getUserAgent } from "./helpers";
// import { version } from "../package.json";
/**

@@ -23,7 +24,8 @@ * Create a log with a random string / current date

describe("browser tests", () => {
it("should set a User-Agent based on the right version number", () => {
const expectedValue = `timber-js(browser)/${package_json_1.version}`;
const actualValue = helpers_1.getUserAgent();
expect(actualValue).toEqual(expectedValue);
});
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// it("should set a User-Agent based on the right version number", () => {
// const expectedValue = `timber-js(browser)/${version}`;
// const actualValue = getUserAgent();
// expect(actualValue).toEqual(expectedValue);
// });
it("should echo log if timber sends 20x status code", async (done) => {

@@ -30,0 +32,0 @@ nock_1.default("https://logs.timber.io")

import fetch from "cross-fetch";
import { Base } from "@timberio/core";
import { getUserAgent } from "./helpers";
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// import { getUserAgent } from "./helpers";
export class Browser extends Base {

@@ -13,4 +14,5 @@ constructor(apiKey, options) {

"Content-Type": "application/json",
Authorization: `Basic ${btoa(this._apiKey)}`,
"User-Agent": getUserAgent()
Authorization: `Basic ${btoa(this._apiKey)}`
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// "User-Agent": getUserAgent()
},

@@ -17,0 +19,0 @@ body: JSON.stringify(logs)

import nock from "nock";
import { base64Encode } from "@timberio/tools";
import { Browser } from "./browser";
import { getUserAgent } from "./helpers";
import { version } from "../package.json";
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// import { getUserAgent } from "./helpers";
// import { version } from "../package.json";
/**

@@ -17,7 +18,8 @@ * Create a log with a random string / current date

describe("browser tests", () => {
it("should set a User-Agent based on the right version number", () => {
const expectedValue = `timber-js(browser)/${version}`;
const actualValue = getUserAgent();
expect(actualValue).toEqual(expectedValue);
});
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// it("should set a User-Agent based on the right version number", () => {
// const expectedValue = `timber-js(browser)/${version}`;
// const actualValue = getUserAgent();
// expect(actualValue).toEqual(expectedValue);
// });
it("should echo log if timber sends 20x status code", async (done) => {

@@ -24,0 +26,0 @@ nock("https://logs.timber.io")

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

!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=2)}([function(t,e,r){var n=function(t){function e(){this.fetch=!1}return e.prototype=t,new e}("undefined"!=typeof self?self:this);(function(t){!function(t){if(!t.fetch){var e={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(e.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=function(t){return t&&DataView.prototype.isPrototypeOf(t)},o=ArrayBuffer.isView||function(t){return t&&r.indexOf(Object.prototype.toString.call(t))>-1};h.prototype.append=function(t,e){t=a(t),e=u(e);var r=this.map[t];this.map[t]=r?r+","+e:e},h.prototype.delete=function(t){delete this.map[a(t)]},h.prototype.get=function(t){return t=a(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(a(t))},h.prototype.set=function(t,e){this.map[a(t)]=u(e)},h.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},h.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),f(t)},h.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),f(t)},h.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),f(t)},e.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var i=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},p.call(b.prototype),p.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},w.error=function(){var t=new w(null,{status:0,statusText:""});return t.type="error",t};var s=[301,302,303,307,308];w.redirect=function(t,e){if(-1===s.indexOf(e))throw new RangeError("Invalid status code");return new w(null,{status:e,headers:{location:t}})},t.Headers=h,t.Request=b,t.Response=w,t.fetch=function(t,r){return new Promise(function(n,o){var i=new b(t,r),s=new XMLHttpRequest;s.onload=function(){var t,e,r={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}}),e)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var o="response"in s?s.response:s.responseText;n(new w(o,r))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.open(i.method,i.url,!0),"include"===i.credentials?s.withCredentials=!0:"omit"===i.credentials&&(s.withCredentials=!1),"responseType"in s&&e.blob&&(s.responseType="blob"),i.headers.forEach(function(t,e){s.setRequestHeader(e,t)}),s.send(void 0===i._bodyInit?null:i._bodyInit)})},t.fetch.polyfill=!0}function a(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function u(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var r={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return e.iterable&&(r[Symbol.iterator]=function(){return r}),r}function h(t){this.map={},t instanceof h?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function c(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function d(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function y(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(e.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(e.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(e.arrayBuffer&&e.blob&&n(t))this._bodyArrayBuffer=y(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!e.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!o(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=y(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e.blob&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var t,e,r,n=c(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},e.formData&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}function b(t,e){var r,n,o=(e=e||{}).body;if(t instanceof b){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new h(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),i.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function m(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}}),e}function w(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}}(void 0!==t?t:this)}).call(n,void 0);var o=n.fetch;o.Response=n.Response,o.Request=n.Request,o.Headers=n.Headers;t.exports&&(t.exports=o,t.exports.default=o)},function(t){t.exports={a:"0.20.2"}},function(t,e,r){"use strict";r.r(e);var n,o=r(0),i=r.n(o);!function(t){t.Debug="debug",t.Info="info",t.Warn="warn",t.Error="error"}(n||(n={}));class s{constructor(){this.length=0}push(t){const e={value:t};this.last=this.last?this.last.next=e:this.first=e,this.length++}shift(){if(this.first){const{value:t}=this.first;return this.first=this.first.next,--this.length||(this.last=void 0),t}}}const a=5,u=100,f=1e3;function h(t=a,e=f){let r,n;t<a&&(console.warn(`warning: Gracefully fixing bad value of batch size to default ${a}`),t=a),e<f&&(console.warn(`warning: Gracefully fixing bad value of timeout to default ${f}`),e=f);let o=[];async function i(){r&&clearTimeout(r),r=null;const t=o;o=[];try{await n(t.map(t=>t.log)),t.forEach(t=>t.resolve(t.log))}catch(e){t.map(t=>t.reject(e))}}return function(s){return n=s,async function(n){return new Promise(async(s,a)=>(o.push({log:n,resolve:s,reject:a}),o.length>=t||o.length===u-1?await i():await async function(){r||(r=setTimeout(async function(){await i()},e))}(),s))}}}const c={endpoint:"https://logs.timber.io/frames",batchSize:1e3,batchInterval:1e3,syncMax:5};var l=class{constructor(t,e){if(this._middleware=[],this._countLogged=0,this._countSynced=0,"string"!=typeof t||""===t)throw new Error("Timber API key missing");this._apiKey=t,this._options=Object.assign({},c,e);const r=function(t){let e=0;const r=new s;return function(n){return async(...o)=>new Promise((i,s)=>(async function a(){if(e<t){e++;try{i(await n(...o))}catch(t){s(t)}e--,r.length>0&&r.shift()()}else r.push(a)})())}}(this._options.syncMax)(t=>this._sync(t)),n=h(this._options.batchSize,this._options.batchInterval);this._batch=n(t=>r(t))}get logged(){return this._countLogged}get synced(){return this._countSynced}async log(t,e=n.Info,r={}){if("function"!=typeof this._sync)throw new Error("No Timber logger sync function provided");this._countLogged++;const o=Object.assign({dt:new Date},r,{level:e,message:t,$schema:"https://raw.githubusercontent.com/timberio/log-event-json-schema/v4.1.0/schema.json"}),i=await this._middleware.reduceRight((t,e)=>t.then(e),Promise.resolve(o));return await this._batch(i),this._countSynced++,i}async debug(t,e={}){return this.log(t,n.Debug,e)}async info(t,e={}){return this.log(t,n.Info,e)}async warn(t,e={}){return this.log(t,n.Warn,e)}async error(t,e={}){return this.log(t,n.Error,e)}setSync(t){this._sync=t}use(t){this._middleware.push(t)}remove(t){this._middleware=this._middleware.filter(e=>e!==t)}},d=r(1);var y=function(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,a)}u((n=n.apply(t,e||[])).next())})};window.Timber=class extends l{constructor(t,e){super(t,e),this.setSync(t=>y(this,void 0,void 0,function*(){const e=yield i()(this._options.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${btoa(this._apiKey)}`,"User-Agent":`timber-js(browser)/${d.a}`},body:JSON.stringify(t)});if(e.ok)return t;throw new Error(e.statusText)}))}}}])});
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var r=e();for(var n in r)("object"==typeof exports?exports:t)[n]=r[n]}}(window,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){var n=function(t){function e(){this.fetch=!1}return e.prototype=t,new e}("undefined"!=typeof self?self:this);(function(t){!function(t){if(!t.fetch){var e={searchParams:"URLSearchParams"in t,iterable:"Symbol"in t&&"iterator"in Symbol,blob:"FileReader"in t&&"Blob"in t&&function(){try{return new Blob,!0}catch(t){return!1}}(),formData:"FormData"in t,arrayBuffer:"ArrayBuffer"in t};if(e.arrayBuffer)var r=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],n=function(t){return t&&DataView.prototype.isPrototypeOf(t)},o=ArrayBuffer.isView||function(t){return t&&r.indexOf(Object.prototype.toString.call(t))>-1};h.prototype.append=function(t,e){t=a(t),e=u(e);var r=this.map[t];this.map[t]=r?r+","+e:e},h.prototype.delete=function(t){delete this.map[a(t)]},h.prototype.get=function(t){return t=a(t),this.has(t)?this.map[t]:null},h.prototype.has=function(t){return this.map.hasOwnProperty(a(t))},h.prototype.set=function(t,e){this.map[a(t)]=u(e)},h.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)},h.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),f(t)},h.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),f(t)},h.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),f(t)},e.iterable&&(h.prototype[Symbol.iterator]=h.prototype.entries);var i=["DELETE","GET","HEAD","OPTIONS","POST","PUT"];b.prototype.clone=function(){return new b(this,{body:this._bodyInit})},p.call(b.prototype),p.call(w.prototype),w.prototype.clone=function(){return new w(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new h(this.headers),url:this.url})},w.error=function(){var t=new w(null,{status:0,statusText:""});return t.type="error",t};var s=[301,302,303,307,308];w.redirect=function(t,e){if(-1===s.indexOf(e))throw new RangeError("Invalid status code");return new w(null,{status:e,headers:{location:t}})},t.Headers=h,t.Request=b,t.Response=w,t.fetch=function(t,r){return new Promise(function(n,o){var i=new b(t,r),s=new XMLHttpRequest;s.onload=function(){var t,e,r={status:s.status,statusText:s.statusText,headers:(t=s.getAllResponseHeaders()||"",e=new h,t.replace(/\r?\n[\t ]+/g," ").split(/\r?\n/).forEach(function(t){var r=t.split(":"),n=r.shift().trim();if(n){var o=r.join(":").trim();e.append(n,o)}}),e)};r.url="responseURL"in s?s.responseURL:r.headers.get("X-Request-URL");var o="response"in s?s.response:s.responseText;n(new w(o,r))},s.onerror=function(){o(new TypeError("Network request failed"))},s.ontimeout=function(){o(new TypeError("Network request failed"))},s.open(i.method,i.url,!0),"include"===i.credentials?s.withCredentials=!0:"omit"===i.credentials&&(s.withCredentials=!1),"responseType"in s&&e.blob&&(s.responseType="blob"),i.headers.forEach(function(t,e){s.setRequestHeader(e,t)}),s.send(void 0===i._bodyInit?null:i._bodyInit)})},t.fetch.polyfill=!0}function a(t){if("string"!=typeof t&&(t=String(t)),/[^a-z0-9\-#$%&'*+.\^_`|~]/i.test(t))throw new TypeError("Invalid character in header field name");return t.toLowerCase()}function u(t){return"string"!=typeof t&&(t=String(t)),t}function f(t){var r={next:function(){var e=t.shift();return{done:void 0===e,value:e}}};return e.iterable&&(r[Symbol.iterator]=function(){return r}),r}function h(t){this.map={},t instanceof h?t.forEach(function(t,e){this.append(e,t)},this):Array.isArray(t)?t.forEach(function(t){this.append(t[0],t[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}function c(t){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}function l(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function d(t){var e=new FileReader,r=l(e);return e.readAsArrayBuffer(t),r}function y(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function p(){return this.bodyUsed=!1,this._initBody=function(t){if(this._bodyInit=t,t)if("string"==typeof t)this._bodyText=t;else if(e.blob&&Blob.prototype.isPrototypeOf(t))this._bodyBlob=t;else if(e.formData&&FormData.prototype.isPrototypeOf(t))this._bodyFormData=t;else if(e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t))this._bodyText=t.toString();else if(e.arrayBuffer&&e.blob&&n(t))this._bodyArrayBuffer=y(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer]);else{if(!e.arrayBuffer||!ArrayBuffer.prototype.isPrototypeOf(t)&&!o(t))throw new Error("unsupported BodyInit type");this._bodyArrayBuffer=y(t)}else this._bodyText="";this.headers.get("content-type")||("string"==typeof t?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):e.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},e.blob&&(this.blob=function(){var t=c(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))},this.arrayBuffer=function(){return this._bodyArrayBuffer?c(this)||Promise.resolve(this._bodyArrayBuffer):this.blob().then(d)}),this.text=function(){var t,e,r,n=c(this);if(n)return n;if(this._bodyBlob)return t=this._bodyBlob,e=new FileReader,r=l(e),e.readAsText(t),r;if(this._bodyArrayBuffer)return Promise.resolve(function(t){for(var e=new Uint8Array(t),r=new Array(e.length),n=0;n<e.length;n++)r[n]=String.fromCharCode(e[n]);return r.join("")}(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},e.formData&&(this.formData=function(){return this.text().then(m)}),this.json=function(){return this.text().then(JSON.parse)},this}function b(t,e){var r,n,o=(e=e||{}).body;if(t instanceof b){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new h(t.headers)),this.method=t.method,this.mode=t.mode,o||null==t._bodyInit||(o=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"omit",!e.headers&&this.headers||(this.headers=new h(e.headers)),this.method=(r=e.method||this.method||"GET",n=r.toUpperCase(),i.indexOf(n)>-1?n:r),this.mode=e.mode||this.mode||null,this.referrer=null,("GET"===this.method||"HEAD"===this.method)&&o)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(o)}function m(t){var e=new FormData;return t.trim().split("&").forEach(function(t){if(t){var r=t.split("="),n=r.shift().replace(/\+/g," "),o=r.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(o))}}),e}function w(t,e){e||(e={}),this.type="default",this.status=void 0===e.status?200:e.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in e?e.statusText:"OK",this.headers=new h(e.headers),this.url=e.url||"",this._initBody(t)}}(void 0!==t?t:this)}).call(n,void 0);var o=n.fetch;o.Response=n.Response,o.Request=n.Request,o.Headers=n.Headers;t.exports&&(t.exports=o,t.exports.default=o)},function(t,e,r){"use strict";r.r(e);var n,o=r(0),i=r.n(o);!function(t){t.Debug="debug",t.Info="info",t.Warn="warn",t.Error="error"}(n||(n={}));class s{constructor(){this.length=0}push(t){const e={value:t};this.last=this.last?this.last.next=e:this.first=e,this.length++}shift(){if(this.first){const{value:t}=this.first;return this.first=this.first.next,--this.length||(this.last=void 0),t}}}const a=5,u=100,f=1e3;function h(t=a,e=f){let r,n;t<a&&(console.warn(`warning: Gracefully fixing bad value of batch size to default ${a}`),t=a),e<f&&(console.warn(`warning: Gracefully fixing bad value of timeout to default ${f}`),e=f);let o=[];async function i(){r&&clearTimeout(r),r=null;const t=o;o=[];try{await n(t.map(t=>t.log)),t.forEach(t=>t.resolve(t.log))}catch(e){t.map(t=>t.reject(e))}}return function(s){return n=s,async function(n){return new Promise(async(s,a)=>(o.push({log:n,resolve:s,reject:a}),o.length>=t||o.length===u-1?await i():await async function(){r||(r=setTimeout(async function(){await i()},e))}(),s))}}}const c={endpoint:"https://logs.timber.io/frames",batchSize:1e3,batchInterval:1e3,syncMax:5};var l=class{constructor(t,e){if(this._middleware=[],this._countLogged=0,this._countSynced=0,"string"!=typeof t||""===t)throw new Error("Timber API key missing");this._apiKey=t,this._options=Object.assign({},c,e);const r=function(t){let e=0;const r=new s;return function(n){return async(...o)=>new Promise((i,s)=>(async function a(){if(e<t){e++;try{i(await n(...o))}catch(t){s(t)}e--,r.length>0&&r.shift()()}else r.push(a)})())}}(this._options.syncMax)(t=>this._sync(t)),n=h(this._options.batchSize,this._options.batchInterval);this._batch=n(t=>r(t))}get logged(){return this._countLogged}get synced(){return this._countSynced}async log(t,e=n.Info,r={}){if("function"!=typeof this._sync)throw new Error("No Timber logger sync function provided");this._countLogged++;const o=Object.assign({dt:new Date},r,{level:e,message:t,$schema:"https://raw.githubusercontent.com/timberio/log-event-json-schema/v4.1.0/schema.json"}),i=await this._middleware.reduceRight((t,e)=>t.then(e),Promise.resolve(o));return await this._batch(i),this._countSynced++,i}async debug(t,e={}){return this.log(t,n.Debug,e)}async info(t,e={}){return this.log(t,n.Info,e)}async warn(t,e={}){return this.log(t,n.Warn,e)}async error(t,e={}){return this.log(t,n.Error,e)}setSync(t){this._sync=t}use(t){this._middleware.push(t)}remove(t){this._middleware=this._middleware.filter(e=>e!==t)}},d=function(t,e,r,n){return new(r||(r=Promise))(function(o,i){function s(t){try{u(n.next(t))}catch(t){i(t)}}function a(t){try{u(n.throw(t))}catch(t){i(t)}}function u(t){t.done?o(t.value):new r(function(e){e(t.value)}).then(s,a)}u((n=n.apply(t,e||[])).next())})};window.Timber=class extends l{constructor(t,e){super(t,e),this.setSync(t=>d(this,void 0,void 0,function*(){const e=yield i()(this._options.endpoint,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Basic ${btoa(this._apiKey)}`},body:JSON.stringify(t)});if(e.ok)return t;throw new Error(e.statusText)}))}}}])});
{
"name": "@timberio/browser",
"version": "0.20.2",
"version": "0.21.0",
"description": "Timber.io browser logging",

@@ -38,3 +38,3 @@ "keywords": [

"devDependencies": {
"@timberio/types": "^0.20.2",
"@timberio/types": "^0.21.0",
"@types/nock": "^9.3.0",

@@ -52,7 +52,7 @@ "@types/node": "^10.12.12",

"dependencies": {
"@timberio/core": "^0.20.2",
"@timberio/tools": "^0.20.2",
"@timberio/core": "^0.21.0",
"@timberio/tools": "^0.21.0",
"cross-fetch": "^2.2.3"
},
"gitHead": "da9c827de56ccd0034758eeccd4a8662de48f55f"
"gitHead": "ad47bc5850606d875f014d39f5a81daf87810729"
}

@@ -6,5 +6,6 @@ import nock from "nock";

import { Browser } from "./browser";
import { getUserAgent } from "./helpers";
import { version } from "../package.json";
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// import { getUserAgent } from "./helpers";
// import { version } from "../package.json";

@@ -24,8 +25,10 @@ /**

describe("browser tests", () => {
it("should set a User-Agent based on the right version number", () => {
const expectedValue = `timber-js(browser)/${version}`;
const actualValue = getUserAgent();
expect(actualValue).toEqual(expectedValue);
});
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// it("should set a User-Agent based on the right version number", () => {
// const expectedValue = `timber-js(browser)/${version}`;
// const actualValue = getUserAgent();
// expect(actualValue).toEqual(expectedValue);
// });
it("should echo log if timber sends 20x status code", async done => {

@@ -32,0 +35,0 @@ nock("https://logs.timber.io")

@@ -6,3 +6,4 @@ import fetch from "cross-fetch";

import { getUserAgent } from "./helpers";
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// import { getUserAgent } from "./helpers";

@@ -19,4 +20,5 @@ export class Browser extends Base {

"Content-Type": "application/json",
Authorization: `Basic ${btoa(this._apiKey)}`,
"User-Agent": getUserAgent()
Authorization: `Basic ${btoa(this._apiKey)}`
// Awaiting: https://bugs.chromium.org/p/chromium/issues/detail?id=571722
// "User-Agent": getUserAgent()
},

@@ -23,0 +25,0 @@ body: JSON.stringify(logs)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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