@@ -58,6 +58,17 @@ import * as util from './util';
5858
5959let connection = null ;
6060
61+ // Workaround for https://github.com/jsforce/jsforce/issues/1806
62+ const workaroundBrokenTransport = connection => {
63+ const transport = connection . _transport ;
64+ const originalHttpRequest = transport . httpRequest . bind ( transport ) ;
65+ transport . httpRequest = ( req , options ) => {
66+ req . headers = { ...req . headers , connection : 'close' } ;
67+ return originalHttpRequest ( req , options ) ;
68+ } ;
69+ return connection ;
70+ } ;
71+
6172/**
6273 * Creates a connection to Salesforce using Basic Auth or OAuth.
6374 * @function connect
@@ -76,10 +87,14 @@ const connect = async state => {
7687 if ( configuration . access_token ) {
7788 const { instance_url : instanceUrl , access_token : accessToken } =
7889 configuration ;
79- connection = new Connection ( { instanceUrl, accessToken, version } ) ;
90+ connection = workaroundBrokenTransport (
91+ new Connection ( { instanceUrl, accessToken, version } ) ,
92+ ) ;
8093 } else {
8194 const { loginUrl, username, password, securityToken } = configuration ;
82- connection = new Connection ( { loginUrl, version } ) ;
95+ connection = workaroundBrokenTransport (
96+ new Connection ( { loginUrl, version } ) ,
97+ ) ;
8398
8499 // Workaround for https://github.com/jsforce/jsforce/issues/1806
85100 const transport = connection . _transport ;
@@ -108,7 +123,7 @@ const connect = async state => {
108123 }
109124
110125 console . info (
111- `Successfully connected to Salesforce with ${ connection . _sessionType } session type`
126+ `Successfully connected to Salesforce with ${ connection . _sessionType } session type` ,
112127 ) ;
113128 console . info ( `API Version: ${ connection . version } ` ) ;
114129
@@ -137,7 +152,7 @@ export function execute(...operations) {
137152 return commonExecute (
138153 connect ,
139154 util . loadAnyAscii ,
140- ...operations
155+ ...operations ,
141156 ) ( {
142157 ...initialState ,
143158 ...state ,
@@ -176,7 +191,7 @@ export function create(sObjectName, records) {
176191 const [ resolvedSObjectName , resolvedRecords ] = expandReferences (
177192 state ,
178193 sObjectName ,
179- records
194+ records ,
180195 ) ;
181196 util . assertNoNesting ( resolvedRecords ) ;
182197 console . info ( `Creating ${ resolvedSObjectName } ` , resolvedRecords ) ;
@@ -344,7 +359,7 @@ export function query(query, options) {
344359
345360 if ( resolvedQuery . includes ( 'LIMIT' ) || resolvedQuery . includes ( 'limit' ) ) {
346361 console . warn (
347- 'Warning: Query contains a LIMIT clause. We recommend using the `limit` option instead.'
362+ 'Warning: Query contains a LIMIT clause. We recommend using the `limit` option instead.' ,
348363 ) ;
349364 }
350365
@@ -359,7 +374,7 @@ export function query(query, options) {
359374 if ( ! response . done && fetchedRecords === maxRecords ) {
360375 console . warn (
361376 `Warning: The default maximum number of items has been reached (${ maxRecords } ), but more items are available on the server.
362- To download all available items, adjust limit to ${ response . totalSize } or set limit to false`
377+ To download all available items, adjust limit to ${ response . totalSize } or set limit to false` ,
363378 ) ;
364379 }
365380 console . log ( 'Fetched: ' + fetchedRecords ) ;
@@ -406,7 +421,7 @@ export function upsert(sObjectName, externalId, records) {
406421 `Upserting ${ resolvedSObjectName } with externalId` ,
407422 resolvedExternalId ,
408423 ':' ,
409- resolvedRecords
424+ resolvedRecords ,
410425 ) ;
411426
412427 return connection
@@ -450,7 +465,7 @@ export function update(sObjectName, records) {
450465 const [ resolvedSObjectName , resolvedRecords ] = expandReferences (
451466 state ,
452467 sObjectName ,
453- records
468+ records ,
454469 ) ;
455470 util . assertNoNesting ( resolvedRecords ) ;
456471 console . info ( `Updating ${ resolvedSObjectName } ` , resolvedRecords ) ;
@@ -486,11 +501,11 @@ export function retrieve(sObjectName, id) {
486501 const [ resolvedSObjectName , resolvedId ] = expandReferences (
487502 state ,
488503 sObjectName ,
489- id
504+ id ,
490505 ) ;
491506
492507 console . log (
493- `Retrieving data for sObject '${ resolvedSObjectName } ' with Id '${ resolvedId } '`
508+ `Retrieving data for sObject '${ resolvedSObjectName } ' with Id '${ resolvedId } '` ,
494509 ) ;
495510 return connection
496511 . sobject ( resolvedSObjectName )
0 commit comments