New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@workerbase/sdk

Package Overview
Dependencies
Maintainers
2
Versions
114
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@workerbase/sdk

## Installing

  • 0.1.8
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-64.71%
Maintainers
2
Weekly downloads
 
Created
Source

Workerbase SDK for JavaScript

Installing

Install with npm

npm install @workerbase/sdk

Typescript

Workerbase SDK fully supports typescript with .d.ts files and the types will be maintained in the next releases.

Usage

You can use a default import with typescript

import workerbase from '@workerbase/sdk';

However we recommend using the following syntax with CommonJS to get the typings for autocomplete.

const { Workerbase } = require('@workerbase/sdk');

Authentication setup

You can configure the Workerbase SDK authentication options wiht the auth mehtod:

workerbase.auth({
  url: 'https://myWorkerbaseDomain.workerbase.io',
  token: TOKEN,
});

If you don't use the auth method will use the following env variables as token and url

WB_ACCESS_TOKEN=token
WB_API_URL=url

However if you are using the Workerbase SDK directly in a Workerbase Function, you don't need to use the specify the authentication config as the SDK will directly use the environment variables within the Workerbase Function.

Example

const workerbase = require('@workerbase/sdk');

// Doing simple requests
const updateUserName = async (userId) => {
  const { firstName } = await workerbase.users.get(userId);
  await workerbase.users.update(userId, { firstName: firstName + "v2" });
};

// Working with database items
const createDbAndInsertItems = async () => {
  const database = await workerbase.databases.create({
    name: "test",
    columns: [
      { name: "field1", type: "String" },
      { name: "value", type: "Integer" },
    ],
  });
  await database.items.create({ field1: "abc" }, "item1");
  await database.items.update("item1", { payload: { value: "5" } });
  await database.items.create({ field1: "abcd" }, "item2");
  await database.items.delete("item2");
};
};

// Using list response builtin methods
const getAllUserDepartments = () =>
  workerbase.users.list().distinctBy("department");
const getAllUsersWithName = (userLastname) =>
  workerbase.users.list().filterBy({ lastName: userLastname });
const getAllUserDepartmentsWithName = (userLastName) =>
  workerbase.users
    .list()
    .filterBy({ lastName: userLastName })
    .distinctBy("department");

// Invoking a workerbase Function
const invokeFunction = async (functionId) => {
  try {
    return await workerbase.functions.invoke(functionId, { some: "data" });
  } catch (err) {
    console.log(err.logs);
  }
};

Methods

Databases

workerbase.databases.list([listConfig])

workerbase.databases.get(id)

workerbase.databases.create(value)

workerbase.databases.update(id,value)

workerbase.databases.delete(id)

Database Items

Database.items.list([listConfig])

Database.items.get(id)

Database.items.create(value[,externalId])

Database.items.createMany(values)

Database.items.update(id,value)

Database.items.delete(id)

Events

workerbase.events.list([listConfig])

workerbase.events.get(id)

workerbase.events.create(value)

workerbase.events.update(id,value)

workerbase.events.delete(id)

workerbase.events.trigger(id,payload)

Functions

workerbase.functions.list([listConfig])

workerbase.functions.get(id)

workerbase.functions.create(value)

workerbase.functions.update(id,value)

workerbase.functions.delete(id)

workerbase.functions.deploy(id)

workerbase.events.invoke(id,payload)

Locations

workerbase.locations.list([listConfig])

workerbase.locations.get(id)

workerbase.locations.create(value)

workerbase.locations.update(id,value)

workerbase.locations.delete(id)

workerbase.locations.getPartsByLevel(levelId)

workerbase.locations.getLevels()

Media

workerbase.media.list([listConfig])

workerbase.media.get(id)

workerbase.media.delete(id)

Roles

workerbase.roles.list([listConfig])

workerbase.roles.get(id)

workerbase.roles.create(value)

workerbase.roles.update(id,value)

workerbase.roles.delete(id)

Skills

workerbase.skills.list([listConfig])

workerbase.skills.get(id)

workerbase.skills.create(value)

workerbase.skills.update(id,value)

workerbase.skills.delete(id)

Users

workerbase.users.list([listConfig])

workerbase.users.get(id)

workerbase.users.create(value)

workerbase.users.update(id,value)

workerbase.users.delete(id)

List documentation

ListConfig

interface ListConfig {
  // page number
  page?: number;

  // number of items per page (default 1000)
  perpage?: number;

  // field to sort on (not supported by every field)
  sort?: string;

  // order of the sorting
  order?: 'desc' | 'asc';

  // fields to select
  fields?: string;
}

List Response Methods

We added some builtin methods in Workerbase SDK to help you work with the data on the list responses. See the examples above, to see how to use them.

list().filterBy(condition)

Filter the list to keep only the values that match the condition object.

list().distinctBy(field)

Return the list of all distinct values of the specified field.

FAQs

Package last updated on 20 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc