diff --git a/src/types/contract.ts b/src/types/contract.ts index 2c53f613c7..3712e793c8 100644 --- a/src/types/contract.ts +++ b/src/types/contract.ts @@ -271,5 +271,5 @@ export type ActivatedDeployment = { deployment: UUID; // Use legacy names - these are passed to the server blueprint: RegistryId; - blueprintVersion: string; + blueprintVersion: SemVerString; }; diff --git a/src/types/helpers.test.ts b/src/types/helpers.test.ts index a52101d95b..c1eda5eac3 100644 --- a/src/types/helpers.test.ts +++ b/src/types/helpers.test.ts @@ -125,6 +125,12 @@ describe("types/helpers.ts", () => { coerce: true, expected: "v1.2.3", }, + { + value: "0.0.0", + allowLeadingV: false, + coerce: false, + expected: "0.0.0", + }, ])( "$value with allowLeadingV: $allowLeadingV and coerce: $coerce returns $expected", ({ value, allowLeadingV, coerce, expected }) => { diff --git a/src/types/registryTypes.ts b/src/types/registryTypes.ts index ef3465b4b5..8262d7855b 100644 --- a/src/types/registryTypes.ts +++ b/src/types/registryTypes.ts @@ -74,19 +74,11 @@ export type Metadata = { */ readonly name: string; - /** - * An optional human-readable description. - */ /** * An optional human-readable description. */ readonly description?: string; - /** - * The semantic version of the package. - * - * Currently optional because it defaults to the browser extension version for bricks defined in JS. - */ /** * The semantic version of the package. * diff --git a/src/utils/deploymentUtils.test.ts b/src/utils/deploymentUtils.test.ts index 60a11e829a..f4e91b631c 100644 --- a/src/utils/deploymentUtils.test.ts +++ b/src/utils/deploymentUtils.test.ts @@ -21,6 +21,7 @@ import { isDeploymentActive, makeUpdatedFilter, mergeDeploymentIntegrationDependencies, + selectActivatedDeployments, } from "./deploymentUtils"; import { uuidv4, @@ -46,7 +47,10 @@ import { import getModDefinitionIntegrationIds from "@/integrations/util/getModDefinitionIntegrationIds"; import { getExtensionVersion } from "@/utils/extensionUtils"; import { validateTimestamp } from "@/utils/timeUtils"; -import { modInstanceFactory } from "@/testUtils/factories/modInstanceFactories"; +import { + modInstanceFactory, + teamDeploymentMetadataFactory, +} from "@/testUtils/factories/modInstanceFactories"; import { mapActivatedModComponentsToModInstance } from "@/store/modComponents/modInstanceUtils"; describe("makeUpdatedFilter", () => { @@ -495,3 +499,22 @@ describe("mergeDeploymentIntegrationDependencies", () => { ]); }); }); + +describe("selectActivatedDeployments", () => { + it("selects deployment", () => { + const manualMod = modInstanceFactory(); + const deploymentMod = modInstanceFactory({ + deploymentMetadata: teamDeploymentMetadataFactory(), + }); + + const result = selectActivatedDeployments([manualMod, deploymentMod]); + + expect(result).toStrictEqual([ + { + deployment: deploymentMod.deploymentMetadata!.id, + blueprint: deploymentMod.definition.metadata.id, + blueprintVersion: deploymentMod.definition.metadata.version, + }, + ]); + }); +}); diff --git a/src/utils/deploymentUtils.ts b/src/utils/deploymentUtils.ts index 0bbbd17a1b..e506e8e22c 100644 --- a/src/utils/deploymentUtils.ts +++ b/src/utils/deploymentUtils.ts @@ -24,7 +24,7 @@ import { type IntegrationDependency, type SanitizedIntegrationConfig, } from "@/integrations/integrationTypes"; -import { validateUUID } from "@/types/helpers"; +import { normalizeSemVerString, validateUUID } from "@/types/helpers"; import { type Except } from "type-fest"; import { PIXIEBRIX_INTEGRATION_ID } from "@/integrations/constants"; import getUnconfiguredComponentIntegrations from "@/integrations/util/getUnconfiguredComponentIntegrations"; @@ -144,17 +144,25 @@ export function checkExtensionUpdateRequired( ); } +/** + * Return activated deployment telemetry for heartbeat. Includes deployments that are activated, but paused. + */ export function selectActivatedDeployments( modInstances: ModInstance[], ): ActivatedDeployment[] { return uniqBy( modInstances .filter((x) => x.deploymentMetadata != null) - .map((x) => ({ + .map((modInstance) => ({ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- Typescript not picking up filter - deployment: x.deploymentMetadata!.id, - blueprint: x.definition.metadata.id, - blueprintVersion: x.definition.metadata.id, + deployment: modInstance.deploymentMetadata!.id, + blueprint: modInstance.definition.metadata.id, + // In practice, all activated mods must have a version. But be defensive given that Metadata type used by + // ModDefinition does not currently require version. + blueprintVersion: + modInstance.definition.metadata.version ?? + // 0.0.0 so it's easier to see the defaulting in the backend + normalizeSemVerString("0.0.0"), })), (x) => x.deployment, );