1.0.1 • Published 8 months ago

geocore-node v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

Geocore Library

A powerful and flexible library for interacting with the Geocore API. This library simplifies the process of managing authentication, making API requests, and handling responses.


Installation

To install the library, use npm or yarn:

# Using npm
npm install geocore-node

# Using yarn
yarn add geocore-node

Initialization

Before making any API calls, initialize the Geocore instance with your API base URL:

const Geocore = require('geocore');

const geocore = new Geocore("https://api.example.com/v1");

Usage

Here are some examples of how to use the library:

Authentication Example

Authenticate a user and retrieve the access token:

(async () => {
  const loginResponse = await geocore.Auth.login({
    username: "exampleUser",
    password: "examplePassword"
  });

  console.log("Access Token:", loginResponse.token.AccessToken);
})();

Listing Users Example

Retrieve a list of users with optional filters:

(async () => {
  const users = await geocore.User.listUser({
    name: "John Doe",
    email: "john.doe@example.com"
  });

  console.log("Users:", users);
})();

Create a New User Example

Create a new user in the system:

(async () => {
  const newUser = await geocore.User.createUser({
    name: "Jane Smith",
    email: "jane.smith@example.com",
    username: "janesmith",
    password: "securePassword123",
    accessLevel: "user"
  });

  console.log("New User:", newUser);
})();

Test API Connection Example

Check if the API is reachable:

(async () => {
  const pingResponse = await geocore.Ping.ping();
  console.log("Ping Response:", pingResponse);
})();

Authentication

Login

Authenticate a user and obtain an access token:

(async () => {
  const loginResponse = await geocore.Auth.login({
    username: "exampleUser",
    password: "examplePassword"
  });

  console.log("Login Response:", loginResponse);
})();

Register

Register a new user:

(async () => {
  const registerResponse = await geocore.Auth.register({
    username: "newUser",
    email: "newUser@example.com",
    password: "securePassword"
  });

  console.log("Register Response:", registerResponse);
})();

Verify Code

Verify a multi-factor authentication (MFA) code:

(async () => {
  const verifyResponse = await geocore.Auth.verifyCode({
    code: "123456",
    username: "exampleUser",
    session: "sessionId"
  });

  console.log("Verify Response:", verifyResponse);
})();

User Management

List Users

Retrieve a list of users with optional query parameters:

(async () => {
  const users = await geocore.User.listUser({
    name: "John",
    email: "john@example.com"
  });

  console.log("Users:", users);
})();

Create User

Create a new user:

(async () => {
  const newUser = await geocore.User.createUser({
    name: "Jane Doe",
    email: "jane.doe@example.com",
    username: "janedoe",
    password: "securePassword",
    accessLevel: "user"
  });

  console.log("New User:", newUser);
})();

Ping API

Test the API connection:

(async () => {
  const pingResponse = await geocore.Ping.ping();
  console.log("Ping Response:", pingResponse);
})();

Configuration

Set Token

Manually set the access token for authenticated requests:

geocore.setToken("yourAccessTokenHere");

Error Handling

The library throws errors if the API call fails. Use try-catch to handle errors:

(async () => {
  try {
    const loginResponse = await geocore.Auth.login({
      username: "invalidUser",
      password: "wrongPassword"
    });
  } catch (error) {
    console.error("Login Failed:", error.message);
  }
})();

TypeScript Support

The library includes TypeScript definitions for better type safety. For example:

import Geocore from 'geocore';

const geocore = new Geocore("https://api.example.com/v1");

(async () => {
  const loginResponse: API.LoginResponse = await geocore.Auth.login({
    username: "exampleUser",
    password: "examplePassword"
  });
  console.log(loginResponse);
})();

Contributing

We welcome contributions! Please fork the repository, make changes, and submit a pull request.


License

This library is licensed under the MIT License. See the LICENSE file for more details.

1.0.1

8 months ago

1.0.0

8 months ago