Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@g123jp/ctw-box-sdk

Package Overview
Dependencies
Maintainers
5
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@g123jp/ctw-box-sdk

The following is the NodeJS implementation of the SDK APIs for CTW BOX

  • 0.2.10
  • npm
  • Socket score

Version published
Maintainers
5
Created
Source

CTW BOX - Core SDK

The following is the NodeJS implementation of the SDK APIs for CTW BOX

Goal

Having a component that can be integrated in other applications to use features from ctw-box like:

  • Searching for object
  • Retrieving objects with permanent links
  • Upoading new objects

Setup

import BoxClient from "@g123jp/ctw-box-sdk";

const boxClient = new BoxClient({
  endpoint: "https://ctwbox.stg.g123.jp/api/v1", // Change between staging and production
  accessToken: "...", // Bearer token to handle auth and permissions
});

After the client instance is created, it is recommended to use the setup command to have access to all the available categories

await boxClient.setup();

const categories = boxClient.categories; // List of categories

Available operations

.listProjects - Fetch available projects

This operation allow to list all the projects that are available under the chosen category

const projects = await boxClient.listProjects("icon");

The function takes a string as input (the id/key of the category)

.listObjects - Search objects

The search feature allows to search in CTW Box for one or more objects given a set of parameters. Follows an example in TypeScript

const options: ListObjectsOptions = {
  category: "icon",
  app_id: "auo",
  text: "image_02",
  searchType: "tag",
};
const { data } = await boxClient.listObjects(options);

This will retrieve a default limit of 20 objects on the page 1 within the icon workspace and the auo project. The search will be further filtered by objects containing the image_02 tag.

The following parameters are usable for search:

nametypedefaultdescription
categorystringCategory (or workspace)
app_idstringProject (or game)
textstringText of the search. Further filtered by the searchType parameter
mime_typestringObject's MIME Type
attributesRecord<string, string | number | boolean>Custom attributes of the object based on the category
propertiesRecord<string, string | number | boolean>Properties of the object like the owner or the file_size
filterRecord<string, string[]>Optional filters
pagenumber1Page of the results pagination
limitnumber20Limit of the results pagination
height_rangestringRange of accepted height for the object. Ex: 300_500
width_rangestringRange of accepted width for the object. Ex: 300_500
file_size_rangestringRange of accepted file sizes for the object. Ex: 300_500
created_at_rangestringRange of dates of creation accepted in the range for the object. Ex: 27636152_33225540152
updated_at_rangestringRange of dates of update accepted in the range for the object. Ex: 27636152_33225540152
searchTypestringType of search when searchin with the text parameter. Can be name or tag
object_idstringExact object ID to look for in any workspace in any project. all the other parameters are being ignored
tagsstringList of tags in stringified JSON array.

With this operation, it is possibile to retrieve all the objects uploaded in a specific batch given the permanent URL

const link =
  "https://ctwbox.stg.g123.jp/?link_id=3c7d6e9ecb0a4ac9ab9aedfa0035232d";
const { data } = await boxClient.listObjectsFromLink({
  fullLink: link,
});

The supported parameters are fullLink, linkId, page and limit

nametypedefaultdescription
fullLinkstringComplete link to the batch
linkIdstringOnly the id of the batch upload
pagenumber1Page of the results pagination
limitnumber1Limit of the results pagination

File Upload

The following is an example of usage for uploading a file to CTW BOX with some parameters like

  • Category
  • Project
  • Attributes Other parameters are not necessary and identified by the method, like
  • Owner: already identified by the access token
  • File Size: from file
  • Mime Type: from file
  • File Name: from file if not set
const options = {
  category: "icon",
  app_id: "auo",
  attributes: {
    style: "round",
    isTemplate: true,
  },
};

const { object_id } = await boxClient.fPutObject(file, metadata);

FAQs

Package last updated on 14 Mar 2023

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