-
Notifications
You must be signed in to change notification settings - Fork 1
fix: replace axios with fetch #288
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,44 @@ | ||
import axios from "axios"; | ||
import * as vscode from 'vscode' | ||
import { RUDDERSTACK_KEY } from "./analytics"; | ||
import { KEYS, StateManager } from "./StateManager"; | ||
|
||
type RudderstackEvent = { | ||
event: string, | ||
userId: string, | ||
properties: Record<string, unknown> | ||
} | ||
|
||
const rudderstackClient = axios.create({ | ||
baseURL: 'https://taplyticsncs.dataplane.rudderstack.com/v1/', | ||
headers: { | ||
Authorization: `Basic ${RUDDERSTACK_KEY}`, | ||
'Content-Type': 'application/json' | ||
} | ||
}) | ||
import { RUDDERSTACK_KEY } from './analytics' | ||
import { KEYS, StateManager } from './StateManager' | ||
|
||
export const trackRudderstackEvent = async ( | ||
eventName: string, | ||
orgId?: string, | ||
): Promise<void> => { | ||
const sendMetrics = vscode.workspace.getConfiguration('devcycle-feature-flags').get('sendMetrics') | ||
const sendMetrics = vscode.workspace | ||
.getConfiguration('devcycle-feature-flags') | ||
.get('sendMetrics') | ||
if (sendMetrics) { | ||
jsalaber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const userId = StateManager.getWorkspaceState(KEYS.AUTH0_USER_ID) | ||
if (!userId) { return } | ||
if (!userId) { | ||
return | ||
} | ||
const event = { | ||
jsalaber marked this conversation as resolved.
Show resolved
Hide resolved
|
||
event: eventName, | ||
userId: userId, | ||
properties: { | ||
a0_organization: orgId | ||
} | ||
a0_organization: orgId, | ||
}, | ||
} | ||
await rudderstackClient.post('track', event).catch((error) => { | ||
if (!axios.isAxiosError(error)) { return } | ||
if (error?.response?.status === 401) { | ||
console.error('Failed to send event. Analytics key is invalid.') | ||
} else { | ||
console.error('Failed to send event. Status: ', error?.response?.status) | ||
|
||
try { | ||
const response = await fetch( | ||
'https://taplyticsncs.dataplane.rudderstack.com/v1/track', | ||
{ | ||
method: 'POST', | ||
body: JSON.stringify(event), | ||
headers: { | ||
Authorization: `Basic ${RUDDERSTACK_KEY}`, | ||
'Content-Type': 'application/json', | ||
}, | ||
}, | ||
) | ||
if (!response.ok) { | ||
throw new Error(`HTTP error! Status: ${response.status}`) | ||
} | ||
}) | ||
} catch (e) { | ||
console.error('Failed to send event. Error: ', e) | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import * as vscode from 'vscode' | ||
import * as path from 'path' | ||
import * as fs from 'fs' | ||
import axios from 'axios' | ||
import tar from 'tar' | ||
import * as tar from 'tar' | ||
import * as stream from 'stream' | ||
import { finished } from 'stream/promises' | ||
import { CLI_VERSION } from '../../constants' | ||
import { showDebugOutput } from '../../utils/showDebugOutput' | ||
import { hideBusyMessage, showBusyMessage } from '../../components/statusBarItem' | ||
import { | ||
hideBusyMessage, | ||
showBusyMessage, | ||
} from '../../components/statusBarItem' | ||
|
||
const CLI_ARTIFACTS = 'https://github.com/DevCycleHQ/cli/releases/download' | ||
const SUPPORTED_PLATFORMS = [ | ||
|
@@ -14,7 +18,7 @@ const SUPPORTED_PLATFORMS = [ | |
'linux-arm', | ||
'linux-x64', | ||
'win32-x64', | ||
'win32-x86' | ||
'win32-x86', | ||
] | ||
const OUTPUT_DIR = path.join(path.resolve(__dirname), '..') | ||
const CLI_ROOT = path.join(OUTPUT_DIR, 'dvc') | ||
|
@@ -39,7 +43,9 @@ function isCliLoaded() { | |
const manifestPath = path.join(CLI_ROOT, 'oclif.manifest.json') | ||
return ( | ||
fs.existsSync(CLI_EXEC) && | ||
fs.existsSync(path.join(CLI_ROOT, 'node_modules/@oclif/core/package.json')) && | ||
fs.existsSync( | ||
path.join(CLI_ROOT, 'node_modules/@oclif/core/package.json'), | ||
) && | ||
fs.existsSync(manifestPath) && | ||
JSON.parse(fs.readFileSync(manifestPath, 'utf8')).version === CLI_VERSION | ||
) | ||
|
@@ -51,21 +57,23 @@ function isCliLoaded() { | |
async function downloadCli() { | ||
const sourceUrl = getTarPath() | ||
|
||
showDebugOutput('Attempting to download DevCycle CLI...') | ||
|
||
const writeStream = tar.x({ cwd: OUTPUT_DIR }) | ||
const response = await axios.get(sourceUrl, { | ||
responseType: 'stream', | ||
const response = await fetch(sourceUrl, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Validate the response status code from fetch to ensure the stream is valid. Checking the response status before processing the stream can prevent issues related to unexpected response statuses, such as 404 or 500 errors. |
||
headers: { 'accept-encoding': 'gzip' }, | ||
}) | ||
response.data.pipe(writeStream) | ||
|
||
await new Promise<void>((resolve, reject) => { | ||
writeStream.on('error', (err: Error) => { | ||
showDebugOutput(`Failed to download ${sourceUrl}: ${err.message}`) | ||
reject(err) | ||
}) | ||
|
||
writeStream.on('close', () => resolve()) | ||
}) | ||
try { | ||
await finished( | ||
stream.Readable.fromWeb(response.body as any).pipe(writeStream), | ||
) | ||
} catch (e) { | ||
if (e instanceof Error) { | ||
showDebugOutput(`Failed to download ${sourceUrl}: ${e.message}`) | ||
} | ||
throw e | ||
} | ||
showDebugOutput('DevCycle CLI download complete!') | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.