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

@vtex/api

Package Overview
Dependencies
Maintainers
89
Versions
890
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vtex/api

VTEX I/O API client

  • 1.9.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5.6K
increased by81.94%
Maintainers
89
Weekly downloads
 
Created
Source

VTEX IO API Client for Node

This client enables Node developers to quickly integrate with the VTEX IO APIs.

Build Status

Getting started

Usage:

We generally create a Resources class that groups all relevant clients and initialize them with the current request's ctx.vtex context, which includes authToken, account, workspace, etc.

import {Apps, LRUCache, Registry, VBase, ServiceContext} from '@vtex/api'

const MAX_ELEMS = 1000
const RESPONSE_CACHE_TTL_MS = 60 * 60 * 1000
const LONG_TIMEOUT = 20 * 1000

const cacheStorage = new LRUCache<string, any>({
  max: MAX_ELEMS,
  maxAge: RESPONSE_CACHE_TTL_MS,
})

// `cacheStorage` has a `getStats` method.
metrics.addOnFlushMeter(() => ({...cacheStorage.getStats(), name: 'example-cache-stats'}))

export default class Resources {
  public apps: Apps
  public registry: Registry
  public vbase: VBase
  
  constructor (ctx: ColossusContext) {
    const opts = {cacheStorage}
    const withLongTimeout = {...opts, timeout: LONG_TIMEOUT}

    this.apps = new Apps(ctx.vtex, withLongTimeout)
    this.registry = new Registry(ctx.vtex, withLongTimeout)
    this.vbase = new VBase(ctx.vtex, opts)
  }
}

Development

Install the dependencies (yarn) and run yarn watch.

Using VBaseClient.sendFile

An example usage of the three supported methods of sending a file to VBase:

import {VBase} from '@vtex/api'
import {createReadStream} from 'fs'

const client = new VBase({
  account: 'account',
  workspace: 'workspace',
  authToken: 'test',
  userAgent: 'test send',
  region: 'aws-us-east-1',
})

client.saveFile(
  'bucket',
  'test-send-stream-gzip.txt',
  createReadStream('./test-send.txt'),
  {gzip: true, gzipOptions: {level: 9}}
).then((res) => {
  console.log('gz:', res)
})

client.saveFile(
  'bucket',
  'test-send-stream.txt',
  createReadStream('./test-send.txt'),
  {gzip: false}
).then((res) => {
  console.log('stream:', res)
})

client.saveFile(
  'bucket',
  'test-send-file.txt',
  './test-send.txt'
).then((res) => {
  console.log('file:', res)
})

Keywords

FAQs

Package last updated on 18 Apr 2022

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