Skip to content

About

Client library for ActivityWatch in JavaScript

Topics

Resources

Stars

40 stars

Watchers

3 watching

Forks

Repository files navigation

aw-client-js

Client library for ActivityWatch in TypeScript/JavaScript.

Build Status npm Known Vulnerabilities

Install

npm install aw-client

Usage

The library uses Promises for almost everything, so either use .then() or async/await syntax.

The example below is written with .then() to make it easy to run in the node REPL.

const { AWClient } = require("aw-client");
const client = new AWClient("test-client");

// Get server info
client.getInfo().then(console.log);

// List buckets
client.getBuckets().then(console.log);

// Create bucket, send a heartbeat, then read it back once both writes finish
const bucketId = "test";
client
    .ensureBucket(bucketId, "bucket-type", "your-hostname")
    .then(() => {
        const nowStr = new Date().toISOString();
        const heartbeat = {
            timestamp: nowStr,
            duration: 0,
            data: { label: "just testing!" },
        };
        return client.heartbeat(bucketId, 5, heartbeat);
    })
    .then(() => {
        // Get events in a bucket, optionally bounded by time range and/or limited in count
        const end = new Date();
        const start = new Date(end.getTime() - 24 * 60 * 60 * 1000); // last 24 hours
        client
            .getEvents(bucketId, { start, end, limit: 100 })
            .then(console.log);

        // Run a query over one or more timeperiods
        const timeperiods = [{ start, end }];
        const query = [
            `events = query_bucket("${bucketId}");`,
            "RETURN = events;",
        ];
        client.query(timeperiods, query).then(console.log);
    });

Contribute

Setup your dev environment

npm install

Build the library

npm run compile

Run the tests

npm test

About

Client library for ActivityWatch in JavaScript

Topics

Resources

Stars

40 stars

Watchers

3 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages