@crvouga/mockingbird-service-posthog 2.1.0 → 2.2.0

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/dist/cli.js CHANGED
@@ -3,8 +3,8 @@ import {
3
3
  runCli,
4
4
  serveCommand,
5
5
  serveTarget
6
- } from "./chunk-SCY2VOTE.js";
7
- import "./chunk-VZ3ZHVNW.js";
6
+ } from "./chunk-DSIEW2HP.js";
7
+ import "./chunk-SOC56HS3.js";
8
8
 
9
9
  // src/cli.ts
10
10
  var code = await runCli(
package/dist/index.d.ts CHANGED
@@ -29,6 +29,8 @@ type FlagRecord = {
29
29
  /** JSON string sent as `metadata.payload` when the flag is enabled. */
30
30
  payload: string | null;
31
31
  overrides: FlagOverride[];
32
+ /** Original management filters; evaluation still uses the deterministic model. */
33
+ filters?: Record<string, unknown>;
32
34
  version: number;
33
35
  created_at: string;
34
36
  updated_at: string;
@@ -52,6 +54,7 @@ declare const evaluateFlag: (flag: FlagRecord, subject: FlagSubject) => Evaluati
52
54
  declare const payloadString: (payload: unknown) => string | null;
53
55
  /** Body of `PUT /__admin/flags/:key`, validated. */
54
56
  type FlagSpec = {
57
+ filters?: Record<string, unknown>;
55
58
  name?: string;
56
59
  active?: boolean;
57
60
  default: FlagValue | null;
@@ -788,10 +791,24 @@ type Settings = {
788
791
  /** Session-recording posts to `/s/`, counted and discarded. */
789
792
  recordings: number;
790
793
  };
794
+ type ExperimentRecord = {
795
+ id: number;
796
+ projectId: string;
797
+ name: string;
798
+ feature_flag_key: string;
799
+ parameters: Record<string, unknown>;
800
+ metrics: unknown[];
801
+ start_date: string | null;
802
+ end_date: string | null;
803
+ archived: boolean;
804
+ created_at: string;
805
+ updated_at: string;
806
+ };
791
807
  declare class PostHogState {
792
808
  private readonly seed;
793
809
  private readonly now;
794
810
  readonly flags: Collection<FlagRecord>;
811
+ readonly experiments: Collection<ExperimentRecord>;
795
812
  readonly events: Collection<CapturedEvent>;
796
813
  readonly settings: Collection<Settings>;
797
814
  readonly ids: IdSequence;
@@ -1029,10 +1046,10 @@ type OpenAPIDocument = {
1029
1046
  };
1030
1047
 
1031
1048
  declare const document: OpenAPIDocument;
1032
- type OperationId = "EvaluateFlags" | "Decide" | "GetRemoteConfig" | "GetRemoteConfigScript" | "CaptureBatch" | "CaptureEvent" | "CaptureEventV0" | "CaptureRecording" | "GetRecorderScript" | "GetVersionedRecorderScript" | "ListSurveys" | "ListWebExperiments" | "ListFeatureFlags" | "CreateFeatureFlag" | "UpdateFeatureFlag" | "RunQuery";
1033
- type SupportedOperationId = "EvaluateFlags" | "Decide" | "GetRemoteConfig" | "GetRemoteConfigScript" | "CaptureBatch" | "CaptureEvent" | "CaptureEventV0" | "CaptureRecording" | "GetRecorderScript" | "GetVersionedRecorderScript" | "ListSurveys" | "ListWebExperiments" | "ListFeatureFlags" | "CreateFeatureFlag" | "UpdateFeatureFlag" | "RunQuery";
1034
- declare const operationIds: readonly ["EvaluateFlags", "Decide", "GetRemoteConfig", "GetRemoteConfigScript", "CaptureBatch", "CaptureEvent", "CaptureEventV0", "CaptureRecording", "GetRecorderScript", "GetVersionedRecorderScript", "ListSurveys", "ListWebExperiments", "ListFeatureFlags", "CreateFeatureFlag", "UpdateFeatureFlag", "RunQuery"];
1035
- declare const supportedOperationIds: readonly ["EvaluateFlags", "Decide", "GetRemoteConfig", "GetRemoteConfigScript", "CaptureBatch", "CaptureEvent", "CaptureEventV0", "CaptureRecording", "GetRecorderScript", "GetVersionedRecorderScript", "ListSurveys", "ListWebExperiments", "ListFeatureFlags", "CreateFeatureFlag", "UpdateFeatureFlag", "RunQuery"];
1049
+ type OperationId = "EvaluateFlags" | "Decide" | "GetRemoteConfig" | "GetRemoteConfigScript" | "CaptureBatch" | "CaptureEvent" | "CaptureEventV0" | "CaptureRecording" | "GetRecorderScript" | "GetVersionedRecorderScript" | "ListSurveys" | "ListWebExperiments" | "ListFeatureFlags" | "CreateFeatureFlag" | "GetFeatureFlag" | "UpdateFeatureFlag" | "ListExperiments" | "CreateExperiment" | "GetExperiment" | "UpdateExperiment" | "RunQuery";
1050
+ type SupportedOperationId = "EvaluateFlags" | "Decide" | "GetRemoteConfig" | "GetRemoteConfigScript" | "CaptureBatch" | "CaptureEvent" | "CaptureEventV0" | "CaptureRecording" | "GetRecorderScript" | "GetVersionedRecorderScript" | "ListSurveys" | "ListWebExperiments" | "ListFeatureFlags" | "CreateFeatureFlag" | "GetFeatureFlag" | "UpdateFeatureFlag" | "ListExperiments" | "CreateExperiment" | "GetExperiment" | "UpdateExperiment" | "RunQuery";
1051
+ declare const operationIds: readonly ["EvaluateFlags", "Decide", "GetRemoteConfig", "GetRemoteConfigScript", "CaptureBatch", "CaptureEvent", "CaptureEventV0", "CaptureRecording", "GetRecorderScript", "GetVersionedRecorderScript", "ListSurveys", "ListWebExperiments", "ListFeatureFlags", "CreateFeatureFlag", "GetFeatureFlag", "UpdateFeatureFlag", "ListExperiments", "CreateExperiment", "GetExperiment", "UpdateExperiment", "RunQuery"];
1052
+ declare const supportedOperationIds: readonly ["EvaluateFlags", "Decide", "GetRemoteConfig", "GetRemoteConfigScript", "CaptureBatch", "CaptureEvent", "CaptureEventV0", "CaptureRecording", "GetRecorderScript", "GetVersionedRecorderScript", "ListSurveys", "ListWebExperiments", "ListFeatureFlags", "CreateFeatureFlag", "GetFeatureFlag", "UpdateFeatureFlag", "ListExperiments", "CreateExperiment", "GetExperiment", "UpdateExperiment", "RunQuery"];
1036
1053
 
1037
1054
  /**
1038
1055
  * Every named PostHog misbehaviour our consumers branch on, switched on with
@@ -1064,6 +1081,7 @@ declare const createRuntime: (options?: PostHogRuntimeOptions) => PostHogRuntime
1064
1081
 
1065
1082
  declare const POSTHOG_NAMESPACE = "posthog";
1066
1083
  type PostHogAPIOptions = APIOptions & {
1084
+ adminPrefix?: string;
1067
1085
  /** Flags every namespace starts with (and returns to on reset), keyed by flag key. */
1068
1086
  flags?: Record<string, FlagSpec>;
1069
1087
  /** Initial per-namespace settings (session recording, canned HogQL results). */
@@ -1131,4 +1149,4 @@ declare class PostHogAPI implements FetchAPI$1 {
1131
1149
  }
1132
1150
 
1133
1151
  export { ACME_FLAG_STATE, POSTHOG_NAMESPACE, POSTHOG_PRESETS, PostHogAPI, createRuntime, decodePostHogBody, document, evaluateFlag, operationIds, parseFlagSpec, payloadString, scrubProperties, specsFromState, supportedOperationIds, tokenFromBody, valueForState };
1134
- export type { CapturedEvent, Evaluation, EventQuery, FetchAPI$1 as FetchAPI, FlagOverride, FlagRecord, FlagSpec, FlagStateFile, FlagSubject, FlagValue, ImportOptions, OperationId, PostHogAPIOptions, PostHogRuntime, PostHogRuntimeOptions, QueryResult, Settings, SqliteClient, SupportedOperationId };
1152
+ export type { CapturedEvent, Evaluation, EventQuery, ExperimentRecord, FetchAPI$1 as FetchAPI, FlagOverride, FlagRecord, FlagSpec, FlagStateFile, FlagSubject, FlagValue, ImportOptions, OperationId, PostHogAPIOptions, PostHogRuntime, PostHogRuntimeOptions, QueryResult, Settings, SqliteClient, SupportedOperationId };
package/dist/index.js CHANGED
@@ -15,7 +15,7 @@ import {
15
15
  supportedOperationIds,
16
16
  tokenFromBody,
17
17
  valueForState
18
- } from "./chunk-VZ3ZHVNW.js";
18
+ } from "./chunk-SOC56HS3.js";
19
19
  export {
20
20
  ACME_FLAG_STATE,
21
21
  POSTHOG_NAMESPACE,
package/dist/server.d.ts CHANGED
@@ -1314,6 +1314,8 @@ type FlagRecord = {
1314
1314
  /** JSON string sent as `metadata.payload` when the flag is enabled. */
1315
1315
  payload: string | null;
1316
1316
  overrides: FlagOverride[];
1317
+ /** Original management filters; evaluation still uses the deterministic model. */
1318
+ filters?: Record<string, unknown>;
1317
1319
  version: number;
1318
1320
  created_at: string;
1319
1321
  updated_at: string;
@@ -1333,6 +1335,7 @@ type Evaluation = {
1333
1335
  };
1334
1336
  /** Body of `PUT /__admin/flags/:key`, validated. */
1335
1337
  type FlagSpec = {
1338
+ filters?: Record<string, unknown>;
1336
1339
  name?: string;
1337
1340
  active?: boolean;
1338
1341
  default: FlagValue | null;
@@ -1384,10 +1387,24 @@ type Settings = {
1384
1387
  /** Session-recording posts to `/s/`, counted and discarded. */
1385
1388
  recordings: number;
1386
1389
  };
1390
+ type ExperimentRecord = {
1391
+ id: number;
1392
+ projectId: string;
1393
+ name: string;
1394
+ feature_flag_key: string;
1395
+ parameters: Record<string, unknown>;
1396
+ metrics: unknown[];
1397
+ start_date: string | null;
1398
+ end_date: string | null;
1399
+ archived: boolean;
1400
+ created_at: string;
1401
+ updated_at: string;
1402
+ };
1387
1403
  declare class PostHogState {
1388
1404
  private readonly seed;
1389
1405
  private readonly now;
1390
1406
  readonly flags: Collection<FlagRecord>;
1407
+ readonly experiments: Collection<ExperimentRecord>;
1391
1408
  readonly events: Collection<CapturedEvent>;
1392
1409
  readonly settings: Collection<Settings>;
1393
1410
  readonly ids: IdSequence;
@@ -1410,6 +1427,7 @@ declare class PostHogState {
1410
1427
  }
1411
1428
 
1412
1429
  type PostHogAPIOptions = APIOptions & {
1430
+ adminPrefix?: string;
1413
1431
  /** Flags every namespace starts with (and returns to on reset), keyed by flag key. */
1414
1432
  flags?: Record<string, FlagSpec>;
1415
1433
  /** Initial per-namespace settings (session recording, canned HogQL results). */
package/dist/server.js CHANGED
@@ -2,8 +2,8 @@ import {
2
2
  DEFAULT_PORT,
3
3
  createServer,
4
4
  serveTarget
5
- } from "./chunk-SCY2VOTE.js";
6
- import "./chunk-VZ3ZHVNW.js";
5
+ } from "./chunk-DSIEW2HP.js";
6
+ import "./chunk-SOC56HS3.js";
7
7
  export {
8
8
  DEFAULT_PORT,
9
9
  createServer,
package/openapi.yaml CHANGED
@@ -5,7 +5,7 @@ info:
5
5
  Stateful mock subset of PostHog: remote flag evaluation (`/flags` v2 and the legacy
6
6
  `/decide` shape), remote config, event capture (`/batch/`, `/e/`, `/i/v0/e/`), session
7
7
  recording intake, the posthog-js asset and survey endpoints, and the slice of the
8
- management API our tooling and crons call (feature-flag list/create/patch, HogQL query).
8
+ management API our tooling and crons call (feature-flag list/create/read/patch, experiment management, HogQL query).
9
9
  Hand-authored from the wire shapes of posthog-node 5.52.2 / @posthog/core 1.54.0,
10
10
  posthog-js 1.433.2 and our own raw fetches.
11
11
 
@@ -498,6 +498,21 @@ paths:
498
498
  x-mockingbird-resource-ref:
499
499
  type: feature_flag
500
500
  missing: "999999"
501
+ get:
502
+ operationId: GetFeatureFlag
503
+ security:
504
+ - bearerAuth: []
505
+ x-mockingbird:
506
+ supported: true
507
+ parity: { enabled: true, safe: true }
508
+ responses:
509
+ "200":
510
+ description: Current flag by numeric id (or mock key alias)
511
+ content:
512
+ application/json:
513
+ schema: { $ref: "#/components/schemas/FeatureFlag" }
514
+ "401": { $ref: "#/components/responses/ManagementError" }
515
+ "404": { $ref: "#/components/responses/ManagementError" }
501
516
  patch:
502
517
  operationId: UpdateFeatureFlag
503
518
  security:
@@ -538,6 +553,115 @@ paths:
538
553
  application/json:
539
554
  schema:
540
555
  $ref: "#/components/schemas/ErrorBody"
556
+ /api/projects/{projectId}/experiments:
557
+ parameters:
558
+ - $ref: "#/components/parameters/ProjectId"
559
+ get:
560
+ operationId: ListExperiments
561
+ security:
562
+ - bearerAuth: []
563
+ x-mockingbird:
564
+ supported: true
565
+ parity: { enabled: true, safe: true }
566
+ parameters:
567
+ - name: limit
568
+ in: query
569
+ schema: { type: integer, minimum: 1, maximum: 100, default: 100 }
570
+ - name: offset
571
+ in: query
572
+ schema: { type: integer, minimum: 0, maximum: 1000, default: 0 }
573
+ responses:
574
+ "200":
575
+ description: Newest experiments first, with limit/offset links
576
+ content:
577
+ application/json:
578
+ schema:
579
+ type: object
580
+ required: [count, next, previous, results]
581
+ properties:
582
+ count: { type: integer }
583
+ next:
584
+ type: [string, "null"]
585
+ x-mockingbird-volatile: { kind: url }
586
+ previous:
587
+ type: [string, "null"]
588
+ x-mockingbird-volatile: { kind: url }
589
+ results:
590
+ type: array
591
+ items: { $ref: "#/components/schemas/Experiment" }
592
+ "400": { $ref: "#/components/responses/ManagementError" }
593
+ "401": { $ref: "#/components/responses/ManagementError" }
594
+ post:
595
+ operationId: CreateExperiment
596
+ security:
597
+ - bearerAuth: []
598
+ x-mockingbird:
599
+ supported: true
600
+ parity: { enabled: true, safe: false }
601
+ requestBody:
602
+ required: true
603
+ content:
604
+ application/json:
605
+ schema:
606
+ allOf:
607
+ - $ref: "#/components/schemas/ExperimentWrite"
608
+ - type: object
609
+ required: [name, feature_flag_key]
610
+ properties:
611
+ feature_flag_key: { type: string, pattern: "^[A-Za-z0-9_-]{1,64}$" }
612
+ responses:
613
+ "201":
614
+ description: Experiment with a linked flag; new draft flags are inactive
615
+ content:
616
+ application/json:
617
+ schema: { $ref: "#/components/schemas/Experiment" }
618
+ "400": { $ref: "#/components/responses/ManagementError" }
619
+ "401": { $ref: "#/components/responses/ManagementError" }
620
+ /api/projects/{projectId}/experiments/{experimentId}:
621
+ parameters:
622
+ - $ref: "#/components/parameters/ProjectId"
623
+ - name: experimentId
624
+ in: path
625
+ required: true
626
+ schema:
627
+ type: string
628
+ pattern: "^[0-9]{1,6}$"
629
+ get:
630
+ operationId: GetExperiment
631
+ security:
632
+ - bearerAuth: []
633
+ x-mockingbird:
634
+ supported: true
635
+ parity: { enabled: true, safe: true }
636
+ responses:
637
+ "200":
638
+ description: Persisted experiment with the current linked flag
639
+ content:
640
+ application/json:
641
+ schema: { $ref: "#/components/schemas/Experiment" }
642
+ "401": { $ref: "#/components/responses/ManagementError" }
643
+ "404": { $ref: "#/components/responses/ManagementError" }
644
+ patch:
645
+ operationId: UpdateExperiment
646
+ security:
647
+ - bearerAuth: []
648
+ x-mockingbird:
649
+ supported: true
650
+ parity: { enabled: true, safe: false }
651
+ requestBody:
652
+ required: true
653
+ content:
654
+ application/json:
655
+ schema: { $ref: "#/components/schemas/ExperimentWrite" }
656
+ responses:
657
+ "200":
658
+ description: Only provided fields change; setting start_date activates a draft's flag
659
+ content:
660
+ application/json:
661
+ schema: { $ref: "#/components/schemas/Experiment" }
662
+ "400": { $ref: "#/components/responses/ManagementError" }
663
+ "401": { $ref: "#/components/responses/ManagementError" }
664
+ "404": { $ref: "#/components/responses/ManagementError" }
541
665
  /api/projects/{projectId}/query:
542
666
  parameters:
543
667
  - $ref: "#/components/parameters/ProjectId"
@@ -579,6 +703,12 @@ paths:
579
703
  schema:
580
704
  $ref: "#/components/schemas/ErrorBody"
581
705
  components:
706
+ responses:
707
+ ManagementError:
708
+ description: Management API error
709
+ content:
710
+ application/json:
711
+ schema: { $ref: "#/components/schemas/ErrorBody" }
582
712
  securitySchemes:
583
713
  bearerAuth:
584
714
  type: http
@@ -620,6 +750,43 @@ components:
620
750
  minimum: 1
621
751
  maximum: 999999999
622
752
  schemas:
753
+ ExperimentWrite:
754
+ type: object
755
+ properties:
756
+ name: { type: string, minLength: 1, maxLength: 120 }
757
+ parameters: { type: object }
758
+ metrics:
759
+ type: array
760
+ maxItems: 5
761
+ items: { type: object }
762
+ start_date: { type: [string, "null"], format: date-time }
763
+ end_date: { type: [string, "null"], format: date-time }
764
+ archived: { type: boolean }
765
+ Experiment:
766
+ type: object
767
+ required: [id, name, feature_flag_key, feature_flag, parameters, metrics, start_date, end_date, archived, created_at, updated_at]
768
+ properties:
769
+ id:
770
+ type: integer
771
+ name: { type: string }
772
+ feature_flag_key: { type: string }
773
+ feature_flag:
774
+ oneOf:
775
+ - $ref: "#/components/schemas/FeatureFlag"
776
+ - type: "null"
777
+ parameters: { type: object }
778
+ metrics:
779
+ type: array
780
+ items: { type: object }
781
+ start_date: { type: [string, "null"] }
782
+ end_date: { type: [string, "null"] }
783
+ archived: { type: boolean }
784
+ created_at:
785
+ type: string
786
+ x-mockingbird-volatile: { kind: timestamp }
787
+ updated_at:
788
+ type: string
789
+ x-mockingbird-volatile: { kind: timestamp }
623
790
  ErrorBody:
624
791
  type: object
625
792
  required: [type, code, detail]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crvouga/mockingbird-service-posthog",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Stateful mock of PostHog: /flags v2 and legacy /decide evaluation with per-test flag, variant and payload control, remote config, gzip/base64 capture (/batch/, /e/, /i/v0/e/), recordings intake, and the feature-flag management and HogQL API slice.",
5
5
  "license": "MIT",
6
6
  "type": "module",