Add deployment environment to identities
This commit is contained in:
parent
cb9550734f
commit
7283e01442
|
@ -35,6 +35,7 @@ const pkg = require("../../package.json")
|
||||||
*/
|
*/
|
||||||
export const getCurrentIdentity = async (): Promise<Identity> => {
|
export const getCurrentIdentity = async (): Promise<Identity> => {
|
||||||
let identityContext = identityCtx.getIdentity()
|
let identityContext = identityCtx.getIdentity()
|
||||||
|
const environment = getDeploymentEnvironment()
|
||||||
|
|
||||||
let identityType
|
let identityType
|
||||||
|
|
||||||
|
@ -52,6 +53,7 @@ export const getCurrentIdentity = async (): Promise<Identity> => {
|
||||||
hosting,
|
hosting,
|
||||||
type: identityType,
|
type: identityType,
|
||||||
installationId,
|
installationId,
|
||||||
|
environment,
|
||||||
}
|
}
|
||||||
} else if (identityType === IdentityType.TENANT) {
|
} else if (identityType === IdentityType.TENANT) {
|
||||||
const installationId = await getInstallationId()
|
const installationId = await getInstallationId()
|
||||||
|
@ -64,6 +66,7 @@ export const getCurrentIdentity = async (): Promise<Identity> => {
|
||||||
hosting,
|
hosting,
|
||||||
installationId,
|
installationId,
|
||||||
tenantId,
|
tenantId,
|
||||||
|
environment,
|
||||||
}
|
}
|
||||||
} else if (identityType === IdentityType.USER) {
|
} else if (identityType === IdentityType.USER) {
|
||||||
const userContext = identityContext as UserContext
|
const userContext = identityContext as UserContext
|
||||||
|
@ -84,6 +87,7 @@ export const getCurrentIdentity = async (): Promise<Identity> => {
|
||||||
hosting,
|
hosting,
|
||||||
installationId,
|
installationId,
|
||||||
tenantId,
|
tenantId,
|
||||||
|
environment,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new Error("Unknown identity type")
|
throw new Error("Unknown identity type")
|
||||||
|
@ -98,12 +102,14 @@ export const identifyInstallationGroup = async (
|
||||||
const type = IdentityType.INSTALLATION
|
const type = IdentityType.INSTALLATION
|
||||||
const hosting = getHostingFromEnv()
|
const hosting = getHostingFromEnv()
|
||||||
const version = pkg.version
|
const version = pkg.version
|
||||||
|
const environment = getDeploymentEnvironment()
|
||||||
|
|
||||||
const group: InstallationGroup = {
|
const group: InstallationGroup = {
|
||||||
id,
|
id,
|
||||||
type,
|
type,
|
||||||
hosting,
|
hosting,
|
||||||
version,
|
version,
|
||||||
|
environment,
|
||||||
}
|
}
|
||||||
|
|
||||||
await identifyGroup(group, timestamp)
|
await identifyGroup(group, timestamp)
|
||||||
|
@ -120,6 +126,7 @@ export const identifyTenantGroup = async (
|
||||||
const id = await getEventTenantId(tenantId)
|
const id = await getEventTenantId(tenantId)
|
||||||
const type = IdentityType.TENANT
|
const type = IdentityType.TENANT
|
||||||
const installationId = await getInstallationId()
|
const installationId = await getInstallationId()
|
||||||
|
const environment = getDeploymentEnvironment()
|
||||||
|
|
||||||
let hosting: Hosting
|
let hosting: Hosting
|
||||||
let profession: string | undefined
|
let profession: string | undefined
|
||||||
|
@ -137,6 +144,7 @@ export const identifyTenantGroup = async (
|
||||||
id,
|
id,
|
||||||
type,
|
type,
|
||||||
hosting,
|
hosting,
|
||||||
|
environment,
|
||||||
installationId,
|
installationId,
|
||||||
profession,
|
profession,
|
||||||
companySize,
|
companySize,
|
||||||
|
@ -164,6 +172,7 @@ export const identifyUser = async (
|
||||||
account && account?.budibaseUserId === user._id ? account.verified : false
|
account && account?.budibaseUserId === user._id ? account.verified : false
|
||||||
const installationId = await getInstallationId()
|
const installationId = await getInstallationId()
|
||||||
const hosting = account ? account.hosting : getHostingFromEnv()
|
const hosting = account ? account.hosting : getHostingFromEnv()
|
||||||
|
const environment = getDeploymentEnvironment()
|
||||||
|
|
||||||
const identity: UserIdentity = {
|
const identity: UserIdentity = {
|
||||||
id,
|
id,
|
||||||
|
@ -176,6 +185,7 @@ export const identifyUser = async (
|
||||||
providerType,
|
providerType,
|
||||||
builder,
|
builder,
|
||||||
admin,
|
admin,
|
||||||
|
environment,
|
||||||
}
|
}
|
||||||
|
|
||||||
await identify(identity, timestamp)
|
await identify(identity, timestamp)
|
||||||
|
@ -190,6 +200,7 @@ export const identifyAccount = async (account: Account) => {
|
||||||
const accountHolder = true
|
const accountHolder = true
|
||||||
const hosting = account.hosting
|
const hosting = account.hosting
|
||||||
const installationId = await getInstallationId()
|
const installationId = await getInstallationId()
|
||||||
|
const environment = getDeploymentEnvironment()
|
||||||
|
|
||||||
if (isCloudAccount(account)) {
|
if (isCloudAccount(account)) {
|
||||||
if (account.budibaseUserId) {
|
if (account.budibaseUserId) {
|
||||||
|
@ -207,6 +218,7 @@ export const identifyAccount = async (account: Account) => {
|
||||||
providerType,
|
providerType,
|
||||||
verified,
|
verified,
|
||||||
accountHolder,
|
accountHolder,
|
||||||
|
environment,
|
||||||
}
|
}
|
||||||
|
|
||||||
await identify(identity)
|
await identify(identity)
|
||||||
|
@ -226,6 +238,14 @@ export const identifyGroup = async (
|
||||||
await processors.identifyGroup(group, timestamp)
|
await processors.identifyGroup(group, timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getDeploymentEnvironment = () => {
|
||||||
|
if (env.isDev()) {
|
||||||
|
return "development"
|
||||||
|
} else {
|
||||||
|
return env.DEPLOYMENT_ENVIRONMENT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const getHostingFromEnv = () => {
|
const getHostingFromEnv = () => {
|
||||||
return env.SELF_HOSTED ? Hosting.SELF : Hosting.CLOUD
|
return env.SELF_HOSTED ? Hosting.SELF : Hosting.CLOUD
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ export default class PosthogProcessor implements EventProcessor {
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
properties.version = pkg.version
|
properties.version = pkg.version
|
||||||
properties.service = env.SERVICE
|
properties.service = env.SERVICE
|
||||||
properties.environment = env.DEPLOYMENT_ENVIRONMENT
|
properties.environment = identity.environment
|
||||||
properties.hosting = identity.hosting
|
properties.hosting = identity.hosting
|
||||||
|
|
||||||
const appId = context.getAppId()
|
const appId = context.getAppId()
|
||||||
|
|
|
@ -10,6 +10,8 @@ export enum GroupType {
|
||||||
export interface Group {
|
export interface Group {
|
||||||
id: string
|
id: string
|
||||||
type: IdentityType
|
type: IdentityType
|
||||||
|
environment: string
|
||||||
|
hosting: Hosting
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TenantGroup extends Group {
|
export interface TenantGroup extends Group {
|
||||||
|
@ -17,13 +19,11 @@ export interface TenantGroup extends Group {
|
||||||
// as we don't have this at the user level
|
// as we don't have this at the user level
|
||||||
profession?: string // only available in cloud
|
profession?: string // only available in cloud
|
||||||
companySize?: string // only available in cloud
|
companySize?: string // only available in cloud
|
||||||
hosting: Hosting // need hosting at the tenant level for cloud self host accounts
|
|
||||||
installationId: string
|
installationId: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface InstallationGroup extends Group {
|
export interface InstallationGroup extends Group {
|
||||||
version: string
|
version: string
|
||||||
hosting: Hosting
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IDENTITIES
|
// IDENTITIES
|
||||||
|
@ -38,6 +38,7 @@ export interface Identity {
|
||||||
id: string
|
id: string
|
||||||
type: IdentityType
|
type: IdentityType
|
||||||
hosting: Hosting
|
hosting: Hosting
|
||||||
|
environment: string
|
||||||
installationId?: string
|
installationId?: string
|
||||||
tenantId?: string
|
tenantId?: string
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue