@sbc-connect/nuxt-forms 0.1.9 → 0.1.11

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.
@@ -0,0 +1,68 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ export const useCanadaPost = () => {
4
+ const activeAddressField = ref<string>()
5
+ const address = reactive<ConnectAddress>({
6
+ street: '',
7
+ streetAdditional: '',
8
+ city: '',
9
+ region: '',
10
+ postalCode: '',
11
+ country: '',
12
+ locationDescription: '',
13
+ streetName: '',
14
+ streetNumber: '',
15
+ unitNumber: ''
16
+ })
17
+
18
+ const createAddressComplete = (
19
+ pca: any, key: string, id: string, countryIso2: string, countrySelect: boolean
20
+ ): object => {
21
+ const fields = [
22
+ { element: id, field: 'Line1', mode: pca.fieldMode.SEARCH }
23
+ ]
24
+ // Conditional to only allow country selection depending on control
25
+ const bar = countrySelect ? { visible: true, showCountry: true } : {}
26
+ const countries = {
27
+ defaultCode: countryIso2,
28
+ ...(countrySelect ? {} : { codesList: 'CA' })
29
+ }
30
+ const options = { key, bar, countries }
31
+ const addressComplete = new pca.Address(fields, options)
32
+ addressComplete.listen('populate', addressCompletePopulate)
33
+ return addressComplete
34
+ }
35
+
36
+ const enableAddressComplete = (id: string, countryIso2: string, countrySelect: boolean): void => {
37
+ activeAddressField.value = id
38
+ const config = useRuntimeConfig()
39
+ const pca = (window as any).pca
40
+ const key = config.public.addressCompleteKey as string
41
+ if (!pca || !key) {
42
+ console.warn('AddressComplete not initialized due to missing script and/or key')
43
+ return
44
+ }
45
+ if ((window as any).currentAddressComplete) {
46
+ (window as any).currentAddressComplete.destroy()
47
+ }
48
+ (window as any).currentAddressComplete = createAddressComplete(pca, key, id, countryIso2, countrySelect)
49
+ }
50
+
51
+ const addressCompletePopulate = (addressComplete: CanadaPostAddressResponse): void => {
52
+ address.street = addressComplete.Line1 || 'N/A'
53
+ address.streetAdditional = addressComplete.Line2 || ''
54
+ address.city = addressComplete.City
55
+ address.region = addressComplete.ProvinceCode
56
+ address.postalCode = addressComplete.PostalCode
57
+ address.country = addressComplete.CountryIso2
58
+ address.streetName = addressComplete.Street
59
+ address.streetNumber = addressComplete.BuildingNumber
60
+ address.unitNumber = addressComplete.SubBuilding
61
+ }
62
+
63
+ return {
64
+ activeAddressField,
65
+ address,
66
+ enableAddressComplete
67
+ }
68
+ }
@@ -0,0 +1,7 @@
1
+ export enum CanadaPostAddressResponseDataLevel {
2
+ UNKNOWN = 'Unknown',
3
+ PREMISE = 'Premise',
4
+ RANGEDPREMISE = 'RangedPremise',
5
+ STREET = 'Street',
6
+ CITY = 'City'
7
+ }
@@ -0,0 +1,38 @@
1
+ export interface CanadaPostAddressResponse {
2
+ Id: string
3
+ DomesticId: string
4
+ Language: string
5
+ LanguageAlternatives: string
6
+ Department: string
7
+ Company: string
8
+ SubBuilding: string
9
+ BuildingNumber: string
10
+ BuildingName: string
11
+ SecondaryStreet: string
12
+ Street: string
13
+ Block: string
14
+ Neighbourhood: string
15
+ District: string
16
+ City: string
17
+ Line1: string
18
+ Line2: string
19
+ Line3: string
20
+ Line4: string
21
+ Line5: string
22
+ AdminAreaName: string
23
+ AdminAreaCode: string
24
+ Province: string
25
+ ProvinceName: string
26
+ ProvinceCode: string
27
+ PostalCode: string
28
+ CountryName: string
29
+ CountryIso2: string
30
+ CountryIso3: string
31
+ CountryIsoNumber: number
32
+ SortingNumber1: string
33
+ SortingNumber2: string
34
+ Barcode: string
35
+ POBoxNumber: string
36
+ Label: string
37
+ DataLevel: CanadaPostAddressResponseDataLevel
38
+ }