posthog-node 3.1.0 → 3.1.2
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/CHANGELOG.md +8 -0
- package/lib/index.cjs.js +33 -26
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.esm.js +33 -26
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +7 -2
- package/package.json +3 -2
- package/src/feature-flags.ts +3 -2
- package/src/posthog-node.ts +1 -0
- package/src/types/rusha.d.ts +23 -0
- package/test/posthog-node.spec.ts +5 -2
- package/tsconfig.json +2 -1
|
@@ -74,6 +74,7 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
74
74
|
private flagCallReported;
|
|
75
75
|
protected _decideResponsePromise?: Promise<PostHogDecideResponse | undefined>;
|
|
76
76
|
protected _sessionExpirationTimeSeconds: number;
|
|
77
|
+
protected sessionProps: PostHogEventProperties;
|
|
77
78
|
constructor(apiKey: string, options?: PosthogCoreOptions);
|
|
78
79
|
protected setupBootstrap(options?: Partial<PosthogCoreOptions>): void;
|
|
79
80
|
private get props();
|
|
@@ -83,15 +84,19 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
83
84
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
84
85
|
reset(propertiesToKeep?: PostHogPersistedProperty[]): void;
|
|
85
86
|
protected getCommonEventProperties(): any;
|
|
86
|
-
|
|
87
|
+
enrichProperties(properties?: PostHogEventProperties): any;
|
|
87
88
|
getSessionId(): string | undefined;
|
|
88
89
|
resetSessionId(): void;
|
|
89
90
|
getAnonymousId(): string;
|
|
90
91
|
getDistinctId(): string;
|
|
92
|
+
unregister(property: string): void;
|
|
91
93
|
register(properties: {
|
|
92
94
|
[key: string]: any;
|
|
93
95
|
}): void;
|
|
94
|
-
|
|
96
|
+
registerForSession(properties: {
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
}): void;
|
|
99
|
+
unregisterForSession(property: string): void;
|
|
95
100
|
/***
|
|
96
101
|
*** TRACKING
|
|
97
102
|
***/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-node",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "PostHog Node.js integration",
|
|
5
5
|
"repository": "PostHog/posthog-node",
|
|
6
6
|
"scripts": {
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"module": "lib/index.esm.js",
|
|
20
20
|
"types": "lib/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"axios": "^0.27.0"
|
|
22
|
+
"axios": "^0.27.0",
|
|
23
|
+
"rusha": "^0.8.14"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@types/node": "^18.0.0",
|
package/src/feature-flags.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createHash } from '
|
|
1
|
+
import { createHash } from 'rusha'
|
|
2
2
|
import { FeatureFlagCondition, FlagProperty, PostHogFeatureFlag, PropertyGroup } from './types'
|
|
3
3
|
import { version } from '../package.json'
|
|
4
4
|
import { JsonType, PostHogFetchOptions, PostHogFetchResponse } from 'posthog-core/src'
|
|
@@ -441,7 +441,8 @@ class FeatureFlagsPoller {
|
|
|
441
441
|
// # uniformly distributed between 0 and 1, so if we want to show this feature to 20% of traffic
|
|
442
442
|
// # we can do _hash(key, distinct_id) < 0.2
|
|
443
443
|
function _hash(key: string, distinctId: string, salt: string = ''): number {
|
|
444
|
-
|
|
444
|
+
// rusha is a fast sha1 implementation in pure javascript
|
|
445
|
+
const sha1Hash = createHash()
|
|
445
446
|
sha1Hash.update(`${key}.${distinctId}${salt}`)
|
|
446
447
|
return parseInt(sha1Hash.digest('hex').slice(0, 15), 16) / LONG_SCALE
|
|
447
448
|
}
|
package/src/posthog-node.ts
CHANGED
|
@@ -207,6 +207,7 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
207
207
|
$feature_flag: key,
|
|
208
208
|
$feature_flag_response: response,
|
|
209
209
|
locally_evaluated: flagWasLocallyEvaluated,
|
|
210
|
+
[`$feature/${key}`]: response,
|
|
210
211
|
},
|
|
211
212
|
groups,
|
|
212
213
|
disableGeoip,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// Adjusted from type definitions for rusha 0.8
|
|
2
|
+
// Project: https://github.com/srijs/rusha#readme
|
|
3
|
+
// Definitions by: Jacopo Scazzosi <https://github.com/jacoscaz>
|
|
4
|
+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
5
|
+
// Minimum TypeScript Version: 4.0
|
|
6
|
+
|
|
7
|
+
/// <reference types="node" />
|
|
8
|
+
|
|
9
|
+
interface Hash {
|
|
10
|
+
update(value: string | number[] | ArrayBuffer | Buffer): Hash
|
|
11
|
+
digest(encoding?: undefined): ArrayBuffer
|
|
12
|
+
digest(encoding: 'hex'): string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface Rusha {
|
|
16
|
+
createHash(): Hash
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare const Rusha: Rusha
|
|
20
|
+
|
|
21
|
+
declare module 'rusha' {
|
|
22
|
+
export = Rusha
|
|
23
|
+
}
|
|
@@ -210,7 +210,6 @@ describe('PostHog Node.js', () => {
|
|
|
210
210
|
host: 'http://example.com',
|
|
211
211
|
disableGeoip: false,
|
|
212
212
|
})
|
|
213
|
-
client.debug()
|
|
214
213
|
client.capture({ distinctId: '123', event: 'test-event', properties: { foo: 'bar' }, groups: { org: 123 } })
|
|
215
214
|
|
|
216
215
|
jest.runOnlyPendingTimers()
|
|
@@ -296,7 +295,7 @@ describe('PostHog Node.js', () => {
|
|
|
296
295
|
flushAt: 1,
|
|
297
296
|
})
|
|
298
297
|
|
|
299
|
-
const logSpy = jest.spyOn(global.console, 'log')
|
|
298
|
+
const logSpy = jest.spyOn(global.console, 'log').mockImplementation(() => {})
|
|
300
299
|
jest.useRealTimers()
|
|
301
300
|
// using debug mode to check console.log output
|
|
302
301
|
// which tells us when the flush is complete
|
|
@@ -556,6 +555,7 @@ describe('PostHog Node.js', () => {
|
|
|
556
555
|
$lib: 'posthog-node',
|
|
557
556
|
$lib_version: '1.2.3',
|
|
558
557
|
locally_evaluated: true,
|
|
558
|
+
'$feature/beta-feature': true,
|
|
559
559
|
}),
|
|
560
560
|
},
|
|
561
561
|
])
|
|
@@ -611,6 +611,7 @@ describe('PostHog Node.js', () => {
|
|
|
611
611
|
properties: expect.objectContaining({
|
|
612
612
|
$feature_flag: 'beta-feature',
|
|
613
613
|
$feature_flag_response: true,
|
|
614
|
+
'$feature/beta-feature': true,
|
|
614
615
|
$lib: 'posthog-node',
|
|
615
616
|
$lib_version: '1.2.3',
|
|
616
617
|
locally_evaluated: true,
|
|
@@ -653,6 +654,7 @@ describe('PostHog Node.js', () => {
|
|
|
653
654
|
$lib: 'posthog-node',
|
|
654
655
|
$lib_version: '1.2.3',
|
|
655
656
|
locally_evaluated: true,
|
|
657
|
+
'$feature/beta-feature': true,
|
|
656
658
|
$groups: { x: 'y' },
|
|
657
659
|
})
|
|
658
660
|
mockedFetch.mockClear()
|
|
@@ -689,6 +691,7 @@ describe('PostHog Node.js', () => {
|
|
|
689
691
|
$lib: 'posthog-node',
|
|
690
692
|
$lib_version: '1.2.3',
|
|
691
693
|
locally_evaluated: false,
|
|
694
|
+
'$feature/decide-flag': 'decide-value',
|
|
692
695
|
$groups: { organization: 'org1' },
|
|
693
696
|
}),
|
|
694
697
|
})
|