@twentyhq/people-data-labs 1.0.0

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.
Files changed (341) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/.nvmrc +1 -0
  3. package/.oxlintrc.json +58 -0
  4. package/.yarnrc.yml +1 -0
  5. package/README.md +16 -0
  6. package/package.json +37 -0
  7. package/public/gallery/cover.png +0 -0
  8. package/public/people-data-labs-icon.png +0 -0
  9. package/src/__tests__/global-setup.ts +87 -0
  10. package/src/__tests__/people-data-labs.integration-test.ts +25 -0
  11. package/src/application-config.ts +18 -0
  12. package/src/command-menu-items/enrich-companies.ts +14 -0
  13. package/src/command-menu-items/enrich-people.ts +14 -0
  14. package/src/constants/__tests__/select-option-constants.spec.ts +142 -0
  15. package/src/constants/billing-margin-multiplier.ts +1 -0
  16. package/src/constants/company-match-cost-dollars.ts +1 -0
  17. package/src/constants/company-type-options.ts +46 -0
  18. package/src/constants/enrichment-status-options.ts +19 -0
  19. package/src/constants/enrichment-workflow-seeds.ts +27 -0
  20. package/src/constants/funding-stage-options.ts +195 -0
  21. package/src/constants/industry-options.ts +1033 -0
  22. package/src/constants/inferred-salary-options.ts +81 -0
  23. package/src/constants/job-role-options.ts +172 -0
  24. package/src/constants/job-title-class-options.ts +39 -0
  25. package/src/constants/job-title-sub-role-options.ts +746 -0
  26. package/src/constants/location-continent-options.ts +53 -0
  27. package/src/constants/metro-options.ts +2692 -0
  28. package/src/constants/mic-exchange-options.ts +494 -0
  29. package/src/constants/micro-credits-per-dollar.ts +1 -0
  30. package/src/constants/pdl-base-url.ts +1 -0
  31. package/src/constants/person-match-cost-dollars.ts +1 -0
  32. package/src/constants/seniority-options.ts +74 -0
  33. package/src/constants/sex-options.ts +18 -0
  34. package/src/constants/size-options.ts +60 -0
  35. package/src/constants/universal-identifiers.ts +1516 -0
  36. package/src/constants/update-fields-option-values.ts +5 -0
  37. package/src/constants/update-fields-options.ts +7 -0
  38. package/src/fields/company/pdl-affiliated-profiles.field.ts +20 -0
  39. package/src/fields/company/pdl-alternative-domains.field.ts +20 -0
  40. package/src/fields/company/pdl-alternative-names.field.ts +20 -0
  41. package/src/fields/company/pdl-company-type.field.ts +28 -0
  42. package/src/fields/company/pdl-employee-count-by-country.field.ts +21 -0
  43. package/src/fields/company/pdl-employee-count.field.ts +19 -0
  44. package/src/fields/company/pdl-enrichment-status.field.ts +29 -0
  45. package/src/fields/company/pdl-facebook-url.field.ts +19 -0
  46. package/src/fields/company/pdl-founded-year.field.ts +19 -0
  47. package/src/fields/company/pdl-funding-stages.field.ts +28 -0
  48. package/src/fields/company/pdl-headline.field.ts +19 -0
  49. package/src/fields/company/pdl-id.field.ts +19 -0
  50. package/src/fields/company/pdl-industry-detail.field.ts +20 -0
  51. package/src/fields/company/pdl-industry.field.ts +28 -0
  52. package/src/fields/company/pdl-last-enriched-at.field.ts +20 -0
  53. package/src/fields/company/pdl-last-funding-date.field.ts +20 -0
  54. package/src/fields/company/pdl-latest-funding-stage.field.ts +29 -0
  55. package/src/fields/company/pdl-legal-name.field.ts +19 -0
  56. package/src/fields/company/pdl-linkedin-id.field.ts +19 -0
  57. package/src/fields/company/pdl-location-continent.field.ts +29 -0
  58. package/src/fields/company/pdl-location-metro.field.ts +28 -0
  59. package/src/fields/company/pdl-mic-exchange.field.ts +28 -0
  60. package/src/fields/company/pdl-naics.field.ts +19 -0
  61. package/src/fields/company/pdl-number-funding-rounds.field.ts +20 -0
  62. package/src/fields/company/pdl-raw-payload.field.ts +19 -0
  63. package/src/fields/company/pdl-sic.field.ts +19 -0
  64. package/src/fields/company/pdl-size-range.field.ts +28 -0
  65. package/src/fields/company/pdl-summary.field.ts +19 -0
  66. package/src/fields/company/pdl-tags.field.ts +19 -0
  67. package/src/fields/company/pdl-ticker.field.ts +19 -0
  68. package/src/fields/company/pdl-total-funding.field.ts +19 -0
  69. package/src/fields/company/pdl-twitter-url.field.ts +19 -0
  70. package/src/fields/person/pdl-birth-date.field.ts +19 -0
  71. package/src/fields/person/pdl-birth-year.field.ts +19 -0
  72. package/src/fields/person/pdl-certifications.field.ts +19 -0
  73. package/src/fields/person/pdl-education.field.ts +19 -0
  74. package/src/fields/person/pdl-enrichment-status.field.ts +29 -0
  75. package/src/fields/person/pdl-experience.field.ts +19 -0
  76. package/src/fields/person/pdl-facebook-url.field.ts +19 -0
  77. package/src/fields/person/pdl-github-url.field.ts +19 -0
  78. package/src/fields/person/pdl-headline.field.ts +19 -0
  79. package/src/fields/person/pdl-id.field.ts +19 -0
  80. package/src/fields/person/pdl-industry.field.ts +28 -0
  81. package/src/fields/person/pdl-inferred-salary.field.ts +28 -0
  82. package/src/fields/person/pdl-interests.field.ts +19 -0
  83. package/src/fields/person/pdl-job-onet-code.field.ts +19 -0
  84. package/src/fields/person/pdl-job-role.field.ts +28 -0
  85. package/src/fields/person/pdl-job-start-date.field.ts +19 -0
  86. package/src/fields/person/pdl-job-summary.field.ts +19 -0
  87. package/src/fields/person/pdl-job-title-class.field.ts +28 -0
  88. package/src/fields/person/pdl-job-title-sub-role.field.ts +29 -0
  89. package/src/fields/person/pdl-languages.field.ts +19 -0
  90. package/src/fields/person/pdl-last-enriched-at.field.ts +19 -0
  91. package/src/fields/person/pdl-likelihood.field.ts +19 -0
  92. package/src/fields/person/pdl-linkedin-connections.field.ts +20 -0
  93. package/src/fields/person/pdl-linkedin-username.field.ts +20 -0
  94. package/src/fields/person/pdl-location-metro.field.ts +28 -0
  95. package/src/fields/person/pdl-location.field.ts +19 -0
  96. package/src/fields/person/pdl-name-aliases.field.ts +19 -0
  97. package/src/fields/person/pdl-profiles.field.ts +19 -0
  98. package/src/fields/person/pdl-raw-payload.field.ts +19 -0
  99. package/src/fields/person/pdl-seniority.field.ts +28 -0
  100. package/src/fields/person/pdl-sex.field.ts +28 -0
  101. package/src/fields/person/pdl-skills.field.ts +19 -0
  102. package/src/fields/person/pdl-summary.field.ts +19 -0
  103. package/src/fields/person/pdl-twitter-url.field.ts +19 -0
  104. package/src/fields/person/pdl-years-experience.field.ts +21 -0
  105. package/src/front-components/enrich-companies-component-effect.tsx +21 -0
  106. package/src/front-components/enrich-people-component-effect.tsx +21 -0
  107. package/src/front-components/utils/call-enrich-logic-function.utils.ts +21 -0
  108. package/src/logic-functions/__mocks__/company-node.mock.ts +11 -0
  109. package/src/logic-functions/__mocks__/create-core-api-client-mock.ts +35 -0
  110. package/src/logic-functions/__mocks__/pdl-company-data.mock.ts +27 -0
  111. package/src/logic-functions/__mocks__/pdl-person-data.mock.ts +23 -0
  112. package/src/logic-functions/__mocks__/person-node.mock.ts +12 -0
  113. package/src/logic-functions/enrich-companies.function.ts +76 -0
  114. package/src/logic-functions/enrich-company.function.ts +73 -0
  115. package/src/logic-functions/enrich-people.function.ts +76 -0
  116. package/src/logic-functions/enrich-person.function.ts +73 -0
  117. package/src/logic-functions/errors/__tests__/pdl-config-error.spec.ts +16 -0
  118. package/src/logic-functions/errors/__tests__/pdl-invalid-input-error.spec.ts +16 -0
  119. package/src/logic-functions/errors/__tests__/pdl-operation-error.spec.ts +16 -0
  120. package/src/logic-functions/errors/__tests__/pdl-record-not-found-error.spec.ts +21 -0
  121. package/src/logic-functions/errors/pdl-config-error.ts +8 -0
  122. package/src/logic-functions/errors/pdl-error-code.ts +8 -0
  123. package/src/logic-functions/errors/pdl-error.ts +12 -0
  124. package/src/logic-functions/errors/pdl-invalid-input-error.ts +8 -0
  125. package/src/logic-functions/errors/pdl-operation-error.ts +8 -0
  126. package/src/logic-functions/errors/pdl-record-not-found-error.ts +22 -0
  127. package/src/logic-functions/handlers/__tests__/enrich-companies.spec.ts +159 -0
  128. package/src/logic-functions/handlers/__tests__/enrich-company.spec.ts +147 -0
  129. package/src/logic-functions/handlers/__tests__/enrich-people.spec.ts +313 -0
  130. package/src/logic-functions/handlers/__tests__/enrich-person.spec.ts +198 -0
  131. package/src/logic-functions/handlers/__tests__/post-install.spec.ts +153 -0
  132. package/src/logic-functions/handlers/company-enrichment-adapter.ts +42 -0
  133. package/src/logic-functions/handlers/company-single-enrichment-adapter.ts +15 -0
  134. package/src/logic-functions/handlers/enrich-companies.ts +15 -0
  135. package/src/logic-functions/handlers/enrich-company.ts +19 -0
  136. package/src/logic-functions/handlers/enrich-people.ts +15 -0
  137. package/src/logic-functions/handlers/enrich-person.ts +19 -0
  138. package/src/logic-functions/handlers/person-enrichment-adapter.ts +29 -0
  139. package/src/logic-functions/handlers/person-single-enrichment-adapter.ts +15 -0
  140. package/src/logic-functions/handlers/post-install.ts +69 -0
  141. package/src/logic-functions/post-install.function.ts +17 -0
  142. package/src/logic-functions/utils/__tests__/aggregate-bulk-enrich-result.spec.ts +52 -0
  143. package/src/logic-functions/utils/__tests__/build-address.spec.ts +30 -0
  144. package/src/logic-functions/utils/__tests__/build-allowed-values.spec.ts +16 -0
  145. package/src/logic-functions/utils/__tests__/build-bulk-records-trigger.spec.ts +26 -0
  146. package/src/logic-functions/utils/__tests__/build-company-create-data.spec.ts +37 -0
  147. package/src/logic-functions/utils/__tests__/build-company-match-keys.spec.ts +35 -0
  148. package/src/logic-functions/utils/__tests__/build-company-matched-data.spec.ts +56 -0
  149. package/src/logic-functions/utils/__tests__/build-currency-from-usd.spec.ts +17 -0
  150. package/src/logic-functions/utils/__tests__/build-emails.spec.ts +23 -0
  151. package/src/logic-functions/utils/__tests__/build-error-result.spec.ts +16 -0
  152. package/src/logic-functions/utils/__tests__/build-full-name.spec.ts +64 -0
  153. package/src/logic-functions/utils/__tests__/build-links.spec.ts +25 -0
  154. package/src/logic-functions/utils/__tests__/build-logic-function-step.spec.ts +33 -0
  155. package/src/logic-functions/utils/__tests__/build-matched-result.spec.ts +33 -0
  156. package/src/logic-functions/utils/__tests__/build-not-found-result.spec.ts +15 -0
  157. package/src/logic-functions/utils/__tests__/build-person-matched-data.spec.ts +117 -0
  158. package/src/logic-functions/utils/__tests__/build-person-name-param.spec.ts +17 -0
  159. package/src/logic-functions/utils/__tests__/build-phones.spec.ts +32 -0
  160. package/src/logic-functions/utils/__tests__/build-skipped-result.spec.ts +17 -0
  161. package/src/logic-functions/utils/__tests__/capitalize-name.spec.ts +26 -0
  162. package/src/logic-functions/utils/__tests__/capitalize-name.test.ts +17 -0
  163. package/src/logic-functions/utils/__tests__/charge-matched-enrichments.spec.ts +56 -0
  164. package/src/logic-functions/utils/__tests__/chunk.spec.ts +25 -0
  165. package/src/logic-functions/utils/__tests__/enrich-companies.spec.ts +26 -0
  166. package/src/logic-functions/utils/__tests__/enrich-company.spec.ts +54 -0
  167. package/src/logic-functions/utils/__tests__/enrich-people.spec.ts +32 -0
  168. package/src/logic-functions/utils/__tests__/enrich-person.spec.ts +62 -0
  169. package/src/logic-functions/utils/__tests__/extract-company-match-params.spec.ts +86 -0
  170. package/src/logic-functions/utils/__tests__/extract-pdl-error-message.spec.ts +17 -0
  171. package/src/logic-functions/utils/__tests__/extract-person-match-params.spec.ts +75 -0
  172. package/src/logic-functions/utils/__tests__/extract-record-ids.spec.ts +32 -0
  173. package/src/logic-functions/utils/__tests__/find-company-id-by-filter.spec.ts +42 -0
  174. package/src/logic-functions/utils/__tests__/find-company-id.spec.ts +118 -0
  175. package/src/logic-functions/utils/__tests__/find-existing-workflow-id.spec.ts +26 -0
  176. package/src/logic-functions/utils/__tests__/find-or-create-current-company.spec.ts +203 -0
  177. package/src/logic-functions/utils/__tests__/get-pdl-api-key.spec.ts +38 -0
  178. package/src/logic-functions/utils/__tests__/is-empty-address.spec.ts +20 -0
  179. package/src/logic-functions/utils/__tests__/is-empty-emails.spec.ts +14 -0
  180. package/src/logic-functions/utils/__tests__/is-empty-full-name.spec.ts +14 -0
  181. package/src/logic-functions/utils/__tests__/is-empty-links.spec.ts +14 -0
  182. package/src/logic-functions/utils/__tests__/is-empty-phones.spec.ts +14 -0
  183. package/src/logic-functions/utils/__tests__/is-empty-text.spec.ts +15 -0
  184. package/src/logic-functions/utils/__tests__/map-company.spec.ts +48 -0
  185. package/src/logic-functions/utils/__tests__/map-person.spec.ts +81 -0
  186. package/src/logic-functions/utils/__tests__/normalize-domain.spec.ts +19 -0
  187. package/src/logic-functions/utils/__tests__/normalize-linkedin-url.spec.ts +22 -0
  188. package/src/logic-functions/utils/__tests__/now-iso.spec.ts +9 -0
  189. package/src/logic-functions/utils/__tests__/parse-geo.spec.ts +21 -0
  190. package/src/logic-functions/utils/__tests__/parse-partial-date.spec.ts +29 -0
  191. package/src/logic-functions/utils/__tests__/parse-pdl-item.spec.ts +88 -0
  192. package/src/logic-functions/utils/__tests__/pick-multi-select.spec.ts +28 -0
  193. package/src/logic-functions/utils/__tests__/pick-select.spec.ts +38 -0
  194. package/src/logic-functions/utils/__tests__/pick-writable-standard.spec.ts +37 -0
  195. package/src/logic-functions/utils/__tests__/post-pdl-enrich.spec.ts +192 -0
  196. package/src/logic-functions/utils/__tests__/post-pdl-single-enrich.spec.ts +172 -0
  197. package/src/logic-functions/utils/__tests__/read-companies.spec.ts +39 -0
  198. package/src/logic-functions/utils/__tests__/read-people.spec.ts +40 -0
  199. package/src/logic-functions/utils/__tests__/resolve-logic-function-id.spec.ts +25 -0
  200. package/src/logic-functions/utils/__tests__/resolve-update-fields-mode.spec.ts +34 -0
  201. package/src/logic-functions/utils/__tests__/run-batch-enrichment.spec.ts +524 -0
  202. package/src/logic-functions/utils/__tests__/salary-transform.spec.ts +15 -0
  203. package/src/logic-functions/utils/__tests__/seed-enrichment-workflow.spec.ts +136 -0
  204. package/src/logic-functions/utils/__tests__/size-transform.spec.ts +18 -0
  205. package/src/logic-functions/utils/__tests__/to-json-array.spec.ts +16 -0
  206. package/src/logic-functions/utils/__tests__/to-json-object.spec.ts +18 -0
  207. package/src/logic-functions/utils/__tests__/to-number.spec.ts +17 -0
  208. package/src/logic-functions/utils/__tests__/to-string-array.spec.ts +17 -0
  209. package/src/logic-functions/utils/__tests__/to-text.spec.ts +20 -0
  210. package/src/logic-functions/utils/__tests__/update-companies-status.spec.ts +32 -0
  211. package/src/logic-functions/utils/__tests__/update-company-record.spec.ts +25 -0
  212. package/src/logic-functions/utils/__tests__/update-people-status.spec.ts +32 -0
  213. package/src/logic-functions/utils/__tests__/update-person-record.spec.ts +25 -0
  214. package/src/logic-functions/utils/aggregate-bulk-enrich-result.ts +21 -0
  215. package/src/logic-functions/utils/build-address.ts +40 -0
  216. package/src/logic-functions/utils/build-allowed-values.ts +5 -0
  217. package/src/logic-functions/utils/build-bulk-records-trigger.ts +25 -0
  218. package/src/logic-functions/utils/build-company-create-data.ts +35 -0
  219. package/src/logic-functions/utils/build-company-match-keys.ts +16 -0
  220. package/src/logic-functions/utils/build-company-matched-data.ts +56 -0
  221. package/src/logic-functions/utils/build-currency-from-usd.ts +16 -0
  222. package/src/logic-functions/utils/build-emails.ts +34 -0
  223. package/src/logic-functions/utils/build-error-result.ts +18 -0
  224. package/src/logic-functions/utils/build-full-name.ts +38 -0
  225. package/src/logic-functions/utils/build-links.ts +23 -0
  226. package/src/logic-functions/utils/build-logic-function-step.ts +30 -0
  227. package/src/logic-functions/utils/build-matched-result.ts +21 -0
  228. package/src/logic-functions/utils/build-not-found-result.ts +9 -0
  229. package/src/logic-functions/utils/build-person-matched-data.ts +78 -0
  230. package/src/logic-functions/utils/build-person-name-param.ts +19 -0
  231. package/src/logic-functions/utils/build-phones.ts +40 -0
  232. package/src/logic-functions/utils/build-skipped-result.ts +15 -0
  233. package/src/logic-functions/utils/capitalize-name.ts +8 -0
  234. package/src/logic-functions/utils/charge-matched-enrichments.ts +29 -0
  235. package/src/logic-functions/utils/chunk.ts +18 -0
  236. package/src/logic-functions/utils/enrich-chunk.ts +361 -0
  237. package/src/logic-functions/utils/enrich-companies.ts +21 -0
  238. package/src/logic-functions/utils/enrich-company.ts +23 -0
  239. package/src/logic-functions/utils/enrich-people.ts +22 -0
  240. package/src/logic-functions/utils/enrich-person.ts +24 -0
  241. package/src/logic-functions/utils/extract-company-match-params.ts +52 -0
  242. package/src/logic-functions/utils/extract-pdl-error-message.ts +47 -0
  243. package/src/logic-functions/utils/extract-person-match-params.ts +59 -0
  244. package/src/logic-functions/utils/extract-record-ids.ts +18 -0
  245. package/src/logic-functions/utils/find-company-id-by-filter.ts +28 -0
  246. package/src/logic-functions/utils/find-company-id.ts +59 -0
  247. package/src/logic-functions/utils/find-existing-workflow-id.ts +18 -0
  248. package/src/logic-functions/utils/find-or-create-current-company.ts +108 -0
  249. package/src/logic-functions/utils/get-pdl-api-key.ts +15 -0
  250. package/src/logic-functions/utils/internal-field-names.ts +6 -0
  251. package/src/logic-functions/utils/is-empty-address.ts +20 -0
  252. package/src/logic-functions/utils/is-empty-emails.ts +13 -0
  253. package/src/logic-functions/utils/is-empty-full-name.ts +13 -0
  254. package/src/logic-functions/utils/is-empty-links.ts +13 -0
  255. package/src/logic-functions/utils/is-empty-phones.ts +13 -0
  256. package/src/logic-functions/utils/is-empty-text.ts +4 -0
  257. package/src/logic-functions/utils/map-company.ts +115 -0
  258. package/src/logic-functions/utils/map-person.ts +136 -0
  259. package/src/logic-functions/utils/normalize-domain.ts +22 -0
  260. package/src/logic-functions/utils/normalize-linkedin-url.ts +23 -0
  261. package/src/logic-functions/utils/now-iso.ts +1 -0
  262. package/src/logic-functions/utils/parse-geo.ts +33 -0
  263. package/src/logic-functions/utils/parse-partial-date.ts +33 -0
  264. package/src/logic-functions/utils/parse-pdl-item.ts +82 -0
  265. package/src/logic-functions/utils/pick-multi-select.ts +32 -0
  266. package/src/logic-functions/utils/pick-select.ts +30 -0
  267. package/src/logic-functions/utils/pick-writable-standard.ts +27 -0
  268. package/src/logic-functions/utils/post-pdl-enrich.ts +89 -0
  269. package/src/logic-functions/utils/post-pdl-single-enrich.ts +59 -0
  270. package/src/logic-functions/utils/read-companies.ts +53 -0
  271. package/src/logic-functions/utils/read-people.ts +48 -0
  272. package/src/logic-functions/utils/resolve-logic-function-id.ts +11 -0
  273. package/src/logic-functions/utils/resolve-min-likelihood.ts +12 -0
  274. package/src/logic-functions/utils/resolve-update-fields-mode.ts +16 -0
  275. package/src/logic-functions/utils/run-batch-enrichment.ts +50 -0
  276. package/src/logic-functions/utils/run-single-enrichment.ts +44 -0
  277. package/src/logic-functions/utils/salary-transform.ts +18 -0
  278. package/src/logic-functions/utils/seed-enrichment-workflow.ts +131 -0
  279. package/src/logic-functions/utils/size-transform.ts +15 -0
  280. package/src/logic-functions/utils/to-bulk-enrich-input.ts +14 -0
  281. package/src/logic-functions/utils/to-json-array.ts +4 -0
  282. package/src/logic-functions/utils/to-json-object.ts +22 -0
  283. package/src/logic-functions/utils/to-number.ts +4 -0
  284. package/src/logic-functions/utils/to-string-array.ts +28 -0
  285. package/src/logic-functions/utils/to-text.ts +11 -0
  286. package/src/logic-functions/utils/update-companies-status.ts +18 -0
  287. package/src/logic-functions/utils/update-company-record.ts +15 -0
  288. package/src/logic-functions/utils/update-people-status.ts +18 -0
  289. package/src/logic-functions/utils/update-person-record.ts +15 -0
  290. package/src/roles/default-function.role.ts +41 -0
  291. package/src/types/address-parts.ts +9 -0
  292. package/src/types/address-value.ts +10 -0
  293. package/src/types/batch-enrichment-adapter.ts +43 -0
  294. package/src/types/bulk-enrich-input.ts +9 -0
  295. package/src/types/bulk-enrich-result.ts +11 -0
  296. package/src/types/company-id-by-match-key-cache.ts +1 -0
  297. package/src/types/company-match-keys.ts +6 -0
  298. package/src/types/company-node.ts +16 -0
  299. package/src/types/currency-value.ts +4 -0
  300. package/src/types/emails-value.ts +4 -0
  301. package/src/types/enrich-result.ts +11 -0
  302. package/src/types/enrich-status.ts +1 -0
  303. package/src/types/enrichment-workflow-seed.ts +9 -0
  304. package/src/types/full-name-value.ts +4 -0
  305. package/src/types/links-value.ts +5 -0
  306. package/src/types/mapped-record.ts +4 -0
  307. package/src/types/pdl-company-data.ts +50 -0
  308. package/src/types/pdl-company-enrich-params.ts +7 -0
  309. package/src/types/pdl-enrich-result.ts +4 -0
  310. package/src/types/pdl-person-data.ts +65 -0
  311. package/src/types/pdl-person-enrich-params.ts +8 -0
  312. package/src/types/person-node.ts +11 -0
  313. package/src/types/phones-value.ts +12 -0
  314. package/src/types/post-install-result.ts +5 -0
  315. package/src/types/seed-enrichment-workflow-result.ts +7 -0
  316. package/src/types/select-option-meta.ts +9 -0
  317. package/src/types/single-enrich-input.ts +7 -0
  318. package/src/types/tag-color.ts +26 -0
  319. package/src/types/update-fields-option.ts +4 -0
  320. package/src/types/workflow-bulk-records-trigger.ts +15 -0
  321. package/src/types/workflow-logic-function-step.ts +18 -0
  322. package/src/utils/__tests__/build-select-options.spec.ts +20 -0
  323. package/src/utils/__tests__/is-defined.spec.ts +16 -0
  324. package/src/utils/__tests__/is-unique-violation-error.spec.ts +71 -0
  325. package/src/utils/__tests__/normalize-enum-value.spec.ts +28 -0
  326. package/src/utils/__tests__/prune-undefined.spec.ts +22 -0
  327. package/src/utils/__tests__/strip-separators.spec.ts +13 -0
  328. package/src/utils/__tests__/to-error-message.spec.ts +13 -0
  329. package/src/utils/build-select-options.ts +16 -0
  330. package/src/utils/is-defined.ts +5 -0
  331. package/src/utils/is-unique-violation-error.ts +74 -0
  332. package/src/utils/normalize-enum-value.ts +15 -0
  333. package/src/utils/prune-undefined.ts +15 -0
  334. package/src/utils/strip-separators.ts +4 -0
  335. package/src/utils/to-error-message.ts +2 -0
  336. package/src/views/enriched-companies.view.ts +69 -0
  337. package/src/views/enriched-people.view.ts +74 -0
  338. package/tsconfig.json +42 -0
  339. package/tsconfig.spec.json +9 -0
  340. package/vitest.config.ts +31 -0
  341. package/vitest.unit.config.ts +14 -0
@@ -0,0 +1,524 @@
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
+ import { type CoreApiClient } from 'twenty-client-sdk/core';
3
+ import { chargeCredits } from 'twenty-sdk/billing';
4
+
5
+ import { UPDATE_FIELDS_OPTIONS } from 'src/constants/update-fields-options';
6
+ import { runBatchEnrichment } from 'src/logic-functions/utils/run-batch-enrichment';
7
+ import { type BatchEnrichmentAdapter } from 'src/types/batch-enrichment-adapter';
8
+ import { type PdlEnrichResult } from 'src/types/pdl-enrich-result';
9
+
10
+ vi.mock('twenty-sdk/billing', () => ({
11
+ chargeCredits: vi.fn(async () => undefined),
12
+ }));
13
+
14
+ const FAKE_COST_PER_MATCH_DOLLARS = 0.1;
15
+ const FAKE_CREDITS_PER_MATCH_MICRO = 120_000;
16
+
17
+ type FakeNode = {
18
+ id: string;
19
+ hasIdentifier: boolean;
20
+ };
21
+ type FakeData = { id: string };
22
+ type FakeParams = { id: string };
23
+
24
+ type BuildMatchedDataArgs = Parameters<
25
+ BatchEnrichmentAdapter<FakeNode, FakeData, FakeParams>['buildMatchedData']
26
+ >[0];
27
+
28
+ type RecordConfig = {
29
+ id: string;
30
+ exists?: boolean;
31
+ hasIdentifier?: boolean;
32
+ outcome?: PdlEnrichResult<FakeData>;
33
+ updateFails?: boolean;
34
+ buildFails?: boolean;
35
+ };
36
+
37
+ const CLIENT = {} as CoreApiClient;
38
+
39
+ const buildHarness = (configs: RecordConfig[]) => {
40
+ const byId = new Map(configs.map((config) => [config.id, config]));
41
+
42
+ const readRecords = vi.fn(
43
+ async ({
44
+ recordIds,
45
+ }: {
46
+ client: CoreApiClient;
47
+ recordIds: string[];
48
+ }): Promise<FakeNode[]> =>
49
+ recordIds
50
+ .map((id) => byId.get(id))
51
+ .filter(
52
+ (config): config is RecordConfig =>
53
+ isPresent(config) && config.exists !== false,
54
+ )
55
+ .map((config) => ({
56
+ id: config.id,
57
+ hasIdentifier: config.hasIdentifier !== false,
58
+ })),
59
+ );
60
+
61
+ const enrichBatch = vi.fn(
62
+ async (params: FakeParams[]): Promise<PdlEnrichResult<FakeData>[]> =>
63
+ params.map(
64
+ (param) =>
65
+ byId.get(param.id)?.outcome ?? {
66
+ outcome: 'matched',
67
+ httpStatus: 200,
68
+ data: { id: param.id },
69
+ },
70
+ ),
71
+ );
72
+
73
+ const updateOne = vi.fn(
74
+ async ({
75
+ recordId,
76
+ }: {
77
+ client: CoreApiClient;
78
+ recordId: string;
79
+ data: Record<string, unknown>;
80
+ }) => {
81
+ if (byId.get(recordId)?.updateFails === true) {
82
+ throw new Error('update failed');
83
+ }
84
+ },
85
+ );
86
+
87
+ const updateManyStatus = vi.fn(async () => undefined);
88
+
89
+ const buildMatchedData = vi.fn(
90
+ async ({
91
+ node,
92
+ }: BuildMatchedDataArgs): Promise<{
93
+ mappedData: Record<string, unknown>;
94
+ persistData: Record<string, unknown>;
95
+ }> => {
96
+ if (byId.get(node.id)?.buildFails === true) {
97
+ throw new Error('build failed');
98
+ }
99
+
100
+ return { mappedData: { mapped: node.id }, persistData: { value: node.id } };
101
+ },
102
+ );
103
+
104
+ const adapter: BatchEnrichmentAdapter<FakeNode, FakeData, FakeParams> = {
105
+ objectNameSingular: 'Test',
106
+ noIdentifierMessage: 'no identifier',
107
+ costPerMatchDollars: FAKE_COST_PER_MATCH_DOLLARS,
108
+ readRecords,
109
+ getNodeId: (node) => node.id,
110
+ extractParams: ({ node }) =>
111
+ node.hasIdentifier ? { id: node.id } : undefined,
112
+ enrichBatch,
113
+ buildMatchedData,
114
+ updateOne,
115
+ updateManyStatus,
116
+ };
117
+
118
+ return {
119
+ adapter,
120
+ readRecords,
121
+ enrichBatch,
122
+ updateOne,
123
+ updateManyStatus,
124
+ buildMatchedData,
125
+ };
126
+ };
127
+
128
+ const isPresent = <TValue>(value: TValue | undefined): value is TValue =>
129
+ value !== undefined;
130
+
131
+ const records = (...ids: string[]) => ids.map((id) => ({ id }));
132
+
133
+ describe('runBatchEnrichment', () => {
134
+ beforeEach(() => {
135
+ vi.mocked(chargeCredits).mockClear();
136
+ });
137
+
138
+ it('reads every id in one call and enriches the set in one batch', async () => {
139
+ const harness = buildHarness([{ id: 'a' }, { id: 'b' }]);
140
+
141
+ const result = await runBatchEnrichment({
142
+ client: CLIENT,
143
+ input: { records: records('a', 'b') },
144
+ adapter: harness.adapter,
145
+ });
146
+
147
+ expect(harness.readRecords).toHaveBeenCalledTimes(1);
148
+ expect(harness.readRecords).toHaveBeenCalledWith({
149
+ client: CLIENT,
150
+ recordIds: ['a', 'b'],
151
+ });
152
+ expect(harness.enrichBatch).toHaveBeenCalledTimes(1);
153
+ expect(harness.enrichBatch).toHaveBeenCalledWith([{ id: 'a' }, { id: 'b' }]);
154
+ expect(harness.updateOne).toHaveBeenCalledTimes(2);
155
+ expect(result).toMatchObject({
156
+ total: 2,
157
+ matched: 2,
158
+ errored: 0,
159
+ success: true,
160
+ });
161
+ });
162
+
163
+ it('writes NOT_FOUND and ERROR statuses with batched status updates', async () => {
164
+ const harness = buildHarness([
165
+ { id: 'a', outcome: { outcome: 'not_found', httpStatus: 404 } },
166
+ { id: 'b', outcome: { outcome: 'not_found', httpStatus: 404 } },
167
+ { id: 'c', outcome: { outcome: 'error', httpStatus: 500, message: 'boom' } },
168
+ ]);
169
+
170
+ const result = await runBatchEnrichment({
171
+ client: CLIENT,
172
+ input: { records: records('a', 'b', 'c') },
173
+ adapter: harness.adapter,
174
+ });
175
+
176
+ expect(harness.updateOne).not.toHaveBeenCalled();
177
+ expect(harness.updateManyStatus).toHaveBeenCalledWith({
178
+ client: CLIENT,
179
+ recordIds: ['c'],
180
+ data: {
181
+ pdlEnrichmentStatus: 'ERROR',
182
+ pdlLastEnrichedAt: expect.any(String),
183
+ },
184
+ });
185
+ expect(harness.updateManyStatus).toHaveBeenCalledWith({
186
+ client: CLIENT,
187
+ recordIds: ['a', 'b'],
188
+ data: {
189
+ pdlEnrichmentStatus: 'NOT_FOUND',
190
+ pdlLastEnrichedAt: expect.any(String),
191
+ },
192
+ });
193
+ expect(result).toMatchObject({ notFound: 2, errored: 1, matched: 0 });
194
+ expect(result.results.find((entry) => entry.recordId === 'c')?.error).toBe(
195
+ 'boom',
196
+ );
197
+ });
198
+
199
+ it('skips no-identifier records before the PDL call', async () => {
200
+ const harness = buildHarness([{ id: 'a', hasIdentifier: false }, { id: 'b' }]);
201
+
202
+ const result = await runBatchEnrichment({
203
+ client: CLIENT,
204
+ input: { records: records('a', 'b') },
205
+ adapter: harness.adapter,
206
+ });
207
+
208
+ expect(harness.enrichBatch).toHaveBeenCalledWith([{ id: 'b' }]);
209
+ expect(result).toMatchObject({ skipped: 1, matched: 1 });
210
+ });
211
+
212
+ it('maps "Yes and overwrite" to overrideExistingValues and persisting', async () => {
213
+ const harness = buildHarness([{ id: 'a' }]);
214
+
215
+ await runBatchEnrichment({
216
+ client: CLIENT,
217
+ input: { records: records('a'), updateFields: UPDATE_FIELDS_OPTIONS.overwrite },
218
+ adapter: harness.adapter,
219
+ });
220
+
221
+ expect(harness.buildMatchedData).toHaveBeenCalledWith(
222
+ expect.objectContaining({ overrideExistingValues: true, shouldPersist: true }),
223
+ );
224
+ });
225
+
226
+ it('defaults to fill-empty persisting when updateFields is omitted', async () => {
227
+ const harness = buildHarness([{ id: 'a' }]);
228
+
229
+ await runBatchEnrichment({
230
+ client: CLIENT,
231
+ input: { records: records('a') },
232
+ adapter: harness.adapter,
233
+ });
234
+
235
+ expect(harness.buildMatchedData).toHaveBeenCalledWith(
236
+ expect.objectContaining({
237
+ overrideExistingValues: false,
238
+ shouldPersist: true,
239
+ }),
240
+ );
241
+ });
242
+
243
+ it('returns mapped data without writing anything when updateFields is "No"', async () => {
244
+ const harness = buildHarness([
245
+ { id: 'a' },
246
+ { id: 'b', outcome: { outcome: 'not_found', httpStatus: 404 } },
247
+ ]);
248
+
249
+ const result = await runBatchEnrichment({
250
+ client: CLIENT,
251
+ input: { records: records('a', 'b'), updateFields: UPDATE_FIELDS_OPTIONS.no },
252
+ adapter: harness.adapter,
253
+ });
254
+
255
+ expect(harness.buildMatchedData).toHaveBeenCalledWith(
256
+ expect.objectContaining({ shouldPersist: false }),
257
+ );
258
+ expect(harness.updateOne).not.toHaveBeenCalled();
259
+ expect(harness.updateManyStatus).not.toHaveBeenCalled();
260
+
261
+ const matched = result.results.find((entry) => entry.recordId === 'a');
262
+ expect(matched?.status).toBe('MATCHED');
263
+ expect(matched?.updatedFields).toEqual([]);
264
+ expect(matched?.data).toEqual({ mapped: 'a' });
265
+ expect(result).toMatchObject({ matched: 1, notFound: 1 });
266
+ });
267
+
268
+ it('marks missing records as ERROR without enriching them', async () => {
269
+ const harness = buildHarness([{ id: 'a' }, { id: 'b', exists: false }]);
270
+
271
+ const result = await runBatchEnrichment({
272
+ client: CLIENT,
273
+ input: { records: records('a', 'b') },
274
+ adapter: harness.adapter,
275
+ });
276
+
277
+ expect(harness.enrichBatch).toHaveBeenCalledWith([{ id: 'a' }]);
278
+ expect(result.results.find((entry) => entry.recordId === 'b')).toMatchObject({
279
+ status: 'ERROR',
280
+ error: 'Test b not found',
281
+ });
282
+ expect(result).toMatchObject({ matched: 1, errored: 1 });
283
+ });
284
+
285
+ it('isolates a per-record matched update failure', async () => {
286
+ const harness = buildHarness([{ id: 'a' }, { id: 'b', updateFails: true }]);
287
+
288
+ const result = await runBatchEnrichment({
289
+ client: CLIENT,
290
+ input: { records: records('a', 'b') },
291
+ adapter: harness.adapter,
292
+ });
293
+
294
+ expect(
295
+ result.results.find((entry) => entry.recordId === 'a')?.status,
296
+ ).toBe('MATCHED');
297
+ expect(result.results.find((entry) => entry.recordId === 'b')).toMatchObject({
298
+ status: 'ERROR',
299
+ error: 'update failed',
300
+ });
301
+ expect(harness.updateManyStatus).toHaveBeenCalledWith({
302
+ client: CLIENT,
303
+ recordIds: ['b'],
304
+ data: {
305
+ pdlEnrichmentStatus: 'ERROR',
306
+ pdlLastEnrichedAt: expect.any(String),
307
+ },
308
+ });
309
+ });
310
+
311
+ it('marks all attempted records as ERROR and writes the status when the batch PDL call rejects', async () => {
312
+ const harness = buildHarness([{ id: 'a' }, { id: 'b' }]);
313
+ harness.enrichBatch.mockRejectedValueOnce(new Error('pdl down'));
314
+
315
+ const result = await runBatchEnrichment({
316
+ client: CLIENT,
317
+ input: { records: records('a', 'b') },
318
+ adapter: harness.adapter,
319
+ });
320
+
321
+ expect(result).toMatchObject({ errored: 2, matched: 0 });
322
+ expect(result.results[0].error).toBe('pdl down');
323
+ expect(harness.updateOne).not.toHaveBeenCalled();
324
+ expect(harness.updateManyStatus).toHaveBeenCalledWith({
325
+ client: CLIENT,
326
+ recordIds: ['a', 'b'],
327
+ data: {
328
+ pdlEnrichmentStatus: 'ERROR',
329
+ pdlLastEnrichedAt: expect.any(String),
330
+ },
331
+ });
332
+ });
333
+
334
+ it('isolates a record whose matched-data build throws', async () => {
335
+ const harness = buildHarness([{ id: 'a' }, { id: 'b', buildFails: true }]);
336
+
337
+ const result = await runBatchEnrichment({
338
+ client: CLIENT,
339
+ input: { records: records('a', 'b') },
340
+ adapter: harness.adapter,
341
+ });
342
+
343
+ expect(
344
+ result.results.find((entry) => entry.recordId === 'a')?.status,
345
+ ).toBe('MATCHED');
346
+ expect(result.results.find((entry) => entry.recordId === 'b')).toMatchObject({
347
+ status: 'ERROR',
348
+ error: 'build failed',
349
+ });
350
+ expect(harness.updateOne).toHaveBeenCalledTimes(1);
351
+ expect(harness.updateManyStatus).toHaveBeenCalledWith({
352
+ client: CLIENT,
353
+ recordIds: ['b'],
354
+ data: {
355
+ pdlEnrichmentStatus: 'ERROR',
356
+ pdlLastEnrichedAt: expect.any(String),
357
+ },
358
+ });
359
+ });
360
+
361
+ it('produces exactly one result per record with counts summing to the total', async () => {
362
+ const harness = buildHarness([
363
+ { id: 'matched' },
364
+ { id: 'notfound', outcome: { outcome: 'not_found', httpStatus: 404 } },
365
+ { id: 'errored', outcome: { outcome: 'error', httpStatus: 500, message: 'x' } },
366
+ { id: 'skipped', hasIdentifier: false },
367
+ { id: 'missing', exists: false },
368
+ ]);
369
+
370
+ const result = await runBatchEnrichment({
371
+ client: CLIENT,
372
+ input: {
373
+ records: records('matched', 'notfound', 'errored', 'skipped', 'missing'),
374
+ },
375
+ adapter: harness.adapter,
376
+ });
377
+
378
+ const recordIds = result.results.map((entry) => entry.recordId);
379
+ expect(new Set(recordIds).size).toBe(recordIds.length);
380
+ expect(result.results).toHaveLength(result.total);
381
+ expect(
382
+ result.matched + result.notFound + result.skipped + result.errored,
383
+ ).toBe(result.total);
384
+ expect(result).toMatchObject({
385
+ total: 5,
386
+ matched: 1,
387
+ notFound: 1,
388
+ errored: 2,
389
+ skipped: 1,
390
+ success: false,
391
+ });
392
+ });
393
+
394
+ it('deduplicates record ids', async () => {
395
+ const harness = buildHarness([{ id: 'a' }]);
396
+
397
+ const result = await runBatchEnrichment({
398
+ client: CLIENT,
399
+ input: { records: records('a', 'a') },
400
+ adapter: harness.adapter,
401
+ });
402
+
403
+ expect(harness.enrichBatch).toHaveBeenCalledWith([{ id: 'a' }]);
404
+ expect(result.total).toBe(1);
405
+ });
406
+
407
+ it('chunks large id sets into separate read and PDL calls', async () => {
408
+ const ids = Array.from({ length: 150 }, (_unused, index) => `r${index}`);
409
+ const harness = buildHarness(ids.map((id) => ({ id })));
410
+
411
+ const result = await runBatchEnrichment({
412
+ client: CLIENT,
413
+ input: { records: ids.map((id) => ({ id })) },
414
+ adapter: harness.adapter,
415
+ });
416
+
417
+ expect(harness.readRecords).toHaveBeenCalledTimes(2);
418
+ expect(harness.enrichBatch).toHaveBeenCalledTimes(2);
419
+ expect(result.matched).toBe(150);
420
+ });
421
+
422
+ it('bills only matched outcomes after the PDL call', async () => {
423
+ const harness = buildHarness([
424
+ { id: 'a' },
425
+ { id: 'b' },
426
+ { id: 'c', outcome: { outcome: 'not_found', httpStatus: 404 } },
427
+ { id: 'd', outcome: { outcome: 'error', httpStatus: 500, message: 'x' } },
428
+ { id: 'e', hasIdentifier: false },
429
+ ]);
430
+
431
+ await runBatchEnrichment({
432
+ client: CLIENT,
433
+ input: { records: records('a', 'b', 'c', 'd', 'e') },
434
+ adapter: harness.adapter,
435
+ });
436
+
437
+ expect(chargeCredits).toHaveBeenCalledExactlyOnceWith({
438
+ creditsUsedMicro: 2 * FAKE_CREDITS_PER_MATCH_MICRO,
439
+ operationType: 'CODE_EXECUTION',
440
+ quantity: 2,
441
+ resourceContext: 'pdl/test',
442
+ });
443
+ });
444
+
445
+ it('does not bill when no record matches', async () => {
446
+ const harness = buildHarness([
447
+ { id: 'a', outcome: { outcome: 'not_found', httpStatus: 404 } },
448
+ { id: 'b', hasIdentifier: false },
449
+ ]);
450
+
451
+ await runBatchEnrichment({
452
+ client: CLIENT,
453
+ input: { records: records('a', 'b') },
454
+ adapter: harness.adapter,
455
+ });
456
+
457
+ expect(chargeCredits).not.toHaveBeenCalled();
458
+ });
459
+
460
+ it('still bills a match whose record write fails', async () => {
461
+ const harness = buildHarness([{ id: 'a', updateFails: true }]);
462
+
463
+ await runBatchEnrichment({
464
+ client: CLIENT,
465
+ input: { records: records('a') },
466
+ adapter: harness.adapter,
467
+ });
468
+
469
+ expect(chargeCredits).toHaveBeenCalledExactlyOnceWith(
470
+ expect.objectContaining({
471
+ creditsUsedMicro: FAKE_CREDITS_PER_MATCH_MICRO,
472
+ quantity: 1,
473
+ }),
474
+ );
475
+ });
476
+
477
+ it('bills each chunk separately', async () => {
478
+ const ids = Array.from({ length: 150 }, (_unused, index) => `r${index}`);
479
+ const harness = buildHarness(ids.map((id) => ({ id })));
480
+
481
+ await runBatchEnrichment({
482
+ client: CLIENT,
483
+ input: { records: ids.map((id) => ({ id })) },
484
+ adapter: harness.adapter,
485
+ });
486
+
487
+ expect(chargeCredits).toHaveBeenCalledTimes(2);
488
+ expect(chargeCredits).toHaveBeenNthCalledWith(
489
+ 1,
490
+ expect.objectContaining({
491
+ creditsUsedMicro: 100 * FAKE_CREDITS_PER_MATCH_MICRO,
492
+ quantity: 100,
493
+ }),
494
+ );
495
+ expect(chargeCredits).toHaveBeenNthCalledWith(
496
+ 2,
497
+ expect.objectContaining({
498
+ creditsUsedMicro: 50 * FAKE_CREDITS_PER_MATCH_MICRO,
499
+ quantity: 50,
500
+ }),
501
+ );
502
+ });
503
+
504
+ it('returns an empty summary when there are no records', async () => {
505
+ const harness = buildHarness([]);
506
+
507
+ const result = await runBatchEnrichment({
508
+ client: CLIENT,
509
+ input: { records: [] },
510
+ adapter: harness.adapter,
511
+ });
512
+
513
+ expect(harness.readRecords).not.toHaveBeenCalled();
514
+ expect(result).toEqual({
515
+ success: true,
516
+ total: 0,
517
+ matched: 0,
518
+ notFound: 0,
519
+ skipped: 0,
520
+ errored: 0,
521
+ results: [],
522
+ });
523
+ });
524
+ });
@@ -0,0 +1,15 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { salaryTransform } from 'src/logic-functions/utils/salary-transform';
4
+
5
+ describe('salaryTransform', () => {
6
+ it('maps PDL salary ranges to option values', () => {
7
+ expect(salaryTransform('<20,000')).toBe('UNDER_20000');
8
+ expect(salaryTransform('45,000-55,000')).toBe('FROM_45000_TO_55000');
9
+ expect(salaryTransform('>250,000')).toBe('OVER_250000');
10
+ });
11
+
12
+ it('returns undefined for an unknown range', () => {
13
+ expect(salaryTransform('weird')).toBeUndefined();
14
+ });
15
+ });
@@ -0,0 +1,136 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { createCoreApiClientMock } from 'src/logic-functions/__mocks__/create-core-api-client-mock';
4
+ import { seedEnrichmentWorkflow } from 'src/logic-functions/utils/seed-enrichment-workflow';
5
+ import { type EnrichmentWorkflowSeed } from 'src/types/enrichment-workflow-seed';
6
+
7
+ const SEED: EnrichmentWorkflowSeed = {
8
+ objectNameSingular: 'company',
9
+ workflowName: 'Enrich companies with People Data Labs',
10
+ triggerName: 'When companies are selected',
11
+ icon: 'IconSparkles',
12
+ stepName: 'Enrich with People Data Labs',
13
+ logicFunctionUniversalIdentifier: 'lf-universal-id',
14
+ logicFunctionInput: { records: '{{trigger.companies}}' },
15
+ };
16
+
17
+ type AnyRequest = Record<string, any>;
18
+
19
+ describe('seedEnrichmentWorkflow', () => {
20
+ it('creates, configures and activates a new workflow', async () => {
21
+ const mutations: AnyRequest[] = [];
22
+
23
+ const client = createCoreApiClientMock({
24
+ queryResult: (request: unknown) => {
25
+ const req = request as AnyRequest;
26
+ if ('workflows' in req) {
27
+ return { workflows: { edges: [] } };
28
+ }
29
+ if ('workflowVersions' in req) {
30
+ return {
31
+ workflowVersions: {
32
+ edges: [{ node: { id: 'version-1', status: 'DRAFT' } }],
33
+ },
34
+ };
35
+ }
36
+ return {};
37
+ },
38
+ mutationResult: (request: unknown) =>
39
+ 'createWorkflow' in (request as AnyRequest)
40
+ ? { createWorkflow: { id: 'workflow-1' } }
41
+ : {},
42
+ onMutation: (request) => mutations.push(request as AnyRequest),
43
+ });
44
+
45
+ const result = await seedEnrichmentWorkflow({
46
+ client,
47
+ logicFunctionId: 'logic-function-1',
48
+ seed: SEED,
49
+ });
50
+
51
+ expect(result).toEqual({
52
+ objectNameSingular: 'company',
53
+ workflowName: SEED.workflowName,
54
+ status: 'created',
55
+ workflowId: 'workflow-1',
56
+ });
57
+
58
+ const createRequest = mutations.find(
59
+ (request) => 'createWorkflow' in request,
60
+ );
61
+ expect(createRequest?.createWorkflow.__args.data).toEqual({
62
+ name: SEED.workflowName,
63
+ });
64
+
65
+ const updateRequest = mutations.find(
66
+ (request) => 'updateWorkflowVersion' in request,
67
+ );
68
+ const { id, data } = updateRequest?.updateWorkflowVersion.__args ?? {};
69
+ expect(id).toBe('version-1');
70
+
71
+ expect(data.trigger.type).toBe('MANUAL');
72
+ expect(data.trigger.settings.availability).toEqual({
73
+ type: 'BULK_RECORDS',
74
+ objectNameSingular: 'company',
75
+ });
76
+ expect(data.trigger.settings.objectType).toBe('company');
77
+ expect(data.trigger.nextStepIds).toEqual([]);
78
+ expect(data.steps).toBeUndefined();
79
+
80
+ const createStepRequest = mutations.find(
81
+ (request) => 'createWorkflowVersionStep' in request,
82
+ );
83
+ const createStepInput =
84
+ createStepRequest?.createWorkflowVersionStep.__args.input;
85
+ expect(createStepInput.workflowVersionId).toBe('version-1');
86
+ expect(createStepInput.stepType).toBe('LOGIC_FUNCTION');
87
+ expect(createStepInput.parentStepId).toBe('trigger');
88
+ expect(createStepInput.defaultSettings.input.logicFunctionId).toBe(
89
+ 'logic-function-1',
90
+ );
91
+
92
+ const updateStepRequest = mutations.find(
93
+ (request) => 'updateWorkflowVersionStep' in request,
94
+ );
95
+ const updateStepInput =
96
+ updateStepRequest?.updateWorkflowVersionStep.__args.input;
97
+ expect(updateStepInput.workflowVersionId).toBe('version-1');
98
+ expect(updateStepInput.step.id).toBe(createStepInput.id);
99
+ expect(updateStepInput.step.type).toBe('LOGIC_FUNCTION');
100
+ expect(updateStepInput.step.settings.input.logicFunctionId).toBe(
101
+ 'logic-function-1',
102
+ );
103
+ expect(updateStepInput.step.settings.input.logicFunctionInput).toEqual({
104
+ records: '{{trigger.companies}}',
105
+ });
106
+
107
+ const activateRequest = mutations.find(
108
+ (request) => 'activateWorkflowVersion' in request,
109
+ );
110
+ expect(
111
+ activateRequest?.activateWorkflowVersion.__args.workflowVersionId,
112
+ ).toBe('version-1');
113
+ });
114
+
115
+ it('skips creation when a workflow with the same name already exists', async () => {
116
+ const mutations: AnyRequest[] = [];
117
+
118
+ const client = createCoreApiClientMock({
119
+ queryResult: (request: unknown) =>
120
+ 'workflows' in (request as AnyRequest)
121
+ ? { workflows: { edges: [{ node: { id: 'existing-1' } }] } }
122
+ : {},
123
+ onMutation: (request) => mutations.push(request as AnyRequest),
124
+ });
125
+
126
+ const result = await seedEnrichmentWorkflow({
127
+ client,
128
+ logicFunctionId: 'logic-function-1',
129
+ seed: SEED,
130
+ });
131
+
132
+ expect(result.status).toBe('skipped');
133
+ expect(result.workflowId).toBe('existing-1');
134
+ expect(mutations).toHaveLength(0);
135
+ });
136
+ });
@@ -0,0 +1,18 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { sizeTransform } from 'src/logic-functions/utils/size-transform';
4
+
5
+ describe('sizeTransform', () => {
6
+ it('maps PDL size ranges to option values', () => {
7
+ expect(sizeTransform('1-10')).toBe('ONE_TO_TEN');
8
+ expect(sizeTransform('10001+')).toBe('TEN_THOUSAND_ONE_PLUS');
9
+ });
10
+
11
+ it('tolerates spacing variants', () => {
12
+ expect(sizeTransform('51 - 200')).toBe('FIFTY_ONE_TO_TWO_HUNDRED');
13
+ });
14
+
15
+ it('returns undefined for an unknown range', () => {
16
+ expect(sizeTransform('weird')).toBeUndefined();
17
+ });
18
+ });