cityworks 0.0.37 → 0.0.38

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 CHANGED
@@ -6,6 +6,8 @@ Require the class:
6
6
 
7
7
  const Cityworks = require('cityworks')
8
8
 
9
+ import { Cityworks } from 'cityworks'
10
+
9
11
  Instantiate the Class for the instance of Cityworks available given a domain:
10
12
 
11
13
  let cw = new Cityworks('cw.domain.tld', {path: 'cityworks'})
@@ -23,11 +25,11 @@ Authenticate with the Cityworks install:
23
25
 
24
26
  Get the currently valid token in order to store it in a session or cookie:
25
27
 
26
- cityworks.getToken()
28
+ cw.getToken()
27
29
 
28
30
  Provide a saved token instead of the standard u/p auth:
29
31
 
30
- cityworks.setToken('mytoken')
32
+ cw.setToken('mytoken')
31
33
 
32
34
  ## Main method calls
33
35
 
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "cityworks",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "A Cityworks API wrapper",
5
5
  "main": "dist/index.js",
6
6
  "umd:main": "dist/index.umd.js",
7
7
  "module": "dist/index.m.js",
8
8
  "source": "src/index.ts",
9
+ "files": ["dist/*"],
9
10
  "directories": {
10
11
  "test": "test"
11
12
  },
package/index.js DELETED
@@ -1 +0,0 @@
1
- module.exports require('./dist/index.js');
@@ -1,241 +0,0 @@
1
- import { CWError } from './error'
2
- import ReversibleMap from 'reversible-map'
3
- const _ = require('lodash')
4
-
5
- /**
6
- * ActivityLink interface for ActivityLinks
7
- *
8
- */
9
- export interface ActivityLink {
10
- linkTypes: ReversibleMap<string, number>
11
- activityTypes: ReversibleMap<string, number>
12
- cw: any
13
- }
14
-
15
- /**
16
- * ActivityLinks implements the activity link functions via using the ActivityLink interface
17
- *
18
- */
19
- export class ActivityLinks implements ActivityLink {
20
- /**
21
- * Activity types to map string to number for internal use. Activity types available are:
22
- *
23
- * "null", "case", "inspection", "request", "workorder", "wipcase"
24
- */
25
- activityTypes: ReversibleMap<string, number>
26
- /**
27
- * Link types to map string to number for internal use. Link types available are:
28
- *
29
- * "null", "parent", "related"
30
- */
31
- linkTypes: ReversibleMap<string, number>
32
- /**
33
- * @hidden
34
- */
35
- cw: any
36
-
37
- /**
38
- * @hidden
39
- */
40
- constructor(cw) {
41
- this.cw = cw
42
- this.activityTypes = new ReversibleMap<string, number>()
43
- this.activityTypes.set("null", 0)
44
- this.activityTypes.set("case", 1)
45
- this.activityTypes.set("inspection", 2)
46
- this.activityTypes.set("request", 3)
47
- this.activityTypes.set("workorder", 4)
48
- this.activityTypes.set("wipcase", 5)
49
-
50
- this.linkTypes = new ReversibleMap<string, number>()
51
- this.linkTypes.set("null", 0)
52
- this.linkTypes.set("parent", 1)
53
- this.linkTypes.set("related", 2)
54
- }
55
-
56
- /**
57
- * Create a new activity link between two items.
58
- *
59
- * @param {string} source_type - Source type as string. Options:
60
- *
61
- * "null", "case", "inspection", "request", "workorder", "wipcase"
62
- *
63
- * @param {number} source_sid - Source SID (numeric ID) one wishes to remove a link between SID as source and a particular destination
64
- * @param {string} destination_type - Destination type as string
65
- *
66
- * "null", "case", "inspection", "request", "workorder", "wipcase"
67
- *
68
- * @param {number} destination_sid - Destination SID (numeric ID) one wishes to remove a link between SID as destination and a particular source
69
- * @param {string} link_type - The type of link which exists between provided source and destination. Defaults to `related`. Options:
70
- *
71
- * "null", "parent", "related"
72
- *
73
- * @return {Object} Returns Promise object that represents a
74
- */
75
- add(source_type: string, source_sid: number, destination_type: string, destination_sid: number, link_type: string = 'related') {
76
- return new Promise((resolve, reject) => {
77
- if(!this.activityTypes.has(source_type)) {
78
- reject(new CWError(1, 'Source type not found.', {'provided': source_type, 'options':this.activityTypes}))
79
- }
80
- if(!this.activityTypes.has(destination_type)) {
81
- reject(new CWError(2, 'Destination type not found.', {'provided': destination_type, 'options':this.activityTypes}))
82
- }
83
- if(!this.linkTypes.has(link_type)) {
84
- reject(new CWError(3, 'Link type not found.', {'provided': link_type, 'options':this.linkTypes}))
85
- }
86
- let data = {
87
- SourceType: this.activityTypes.get(source_type),
88
- SourceSid: source_sid,
89
- DestType: this.activityTypes.get(destination_type),
90
- DestSid: destination_sid,
91
- LinkType: this.linkTypes.get(link_type)
92
- }
93
- let path = 'General/ActivityLink/Add'
94
- this.cw.runRequest(path, data).then((response: any) => {
95
- resolve(response.Value)
96
- }).catch(e => {
97
- reject(e)
98
- })
99
- })
100
- }
101
-
102
- /**
103
- * Get the links for a particular node type by ID.
104
- *
105
- * @param {string} type - Source type as string. Options:
106
- *
107
- * "null", "case", "inspection", "request", "workorder", "wipcase"
108
- *
109
- * @param {Array<number>} sids - Array of numeric (S)IDs you wish to get of the specified type
110
- * @return {Object} Returns Promise object that represents a collection
111
- */
112
- get(type: string, sids: Array<number>) {
113
- return new Promise((resolve, reject) => {
114
- if(!this.activityTypes.has(type)) {
115
- reject(new CWError(4, 'Activity type not found.', {'provided': type, 'options':this.activityTypes}))
116
- }
117
- let data = {
118
- ActivityType: this.activityTypes.get(type),
119
- ActivitySids: sids
120
- }
121
- let _this = this
122
- let path = 'General/ActivityLink/ByActivitySids'
123
- this.cw.runRequest(path, data).then((response: any) => {
124
- let return_data = new Array()
125
- _.forEach(response.Value, (link, key) => {
126
- link.DestType = _this.activityTypes.get(link.DestType)
127
- link.SourceType = _this.activityTypes.get(link.SourceType)
128
- link.LinkType = _this.linkTypes.get(link.LinkType)
129
- return_data.push(link)
130
- })
131
- resolve(return_data)
132
- }).catch(e => {
133
- reject(e)
134
- })
135
- })
136
- }
137
-
138
- /**
139
- * Clone a current activity link.
140
- *
141
- * @param {string} source_type - Source type as string. Options:
142
- *
143
- * "null", "case", "inspection", "request", "workorder", "wipcase"
144
- *
145
- * @param {number} source_sid - Source SID (numeric ID) one wishes to clone a link between SID as source and a particular destination
146
- * @param {string} destination_type - Destination type as string
147
- *
148
- * "null", "case", "inspection", "request", "workorder", "wipcase"
149
- *
150
- * @param {number} destination_sid - Destination SID (numeric ID) one wishes to clone a link between SID as destination and a particular source
151
- * @return {Object} Returns Promise object that represents a
152
- */
153
- clone(source_type: string, source_sid: number, destination_type: string, destination_sid: number) {
154
- return new Promise((resolve, reject) => {
155
- if(!this.activityTypes.has(source_type)) {
156
- reject(new CWError(1, 'Source type not found.', {'provided': source_type, 'options':this.activityTypes}))
157
- }
158
- if(!this.activityTypes.has(destination_type)) {
159
- reject(new CWError(2, 'Destination type not found.', {'provided': destination_type, 'options':this.activityTypes}))
160
- }
161
- let data = {
162
- SourceActivityType: this.activityTypes.get(source_type),
163
- SourceActivitySid: source_sid,
164
- DestinationActivityType: this.activityTypes.get(destination_type),
165
- DestinationActivitySid: destination_sid
166
- }
167
- let path = 'General/ActivityLink/CloneByActivitySid'
168
- this.cw.runRequest(path, data).then((response: any) => {
169
- resolve(response.Value)
170
- }).catch(e => {
171
- reject(e)
172
- })
173
- })
174
- }
175
-
176
- /**
177
- * Delete an activity link by ID
178
- *
179
- * @param {number} activity_link_id - The ID of the activity link one wishes to delete
180
- * @return {Object} Returns Promise object that represents a
181
- */
182
- delete(activity_link_id: number) {
183
- return new Promise((resolve, reject) => {
184
- let data = {
185
- ActivityLinkId: activity_link_id
186
- }
187
- let path = 'General/ActivityLink/Delete'
188
- this.cw.runRequest(path, data).then((response: any) => {
189
- resolve(response.Value)
190
- }).catch(e => {
191
- reject(e)
192
- })
193
- })
194
- }
195
-
196
- /**
197
- * Remove a link by specifying everything.
198
- *
199
- * @param {string} source_type - Source type as string. Options:
200
- *
201
- * "null", "case", "inspection", "request", "workorder", "wipcase"
202
- *
203
- * @param {number} source_sid - Source SID (numeric ID) one wishes to remove a link between SID as source and a particular destination
204
- * @param {string} destination_type - Destination type as string
205
- *
206
- * "null", "case", "inspection", "request", "workorder", "wipcase"
207
- *
208
- * @param {number} destination_sid - Destination SID (numeric ID) one wishes to remove a link between SID as destination and a particular source
209
- * @param {string} link_type - The type of link which exists between provided source and destination. Defaults to `related`. Options:
210
- *
211
- * "null", "parent", "related"
212
- *
213
- * @return {Object} Returns Promise object that represents a
214
- */
215
- remove(source_type: string, source_sid: number, destination_type: string, destination_sid: number, link_type: string = 'related') {
216
- return new Promise((resolve, reject) => {
217
- if(!this.activityTypes.has(source_type)) {
218
- reject(new CWError(1, 'Source type not found.', {'provided': source_type, 'options':this.activityTypes}))
219
- }
220
- if(!this.activityTypes.has(destination_type)) {
221
- reject(new CWError(1, 'Destination type not found.', {'provided': destination_type, 'options':this.activityTypes}))
222
- }
223
- if(!this.linkTypes.has(link_type)) {
224
- reject(new CWError(1, 'Link type not found.', {'provided': link_type, 'options':this.linkTypes}))
225
- }
226
- let data = {
227
- SourceType: this.activityTypes.get(source_type),
228
- SourceSid: source_sid,
229
- DestType: this.activityTypes.get(destination_type),
230
- DestSid: destination_sid,
231
- LinkType: this.linkTypes.get(link_type)
232
- }
233
- let path = 'General/ActivityLink/Remove'
234
- this.cw.runRequest(path, data).then((response: any) => {
235
- resolve(response.Value)
236
- }).catch(e => {
237
- reject(e)
238
- })
239
- })
240
- }
241
- }
package/src/case.ts DELETED
@@ -1,282 +0,0 @@
1
- import { CWError } from './error'
2
- const _ = require('lodash')
3
-
4
- import { CaseData } from './case_data'
5
- import { CaseFinancial } from './case_financial'
6
- import { CaseWorkflow} from './case_workflow'
7
- import { CaseAdmin } from './case_admin'
8
- import { Comments } from './comments'
9
- import { CaseAssets } from './case_assets'
10
-
11
- export class Case {
12
- /**
13
- * @hidden
14
- */
15
- cw: any
16
-
17
-
18
- /**
19
- * Data Detail methods
20
- */
21
- data?: Object
22
- /**
23
- * Asset (Address) methods
24
- */
25
- asset?: Object
26
- /**
27
- * Workflow & task methods
28
- */
29
- workflow?: Object
30
- /**
31
- * Payment, Receipt, & Fee methods
32
- */
33
- financial?: Object
34
- /**
35
- * Commenting methods
36
- */
37
- comment?: Object
38
- /**
39
- * PLL Administration methods
40
- */
41
- admin?: Object
42
-
43
- /**
44
- * @hidden
45
- */
46
- constructor(cw) {
47
- this.cw = cw
48
- this.data = new CaseData(cw)
49
- this.asset = new CaseAssets(cw)
50
- this.workflow = new CaseWorkflow(cw)
51
- this.financial = new CaseFinancial(cw)
52
- this.comment = new Comments(cw, 'CaObject')
53
- this.admin = new CaseAdmin(cw)
54
- }
55
-
56
- /**
57
- * Create new case
58
- *
59
- * @category Cases
60
- * @param {number} caseTypeId - The case Type ID
61
- * @param {number} subTypeId - The case subType ID
62
- * @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
63
- * @return {Object} Returns Promise that represents an object describing the newly-created case
64
- */
65
- create(caseTypeId: number, subTypeId: number, options?: Object) {
66
- return new Promise((resolve, reject) => {
67
- var data_init = {
68
- CaseTypeId: caseTypeId,
69
- SubTypeId: subTypeId
70
- }
71
- var data = _.merge(data_init, options)
72
- this.cw.runRequest('Pll/Case/Create', data).then(r => {
73
- resolve(r.Value)
74
- }).catch(e => {
75
- reject(e)
76
- })
77
- })
78
- }
79
-
80
- /**
81
- * Create a child case
82
- *
83
- * @category Cases
84
- * @param {number} busCaseId - The case Type ID
85
- * @param {number} parentCaObjectId - The case subType ID
86
- * @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
87
- * @return {Object} Returns Promise that represents an object describing the newly-created case
88
- */
89
- createChild(busCaseId: number, parentCaObjectId: number, options?: Object) {
90
- return new Promise((resolve, reject) => {
91
- var data_init = {
92
- BusCaseId: busCaseId,
93
- ParentCaObjectId: parentCaObjectId
94
- }
95
- var data = _.merge(data_init, options)
96
- this.cw.runRequest('Pll/Case/CreateChild', data).then(r => {
97
- resolve(r.Value)
98
- }).catch(e => {
99
- reject(e)
100
- })
101
- })
102
- }
103
-
104
- /**
105
- * Create a case from a Service Request
106
- *
107
- * @category Cases
108
- * @param {number} caseTypeId - The case Type ID
109
- * @param {number} subTypeId - The case subType ID
110
- * @param {number} requestId - The service request ID
111
- * @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
112
- * @return {Object} Returns Promise that represents an object describing the newly-created case
113
- */
114
- createFromRequest(caseTypeId: number, subTypeId: number, requestId: number, options?: Object) {
115
- return new Promise((resolve, reject) => {
116
- var data_init = {
117
- CaseTypeId: caseTypeId,
118
- SubTypeId: subTypeId,
119
- ServiceRequestId: requestId
120
- }
121
- var data = _.merge(data_init, options)
122
- this.cw.runRequest('Pll/CaseObject/CreateCaseFromServiceRequest', data).then(r => {
123
- resolve(r.Value)
124
- }).catch(e => {
125
- reject(e)
126
- })
127
- })
128
- }
129
-
130
- /**
131
- * Update a case
132
- *
133
- * @category Cases
134
- * @param {number} caObjectId - The case Object ID to update
135
- * @param {Object} [options] - See /{subdirectory}/apidocs/#/data-type-info;dataType=CaObjectItemBase
136
- * @return {Object} Returns Promise that represents an object describing the updated case
137
- */
138
- update(caObjectId: number, options?: Object) {
139
- return new Promise((resolve, reject) => {
140
- var data_init = {
141
- CaObjectId: caObjectId
142
- }
143
- var data = _.merge(data_init, options)
144
- this.cw.runRequest('Pll/CaseObject/Update', data).then(r => {
145
- resolve(r.Value)
146
- }).catch(e => {
147
- reject(e)
148
- })
149
- })
150
- }
151
-
152
- /**
153
- * Get cases by IDs
154
- *
155
- * @category Cases
156
- * @param {Array<number>} caObjectIds - The case Object ID to update
157
- * @return {Object} Returns Promise that represents a collection of objects describing the cases
158
- */
159
- getByIds(caObjectIds: Array<number>) {
160
- return new Promise((resolve, reject) => {
161
- var data = {
162
- CaObjectIds: caObjectIds
163
- }
164
- this.cw.runRequest('Pll/CaseObject/ByIds', data).then(r => {
165
- resolve(r.Value)
166
- }).catch(e => {
167
- reject(e)
168
- })
169
- })
170
- }
171
-
172
- /**
173
- * Search for Cases. Include at least one of the search fields. A logical 'and' operation is applied for multiple search fields.
174
- *
175
- * @category Cases
176
- * @param {Object} filters - The parameter(s) to search by
177
- * @return {Object} Returns Promise that represents an Array of case Object IDs
178
- */
179
- search(filters: Object) {
180
- return new Promise((resolve, reject) => {
181
- var data = filters
182
- this.cw.runRequest('Pll/CaseObject/Search', data).then(r => {
183
- resolve(r.Value)
184
- }).catch(e => {
185
- reject(e)
186
- })
187
- })
188
- }
189
-
190
- /**
191
- * Move a Case point
192
- *
193
- * @category Cases
194
- * @param {string} caObjectId
195
- * @param {number} x
196
- * @param {number} y
197
- * @param {Object} projection - Should include at least WKT _or_ WKID attribute. Can also include VcsWKID attribute.
198
- * @param {number} [z] - Optional Z coordinate
199
- * @return {Object} Returns Promise that represents an object describing the updated GISPoint
200
- */
201
- move(caObjectId: number, x: number, y: number, projection: {WKID?: string, WKT?: string, VcsWKID?: string}, z?: number) {
202
- return new Promise((resolve, reject) => {
203
- if(!_.has(projection, 'WKID') && !_.has(projection, 'WKT')) {
204
- // Throw error
205
- reject(new CWError(1, 'You must provide either the WKID or WKT for the x/y coordinates.', {'projection': projection}))
206
- }
207
- var data_init = {
208
- CaObjectId: caObjectId,
209
- X: x,
210
- Y: y
211
- };
212
- if(typeof(z)!='undefined') {
213
- _.set(data_init, 'Z', z)
214
- }
215
- var data = _.merge(data_init, projection);
216
- this.cw.runRequest('Pll/CaseObject/Move', data).then(r => {
217
- resolve(r.Value)
218
- }).catch(e => {
219
- reject(e)
220
- })
221
- })
222
- }
223
-
224
- /**
225
- * Delete case
226
- *
227
- * @category Cases
228
- * @param {number} caObjectId - The case Object ID
229
- * @return {Object} Returns Promise that represents an object describing the deleted case
230
- */
231
- delete(caObjectId: number) {
232
- return new Promise((resolve, reject) => {
233
- var data = {
234
- CaObjectId: caObjectId
235
- }
236
- this.cw.runRequest('Pll/CaseObject/DeleteCase', data).then(r => {
237
- resolve(r.Value)
238
- }).catch(e => {
239
- reject(e)
240
- })
241
- })
242
- }
243
-
244
- // importCase(caseTypeId: number, subTypeId: number, caseName: string, location: string, x: number, y:number, appData: object, comment: string, expiration: string, assetIds: object) {
245
- // return new Promise(resolve => {
246
- // const _this = this;
247
- // let case_data = {"CaseName":caseName, "Location":location, "DateExpiration": expiration, "X":x,"Y":y}
248
- // this.create(caseTypeId, subTypeId, case_data).then((response: any) => {
249
- // if(response) {
250
- // if(typeof(response.CaObjectId)!='undefined') {
251
- // var CaObjectId = response.CaObjectId
252
- // if(typeof(comment) != 'undefined') {
253
- // _this.comments.add(CaObjectId, comment)
254
- // }
255
- // if(assetIds) {
256
- // _this.assets!.attach(CaObjectId, true, assetIds)
257
- // }
258
- // if(appData) {
259
- // _this.data!.getGroupsByCaseId(response.CaObjectId).then(response_one => {
260
- // // loop through all groups
261
- // let data_details_items = []
262
- // _this.data!.caseDataGroupIterator(appData, response_one, data_details_items).then(di => {
263
- // _this.data!.caseDataDetailIterator(appData, di).then(resp => {
264
- // resolve(response)
265
- // })
266
- // })
267
- // })
268
- // } else {
269
- // resolve(response)
270
- // }
271
- // } else {
272
- // console.log('Error creating case: '+ JSON.stringify(case_data))
273
- // process.exit(0)
274
- // }
275
- // } else {
276
- // resolve(false)
277
- // }
278
- // })
279
- // })
280
- // }
281
-
282
- }