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GJ,CACV,IACA,SAAQ,SAAA,GAGL,IAAM,EAAmB,EAAU,WAAW,QAC1C,SAAA,GAKI,OAEI,IADA,EALwB,CACxB,EAAO,SACP,aACF,KAAK,IAKV,IAIA,OAAO,UAAU,eAAe,KAC7B,EAAG,OACH,EAAO,WAGX,EAAG,OAAO,IACN,eAAM,gBAAgB,iBAClB,EACA,GAIf,IAyBL,EAAG,YAAc,qBAAY,OACzB,EAAU,YACV,EAAU,YACV,EAAG,OACH,EAAU,cAEd,EAAG,OAAO,cAAc,EAAU,YAClC,EAAG,OAAO,iBAAiB,EAAU,MAErC,eAAe,QAAQ,GAChB,eAAe,OACzB,IACA,OAAM,SAAA,GAQH,OAPA,EAAO,MACH,qCACA,KAAK,UAAU,GACf,GAGJ,eAAe,OAAO,4CACf,eAAe,OACzB,GACR,CAkBM,SAAS,cACZ,OAAO,eAAe,OACzB,CAEM,SAAS,YAAY,GACxB,eAAe,QAAQ,EAC1B,CAqBM,IAAM,OAAS,c","file":"/npm/d2@31.10.2/d2.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.19.2.\n * Original file: /npm/d2@31.10.2/d2.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * @module d2\n *\n * @description\n * Module that contains the entry points for working with the d2 instance. Most of the api related functionality will be available through this package.\n *\n * The most important functions from the module are {@link module:d2.init|init} and {@link module:d2.init|getInstance} these are used to create and to get\n * a hold of the initialized instance of {@link module:d2.init~d2|d2}. The initialized instance is the object that allows you access most of d2's functionality.\n *\n * @example\n * import { init } from 'd2/lib/d2';\n *\n * init({ baseUrl: 'https://play.dhis2.org/demo/api/27/' })\n *  .then(d2 => console.log(d2.currentUser.name));\n */\nimport 'isomorphic-fetch'\nimport {\n    pick,\n    Deferred,\n    updateAPIUrlWithBaseUrlVersionNumber,\n} from './lib/utils'\nimport Logger from './logger/Logger'\nimport model from './model'\nimport Api from './api/Api'\nimport System from './system/System'\nimport I18n from './i18n/I18n'\nimport Config from './config'\nimport CurrentUser from './current-user/CurrentUser'\nimport { fieldsForSchemas } from './model/config'\nimport DataStore from './datastore/DataStore'\nimport Analytics from './analytics/Analytics'\nimport GeoFeatures from './geofeatures/GeoFeatures'\n\nlet firstRun = true\nlet deferredD2Init = Deferred.create()\n\nconst preInitConfig = Config.create()\n\n/**\n * Utility function to load the app manifest.\n *\n * The manifest well be enhanced with a `getBaseUrl()` utility function that will return the base url of the DHIS2 instance.\n * This is a simple getter for the `activities.dhis.href` property on the manifest.\n *\n * @example\n * import { getManifest } from 'd2/lib/d2';\n *\n * getManifest()\n *   .then(manifest => {\n *      console.log(manifest.getBaseUrl());\n *   });\n *\n * @param {string} url The location of the manifest. Generally this is located in the root of your app folder. (e.g. './manifest.webapp)\n * @param {Api} [ApiClass] An implementation of the Api class that will be used to fetch the manifest.\n *\n * @returns {Promise} Returns a Promise to  the DHIS2 app manifest with the added `getBaseUrl` method.\n */\nexport function getManifest(url, ApiClass = Api) {\n    const api = ApiClass.getApi()\n    api.setBaseUrl('')\n\n    const manifestUtilities = {\n        getBaseUrl() {\n            return this.activities.dhis.href\n        },\n    }\n\n    return api\n        .get(`${url}`)\n        .then(manifest => Object.assign({}, manifest, manifestUtilities))\n}\n\n/**\n * @function getUserSettings\n *\n * @returns {Promise} A promise to the current user settings\n *\n * @description\n * The object that is the result of the promise will have the following properties\n *\n * @example\n * import {getUserSettings} from 'd2/lib/d2';\n *\n * getUserSettings()\n *  .then(userSettings => {\n *      console.log(userSettings);\n *  });\n */\nexport function getUserSettings(ApiClass = Api) {\n    const api = ApiClass.getApi()\n\n    if (firstRun) {\n        Config.processPreInitConfig(preInitConfig, api)\n    }\n\n    return api.get('userSettings')\n}\n\nfunction getModelRequests(api, schemaNames) {\n    const modelRequests = []\n    const loadSchemaForName = schemaName =>\n        api.get(`schemas/${schemaName}`, { fields: fieldsForSchemas })\n\n    if (Array.isArray(schemaNames)) {\n        const individualSchemaRequests = schemaNames\n            .map(loadSchemaForName)\n            .concat([])\n\n        const schemasPromise = Promise.all(\n            individualSchemaRequests\n        ).then(schemas => ({ schemas }))\n\n        modelRequests.push(schemasPromise)\n\n        if (schemaNames.length > 0) {\n            // If schemas are loaded, attributes should be as well\n            modelRequests.push(\n                api.get('attributes', {\n                    fields: ':all,optionSet[:all,options[:all]]',\n                    paging: false,\n                })\n            )\n        } else {\n            // Otherwise, just return an empty list of attributes\n            modelRequests.push({ attributes: [] })\n        }\n    } else {\n        // If no schemas are specified, load all schemas and attributes\n        modelRequests.push(api.get('schemas', { fields: fieldsForSchemas }))\n        modelRequests.push(\n            api.get('attributes', {\n                fields: ':all,optionSet[:all,options[:all]]',\n                paging: false,\n            })\n        )\n    }\n\n    return modelRequests\n}\n\n/**\n * Init function that used to initialise {@link module:d2.init~d2|d2}. This will load the schemas from the DHIS2 api and configure your {@link module:d2.init~d2|d2} instance.\n *\n * The `config` object that can be passed into init can have the following properties:\n *\n * baseUrl: Set this when the url is something different then `/api`. If you are running your dhis instance in a subdirectory of the actual domain\n * for example http://localhost/dhis/ you should set the base url to `/dhis/api`\n *\n * unauthorizedCb: A callback function that is called whenever a API-request encounters a 401 - Unauthorized response.\n *  The function is called with (request, response) - the request object that failed, and the parsed response from the server.\n *\n * @param {Object} initConfig Configuration object that will be used to configure to define D2 Setting.\n * See the description for more information on the available settings.\n * @returns {Promise.<D2>} A promise that resolves with the intialized {@link init~d2|d2} object.\n *\n * @example\n * import init from 'd2';\n *\n * init({baseUrl: '/dhis/api'})\n *   .then((d2) => {\n *     console.log(d2.model.dataElement.list());\n *   });\n */\nexport function init(initConfig, ApiClass = Api, logger = Logger.getLogger()) {\n    const api = ApiClass.getApi()\n\n    const config = Config.create(preInitConfig, initConfig)\n\n    /**\n     * @namespace\n     */\n    const d2 = {\n        /**\n         * @description\n         * This is the entry point for the modelDefinitions that were loaded. To start interacting with the metadata api\n         * you would pick a modelDefinition from this object to interact with.\n         *\n         * @type {Object.<string, ModelDefinition>}\n         * @instance\n         */\n        models: undefined,\n        /**\n         * Collection of the {@link module:model} classes\n         *\n         * @deprecated There is probably no point to expose this.\n         * @instance\n         */\n        model, // TODO: Remove (Breaking)\n        /**\n         * Api class that is used throughout the api interaction. This can be used to get hold of the module:Api singleton.\n         *\n         * @example\n         * d2.Api.getApi()      // Returns the api object\n         *  .get('resources')   // Do a get request for /api/resources\n         *  .then(resources => {\n         *      console.log(resources);\n         *  });\n         *\n         * @see {@link module:api~Api#getApi}\n         *\n         * @instance\n         */\n        Api: ApiClass,\n        /**\n         * System instance to interact with system information like system settings, system info etc.\n         *\n         * @example\n         * console.log(d2.system.version.major); // 2 for DHIS 2.27\n         *\n         * @see {@link module:system/System~System|System}\n         * @instance\n         */\n        system: System.getSystem(),\n        /**\n         * I18n instance with the loaded translations.\n         *\n         * Usually used for retrieving translations for a given key using `getTranslation(key: string)`\n         *\n         * @example\n         * d2.i18n.getTranslation('success'); // Returns \"Success\" for the english locale\n         *\n         * @see {@link module:i18n~I18n#getTranslation|getTranslation}\n         *\n         * @instance\n         */\n        i18n: I18n.getI18n(),\n        /**\n         * Instance of the DataStore class for interaction with the dataStore api.\n         *\n         * @see {@link module:datastore.DataStore DataStore}\n         *\n         * @instance\n         */\n        dataStore: DataStore.getDataStore(),\n\n        /**\n         * Analytics instance for requesting analytics data from various endpoints.\n         *\n         * @example\n         * d2.analytics.aggregate\n         *  .addDimensions([\n         *   'dx:Uvn6LCg7dVU;OdiHJayrsKo',\n         *   'pe:LAST_4_QUARTERS',\n         *   'ou:lc3eMKXaEfw;PMa2VCrupOd',\n         *  ])\n         *  .addFilter('pe:2016Q1;2016Q2')\n         *  .getRawData({\n         *    startDate: '2017-10-01',\n         *    endDate: '2017-10-31'\n         *  })\n         *  .then(console.log)\n         *\n         * @see {@link module:analytics.Analytics Analytics}\n         * @instance\n         */\n        analytics: Analytics.getAnalytics(),\n\n        /*\n         * GeoFeatures instance\n         *\n         * @see {@link module:geoFeatures.GeoFeatures GeoFeatures}\n         * @instance\n         */\n        geoFeatures: GeoFeatures.getGeoFeatures(),\n    }\n\n    // Process the config in a the config class to keep all config calls together.\n    Config.processConfigForD2(config, d2)\n\n    // Because when importing the getInstance method in dependencies the getInstance could run before\n    // init we have to resolve the current promise on first run and for consecutive ones replace the\n    // old one with a fresh promise.\n    if (firstRun) {\n        firstRun = false\n    } else {\n        deferredD2Init = Deferred.create()\n    }\n\n    const modelRequests = getModelRequests(api, config.schemas)\n\n    const userRequests = [\n        api.get('me', {\n            fields:\n                ':all,organisationUnits[id],userGroups[id],userCredentials[:all,!user,userRoles[id]',\n        }),\n        api.get('me/authorization'),\n        getUserSettings(ApiClass),\n    ]\n\n    const systemRequests = [api.get('system/info'), api.get('apps')]\n\n    return Promise.all([\n        ...modelRequests,\n        ...userRequests,\n        ...systemRequests,\n        d2.i18n.load(),\n    ])\n        .then(res => {\n            const responses = {\n                schemas: pick('schemas')(res[0]),\n                attributes: pick('attributes')(res[1]),\n                currentUser: res[2],\n                authorities: res[3],\n                userSettings: res[4],\n                systemInfo: res[5],\n                apps: res[6],\n            }\n\n            responses.schemas\n                // We only deal with metadata schemas\n                .filter(schema => schema.metadata)\n                // TODO: Remove this when the schemas endpoint is versioned or shows the correct urls for the requested version\n                // The schemas endpoint is not versioned which will result into the modelDefinitions always using the\n                // \"default\" endpoint, we therefore modify the endpoint url based on the given baseUrl.\n                .map(schema => {\n                    schema.apiEndpoint = updateAPIUrlWithBaseUrlVersionNumber(\n                        schema.apiEndpoint,\n                        config.baseUrl\n                    )\n\n                    return schema\n                })\n                .forEach(schema => {\n                    // Attributes that do not have values do not by default get returned with the data,\n                    // therefore we need to grab the attributes that are attached to this particular schema to be able to know about them\n                    const schemaAttributes = responses.attributes.filter(\n                        attributeDescriptor => {\n                            const attributeNameFilter = [\n                                schema.singular,\n                                'Attribute',\n                            ].join('')\n                            return (\n                                attributeDescriptor[attributeNameFilter] ===\n                                true\n                            )\n                        }\n                    )\n\n                    if (\n                        !Object.prototype.hasOwnProperty.call(\n                            d2.models,\n                            schema.singular\n                        )\n                    ) {\n                        d2.models.add(\n                            model.ModelDefinition.createFromSchema(\n                                schema,\n                                schemaAttributes\n                            )\n                        )\n                    }\n                })\n\n            /**\n             * An instance of {@link module:current-user/CurrentUser~CurrentUser|CurrentUser}\n             *\n             * The currentUser can be used to retrieve data related to the currentUser.\n             *\n             * These things primarily include:\n             * - currentUser properties retrieved from `/api/me`\n             * - Lazily request collections related to the user such as\n             *      - userRoles\n             *      - userGroups\n             *      - organisationUnits\n             *      - dataViewOrganisationUnits\n             * - authorities\n             * - userSettings\n             * - utility methods for ACL\n             *\n             * @example\n             * d2.currentUser.canCreate(d2.models.dataElement); // Returns true when the user can create either a private/public dataElement\n             * d2.currentUser.canCreate(d2.models.organisationUnit); // Returns true the user can create an organisationUnit\n             *\n             * @see {@link module:current-user/CurrentUser~CurrentUser|CurrentUser}\n             * @instance\n             */\n            d2.currentUser = CurrentUser.create(\n                responses.currentUser,\n                responses.authorities,\n                d2.models,\n                responses.userSettings\n            )\n            d2.system.setSystemInfo(responses.systemInfo)\n            d2.system.setInstalledApps(responses.apps)\n\n            deferredD2Init.resolve(d2)\n            return deferredD2Init.promise\n        })\n        .catch(error => {\n            logger.error(\n                'Unable to get schemas from the api',\n                JSON.stringify(error),\n                error\n            )\n\n            deferredD2Init.reject('Unable to get schemas from the DHIS2 API')\n            return deferredD2Init.promise\n        })\n}\n\n/**\n * This function can be used to retrieve the `singleton` instance of d2. The instance is being created by calling\n * the `init` method.\n *\n * @returns {Promise.<D2>} A promise to the initialized {@link module:d2.init~d2|d2} instance.\n *\n * @example\n * import {init, getInstance} from 'd2';\n *\n * init({baseUrl: '/dhis2/api/'});\n * getInstance()\n *   .then(d2 => {\n *      d2.models.dataElement.list();\n *      // and all your other d2 magic.\n *   });\n */\nexport function getInstance() {\n    return deferredD2Init.promise\n}\n\nexport function setInstance(d2) {\n    deferredD2Init.resolve(d2)\n}\n\n/**\n * Can be used to set config options before initialisation of d2.\n *\n * @example\n * import {config, init} from 'd2';\n *\n * config.baseUrl = '/demo/api';\n * config.i18n.sources.add('i18n/systemsettingstranslations.properties');\n *\n * init()\n *   .then(d2 => {\n *     d2.system.settings.all()\n *       .then(systemSettings => Object.keys())\n *       .then(systemSettingsKey => {\n *         d2.i18n.getTranslation(systemSettingsKey);\n *       });\n *   });\n *   @type Config\n */\nexport const config = preInitConfig // Alias preInitConfig to be able to `import {config} from 'd2';`\n"]}