From 7d3526940e31bf63b9c62e03a7873737b7adde05 Mon Sep 17 00:00:00 2001 From: Dimitri Mitropoulos Date: Tue, 25 Jan 2022 10:40:31 -0600 Subject: [PATCH] updates documentation and adds typings for axiosConfig (#4405) --- packages/insomnia-app/app/common/analytics.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/insomnia-app/app/common/analytics.ts b/packages/insomnia-app/app/common/analytics.ts index f9ca95dc5..740e868e1 100644 --- a/packages/insomnia-app/app/common/analytics.ts +++ b/packages/insomnia-app/app/common/analytics.ts @@ -1,4 +1,5 @@ import Analytics from 'analytics-node'; +import { AxiosRequestConfig } from 'axios'; import * as uuid from 'uuid'; import { getAccountId } from '../account/session'; @@ -12,14 +13,18 @@ import { getSegmentWriteKey, } from './constants'; +const axiosConfig: AxiosRequestConfig = { + // This is needed to ensure that we use the NodeJS adapter in the render process + ...(global?.require ? { + adapter: global.require('axios/lib/adapters/http'), + } : {}), +}; + const segmentClient = new Analytics(getSegmentWriteKey(), { - // @ts-expect-error -- TSCONVERSION - axiosConfig: { - // This is needed to ensure that we use the NodeJS adapter in the render process - ...(global?.require && { - adapter: global.require('axios/lib/adapters/http'), - }), - }, + // @ts-expect-error this is missing from the analytics-node types (and docs) but is present in the source code + // https://github.com/segmentio/analytics-node/blob/0a6aa0d9d865b56f799f9d014b4d7b98ae5d2f2e/index.js#L28 + // as for the types: since (as of @types/analytics-node v3.1.7) this is hardcoded into a class constructor, it makes it hard to fix with module augmentation + axiosConfig, }); const getDeviceId = async () => {