Skip to content

Commit bfb3e8d

Browse files
Skosche3Rick Saccoccianewmanwryanslatten
authored
Convert httpClient calls to @esri/arcgis-rest-request (#228)
* Convert httpClient calls to @esri/arcgis-rest-request with ArcGISIdentityManager for authentication * Fix addFields and deleteFields * Fixed outFields and returnGeometry for query generation * [service] prepend form name to all event form fields for clarity and to avoid ESRI column name conflicts * [service] Fix check to determine if an observation sync to ESRI is a create or update * [service] OAuth refresh token flow in work * [service] Add IdentityManager to ObservationSender construction * [service] Remove httpClient * [service] fix FeatureQuerier response from request * [service] Refactor ArcGISIdentityManager management * draft changes * [service] ArcGIS field names are lowercase, account for this when adding/removing fields * Undo revert of FeatureQuerier * [service] Remove HttpClient.ts, no longer used * [service] updateConfig inner async methods await before we query * [server] Attribute sync fix upon adding feature server * [web/service] API update to include feature service authentication status * [service] fix regression in token, username/password validation req parameter parsing * [service] Clean up TODO comments * [service] form field mapping need to account for form name and field name to avoid conflicts * Reduce response logging that may cause confusion * [service] include event forms in detecting config changes * Merge develop --------- Co-authored-by: Rick Saccoccia <[email protected]> Co-authored-by: William Newman <[email protected]> Co-authored-by: Ryan Slatten <[email protected]>
1 parent f5ac5c1 commit bfb3e8d

27 files changed

+1500
-1912
lines changed

plugins/arcgis/service/package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/arcgis/service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@esri/arcgis-rest-feature-service": "^4.0.6",
4242
"@esri/arcgis-rest-request": "^4.2.3",
4343
"@terraformer/arcgis": "2.1.2",
44-
"form-data": "^4.0.0"
44+
"form-data": "^4.0.1"
4545
},
4646
"peerDependencies": {
4747
"@ngageoint/mage.service": "^6.2.9 || ^6.3.0-beta",

plugins/arcgis/service/src/ArcGISConfig.ts

Lines changed: 4 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,10 @@ export interface FeatureServiceConfig {
88
*/
99
url: string
1010

11-
/**
12-
* Username and password for ArcGIS authentication
13-
*/
14-
auth?: ArcGISAuthConfig
15-
16-
/**
17-
* Create layers that don't exist
18-
*/
19-
createLayers?: boolean
20-
21-
/**
22-
* The administration url to the arc feature service.
23-
*/
24-
adminUrl?: string
25-
26-
/**
27-
* Administration access token
28-
*/
29-
adminToken?: string
11+
/**
12+
* Serialized ArcGISIdentityManager
13+
*/
14+
identityManager: string
3015

3116
/**
3217
* The feature layers.
@@ -49,104 +34,12 @@ export interface FeatureLayerConfig {
4934
*/
5035
geometryType?: string
5136

52-
/**
53-
* Access token
54-
*/
55-
token?: string // TODO - can this be removed? Will Layers have a token too?
5637
/**
5738
* The event ids or names that sync to this arc feature layer.
5839
*/
5940
events?: (number|string)[]
60-
61-
/**
62-
* Add layer fields from form fields
63-
*/
64-
addFields?: boolean
65-
66-
/**
67-
* Delete editable layer fields missing from form fields
68-
*/
69-
deleteFields?: boolean
70-
7141
}
7242

73-
export enum AuthType {
74-
Token = 'token',
75-
UsernamePassword = 'usernamePassword',
76-
OAuth = 'oauth'
77-
}
78-
79-
80-
/**
81-
* Contains token-based authentication configuration.
82-
*/
83-
export interface TokenAuthConfig {
84-
type: AuthType.Token
85-
token: string
86-
authTokenExpires?: string
87-
}
88-
89-
/**
90-
* Contains username and password for ArcGIS server authentication.
91-
*/
92-
export interface UsernamePasswordAuthConfig {
93-
type: AuthType.UsernamePassword
94-
/**
95-
* The username for authentication.
96-
*/
97-
username: string
98-
99-
/**
100-
* The password for authentication.
101-
*/
102-
password: string
103-
}
104-
105-
/**
106-
* Contains OAuth authentication configuration.
107-
*/
108-
export interface OAuthAuthConfig {
109-
110-
type: AuthType.OAuth
111-
112-
/**
113-
* The Client Id for OAuth
114-
*/
115-
clientId: string
116-
117-
/**
118-
* The redirectUri for OAuth
119-
*/
120-
redirectUri?: string
121-
122-
/**
123-
* The temporary auth token for OAuth
124-
*/
125-
authToken?: string
126-
127-
/**
128-
* The expiration date for the temporary token
129-
*/
130-
authTokenExpires?: number
131-
132-
/**
133-
* The Refresh token for OAuth
134-
*/
135-
refreshToken?: string
136-
137-
/**
138-
* The expiration date for the Refresh token
139-
*/
140-
refreshTokenExpires?: number
141-
}
142-
143-
/**
144-
* Union type for authentication configurations.
145-
*/
146-
export type ArcGISAuthConfig =
147-
| TokenAuthConfig
148-
| UsernamePasswordAuthConfig
149-
| OAuthAuthConfig
15043

15144
/**
15245
* Attribute configurations

plugins/arcgis/service/src/ArcGISIdentityManagerFactory.ts

Lines changed: 0 additions & 118 deletions
This file was deleted.

plugins/arcgis/service/src/ArcGISPluginConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export const defaultArcGISPluginConfig = Object.freeze<ArcGISPluginConfig>({
145145
textAreaFieldLength: 256,
146146
observationIdField: 'description',
147147
idSeparator: '-',
148-
// eventIdField: 'event_id',
148+
eventIdField: 'event_id',
149149
lastEditedDateField: 'last_edited_date',
150150
eventNameField: 'event_name',
151151
userIdField: 'user_id',
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { ArcGISIdentityManager } from '@esri/arcgis-rest-request'
2+
import { FeatureServiceConfig } from './ArcGISConfig'
3+
import { PluginStateRepository } from '@ngageoint/mage.service/lib/plugins.api'
4+
5+
export interface ArcGISIdentityService {
6+
signin(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager>
7+
updateIndentityManagers(): Promise<void>
8+
}
9+
10+
export function createArcGISIdentityService(
11+
stateRepo: PluginStateRepository<any>
12+
): ArcGISIdentityService {
13+
const identityManagerCache: Map<string, Promise<ArcGISIdentityManager>> = new Map()
14+
15+
return {
16+
async signin(featureService: FeatureServiceConfig): Promise<ArcGISIdentityManager> {
17+
let cached = await identityManagerCache.get(featureService.url)
18+
if (!cached) {
19+
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
20+
const promise = identityManager.getUser().then(() => identityManager)
21+
identityManagerCache.set(featureService.url, promise)
22+
return promise
23+
} else {
24+
return cached
25+
}
26+
},
27+
async updateIndentityManagers() {
28+
const config = await stateRepo.get()
29+
for (let [url, persistedIdentityManagerPromise] of identityManagerCache) {
30+
const persistedIdentityManager = await persistedIdentityManagerPromise
31+
const featureService: FeatureServiceConfig | undefined = config.featureServices.find((service: FeatureServiceConfig) => service.url === url)
32+
if (featureService) {
33+
const identityManager = ArcGISIdentityManager.deserialize(featureService.identityManager)
34+
if (identityManager.token !== persistedIdentityManager.token || identityManager.refreshToken !== persistedIdentityManager.refreshToken) {
35+
featureService.identityManager = persistedIdentityManager.serialize()
36+
await stateRepo.put(config)
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
44+
export function getPortalUrl(featureService: FeatureServiceConfig | string): string {
45+
const url = getFeatureServiceUrl(featureService)
46+
return `https://${url.hostname}/arcgis/sharing/rest`
47+
}
48+
49+
export function getServerUrl(featureService: FeatureServiceConfig | string): string {
50+
const url = getFeatureServiceUrl(featureService)
51+
return `https://${url.hostname}/arcgis`
52+
}
53+
54+
export function getFeatureServiceUrl(featureService: FeatureServiceConfig | string): URL {
55+
const url = typeof featureService === 'string' ? featureService : featureService.url
56+
return new URL(url)
57+
}

plugins/arcgis/service/src/FeatureLayerProcessor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { LayerInfo } from "./LayerInfo";
55
import { ObservationBinner } from "./ObservationBinner";
66
import { ObservationBins } from "./ObservationBins";
77
import { ObservationsSender } from "./ObservationsSender";
8-
8+
import { ArcGISIdentityManager } from "@esri/arcgis-rest-request";
99
/**
1010
* Processes new, updated, and deleted observations and sends the changes to a specific arc feature layer.
1111
*/
@@ -42,12 +42,12 @@ export class FeatureLayerProcessor {
4242
* @param config Contains certain parameters that can be configured.
4343
* @param console Used to log messages to the console.
4444
*/
45-
constructor(layerInfo: LayerInfo, config: ArcGISPluginConfig, console: Console) {
45+
constructor(layerInfo: LayerInfo, config: ArcGISPluginConfig, identityManager: ArcGISIdentityManager, console: Console) {
4646
this.layerInfo = layerInfo;
4747
this.lastTimeStamp = 0;
48-
this.featureQuerier = new FeatureQuerier(layerInfo, config, console);
48+
this.featureQuerier = new FeatureQuerier(layerInfo, config, identityManager,console);
4949
this._binner = new ObservationBinner(layerInfo, this.featureQuerier, config);
50-
this.sender = new ObservationsSender(layerInfo, config, console);
50+
this.sender = new ObservationsSender(layerInfo, config, identityManager, console);
5151
}
5252

5353
/**
@@ -85,7 +85,7 @@ export class FeatureLayerProcessor {
8585

8686
for (const arcObservation of observations.deletions) {
8787
if (this.layerInfo.geometryType == arcObservation.esriGeometryType) {
88-
this.sender.sendDelete(arcObservation.id)
88+
this.sender.sendDelete(Number(arcObservation.id));
8989
}
9090
}
9191
}

0 commit comments

Comments
 (0)