|
|
@ -14,7 +14,6 @@ import { |
|
|
CloudAccount, |
|
|
CloudAccount, |
|
|
UserIdentity, |
|
|
UserIdentity, |
|
|
InstallationGroup, |
|
|
InstallationGroup, |
|
|
isSelfHostAccount, |
|
|
|
|
|
UserContext, |
|
|
UserContext, |
|
|
Group, |
|
|
Group, |
|
|
} from "@budibase/types" |
|
|
} from "@budibase/types" |
|
|
@ -36,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 |
|
|
|
|
|
|
|
|
@ -47,36 +47,47 @@ export const getCurrentIdentity = async (): Promise<Identity> => { |
|
|
|
|
|
|
|
|
if (identityType === IdentityType.INSTALLATION) { |
|
|
if (identityType === IdentityType.INSTALLATION) { |
|
|
const installationId = await getInstallationId() |
|
|
const installationId = await getInstallationId() |
|
|
|
|
|
const hosting = getHostingFromEnv() |
|
|
return { |
|
|
return { |
|
|
id: formatDistinctId(installationId, identityType), |
|
|
id: formatDistinctId(installationId, identityType), |
|
|
|
|
|
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() |
|
|
const tenantId = await getEventTenantId(context.getTenantId()) |
|
|
const tenantId = await getEventTenantId(context.getTenantId()) |
|
|
|
|
|
const hosting = getHostingFromEnv() |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
id: formatDistinctId(tenantId, identityType), |
|
|
id: formatDistinctId(tenantId, identityType), |
|
|
type: identityType, |
|
|
type: identityType, |
|
|
|
|
|
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 |
|
|
const tenantId = await getEventTenantId(context.getTenantId()) |
|
|
const tenantId = await getEventTenantId(context.getTenantId()) |
|
|
let installationId: string | undefined |
|
|
const installationId = await getInstallationId() |
|
|
|
|
|
|
|
|
// self host account users won't have installation
|
|
|
const account = userContext.account |
|
|
if (!userContext.account || !isSelfHostAccount(userContext.account)) { |
|
|
let hosting |
|
|
installationId = await getInstallationId() |
|
|
if (account) { |
|
|
|
|
|
hosting = account.hosting |
|
|
|
|
|
} else { |
|
|
|
|
|
hosting = getHostingFromEnv() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
id: userContext._id, |
|
|
id: userContext._id, |
|
|
type: identityType, |
|
|
type: identityType, |
|
|
|
|
|
hosting, |
|
|
installationId, |
|
|
installationId, |
|
|
tenantId, |
|
|
tenantId, |
|
|
|
|
|
environment, |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
throw new Error("Unknown identity type") |
|
|
throw new Error("Unknown identity type") |
|
|
@ -91,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) |
|
|
@ -112,6 +125,8 @@ export const identifyTenantGroup = async ( |
|
|
): Promise<void> => { |
|
|
): Promise<void> => { |
|
|
const id = await getEventTenantId(tenantId) |
|
|
const id = await getEventTenantId(tenantId) |
|
|
const type = IdentityType.TENANT |
|
|
const type = IdentityType.TENANT |
|
|
|
|
|
const installationId = await getInstallationId() |
|
|
|
|
|
const environment = getDeploymentEnvironment() |
|
|
|
|
|
|
|
|
let hosting: Hosting |
|
|
let hosting: Hosting |
|
|
let profession: string | undefined |
|
|
let profession: string | undefined |
|
|
@ -129,6 +144,8 @@ export const identifyTenantGroup = async ( |
|
|
id, |
|
|
id, |
|
|
type, |
|
|
type, |
|
|
hosting, |
|
|
hosting, |
|
|
|
|
|
environment, |
|
|
|
|
|
installationId, |
|
|
profession, |
|
|
profession, |
|
|
companySize, |
|
|
companySize, |
|
|
} |
|
|
} |
|
|
@ -154,10 +171,13 @@ export const identifyUser = async ( |
|
|
const verified = |
|
|
const verified = |
|
|
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 environment = getDeploymentEnvironment() |
|
|
|
|
|
|
|
|
const identity: UserIdentity = { |
|
|
const identity: UserIdentity = { |
|
|
id, |
|
|
id, |
|
|
type, |
|
|
type, |
|
|
|
|
|
hosting, |
|
|
installationId, |
|
|
installationId, |
|
|
tenantId, |
|
|
tenantId, |
|
|
verified, |
|
|
verified, |
|
|
@ -165,6 +185,7 @@ export const identifyUser = async ( |
|
|
providerType, |
|
|
providerType, |
|
|
builder, |
|
|
builder, |
|
|
admin, |
|
|
admin, |
|
|
|
|
|
environment, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await identify(identity, timestamp) |
|
|
await identify(identity, timestamp) |
|
|
@ -177,6 +198,9 @@ export const identifyAccount = async (account: Account) => { |
|
|
let providerType = isSSOAccount(account) ? account.providerType : undefined |
|
|
let providerType = isSSOAccount(account) ? account.providerType : undefined |
|
|
const verified = account.verified |
|
|
const verified = account.verified |
|
|
const accountHolder = true |
|
|
const accountHolder = true |
|
|
|
|
|
const hosting = account.hosting |
|
|
|
|
|
const installationId = await getInstallationId() |
|
|
|
|
|
const environment = getDeploymentEnvironment() |
|
|
|
|
|
|
|
|
if (isCloudAccount(account)) { |
|
|
if (isCloudAccount(account)) { |
|
|
if (account.budibaseUserId) { |
|
|
if (account.budibaseUserId) { |
|
|
@ -188,10 +212,13 @@ export const identifyAccount = async (account: Account) => { |
|
|
const identity: UserIdentity = { |
|
|
const identity: UserIdentity = { |
|
|
id, |
|
|
id, |
|
|
type, |
|
|
type, |
|
|
|
|
|
hosting, |
|
|
|
|
|
installationId, |
|
|
tenantId, |
|
|
tenantId, |
|
|
providerType, |
|
|
providerType, |
|
|
verified, |
|
|
verified, |
|
|
accountHolder, |
|
|
accountHolder, |
|
|
|
|
|
environment, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
await identify(identity) |
|
|
await identify(identity) |
|
|
@ -211,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 |
|
|
} |
|
|
} |
|
|
|