{"version":3,"file":"BmAddress-82f2cb97.js","sources":["../../src/components/controls/address/loqateService.ts","../../src/components/controls/address/BmAddressLookup.vue","../../src/components/controls/address/BmAddressCaptureDialog.vue","../../src/components/controls/address/BmAddress.vue"],"sourcesContent":["import errorLoggerService from \"@/app/errors/errorLoggerService\";\nimport environment from \"@/environment\";\nimport messages from \"@/plugins/i18n\";\nimport userStore from \"@/store/modules/userStore\";\nimport type { Address } from \"@/components/controls/address/addresses\";\nimport { dutySchemeType } from \"@/components/pages/duty/composables/dutyConfiguration\";\nimport { EnumDutyScheme } from \"@/app/services/generated/enums/enumDutyScheme.generated\";\n\nexport function mapLoqateRetrieveToAddress(\n retrievedAddress: LoqateRetrieveResponse\n): Address {\n const address: Address = {\n addressLine1: retrievedAddress.Line1,\n addressLine2: retrievedAddress.Line2,\n addressLine3: retrievedAddress.Line3,\n addressLine4: retrievedAddress.City,\n addressLine5: retrievedAddress.ProvinceName,\n addressLine6: retrievedAddress.CountryName,\n addressPostcode: retrievedAddress.PostalCode,\n addressBusinessName: retrievedAddress.Company, // Not sure what to bind this to\n };\n\n /**\n * For the US:\n * - addressLine3 = city\n * - addressLine4 = US county\n * - addressLine5 = state (province)\n *\n * For everywhere else:\n * - addressLine4 = city\n * - addressLine5 = county (province)\n *\n * The Loqate API does not appear to return a US county field, so\n * leave addressLine4 blank.\n */\n if (dutySchemeType.value === EnumDutyScheme.us) {\n address.addressLine2 = [retrievedAddress.Line2, retrievedAddress.Line3]\n .filter((line) => !!line)\n .join(\", \");\n address.addressLine3 = retrievedAddress.City;\n address.addressLine4 = \"\";\n }\n\n return address;\n}\n\n// https://www.loqate.com/resources/support/apis/Capture/Interactive/Find/1.1/\ntype LoqateSearchParams = {\n Text: string; // Text to find\n IsMiddleware?: boolean; // Is called from middleware\n Container?: string; // Id from another search, used for refinement\n Origin?: string; // Starting location for search ISO 2/3 country character codes, csv, or IP address\n Countries?: string; // Limit location for search ISO 2/3 country character codes, csv\n Limit?: number; // Number of results\n Language?: string; // Language codes 2/4 char (en, en-gb)\n Bias?: boolean; // Used with origin, better narrows search to local places\n // Skipped filters for now\n};\n\nexport type LoqateSearchResponse = {\n Id: string; // Id of result\n Type: \"Address\" | \"Container\"; // Address or group of addresses\n Text: string; // Display text\n Highlight: string; // Matching character groups\n Description: string; // Other info\n};\n\n// Options object as you can specify formats as additional params, omitted as not used\ntype LoqateRetrieveParams = {\n Id: string;\n};\n\n// https://www.loqate.com/resources/support/apis/Capture/Interactive/Retrieve/1.2/\nexport type LoqateRetrieveResponse = {\n Id: string;\n DomesticId: string;\n Language: string;\n LanguageAlternatives: string;\n Department: string;\n Company: string;\n SubBuilding: string;\n BuildingNumber: string;\n BuildingName: string;\n SecondaryStreet: string;\n Street: string;\n Block: string;\n Neighbourhood: string;\n District: string;\n City: string;\n Line1: string;\n Line2: string;\n Line3: string;\n Line4: string;\n Line5: string;\n AdminAreaName: string;\n AdminAreaCode: string;\n Province: string;\n ProvinceName: string;\n ProvinceCode: string;\n PostalCode: string;\n CountryName: string;\n CountryIso2: string;\n CountryIso3: string;\n CountryIsoNumber: string;\n SortingNumber1: string;\n SortingNumber2: string;\n Barcode: string;\n POBoxNumber: string;\n Label: string;\n Type: string;\n DataLevel: string;\n};\n\nexport class LoqateService {\n private readonly findUrl =\n \"https://api.addressy.com/Capture/Interactive/Find/v1.10/json3.ws\" as const;\n\n private readonly retrieveUrl =\n \"https://api.addressy.com/Capture/Interactive/Retrieve/v1.2/json3.ws\" as const;\n\n private readonly key = environment.loqateApiKey;\n\n private applyDefaultSearchParams(\n params: LoqateSearchParams\n ): Required {\n return {\n Text: params.Text,\n IsMiddleware: params.IsMiddleware ?? false,\n Container: params.Container ?? \"\",\n Origin: params.Origin ?? userStore.state.userLanguageLocale,\n Countries: params.Countries ?? \"\",\n Limit: params.Limit ?? 200,\n Language: params.Language ?? userStore.state.userLanguageLocale,\n Bias: params.Bias ?? true,\n };\n }\n\n public async searchForAddress(params: LoqateSearchParams) {\n const paramsWithDefaults = this.applyDefaultSearchParams(params);\n\n const searchParams = new URLSearchParams(\n Object.entries(paramsWithDefaults).map(([key, value]) => {\n return [key, value.toString()];\n })\n );\n\n searchParams.set(\"Key\", this.key);\n\n const response = await fetch(this.findUrl, {\n method: \"POST\",\n headers: { Accept: \"application/json\" },\n mode: \"cors\",\n body: searchParams,\n });\n\n if (!response.ok) {\n errorLoggerService.logError(messages.smart_address_error_in_response);\n return;\n }\n\n const responseObject = await response.json();\n\n if (\n responseObject.Items.length == 1 &&\n responseObject.Items[0].Error !== undefined\n ) {\n errorLoggerService.logError(messages.smart_address_error_in_search);\n return;\n }\n\n return responseObject.Items as LoqateSearchResponse[];\n }\n\n public async resolveLoqateId(\n params: LoqateRetrieveParams\n ): Promise
{\n const searchParams = new URLSearchParams(\n Object.entries(params).map(([key, value]) => {\n return [key, value.toString()];\n })\n );\n\n searchParams.set(\"Key\", this.key);\n\n const response = await fetch(this.retrieveUrl, {\n method: \"POST\",\n headers: { Accept: \"application/json\" },\n mode: \"cors\",\n body: searchParams,\n });\n\n if (!response.ok) {\n errorLoggerService.logError(messages.smart_address_error_in_response);\n return;\n }\n\n const responseObject = await response.json();\n\n if (\n responseObject.Items.length === 1 &&\n responseObject.Items[0].Error !== undefined\n ) {\n errorLoggerService.logError(messages.smart_address_error_in_retrieve);\n return;\n }\n\n if (responseObject.Items === undefined) {\n errorLoggerService.logError(messages.smart_address_no_retrieve_item);\n return;\n }\n\n return mapLoqateRetrieveToAddress(\n responseObject.Items[0] as LoqateRetrieveResponse\n );\n }\n}\n\nexport const loqateService = new LoqateService();\n","\n\n\n","\n\n\n\n\n","\n\n\n"],"names":["ref"],"mappings":"g4BAQO,SAAS,2BACd,iBACS,CACT,MAAM,QAAmB,CACvB,aAAc,iBAAiB,MAC/B,aAAc,iBAAiB,MAC/B,aAAc,iBAAiB,MAC/B,aAAc,iBAAiB,KAC/B,aAAc,iBAAiB,aAC/B,aAAc,iBAAiB,YAC/B,gBAAiB,iBAAiB,WAClC,oBAAq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