-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added posthog feature flags instead of split
- Loading branch information
Showing
18 changed files
with
88 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
/** | ||
* This file contains the list of feature flags that are used in the application. | ||
* Please keep this file in sync with the feature flags in the Split.io dashboard. | ||
* Please keep this file in sync with the feature flags in the posthog.com dashboard. | ||
* Also keep them sorted alphabetically. | ||
* | ||
* @see {@link https://app.split.io/} | ||
* @see {@link https://posthog.com/docs/feature-flags/manual} | ||
*/ | ||
export enum Features { | ||
AUTH = 'auth_enabled', | ||
HELLO = 'hello_split' | ||
AUTH = 'auth', | ||
HELLO = 'hello' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
import { posthog } from '~/posthog.server'; | ||
import { getVisitorIdFromRequest } from '~/session.server'; | ||
import splitClient from '~/split.server'; | ||
import type { Features } from '~/features'; | ||
|
||
/** | ||
* @name hasFeature | ||
* @description | ||
*/ | ||
export const hasFeature = async (request: Request, feature: Features): Promise<boolean> => { | ||
await splitClient.ready(); | ||
const visitorId = await getVisitorIdFromRequest(request); | ||
const serverTreatment = splitClient.getTreatment(visitorId, feature); | ||
|
||
return serverTreatment === 'on'; | ||
const isEnabled = await posthog.isFeatureEnabled(feature, visitorId); | ||
return !!isEnabled; | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { PostHog } from 'posthog-node'; | ||
import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
|
||
vi.mock('posthog-node', () => ({ | ||
PostHog: vi.fn() | ||
})); | ||
|
||
describe('The PostHog Server', () => { | ||
beforeEach(() => { | ||
vi.resetAllMocks(); | ||
}); | ||
|
||
it('should initialise the posthog server', async () => { | ||
vi.stubEnv('POSTHOG_TOKEN', 'test-token'); | ||
vi.stubEnv('POSTHOG_API', 'test-api'); | ||
const processSpy = vi.spyOn(process, 'on'); | ||
const shutdownStub = vi.fn(); | ||
const expected = { | ||
shutdownAsync: shutdownStub | ||
} as never; | ||
|
||
vi.mocked(PostHog).mockImplementation(() => expected); | ||
|
||
const { posthog } = await import('~/posthog.server'); | ||
expect(PostHog).toHaveBeenCalledWith('test-token', { host: 'test-api' }); | ||
|
||
const exitCallback = processSpy.mock.calls[0][1]; | ||
await exitCallback(); | ||
|
||
expect(shutdownStub).toHaveBeenCalled(); | ||
|
||
expect(posthog).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { PostHog } from 'posthog-node'; | ||
|
||
export const posthog = new PostHog( | ||
process.env.POSTHOG_TOKEN, | ||
{ | ||
host: process.env.POSTHOG_API | ||
} | ||
); | ||
|
||
process.on('exit', async () => { | ||
await posthog.shutdownAsync(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters