Skip to content

TimeTrackerX/timetrackerx-sdk-js

Repository files navigation

TimeTrackerX JavaScript SDK

npm version GitHub codecov

The official JavaScript SDK for integrating with the TimeTrackerX API.

To install dependencies:

npm install @timetrackerx/js-sdk

Usage

Import the SDK in your project and initialize it with either a base URL or a custom Axios instance.

const { Auth } = require('@timetrackerx/js-sdk');

// Initialize the SDK with a base URL
const ttWithBaseUrl = new Auth({ baseUrl: 'https://your-timetrackerx-api.com' });

// OR

// Initialize the SDK with a custom Axios instance
const axios = require('axios');
const customHttp = axios.create({
    /* your custom configuration */
});
const ttWithCustomHttp = new Auth({ http: customHttp });

Methods

authenticateWithGoogleCode(code: string): Promise<AuthResult>

Authenticate with Google Code and receive an authentication result.

try {
    const { auth, error } = await ttWithBaseUrl.authenticateWithGoogleCode('your-google-code');

    if (auth) {
        console.log('Authentication successful:', auth);
    } else {
        console.error('Authentication failed:', error);
    }
} catch (err) {
    console.error('Error during authentication:', err.message);
}

Configuration Options

baseUrl (optional)

Specify the base URL for the TimeTrackerX API.

const tt = new Auth({ baseUrl: 'https://your-timetrackerx-api.com' });

http (optional)

Provide a custom Axios instance for making HTTP requests.

const axios = require('axios');
const customHttp = axios.create({
    /* your custom configuration */
});

const tt = new Auth({ http: customHttp });

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.