@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.
- package/.claude/settings.local.json +7 -0
- package/.nvmrc +1 -0
- package/.oxlintrc.json +58 -0
- package/.yarnrc.yml +1 -0
- package/README.md +16 -0
- package/package.json +37 -0
- package/public/gallery/cover.png +0 -0
- package/public/people-data-labs-icon.png +0 -0
- package/src/__tests__/global-setup.ts +87 -0
- package/src/__tests__/people-data-labs.integration-test.ts +25 -0
- package/src/application-config.ts +18 -0
- package/src/command-menu-items/enrich-companies.ts +14 -0
- package/src/command-menu-items/enrich-people.ts +14 -0
- package/src/constants/__tests__/select-option-constants.spec.ts +142 -0
- package/src/constants/billing-margin-multiplier.ts +1 -0
- package/src/constants/company-match-cost-dollars.ts +1 -0
- package/src/constants/company-type-options.ts +46 -0
- package/src/constants/enrichment-status-options.ts +19 -0
- package/src/constants/enrichment-workflow-seeds.ts +27 -0
- package/src/constants/funding-stage-options.ts +195 -0
- package/src/constants/industry-options.ts +1033 -0
- package/src/constants/inferred-salary-options.ts +81 -0
- package/src/constants/job-role-options.ts +172 -0
- package/src/constants/job-title-class-options.ts +39 -0
- package/src/constants/job-title-sub-role-options.ts +746 -0
- package/src/constants/location-continent-options.ts +53 -0
- package/src/constants/metro-options.ts +2692 -0
- package/src/constants/mic-exchange-options.ts +494 -0
- package/src/constants/micro-credits-per-dollar.ts +1 -0
- package/src/constants/pdl-base-url.ts +1 -0
- package/src/constants/person-match-cost-dollars.ts +1 -0
- package/src/constants/seniority-options.ts +74 -0
- package/src/constants/sex-options.ts +18 -0
- package/src/constants/size-options.ts +60 -0
- package/src/constants/universal-identifiers.ts +1516 -0
- package/src/constants/update-fields-option-values.ts +5 -0
- package/src/constants/update-fields-options.ts +7 -0
- package/src/fields/company/pdl-affiliated-profiles.field.ts +20 -0
- package/src/fields/company/pdl-alternative-domains.field.ts +20 -0
- package/src/fields/company/pdl-alternative-names.field.ts +20 -0
- package/src/fields/company/pdl-company-type.field.ts +28 -0
- package/src/fields/company/pdl-employee-count-by-country.field.ts +21 -0
- package/src/fields/company/pdl-employee-count.field.ts +19 -0
- package/src/fields/company/pdl-enrichment-status.field.ts +29 -0
- package/src/fields/company/pdl-facebook-url.field.ts +19 -0
- package/src/fields/company/pdl-founded-year.field.ts +19 -0
- package/src/fields/company/pdl-funding-stages.field.ts +28 -0
- package/src/fields/company/pdl-headline.field.ts +19 -0
- package/src/fields/company/pdl-id.field.ts +19 -0
- package/src/fields/company/pdl-industry-detail.field.ts +20 -0
- package/src/fields/company/pdl-industry.field.ts +28 -0
- package/src/fields/company/pdl-last-enriched-at.field.ts +20 -0
- package/src/fields/company/pdl-last-funding-date.field.ts +20 -0
- package/src/fields/company/pdl-latest-funding-stage.field.ts +29 -0
- package/src/fields/company/pdl-legal-name.field.ts +19 -0
- package/src/fields/company/pdl-linkedin-id.field.ts +19 -0
- package/src/fields/company/pdl-location-continent.field.ts +29 -0
- package/src/fields/company/pdl-location-metro.field.ts +28 -0
- package/src/fields/company/pdl-mic-exchange.field.ts +28 -0
- package/src/fields/company/pdl-naics.field.ts +19 -0
- package/src/fields/company/pdl-number-funding-rounds.field.ts +20 -0
- package/src/fields/company/pdl-raw-payload.field.ts +19 -0
- package/src/fields/company/pdl-sic.field.ts +19 -0
- package/src/fields/company/pdl-size-range.field.ts +28 -0
- package/src/fields/company/pdl-summary.field.ts +19 -0
- package/src/fields/company/pdl-tags.field.ts +19 -0
- package/src/fields/company/pdl-ticker.field.ts +19 -0
- package/src/fields/company/pdl-total-funding.field.ts +19 -0
- package/src/fields/company/pdl-twitter-url.field.ts +19 -0
- package/src/fields/person/pdl-birth-date.field.ts +19 -0
- package/src/fields/person/pdl-birth-year.field.ts +19 -0
- package/src/fields/person/pdl-certifications.field.ts +19 -0
- package/src/fields/person/pdl-education.field.ts +19 -0
- package/src/fields/person/pdl-enrichment-status.field.ts +29 -0
- package/src/fields/person/pdl-experience.field.ts +19 -0
- package/src/fields/person/pdl-facebook-url.field.ts +19 -0
- package/src/fields/person/pdl-github-url.field.ts +19 -0
- package/src/fields/person/pdl-headline.field.ts +19 -0
- package/src/fields/person/pdl-id.field.ts +19 -0
- package/src/fields/person/pdl-industry.field.ts +28 -0
- package/src/fields/person/pdl-inferred-salary.field.ts +28 -0
- package/src/fields/person/pdl-interests.field.ts +19 -0
- package/src/fields/person/pdl-job-onet-code.field.ts +19 -0
- package/src/fields/person/pdl-job-role.field.ts +28 -0
- package/src/fields/person/pdl-job-start-date.field.ts +19 -0
- package/src/fields/person/pdl-job-summary.field.ts +19 -0
- package/src/fields/person/pdl-job-title-class.field.ts +28 -0
- package/src/fields/person/pdl-job-title-sub-role.field.ts +29 -0
- package/src/fields/person/pdl-languages.field.ts +19 -0
- package/src/fields/person/pdl-last-enriched-at.field.ts +19 -0
- package/src/fields/person/pdl-likelihood.field.ts +19 -0
- package/src/fields/person/pdl-linkedin-connections.field.ts +20 -0
- package/src/fields/person/pdl-linkedin-username.field.ts +20 -0
- package/src/fields/person/pdl-location-metro.field.ts +28 -0
- package/src/fields/person/pdl-location.field.ts +19 -0
- package/src/fields/person/pdl-name-aliases.field.ts +19 -0
- package/src/fields/person/pdl-profiles.field.ts +19 -0
- package/src/fields/person/pdl-raw-payload.field.ts +19 -0
- package/src/fields/person/pdl-seniority.field.ts +28 -0
- package/src/fields/person/pdl-sex.field.ts +28 -0
- package/src/fields/person/pdl-skills.field.ts +19 -0
- package/src/fields/person/pdl-summary.field.ts +19 -0
- package/src/fields/person/pdl-twitter-url.field.ts +19 -0
- package/src/fields/person/pdl-years-experience.field.ts +21 -0
- package/src/front-components/enrich-companies-component-effect.tsx +21 -0
- package/src/front-components/enrich-people-component-effect.tsx +21 -0
- package/src/front-components/utils/call-enrich-logic-function.utils.ts +21 -0
- package/src/logic-functions/__mocks__/company-node.mock.ts +11 -0
- package/src/logic-functions/__mocks__/create-core-api-client-mock.ts +35 -0
- package/src/logic-functions/__mocks__/pdl-company-data.mock.ts +27 -0
- package/src/logic-functions/__mocks__/pdl-person-data.mock.ts +23 -0
- package/src/logic-functions/__mocks__/person-node.mock.ts +12 -0
- package/src/logic-functions/enrich-companies.function.ts +76 -0
- package/src/logic-functions/enrich-company.function.ts +73 -0
- package/src/logic-functions/enrich-people.function.ts +76 -0
- package/src/logic-functions/enrich-person.function.ts +73 -0
- package/src/logic-functions/errors/__tests__/pdl-config-error.spec.ts +16 -0
- package/src/logic-functions/errors/__tests__/pdl-invalid-input-error.spec.ts +16 -0
- package/src/logic-functions/errors/__tests__/pdl-operation-error.spec.ts +16 -0
- package/src/logic-functions/errors/__tests__/pdl-record-not-found-error.spec.ts +21 -0
- package/src/logic-functions/errors/pdl-config-error.ts +8 -0
- package/src/logic-functions/errors/pdl-error-code.ts +8 -0
- package/src/logic-functions/errors/pdl-error.ts +12 -0
- package/src/logic-functions/errors/pdl-invalid-input-error.ts +8 -0
- package/src/logic-functions/errors/pdl-operation-error.ts +8 -0
- package/src/logic-functions/errors/pdl-record-not-found-error.ts +22 -0
- package/src/logic-functions/handlers/__tests__/enrich-companies.spec.ts +159 -0
- package/src/logic-functions/handlers/__tests__/enrich-company.spec.ts +147 -0
- package/src/logic-functions/handlers/__tests__/enrich-people.spec.ts +313 -0
- package/src/logic-functions/handlers/__tests__/enrich-person.spec.ts +198 -0
- package/src/logic-functions/handlers/__tests__/post-install.spec.ts +153 -0
- package/src/logic-functions/handlers/company-enrichment-adapter.ts +42 -0
- package/src/logic-functions/handlers/company-single-enrichment-adapter.ts +15 -0
- package/src/logic-functions/handlers/enrich-companies.ts +15 -0
- package/src/logic-functions/handlers/enrich-company.ts +19 -0
- package/src/logic-functions/handlers/enrich-people.ts +15 -0
- package/src/logic-functions/handlers/enrich-person.ts +19 -0
- package/src/logic-functions/handlers/person-enrichment-adapter.ts +29 -0
- package/src/logic-functions/handlers/person-single-enrichment-adapter.ts +15 -0
- package/src/logic-functions/handlers/post-install.ts +69 -0
- package/src/logic-functions/post-install.function.ts +17 -0
- package/src/logic-functions/utils/__tests__/aggregate-bulk-enrich-result.spec.ts +52 -0
- package/src/logic-functions/utils/__tests__/build-address.spec.ts +30 -0
- package/src/logic-functions/utils/__tests__/build-allowed-values.spec.ts +16 -0
- package/src/logic-functions/utils/__tests__/build-bulk-records-trigger.spec.ts +26 -0
- package/src/logic-functions/utils/__tests__/build-company-create-data.spec.ts +37 -0
- package/src/logic-functions/utils/__tests__/build-company-match-keys.spec.ts +35 -0
- package/src/logic-functions/utils/__tests__/build-company-matched-data.spec.ts +56 -0
- package/src/logic-functions/utils/__tests__/build-currency-from-usd.spec.ts +17 -0
- package/src/logic-functions/utils/__tests__/build-emails.spec.ts +23 -0
- package/src/logic-functions/utils/__tests__/build-error-result.spec.ts +16 -0
- package/src/logic-functions/utils/__tests__/build-full-name.spec.ts +64 -0
- package/src/logic-functions/utils/__tests__/build-links.spec.ts +25 -0
- package/src/logic-functions/utils/__tests__/build-logic-function-step.spec.ts +33 -0
- package/src/logic-functions/utils/__tests__/build-matched-result.spec.ts +33 -0
- package/src/logic-functions/utils/__tests__/build-not-found-result.spec.ts +15 -0
- package/src/logic-functions/utils/__tests__/build-person-matched-data.spec.ts +117 -0
- package/src/logic-functions/utils/__tests__/build-person-name-param.spec.ts +17 -0
- package/src/logic-functions/utils/__tests__/build-phones.spec.ts +32 -0
- package/src/logic-functions/utils/__tests__/build-skipped-result.spec.ts +17 -0
- package/src/logic-functions/utils/__tests__/capitalize-name.spec.ts +26 -0
- package/src/logic-functions/utils/__tests__/capitalize-name.test.ts +17 -0
- package/src/logic-functions/utils/__tests__/charge-matched-enrichments.spec.ts +56 -0
- package/src/logic-functions/utils/__tests__/chunk.spec.ts +25 -0
- package/src/logic-functions/utils/__tests__/enrich-companies.spec.ts +26 -0
- package/src/logic-functions/utils/__tests__/enrich-company.spec.ts +54 -0
- package/src/logic-functions/utils/__tests__/enrich-people.spec.ts +32 -0
- package/src/logic-functions/utils/__tests__/enrich-person.spec.ts +62 -0
- package/src/logic-functions/utils/__tests__/extract-company-match-params.spec.ts +86 -0
- package/src/logic-functions/utils/__tests__/extract-pdl-error-message.spec.ts +17 -0
- package/src/logic-functions/utils/__tests__/extract-person-match-params.spec.ts +75 -0
- package/src/logic-functions/utils/__tests__/extract-record-ids.spec.ts +32 -0
- package/src/logic-functions/utils/__tests__/find-company-id-by-filter.spec.ts +42 -0
- package/src/logic-functions/utils/__tests__/find-company-id.spec.ts +118 -0
- package/src/logic-functions/utils/__tests__/find-existing-workflow-id.spec.ts +26 -0
- package/src/logic-functions/utils/__tests__/find-or-create-current-company.spec.ts +203 -0
- package/src/logic-functions/utils/__tests__/get-pdl-api-key.spec.ts +38 -0
- package/src/logic-functions/utils/__tests__/is-empty-address.spec.ts +20 -0
- package/src/logic-functions/utils/__tests__/is-empty-emails.spec.ts +14 -0
- package/src/logic-functions/utils/__tests__/is-empty-full-name.spec.ts +14 -0
- package/src/logic-functions/utils/__tests__/is-empty-links.spec.ts +14 -0
- package/src/logic-functions/utils/__tests__/is-empty-phones.spec.ts +14 -0
- package/src/logic-functions/utils/__tests__/is-empty-text.spec.ts +15 -0
- package/src/logic-functions/utils/__tests__/map-company.spec.ts +48 -0
- package/src/logic-functions/utils/__tests__/map-person.spec.ts +81 -0
- package/src/logic-functions/utils/__tests__/normalize-domain.spec.ts +19 -0
- package/src/logic-functions/utils/__tests__/normalize-linkedin-url.spec.ts +22 -0
- package/src/logic-functions/utils/__tests__/now-iso.spec.ts +9 -0
- package/src/logic-functions/utils/__tests__/parse-geo.spec.ts +21 -0
- package/src/logic-functions/utils/__tests__/parse-partial-date.spec.ts +29 -0
- package/src/logic-functions/utils/__tests__/parse-pdl-item.spec.ts +88 -0
- package/src/logic-functions/utils/__tests__/pick-multi-select.spec.ts +28 -0
- package/src/logic-functions/utils/__tests__/pick-select.spec.ts +38 -0
- package/src/logic-functions/utils/__tests__/pick-writable-standard.spec.ts +37 -0
- package/src/logic-functions/utils/__tests__/post-pdl-enrich.spec.ts +192 -0
- package/src/logic-functions/utils/__tests__/post-pdl-single-enrich.spec.ts +172 -0
- package/src/logic-functions/utils/__tests__/read-companies.spec.ts +39 -0
- package/src/logic-functions/utils/__tests__/read-people.spec.ts +40 -0
- package/src/logic-functions/utils/__tests__/resolve-logic-function-id.spec.ts +25 -0
- package/src/logic-functions/utils/__tests__/resolve-update-fields-mode.spec.ts +34 -0
- package/src/logic-functions/utils/__tests__/run-batch-enrichment.spec.ts +524 -0
- package/src/logic-functions/utils/__tests__/salary-transform.spec.ts +15 -0
- package/src/logic-functions/utils/__tests__/seed-enrichment-workflow.spec.ts +136 -0
- package/src/logic-functions/utils/__tests__/size-transform.spec.ts +18 -0
- package/src/logic-functions/utils/__tests__/to-json-array.spec.ts +16 -0
- package/src/logic-functions/utils/__tests__/to-json-object.spec.ts +18 -0
- package/src/logic-functions/utils/__tests__/to-number.spec.ts +17 -0
- package/src/logic-functions/utils/__tests__/to-string-array.spec.ts +17 -0
- package/src/logic-functions/utils/__tests__/to-text.spec.ts +20 -0
- package/src/logic-functions/utils/__tests__/update-companies-status.spec.ts +32 -0
- package/src/logic-functions/utils/__tests__/update-company-record.spec.ts +25 -0
- package/src/logic-functions/utils/__tests__/update-people-status.spec.ts +32 -0
- package/src/logic-functions/utils/__tests__/update-person-record.spec.ts +25 -0
- package/src/logic-functions/utils/aggregate-bulk-enrich-result.ts +21 -0
- package/src/logic-functions/utils/build-address.ts +40 -0
- package/src/logic-functions/utils/build-allowed-values.ts +5 -0
- package/src/logic-functions/utils/build-bulk-records-trigger.ts +25 -0
- package/src/logic-functions/utils/build-company-create-data.ts +35 -0
- package/src/logic-functions/utils/build-company-match-keys.ts +16 -0
- package/src/logic-functions/utils/build-company-matched-data.ts +56 -0
- package/src/logic-functions/utils/build-currency-from-usd.ts +16 -0
- package/src/logic-functions/utils/build-emails.ts +34 -0
- package/src/logic-functions/utils/build-error-result.ts +18 -0
- package/src/logic-functions/utils/build-full-name.ts +38 -0
- package/src/logic-functions/utils/build-links.ts +23 -0
- package/src/logic-functions/utils/build-logic-function-step.ts +30 -0
- package/src/logic-functions/utils/build-matched-result.ts +21 -0
- package/src/logic-functions/utils/build-not-found-result.ts +9 -0
- package/src/logic-functions/utils/build-person-matched-data.ts +78 -0
- package/src/logic-functions/utils/build-person-name-param.ts +19 -0
- package/src/logic-functions/utils/build-phones.ts +40 -0
- package/src/logic-functions/utils/build-skipped-result.ts +15 -0
- package/src/logic-functions/utils/capitalize-name.ts +8 -0
- package/src/logic-functions/utils/charge-matched-enrichments.ts +29 -0
- package/src/logic-functions/utils/chunk.ts +18 -0
- package/src/logic-functions/utils/enrich-chunk.ts +361 -0
- package/src/logic-functions/utils/enrich-companies.ts +21 -0
- package/src/logic-functions/utils/enrich-company.ts +23 -0
- package/src/logic-functions/utils/enrich-people.ts +22 -0
- package/src/logic-functions/utils/enrich-person.ts +24 -0
- package/src/logic-functions/utils/extract-company-match-params.ts +52 -0
- package/src/logic-functions/utils/extract-pdl-error-message.ts +47 -0
- package/src/logic-functions/utils/extract-person-match-params.ts +59 -0
- package/src/logic-functions/utils/extract-record-ids.ts +18 -0
- package/src/logic-functions/utils/find-company-id-by-filter.ts +28 -0
- package/src/logic-functions/utils/find-company-id.ts +59 -0
- package/src/logic-functions/utils/find-existing-workflow-id.ts +18 -0
- package/src/logic-functions/utils/find-or-create-current-company.ts +108 -0
- package/src/logic-functions/utils/get-pdl-api-key.ts +15 -0
- package/src/logic-functions/utils/internal-field-names.ts +6 -0
- package/src/logic-functions/utils/is-empty-address.ts +20 -0
- package/src/logic-functions/utils/is-empty-emails.ts +13 -0
- package/src/logic-functions/utils/is-empty-full-name.ts +13 -0
- package/src/logic-functions/utils/is-empty-links.ts +13 -0
- package/src/logic-functions/utils/is-empty-phones.ts +13 -0
- package/src/logic-functions/utils/is-empty-text.ts +4 -0
- package/src/logic-functions/utils/map-company.ts +115 -0
- package/src/logic-functions/utils/map-person.ts +136 -0
- package/src/logic-functions/utils/normalize-domain.ts +22 -0
- package/src/logic-functions/utils/normalize-linkedin-url.ts +23 -0
- package/src/logic-functions/utils/now-iso.ts +1 -0
- package/src/logic-functions/utils/parse-geo.ts +33 -0
- package/src/logic-functions/utils/parse-partial-date.ts +33 -0
- package/src/logic-functions/utils/parse-pdl-item.ts +82 -0
- package/src/logic-functions/utils/pick-multi-select.ts +32 -0
- package/src/logic-functions/utils/pick-select.ts +30 -0
- package/src/logic-functions/utils/pick-writable-standard.ts +27 -0
- package/src/logic-functions/utils/post-pdl-enrich.ts +89 -0
- package/src/logic-functions/utils/post-pdl-single-enrich.ts +59 -0
- package/src/logic-functions/utils/read-companies.ts +53 -0
- package/src/logic-functions/utils/read-people.ts +48 -0
- package/src/logic-functions/utils/resolve-logic-function-id.ts +11 -0
- package/src/logic-functions/utils/resolve-min-likelihood.ts +12 -0
- package/src/logic-functions/utils/resolve-update-fields-mode.ts +16 -0
- package/src/logic-functions/utils/run-batch-enrichment.ts +50 -0
- package/src/logic-functions/utils/run-single-enrichment.ts +44 -0
- package/src/logic-functions/utils/salary-transform.ts +18 -0
- package/src/logic-functions/utils/seed-enrichment-workflow.ts +131 -0
- package/src/logic-functions/utils/size-transform.ts +15 -0
- package/src/logic-functions/utils/to-bulk-enrich-input.ts +14 -0
- package/src/logic-functions/utils/to-json-array.ts +4 -0
- package/src/logic-functions/utils/to-json-object.ts +22 -0
- package/src/logic-functions/utils/to-number.ts +4 -0
- package/src/logic-functions/utils/to-string-array.ts +28 -0
- package/src/logic-functions/utils/to-text.ts +11 -0
- package/src/logic-functions/utils/update-companies-status.ts +18 -0
- package/src/logic-functions/utils/update-company-record.ts +15 -0
- package/src/logic-functions/utils/update-people-status.ts +18 -0
- package/src/logic-functions/utils/update-person-record.ts +15 -0
- package/src/roles/default-function.role.ts +41 -0
- package/src/types/address-parts.ts +9 -0
- package/src/types/address-value.ts +10 -0
- package/src/types/batch-enrichment-adapter.ts +43 -0
- package/src/types/bulk-enrich-input.ts +9 -0
- package/src/types/bulk-enrich-result.ts +11 -0
- package/src/types/company-id-by-match-key-cache.ts +1 -0
- package/src/types/company-match-keys.ts +6 -0
- package/src/types/company-node.ts +16 -0
- package/src/types/currency-value.ts +4 -0
- package/src/types/emails-value.ts +4 -0
- package/src/types/enrich-result.ts +11 -0
- package/src/types/enrich-status.ts +1 -0
- package/src/types/enrichment-workflow-seed.ts +9 -0
- package/src/types/full-name-value.ts +4 -0
- package/src/types/links-value.ts +5 -0
- package/src/types/mapped-record.ts +4 -0
- package/src/types/pdl-company-data.ts +50 -0
- package/src/types/pdl-company-enrich-params.ts +7 -0
- package/src/types/pdl-enrich-result.ts +4 -0
- package/src/types/pdl-person-data.ts +65 -0
- package/src/types/pdl-person-enrich-params.ts +8 -0
- package/src/types/person-node.ts +11 -0
- package/src/types/phones-value.ts +12 -0
- package/src/types/post-install-result.ts +5 -0
- package/src/types/seed-enrichment-workflow-result.ts +7 -0
- package/src/types/select-option-meta.ts +9 -0
- package/src/types/single-enrich-input.ts +7 -0
- package/src/types/tag-color.ts +26 -0
- package/src/types/update-fields-option.ts +4 -0
- package/src/types/workflow-bulk-records-trigger.ts +15 -0
- package/src/types/workflow-logic-function-step.ts +18 -0
- package/src/utils/__tests__/build-select-options.spec.ts +20 -0
- package/src/utils/__tests__/is-defined.spec.ts +16 -0
- package/src/utils/__tests__/is-unique-violation-error.spec.ts +71 -0
- package/src/utils/__tests__/normalize-enum-value.spec.ts +28 -0
- package/src/utils/__tests__/prune-undefined.spec.ts +22 -0
- package/src/utils/__tests__/strip-separators.spec.ts +13 -0
- package/src/utils/__tests__/to-error-message.spec.ts +13 -0
- package/src/utils/build-select-options.ts +16 -0
- package/src/utils/is-defined.ts +5 -0
- package/src/utils/is-unique-violation-error.ts +74 -0
- package/src/utils/normalize-enum-value.ts +15 -0
- package/src/utils/prune-undefined.ts +15 -0
- package/src/utils/strip-separators.ts +4 -0
- package/src/utils/to-error-message.ts +2 -0
- package/src/views/enriched-companies.view.ts +69 -0
- package/src/views/enriched-people.view.ts +74 -0
- package/tsconfig.json +42 -0
- package/tsconfig.spec.json +9 -0
- package/vitest.config.ts +31 -0
- 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
|
+
});
|