@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,78 @@
|
|
|
1
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
2
|
+
|
|
3
|
+
import { findOrCreateCurrentCompany } from 'src/logic-functions/utils/find-or-create-current-company';
|
|
4
|
+
import { isEmptyEmails } from 'src/logic-functions/utils/is-empty-emails';
|
|
5
|
+
import { isEmptyFullName } from 'src/logic-functions/utils/is-empty-full-name';
|
|
6
|
+
import { isEmptyLinks } from 'src/logic-functions/utils/is-empty-links';
|
|
7
|
+
import { isEmptyPhones } from 'src/logic-functions/utils/is-empty-phones';
|
|
8
|
+
import { isEmptyText } from 'src/logic-functions/utils/is-empty-text';
|
|
9
|
+
import { mapPerson } from 'src/logic-functions/utils/map-person';
|
|
10
|
+
import { pickWritableStandard } from 'src/logic-functions/utils/pick-writable-standard';
|
|
11
|
+
import { type CompanyIdByMatchKeyCache } from 'src/types/company-id-by-match-key-cache';
|
|
12
|
+
import { type PdlPersonData } from 'src/types/pdl-person-data';
|
|
13
|
+
import { type PersonNode } from 'src/types/person-node';
|
|
14
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
15
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
16
|
+
|
|
17
|
+
const PERSON_EMPTY_CHECKS = {
|
|
18
|
+
name: isEmptyFullName,
|
|
19
|
+
emails: isEmptyEmails,
|
|
20
|
+
phones: isEmptyPhones,
|
|
21
|
+
jobTitle: isEmptyText,
|
|
22
|
+
linkedinLink: isEmptyLinks,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const buildPersonMatchedData = async ({
|
|
26
|
+
client,
|
|
27
|
+
node,
|
|
28
|
+
outcome,
|
|
29
|
+
enrichedAt,
|
|
30
|
+
companyIdByMatchKeyCache,
|
|
31
|
+
overrideExistingValues,
|
|
32
|
+
shouldPersist,
|
|
33
|
+
}: {
|
|
34
|
+
client: CoreApiClient;
|
|
35
|
+
node: PersonNode;
|
|
36
|
+
outcome: { likelihood?: number; data: PdlPersonData };
|
|
37
|
+
enrichedAt: string;
|
|
38
|
+
companyIdByMatchKeyCache: CompanyIdByMatchKeyCache;
|
|
39
|
+
overrideExistingValues: boolean;
|
|
40
|
+
shouldPersist: boolean;
|
|
41
|
+
}): Promise<{
|
|
42
|
+
mappedData: Record<string, unknown>;
|
|
43
|
+
persistData: Record<string, unknown>;
|
|
44
|
+
}> => {
|
|
45
|
+
const mapped = mapPerson(outcome.data);
|
|
46
|
+
const mappedData = pruneUndefined({ ...mapped.standard, ...mapped.pdl });
|
|
47
|
+
|
|
48
|
+
if (!shouldPersist) {
|
|
49
|
+
return { mappedData, persistData: {} };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const writableStandard = pickWritableStandard({
|
|
53
|
+
standard: mapped.standard,
|
|
54
|
+
current: node as unknown as Record<string, unknown>,
|
|
55
|
+
emptyChecks: PERSON_EMPTY_CHECKS,
|
|
56
|
+
overrideExistingValues,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
const currentCompanyId = isDefined(node.company?.id)
|
|
60
|
+
? undefined
|
|
61
|
+
: await findOrCreateCurrentCompany({
|
|
62
|
+
client,
|
|
63
|
+
personData: outcome.data,
|
|
64
|
+
companyIdByMatchKeyCache,
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const persistData = pruneUndefined({
|
|
68
|
+
...writableStandard,
|
|
69
|
+
...mapped.pdl,
|
|
70
|
+
companyId: currentCompanyId,
|
|
71
|
+
pdlLikelihood: outcome.likelihood,
|
|
72
|
+
pdlRawPayload: outcome.data,
|
|
73
|
+
pdlLastEnrichedAt: enrichedAt,
|
|
74
|
+
pdlEnrichmentStatus: 'MATCHED',
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return { mappedData, persistData };
|
|
78
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { toText } from 'src/logic-functions/utils/to-text';
|
|
2
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
3
|
+
|
|
4
|
+
export const buildPersonNameParam = ({
|
|
5
|
+
firstName,
|
|
6
|
+
lastName,
|
|
7
|
+
}: {
|
|
8
|
+
firstName: unknown;
|
|
9
|
+
lastName: unknown;
|
|
10
|
+
}): string | undefined => {
|
|
11
|
+
const first = toText(firstName);
|
|
12
|
+
const last = toText(lastName);
|
|
13
|
+
|
|
14
|
+
if (!isDefined(first) || !isDefined(last)) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return `${first} ${last}`;
|
|
19
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { isNonEmptyArray } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { toText } from 'src/logic-functions/utils/to-text';
|
|
4
|
+
import { type PhonesValue } from 'src/types/phones-value';
|
|
5
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
6
|
+
|
|
7
|
+
export const buildPhones = (
|
|
8
|
+
phoneCandidates: (string | null | undefined)[],
|
|
9
|
+
): PhonesValue | undefined => {
|
|
10
|
+
const uniquePhoneNumbers: string[] = [];
|
|
11
|
+
const seenPhoneNumbers = new Set<string>();
|
|
12
|
+
|
|
13
|
+
for (const candidate of phoneCandidates) {
|
|
14
|
+
const phoneNumber = toText(candidate);
|
|
15
|
+
if (!isDefined(phoneNumber) || seenPhoneNumbers.has(phoneNumber)) {
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
seenPhoneNumbers.add(phoneNumber);
|
|
20
|
+
uniquePhoneNumbers.push(phoneNumber);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const [primaryPhoneNumber, ...additionalPhoneNumbers] = uniquePhoneNumbers;
|
|
24
|
+
if (!isDefined(primaryPhoneNumber)) {
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
primaryPhoneNumber,
|
|
30
|
+
primaryPhoneCountryCode: '',
|
|
31
|
+
primaryPhoneCallingCode: '',
|
|
32
|
+
additionalPhones: isNonEmptyArray(additionalPhoneNumbers)
|
|
33
|
+
? additionalPhoneNumbers.map((phoneNumber) => ({
|
|
34
|
+
number: phoneNumber,
|
|
35
|
+
countryCode: '',
|
|
36
|
+
callingCode: '',
|
|
37
|
+
}))
|
|
38
|
+
: null,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type EnrichResult } from 'src/types/enrich-result';
|
|
2
|
+
|
|
3
|
+
export const buildSkippedResult = ({
|
|
4
|
+
recordId,
|
|
5
|
+
message,
|
|
6
|
+
}: {
|
|
7
|
+
recordId: string;
|
|
8
|
+
message: string;
|
|
9
|
+
}): EnrichResult => ({
|
|
10
|
+
success: true,
|
|
11
|
+
recordId,
|
|
12
|
+
status: 'SKIPPED',
|
|
13
|
+
updatedFields: [],
|
|
14
|
+
message,
|
|
15
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { chargeCredits } from 'twenty-sdk/billing';
|
|
2
|
+
|
|
3
|
+
import { BILLING_MARGIN_MULTIPLIER } from 'src/constants/billing-margin-multiplier';
|
|
4
|
+
import { MICRO_CREDITS_PER_DOLLAR } from 'src/constants/micro-credits-per-dollar';
|
|
5
|
+
|
|
6
|
+
export const chargeMatchedEnrichments = async ({
|
|
7
|
+
matchedCount,
|
|
8
|
+
costPerMatchDollars,
|
|
9
|
+
resourceContext,
|
|
10
|
+
}: {
|
|
11
|
+
matchedCount: number;
|
|
12
|
+
costPerMatchDollars: number;
|
|
13
|
+
resourceContext: string;
|
|
14
|
+
}): Promise<void> => {
|
|
15
|
+
if (matchedCount === 0) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const creditsPerMatchMicro = Math.round(
|
|
20
|
+
costPerMatchDollars * BILLING_MARGIN_MULTIPLIER * MICRO_CREDITS_PER_DOLLAR,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
await chargeCredits({
|
|
24
|
+
creditsUsedMicro: matchedCount * creditsPerMatchMicro,
|
|
25
|
+
operationType: 'CODE_EXECUTION',
|
|
26
|
+
quantity: matchedCount,
|
|
27
|
+
resourceContext,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const chunk = <TItem>({
|
|
2
|
+
items,
|
|
3
|
+
size,
|
|
4
|
+
}: {
|
|
5
|
+
items: TItem[];
|
|
6
|
+
size: number;
|
|
7
|
+
}): TItem[][] => {
|
|
8
|
+
if (size <= 0) {
|
|
9
|
+
return items.length > 0 ? [items] : [];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const chunks: TItem[][] = [];
|
|
13
|
+
for (let index = 0; index < items.length; index += size) {
|
|
14
|
+
chunks.push(items.slice(index, index + size));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return chunks;
|
|
18
|
+
};
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
2
|
+
|
|
3
|
+
import { buildErrorResult } from 'src/logic-functions/utils/build-error-result';
|
|
4
|
+
import { buildMatchedResult } from 'src/logic-functions/utils/build-matched-result';
|
|
5
|
+
import { buildNotFoundResult } from 'src/logic-functions/utils/build-not-found-result';
|
|
6
|
+
import { buildSkippedResult } from 'src/logic-functions/utils/build-skipped-result';
|
|
7
|
+
import { chargeMatchedEnrichments } from 'src/logic-functions/utils/charge-matched-enrichments';
|
|
8
|
+
import { INTERNAL_BOOKKEEPING_FIELDS } from 'src/logic-functions/utils/internal-field-names';
|
|
9
|
+
import { nowIso } from 'src/logic-functions/utils/now-iso';
|
|
10
|
+
import { resolveUpdateFieldsMode } from 'src/logic-functions/utils/resolve-update-fields-mode';
|
|
11
|
+
import { type BatchEnrichmentAdapter } from 'src/types/batch-enrichment-adapter';
|
|
12
|
+
import { type BulkEnrichInput } from 'src/types/bulk-enrich-input';
|
|
13
|
+
import { type CompanyIdByMatchKeyCache } from 'src/types/company-id-by-match-key-cache';
|
|
14
|
+
import { type EnrichResult } from 'src/types/enrich-result';
|
|
15
|
+
import { type PdlEnrichResult } from 'src/types/pdl-enrich-result';
|
|
16
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
17
|
+
import { toErrorMessage } from 'src/utils/to-error-message';
|
|
18
|
+
|
|
19
|
+
const writeErrorStatusWithBackoff = async <TNode, TData, TParams>({
|
|
20
|
+
adapter,
|
|
21
|
+
client,
|
|
22
|
+
recordIds,
|
|
23
|
+
enrichedAt,
|
|
24
|
+
}: {
|
|
25
|
+
adapter: BatchEnrichmentAdapter<TNode, TData, TParams>;
|
|
26
|
+
client: CoreApiClient;
|
|
27
|
+
recordIds: string[];
|
|
28
|
+
enrichedAt: string;
|
|
29
|
+
}): Promise<void> => {
|
|
30
|
+
if (recordIds.length === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
await adapter
|
|
35
|
+
.updateManyStatus({
|
|
36
|
+
client,
|
|
37
|
+
recordIds,
|
|
38
|
+
data: { pdlEnrichmentStatus: 'ERROR', pdlLastEnrichedAt: enrichedAt },
|
|
39
|
+
})
|
|
40
|
+
.catch(() => undefined);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
type MatchedRecord = {
|
|
44
|
+
recordId: string;
|
|
45
|
+
mappedData: Record<string, unknown>;
|
|
46
|
+
persistData: Record<string, unknown>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const recordMatchedRecords = async <TNode, TData, TParams>({
|
|
50
|
+
adapter,
|
|
51
|
+
client,
|
|
52
|
+
matchedRecords,
|
|
53
|
+
shouldPersist,
|
|
54
|
+
resultById,
|
|
55
|
+
}: {
|
|
56
|
+
adapter: BatchEnrichmentAdapter<TNode, TData, TParams>;
|
|
57
|
+
client: CoreApiClient;
|
|
58
|
+
matchedRecords: MatchedRecord[];
|
|
59
|
+
shouldPersist: boolean;
|
|
60
|
+
resultById: Map<string, EnrichResult>;
|
|
61
|
+
}): Promise<string[]> => {
|
|
62
|
+
if (matchedRecords.length === 0) {
|
|
63
|
+
return [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (!shouldPersist) {
|
|
67
|
+
for (const matchedRecord of matchedRecords) {
|
|
68
|
+
resultById.set(
|
|
69
|
+
matchedRecord.recordId,
|
|
70
|
+
buildMatchedResult({
|
|
71
|
+
recordId: matchedRecord.recordId,
|
|
72
|
+
updatedFields: [],
|
|
73
|
+
data: matchedRecord.mappedData,
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const settledWriteResults = await Promise.allSettled(
|
|
82
|
+
matchedRecords.map((matchedRecord) =>
|
|
83
|
+
adapter.updateOne({
|
|
84
|
+
client,
|
|
85
|
+
recordId: matchedRecord.recordId,
|
|
86
|
+
data: matchedRecord.persistData,
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const failedRecordIds: string[] = [];
|
|
92
|
+
for (const [index, writeResult] of settledWriteResults.entries()) {
|
|
93
|
+
const matchedRecord = matchedRecords[index];
|
|
94
|
+
if (writeResult.status === 'rejected') {
|
|
95
|
+
resultById.set(
|
|
96
|
+
matchedRecord.recordId,
|
|
97
|
+
buildErrorResult({
|
|
98
|
+
recordId: matchedRecord.recordId,
|
|
99
|
+
error: toErrorMessage(writeResult.reason),
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
failedRecordIds.push(matchedRecord.recordId);
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
resultById.set(
|
|
107
|
+
matchedRecord.recordId,
|
|
108
|
+
buildMatchedResult({
|
|
109
|
+
recordId: matchedRecord.recordId,
|
|
110
|
+
updatedFields: Object.keys(matchedRecord.persistData).filter(
|
|
111
|
+
(fieldName) => !INTERNAL_BOOKKEEPING_FIELDS.has(fieldName),
|
|
112
|
+
),
|
|
113
|
+
data: matchedRecord.mappedData,
|
|
114
|
+
}),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return failedRecordIds;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const recordNotFoundRecords = async <TNode, TData, TParams>({
|
|
122
|
+
adapter,
|
|
123
|
+
client,
|
|
124
|
+
notFoundRecordIds,
|
|
125
|
+
shouldPersist,
|
|
126
|
+
enrichedAt,
|
|
127
|
+
resultById,
|
|
128
|
+
}: {
|
|
129
|
+
adapter: BatchEnrichmentAdapter<TNode, TData, TParams>;
|
|
130
|
+
client: CoreApiClient;
|
|
131
|
+
notFoundRecordIds: string[];
|
|
132
|
+
shouldPersist: boolean;
|
|
133
|
+
enrichedAt: string;
|
|
134
|
+
resultById: Map<string, EnrichResult>;
|
|
135
|
+
}): Promise<string[]> => {
|
|
136
|
+
if (notFoundRecordIds.length === 0) {
|
|
137
|
+
return [];
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!shouldPersist) {
|
|
141
|
+
for (const recordId of notFoundRecordIds) {
|
|
142
|
+
resultById.set(recordId, buildNotFoundResult(recordId));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
await adapter.updateManyStatus({
|
|
150
|
+
client,
|
|
151
|
+
recordIds: notFoundRecordIds,
|
|
152
|
+
data: { pdlEnrichmentStatus: 'NOT_FOUND', pdlLastEnrichedAt: enrichedAt },
|
|
153
|
+
});
|
|
154
|
+
for (const recordId of notFoundRecordIds) {
|
|
155
|
+
resultById.set(recordId, buildNotFoundResult(recordId));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return [];
|
|
159
|
+
} catch (notFoundStatusWriteError) {
|
|
160
|
+
const notFoundStatusWriteErrorMessage = toErrorMessage(
|
|
161
|
+
notFoundStatusWriteError,
|
|
162
|
+
);
|
|
163
|
+
for (const recordId of notFoundRecordIds) {
|
|
164
|
+
resultById.set(
|
|
165
|
+
recordId,
|
|
166
|
+
buildErrorResult({ recordId, error: notFoundStatusWriteErrorMessage }),
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return notFoundRecordIds;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export const enrichChunk = async <TNode, TData, TParams>({
|
|
175
|
+
client,
|
|
176
|
+
recordIds,
|
|
177
|
+
input,
|
|
178
|
+
adapter,
|
|
179
|
+
resultById,
|
|
180
|
+
companyIdByMatchKeyCache,
|
|
181
|
+
}: {
|
|
182
|
+
client: CoreApiClient;
|
|
183
|
+
recordIds: string[];
|
|
184
|
+
input: BulkEnrichInput;
|
|
185
|
+
adapter: BatchEnrichmentAdapter<TNode, TData, TParams>;
|
|
186
|
+
resultById: Map<string, EnrichResult>;
|
|
187
|
+
companyIdByMatchKeyCache: CompanyIdByMatchKeyCache;
|
|
188
|
+
}): Promise<void> => {
|
|
189
|
+
const { shouldPersist, overrideExistingValues } = resolveUpdateFieldsMode(
|
|
190
|
+
input.updateFields,
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
let recordNodes: TNode[];
|
|
194
|
+
try {
|
|
195
|
+
recordNodes = await adapter.readRecords({ client, recordIds });
|
|
196
|
+
} catch (readError) {
|
|
197
|
+
const readErrorMessage = toErrorMessage(readError);
|
|
198
|
+
for (const recordId of recordIds) {
|
|
199
|
+
resultById.set(
|
|
200
|
+
recordId,
|
|
201
|
+
buildErrorResult({ recordId, error: readErrorMessage }),
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const nodeByRecordId = new Map(
|
|
209
|
+
recordNodes.map((recordNode) => [adapter.getNodeId(recordNode), recordNode]),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const recordsToEnrich: { recordId: string; node: TNode; params: TParams }[] =
|
|
213
|
+
[];
|
|
214
|
+
for (const recordId of recordIds) {
|
|
215
|
+
const recordNode = nodeByRecordId.get(recordId);
|
|
216
|
+
if (!isDefined(recordNode)) {
|
|
217
|
+
resultById.set(
|
|
218
|
+
recordId,
|
|
219
|
+
buildErrorResult({
|
|
220
|
+
recordId,
|
|
221
|
+
error: `${adapter.objectNameSingular} ${recordId} not found`,
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const matchParams = adapter.extractParams({ node: recordNode, input });
|
|
228
|
+
if (!isDefined(matchParams)) {
|
|
229
|
+
resultById.set(
|
|
230
|
+
recordId,
|
|
231
|
+
buildSkippedResult({
|
|
232
|
+
recordId,
|
|
233
|
+
message: adapter.noIdentifierMessage,
|
|
234
|
+
}),
|
|
235
|
+
);
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
recordsToEnrich.push({ recordId, node: recordNode, params: matchParams });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (recordsToEnrich.length === 0) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const enrichedAt = nowIso();
|
|
247
|
+
const recordIdsToMarkAsError: string[] = [];
|
|
248
|
+
|
|
249
|
+
let pdlEnrichmentOutcomes: PdlEnrichResult<TData>[];
|
|
250
|
+
try {
|
|
251
|
+
pdlEnrichmentOutcomes = await adapter.enrichBatch(
|
|
252
|
+
recordsToEnrich.map((recordToEnrich) => recordToEnrich.params),
|
|
253
|
+
);
|
|
254
|
+
} catch (enrichBatchError) {
|
|
255
|
+
const enrichBatchErrorMessage = toErrorMessage(enrichBatchError);
|
|
256
|
+
for (const recordToEnrich of recordsToEnrich) {
|
|
257
|
+
resultById.set(
|
|
258
|
+
recordToEnrich.recordId,
|
|
259
|
+
buildErrorResult({
|
|
260
|
+
recordId: recordToEnrich.recordId,
|
|
261
|
+
error: enrichBatchErrorMessage,
|
|
262
|
+
}),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (shouldPersist) {
|
|
266
|
+
await writeErrorStatusWithBackoff({
|
|
267
|
+
adapter,
|
|
268
|
+
client,
|
|
269
|
+
recordIds: recordsToEnrich.map(
|
|
270
|
+
(recordToEnrich) => recordToEnrich.recordId,
|
|
271
|
+
),
|
|
272
|
+
enrichedAt,
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
await chargeMatchedEnrichments({
|
|
280
|
+
matchedCount: pdlEnrichmentOutcomes.filter(
|
|
281
|
+
(enrichmentOutcome) => enrichmentOutcome?.outcome === 'matched',
|
|
282
|
+
).length,
|
|
283
|
+
costPerMatchDollars: adapter.costPerMatchDollars,
|
|
284
|
+
resourceContext: `pdl/${adapter.objectNameSingular.toLowerCase()}`,
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const notFoundRecordIds: string[] = [];
|
|
288
|
+
const matchedRecords: MatchedRecord[] = [];
|
|
289
|
+
|
|
290
|
+
for (let index = 0; index < recordsToEnrich.length; index++) {
|
|
291
|
+
const { recordId, node: recordNode } = recordsToEnrich[index];
|
|
292
|
+
const enrichmentOutcome = pdlEnrichmentOutcomes[index];
|
|
293
|
+
|
|
294
|
+
if (!isDefined(enrichmentOutcome) || enrichmentOutcome.outcome === 'error') {
|
|
295
|
+
const enrichmentErrorMessage = isDefined(enrichmentOutcome)
|
|
296
|
+
? enrichmentOutcome.message
|
|
297
|
+
: 'People Data Labs returned no response for this record.';
|
|
298
|
+
resultById.set(
|
|
299
|
+
recordId,
|
|
300
|
+
buildErrorResult({ recordId, error: enrichmentErrorMessage }),
|
|
301
|
+
);
|
|
302
|
+
recordIdsToMarkAsError.push(recordId);
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (enrichmentOutcome.outcome === 'not_found') {
|
|
307
|
+
notFoundRecordIds.push(recordId);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
const { mappedData, persistData } = await adapter.buildMatchedData({
|
|
313
|
+
client,
|
|
314
|
+
node: recordNode,
|
|
315
|
+
outcome: enrichmentOutcome,
|
|
316
|
+
enrichedAt,
|
|
317
|
+
companyIdByMatchKeyCache,
|
|
318
|
+
overrideExistingValues,
|
|
319
|
+
shouldPersist,
|
|
320
|
+
});
|
|
321
|
+
matchedRecords.push({ recordId, mappedData, persistData });
|
|
322
|
+
} catch (buildMatchedDataError) {
|
|
323
|
+
resultById.set(
|
|
324
|
+
recordId,
|
|
325
|
+
buildErrorResult({
|
|
326
|
+
recordId,
|
|
327
|
+
error: toErrorMessage(buildMatchedDataError),
|
|
328
|
+
}),
|
|
329
|
+
);
|
|
330
|
+
recordIdsToMarkAsError.push(recordId);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const failedMatchedWriteRecordIds = await recordMatchedRecords({
|
|
335
|
+
adapter,
|
|
336
|
+
client,
|
|
337
|
+
matchedRecords,
|
|
338
|
+
shouldPersist,
|
|
339
|
+
resultById,
|
|
340
|
+
});
|
|
341
|
+
recordIdsToMarkAsError.push(...failedMatchedWriteRecordIds);
|
|
342
|
+
|
|
343
|
+
const failedNotFoundWriteRecordIds = await recordNotFoundRecords({
|
|
344
|
+
adapter,
|
|
345
|
+
client,
|
|
346
|
+
notFoundRecordIds,
|
|
347
|
+
shouldPersist,
|
|
348
|
+
enrichedAt,
|
|
349
|
+
resultById,
|
|
350
|
+
});
|
|
351
|
+
recordIdsToMarkAsError.push(...failedNotFoundWriteRecordIds);
|
|
352
|
+
|
|
353
|
+
if (shouldPersist) {
|
|
354
|
+
await writeErrorStatusWithBackoff({
|
|
355
|
+
adapter,
|
|
356
|
+
client,
|
|
357
|
+
recordIds: recordIdsToMarkAsError,
|
|
358
|
+
enrichedAt,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { postPdlBulkEnrich } from 'src/logic-functions/utils/post-pdl-enrich';
|
|
2
|
+
import { type PdlCompanyData } from 'src/types/pdl-company-data';
|
|
3
|
+
import { type PdlCompanyEnrichParams } from 'src/types/pdl-company-enrich-params';
|
|
4
|
+
import { type PdlEnrichResult } from 'src/types/pdl-enrich-result';
|
|
5
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
6
|
+
|
|
7
|
+
export const enrichCompanies = (
|
|
8
|
+
params: PdlCompanyEnrichParams[],
|
|
9
|
+
): Promise<PdlEnrichResult<PdlCompanyData>[]> =>
|
|
10
|
+
postPdlBulkEnrich<PdlCompanyData>({
|
|
11
|
+
path: '/company/enrich/bulk',
|
|
12
|
+
requests: params.map((entry) =>
|
|
13
|
+
pruneUndefined({
|
|
14
|
+
pdl_id: entry.pdlId,
|
|
15
|
+
website: entry.website,
|
|
16
|
+
profile: entry.profile,
|
|
17
|
+
name: entry.name,
|
|
18
|
+
min_likelihood: entry.minLikelihood,
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { postPdlSingleEnrich } from 'src/logic-functions/utils/post-pdl-single-enrich';
|
|
2
|
+
import { type PdlCompanyData } from 'src/types/pdl-company-data';
|
|
3
|
+
import { type PdlCompanyEnrichParams } from 'src/types/pdl-company-enrich-params';
|
|
4
|
+
import { type PdlEnrichResult } from 'src/types/pdl-enrich-result';
|
|
5
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
6
|
+
|
|
7
|
+
export const enrichCompany = (
|
|
8
|
+
params: PdlCompanyEnrichParams[],
|
|
9
|
+
): Promise<PdlEnrichResult<PdlCompanyData>[]> =>
|
|
10
|
+
Promise.all(
|
|
11
|
+
params.map((entry) =>
|
|
12
|
+
postPdlSingleEnrich<PdlCompanyData>({
|
|
13
|
+
path: '/company/enrich',
|
|
14
|
+
params: pruneUndefined({
|
|
15
|
+
pdl_id: entry.pdlId,
|
|
16
|
+
website: entry.website,
|
|
17
|
+
profile: entry.profile,
|
|
18
|
+
name: entry.name,
|
|
19
|
+
min_likelihood: entry.minLikelihood,
|
|
20
|
+
}),
|
|
21
|
+
}),
|
|
22
|
+
),
|
|
23
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { postPdlBulkEnrich } from 'src/logic-functions/utils/post-pdl-enrich';
|
|
2
|
+
import { type PdlEnrichResult } from 'src/types/pdl-enrich-result';
|
|
3
|
+
import { type PdlPersonData } from 'src/types/pdl-person-data';
|
|
4
|
+
import { type PdlPersonEnrichParams } from 'src/types/pdl-person-enrich-params';
|
|
5
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
6
|
+
|
|
7
|
+
export const enrichPeople = (
|
|
8
|
+
params: PdlPersonEnrichParams[],
|
|
9
|
+
): Promise<PdlEnrichResult<PdlPersonData>[]> =>
|
|
10
|
+
postPdlBulkEnrich<PdlPersonData>({
|
|
11
|
+
path: '/person/bulk',
|
|
12
|
+
requests: params.map((entry) =>
|
|
13
|
+
pruneUndefined({
|
|
14
|
+
pdl_id: entry.pdlId,
|
|
15
|
+
profile: entry.profile,
|
|
16
|
+
email: entry.email,
|
|
17
|
+
name: entry.name,
|
|
18
|
+
company: entry.company,
|
|
19
|
+
min_likelihood: entry.minLikelihood,
|
|
20
|
+
}),
|
|
21
|
+
),
|
|
22
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { postPdlSingleEnrich } from 'src/logic-functions/utils/post-pdl-single-enrich';
|
|
2
|
+
import { type PdlEnrichResult } from 'src/types/pdl-enrich-result';
|
|
3
|
+
import { type PdlPersonData } from 'src/types/pdl-person-data';
|
|
4
|
+
import { type PdlPersonEnrichParams } from 'src/types/pdl-person-enrich-params';
|
|
5
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
6
|
+
|
|
7
|
+
export const enrichPerson = (
|
|
8
|
+
params: PdlPersonEnrichParams[],
|
|
9
|
+
): Promise<PdlEnrichResult<PdlPersonData>[]> =>
|
|
10
|
+
Promise.all(
|
|
11
|
+
params.map((entry) =>
|
|
12
|
+
postPdlSingleEnrich<PdlPersonData>({
|
|
13
|
+
path: '/person/enrich',
|
|
14
|
+
params: pruneUndefined({
|
|
15
|
+
pdl_id: entry.pdlId,
|
|
16
|
+
profile: entry.profile,
|
|
17
|
+
email: entry.email,
|
|
18
|
+
name: entry.name,
|
|
19
|
+
company: entry.company,
|
|
20
|
+
min_likelihood: entry.minLikelihood,
|
|
21
|
+
}),
|
|
22
|
+
}),
|
|
23
|
+
),
|
|
24
|
+
);
|