-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathtypes.ts
More file actions
950 lines (840 loc) · 26.5 KB
/
Copy pathtypes.ts
File metadata and controls
950 lines (840 loc) · 26.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
import { Pool as GenericPool } from 'generic-pool'
import { Redis } from 'ioredis'
import { DateTime } from 'luxon'
import { Message } from 'node-rdkafka'
import { GroupTypeManager } from '~/common/groups/group-type-manager'
import { GroupRepository } from '~/common/groups/repositories/group-repository.interface'
import { PersonRepository } from '~/common/persons/repositories/person-repository'
import { QuotaLimiting } from '~/common/services/quota-limiting.service'
import { PostgresRouter } from '~/common/utils/db/postgres'
import { GeoIPService } from '~/common/utils/geoip'
import { PubSub } from '~/common/utils/pubsub'
import { TeamManager } from '~/common/utils/team-manager'
import type { LogsIngestionConsumerConfig, TracesIngestionConsumerConfig } from '~/logs/config'
import { Element, PluginEvent, Properties } from '~/plugin-scaffold'
import type { AIObservabilityConfig } from './ai-observability/config'
import type { CdpConfig } from './cdp/config'
import type {
KafkaWarehouseProducerEnvConfig,
KafkaWarpstreamCyclotronProducerEnvConfig,
KafkaWarpstreamIngestionProducerEnvConfig,
} from './cdp/outputs/producers'
import { IntegrationManagerService } from './cdp/services/managers/integration-manager.service'
import { EncryptedFields } from './cdp/utils/encryption-utils'
import type { CommonConfig } from './common/config'
export type { Element } from '~/plugin-scaffold' // Re-export Element from scaffolding, for backwards compat.
type Brand<K, T> = K & { __brand: T }
// Re-export config types from domain-specific files, this is to avoid mass refactors, we can eventually update it
export type { CdpConfig } from './cdp/config'
export type { AIObservabilityConfig } from './ai-observability/config'
export { KafkaSaslMechanism, PluginServerMode, stringToPluginServerMode } from './common/config'
export type { CommonConfig, LogLevel } from './common/config'
export type { LogsIngestionConsumerConfig } from '~/logs/config'
interface HealthCheckResultResponse {
service: string
status: 'ok' | 'error' | 'degraded'
message?: string
details?: Record<string, any>
}
export abstract class HealthCheckResult {
public status: 'ok' | 'error' | 'degraded'
constructor(status: 'ok' | 'error' | 'degraded') {
this.status = status
}
public abstract toResponse(serviceId: string): HealthCheckResultResponse
public isError(): boolean {
return this.status === 'error'
}
}
export class HealthCheckResultOk extends HealthCheckResult {
constructor() {
super('ok')
}
public toResponse(serviceId: string): HealthCheckResultResponse {
return { service: serviceId, status: this.status }
}
}
export class HealthCheckResultError extends HealthCheckResult {
constructor(
public message: string,
public details: Record<string, any>
) {
super('error')
}
public toResponse(serviceId: string): HealthCheckResultResponse {
return { service: serviceId, status: this.status, message: this.message, details: this.details }
}
}
export class HealthCheckResultDegraded extends HealthCheckResult {
constructor(
public message: string,
public details: Record<string, any>
) {
super('degraded')
}
public toResponse(serviceId: string): HealthCheckResultResponse {
return { service: serviceId, status: this.status, message: this.message, details: this.details }
}
}
export type PluginServerService = {
id: string
onShutdown: () => Promise<any>
healthcheck: () => HealthCheckResult | Promise<HealthCheckResult>
}
export interface PluginsServerConfig
extends CommonConfig,
CdpConfig,
AIObservabilityConfig,
LogsIngestionConsumerConfig,
TracesIngestionConsumerConfig,
// Producer envs needed by the CDP producer registry the legacy big server builds.
KafkaWarpstreamIngestionProducerEnvConfig,
KafkaWarpstreamCyclotronProducerEnvConfig,
KafkaWarehouseProducerEnvConfig {}
export interface HubServices {
postgres: PostgresRouter
redisPool: GenericPool<Redis>
posthogRedisPool: GenericPool<Redis>
teamManager: TeamManager
groupTypeManager: GroupTypeManager
groupRepository: GroupRepository
personRepository: PersonRepository
geoipService: GeoIPService
encryptedFields: EncryptedFields
pubSub: PubSub
integrationManager: IntegrationManagerService
quotaLimiting: QuotaLimiting
}
export interface Hub extends PluginsServerConfig, HubServices {}
export interface PluginServerCapabilities {
// Warning: when adding more entries, make sure to update worker/vm/capabilities.ts
// and the shouldSetupPluginInServer() test accordingly.
ingestionV2Combined?: boolean
ingestionV2?: boolean
errorTrackingIngestion?: boolean
logsIngestion?: boolean
metricsIngestion?: boolean
sessionRecordingBlobIngestionV2?: boolean
sessionRecordingBlobIngestionV2Overflow?: boolean
cdpProcessedEvents?: boolean
cdpDataWarehouseEvents?: boolean
cdpPersonUpdates?: boolean
cdpInternalEvents?: boolean
cdpLegacyOnEvent?: boolean
cdpCyclotronWorkerBatchResolve?: boolean
cdpCyclotronWorker?: boolean
cdpCyclotronWorkerHogFlow?: boolean
cdpCyclotronWorkerEmail?: boolean
cdpCohortMembership?: boolean
cdpApi?: boolean
appManagementSingleton?: boolean
evaluationScheduler?: boolean
cdpCyclotronV2Janitor?: boolean
cdpRerunWorker?: boolean
cdpHogflowScheduler?: boolean
cdpHogflowSubscriptionMatcher?: boolean
recordingApi?: boolean
ingestionV2Testing?: boolean
}
export type TeamId = Team['id']
/**
* An integer, just like team ID. In fact project ID = ID of its first team, the one was created along with the project.
* A branded type here so that we don't accidentally pass a team ID as a project ID, or vice versa.
*/
export type ProjectId = Team['id'] & { __brand: 'ProjectId' }
export enum MetricMathOperations {
Increment = 'increment',
Max = 'max',
Min = 'min',
}
export type StoredMetricMathOperations = 'max' | 'min' | 'sum'
export type StoredPluginMetrics = Record<string, StoredMetricMathOperations> | null
export type PluginMetricsVmResponse = Record<string, string> | null
export interface JobPayloadFieldOptions {
type: 'string' | 'boolean' | 'json' | 'number' | 'date' | 'daterange'
title?: string
required?: boolean
default?: any
staff_only?: boolean
}
export interface JobSpec {
payload?: Record<string, JobPayloadFieldOptions>
}
export enum CookielessServerHashMode {
Disabled = 0,
Stateless = 1,
Stateful = 2,
}
export enum AlertLevel {
P0 = 0,
P1 = 1,
P2 = 2,
P3 = 3,
P4 = 4,
}
export enum Service {
PluginServer = 'plugin_server',
DjangoServer = 'django_server',
Redis = 'redis',
Postgres = 'postgres',
ClickHouse = 'clickhouse',
Kafka = 'kafka',
}
export interface Alert {
id: string
level: AlertLevel
key: string
description?: string
trigger_location: Service
}
export interface EventUsage {
event: string
usage_count: number | null
volume: number | null
}
export interface PropertyUsage {
key: string
usage_count: number | null
volume: number | null
}
export interface ProductFeature {
key: string
name: string
}
/** Raw Organization row from database. */
export interface RawOrganization {
id: string
name: string
created_at: string
updated_at: string
available_product_features: ProductFeature[]
default_anonymize_ips: boolean
}
// NOTE: We don't need to list all options here - only the ones we use
export type OrganizationAvailableFeature = 'group_analytics' | 'data_pipelines' | 'zapier'
/** Event schema with enforcement enabled. Only includes required properties since optional properties are not validated. */
export interface EventSchemaEnforcement {
event_name: string
/** Map from property name to accepted types (multiple types when property groups disagree) */
required_properties: Map<string, string[]>
}
/** Usable Team model. */
export interface LogsSettings {
capture_console_logs?: boolean
json_parse_logs?: boolean
pii_scrub_logs?: boolean
retention_days?: number
retention_last_updated?: string
}
export interface Team {
id: number
project_id: ProjectId
uuid: string
organization_id: string
name: string
anonymize_ips: boolean
api_token: string
secret_api_token: string | null
session_recording_opt_in: boolean
person_processing_opt_out: boolean | null
heatmaps_opt_in: boolean | null
ingested_event: boolean
person_display_name_properties: string[] | null
minimal_flag_called_events: boolean
test_account_filters:
| (EventPropertyFilter | PersonPropertyFilter | ElementPropertyFilter | CohortPropertyFilter)[]
| null
cookieless_server_hash_mode: CookielessServerHashMode | null
timezone: string
// This is parsed as a join from the org table
available_features: OrganizationAvailableFeature[]
drop_events_older_than_seconds: number | null
logs_settings?: LogsSettings | null
extra_settings: Record<string, string | number | boolean> | null
}
/** Properties shared by RawEventMessage and EventMessage. */
export interface BaseEventMessage {
distinct_id: string
ip: string
site_url: string
team_id: number
uuid: string
}
/** Raw event message as received via Kafka. */
export interface RawEventMessage extends BaseEventMessage {
/** JSON-encoded object. */
data: string
/** ISO-formatted datetime. */
now: string
/** ISO-formatted datetime. May be empty! */
sent_at: string
/** JSON-encoded number. */
kafka_offset: string
/** Messages may have a token instead of a team_id, to be used e.g. to
* resolve to a team_id */
token?: string
}
/** Usable event message. */
export interface EventMessage extends BaseEventMessage {
data: PluginEvent
now: DateTime
sent_at: DateTime | null
}
/** Properties shared by RawClickHouseEvent and ClickHouseEvent. */
interface BaseEvent {
uuid: string
event: string
team_id: TeamId
distinct_id: string
/** Person UUID. */
person_id?: string
}
export type ISOTimestamp = Brand<string, 'ISOTimestamp'>
export type ClickHouseTimestamp = Brand<string, 'ClickHouseTimestamp'>
export type ClickHouseTimestampSecondPrecision = Brand<string, 'ClickHouseTimestamp'>
export type PersonMode = 'full' | 'propertyless' | 'force_upgrade'
/** Raw event row from ClickHouse. */
export interface RawClickHouseEvent extends BaseEvent {
project_id: ProjectId
timestamp: ClickHouseTimestamp
created_at: ClickHouseTimestamp
captured_at?: ClickHouseTimestamp | null
properties?: string
elements_chain: string
person_created_at?: ClickHouseTimestamp
person_properties?: string
group0_properties?: string
group1_properties?: string
group2_properties?: string
group3_properties?: string
group4_properties?: string
group0_created_at?: ClickHouseTimestamp
group1_created_at?: ClickHouseTimestamp
group2_created_at?: ClickHouseTimestamp
group3_created_at?: ClickHouseTimestamp
group4_created_at?: ClickHouseTimestamp
person_mode: PersonMode
historical_migration?: boolean
}
export interface RawKafkaEvent extends RawClickHouseEvent {
/**
* The project ID field is only included in the `clickhouse_events_json` topic, not present in ClickHouse.
* That's because we need it in `property-defs-rs` and not elsewhere.
*/
project_id: ProjectId
}
/** Pre-serialization event produced by create-event, before ClickHouse formatting. */
export interface ProcessedEvent {
uuid: string
event: string
properties: Record<string, unknown>
timestamp: ISOTimestamp
team_id: TeamId
project_id: ProjectId
distinct_id: string
elements_chain: string
/**
* Stamped once when create-event assembles the event, so every table this
* event is written to agrees on it. Serializing twice would otherwise read
* the wall clock twice and stamp two different values.
*/
created_at: DateTime
captured_at: Date | null
person_id: string
person_properties: Record<string, unknown>
person_created_at: DateTime | null
person_mode: PersonMode
historical_migration?: boolean
}
/** Parsed event row from ClickHouse. */
export interface ClickHouseEvent extends BaseEvent {
project_id: ProjectId
timestamp: DateTime
created_at: DateTime
properties: Record<string, any>
elements_chain: Element[] | null
person_created_at: DateTime | null
person_properties: Record<string, any>
group0_properties: Record<string, any>
group1_properties: Record<string, any>
group2_properties: Record<string, any>
group3_properties: Record<string, any>
group4_properties: Record<string, any>
group0_created_at?: DateTime | null
group1_created_at?: DateTime | null
group2_created_at?: DateTime | null
group3_created_at?: DateTime | null
group4_created_at?: DateTime | null
person_mode: PersonMode
}
/** Event structure before initial ingestion.
* This is what is used for all ingestion steps that run _before_ the clickhouse events topic.
*/
export interface PreIngestionEvent {
eventUuid: string
event: string
teamId: TeamId
projectId: ProjectId
distinctId: string
properties: Properties
timestamp: ISOTimestamp
}
/** Parsed event structure after initial ingestion.
* This is what is used for all ingestion steps that run _after_ the clickhouse events topic.
*/
export interface PostIngestionEvent extends PreIngestionEvent {
elementsList?: Element[]
person_id?: string // This is not optional, but BaseEvent needs to be fixed first
person_created_at: ISOTimestamp | null
person_properties: Properties
groups?: Record<
string,
{
key: string
type: string
index: number
properties: Properties
}
>
}
export interface DeadLetterQueueEvent {
id: string
event_uuid: string
event: string
properties: string
distinct_id: string
team_id: number
elements_chain: string
created_at: string
ip: string
site_url: string
now: string
raw_payload: string
error_timestamp: string
error_location: string
error: string
tags: string[]
_timestamp: string
_offset: number
}
export type PropertiesLastUpdatedAt = Record<string, string>
export type PropertiesLastOperation = Record<string, PropertyUpdateOperation>
/** Properties shared by RawPerson and Person. */
export interface BasePerson {
// NOTE: id is a bigint in the DB, which pg lib returns as a string
// We leave it as a string as dealing with the bigint type is tricky and we don't need any of its features
id: string
team_id: number
properties: Properties
is_user_id: number | null
is_identified: boolean
uuid: string
properties_last_updated_at: PropertiesLastUpdatedAt
properties_last_operation: PropertiesLastOperation | null
}
/** Raw Person row from database. */
export interface RawPerson extends BasePerson {
created_at: string
version: string | null
last_seen_at: string | null
}
/** Usable Person model. */
export interface InternalPerson extends BasePerson {
created_at: DateTime
version: number
last_seen_at: DateTime | null
}
/** Mutable fields that can be updated on a Person via updatePerson. */
export interface PersonUpdateFields {
properties: Properties
properties_last_updated_at: PropertiesLastUpdatedAt
properties_last_operation: PropertiesLastOperation | null
is_identified: boolean
created_at: DateTime
version?: number // Optional: allows forcing a specific version
last_seen_at?: DateTime | null
}
/** Person model exposed outside of person-specific DB logic. */
export interface Person {
team_id: number
properties: Properties
uuid: string
created_at: DateTime
// Set to `true` when an existing person row was found for this `distinct_id`, but the event was
// sent with `$process_person_profile=false`. This is an unexpected branch that we want to flag
// for debugging and billing purposes, and typically means a misconfigured SDK.
force_upgrade?: boolean
}
/** Clickhouse Person model. */
export interface ClickHousePerson {
id: string
created_at: string
team_id: number
properties: string
is_identified: number
is_deleted: number
timestamp: string
version: number
last_seen_at: string | null
}
export type GroupTypeIndex = 0 | 1 | 2 | 3 | 4
interface BaseGroup {
id: number
team_id: number
group_type_index: GroupTypeIndex
group_key: string
group_properties: Properties
properties_last_updated_at: PropertiesLastUpdatedAt
properties_last_operation: PropertiesLastOperation
}
/** Raw Group row from database. */
export interface RawGroup extends BaseGroup {
created_at: string
version: string
}
/** Usable Group model. */
export interface Group extends BaseGroup {
created_at: DateTime
version: number
}
export type GroupKey = string
/** Clickhouse Group model */
export interface ClickhouseGroup {
group_type_index: GroupTypeIndex
group_key: GroupKey
created_at: string
team_id: number
group_properties: string
}
/** Usable PersonDistinctId model. */
export interface PersonDistinctId {
id: number
team_id: number
person_id: number
distinct_id: string
version: string | null
}
/** ClickHouse PersonDistinctId model. (person_distinct_id2 table) */
export interface ClickHousePersonDistinctId2 {
team_id: number
person_id: string
distinct_id: string
is_deleted: 0 | 1
version: number
}
/** Usable Cohort model. */
export interface Cohort {
id: number
name: string
description: string
deleted: boolean
groups: any[]
team_id: Team['id']
created_at: string
created_by_id: number
is_calculating: boolean
last_calculation: string
errors_calculating: number
is_static: boolean
version: number | null
pending_version: number
}
/** Usable CohortPeople model. */
export interface CohortPeople {
id: number
cohort_id: number
person_id: number
}
/** Usable Hook model. */
export interface Hook {
id: string
team_id: number
user_id: number
resource_id: number | null
event: string
target: string
created: string
updated: string
}
/** Sync with posthog/frontend/src/types.ts */
export enum PropertyOperator {
Exact = 'exact',
IsNot = 'is_not',
IContains = 'icontains',
NotIContains = 'not_icontains',
StartsWith = 'starts_with',
NotStartsWith = 'not_starts_with',
EndsWith = 'ends_with',
NotEndsWith = 'not_ends_with',
Regex = 'regex',
NotRegex = 'not_regex',
GreaterThan = 'gt',
LessThan = 'lt',
IsSet = 'is_set',
IsNotSet = 'is_not_set',
IsDateBefore = 'is_date_before',
IsDateAfter = 'is_date_after',
IsCleanedPathExact = 'is_cleaned_path_exact',
}
/** Sync with posthog/frontend/src/types.ts */
interface PropertyFilterBase {
key: string
value?: string | number | Array<string | number> | null
label?: string
}
/** Sync with posthog/frontend/src/types.ts */
export interface PropertyFilterWithOperator extends PropertyFilterBase {
operator?: PropertyOperator
}
/** Sync with posthog/frontend/src/types.ts */
export interface EventPropertyFilter extends PropertyFilterWithOperator {
type: 'event'
}
/** Sync with posthog/frontend/src/types.ts */
export interface HogQLPropertyFilter extends PropertyFilterWithOperator {
type: 'hogql'
}
/** Sync with posthog/frontend/src/types.ts */
export interface PersonPropertyFilter extends PropertyFilterWithOperator {
type: 'person'
}
export interface DataWarehousePropertyFilter extends PropertyFilterWithOperator {
type: 'data_warehouse'
}
export interface DataWarehousePersonPropertyFilter extends PropertyFilterWithOperator {
type: 'data_warehouse_person_property'
}
/** Sync with posthog/frontend/src/types.ts */
export interface ElementPropertyFilter extends PropertyFilterWithOperator {
type: 'element'
key: 'tag_name' | 'text' | 'href' | 'selector'
value: string | string[]
}
/** Sync with posthog/frontend/src/types.ts */
export interface CohortPropertyFilter extends PropertyFilterBase {
type: 'cohort'
key: 'id'
value: number | string
}
/** Sync with posthog/frontend/src/types.ts */
export type PropertyFilter =
| EventPropertyFilter
| PersonPropertyFilter
| ElementPropertyFilter
| CohortPropertyFilter
| DataWarehousePropertyFilter
| DataWarehousePersonPropertyFilter
| HogQLPropertyFilter
/** Sync with posthog/frontend/src/types.ts */
export enum StringMatching {
Contains = 'contains',
Regex = 'regex',
Exact = 'exact',
}
export interface ActionStep {
tag_name: string | null
text: string | null
/** @default StringMatching.Exact */
text_matching: StringMatching | null
href: string | null
/** @default StringMatching.Exact */
href_matching: StringMatching | null
selector: string | null
url: string | null
/** @default StringMatching.Contains */
url_matching: StringMatching | null
event: string | null
properties: PropertyFilter[] | null
}
/** Raw Action row from database. */
export interface RawAction {
id: number
team_id: TeamId
name: string | null
description: string
created_at: string
created_by_id: number | null
deleted: boolean
post_to_slack: boolean
slack_message_format: string
is_calculating: boolean
updated_at: string
last_calculated_at: string
steps_json: ActionStep[] | null
}
/** Usable Action model. */
export interface Action extends Omit<RawAction, 'steps_json'> {
steps: ActionStep[]
hooks: Hook[]
}
/** Raw session recording event row from ClickHouse. */
export interface RawSessionRecordingEvent {
uuid: string
timestamp: string
team_id: number
distinct_id: string
session_id: string
window_id: string
snapshot_data: string
created_at: string
}
/** Raw session replay event row from ClickHouse. */
export interface RawSessionReplayEvent {
min_first_timestamp: string
team_id: number
distinct_id: string
session_id: string
/* TODO what columns do we need */
}
export enum TimestampFormat {
ClickHouseSecondPrecision = 'clickhouse-second-precision',
ClickHouse = 'clickhouse',
ISO = 'iso',
}
export interface JobsConsumerControl {
stop: () => Promise<void>
resume: () => Promise<void>
}
export type IngestEventResponse =
| { success: true; actionMatches: Action[]; preIngestionEvent: PreIngestionEvent | null }
| { success: false; error: string }
export enum UnixTimestampPropertyTypeFormat {
UNIX_TIMESTAMP = 'unix_timestamp',
UNIX_TIMESTAMP_MILLISECONDS = 'unix_timestamp_milliseconds',
}
export enum DateTimePropertyTypeFormat {
ISO8601_DATE = 'YYYY-MM-DDThh:mm:ssZ',
FULL_DATE = 'YYYY-MM-DD hh:mm:ss',
FULL_DATE_INCREASING = 'DD-MM-YYYY hh:mm:ss',
DATE = 'YYYY-MM-DD',
RFC_822 = 'rfc_822',
WITH_SLASHES = 'YYYY/MM/DD hh:mm:ss',
WITH_SLASHES_INCREASING = 'DD/MM/YYYY hh:mm:ss',
}
export enum PropertyType {
DateTime = 'DateTime',
String = 'String',
Numeric = 'Numeric',
Boolean = 'Boolean',
}
export enum PropertyDefinitionTypeEnum {
Event = 1,
Person = 2,
Group = 3,
Session = 4,
}
export type ResolvedGroups = Record<string, number>
export interface PropertyDefinitionType {
id: string
name: string
is_numerical: boolean
team_id: number
project_id: number | null
property_type: PropertyType | null
type: PropertyDefinitionTypeEnum
group_type_name?: string
group_type_index?: number | null
volume_30_day?: number | null
query_usage_30_day?: number | null
}
export interface EventPropertyType {
id: string
event: string
property: string
team_id: number
project_id: number | null
}
export type GroupTypeToColumnIndex = Record<string, GroupTypeIndex>
export type GroupTypesByProjectId = Record<ProjectId, GroupTypeToColumnIndex>
export enum PropertyUpdateOperation {
Set = 'set',
SetOnce = 'set_once',
}
export enum OrganizationPluginsAccessLevel {
NONE = 0,
CONFIG = 3,
INSTALL = 6,
ROOT = 9,
}
export enum OrganizationMembershipLevel {
Member = 1,
Admin = 8,
Owner = 15,
}
export interface PipelineEvent extends Omit<PluginEvent, 'team_id'> {
team_id?: number | null
}
export interface EventHeaders {
token?: string
distinct_id?: string
session_id?: string
timestamp?: string
event?: string
uuid?: string
now?: Date
force_disable_person_processing: boolean
historical_migration: boolean
skip_heatmap_processing: boolean
}
export interface IncomingEvent {
event: PipelineEvent
}
export interface IncomingEventWithTeam {
message: Message
event: PipelineEvent
team: Team
headers: EventHeaders
}
export type RedisPool = GenericPool<Redis>
export type RRWebEvent = Record<string, any> & {
timestamp: number
type: number
data: any
}
export interface ValueMatcher<T> {
(value: T): boolean
}
export type RawClickhouseHeatmapEvent = {
/**
* session id lets us offer example recordings on high traffic parts of the page,
* and could let us offer more advanced filtering of heatmap data
* we will break the relationship between particular sessions and clicks in aggregating this data
* it should always be treated as an exemplar and not as concrete values
*/
session_id: string
distinct_id: string
viewport_width: number
viewport_height: number
pointer_target_fixed: boolean
current_url: string
// x is the x with resolution applied, the resolution converts high fidelity mouse positions into an NxN grid
x: number
// y is the y with resolution applied, the resolution converts high fidelity mouse positions into an NxN grid
y: number
scale_factor: 16 // in the future we may support other values
timestamp: string
type: string
team_id: number
}
export interface CdpPersonPerformedEvent {
teamId: number
personId: string
eventName: string
}
export interface HookPayload {
hook: Pick<Hook, 'id' | 'event' | 'target'>
data: {
eventUuid: string
event: string
teamId: TeamId
distinctId: string
properties: Properties
timestamp: ISOTimestamp
elementsList?: Element[]
person: {
uuid: string
properties: Properties
created_at: ISOTimestamp | null
}
}
}