Skip to content

Commit

Permalink
Merge pull request #66 from HubSpot/fix-track-usage-bug
Browse files Browse the repository at this point in the history
Fix bug with unauthenticated usage tracking requests
  • Loading branch information
camden11 authored Nov 15, 2023
2 parents 1c6144d + 7e54a11 commit ace0cf5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config/config_DEPRECATED.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export function findConfig(directory: string): string | null {
);
}

export function getEnv(nameOrId: string | number): Environment {
export function getEnv(nameOrId?: string | number): Environment {
let env: Environment = ENVIRONMENTS.PROD;
const config = getAndLoadConfigIfNeeded();
const accountId = getAccountId(nameOrId);
Expand Down
2 changes: 1 addition & 1 deletion config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ export function isTrackingAllowed() {
return config_DEPRECATED.isTrackingAllowed();
}

export function getEnv(nameOrId: string | number) {
export function getEnv(nameOrId?: string | number) {
if (CLIConfiguration.isActive()) {
return CLIConfiguration.getEnv(nameOrId);
}
Expand Down
9 changes: 6 additions & 3 deletions lib/trackUsage.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import axios from 'axios';
import { getAxiosConfig } from '../http/getAxiosConfig';
import { debug } from '../utils/logger';
import http from '../http';
import { getAccountConfig, getEnv } from '../config';
Expand All @@ -9,7 +11,7 @@ export async function trackUsage(
eventName: string,
eventClass: string,
meta = {},
accountId: number
accountId?: number
): Promise<void> {
const usageEvent = {
accountId,
Expand Down Expand Up @@ -49,11 +51,12 @@ export async function trackUsage(
}

const env = getEnv(accountId);
debug(`${i18nKey}.sendingEventUnauthenticated`);
http.post<void>(accountId, {
const axiosConfig = getAxiosConfig({
env,
url: path,
data: usageEvent,
resolveWithFullResponse: true,
});
debug(`${i18nKey}.sendingEventUnauthenticated`);
axios({ ...axiosConfig, method: 'post' });
}

0 comments on commit ace0cf5

Please sign in to comment.