Skip to content

Transform record phone field metadata #12706

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jun 19, 2025
Merged

Transform record phone field metadata #12706

merged 20 commits into from
Jun 19, 2025

Conversation

prastoin
Copy link
Contributor

@prastoin prastoin commented Jun 18, 2025

Introduction

close #12343

Adding a transform step for any field phone in order to infer country code and calling code from the number if they're provided

Edges cases

RecordTransformerExceptionCode.INVALID_PHONE_NUMBER:
RecordTransformerExceptionCode.INVALID_PHONE_COUNTRY_CODE:
RecordTransformerExceptionCode.CONFLICTING_PHONE_COUNTRY_CODE:
RecordTransformerExceptionCode.CONFLICTING_PHONE_CALLING_CODE:
RecordTransformerExceptionCode.CONFLICTING_PHONE_CALLING_CODE_AND_COUNTRY_CODE:
RecordTransformerExceptionCode.INVALID_PHONE_CALLING_CODE:
RecordTransformerExceptionCode.INVALID_URL:

Coverage

Note: Will handle REST api integration testing pivot and UPDATE operation later in the afternoon, critical bug appeared that I prefer handling before improving this PR coverage, also would be too many updates
Note2: Haven't fuzzed all of the string inputs, would seem overkill for such a use case, to be debated

 PASS  test/integration/metadata/suites/field-metadata/phone/create-one-field-metadata-phone.integration-spec.ts (23.609 s)
  Phone field metadata tests suite
     It should succeed create primary phone field (1397 ms)
     It should succeed create primary phone field with number and other information (930 ms)
     It should succeed create primary phone field with full international format and other information (893 ms)
     It should succeed create primary phone field with full international and infer other information from it but not the countryCode as its shared (825 ms)
     It should succeed create primary phone field with full international and infer other information from it (818 ms)
     It should succeed create primary phone field with empty payload (827 ms)
     It should succeed create additional phone field with number and other information (894 ms)
     It should succeed create additional phone field with full international format and other information (1024 ms)
     It should succeed create additional phone field with full international and infer other information from it but not the countryCode as its shared (808 ms)
     It should succeed create additional phone field with full international and infer other information from it (751 ms)
     It should succeed create additional phone field with empty payload (739 ms)
     It should fail to create primary phone field without country or calling code at all (776 ms)
     It should fail to create primary phone field with invalid country code (782 ms)
     It should fail to create primary phone field with invalid calling code (858 ms)
     It should fail to create primary phone field with conflicting country code and calling code (872 ms)
     It should fail to create primary phone field with invalid phone number format (1489 ms)
     It should fail to create primary phone field with conflicting phone number country code (1425 ms)
     It should fail to create primary phone field with conflicting phone number calling code (1553 ms)
     It should fail to create primary phone field without country or calling code at all (814 ms)
     It should fail to create primary phone field with invalid country code (813 ms)
     It should fail to create primary phone field with invalid calling code (742 ms)
     It should fail to create primary phone field with conflicting country code and calling code (783 ms)
     It should fail to create primary phone field with invalid phone number format (731 ms)
     It should fail to create primary phone field with conflicting phone number country code (947 ms)
     It should fail to create primary phone field with conflicting phone number calling code (822 ms)

Test Suites: 1 passed, 1 total
Tests:       25 passed, 25 total
Snapshots:   14 passed, 14 total
Time:        23.627 s

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Major refactoring of phone number handling to fix incorrect '+1' prefix being added to phone numbers when updated via API, with improved validation and transformation logic.

  • Added new transform-phones-value.util.ts with comprehensive validation using libphonenumber-js for country codes and phone formats
  • Modified RecordInputTransformerService to properly handle phone field transformations, preventing unwanted '+1' prefix
  • Added integration tests in create-one-field-metadata-phone.integration-spec.ts covering various phone number formats and edge cases
  • Enhanced phone metadata types in phones.composite-type.ts with improved type safety and validation
  • Implemented proper validation in validate-default-value-for-type.util.ts for phone number field metadata

7 files reviewed, 10 comments
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

github-actions bot commented Jun 18, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:46643

This environment will automatically shut down when the PR is closed or after 5 hours.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Enhanced phone number validation with extensive error handling and utility functions for data cleanup and transformation.

  • Added new error codes in record-transformer.exception.ts for specific phone validation failures like conflicting country/calling codes
  • Introduced removeUndefinedFields utility in packages/twenty-shared/src/utils to prevent data corruption during phone number processing
  • Implemented comprehensive test coverage with specific validation cases including empty payloads and international formats
  • Added recordTransformerGraphqlApiExceptionHandler to properly surface phone-related errors to the API layer
  • Removed debug console.log statements throughout codebase for cleaner production code

9 files reviewed, 1 comment
Edit PR Review Bot Settings | Greptile

Copy link
Member

@Weiko Weiko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@prastoin prastoin merged commit e1393c4 into main Jun 19, 2025
65 of 67 checks passed
@prastoin prastoin deleted the fix-phone-number branch June 19, 2025 14:40
abdulrahmancodes pushed a commit to abdulrahmancodes/twenty that referenced this pull request Jun 19, 2025
# Introduction
close twentyhq#12343

Adding a transform step for any field phone in order to infer country
code and calling code from the number if they're provided

## Edges cases
```ts
RecordTransformerExceptionCode.INVALID_PHONE_NUMBER:
RecordTransformerExceptionCode.INVALID_PHONE_COUNTRY_CODE:
RecordTransformerExceptionCode.CONFLICTING_PHONE_COUNTRY_CODE:
RecordTransformerExceptionCode.CONFLICTING_PHONE_CALLING_CODE:
RecordTransformerExceptionCode.CONFLICTING_PHONE_CALLING_CODE_AND_COUNTRY_CODE:
RecordTransformerExceptionCode.INVALID_PHONE_CALLING_CODE:
RecordTransformerExceptionCode.INVALID_URL:
```

## Coverage
Note: Will handle REST api integration testing pivot and UPDATE
operation later in the afternoon, critical bug appeared that I prefer
handling before improving this PR coverage, also would be too many
updates
Note2: Haven't fuzzed all of the string inputs, would seem overkill for
such a use case, to be debated
```ts
 PASS  test/integration/metadata/suites/field-metadata/phone/create-one-field-metadata-phone.integration-spec.ts (23.609 s)
  Phone field metadata tests suite
    ✓ It should succeed create primary phone field (1397 ms)
    ✓ It should succeed create primary phone field with number and other information (930 ms)
    ✓ It should succeed create primary phone field with full international format and other information (893 ms)
    ✓ It should succeed create primary phone field with full international and infer other information from it but not the countryCode as its shared (825 ms)
    ✓ It should succeed create primary phone field with full international and infer other information from it (818 ms)
    ✓ It should succeed create primary phone field with empty payload (827 ms)
    ✓ It should succeed create additional phone field with number and other information (894 ms)
    ✓ It should succeed create additional phone field with full international format and other information (1024 ms)
    ✓ It should succeed create additional phone field with full international and infer other information from it but not the countryCode as its shared (808 ms)
    ✓ It should succeed create additional phone field with full international and infer other information from it (751 ms)
    ✓ It should succeed create additional phone field with empty payload (739 ms)
    ✓ It should fail to create primary phone field without country or calling code at all (776 ms)
    ✓ It should fail to create primary phone field with invalid country code (782 ms)
    ✓ It should fail to create primary phone field with invalid calling code (858 ms)
    ✓ It should fail to create primary phone field with conflicting country code and calling code (872 ms)
    ✓ It should fail to create primary phone field with invalid phone number format (1489 ms)
    ✓ It should fail to create primary phone field with conflicting phone number country code (1425 ms)
    ✓ It should fail to create primary phone field with conflicting phone number calling code (1553 ms)
    ✓ It should fail to create primary phone field without country or calling code at all (814 ms)
    ✓ It should fail to create primary phone field with invalid country code (813 ms)
    ✓ It should fail to create primary phone field with invalid calling code (742 ms)
    ✓ It should fail to create primary phone field with conflicting country code and calling code (783 ms)
    ✓ It should fail to create primary phone field with invalid phone number format (731 ms)
    ✓ It should fail to create primary phone field with conflicting phone number country code (947 ms)
    ✓ It should fail to create primary phone field with conflicting phone number calling code (822 ms)

Test Suites: 1 passed, 1 total
Tests:       25 passed, 25 total
Snapshots:   14 passed, 14 total
Time:        23.627 s
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Updating phone numbers using the API adds a "+1" in front of numbers despite having selected "no country" in the data model
2 participants