logflare-transport-core
Advanced tools
Comparing version 0.2.4 to 0.2.5-5eb53706
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
interface IngestTransformsI { | ||
jsNumbers: boolean; | ||
numbersToFloats: boolean; | ||
} | ||
@@ -27,2 +27,3 @@ interface LogflareUserOptionsI { | ||
postLogEvents(batch: object[]): Promise<any>; | ||
addTypecasting(): Promise<void>; | ||
private _initializeResponseInterceptor; | ||
@@ -29,0 +30,0 @@ private _handleResponse; |
@@ -44,4 +44,2 @@ "use strict"; | ||
var axios_1 = __importDefault(require("axios")); | ||
var lodash_1 = __importDefault(require("lodash")); | ||
var typecasting_1 = require("./typecasting"); | ||
var stream_1 = __importDefault(require("stream")); | ||
@@ -78,3 +76,3 @@ var defaultOptions = { | ||
headers: { | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
}, | ||
@@ -85,10 +83,6 @@ }); | ||
LogflareHttpClient.prototype.addLogEvent = function (logEvent) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var logEvents; | ||
return __generator(this, function (_b) { | ||
return __generator(this, function (_a) { | ||
logEvents = Array.isArray(logEvent) ? logEvent : [logEvent]; | ||
if ((_a = this === null || this === void 0 ? void 0 : this.transforms) === null || _a === void 0 ? void 0 : _a.jsNumbers) { | ||
logEvents = lodash_1.default.map(logEvents, typecasting_1.applyNumberToStringTypecasting); | ||
} | ||
return [2 /*return*/, this.postLogEvents(logEvents)]; | ||
@@ -126,3 +120,3 @@ }); | ||
payload = { | ||
batch: batch | ||
batch: batch, | ||
}; | ||
@@ -151,2 +145,10 @@ _a.label = 1; | ||
}; | ||
LogflareHttpClient.prototype.addTypecasting = function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this.axiosInstance.post("/sources/"); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
return LogflareHttpClient; | ||
@@ -153,0 +155,0 @@ }()); |
@@ -86,2 +86,3 @@ "use strict"; | ||
}; | ||
// @ts-ignore | ||
return mapFn(obj, function (val, key) { | ||
@@ -88,0 +89,0 @@ var keyPathNext = path.concat(key); |
{ | ||
"name": "logflare-transport-core", | ||
"version": "0.2.4", | ||
"version": "0.2.5-5eb53706", | ||
"description": "A common core for Logflare javascript transports.", | ||
@@ -13,3 +13,3 @@ "keywords": [ | ||
"@types/lodash": "^4.14.153", | ||
"axios": "^0.19.2", | ||
"axios": "^0.21.1", | ||
"big-integer": "^1.6.48", | ||
@@ -47,2 +47,2 @@ "bignumber.js": "^9.0.0", | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import axios, { AxiosInstance, AxiosResponse } from "axios" | ||
import axios, {AxiosInstance, AxiosResponse} from "axios" | ||
import _ from "lodash" | ||
@@ -10,3 +10,3 @@ import { | ||
interface IngestTransformsI { | ||
jsNumbers: boolean | ||
numbersToFloats: boolean | ||
} | ||
@@ -36,3 +36,3 @@ | ||
public constructor(options: LogflareUserOptionsI) { | ||
const { sourceToken, apiKey, transforms, endpoint } = options | ||
const {sourceToken, apiKey, transforms, endpoint} = options | ||
if (!sourceToken || sourceToken == "") { | ||
@@ -52,3 +52,3 @@ throw "Logflare API logging transport source token is NOT configured!" | ||
headers: { | ||
"Content-Type": "application/json" | ||
"Content-Type": "application/json", | ||
}, | ||
@@ -62,5 +62,2 @@ }) | ||
let logEvents = Array.isArray(logEvent) ? logEvent : [logEvent] | ||
if (this?.transforms?.jsNumbers) { | ||
logEvents = _.map(logEvents, applyNumberToStringTypecasting) | ||
} | ||
return this.postLogEvents(logEvents) | ||
@@ -93,3 +90,3 @@ } | ||
const payload = { | ||
batch | ||
batch, | ||
} | ||
@@ -102,3 +99,3 @@ try { | ||
`Logflare API request failed with ${ | ||
e.response.status | ||
e.response.status | ||
} status: ${JSON.stringify(e.response.data)}` | ||
@@ -116,2 +113,6 @@ ) | ||
async addTypecasting() { | ||
this.axiosInstance.post("/sources/") | ||
} | ||
private _initializeResponseInterceptor = () => { | ||
@@ -124,6 +125,6 @@ this.axiosInstance.interceptors.response.use( | ||
private _handleResponse = ({ data }: AxiosResponse) => data | ||
private _handleResponse = ({data}: AxiosResponse) => data | ||
protected _handleError = (error: any) => Promise.reject(error) | ||
} | ||
export { LogflareHttpClient, LogflareUserOptionsI } | ||
export {LogflareHttpClient, LogflareUserOptionsI} |
@@ -36,7 +36,6 @@ import moxios from "moxios" | ||
"Content-Type": "application/json", | ||
"X-API-KEY": "testApiKey", | ||
}) | ||
expect(request.config.data).toBe( | ||
JSON.stringify({batch: [le], source: testSourceToken}) | ||
JSON.stringify({batch: [le]}) | ||
) | ||
@@ -97,3 +96,3 @@ | ||
it("trarnsforms js numbers if configured", async (done) => { | ||
it.skip("transforms js numbers if configured", async (done) => { | ||
const le = { | ||
@@ -111,7 +110,6 @@ message: "info log msg", | ||
"Content-Type": "application/json", | ||
"X-API-KEY": "testApiKey", | ||
}) | ||
expect(request.config.data).toBe( | ||
'{"batch":[{"body":{"message":"info log msg","metadata":{"number":"1","number2":"1"}},"typecasts":[{"path":["metadata","number"],"from":"string","to":"float"},{"path":["metadata","number2"],"from":"string","to":"float"}]}],"source":"2222-2222"}' | ||
'{"batch":[{"body":{"message":"info log msg","metadata":{"number":"1","number2":"1"}},"typecasts":[{"path":["metadata","number"],"from":"string","to":"float"},{"path":["metadata","number2"],"from":"string","to":"float"}]}]}' | ||
) | ||
@@ -118,0 +116,0 @@ |
@@ -91,3 +91,3 @@ import _ from "lodash" | ||
obj: object, | ||
fn, | ||
fn: any, | ||
path: string[], | ||
@@ -106,2 +106,3 @@ typecasts: object[] | ||
} | ||
// @ts-ignore | ||
return mapFn(obj, (val: object | object[], key: string) => { | ||
@@ -108,0 +109,0 @@ let keyPathNext = path.concat(key) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46368
19
1052
+ Addedaxios@0.21.4(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
- Removedaxios@0.19.2(transitive)
- Removedfollow-redirects@1.5.10(transitive)
Updatedaxios@^0.21.1