UNPKG

@ngageoint/mage.arcgis.service

Version:

A mage service plugin that synchronizes mage observations to a configured ArcGIS feature layer.

84 lines 4.2 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.createArcGISIdentityService = createArcGISIdentityService; exports.getPortalUrl = getPortalUrl; exports.getServerUrl = getServerUrl; exports.getFeatureServiceUrl = getFeatureServiceUrl; const arcgis_rest_request_1 = require("@esri/arcgis-rest-request"); /** * Creates a new ArcGIS identity service. * @param {PluginStateRepository<ArcGISPluginConfig>} stateRepo The plugin state repository. * @returns {ArcGISIdentityService} The ArcGIS identity service. */ function createArcGISIdentityService(stateRepo) { const identityManagerCache = new Map(); return { signin(featureService) { return __awaiter(this, void 0, void 0, function* () { const cached = yield identityManagerCache.get(featureService.url); if (!cached) { const identityManager = arcgis_rest_request_1.ArcGISIdentityManager.deserialize(featureService.identityManager); const promise = identityManager.getUser().then(() => identityManager); identityManagerCache.set(featureService.url, promise); return promise; } else { return cached; } }); }, updateIndentityManagers() { return __awaiter(this, void 0, void 0, function* () { const config = yield stateRepo.get(); for (const [url, persistedIdentityManagerPromise] of identityManagerCache) { const persistedIdentityManager = yield persistedIdentityManagerPromise; const featureService = config === null || config === void 0 ? void 0 : config.featureServices.find((service) => service.url === url); if (featureService && config) { const identityManager = arcgis_rest_request_1.ArcGISIdentityManager.deserialize(featureService.identityManager); if (identityManager.token !== persistedIdentityManager.token || identityManager.refreshToken !== persistedIdentityManager.refreshToken) { featureService.identityManager = persistedIdentityManager.serialize(); yield stateRepo.patch(config); } } } }); } }; } /** * Gets the portal URL for an ArcGIS feature service. * @param {FeatureServiceConfig | string} featureService The feature service config or URL. * @returns {string} The portal URL. */ function getPortalUrl(featureService) { const url = getFeatureServiceUrl(featureService); return `https://${url.hostname}/arcgis/sharing/rest`; } /** * Gets the server URL for an ArcGIS feature service. * @param {FeatureServiceConfig | string} featureService The feature service config or URL. * @returns {string} The server URL. */ function getServerUrl(featureService) { const url = getFeatureServiceUrl(featureService); return `https://${url.hostname}/arcgis`; } /** * Gets the URL object for an ArcGIS feature service. * @param {FeatureServiceConfig | string} featureService The feature service config or URL string. * @returns {URL} The feature service URL. */ function getFeatureServiceUrl(featureService) { const url = typeof featureService === 'string' ? featureService : featureService.url; return new URL(url); } //# sourceMappingURL=ArcGISService.js.map