Skip to content

Commit

Permalink
ci: check in dist folder
Browse files Browse the repository at this point in the history
  • Loading branch information
wsbrunson committed Jul 26, 2023
1 parent 3988758 commit 7c6f9df
Show file tree
Hide file tree
Showing 10 changed files with 362 additions and 79 deletions.
31 changes: 2 additions & 29 deletions dist/beaver-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@
__webpack_require__.d(__webpack_exports__, "extendIfDefined", (function() {
return extendIfDefined;
}));
__webpack_require__.d(__webpack_exports__, "isAmplitude", (function() {
return util_isAmplitude;
}));
__webpack_require__.d(__webpack_exports__, "sendBeacon", (function() {
return sendBeacon;
}));
Expand Down Expand Up @@ -986,9 +983,6 @@
var hasHeaders = headers && Object.keys(headers).length;
return !!(window && window.navigator.sendBeacon && !hasHeaders && enableSendBeacon && window.Blob);
};
var util_isAmplitude = function(url) {
return "https://api2.amplitude.com/2/httpapi" === url;
};
var sendBeacon = function(_ref2) {
var _ref2$win = _ref2.win, win = void 0 === _ref2$win ? window : _ref2$win, url = _ref2.url, data = _ref2.data, _ref2$useBlob = _ref2.useBlob, useBlob = void 0 === _ref2$useBlob || _ref2$useBlob;
try {
Expand Down Expand Up @@ -1021,12 +1015,7 @@
canUseSendBeacon({
headers: headers,
enableSendBeacon: enableSendBeacon
}) && (beaconResult = util_isAmplitude(url) ? sendBeacon({
win: win,
url: url,
data: json,
useBlob: !1
}) : sendBeacon({
}) && (beaconResult = sendBeacon({
win: win,
url: url,
data: json,
Expand Down Expand Up @@ -1101,7 +1090,7 @@
};
}
function Logger(_ref) {
var url = _ref.url, prefix = _ref.prefix, _ref$logLevel = _ref.logLevel, logLevel = void 0 === _ref$logLevel ? DEFAULT_LOG_LEVEL : _ref$logLevel, _ref$transport = _ref.transport, transport = void 0 === _ref$transport ? getHTTPTransport() : _ref$transport, amplitudeApiKey = _ref.amplitudeApiKey, _ref$flushInterval = _ref.flushInterval, flushInterval = void 0 === _ref$flushInterval ? 6e4 : _ref$flushInterval, _ref$enableSendBeacon = _ref.enableSendBeacon, enableSendBeacon = void 0 !== _ref$enableSendBeacon && _ref$enableSendBeacon;
var url = _ref.url, prefix = _ref.prefix, _ref$logLevel = _ref.logLevel, logLevel = void 0 === _ref$logLevel ? DEFAULT_LOG_LEVEL : _ref$logLevel, _ref$transport = _ref.transport, transport = void 0 === _ref$transport ? getHTTPTransport() : _ref$transport, _ref$flushInterval = _ref.flushInterval, flushInterval = void 0 === _ref$flushInterval ? 6e4 : _ref$flushInterval, _ref$enableSendBeacon = _ref.enableSendBeacon, enableSendBeacon = void 0 !== _ref$enableSendBeacon && _ref$enableSendBeacon;
var events = [];
var tracking = [];
var metrics = [];
Expand Down Expand Up @@ -1140,21 +1129,6 @@
},
enableSendBeacon: enableSendBeacon
}).catch(src_util_noop));
amplitudeApiKey && transport({
method: "POST",
url: "https://api2.amplitude.com/2/httpapi",
headers: {},
json: {
api_key: amplitudeApiKey,
events: tracking.map((function(payload) {
return _extends({
event_type: payload.transition_name || "event",
event_properties: payload
}, payload);
}))
},
enableSendBeacon: enableSendBeacon
}).catch(src_util_noop);
events = [];
tracking = [];
metrics = [];
Expand Down Expand Up @@ -1275,7 +1249,6 @@
opts.prefix && (prefix = opts.prefix);
opts.logLevel && (logLevel = opts.logLevel);
opts.transport && (transport = opts.transport);
opts.amplitudeApiKey && (amplitudeApiKey = opts.amplitudeApiKey);
opts.flushInterval && (flushInterval = opts.flushInterval);
opts.enableSendBeacon && (enableSendBeacon = opts.enableSendBeacon);
return logger;
Expand Down
2 changes: 1 addition & 1 deletion dist/beaver-logger.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/beaver-logger.min.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/module/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import { LOG_LEVEL } from "./constants";
export var AUTO_FLUSH_LEVEL = [LOG_LEVEL.WARN, LOG_LEVEL.ERROR];
export var LOG_LEVEL_PRIORITY = [LOG_LEVEL.ERROR, LOG_LEVEL.WARN, LOG_LEVEL.INFO, LOG_LEVEL.DEBUG];
export var FLUSH_INTERVAL = 60 * 1000;
export var DEFAULT_LOG_LEVEL = __DEBUG__ ? LOG_LEVEL.DEBUG : LOG_LEVEL.WARN;
export var AMPLITUDE_URL = "https://api2.amplitude.com/2/httpapi";
export var DEFAULT_LOG_LEVEL = __DEBUG__ ? LOG_LEVEL.DEBUG : LOG_LEVEL.WARN;
23 changes: 7 additions & 16 deletions dist/module/http.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
import { request, noop } from "@krakenjs/belter/src";
import { isSameDomain, assertSameDomain } from "@krakenjs/cross-domain-utils/src";
import { canUseSendBeacon, isAmplitude, sendBeacon } from "./util";
import { canUseSendBeacon, sendBeacon } from "./util";
export function getHTTPTransport(httpWin) {
return function (_ref) {
var url = _ref.url,
Expand All @@ -18,21 +18,12 @@ export function getHTTPTransport(httpWin) {
headers: headers,
enableSendBeacon: enableSendBeacon
})) {
if (isAmplitude(url)) {
beaconResult = sendBeacon({
win: win,
url: url,
data: json,
useBlob: false
});
} else {
beaconResult = sendBeacon({
win: win,
url: url,
data: json,
useBlob: true
});
}
beaconResult = sendBeacon({
win: win,
url: url,
data: json,
useBlob: true
});
}
return beaconResult ? beaconResult : request({
win: win,
Expand Down
122 changes: 122 additions & 0 deletions dist/module/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
import { beforeEach, describe, expect, it, vi } from "vitest";
import * as belter from "@krakenjs/belter/src";
import * as crossDomainUtils from "@krakenjs/cross-domain-utils/src";
import { Logger, getHTTPTransport } from ".";
describe("beaver-logger custom transport tests", function () {
beforeEach(function () {
vi.spyOn(crossDomainUtils, "isSameDomain").mockReturnValue(true);
vi.spyOn(crossDomainUtils, "assertSameDomain").mockImplementation(function (win) {
return win;
});
});
it("should log something using XMLHttpRequest and a custom transport", _asyncToGenerator(function* () {
var XMLHttpRequest = vi.fn();
var win = _extends({}, window, {
XMLHttpRequest: XMLHttpRequest
});
var $logger = Logger({
url: "/test/api/log",
transport: getHTTPTransport(win)
});
$logger.info("hello_world", {
foo: "bar",
bar: true
});
yield $logger.flush();
expect(XMLHttpRequest).toHaveBeenCalledOnce();
}));
it("should log something using sendBeacon and a custom transport", _asyncToGenerator(function* () {
var sendBeacon = vi.fn().mockReturnValue(true);
window.navigator.sendBeacon = function () {
return true;
};
var win = _extends({}, window, {
navigator: _extends({}, window.navigator, {
sendBeacon: sendBeacon
})
});
var $logger = Logger({
url: "/test/api/log",
enableSendBeacon: true,
transport: getHTTPTransport(win)
});
$logger.info("hello_world", {
foo: "bar",
bar: true
});
yield $logger.flush();
expect(sendBeacon).toHaveBeenCalledOnce();
}));
});
describe("beaver-logger default transport tests", function () {
var requestSpy = vi.fn();
beforeEach(function () {
requestSpy = vi.spyOn(belter, "request").mockImplementation(function (data) {
var url = data.url,
method = data.method,
json = data.json;
if (url === "/test/api/log" && method === "POST") {
return json.events.some(function (event) {
return event.event === "hello_world" && event.level === "info";
});
}
return false;
});
});
it("should log something and flush it to the buffer", _asyncToGenerator(function* () {
window.navigator.sendBeacon = undefined;
var $logger = Logger({
url: "/test/api/log"
});
$logger.info("hello_world", {
foo: "bar",
bar: true
});
yield $logger.flush();
expect(requestSpy).toHaveBeenCalled();
expect(requestSpy).toReturnWith(true);
}));
it("should log something and flush it to the buffer using sendBeacon", _asyncToGenerator(function* () {
var $logger = Logger({
url: "/test/api/log",
enableSendBeacon: true
});
$logger.info("hello_world", {
foo: "bar",
bar: true
});
var sendBeaconCalled = false;
window.navigator.sendBeacon = function () {
sendBeaconCalled = true;
};
yield $logger.flush();
expect(requestSpy).toHaveBeenCalled();
expect(requestSpy).toReturnWith(true);
expect(sendBeaconCalled).toBeTruthy();
}));
it("should not log using sendBeacon if custom headers are passed", _asyncToGenerator(function* () {
var $logger = Logger({
url: "/test/api/log",
enableSendBeacon: true
});
$logger.addHeaderBuilder(function () {
return {
"x-custom-header": "hunter2"
};
});
$logger.info("hello_world", {
foo: "bar",
bar: true
});
var sendBeaconCalled = false;
window.navigator.sendBeacon = function () {
sendBeaconCalled = true;
};
yield $logger.flush();
expect(requestSpy).toHaveBeenCalled();
expect(requestSpy).toReturnWith(true);
expect(sendBeaconCalled).toBeFalsy();
}));
});
23 changes: 1 addition & 22 deletions dist/module/logger.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import _extends from "@babel/runtime/helpers/esm/extends";
import { ZalgoPromise } from "@krakenjs/zalgo-promise/src";
import { isBrowser, promiseDebounce, noop, safeInterval, objFilter } from "@krakenjs/belter/src";
import { DEFAULT_LOG_LEVEL, LOG_LEVEL_PRIORITY, AUTO_FLUSH_LEVEL, FLUSH_INTERVAL, AMPLITUDE_URL } from "./config";
import { DEFAULT_LOG_LEVEL, LOG_LEVEL_PRIORITY, AUTO_FLUSH_LEVEL, FLUSH_INTERVAL } from "./config";
import { LOG_LEVEL, PROTOCOL } from "./constants";
import { extendIfDefined } from "./util";
import { getHTTPTransport } from "./http";
Expand All @@ -12,7 +12,6 @@ export function Logger(_ref) {
logLevel = _ref$logLevel === void 0 ? DEFAULT_LOG_LEVEL : _ref$logLevel,
_ref$transport = _ref.transport,
transport = _ref$transport === void 0 ? getHTTPTransport() : _ref$transport,
amplitudeApiKey = _ref.amplitudeApiKey,
_ref$flushInterval = _ref.flushInterval,
flushInterval = _ref$flushInterval === void 0 ? FLUSH_INTERVAL : _ref$flushInterval,
_ref$enableSendBeacon = _ref.enableSendBeacon,
Expand Down Expand Up @@ -77,23 +76,6 @@ export function Logger(_ref) {
enableSendBeacon: enableSendBeacon
}).catch(noop);
}
if (amplitudeApiKey) {
transport({
method: "POST",
url: AMPLITUDE_URL,
headers: {},
json: {
api_key: amplitudeApiKey,
events: tracking.map(function (payload) {
return _extends({
event_type: payload.transition_name || "event",
event_properties: payload
}, payload);
})
},
enableSendBeacon: enableSendBeacon
}).catch(noop);
}
events = [];
tracking = [];
metrics = [];
Expand Down Expand Up @@ -201,9 +183,6 @@ export function Logger(_ref) {
if (opts.transport) {
transport = opts.transport;
}
if (opts.amplitudeApiKey) {
amplitudeApiKey = opts.amplitudeApiKey;
}
if (opts.flushInterval) {
flushInterval = opts.flushInterval;
}
Expand Down
Loading

0 comments on commit 7c6f9df

Please sign in to comment.