@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,52 @@
|
|
|
1
|
+
import { normalizeDomain } from 'src/logic-functions/utils/normalize-domain';
|
|
2
|
+
import { normalizeLinkedinUrl } from 'src/logic-functions/utils/normalize-linkedin-url';
|
|
3
|
+
import { resolveMinLikelihood } from 'src/logic-functions/utils/resolve-min-likelihood';
|
|
4
|
+
import { toText } from 'src/logic-functions/utils/to-text';
|
|
5
|
+
import { type BulkEnrichInput } from 'src/types/bulk-enrich-input';
|
|
6
|
+
import { type CompanyNode } from 'src/types/company-node';
|
|
7
|
+
import { type PdlCompanyEnrichParams } from 'src/types/pdl-company-enrich-params';
|
|
8
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
9
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
10
|
+
|
|
11
|
+
export const extractCompanyMatchParams = ({
|
|
12
|
+
node,
|
|
13
|
+
input,
|
|
14
|
+
}: {
|
|
15
|
+
node: CompanyNode;
|
|
16
|
+
input: BulkEnrichInput;
|
|
17
|
+
}): PdlCompanyEnrichParams | undefined => {
|
|
18
|
+
const existingPdlId = toText(node.pdlId);
|
|
19
|
+
if (isDefined(existingPdlId)) {
|
|
20
|
+
return {
|
|
21
|
+
pdlId: existingPdlId,
|
|
22
|
+
minLikelihood: resolveMinLikelihood({
|
|
23
|
+
inputMinLikelihood: input.minLikelihood,
|
|
24
|
+
hasStrongIdentifier: true,
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const websiteDomain = normalizeDomain(node.domainName?.primaryLinkUrl);
|
|
30
|
+
const linkedinProfileUrl = normalizeLinkedinUrl(node.linkedinLink?.primaryLinkUrl);
|
|
31
|
+
const companyName = toText(node.name);
|
|
32
|
+
const hasStrongIdentifier =
|
|
33
|
+
isDefined(websiteDomain) || isDefined(linkedinProfileUrl);
|
|
34
|
+
|
|
35
|
+
const companyMatchParams = pruneUndefined({
|
|
36
|
+
website: websiteDomain,
|
|
37
|
+
profile: linkedinProfileUrl,
|
|
38
|
+
name: companyName,
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (Object.keys(companyMatchParams).length === 0) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
...companyMatchParams,
|
|
47
|
+
minLikelihood: resolveMinLikelihood({
|
|
48
|
+
inputMinLikelihood: input.minLikelihood,
|
|
49
|
+
hasStrongIdentifier,
|
|
50
|
+
}),
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { isNonEmptyString, isObject, isString } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
4
|
+
|
|
5
|
+
const extractMessageFromValue = (
|
|
6
|
+
messageValue: unknown,
|
|
7
|
+
): string | undefined => {
|
|
8
|
+
if (isNonEmptyString(messageValue)) {
|
|
9
|
+
return messageValue;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (Array.isArray(messageValue)) {
|
|
13
|
+
const joinedMessages = messageValue.filter(isString).join('; ');
|
|
14
|
+
|
|
15
|
+
return isNonEmptyString(joinedMessages) ? joinedMessages : undefined;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return undefined;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const extractPdlErrorMessage = ({
|
|
22
|
+
json,
|
|
23
|
+
httpStatus,
|
|
24
|
+
}: {
|
|
25
|
+
json: Record<string, unknown>;
|
|
26
|
+
httpStatus: number;
|
|
27
|
+
}): string => {
|
|
28
|
+
const errorField = json.error;
|
|
29
|
+
|
|
30
|
+
if (isObject(errorField)) {
|
|
31
|
+
const messageFromErrorObject = extractMessageFromValue(
|
|
32
|
+
(errorField as Record<string, unknown>).message,
|
|
33
|
+
);
|
|
34
|
+
if (isDefined(messageFromErrorObject)) {
|
|
35
|
+
return messageFromErrorObject;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const messageFromTopLevelField =
|
|
40
|
+
extractMessageFromValue(errorField) ??
|
|
41
|
+
extractMessageFromValue(json.message);
|
|
42
|
+
if (isDefined(messageFromTopLevelField)) {
|
|
43
|
+
return messageFromTopLevelField;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return `PDL request failed (HTTP ${httpStatus}).`;
|
|
47
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { buildPersonNameParam } from 'src/logic-functions/utils/build-person-name-param';
|
|
2
|
+
import { resolveMinLikelihood } from 'src/logic-functions/utils/resolve-min-likelihood';
|
|
3
|
+
import { toText } from 'src/logic-functions/utils/to-text';
|
|
4
|
+
import { type BulkEnrichInput } from 'src/types/bulk-enrich-input';
|
|
5
|
+
import { type PdlPersonEnrichParams } from 'src/types/pdl-person-enrich-params';
|
|
6
|
+
import { type PersonNode } from 'src/types/person-node';
|
|
7
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
8
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
9
|
+
|
|
10
|
+
export const extractPersonMatchParams = ({
|
|
11
|
+
node,
|
|
12
|
+
input,
|
|
13
|
+
}: {
|
|
14
|
+
node: PersonNode;
|
|
15
|
+
input: BulkEnrichInput;
|
|
16
|
+
}): PdlPersonEnrichParams | undefined => {
|
|
17
|
+
const existingPdlId = toText(node.pdlId);
|
|
18
|
+
if (isDefined(existingPdlId)) {
|
|
19
|
+
return {
|
|
20
|
+
pdlId: existingPdlId,
|
|
21
|
+
minLikelihood: resolveMinLikelihood({
|
|
22
|
+
inputMinLikelihood: input.minLikelihood,
|
|
23
|
+
hasStrongIdentifier: true,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const linkedinProfileUrl = toText(node.linkedinLink?.primaryLinkUrl);
|
|
29
|
+
const primaryEmail = toText(node.emails?.primaryEmail);
|
|
30
|
+
const fullName = buildPersonNameParam({
|
|
31
|
+
firstName: node.name?.firstName,
|
|
32
|
+
lastName: node.name?.lastName,
|
|
33
|
+
});
|
|
34
|
+
const companyName = toText(node.company?.name);
|
|
35
|
+
const hasStrongIdentifier =
|
|
36
|
+
isDefined(linkedinProfileUrl) || isDefined(primaryEmail);
|
|
37
|
+
|
|
38
|
+
const nameIsUsableAsMatchSignal =
|
|
39
|
+
isDefined(fullName) && (hasStrongIdentifier || isDefined(companyName));
|
|
40
|
+
|
|
41
|
+
const personMatchParams = pruneUndefined({
|
|
42
|
+
profile: linkedinProfileUrl,
|
|
43
|
+
email: primaryEmail,
|
|
44
|
+
name: nameIsUsableAsMatchSignal ? fullName : undefined,
|
|
45
|
+
company: nameIsUsableAsMatchSignal ? companyName : undefined,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
if (Object.keys(personMatchParams).length === 0) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...personMatchParams,
|
|
54
|
+
minLikelihood: resolveMinLikelihood({
|
|
55
|
+
inputMinLikelihood: input.minLikelihood,
|
|
56
|
+
hasStrongIdentifier,
|
|
57
|
+
}),
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { type RecordInput } from 'src/types/bulk-enrich-input';
|
|
4
|
+
|
|
5
|
+
export const extractRecordIds = (
|
|
6
|
+
records: RecordInput | RecordInput[],
|
|
7
|
+
): string[] => {
|
|
8
|
+
const recordsAsArray =
|
|
9
|
+
records === null || records === undefined
|
|
10
|
+
? []
|
|
11
|
+
: Array.isArray(records)
|
|
12
|
+
? records
|
|
13
|
+
: [records];
|
|
14
|
+
|
|
15
|
+
return recordsAsArray
|
|
16
|
+
.map((record) => (typeof record === 'string' ? record : record?.id))
|
|
17
|
+
.filter((id): id is string => isNonEmptyString(id));
|
|
18
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
2
|
+
|
|
3
|
+
type CompaniesConnection = { edges?: { node: { id: string } }[] };
|
|
4
|
+
|
|
5
|
+
export const findCompanyIdByFilter = async ({
|
|
6
|
+
client,
|
|
7
|
+
filter,
|
|
8
|
+
requireUnique = false,
|
|
9
|
+
}: {
|
|
10
|
+
client: CoreApiClient;
|
|
11
|
+
filter: Record<string, unknown>;
|
|
12
|
+
requireUnique?: boolean;
|
|
13
|
+
}): Promise<string | undefined> => {
|
|
14
|
+
const result = (await client.query({
|
|
15
|
+
companies: {
|
|
16
|
+
__args: { filter, first: requireUnique ? 2 : 1 },
|
|
17
|
+
edges: { node: { id: true } },
|
|
18
|
+
},
|
|
19
|
+
})) as { companies?: CompaniesConnection };
|
|
20
|
+
|
|
21
|
+
const edges = result.companies?.edges ?? [];
|
|
22
|
+
|
|
23
|
+
if (requireUnique && edges.length !== 1) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return edges[0]?.node?.id;
|
|
28
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
3
|
+
|
|
4
|
+
import { findCompanyIdByFilter } from 'src/logic-functions/utils/find-company-id-by-filter';
|
|
5
|
+
import { type CompanyMatchKeys } from 'src/types/company-match-keys';
|
|
6
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
7
|
+
|
|
8
|
+
export const findCompanyId = async ({
|
|
9
|
+
client,
|
|
10
|
+
matchKeys,
|
|
11
|
+
}: {
|
|
12
|
+
client: CoreApiClient;
|
|
13
|
+
matchKeys: CompanyMatchKeys;
|
|
14
|
+
}): Promise<string | undefined> => {
|
|
15
|
+
const { pdlId, website, linkedinUrl, name } = matchKeys;
|
|
16
|
+
|
|
17
|
+
if (isNonEmptyString(pdlId)) {
|
|
18
|
+
const matchById = await findCompanyIdByFilter({
|
|
19
|
+
client,
|
|
20
|
+
filter: { pdlId: { eq: pdlId } },
|
|
21
|
+
});
|
|
22
|
+
if (isDefined(matchById)) {
|
|
23
|
+
return matchById;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (isNonEmptyString(website)) {
|
|
28
|
+
const matchByDomain = await findCompanyIdByFilter({
|
|
29
|
+
client,
|
|
30
|
+
filter: { domainName: { primaryLinkUrl: { eq: website } } },
|
|
31
|
+
});
|
|
32
|
+
if (isDefined(matchByDomain)) {
|
|
33
|
+
return matchByDomain;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (isNonEmptyString(linkedinUrl)) {
|
|
38
|
+
const matchByLinkedin = await findCompanyIdByFilter({
|
|
39
|
+
client,
|
|
40
|
+
filter: { linkedinLink: { primaryLinkUrl: { eq: linkedinUrl } } },
|
|
41
|
+
});
|
|
42
|
+
if (isDefined(matchByLinkedin)) {
|
|
43
|
+
return matchByLinkedin;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (isNonEmptyString(name)) {
|
|
48
|
+
const matchByName = await findCompanyIdByFilter({
|
|
49
|
+
client,
|
|
50
|
+
filter: { name: { eq: name } },
|
|
51
|
+
requireUnique: true,
|
|
52
|
+
});
|
|
53
|
+
if (isDefined(matchByName)) {
|
|
54
|
+
return matchByName;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return undefined;
|
|
59
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
2
|
+
|
|
3
|
+
export const findExistingWorkflowId = async ({
|
|
4
|
+
client,
|
|
5
|
+
name,
|
|
6
|
+
}: {
|
|
7
|
+
client: CoreApiClient;
|
|
8
|
+
name: string;
|
|
9
|
+
}): Promise<string | undefined> => {
|
|
10
|
+
const result = (await client.query({
|
|
11
|
+
workflows: {
|
|
12
|
+
__args: { filter: { name: { eq: name } } },
|
|
13
|
+
edges: { node: { id: true } },
|
|
14
|
+
},
|
|
15
|
+
})) as { workflows?: { edges?: { node?: { id?: string } }[] } };
|
|
16
|
+
|
|
17
|
+
return result.workflows?.edges?.[0]?.node?.id;
|
|
18
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
import { type CoreApiClient } from 'twenty-client-sdk/core';
|
|
3
|
+
|
|
4
|
+
import { PdlOperationError } from 'src/logic-functions/errors/pdl-operation-error';
|
|
5
|
+
import { buildCompanyCreateData } from 'src/logic-functions/utils/build-company-create-data';
|
|
6
|
+
import { buildCompanyMatchKeys } from 'src/logic-functions/utils/build-company-match-keys';
|
|
7
|
+
import { findCompanyId } from 'src/logic-functions/utils/find-company-id';
|
|
8
|
+
import { type CompanyIdByMatchKeyCache } from 'src/types/company-id-by-match-key-cache';
|
|
9
|
+
import { type CompanyMatchKeys } from 'src/types/company-match-keys';
|
|
10
|
+
import { type PdlPersonData } from 'src/types/pdl-person-data';
|
|
11
|
+
import { isDefined } from 'src/utils/is-defined';
|
|
12
|
+
import { isUniqueViolationError } from 'src/utils/is-unique-violation-error';
|
|
13
|
+
|
|
14
|
+
type CreateCompanyResult = { createCompany?: { id?: string } };
|
|
15
|
+
|
|
16
|
+
const findOrCreateUncachedCompany = async ({
|
|
17
|
+
client,
|
|
18
|
+
personData,
|
|
19
|
+
companyMatchKeys,
|
|
20
|
+
}: {
|
|
21
|
+
client: CoreApiClient;
|
|
22
|
+
personData: PdlPersonData;
|
|
23
|
+
companyMatchKeys: CompanyMatchKeys;
|
|
24
|
+
}): Promise<string | undefined> => {
|
|
25
|
+
const existingCompanyId = await findCompanyId({
|
|
26
|
+
client,
|
|
27
|
+
matchKeys: companyMatchKeys,
|
|
28
|
+
});
|
|
29
|
+
if (isDefined(existingCompanyId)) {
|
|
30
|
+
return existingCompanyId;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const canCreateNewCompany =
|
|
34
|
+
isNonEmptyString(companyMatchKeys.name) ||
|
|
35
|
+
isNonEmptyString(companyMatchKeys.website);
|
|
36
|
+
|
|
37
|
+
if (!canCreateNewCompany) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const createCompanyResult = (await client.mutation({
|
|
43
|
+
createCompany: {
|
|
44
|
+
__args: { data: buildCompanyCreateData(personData) },
|
|
45
|
+
id: true,
|
|
46
|
+
},
|
|
47
|
+
})) as CreateCompanyResult;
|
|
48
|
+
|
|
49
|
+
const createdCompanyId = createCompanyResult.createCompany?.id;
|
|
50
|
+
|
|
51
|
+
if (!isDefined(createdCompanyId)) {
|
|
52
|
+
throw new PdlOperationError('Failed to create company: no id returned.');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return createdCompanyId;
|
|
56
|
+
} catch (createCompanyError) {
|
|
57
|
+
if (!isUniqueViolationError(createCompanyError)) {
|
|
58
|
+
throw createCompanyError;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const raceWinnerCompanyId = await findCompanyId({
|
|
62
|
+
client,
|
|
63
|
+
matchKeys: companyMatchKeys,
|
|
64
|
+
});
|
|
65
|
+
if (isDefined(raceWinnerCompanyId)) {
|
|
66
|
+
return raceWinnerCompanyId;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
throw createCompanyError;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const findOrCreateCurrentCompany = async ({
|
|
74
|
+
client,
|
|
75
|
+
personData,
|
|
76
|
+
companyIdByMatchKeyCache,
|
|
77
|
+
}: {
|
|
78
|
+
client: CoreApiClient;
|
|
79
|
+
personData: PdlPersonData;
|
|
80
|
+
companyIdByMatchKeyCache: CompanyIdByMatchKeyCache;
|
|
81
|
+
}): Promise<string | undefined> => {
|
|
82
|
+
const companyMatchKeys = buildCompanyMatchKeys(personData);
|
|
83
|
+
|
|
84
|
+
const hasAnyCompanyMatchKey =
|
|
85
|
+
isNonEmptyString(companyMatchKeys.pdlId) ||
|
|
86
|
+
isNonEmptyString(companyMatchKeys.website) ||
|
|
87
|
+
isNonEmptyString(companyMatchKeys.linkedinUrl) ||
|
|
88
|
+
isNonEmptyString(companyMatchKeys.name);
|
|
89
|
+
|
|
90
|
+
if (!hasAnyCompanyMatchKey) {
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const companyMatchKeyCacheKey = JSON.stringify(companyMatchKeys);
|
|
95
|
+
if (companyIdByMatchKeyCache.has(companyMatchKeyCacheKey)) {
|
|
96
|
+
return companyIdByMatchKeyCache.get(companyMatchKeyCacheKey);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const resolvedCompanyId = await findOrCreateUncachedCompany({
|
|
100
|
+
client,
|
|
101
|
+
personData,
|
|
102
|
+
companyMatchKeys,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
companyIdByMatchKeyCache.set(companyMatchKeyCacheKey, resolvedCompanyId);
|
|
106
|
+
|
|
107
|
+
return resolvedCompanyId;
|
|
108
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isNonEmptyString } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { PdlConfigError } from 'src/logic-functions/errors/pdl-config-error';
|
|
4
|
+
|
|
5
|
+
export const getPdlApiKey = (): string => {
|
|
6
|
+
const apiKey = process.env.PDL_API_KEY?.trim();
|
|
7
|
+
|
|
8
|
+
if (!isNonEmptyString(apiKey)) {
|
|
9
|
+
throw new PdlConfigError(
|
|
10
|
+
'PDL_API_KEY is not set. The workspace admin must configure the People Data Labs API key in Settings -> Apps.',
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return apiKey;
|
|
15
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { isObject } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { isEmptyText } from 'src/logic-functions/utils/is-empty-text';
|
|
4
|
+
|
|
5
|
+
export const isEmptyAddress = (value: unknown): boolean => {
|
|
6
|
+
if (!isObject(value)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const record = value as Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
isEmptyText(record.addressStreet1) &&
|
|
14
|
+
isEmptyText(record.addressStreet2) &&
|
|
15
|
+
isEmptyText(record.addressCity) &&
|
|
16
|
+
isEmptyText(record.addressPostcode) &&
|
|
17
|
+
isEmptyText(record.addressState) &&
|
|
18
|
+
isEmptyText(record.addressCountry)
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isObject } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { isEmptyText } from 'src/logic-functions/utils/is-empty-text';
|
|
4
|
+
|
|
5
|
+
export const isEmptyEmails = (value: unknown): boolean => {
|
|
6
|
+
if (!isObject(value)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const record = value as Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
return isEmptyText(record.primaryEmail);
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isObject } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { isEmptyText } from 'src/logic-functions/utils/is-empty-text';
|
|
4
|
+
|
|
5
|
+
export const isEmptyFullName = (value: unknown): boolean => {
|
|
6
|
+
if (!isObject(value)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const record = value as Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
return isEmptyText(record.firstName) && isEmptyText(record.lastName);
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isObject } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { isEmptyText } from 'src/logic-functions/utils/is-empty-text';
|
|
4
|
+
|
|
5
|
+
export const isEmptyLinks = (value: unknown): boolean => {
|
|
6
|
+
if (!isObject(value)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const record = value as Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
return isEmptyText(record.primaryLinkUrl);
|
|
13
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isObject } from '@sniptt/guards';
|
|
2
|
+
|
|
3
|
+
import { isEmptyText } from 'src/logic-functions/utils/is-empty-text';
|
|
4
|
+
|
|
5
|
+
export const isEmptyPhones = (value: unknown): boolean => {
|
|
6
|
+
if (!isObject(value)) {
|
|
7
|
+
return true;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const record = value as Record<string, unknown>;
|
|
11
|
+
|
|
12
|
+
return isEmptyText(record.primaryPhoneNumber);
|
|
13
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { COMPANY_TYPE_OPTIONS } from 'src/constants/company-type-options';
|
|
2
|
+
import { FUNDING_STAGE_OPTIONS } from 'src/constants/funding-stage-options';
|
|
3
|
+
import { INDUSTRY_OPTIONS } from 'src/constants/industry-options';
|
|
4
|
+
import { LOCATION_CONTINENT_OPTIONS } from 'src/constants/location-continent-options';
|
|
5
|
+
import { METRO_OPTIONS } from 'src/constants/metro-options';
|
|
6
|
+
import { MIC_EXCHANGE_OPTIONS } from 'src/constants/mic-exchange-options';
|
|
7
|
+
import { SIZE_OPTIONS } from 'src/constants/size-options';
|
|
8
|
+
import { toJsonArray } from 'src/logic-functions/utils/to-json-array';
|
|
9
|
+
import { toJsonObject } from 'src/logic-functions/utils/to-json-object';
|
|
10
|
+
import { toNumber } from 'src/logic-functions/utils/to-number';
|
|
11
|
+
import { toStringArray } from 'src/logic-functions/utils/to-string-array';
|
|
12
|
+
import { toText } from 'src/logic-functions/utils/to-text';
|
|
13
|
+
import { buildAddress } from 'src/logic-functions/utils/build-address';
|
|
14
|
+
import { buildCurrencyFromUsd } from 'src/logic-functions/utils/build-currency-from-usd';
|
|
15
|
+
import { buildLinks } from 'src/logic-functions/utils/build-links';
|
|
16
|
+
import { normalizeDomain } from 'src/logic-functions/utils/normalize-domain';
|
|
17
|
+
import { normalizeLinkedinUrl } from 'src/logic-functions/utils/normalize-linkedin-url';
|
|
18
|
+
import { parsePartialDate } from 'src/logic-functions/utils/parse-partial-date';
|
|
19
|
+
import { buildAllowedValues } from 'src/logic-functions/utils/build-allowed-values';
|
|
20
|
+
import { pickMultiSelect } from 'src/logic-functions/utils/pick-multi-select';
|
|
21
|
+
import { pickSelect } from 'src/logic-functions/utils/pick-select';
|
|
22
|
+
import { sizeTransform } from 'src/logic-functions/utils/size-transform';
|
|
23
|
+
import { type MappedRecord } from 'src/types/mapped-record';
|
|
24
|
+
import { type PdlCompanyData } from 'src/types/pdl-company-data';
|
|
25
|
+
import { pruneUndefined } from 'src/utils/prune-undefined';
|
|
26
|
+
|
|
27
|
+
const INDUSTRY_VALUES = buildAllowedValues(INDUSTRY_OPTIONS);
|
|
28
|
+
const COMPANY_TYPE_VALUES = buildAllowedValues(COMPANY_TYPE_OPTIONS);
|
|
29
|
+
const SIZE_VALUES = buildAllowedValues(SIZE_OPTIONS);
|
|
30
|
+
const METRO_VALUES = buildAllowedValues(METRO_OPTIONS);
|
|
31
|
+
const LOCATION_CONTINENT_VALUES = buildAllowedValues(LOCATION_CONTINENT_OPTIONS);
|
|
32
|
+
const MIC_EXCHANGE_VALUES = buildAllowedValues(MIC_EXCHANGE_OPTIONS);
|
|
33
|
+
const FUNDING_STAGE_VALUES = buildAllowedValues(FUNDING_STAGE_OPTIONS);
|
|
34
|
+
|
|
35
|
+
export const mapCompany = (companyData: PdlCompanyData): MappedRecord => {
|
|
36
|
+
const location = companyData.location ?? {};
|
|
37
|
+
|
|
38
|
+
const standard = pruneUndefined({
|
|
39
|
+
name: toText(companyData.display_name) ?? toText(companyData.name),
|
|
40
|
+
domainName: buildLinks({ url: normalizeDomain(companyData.website) }),
|
|
41
|
+
linkedinLink: buildLinks({ url: normalizeLinkedinUrl(companyData.linkedin_url) }),
|
|
42
|
+
address: buildAddress({
|
|
43
|
+
street1: location.street_address,
|
|
44
|
+
street2: location.address_line_2,
|
|
45
|
+
city: location.locality,
|
|
46
|
+
postcode: location.postal_code,
|
|
47
|
+
state: location.region,
|
|
48
|
+
country: location.country,
|
|
49
|
+
geo: location.geo,
|
|
50
|
+
}),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const pdl = pruneUndefined({
|
|
54
|
+
pdlId: toText(companyData.id),
|
|
55
|
+
|
|
56
|
+
pdlIndustry: pickSelect({ raw: companyData.industry, allowedValues: INDUSTRY_VALUES }),
|
|
57
|
+
pdlIndustryDetail: toText(companyData.industry_v2),
|
|
58
|
+
pdlCompanyType: pickSelect({
|
|
59
|
+
raw: companyData.type,
|
|
60
|
+
allowedValues: COMPANY_TYPE_VALUES,
|
|
61
|
+
}),
|
|
62
|
+
pdlSizeRange: pickSelect({
|
|
63
|
+
raw: companyData.size,
|
|
64
|
+
allowedValues: SIZE_VALUES,
|
|
65
|
+
transform: sizeTransform,
|
|
66
|
+
}),
|
|
67
|
+
pdlLocationMetro: pickSelect({
|
|
68
|
+
raw: location.metro,
|
|
69
|
+
allowedValues: METRO_VALUES,
|
|
70
|
+
}),
|
|
71
|
+
pdlLocationContinent: pickSelect({
|
|
72
|
+
raw: location.continent,
|
|
73
|
+
allowedValues: LOCATION_CONTINENT_VALUES,
|
|
74
|
+
}),
|
|
75
|
+
pdlMicExchange: pickSelect({
|
|
76
|
+
raw: companyData.mic_exchange,
|
|
77
|
+
allowedValues: MIC_EXCHANGE_VALUES,
|
|
78
|
+
}),
|
|
79
|
+
|
|
80
|
+
pdlLegalName: toText(companyData.legal_name),
|
|
81
|
+
pdlHeadline: toText(companyData.headline),
|
|
82
|
+
pdlSummary: toText(companyData.summary),
|
|
83
|
+
pdlTicker: toText(companyData.ticker),
|
|
84
|
+
pdlLinkedinId: toText(companyData.linkedin_id),
|
|
85
|
+
|
|
86
|
+
pdlEmployeeCount: toNumber(companyData.employee_count),
|
|
87
|
+
pdlFoundedYear: toNumber(companyData.founded),
|
|
88
|
+
pdlNumberFundingRounds: toNumber(companyData.number_funding_rounds),
|
|
89
|
+
|
|
90
|
+
pdlTotalFunding: buildCurrencyFromUsd(companyData.total_funding_raised),
|
|
91
|
+
pdlLatestFundingStage: pickSelect({
|
|
92
|
+
raw: companyData.latest_funding_stage,
|
|
93
|
+
allowedValues: FUNDING_STAGE_VALUES,
|
|
94
|
+
}),
|
|
95
|
+
pdlFundingStages: pickMultiSelect({
|
|
96
|
+
rawValues: companyData.funding_stages,
|
|
97
|
+
allowedValues: FUNDING_STAGE_VALUES,
|
|
98
|
+
}),
|
|
99
|
+
pdlLastFundingDate: parsePartialDate(companyData.last_funding_date),
|
|
100
|
+
|
|
101
|
+
pdlTwitterUrl: buildLinks({ url: companyData.twitter_url }),
|
|
102
|
+
pdlFacebookUrl: buildLinks({ url: companyData.facebook_url }),
|
|
103
|
+
|
|
104
|
+
pdlTags: toStringArray(companyData.tags),
|
|
105
|
+
pdlAlternativeNames: toStringArray(companyData.alternative_names),
|
|
106
|
+
pdlAlternativeDomains: toStringArray(companyData.alternative_domains),
|
|
107
|
+
pdlAffiliatedProfiles: toStringArray(companyData.profiles),
|
|
108
|
+
|
|
109
|
+
pdlNaics: toJsonArray(companyData.naics),
|
|
110
|
+
pdlSic: toJsonArray(companyData.sic),
|
|
111
|
+
pdlEmployeeCountByCountry: toJsonObject(companyData.employee_count_by_country),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return { standard, pdl };
|
|
115
|
+
};
|