@axiomhq/js
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -10,4 +10,27 @@ # Changelog | ||
## [1.3.0] - 2024-09-20 | ||
## Added | ||
- feat: Added timeouts to Axiom client [#236](https://github.com/axiomhq/axiom-js/pull/236) | ||
## [1.2.0] - 2024-09-23 | ||
## Added | ||
- feat: Added support for quert tabular result format | ||
## [1.1.0] - 2024-08-15 | ||
## Security | ||
- Warning against usage of personal tokens | ||
## [1.1.0] - 2024-07-12 | ||
## Added | ||
- feate: Add referrer opt to dataset creation | ||
## [1.0.0] - 2024-06-12 | ||
@@ -19,2 +42,16 @@ | ||
## Migrate to v1.x | ||
- Pass the credentials as an object to Axiom client, this package no longer reads them from the environment variables. | ||
do: | ||
```ts | ||
const axiom = new Axiom({ | ||
token: process.env.AXIOM_TOKEN, | ||
}); | ||
``` | ||
instead of: | ||
```ts | ||
const axiom = new Axiom(); | ||
``` | ||
## [1.0.0-rc.4] - 2024-06-10 | ||
@@ -24,3 +61,3 @@ | ||
- fix: add BigInt support to JSON.stringify [#189] from lucassmuller/fix/json-stringify | ||
- fix: add BigInt support to JSON.stringify [#189] from lucassmuller/fix/json-stringify | ||
@@ -31,3 +68,3 @@ ## [1.0.0-rc.3] - 2024-03-20 | ||
- Fix fetch request init with retry | ||
- Fix fetch request init with retry | ||
@@ -34,0 +71,0 @@ ## [1.0.0-rc.2] - 2024-02-09 |
@@ -15,7 +15,7 @@ import { Limit } from './limit.js'; | ||
[key: string]: string; | ||
}): Promise<T>; | ||
post<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
get<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
put<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
delete<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
}, timeout?: number): Promise<T>; | ||
post<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
get<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
put<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
delete<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
_prepareSearchParams: (searchParams: { | ||
@@ -22,0 +22,0 @@ [key: string]: string; |
@@ -45,4 +45,12 @@ function createBatchKey(id, options) { | ||
} | ||
const res = await this.ingestFn(this.id, events, this.options); | ||
this.lastFlush = new Date(); | ||
let res = null; | ||
try { | ||
res = await this.ingestFn(this.id, events, this.options); | ||
} | ||
catch (e) { | ||
throw e; | ||
} | ||
finally { | ||
this.lastFlush = new Date(); | ||
} | ||
return res; | ||
@@ -49,0 +57,0 @@ }; |
@@ -71,3 +71,3 @@ import { datasets } from './datasets.js'; | ||
nocache: options?.noCache, | ||
}); | ||
}, 120_000); | ||
/** | ||
@@ -101,3 +101,3 @@ * Executes APL query using the provided APL and returns the result | ||
format: options?.format ?? 'legacy', | ||
}) | ||
}, 120_000) | ||
.then((res) => { | ||
@@ -104,0 +104,0 @@ if (options?.format !== 'tabular') { |
@@ -9,3 +9,3 @@ import fetchRetry from 'fetch-retry'; | ||
} | ||
async doReq(endpoint, method, init = {}, searchParams = {}) { | ||
async doReq(endpoint, method, init = {}, searchParams = {}, timeout = this.config.timeout) { | ||
let finalUrl = `${this.config.baseUrl}${endpoint}`; | ||
@@ -26,2 +26,3 @@ const params = this._prepareSearchParams(searchParams); | ||
body: init.body ? init.body : undefined, | ||
signal: AbortSignal.timeout(timeout), | ||
cache: 'no-cache', | ||
@@ -45,13 +46,13 @@ }); | ||
} | ||
post(url, init = {}, searchParams = {}) { | ||
return this.doReq(url, 'POST', init, searchParams); | ||
post(url, init = {}, searchParams = {}, timeout = this.config.timeout) { | ||
return this.doReq(url, 'POST', init, searchParams, timeout); | ||
} | ||
get(url, init = {}, searchParams = {}) { | ||
return this.doReq(url, 'GET', init, searchParams); | ||
get(url, init = {}, searchParams = {}, timeout = this.config.timeout) { | ||
return this.doReq(url, 'GET', init, searchParams, timeout); | ||
} | ||
put(url, init = {}, searchParams = {}) { | ||
return this.doReq(url, 'PUT', init, searchParams); | ||
put(url, init = {}, searchParams = {}, timeout = this.config.timeout) { | ||
return this.doReq(url, 'PUT', init, searchParams, timeout); | ||
} | ||
delete(url, init = {}, searchParams = {}) { | ||
return this.doReq(url, 'DELETE', init, searchParams); | ||
delete(url, init = {}, searchParams = {}, timeout = this.config.timeout) { | ||
return this.doReq(url, 'DELETE', init, searchParams, timeout); | ||
} | ||
@@ -58,0 +59,0 @@ _prepareSearchParams = (searchParams) => { |
import { FetchClient } from './fetchClient.js'; | ||
const Version = '1.2.0'; | ||
const Version = '1.3.0'; | ||
const AxiomURL = 'https://api.axiom.co'; | ||
@@ -26,3 +26,3 @@ class HTTPClient { | ||
headers, | ||
timeout: 3000, | ||
timeout: 20_000, | ||
}); | ||
@@ -29,0 +29,0 @@ } |
@@ -15,7 +15,7 @@ import { Limit } from './limit.js'; | ||
[key: string]: string; | ||
}): Promise<T>; | ||
post<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
get<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
put<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
delete<T>(url: string, init?: RequestInit, searchParams?: any): Promise<T>; | ||
}, timeout?: number): Promise<T>; | ||
post<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
get<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
put<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
delete<T>(url: string, init?: RequestInit, searchParams?: any, timeout?: number): Promise<T>; | ||
_prepareSearchParams: (searchParams: { | ||
@@ -22,0 +22,0 @@ [key: string]: string; |
{ | ||
"name": "@axiomhq/js", | ||
"description": "The official javascript bindings for the Axiom API", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"author": "Axiom, Inc.", | ||
@@ -39,3 +39,3 @@ "license": "MIT", | ||
"fetch-retry": "^6.0.0", | ||
"uuid": "^8.3.2" | ||
"uuid": "^11.0.2" | ||
}, | ||
@@ -48,2 +48,5 @@ "exports": { | ||
}, | ||
"devDependencies": { | ||
"msw": "^2.6.2" | ||
}, | ||
"scripts": { | ||
@@ -50,0 +53,0 @@ "build": "rollup -c rollup.config.js", |
@@ -1,17 +0,5 @@ | ||
## Javascript SDK for Axiom | ||
# Axiom JavaScript SDK | ||
## Quickstart | ||
The Axiom JavaScript SDK allows you to send data from a JavaScript app to Axiom. | ||
Install using `npm install`: | ||
```shell | ||
npm install @axiomhq/js | ||
``` | ||
If you use the [Axiom CLI](https://github.com/axiomhq/cli), run `eval $(axiom config export -f)` to configure your environment variables. | ||
Otherwise create a new token in [the Axiom settings](https://app.axiom.co/api-tokens) and export it as `AXIOM_TOKEN`. | ||
You can also configure the client using options passed to the constructor of the Client: | ||
```ts | ||
@@ -23,59 +11,19 @@ import { Axiom } from '@axiomhq/js'; | ||
}); | ||
``` | ||
You can then ingest data like this: | ||
```ts | ||
axiom.ingest('my-dataset', [{ foo: 'bar' }]); | ||
axiom.ingest('DATASET_NAME', [{ foo: 'bar' }]); | ||
await axiom.flush(); | ||
``` | ||
> **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. | ||
## Install | ||
And query data like this: | ||
```ts | ||
const res = await axiom.query(`['my-dataset'] | where foo == 'bar' | limit 100`); | ||
console.log(res); | ||
```bash | ||
npm install @axiomhq/js | ||
``` | ||
For further examples, head over to the [examples](../../examples/js) directory. | ||
## Documentation | ||
For more information about how to set up and use the Axiom JavaScript SDK, read documentation on [axiom.co/docs/guides/javascript](https://axiom.co/docs/guides/javascript). | ||
## Capture Errors | ||
## License | ||
To capture errors, you can pass a method `onError` to the client: | ||
```ts | ||
let client = new Axiom({ | ||
token: '', | ||
..., | ||
onError: (err) => { | ||
console.error('ERROR:', err); | ||
} | ||
}); | ||
``` | ||
by default `onError` is set to `console.error`. | ||
## Annotations | ||
Starting from `v1.0.0` the SDK supports the [Annotations API](https://axiom.co/docs/restapi/endpoints/createAnnotation). You can create annotations like this: | ||
```ts | ||
// import the annotations module | ||
import { annotations } from '@axiomhq/js'; | ||
// create a client | ||
const client = new annotations.Service({ token: process.env.AXIOM_TOKEN }); | ||
``` | ||
Then create an annotation like this: | ||
```ts | ||
await annotations.create({ | ||
type: 'deployment', | ||
datasets: ['dataset_name'], | ||
title: 'New deployment', | ||
description: 'Deployed version 1.0.0 with fixes for ...', | ||
}) | ||
``` | ||
[MIT](../../LICENSE) |
@@ -61,6 +61,13 @@ import { IngestOptions, IngestStatus } from './client.js'; | ||
const res = await this.ingestFn(this.id, events, this.options); | ||
this.lastFlush = new Date(); | ||
let res = null; | ||
try { | ||
res = await this.ingestFn(this.id, events, this.options); | ||
} catch (e) { | ||
throw e; | ||
} finally { | ||
this.lastFlush = new Date(); | ||
} | ||
return res; | ||
}; | ||
} |
@@ -91,2 +91,3 @@ import { datasets } from './datasets.js'; | ||
}, | ||
120_000, | ||
); | ||
@@ -133,2 +134,3 @@ | ||
}, | ||
120_000, | ||
) | ||
@@ -135,0 +137,0 @@ .then((res) => { |
@@ -12,2 +12,3 @@ import fetchRetry from 'fetch-retry'; | ||
searchParams: { [key: string]: string } = {}, | ||
timeout = this.config.timeout, | ||
): Promise<T> { | ||
@@ -31,2 +32,3 @@ let finalUrl = `${this.config.baseUrl}${endpoint}`; | ||
body: init.body ? init.body : undefined, | ||
signal: AbortSignal.timeout(timeout), | ||
cache: 'no-cache', | ||
@@ -51,16 +53,16 @@ }); | ||
post<T>(url: string, init: RequestInit = {}, searchParams: any = {}): Promise<T> { | ||
return this.doReq<T>(url, 'POST', init, searchParams); | ||
post<T>(url: string, init: RequestInit = {}, searchParams: any = {}, timeout = this.config.timeout): Promise<T> { | ||
return this.doReq<T>(url, 'POST', init, searchParams, timeout); | ||
} | ||
get<T>(url: string, init: RequestInit = {}, searchParams: any = {}): Promise<T> { | ||
return this.doReq<T>(url, 'GET', init, searchParams); | ||
get<T>(url: string, init: RequestInit = {}, searchParams: any = {}, timeout = this.config.timeout): Promise<T> { | ||
return this.doReq<T>(url, 'GET', init, searchParams, timeout); | ||
} | ||
put<T>(url: string, init: RequestInit = {}, searchParams: any = {}): Promise<T> { | ||
return this.doReq<T>(url, 'PUT', init, searchParams); | ||
put<T>(url: string, init: RequestInit = {}, searchParams: any = {}, timeout = this.config.timeout): Promise<T> { | ||
return this.doReq<T>(url, 'PUT', init, searchParams, timeout); | ||
} | ||
delete<T>(url: string, init: RequestInit = {}, searchParams: any = {}): Promise<T> { | ||
return this.doReq<T>(url, 'DELETE', init, searchParams); | ||
delete<T>(url: string, init: RequestInit = {}, searchParams: any = {}, timeout = this.config.timeout): Promise<T> { | ||
return this.doReq<T>(url, 'DELETE', init, searchParams, timeout); | ||
} | ||
@@ -86,3 +88,6 @@ | ||
constructor(public limit: Limit, public shortcircuit = false) { | ||
constructor( | ||
public limit: Limit, | ||
public shortcircuit = false, | ||
) { | ||
super(); | ||
@@ -89,0 +94,0 @@ Object.setPrototypeOf(this, AxiomTooManyRequestsError.prototype); // https://github.com/Microsoft/TypeScript/wiki/Breaking-Changes#extending-built-ins-like-error-array-and-map-may-no-longer-work |
@@ -62,5 +62,5 @@ import { FetchClient } from './fetchClient.js'; | ||
headers, | ||
timeout: 3000, | ||
timeout: 20_000, | ||
}); | ||
} | ||
} |
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
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
190268
3463
1
29
0
+ Addeduuid@11.0.3(transitive)
- Removeduuid@8.3.2(transitive)
Updateduuid@^11.0.2