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

@acho-inc/acho-js

v1.5.3

Published

Acho Javascript SDK

Downloads

347

Readme

npm version npm version npm version

What is this repository for?

  • SDK for Acho Studio API

Features

  • Get data from Acho Resource by page
  • Run data sync for Acho Resource
  • Download data from Acho Resource
  • Query Acho Resource for data
  • Get Acho Resource Schema
  • Create Node.js Readable Stream from Acho Resource
  • Create Node.js Writable Stream from Acho Resource
  • Get data from Acho Project view
  • Get a list of Configured OAuth Client IDs for current organization
  • Use an OAuth Client ID to issue a Bearer Token
  • Connect to an Acho Published APP's instance
  • Join / leave the Acho Published APP instance's socket room
  • Send Event to the Acho Published APP instance

Installing

Package Manager

$ npm install @acho-inc/acho-js

If you want to use it as a dependency in your project that needs to be built and deployed

$ npm install @acho-inc/acho-js --save

After the package is installed in your package.json

import { Acho } from '@acho-inc/acho-js';

Example

Initializing the Acho Client

const AchoInstance = new Acho();

The SDK will use the environment variables from your system

ACHO_TOKEN: The Acho develoepr API token

  • If you are a current subscriber, retrieve it from your profile page
  • If you want to try out the SDK without an active subscription, please contact us

ACHO_API_ENDPOINT: The service backend you are connecting to

  • Default to https://kube.acho.io
  • This setting is irrelevant unless you subscribe to on-premise or dedicated server

If you prefer convenience in testing, you could also initialize the instance by passing in the variables in constructor

const AchoInstance = new Acho({
  apiToken: 'eyEi3oldsi....',
  endpoint: 'https://kube.acho.io'
});

Note: It is not recommended to expose your API token in the code base, especially on production
We highly recommend dotenv for conveniently modifying environment variables during testing
If you suspect your token might be leaked, you can invalidate the token in your profile page, or report to [email protected]

Working with Resource Endpoints

Create a new resource

const resourceResp = await AchoInstance.ResourceEndpoints.create({ name: 'test' });

/* resourceResp: { 
    resId: number,
    assetId: number,
    resource: {
      id: number,
      res_name: string,
      res_display_name: string,
      res_type: 'integration',
      is_ready: 1,
      create_time: unix_timestamp (UTC),
      user_id: number,
      update_time: unix_timestamp (UTC),
      asset_id: number
    }
   }
*/

Create a table in a resource

const resourceTableResp = await AchoInstance.ResourceEndpoints.createTable({
  resId: testResId,
  tableName: 'test',
  schema: { col1: 'STRING', col2: 'INTEGER' }
});

/* resourceTableResp: {
    resource: {
      id: number,
      res_name: string,
      ...
    }
    tableName: string
   }
*/

Stream data into a table

// JSON flavor
const writableStream = AchoInstance.ResourceEndpoints.createWriteStream({
  resId: testResId,
  tableId: 'test',
  dataType: 'json'
});
const testArray = [
  { col1: 'JSON_1', col2: 1 },
  { col1: 'JSON_2', col2: 2 },
  { col1: 'JSON_3', col2: 3 },
  { col1: 'JSON_4', col2: 4 }
];
await new Promise((resolve) => {
  testArray.forEach((row) => {
    writableStream.write(JSON.stringify(row) + '\n');
  });
  writableStream.end();
  writableStream.on('response', (res) => {
    // expect(res.statusCode).toBe(200);
    resolve('done');
  });
});

// CSV flavor
const writableStream = AchoInstance.ResourceEndpoints.createWriteStream({
  resId: testResId,
  tableId: 'test',
  dataType: 'csv'
});
const testCSV = 'CSV_1,1\nCSV_2,2\nCSV_3,3\nCSV_4,4\n';
await new Promise((resolve) => {
  writableStream.write(testCSV);
  writableStream.end();
  writableStream.on('response', (res) => {
    // expect(res.statusCode).toBe(200);
    resolve('done');
  });
});

Note: You can also pipe readable stream into the writableStream created from a resource table
The supported formats are CSV and NDJSON.

Use Cases

Create a Resource and a table in the Resource, then insert data into the table

Create a new resource and a resource table first

const createResourceTable = async () => {
  const resourceResp = await AchoInstance.ResourceEndpoints.create({
    name: 'Test Resource'
  });

  const { resId } = resourceResp;

  // please make sure you capture the resId here if you want to do the process in two steps
  console.log(resId);

  const resourceTableResp = await AchoInstance.ResourceEndpoints.createTable({
    resId: resId,
    tableName: 'Test Table',
    schema: { name: 'STRING', age: 'INTEGER' }
  });
};

Write data to the resource table (in this example we are using JSON)

const writeData = async () => {
  const writableStream = AchoInstance.ResourceEndpoints.createWriteStream({
    // replace 1234 with the id you captured earlier
    resId: 1234,
    tableId: 'Test Table',
    dataType: 'json'
  });

  const testArray = [
    { name: 'Adam', age: 28 },
    { name: 'Dan', age: 33 },
    { name: 'Jason', age: 35 },
    { name: 'Zach', age: 40 }
  ];

  await new Promise((resolve) => {
    testArray.forEach((row) => {
      writableStream.write(JSON.stringify(row) + '\n');
    });
    writableStream.end();
    writableStream.on('response', (res) => {
      resolve('done');
    });
  });
};

After finishing the previous steps, if you add "Test Table" from Resource "Test Resource" to a Project on Acho, here is what you will get.