Giter VIP home page Giter VIP logo

node-vtex-api's Introduction

VTEX IO API Client for Node

This library enables developers to quickly integrate with the VTEX IO APIs and create full fledged node services using VTEX IO.

Build Status

Getting started

For a complete example on using @vtex/api, check out this app: https://github.com/vtex-apps/service-example

The most basic usage is to export a new Service() with your route handlers:

// Import global types
import './globals'

import { Service } from '@vtex/api'

import { clients } from './clients'
import example from './handlers/example'

// Export a service that defines route handlers and client options.
export default new Service({
  clients,
  routes: {
    example,
  },
})

This allows you to define middlewares that receive a Context param which contains all IO Clients in the clients property:

export const example = async (ctx: Context, next: () => Promise<void>) => {
  const {state: {code}, clients: {apps}} = ctx
  console.log('Received code:', code)

  const apps = await apps.listApps()
  
  ctx.status = 200
  ctx.body = apps
  ctx.set('Cache-Control', 'private')

  await next()
}

ctx.clients.apps is an instance of Apps.

Development

  • Install the dependencies: yarn
  • Watch for changes: yarn watch

Development with IO clients

  • Install the dependencies: yarn
  • Link this package: yarn link
  • Watch for changes: yarn watch
  • Move to the app that depends on the changes made on this package: cd ../<your-app>/node
  • Link this package to your app's node_modules: yarn link @vtex/api

Now, when you get a workspace up and running for your app with vtex link, you'll have this package linked as well.

When done developing, don't forget to unlink it from <your-app>/node: yarn unlink @vtex/api

node-vtex-api's People

Contributors

amoreira avatar arturpimentel avatar becageuse avatar dhasuda avatar diegoximenes avatar filafb avatar filipewl avatar gris avatar guifromrio avatar gustavorosolem avatar iagoaraujo avatar jeymisson avatar juaresba avatar mairatma avatar marcelovicentegc avatar mcandeia avatar natalia-godot avatar pedroig avatar rdumont avatar rogerlucena avatar tamorim avatar thiagomurakami avatar tiagonapoli avatar tlgimenes avatar valentino-amadeus avatar vcalasans avatar verasthiago avatar viniagostini avatar vsseixaso avatar vwraposo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-vtex-api's Issues

stats-lite version declared in package.json is breaking yarn install

Hi, I'm installing @vtex/[email protected] in a monorepo where I'm using [email protected] as package manager. Installing this package is breaking my yarn install command, here the logs:

Packing stats-lite@https://github.com/vtex/node-stats-lite.git#commit=1b0d39cc41ef7aaecfd541191f877887a2044797 from sources
Using Yarn Classic for bootstrap. Reason: "__metadata" key not found in yarn.lock, must be a Yarn classic lockfile

➤ YN0000: Downloading https://classic.yarnpkg.com/latest.js
➤ YN0000: Saving the new release in .yarn/releases/yarn-classic.cjs
➤ YN0000: Done in 0s 922ms

! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing [email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e.
! For more details about this field, consult the documentation at https://nodejs.org/api/packages.html#packagemanager

yarn install v1.22.22
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
error Error: https://registry.yarnpkg.com/event-stream/-/event-stream-3.3.6.tgz: Request failed "404 Not Found"
    at Request.<anonymous> (/private/var/folders/r0/ww_pkx_d5qxcd8h7fc3fqmfm0000gn/T/xfs-ddc7b71e/.yarn/releases/yarn-classic.cjs:78280:16)
    at Request.emit (node:events:519:28)
    at module.exports.Request.onRequestResponse (/private/var/folders/r0/ww_pkx_d5qxcd8h7fc3fqmfm0000gn/T/xfs-ddc7b71e/.yarn/releases/yarn-classic.cjs:136694:10)
    at ClientRequest.emit (node:events:519:28)
    at HTTPParser.parserOnIncomingClient (node:_http_client:698:27)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:119:17)
    at TLSSocket.socketOnData (node:_http_client:540:22)
    at TLSSocket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Expected Behavior

Installing @vtex/[email protected] should not break yarn install.

Current Behavior

Installing @vtex/[email protected] breaks yarn install on version 4.2.2.

Possible Solution

I tried to install the package [email protected] as a dev dependency and all went well. So I wonder why in this package instead of using [email protected] in the package.json file you are using "stats-lite": "vtex/node-stats-lite#dist"

See > https://github.com/vtex/node-vtex-api/blob/v6.47.0/package.json#L84-L86

TBH that's terrible, IMO. You should never use latest version or no version of a package, it could introduce several side effects. Please correct me if I'm wrong or explain to me why you're doing that? Why not using [email protected] ?

Steps to Reproduce (for bugs)

Use the repository https://github.com/vtex-apps/payment-provider-example, update the repo to use yarn 4.2.2. You will need to adjust the package.json files.

Context

I'm setting up the folder structure for being able to build a payment app following the Payment Provider Framework but since I have a monorepo installing @vtex/[email protected] breaks yarn install.

Your Environment

  • Version used: 6.47.0
  • Environment name and version (e.g. Chrome 39, node.js 5.4): node 20.14.0 + yarn 4.2.2
  • Operating System and version (desktop or mobile):
  • Link to your project: Private repo.

MasterData client delivers infinite/repeated data on scroll and search methods

When using client factories that use the MasterData client (such as masterDataFor available at io-clients) the data returned from search and scroll methods is repeated and infinite. Such bug occurs because the http request made is cached and as the search and scroll queries are the same (without the query string) throughout the iterations the http client returns the cached result.

Expected Behavior

When executing a scroll/search the results should change on a page number increase or in a scroll iteration.

Current Behavior

When executing a scroll/search the results returned are the same regardless the page number or the current scroll iteration.

Possible Solution

Setting the cache argument of the request to CacheType.None worked for me.

Steps to Reproduce (for bugs)

  1. Create a masterDataFor client in an IO app
  2. Execute the code below
const records: T[] = []

    const lastResult: { hasNext: boolean; token: string | undefined } = {
      hasNext: true,
      token: undefined,
    }

    while (lastResult.hasNext) {
      const { data, mdToken } = await mdClient.scroll({
        size: 100,
        mdToken: lastResult.token,
        fields: ['_all'],
      })

      records.push(...(data as T[]))

      console.log(data[0].id)

      lastResult.hasNext = !!data.length
      if (!lastResult.token) {
        lastResult.token = mdToken
      }
    }
  1. Notice how the while falls in an infinite loop printing always the same id from the first fetched document.

Context

I had to switch from using the masterDataFor client to making raw http requests to the MasterData endpoint

Your Environment

  • Version used:
    "@vtex/api": "^6.44.0",
    "@vtex/clients": "^2.17.0",

Invalid regular expression when linking IO app

Today, 2020-02-26 we wanted to update our app and were unable to link it.

Expected Behavior

App should link without errors.

Current Behavior

App errors with the following message:

helles:io> vtex link --verbose
16:13:44.687 - debug: Toolbelt version: 2.89.0  
16:13:44.693 - debug: node v13.8.0 - linux 5.3.0-40-generic  
16:13:44.694 - debug:  [ 'link', '--verbose' ]  
...
16:14:37.573 - debug: Starting app code [email protected]  
16:14:38.387 - error: SyntaxError: Invalid regular expression: /\(\(\((?<context>(.)*)\)\)\)/: Invalid group
    at Object.<anonymous> (/usr/local/data/service/node_modules/@vtex/api/lib/service/worker/runtime/graphql/schema/schemaDirectives/TranslatableV2.js:6:23)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/local/data/service/node_modules/@vtex/api/lib/service/worker/runtime/graphql/schema/schemaDirectives/index.js:9:26)
    at Module._compile (module.js:652:30) [email protected]  
16:14:38.388 - error: App failed to start. Will not attempt to restart. [email protected] 

Steps to Reproduce (for bugs)

Just link the application.

Your Environment

Toolbelt version: 2.89.0
node v13.8.0 - linux 5.3.0-40-generic
Ubuntu linux 18.04

Thanks!

Error handling in Apps relink (patch)

In the relink method in Apps, there is no error-handling for the archiver.

Maybe we should add something like this:

archive.on('error', function(err) {
  // do something
})

We believe this may have led to some recent builder-hub restarts when there was a missing file during relink, after we investigated the following error:

Error: ENOENT: no such file or directory, open '<filename>'
time="2018-08-07T20:14:19Z" level=fatal msg="Not a linked app and failed to start unrecoverably." error="App ended with exit code 1: exit status 1" 

Masterdata client doesn't allow search by keyword

The Masterdata API accepts a _keyword query string which allows you to search in all fields marked as searchable, but there is no way to populate this attribute through the @vtex/api Masterdata client functions.

I would suggest that an optional keyword property be added to the SearchInput object in searchDocuments, searchDocumentsWithPaginationInfo, and scrollDocuments.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.