Skip to content

Commit a1b13db

Browse files
Updated server to tableauServer as it was always set to heroku
1 parent fd3ab4a commit a1b13db

File tree

12 files changed

+43
-45
lines changed

12 files changed

+43
-45
lines changed

src/client/components/analytics/EmbeddedDashboard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import styles from './EmbeddedDashboard.module.css';
33
import { TableauViz } from '@tableau/embedding-api-react';
44
import { ProductInfo } from '../productCatalog/ProductCatalog';
55
import { useAuth } from '../auth/useAuth';
6-
import { server, site } from "../../constants/Constants";
6+
import { tableauServer, site } from "../../constants/Constants";
77
import { useAppContext } from '../../App';
88

99
const EmbeddedDashboard: React.FC<{
@@ -35,7 +35,7 @@ const EmbeddedDashboard: React.FC<{
3535
<div className={styles.root}>
3636
<div className={styles.viz}>
3737
<TableauViz
38-
src={`https://${server}/t/${site}/views/eBikeSalesAnalysis/${sheet}`}
38+
src={`https://${tableauServer}/t/${site}/views/eBikeSalesAnalysis/${sheet}`}
3939
token={jwt}
4040
height={`${height}px`}
4141
width={`${width}px`}

src/client/components/analytics/WebAuthoring.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
22
import styles from './WebAuthoring.module.css';
33
import { useAuth } from '../auth/useAuth';
44
import { TableauAuthoringViz } from '@tableau/embedding-api-react';
5-
import { server, site } from "../../constants/Constants";
5+
import { tableauServer, site } from "../../constants/Constants";
66

77
function WebAuthoring() {
88

@@ -22,7 +22,7 @@ function WebAuthoring() {
2222
return (
2323
<div className={styles.root}>
2424
<TableauAuthoringViz
25-
src={`https://${server}/t/${site}/authoringNewWorkbook/${crypto.randomUUID()}/eBikesInventoryandSales`}
25+
src={`https://${tableauServer}/t/${site}/authoringNewWorkbook/${crypto.randomUUID()}/eBikesInventoryandSales`}
2626
token={jwt}
2727
hideCloseButton={true}
2828
/>

src/client/components/analytics/usePulseAPI.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAuth } from "../auth/useAuth";
2-
import { appServer, server, site, subscriber } from "../../constants/Constants";
2+
import { appServer, tableauServer, site, subscriber } from "../../constants/Constants";
33

44
interface MetricDefinition {
55
metric_id: string,
@@ -32,8 +32,8 @@ export function usePulseApi() {
3232
'Content-Type': 'application/json',
3333
Accept: 'application/json',
3434
jwt: await getJwtFromServer(),
35-
server: server,
36-
site: site,
35+
tableauServer,
36+
site,
3737
} as HeadersInit;
3838

3939
}
@@ -168,7 +168,7 @@ export function usePulseApi() {
168168
metric_id: definition.metric_id,
169169
definition_id: definition.definition_id,
170170
name: definition_response.metadata.name,
171-
url: `https://${server}/pulse/site/${site}/metrics/${definition.metric_id}`,
171+
url: `https://${tableauServer}/pulse/site/${site}/metrics/${definition.metric_id}`,
172172
metric_specification: definition.metric_specification,
173173
definition_specification: definition_response.specification,
174174
extension_options: definition_response.extension_options,

src/client/components/header/NotificationBell.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import NotificationWindow from './NotificationWindow';
55
import { NotificationItem } from './NotificationWindow';
66
import { Query } from '../../../server/hbi'
77
import { useAuth } from '../auth/useAuth';
8-
import { server, site, datasourceLuid, appServer } from "../../constants/Constants";
8+
import { tableauServer, site, datasourceLuid, appServer } from "../../constants/Constants";
99

1010
// Our HBI Query to get return percentages
1111
const query: Query = {
@@ -84,9 +84,9 @@ const NotificationBell: React.FC = () => {
8484
body: JSON.stringify(query),
8585
headers: {
8686
'Content-Type': 'application/json',
87-
server: server,
88-
site: site,
89-
jwt: jwt
87+
tableauServer,
88+
site,
89+
jwt
9090
}
9191
}
9292

src/client/components/productCatalog/useProductSales.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Query } from '../../../server/hbi'
22
import { useAuth } from '../auth/useAuth';
3-
import { server, site, datasourceLuid, appServer } from "../../constants/Constants";
3+
import { tableauServer, site, datasourceLuid, appServer } from "../../constants/Constants";
44
import { useEffect, useState } from 'react';
55
import { useParams } from 'react-router-dom';
66
import { users } from '../../../db/users';
@@ -121,9 +121,9 @@ export function useProductSales() {
121121
body: JSON.stringify(query),
122122
headers: {
123123
'Content-Type': 'application/json',
124-
server: server,
125-
site: site,
126-
jwt: jwt
124+
tableauServer,
125+
site,
126+
jwt
127127
},
128128
};
129129

src/client/constants/Constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const server = import.meta.env.VITE_SERVER!;
1+
export const tableauServer = import.meta.env.VITE_SERVER!;
22
export const site = import.meta.env.VITE_SITE!;
33
export const subscriber = import.meta.env.VITE_SUBSCRIBER!;
44
export const datasourceLuid = import.meta.env.VITE_DATASOURCE_LUID!;

src/server/get.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Err, Ok, Result } from 'ts-results';
44
import { signinAsync } from './signin';
55

66
export type RequestData = {
7-
server: string;
7+
tableauServer: string;
88
site: string;
99
apiVersion: string;
1010
apiPath: string;
@@ -20,11 +20,10 @@ export async function get(request: ExpressRequest, response: ExpressResponse) {
2020
return;
2121
}
2222

23-
const { server, site, apiVersion, apiPath, query, jwt } = requestResult.val;
24-
response.send({ error: `debug info: server = '${server}'` });
23+
const { tableauServer, site, apiVersion, apiPath, query, jwt } = requestResult.val;
2524
let token = '';
2625
if (jwt) {
27-
const signinResult = await signinAsync({ server, apiVersion, site, jwt })
26+
const signinResult = await signinAsync({ tableauServer, apiVersion, site, jwt })
2827
if (signinResult.err) {
2928
response.status(400).send(signinResult.val);
3029
return;
@@ -42,7 +41,7 @@ export async function get(request: ExpressRequest, response: ExpressResponse) {
4241
headers['X-Tableau-Auth'] = token;
4342
}
4443

45-
const fetchResponse = await fetch(`https://${server}/api/${apiVersion}/${apiPath}?${query}`, {
44+
const fetchResponse = await fetch(`https://${tableauServer}/api/${apiVersion}/${apiPath}?${query}`, {
4645
method: 'GET',
4746
headers,
4847
});
@@ -66,20 +65,20 @@ export async function get(request: ExpressRequest, response: ExpressResponse) {
6665
function validateRequest(request: ExpressRequest): Result<RequestData, void> {
6766
const params = request.params;
6867

69-
const server = request.header('server') ?? '';
68+
const tableauServer = request.header('tableauServer') ?? '';
7069
const site = request.header('site') ?? '';
7170
const jwt = request.header('jwt') ?? '';
7271

7372
const apiVersion = `${params.apiVersion || ''}`;
7473
const apiPath = `${params.apiPath || ''}${params[0] || ''}`;
7574
const query = `${request.query.query || ''}`;
76-
if (!server || !apiVersion || !apiPath) {
75+
if (!tableauServer || !apiVersion || !apiPath) {
7776
return Err.EMPTY;
7877
}
7978

8079
if (jwt && !site) {
8180
return Err.EMPTY;
8281
}
8382

84-
return new Ok({ server, apiVersion, site, apiPath, query, jwt });
83+
return new Ok({ tableauServer, apiVersion, site, apiPath, query, jwt });
8584
}

src/server/getJwt.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import hmacSHA256 from 'crypto-js/hmac-sha256';
66
import WordArray from 'crypto-js/lib-typedarrays';
77
import { v4 as uuidv4 } from 'uuid';
88
import { User, users } from '../db/users';
9-
import { clientId, secretId, secretValue, username } from './Constants';
109

1110
export type RequestData = {
12-
server: string;
11+
tableauServer: string;
1312
site: string;
1413
apiVersion: string;
1514
apiPath: string;
@@ -73,15 +72,15 @@ export function createJwt(user: User, license: string) {
7372
const header = {
7473
alg: 'HS256',
7574
typ: 'JWT',
76-
kid: secretId,
77-
iss: clientId,
75+
kid: process.env.VITE_SECRET_ID,
76+
iss: process.env.VITE_CLIENT_ID,
7877
};
7978

8079
const data = {
8180
jti: uuidv4(),
82-
iss: clientId,
81+
iss: process.env.VITE_CLIENT_ID,
8382
aud: 'tableau',
84-
sub: username,
83+
sub: process.env.VITE_USERNAME,
8584
scp: scopes,
8685
iat: Math.floor(Date.now() / 1000) - 5,
8786
exp: Math.floor(Date.now() / 1000) + 10 * 60,
@@ -93,7 +92,7 @@ export function createJwt(user: User, license: string) {
9392
const encodedData = base64url(Utf8.parse(JSON.stringify(data)));
9493

9594
const token = `${encodedHeader}.${encodedData}`;
96-
const signature = base64url(hmacSHA256(token, secretValue));
95+
const signature = base64url(hmacSHA256(token, process.env.VITE_SECRET_VALUE!));
9796

9897
return `${token}.${signature}`;
9998
}

src/server/hbi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'node-fetch';
2-
import { server } from "../client/constants/Constants";
2+
import { tableauServer } from "../client/constants/Constants";
33

44
// Define interfaces for your query structure
55
interface QueryColumn {
@@ -53,7 +53,7 @@ export async function callHBI(token: string, query: Query) {
5353
'X-Tableau-Auth': token,
5454
}
5555
}
56-
const response = await fetch(`https://${server}/api/v1/vizql-data-service/query-datasource`, post);
56+
const response = await fetch(`https://${tableauServer}/api/v1/vizql-data-service/query-datasource`, post);
5757
if (response.ok) {
5858
const jsonResponse = await response.json() as QueryOutput;
5959
return jsonResponse;

src/server/post.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { signinAsync } from './signin';
55
import { callHBI } from './hbi';
66

77
export type RequestData = {
8-
server: string;
8+
tableauServer: string;
99
site: string;
1010
apiVersion: string;
1111
apiPath: string;
@@ -21,10 +21,10 @@ export async function post(request: ExpressRequest, response: ExpressResponse) {
2121
return;
2222
}
2323

24-
const { server, site, apiVersion, apiPath, body, jwt } = requestResult.val;
24+
const { tableauServer, site, apiVersion, apiPath, body, jwt } = requestResult.val;
2525
let token = '';
2626
if (jwt) {
27-
const signinResult = await signinAsync({ server, apiVersion, site, jwt })
27+
const signinResult = await signinAsync({ tableauServer, apiVersion, site, jwt })
2828
if (signinResult.err) {
2929
response.status(400).send(signinResult.val);
3030
return;
@@ -65,7 +65,7 @@ export async function post(request: ExpressRequest, response: ExpressResponse) {
6565
}
6666
}
6767

68-
const fetchResponse = await fetch(`https://${server}/api/${apiVersion}/${apiPath}`, init);
68+
const fetchResponse = await fetch(`https://${tableauServer}/api/${apiVersion}/${apiPath}`, init);
6969

7070
const raw = await fetchResponse.text();
7171
if (!raw) {
@@ -86,7 +86,7 @@ export async function post(request: ExpressRequest, response: ExpressResponse) {
8686
function validateRequest(request: ExpressRequest): Result<RequestData, void> {
8787
const params = request.params;
8888

89-
const server = request.header('server') ?? '';
89+
const tableauServer = request.header('tableauServer') ?? '';
9090
const site = request.header('site') ?? '';
9191
const jwt = request.header('jwt') ?? '';
9292

@@ -95,13 +95,13 @@ function validateRequest(request: ExpressRequest): Result<RequestData, void> {
9595

9696
const bodyStr = `${JSON.stringify(request.body) || ''}`;
9797
const body = bodyStr === '{}' ? '' : bodyStr;
98-
if (!server || !apiVersion || !apiPath) {
98+
if (!tableauServer || !apiVersion || !apiPath) {
9999
return Err.EMPTY;
100100
}
101101

102102
if (jwt && !site) {
103103
return Err.EMPTY;
104104
}
105105

106-
return new Ok({ server, apiVersion, site, apiPath, body, jwt });
106+
return new Ok({ tableauServer, apiVersion, site, apiPath, body, jwt });
107107
}

0 commit comments

Comments
 (0)