{"version":3,"file":"Geo.mjs","sources":["../../src/Geo.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify, ConsoleLogger } from '@aws-amplify/core';\nimport { AmazonLocationServiceProvider } from './providers/location-service/AmazonLocationServiceProvider';\nimport { validateCoordinates } from './util';\nconst logger = new ConsoleLogger('Geo');\nconst DEFAULT_PROVIDER = 'AmazonLocationService';\nexport class GeoClass {\n    constructor() {\n        this._config = undefined;\n        this._pluggables = [];\n        const amplifyConfig = Amplify.getConfig() ?? {};\n        this._config = Object.assign({}, this._config, amplifyConfig.Geo);\n        const locationProvider = new AmazonLocationServiceProvider(amplifyConfig.Geo);\n        this._pluggables.push(locationProvider);\n        logger.debug('Geo Options', this._config);\n    }\n    /**\n     * get the name of the module category\n     * @returns {string} name of the module category\n     */\n    getModuleName() {\n        return GeoClass.MODULE;\n    }\n    /**\n     * add plugin into Geo category\n     * @param {Object} pluggable an instance of the plugin\n     */\n    addPluggable(pluggable) {\n        if (pluggable && pluggable.getCategory() === 'Geo') {\n            this._pluggables.push(pluggable);\n        }\n    }\n    /**\n     * Get the plugin object\n     * @param providerName the name of the plugin\n     */\n    getPluggable(providerName) {\n        const targetPluggable = this._pluggables.find(pluggable => pluggable.getProviderName() === providerName);\n        if (targetPluggable === undefined) {\n            logger.debug('No plugin found with providerName', providerName);\n            throw new Error('No plugin found in Geo for the provider');\n        }\n        else\n            return targetPluggable;\n    }\n    /**\n     * Remove the plugin object\n     * @param providerName the name of the plugin\n     */\n    removePluggable(providerName) {\n        this._pluggables = this._pluggables.filter(pluggable => pluggable.getProviderName() !== providerName);\n    }\n    /**\n     * Get the map resources that are currently available through the provider\n     * @param {string} provider\n     * @returns - Array of available map resources\n     */\n    getAvailableMaps(provider = DEFAULT_PROVIDER) {\n        const prov = this.getPluggable(provider);\n        return prov.getAvailableMaps();\n    }\n    /**\n     * Get the map resource set as default in amplify config\n     * @param {string} provider\n     * @returns - Map resource set as the default in amplify config\n     */\n    getDefaultMap(provider = DEFAULT_PROVIDER) {\n        const prov = this.getPluggable(provider);\n        return prov.getDefaultMap();\n    }\n    /**\n     * Search by text input with optional parameters\n     * @param  {string} text The text string that is to be searched for\n     * @param  {SearchByTextOptions} options Optional parameters to the search\n     * @returns {Promise<Place[]>} - Promise resolves to a list of Places that match search parameters\n     */\n    async searchByText(text, options) {\n        const { providerName = DEFAULT_PROVIDER } = options || {};\n        const prov = this.getPluggable(providerName);\n        try {\n            return await prov.searchByText(text, options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n    /**\n     * Search for search term suggestions based on input text\n     * @param  {string} text The text string that is to be search for\n     * @param  {SearchByTextOptions} options Optional parameters to the search\n     * @returns a `Promise` of {@link SearchForSuggestionsResults} that resolves to an array of search suggestion strings\n     */\n    async searchForSuggestions(text, options) {\n        const { providerName = DEFAULT_PROVIDER } = options || {};\n        const prov = this.getPluggable(providerName);\n        try {\n            return await prov.searchForSuggestions(text, options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n    /**\n     * Search for location by unique ID\n     * @param  {string} placeId Unique ID of the location that is to be searched for\n     * @param  {searchByPlaceIdOptions} options Optional parameters to the search\n     * @returns {Promise<Place>} - Resolves to a place with the given placeId\n     */\n    async searchByPlaceId(placeId, options) {\n        const providerName = DEFAULT_PROVIDER;\n        const prov = this.getPluggable(providerName);\n        try {\n            return await prov.searchByPlaceId(placeId, options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n    /**\n     * Reverse geocoding search via a coordinate point on the map\n     * @param coordinates Coordinates array for the search input\n     * @param options Options parameters for the search\n     * @returns {Promise<Place>} - Promise that resolves to a place matching search coordinates\n     */\n    async searchByCoordinates(coordinates, options) {\n        const { providerName = DEFAULT_PROVIDER } = options || {};\n        const prov = this.getPluggable(providerName);\n        const [lng, lat] = coordinates;\n        try {\n            validateCoordinates(lng, lat);\n            return await prov.searchByCoordinates(coordinates, options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n    /**\n     * Create geofences\n     * @param geofences Single or array of geofence objects to create\n     * @param options Optional parameters for creating geofences\n     * @returns {Promise<SaveGeofencesResults>} - Promise that resolves to an object with:\n     *   successes: list of geofences successfully created\n     *   errors: list of geofences that failed to create\n     */\n    async saveGeofences(geofences, options) {\n        const { providerName = DEFAULT_PROVIDER } = options || {};\n        const prov = this.getPluggable(providerName);\n        // If single geofence input, make it an array for batch call\n        let geofenceInputArray;\n        if (!Array.isArray(geofences)) {\n            geofenceInputArray = [geofences];\n        }\n        else {\n            geofenceInputArray = geofences;\n        }\n        try {\n            return await prov.saveGeofences(geofenceInputArray, options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n    /**\n     * Get a single geofence by geofenceId\n     * @param geofenceId The string id of the geofence to get\n     * @param options Optional parameters for getting a geofence\n     * @returns Promise<Geofence> - Promise that resolves to a geofence object\n     */\n    async getGeofence(geofenceId, options) {\n        const { providerName = DEFAULT_PROVIDER } = options || {};\n        const prov = this.getPluggable(providerName);\n        try {\n            return await prov.getGeofence(geofenceId, options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n    /**\n     * List geofences\n     * @param  options ListGeofenceOptions\n     * @returns a promise that resolves to an object that conforms to {@link ListGeofenceResults}:\n     *   entries: list of geofences - 100 geofences are listed per page\n     *   nextToken: token for next page of geofences\n     */\n    async listGeofences(options) {\n        const { providerName = DEFAULT_PROVIDER } = options || {};\n        const prov = this.getPluggable(providerName);\n        try {\n            return await prov.listGeofences(options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n    /**\n     * Delete geofences\n     * @param geofenceIds string|string[]\n     * @param options GeofenceOptions\n     * @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:\n     *  successes: list of geofences successfully deleted\n     *  errors: list of geofences that failed to delete\n     */\n    async deleteGeofences(geofenceIds, options) {\n        const { providerName = DEFAULT_PROVIDER } = options || {};\n        const prov = this.getPluggable(providerName);\n        // If single geofence input, make it an array for batch call\n        let geofenceIdsInputArray;\n        if (!Array.isArray(geofenceIds)) {\n            geofenceIdsInputArray = [geofenceIds];\n        }\n        else {\n            geofenceIdsInputArray = geofenceIds;\n        }\n        //  Delete geofences\n        try {\n            return await prov.deleteGeofences(geofenceIdsInputArray, options);\n        }\n        catch (error) {\n            logger.debug(error);\n            throw error;\n        }\n    }\n}\nGeoClass.MODULE = 'Geo';\nexport const Geo = new GeoClass();\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIA,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,KAAK,CAAC;AACvC,MAAM,gBAAgB,GAAG,uBAAuB;AACzC,MAAM,QAAQ,CAAC;AACtB,IAAI,WAAW,GAAG;AAClB,QAAQ,IAAI,CAAC,OAAO,GAAG,SAAS;AAChC,QAAQ,IAAI,CAAC,WAAW,GAAG,EAAE;AAC7B,QAAQ,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE;AACvD,QAAQ,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC;AACzE,QAAQ,MAAM,gBAAgB,GAAG,IAAI,6BAA6B,CAAC,aAAa,CAAC,GAAG,CAAC;AACrF,QAAQ,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,gBAAgB,CAAC;AAC/C,QAAQ,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,CAAC;AACjD,IAAI;AACJ;AACA;AACA;AACA;AACA,IAAI,aAAa,GAAG;AACpB,QAAQ,OAAO,QAAQ,CAAC,MAAM;AAC9B,IAAI;AACJ;AACA;AACA;AACA;AACA,IAAI,YAAY,CAAC,SAAS,EAAE;AAC5B,QAAQ,IAAI,SAAS,IAAI,SAAS,CAAC,WAAW,EAAE,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