@eightyfourthousand/lib-instr 2026.4.0 → 2026.4.1

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.
Files changed (42) hide show
  1. package/index.js +5 -0
  2. package/index.js.map +1 -0
  3. package/lib/browser-client.d.ts +1 -0
  4. package/lib/browser-client.js +19 -0
  5. package/lib/browser-client.js.map +1 -0
  6. package/lib/feature-flags.d.ts +27 -0
  7. package/lib/feature-flags.js +52 -0
  8. package/lib/feature-flags.js.map +1 -0
  9. package/lib/instr-provider.d.ts +4 -0
  10. package/lib/instr-provider.js +7 -0
  11. package/lib/instr-provider.js.map +1 -0
  12. package/lib/server-client.d.ts +2 -0
  13. package/lib/server-client.js +20 -0
  14. package/lib/server-client.js.map +1 -0
  15. package/lib/static-features.d.ts +2 -0
  16. package/lib/static-features.js +15 -0
  17. package/lib/static-features.js.map +1 -0
  18. package/lib/use-instr.d.ts +1 -0
  19. package/{src/lib/use-instr.ts → lib/use-instr.js} +1 -1
  20. package/lib/use-instr.js.map +1 -0
  21. package/package.json +29 -2
  22. package/ssr.js +2 -0
  23. package/ssr.js.map +1 -0
  24. package/static.js +2 -0
  25. package/static.js.map +1 -0
  26. package/.babelrc +0 -12
  27. package/.eslintrc.json +0 -18
  28. package/README.md +0 -9
  29. package/jest.config.ts +0 -10
  30. package/postcss.config.mjs +0 -9
  31. package/project.json +0 -24
  32. package/src/lib/browser-client.ts +0 -22
  33. package/src/lib/feature-flags.tsx +0 -91
  34. package/src/lib/instr-provider.tsx +0 -7
  35. package/src/lib/server-client.ts +0 -24
  36. package/src/lib/static-features.ts +0 -21
  37. package/tsconfig.json +0 -20
  38. package/tsconfig.lib.json +0 -28
  39. package/tsconfig.spec.json +0 -22
  40. /package/{src/index.ts → index.d.ts} +0 -0
  41. /package/{src/ssr.ts → ssr.d.ts} +0 -0
  42. /package/{src/static.ts → static.d.ts} +0 -0
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './lib/browser-client';
2
+ export * from './lib/feature-flags';
3
+ export * from './lib/instr-provider';
4
+ export * from './lib/use-instr';
5
+ //# sourceMappingURL=index.js.map
package/index.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../libs/lib-instr/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const initializeInstrumentation: () => void;
@@ -0,0 +1,19 @@
1
+ import posthog from 'posthog-js';
2
+ export const initializeInstrumentation = () => {
3
+ const POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY;
4
+ const POSTHOG_HOST = process.env.NEXT_PUBLIC_POSTHOG_HOST;
5
+ if (!POSTHOG_KEY) {
6
+ console.warn('Missing NEXT_PUBLIC_POSTHOG_KEY environment variable');
7
+ }
8
+ if (!POSTHOG_HOST) {
9
+ console.warn('Missing NEXT_PUBLIC_POSTHOG_HOST environment variable');
10
+ }
11
+ if (POSTHOG_KEY && POSTHOG_HOST) {
12
+ posthog.init(POSTHOG_KEY, {
13
+ api_host: POSTHOG_HOST,
14
+ defaults: '2025-05-24',
15
+ person_profiles: 'identified_only',
16
+ });
17
+ }
18
+ };
19
+ //# sourceMappingURL=browser-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../../../libs/lib-instr/src/lib/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,YAAY,CAAC;AAEjC,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,EAAE;IAC5C,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;IAE1D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,WAAW,IAAI,YAAY,EAAE,CAAC;QAChC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE;YACxB,QAAQ,EAAE,YAAY;YACtB,QAAQ,EAAE,YAAY;YACtB,eAAe,EAAE,iBAAiB;SACnC,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { PostHogFeatureProps } from '@posthog/react';
2
+ import { JsonType } from 'posthog-js';
3
+ export type FeatureFlag = 'authority-pages' | 'translation-hover-cards' | 'studio-header-config' | 'show-reader-header' | 'show-restriction-warning';
4
+ export type FeatureFlagPayload = {
5
+ apps?: string[];
6
+ [key: string]: JsonType;
7
+ };
8
+ /**
9
+ * Checks if a feature flag is enabled for the current application.
10
+ * If the feature flag has an "apps" payload, it checks if the current
11
+ * application is included in that list.
12
+ *
13
+ * @param flagKey - The key of the feature flag to check.
14
+ * @returns True if the feature flag is enabled for the current application, false otherwise.
15
+ */
16
+ export declare const useFeatureFlagEnabled: (flagKey: FeatureFlag) => boolean;
17
+ export declare const useFeatureFlagPayload: (flagKey: FeatureFlag) => FeatureFlagPayload;
18
+ export declare const useFeatureFlagVariantKey: (flagKey: FeatureFlag) => string | boolean | undefined;
19
+ export type GatedFeatureProps = PostHogFeatureProps & {
20
+ flag: FeatureFlag;
21
+ };
22
+ export declare const GatedFeature: ({ children, flag }: GatedFeatureProps) => string | number | bigint | boolean | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<import("react").ReactNode> | null | undefined> | null | undefined;
23
+ /**
24
+ * Returns the studio header config payload from PostHog.
25
+ * Returns undefined if the flag is not enabled or has no payload.
26
+ */
27
+ export declare const useStudioHeaderConfig: () => unknown;
@@ -0,0 +1,52 @@
1
+ 'use client';
2
+ import { useFeatureFlagEnabled as phUseFeatureFlagEnabled, useFeatureFlagPayload as phUseFeatureFlagPayload, useFeatureFlagVariantKey as phUseFeatureFlagVariantKey, } from '@posthog/react';
3
+ import { useEffect, useState } from 'react';
4
+ /**
5
+ * Checks if a feature flag is enabled for the current application.
6
+ * If the feature flag has an "apps" payload, it checks if the current
7
+ * application is included in that list.
8
+ *
9
+ * @param flagKey - The key of the feature flag to check.
10
+ * @returns True if the feature flag is enabled for the current application, false otherwise.
11
+ */
12
+ export const useFeatureFlagEnabled = (flagKey) => {
13
+ if (!phUseFeatureFlagEnabled(flagKey)) {
14
+ return false;
15
+ }
16
+ const APPLICATION_NAME = process.env.NEXT_PUBLIC_APPLICATION_NAME || '';
17
+ const { apps } = phUseFeatureFlagPayload(flagKey);
18
+ if (!(apps === null || apps === void 0 ? void 0 : apps.length)) {
19
+ return true;
20
+ }
21
+ return apps.includes(APPLICATION_NAME);
22
+ };
23
+ export const useFeatureFlagPayload = (flagKey) => {
24
+ return phUseFeatureFlagPayload(flagKey);
25
+ };
26
+ export const useFeatureFlagVariantKey = (flagKey) => {
27
+ return phUseFeatureFlagVariantKey(flagKey);
28
+ };
29
+ export const GatedFeature = ({ children, flag }) => {
30
+ const [isClient, setIsClient] = useState(false);
31
+ const enabled = useFeatureFlagEnabled(flag);
32
+ useEffect(() => {
33
+ setIsClient(true);
34
+ }, []);
35
+ if (!isClient) {
36
+ return null;
37
+ }
38
+ return enabled ? children : null;
39
+ };
40
+ /**
41
+ * Returns the studio header config payload from PostHog.
42
+ * Returns undefined if the flag is not enabled or has no payload.
43
+ */
44
+ export const useStudioHeaderConfig = () => {
45
+ const enabled = phUseFeatureFlagEnabled('studio-header-config');
46
+ const payload = phUseFeatureFlagPayload('studio-header-config');
47
+ if (!enabled) {
48
+ return undefined;
49
+ }
50
+ return payload;
51
+ };
52
+ //# sourceMappingURL=feature-flags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"feature-flags.js","sourceRoot":"","sources":["../../../../libs/lib-instr/src/lib/feature-flags.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EACL,qBAAqB,IAAI,uBAAuB,EAChD,qBAAqB,IAAI,uBAAuB,EAChD,wBAAwB,IAAI,0BAA0B,GAEvD,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAc5C;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,OAAoB,EAAW,EAAE;IACrE,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,EAAE,CAAC;IACxE,MAAM,EAAE,IAAI,EAAE,GAAG,uBAAuB,CAAC,OAAO,CAAuB,CAAC;IAExE,IAAI,CAAC,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,MAAM,CAAA,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,OAAoB,EACA,EAAE;IACtB,OAAO,uBAAuB,CAAC,OAAO,CAAuB,CAAC;AAChE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,OAAoB,EACU,EAAE;IAChC,OAAO,0BAA0B,CAAC,OAAO,CAAC,CAAC;AAC7C,CAAC,CAAC;AAMF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAqB,EAAE,EAAE;IACpE,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAChD,MAAM,OAAO,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAE5C,SAAS,CAAC,GAAG,EAAE;QACb,WAAW,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC;AACnC,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAY,EAAE;IACjD,MAAM,OAAO,GAAG,uBAAuB,CAAC,sBAAsB,CAAC,CAAC;IAChE,MAAM,OAAO,GAAG,uBAAuB,CAAC,sBAAsB,CAAC,CAAC;IAEhE,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { ReactNode } from 'react';
2
+ export declare const InstrProvider: ({ children }: {
3
+ children: ReactNode;
4
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import posthog from 'posthog-js';
3
+ import { PostHogProvider } from '@posthog/react';
4
+ export const InstrProvider = ({ children }) => {
5
+ return _jsx(PostHogProvider, { client: posthog, children: children });
6
+ };
7
+ //# sourceMappingURL=instr-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"instr-provider.js","sourceRoot":"","sources":["../../../../libs/lib-instr/src/lib/instr-provider.tsx"],"names":[],"mappings":";AACA,OAAO,OAAO,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,EAAE,QAAQ,EAA2B,EAAE,EAAE;IACrE,OAAO,KAAC,eAAe,IAAC,MAAM,EAAE,OAAO,YAAG,QAAQ,GAAmB,CAAC;AACxE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { PostHog } from 'posthog-node';
2
+ export declare const createInstrumentationClient: () => PostHog | undefined;
@@ -0,0 +1,20 @@
1
+ import { PostHog } from 'posthog-node';
2
+ export const createInstrumentationClient = () => {
3
+ const POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY;
4
+ const POSTHOG_HOST = process.env.NEXT_PUBLIC_POSTHOG_HOST;
5
+ if (!POSTHOG_KEY) {
6
+ console.warn('Missing NEXT_PUBLIC_POSTHOG_KEY environment variable');
7
+ }
8
+ if (!POSTHOG_HOST) {
9
+ console.warn('Missing NEXT_PUBLIC_POSTHOG_HOST environment variable');
10
+ }
11
+ if (!POSTHOG_KEY || !POSTHOG_HOST) {
12
+ return;
13
+ }
14
+ return new PostHog(POSTHOG_KEY, {
15
+ host: POSTHOG_HOST,
16
+ flushAt: 1,
17
+ flushInterval: 0,
18
+ });
19
+ };
20
+ //# sourceMappingURL=server-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-client.js","sourceRoot":"","sources":["../../../../libs/lib-instr/src/lib/server-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC;IACxD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC;IAE1D,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,sDAAsD,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,uDAAuD,CAAC,CAAC;IACxE,CAAC;IAED,IAAI,CAAC,WAAW,IAAI,CAAC,YAAY,EAAE,CAAC;QAClC,OAAO;IACT,CAAC;IAED,OAAO,IAAI,OAAO,CAAC,WAAW,EAAE;QAC9B,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,CAAC;QACV,aAAa,EAAE,CAAC;KACjB,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export type StaticFeature = 'glossary-attestations';
2
+ export declare const isStaticFeatureEnabled: (flagKey: StaticFeature) => boolean;
@@ -0,0 +1,15 @@
1
+ // NOTE: PostHog does not currently support checking feature flags or remote
2
+ // config values during server-side rendering. Until that is supported, we will
3
+ // use this hard coded configuration.
4
+ const STATIC_FEATURE_FLAGS = {
5
+ 'glossary-attestations': ['scholars-room', 'studio', 'reader-embed'],
6
+ };
7
+ export const isStaticFeatureEnabled = (flagKey) => {
8
+ const APPLICATION_NAME = process.env.NEXT_PUBLIC_APPLICATION_NAME || '';
9
+ const apps = STATIC_FEATURE_FLAGS[flagKey] || [];
10
+ if (!apps.length) {
11
+ return true;
12
+ }
13
+ return apps.includes(APPLICATION_NAME);
14
+ };
15
+ //# sourceMappingURL=static-features.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static-features.js","sourceRoot":"","sources":["../../../../libs/lib-instr/src/lib/static-features.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,+EAA+E;AAC/E,qCAAqC;AAIrC,MAAM,oBAAoB,GAAoC;IAC5D,uBAAuB,EAAE,CAAC,eAAe,EAAE,QAAQ,EAAE,cAAc,CAAC;CACrE,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAAsB,EAAE,EAAE;IAC/D,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,4BAA4B,IAAI,EAAE,CAAC;IAExE,MAAM,IAAI,GAAG,oBAAoB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAEjD,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACjB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACzC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare const useInstr: () => import("@posthog/react").PostHog;
@@ -1,3 +1,3 @@
1
1
  import { usePostHog } from '@posthog/react';
2
-
3
2
  export const useInstr = usePostHog;
3
+ //# sourceMappingURL=use-instr.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-instr.js","sourceRoot":"","sources":["../../../../libs/lib-instr/src/lib/use-instr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eightyfourthousand/lib-instr",
3
- "version": "2026.4.0",
3
+ "version": "2026.4.1",
4
4
  "description": "Feature flag and instrumentation helpers for 84000 applications.",
5
5
  "private": false,
6
6
  "repository": {
@@ -16,11 +16,38 @@
16
16
  "publishConfig": {
17
17
  "access": "public"
18
18
  },
19
+ "dependencies": {
20
+ "@posthog/react": "^1.4.0",
21
+ "posthog-js": "^1.285.1",
22
+ "posthog-node": "^5.11.2"
23
+ },
19
24
  "peerDependencies": {
20
25
  "react": "^19.0.0",
21
26
  "react-dom": "^19.0.0"
22
27
  },
28
+ "type": "module",
29
+ "main": "./index.js",
30
+ "module": "./index.js",
31
+ "types": "./index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./index.d.ts",
35
+ "import": "./index.js",
36
+ "default": "./index.js"
37
+ },
38
+ "./ssr": {
39
+ "types": "./ssr.d.ts",
40
+ "import": "./ssr.js",
41
+ "default": "./ssr.js"
42
+ },
43
+ "./static": {
44
+ "types": "./static.d.ts",
45
+ "import": "./static.js",
46
+ "default": "./static.js"
47
+ },
48
+ "./package.json": "./package.json"
49
+ },
23
50
  "sideEffects": false,
24
51
  "keywords": [],
25
52
  "author": ""
26
- }
53
+ }
package/ssr.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/server-client';
2
+ //# sourceMappingURL=ssr.js.map
package/ssr.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ssr.js","sourceRoot":"","sources":["../../../libs/lib-instr/src/ssr.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC"}
package/static.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from './lib/static-features';
2
+ //# sourceMappingURL=static.js.map
package/static.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"static.js","sourceRoot":"","sources":["../../../libs/lib-instr/src/static.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC"}
package/.babelrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "@nx/react/babel",
5
- {
6
- "runtime": "automatic",
7
- "useBuiltIns": "usage"
8
- }
9
- ]
10
- ],
11
- "plugins": []
12
- }
package/.eslintrc.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "extends": ["plugin:@nx/react", "../../.eslintrc.json"],
3
- "ignorePatterns": ["!**/*", "storybook-static"],
4
- "overrides": [
5
- {
6
- "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
7
- "rules": {}
8
- },
9
- {
10
- "files": ["*.ts", "*.tsx"],
11
- "rules": {}
12
- },
13
- {
14
- "files": ["*.js", "*.jsx"],
15
- "rules": {}
16
- }
17
- ]
18
- }
package/README.md DELETED
@@ -1,9 +0,0 @@
1
- # @eightyfourthousand/lib-instr
2
-
3
- Feature flag and instrumentation helpers for 84000 applications.
4
-
5
- This package contains shared feature-gating and instrumentation utilities used by frontend applications and companion libraries.
6
-
7
- ## Running unit tests
8
-
9
- Run `nx test lib-instr` to execute the unit tests via [Jest](https://jestjs.io).
package/jest.config.ts DELETED
@@ -1,10 +0,0 @@
1
- module.exports = {
2
- displayName: 'lib-instr',
3
- preset: '../../jest.preset.js',
4
- transform: {
5
- '^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
6
- '^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
7
- },
8
- moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
9
- coverageDirectory: '../../coverage/libs/lib-utils',
10
- };
@@ -1,9 +0,0 @@
1
- // postcss.config.mjs
2
- /** @type {import('postcss-load-config').Config} */
3
- const config = {
4
- plugins: {
5
- '@tailwindcss/postcss': {},
6
- },
7
- };
8
-
9
- export default config;
package/project.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "name": "lib-instr",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "sourceRoot": "libs/lib-instr/src",
5
- "projectType": "library",
6
- "tags": ["type:utility", "scope:shared"],
7
- "targets": {
8
- "build": {
9
- "executor": "@nx/js:tsc",
10
- "outputs": ["{options.outputPath}"],
11
- "options": {
12
- "outputPath": "dist/libs/lib-instr",
13
- "main": "libs/lib-instr/src/index.ts",
14
- "tsConfig": "libs/lib-instr/tsconfig.lib.json",
15
- "rootDir": "libs/lib-instr/src",
16
- "generateExportsField": true,
17
- "additionalEntryPoints": [
18
- "libs/lib-instr/src/ssr.ts",
19
- "libs/lib-instr/src/static.ts"
20
- ]
21
- }
22
- }
23
- }
24
- }
@@ -1,22 +0,0 @@
1
- import posthog from 'posthog-js';
2
-
3
- export const initializeInstrumentation = () => {
4
- const POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY;
5
- const POSTHOG_HOST = process.env.NEXT_PUBLIC_POSTHOG_HOST;
6
-
7
- if (!POSTHOG_KEY) {
8
- console.warn('Missing NEXT_PUBLIC_POSTHOG_KEY environment variable');
9
- }
10
-
11
- if (!POSTHOG_HOST) {
12
- console.warn('Missing NEXT_PUBLIC_POSTHOG_HOST environment variable');
13
- }
14
-
15
- if (POSTHOG_KEY && POSTHOG_HOST) {
16
- posthog.init(POSTHOG_KEY, {
17
- api_host: POSTHOG_HOST,
18
- defaults: '2025-05-24',
19
- person_profiles: 'identified_only',
20
- });
21
- }
22
- };
@@ -1,91 +0,0 @@
1
- 'use client';
2
-
3
- import {
4
- useFeatureFlagEnabled as phUseFeatureFlagEnabled,
5
- useFeatureFlagPayload as phUseFeatureFlagPayload,
6
- useFeatureFlagVariantKey as phUseFeatureFlagVariantKey,
7
- PostHogFeatureProps,
8
- } from '@posthog/react';
9
- import { JsonType } from 'posthog-js';
10
- import { useEffect, useState } from 'react';
11
-
12
- export type FeatureFlag =
13
- | 'authority-pages'
14
- | 'translation-hover-cards'
15
- | 'studio-header-config'
16
- | 'show-reader-header'
17
- | 'show-restriction-warning';
18
-
19
- export type FeatureFlagPayload = {
20
- apps?: string[];
21
- [key: string]: JsonType;
22
- };
23
-
24
- /**
25
- * Checks if a feature flag is enabled for the current application.
26
- * If the feature flag has an "apps" payload, it checks if the current
27
- * application is included in that list.
28
- *
29
- * @param flagKey - The key of the feature flag to check.
30
- * @returns True if the feature flag is enabled for the current application, false otherwise.
31
- */
32
- export const useFeatureFlagEnabled = (flagKey: FeatureFlag): boolean => {
33
- if (!phUseFeatureFlagEnabled(flagKey)) {
34
- return false;
35
- }
36
-
37
- const APPLICATION_NAME = process.env.NEXT_PUBLIC_APPLICATION_NAME || '';
38
- const { apps } = phUseFeatureFlagPayload(flagKey) as FeatureFlagPayload;
39
-
40
- if (!apps?.length) {
41
- return true;
42
- }
43
-
44
- return apps.includes(APPLICATION_NAME);
45
- };
46
-
47
- export const useFeatureFlagPayload = (
48
- flagKey: FeatureFlag,
49
- ): FeatureFlagPayload => {
50
- return phUseFeatureFlagPayload(flagKey) as FeatureFlagPayload;
51
- };
52
-
53
- export const useFeatureFlagVariantKey = (
54
- flagKey: FeatureFlag,
55
- ): string | boolean | undefined => {
56
- return phUseFeatureFlagVariantKey(flagKey);
57
- };
58
-
59
- export type GatedFeatureProps = PostHogFeatureProps & {
60
- flag: FeatureFlag;
61
- };
62
-
63
- export const GatedFeature = ({ children, flag }: GatedFeatureProps) => {
64
- const [isClient, setIsClient] = useState(false);
65
- const enabled = useFeatureFlagEnabled(flag);
66
-
67
- useEffect(() => {
68
- setIsClient(true);
69
- }, []);
70
-
71
- if (!isClient) {
72
- return null;
73
- }
74
-
75
- return enabled ? children : null;
76
- };
77
-
78
- /**
79
- * Returns the studio header config payload from PostHog.
80
- * Returns undefined if the flag is not enabled or has no payload.
81
- */
82
- export const useStudioHeaderConfig = (): unknown => {
83
- const enabled = phUseFeatureFlagEnabled('studio-header-config');
84
- const payload = phUseFeatureFlagPayload('studio-header-config');
85
-
86
- if (!enabled) {
87
- return undefined;
88
- }
89
-
90
- return payload;
91
- };
@@ -1,7 +0,0 @@
1
- import { ReactNode } from 'react';
2
- import posthog from 'posthog-js';
3
- import { PostHogProvider } from '@posthog/react';
4
-
5
- export const InstrProvider = ({ children }: { children: ReactNode }) => {
6
- return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
7
- };
@@ -1,24 +0,0 @@
1
- import { PostHog } from 'posthog-node';
2
-
3
- export const createInstrumentationClient = () => {
4
- const POSTHOG_KEY = process.env.NEXT_PUBLIC_POSTHOG_KEY;
5
- const POSTHOG_HOST = process.env.NEXT_PUBLIC_POSTHOG_HOST;
6
-
7
- if (!POSTHOG_KEY) {
8
- console.warn('Missing NEXT_PUBLIC_POSTHOG_KEY environment variable');
9
- }
10
-
11
- if (!POSTHOG_HOST) {
12
- console.warn('Missing NEXT_PUBLIC_POSTHOG_HOST environment variable');
13
- }
14
-
15
- if (!POSTHOG_KEY || !POSTHOG_HOST) {
16
- return;
17
- }
18
-
19
- return new PostHog(POSTHOG_KEY, {
20
- host: POSTHOG_HOST,
21
- flushAt: 1,
22
- flushInterval: 0,
23
- });
24
- };
@@ -1,21 +0,0 @@
1
- // NOTE: PostHog does not currently support checking feature flags or remote
2
- // config values during server-side rendering. Until that is supported, we will
3
- // use this hard coded configuration.
4
-
5
- export type StaticFeature = 'glossary-attestations';
6
-
7
- const STATIC_FEATURE_FLAGS: Record<StaticFeature, string[]> = {
8
- 'glossary-attestations': ['scholars-room', 'studio', 'reader-embed'],
9
- };
10
-
11
- export const isStaticFeatureEnabled = (flagKey: StaticFeature) => {
12
- const APPLICATION_NAME = process.env.NEXT_PUBLIC_APPLICATION_NAME || '';
13
-
14
- const apps = STATIC_FEATURE_FLAGS[flagKey] || [];
15
-
16
- if (!apps.length) {
17
- return true;
18
- }
19
-
20
- return apps.includes(APPLICATION_NAME);
21
- };
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "jsx": "react-jsx",
4
- "allowJs": false,
5
- "esModuleInterop": false,
6
- "allowSyntheticDefaultImports": true,
7
- "strict": true
8
- },
9
- "files": [],
10
- "include": [],
11
- "references": [
12
- {
13
- "path": "./tsconfig.lib.json"
14
- },
15
- {
16
- "path": "./tsconfig.spec.json"
17
- }
18
- ],
19
- "extends": "../../tsconfig.base.json"
20
- }
package/tsconfig.lib.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "types": [
7
- "node",
8
- "@nx/react/typings/cssmodule.d.ts",
9
- "@nx/react/typings/image.d.ts",
10
- "next",
11
- "@nx/next/typings/image.d.ts"
12
- ]
13
- },
14
- "exclude": [
15
- "jest.config.ts",
16
- "src/**/*.spec.ts",
17
- "src/**/*.test.ts",
18
- "src/**/*.spec.tsx",
19
- "src/**/*.test.tsx",
20
- "src/**/*.spec.js",
21
- "src/**/*.test.js",
22
- "src/**/*.spec.jsx",
23
- "src/**/*.test.jsx",
24
- "**/*.stories.ts",
25
- "**/*.stories.js"
26
- ],
27
- "include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
28
- }
@@ -1,22 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "module": "commonjs",
6
- "moduleResolution": "node10",
7
- "jsx": "react-jsx",
8
- "types": ["jest", "node"]
9
- },
10
- "include": [
11
- "jest.config.ts",
12
- "src/**/*.test.ts",
13
- "src/**/*.spec.ts",
14
- "src/**/*.test.tsx",
15
- "src/**/*.spec.tsx",
16
- "src/**/*.test.js",
17
- "src/**/*.spec.js",
18
- "src/**/*.test.jsx",
19
- "src/**/*.spec.jsx",
20
- "src/**/*.d.ts"
21
- ]
22
- }
File without changes
File without changes
File without changes