0.1.18 • Published 5 months ago

@goodtok/sdk v0.1.18

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

sdk

SDK for Goodtok Server

goodtok Version Downloads/week License

Installation

$ npm install --save @goodtok/sdk

APIs

Customers ⇐ AbstractBaseClient

Use the Goodtok Customers capability to retrieve and manage customers. Ensure the Goodtok API Server is running for the Customers API to function.

Kind: global class
Extends: AbstractBaseClient
See: module:sdk:Client

new Customers(client)

Constructs a new Customers API object.

ParamTypeDescription
clientClientObject containing the client configuration

Example

const SDK = require("@goodtok/sdk");

async function getCustomer() {
  const client = new SDK.Client({ workspace: "myworkspace" });
  await client.login("goodtok", "mysecretpassword");

  const customers = new SDK.Customers(client);
  const id = "5f9d7a3a-2b2b-4b7a-9b9b-8e9d9d9d9d9d";
  const customer = await customers.getCustomerById(id);

  console.log(customer);
}

getCustomer().catch(console.error);

customers.getCustomerById(request) ⇒ Promise.<Customer>

Retrieves a customer for a workspace by customer ID.

Kind: instance method of Customers
Returns: Promise.<Customer> - A promise resolving to the customer
Throws:

  • Will throw an error if the customer is not found
ParamTypeDescription
requestGetCustomerRequestRequest object containing the customer ID and workspace ID
request.workspaceIdstringThe workspace ID
request.customerIdstringThe customer ID

Example

const request = {
  workspaceId: "452b1b1b-1b1b-1b1b-1b1b-1b1b1b1b1b1b",
  customerId: "5f9d7a3a-2b2b-4b7a-9b9b-8e9d9d9d9d9d"
};

customers.getCustomer(request)
  .then(console.log)
  .catch(console.error); // handle any errors

customers.getOrdersByCustomerId(request) ⇒ Promise.<Array.<Order>>

Retrieves a list of orders for a customer by customer ID.

Kind: instance method of Customers
Returns: Promise.<Array.<Order>> - A promise resolving to the list of orders

ParamTypeDescription
requestGetOrdersByCustomerIdRequestRequest object containing the customer ID and workspace ID
request.workspaceIdstringThe workspace ID
request.customerIdstringThe customer ID

Example

const request = {
  workspaceId: "452b1b1b-1b1b-1b1b-1b1b-1b1b1b1b1b1b",
  customerId: "5f9d7a3a-2b2b-4b7a-9b9b-8e9d9d9d9d9d"
};

customers.getOrdersByCustomerId(request)
 .then(console.log)
 .catch(console.error); // handle any errors

customers.getCustomerInDefaultWorkspace(id) ⇒ Promise.<Customer>

Retrieves a customer by ID in the default workspace.

Kind: instance method of Customers
Returns: Promise.<Customer> - A promise resolving to the customer
Throws:

  • Will throw an error if the customer is not found
ParamTypeDescription
idstringThe customer ID

Example

const id = "5f9d7a3a-2b2b-4b7a-9b9b-8e9d9d9d9d9d";
customers.getCustomerInDefaultWorkspace(id)
  .then(console.log)
  .catch(console.error); // handle any errors

Queues ⇐ AbstractBaseClient

Use the Goodtok Queues capability to retrieve and manage queues. Ensure the Goodtok API Server is running for the Queues API to function.

Kind: global class
Extends: AbstractBaseClient
See: module:sdk:Client

new Queues(client)

Constructs a new Queues API object.

ParamTypeDescription
clientClientObject containing the client configuration

Example

const SDK = require("@goodtok/sdk");

async function getWorkspace() {
  const client = new SDK.Client({ workspace: "myworkspace" });
  await client.login("goodtok", "mysecretpassword");

  const workspaceId = "g-7b7c46fb05";

  const queues = new SDK.Queues(client);
  const queue = await workspaces.getQueueByWorkspaceId(workspaceId);

  console.log(workspace);
}

getWorkspace().catch(console.error);

queues.getDefaultWorkspaceQueue() ⇒ Promise.<GetQueueResponse>

Retrieves the queue for the default workspace.

Kind: instance method of Queues
Returns: Promise.<GetQueueResponse> - A promise resolving to the queue
Example

workspaces.getDefaultWorkspaceQueue()
  .then(console.log)
  .catch(console.error); // handle any errors

queues.getQueueByWorkspaceId(id) ⇒ Promise.<Workspace>

Retrieves the queue for a workspace by its ID.

Kind: instance method of Queues
Returns: Promise.<Workspace> - A promise resolving to an object containing an array of queue entries

ParamTypeDescription
idstringThe workspace ID

Example

const id = "g-7b7c46fb05";

queues.getQueueByWorkspaceId(id)
  .then(console.log)
  .catch(console.error); // handle any errors

queues.watchQueue(id, callback)

Registers a callback for real-time updates on queue entries within a workspace.

Kind: instance method of Queues

ParamTypeDescription
idstringThe ID of the workspace
callbackfunctionThe callback to be invoked when a queue entry updates

Example

const id = "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d";

queues.watchQueue(id, (err, data) => {
  if (err) {
   console.error(err);
   return;
  }

  console.log(data);
});

queues.updateQueueEntryStatus(request) ⇒ Promise.<void>

Updates the status of a queue entry.

Kind: instance method of Queues
Returns: Promise.<void> - A promise resolving to void

ParamTypeDescription
requestUpdateQueueEntryStatusRequestThe request object
request.workspaceIdstringThe workspace ID
request.customerIdstringThe customer ID to update the queue entry for
request.statusstringThe status to update the queue entry to

Example

const request = {
 workspaceId: "g-7b7c46fb05",
 customerId: "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d",
 status: "DEQUEUED"
};

queues.updateQueueEntryStatus(request)
  .then(console.log)
  .catch(console.error); // handle any errors

queues.joinQueue(request) ⇒ Promise.<void>

Adds a customer to a queue.

Kind: instance method of Queues
Returns: Promise.<void> - A promise resolving to void

ParamTypeDescription
requestJoinQueueRequestThe request object
request.workspaceIdstringThe workspace ID
request.customerIdstringThe customer ID to add to the queue

Example

const request = {
 workspaceId: "g-7b7c46fb05",
 customerId: "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d"
};

queues.joinQueue(request)
 .then(console.log)
 .catch(console.error); // handle any errors

Tokens ⇐ AbstractBaseClient

Use the Goodtok Tokens capability to create and verify JWT tokens. Ensure the Goodtok API Server is running for the Tokens API to function.

Kind: global class
Extends: AbstractBaseClient
See: module:sdk:Client

new Tokens(client)

Constructs a new Tokens API object.

ParamTypeDescription
clientClientObject containing the client configuration

Example

const SDK = require("@goodtok/sdk");

async function createAnonymousToken() {
  const client = new SDK.Client({ workspace: "myworkspace" });
  await client.login("goodtok", "mysecretpassword");

  const tokens = new SDK.Tokens(client);

  const request = {
    ref: "myref",
    workspaceId: "g-1234567890",
    metadata: {
     customField: "customValue"
    }
  }

  const connectionObject = await tokens.createAnonymousToken(request);
  console.log(connectionObject);
}

createAnonymousToken().catch(console.error);

tokens.createAnonymousToken(request) ⇒ Promise.<string>

Creates a new anonymous token for the specified workspace, and does not require authentication.

Kind: instance method of Tokens
Returns: Promise.<string> - A promise resolving to the token
Throws:

  • Will throw an error if the workspace does not have the anonymous feature enabled
ParamTypeDescription
requestCreateAnonymousTokenInputA request with claims required to create a token
request.refstringA reference for the anonymous user
request.workspaceIdstringThe workspace ID
request.metadatastringCustom metadata to be included in the token

Example

const request = {
  ref: "myref",
  workspaceId: "g-1234567890",
  metadata: {
   customField: "customValue"
  }
}

tokens.createAnonymousToken(request)
  .then(console.log)
  .catch(console.error) // handle any errors

tokens.createToken(request) ⇒ Promise.<string>

Creates a new token with the specified permissions.

Kind: instance method of Tokens
Returns: Promise.<string> - A promise resolving to the token
Throws:

  • Will throw an error if the user is not logged in
ParamTypeDescription
requestCreateTokenInputA request with claims required to create the token
request.refstringA reference for the user
request.peerIdstringThe peer ID for the user

Example

const request = {
  ref: "myref",
  customerId: "121a4579",
  workspaceId: "g-1234567890"
};

tokens.createToken(request)
  .then(console.log)
  .catch(console.error); // handle any errors

Users ⇐ AbstractBaseClient

Use the Goodtok Users capability to retrieve and manage users. Ensure the Goodtok API Server is running for the Users API to function.

Kind: global class
Extends: AbstractBaseClient
See: module:sdk:Client

new Users(client)

Constructs a new Users API object.

ParamTypeDescription
clientClientObject containing the client configuration

Example

const SDK = require("@goodtok/sdk");

async function getUser() {
  const client = new SDK.Client({ workspace: "myworkspace" });
  await client.login("goodtok", "mysecretpassword");

  const users = new SDK.Users(client);
  const id = "5f9d7a3a-2b2b-4b7a-9b9b-8e9d9d9d9d9d";
  const user = await users.getUserById(id);

  console.log(user);
}

getUser().catch(console.error);

users.getCurrentUser() ⇒ Promise.<User>

Retrieves the logged-in user.

Kind: instance method of Users
Returns: Promise.<User> - A promise resolving to the user
Throws:

  • Will throw an error if user is not logged in or the JWT token has expired

Example

const id = "5f9d7a3a-2b2b-4b7a-9b9b-8e9d9d9d9d9d";

users.getCurrentUser(id)
  .then(console.log)
  .catch(console.error); // handle any errors

users.getUserById(id) ⇒ Promise.<User>

Retrieves a user by its ID. The calling user must have an admin role to retrieve other users.

Kind: instance method of Users
Returns: Promise.<User> - A promise resolving to the user
Throws:

  • Will throw an error if the user is not found
  • If the user is not an admin and the user ID does not match the logged-in user's ID
ParamTypeDescription
idstringThe user ID

Example

const id = "5f9d7a3a-2b2b-4b7a-9b9b-8e9d9d9d9d9d";

users.getUserById(id)
  .then(console.log)
  .catch(console.error); // handle any errors

users.updateUser(request) ⇒ Promise.<UpdateUserResponse>

Updates a user's details. The calling user must have an admin role to update other users.

Kind: instance method of Users
Returns: Promise.<UpdateUserResponse> - A promise resolving to the updated user's details
Throws:

  • If the user is not an admin and the user ID does not match the logged-in user's ID
ParamTypeDescription
requestUpdateUserRequestA request object containing the user ID and update data
request.namestringOptional parameter to update the user's name
request.passwordstringOptional parameter to update the user's password
request.avatarstringOptional parameter to update the user's avatar

Example

const request = {
  name: "John Doe",
  password: "mysecretpassword",
  avatar: "https://example.com/avatar.png"
};

users.updateUser(request)
  .then(console.log)
  .catch(console.error); // handle any errors

Workspaces ⇐ AbstractBaseClient

Use the Goodtok Workspaces capability to retrieve and manage workspaces. Ensure the Goodtok API Server is running for the Workspaces API to function.

Kind: global class
Extends: AbstractBaseClient
See: module:sdk:Client

new Workspaces(client)

Constructs a new Workspaces API object.

ParamTypeDescription
clientClientObject containing the client configuration

Example

const SDK = require("@goodtok/sdk");

async function getWorkspace() {
  const client = new SDK.Client({ workspace: "myworkspace" });
  await client.login("goodtok", "mysecretpassword");

  const workspaces = new SDK.Workspaces(client);
  const workspace = await workspaces.getDefaultWorkspace();

  console.log(workspace);
}

getWorkspace().catch(console.error);

workspaces.createWorkspace(request) ⇒ Promise.<Workspace>

Creates a new workspace.

Kind: instance method of Workspaces
Returns: Promise.<Workspace> - A promise resolving to the created workspace

ParamTypeDescription
requestCreateWorkspaceRequestThe request object containing the workspace name, timezone, and hours of operation
request.namestringThe workspace name
request.timezonestringThe workspace timezone
request.hoursOfOperationobjectThe workspace hours of operation

Example

const request = {
  name: "My Workspace",
  timezone: "America/New_York",
  hoursOfOperation: {
    Monday: { from: "09:00", to: "17:00" },
    Tuesday: { from: "09:00", to: "17:00" },
    // ...
  }
};

workspaces.createWorkspace(request)
 .then(console.log)
 .catch(console.error); // handle any errors

workspaces.getDefaultWorkspaceId() ⇒ string

Retrieves the default workspace ID.

Kind: instance method of Workspaces
Returns: string - The default workspace ID
Example

workspaces.getDefaultWorkspaceId();

workspaces.getDefaultWorkspace() ⇒ Promise.<Workspace>

Retrieves the default workspace.

Kind: instance method of Workspaces
Returns: Promise.<Workspace> - A promise resolving to the workspace
Example

workspaces.getDefaultWorkspace()
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.getDefaultWorkspaceMembers() ⇒ Promise.<GetMembersResponse>

Retrieves the members for the default workspace.

Kind: instance method of Workspaces
Returns: Promise.<GetMembersResponse> - A promise resolving to the members
Example

workspaces.getDefaultWorkspaceMembers()
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.getWorkspaceById(id) ⇒ Promise.<Workspace>

Retrieves a workspace by its ID.

Kind: instance method of Workspaces
Returns: Promise.<Workspace> - A promise resolving to the workspace

ParamTypeDescription
idstringThe workspace ID

Example

const id = "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d";

workspaces.getWorkspaceById(id)
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.getMembersByWorkspaceId(id) ⇒ Promise.<Workspace>

Retrieves the members for a workspace by its ID.

Kind: instance method of Workspaces
Returns: Promise.<Workspace> - A promise resolving to an object containing an array of members

ParamTypeDescription
idstringThe workspace ID

Example

const id = "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d";

workspaces.getMembersByWorkspaceId(id)
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.updateWorkspace(request) ⇒ Promise.<Workspace>

Updates the details of a workspace.

Kind: instance method of Workspaces
Returns: Promise.<Workspace> - A promise resolving to the updated workspace's details

ParamTypeDescription
requestUpdateWorkspaceRequestThe request object containing the workspace ID and update data
request.idstringThe workspace ID
request.namestringThe workspace name
request.timezonestringThe workspace timezone
request.hoursOfOperationobjectThe workspace hours of operation

Example

const request = {
  id: "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d",
  name: "My Workspace",
  timezone: "America/New_York",
  hoursOfOperation: {
    Monday: { from: "09:00", to: "17:00" },
    Tuesday: { from: "09:00", to: "17:00" },
    // ...
  }
};

workspaces.updateWorkspace(request)
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.getWorkspaces() ⇒ Promise.<Array.<Workspace>>

Retrieves all workspaces for the authenticated user.

Kind: instance method of Workspaces
Returns: Promise.<Array.<Workspace>> - A promise resolving to an array of workspaces
Example

workspaces.getWorkspaces()
 .then(console.log)
 .catch(console.error); // handle any errors

workspaces.addWorkspaceMember(request) ⇒ Promise.<Member>

Adds a member to a workspace.

Kind: instance method of Workspaces
Returns: Promise.<Member> - A promise resolving to the added member

ParamTypeDescription
requestAddWorkspaceMemberRequestThe request object containing the workspace ID and member details
request.workspaceIdstringThe workspace ID
request.namestringThe member name
request.emailstringThe member email
request.rolestringThe member role

Example

const request = {
  workspaceId: "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d",
  name: "John Doe",
  email: "jhon@example.com",
  role: "MEMBER"
};

workspaces.addWorkspaceMember(request)
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.removeWorkspaceMember(id) ⇒ Promise.<void>

Removes a member from a workspace.

Kind: instance method of Workspaces
Returns: Promise.<void> - A promise resolving to void

ParamTypeDescription
idstringThe member ID

Example

const id = "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d";

workspaces.removeWorkspaceMember(id)
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.removeWorkspace(id) ⇒ Promise.<void>

Removes a workspace.

Kind: instance method of Workspaces
Returns: Promise.<void> - A promise resolving to void

ParamTypeDescription
idstringThe workspace ID

Example

const id = "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d";

workspaces.removeWorkspace(id)
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.resendWorkspaceMemberInvite(id) ⇒ Promise.<void>

Resends a workspace member invite.

Kind: instance method of Workspaces
Returns: Promise.<void> - A promise resolving to void

ParamTypeDescription
idstringThe member ID

Example

const id = "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d";

workspaces.resendWorkspaceMemberInvite(id)
  .then(console.log)
  .catch(console.error); // handle any errors

workspaces.watchWorkspaceStatus(id, callback) ⇒ Unsubscribable

Registers a callback for real-time updates on workspace status.

Kind: instance method of Workspaces
Returns: Unsubscribable - An object containing the unsubscribe method

ParamTypeDescription
idstringThe ID of the workspace
callbackfunctionThe callback to be invoked when the workspace status updates

Example

const id = "4f9d5a3a-362b-7b7a-34gb-4e94969d7d2d";

workspaces.watchWorkspaceStatus(id, (err, data) => {
  if (err) {
   console.error(err);
   return;
  }

  console.log(data);
});
0.1.16

5 months ago

0.1.17

5 months ago

0.1.18

5 months ago

0.1.14

5 months ago

0.1.13

5 months ago

0.1.11

5 months ago

0.1.10

5 months ago

0.1.8

5 months ago

0.1.6

5 months ago

0.1.5

5 months ago

0.1.4

6 months ago

0.1.2

6 months ago

0.1.1

6 months ago

0.1.0

6 months ago

0.0.15

6 months ago

0.0.14

6 months ago

0.0.13

6 months ago

0.0.12

6 months ago

0.0.11

6 months ago

0.0.10

7 months ago

0.0.9

7 months ago

0.0.8

7 months ago

0.0.7

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago