Skip to content

Commit

Permalink
feat: Adjust client options to send credentials when needed (#790) Th…
Browse files Browse the repository at this point in the history
…anks to @colefichter !

* Adjust client options to send credentials when needed

* Remove defaults

* Try to fix lint issues.

* Make credentials optional.

Fixes #788
  • Loading branch information
colefichter authored Jul 4, 2020
1 parent f786fdd commit 5203f6c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion packages/cubejs-client-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ declare module '@cubejs-client/core' {
* custom headers
*/
headers?: Record<string, string>;
credentials?: 'omit' | 'same-origin' | 'include';
};

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

export type LoadMethodOptions = {
Expand Down Expand Up @@ -646,7 +648,7 @@ declare module '@cubejs-client/core' {

/**
* Main class for accessing Cube.js API
*
*
* @order 2
*/
export class CubejsApi {
Expand Down
6 changes: 4 additions & 2 deletions packages/cubejs-client-core/src/HttpTransport.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import fetch from 'cross-fetch';
import 'url-search-params-polyfill';

class HttpTransport {
constructor({ authorization, apiUrl, headers = {} }) {
constructor({ authorization, apiUrl, headers = {}, credentials }) {
this.authorization = authorization;
this.apiUrl = apiUrl;
this.headers = headers;
this.credentials = credentials;
}

request(method, { baseRequestId, ...params }) {
Expand All @@ -25,7 +26,8 @@ class HttpTransport {
Authorization: this.authorization,
'x-request-id': baseRequestId && `${baseRequestId}-span-${spanCounter++}`,
...this.headers
}
},
credentials: this.credentials
}
);

Expand Down
4 changes: 3 additions & 1 deletion packages/cubejs-client-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ class CubejsApi {
this.apiToken = apiToken;
this.apiUrl = options.apiUrl || API_URL;
this.headers = options.headers || {};
this.credentials = options.credentials;
this.transport = options.transport || new HttpTransport({
authorization: typeof apiToken === 'function' ? undefined : apiToken,
apiUrl: this.apiUrl,
headers: this.headers
headers: this.headers,
credentials: this.credentials
});
this.pollInterval = options.pollInterval || 5;
this.parseDateMeasures = options.parseDateMeasures;
Expand Down

0 comments on commit 5203f6c

Please sign in to comment.