googlemaps / googlemaps/extended-component-library

`addressComponents` are now `components` in the `Address` type

Open
#272 0 comments 0 reactions 0 assignees View on GitHub
triage me type: bug
Dominant language
TypeScript
Stars
192
Forks
22
Avg merge
2d 23h
Merged PRs (30d)
8

Description

#### 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](https://github.com/googlemaps/extended-component-library/blob/07ff7809d065f2660617fd824436c16c5e35a6c3/src/utils/googlemaps_types.ts#L99). 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.