I want to understand one simple thing, which javas...
# suitescript
t
I want to understand one simple thing, which javascript libraries can be used in suiteScript. Like what’s the dependency client side/ server side?
b
i wouldnt describe it as simple, but the primary requirement for a library to work in suitescript is that it must not use any global or modules specific to the browsers or node
for example, pdf-to-base64.js uses fetch for browsers
and uses the fs module for node
that drastically reduces the chances of this library working in suitescript
t
Ohh, got it. I think need to work/learn more on this. In the meantime, do you know any method or any other library that I can use to convert PDF to base 64 inside of suitescript. I have an API that accepts base64 encoded PDFs.
b
occasionally you might get away with using more minor node modules like path. bundlers like browserify or webpack have equivalents that they can include in their bundles
your question is honestly a little on the strange side
pdf files in suitescript are represented as base64 already
t
Yeah, you said this other day as well.
I saved the base64 image directly and it worked that day.
Do you mean
Copy code
fileObj.getContents();
for a PDF file will return me a base64 encoded string.
Let me try
Yeah, makes sense @battk. It does give me base64 encoded string.
Thanks for the help man.
@battk Can I get the the equivalent of this
CryptoJS.SHA256(accessKeyStr).*toString*(CryptoJS.enc.HEX);
without using CryptoJs in SS. I can see there is
Copy code
var hashObj = crypto.createHash({
    algorithm: crypto.HashAlg.SHA256
});
but it does not accept any string, Do I need to this further?
Copy code
hasObj.update({
    input: inputString,
inputEncoding: encode.Encoding.HEX
});
Will they be equivalent then?
b
you will end up using all methods related to hashes
t
Do you mean this?
Copy code
var finalHash = crypto.createHash({
    algorithm: crypto.HashAlg.SHA256
}).update({
    input: inputString
}).digest({outputEncoding: encode.Encoding.HEX})
Let me try this , will compare both then.