posthog-node
Advanced tools
Comparing version 3.1.3 to 3.2.0
@@ -0,1 +1,6 @@ | ||
# 3.2.0 - 2023-12-05 | ||
1. Fixes issues with Axios imports for non-node environments like Cloudflare workers | ||
2. Uses the globally defined `fetch` if available, otherwise imports and uses axios as a polyfill | ||
# 3.1.3 - 2023-10-27 | ||
@@ -2,0 +7,0 @@ |
@@ -120,5 +120,15 @@ import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, PosthogCaptureOptions, JsonType } from './types'; | ||
***/ | ||
setPersonPropertiesForFlags(properties: { | ||
[type: string]: string; | ||
}): this; | ||
resetPersonPropertiesForFlags(): void; | ||
/** @deprecated - Renamed to setPersonPropertiesForFlags */ | ||
personProperties(properties: { | ||
[type: string]: string; | ||
}): this; | ||
setGroupPropertiesForFlags(properties: { | ||
[type: string]: Record<string, string>; | ||
}): this; | ||
resetGroupPropertiesForFlags(): void; | ||
/** @deprecated - Renamed to setGroupPropertiesForFlags */ | ||
groupProperties(properties: { | ||
@@ -125,0 +135,0 @@ [type: string]: Record<string, string>; |
@@ -0,2 +1,12 @@ | ||
/** | ||
* Fetch wrapper | ||
* | ||
* We want to polyfill fetch when not available with axios but use it when it is. | ||
* NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers. | ||
* This is currently solved by using the global fetch if available instead. | ||
* See https://github.com/PostHog/posthog-js-lite/issues/127 for more info | ||
*/ | ||
import { PostHogFetchOptions, PostHogFetchResponse } from 'posthog-core/src'; | ||
export declare const fetch: (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>; | ||
declare type FetchLike = (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse>; | ||
declare const _default: FetchLike; | ||
export default _default; |
{ | ||
"name": "posthog-node", | ||
"version": "3.1.3", | ||
"version": "3.2.0", | ||
"description": "PostHog Node.js integration", | ||
@@ -22,3 +22,3 @@ "repository": "PostHog/posthog-node", | ||
"dependencies": { | ||
"axios": "^1.6.0", | ||
"axios": "^1.6.2", | ||
"rusha": "^0.8.14" | ||
@@ -25,0 +25,0 @@ }, |
@@ -6,3 +6,3 @@ import { createHash } from 'rusha' | ||
import { safeSetTimeout } from 'posthog-core/src/utils' | ||
import { fetch } from './fetch' | ||
import fetch from './fetch' | ||
@@ -9,0 +9,0 @@ // eslint-disable-next-line |
@@ -1,22 +0,43 @@ | ||
import axios from 'axios' | ||
/** | ||
* Fetch wrapper | ||
* | ||
* We want to polyfill fetch when not available with axios but use it when it is. | ||
* NOTE: The current version of Axios has an issue when in non-node environments like Clouflare Workers. | ||
* This is currently solved by using the global fetch if available instead. | ||
* See https://github.com/PostHog/posthog-js-lite/issues/127 for more info | ||
*/ | ||
import { PostHogFetchOptions, PostHogFetchResponse } from 'posthog-core/src' | ||
// NOTE: We use axios as a reliable, well supported request library but follow the Fetch API (roughly) | ||
// So that alternative implementations can be used if desired | ||
export const fetch = async (url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse> => { | ||
const res = await axios.request({ | ||
url, | ||
headers: options.headers, | ||
method: options.method.toLowerCase(), | ||
data: options.body, | ||
signal: options.signal, | ||
// fetch only throws on network errors, not on HTTP errors | ||
validateStatus: () => true, | ||
}) | ||
type FetchLike = (url: string, options: PostHogFetchOptions) => Promise<PostHogFetchResponse> | ||
return { | ||
status: res.status, | ||
text: async () => res.data, | ||
json: async () => res.data, | ||
let _fetch: FetchLike | undefined = | ||
// eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error | ||
// @ts-ignore | ||
typeof fetch !== 'undefined' ? fetch : typeof global.fetch !== 'undefined' ? global.fetch : undefined | ||
if (!_fetch) { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const axios = require('axios') | ||
_fetch = async (url: string, options: PostHogFetchOptions): Promise<PostHogFetchResponse> => { | ||
const res = await axios.request({ | ||
url, | ||
headers: options.headers, | ||
method: options.method.toLowerCase(), | ||
data: options.body, | ||
signal: options.signal, | ||
// fetch only throws on network errors, not on HTTP errors | ||
validateStatus: () => true, | ||
}) | ||
return { | ||
status: res.status, | ||
text: async () => res.data, | ||
json: async () => res.data, | ||
} | ||
} | ||
} | ||
// NOTE: We have to export this as default, even though we prefer named exports as we are relying on detecting "fetch" in the global scope | ||
export default _fetch as FetchLike |
@@ -15,3 +15,3 @@ import { version } from '../package.json' | ||
import { FeatureFlagsPoller } from './feature-flags' | ||
import { fetch } from './fetch' | ||
import fetch from './fetch' | ||
@@ -18,0 +18,0 @@ export type PostHogOptions = PosthogCoreOptions & { |
// import { PostHog } from '../' | ||
import { PostHog as PostHog } from '../src/posthog-node' | ||
jest.mock('../src/fetch') | ||
import { fetch } from '../src/fetch' | ||
import fetch from '../src/fetch' | ||
import { anyDecideCall, anyLocalEvalCall, apiImplementation } from './feature-flags.spec' | ||
@@ -298,3 +298,3 @@ import { waitForPromises, wait } from '../../posthog-core/test/test-utils/test-utils' | ||
const logSpy = jest.spyOn(global.console, 'log').mockImplementation(() => {}) | ||
const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}) | ||
jest.useRealTimers() | ||
@@ -301,0 +301,0 @@ // using debug mode to check console.log output |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
868416
12183
Updatedaxios@^1.6.2