un-cli 0.0.79 → 0.0.81

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cmd.txt CHANGED
@@ -1,2 +1,3 @@
1
- topology --validate --fishnet
1
+ reconcile --version U136967.MigrateTransm
2
+ update subnetworks --all
2
3
  exit
package/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { AdminLog } from "./adminlog.mjs"
7
7
  import logger from "./logger.mjs"
8
8
  import fetch from "node-fetch"
9
9
  //update version
10
- let version = "0.0.79";
10
+ let version = "0.0.81";
11
11
  const GENERATE_TOKEN_TIME_MIN = 30;
12
12
 
13
13
  let rl = null;
@@ -27,7 +27,8 @@ function parseInput(){
27
27
  "--gdbversion",
28
28
  "--file",
29
29
  "--verify",
30
- "--server"
30
+ "--server",
31
+ "--proxy"
31
32
  ]
32
33
 
33
34
  //null marked parmaters are required
@@ -40,7 +41,8 @@ function parseInput(){
40
41
  "gdbversion": "SDE.DEFAULT",
41
42
  "file": "",
42
43
  "verify": "true",
43
- "server": undefined
44
+ "server": undefined,
45
+ "proxy": undefined
44
46
  }
45
47
 
46
48
  for (let i = 0; i < process.argv.length ; i++){
@@ -53,7 +55,7 @@ function parseInput(){
53
55
 
54
56
  if (Object.values(params).includes(null))
55
57
  {
56
- logger.info ("HELP: uncli --portal https://unportal.domain.com/portal --service servicename --user username --password password [--gdbversion* user.version --server https://federatedserver.domain.com/server --file commandfile* --verify true|false]")
58
+ logger.info ("HELP: uncli --portal https://unportal.domain.com/portal --service servicename --user username --password password [--gdbversion* user.version --server https://federatedserver.domain.com/server --file commandfile* --verify true|false] --proxy http://proxyurl:port")
57
59
  logger.info("--file commandfile is optional and you can pass a path to a file with a list of command to execute. ")
58
60
  logger.info("--gdbversion is optional and allows the UN to be opened in that version. When not specified sde.DEFAULT is used.")
59
61
  logger.info("--server is optional except when there are more than one federated server sites to the portal. If the portal only has one server it will be selected.")
@@ -175,7 +177,10 @@ const inputs = {
175
177
  "export subnetworks --new [--folder]": "Export all subnetworks with ACK that haven't been exported --folder where exported files are saved",
176
178
  "export subnetworks --deleted": "Export all subnetworks with ACK that are deleted ",
177
179
  "updateisconnected": "Run update is connected ",
178
-
180
+ "versions": "List all versions available to the current logged in user.",
181
+ "reconcile --version <version name>": "Reconcile the input version synchronously",
182
+ "reconcile --all": "Reconcile all versions available to the current user synchronously",
183
+ "reconcile --all --async": "Reconcile all versions available to the current user asynchronously",
179
184
  "count": "Lists the number of rows in all feature layers and tables.",
180
185
  "count --system": "Lists the number of rows in system layers.",
181
186
  "connect --service": "Connects to the another service",
@@ -228,6 +233,100 @@ const inputs = {
228
233
 
229
234
  console.table(serviceDef)
230
235
  },
236
+
237
+ "^versions$": async () => {
238
+
239
+ const versions = await un.versions();
240
+ if (versions.versions.length === 0) {
241
+ logger.info("No versions found.")
242
+ return;
243
+ }
244
+ const subs = versions.versions.map( (a) => {
245
+ return {"versionName": a.versionName, "Id": a.versionId, "guid" : a.versionGuid, "created": a.creationDate, "modified": a.modifiedDate, "access": a.access};
246
+ })
247
+
248
+ console.table(subs)
249
+ const rowCount = subs.length;
250
+ logger.info (`${numberWithCommas(rowCount)} rows returned.`)
251
+ },
252
+
253
+
254
+ "^reconcile --version": async (input) => {
255
+
256
+ const inputParam = input.match(/--version .*/gm)
257
+ let versionName = null;
258
+ if (inputParam != null && inputParam.length > 0)
259
+ versionName = inputParam[0].replace("--version ", "")
260
+
261
+ const versions = await un.versions();
262
+
263
+ for (let v = 0; v < versions.versions.length; v++)
264
+ {
265
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
266
+ if (versions.versions[v].versionName.toString().toUpperCase() == versionName.toUpperCase()) {
267
+ logger.info (`Reconciling version ${versions.versions[v].versionName} ...`)
268
+
269
+ const result = await un.reconcile(versions.versions[v].versionGuid, false, false, true, false);
270
+ logger.info(JSON.stringify(result))
271
+ break;
272
+ }
273
+
274
+ }
275
+ logger.info (`Reconciled ${versionName}.`)
276
+ },
277
+
278
+
279
+ "^reconcile --all$": async () => {
280
+
281
+ const versions = await un.versions();
282
+
283
+ for (let v = 0; v < versions.versions.length; v++)
284
+ {
285
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
286
+ logger.info (`Reconciling version ${versions.versions[v].versionName} ...`)
287
+
288
+ const result = await un.reconcile(versions.versions[v].versionGuid, false, false, true, false);
289
+ logger.info(JSON.stringify(result))
290
+ }
291
+ const rowCount = versions.versions.length;
292
+ logger.info (`Reconciled ${numberWithCommas(rowCount)} versions.`)
293
+ },
294
+
295
+ "^reconcile --all --async$": async () => {
296
+ //async
297
+ const versions = await un.versions();
298
+
299
+ for (let v = 0; v < versions.versions.length; v++)
300
+ {
301
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
302
+ logger.info (`Reconciling version ${versions.versions[v].versionName} ...`)
303
+
304
+ const result = await un.reconcile(versions.versions[v].versionGuid, false, false, true, true);
305
+ logger.info(JSON.stringify(result))
306
+ }
307
+ const rowCount = versions.versions.length;
308
+ logger.info (`Reconciled ${numberWithCommas(rowCount)} versions.`)
309
+ },
310
+
311
+
312
+ "^versions --disconnect$": async () => {
313
+ //disconnect all versions
314
+ const versions = await un.versions();
315
+
316
+ for (let v = 0; v < versions.versions.length; v++)
317
+ {
318
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
319
+ logger.info (`Stopping editing on version ${versions.versions[v].versionName} ...`)
320
+ const g = versions.versions[v].versionGuid
321
+ let result = await un.stopEditing(g,g);
322
+ logger.info(JSON.stringify(result))
323
+ logger.info (`Stopping reading on version ${versions.versions[v].versionName} ...`)
324
+ result = await un.stopReading(g,g);
325
+ logger.info(JSON.stringify(result))
326
+ }
327
+ const rowCount = versions.versions.length;
328
+ logger.info (`Disconnected ${numberWithCommas(rowCount)} versions.`)
329
+ },
231
330
  "^subnetworks$": async () => {
232
331
 
233
332
  const subnetworks = await un.getSubnetworks();
@@ -1425,7 +1524,16 @@ export async function run (){
1425
1524
  parameters = await parseInput( )
1426
1525
  //set certificate verification
1427
1526
  const verifyCert = parameters["verify"] === 'true' ? 1 : 0;
1527
+ const proxy = parameters["proxy"]
1428
1528
  process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = verifyCert;
1529
+
1530
+ if (proxy){
1531
+ logger.info(`Using proxy ${proxy}`);
1532
+ process.env['HTTPS_PROXY'] = proxy;
1533
+ }
1534
+
1535
+
1536
+
1429
1537
  setTimeout( async ()=> await regenerateToken(parameters) , 1000*60*GENERATE_TOKEN_TIME_MIN)
1430
1538
  await connect(parameters)
1431
1539
  }
package/makerequest.mjs CHANGED
@@ -1,6 +1,5 @@
1
-
2
-
3
1
 
2
+
4
3
  export function makeRequest (opts) {
5
4
 
6
5
  return new Promise(async function (resolve, reject) {
@@ -23,26 +22,43 @@ export function makeRequest (opts) {
23
22
 
24
23
  if (opts.headers)
25
24
  Object.keys(opts.headers).forEach( key => headers[key] = opts.headers[key] )
26
-
27
- //console.log(opts)
28
-
25
+
26
+ let jsonRes
27
+ let agent;
29
28
  let f;
29
+
30
30
  try {
31
-
31
+
32
32
  let nodeFetch = await import ("node-fetch");
33
33
  f = nodeFetch.default;
34
34
  }
35
35
  catch(ex) {
36
36
  f = fetch;
37
+ }
38
+ //set a proxy if one exists
39
+
40
+ if (process.env['HTTPS_PROXY'])
41
+ {
42
+ try {
43
+ const HttpsProxyAgent = await import ('https-proxy-agent')
44
+ agent = new HttpsProxyAgent.HttpsProxyAgent(process.env['HTTPS_PROXY'])
45
+ }
46
+ catch (ex){
47
+ agent = undefined;
48
+ }
49
+
50
+ }
51
+
52
+ const options = {
53
+ "method" : opts.method,
54
+ "headers": headers,
55
+ "body": params
37
56
  }
38
-
39
- let jsonRes
40
-
41
- const result = await f(opts.url, {
42
- "method" : opts.method,
43
- "headers": headers,
44
- "body": params
45
- });
57
+
58
+ if (agent)
59
+ options.agent = agent;
60
+
61
+ const result = await f(opts.url,options);
46
62
 
47
63
  jsonRes = await result.json();
48
64
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "un-cli",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
4
4
  "description": "Command line interface for working with ArcGIS Utility Network Extension",
5
5
  "main": "index.mjs",
6
6
  "bin": {
@@ -17,6 +17,7 @@
17
17
  "author": "Hussein Nasser",
18
18
  "license": "ISC",
19
19
  "dependencies": {
20
+ "https-proxy-agent": "^7.0.6",
20
21
  "node-fetch": "^2.6.0"
21
22
  }
22
23
  }
package/un.mjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node --experimental-modules
2
-
3
- import {run} from "./index.mjs"
1
+ #!/usr/bin/env node --experimental-modules
2
+
3
+ import {run} from "./index.mjs"
4
4
  run();
@@ -443,6 +443,13 @@ export class UtilityNetwork {
443
443
 
444
444
 
445
445
 
446
+ if (this.layerDefinition.systemLayers.dirtyObjectsTableId)
447
+ systemLayers.push({
448
+ "id": this.layerDefinition.systemLayers.dirtyObjectsTableId,
449
+ "name": "Dirty Objects",
450
+ "type": "Feature Layer",
451
+ "geometryType": "None"
452
+ })
446
453
 
447
454
  if (this.layerDefinition.systemLayers.pointErrorsLayerId)
448
455
  systemLayers.push({
@@ -815,8 +822,109 @@ export class UtilityNetwork {
815
822
 
816
823
  }
817
824
 
825
+ startReading(versionGuid, sessionGuid){
826
+ let thisObj = this;
827
+ let ar = thisObj.featureServiceUrl.split("/");
828
+ ar[ar.length-1]="VersionManagementServer";
829
+
830
+ let url = ar.join("/") + "/versions/" + versionGuid.replace("{","").replace("}", "") + "/startReading"
831
+ let vmsJson = {
832
+ f: "json",
833
+ sessionId: sessionGuid,
834
+ token: this.token
835
+ }
836
+
837
+ return makeRequest({method:'POST', params: vmsJson, url: url })
838
+
839
+ }
840
+
841
+
842
+
843
+ stopReading(versionGuid, sessionGuid){
844
+ let thisObj = this;
845
+ let ar = thisObj.featureServiceUrl.split("/");
846
+ ar[ar.length-1]="VersionManagementServer";
847
+
848
+ let url = ar.join("/") + "/versions/" + versionGuid.replace("{","").replace("}", "") + "/stopReading"
849
+ let vmsJson = {
850
+ f: "json",
851
+ sessionId: sessionGuid,
852
+ token: this.token
853
+ }
854
+
855
+ return makeRequest({method:'POST', params: vmsJson, url: url })
856
+
857
+ }
858
+
859
+
860
+
861
+ startEditing(versionGuid, sessionGuid){
862
+
863
+ let thisObj = this;
864
+ let ar = thisObj.featureServiceUrl.split("/");
865
+ ar[ar.length-1]="VersionManagementServer";
866
+
867
+ let url = ar.join("/") + "/versions/" + versionGuid.replace("{","").replace("}", "") + "/startEditing"
868
+ let vmsJson = {
869
+ f: "json",
870
+ sessionId: sessionGuid,
871
+ token: this.token
872
+ }
873
+
874
+ return makeRequest({method:'POST', params: vmsJson, url: url })
875
+
876
+ }
877
+
878
+
879
+
880
+ stopEditing(versionGuid, sessionGuid,saveEdits=true){
881
+ let thisObj = this;
882
+ let ar = thisObj.featureServiceUrl.split("/");
883
+ ar[ar.length-1]="VersionManagementServer";
884
+
885
+ let url = ar.join("/") + "/versions/" + versionGuid.replace("{","").replace("}", "") + "/stopEditing"
886
+ let vmsJson = {
887
+ f: "json",
888
+ sessionId: sessionGuid,
889
+ saveEdits:saveEdits,
890
+ token: this.token
891
+ }
892
+
893
+ return makeRequest({method:'POST', params: vmsJson, url: url })
894
+
895
+ }
896
+
818
897
 
819
- versions() {
898
+
899
+ async reconcile (versionGuid, withPost = false, abortIfConflicts=false, conflictDetection=true, async = false ) {
900
+
901
+ //startReading use the version guid as a session id
902
+ await this.startReading(versionGuid,versionGuid );
903
+ await this.startEditing(versionGuid,versionGuid );
904
+ let thisObj = this;
905
+ let ar = thisObj.featureServiceUrl.split("/");
906
+ ar[ar.length-1]="VersionManagementServer";
907
+
908
+ let url = ar.join("/") + "/versions/" + versionGuid.replace("{","").replace("}", "") + "/reconcile"
909
+ let vmsJson = {
910
+ f: "json",
911
+ sessionId: versionGuid,
912
+ withPost: withPost,
913
+ async: async,
914
+ token: this.token
915
+ }
916
+
917
+ const result = makeRequest({method:'POST', params: vmsJson, url: url })
918
+
919
+ /* if (async == false){
920
+ await this.stopEditing(versionGuid,versionGuid );
921
+ await this.stopReading(versionGuid,versionGuid );}*/
922
+
923
+ return result;
924
+
925
+ }
926
+
927
+ versions() {
820
928
 
821
929
  let thisObj = this;
822
930
  let ar = thisObj.featureServiceUrl.split("/");