Giter VIP home page Giter VIP logo

swell-node's People

Contributors

awwit avatar dependabot[bot] avatar dimazhukovsky avatar ericingram avatar kyle-swell avatar patrickheneise avatar rodrigo-swell avatar swellmike avatar vstudenichnik-insoft avatar

Stargazers

 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

swell-node's Issues

Unable to use Swell-node

Hi,
I am hoping this is a mistake on my part and am doing something wrong, but i recently started trying out swell , and since i started i have been having big issues and problems trying to using the backend 'swell-node'.

I have followed the documentations closely to have the package installed in my project, but when i try using it in my project it doesnt seem to find the module.

image

image

Note:

  • I am using a Next 13 project.

Hanging forever after receiving results

I am trying to run a simple CLI script that returns an order using swell-node, however for some reason it gets stuck and keeps hanging forever.

Example POC:

const swell = require('swell-node');
swell.init(SWELL_SHOP, SWELL_KEY);

const main = async () => {
  const orders = await swell.get('/orders', { id: 'some-swell-id' })
  const { count, results } = orders
  console.log(count)
}

main()

Response is being received successfully and then the process gets stuck forever.
Things I've tried: enabling/disabling cache, decreasing the timeout, adding DEBUG=* (no debug available), switching from node14 to node10, tracing with why-is-node-running:

# TCPWRAP
some-path/node_modules/swell-node/lib/connection.js:41 - this.stream = proto.connect(
some-path/node_modules/swell-node/lib/connection.js:33 - this.connect(callback);
some-path/node_modules/swell-node/lib/client.js:70     - this.server = new Connection(
some-path/node_modules/swell-node/lib/client.js:124    - this.connect();
some-path/node_modules/swell-node/lib/client.js:276    - return this.request('get', url, data, callback);

# TLSWRAP
some-path/node_modules/swell-node/lib/connection.js:41 - this.stream = proto.connect(
some-path/node_modules/swell-node/lib/connection.js:33 - this.connect(callback);
some-path/node_modules/swell-node/lib/client.js:70     - this.server = new Connection(
some-path/node_modules/swell-node/lib/client.js:124    - this.connect();
some-path/node_modules/swell-node/lib/client.js:276    - return this.request('get', url, data, callback);

# DNSCHANNEL
(unknown stack trace)

Currently out of ideas. Any suggestions? Thanks!

Unable to fetch Orders with account_Id

Hi,

I have been tryin to fetch orders related to a users account.

I know swell provides a backend api to fetch order by Id.
Each orders also have account id's associated with them, I have been trying to fetch specific orders based on the account_id associated with them since there is no other way to get the order_id except from fetching the swell.get('/order') which fetch all the order...

Am i doing this wrong or is there a way to get this data from my app.

async function getOrder(accountId: string) {
try {
const res = await swellNode.get('/orders', {
params: {
account_id: accountId,
},
});
return res.results;
} catch (error) {
console.error('Failed to fetch orders:', error);
throw error;
}
}

i wrote this simple function to fetch orders based on the users account, but this will continue to return an [ ] array

Perhaps some one could help point out how i could achieve this

ReferenceError: j is not defined

swell-node/lib/connection.js:131:5

swell-node/lib/connection.js
    5:7   error  'DEFAULT_NETWORK_ERROR' is assigned a value but never used  no-unused-vars
  131:9   error  'j' is not defined                                          no-undef
  132:37  error  'j' is not defined                                          no-undef
  223:19  error  'error' is defined but never used                           no-unused-vars

j is defined inside the for block and therefore undefined in the condition that comes after the block.

Swell client does not close connection

I'm trying to test the integration with Swell and run into connection errors with jest:

 FAIL  test/swell.test.js (5.541 s)
  ✕ should return a list of orders (5044 ms)

  ● should return a list of orders

    : Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error:

      25 | })
      26 | 
    > 27 | test('should return a list of orders', async () => {
         | ^
      28 |   const response = await fastify.inject({
      29 |     method: 'GET',
      30 |     url: '/'

      at new Spec (node_modules/jest-jasmine2/build/jasmine/Spec.js:116:22)
      at Object.<anonymous> (test/swell.test.js:27:1)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        5.608 s, estimated 7 s

this is the file to reproduce the issue easily:

const swell = require('swell-node').init(
  process.env.SWELL_ID,
  process.env.SWELL_KEY,
  { cache: false }
)

const fastify = require('fastify')()

fastify.get('/', async function (request, reply) {
  const orders = await swell.get('/orders', {
    limit: 10,
    page: 1
  })
  reply.send(orders)
})

fastify.listen(3000, function (err, address) {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
  fastify.log.info(`server listening on ${address}`)
})

test('should return a list of orders', async () => {
  const response = await fastify.inject({
    method: 'GET',
    url: '/'
  })
  expect(response.statusCode).toEqual(200)
})

Cannot deploy on Cloudflare Pages or Vercel Edge Functions

I'm trying to deploy a site using the swell-node library which is based on a custom API endpoint /api/swell (mostly to avoid exposing the tokens and have more control) on Cloudflare Pages or Vercel Edge Functions but I get these errors:

21:12:56.149 | > Using @sveltejs/adapter-cloudflare
-- | --
21:12:56.243 | ✘ [ERROR] Could not resolve "events"
21:12:56.243 |  
21:12:56.244 | node_modules/swell-node/lib/client.js:1:29:
21:12:56.244 | 1 │ const EventEmitter = require('events');
21:12:56.244 | ╵                              ~~~~~~~~
21:12:56.244 |  
21:12:56.245 | The package "events" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
21:12:56.245 |  
21:12:56.245 | ✘ [ERROR] Could not resolve "crypto"
21:12:56.246 |  
21:12:56.246 | node_modules/swell-node/lib/client.js:2:23:
21:12:56.246 | 2 │ const crypto = require('crypto');
21:12:56.247 | ╵                        ~~~~~~~~
21:12:56.249 |  
21:12:56.249 | The package "crypto" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

Do you think there would be a way to make it work on these platforms? Or is it too relying on node?

Add example for createClient

Hi there.

I've been checking the official documentation, and AFAIK, there is no mention of the possibility you offer to create more than one client (createClient vs just init the exposed client instance). This may be quite useful for people having to interact with more than one store on the same service.

As the documentation in this repo is still in progress, maybe adding a simple reference in the Connect section like the following could be enough to keep rolling:

const swell = require('swell-node');

// Exposes a client instance
swell.init('my-store', 'secret-key');

// Creates client intances to interact with several stores
const myClient1 = swell.createClient().init('my-store-1', 'secret-key-1');
const myClient2 = swell.createClient().init('my-store-2', 'secret-key-2');

Greetings 👋

Carts Not Getting Created

Hi.

I'm using swellNode.post("/carts") to create a new empty cart before adding items.

It was working fine before, but now there's no cart being created when I go in the Swell Dashboard.

Anyone with the same issue?

[Bug] Methods don't retrieve information

I was using this library v3.1.4 and v3.1.3 and in both versions, in macOS, and in our Live environment (Docker image node:10.4) we have this problem.

When we do a request to the API it gets stuck and does not retrieve any information.

const result = await swell.get('/accounts', { where: { email } })
// no response

If we do the same but using Axios we get the results.

const { data: result } = await axios.get(`https://api.swell.store/accounts?where[email]=${email}`, {
      auth: {
        username: 'username',
        password: 'password',
      },
    });

We've been using this package since 2019 and we haven't had this problem.

You can reproduce the error with this code:

const swell = require('swell-node');

swell.init('my-store', 'secret-key');

const searchAccount = async email => {
  console.log('email', email);
  const result = await swell.get('/accounts', { where: { email } })
  console.log('searchAccount', result);
  return result;
};

searchAccount('[email protected]');

Execution result node app.js

Screen Shot 2020-07-24 at 14 26 57

APIs not returning data on filtering

I'm new to swell and decided to try out it for my next project.
I'm using swell APIs to fetch product details on my web app. While some paths are working super fine, I'm having trouble at getting other paths to work for me, especially the query and filtering ones.

Docs are quite unhelpful and not provide enough details.

I'm trying to filter products based on an attribute - featured_products which can be either yes or no or null if not set
Based on what you suggest in docs, I've literally tried various combination of paths but nothing works and I always get zero results.

https://api.swell.store/products?where[active][$eq]=true&where[attributes][featured_products]=yes
https://api.swell.store/products?where[active][$eq]=true&where[attributes][featured_products][$eq]=yes
https://api.swell.store/products?where[active][$eq]=true&where[attributes][featured_products][$eq]='yes'
https://api.swell.store/products?where[active][$eq]=true&where[attributes][featured_products][0][$eq]=yes
https://api.swell.store/products?where[active][$eq]=true&where[attributes][featured_products][0]=yes

https://api.swell.store/products?where[active][$eq]=true&where[featured_products][$eq]=yes
https://api.swell.store/products?where[active][$eq]=true&where[featured_products][0][$eq]=yes

Otherwise the both of the below given paths work for all products with pagination
https://api.swell.store/products?limit=25&page=1&where[active]=true
https://api.swell.store/products?limit=25&page=1&where[active][$eq]=true

Please suggest me correct way to use swell APIs for filtering.

Passing include query

I've tried to pass 'include[variants][url]': '/products:variants' in query, but response was null:

const SWELL_ID = '...'
const SWELL_SECRET_KEY = '...'
const productId = '...'

swell.init(SWELL_ID, SWELL_SECRET_KEY, { cache: false })
const params = {
  active: true,
  'include[variants][url]': '/products:variants'
}

try {
  const response = await swell.get(`/products/${productId}`, params)
  console.log(JSON.stringify(response, null, 2))
} catch (e) {
  console.error(e)
}

After removing 'include[variants][url]': '/products:variants' it returns data

When I've tried to use API directly everything was okay:

await fetch(`https://${SWELL_ID}:${SWELL_SECRET_KEY}@api.swell.store/products/${productId}?active=true&include[variants][url]=/products:variants`

BUG - Unexpected charge to the swell account on cancelling a subscription

I came across this catastrophic bug yesterday on swell, which I hope gets looked into soon.

I noticed that when you create a subscription manually on the swell dashboard and you then try to cancel/delete the subscription, it doesnt delete the subscription, but then charges your account for the initial yearly amount of your swell subscription.

Steps to reproduce

  • Create a subscription product
  • Navigate to subscription tab
  • Create a new subscription under the new subscription product
  • Edit the subscription by trying to delete it

image

  • refresh the page

image
This actually atempts a charge to my bank too on my actual account

Send email notification with new shipment via API

When creating a new shipment in the front end for an order, there is a checkbox that allows you to send a confirmation email to the customer.

Is it possible to trigger this email when creating a shipment from the backend API?

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.