-
Notifications
You must be signed in to change notification settings - Fork 731
Expand file tree
/
Copy pathindex.ts
More file actions
94 lines (86 loc) · 3.33 KB
/
index.ts
File metadata and controls
94 lines (86 loc) · 3.33 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
/**
* Platform registry / discovery.
*
* All supported platforms are registered here, keyed by PlatformType.
* Only those listed in CROWD_SNOWFLAKE_ENABLED_PLATFORMS (comma-separated) are active.
*/
import { PlatformType } from '@crowd/types'
import { buildSourceQuery as cventBuildSourceQuery } from './cvent/event-registrations/buildSourceQuery'
import { CventTransformer } from './cvent/event-registrations/transformer'
import { buildSourceQuery as meetingAttendanceBuildQuery } from './meetings/meeting-attendance/buildSourceQuery'
import { MeetingAttendanceTransformer } from './meetings/meeting-attendance/transformer'
import { buildSourceQuery as tncCertificatesBuildQuery } from './tnc/certificates/buildSourceQuery'
import { TncCertificatesTransformer } from './tnc/certificates/transformer'
import { buildSourceQuery as tncCoursesBuildQuery } from './tnc/courses/buildSourceQuery'
import { TncCoursesTransformer } from './tnc/courses/transformer'
import { buildSourceQuery as tncEnrollmentsBuildQuery } from './tnc/enrollments/buildSourceQuery'
import { TncEnrollmentsTransformer } from './tnc/enrollments/transformer'
import { DataSource, DataSourceName, PlatformDefinition } from './types'
export type { BuildSourceQuery, DataSource, PlatformDefinition } from './types'
export { DataSourceName } from './types'
const supported: Partial<Record<PlatformType, PlatformDefinition>> = {
[PlatformType.MEETINGS]: {
sources: [
{
name: DataSourceName.MEETINGS_MEETING_ATTENDANCE,
buildSourceQuery: meetingAttendanceBuildQuery,
transformer: new MeetingAttendanceTransformer(),
},
],
},
[PlatformType.CVENT]: {
sources: [
{
name: DataSourceName.CVENT_EVENT_REGISTRATIONS,
buildSourceQuery: cventBuildSourceQuery,
transformer: new CventTransformer(),
},
],
},
[PlatformType.TNC]: {
sources: [
{
name: DataSourceName.TNC_ENROLLMENTS,
buildSourceQuery: tncEnrollmentsBuildQuery,
transformer: new TncEnrollmentsTransformer(),
},
{
name: DataSourceName.TNC_CERTIFICATES,
buildSourceQuery: tncCertificatesBuildQuery,
transformer: new TncCertificatesTransformer(),
},
{
name: DataSourceName.TNC_COURSES,
buildSourceQuery: tncCoursesBuildQuery,
transformer: new TncCoursesTransformer(),
},
],
},
}
const enabled = (process.env.CROWD_SNOWFLAKE_ENABLED_PLATFORMS || '')
.split(',')
.map((s) => s.trim())
.filter(Boolean) as PlatformType[]
export function getPlatform(platform: PlatformType): PlatformDefinition {
if (!supported[platform]) {
throw new Error(`Unsupported platform: ${platform}`)
}
if (!enabled.includes(platform)) {
throw new Error(`Platform not enabled: ${platform} (enabled: ${enabled.join(', ')})`)
}
return supported[platform]
}
export function getDataSourceNames(platform: PlatformType): string[] {
return getPlatform(platform).sources.map((s) => s.name)
}
export function getDataSource(platform: PlatformType, sourceName: string): DataSource {
const def = getPlatform(platform)
const source = def.sources.find((s) => s.name === sourceName)
if (!source) {
throw new Error(`Unknown data source '${sourceName}' for platform '${platform}'`)
}
return source
}
export function getEnabledPlatforms(): PlatformType[] {
return enabled
}