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

@axiomhq/js

Package Overview
Dependencies
Maintainers
7
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@axiomhq/js - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

24

dist/cjs/client.js

@@ -57,3 +57,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.FilterOp = exports.AggregationOp = exports.ContentEncoding = exports.ContentType = exports.Client = exports.ClientWithoutBatching = void 0;
exports.FilterOp = exports.AggregationOp = exports.ContentEncoding = exports.ContentType = exports.Axiom = exports.AxiomWithoutBatching = void 0;
var datasets_1 = require("./datasets");

@@ -114,8 +114,8 @@ var users_1 = require("./users");

}(httpClient_1.default));
var ClientWithoutBatching = /** @class */ (function (_super) {
__extends(ClientWithoutBatching, _super);
function ClientWithoutBatching() {
var AxiomWithoutBatching = /** @class */ (function (_super) {
__extends(AxiomWithoutBatching, _super);
function AxiomWithoutBatching() {
return _super !== null && _super.apply(this, arguments) || this;
}
ClientWithoutBatching.prototype.ingest = function (dataset, events, options) {
AxiomWithoutBatching.prototype.ingest = function (dataset, events, options) {
var array = Array.isArray(events) ? events : [events];

@@ -125,8 +125,8 @@ var json = array.map(function (v) { return JSON.stringify(v); }).join('\n');

};
return ClientWithoutBatching;
return AxiomWithoutBatching;
}(BaseClient));
exports.ClientWithoutBatching = ClientWithoutBatching;
var Client = /** @class */ (function (_super) {
__extends(Client, _super);
function Client() {
exports.AxiomWithoutBatching = AxiomWithoutBatching;
var Axiom = /** @class */ (function (_super) {
__extends(Axiom, _super);
function Axiom() {
var _this = _super !== null && _super.apply(this, arguments) || this;

@@ -163,5 +163,5 @@ _this.batch = {};

}
return Client;
return Axiom;
}(BaseClient));
exports.Client = Client;
exports.Axiom = Axiom;
var ContentType;

@@ -168,0 +168,0 @@ (function (ContentType) {

@@ -49,3 +49,3 @@ import { datasets } from './datasets';

}
export class ClientWithoutBatching extends BaseClient {
export class AxiomWithoutBatching extends BaseClient {
ingest(dataset, events, options) {

@@ -57,3 +57,3 @@ const array = Array.isArray(events) ? events : [events];

}
export class Client extends BaseClient {
export class Axiom extends BaseClient {
batch = {};

@@ -60,0 +60,0 @@ ingest = (dataset, events, options) => {

@@ -16,6 +16,6 @@ /// <reference types="node" />

}
export declare class ClientWithoutBatching extends BaseClient {
export declare class AxiomWithoutBatching extends BaseClient {
ingest(dataset: string, events: Array<object> | object, options?: IngestOptions): Promise<IngestStatus>;
}
export declare class Client extends BaseClient {
export declare class Axiom extends BaseClient {
batch: {

@@ -22,0 +22,0 @@ [id: string]: Batch;

export * from './client';
export { ClientOptions } from './httpClient';
export { datasets } from './datasets';
export { users } from './users';
//# sourceMappingURL=index.d.ts.map
{
"name": "@axiomhq/js",
"description": "The official javascript bindings for the Axiom API",
"version": "0.1.0",
"version": "0.1.1",
"author": "Axiom, Inc.",

@@ -6,0 +6,0 @@ "license": "MIT",

@@ -18,25 +18,26 @@ ## Javascript SDK for Axiom

```ts
const client = new Client({
token: process.env.AXIOM_TOKEN,
orgId: process.env.AXIOM_ORG_ID,
import { Axiom } from '@axiomhq/js';
const axiom = new Axiom({
token: process.env.AXIOM_TOKEN,
orgId: process.env.AXIOM_ORG_ID,
});
```
Create and use a client like this:
You can then ingest data like this:
```ts
import Client from '@axiomhq/js';
axiom.ingest('my-dataset', [{ foo: 'bar' }]);
await client.flush();
```
async function main() {
const client = new Client();
> **Note** that the client is automatically batching events in the background, in most cases you'll only want to call `flush()` before your application exits.
client.ingest('my-dataset', [
{ 'foo': 'bar'},
]);
await client.flush();
And query data like this:
const res = await client.query(`['my-dataset'] | where foo == 'bar' | limit 100`);
}
```ts
const res = await axiom.query(`['my-dataset'] | where foo == 'bar' | limit 100`);
console.log(res);
```
For further examples, head over to the [examples](../../examples/js) directory.
For further examples, head over to the [examples](../../examples/js) directory.

@@ -76,3 +76,3 @@ import { datasets } from './datasets';

export class ClientWithoutBatching extends BaseClient {
export class AxiomWithoutBatching extends BaseClient {
ingest(dataset: string, events: Array<object> | object, options?: IngestOptions): Promise<IngestStatus> {

@@ -85,3 +85,3 @@ const array = Array.isArray(events) ? events : [events];

export class Client extends BaseClient {
export class Axiom extends BaseClient {
batch: { [id: string]: Batch } = {};

@@ -88,0 +88,0 @@

export * from './client';
export { ClientOptions } from './httpClient';
export { datasets } from './datasets';
export { users } from './users';

@@ -6,3 +6,3 @@ /*

import { Client } from '../../src/client';
import { Axiom } from '../../src/client';
import { mockFetchResponse } from '../lib/mock';

@@ -16,6 +16,6 @@

expect(typeof window).toBe('object');
const client = new Client({ url: clientUrl });
expect(client).toBeDefined();
const axiom = new Axiom({ url: clientUrl });
expect(axiom).toBeDefined();
const resp = await client.datasets.create({ name: 'test' });
const resp = await axiom.datasets.create({ name: 'test' });
expect(resp).toBeTruthy();

@@ -22,0 +22,0 @@ expect(resp.created).toEqual(true);

import { describe, expect, it, beforeEach } from '@jest/globals';
import { ContentType, ContentEncoding, ClientWithoutBatching } from '../../src/client';
import { ContentType, ContentEncoding, AxiomWithoutBatching } from '../../src/client';
import { AxiomTooManyRequestsError } from '../../src/fetchClient';

@@ -69,14 +69,14 @@ import { headerAPILimit, headerAPIRateRemaining, headerAPIRateReset, headerRateScope } from '../../src/limit';

describe('Client', () => {
let client = new ClientWithoutBatching({ url: clientURL });
expect(client).toBeDefined();
describe('Axiom', () => {
let axiom = new AxiomWithoutBatching({ url: clientURL });
expect(axiom).toBeDefined();
beforeEach(() => {
// reset client to clear rate limits
client = new ClientWithoutBatching({ url: clientURL });
axiom = new AxiomWithoutBatching({ url: clientURL });
});
it('Services', () => {
expect(client.datasets).toBeTruthy();
expect(client.users).toBeTruthy();
expect(axiom.datasets).toBeTruthy();
expect(axiom.users).toBeTruthy();
});

@@ -90,3 +90,3 @@

const resp = await client.datasets.list();
const resp = await axiom.datasets.list();
// expect(fetch).toHaveBeenCalledTimes(3);

@@ -101,7 +101,7 @@ expect(resp.length).toEqual(1);

expect(client.datasets.list).rejects.toThrow(new Error('Forbidden'));
expect(axiom.datasets.list).rejects.toThrow(new Error('Forbidden'));
// create another request to ensure that
// the fetch mock was not consumed before
// const resp = await client.datasets.list();
// const resp = await axiom.datasets.list();
// expect(fetch).toHaveBeenCalledTimes(2);

@@ -120,10 +120,10 @@ // expect(resp.length).toEqual(1);

mockFetchResponse({}, 429, headers);
expect(client.datasets.list).rejects.toBeInstanceOf(AxiomTooManyRequestsError);
expect(axiom.datasets.list).rejects.toBeInstanceOf(AxiomTooManyRequestsError);
// ingest and query should succeed
mockFetchResponse({}, 200, headers);
await client.ingest('test', [{ name: 'test' }]);
await axiom.ingest('test', [{ name: 'test' }]);
mockFetchResponse({}, 200, headers);
await client.query("['test']");
await axiom.query("['test']");
});

@@ -147,3 +147,3 @@

const response = await client.ingestRaw('test', JSON.stringify(query), ContentType.JSON, ContentEncoding.Identity);
const response = await axiom.ingestRaw('test', JSON.stringify(query), ContentType.JSON, ContentEncoding.Identity);
expect(response).toBeDefined();

@@ -163,3 +163,3 @@ expect(response.ingested).toEqual(2);

};
let response = await client.queryLegacy('test', query);
let response = await axiom.queryLegacy('test', query);
expect(response).toBeDefined();

@@ -180,3 +180,3 @@ expect(response.matches).toHaveLength(2);

mockFetchResponse(queryLegacyResult);
response = await client.queryLegacy('test', query, options);
response = await axiom.queryLegacy('test', query, options);
expect(response).toBeDefined();

@@ -189,3 +189,3 @@ expect(response.matches).toHaveLength(2);

// works without options
let response = await client.query("['test'] | where response == 304");
let response = await axiom.query("['test'] | where response == 304");
expect(response).not.toEqual('undefined');

@@ -201,3 +201,3 @@ expect(response.matches).toHaveLength(2);

mockFetchResponse(queryResult);
response = await client.query("['test'] | where response == 304", options);
response = await axiom.query("['test'] | where response == 304", options);
expect(response).not.toEqual('undefined');

@@ -204,0 +204,0 @@ expect(response.matches).toHaveLength(2);

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

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

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