# @g123jp/ctw-box-sdk

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

Latest version **0.4.7** (published 2024-03-18) · ISC license · 0 weekly downloads

## Install

```sh
npm install @g123jp/ctw-box-sdk
pnpm add @g123jp/ctw-box-sdk
yarn add @g123jp/ctw-box-sdk
bun add @g123jp/ctw-box-sdk
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.7 |
| Published | 2024-03-18 |
| First published | 2023-01-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 56.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Lukasz Moskwa at CTW |
| Maintainers | lukaszmoskwactw, chinterry, huli-ctw, hydranger, kouhin |

## Links

- npm: https://www.npmjs.com/package/@g123jp/ctw-box-sdk
- npm.io page: https://npm.io/package/@g123jp/ctw-box-sdk

## Dependencies (7)

- [jest](https://npm.io/package/jest.md) ^29.3.1
- [axios](https://npm.io/package/axios.md) ^1.2.1
- [ts-jest](https://npm.io/package/ts-jest.md) ^29.0.3
- [form-data](https://npm.io/package/form-data.md) ^4.0.0
- [cross-blob](https://npm.io/package/cross-blob.md) ^3.0.2
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2
- [@types/jest](https://npm.io/package/@types/jest.md) ^29.2.4

## Recent versions

- 0.4.7 (latest) — 2024-03-18
- 0.4.6 — 2024-03-18
- 0.4.4 — 2024-03-18
- 0.4.5 — 2024-03-18
- 0.4.3 — 2023-05-29
- 0.4.2 — 2023-05-28
- 0.4.1 — 2023-05-19
- 0.4.0 — 2023-05-16
- 0.3.0 — 2023-05-11
- 0.2.16 — 2023-04-21
- 0.2.15 — 2023-04-17
- 0.2.14 — 2023-04-13
- 0.2.13 — 2023-04-07
- 0.2.12 — 2023-03-22
- 0.2.11 — 2023-03-20
- … 23 more at https://npm.io/package/@g123jp/ctw-box-sdk/versions

## 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

```typescript
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

```typescript
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

```typescript
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

```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

```typescript
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

```typescript
const options = {
  category: "icon",
  app_id: "auo",
  attributes: {
    style: "round",
    isTemplate: true,
  },
};

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

---
_Source: https://npm.io/package/@g123jp/ctw-box-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
