updates documentation and adds typings for axiosConfig (#4405)

This commit is contained in:
Dimitri Mitropoulos 2022-01-25 10:40:31 -06:00 committed by GitHub
parent 4940348dd9
commit 7d3526940e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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 segmentClient = new Analytics(getSegmentWriteKey(), {
// @ts-expect-error -- TSCONVERSION
axiosConfig: {
const axiosConfig: AxiosRequestConfig = {
// This is needed to ensure that we use the NodeJS adapter in the render process
...(global?.require && {
...(global?.require ? {
adapter: global.require('axios/lib/adapters/http'),
}),
},
} : {}),
};
const segmentClient = new Analytics(getSegmentWriteKey(), {
// @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 () => {