Skip to content

addressComponents are now components in the Address type #272

@krzysztofkaszanek

Description

@krzysztofkaszanek

Environment details

  1. API: Address Validation API
  2. OS type and version: any
  3. Library version and other environment information: @googlemaps/extended-component-library:v0.6.14

Steps to reproduce

First of all, I want to say that 0.6.14 seems to have some serious changes as for the "patch" version. After the update from 0.6.13->0.6.14 our code stopped working.

  1. Call the Address Validation API and receive the response
  2. const { suggestedAction } = suggestValidationAction(response)
  3. Result: suggestedAction value is incorrect (best scenario) or the whole function fails (worst scenario)

Code example

const response = await $fetch(
    `https://addressvalidation.googleapis.com/v1:validateAddress?key=${googleMapsApiKey}`,
    {
        method: 'POST',
        body: {
            address: {
                regionCode: address.countryIsoCode,
                locality: address.city,
                addressLines: [address.street],
                postalCode: address.zipcode,
            },
        },
    }
)
const { suggestedAction } = suggestValidationAction(response)

Stack trace

TypeError: can't access property "some", result.address.components is undefined
    hasSuspiciousComponent suggest_validation_action.ts:53
    suggestValidationAction suggest_validation_action.ts:151

I see two issues with the changes introduced in 0.6.14

1. The response argument type of suggestValidationAction function was changed from AddressValidationResponse to AddressValidation.

This is not reflected in the documentation (e.g. README: https://github.com/googlemaps/extended-component-library/blob/main/src/address_validation/README.md#examples)

Image

It means that this code:

...
response = await AddressValidation.validateAddress(request);
const {suggestedAction} = suggestValidationAction(response);

will no longer work. Instead you have to pass response.result which is unintuitive and is a breaking change.

2. The Address interface addressComponents was changed to components

The field addressComponents is now components in the Address interface. This is simply incorrect, as the API response has addressComponents, not components!

Image

This can be easily verified using this demo: https://developers.google.com/maps/documentation/address-validation/demo

This causes the problem I pasted in the stacktrace above, there is no components field in the response, so it fails to run .some() function on it and the whole function breaks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions