Skip to content

Commit 5203f6c

Browse files
authored
feat: Adjust client options to send credentials when needed (#790) Thanks to @colefichter !
* Adjust client options to send credentials when needed * Remove defaults * Try to fix lint issues. * Make credentials optional. Fixes #788
1 parent f786fdd commit 5203f6c

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

packages/cubejs-client-core/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ declare module '@cubejs-client/core' {
2121
* custom headers
2222
*/
2323
headers?: Record<string, string>;
24+
credentials?: 'omit' | 'same-origin' | 'include';
2425
};
2526

2627
export interface ITransport {
@@ -47,6 +48,7 @@ declare module '@cubejs-client/core' {
4748
transport?: ITransport;
4849
headers?: Record<string, string>;
4950
pollInterval?: number;
51+
credentials?: 'omit' | 'same-origin' | 'include';
5052
};
5153

5254
export type LoadMethodOptions = {
@@ -646,7 +648,7 @@ declare module '@cubejs-client/core' {
646648

647649
/**
648650
* Main class for accessing Cube.js API
649-
*
651+
*
650652
* @order 2
651653
*/
652654
export class CubejsApi {

packages/cubejs-client-core/src/HttpTransport.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import fetch from 'cross-fetch';
22
import 'url-search-params-polyfill';
33

44
class HttpTransport {
5-
constructor({ authorization, apiUrl, headers = {} }) {
5+
constructor({ authorization, apiUrl, headers = {}, credentials }) {
66
this.authorization = authorization;
77
this.apiUrl = apiUrl;
88
this.headers = headers;
9+
this.credentials = credentials;
910
}
1011

1112
request(method, { baseRequestId, ...params }) {
@@ -25,7 +26,8 @@ class HttpTransport {
2526
Authorization: this.authorization,
2627
'x-request-id': baseRequestId && `${baseRequestId}-span-${spanCounter++}`,
2728
...this.headers
28-
}
29+
},
30+
credentials: this.credentials
2931
}
3032
);
3133

packages/cubejs-client-core/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ class CubejsApi {
2525
this.apiToken = apiToken;
2626
this.apiUrl = options.apiUrl || API_URL;
2727
this.headers = options.headers || {};
28+
this.credentials = options.credentials;
2829
this.transport = options.transport || new HttpTransport({
2930
authorization: typeof apiToken === 'function' ? undefined : apiToken,
3031
apiUrl: this.apiUrl,
31-
headers: this.headers
32+
headers: this.headers,
33+
credentials: this.credentials
3234
});
3335
this.pollInterval = options.pollInterval || 5;
3436
this.parseDateMeasures = options.parseDateMeasures;

0 commit comments

Comments
 (0)