Uploading a file to Netsuite using Node.js - javascript

So I am testing out a script that comes with an npm module that will upload a NetSuite file to the File Cabinet.
Here is a link to the npm module called nsupload. The instructions say to upload the Restlet included in the module to Netsuite and set the function in the RESTlet in the PUT method in Netsuite. When I run the script on my end to upload a file to the Netsuite File Cabinet I get the error "TypeError: sendToNetsuite is not a function."
Here is the test code the module supplies:
var sendToNetsuite = require('nsupload')
.config({
email: 'email',
password: 'pass',
account: 'account number',
script: 'script number',
method: 'PUT'
});
sendToNetsuite('./foo.json', function(err, body) {
console.log('Success!');
console.log(body);
});
EDIT:
I changed the npm module I was using to the one called nscabinet. This stoo came with a sample code for uploading a file to Netsuite. Here's the code to that:
var nscabinet = require('nscabinet') ,
gulp = require('gulp') //or just vinyl-fs
gulp.src('foo.js')
.pipe(nscabinet({
email : 'foo#bar.baz.com' ,
password : '123456' ,
account : '123456' ,
// realm : 'sandbox.netsuite.com' ,
//role : 3 ,
rootPath : '/SuiteScripts',
script : 'myuploadfile' ,
deployment : 2
}))
I left out a few parameters but I don't believe they make a difference. At the moment the error I keep getting is "SSS_INVALID_SCRIPTLET_ID - That Suitelet is invalid, disabled, or no longer exists." I have upload the Restlet that came with it to Netsuite as well but the problem persists.
Again, I have looked up the error but I still haven't figured out what the problem is. I tried testing the code within the code I wanted to use and by itself when it didn't work. Any ideas on solving this?
Thanks!

Change your script option to the script id of the Restlet you uploaded to NetSuite.
gulp.src('foo.js')
.pipe(nscabinet({
email : 'foo#bar.baz.com' ,
password : '123456' ,
account : '123456' ,
// realm : 'sandbox.netsuite.com' ,
//role : 3 ,
rootPath : '/SuiteScripts',
script : 1234 ,
deployment : 2
}))

Output console.log(inspect(sendToNetsuite)); It is not defined or not a function. The repo is private here https://github.com/truecloud-com/nsupload -- maybe contact TrueCloud/Netsuite whatever.

Related

Problem After registering a url protocol handler in Node.js

I was successfully able to register a custom protocol using npm i protocol-registry. Here is the code for the same :
ProtocolRegistry.register({
protocol: "mydemoprotocol",
command: `node ${path.join(__dirname, './app_code.js')} $_URL_`,
override: true,
terminal: true,
script: false,
}).then(async () => {
console.log("Registered Successully...");
});
But when I enter mydemoprotocol:// in the browser, I get the following error :
I am trying to load faceapi models in app_code.js. Here is the code for the same :
await faceapi.nets.ssdMobilenetv1.loadFromDisk('/models')
await faceapi.nets.faceLandmark68Net.loadFromDisk("./models"),
await faceapi.nets.faceRecognitionNet.loadFromDisk("./models"))
All the files required to load the model are present in the same directory as app_code.js. Why am I getting error for the path 'C:\WINDOWS\system32\' when I am trying to run the file from D: Drive.
Any help will be grateful. Thanks.

url.pathToFileURL is not a function : how to convert a file path to an URL in node.js?

I want to convert a file path to an URL.
I tried to follow the indications found in the official docs: https://nodejs.org/dist/latest-v16.x/docs/api/url.html#urlpathtofileurlpath
import { pathToFileURL } from 'url'
let filepathurl = pathToFileURL(file.path)
But I get this error:
Uncaught TypeError: (0 , _url.pathToFileURL) is not a function
Or :
import url from 'url'
let filepathurl = url.pathToFileURL(file.path)
Error message:
_url.default.pathToFileURL is not a function
Other info:
node: v16.13.0
O.S. : Ubuntu 20.04 Desktop
What am I doing wrongly? How to solve the problem?
Example of file path:
/home/raphy/Downloads/sample.pdf
At the moment, I solved the problem using https://www.npmjs.com/package/file-url combined with this helpful suggestion for webpack configuration: https://github.com/facebook/create-react-app/pull/11764#issuecomment-1104019653
But I would like to know if and how to correctly use the features of the node.js library

Trouble with file upload using javascript swagger client and react

I have a problem with the source code generated by the Swagger codegen.
I want to upload a file with react. For this I have created a Dropzone and get a path to the file. If I use the generated client as it is in the documentation, it will not work. Unfortunately, the file is not sent. Only the file name. The debug console also does not show that binary data has been sent.
The request is not executed correctly. The file will not be uploaded. The parameter "file" is just the file name, instead of the binary data.
Swagger-codegen version
openapi-generator-cli-3.3.4.jar
Swagger declaration file content
Swagger .yaml:
/orders/upload:
post:
operationId: "orderUploadPart"
summary: "upload a textual or audio part of an order"
tags:
- "orders"
description: "This funktion uploads a textual or audio part of an order to the sense.ai.tion cloud system.
The result is the resource identifier, that must be used in the order request."
consumes:
- multipart/form-data
parameters:
- in: "formData"
name: "file"
type: "file"
required: true
description: "the file to upload"
- in: "formData"
name: "media"
type: "string"
enum:
- "text"
- "wav"
- "mp3"
required: true
description: "the media type of the the upload, can be ***text***, ***wav*** or ***mp3***"
Code:
var apiInstance = new SenseaitionApi.OrdersApi();
var file = "/path/to/file"; // File | the file to upload
var media = "media_example"; // String | the media type of the the upload, can be ***text***, ***wav*** or ***mp3***
var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.orderUploadPart(file, media, callback);
It's like in: https://github.com/swagger-api/swagger-codegen/blob/master/samples/client/petstore/javascript/docs/PetApi.md#uploadFile
Screenshot Chrome DevTools
Command line used for generation
java -jar ${GOPATH}/bin/openapi-generator-cli.jar generate -i service_js_api.yaml -g javascript -o clients/javascript/senseaition-api-js -Dio.swagger.parser.util.RemoteUrl.trustAll=true
I found the mistake. The documentation of generated Javascript code is wrong. For uploading a file (Javascript object) must be passed, not the Path.
This line is wrong:
var file = "/path/to/file"; // File | the file to upload

ModuleParse Failed or Not Found

I am building a web app that allows users to type in phone numbers and send text messages via the Twilio API. I've built the functionality in a file, shown below. If I cd to this file and run node twilioActions.js, the text message gets sent.
var client = require('twilio')(CLIENT_ID, CLIENT_SECRET);
// ideally, I'd like to send the message using this method and call this from other JavaScript files
export const sendMessage = () => {
}
// the following code works when I run 'node twilioActions.js'
client.sendMessage({
to:'...',
from: '...',
body: 'Text message test.'
}, function(err, responseData) {
if (!err) {
console.log(responseData.from); // outputs "+14506667788"
console.log(responseData.body); // outputs "word to your mother."
}
});
However, I want to call the sendMessage method from a different React file. Here is it:
import * as twilioActions from './twilioActions';
class PhoneView extends React.Component{
// other methods are hidden obviously, the one below is called when a button is pressed to send a message.
sendMessage() {
twilioActions.sendMessage();
}
}
When I try to build the project, I get the following errors:
ERROR in ./~/twilio/package.json
Module parse failed:/Users/Felix/Desktop/ECE590/node_modules/twilio/package.json Line 2: Unexpected token :
You may need an appropriate loader to handle this file type.
| {
| "_args": [
| [
| "twilio",
# ./~/twilio/lib/Client.js 5:17-43
ERROR in ./~/request/lib/har.js
Module not found: Error: Cannot resolve module 'fs' in /Users/Felix/Desktop/ECE590/node_modules/request/lib
# ./~/request/lib/har.js 3:9-22
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'net' in /Users/Felix/Desktop/ECE590/node_modules/tunnel-agent
# ./~/tunnel-agent/index.js 3:10-24
ERROR in ./~/tunnel-agent/index.js
Module not found: Error: Cannot resolve module 'tls' in /Users/Felix/Desktop/ECE590/node_modules/tunnel-agent
# ./~/tunnel-agent/index.js 4:10-24
I feel like I am making a simple mistake and perhaps am not using the correct libraries or including the proper references. Could someone point me in the right direction about how to get this to work? Thank you so much!
Twilio developer evangelist here.
The twilio npm module is not built or recommended for use in the front end. The main thing is that you would need to expose your account credentials in the front end code of your site. This is a security risk as it means a malicious attacker could get hold of your credentials and abuse your Twilio account.
I recommend creating a service on your server side that you can call to with an AJAX request in order to perform actions like this.

Execute javascript on mongo command line with Authorization

I have been successfully executing javascripts from the mongo shell
We have now enabled authorization on the mongo database
The permissions have been given and if I login to the shell and execute queries everything is fine
However, I am trying to execute the javascript from command line and I have a problem
I am issuing the command
mongo -u -p -authenticationDatabase admin GetProcessDate.js
I get the error message
MongoDB shell version: 2.6.5
connecting to: test
2014-10-15T06:44:11.451-0700 error: { "$err" : "not authorized for query on bvmaster.ProcessDate", "code" : 13 } at src/mongo/shell/query.js:131
failed to load: GetProcessDate.js
When I disable authorization this javascript executes just fine
mongo GetProcessDate.js
When I enable authorization and login to the shell everything works fine
mongo -u <user>-p <password> -authenticationDatabase admin
The javascript is a very simple one
mongo = new Mongo();
bvmasternew = mongo.getDB( "bvmaster" );
ProcessDateCursor = bvmasternew.ProcessDate.find();
ProcessDateRec = ProcessDateCursor.next();
print( ProcessDateRec.Date);
Any help will be appreciated!!
After a lot of searchs I found the following;
When you are executing a javascript on the mongo command line, it does not matter what parameters you pass on the command line
inside your mongo javascript
you need to call the mongo with proper parameters
mongo = new Mongo( server:port );
admin = mongo.getDB( "admin" );
admin.auth( User, Password );
These lines basically authorizes the user to perform various operations in that mongo instance you have connected using server/port combination

Categories

Resources