cityworks 0.0.37 → 0.0.39
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/README.md +4 -2
- package/dist/cityworks.d.ts +10 -25
- package/dist/index.js.map +1 -1
- package/dist/index.m.js.map +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -1
- package/index.js +0 -1
- package/src/activity_link.ts +0 -241
- package/src/case.ts +0 -282
- package/src/case_admin.ts +0 -883
- package/src/case_assets.ts +0 -129
- package/src/case_data.ts +0 -446
- package/src/case_financial.ts +0 -848
- package/src/case_workflow.ts +0 -462
- package/src/cityworks.ts +0 -719
- package/src/comments.ts +0 -167
- package/src/costs.ts +0 -289
- package/src/error.ts +0 -56
- package/src/event_layer.ts +0 -231
- package/src/general.ts +0 -143
- package/src/gis.ts +0 -242
- package/src/index.ts +0 -1
- package/src/inspection.ts +0 -851
- package/src/inspection_admin.ts +0 -45
- package/src/message_queue.ts +0 -243
- package/src/request.ts +0 -823
- package/src/request_admin.ts +0 -35
- package/src/search.ts +0 -339
- package/src/workorder.ts +0 -838
- package/src/workorder_admin.ts +0 -248
- package/test/01.cityworksTest.js +0 -80
- package/test/02.activitylinkTest.js +0 -58
- package/test/03.generalTest.js +0 -87
- package/test/04.requestTest.js +0 -293
- package/test/05.caseTest.js +0 -110
- package/test/06.caseFinancialTest.js +0 -172
- package/test/07.searchTest.js +0 -191
- package/test/08.workOrderTest.js +0 -48
- package/test/09.caseAssetsTest.js +0 -72
- package/test/09.inspectionTest.js +0 -28
- package/tsconfig.json +0 -68
package/src/cityworks.ts
DELETED
|
@@ -1,719 +0,0 @@
|
|
|
1
|
-
import { CWError } from './error'
|
|
2
|
-
import { General } from './general'
|
|
3
|
-
import { ActivityLinks } from './activity_link'
|
|
4
|
-
import { Gis } from './gis'
|
|
5
|
-
import { MessageQueue } from './message_queue'
|
|
6
|
-
import { Search } from './search'
|
|
7
|
-
import { Request } from './request'
|
|
8
|
-
import { Inspection } from './inspection'
|
|
9
|
-
import { WorkOrder } from './workorder'
|
|
10
|
-
|
|
11
|
-
import { Case } from './case'
|
|
12
|
-
|
|
13
|
-
const https = require('https')
|
|
14
|
-
const querystring = require('querystring')
|
|
15
|
-
const _ = require('lodash')
|
|
16
|
-
|
|
17
|
-
interface postData {
|
|
18
|
-
data?: string
|
|
19
|
-
token?: string
|
|
20
|
-
file?: any
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Core interface Citywork which defines the access vars for many of the functions and the connection settings
|
|
25
|
-
*/
|
|
26
|
-
interface Citywork {
|
|
27
|
-
base_url: any
|
|
28
|
-
settings: Object
|
|
29
|
-
login?: string
|
|
30
|
-
password?: string
|
|
31
|
-
Token?: string
|
|
32
|
-
gisToken?: string
|
|
33
|
-
gisTokenUrl?: string
|
|
34
|
-
|
|
35
|
-
default_domain?: any
|
|
36
|
-
|
|
37
|
-
general?: Object
|
|
38
|
-
search?: Object
|
|
39
|
-
activity_link?: Object
|
|
40
|
-
message_queue?: Object
|
|
41
|
-
gis?: Object
|
|
42
|
-
inspection?: Object
|
|
43
|
-
workorder?: Object
|
|
44
|
-
request?: Object
|
|
45
|
-
|
|
46
|
-
case?: Object
|
|
47
|
-
|
|
48
|
-
extensions: Object
|
|
49
|
-
features: Object
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Core class Cityworks with most of the authentication and install capabilities functions
|
|
54
|
-
*/
|
|
55
|
-
export class Cityworks implements Citywork {
|
|
56
|
-
/**
|
|
57
|
-
* The domain of the cityworks install. Defaults to Cityworks Online
|
|
58
|
-
*/
|
|
59
|
-
base_url: string
|
|
60
|
-
/**
|
|
61
|
-
* Stores the currently in use authentication token
|
|
62
|
-
*/
|
|
63
|
-
Token?: string
|
|
64
|
-
/**
|
|
65
|
-
* Stores the login username
|
|
66
|
-
*/
|
|
67
|
-
login?: string
|
|
68
|
-
/**
|
|
69
|
-
* Holds the login password
|
|
70
|
-
*/
|
|
71
|
-
password?: string
|
|
72
|
-
/**
|
|
73
|
-
* Holds the GIS Token for GIS-based Authentication (Portal)
|
|
74
|
-
*/
|
|
75
|
-
gisToken?: string
|
|
76
|
-
/**
|
|
77
|
-
* Holds the GIS Token URL for GIS-based Authentication (Portal)
|
|
78
|
-
*/
|
|
79
|
-
gisTokenUrl?: string
|
|
80
|
-
/**
|
|
81
|
-
* Stores settings including path (defaults to "cityworks"), secure (defaults to true), expires (defaults to null - does not expire), default_domain
|
|
82
|
-
*/
|
|
83
|
-
settings: {
|
|
84
|
-
path: string,
|
|
85
|
-
secure: boolean,
|
|
86
|
-
expires: any,
|
|
87
|
-
default_domain?: any
|
|
88
|
-
}
|
|
89
|
-
error?: Object
|
|
90
|
-
general?: Object
|
|
91
|
-
search?: Object
|
|
92
|
-
activity_link?: Object
|
|
93
|
-
message_queue?: Object
|
|
94
|
-
gis?: Object
|
|
95
|
-
request?: Object
|
|
96
|
-
inspection?: Object
|
|
97
|
-
workorder?: Object
|
|
98
|
-
|
|
99
|
-
case?: Object
|
|
100
|
-
|
|
101
|
-
extensions: Object
|
|
102
|
-
features: Object
|
|
103
|
-
potential_loads: Array<string>
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Contructor for a new cityworks instance's object, allows one to optionally configure the domain and other settings right from the get-go
|
|
107
|
-
* @param {string} [base_url] - The first color, in hexadecimal format.
|
|
108
|
-
* @param {object} [settings] - The second color, in hexadecimal format.
|
|
109
|
-
* @param {array} [load] - allows user to choose which modules to load and make available. Full availability array: ['general', 'activity_link', 'message_queue', 'gis', 'workorder', 'inspection', 'request', 'case']
|
|
110
|
-
*/
|
|
111
|
-
constructor(base_url?: string, settings?: Object, load?: Array<string>) {
|
|
112
|
-
this.base_url = 'cityworksonline'
|
|
113
|
-
this.extensions = {"UnknownExtension": 0, "CwAnalytics": 1, "WebHooks": 2, "PLLPublicApp": 3, "ActivityUpdate": 4, "SingleSignOn": 5}
|
|
114
|
-
this.features = {"UnknownFeature": 0, "ViewInspections": 1, "EditInspections": 2, "ViewServiceRequest": 3, "EditServiceRequest": 4, "ViewWorkOrder": 5, "EditWorkOrder": 6, "EquipmentCheckOut": 7, "OfficeField": 8, "Respond": 9, "Eurl": 10, "PaverInterface": 11, "Contracts": 12, "Storeroom": 13, "PLL": 14, "Cw4XL": 15, "TableEditor": 16, "CCTVInterface": 17, "MobileAndroid": 18, "MobileiOS": 19, "PerformanceBudgeting": 20, "Insights": 21, "RespondCase": 22, "RespondInspection": 23, "RespondServiceRequest": 24, "RespondTaskManager": 25, "RespondWorkOrder": 26, "Workload": 27, "OpX": 28, "TrimbleUnityMobile": 29, "TrimbleVegetationManager": 30}
|
|
115
|
-
this.settings = {
|
|
116
|
-
path: 'cityworks',
|
|
117
|
-
secure: true,
|
|
118
|
-
expires: null,
|
|
119
|
-
default_domain: null
|
|
120
|
-
}
|
|
121
|
-
this.potential_loads = ['general', 'activity_link', 'message_queue', 'gis', 'search', 'request', 'case', 'case_financial']
|
|
122
|
-
if(typeof(base_url)!='undefined') {
|
|
123
|
-
this.configure(base_url, settings, load)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Configure a new cityworks instance's domain and other settings
|
|
129
|
-
*
|
|
130
|
-
* @param {string} [base_url] - The first color, in hexadecimal format.
|
|
131
|
-
* @param {object} [settings] - The second color, in hexadecimal format.
|
|
132
|
-
* @param {array} [load] - allows user to choose which modules to load and make available. Full availability array: ['general', 'activity_link', 'message_queue', 'gis', 'search', 'workorder', 'inspection', 'request', 'case']
|
|
133
|
-
* @return {boolean} Returns true if successful, otherwise, throws error
|
|
134
|
-
*/
|
|
135
|
-
configure(base_url?: string, settings?: Object, load?: Array<string>) {
|
|
136
|
-
if(typeof base_url !== 'undefined') { this.base_url = base_url } else { this.base_url = 'cityworksonline' }
|
|
137
|
-
this.settings = {
|
|
138
|
-
path: 'cityworks',
|
|
139
|
-
secure: true,
|
|
140
|
-
expires: null,
|
|
141
|
-
default_domain: null
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if(typeof(settings)!='undefined') {
|
|
145
|
-
_.forEach(settings, (v,k) => {
|
|
146
|
-
if(typeof(this.settings[k])!='undefined') {this.settings[k] = v}
|
|
147
|
-
})
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
if(typeof(load)=='undefined') {
|
|
151
|
-
this.general = new General(this)
|
|
152
|
-
this.activity_link = new ActivityLinks(this)
|
|
153
|
-
this.message_queue = new MessageQueue(this)
|
|
154
|
-
this.request = new Request(this)
|
|
155
|
-
this.inspection = new Inspection(this)
|
|
156
|
-
this.workorder = new WorkOrder(this)
|
|
157
|
-
this.case = new Case(this)
|
|
158
|
-
this.search = new Search(this)
|
|
159
|
-
} else {
|
|
160
|
-
let _this = this
|
|
161
|
-
_.forEach(this.potential_loads, function(v) {
|
|
162
|
-
switch(v) {
|
|
163
|
-
case 'general':
|
|
164
|
-
_this.general = new General(_this)
|
|
165
|
-
break
|
|
166
|
-
case 'activity_link':
|
|
167
|
-
_this.activity_link = new ActivityLinks(_this)
|
|
168
|
-
break
|
|
169
|
-
case 'message_queue':
|
|
170
|
-
_this.message_queue = new MessageQueue(_this)
|
|
171
|
-
break
|
|
172
|
-
case 'gis':
|
|
173
|
-
_this.gis = new Gis(_this)
|
|
174
|
-
break
|
|
175
|
-
case 'search':
|
|
176
|
-
_this.search = new Search(_this)
|
|
177
|
-
break
|
|
178
|
-
case 'request':
|
|
179
|
-
_this.request = new Request(_this)
|
|
180
|
-
break
|
|
181
|
-
case 'case':
|
|
182
|
-
_this.case = new Case(_this)
|
|
183
|
-
break
|
|
184
|
-
case 'inspection':
|
|
185
|
-
_this.inspection = new Inspection(_this)
|
|
186
|
-
break
|
|
187
|
-
case 'workorder':
|
|
188
|
-
_this.workorder = new WorkOrder(_this)
|
|
189
|
-
break
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Send a request to the Cityworks API
|
|
197
|
-
*
|
|
198
|
-
* If one ever needs to access or call an unimplemented API endpoint of a Cityworks install, one can call this method directly with the path and data payload:
|
|
199
|
-
*
|
|
200
|
-
* `cityworks.runRequest(path, data)`
|
|
201
|
-
*
|
|
202
|
-
* @param {string} path - The path to the particular endpoint
|
|
203
|
-
* @param {Object} data - The data object to be sent to the Cityworks API
|
|
204
|
-
* @param {any} file - The file to send in binary to the Cityworks API
|
|
205
|
-
* @return {Object} Returns Promise object that represents the json object returned from the Cityworks API
|
|
206
|
-
*/
|
|
207
|
-
runRequest(path, data?, file?: any) {
|
|
208
|
-
return new Promise((resolve, reject) => {
|
|
209
|
-
let pd = {} as postData
|
|
210
|
-
|
|
211
|
-
if(typeof(data) !== 'undefined') {
|
|
212
|
-
pd.data = JSON.stringify(data)
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
if(typeof(file) !== 'undefined' && (path=='Pll/CaseRelDocs/AddTaskRelDoc' || path=='Pll/CaseRelDocs/Add')) {
|
|
216
|
-
pd.file = file
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if(typeof(this.Token) !== 'undefined' && this.Token != '' && path!='General/Authentication/CityworksOnlineAuthenticate' && path!='General/Authentication/Authenticate') {
|
|
220
|
-
pd.token = this.Token
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
let obj: {
|
|
224
|
-
Status: number,
|
|
225
|
-
Message: string
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
let options = {
|
|
229
|
-
hostname: this.base_url,
|
|
230
|
-
port: 443,
|
|
231
|
-
path: '/' + this.settings.path + '/services/' + path,
|
|
232
|
-
method: 'POST',
|
|
233
|
-
headers: {
|
|
234
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
235
|
-
'Content-Length': Buffer.byteLength(querystring.stringify(pd))
|
|
236
|
-
},
|
|
237
|
-
timeout: 10000000
|
|
238
|
-
}
|
|
239
|
-
let request = https.request(options, (response) => {
|
|
240
|
-
let str=''
|
|
241
|
-
response.on('error',function(e){
|
|
242
|
-
console.log(e, 'Caught on error')
|
|
243
|
-
reject(new CWError(13, "Unknown error.", e))
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
response.on('data',function(chunk){
|
|
247
|
-
str+=chunk
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
response.on('end',function(){
|
|
251
|
-
try {
|
|
252
|
-
var test_str = JSON.stringify(str) + "[test string]"
|
|
253
|
-
if(test_str.match(/\<h2\>Object\ moved\ to/)==null) {
|
|
254
|
-
var obj=JSON.parse(str)
|
|
255
|
-
// if(path=='General/ActivityNotification/UserWatching') {
|
|
256
|
-
// console.log(str, options, pd, obj)
|
|
257
|
-
// }
|
|
258
|
-
if(typeof(obj)=='undefined') {
|
|
259
|
-
// failed
|
|
260
|
-
reject(new CWError(10, 'No response received from Cityworks API.'))
|
|
261
|
-
} else if(typeof(obj)!='undefined' && typeof(obj.Value)!='undefined') { // && typeof(response.Value.Token)!='undefined') {
|
|
262
|
-
switch(obj.Status) {
|
|
263
|
-
case 1:
|
|
264
|
-
reject(new CWError(1, 'Error', obj))
|
|
265
|
-
break;
|
|
266
|
-
case 2:
|
|
267
|
-
reject(new CWError(2, 'Unauthorized', obj))
|
|
268
|
-
break;
|
|
269
|
-
case 3:
|
|
270
|
-
reject(new CWError(3, 'InvalidCredentials', obj))
|
|
271
|
-
break;
|
|
272
|
-
case 0:
|
|
273
|
-
default:
|
|
274
|
-
resolve(obj);
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
} else {
|
|
278
|
-
reject(new CWError(4, "Unknown error.", {options: options, postedData: pd, api_returned_string: obj}))
|
|
279
|
-
}
|
|
280
|
-
} else {
|
|
281
|
-
reject(new CWError(5, "Error parsing JSON. Cityworks returned HTML.", {response: str}))
|
|
282
|
-
}
|
|
283
|
-
} catch (e) {
|
|
284
|
-
if (e instanceof SyntaxError) {
|
|
285
|
-
console.log('try/catch error on JSON')
|
|
286
|
-
reject(new CWError(6, "Error parsing JSON.", {error: e}))
|
|
287
|
-
} else {
|
|
288
|
-
console.log('try/catch error on JSON - but not an instance of SyntaxError')
|
|
289
|
-
reject(new CWError(7, "Error parsing JSON."))
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
})
|
|
293
|
-
})
|
|
294
|
-
request.write(querystring.stringify(pd))
|
|
295
|
-
request.end()
|
|
296
|
-
})
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Authenticate with the Cityworks API and store an access token for use. Stores the token on cityworks.Token.
|
|
301
|
-
* @param {string} login - User's login name
|
|
302
|
-
* @param {password} password - User's password
|
|
303
|
-
* @return {Object} Returns Promise object that represents a boolean which tells you the login succeeded (true) or failed (false).
|
|
304
|
-
*/
|
|
305
|
-
authenticate(login: string, password: string) {
|
|
306
|
-
return new Promise((resolve, reject) => {
|
|
307
|
-
let data = { LoginName:login, Password:password }
|
|
308
|
-
let path = 'General/Authentication/Authenticate'
|
|
309
|
-
if(this.base_url == 'cityworksonline') {
|
|
310
|
-
path = 'General/Authentication/CityworksOnlineAuthenticate'
|
|
311
|
-
}
|
|
312
|
-
this.runRequest(path, data).then((response: any) => {
|
|
313
|
-
// if(response.Status>0) {
|
|
314
|
-
// // failed
|
|
315
|
-
// reject(new CWError(100, response.Message))
|
|
316
|
-
// } else if(typeof(response.Value)!='undefined' && typeof(response.Value.Token)!='undefined') {
|
|
317
|
-
this.login = login
|
|
318
|
-
this.password = password
|
|
319
|
-
this.Token = response.Value.Token
|
|
320
|
-
resolve(true)
|
|
321
|
-
// } else {
|
|
322
|
-
// // failed
|
|
323
|
-
// reject(new CWError(11, 'Unknown Error'))
|
|
324
|
-
// }
|
|
325
|
-
}).catch(error => {
|
|
326
|
-
reject(error);
|
|
327
|
-
})
|
|
328
|
-
})
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* Authenticate a username with a GIS Token
|
|
333
|
-
* @param {login} - Gis user name, should match a Cityworks employee login name
|
|
334
|
-
* @param {string} gisToken - Gis Oauth2 access token
|
|
335
|
-
* @param {string} gisTokenUrl - Base url to GIS server (not the '/generateToken' endpoint)
|
|
336
|
-
* @param {number} [expires] - Authenticate to Cityworks for a specified number of milliseconds, defaults to 2 weeks
|
|
337
|
-
*/
|
|
338
|
-
authenticateWithGISToken(login: string, gisToken: string, gisTokenUrl: string, expires?: number) {
|
|
339
|
-
this.login = login
|
|
340
|
-
this.gisToken = gisToken
|
|
341
|
-
this.gisTokenUrl = gisTokenUrl
|
|
342
|
-
if(typeof(expires)!='undefined') {
|
|
343
|
-
expires = 1209600000
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
return new Promise((resolve, reject) => {
|
|
347
|
-
let path = 'General/Authentication/AuthenticateGisToken'
|
|
348
|
-
let data = { LoginName:this.login, GisToken: this.gisToken, GisTokenUrl: this.gisTokenUrl, Expires: expires}
|
|
349
|
-
|
|
350
|
-
this.runRequest(path, data).then((response: any) => {
|
|
351
|
-
if((typeof(response.Status)!='undefined' && response.Status>0)) {
|
|
352
|
-
// failed
|
|
353
|
-
// TODO: CWError here.
|
|
354
|
-
} else if(typeof(response.Value)!='undefined' && typeof(response.Value.Token)!='undefined') {
|
|
355
|
-
this.Token = response.Value.Token
|
|
356
|
-
resolve(true)
|
|
357
|
-
} else {
|
|
358
|
-
// failed
|
|
359
|
-
resolve(false)
|
|
360
|
-
}
|
|
361
|
-
}).catch(error => {
|
|
362
|
-
throw error
|
|
363
|
-
})
|
|
364
|
-
})
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Validate provided token
|
|
369
|
-
* @param {string} token - User's login name
|
|
370
|
-
* @param {boolean} [set] - Set a valid token as the cityworks instance's active token
|
|
371
|
-
* @return {Object} Returns Promise object that represents a boolean which apprises one of the token's validity and that is was set (true) or throws an error if was not valid (and not set).
|
|
372
|
-
*/
|
|
373
|
-
validateToken(token:string, set?:boolean) {
|
|
374
|
-
return new Promise((resolve, reject) => {
|
|
375
|
-
if(typeof(set)=='undefined') {
|
|
376
|
-
let set = false
|
|
377
|
-
}
|
|
378
|
-
let data = { Token: token }
|
|
379
|
-
let path = 'General/Authentication/Validate'
|
|
380
|
-
this.runRequest(path, data).then((response: any) => {
|
|
381
|
-
if(response.Status>0) {
|
|
382
|
-
// failed
|
|
383
|
-
resolve(false)
|
|
384
|
-
} else {
|
|
385
|
-
if(set) {
|
|
386
|
-
this.Token = token
|
|
387
|
-
}
|
|
388
|
-
resolve(response.Value)
|
|
389
|
-
}
|
|
390
|
-
}).catch(error => {
|
|
391
|
-
throw error
|
|
392
|
-
})
|
|
393
|
-
})
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
/**
|
|
397
|
-
* Set a token you've retrieved from your storage system as the active token for the cityworks instance. Note that this doesn't check the token for validity.
|
|
398
|
-
* @param {token} token - The token string to set as the active token.
|
|
399
|
-
* @return {boolean} Returns a boolean which apprises one that the token was set (true) or not set (false).
|
|
400
|
-
*/
|
|
401
|
-
setToken(token) {
|
|
402
|
-
if(token!='' && token!=null) {
|
|
403
|
-
this.Token = token
|
|
404
|
-
return true
|
|
405
|
-
} else {
|
|
406
|
-
return false
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
/**
|
|
411
|
-
* Get currently set, valid token
|
|
412
|
-
* @param {token} token - The token string to set as the active token.
|
|
413
|
-
* @return {string} Returns a string which is the currently-set token or the boolean false value if no (valid) token set
|
|
414
|
-
*/
|
|
415
|
-
getToken() {
|
|
416
|
-
if(this.Token=='' || this.Token==null) {
|
|
417
|
-
return false
|
|
418
|
-
} else {
|
|
419
|
-
return this.Token
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
/**
|
|
424
|
-
* Revoke all current user's tokens or only tokens created before a particular date and time.
|
|
425
|
-
* @param {number} [revokeBefore] - Datetime as an Epoch integer (number), if you wish to revoke only tokens created before a particular datetime
|
|
426
|
-
* @return {Object} Returns Promise object that represents a boolean which apprises one of the revocation outcome's success (true) or failure (false)
|
|
427
|
-
*/
|
|
428
|
-
revokeToken(revokeBefore?:number) {
|
|
429
|
-
return new Promise((resolve, reject) => {
|
|
430
|
-
let data = { RevokeDate: revokeBefore }
|
|
431
|
-
let path = 'General/Token/RevokeUser'
|
|
432
|
-
this.runRequest(path, data).then((response: any) => {
|
|
433
|
-
if((typeof(response.Status)!='undefined' && response.Status>0)) {
|
|
434
|
-
// failed
|
|
435
|
-
resolve(false)
|
|
436
|
-
} else {
|
|
437
|
-
resolve(true)
|
|
438
|
-
}
|
|
439
|
-
}).catch(error => {
|
|
440
|
-
throw error
|
|
441
|
-
})
|
|
442
|
-
})
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// App data
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Get the localization settings for current Cityworks install
|
|
449
|
-
* @return {Object} Returns Promise object that represents an Object which contains all the localization settings for the current Cityworks install
|
|
450
|
-
*/
|
|
451
|
-
getLocalizationSettings() {
|
|
452
|
-
return new Promise((resolve, reject) => {
|
|
453
|
-
let path = 'General/Localization/LocalizationSettings'
|
|
454
|
-
this.runRequest(path, {}).then((response: any) => {
|
|
455
|
-
resolve(response.Value)
|
|
456
|
-
})
|
|
457
|
-
})
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Get the system timezone options for current Cityworks install
|
|
462
|
-
* @return {Object} Returns Promise object that represents an Object which contains all the timezone settings for the currentCityworks install
|
|
463
|
-
*/
|
|
464
|
-
getTimezoneOptions() {
|
|
465
|
-
return new Promise((resolve, reject) => {
|
|
466
|
-
let path = 'General/Localization/TimeZones'
|
|
467
|
-
this.runRequest(path, {}).then((response: any) => {
|
|
468
|
-
resolve(response.Value)
|
|
469
|
-
})
|
|
470
|
-
})
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
/**
|
|
474
|
-
* Get the current install's location information
|
|
475
|
-
* @return {Object} Returns Promise object that represents an Object which contains the location information
|
|
476
|
-
*/
|
|
477
|
-
getCurrentLocation() {
|
|
478
|
-
return new Promise((resolve, reject) => {
|
|
479
|
-
let path = 'General/AppData/CurrentLocation'
|
|
480
|
-
this.runRequest(path, {}).then((response: any) => {
|
|
481
|
-
resolve(response.Value)
|
|
482
|
-
})
|
|
483
|
-
})
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
// Licensing Checks
|
|
487
|
-
/**
|
|
488
|
-
* Check if a particular license is available to the currently-authenticated user
|
|
489
|
-
* @param {string} area - Area of access
|
|
490
|
-
* @param {string} service - Service to access
|
|
491
|
-
* @return {boolean} Returns Promise object that represents a boolean which informs access is granted (true) or denied (false)
|
|
492
|
-
*/
|
|
493
|
-
licensedApiCheck(area: string, service: string) {
|
|
494
|
-
return new Promise((resolve, reject) => {
|
|
495
|
-
let data = {
|
|
496
|
-
"Area": area,
|
|
497
|
-
"Service": service
|
|
498
|
-
}
|
|
499
|
-
let path = 'General/AppData/SelectedEntities'
|
|
500
|
-
this.runRequest(path, data).then((response: any) => {
|
|
501
|
-
resolve(response.Value)
|
|
502
|
-
})
|
|
503
|
-
})
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* Check if a current Cityworks install is licensed to use a particular extension
|
|
508
|
-
*
|
|
509
|
-
* Possible extensions currently include: "UnknownExtension", "CwAnalytics", "WebHooks", "PLLPublicApp", "ActivityUpdate", "SingleSignOn"
|
|
510
|
-
*
|
|
511
|
-
* @param {string} extension - Extension name
|
|
512
|
-
* @return {boolean} Returns Promise object that represents a boolean which informs extension is licensed (true) or not (false)
|
|
513
|
-
*/
|
|
514
|
-
licensedExtensionCheck(extension: string) {
|
|
515
|
-
return new Promise((resolve, reject) => {
|
|
516
|
-
if(typeof(this.extensions[extension])=='undefined') {
|
|
517
|
-
reject(new CWError(4, 'Extension provided does not exist or is mispelled.', {'provided': extension, 'available': this.extensions}))
|
|
518
|
-
}
|
|
519
|
-
let data = {
|
|
520
|
-
"Extension": this.extensions[extension]
|
|
521
|
-
}
|
|
522
|
-
let path = 'General/Authorization/LicensedExtensionCheck'
|
|
523
|
-
this.runRequest(path, data).then((response: any) => {
|
|
524
|
-
resolve(response.Value)
|
|
525
|
-
})
|
|
526
|
-
})
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Check a whole list to see if current Cityworks install is licensed to use extensions
|
|
531
|
-
*
|
|
532
|
-
* Possible extensions currently include: "UnknownExtension", "CwAnalytics", "WebHooks", "PLLPublicApp", "ActivityUpdate", "SingleSignOn"
|
|
533
|
-
*
|
|
534
|
-
* @param {Array<string>} extension - Extension names
|
|
535
|
-
* @return {Object} Returns Promise object that represents a boolean which informs extension is licensed (true) or not (false)
|
|
536
|
-
*/
|
|
537
|
-
licensedExtensionsCheck(extensions: Array<string>) {
|
|
538
|
-
return new Promise((resolve, reject) => {
|
|
539
|
-
var data: { Extensions: Array<number> } = {
|
|
540
|
-
Extensions: []
|
|
541
|
-
}
|
|
542
|
-
_.forEach(extensions, (v) => {
|
|
543
|
-
if(typeof(this.extensions[v])=='undefined') {
|
|
544
|
-
reject(new CWError(5, 'Extension provided does not exist or is mispelled.', {'provided': v, 'available': this.extensions}))
|
|
545
|
-
} else {
|
|
546
|
-
data.Extensions.push(this.extensions[v])
|
|
547
|
-
}
|
|
548
|
-
})
|
|
549
|
-
let path = 'General/Authorization/LicensedExtensionsCheck'
|
|
550
|
-
this.runRequest(path, data).then((response: any) => {
|
|
551
|
-
let rez: Object = {}
|
|
552
|
-
// reverse boolean to numeric dictionary to a boolean to string dictionary
|
|
553
|
-
let inv_extensions = _.invert(this.extensions)
|
|
554
|
-
_.forEach(response, (ext_num, bool) => {
|
|
555
|
-
if(typeof(inv_extensions[ext_num])=='undefined') {
|
|
556
|
-
reject(new CWError(6, 'Extension index provided does not exist or isn\'t configured properly.', {'provided_num_returned': ext_num, 'available': this.extensions}))
|
|
557
|
-
} else {
|
|
558
|
-
// Put string name of extension in rezponse object and set boolean on it.
|
|
559
|
-
rez[inv_extensions[ext_num]] = bool
|
|
560
|
-
}
|
|
561
|
-
})
|
|
562
|
-
resolve(rez)
|
|
563
|
-
})
|
|
564
|
-
})
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* Check if current user is licensed to use a feature:
|
|
569
|
-
*
|
|
570
|
-
* "UnknownFeature", "ViewInspections", "EditInspections", "ViewServiceRequest", "EditServiceRequest", "ViewWorkOrder", "EditWorkOrder", "EquipmentCheckOut", "OfficeField", "Respond", "Eurl", "PaverInterface", "Contracts", "Storeroom", "PLL", "Cw4XL", "TableEditor", "CCTVInterface", "MobileAndroid", "MobileiOS", "PerformanceBudgeting", "Insights", "RespondCase", "RespondInspection", "RespondServiceRequest", "RespondTaskManager", "RespondWorkOrder", "Workload", "OpX", "TrimbleUnityMobile", "TrimbleVegetationManager"
|
|
571
|
-
*
|
|
572
|
-
* @param {string} [feature] - Feature to check to see if ciurrently authenticated user can utilize
|
|
573
|
-
* @return {Object} Returns Promise object that represents a boolean which communicates license state as licensed (true) or not (false)
|
|
574
|
-
*/
|
|
575
|
-
licensedFeatureCheck(feature: string) {
|
|
576
|
-
return new Promise((resolve, reject) => {
|
|
577
|
-
if(typeof(this.features[feature])=='undefined') {
|
|
578
|
-
reject(new CWError(7, 'Feature provided does not exist or is mispelled.', {'provided': feature, 'available': this.features}))
|
|
579
|
-
}
|
|
580
|
-
let data = {
|
|
581
|
-
"Feature": this.features[feature]
|
|
582
|
-
}
|
|
583
|
-
let path = 'General/Authorization/LicensedFeatureCheck'
|
|
584
|
-
this.runRequest(path, data).then((response: any) => {
|
|
585
|
-
resolve(response.Value)
|
|
586
|
-
})
|
|
587
|
-
})
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
/**
|
|
591
|
-
* Check if current user is licensed to use features:
|
|
592
|
-
*
|
|
593
|
-
* "UnknownFeature", "ViewInspections", "EditInspections", "ViewServiceRequest", "EditServiceRequest", "ViewWorkOrder", "EditWorkOrder", "EquipmentCheckOut", "OfficeField", "Respond", "Eurl", "PaverInterface", "Contracts", "Storeroom", "PLL", "Cw4XL", "TableEditor", "CCTVInterface", "MobileAndroid", "MobileiOS", "PerformanceBudgeting", "Insights", "RespondCase", "RespondInspection", "RespondServiceRequest", "RespondTaskManager", "RespondWorkOrder", "Workload", "OpX", "TrimbleUnityMobile", "TrimbleVegetationManager"
|
|
594
|
-
*
|
|
595
|
-
* @param {Array<string>} [feature] - Features to check to see if currently authenticated user can utilize
|
|
596
|
-
* @return {Object} Returns Promise object that represents a boolean which communicates license state as licensed (true) or not (false)
|
|
597
|
-
*/
|
|
598
|
-
licensedFeaturesCheck(features: Array<string>) {
|
|
599
|
-
return new Promise((resolve, reject) => {
|
|
600
|
-
var data: { Features: Array<number> } = {
|
|
601
|
-
Features: []
|
|
602
|
-
}
|
|
603
|
-
_.forEach(features, (v: string) => {
|
|
604
|
-
if(typeof(this.features[v])=='undefined') {
|
|
605
|
-
reject(new CWError(8, 'Feature provided does not exist or is mispelled.', {'provided': v, 'available': this.features}))
|
|
606
|
-
} else {
|
|
607
|
-
data.Features.push(this.features[v])
|
|
608
|
-
}
|
|
609
|
-
})
|
|
610
|
-
let path = 'General/Authorization/LicensedFeaturesCheck'
|
|
611
|
-
this.runRequest(path, data).then((response: any) => {
|
|
612
|
-
let rez: Object = {}
|
|
613
|
-
// reverse boolean to numeric dictionary to a boolean to string dictionary
|
|
614
|
-
let inv_features = _.invert(this.features)
|
|
615
|
-
_.forEach(response.Value, (feat_num, bool) => {
|
|
616
|
-
if(typeof(inv_features[feat_num])=='undefined') {
|
|
617
|
-
reject(new CWError(9, 'Feature index provided does not exist or isn\'t configured properly.', {'provided': feat_num, 'available': inv_features}))
|
|
618
|
-
} else {
|
|
619
|
-
// Put string name of extension in rezponse object and set boolean on it.
|
|
620
|
-
rez[inv_features[feat_num]] = bool
|
|
621
|
-
}
|
|
622
|
-
})
|
|
623
|
-
resolve(rez)
|
|
624
|
-
})
|
|
625
|
-
})
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// LicensedServicesCheck
|
|
629
|
-
// Check if current user is licensed to use services
|
|
630
|
-
// List req ServicesList of 'Area/Service', i.e. ['AMS/Inspection','AMS/WorkOrder','PLL/Case']
|
|
631
|
-
/**
|
|
632
|
-
* Check if current user is licensed to use services. List req ServicesList of 'Area/Service', i.e.:
|
|
633
|
-
*
|
|
634
|
-
* ['AMS/Inspection','AMS/WorkOrder','PLL/Case']
|
|
635
|
-
*
|
|
636
|
-
* @param {Array<string>} [services] - Services to check to see if currently authenticated user can utilize
|
|
637
|
-
* @return {Object} Returns Promise object that represents a boolean which communicates license state as licensed (true) or not (false)
|
|
638
|
-
*/
|
|
639
|
-
licensedServicesCheck(services: Array<string>) {
|
|
640
|
-
return new Promise((resolve, reject) => {
|
|
641
|
-
let path = 'General/Authorization/LicensedServicesCheck'
|
|
642
|
-
var data: { Services: Array<string> } = {
|
|
643
|
-
Services: services
|
|
644
|
-
}
|
|
645
|
-
this.runRequest(path, data).then((response: any) => {
|
|
646
|
-
resolve(response.Value)
|
|
647
|
-
})
|
|
648
|
-
})
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* Get a list of CityworksOnline sites for this user
|
|
653
|
-
*
|
|
654
|
-
* @param {string} [login] - Login Name to use when checking. Defaults to previously-stored login name.
|
|
655
|
-
* @param {string} [password] - Password to use when checking. Defaults to previously-stored password.
|
|
656
|
-
* @return {Object} Returns Promise object that represents an array of cityworks online sites available to this user.
|
|
657
|
-
*/
|
|
658
|
-
cityworksOnlineSites(login?: string, password?: string) {
|
|
659
|
-
return new Promise((resolve, reject) => {
|
|
660
|
-
let path = 'General/Authentication/CityworksOnlineSites'
|
|
661
|
-
var data = {
|
|
662
|
-
LoginName: (typeof(login)!='undefined') ? login: this.login,
|
|
663
|
-
Password: (typeof(password)!='undefined') ? password : this.password
|
|
664
|
-
}
|
|
665
|
-
this.runRequest(path, data).then((response: any) => {
|
|
666
|
-
resolve(response.Value)
|
|
667
|
-
})
|
|
668
|
-
})
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
/**
|
|
672
|
-
* Get a list of Domains (not tld, but organizations) in the currently-connected Cityworks install
|
|
673
|
-
*
|
|
674
|
-
* @return {Object} Returns Promise object that represents a collection of the configured domains.
|
|
675
|
-
*/
|
|
676
|
-
domains() {
|
|
677
|
-
return new Promise((resolve, reject) => {
|
|
678
|
-
let path = 'General/Authentication/Domains'
|
|
679
|
-
var data = {}
|
|
680
|
-
this.runRequest(path, data).then((response: any) => {
|
|
681
|
-
resolve(response.Value)
|
|
682
|
-
})
|
|
683
|
-
})
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
/**
|
|
687
|
-
* Get a list of Domains (not tld, but organizations) in the currently-connected Cityworks install
|
|
688
|
-
*
|
|
689
|
-
* @param {string} [login] - Optional login name to get user information for. Defaults to currently-set user name used for login.
|
|
690
|
-
* @return {Object} Returns Promise object that represents an Object with the user information
|
|
691
|
-
*/
|
|
692
|
-
user(login?: string) {
|
|
693
|
-
return new Promise((resolve, reject) => {
|
|
694
|
-
let path = 'General/Authentication/User'
|
|
695
|
-
let data = { LoginName: (typeof(login)!='undefined') ? login: this.login }
|
|
696
|
-
this.runRequest(path, data).then((response: any) => {
|
|
697
|
-
resolve(response.Value)
|
|
698
|
-
})
|
|
699
|
-
})
|
|
700
|
-
}
|
|
701
|
-
|
|
702
|
-
/**
|
|
703
|
-
* Get the software version number of the currently-connected Cityworks install
|
|
704
|
-
*
|
|
705
|
-
* @return {Object} Returns Promise object that represents a string of the version number
|
|
706
|
-
*/
|
|
707
|
-
version() {
|
|
708
|
-
return new Promise((resolve, reject) => {
|
|
709
|
-
let path = 'General/Authentication/Version'
|
|
710
|
-
var data = {}
|
|
711
|
-
this.runRequest(path, data).then((response: any) => {
|
|
712
|
-
resolve(response.Value)
|
|
713
|
-
})
|
|
714
|
-
})
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
// export default new Cityworks() as cityworks
|