@budibase/backend-core 3.2.4 → 3.2.6
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/index.js.map +1 -1
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +11 -4
- package/dist/plugins.js.meta.json +1 -1
- package/package.json +11 -4
- package/src/accounts/accounts.ts +0 -82
- package/src/accounts/api.ts +0 -59
- package/src/accounts/index.ts +0 -1
- package/src/auth/auth.ts +0 -210
- package/src/auth/index.ts +0 -1
- package/src/auth/tests/auth.spec.ts +0 -14
- package/src/blacklist/blacklist.ts +0 -54
- package/src/blacklist/index.ts +0 -1
- package/src/blacklist/tests/blacklist.spec.ts +0 -46
- package/src/cache/appMetadata.ts +0 -88
- package/src/cache/base/index.ts +0 -150
- package/src/cache/docWritethrough.ts +0 -105
- package/src/cache/generic.ts +0 -33
- package/src/cache/index.ts +0 -8
- package/src/cache/invite.ts +0 -86
- package/src/cache/passwordReset.ts +0 -49
- package/src/cache/tests/docWritethrough.spec.ts +0 -296
- package/src/cache/tests/user.spec.ts +0 -145
- package/src/cache/tests/writethrough.spec.ts +0 -139
- package/src/cache/user.ts +0 -154
- package/src/cache/writethrough.ts +0 -133
- package/src/configs/configs.ts +0 -263
- package/src/configs/index.ts +0 -1
- package/src/configs/tests/configs.spec.ts +0 -184
- package/src/constants/db.ts +0 -75
- package/src/constants/index.ts +0 -2
- package/src/constants/misc.ts +0 -36
- package/src/context/Context.ts +0 -14
- package/src/context/identity.ts +0 -58
- package/src/context/index.ts +0 -3
- package/src/context/mainContext.ts +0 -422
- package/src/context/tests/index.spec.ts +0 -255
- package/src/context/types.ts +0 -26
- package/src/db/Replication.ts +0 -94
- package/src/db/couch/DatabaseImpl.ts +0 -511
- package/src/db/couch/connections.ts +0 -89
- package/src/db/couch/index.ts +0 -4
- package/src/db/couch/pouchDB.ts +0 -97
- package/src/db/couch/pouchDump.ts +0 -0
- package/src/db/couch/tests/DatabaseImpl.spec.ts +0 -118
- package/src/db/couch/utils.ts +0 -55
- package/src/db/db.ts +0 -34
- package/src/db/errors.ts +0 -14
- package/src/db/index.ts +0 -12
- package/src/db/instrumentation.ts +0 -199
- package/src/db/lucene.ts +0 -721
- package/src/db/searchIndexes/index.ts +0 -1
- package/src/db/searchIndexes/searchIndexes.ts +0 -62
- package/src/db/tests/DatabaseImpl.spec.ts +0 -55
- package/src/db/tests/connections.spec.ts +0 -22
- package/src/db/tests/index.spec.ts +0 -32
- package/src/db/tests/lucene.spec.ts +0 -400
- package/src/db/tests/pouch.spec.js +0 -62
- package/src/db/tests/utils.spec.ts +0 -63
- package/src/db/utils.ts +0 -208
- package/src/db/views.ts +0 -245
- package/src/docIds/conversions.ts +0 -60
- package/src/docIds/ids.ts +0 -126
- package/src/docIds/index.ts +0 -2
- package/src/docIds/newid.ts +0 -5
- package/src/docIds/params.ts +0 -189
- package/src/docUpdates/index.ts +0 -24
- package/src/environment.ts +0 -293
- package/src/errors/errors.ts +0 -119
- package/src/errors/index.ts +0 -1
- package/src/events/analytics.ts +0 -6
- package/src/events/asyncEvents/index.ts +0 -2
- package/src/events/asyncEvents/publisher.ts +0 -12
- package/src/events/asyncEvents/queue.ts +0 -22
- package/src/events/backfill.ts +0 -183
- package/src/events/documentId.ts +0 -56
- package/src/events/events.ts +0 -47
- package/src/events/identification.ts +0 -311
- package/src/events/index.ts +0 -15
- package/src/events/processors/AnalyticsProcessor.ts +0 -64
- package/src/events/processors/AuditLogsProcessor.ts +0 -92
- package/src/events/processors/LoggingProcessor.ts +0 -36
- package/src/events/processors/Processors.ts +0 -52
- package/src/events/processors/async/DocumentUpdateProcessor.ts +0 -38
- package/src/events/processors/index.ts +0 -19
- package/src/events/processors/posthog/PosthogProcessor.ts +0 -118
- package/src/events/processors/posthog/index.ts +0 -3
- package/src/events/processors/posthog/rateLimiting.ts +0 -106
- package/src/events/processors/posthog/tests/PosthogProcessor.spec.ts +0 -164
- package/src/events/processors/types.ts +0 -1
- package/src/events/publishers/account.ts +0 -41
- package/src/events/publishers/ai.ts +0 -21
- package/src/events/publishers/app.ts +0 -168
- package/src/events/publishers/auditLog.ts +0 -26
- package/src/events/publishers/auth.ts +0 -73
- package/src/events/publishers/automation.ts +0 -110
- package/src/events/publishers/backfill.ts +0 -74
- package/src/events/publishers/backup.ts +0 -42
- package/src/events/publishers/datasource.ts +0 -48
- package/src/events/publishers/email.ts +0 -17
- package/src/events/publishers/environmentVariable.ts +0 -38
- package/src/events/publishers/group.ts +0 -99
- package/src/events/publishers/index.ts +0 -25
- package/src/events/publishers/installation.ts +0 -38
- package/src/events/publishers/layout.ts +0 -26
- package/src/events/publishers/license.ts +0 -84
- package/src/events/publishers/org.ts +0 -37
- package/src/events/publishers/plugin.ts +0 -47
- package/src/events/publishers/query.ts +0 -89
- package/src/events/publishers/role.ts +0 -62
- package/src/events/publishers/rows.ts +0 -29
- package/src/events/publishers/screen.ts +0 -36
- package/src/events/publishers/serve.ts +0 -43
- package/src/events/publishers/table.ts +0 -70
- package/src/events/publishers/user.ts +0 -202
- package/src/events/publishers/view.ts +0 -107
- package/src/features/features.ts +0 -277
- package/src/features/index.ts +0 -2
- package/src/features/tests/features.spec.ts +0 -267
- package/src/features/tests/utils.ts +0 -64
- package/src/helpers.ts +0 -9
- package/src/index.ts +0 -59
- package/src/installation.ts +0 -115
- package/src/logging/alerts.ts +0 -26
- package/src/logging/correlation/correlation.ts +0 -15
- package/src/logging/correlation/index.ts +0 -1
- package/src/logging/correlation/middleware.ts +0 -18
- package/src/logging/index.ts +0 -4
- package/src/logging/pino/logger.ts +0 -239
- package/src/logging/pino/middleware.ts +0 -48
- package/src/logging/system.ts +0 -81
- package/src/logging/tests/system.spec.ts +0 -61
- package/src/middleware/adminOnly.ts +0 -9
- package/src/middleware/auditLog.ts +0 -6
- package/src/middleware/authenticated.ts +0 -247
- package/src/middleware/builderOnly.ts +0 -21
- package/src/middleware/builderOrAdmin.ts +0 -21
- package/src/middleware/contentSecurityPolicy.ts +0 -113
- package/src/middleware/csrf.ts +0 -81
- package/src/middleware/errorHandling.ts +0 -43
- package/src/middleware/index.ts +0 -24
- package/src/middleware/internalApi.ts +0 -23
- package/src/middleware/ip.ts +0 -12
- package/src/middleware/joi-validator.ts +0 -58
- package/src/middleware/matchers.ts +0 -39
- package/src/middleware/passport/datasource/google.ts +0 -102
- package/src/middleware/passport/local.ts +0 -54
- package/src/middleware/passport/sso/google.ts +0 -77
- package/src/middleware/passport/sso/oidc.ts +0 -152
- package/src/middleware/passport/sso/sso.ts +0 -138
- package/src/middleware/passport/sso/tests/google.spec.ts +0 -68
- package/src/middleware/passport/sso/tests/oidc.spec.ts +0 -144
- package/src/middleware/passport/sso/tests/sso.spec.ts +0 -197
- package/src/middleware/passport/utils.ts +0 -38
- package/src/middleware/querystringToBody.ts +0 -28
- package/src/middleware/tenancy.ts +0 -36
- package/src/middleware/tests/builder.spec.ts +0 -181
- package/src/middleware/tests/contentSecurityPolicy.spec.ts +0 -75
- package/src/middleware/tests/matchers.spec.ts +0 -100
- package/src/migrations/definitions.ts +0 -40
- package/src/migrations/index.ts +0 -2
- package/src/migrations/migrations.ts +0 -186
- package/src/migrations/tests/__snapshots__/migrations.spec.ts.snap +0 -11
- package/src/migrations/tests/migrations.spec.ts +0 -64
- package/src/objectStore/buckets/app.ts +0 -53
- package/src/objectStore/buckets/global.ts +0 -29
- package/src/objectStore/buckets/index.ts +0 -3
- package/src/objectStore/buckets/plugins.ts +0 -71
- package/src/objectStore/buckets/tests/app.spec.ts +0 -161
- package/src/objectStore/buckets/tests/global.spec.ts +0 -74
- package/src/objectStore/buckets/tests/plugins.spec.ts +0 -111
- package/src/objectStore/cloudfront.ts +0 -41
- package/src/objectStore/index.ts +0 -3
- package/src/objectStore/objectStore.ts +0 -585
- package/src/objectStore/utils.ts +0 -113
- package/src/platform/index.ts +0 -3
- package/src/platform/platformDb.ts +0 -6
- package/src/platform/tenants.ts +0 -101
- package/src/platform/tests/tenants.spec.ts +0 -26
- package/src/platform/users.ts +0 -129
- package/src/plugin/index.ts +0 -1
- package/src/plugin/tests/validation.spec.ts +0 -209
- package/src/plugin/utils.ts +0 -175
- package/src/queue/constants.ts +0 -8
- package/src/queue/inMemoryQueue.ts +0 -189
- package/src/queue/index.ts +0 -2
- package/src/queue/listeners.ts +0 -199
- package/src/queue/queue.ts +0 -84
- package/src/redis/index.ts +0 -6
- package/src/redis/init.ts +0 -118
- package/src/redis/redis.ts +0 -358
- package/src/redis/redlockImpl.ts +0 -155
- package/src/redis/tests/redis.spec.ts +0 -207
- package/src/redis/tests/redlockImpl.spec.ts +0 -105
- package/src/redis/utils.ts +0 -128
- package/src/security/auth.ts +0 -24
- package/src/security/encryption.ts +0 -185
- package/src/security/index.ts +0 -1
- package/src/security/permissions.ts +0 -166
- package/src/security/roles.ts +0 -655
- package/src/security/secrets.ts +0 -20
- package/src/security/sessions.ts +0 -123
- package/src/security/tests/auth.spec.ts +0 -45
- package/src/security/tests/encryption.spec.ts +0 -31
- package/src/security/tests/permissions.spec.ts +0 -146
- package/src/security/tests/secrets.spec.ts +0 -35
- package/src/security/tests/sessions.spec.ts +0 -12
- package/src/sql/designDoc.ts +0 -17
- package/src/sql/index.ts +0 -5
- package/src/sql/sql.ts +0 -1854
- package/src/sql/sqlTable.ts +0 -319
- package/src/sql/utils.ts +0 -193
- package/src/tenancy/db.ts +0 -6
- package/src/tenancy/index.ts +0 -2
- package/src/tenancy/tenancy.ts +0 -148
- package/src/tenancy/tests/tenancy.spec.ts +0 -184
- package/src/timers/index.ts +0 -1
- package/src/timers/timers.ts +0 -22
- package/src/users/db.ts +0 -582
- package/src/users/events.ts +0 -176
- package/src/users/index.ts +0 -4
- package/src/users/lookup.ts +0 -99
- package/src/users/test/db.spec.ts +0 -188
- package/src/users/test/utils.spec.ts +0 -67
- package/src/users/users.ts +0 -353
- package/src/users/utils.ts +0 -81
- package/src/utils/Duration.ts +0 -56
- package/src/utils/hashing.ts +0 -15
- package/src/utils/index.ts +0 -4
- package/src/utils/stringUtils.ts +0 -8
- package/src/utils/tests/Duration.spec.ts +0 -19
- package/src/utils/tests/utils.spec.ts +0 -204
- package/src/utils/utils.ts +0 -249
- package/tests/core/logging.ts +0 -34
- package/tests/core/users/users.spec.js +0 -53
- package/tests/core/utilities/index.ts +0 -7
- package/tests/core/utilities/jestUtils.ts +0 -33
- package/tests/core/utilities/mocks/alerts.ts +0 -4
- package/tests/core/utilities/mocks/date.ts +0 -3
- package/tests/core/utilities/mocks/events.ts +0 -132
- package/tests/core/utilities/mocks/index.ts +0 -9
- package/tests/core/utilities/mocks/licenses.ts +0 -119
- package/tests/core/utilities/queue.ts +0 -9
- package/tests/core/utilities/structures/Chance.ts +0 -20
- package/tests/core/utilities/structures/accounts.ts +0 -80
- package/tests/core/utilities/structures/apps.ts +0 -21
- package/tests/core/utilities/structures/common.ts +0 -7
- package/tests/core/utilities/structures/db.ts +0 -12
- package/tests/core/utilities/structures/documents/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/index.ts +0 -1
- package/tests/core/utilities/structures/documents/platform/installation.ts +0 -12
- package/tests/core/utilities/structures/generator.ts +0 -3
- package/tests/core/utilities/structures/index.ts +0 -15
- package/tests/core/utilities/structures/koa.ts +0 -16
- package/tests/core/utilities/structures/licenses.ts +0 -190
- package/tests/core/utilities/structures/plugins.ts +0 -19
- package/tests/core/utilities/structures/quotas.ts +0 -72
- package/tests/core/utilities/structures/scim.ts +0 -80
- package/tests/core/utilities/structures/sso.ts +0 -118
- package/tests/core/utilities/structures/tenants.ts +0 -5
- package/tests/core/utilities/structures/userGroups.ts +0 -10
- package/tests/core/utilities/structures/users.ts +0 -89
- package/tests/core/utilities/testContainerUtils.ts +0 -165
- package/tests/core/utilities/utils/index.ts +0 -2
- package/tests/core/utilities/utils/queue.ts +0 -27
- package/tests/core/utilities/utils/time.ts +0 -3
- package/tests/extra/DBTestConfiguration.ts +0 -36
- package/tests/extra/index.ts +0 -2
- package/tests/extra/testEnv.ts +0 -95
- package/tests/index.ts +0 -2
- package/tests/jestEnv.ts +0 -10
- package/tests/jestSetup.ts +0 -36
package/src/events/backfill.ts
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Event,
|
|
3
|
-
BackfillMetadata,
|
|
4
|
-
CachedEvent,
|
|
5
|
-
SSOCreatedEvent,
|
|
6
|
-
AutomationCreatedEvent,
|
|
7
|
-
AutomationStepCreatedEvent,
|
|
8
|
-
DatasourceCreatedEvent,
|
|
9
|
-
LayoutCreatedEvent,
|
|
10
|
-
QueryCreatedEvent,
|
|
11
|
-
RoleCreatedEvent,
|
|
12
|
-
ScreenCreatedEvent,
|
|
13
|
-
TableCreatedEvent,
|
|
14
|
-
ViewCreatedEvent,
|
|
15
|
-
ViewCalculationCreatedEvent,
|
|
16
|
-
ViewFilterCreatedEvent,
|
|
17
|
-
AppPublishedEvent,
|
|
18
|
-
UserCreatedEvent,
|
|
19
|
-
RoleAssignedEvent,
|
|
20
|
-
UserPermissionAssignedEvent,
|
|
21
|
-
AppCreatedEvent,
|
|
22
|
-
} from "@budibase/types"
|
|
23
|
-
import * as context from "../context"
|
|
24
|
-
import { CacheKey } from "../cache/generic"
|
|
25
|
-
import * as cache from "../cache/generic"
|
|
26
|
-
|
|
27
|
-
// LIFECYCLE
|
|
28
|
-
|
|
29
|
-
export const start = async (events: Event[]) => {
|
|
30
|
-
const metadata: BackfillMetadata = {
|
|
31
|
-
eventWhitelist: events,
|
|
32
|
-
}
|
|
33
|
-
return saveBackfillMetadata(metadata)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const recordEvent = async (event: Event, properties: any) => {
|
|
37
|
-
const eventKey = getEventKey(event, properties)
|
|
38
|
-
// don't use a ttl - cleaned up by migration
|
|
39
|
-
// don't use tenancy - already in the key
|
|
40
|
-
await cache.store(eventKey, properties, undefined, { useTenancy: false })
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export const end = async () => {
|
|
44
|
-
await deleteBackfillMetadata()
|
|
45
|
-
await clearEvents()
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// CRUD
|
|
49
|
-
|
|
50
|
-
const getBackfillMetadata = async (): Promise<BackfillMetadata | null> => {
|
|
51
|
-
return cache.get(CacheKey.BACKFILL_METADATA)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const saveBackfillMetadata = async (
|
|
55
|
-
backfill: BackfillMetadata
|
|
56
|
-
): Promise<void> => {
|
|
57
|
-
// no TTL - deleted by backfill
|
|
58
|
-
return cache.store(CacheKey.BACKFILL_METADATA, backfill)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const deleteBackfillMetadata = async (): Promise<void> => {
|
|
62
|
-
await cache.destroy(CacheKey.BACKFILL_METADATA)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const clearEvents = async () => {
|
|
66
|
-
// wildcard
|
|
67
|
-
const pattern = getEventKey()
|
|
68
|
-
const keys = await cache.keys(pattern)
|
|
69
|
-
|
|
70
|
-
for (const key of keys) {
|
|
71
|
-
// delete each key
|
|
72
|
-
// don't use tenancy, already in the key
|
|
73
|
-
await cache.destroy(key, { useTenancy: false })
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// HELPERS
|
|
78
|
-
|
|
79
|
-
export const isBackfillingEvent = async (event: Event) => {
|
|
80
|
-
const backfill = await getBackfillMetadata()
|
|
81
|
-
const events = backfill?.eventWhitelist
|
|
82
|
-
if (events && events.includes(event)) {
|
|
83
|
-
return true
|
|
84
|
-
} else {
|
|
85
|
-
return false
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export const isAlreadySent = async (event: Event, properties: any) => {
|
|
90
|
-
const eventKey = getEventKey(event, properties)
|
|
91
|
-
const cachedEvent: CachedEvent = await cache.get(eventKey, {
|
|
92
|
-
useTenancy: false,
|
|
93
|
-
})
|
|
94
|
-
return !!cachedEvent
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const CUSTOM_PROPERTY_SUFFIX: any = {
|
|
98
|
-
// APP EVENTS
|
|
99
|
-
[Event.AUTOMATION_CREATED]: (properties: AutomationCreatedEvent) => {
|
|
100
|
-
return properties.automationId
|
|
101
|
-
},
|
|
102
|
-
[Event.AUTOMATION_STEP_CREATED]: (properties: AutomationStepCreatedEvent) => {
|
|
103
|
-
return properties.stepId
|
|
104
|
-
},
|
|
105
|
-
[Event.DATASOURCE_CREATED]: (properties: DatasourceCreatedEvent) => {
|
|
106
|
-
return properties.datasourceId
|
|
107
|
-
},
|
|
108
|
-
[Event.LAYOUT_CREATED]: (properties: LayoutCreatedEvent) => {
|
|
109
|
-
return properties.layoutId
|
|
110
|
-
},
|
|
111
|
-
[Event.QUERY_CREATED]: (properties: QueryCreatedEvent) => {
|
|
112
|
-
return properties.queryId
|
|
113
|
-
},
|
|
114
|
-
[Event.ROLE_CREATED]: (properties: RoleCreatedEvent) => {
|
|
115
|
-
return properties.roleId
|
|
116
|
-
},
|
|
117
|
-
[Event.SCREEN_CREATED]: (properties: ScreenCreatedEvent) => {
|
|
118
|
-
return properties.screenId
|
|
119
|
-
},
|
|
120
|
-
[Event.TABLE_CREATED]: (properties: TableCreatedEvent) => {
|
|
121
|
-
return properties.tableId
|
|
122
|
-
},
|
|
123
|
-
[Event.VIEW_CREATED]: (properties: ViewCreatedEvent) => {
|
|
124
|
-
return properties.tableId // best uniqueness
|
|
125
|
-
},
|
|
126
|
-
[Event.VIEW_CALCULATION_CREATED]: (
|
|
127
|
-
properties: ViewCalculationCreatedEvent
|
|
128
|
-
) => {
|
|
129
|
-
return properties.tableId // best uniqueness
|
|
130
|
-
},
|
|
131
|
-
[Event.VIEW_FILTER_CREATED]: (properties: ViewFilterCreatedEvent) => {
|
|
132
|
-
return properties.tableId // best uniqueness
|
|
133
|
-
},
|
|
134
|
-
[Event.APP_CREATED]: (properties: AppCreatedEvent) => {
|
|
135
|
-
return properties.appId // best uniqueness
|
|
136
|
-
},
|
|
137
|
-
[Event.APP_PUBLISHED]: (properties: AppPublishedEvent) => {
|
|
138
|
-
return properties.appId // best uniqueness
|
|
139
|
-
},
|
|
140
|
-
// GLOBAL EVENTS
|
|
141
|
-
[Event.AUTH_SSO_CREATED]: (properties: SSOCreatedEvent) => {
|
|
142
|
-
return properties.type
|
|
143
|
-
},
|
|
144
|
-
[Event.AUTH_SSO_ACTIVATED]: (properties: SSOCreatedEvent) => {
|
|
145
|
-
return properties.type
|
|
146
|
-
},
|
|
147
|
-
[Event.USER_CREATED]: (properties: UserCreatedEvent) => {
|
|
148
|
-
return properties.userId
|
|
149
|
-
},
|
|
150
|
-
[Event.USER_PERMISSION_ADMIN_ASSIGNED]: (
|
|
151
|
-
properties: UserPermissionAssignedEvent
|
|
152
|
-
) => {
|
|
153
|
-
return properties.userId
|
|
154
|
-
},
|
|
155
|
-
[Event.USER_PERMISSION_BUILDER_ASSIGNED]: (
|
|
156
|
-
properties: UserPermissionAssignedEvent
|
|
157
|
-
) => {
|
|
158
|
-
return properties.userId
|
|
159
|
-
},
|
|
160
|
-
[Event.ROLE_ASSIGNED]: (properties: RoleAssignedEvent) => {
|
|
161
|
-
return `${properties.roleId}-${properties.userId}`
|
|
162
|
-
},
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const getEventKey = (event?: Event, properties?: any) => {
|
|
166
|
-
let eventKey: string
|
|
167
|
-
|
|
168
|
-
const tenantId = context.getTenantId()
|
|
169
|
-
if (event) {
|
|
170
|
-
eventKey = `${CacheKey.EVENTS}:${tenantId}:${event}`
|
|
171
|
-
|
|
172
|
-
// use some properties to make the key more unique
|
|
173
|
-
const custom = CUSTOM_PROPERTY_SUFFIX[event]
|
|
174
|
-
const suffix = custom ? custom(properties) : undefined
|
|
175
|
-
if (suffix) {
|
|
176
|
-
eventKey = `${eventKey}:${suffix}`
|
|
177
|
-
}
|
|
178
|
-
} else {
|
|
179
|
-
eventKey = `${CacheKey.EVENTS}:${tenantId}:*`
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
return eventKey
|
|
183
|
-
}
|
package/src/events/documentId.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Event,
|
|
3
|
-
UserCreatedEvent,
|
|
4
|
-
UserUpdatedEvent,
|
|
5
|
-
UserDeletedEvent,
|
|
6
|
-
UserPermissionAssignedEvent,
|
|
7
|
-
UserPermissionRemovedEvent,
|
|
8
|
-
GroupCreatedEvent,
|
|
9
|
-
GroupUpdatedEvent,
|
|
10
|
-
GroupDeletedEvent,
|
|
11
|
-
GroupUsersAddedEvent,
|
|
12
|
-
GroupUsersDeletedEvent,
|
|
13
|
-
GroupPermissionsEditedEvent,
|
|
14
|
-
} from "@budibase/types"
|
|
15
|
-
|
|
16
|
-
const getEventProperties: Record<
|
|
17
|
-
string,
|
|
18
|
-
(properties: any) => string | undefined
|
|
19
|
-
> = {
|
|
20
|
-
[Event.USER_CREATED]: (properties: UserCreatedEvent) => properties.userId,
|
|
21
|
-
[Event.USER_UPDATED]: (properties: UserUpdatedEvent) => properties.userId,
|
|
22
|
-
[Event.USER_DELETED]: (properties: UserDeletedEvent) => properties.userId,
|
|
23
|
-
[Event.USER_PERMISSION_ADMIN_ASSIGNED]: (
|
|
24
|
-
properties: UserPermissionAssignedEvent
|
|
25
|
-
) => properties.userId,
|
|
26
|
-
[Event.USER_PERMISSION_ADMIN_REMOVED]: (
|
|
27
|
-
properties: UserPermissionRemovedEvent
|
|
28
|
-
) => properties.userId,
|
|
29
|
-
[Event.USER_PERMISSION_BUILDER_ASSIGNED]: (
|
|
30
|
-
properties: UserPermissionAssignedEvent
|
|
31
|
-
) => properties.userId,
|
|
32
|
-
[Event.USER_PERMISSION_BUILDER_REMOVED]: (
|
|
33
|
-
properties: UserPermissionRemovedEvent
|
|
34
|
-
) => properties.userId,
|
|
35
|
-
[Event.USER_GROUP_CREATED]: (properties: GroupCreatedEvent) =>
|
|
36
|
-
properties.groupId,
|
|
37
|
-
[Event.USER_GROUP_UPDATED]: (properties: GroupUpdatedEvent) =>
|
|
38
|
-
properties.groupId,
|
|
39
|
-
[Event.USER_GROUP_DELETED]: (properties: GroupDeletedEvent) =>
|
|
40
|
-
properties.groupId,
|
|
41
|
-
[Event.USER_GROUP_USERS_ADDED]: (properties: GroupUsersAddedEvent) =>
|
|
42
|
-
properties.groupId,
|
|
43
|
-
[Event.USER_GROUP_USERS_REMOVED]: (properties: GroupUsersDeletedEvent) =>
|
|
44
|
-
properties.groupId,
|
|
45
|
-
[Event.USER_GROUP_PERMISSIONS_EDITED]: (
|
|
46
|
-
properties: GroupPermissionsEditedEvent
|
|
47
|
-
) => properties.groupId,
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getDocumentId(event: Event, properties: any) {
|
|
51
|
-
const extractor = getEventProperties[event]
|
|
52
|
-
if (!extractor) {
|
|
53
|
-
throw new Error("Event does not have a method of document ID extraction")
|
|
54
|
-
}
|
|
55
|
-
return extractor(properties)
|
|
56
|
-
}
|
package/src/events/events.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Event, Identity } from "@budibase/types"
|
|
2
|
-
import { processors } from "./processors"
|
|
3
|
-
import identification from "./identification"
|
|
4
|
-
import * as backfill from "./backfill"
|
|
5
|
-
import { publishAsyncEvent } from "./asyncEvents"
|
|
6
|
-
|
|
7
|
-
export const publishEvent = async (
|
|
8
|
-
event: Event,
|
|
9
|
-
properties: any,
|
|
10
|
-
timestamp?: string | number,
|
|
11
|
-
identityOverride?: Identity
|
|
12
|
-
) => {
|
|
13
|
-
// in future this should use async events via a distributed queue.
|
|
14
|
-
const identity =
|
|
15
|
-
identityOverride || (await identification.getCurrentIdentity())
|
|
16
|
-
|
|
17
|
-
// Backfilling is get from the user cache, but when we override the identity cache is not available. Overrides are
|
|
18
|
-
// normally performed in automatic actions or operations in async flows (BPM) where the user session is not available.
|
|
19
|
-
const backfilling = identityOverride
|
|
20
|
-
? false
|
|
21
|
-
: await backfill.isBackfillingEvent(event)
|
|
22
|
-
|
|
23
|
-
// no backfill - send the event and exit
|
|
24
|
-
if (!backfilling) {
|
|
25
|
-
// send off async events if required
|
|
26
|
-
await publishAsyncEvent({
|
|
27
|
-
event,
|
|
28
|
-
identity,
|
|
29
|
-
properties,
|
|
30
|
-
timestamp,
|
|
31
|
-
})
|
|
32
|
-
// now handle the main sync event processing pipeline
|
|
33
|
-
await processors.processEvent(event, identity, properties, timestamp)
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// backfill active - check if the event has been sent already
|
|
38
|
-
const alreadySent = await backfill.isAlreadySent(event, properties)
|
|
39
|
-
if (alreadySent) {
|
|
40
|
-
// do nothing
|
|
41
|
-
return
|
|
42
|
-
} else {
|
|
43
|
-
// send and record the event
|
|
44
|
-
await processors.processEvent(event, identity, properties, timestamp)
|
|
45
|
-
await backfill.recordEvent(event, properties)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import * as context from "../context"
|
|
2
|
-
import * as identityCtx from "../context/identity"
|
|
3
|
-
import env from "../environment"
|
|
4
|
-
import {
|
|
5
|
-
Hosting,
|
|
6
|
-
User,
|
|
7
|
-
Identity,
|
|
8
|
-
IdentityType,
|
|
9
|
-
Account,
|
|
10
|
-
isCloudAccount,
|
|
11
|
-
isSSOAccount,
|
|
12
|
-
TenantGroup,
|
|
13
|
-
CloudAccount,
|
|
14
|
-
UserIdentity,
|
|
15
|
-
InstallationGroup,
|
|
16
|
-
UserContext,
|
|
17
|
-
Group,
|
|
18
|
-
isSSOUser,
|
|
19
|
-
} from "@budibase/types"
|
|
20
|
-
import { processors } from "./processors"
|
|
21
|
-
import { newid } from "../utils"
|
|
22
|
-
import * as installation from "../installation"
|
|
23
|
-
import * as configs from "../configs"
|
|
24
|
-
import * as users from "../users"
|
|
25
|
-
import { withCache, TTL, CacheKey } from "../cache/generic"
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* An identity can be:
|
|
29
|
-
* - account user (Self host)
|
|
30
|
-
* - budibase user
|
|
31
|
-
* - tenant
|
|
32
|
-
* - installation
|
|
33
|
-
*/
|
|
34
|
-
const getCurrentIdentity = async (): Promise<Identity> => {
|
|
35
|
-
let identityContext = identityCtx.getIdentity()
|
|
36
|
-
const environment = getDeploymentEnvironment()
|
|
37
|
-
|
|
38
|
-
let identityType
|
|
39
|
-
|
|
40
|
-
if (!identityContext) {
|
|
41
|
-
identityType = IdentityType.TENANT
|
|
42
|
-
} else {
|
|
43
|
-
identityType = identityContext.type
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (identityType === IdentityType.INSTALLATION) {
|
|
47
|
-
const installationId = await getInstallationId()
|
|
48
|
-
const hosting = getHostingFromEnv()
|
|
49
|
-
return {
|
|
50
|
-
id: formatDistinctId(installationId, identityType),
|
|
51
|
-
hosting,
|
|
52
|
-
type: identityType,
|
|
53
|
-
installationId,
|
|
54
|
-
environment,
|
|
55
|
-
}
|
|
56
|
-
} else if (identityType === IdentityType.TENANT) {
|
|
57
|
-
const installationId = await getInstallationId()
|
|
58
|
-
const tenantId = await getEventTenantId(context.getTenantId())
|
|
59
|
-
const hosting = getHostingFromEnv()
|
|
60
|
-
|
|
61
|
-
return {
|
|
62
|
-
id: formatDistinctId(tenantId, identityType),
|
|
63
|
-
type: identityType,
|
|
64
|
-
hosting,
|
|
65
|
-
installationId,
|
|
66
|
-
tenantId,
|
|
67
|
-
realTenantId: context.getTenantId(),
|
|
68
|
-
environment,
|
|
69
|
-
}
|
|
70
|
-
} else if (identityType === IdentityType.USER) {
|
|
71
|
-
const userContext = identityContext as UserContext
|
|
72
|
-
const tenantId = await getEventTenantId(context.getTenantId())
|
|
73
|
-
const installationId = await getInstallationId()
|
|
74
|
-
|
|
75
|
-
const account = userContext.account
|
|
76
|
-
let hosting
|
|
77
|
-
if (account) {
|
|
78
|
-
hosting = account.hosting
|
|
79
|
-
} else {
|
|
80
|
-
hosting = getHostingFromEnv()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
id: userContext._id,
|
|
85
|
-
type: identityType,
|
|
86
|
-
hosting,
|
|
87
|
-
installationId,
|
|
88
|
-
tenantId,
|
|
89
|
-
environment,
|
|
90
|
-
realTenantId: context.getTenantId(),
|
|
91
|
-
hostInfo: userContext.hostInfo,
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
throw new Error("Unknown identity type")
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const identifyInstallationGroup = async (
|
|
99
|
-
installId: string,
|
|
100
|
-
timestamp?: string | number
|
|
101
|
-
): Promise<void> => {
|
|
102
|
-
const id = installId
|
|
103
|
-
const type = IdentityType.INSTALLATION
|
|
104
|
-
const hosting = getHostingFromEnv()
|
|
105
|
-
const version = env.VERSION
|
|
106
|
-
const environment = getDeploymentEnvironment()
|
|
107
|
-
|
|
108
|
-
const group: InstallationGroup = {
|
|
109
|
-
id,
|
|
110
|
-
type,
|
|
111
|
-
hosting,
|
|
112
|
-
version,
|
|
113
|
-
environment,
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
await identifyGroup(group, timestamp)
|
|
117
|
-
// need to create a normal identity for the group to be able to query it globally
|
|
118
|
-
// match the posthog syntax to link this identity to the empty auto generated one
|
|
119
|
-
await identify({ ...group, id: `$${type}_${id}` }, timestamp)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const identifyTenantGroup = async (
|
|
123
|
-
tenantId: string,
|
|
124
|
-
account: Account | undefined,
|
|
125
|
-
timestamp?: string | number
|
|
126
|
-
): Promise<void> => {
|
|
127
|
-
const id = await getEventTenantId(tenantId)
|
|
128
|
-
const type = IdentityType.TENANT
|
|
129
|
-
const installationId = await getInstallationId()
|
|
130
|
-
const environment = getDeploymentEnvironment()
|
|
131
|
-
|
|
132
|
-
let hosting: Hosting
|
|
133
|
-
let profession: string | undefined
|
|
134
|
-
let companySize: string | undefined
|
|
135
|
-
|
|
136
|
-
if (account) {
|
|
137
|
-
profession = account.profession
|
|
138
|
-
companySize = account.size
|
|
139
|
-
hosting = account.hosting
|
|
140
|
-
} else {
|
|
141
|
-
hosting = getHostingFromEnv()
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const group: TenantGroup = {
|
|
145
|
-
id,
|
|
146
|
-
type,
|
|
147
|
-
hosting,
|
|
148
|
-
environment,
|
|
149
|
-
installationId,
|
|
150
|
-
profession,
|
|
151
|
-
companySize,
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
await identifyGroup(group, timestamp)
|
|
155
|
-
// need to create a normal identity for the group to be able to query it globally
|
|
156
|
-
// match the posthog syntax to link this identity to the auto generated one
|
|
157
|
-
await identify({ ...group, id: `$${type}_${id}` }, timestamp)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const identifyUser = async (
|
|
161
|
-
user: User,
|
|
162
|
-
account: CloudAccount | undefined,
|
|
163
|
-
timestamp?: string | number
|
|
164
|
-
) => {
|
|
165
|
-
const id = user._id as string
|
|
166
|
-
const tenantId = await getEventTenantId(user.tenantId)
|
|
167
|
-
const type = IdentityType.USER
|
|
168
|
-
let builder = users.hasBuilderPermissions(user)
|
|
169
|
-
let admin = users.hasAdminPermissions(user)
|
|
170
|
-
let providerType
|
|
171
|
-
if (isSSOUser(user)) {
|
|
172
|
-
providerType = user.providerType
|
|
173
|
-
}
|
|
174
|
-
const accountHolder = await users.getExistingAccounts([user.email])
|
|
175
|
-
const isAccountHolder = accountHolder.length > 0
|
|
176
|
-
const verified = !!account && isAccountHolder && account.verified
|
|
177
|
-
const installationId = await getInstallationId()
|
|
178
|
-
const hosting = account ? account.hosting : getHostingFromEnv()
|
|
179
|
-
const environment = getDeploymentEnvironment()
|
|
180
|
-
|
|
181
|
-
const identity: UserIdentity = {
|
|
182
|
-
id,
|
|
183
|
-
type,
|
|
184
|
-
hosting,
|
|
185
|
-
installationId,
|
|
186
|
-
tenantId,
|
|
187
|
-
verified,
|
|
188
|
-
accountHolder: isAccountHolder,
|
|
189
|
-
providerType,
|
|
190
|
-
builder,
|
|
191
|
-
admin,
|
|
192
|
-
environment,
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
await identify(identity, timestamp)
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
const identifyAccount = async (account: Account) => {
|
|
199
|
-
let id = account.accountId
|
|
200
|
-
const tenantId = account.tenantId
|
|
201
|
-
let type = IdentityType.USER
|
|
202
|
-
let providerType = isSSOAccount(account) ? account.providerType : undefined
|
|
203
|
-
const verified = account.verified
|
|
204
|
-
const accountHolder = true
|
|
205
|
-
const hosting = account.hosting
|
|
206
|
-
const installationId = await getInstallationId()
|
|
207
|
-
const environment = getDeploymentEnvironment()
|
|
208
|
-
|
|
209
|
-
if (isCloudAccount(account)) {
|
|
210
|
-
const user = await users.getGlobalUserByEmail(account.email)
|
|
211
|
-
if (user?._id) {
|
|
212
|
-
// use the budibase user as the id if set
|
|
213
|
-
id = user._id
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const identity: UserIdentity = {
|
|
218
|
-
id,
|
|
219
|
-
type,
|
|
220
|
-
hosting,
|
|
221
|
-
installationId,
|
|
222
|
-
tenantId,
|
|
223
|
-
providerType,
|
|
224
|
-
verified,
|
|
225
|
-
accountHolder,
|
|
226
|
-
environment,
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
await identify(identity)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const identify = async (identity: Identity, timestamp?: string | number) => {
|
|
233
|
-
await processors.identify(identity, timestamp)
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
const identifyGroup = async (group: Group, timestamp?: string | number) => {
|
|
237
|
-
await processors.identifyGroup(group, timestamp)
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
const getDeploymentEnvironment = () => {
|
|
241
|
-
if (env.isDev()) {
|
|
242
|
-
return "development"
|
|
243
|
-
} else {
|
|
244
|
-
return env.DEPLOYMENT_ENVIRONMENT
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const getHostingFromEnv = () => {
|
|
249
|
-
return env.SELF_HOSTED ? Hosting.SELF : Hosting.CLOUD
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
const getInstallationId = async () => {
|
|
253
|
-
if (isAccountPortal()) {
|
|
254
|
-
return "account-portal"
|
|
255
|
-
}
|
|
256
|
-
const install = await installation.getInstall()
|
|
257
|
-
return install.installId
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const getEventTenantId = async (tenantId: string): Promise<string> => {
|
|
261
|
-
if (env.SELF_HOSTED) {
|
|
262
|
-
return getUniqueTenantId(tenantId)
|
|
263
|
-
} else {
|
|
264
|
-
// tenant id's in the cloud are already unique
|
|
265
|
-
return tenantId
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export const getUniqueTenantId = async (tenantId: string): Promise<string> => {
|
|
270
|
-
// make sure this tenantId always matches the tenantId in context
|
|
271
|
-
return context.doInTenant(tenantId, () => {
|
|
272
|
-
return withCache(CacheKey.UNIQUE_TENANT_ID, TTL.ONE_DAY, async () => {
|
|
273
|
-
const db = context.getGlobalDB()
|
|
274
|
-
const config = await configs.getSettingsConfigDoc()
|
|
275
|
-
|
|
276
|
-
let uniqueTenantId: string
|
|
277
|
-
if (config.config.uniqueTenantId) {
|
|
278
|
-
return config.config.uniqueTenantId
|
|
279
|
-
} else {
|
|
280
|
-
uniqueTenantId = `${newid()}_${tenantId}`
|
|
281
|
-
config.config.uniqueTenantId = uniqueTenantId
|
|
282
|
-
await db.put(config)
|
|
283
|
-
return uniqueTenantId
|
|
284
|
-
}
|
|
285
|
-
})
|
|
286
|
-
})
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const isAccountPortal = () => {
|
|
290
|
-
return env.SERVICE === "account-portal"
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const formatDistinctId = (id: string, type: IdentityType) => {
|
|
294
|
-
if (type === IdentityType.INSTALLATION || type === IdentityType.TENANT) {
|
|
295
|
-
return `$${type}_${id}`
|
|
296
|
-
} else {
|
|
297
|
-
return id
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
export default {
|
|
302
|
-
getCurrentIdentity,
|
|
303
|
-
identifyInstallationGroup,
|
|
304
|
-
identifyTenantGroup,
|
|
305
|
-
identifyUser,
|
|
306
|
-
identifyAccount,
|
|
307
|
-
identify,
|
|
308
|
-
identifyGroup,
|
|
309
|
-
getInstallationId,
|
|
310
|
-
getUniqueTenantId,
|
|
311
|
-
}
|
package/src/events/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export * from "./publishers"
|
|
2
|
-
export * as processors from "./processors"
|
|
3
|
-
export * as analytics from "./analytics"
|
|
4
|
-
export { default as identification } from "./identification"
|
|
5
|
-
export * as backfillCache from "./backfill"
|
|
6
|
-
export { publishEvent } from "./events"
|
|
7
|
-
|
|
8
|
-
import { processors } from "./processors"
|
|
9
|
-
|
|
10
|
-
export function initAsyncEvents() {}
|
|
11
|
-
|
|
12
|
-
export const shutdown = () => {
|
|
13
|
-
processors.shutdown()
|
|
14
|
-
console.log("Events shutdown")
|
|
15
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Event, Identity, Group, IdentityType } from "@budibase/types"
|
|
2
|
-
import { EventProcessor } from "./types"
|
|
3
|
-
import env from "../../environment"
|
|
4
|
-
import * as analytics from "../analytics"
|
|
5
|
-
import PosthogProcessor from "./posthog"
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Events that are always captured.
|
|
9
|
-
*/
|
|
10
|
-
const EVENT_WHITELIST = [
|
|
11
|
-
Event.INSTALLATION_VERSION_UPGRADED,
|
|
12
|
-
Event.INSTALLATION_VERSION_DOWNGRADED,
|
|
13
|
-
]
|
|
14
|
-
const IDENTITY_WHITELIST = [IdentityType.INSTALLATION, IdentityType.TENANT]
|
|
15
|
-
|
|
16
|
-
export default class AnalyticsProcessor implements EventProcessor {
|
|
17
|
-
posthog: PosthogProcessor | undefined
|
|
18
|
-
|
|
19
|
-
constructor() {
|
|
20
|
-
if (env.POSTHOG_TOKEN && !env.isTest()) {
|
|
21
|
-
this.posthog = new PosthogProcessor(env.POSTHOG_TOKEN)
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async processEvent(
|
|
26
|
-
event: Event,
|
|
27
|
-
identity: Identity,
|
|
28
|
-
properties: any,
|
|
29
|
-
timestamp?: string | number
|
|
30
|
-
): Promise<void> {
|
|
31
|
-
if (!EVENT_WHITELIST.includes(event) && !(await analytics.enabled())) {
|
|
32
|
-
return
|
|
33
|
-
}
|
|
34
|
-
if (this.posthog) {
|
|
35
|
-
await this.posthog.processEvent(event, identity, properties, timestamp)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async identify(identity: Identity, timestamp?: string | number) {
|
|
40
|
-
// Group indentifications (tenant and installation) always on
|
|
41
|
-
if (
|
|
42
|
-
!IDENTITY_WHITELIST.includes(identity.type) &&
|
|
43
|
-
!(await analytics.enabled())
|
|
44
|
-
) {
|
|
45
|
-
return
|
|
46
|
-
}
|
|
47
|
-
if (this.posthog) {
|
|
48
|
-
await this.posthog.identify(identity, timestamp)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
async identifyGroup(group: Group, timestamp?: string | number) {
|
|
53
|
-
// Group indentifications (tenant and installation) always on
|
|
54
|
-
if (this.posthog) {
|
|
55
|
-
await this.posthog.identifyGroup(group, timestamp)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
shutdown() {
|
|
60
|
-
if (this.posthog) {
|
|
61
|
-
this.posthog.shutdown()
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|