Skip to content
Open
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 .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22.13.0
24.11.1
1 change: 1 addition & 0 deletions dist/ApiConfig.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export type ApiConfig = {
apiKey?: string;
auth?: AxiosBasicCredentials;
withCredentials?: boolean;
withXSRFToken?: boolean | undefined;
};
export default ApiConfig;
17 changes: 9 additions & 8 deletions dist/bitbar-cloud-api-client.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/bitbar-cloud-api-client.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions dist/bitbar-cloud-api-client.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/bitbar-cloud-api-client.min.js.map

Large diffs are not rendered by default.

38 changes: 28 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bitbar/cloud-api-client",
"version": "1.5.16",
"version": "1.6.0",
"description": "Bitbar Cloud API Client for JavaScript",
"main": "dist/bitbar-cloud-api-client.min.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -69,14 +69,14 @@
"ts-node": "^10.7.0",
"tslib": "^2.3.1",
"typedoc": "0.27.6",
"typedoc-github-theme": "^0.2.1",
"typescript": "^5.7.2",
"typescript-eslint": "^8.3.0",
"typedoc-github-theme": "^0.2.1"
"typescript-eslint": "^8.3.0"
},
"dependencies": {
"@babel/runtime": "^7.28.2",
"@bitbar/finka": "^2.4.4",
"axios": "^0.26.1",
"axios": "^1.13.2",
"form-data": "^4.0.4",
"node-abort-controller": "^3.1.1",
"qs": "6.10.3"
Expand Down
10 changes: 8 additions & 2 deletions src/API.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import {AxiosInstance} from 'axios';

// this version of axios has some issue paired with rollup and is not handling default import correctly
// as a workaround we need to use require instead of import until migrating to newer axios version
// as a workaround we need to use require instead of import until migrating to newer axios version.
//
// Axios has been updated to version 1.13.2. Due to issues related to how axios exports are handled between CommonJS and ES Module
// as a workaround we need to use require instead of import in case we want to support both CJS and ESM.
// For CommonJS output in the consumer project (f.ex cloud-frontend), the workaround may still be needed. For ESM, the default import should work.
const axios = require('axios').default;
// @ts-ignore
import {version} from '../package.json';
Expand Down Expand Up @@ -42,7 +47,6 @@ if (globalThis.isNodeJs) {
// Disable max content length
axios.defaults.maxContentLength = 1073741824; // 1GB


/**
* API
* Root for other API resources
Expand Down Expand Up @@ -91,6 +95,8 @@ export class API {
};
}

// With XSRFToken
this.axiosConfig.withXSRFToken = true;
// With credentials
this.axiosConfig.withCredentials = config.withCredentials == null ? false : config.withCredentials;

Expand Down
7 changes: 7 additions & 0 deletions src/ApiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export type ApiConfig = {
*
*/
withCredentials?: boolean;


/**
* With credentials? `undefined` (default) - set XSRF header only for the same origin requests
*
*/
withXSRFToken?: boolean | undefined;
}

export default ApiConfig;
17 changes: 7 additions & 10 deletions src/api/APIEntity.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,10 @@ describe('APIEntity', () => {
});

describe('@formData', () => {
it('should set data and content header in existing configuration', () => {
const call = service.formData({
test: 'me',
properly: 1
});
expect((<any>service).requestConfig.data.test).toEqual('me');
expect((<any>service).requestConfig.data.properly).toEqual(1);
expect((<any>service).requestConfig.headers['Content-Type']).toEqual('multipart/form-data');
expect(call).toEqual(service);
it('should set data in requestConfig', () => {
const data = {foo: 'bar'};
service.formData(data);
expect((<any>service).requestConfig.data).toEqual(data);
});
});

Expand Down Expand Up @@ -304,7 +299,9 @@ describe('APIEntity', () => {
params: {
test: 'me'
},
paramsSerializer: (<any>service).paramsSerializer,
paramsSerializer: {
indexes: false,
},
signal: (<any>service).abortController.signal
});
});
Expand Down
12 changes: 5 additions & 7 deletions src/api/APIEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ export class APIEntity<RESPONSE = any, QUERY_PARAMS extends QueryParams | void =
* Set form data
*/
formData(data: DATA): this {
this.headers({
'Content-Type': 'multipart/form-data'
}).data(data);
this.data(data);
return this;
}

Expand All @@ -211,20 +209,20 @@ export class APIEntity<RESPONSE = any, QUERY_PARAMS extends QueryParams | void =
requestConfig.headers = {};
}

// Set default Content-Type
if (requestConfig.headers['Content-Type'] == null) {
if (!(requestConfig.method === 'POST' && requestConfig.data instanceof FormData) &&
requestConfig.headers['Content-Type'] == null) {
requestConfig.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
}

// Convert data if needed
if (requestConfig.method === 'POST' &&
(<string>requestConfig.headers['Content-Type']).startsWith('application/x-www-form-urlencoded') &&
(<string>requestConfig.headers['Content-Type'])?.startsWith('application/x-www-form-urlencoded') &&
requestConfig.data != null) {
requestConfig.data = this.paramsSerializer(requestConfig.data);
}

if (requestConfig.params) {
requestConfig.paramsSerializer = this.paramsSerializer;
requestConfig.paramsSerializer = {indexes: false};
}

// Send request
Expand Down