Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const Workfront = require('workfront-api')
/**
* The console.log statement below will output the following:
* {
* NodeApi: [Function: Api],
* Api: [Function: Api],
* ResponseHandler: { success: [Function: success], failure: [Function: failure] }
* }
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"typings"
],
"sideEffects": false,
"typings": "typings/Api.d.ts",
"typings": "typings/node.d.ts",
"dependencies": {
"@types/node": "^17.0.8",
"form-data": "^4.0.0",
Expand Down
12 changes: 8 additions & 4 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import * as NodeFormData from 'form-data'
import 'isomorphic-fetch'
import {Readable} from 'stream'
import {Api as BaseApi, makeFetchCall} from './Api'
import {Api as BaseApi, makeFetchCall, ResponseHandler} from './Api'

/**
* Starting from version 2.0 API allows users to upload files.
Expand All @@ -29,7 +29,7 @@ import {Api as BaseApi, makeFetchCall} from './Api'
* @param {fs.ReadStream} stream A readable stream with file contents
* @param {String} filename Override the filename
*/
export class NodeApi extends BaseApi {
class NodeApi extends BaseApi {
constructor(options) {
super(options)
}
Expand All @@ -45,6 +45,10 @@ export class NodeApi extends BaseApi {
}
}

export {ResponseHandler} from './Api'
export {ResponseHandler, NodeApi, NodeApi as Api, makeFetchCall}

export {NodeApi as Api}
export default {
NodeApi,
ResponseHandler,
Api: NodeApi,
}
10 changes: 5 additions & 5 deletions test/Api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
import * as should from 'should'

import {NodeApi} from '../src/node'
import {Api} from '../'

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

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

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

it('should set correct API path based on passed configuration (version="asp")', function () {
const api = new NodeApi({url: 'http://localhost', version: 'asp'})
const api = new Api({url: 'http://localhost', version: 'asp'})
should(api._httpOptions.path).equal('/attask/api-asp')
})
})
18 changes: 18 additions & 0 deletions test/module.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as should from 'should'
import * as cjsModule from '../'

describe('Verify workfront-api cjs exported members', function () {
it('exports cjs required members', function () {
should(cjsModule).properties('Api', 'ResponseHandler', 'makeFetchCall')
})
it('has NodeApi as Api fallback', function () {
should(cjsModule).properties('Api', 'NodeApi')
should(cjsModule.Api).equals(cjsModule.NodeApi)
})
it('exports "default" for backward compatibility', function () {
should(cjsModule).properties('default')
should(cjsModule.default).property('Api', cjsModule.Api)
should(cjsModule.default).property('NodeApi', cjsModule.NodeApi)
should(cjsModule.default).property('ResponseHandler', cjsModule.ResponseHandler)
})
})