UNPKG

netsuite

Version:

A wrapper library for NetSuite's SuiteTalk SOAP API using NodeJS

61 lines (55 loc) 1.52 kB
'use strict'; const soap = require('soap'); const config = require('./config.json'); class Wrapper { constructor(options) { this.accountId = options.accountId; this.baseUrl = options.baseUrl || config.baseUrl; this.appId = options.appId; this.client = {}; this.password = options.password; this.roleId = options.roleId; this.username = options.username; this.wsdlPath = options.wsdlPath || __dirname + '/' + config.wsdlPath; } init(cb) { soap.createClient(this.wsdlPath, (err, client) => { if(err) { return cb(err); } client.addSoapHeader({ applicationInfo: { applicationId: this.appId }, passport: { email: this.username, password: this.password, account: this.accountId, role: { attributes: { internalId: this.roleId } } } }); client.setEndpoint(this.baseUrl); this.client = client; cb(); }); } getRecord(type, internalId, cb) { const wrappedData = { ':record': { 'attributes': { 'xmlns:listRel': 'urn:relationships_2016_1.lists.webservices.netsuite.com', 'xmlns:platformCore': 'urn:core_2016_1.platform.webservices.netsuite.com', 'xsi:type': 'platformCore:RecordRef', 'type': type, 'internalId': internalId } } }; this.client.get(wrappedData, cb); } } module.exports = Wrapper;