The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
Backfill when switching from <1.4.0 to >=1.4.0 (#26149)
martmull65139e2f2cee
diff --git a/packages/twenty-apps/public/last-contact/package.json b/packages/twenty-apps/public/last-contact/package.jsonindex 936eae6a99c..7a69ea956ce 100644--- a/packages/twenty-apps/public/last-contact/package.json+++ b/packages/twenty-apps/public/last-contact/package.json@@ -1,6 +1,6 @@{"name": "@twentyhq/last-contact",- "version": "1.4.0",+ "version": "1.4.1","license": "MIT","engines": {"node": "^24.5.0",@@ -24,6 +24,7 @@"devDependencies": {"@types/node": "^24.7.2","@types/react": "^19.0.0",+ "@types/semver": "^7","@typescript/native-preview": "^7.0.0-dev.20260116.1","oxlint": "^0.16.0","react": "^19.0.0",@@ -33,5 +34,8 @@"typescript": "^5.9.3","vite-tsconfig-paths": "^4.2.1","vitest": "^4.0.0"+ },+ "dependencies": {+ "semver": "^7.8.5"}}diff --git a/packages/twenty-apps/public/last-contact/src/logic-functions/backfill-last-contact.ts b/packages/twenty-apps/public/last-contact/src/logic-functions/backfill-last-contact.tsindex 1cc102c940d..41759464f74 100644--- a/packages/twenty-apps/public/last-contact/src/logic-functions/backfill-last-contact.ts+++ b/packages/twenty-apps/public/last-contact/src/logic-functions/backfill-last-contact.ts@@ -1,5 +1,6 @@import { CoreApiClient } from 'twenty-client-sdk/core';-import { definePostInstallLogicFunction } from 'twenty-sdk/define';+import { definePostInstallLogicFunction, type InstallPayload } from 'twenty-sdk/define';+import { compare } from 'semver'import { BACKFILL_POST_INSTALL_LOGIC_FUNCTION_UNIVERSAL_IDENTIFIER } from 'src/constants/universal-identifiers';import {@@ -7,8 +8,36 @@ import {getBackfillSleepMs,} from 'src/utils/backfill-settings';import { enqueueBackfillJobs } from 'src/utils/enqueue-backfill-jobs';+import { isDefined } from 'twenty-sdk/utils';++const shouldRunPostInstall = ({+ previousVersion,+ newVersion+}: InstallPayload): boolean => {+ if(!isDefined(previousVersion)) { // Fresh install+ return true;+ }++ if (compare(previousVersion, "1.4.0") < 0 && compare(newVersion, "1.4.0") >= 1) { // Rate limitation fix+ return true;+ }++ return false+}++const handler = async ({+ previousVersion,+ newVersion+}: InstallPayload): Promise<object> => {+ if(!shouldRunPostInstall({+ previousVersion,+ newVersion+ })) {+ console.log('Post install skipped');++ return {}+ }-const handler = async (): Promise<object> => {console.log('Backfill params',JSON.stringify({@@ -28,6 +57,6 @@ export default definePostInstallLogicFunction({description:'Counts people, opportunities and companies after installation and enqueues one backfill job per record batch.',timeoutSeconds: 300,- shouldRunOnVersionUpgrade: false,+ shouldRunOnVersionUpgrade: true,handler,});diff --git a/packages/twenty-apps/public/last-contact/yarn.lock b/packages/twenty-apps/public/last-contact/yarn.lockindex 47629f40c3e..5823e10004f 100644--- a/packages/twenty-apps/public/last-contact/yarn.lock+++ b/packages/twenty-apps/public/last-contact/yarn.lock@@ -967,10 +967,12 @@ __metadata:dependencies:"@types/node": "npm:^24.7.2""@types/react": "npm:^19.0.0"+ "@types/semver": "npm:^7""@typescript/native-preview": "npm:^7.0.0-dev.20260116.1"oxlint: "npm:^0.16.0"react: "npm:^19.0.0"react-dom: "npm:^19.0.0"+ semver: "npm:^7.8.5"twenty-client-sdk: "npm:2.40.0"twenty-sdk: "npm:2.40.0"typescript: "npm:^5.9.3"@@ -1046,6 +1048,13 @@ __metadata:languageName: nodelinkType: hard+"@types/semver@npm:^7":+ version: 7.8.0+ resolution: "@types/semver@npm:7.8.0"+ checksum: 10c0/46a1f38e36013448b279798e8b134e7e8de3b3630b1f40683903b9d57d36dd1d70838515570ed9a149fa09e9c381b9e39319b58d7b9f3b929b42ae2becff7aa3+ languageName: node+ linkType: hard+"@types/ws@npm:^6.0.1":version: 6.0.4resolution: "@types/ws@npm:6.0.4"