Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DCJ-654: Standardize metrics token usage #2668

Merged
merged 2 commits into from
Sep 10, 2024
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 src/libs/acknowledgements.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const acknowledgementStorageKey = (ackKey) => {

export const hasAccepted = async (...acknowledgements) => {

// check if the acknowledgements are int he cache
// check if the acknowledgements are in the cache
const allAcknowledgementsInStorage = acknowledgements.every(
(ackKey) => Storage.getCurrentUserSettings(acknowledgementStorageKey(ackKey)) || false
);
Expand Down
24 changes: 14 additions & 10 deletions src/libs/ajax/Metrics.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import axios from 'axios';
import { getDefaultProperties } from '@databiosphere/bard-client';
import {getDefaultProperties} from '@databiosphere/bard-client';

import { Storage } from '../storage';
import { getBardApiUrl } from '../ajax';
import {Storage} from '../storage';
import {getBardApiUrl} from '../ajax';
import {Token} from '../config';

export const Metrics = {
captureEvent: (event, details, signal) => captureEventFn(event, details, signal).catch(() => { }),
captureEvent: (event, details, signal) => captureEventFn(event, details, signal).catch(() => {
}),
syncProfile: (signal) => syncProfile(signal),
identify: (anonId, signal) => identify(anonId, signal),
};
Expand Down Expand Up @@ -42,7 +44,7 @@ const captureEventFn = async (event, details = {}, signal) => {
method: 'POST',
url: `${await getBardApiUrl()}/api/event`,
data: body,
headers: isRegistered ? { Authorization: `Bearer ${Storage.getGoogleData()?.accessToken}` } : undefined,
headers: isRegistered ? {Authorization: `Bearer ${Token.getToken()}`} : undefined,
signal,
};

Expand All @@ -59,11 +61,12 @@ const syncProfile = async (signal) => {
const config = {
method: 'POST',
url: `${await getBardApiUrl()}/api/syncProfile`,
headers: { Authorization: `Bearer ${Storage.getGoogleData()?.accessToken}` },
headers: {Authorization: `Bearer ${Token.getToken()}`},
signal,
};

return axios(config).catch(() => { });
return axios(config).catch(() => {
});
};

/**
Expand All @@ -74,17 +77,18 @@ const syncProfile = async (signal) => {
* @returns {Promise} - A Promise that resolves when the user is identified.
*/
const identify = async (anonId, signal) => {
const body = { anonId };
const body = {anonId};

const config = {
method: 'POST',
url: `${await getBardApiUrl()}/api/identify`,
data: body,
headers: { Authorization: `Bearer ${Storage.getGoogleData()?.accessToken}` },
headers: {Authorization: `Bearer ${Token.getToken()}`},
signal,
};

return axios(config).catch(() => { });
return axios(config).catch(() => {
});
};


20 changes: 1 addition & 19 deletions src/libs/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ export const Config = {

getTag: async () => (await getConfig()).tag,

getFeatureFlag: async (featureName) => {
const feature = _.get(await getConfig(), 'features', {});
return _.get(feature, featureName, false);
},

getProject: async () => {
const env = await Config.getEnv();
switch (env) {
Expand Down Expand Up @@ -65,13 +60,6 @@ export const Config = {
},
}),

fileOpts: (token = Token.getToken()) => ({
headers: {
Authorization: `Bearer ${token}`,
Accept: 'application/json',
},
}),

jsonBody: body => ({
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'},
Expand All @@ -82,15 +70,9 @@ export const Config = {
headers: {'Content-Type': 'application/binary'}
}),

fileBody: (token = Token.getToken()) => ({
headers: {
Authorization: `Bearer ${token}`,
Accept: '*/*',
},
}),
};

const Token = {
export const Token = {
getToken: () => {
return Storage.getGoogleData() !== null ?
Storage.getGoogleData().accessToken :
Expand Down
Loading