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

@appsignal/javascript

Package Overview
Dependencies
Maintainers
2
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@appsignal/javascript - npm Package Compare versions

Comparing version 1.0.0-beta.1 to 1.0.0-beta.2

dist/cjs/dispatcher.js

125

dist/cjs/index.js

@@ -6,6 +6,65 @@ "use strict";

*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
Object.defineProperty(exports, "__esModule", { value: true });
var version_1 = require("./version");
var api_1 = require("./api");
var environment_1 = require("./environment");
var span_1 = require("./span");
var functional_1 = require("./utils/functional");
var queue_1 = require("./queue");
var dispatcher_1 = require("./dispatcher");
var Appsignal = /** @class */ (function () {

@@ -20,4 +79,9 @@ /**

function Appsignal(options) {
this.VERSION = "1.0.0";
this.VERSION = version_1.VERSION;
this._hooks = {
decorators: [],
overrides: []
};
this._env = environment_1.Environment.serialize();
this._queue = new queue_1.Queue(window.__APPSIGNAL_QUEUE__ || []);
var key = options.key, uri = options.uri;

@@ -29,2 +93,3 @@ this._api = new api_1.PushApi({

});
this._dispatcher = new dispatcher_1.Dispatcher(this._queue, this._api);
this._options = options;

@@ -41,2 +106,3 @@ }

Appsignal.prototype.send = function (data, tags, namespace) {
var _this = this;
if (tags === void 0) { tags = {}; }

@@ -46,5 +112,11 @@ if (!(data instanceof Error) && !(data instanceof span_1.Span)) {

}
// "events" refer to a fixed point in time, as opposed to
// a range or length in time
// a "span" currently refers to a fixed point in time, as opposed to
// a range or length in time. this may change in future!
var span = data instanceof span_1.Span ? data : this._createSpanFromError(data);
// A Span can be "decorated" with metadata after it has been created,
// but before it is sent to the API and before metadata provided
// as arguments is added
if (this._hooks.decorators.length > 0) {
functional_1.compose.apply(void 0, __spread(this._hooks.decorators))(span);
}
if (tags)

@@ -54,4 +126,14 @@ span.setTags(tags);

span.setNamespace(namespace);
// A Span can be "overridden" with metadata after it has been created,
// but before it is sent to the API and after metadata provided
// as arguments is added
if (this._hooks.overrides.length > 0) {
functional_1.compose.apply(void 0, __spread(this._hooks.overrides))(span);
}
if (environment_1.Environment.supportsPromises()) {
return this._api.push(span);
return this._api.push(span).catch(function () {
_this._queue.push(span);
// schedule on next tick
setTimeout(function () { return _this._dispatcher.schedule(); }, 0);
});
}

@@ -94,12 +176,43 @@ else {

*
* @param {Function | void} fn Optional function to modify span
*
* @return {Span} An AppSignal `Span` object
*/
Appsignal.prototype.createSpan = function () {
Appsignal.prototype.createSpan = function (fn) {
var _a = this._options.revision, revision = _a === void 0 ? "" : _a;
return new span_1.Span({
var span = new span_1.Span({
environment: this._env,
revision: revision
});
if (fn && typeof fn === "function")
fn(span);
return span;
};
/**
* Wraps and catches errors within a given function
*
* @param {Function} fn [fn description]
*
* @return {Promise<any>} A Promise containing the return value of the function, or a `Span` if an error was thrown.
*/
Appsignal.prototype.wrap = function (fn) {
return __awaiter(this, void 0, void 0, function () {
var e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 1, , 3]);
return [2 /*return*/, Promise.resolve(fn())];
case 1:
e_1 = _a.sent();
return [4 /*yield*/, this.sendError(e_1)];
case 2:
_a.sent();
return [2 /*return*/, Promise.reject(e_1)];
case 3: return [2 /*return*/];
}
});
});
};
/**
* Returns an object that includes useful diagnostic information.

@@ -106,0 +219,0 @@ * Can be used to debug the installation.

28

dist/cjs/span.js
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {

@@ -14,10 +27,12 @@ __assign = Object.assign || function(t) {

Object.defineProperty(exports, "__esModule", { value: true });
var serializable_1 = require("./serializable");
var stacktrace_1 = require("./utils/stacktrace");
var Span = /** @class */ (function () {
var Span = /** @class */ (function (_super) {
__extends(Span, _super);
function Span(span) {
this._data = __assign({ timestamp: Math.round(new Date().getTime() / 1000), namespace: "frontend", revision: "", error: {
return _super.call(this, __assign({ timestamp: Math.round(new Date().getTime() / 1000), namespace: "frontend", revision: "", error: {
name: "",
message: "",
backtrace: []
}, environment: {}, tags: {} }, span);
}, environment: {}, tags: {}, params: {} }, span)) || this;
}

@@ -45,7 +60,8 @@ Span.prototype.setAction = function (name) {

};
Span.prototype.toJSON = function () {
return JSON.stringify(this._data);
Span.prototype.setParams = function (params) {
this._data.params = __assign({}, this._data.params, params);
return this;
};
return Span;
}());
}(serializable_1.Serializable));
exports.Span = Span;

@@ -5,5 +5,64 @@ /**

*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
var __spread = (this && this.__spread) || function () {
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
return ar;
};
import { VERSION } from "./version";
import { PushApi } from "./api";
import { Environment } from "./environment";
import { Span } from "./span";
import { compose } from "./utils/functional";
import { Queue } from "./queue";
import { Dispatcher } from "./dispatcher";
var Appsignal = /** @class */ (function () {

@@ -18,4 +77,9 @@ /**

function Appsignal(options) {
this.VERSION = "1.0.0";
this.VERSION = VERSION;
this._hooks = {
decorators: [],
overrides: []
};
this._env = Environment.serialize();
this._queue = new Queue(window.__APPSIGNAL_QUEUE__ || []);
var key = options.key, uri = options.uri;

@@ -27,2 +91,3 @@ this._api = new PushApi({

});
this._dispatcher = new Dispatcher(this._queue, this._api);
this._options = options;

@@ -39,2 +104,3 @@ }

Appsignal.prototype.send = function (data, tags, namespace) {
var _this = this;
if (tags === void 0) { tags = {}; }

@@ -44,5 +110,11 @@ if (!(data instanceof Error) && !(data instanceof Span)) {

}
// "events" refer to a fixed point in time, as opposed to
// a range or length in time
// a "span" currently refers to a fixed point in time, as opposed to
// a range or length in time. this may change in future!
var span = data instanceof Span ? data : this._createSpanFromError(data);
// A Span can be "decorated" with metadata after it has been created,
// but before it is sent to the API and before metadata provided
// as arguments is added
if (this._hooks.decorators.length > 0) {
compose.apply(void 0, __spread(this._hooks.decorators))(span);
}
if (tags)

@@ -52,4 +124,14 @@ span.setTags(tags);

span.setNamespace(namespace);
// A Span can be "overridden" with metadata after it has been created,
// but before it is sent to the API and after metadata provided
// as arguments is added
if (this._hooks.overrides.length > 0) {
compose.apply(void 0, __spread(this._hooks.overrides))(span);
}
if (Environment.supportsPromises()) {
return this._api.push(span);
return this._api.push(span).catch(function () {
_this._queue.push(span);
// schedule on next tick
setTimeout(function () { return _this._dispatcher.schedule(); }, 0);
});
}

@@ -92,12 +174,43 @@ else {

*
* @param {Function | void} fn Optional function to modify span
*
* @return {Span} An AppSignal `Span` object
*/
Appsignal.prototype.createSpan = function () {
Appsignal.prototype.createSpan = function (fn) {
var _a = this._options.revision, revision = _a === void 0 ? "" : _a;
return new Span({
var span = new Span({
environment: this._env,
revision: revision
});
if (fn && typeof fn === "function")
fn(span);
return span;
};
/**
* Wraps and catches errors within a given function
*
* @param {Function} fn [fn description]
*
* @return {Promise<any>} A Promise containing the return value of the function, or a `Span` if an error was thrown.
*/
Appsignal.prototype.wrap = function (fn) {
return __awaiter(this, void 0, void 0, function () {
var e_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 1, , 3]);
return [2 /*return*/, Promise.resolve(fn())];
case 1:
e_1 = _a.sent();
return [4 /*yield*/, this.sendError(e_1)];
case 2:
_a.sent();
return [2 /*return*/, Promise.reject(e_1)];
case 3: return [2 /*return*/];
}
});
});
};
/**
* Returns an object that includes useful diagnostic information.

@@ -104,0 +217,0 @@ * Can be used to debug the installation.

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

var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {

@@ -12,10 +25,12 @@ __assign = Object.assign || function(t) {

};
import { Serializable } from "./serializable";
import { getStacktrace } from "./utils/stacktrace";
var Span = /** @class */ (function () {
var Span = /** @class */ (function (_super) {
__extends(Span, _super);
function Span(span) {
this._data = __assign({ timestamp: Math.round(new Date().getTime() / 1000), namespace: "frontend", revision: "", error: {
return _super.call(this, __assign({ timestamp: Math.round(new Date().getTime() / 1000), namespace: "frontend", revision: "", error: {
name: "",
message: "",
backtrace: []
}, environment: {}, tags: {} }, span);
}, environment: {}, tags: {}, params: {} }, span)) || this;
}

@@ -43,7 +58,8 @@ Span.prototype.setAction = function (name) {

};
Span.prototype.toJSON = function () {
return JSON.stringify(this._data);
Span.prototype.setParams = function (params) {
this._data.params = __assign({}, this._data.params, params);
return this;
};
return Span;
}());
}(Serializable));
export { Span };
{
"name": "@appsignal/javascript",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"main": "dist/cjs/index.js",

@@ -10,3 +10,3 @@ "module": "dist/esm/index.js",

"scripts": {
"build": "run-s build:cjs build:esm",
"build": "yarn version && run-s build:cjs build:esm",
"build:esm": "tsc -p tsconfig.esm.json",

@@ -16,7 +16,8 @@ "build:esm:watch": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",

"build:cjs:watch": "tsc -p tsconfig.cjs.json -w --preserveWatchOutput",
"build:watch": "run-p build:cjs:watch build:esm:watch",
"clean": "rimraf dist coverage",
"build:watch": "yarn version && run-p build:cjs:watch build:esm:watch",
"clean": "rimraf dist coverage src/version.ts",
"link:yarn": "yarn link",
"test": "jest",
"test:watch": "jest --watch"
"test:watch": "jest --watch",
"version": "node scripts/create-versionfile.js"
},

@@ -29,3 +30,3 @@ "publishConfig": {

},
"gitHead": "bbecd8c57efcdf61f546d4c4e522da0a59ea9115"
"gitHead": "c0152b2c6455b02f55d0500f978a97442a842c5a"
}
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