posthog-node 1.1.3 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,3 +22,5 @@ This library is largely based on the `analytics-node` package.
22
22
  ## Questions?
23
23
 
24
24
  ### [Join our Slack community.](https://posthog.com/slack)
25
+
26
+
package/cli.js CHANGED
File without changes
package/feature-flags.js CHANGED
@@ -5,6 +5,17 @@ const version = require('./package.json').version
5
5
 
6
6
  const LONG_SCALE = 0xfffffffffffffff
7
7
 
8
+ class ClientError extends Error {
9
+ constructor(message, extra) {
10
+ super()
11
+ Error.captureStackTrace(this, this.constructor)
12
+ this.name = 'ClientError'
13
+ this.message = message
14
+ if (extra) {
15
+ this.extra = extra
16
+ }
17
+ }
18
+ }
8
19
 
9
20
  class FeatureFlagsPoller {
10
21
  constructor({ pollingInterval, personalApiKey, projectApiKey, timeout, host, featureFlagCalledCallback }) {
@@ -72,16 +83,24 @@ class FeatureFlagsPoller {
72
83
  }
73
84
  this.poller = setTimeout(() => this._loadFeatureFlags(), this.pollingInterval)
74
85
 
75
- const res = await this._request({ path: 'api/feature_flag', usePersonalApiKey: true })
86
+ try {
87
+ const res = await this._request({ path: 'api/feature_flag', usePersonalApiKey: true })
88
+ if (res && res.status === 401) {
89
+ throw new ClientError(
90
+ `Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview`
91
+ )
92
+ }
93
+
94
+ this.featureFlags = res.data.results.filter(flag => flag.active)
76
95
 
77
- if (res && res.status === 401) {
78
- throw new Error(
79
- `Your personalApiKey is invalid. Are you sure you're not using your Project API key? More information: https://posthog.com/docs/api/overview`
80
- )
96
+ this.loadedSuccessfullyOnce = true
97
+ } catch (err) {
98
+ // if an error that is not an instance of ClientError is thrown
99
+ // we silently ignore the error when reloading feature flags
100
+ if (err instanceof ClientError) {
101
+ throw err
102
+ }
81
103
  }
82
-
83
- this.featureFlags = res.data.results.filter(flag => flag.active)
84
- this.loadedSuccessfullyOnce = true
85
104
  }
86
105
 
87
106
  // sha1('a.b') should equal '69f6642c9d71b463485b4faf4e989dc3fe77a8c6'
@@ -125,6 +144,7 @@ class FeatureFlagsPoller {
125
144
  req.timeout = typeof this.timeout === 'string' ? ms(this.timeout) : this.timeout
126
145
  }
127
146
 
147
+
128
148
  let res
129
149
  try {
130
150
  res = await axios(req)
package/index.d.ts CHANGED
@@ -10,14 +10,9 @@ declare module 'posthog-node' {
10
10
  personalApiKey?: string
11
11
  featureFlagsPollingInterval?: number
12
12
  }
13
-
14
- interface CommonParamsInterfacePropertiesProp {
15
- [key: string]: string | number | Array<any | { [key: string]: string | number }>
16
- }
17
-
18
13
  interface IdentifyMessage {
19
14
  distinctId: string
20
- properties?: CommonParamsInterfacePropertiesProp
15
+ properties?: Record<string | number, any>
21
16
  }
22
17
 
23
18
  interface EventMessage extends IdentifyMessage {
package/index.js CHANGED
@@ -68,7 +68,7 @@ class PostHog {
68
68
  }
69
69
 
70
70
  this.featureFlagsPoller = new FeatureFlagsPoller({
71
- featureFlagsPollingInterval:
71
+ pollingInterval:
72
72
  typeof options.featureFlagsPollingInterval === 'number'
73
73
  ? options.featureFlagsPollingInterval
74
74
  : FIVE_MINUTES,
@@ -164,7 +164,7 @@ class PostHog {
164
164
  })
165
165
  delete apiMessage.alias
166
166
  delete apiMessage.distinctId
167
- apiMessage.distinct_id = null
167
+ apiMessage.distinct_id = message.distinctId || message.distinct_id
168
168
 
169
169
  this.enqueue('alias', apiMessage, callback)
170
170
  return this
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "posthog-node",
3
- "version": "1.1.3",
3
+ "version": "1.1.7",
4
4
  "description": "PostHog Node.js integration",
5
5
  "license": "MIT",
6
6
  "repository": "PostHog/posthog-node",
@@ -42,7 +42,7 @@
42
42
  "funnels"
43
43
  ],
44
44
  "dependencies": {
45
- "axios": "^0.21.1",
45
+ "axios": "0.24.0",
46
46
  "axios-retry": "^3.1.9",
47
47
  "component-type": "^1.2.1",
48
48
  "join-component": "^1.1.0",