npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@g123jp/ctw-box-sdk

v0.4.7

Published

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

Downloads

133

Readme

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",
};
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:

| name | type | default | description | | ---------------- | ------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------- | | category | string | | Category (or workspace) | | app_id | string | | Project (or game) | | text | string | | Text of the search. Matches with file_name | | mime_type | string | | Object's MIME Type | | attributes | Record<string, string | number | boolean> | | Custom attributes of the object based on the category | | properties | Record<string, string | number | boolean> | | Properties of the object like the owner or the file_size | | filter | Record<string, string[]> | | Optional filters | | page | number | 1 | Page of the results pagination | | limit | number | 20 | Limit of the results pagination | | height_range | string | | Range of accepted height for the object. Ex: 300_500 | | width_range | string | | Range of accepted width for the object. Ex: 300_500 | | file_size_range | string | | Range of accepted file sizes for the object. Ex: 300_500 | | created_at_range | string | | Range of dates of creation accepted in the range for the object. Ex: 27636152_33225540152 | | updated_at_range | string | | Range of dates of update accepted in the range for the object. Ex: 27636152_33225540152 | | object_id | string | | Exact object ID to look for in any workspace in any project. all the other parameters are being ignored | | tags | string | | List of tags in stringified JSON array. |

.listObjectsFromLink - Retrieve with permanent link

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

| name | type | default | description | | -------- | ------ | ------- | ------------------------------- | | fullLink | string | | Complete link to the batch | | linkId | string | | Only the id of the batch upload | | page | number | 1 | Page of the results pagination | | limit | number | 1 | Limit 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);