Skip to content

Commit a6c367e

Browse files
authored
fix: exports Api and NodeApi for NodeJS (#1037)
Api === NodeApi
1 parent eda8acf commit a6c367e

5 files changed

Lines changed: 33 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const Workfront = require('workfront-api')
2626
/**
2727
* The console.log statement below will output the following:
2828
* {
29-
* NodeApi: [Function: Api],
29+
* Api: [Function: Api],
3030
* ResponseHandler: { success: [Function: success], failure: [Function: failure] }
3131
* }
3232
*/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"typings"
1010
],
1111
"sideEffects": false,
12-
"typings": "typings/Api.d.ts",
12+
"typings": "typings/node.d.ts",
1313
"dependencies": {
1414
"@types/node": "^17.0.8",
1515
"form-data": "^4.0.0",

src/node.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import * as NodeFormData from 'form-data'
1717
import 'isomorphic-fetch'
1818
import {Readable} from 'stream'
19-
import {Api as BaseApi, makeFetchCall} from './Api'
19+
import {Api as BaseApi, makeFetchCall, ResponseHandler} from './Api'
2020

2121
/**
2222
* Starting from version 2.0 API allows users to upload files.
@@ -29,7 +29,7 @@ import {Api as BaseApi, makeFetchCall} from './Api'
2929
* @param {fs.ReadStream} stream A readable stream with file contents
3030
* @param {String} filename Override the filename
3131
*/
32-
export class NodeApi extends BaseApi {
32+
class NodeApi extends BaseApi {
3333
constructor(options) {
3434
super(options)
3535
}
@@ -45,6 +45,10 @@ export class NodeApi extends BaseApi {
4545
}
4646
}
4747

48-
export {ResponseHandler} from './Api'
48+
export {ResponseHandler, NodeApi, NodeApi as Api, makeFetchCall}
4949

50-
export {NodeApi as Api}
50+
export default {
51+
NodeApi,
52+
ResponseHandler,
53+
Api: NodeApi,
54+
}

test/Api.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
*/
1616
import * as should from 'should'
1717

18-
import {NodeApi} from '../src/node'
18+
import {Api} from '../'
1919

2020
describe('Create new instance for API', function () {
2121
it('should have methods', function () {
22-
const api = new NodeApi({url: 'http://localhost'})
22+
const api = new Api({url: 'http://localhost'})
2323
should(api.copy).be.a.Function().and.has.lengthOf(5)
2424
should(api.count).be.a.Function().and.has.lengthOf(2)
2525
should(api.create).be.a.Function().and.has.lengthOf(3)
@@ -41,17 +41,17 @@ describe('Create new instance for API', function () {
4141
})
4242

4343
it('should set correct API path based on passed configuration (version is passed)', function () {
44-
const api = new NodeApi({url: 'http://localhost', version: '2.0'})
44+
const api = new Api({url: 'http://localhost', version: '2.0'})
4545
should(api._httpOptions.path).equal('/attask/api/v2.0')
4646
})
4747

4848
it('should set correct API path based on passed configuration (version is not passed)', function () {
49-
const api = new NodeApi({url: 'http://localhost'})
49+
const api = new Api({url: 'http://localhost'})
5050
should(api._httpOptions.path).equal('/attask/api-internal')
5151
})
5252

5353
it('should set correct API path based on passed configuration (version="asp")', function () {
54-
const api = new NodeApi({url: 'http://localhost', version: 'asp'})
54+
const api = new Api({url: 'http://localhost', version: 'asp'})
5555
should(api._httpOptions.path).equal('/attask/api-asp')
5656
})
5757
})

test/module.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as should from 'should'
2+
import * as cjsModule from '../'
3+
4+
describe('Verify workfront-api cjs exported members', function () {
5+
it('exports cjs required members', function () {
6+
should(cjsModule).properties('Api', 'ResponseHandler', 'makeFetchCall')
7+
})
8+
it('has NodeApi as Api fallback', function () {
9+
should(cjsModule).properties('Api', 'NodeApi')
10+
should(cjsModule.Api).equals(cjsModule.NodeApi)
11+
})
12+
it('exports "default" for backward compatibility', function () {
13+
should(cjsModule).properties('default')
14+
should(cjsModule.default).property('Api', cjsModule.Api)
15+
should(cjsModule.default).property('NodeApi', cjsModule.NodeApi)
16+
should(cjsModule.default).property('ResponseHandler', cjsModule.ResponseHandler)
17+
})
18+
})

0 commit comments

Comments
 (0)