Is there a way to use SuiteScript modules locally ...
# sdf
b
Is there a way to use SuiteScript modules locally ( outside of NetSuite ) for development purposes?
c
No
Doesn't even make sense. They'd need access to the DB/backend/whatever other spaghetti there is server-side
b
I thought so too. Thanks for confirming. I was hopeful though. In terms of scripts, I only wanted to play with front end UI either using Client Scripts or just HTML files to be inlined later on.
For more context, we use React to develop custom UI and front-end logic which is build into SuiteScripts and needs to be deployed to NetSuite to see the changes. I want to be able to see the front end changes right in my local browser which is faster. This is possible with few more set ups.
c
For local testing you could just stub the modules
m
When running react apps as a Suitelet, I've always built mock APIs to match what my RESTlet would eventually provide. If the current environment was 'Production', use the API that would make calls to the RESTlet. If not, use the mock api with local JSON data.
b
@CD Is there any docs/tutorial how to do that? @Mike Robbins That’s a good idea. In the past, I have used local dev server which would call the RESTlets during development. It is an extra hassle but you get live data from NetSuite.
m
I've always run into CORS issues if I try to call live RESTlets from a locally run web page.
b
that’s where the local dev server comes in, that’s another server running something like express which listens to calls from React app and makes calls to NetSuite RESTLets
m
Gotcha. Yeah, that makes sense. Here's the API folder from a react/suitelet that shows how I just return JSON data when running locally and calls RESTlets when running in production: https://github.com/datatek-software/netsuite-react-order-entry/tree/master/src/api
b
Thanks, I will check it out.
You can check out this as well. It is a Vue app but same logic applies. https://github.com/BibekStha/netsuite-vue-vite-spa
r
my mind is churning and maybe blown. you are using react to serve up SPA out of NS?
b
When you come from web dev background, you prefer this for your front end development.
r
u are using JS to serve a SPA? are you using suitelets to have an authenticated page? or are you using SPA connecting to restlets? just curious
s
We do something similar but use Angular (mostly) and have iterated and formalized the backend API to support VERY rapid development.
b
@redfishdev In the past, for each custom NetSuite page, I have created an individual SPA project. My project compiles the app into single
.html
file which is rendered by a SuiteLet. It communicates with NetSuite backend using SuiteTalk/RestLet. During dev, call to RestLet is achieved using a local backend dev server as making calls from front end would cause CORS error. I have a boiler plate repo (Vue3 app) for this which is shared above. Currently, I work on a much bigger SDF project with multiple custom pages and suitescripts. The project compiles all the react files into respective SuiteScript types. The drawback here is you have to deploy the files to NetSuite to see the changes. I am trying to find a common ground between these two.
r
@Bibek Shrestha very nice. do the client auth keys get pushed to the browser?const consumer = { public: process.env.TBA_CONSUMER_KEY, secret: process.env.TBA_CONSUMER_SECRET, }; const token = { public: process.env.TBA_TOKEN_KEY, secret: process.env.TBA_TOKEN_SECRET, };
or is the server code truly ran on the server
b
these keys are only used during the development so production code doesn’t have it
r
this was my authentication question
I understand the SPA running in the browser. so is the api layer hosted on another server than netsuite with the clint keys server side? if so, how does the client authenticate to the api server
s
we take a simpler approach - for UI, run with fake data locally for dev, real data for integration testing. Testing the backend is independent, using jest to call the restlet/suitlet with sample payloads and interrogate responses.
b
@redfishdev during dev, a second server (express) handles the calls to restlet. It uses TBA method for authentication using those keys. For production, there is no need for this server or extra authentication as the compiled file is rendered in NetSuite using suitelet.
@Shawn Talbert I know lot of people use mock APIs during dev which makes it much easier I guess.
s
a main benefit of using mock data locally is parallel development - one person can be working on the UI whllst another is building out the backend API.
k
We are doing something similar with Shawn, front end (react) is tested with mock data. Webpack or parcel is firing up a test server. We write controllers that either look at test data or make calls to back end SL. So the code is exactly the same as the one we ship. When both back and front are ready we monkey test the whole app.
243 Views