seneca icon indicating copy to clipboard operation
seneca copied to clipboard

Getting started: Shop.js with shop-stats.js example is broken

Open rhythnic opened this issue 6 years ago • 1 comments

In shop.js, the role:shop,info:purchase action works when handled locally, but breaks when using the shop-stats.js integration.

// shop.js line 27
this.act('role:shop,info:purchase',{purchase:purchase})

Error in terminal

$ node shop-test.js
{"kind":"notice","notice":"hello seneca e35mopzsfmw0/1527260988205/13208/3.5.0/-","level":"info","seneca":"e35mopzsfmw0/1527260988205/13208/3.5.0/-","when":1527260988263}
["client","invalid_origin",{"port":9003,"pin":"role:shop,info:purchase","pg":"info:purchase,role:shop","type":"web","host":"0.0.0.0","path":"/act","id":"pg:info:purchase,role:shop,pin:role:shop,info:purchase,port:9003","role":"transport","hook":"client","plugin$":{"name":"transport","tag":"-","fullname":"transport"},"fatal$":true,"tx$":"dvoj53vxgl91","protocol":"http","timeout":5555,"max_listen_attempts":11,"attempt_delay":222,"serverOptions":{}},{"kind":"res","res":{"type":"Buffer","data":[115,101,110,101,99,97,46,109,97,107,101,36,32,105,115,32,110,111,116,32,97,32,102,117,110,99,116,105,111,110,58,32,123,34,112,117,114,99,104,97,115,101,34,58,123,34,101,110,116,105,116,121,36,34,58,34,45,47,45,47,112,117,114,99,104,97,115,101,34,44,34,119,104,101,110,34,58,49,53,50,55,50,54,48,57,56,56,50,54,48,44,34,112,114,111,100,117,99,116,34,58,34,115,108,100,99,121,108,34,44,34,110,97,109,101,34,58,34,65,112,112,108,101,34,44,34,112,114,105,99,101,34,58,49,46,57,57,44,34,105,100,34,58,34,99,101,104,116,49,117,34,125,44,34,114,111,108,101,34,58,34,115,104,111,112,34,44,34,105,110,102,111,34,58,34,112,117,114,99,104,97,115,101,34,125]},"error":null,"sync":false,"time":{"client_recv":1527260988275}}]

Fix

Don't pass the entire purchase-save result, with the special $ properties.

const infoPurchase = R.pick(['when', 'product', 'name', 'price'], purchase)
this.act('role:shop,info:purchase',{ purchase: infoPurchase })

Other enhancements

  • Mention that the local action handler needs to be removed from shop.js in order for the message to get sent to the shop-stats service.
  • swap the order of the run commands in the terminal, to indicate that the shop-stats service needs to start before shop-test

By the way, I am enjoying learning Seneca. It's a great library.

rhythnic avatar May 25 '18 15:05 rhythnic

I wan to work on this issue

OpenTechConsult avatar Oct 11 '22 11:10 OpenTechConsult